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