src/HOL/Set.thy
author nipkow
Mon Aug 31 14:09:42 2009 +0200 (2009-08-31)
changeset 32456 341c83339aeb
parent 32264 0be31453f698
child 32683 7c1fe854ca6a
permissions -rw-r--r--
tuned the simp rules for Int involving insert and intervals.
haftmann@32139
     1
(*  Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel *)
clasohm@923
     2
wenzelm@11979
     3
header {* Set theory for higher-order logic *}
wenzelm@11979
     4
nipkow@15131
     5
theory Set
haftmann@30304
     6
imports Lattices
nipkow@15131
     7
begin
wenzelm@11979
     8
haftmann@32081
     9
subsection {* Sets as predicates *}
haftmann@30531
    10
wenzelm@3947
    11
global
wenzelm@3947
    12
berghofe@26800
    13
types 'a set = "'a => bool"
wenzelm@3820
    14
clasohm@923
    15
consts
haftmann@30531
    16
  Collect       :: "('a => bool) => 'a set"              -- "comprehension"
haftmann@30531
    17
  "op :"        :: "'a => 'a set => bool"                -- "membership"
haftmann@30304
    18
haftmann@30304
    19
local
wenzelm@19656
    20
wenzelm@21210
    21
notation
wenzelm@21404
    22
  "op :"  ("op :") and
wenzelm@19656
    23
  "op :"  ("(_/ : _)" [50, 51] 50)
wenzelm@11979
    24
haftmann@32077
    25
defs
haftmann@32077
    26
  mem_def [code]: "x : S == S x"
haftmann@32077
    27
  Collect_def [code]: "Collect P == P"
haftmann@32077
    28
wenzelm@19656
    29
abbreviation
wenzelm@21404
    30
  "not_mem x A == ~ (x : A)" -- "non-membership"
wenzelm@19656
    31
wenzelm@21210
    32
notation
wenzelm@21404
    33
  not_mem  ("op ~:") and
wenzelm@19656
    34
  not_mem  ("(_/ ~: _)" [50, 51] 50)
wenzelm@19656
    35
wenzelm@21210
    36
notation (xsymbols)
wenzelm@21404
    37
  "op :"  ("op \<in>") and
wenzelm@21404
    38
  "op :"  ("(_/ \<in> _)" [50, 51] 50) and
wenzelm@21404
    39
  not_mem  ("op \<notin>") and
haftmann@30304
    40
  not_mem  ("(_/ \<notin> _)" [50, 51] 50)
wenzelm@19656
    41
wenzelm@21210
    42
notation (HTML output)
wenzelm@21404
    43
  "op :"  ("op \<in>") and
wenzelm@21404
    44
  "op :"  ("(_/ \<in> _)" [50, 51] 50) and
wenzelm@21404
    45
  not_mem  ("op \<notin>") and
wenzelm@19656
    46
  not_mem  ("(_/ \<notin> _)" [50, 51] 50)
wenzelm@19656
    47
haftmann@32081
    48
text {* Set comprehensions *}
haftmann@32081
    49
haftmann@30531
    50
syntax
haftmann@30531
    51
  "@Coll"       :: "pttrn => bool => 'a set"              ("(1{_./ _})")
haftmann@30531
    52
haftmann@30531
    53
translations
haftmann@30531
    54
  "{x. P}"      == "Collect (%x. P)"
haftmann@30531
    55
haftmann@32081
    56
syntax
haftmann@32081
    57
  "@SetCompr"   :: "'a => idts => bool => 'a set"         ("(1{_ |/_./ _})")
haftmann@32081
    58
  "@Collect"    :: "idt => 'a set => bool => 'a set"      ("(1{_ :/ _./ _})")
haftmann@32081
    59
haftmann@32081
    60
syntax (xsymbols)
haftmann@32081
    61
  "@Collect"    :: "idt => 'a set => bool => 'a set"      ("(1{_ \<in>/ _./ _})")
haftmann@32081
    62
haftmann@32081
    63
translations
haftmann@32081
    64
  "{x:A. P}"    => "{x. x:A & P}"
haftmann@32081
    65
haftmann@32081
    66
lemma mem_Collect_eq [iff]: "(a : {x. P(x)}) = P(a)"
haftmann@32081
    67
  by (simp add: Collect_def mem_def)
haftmann@32081
    68
haftmann@32081
    69
lemma Collect_mem_eq [simp]: "{x. x:A} = A"
haftmann@32081
    70
  by (simp add: Collect_def mem_def)
haftmann@32081
    71
haftmann@32081
    72
lemma CollectI: "P(a) ==> a : {x. P(x)}"
haftmann@32081
    73
  by simp
haftmann@32081
    74
haftmann@32081
    75
lemma CollectD: "a : {x. P(x)} ==> P(a)"
haftmann@32081
    76
  by simp
haftmann@32081
    77
haftmann@32081
    78
lemma Collect_cong: "(!!x. P x = Q x) ==> {x. P(x)} = {x. Q(x)}"
haftmann@32081
    79
  by simp
haftmann@32081
    80
haftmann@32117
    81
text {*
haftmann@32117
    82
Simproc for pulling @{text "x=t"} in @{text "{x. \<dots> & x=t & \<dots>}"}
haftmann@32117
    83
to the front (and similarly for @{text "t=x"}):
haftmann@32117
    84
*}
haftmann@32117
    85
haftmann@32117
    86
setup {*
haftmann@32117
    87
let
haftmann@32117
    88
  val Coll_perm_tac = rtac @{thm Collect_cong} 1 THEN rtac @{thm iffI} 1 THEN
haftmann@32117
    89
    ALLGOALS(EVERY'[REPEAT_DETERM o (etac @{thm conjE}),
haftmann@32117
    90
                    DEPTH_SOLVE_1 o (ares_tac [@{thm conjI}])])
haftmann@32117
    91
  val defColl_regroup = Simplifier.simproc @{theory}
haftmann@32117
    92
    "defined Collect" ["{x. P x & Q x}"]
haftmann@32117
    93
    (Quantifier1.rearrange_Coll Coll_perm_tac)
haftmann@32117
    94
in
haftmann@32117
    95
  Simplifier.map_simpset (fn ss => ss addsimprocs [defColl_regroup])
haftmann@32117
    96
end
haftmann@32117
    97
*}
haftmann@32117
    98
haftmann@32081
    99
lemmas CollectE = CollectD [elim_format]
haftmann@32081
   100
haftmann@32081
   101
text {* Set enumerations *}
haftmann@30531
   102
haftmann@32264
   103
abbreviation empty :: "'a set" ("{}") where
haftmann@32264
   104
  "{} \<equiv> bot"
haftmann@31456
   105
haftmann@31456
   106
definition insert :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" where
haftmann@32081
   107
  insert_compr: "insert a B = {x. x = a \<or> x \<in> B}"
haftmann@31456
   108
haftmann@31456
   109
syntax
haftmann@31456
   110
  "@Finset"     :: "args => 'a set"                       ("{(_)}")
haftmann@31456
   111
haftmann@31456
   112
translations
haftmann@31456
   113
  "{x, xs}"     == "CONST insert x {xs}"
haftmann@31456
   114
  "{x}"         == "CONST insert x {}"
haftmann@31456
   115
haftmann@32081
   116
haftmann@32081
   117
subsection {* Subsets and bounded quantifiers *}
haftmann@32081
   118
haftmann@32081
   119
abbreviation
haftmann@32081
   120
  subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@32081
   121
  "subset \<equiv> less"
haftmann@32081
   122
haftmann@32081
   123
abbreviation
haftmann@32081
   124
  subset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@32081
   125
  "subset_eq \<equiv> less_eq"
haftmann@32081
   126
haftmann@32081
   127
notation (output)
haftmann@32081
   128
  subset  ("op <") and
haftmann@32081
   129
  subset  ("(_/ < _)" [50, 51] 50) and
haftmann@32081
   130
  subset_eq  ("op <=") and
haftmann@32081
   131
  subset_eq  ("(_/ <= _)" [50, 51] 50)
haftmann@32081
   132
haftmann@32081
   133
notation (xsymbols)
haftmann@32081
   134
  subset  ("op \<subset>") and
haftmann@32081
   135
  subset  ("(_/ \<subset> _)" [50, 51] 50) and
haftmann@32081
   136
  subset_eq  ("op \<subseteq>") and
haftmann@32081
   137
  subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)
haftmann@32081
   138
haftmann@32081
   139
notation (HTML output)
haftmann@32081
   140
  subset  ("op \<subset>") and
haftmann@32081
   141
  subset  ("(_/ \<subset> _)" [50, 51] 50) and
haftmann@32081
   142
  subset_eq  ("op \<subseteq>") and
haftmann@32081
   143
  subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)
haftmann@32081
   144
haftmann@32081
   145
abbreviation (input)
haftmann@32081
   146
  supset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@32081
   147
  "supset \<equiv> greater"
haftmann@32081
   148
haftmann@32081
   149
abbreviation (input)
haftmann@32081
   150
  supset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@32081
   151
  "supset_eq \<equiv> greater_eq"
haftmann@32081
   152
haftmann@32081
   153
notation (xsymbols)
haftmann@32081
   154
  supset  ("op \<supset>") and
haftmann@32081
   155
  supset  ("(_/ \<supset> _)" [50, 51] 50) and
haftmann@32081
   156
  supset_eq  ("op \<supseteq>") and
haftmann@32081
   157
  supset_eq  ("(_/ \<supseteq> _)" [50, 51] 50)
haftmann@32081
   158
haftmann@32077
   159
global
haftmann@32077
   160
haftmann@32077
   161
consts
haftmann@32077
   162
  Ball          :: "'a set => ('a => bool) => bool"      -- "bounded universal quantifiers"
haftmann@32077
   163
  Bex           :: "'a set => ('a => bool) => bool"      -- "bounded existential quantifiers"
haftmann@32077
   164
  Bex1          :: "'a set => ('a => bool) => bool"      -- "bounded unique existential quantifiers"
haftmann@32077
   165
haftmann@32077
   166
local
haftmann@32077
   167
haftmann@32077
   168
defs
haftmann@32077
   169
  Ball_def:     "Ball A P       == ALL x. x:A --> P(x)"
haftmann@32077
   170
  Bex_def:      "Bex A P        == EX x. x:A & P(x)"
haftmann@32077
   171
  Bex1_def:     "Bex1 A P       == EX! x. x:A & P(x)"
haftmann@32077
   172
haftmann@30531
   173
syntax
haftmann@30531
   174
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3ALL _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   175
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3EX _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   176
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3EX! _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   177
  "_Bleast"     :: "id => 'a set => bool => 'a"           ("(3LEAST _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   178
haftmann@30531
   179
syntax (HOL)
haftmann@30531
   180
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3! _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   181
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3? _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   182
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3?! _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   183
haftmann@30531
   184
syntax (xsymbols)
haftmann@30531
   185
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   186
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   187
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   188
  "_Bleast"     :: "id => 'a set => bool => 'a"           ("(3LEAST_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   189
haftmann@30531
   190
syntax (HTML output)
haftmann@30531
   191
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   192
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   193
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   194
haftmann@30531
   195
translations
haftmann@30531
   196
  "ALL x:A. P"  == "Ball A (%x. P)"
haftmann@30531
   197
  "EX x:A. P"   == "Bex A (%x. P)"
haftmann@30531
   198
  "EX! x:A. P"  == "Bex1 A (%x. P)"
haftmann@30531
   199
  "LEAST x:A. P" => "LEAST x. x:A & P"
haftmann@30531
   200
wenzelm@19656
   201
syntax (output)
nipkow@14804
   202
  "_setlessAll" :: "[idt, 'a, bool] => bool"  ("(3ALL _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   203
  "_setlessEx"  :: "[idt, 'a, bool] => bool"  ("(3EX _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   204
  "_setleAll"   :: "[idt, 'a, bool] => bool"  ("(3ALL _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   205
  "_setleEx"    :: "[idt, 'a, bool] => bool"  ("(3EX _<=_./ _)" [0, 0, 10] 10)
webertj@20217
   206
  "_setleEx1"   :: "[idt, 'a, bool] => bool"  ("(3EX! _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   207
nipkow@14804
   208
syntax (xsymbols)
nipkow@14804
   209
  "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   210
  "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   211
  "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   212
  "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)
webertj@20217
   213
  "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   214
wenzelm@19656
   215
syntax (HOL output)
nipkow@14804
   216
  "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   217
  "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   218
  "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   219
  "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
webertj@20217
   220
  "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3?! _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   221
nipkow@14804
   222
syntax (HTML output)
nipkow@14804
   223
  "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   224
  "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   225
  "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   226
  "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)
webertj@20217
   227
  "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   228
nipkow@14804
   229
translations
haftmann@30531
   230
 "\<forall>A\<subset>B. P"   =>  "ALL A. A \<subset> B --> P"
haftmann@30531
   231
 "\<exists>A\<subset>B. P"   =>  "EX A. A \<subset> B & P"
haftmann@30531
   232
 "\<forall>A\<subseteq>B. P"   =>  "ALL A. A \<subseteq> B --> P"
haftmann@30531
   233
 "\<exists>A\<subseteq>B. P"   =>  "EX A. A \<subseteq> B & P"
haftmann@30531
   234
 "\<exists>!A\<subseteq>B. P"  =>  "EX! A. A \<subseteq> B & P"
nipkow@14804
   235
nipkow@14804
   236
print_translation {*
nipkow@14804
   237
let
wenzelm@22377
   238
  val Type (set_type, _) = @{typ "'a set"};
wenzelm@22377
   239
  val All_binder = Syntax.binder_name @{const_syntax "All"};
wenzelm@22377
   240
  val Ex_binder = Syntax.binder_name @{const_syntax "Ex"};
wenzelm@22377
   241
  val impl = @{const_syntax "op -->"};
wenzelm@22377
   242
  val conj = @{const_syntax "op &"};
wenzelm@22377
   243
  val sbset = @{const_syntax "subset"};
wenzelm@22377
   244
  val sbset_eq = @{const_syntax "subset_eq"};
haftmann@21819
   245
haftmann@21819
   246
  val trans =
haftmann@21819
   247
   [((All_binder, impl, sbset), "_setlessAll"),
haftmann@21819
   248
    ((All_binder, impl, sbset_eq), "_setleAll"),
haftmann@21819
   249
    ((Ex_binder, conj, sbset), "_setlessEx"),
haftmann@21819
   250
    ((Ex_binder, conj, sbset_eq), "_setleEx")];
haftmann@21819
   251
haftmann@21819
   252
  fun mk v v' c n P =
haftmann@21819
   253
    if v = v' andalso not (Term.exists_subterm (fn Free (x, _) => x = v | _ => false) n)
haftmann@21819
   254
    then Syntax.const c $ Syntax.mark_bound v' $ n $ P else raise Match;
haftmann@21819
   255
haftmann@21819
   256
  fun tr' q = (q,
haftmann@21819
   257
    fn [Const ("_bound", _) $ Free (v, Type (T, _)), Const (c, _) $ (Const (d, _) $ (Const ("_bound", _) $ Free (v', _)) $ n) $ P] =>
haftmann@21819
   258
         if T = (set_type) then case AList.lookup (op =) trans (q, c, d)
haftmann@21819
   259
          of NONE => raise Match
haftmann@21819
   260
           | SOME l => mk v v' l n P
haftmann@21819
   261
         else raise Match
haftmann@21819
   262
     | _ => raise Match);
nipkow@14804
   263
in
haftmann@21819
   264
  [tr' All_binder, tr' Ex_binder]
nipkow@14804
   265
end
nipkow@14804
   266
*}
nipkow@14804
   267
haftmann@30531
   268
wenzelm@11979
   269
text {*
wenzelm@11979
   270
  \medskip Translate between @{text "{e | x1...xn. P}"} and @{text
wenzelm@11979
   271
  "{u. EX x1..xn. u = e & P}"}; @{text "{y. EX x1..xn. y = e & P}"} is
wenzelm@11979
   272
  only translated if @{text "[0..n] subset bvs(e)"}.
wenzelm@11979
   273
*}
wenzelm@11979
   274
wenzelm@11979
   275
parse_translation {*
wenzelm@11979
   276
  let
wenzelm@11979
   277
    val ex_tr = snd (mk_binder_tr ("EX ", "Ex"));
wenzelm@3947
   278
wenzelm@11979
   279
    fun nvars (Const ("_idts", _) $ _ $ idts) = nvars idts + 1
wenzelm@11979
   280
      | nvars _ = 1;
wenzelm@11979
   281
wenzelm@11979
   282
    fun setcompr_tr [e, idts, b] =
wenzelm@11979
   283
      let
wenzelm@11979
   284
        val eq = Syntax.const "op =" $ Bound (nvars idts) $ e;
wenzelm@11979
   285
        val P = Syntax.const "op &" $ eq $ b;
wenzelm@11979
   286
        val exP = ex_tr [idts, P];
wenzelm@17784
   287
      in Syntax.const "Collect" $ Term.absdummy (dummyT, exP) end;
wenzelm@11979
   288
wenzelm@11979
   289
  in [("@SetCompr", setcompr_tr)] end;
wenzelm@11979
   290
*}
clasohm@923
   291
haftmann@32120
   292
print_translation {* [
haftmann@32120
   293
Syntax.preserve_binder_abs2_tr' @{const_syntax Ball} "_Ball",
haftmann@32120
   294
Syntax.preserve_binder_abs2_tr' @{const_syntax Bex} "_Bex"
haftmann@32120
   295
] *} -- {* to avoid eta-contraction of body *}
haftmann@30531
   296
nipkow@13763
   297
print_translation {*
nipkow@13763
   298
let
nipkow@13763
   299
  val ex_tr' = snd (mk_binder_tr' ("Ex", "DUMMY"));
nipkow@13763
   300
nipkow@13763
   301
  fun setcompr_tr' [Abs (abs as (_, _, P))] =
nipkow@13763
   302
    let
nipkow@13763
   303
      fun check (Const ("Ex", _) $ Abs (_, _, P), n) = check (P, n + 1)
nipkow@13763
   304
        | check (Const ("op &", _) $ (Const ("op =", _) $ Bound m $ e) $ P, n) =
nipkow@13763
   305
            n > 0 andalso m = n andalso not (loose_bvar1 (P, n)) andalso
nipkow@13763
   306
            ((0 upto (n - 1)) subset add_loose_bnos (e, 0, []))
nipkow@13764
   307
        | check _ = false
clasohm@923
   308
wenzelm@11979
   309
        fun tr' (_ $ abs) =
wenzelm@11979
   310
          let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr' [abs]
wenzelm@11979
   311
          in Syntax.const "@SetCompr" $ e $ idts $ Q end;
nipkow@13763
   312
    in if check (P, 0) then tr' P
nipkow@15535
   313
       else let val (x as _ $ Free(xN,_), t) = atomic_abs_tr' abs
nipkow@15535
   314
                val M = Syntax.const "@Coll" $ x $ t
nipkow@15535
   315
            in case t of
nipkow@15535
   316
                 Const("op &",_)
nipkow@15535
   317
                   $ (Const("op :",_) $ (Const("_bound",_) $ Free(yN,_)) $ A)
nipkow@15535
   318
                   $ P =>
nipkow@15535
   319
                   if xN=yN then Syntax.const "@Collect" $ x $ A $ P else M
nipkow@15535
   320
               | _ => M
nipkow@15535
   321
            end
nipkow@13763
   322
    end;
wenzelm@11979
   323
  in [("Collect", setcompr_tr')] end;
wenzelm@11979
   324
*}
wenzelm@11979
   325
haftmann@32117
   326
setup {*
haftmann@32117
   327
let
haftmann@32117
   328
  val unfold_bex_tac = unfold_tac @{thms "Bex_def"};
haftmann@32117
   329
  fun prove_bex_tac ss = unfold_bex_tac ss THEN Quantifier1.prove_one_point_ex_tac;
haftmann@32117
   330
  val rearrange_bex = Quantifier1.rearrange_bex prove_bex_tac;
haftmann@32117
   331
  val unfold_ball_tac = unfold_tac @{thms "Ball_def"};
haftmann@32117
   332
  fun prove_ball_tac ss = unfold_ball_tac ss THEN Quantifier1.prove_one_point_all_tac;
haftmann@32117
   333
  val rearrange_ball = Quantifier1.rearrange_ball prove_ball_tac;
haftmann@32117
   334
  val defBEX_regroup = Simplifier.simproc @{theory}
haftmann@32117
   335
    "defined BEX" ["EX x:A. P x & Q x"] rearrange_bex;
haftmann@32117
   336
  val defBALL_regroup = Simplifier.simproc @{theory}
haftmann@32117
   337
    "defined BALL" ["ALL x:A. P x --> Q x"] rearrange_ball;
haftmann@32117
   338
in
haftmann@32117
   339
  Simplifier.map_simpset (fn ss => ss addsimprocs [defBALL_regroup, defBEX_regroup])
haftmann@32117
   340
end
haftmann@32117
   341
*}
haftmann@32117
   342
wenzelm@11979
   343
lemma ballI [intro!]: "(!!x. x:A ==> P x) ==> ALL x:A. P x"
wenzelm@11979
   344
  by (simp add: Ball_def)
wenzelm@11979
   345
wenzelm@11979
   346
lemmas strip = impI allI ballI
wenzelm@11979
   347
wenzelm@11979
   348
lemma bspec [dest?]: "ALL x:A. P x ==> x:A ==> P x"
wenzelm@11979
   349
  by (simp add: Ball_def)
wenzelm@11979
   350
wenzelm@11979
   351
text {*
wenzelm@11979
   352
  Gives better instantiation for bound:
wenzelm@11979
   353
*}
wenzelm@11979
   354
wenzelm@26339
   355
declaration {* fn _ =>
wenzelm@26339
   356
  Classical.map_cs (fn cs => cs addbefore ("bspec", datac @{thm bspec} 1))
wenzelm@11979
   357
*}
wenzelm@11979
   358
haftmann@32117
   359
ML {*
haftmann@32117
   360
structure Simpdata =
haftmann@32117
   361
struct
haftmann@32117
   362
haftmann@32117
   363
open Simpdata;
haftmann@32117
   364
haftmann@32117
   365
val mksimps_pairs = [(@{const_name Ball}, @{thms bspec})] @ mksimps_pairs;
haftmann@32117
   366
haftmann@32117
   367
end;
haftmann@32117
   368
haftmann@32117
   369
open Simpdata;
haftmann@32117
   370
*}
haftmann@32117
   371
haftmann@32117
   372
declaration {* fn _ =>
haftmann@32117
   373
  Simplifier.map_ss (fn ss => ss setmksimps (mksimps mksimps_pairs))
haftmann@32117
   374
*}
haftmann@32117
   375
haftmann@32117
   376
lemma ballE [elim]: "ALL x:A. P x ==> (P x ==> Q) ==> (x ~: A ==> Q) ==> Q"
haftmann@32117
   377
  by (unfold Ball_def) blast
haftmann@32117
   378
wenzelm@11979
   379
lemma bexI [intro]: "P x ==> x:A ==> EX x:A. P x"
wenzelm@11979
   380
  -- {* Normally the best argument order: @{prop "P x"} constrains the
wenzelm@11979
   381
    choice of @{prop "x:A"}. *}
wenzelm@11979
   382
  by (unfold Bex_def) blast
wenzelm@11979
   383
wenzelm@13113
   384
lemma rev_bexI [intro?]: "x:A ==> P x ==> EX x:A. P x"
wenzelm@11979
   385
  -- {* The best argument order when there is only one @{prop "x:A"}. *}
wenzelm@11979
   386
  by (unfold Bex_def) blast
wenzelm@11979
   387
wenzelm@11979
   388
lemma bexCI: "(ALL x:A. ~P x ==> P a) ==> a:A ==> EX x:A. P x"
wenzelm@11979
   389
  by (unfold Bex_def) blast
wenzelm@11979
   390
wenzelm@11979
   391
lemma bexE [elim!]: "EX x:A. P x ==> (!!x. x:A ==> P x ==> Q) ==> Q"
wenzelm@11979
   392
  by (unfold Bex_def) blast
wenzelm@11979
   393
wenzelm@11979
   394
lemma ball_triv [simp]: "(ALL x:A. P) = ((EX x. x:A) --> P)"
wenzelm@11979
   395
  -- {* Trival rewrite rule. *}
wenzelm@11979
   396
  by (simp add: Ball_def)
wenzelm@11979
   397
wenzelm@11979
   398
lemma bex_triv [simp]: "(EX x:A. P) = ((EX x. x:A) & P)"
wenzelm@11979
   399
  -- {* Dual form for existentials. *}
wenzelm@11979
   400
  by (simp add: Bex_def)
wenzelm@11979
   401
wenzelm@11979
   402
lemma bex_triv_one_point1 [simp]: "(EX x:A. x = a) = (a:A)"
wenzelm@11979
   403
  by blast
wenzelm@11979
   404
wenzelm@11979
   405
lemma bex_triv_one_point2 [simp]: "(EX x:A. a = x) = (a:A)"
wenzelm@11979
   406
  by blast
wenzelm@11979
   407
wenzelm@11979
   408
lemma bex_one_point1 [simp]: "(EX x:A. x = a & P x) = (a:A & P a)"
wenzelm@11979
   409
  by blast
wenzelm@11979
   410
wenzelm@11979
   411
lemma bex_one_point2 [simp]: "(EX x:A. a = x & P x) = (a:A & P a)"
wenzelm@11979
   412
  by blast
wenzelm@11979
   413
wenzelm@11979
   414
lemma ball_one_point1 [simp]: "(ALL x:A. x = a --> P x) = (a:A --> P a)"
wenzelm@11979
   415
  by blast
wenzelm@11979
   416
wenzelm@11979
   417
lemma ball_one_point2 [simp]: "(ALL x:A. a = x --> P x) = (a:A --> P a)"
wenzelm@11979
   418
  by blast
wenzelm@11979
   419
wenzelm@11979
   420
haftmann@32081
   421
text {* Congruence rules *}
wenzelm@11979
   422
berghofe@16636
   423
lemma ball_cong:
wenzelm@11979
   424
  "A = B ==> (!!x. x:B ==> P x = Q x) ==>
wenzelm@11979
   425
    (ALL x:A. P x) = (ALL x:B. Q x)"
wenzelm@11979
   426
  by (simp add: Ball_def)
wenzelm@11979
   427
berghofe@16636
   428
lemma strong_ball_cong [cong]:
berghofe@16636
   429
  "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>
berghofe@16636
   430
    (ALL x:A. P x) = (ALL x:B. Q x)"
berghofe@16636
   431
  by (simp add: simp_implies_def Ball_def)
berghofe@16636
   432
berghofe@16636
   433
lemma bex_cong:
wenzelm@11979
   434
  "A = B ==> (!!x. x:B ==> P x = Q x) ==>
wenzelm@11979
   435
    (EX x:A. P x) = (EX x:B. Q x)"
wenzelm@11979
   436
  by (simp add: Bex_def cong: conj_cong)
regensbu@1273
   437
berghofe@16636
   438
lemma strong_bex_cong [cong]:
berghofe@16636
   439
  "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>
berghofe@16636
   440
    (EX x:A. P x) = (EX x:B. Q x)"
berghofe@16636
   441
  by (simp add: simp_implies_def Bex_def cong: conj_cong)
berghofe@16636
   442
haftmann@30531
   443
haftmann@32081
   444
subsection {* Basic operations *}
haftmann@32081
   445
haftmann@30531
   446
subsubsection {* Subsets *}
haftmann@30531
   447
haftmann@30531
   448
lemma subsetI [atp,intro!]: "(!!x. x:A ==> x:B) ==> A \<subseteq> B"
haftmann@30531
   449
  by (auto simp add: mem_def intro: predicate1I)
haftmann@30352
   450
wenzelm@11979
   451
text {*
haftmann@30531
   452
  \medskip Map the type @{text "'a set => anything"} to just @{typ
haftmann@30531
   453
  'a}; for overloading constants whose first argument has type @{typ
haftmann@30531
   454
  "'a set"}.
wenzelm@11979
   455
*}
wenzelm@11979
   456
haftmann@30596
   457
lemma subsetD [elim, intro?]: "A \<subseteq> B ==> c \<in> A ==> c \<in> B"
haftmann@30531
   458
  -- {* Rule in Modus Ponens style. *}
haftmann@30531
   459
  by (unfold mem_def) blast
haftmann@30531
   460
haftmann@30596
   461
lemma rev_subsetD [intro?]: "c \<in> A ==> A \<subseteq> B ==> c \<in> B"
haftmann@30531
   462
  -- {* The same, with reversed premises for use with @{text erule} --
haftmann@30531
   463
      cf @{text rev_mp}. *}
haftmann@30531
   464
  by (rule subsetD)
haftmann@30531
   465
wenzelm@11979
   466
text {*
haftmann@30531
   467
  \medskip Converts @{prop "A \<subseteq> B"} to @{prop "x \<in> A ==> x \<in> B"}.
haftmann@30531
   468
*}
haftmann@30531
   469
haftmann@30531
   470
lemma subsetCE [elim]: "A \<subseteq>  B ==> (c \<notin> A ==> P) ==> (c \<in> B ==> P) ==> P"
haftmann@30531
   471
  -- {* Classical elimination rule. *}
haftmann@30531
   472
  by (unfold mem_def) blast
haftmann@30531
   473
haftmann@30531
   474
lemma subset_eq: "A \<le> B = (\<forall>x\<in>A. x \<in> B)" by blast
wenzelm@2388
   475
haftmann@30531
   476
lemma contra_subsetD: "A \<subseteq> B ==> c \<notin> B ==> c \<notin> A"
haftmann@30531
   477
  by blast
haftmann@30531
   478
haftmann@30531
   479
lemma subset_refl [simp,atp]: "A \<subseteq> A"
haftmann@32081
   480
  by (fact order_refl)
haftmann@30531
   481
haftmann@30531
   482
lemma subset_trans: "A \<subseteq> B ==> B \<subseteq> C ==> A \<subseteq> C"
haftmann@32081
   483
  by (fact order_trans)
haftmann@32081
   484
haftmann@32081
   485
lemma set_rev_mp: "x:A ==> A \<subseteq> B ==> x:B"
haftmann@32081
   486
  by (rule subsetD)
haftmann@32081
   487
haftmann@32081
   488
lemma set_mp: "A \<subseteq> B ==> x:A ==> x:B"
haftmann@32081
   489
  by (rule subsetD)
haftmann@32081
   490
haftmann@32081
   491
lemmas basic_trans_rules [trans] =
haftmann@32081
   492
  order_trans_rules set_rev_mp set_mp
haftmann@30531
   493
haftmann@30531
   494
haftmann@30531
   495
subsubsection {* Equality *}
haftmann@30531
   496
haftmann@30531
   497
lemma set_ext: assumes prem: "(!!x. (x:A) = (x:B))" shows "A = B"
haftmann@30531
   498
  apply (rule prem [THEN ext, THEN arg_cong, THEN box_equals])
haftmann@30531
   499
   apply (rule Collect_mem_eq)
haftmann@30531
   500
  apply (rule Collect_mem_eq)
haftmann@30531
   501
  done
haftmann@30531
   502
haftmann@30531
   503
(* Due to Brian Huffman *)
haftmann@30531
   504
lemma expand_set_eq: "(A = B) = (ALL x. (x:A) = (x:B))"
haftmann@30531
   505
by(auto intro:set_ext)
haftmann@30531
   506
haftmann@30531
   507
lemma subset_antisym [intro!]: "A \<subseteq> B ==> B \<subseteq> A ==> A = B"
haftmann@30531
   508
  -- {* Anti-symmetry of the subset relation. *}
haftmann@30531
   509
  by (iprover intro: set_ext subsetD)
haftmann@30531
   510
haftmann@30531
   511
text {*
haftmann@30531
   512
  \medskip Equality rules from ZF set theory -- are they appropriate
haftmann@30531
   513
  here?
haftmann@30531
   514
*}
haftmann@30531
   515
haftmann@30531
   516
lemma equalityD1: "A = B ==> A \<subseteq> B"
haftmann@30531
   517
  by (simp add: subset_refl)
haftmann@30531
   518
haftmann@30531
   519
lemma equalityD2: "A = B ==> B \<subseteq> A"
haftmann@30531
   520
  by (simp add: subset_refl)
haftmann@30531
   521
haftmann@30531
   522
text {*
haftmann@30531
   523
  \medskip Be careful when adding this to the claset as @{text
haftmann@30531
   524
  subset_empty} is in the simpset: @{prop "A = {}"} goes to @{prop "{}
haftmann@30531
   525
  \<subseteq> A"} and @{prop "A \<subseteq> {}"} and then back to @{prop "A = {}"}!
haftmann@30352
   526
*}
haftmann@30352
   527
haftmann@30531
   528
lemma equalityE: "A = B ==> (A \<subseteq> B ==> B \<subseteq> A ==> P) ==> P"
haftmann@30531
   529
  by (simp add: subset_refl)
haftmann@30531
   530
haftmann@30531
   531
lemma equalityCE [elim]:
haftmann@30531
   532
    "A = B ==> (c \<in> A ==> c \<in> B ==> P) ==> (c \<notin> A ==> c \<notin> B ==> P) ==> P"
haftmann@30531
   533
  by blast
haftmann@30531
   534
haftmann@30531
   535
lemma eqset_imp_iff: "A = B ==> (x : A) = (x : B)"
haftmann@30531
   536
  by simp
haftmann@30531
   537
haftmann@30531
   538
lemma eqelem_imp_iff: "x = y ==> (x : A) = (y : A)"
haftmann@30531
   539
  by simp
haftmann@30531
   540
haftmann@30531
   541
haftmann@30531
   542
subsubsection {* The universal set -- UNIV *}
haftmann@30531
   543
haftmann@32264
   544
abbreviation UNIV :: "'a set" where
haftmann@32264
   545
  "UNIV \<equiv> top"
haftmann@32135
   546
haftmann@32135
   547
lemma UNIV_def:
haftmann@32117
   548
  "UNIV = {x. True}"
haftmann@32264
   549
  by (simp add: top_fun_eq top_bool_eq Collect_def)
haftmann@32081
   550
haftmann@30531
   551
lemma UNIV_I [simp]: "x : UNIV"
haftmann@30531
   552
  by (simp add: UNIV_def)
haftmann@30531
   553
haftmann@30531
   554
declare UNIV_I [intro]  -- {* unsafe makes it less likely to cause problems *}
haftmann@30531
   555
haftmann@30531
   556
lemma UNIV_witness [intro?]: "EX x. x : UNIV"
haftmann@30531
   557
  by simp
haftmann@30531
   558
haftmann@30531
   559
lemma subset_UNIV [simp]: "A \<subseteq> UNIV"
haftmann@30531
   560
  by (rule subsetI) (rule UNIV_I)
haftmann@30531
   561
haftmann@30531
   562
text {*
haftmann@30531
   563
  \medskip Eta-contracting these two rules (to remove @{text P})
haftmann@30531
   564
  causes them to be ignored because of their interaction with
haftmann@30531
   565
  congruence rules.
haftmann@30531
   566
*}
haftmann@30531
   567
haftmann@30531
   568
lemma ball_UNIV [simp]: "Ball UNIV P = All P"
haftmann@30531
   569
  by (simp add: Ball_def)
haftmann@30531
   570
haftmann@30531
   571
lemma bex_UNIV [simp]: "Bex UNIV P = Ex P"
haftmann@30531
   572
  by (simp add: Bex_def)
haftmann@30531
   573
haftmann@30531
   574
lemma UNIV_eq_I: "(\<And>x. x \<in> A) \<Longrightarrow> UNIV = A"
haftmann@30531
   575
  by auto
haftmann@30531
   576
haftmann@30531
   577
haftmann@30531
   578
subsubsection {* The empty set *}
haftmann@30531
   579
haftmann@32135
   580
lemma empty_def:
haftmann@32135
   581
  "{} = {x. False}"
haftmann@32264
   582
  by (simp add: bot_fun_eq bot_bool_eq Collect_def)
haftmann@32135
   583
haftmann@30531
   584
lemma empty_iff [simp]: "(c : {}) = False"
haftmann@30531
   585
  by (simp add: empty_def)
haftmann@30531
   586
haftmann@30531
   587
lemma emptyE [elim!]: "a : {} ==> P"
haftmann@30531
   588
  by simp
haftmann@30531
   589
haftmann@30531
   590
lemma empty_subsetI [iff]: "{} \<subseteq> A"
haftmann@30531
   591
    -- {* One effect is to delete the ASSUMPTION @{prop "{} <= A"} *}
haftmann@30531
   592
  by blast
haftmann@30531
   593
haftmann@30531
   594
lemma equals0I: "(!!y. y \<in> A ==> False) ==> A = {}"
haftmann@30531
   595
  by blast
haftmann@30531
   596
haftmann@30531
   597
lemma equals0D: "A = {} ==> a \<notin> A"
haftmann@32082
   598
    -- {* Use for reasoning about disjointness: @{text "A Int B = {}"} *}
haftmann@30531
   599
  by blast
haftmann@30531
   600
haftmann@30531
   601
lemma ball_empty [simp]: "Ball {} P = True"
haftmann@30531
   602
  by (simp add: Ball_def)
haftmann@30531
   603
haftmann@30531
   604
lemma bex_empty [simp]: "Bex {} P = False"
haftmann@30531
   605
  by (simp add: Bex_def)
haftmann@30531
   606
haftmann@30531
   607
lemma UNIV_not_empty [iff]: "UNIV ~= {}"
haftmann@30531
   608
  by (blast elim: equalityE)
haftmann@30531
   609
haftmann@30531
   610
haftmann@30531
   611
subsubsection {* The Powerset operator -- Pow *}
haftmann@30531
   612
haftmann@32077
   613
definition Pow :: "'a set => 'a set set" where
haftmann@32077
   614
  Pow_def: "Pow A = {B. B \<le> A}"
haftmann@32077
   615
haftmann@30531
   616
lemma Pow_iff [iff]: "(A \<in> Pow B) = (A \<subseteq> B)"
haftmann@30531
   617
  by (simp add: Pow_def)
haftmann@30531
   618
haftmann@30531
   619
lemma PowI: "A \<subseteq> B ==> A \<in> Pow B"
haftmann@30531
   620
  by (simp add: Pow_def)
haftmann@30531
   621
haftmann@30531
   622
lemma PowD: "A \<in> Pow B ==> A \<subseteq> B"
haftmann@30531
   623
  by (simp add: Pow_def)
haftmann@30531
   624
haftmann@30531
   625
lemma Pow_bottom: "{} \<in> Pow B"
haftmann@30531
   626
  by simp
haftmann@30531
   627
haftmann@30531
   628
lemma Pow_top: "A \<in> Pow A"
haftmann@30531
   629
  by (simp add: subset_refl)
haftmann@30531
   630
haftmann@30531
   631
haftmann@30531
   632
subsubsection {* Set complement *}
haftmann@30531
   633
haftmann@30531
   634
lemma Compl_iff [simp]: "(c \<in> -A) = (c \<notin> A)"
haftmann@30531
   635
  by (simp add: mem_def fun_Compl_def bool_Compl_def)
haftmann@30531
   636
haftmann@30531
   637
lemma ComplI [intro!]: "(c \<in> A ==> False) ==> c \<in> -A"
haftmann@30531
   638
  by (unfold mem_def fun_Compl_def bool_Compl_def) blast
clasohm@923
   639
wenzelm@11979
   640
text {*
haftmann@30531
   641
  \medskip This form, with negated conclusion, works well with the
haftmann@30531
   642
  Classical prover.  Negated assumptions behave like formulae on the
haftmann@30531
   643
  right side of the notional turnstile ... *}
haftmann@30531
   644
haftmann@30531
   645
lemma ComplD [dest!]: "c : -A ==> c~:A"
haftmann@30531
   646
  by (simp add: mem_def fun_Compl_def bool_Compl_def)
haftmann@30531
   647
haftmann@30531
   648
lemmas ComplE = ComplD [elim_format]
haftmann@30531
   649
haftmann@30531
   650
lemma Compl_eq: "- A = {x. ~ x : A}" by blast
haftmann@30531
   651
haftmann@30531
   652
haftmann@30531
   653
subsubsection {* Binary union -- Un *}
haftmann@30531
   654
haftmann@32135
   655
definition union :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Un" 65) where
haftmann@32135
   656
  sup_set_eq [symmetric]: "A Un B = sup A B"
haftmann@32081
   657
haftmann@32081
   658
notation (xsymbols)
haftmann@32135
   659
  union  (infixl "\<union>" 65)
haftmann@32081
   660
haftmann@32081
   661
notation (HTML output)
haftmann@32135
   662
  union  (infixl "\<union>" 65)
haftmann@32135
   663
haftmann@32135
   664
lemma Un_def:
haftmann@32135
   665
  "A \<union> B = {x. x \<in> A \<or> x \<in> B}"
haftmann@32135
   666
  by (simp add: sup_fun_eq sup_bool_eq sup_set_eq [symmetric] Collect_def mem_def)
haftmann@32081
   667
haftmann@30531
   668
lemma Un_iff [simp]: "(c : A Un B) = (c:A | c:B)"
haftmann@30531
   669
  by (unfold Un_def) blast
haftmann@30531
   670
haftmann@30531
   671
lemma UnI1 [elim?]: "c:A ==> c : A Un B"
haftmann@30531
   672
  by simp
haftmann@30531
   673
haftmann@30531
   674
lemma UnI2 [elim?]: "c:B ==> c : A Un B"
haftmann@30531
   675
  by simp
haftmann@30531
   676
haftmann@30531
   677
text {*
haftmann@30531
   678
  \medskip Classical introduction rule: no commitment to @{prop A} vs
haftmann@30531
   679
  @{prop B}.
wenzelm@11979
   680
*}
wenzelm@11979
   681
haftmann@30531
   682
lemma UnCI [intro!]: "(c~:B ==> c:A) ==> c : A Un B"
haftmann@30531
   683
  by auto
haftmann@30531
   684
haftmann@30531
   685
lemma UnE [elim!]: "c : A Un B ==> (c:A ==> P) ==> (c:B ==> P) ==> P"
haftmann@30531
   686
  by (unfold Un_def) blast
haftmann@30531
   687
haftmann@32117
   688
lemma insert_def: "insert a B = {x. x = a} \<union> B"
haftmann@32081
   689
  by (simp add: Collect_def mem_def insert_compr Un_def)
haftmann@32081
   690
haftmann@32081
   691
lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"
haftmann@32081
   692
  apply (fold sup_set_eq)
haftmann@32081
   693
  apply (erule mono_sup)
haftmann@32081
   694
  done
haftmann@32081
   695
haftmann@30531
   696
haftmann@30531
   697
subsubsection {* Binary intersection -- Int *}
haftmann@30531
   698
haftmann@32135
   699
definition inter :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Int" 70) where
haftmann@32135
   700
  inf_set_eq [symmetric]: "A Int B = inf A B"
haftmann@32081
   701
haftmann@32081
   702
notation (xsymbols)
haftmann@32135
   703
  inter  (infixl "\<inter>" 70)
haftmann@32081
   704
haftmann@32081
   705
notation (HTML output)
haftmann@32135
   706
  inter  (infixl "\<inter>" 70)
haftmann@32135
   707
haftmann@32135
   708
lemma Int_def:
haftmann@32135
   709
  "A \<inter> B = {x. x \<in> A \<and> x \<in> B}"
haftmann@32135
   710
  by (simp add: inf_fun_eq inf_bool_eq inf_set_eq [symmetric] Collect_def mem_def)
haftmann@32081
   711
haftmann@30531
   712
lemma Int_iff [simp]: "(c : A Int B) = (c:A & c:B)"
haftmann@30531
   713
  by (unfold Int_def) blast
haftmann@30531
   714
haftmann@30531
   715
lemma IntI [intro!]: "c:A ==> c:B ==> c : A Int B"
haftmann@30531
   716
  by simp
haftmann@30531
   717
haftmann@30531
   718
lemma IntD1: "c : A Int B ==> c:A"
haftmann@30531
   719
  by simp
haftmann@30531
   720
haftmann@30531
   721
lemma IntD2: "c : A Int B ==> c:B"
haftmann@30531
   722
  by simp
haftmann@30531
   723
haftmann@30531
   724
lemma IntE [elim!]: "c : A Int B ==> (c:A ==> c:B ==> P) ==> P"
haftmann@30531
   725
  by simp
haftmann@30531
   726
haftmann@32081
   727
lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"
haftmann@32081
   728
  apply (fold inf_set_eq)
haftmann@32081
   729
  apply (erule mono_inf)
haftmann@32081
   730
  done
haftmann@32081
   731
haftmann@30531
   732
haftmann@30531
   733
subsubsection {* Set difference *}
haftmann@30531
   734
haftmann@30531
   735
lemma Diff_iff [simp]: "(c : A - B) = (c:A & c~:B)"
haftmann@30531
   736
  by (simp add: mem_def fun_diff_def bool_diff_def)
haftmann@30531
   737
haftmann@30531
   738
lemma DiffI [intro!]: "c : A ==> c ~: B ==> c : A - B"
haftmann@30531
   739
  by simp
haftmann@30531
   740
haftmann@30531
   741
lemma DiffD1: "c : A - B ==> c : A"
haftmann@30531
   742
  by simp
haftmann@30531
   743
haftmann@30531
   744
lemma DiffD2: "c : A - B ==> c : B ==> P"
haftmann@30531
   745
  by simp
haftmann@30531
   746
haftmann@30531
   747
lemma DiffE [elim!]: "c : A - B ==> (c:A ==> c~:B ==> P) ==> P"
haftmann@30531
   748
  by simp
haftmann@30531
   749
haftmann@30531
   750
lemma set_diff_eq: "A - B = {x. x : A & ~ x : B}" by blast
haftmann@30531
   751
haftmann@30531
   752
lemma Compl_eq_Diff_UNIV: "-A = (UNIV - A)"
haftmann@30531
   753
by blast
haftmann@30531
   754
haftmann@30531
   755
haftmann@31456
   756
subsubsection {* Augmenting a set -- @{const insert} *}
haftmann@30531
   757
haftmann@30531
   758
lemma insert_iff [simp]: "(a : insert b A) = (a = b | a:A)"
haftmann@30531
   759
  by (unfold insert_def) blast
haftmann@30531
   760
haftmann@30531
   761
lemma insertI1: "a : insert a B"
haftmann@30531
   762
  by simp
haftmann@30531
   763
haftmann@30531
   764
lemma insertI2: "a : B ==> a : insert b B"
haftmann@30531
   765
  by simp
haftmann@30531
   766
haftmann@30531
   767
lemma insertE [elim!]: "a : insert b A ==> (a = b ==> P) ==> (a:A ==> P) ==> P"
haftmann@30531
   768
  by (unfold insert_def) blast
haftmann@30531
   769
haftmann@30531
   770
lemma insertCI [intro!]: "(a~:B ==> a = b) ==> a: insert b B"
haftmann@30531
   771
  -- {* Classical introduction rule. *}
haftmann@30531
   772
  by auto
haftmann@30531
   773
haftmann@30531
   774
lemma subset_insert_iff: "(A \<subseteq> insert x B) = (if x:A then A - {x} \<subseteq> B else A \<subseteq> B)"
haftmann@30531
   775
  by auto
haftmann@30531
   776
haftmann@30531
   777
lemma set_insert:
haftmann@30531
   778
  assumes "x \<in> A"
haftmann@30531
   779
  obtains B where "A = insert x B" and "x \<notin> B"
haftmann@30531
   780
proof
haftmann@30531
   781
  from assms show "A = insert x (A - {x})" by blast
haftmann@30531
   782
next
haftmann@30531
   783
  show "x \<notin> A - {x}" by blast
haftmann@30531
   784
qed
haftmann@30531
   785
haftmann@30531
   786
lemma insert_ident: "x ~: A ==> x ~: B ==> (insert x A = insert x B) = (A = B)"
haftmann@30531
   787
by auto
haftmann@30531
   788
haftmann@30531
   789
subsubsection {* Singletons, using insert *}
haftmann@30531
   790
haftmann@30531
   791
lemma singletonI [intro!,noatp]: "a : {a}"
haftmann@30531
   792
    -- {* Redundant? But unlike @{text insertCI}, it proves the subgoal immediately! *}
haftmann@30531
   793
  by (rule insertI1)
haftmann@30531
   794
haftmann@30531
   795
lemma singletonD [dest!,noatp]: "b : {a} ==> b = a"
haftmann@30531
   796
  by blast
haftmann@30531
   797
haftmann@30531
   798
lemmas singletonE = singletonD [elim_format]
haftmann@30531
   799
haftmann@30531
   800
lemma singleton_iff: "(b : {a}) = (b = a)"
haftmann@30531
   801
  by blast
haftmann@30531
   802
haftmann@30531
   803
lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"
haftmann@30531
   804
  by blast
haftmann@30531
   805
haftmann@30531
   806
lemma singleton_insert_inj_eq [iff,noatp]:
haftmann@30531
   807
     "({b} = insert a A) = (a = b & A \<subseteq> {b})"
haftmann@30531
   808
  by blast
haftmann@30531
   809
haftmann@30531
   810
lemma singleton_insert_inj_eq' [iff,noatp]:
haftmann@30531
   811
     "(insert a A = {b}) = (a = b & A \<subseteq> {b})"
haftmann@30531
   812
  by blast
haftmann@30531
   813
haftmann@30531
   814
lemma subset_singletonD: "A \<subseteq> {x} ==> A = {} | A = {x}"
haftmann@30531
   815
  by fast
haftmann@30531
   816
haftmann@30531
   817
lemma singleton_conv [simp]: "{x. x = a} = {a}"
haftmann@30531
   818
  by blast
haftmann@30531
   819
haftmann@30531
   820
lemma singleton_conv2 [simp]: "{x. a = x} = {a}"
haftmann@30531
   821
  by blast
haftmann@30531
   822
haftmann@30531
   823
lemma diff_single_insert: "A - {x} \<subseteq> B ==> x \<in> A ==> A \<subseteq> insert x B"
haftmann@30531
   824
  by blast
haftmann@30531
   825
haftmann@30531
   826
lemma doubleton_eq_iff: "({a,b} = {c,d}) = (a=c & b=d | a=d & b=c)"
haftmann@30531
   827
  by (blast elim: equalityE)
haftmann@30531
   828
wenzelm@11979
   829
haftmann@32077
   830
subsubsection {* Image of a set under a function *}
haftmann@32077
   831
haftmann@32077
   832
text {*
haftmann@32077
   833
  Frequently @{term b} does not have the syntactic form of @{term "f x"}.
haftmann@32077
   834
*}
haftmann@32077
   835
haftmann@32077
   836
definition image :: "('a => 'b) => 'a set => 'b set" (infixr "`" 90) where
haftmann@32077
   837
  image_def [noatp]: "f ` A = {y. EX x:A. y = f(x)}"
haftmann@32077
   838
haftmann@32077
   839
abbreviation
haftmann@32077
   840
  range :: "('a => 'b) => 'b set" where -- "of function"
haftmann@32077
   841
  "range f == f ` UNIV"
haftmann@32077
   842
haftmann@32077
   843
lemma image_eqI [simp, intro]: "b = f x ==> x:A ==> b : f`A"
haftmann@32077
   844
  by (unfold image_def) blast
haftmann@32077
   845
haftmann@32077
   846
lemma imageI: "x : A ==> f x : f ` A"
haftmann@32077
   847
  by (rule image_eqI) (rule refl)
haftmann@32077
   848
haftmann@32077
   849
lemma rev_image_eqI: "x:A ==> b = f x ==> b : f`A"
haftmann@32077
   850
  -- {* This version's more effective when we already have the
haftmann@32077
   851
    required @{term x}. *}
haftmann@32077
   852
  by (unfold image_def) blast
haftmann@32077
   853
haftmann@32077
   854
lemma imageE [elim!]:
haftmann@32077
   855
  "b : (%x. f x)`A ==> (!!x. b = f x ==> x:A ==> P) ==> P"
haftmann@32077
   856
  -- {* The eta-expansion gives variable-name preservation. *}
haftmann@32077
   857
  by (unfold image_def) blast
haftmann@32077
   858
haftmann@32077
   859
lemma image_Un: "f`(A Un B) = f`A Un f`B"
haftmann@32077
   860
  by blast
haftmann@32077
   861
haftmann@32077
   862
lemma image_iff: "(z : f`A) = (EX x:A. z = f x)"
haftmann@32077
   863
  by blast
haftmann@32077
   864
haftmann@32077
   865
lemma image_subset_iff: "(f`A \<subseteq> B) = (\<forall>x\<in>A. f x \<in> B)"
haftmann@32077
   866
  -- {* This rewrite rule would confuse users if made default. *}
haftmann@32077
   867
  by blast
haftmann@32077
   868
haftmann@32077
   869
lemma subset_image_iff: "(B \<subseteq> f`A) = (EX AA. AA \<subseteq> A & B = f`AA)"
haftmann@32077
   870
  apply safe
haftmann@32077
   871
   prefer 2 apply fast
haftmann@32077
   872
  apply (rule_tac x = "{a. a : A & f a : B}" in exI, fast)
haftmann@32077
   873
  done
haftmann@32077
   874
haftmann@32077
   875
lemma image_subsetI: "(!!x. x \<in> A ==> f x \<in> B) ==> f`A \<subseteq> B"
haftmann@32077
   876
  -- {* Replaces the three steps @{text subsetI}, @{text imageE},
haftmann@32077
   877
    @{text hypsubst}, but breaks too many existing proofs. *}
haftmann@32077
   878
  by blast
wenzelm@11979
   879
wenzelm@11979
   880
text {*
haftmann@32077
   881
  \medskip Range of a function -- just a translation for image!
haftmann@32077
   882
*}
haftmann@32077
   883
haftmann@32077
   884
lemma range_eqI: "b = f x ==> b \<in> range f"
haftmann@32077
   885
  by simp
haftmann@32077
   886
haftmann@32077
   887
lemma rangeI: "f x \<in> range f"
haftmann@32077
   888
  by simp
haftmann@32077
   889
haftmann@32077
   890
lemma rangeE [elim?]: "b \<in> range (\<lambda>x. f x) ==> (!!x. b = f x ==> P) ==> P"
haftmann@32077
   891
  by blast
haftmann@32077
   892
haftmann@32077
   893
haftmann@32117
   894
subsubsection {* Some rules with @{text "if"} *}
haftmann@32081
   895
haftmann@32081
   896
text{* Elimination of @{text"{x. \<dots> & x=t & \<dots>}"}. *}
haftmann@32081
   897
haftmann@32081
   898
lemma Collect_conv_if: "{x. x=a & P x} = (if P a then {a} else {})"
haftmann@32117
   899
  by auto
haftmann@32081
   900
haftmann@32081
   901
lemma Collect_conv_if2: "{x. a=x & P x} = (if P a then {a} else {})"
haftmann@32117
   902
  by auto
haftmann@32081
   903
haftmann@32081
   904
text {*
haftmann@32081
   905
  Rewrite rules for boolean case-splitting: faster than @{text
haftmann@32081
   906
  "split_if [split]"}.
haftmann@32081
   907
*}
haftmann@32081
   908
haftmann@32081
   909
lemma split_if_eq1: "((if Q then x else y) = b) = ((Q --> x = b) & (~ Q --> y = b))"
haftmann@32081
   910
  by (rule split_if)
haftmann@32081
   911
haftmann@32081
   912
lemma split_if_eq2: "(a = (if Q then x else y)) = ((Q --> a = x) & (~ Q --> a = y))"
haftmann@32081
   913
  by (rule split_if)
haftmann@32081
   914
haftmann@32081
   915
text {*
haftmann@32081
   916
  Split ifs on either side of the membership relation.  Not for @{text
haftmann@32081
   917
  "[simp]"} -- can cause goals to blow up!
haftmann@32081
   918
*}
haftmann@32081
   919
haftmann@32081
   920
lemma split_if_mem1: "((if Q then x else y) : b) = ((Q --> x : b) & (~ Q --> y : b))"
haftmann@32081
   921
  by (rule split_if)
haftmann@32081
   922
haftmann@32081
   923
lemma split_if_mem2: "(a : (if Q then x else y)) = ((Q --> a : x) & (~ Q --> a : y))"
haftmann@32081
   924
  by (rule split_if [where P="%S. a : S"])
haftmann@32081
   925
haftmann@32081
   926
lemmas split_ifs = if_bool_eq_conj split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2
haftmann@32081
   927
haftmann@32081
   928
(*Would like to add these, but the existing code only searches for the
haftmann@32081
   929
  outer-level constant, which in this case is just "op :"; we instead need
haftmann@32081
   930
  to use term-nets to associate patterns with rules.  Also, if a rule fails to
haftmann@32081
   931
  apply, then the formula should be kept.
haftmann@32081
   932
  [("HOL.uminus", Compl_iff RS iffD1), ("HOL.minus", [Diff_iff RS iffD1]),
haftmann@32081
   933
   ("Int", [IntD1,IntD2]),
haftmann@32081
   934
   ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]
haftmann@32081
   935
 *)
haftmann@32081
   936
haftmann@32081
   937
haftmann@32135
   938
subsection {* Further operations and lemmas *}
haftmann@32135
   939
haftmann@32135
   940
subsubsection {* The ``proper subset'' relation *}
haftmann@32135
   941
haftmann@32135
   942
lemma psubsetI [intro!,noatp]: "A \<subseteq> B ==> A \<noteq> B ==> A \<subset> B"
haftmann@32135
   943
  by (unfold less_le) blast
haftmann@32135
   944
haftmann@32135
   945
lemma psubsetE [elim!,noatp]: 
haftmann@32135
   946
    "[|A \<subset> B;  [|A \<subseteq> B; ~ (B\<subseteq>A)|] ==> R|] ==> R"
haftmann@32135
   947
  by (unfold less_le) blast
haftmann@32135
   948
haftmann@32135
   949
lemma psubset_insert_iff:
haftmann@32135
   950
  "(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
   951
  by (auto simp add: less_le subset_insert_iff)
haftmann@32135
   952
haftmann@32135
   953
lemma psubset_eq: "(A \<subset> B) = (A \<subseteq> B & A \<noteq> B)"
haftmann@32135
   954
  by (simp only: less_le)
haftmann@32135
   955
haftmann@32135
   956
lemma psubset_imp_subset: "A \<subset> B ==> A \<subseteq> B"
haftmann@32135
   957
  by (simp add: psubset_eq)
haftmann@32135
   958
haftmann@32135
   959
lemma psubset_trans: "[| A \<subset> B; B \<subset> C |] ==> A \<subset> C"
haftmann@32135
   960
apply (unfold less_le)
haftmann@32135
   961
apply (auto dest: subset_antisym)
haftmann@32135
   962
done
haftmann@32135
   963
haftmann@32135
   964
lemma psubsetD: "[| A \<subset> B; c \<in> A |] ==> c \<in> B"
haftmann@32135
   965
apply (unfold less_le)
haftmann@32135
   966
apply (auto dest: subsetD)
haftmann@32135
   967
done
haftmann@32135
   968
haftmann@32135
   969
lemma psubset_subset_trans: "A \<subset> B ==> B \<subseteq> C ==> A \<subset> C"
haftmann@32135
   970
  by (auto simp add: psubset_eq)
haftmann@32135
   971
haftmann@32135
   972
lemma subset_psubset_trans: "A \<subseteq> B ==> B \<subset> C ==> A \<subset> C"
haftmann@32135
   973
  by (auto simp add: psubset_eq)
haftmann@32135
   974
haftmann@32135
   975
lemma psubset_imp_ex_mem: "A \<subset> B ==> \<exists>b. b \<in> (B - A)"
haftmann@32135
   976
  by (unfold less_le) blast
haftmann@32135
   977
haftmann@32135
   978
lemma atomize_ball:
haftmann@32135
   979
    "(!!x. x \<in> A ==> P x) == Trueprop (\<forall>x\<in>A. P x)"
haftmann@32135
   980
  by (simp only: Ball_def atomize_all atomize_imp)
haftmann@32135
   981
haftmann@32135
   982
lemmas [symmetric, rulify] = atomize_ball
haftmann@32135
   983
  and [symmetric, defn] = atomize_ball
haftmann@32135
   984
haftmann@32135
   985
subsubsection {* Derived rules involving subsets. *}
haftmann@32135
   986
haftmann@32135
   987
text {* @{text insert}. *}
haftmann@32135
   988
haftmann@32135
   989
lemma subset_insertI: "B \<subseteq> insert a B"
haftmann@32135
   990
  by (rule subsetI) (erule insertI2)
haftmann@32135
   991
haftmann@32135
   992
lemma subset_insertI2: "A \<subseteq> B \<Longrightarrow> A \<subseteq> insert b B"
haftmann@32135
   993
  by blast
haftmann@32135
   994
haftmann@32135
   995
lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"
haftmann@32135
   996
  by blast
haftmann@32135
   997
haftmann@32135
   998
haftmann@32135
   999
text {* \medskip Finite Union -- the least upper bound of two sets. *}
haftmann@32135
  1000
haftmann@32135
  1001
lemma Un_upper1: "A \<subseteq> A \<union> B"
haftmann@32135
  1002
  by blast
haftmann@32135
  1003
haftmann@32135
  1004
lemma Un_upper2: "B \<subseteq> A \<union> B"
haftmann@32135
  1005
  by blast
haftmann@32135
  1006
haftmann@32135
  1007
lemma Un_least: "A \<subseteq> C ==> B \<subseteq> C ==> A \<union> B \<subseteq> C"
haftmann@32135
  1008
  by blast
haftmann@32135
  1009
haftmann@32135
  1010
haftmann@32135
  1011
text {* \medskip Finite Intersection -- the greatest lower bound of two sets. *}
haftmann@32135
  1012
haftmann@32135
  1013
lemma Int_lower1: "A \<inter> B \<subseteq> A"
haftmann@32135
  1014
  by blast
haftmann@32135
  1015
haftmann@32135
  1016
lemma Int_lower2: "A \<inter> B \<subseteq> B"
haftmann@32135
  1017
  by blast
haftmann@32135
  1018
haftmann@32135
  1019
lemma Int_greatest: "C \<subseteq> A ==> C \<subseteq> B ==> C \<subseteq> A \<inter> B"
haftmann@32135
  1020
  by blast
haftmann@32135
  1021
haftmann@32135
  1022
haftmann@32135
  1023
text {* \medskip Set difference. *}
haftmann@32135
  1024
haftmann@32135
  1025
lemma Diff_subset: "A - B \<subseteq> A"
haftmann@32135
  1026
  by blast
haftmann@32135
  1027
haftmann@32135
  1028
lemma Diff_subset_conv: "(A - B \<subseteq> C) = (A \<subseteq> B \<union> C)"
haftmann@32135
  1029
by blast
haftmann@32135
  1030
haftmann@32135
  1031
haftmann@32135
  1032
subsubsection {* Equalities involving union, intersection, inclusion, etc. *}
haftmann@32135
  1033
haftmann@32135
  1034
text {* @{text "{}"}. *}
haftmann@32135
  1035
haftmann@32135
  1036
lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})"
haftmann@32135
  1037
  -- {* supersedes @{text "Collect_False_empty"} *}
haftmann@32135
  1038
  by auto
haftmann@32135
  1039
haftmann@32135
  1040
lemma subset_empty [simp]: "(A \<subseteq> {}) = (A = {})"
haftmann@32135
  1041
  by blast
haftmann@32135
  1042
haftmann@32135
  1043
lemma not_psubset_empty [iff]: "\<not> (A < {})"
haftmann@32135
  1044
  by (unfold less_le) blast
haftmann@32135
  1045
haftmann@32135
  1046
lemma Collect_empty_eq [simp]: "(Collect P = {}) = (\<forall>x. \<not> P x)"
haftmann@32135
  1047
by blast
haftmann@32135
  1048
haftmann@32135
  1049
lemma empty_Collect_eq [simp]: "({} = Collect P) = (\<forall>x. \<not> P x)"
haftmann@32135
  1050
by blast
haftmann@32135
  1051
haftmann@32135
  1052
lemma Collect_neg_eq: "{x. \<not> P x} = - {x. P x}"
haftmann@32135
  1053
  by blast
haftmann@32135
  1054
haftmann@32135
  1055
lemma Collect_disj_eq: "{x. P x | Q x} = {x. P x} \<union> {x. Q x}"
haftmann@32135
  1056
  by blast
haftmann@32135
  1057
haftmann@32135
  1058
lemma Collect_imp_eq: "{x. P x --> Q x} = -{x. P x} \<union> {x. Q x}"
haftmann@32135
  1059
  by blast
haftmann@32135
  1060
haftmann@32135
  1061
lemma Collect_conj_eq: "{x. P x & Q x} = {x. P x} \<inter> {x. Q x}"
haftmann@32135
  1062
  by blast
haftmann@32135
  1063
haftmann@32135
  1064
haftmann@32135
  1065
text {* \medskip @{text insert}. *}
haftmann@32135
  1066
haftmann@32135
  1067
lemma insert_is_Un: "insert a A = {a} Un A"
haftmann@32135
  1068
  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a {}"} *}
haftmann@32135
  1069
  by blast
haftmann@32135
  1070
haftmann@32135
  1071
lemma insert_not_empty [simp]: "insert a A \<noteq> {}"
haftmann@32135
  1072
  by blast
haftmann@32135
  1073
haftmann@32135
  1074
lemmas empty_not_insert = insert_not_empty [symmetric, standard]
haftmann@32135
  1075
declare empty_not_insert [simp]
haftmann@32135
  1076
haftmann@32135
  1077
lemma insert_absorb: "a \<in> A ==> insert a A = A"
haftmann@32135
  1078
  -- {* @{text "[simp]"} causes recursive calls when there are nested inserts *}
haftmann@32135
  1079
  -- {* with \emph{quadratic} running time *}
haftmann@32135
  1080
  by blast
haftmann@32135
  1081
haftmann@32135
  1082
lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A"
haftmann@32135
  1083
  by blast
haftmann@32135
  1084
haftmann@32135
  1085
lemma insert_commute: "insert x (insert y A) = insert y (insert x A)"
haftmann@32135
  1086
  by blast
haftmann@32135
  1087
haftmann@32135
  1088
lemma insert_subset [simp]: "(insert x A \<subseteq> B) = (x \<in> B & A \<subseteq> B)"
haftmann@32135
  1089
  by blast
haftmann@32135
  1090
haftmann@32135
  1091
lemma mk_disjoint_insert: "a \<in> A ==> \<exists>B. A = insert a B & a \<notin> B"
haftmann@32135
  1092
  -- {* use new @{text B} rather than @{text "A - {a}"} to avoid infinite unfolding *}
haftmann@32135
  1093
  apply (rule_tac x = "A - {a}" in exI, blast)
haftmann@32135
  1094
  done
haftmann@32135
  1095
haftmann@32135
  1096
lemma insert_Collect: "insert a (Collect P) = {u. u \<noteq> a --> P u}"
haftmann@32135
  1097
  by auto
haftmann@32135
  1098
haftmann@32135
  1099
lemma insert_inter_insert[simp]: "insert a A \<inter> insert a B = insert a (A \<inter> B)"
haftmann@32135
  1100
  by blast
haftmann@32135
  1101
haftmann@32135
  1102
lemma insert_disjoint [simp,noatp]:
haftmann@32135
  1103
 "(insert a A \<inter> B = {}) = (a \<notin> B \<and> A \<inter> B = {})"
haftmann@32135
  1104
 "({} = insert a A \<inter> B) = (a \<notin> B \<and> {} = A \<inter> B)"
haftmann@32135
  1105
  by auto
haftmann@32135
  1106
haftmann@32135
  1107
lemma disjoint_insert [simp,noatp]:
haftmann@32135
  1108
 "(B \<inter> insert a A = {}) = (a \<notin> B \<and> B \<inter> A = {})"
haftmann@32135
  1109
 "({} = A \<inter> insert b B) = (b \<notin> A \<and> {} = A \<inter> B)"
haftmann@32135
  1110
  by auto
haftmann@32135
  1111
haftmann@32135
  1112
text {* \medskip @{text image}. *}
haftmann@32135
  1113
haftmann@32135
  1114
lemma image_empty [simp]: "f`{} = {}"
haftmann@32135
  1115
  by blast
haftmann@32135
  1116
haftmann@32135
  1117
lemma image_insert [simp]: "f ` insert a B = insert (f a) (f`B)"
haftmann@32135
  1118
  by blast
haftmann@32135
  1119
haftmann@32135
  1120
lemma image_constant: "x \<in> A ==> (\<lambda>x. c) ` A = {c}"
haftmann@32135
  1121
  by auto
haftmann@32135
  1122
haftmann@32135
  1123
lemma image_constant_conv: "(%x. c) ` A = (if A = {} then {} else {c})"
haftmann@32135
  1124
by auto
haftmann@32135
  1125
haftmann@32135
  1126
lemma image_image: "f ` (g ` A) = (\<lambda>x. f (g x)) ` A"
haftmann@32135
  1127
by blast
haftmann@32135
  1128
haftmann@32135
  1129
lemma insert_image [simp]: "x \<in> A ==> insert (f x) (f`A) = f`A"
haftmann@32135
  1130
by blast
haftmann@32135
  1131
haftmann@32135
  1132
lemma image_is_empty [iff]: "(f`A = {}) = (A = {})"
haftmann@32135
  1133
by blast
haftmann@32135
  1134
haftmann@32135
  1135
lemma empty_is_image[iff]: "({} = f ` A) = (A = {})"
haftmann@32135
  1136
by blast
haftmann@32135
  1137
haftmann@32135
  1138
haftmann@32135
  1139
lemma image_Collect [noatp]: "f ` {x. P x} = {f x | x. P x}"
haftmann@32135
  1140
  -- {* NOT suitable as a default simprule: the RHS isn't simpler than the LHS,
haftmann@32135
  1141
      with its implicit quantifier and conjunction.  Also image enjoys better
haftmann@32135
  1142
      equational properties than does the RHS. *}
haftmann@32135
  1143
  by blast
haftmann@32135
  1144
haftmann@32135
  1145
lemma if_image_distrib [simp]:
haftmann@32135
  1146
  "(\<lambda>x. if P x then f x else g x) ` S
haftmann@32135
  1147
    = (f ` (S \<inter> {x. P x})) \<union> (g ` (S \<inter> {x. \<not> P x}))"
haftmann@32135
  1148
  by (auto simp add: image_def)
haftmann@32135
  1149
haftmann@32135
  1150
lemma image_cong: "M = N ==> (!!x. x \<in> N ==> f x = g x) ==> f`M = g`N"
haftmann@32135
  1151
  by (simp add: image_def)
haftmann@32135
  1152
haftmann@32135
  1153
haftmann@32135
  1154
text {* \medskip @{text range}. *}
haftmann@32135
  1155
haftmann@32135
  1156
lemma full_SetCompr_eq [noatp]: "{u. \<exists>x. u = f x} = range f"
haftmann@32135
  1157
  by auto
haftmann@32135
  1158
haftmann@32135
  1159
lemma range_composition: "range (\<lambda>x. f (g x)) = f`range g"
haftmann@32135
  1160
by (subst image_image, simp)
haftmann@32135
  1161
haftmann@32135
  1162
haftmann@32135
  1163
text {* \medskip @{text Int} *}
haftmann@32135
  1164
haftmann@32135
  1165
lemma Int_absorb [simp]: "A \<inter> A = A"
haftmann@32135
  1166
  by blast
haftmann@32135
  1167
haftmann@32135
  1168
lemma Int_left_absorb: "A \<inter> (A \<inter> B) = A \<inter> B"
haftmann@32135
  1169
  by blast
haftmann@32135
  1170
haftmann@32135
  1171
lemma Int_commute: "A \<inter> B = B \<inter> A"
haftmann@32135
  1172
  by blast
haftmann@32135
  1173
haftmann@32135
  1174
lemma Int_left_commute: "A \<inter> (B \<inter> C) = B \<inter> (A \<inter> C)"
haftmann@32135
  1175
  by blast
haftmann@32135
  1176
haftmann@32135
  1177
lemma Int_assoc: "(A \<inter> B) \<inter> C = A \<inter> (B \<inter> C)"
haftmann@32135
  1178
  by blast
haftmann@32135
  1179
haftmann@32135
  1180
lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute
haftmann@32135
  1181
  -- {* Intersection is an AC-operator *}
haftmann@32135
  1182
haftmann@32135
  1183
lemma Int_absorb1: "B \<subseteq> A ==> A \<inter> B = B"
haftmann@32135
  1184
  by blast
haftmann@32135
  1185
haftmann@32135
  1186
lemma Int_absorb2: "A \<subseteq> B ==> A \<inter> B = A"
haftmann@32135
  1187
  by blast
haftmann@32135
  1188
haftmann@32135
  1189
lemma Int_empty_left [simp]: "{} \<inter> B = {}"
haftmann@32135
  1190
  by blast
haftmann@32135
  1191
haftmann@32135
  1192
lemma Int_empty_right [simp]: "A \<inter> {} = {}"
haftmann@32135
  1193
  by blast
haftmann@32135
  1194
haftmann@32135
  1195
lemma disjoint_eq_subset_Compl: "(A \<inter> B = {}) = (A \<subseteq> -B)"
haftmann@32135
  1196
  by blast
haftmann@32135
  1197
haftmann@32135
  1198
lemma disjoint_iff_not_equal: "(A \<inter> B = {}) = (\<forall>x\<in>A. \<forall>y\<in>B. x \<noteq> y)"
haftmann@32135
  1199
  by blast
haftmann@32135
  1200
haftmann@32135
  1201
lemma Int_UNIV_left [simp]: "UNIV \<inter> B = B"
haftmann@32135
  1202
  by blast
haftmann@32135
  1203
haftmann@32135
  1204
lemma Int_UNIV_right [simp]: "A \<inter> UNIV = A"
haftmann@32135
  1205
  by blast
haftmann@32135
  1206
haftmann@32135
  1207
lemma Int_Un_distrib: "A \<inter> (B \<union> C) = (A \<inter> B) \<union> (A \<inter> C)"
haftmann@32135
  1208
  by blast
haftmann@32135
  1209
haftmann@32135
  1210
lemma Int_Un_distrib2: "(B \<union> C) \<inter> A = (B \<inter> A) \<union> (C \<inter> A)"
haftmann@32135
  1211
  by blast
haftmann@32135
  1212
haftmann@32135
  1213
lemma Int_UNIV [simp,noatp]: "(A \<inter> B = UNIV) = (A = UNIV & B = UNIV)"
haftmann@32135
  1214
  by blast
haftmann@32135
  1215
haftmann@32135
  1216
lemma Int_subset_iff [simp]: "(C \<subseteq> A \<inter> B) = (C \<subseteq> A & C \<subseteq> B)"
haftmann@32135
  1217
  by blast
haftmann@32135
  1218
haftmann@32135
  1219
lemma Int_Collect: "(x \<in> A \<inter> {x. P x}) = (x \<in> A & P x)"
haftmann@32135
  1220
  by blast
haftmann@32135
  1221
haftmann@32135
  1222
haftmann@32135
  1223
text {* \medskip @{text Un}. *}
haftmann@32135
  1224
haftmann@32135
  1225
lemma Un_absorb [simp]: "A \<union> A = A"
haftmann@32135
  1226
  by blast
haftmann@32135
  1227
haftmann@32135
  1228
lemma Un_left_absorb: "A \<union> (A \<union> B) = A \<union> B"
haftmann@32135
  1229
  by blast
haftmann@32135
  1230
haftmann@32135
  1231
lemma Un_commute: "A \<union> B = B \<union> A"
haftmann@32135
  1232
  by blast
haftmann@32135
  1233
haftmann@32135
  1234
lemma Un_left_commute: "A \<union> (B \<union> C) = B \<union> (A \<union> C)"
haftmann@32135
  1235
  by blast
haftmann@32135
  1236
haftmann@32135
  1237
lemma Un_assoc: "(A \<union> B) \<union> C = A \<union> (B \<union> C)"
haftmann@32135
  1238
  by blast
haftmann@32135
  1239
haftmann@32135
  1240
lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute
haftmann@32135
  1241
  -- {* Union is an AC-operator *}
haftmann@32135
  1242
haftmann@32135
  1243
lemma Un_absorb1: "A \<subseteq> B ==> A \<union> B = B"
haftmann@32135
  1244
  by blast
haftmann@32135
  1245
haftmann@32135
  1246
lemma Un_absorb2: "B \<subseteq> A ==> A \<union> B = A"
haftmann@32135
  1247
  by blast
haftmann@32135
  1248
haftmann@32135
  1249
lemma Un_empty_left [simp]: "{} \<union> B = B"
haftmann@32135
  1250
  by blast
haftmann@32135
  1251
haftmann@32135
  1252
lemma Un_empty_right [simp]: "A \<union> {} = A"
haftmann@32135
  1253
  by blast
haftmann@32135
  1254
haftmann@32135
  1255
lemma Un_UNIV_left [simp]: "UNIV \<union> B = UNIV"
haftmann@32135
  1256
  by blast
haftmann@32135
  1257
haftmann@32135
  1258
lemma Un_UNIV_right [simp]: "A \<union> UNIV = UNIV"
haftmann@32135
  1259
  by blast
haftmann@32135
  1260
haftmann@32135
  1261
lemma Un_insert_left [simp]: "(insert a B) \<union> C = insert a (B \<union> C)"
haftmann@32135
  1262
  by blast
haftmann@32135
  1263
haftmann@32135
  1264
lemma Un_insert_right [simp]: "A \<union> (insert a B) = insert a (A \<union> B)"
haftmann@32135
  1265
  by blast
haftmann@32135
  1266
haftmann@32135
  1267
lemma Int_insert_left:
haftmann@32135
  1268
    "(insert a B) Int C = (if a \<in> C then insert a (B \<inter> C) else B \<inter> C)"
haftmann@32135
  1269
  by auto
haftmann@32135
  1270
nipkow@32456
  1271
lemma Int_insert_left_if0[simp]:
nipkow@32456
  1272
    "a \<notin> C \<Longrightarrow> (insert a B) Int C = B \<inter> C"
nipkow@32456
  1273
  by auto
nipkow@32456
  1274
nipkow@32456
  1275
lemma Int_insert_left_if1[simp]:
nipkow@32456
  1276
    "a \<in> C \<Longrightarrow> (insert a B) Int C = insert a (B Int C)"
nipkow@32456
  1277
  by auto
nipkow@32456
  1278
haftmann@32135
  1279
lemma Int_insert_right:
haftmann@32135
  1280
    "A \<inter> (insert a B) = (if a \<in> A then insert a (A \<inter> B) else A \<inter> B)"
haftmann@32135
  1281
  by auto
haftmann@32135
  1282
nipkow@32456
  1283
lemma Int_insert_right_if0[simp]:
nipkow@32456
  1284
    "a \<notin> A \<Longrightarrow> A Int (insert a B) = A Int B"
nipkow@32456
  1285
  by auto
nipkow@32456
  1286
nipkow@32456
  1287
lemma Int_insert_right_if1[simp]:
nipkow@32456
  1288
    "a \<in> A \<Longrightarrow> A Int (insert a B) = insert a (A Int B)"
nipkow@32456
  1289
  by auto
nipkow@32456
  1290
haftmann@32135
  1291
lemma Un_Int_distrib: "A \<union> (B \<inter> C) = (A \<union> B) \<inter> (A \<union> C)"
haftmann@32135
  1292
  by blast
haftmann@32135
  1293
haftmann@32135
  1294
lemma Un_Int_distrib2: "(B \<inter> C) \<union> A = (B \<union> A) \<inter> (C \<union> A)"
haftmann@32135
  1295
  by blast
haftmann@32135
  1296
haftmann@32135
  1297
lemma Un_Int_crazy:
haftmann@32135
  1298
    "(A \<inter> B) \<union> (B \<inter> C) \<union> (C \<inter> A) = (A \<union> B) \<inter> (B \<union> C) \<inter> (C \<union> A)"
haftmann@32135
  1299
  by blast
haftmann@32135
  1300
haftmann@32135
  1301
lemma subset_Un_eq: "(A \<subseteq> B) = (A \<union> B = B)"
haftmann@32135
  1302
  by blast
haftmann@32135
  1303
haftmann@32135
  1304
lemma Un_empty [iff]: "(A \<union> B = {}) = (A = {} & B = {})"
haftmann@32135
  1305
  by blast
haftmann@32135
  1306
haftmann@32135
  1307
lemma Un_subset_iff [simp]: "(A \<union> B \<subseteq> C) = (A \<subseteq> C & B \<subseteq> C)"
haftmann@32135
  1308
  by blast
haftmann@32135
  1309
haftmann@32135
  1310
lemma Un_Diff_Int: "(A - B) \<union> (A \<inter> B) = A"
haftmann@32135
  1311
  by blast
haftmann@32135
  1312
haftmann@32135
  1313
lemma Diff_Int2: "A \<inter> C - B \<inter> C = A \<inter> C - B"
haftmann@32135
  1314
  by blast
haftmann@32135
  1315
haftmann@32135
  1316
haftmann@32135
  1317
text {* \medskip Set complement *}
haftmann@32135
  1318
haftmann@32135
  1319
lemma Compl_disjoint [simp]: "A \<inter> -A = {}"
haftmann@32135
  1320
  by blast
haftmann@32135
  1321
haftmann@32135
  1322
lemma Compl_disjoint2 [simp]: "-A \<inter> A = {}"
haftmann@32135
  1323
  by blast
haftmann@32135
  1324
haftmann@32135
  1325
lemma Compl_partition: "A \<union> -A = UNIV"
haftmann@32135
  1326
  by blast
haftmann@32135
  1327
haftmann@32135
  1328
lemma Compl_partition2: "-A \<union> A = UNIV"
haftmann@32135
  1329
  by blast
haftmann@32135
  1330
haftmann@32135
  1331
lemma double_complement [simp]: "- (-A) = (A::'a set)"
haftmann@32135
  1332
  by blast
haftmann@32135
  1333
haftmann@32135
  1334
lemma Compl_Un [simp]: "-(A \<union> B) = (-A) \<inter> (-B)"
haftmann@32135
  1335
  by blast
haftmann@32135
  1336
haftmann@32135
  1337
lemma Compl_Int [simp]: "-(A \<inter> B) = (-A) \<union> (-B)"
haftmann@32135
  1338
  by blast
haftmann@32135
  1339
haftmann@32135
  1340
lemma subset_Compl_self_eq: "(A \<subseteq> -A) = (A = {})"
haftmann@32135
  1341
  by blast
haftmann@32135
  1342
haftmann@32135
  1343
lemma Un_Int_assoc_eq: "((A \<inter> B) \<union> C = A \<inter> (B \<union> C)) = (C \<subseteq> A)"
haftmann@32135
  1344
  -- {* Halmos, Naive Set Theory, page 16. *}
haftmann@32135
  1345
  by blast
haftmann@32135
  1346
haftmann@32135
  1347
lemma Compl_UNIV_eq [simp]: "-UNIV = {}"
haftmann@32135
  1348
  by blast
haftmann@32135
  1349
haftmann@32135
  1350
lemma Compl_empty_eq [simp]: "-{} = UNIV"
haftmann@32135
  1351
  by blast
haftmann@32135
  1352
haftmann@32135
  1353
lemma Compl_subset_Compl_iff [iff]: "(-A \<subseteq> -B) = (B \<subseteq> A)"
haftmann@32135
  1354
  by blast
haftmann@32135
  1355
haftmann@32135
  1356
lemma Compl_eq_Compl_iff [iff]: "(-A = -B) = (A = (B::'a set))"
haftmann@32135
  1357
  by blast
haftmann@32135
  1358
haftmann@32135
  1359
text {* \medskip Bounded quantifiers.
haftmann@32135
  1360
haftmann@32135
  1361
  The following are not added to the default simpset because
haftmann@32135
  1362
  (a) they duplicate the body and (b) there are no similar rules for @{text Int}. *}
haftmann@32135
  1363
haftmann@32135
  1364
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
  1365
  by blast
haftmann@32135
  1366
haftmann@32135
  1367
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
  1368
  by blast
haftmann@32135
  1369
haftmann@32135
  1370
haftmann@32135
  1371
text {* \medskip Set difference. *}
haftmann@32135
  1372
haftmann@32135
  1373
lemma Diff_eq: "A - B = A \<inter> (-B)"
haftmann@32135
  1374
  by blast
haftmann@32135
  1375
haftmann@32135
  1376
lemma Diff_eq_empty_iff [simp,noatp]: "(A - B = {}) = (A \<subseteq> B)"
haftmann@32135
  1377
  by blast
haftmann@32135
  1378
haftmann@32135
  1379
lemma Diff_cancel [simp]: "A - A = {}"
haftmann@32135
  1380
  by blast
haftmann@32135
  1381
haftmann@32135
  1382
lemma Diff_idemp [simp]: "(A - B) - B = A - (B::'a set)"
haftmann@32135
  1383
by blast
haftmann@32135
  1384
haftmann@32135
  1385
lemma Diff_triv: "A \<inter> B = {} ==> A - B = A"
haftmann@32135
  1386
  by (blast elim: equalityE)
haftmann@32135
  1387
haftmann@32135
  1388
lemma empty_Diff [simp]: "{} - A = {}"
haftmann@32135
  1389
  by blast
haftmann@32135
  1390
haftmann@32135
  1391
lemma Diff_empty [simp]: "A - {} = A"
haftmann@32135
  1392
  by blast
haftmann@32135
  1393
haftmann@32135
  1394
lemma Diff_UNIV [simp]: "A - UNIV = {}"
haftmann@32135
  1395
  by blast
haftmann@32135
  1396
haftmann@32135
  1397
lemma Diff_insert0 [simp,noatp]: "x \<notin> A ==> A - insert x B = A - B"
haftmann@32135
  1398
  by blast
haftmann@32135
  1399
haftmann@32135
  1400
lemma Diff_insert: "A - insert a B = A - B - {a}"
haftmann@32135
  1401
  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
haftmann@32135
  1402
  by blast
haftmann@32135
  1403
haftmann@32135
  1404
lemma Diff_insert2: "A - insert a B = A - {a} - B"
haftmann@32135
  1405
  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
haftmann@32135
  1406
  by blast
haftmann@32135
  1407
haftmann@32135
  1408
lemma insert_Diff_if: "insert x A - B = (if x \<in> B then A - B else insert x (A - B))"
haftmann@32135
  1409
  by auto
haftmann@32135
  1410
haftmann@32135
  1411
lemma insert_Diff1 [simp]: "x \<in> B ==> insert x A - B = A - B"
haftmann@32135
  1412
  by blast
haftmann@32135
  1413
haftmann@32135
  1414
lemma insert_Diff_single[simp]: "insert a (A - {a}) = insert a A"
haftmann@32135
  1415
by blast
haftmann@32135
  1416
haftmann@32135
  1417
lemma insert_Diff: "a \<in> A ==> insert a (A - {a}) = A"
haftmann@32135
  1418
  by blast
haftmann@32135
  1419
haftmann@32135
  1420
lemma Diff_insert_absorb: "x \<notin> A ==> (insert x A) - {x} = A"
haftmann@32135
  1421
  by auto
haftmann@32135
  1422
haftmann@32135
  1423
lemma Diff_disjoint [simp]: "A \<inter> (B - A) = {}"
haftmann@32135
  1424
  by blast
haftmann@32135
  1425
haftmann@32135
  1426
lemma Diff_partition: "A \<subseteq> B ==> A \<union> (B - A) = B"
haftmann@32135
  1427
  by blast
haftmann@32135
  1428
haftmann@32135
  1429
lemma double_diff: "A \<subseteq> B ==> B \<subseteq> C ==> B - (C - A) = A"
haftmann@32135
  1430
  by blast
haftmann@32135
  1431
haftmann@32135
  1432
lemma Un_Diff_cancel [simp]: "A \<union> (B - A) = A \<union> B"
haftmann@32135
  1433
  by blast
haftmann@32135
  1434
haftmann@32135
  1435
lemma Un_Diff_cancel2 [simp]: "(B - A) \<union> A = B \<union> A"
haftmann@32135
  1436
  by blast
haftmann@32135
  1437
haftmann@32135
  1438
lemma Diff_Un: "A - (B \<union> C) = (A - B) \<inter> (A - C)"
haftmann@32135
  1439
  by blast
haftmann@32135
  1440
haftmann@32135
  1441
lemma Diff_Int: "A - (B \<inter> C) = (A - B) \<union> (A - C)"
haftmann@32135
  1442
  by blast
haftmann@32135
  1443
haftmann@32135
  1444
lemma Un_Diff: "(A \<union> B) - C = (A - C) \<union> (B - C)"
haftmann@32135
  1445
  by blast
haftmann@32135
  1446
haftmann@32135
  1447
lemma Int_Diff: "(A \<inter> B) - C = A \<inter> (B - C)"
haftmann@32135
  1448
  by blast
haftmann@32135
  1449
haftmann@32135
  1450
lemma Diff_Int_distrib: "C \<inter> (A - B) = (C \<inter> A) - (C \<inter> B)"
haftmann@32135
  1451
  by blast
haftmann@32135
  1452
haftmann@32135
  1453
lemma Diff_Int_distrib2: "(A - B) \<inter> C = (A \<inter> C) - (B \<inter> C)"
haftmann@32135
  1454
  by blast
haftmann@32135
  1455
haftmann@32135
  1456
lemma Diff_Compl [simp]: "A - (- B) = A \<inter> B"
haftmann@32135
  1457
  by auto
haftmann@32135
  1458
haftmann@32135
  1459
lemma Compl_Diff_eq [simp]: "- (A - B) = -A \<union> B"
haftmann@32135
  1460
  by blast
haftmann@32135
  1461
haftmann@32135
  1462
haftmann@32135
  1463
text {* \medskip Quantification over type @{typ bool}. *}
haftmann@32135
  1464
haftmann@32135
  1465
lemma bool_induct: "P True \<Longrightarrow> P False \<Longrightarrow> P x"
haftmann@32135
  1466
  by (cases x) auto
haftmann@32135
  1467
haftmann@32135
  1468
lemma all_bool_eq: "(\<forall>b. P b) \<longleftrightarrow> P True \<and> P False"
haftmann@32135
  1469
  by (auto intro: bool_induct)
haftmann@32135
  1470
haftmann@32135
  1471
lemma bool_contrapos: "P x \<Longrightarrow> \<not> P False \<Longrightarrow> P True"
haftmann@32135
  1472
  by (cases x) auto
haftmann@32135
  1473
haftmann@32135
  1474
lemma ex_bool_eq: "(\<exists>b. P b) \<longleftrightarrow> P True \<or> P False"
haftmann@32135
  1475
  by (auto intro: bool_contrapos)
haftmann@32135
  1476
haftmann@32135
  1477
text {* \medskip @{text Pow} *}
haftmann@32135
  1478
haftmann@32135
  1479
lemma Pow_empty [simp]: "Pow {} = {{}}"
haftmann@32135
  1480
  by (auto simp add: Pow_def)
haftmann@32135
  1481
haftmann@32135
  1482
lemma Pow_insert: "Pow (insert a A) = Pow A \<union> (insert a ` Pow A)"
haftmann@32135
  1483
  by (blast intro: image_eqI [where ?x = "u - {a}", standard])
haftmann@32135
  1484
haftmann@32135
  1485
lemma Pow_Compl: "Pow (- A) = {-B | B. A \<in> Pow B}"
haftmann@32135
  1486
  by (blast intro: exI [where ?x = "- u", standard])
haftmann@32135
  1487
haftmann@32135
  1488
lemma Pow_UNIV [simp]: "Pow UNIV = UNIV"
haftmann@32135
  1489
  by blast
haftmann@32135
  1490
haftmann@32135
  1491
lemma Un_Pow_subset: "Pow A \<union> Pow B \<subseteq> Pow (A \<union> B)"
haftmann@32135
  1492
  by blast
haftmann@32135
  1493
haftmann@32135
  1494
lemma Pow_Int_eq [simp]: "Pow (A \<inter> B) = Pow A \<inter> Pow B"
haftmann@32135
  1495
  by blast
haftmann@32135
  1496
haftmann@32135
  1497
haftmann@32135
  1498
text {* \medskip Miscellany. *}
haftmann@32135
  1499
haftmann@32135
  1500
lemma set_eq_subset: "(A = B) = (A \<subseteq> B & B \<subseteq> A)"
haftmann@32135
  1501
  by blast
haftmann@32135
  1502
haftmann@32135
  1503
lemma subset_iff: "(A \<subseteq> B) = (\<forall>t. t \<in> A --> t \<in> B)"
haftmann@32135
  1504
  by blast
haftmann@32135
  1505
haftmann@32135
  1506
lemma subset_iff_psubset_eq: "(A \<subseteq> B) = ((A \<subset> B) | (A = B))"
haftmann@32135
  1507
  by (unfold less_le) blast
haftmann@32135
  1508
haftmann@32135
  1509
lemma all_not_in_conv [simp]: "(\<forall>x. x \<notin> A) = (A = {})"
haftmann@32135
  1510
  by blast
haftmann@32135
  1511
haftmann@32135
  1512
lemma ex_in_conv: "(\<exists>x. x \<in> A) = (A \<noteq> {})"
haftmann@32135
  1513
  by blast
haftmann@32135
  1514
haftmann@32135
  1515
lemma distinct_lemma: "f x \<noteq> f y ==> x \<noteq> y"
haftmann@32135
  1516
  by iprover
haftmann@32135
  1517
haftmann@32135
  1518
haftmann@32135
  1519
subsubsection {* Monotonicity of various operations *}
haftmann@32135
  1520
haftmann@32135
  1521
lemma image_mono: "A \<subseteq> B ==> f`A \<subseteq> f`B"
haftmann@32135
  1522
  by blast
haftmann@32135
  1523
haftmann@32135
  1524
lemma Pow_mono: "A \<subseteq> B ==> Pow A \<subseteq> Pow B"
haftmann@32135
  1525
  by blast
haftmann@32135
  1526
haftmann@32135
  1527
lemma insert_mono: "C \<subseteq> D ==> insert a C \<subseteq> insert a D"
haftmann@32135
  1528
  by blast
haftmann@32135
  1529
haftmann@32135
  1530
lemma Un_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<union> B \<subseteq> C \<union> D"
haftmann@32135
  1531
  by blast
haftmann@32135
  1532
haftmann@32135
  1533
lemma Int_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<inter> B \<subseteq> C \<inter> D"
haftmann@32135
  1534
  by blast
haftmann@32135
  1535
haftmann@32135
  1536
lemma Diff_mono: "A \<subseteq> C ==> D \<subseteq> B ==> A - B \<subseteq> C - D"
haftmann@32135
  1537
  by blast
haftmann@32135
  1538
haftmann@32135
  1539
lemma Compl_anti_mono: "A \<subseteq> B ==> -B \<subseteq> -A"
haftmann@32135
  1540
  by blast
haftmann@32135
  1541
haftmann@32135
  1542
text {* \medskip Monotonicity of implications. *}
haftmann@32135
  1543
haftmann@32135
  1544
lemma in_mono: "A \<subseteq> B ==> x \<in> A --> x \<in> B"
haftmann@32135
  1545
  apply (rule impI)
haftmann@32135
  1546
  apply (erule subsetD, assumption)
haftmann@32135
  1547
  done
haftmann@32135
  1548
haftmann@32135
  1549
lemma conj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 & P2) --> (Q1 & Q2)"
haftmann@32135
  1550
  by iprover
haftmann@32135
  1551
haftmann@32135
  1552
lemma disj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 | P2) --> (Q1 | Q2)"
haftmann@32135
  1553
  by iprover
haftmann@32135
  1554
haftmann@32135
  1555
lemma imp_mono: "Q1 --> P1 ==> P2 --> Q2 ==> (P1 --> P2) --> (Q1 --> Q2)"
haftmann@32135
  1556
  by iprover
haftmann@32135
  1557
haftmann@32135
  1558
lemma imp_refl: "P --> P" ..
haftmann@32135
  1559
haftmann@32135
  1560
lemma ex_mono: "(!!x. P x --> Q x) ==> (EX x. P x) --> (EX x. Q x)"
haftmann@32135
  1561
  by iprover
haftmann@32135
  1562
haftmann@32135
  1563
lemma all_mono: "(!!x. P x --> Q x) ==> (ALL x. P x) --> (ALL x. Q x)"
haftmann@32135
  1564
  by iprover
haftmann@32135
  1565
haftmann@32135
  1566
lemma Collect_mono: "(!!x. P x --> Q x) ==> Collect P \<subseteq> Collect Q"
haftmann@32135
  1567
  by blast
haftmann@32135
  1568
haftmann@32135
  1569
lemma Int_Collect_mono:
haftmann@32135
  1570
    "A \<subseteq> B ==> (!!x. x \<in> A ==> P x --> Q x) ==> A \<inter> Collect P \<subseteq> B \<inter> Collect Q"
haftmann@32135
  1571
  by blast
haftmann@32135
  1572
haftmann@32135
  1573
lemmas basic_monos =
haftmann@32135
  1574
  subset_refl imp_refl disj_mono conj_mono
haftmann@32135
  1575
  ex_mono Collect_mono in_mono
haftmann@32135
  1576
haftmann@32135
  1577
lemma eq_to_mono: "a = b ==> c = d ==> b --> d ==> a --> c"
haftmann@32135
  1578
  by iprover
haftmann@32135
  1579
haftmann@32135
  1580
lemma eq_to_mono2: "a = b ==> c = d ==> ~ b --> ~ d ==> ~ a --> ~ c"
haftmann@32135
  1581
  by iprover
haftmann@32135
  1582
haftmann@32135
  1583
haftmann@32135
  1584
subsubsection {* Inverse image of a function *}
haftmann@32135
  1585
haftmann@32135
  1586
constdefs
haftmann@32135
  1587
  vimage :: "('a => 'b) => 'b set => 'a set"    (infixr "-`" 90)
haftmann@32135
  1588
  [code del]: "f -` B == {x. f x : B}"
haftmann@32135
  1589
haftmann@32135
  1590
lemma vimage_eq [simp]: "(a : f -` B) = (f a : B)"
haftmann@32135
  1591
  by (unfold vimage_def) blast
haftmann@32135
  1592
haftmann@32135
  1593
lemma vimage_singleton_eq: "(a : f -` {b}) = (f a = b)"
haftmann@32135
  1594
  by simp
haftmann@32135
  1595
haftmann@32135
  1596
lemma vimageI [intro]: "f a = b ==> b:B ==> a : f -` B"
haftmann@32135
  1597
  by (unfold vimage_def) blast
haftmann@32135
  1598
haftmann@32135
  1599
lemma vimageI2: "f a : A ==> a : f -` A"
haftmann@32135
  1600
  by (unfold vimage_def) fast
haftmann@32135
  1601
haftmann@32135
  1602
lemma vimageE [elim!]: "a: f -` B ==> (!!x. f a = x ==> x:B ==> P) ==> P"
haftmann@32135
  1603
  by (unfold vimage_def) blast
haftmann@32135
  1604
haftmann@32135
  1605
lemma vimageD: "a : f -` A ==> f a : A"
haftmann@32135
  1606
  by (unfold vimage_def) fast
haftmann@32135
  1607
haftmann@32135
  1608
lemma vimage_empty [simp]: "f -` {} = {}"
haftmann@32135
  1609
  by blast
haftmann@32135
  1610
haftmann@32135
  1611
lemma vimage_Compl: "f -` (-A) = -(f -` A)"
haftmann@32135
  1612
  by blast
haftmann@32135
  1613
haftmann@32135
  1614
lemma vimage_Un [simp]: "f -` (A Un B) = (f -` A) Un (f -` B)"
haftmann@32135
  1615
  by blast
haftmann@32135
  1616
haftmann@32135
  1617
lemma vimage_Int [simp]: "f -` (A Int B) = (f -` A) Int (f -` B)"
haftmann@32135
  1618
  by fast
haftmann@32135
  1619
haftmann@32135
  1620
lemma vimage_Collect_eq [simp]: "f -` Collect P = {y. P (f y)}"
haftmann@32135
  1621
  by blast
haftmann@32135
  1622
haftmann@32135
  1623
lemma vimage_Collect: "(!!x. P (f x) = Q x) ==> f -` (Collect P) = Collect Q"
haftmann@32135
  1624
  by blast
haftmann@32135
  1625
haftmann@32135
  1626
lemma vimage_insert: "f-`(insert a B) = (f-`{a}) Un (f-`B)"
haftmann@32135
  1627
  -- {* NOT suitable for rewriting because of the recurrence of @{term "{a}"}. *}
haftmann@32135
  1628
  by blast
haftmann@32135
  1629
haftmann@32135
  1630
lemma vimage_Diff: "f -` (A - B) = (f -` A) - (f -` B)"
haftmann@32135
  1631
  by blast
haftmann@32135
  1632
haftmann@32135
  1633
lemma vimage_UNIV [simp]: "f -` UNIV = UNIV"
haftmann@32135
  1634
  by blast
haftmann@32135
  1635
haftmann@32135
  1636
lemma vimage_mono: "A \<subseteq> B ==> f -` A \<subseteq> f -` B"
haftmann@32135
  1637
  -- {* monotonicity *}
haftmann@32135
  1638
  by blast
haftmann@32135
  1639
haftmann@32135
  1640
lemma vimage_image_eq [noatp]: "f -` (f ` A) = {y. EX x:A. f x = f y}"
haftmann@32135
  1641
by (blast intro: sym)
haftmann@32135
  1642
haftmann@32135
  1643
lemma image_vimage_subset: "f ` (f -` A) <= A"
haftmann@32135
  1644
by blast
haftmann@32135
  1645
haftmann@32135
  1646
lemma image_vimage_eq [simp]: "f ` (f -` A) = A Int range f"
haftmann@32135
  1647
by blast
haftmann@32135
  1648
haftmann@32135
  1649
lemma image_Int_subset: "f`(A Int B) <= f`A Int f`B"
haftmann@32135
  1650
by blast
haftmann@32135
  1651
haftmann@32135
  1652
lemma image_diff_subset: "f`A - f`B <= f`(A - B)"
haftmann@32135
  1653
by blast
haftmann@32135
  1654
haftmann@32135
  1655
haftmann@32135
  1656
subsubsection {* Getting the Contents of a Singleton Set *}
haftmann@32135
  1657
haftmann@32135
  1658
definition contents :: "'a set \<Rightarrow> 'a" where
haftmann@32135
  1659
  [code del]: "contents X = (THE x. X = {x})"
haftmann@32135
  1660
haftmann@32135
  1661
lemma contents_eq [simp]: "contents {x} = x"
haftmann@32135
  1662
  by (simp add: contents_def)
haftmann@32135
  1663
haftmann@32135
  1664
haftmann@32135
  1665
subsubsection {* Least value operator *}
haftmann@32135
  1666
haftmann@32135
  1667
lemma Least_mono:
haftmann@32135
  1668
  "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y
haftmann@32135
  1669
    ==> (LEAST y. y : f ` S) = f (LEAST x. x : S)"
haftmann@32135
  1670
    -- {* Courtesy of Stephan Merz *}
haftmann@32135
  1671
  apply clarify
haftmann@32135
  1672
  apply (erule_tac P = "%x. x : S" in LeastI2_order, fast)
haftmann@32135
  1673
  apply (rule LeastI2_order)
haftmann@32135
  1674
  apply (auto elim: monoD intro!: order_antisym)
haftmann@32135
  1675
  done
haftmann@32135
  1676
haftmann@32135
  1677
subsection {* Misc *}
haftmann@32135
  1678
haftmann@32135
  1679
text {* Rudimentary code generation *}
haftmann@32135
  1680
haftmann@32135
  1681
lemma insert_code [code]: "insert y A x \<longleftrightarrow> y = x \<or> A x"
haftmann@32135
  1682
  by (auto simp add: insert_compr Collect_def mem_def)
haftmann@32135
  1683
haftmann@32135
  1684
lemma vimage_code [code]: "(f -` A) x = A (f x)"
haftmann@32135
  1685
  by (simp add: vimage_def Collect_def mem_def)
haftmann@32135
  1686
haftmann@32135
  1687
haftmann@32135
  1688
text {* Misc theorem and ML bindings *}
haftmann@32135
  1689
haftmann@32135
  1690
lemmas equalityI = subset_antisym
haftmann@32135
  1691
haftmann@32135
  1692
ML {*
haftmann@32135
  1693
val Ball_def = @{thm Ball_def}
haftmann@32135
  1694
val Bex_def = @{thm Bex_def}
haftmann@32135
  1695
val CollectD = @{thm CollectD}
haftmann@32135
  1696
val CollectE = @{thm CollectE}
haftmann@32135
  1697
val CollectI = @{thm CollectI}
haftmann@32135
  1698
val Collect_conj_eq = @{thm Collect_conj_eq}
haftmann@32135
  1699
val Collect_mem_eq = @{thm Collect_mem_eq}
haftmann@32135
  1700
val IntD1 = @{thm IntD1}
haftmann@32135
  1701
val IntD2 = @{thm IntD2}
haftmann@32135
  1702
val IntE = @{thm IntE}
haftmann@32135
  1703
val IntI = @{thm IntI}
haftmann@32135
  1704
val Int_Collect = @{thm Int_Collect}
haftmann@32135
  1705
val UNIV_I = @{thm UNIV_I}
haftmann@32135
  1706
val UNIV_witness = @{thm UNIV_witness}
haftmann@32135
  1707
val UnE = @{thm UnE}
haftmann@32135
  1708
val UnI1 = @{thm UnI1}
haftmann@32135
  1709
val UnI2 = @{thm UnI2}
haftmann@32135
  1710
val ballE = @{thm ballE}
haftmann@32135
  1711
val ballI = @{thm ballI}
haftmann@32135
  1712
val bexCI = @{thm bexCI}
haftmann@32135
  1713
val bexE = @{thm bexE}
haftmann@32135
  1714
val bexI = @{thm bexI}
haftmann@32135
  1715
val bex_triv = @{thm bex_triv}
haftmann@32135
  1716
val bspec = @{thm bspec}
haftmann@32135
  1717
val contra_subsetD = @{thm contra_subsetD}
haftmann@32135
  1718
val distinct_lemma = @{thm distinct_lemma}
haftmann@32135
  1719
val eq_to_mono = @{thm eq_to_mono}
haftmann@32135
  1720
val eq_to_mono2 = @{thm eq_to_mono2}
haftmann@32135
  1721
val equalityCE = @{thm equalityCE}
haftmann@32135
  1722
val equalityD1 = @{thm equalityD1}
haftmann@32135
  1723
val equalityD2 = @{thm equalityD2}
haftmann@32135
  1724
val equalityE = @{thm equalityE}
haftmann@32135
  1725
val equalityI = @{thm equalityI}
haftmann@32135
  1726
val imageE = @{thm imageE}
haftmann@32135
  1727
val imageI = @{thm imageI}
haftmann@32135
  1728
val image_Un = @{thm image_Un}
haftmann@32135
  1729
val image_insert = @{thm image_insert}
haftmann@32135
  1730
val insert_commute = @{thm insert_commute}
haftmann@32135
  1731
val insert_iff = @{thm insert_iff}
haftmann@32135
  1732
val mem_Collect_eq = @{thm mem_Collect_eq}
haftmann@32135
  1733
val rangeE = @{thm rangeE}
haftmann@32135
  1734
val rangeI = @{thm rangeI}
haftmann@32135
  1735
val range_eqI = @{thm range_eqI}
haftmann@32135
  1736
val subsetCE = @{thm subsetCE}
haftmann@32135
  1737
val subsetD = @{thm subsetD}
haftmann@32135
  1738
val subsetI = @{thm subsetI}
haftmann@32135
  1739
val subset_refl = @{thm subset_refl}
haftmann@32135
  1740
val subset_trans = @{thm subset_trans}
haftmann@32135
  1741
val vimageD = @{thm vimageD}
haftmann@32135
  1742
val vimageE = @{thm vimageE}
haftmann@32135
  1743
val vimageI = @{thm vimageI}
haftmann@32135
  1744
val vimageI2 = @{thm vimageI2}
haftmann@32135
  1745
val vimage_Collect = @{thm vimage_Collect}
haftmann@32135
  1746
val vimage_Int = @{thm vimage_Int}
haftmann@32135
  1747
val vimage_Un = @{thm vimage_Un}
haftmann@32135
  1748
*}
haftmann@32135
  1749
haftmann@32077
  1750
end