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