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