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