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