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