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