src/HOL/Set.thy
author hoelzl
Fri Mar 22 10:41:43 2013 +0100 (2013-03-22)
changeset 51474 1e9e68247ad1
parent 51392 635562bc14ef
child 51703 f2e92fc0c8aa
permissions -rw-r--r--
generalize Bfun and Bseq to metric spaces; Bseq is an abbreviation for Bfun
haftmann@32139
     1
(*  Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel *)
clasohm@923
     2
wenzelm@11979
     3
header {* Set theory for higher-order logic *}
wenzelm@11979
     4
nipkow@15131
     5
theory Set
haftmann@30304
     6
imports Lattices
nipkow@15131
     7
begin
wenzelm@11979
     8
haftmann@32081
     9
subsection {* Sets as predicates *}
haftmann@30531
    10
haftmann@45959
    11
typedecl 'a set
wenzelm@3820
    12
haftmann@45959
    13
axiomatization Collect :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set" -- "comprehension"
haftmann@45959
    14
  and member :: "'a \<Rightarrow> 'a set \<Rightarrow> bool" -- "membership"
haftmann@45959
    15
where
haftmann@45959
    16
  mem_Collect_eq [iff, code_unfold]: "member a (Collect P) = P a"
haftmann@45959
    17
  and Collect_mem_eq [simp]: "Collect (\<lambda>x. member x A) = A"
wenzelm@19656
    18
wenzelm@21210
    19
notation
haftmann@37677
    20
  member  ("op :") and
nipkow@50580
    21
  member  ("(_/ : _)" [51, 51] 50)
wenzelm@11979
    22
haftmann@37677
    23
abbreviation not_member where
haftmann@37677
    24
  "not_member x A \<equiv> ~ (x : A)" -- "non-membership"
wenzelm@19656
    25
wenzelm@21210
    26
notation
haftmann@37677
    27
  not_member  ("op ~:") and
nipkow@50580
    28
  not_member  ("(_/ ~: _)" [51, 51] 50)
wenzelm@19656
    29
wenzelm@21210
    30
notation (xsymbols)
haftmann@37677
    31
  member      ("op \<in>") and
nipkow@50580
    32
  member      ("(_/ \<in> _)" [51, 51] 50) and
haftmann@37677
    33
  not_member  ("op \<notin>") and
nipkow@50580
    34
  not_member  ("(_/ \<notin> _)" [51, 51] 50)
wenzelm@19656
    35
wenzelm@21210
    36
notation (HTML output)
haftmann@37677
    37
  member      ("op \<in>") and
nipkow@50580
    38
  member      ("(_/ \<in> _)" [51, 51] 50) and
haftmann@37677
    39
  not_member  ("op \<notin>") and
nipkow@50580
    40
  not_member  ("(_/ \<notin> _)" [51, 51] 50)
wenzelm@19656
    41
haftmann@41107
    42
haftmann@32081
    43
text {* Set comprehensions *}
haftmann@32081
    44
haftmann@30531
    45
syntax
wenzelm@35115
    46
  "_Coll" :: "pttrn => bool => 'a set"    ("(1{_./ _})")
haftmann@30531
    47
translations
wenzelm@35115
    48
  "{x. P}" == "CONST Collect (%x. P)"
haftmann@30531
    49
haftmann@32081
    50
syntax
nipkow@51392
    51
  "_Collect" :: "pttrn => 'a set => bool => 'a set"    ("(1{_ :/ _./ _})")
haftmann@32081
    52
syntax (xsymbols)
nipkow@51392
    53
  "_Collect" :: "pttrn => 'a set => bool => 'a set"    ("(1{_ \<in>/ _./ _})")
haftmann@32081
    54
translations
nipkow@51392
    55
  "{p:A. P}" => "CONST Collect (%p. p:A & P)"
haftmann@32081
    56
haftmann@41107
    57
lemma CollectI: "P a \<Longrightarrow> a \<in> {x. P x}"
haftmann@32081
    58
  by simp
haftmann@32081
    59
haftmann@41107
    60
lemma CollectD: "a \<in> {x. P x} \<Longrightarrow> P a"
haftmann@32081
    61
  by simp
haftmann@32081
    62
haftmann@41107
    63
lemma Collect_cong: "(\<And>x. P x = Q x) ==> {x. P x} = {x. Q x}"
haftmann@32081
    64
  by simp
haftmann@32081
    65
haftmann@32117
    66
text {*
haftmann@32117
    67
Simproc for pulling @{text "x=t"} in @{text "{x. \<dots> & x=t & \<dots>}"}
haftmann@32117
    68
to the front (and similarly for @{text "t=x"}):
haftmann@32117
    69
*}
haftmann@32117
    70
wenzelm@42455
    71
simproc_setup defined_Collect ("{x. P x & Q x}") = {*
wenzelm@42459
    72
  fn _ =>
wenzelm@42459
    73
    Quantifier1.rearrange_Collect
wenzelm@42459
    74
     (rtac @{thm Collect_cong} 1 THEN
wenzelm@42455
    75
      rtac @{thm iffI} 1 THEN
wenzelm@42459
    76
      ALLGOALS
wenzelm@42459
    77
        (EVERY' [REPEAT_DETERM o etac @{thm conjE}, DEPTH_SOLVE_1 o ares_tac @{thms conjI}]))
haftmann@32117
    78
*}
haftmann@32117
    79
haftmann@32081
    80
lemmas CollectE = CollectD [elim_format]
haftmann@32081
    81
haftmann@41107
    82
lemma set_eqI:
haftmann@41107
    83
  assumes "\<And>x. x \<in> A \<longleftrightarrow> x \<in> B"
haftmann@41107
    84
  shows "A = B"
haftmann@41107
    85
proof -
haftmann@41107
    86
  from assms have "{x. x \<in> A} = {x. x \<in> B}" by simp
haftmann@41107
    87
  then show ?thesis by simp
haftmann@41107
    88
qed
haftmann@41107
    89
haftmann@41107
    90
lemma set_eq_iff [no_atp]:
haftmann@41107
    91
  "A = B \<longleftrightarrow> (\<forall>x. x \<in> A \<longleftrightarrow> x \<in> B)"
haftmann@41107
    92
  by (auto intro:set_eqI)
haftmann@41107
    93
haftmann@45959
    94
text {* Lifting of predicate class instances *}
haftmann@45959
    95
haftmann@45959
    96
instantiation set :: (type) boolean_algebra
haftmann@45959
    97
begin
haftmann@45959
    98
haftmann@45959
    99
definition less_eq_set where
haftmann@46853
   100
  "A \<le> B \<longleftrightarrow> (\<lambda>x. member x A) \<le> (\<lambda>x. member x B)"
haftmann@45959
   101
haftmann@45959
   102
definition less_set where
haftmann@46853
   103
  "A < B \<longleftrightarrow> (\<lambda>x. member x A) < (\<lambda>x. member x B)"
haftmann@45959
   104
haftmann@45959
   105
definition inf_set where
haftmann@46853
   106
  "A \<sqinter> B = Collect ((\<lambda>x. member x A) \<sqinter> (\<lambda>x. member x B))"
haftmann@45959
   107
haftmann@45959
   108
definition sup_set where
haftmann@46853
   109
  "A \<squnion> B = Collect ((\<lambda>x. member x A) \<squnion> (\<lambda>x. member x B))"
haftmann@45959
   110
haftmann@45959
   111
definition bot_set where
haftmann@46853
   112
  "\<bottom> = Collect \<bottom>"
haftmann@45959
   113
haftmann@45959
   114
definition top_set where
haftmann@46853
   115
  "\<top> = Collect \<top>"
haftmann@45959
   116
haftmann@45959
   117
definition uminus_set where
haftmann@46853
   118
  "- A = Collect (- (\<lambda>x. member x A))"
haftmann@45959
   119
haftmann@45959
   120
definition minus_set where
haftmann@46853
   121
  "A - B = Collect ((\<lambda>x. member x A) - (\<lambda>x. member x B))"
haftmann@45959
   122
haftmann@45959
   123
instance proof
haftmann@45959
   124
qed (simp_all add: less_eq_set_def less_set_def inf_set_def sup_set_def
haftmann@45959
   125
  bot_set_def top_set_def uminus_set_def minus_set_def
haftmann@45959
   126
  less_le_not_le inf_compl_bot sup_compl_top sup_inf_distrib1 diff_eq
noschinl@46882
   127
  set_eqI fun_eq_iff
noschinl@46882
   128
  del: inf_apply sup_apply bot_apply top_apply minus_apply uminus_apply)
haftmann@45959
   129
haftmann@45959
   130
end
haftmann@45959
   131
haftmann@32081
   132
text {* Set enumerations *}
haftmann@30531
   133
haftmann@32264
   134
abbreviation empty :: "'a set" ("{}") where
haftmann@32264
   135
  "{} \<equiv> bot"
haftmann@31456
   136
haftmann@31456
   137
definition insert :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" where
haftmann@32081
   138
  insert_compr: "insert a B = {x. x = a \<or> x \<in> B}"
haftmann@31456
   139
haftmann@31456
   140
syntax
wenzelm@35115
   141
  "_Finset" :: "args => 'a set"    ("{(_)}")
haftmann@31456
   142
translations
wenzelm@35115
   143
  "{x, xs}" == "CONST insert x {xs}"
wenzelm@35115
   144
  "{x}" == "CONST insert x {}"
haftmann@31456
   145
haftmann@32081
   146
haftmann@32081
   147
subsection {* Subsets and bounded quantifiers *}
haftmann@32081
   148
haftmann@32081
   149
abbreviation
haftmann@32081
   150
  subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@32081
   151
  "subset \<equiv> less"
haftmann@32081
   152
haftmann@32081
   153
abbreviation
haftmann@32081
   154
  subset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@32081
   155
  "subset_eq \<equiv> less_eq"
haftmann@32081
   156
haftmann@32081
   157
notation (output)
haftmann@32081
   158
  subset  ("op <") and
nipkow@50580
   159
  subset  ("(_/ < _)" [51, 51] 50) and
haftmann@32081
   160
  subset_eq  ("op <=") and
nipkow@50580
   161
  subset_eq  ("(_/ <= _)" [51, 51] 50)
haftmann@32081
   162
haftmann@32081
   163
notation (xsymbols)
haftmann@32081
   164
  subset  ("op \<subset>") and
nipkow@50580
   165
  subset  ("(_/ \<subset> _)" [51, 51] 50) and
haftmann@32081
   166
  subset_eq  ("op \<subseteq>") and
nipkow@50580
   167
  subset_eq  ("(_/ \<subseteq> _)" [51, 51] 50)
haftmann@32081
   168
haftmann@32081
   169
notation (HTML output)
haftmann@32081
   170
  subset  ("op \<subset>") and
nipkow@50580
   171
  subset  ("(_/ \<subset> _)" [51, 51] 50) and
haftmann@32081
   172
  subset_eq  ("op \<subseteq>") and
nipkow@50580
   173
  subset_eq  ("(_/ \<subseteq> _)" [51, 51] 50)
haftmann@32081
   174
haftmann@32081
   175
abbreviation (input)
haftmann@32081
   176
  supset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@32081
   177
  "supset \<equiv> greater"
haftmann@32081
   178
haftmann@32081
   179
abbreviation (input)
haftmann@32081
   180
  supset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where
haftmann@32081
   181
  "supset_eq \<equiv> greater_eq"
haftmann@32081
   182
haftmann@32081
   183
notation (xsymbols)
haftmann@32081
   184
  supset  ("op \<supset>") and
nipkow@50580
   185
  supset  ("(_/ \<supset> _)" [51, 51] 50) and
haftmann@32081
   186
  supset_eq  ("op \<supseteq>") and
nipkow@50580
   187
  supset_eq  ("(_/ \<supseteq> _)" [51, 51] 50)
haftmann@32081
   188
haftmann@37387
   189
definition Ball :: "'a set \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@37387
   190
  "Ball A P \<longleftrightarrow> (\<forall>x. x \<in> A \<longrightarrow> P x)"   -- "bounded universal quantifiers"
haftmann@32077
   191
haftmann@37387
   192
definition Bex :: "'a set \<Rightarrow> ('a \<Rightarrow> bool) \<Rightarrow> bool" where
haftmann@37387
   193
  "Bex A P \<longleftrightarrow> (\<exists>x. x \<in> A \<and> P x)"   -- "bounded existential quantifiers"
haftmann@32077
   194
haftmann@30531
   195
syntax
haftmann@30531
   196
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3ALL _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   197
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3EX _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   198
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3EX! _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   199
  "_Bleast"     :: "id => 'a set => bool => 'a"           ("(3LEAST _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   200
haftmann@30531
   201
syntax (HOL)
haftmann@30531
   202
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3! _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   203
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3? _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   204
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3?! _:_./ _)" [0, 0, 10] 10)
haftmann@30531
   205
haftmann@30531
   206
syntax (xsymbols)
haftmann@30531
   207
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   208
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   209
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   210
  "_Bleast"     :: "id => 'a set => bool => 'a"           ("(3LEAST_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   211
haftmann@30531
   212
syntax (HTML output)
haftmann@30531
   213
  "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   214
  "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   215
  "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)
haftmann@30531
   216
haftmann@30531
   217
translations
wenzelm@35115
   218
  "ALL x:A. P" == "CONST Ball A (%x. P)"
wenzelm@35115
   219
  "EX x:A. P" == "CONST Bex A (%x. P)"
wenzelm@35115
   220
  "EX! x:A. P" => "EX! x. x:A & P"
haftmann@30531
   221
  "LEAST x:A. P" => "LEAST x. x:A & P"
haftmann@30531
   222
wenzelm@19656
   223
syntax (output)
nipkow@14804
   224
  "_setlessAll" :: "[idt, 'a, bool] => bool"  ("(3ALL _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   225
  "_setlessEx"  :: "[idt, 'a, bool] => bool"  ("(3EX _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   226
  "_setleAll"   :: "[idt, 'a, bool] => bool"  ("(3ALL _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   227
  "_setleEx"    :: "[idt, 'a, bool] => bool"  ("(3EX _<=_./ _)" [0, 0, 10] 10)
webertj@20217
   228
  "_setleEx1"   :: "[idt, 'a, bool] => bool"  ("(3EX! _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   229
nipkow@14804
   230
syntax (xsymbols)
nipkow@14804
   231
  "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   232
  "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   233
  "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   234
  "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)
webertj@20217
   235
  "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   236
wenzelm@19656
   237
syntax (HOL output)
nipkow@14804
   238
  "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   239
  "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)
nipkow@14804
   240
  "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   241
  "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)
webertj@20217
   242
  "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3?! _<=_./ _)" [0, 0, 10] 10)
nipkow@14804
   243
nipkow@14804
   244
syntax (HTML output)
nipkow@14804
   245
  "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   246
  "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)
nipkow@14804
   247
  "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   248
  "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)
webertj@20217
   249
  "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)
nipkow@14804
   250
nipkow@14804
   251
translations
haftmann@30531
   252
 "\<forall>A\<subset>B. P"   =>  "ALL A. A \<subset> B --> P"
haftmann@30531
   253
 "\<exists>A\<subset>B. P"   =>  "EX A. A \<subset> B & P"
haftmann@30531
   254
 "\<forall>A\<subseteq>B. P"   =>  "ALL A. A \<subseteq> B --> P"
haftmann@30531
   255
 "\<exists>A\<subseteq>B. P"   =>  "EX A. A \<subseteq> B & P"
haftmann@30531
   256
 "\<exists>!A\<subseteq>B. P"  =>  "EX! A. A \<subseteq> B & P"
nipkow@14804
   257
nipkow@14804
   258
print_translation {*
nipkow@14804
   259
let
wenzelm@42287
   260
  val All_binder = Mixfix.binder_name @{const_syntax All};
wenzelm@42287
   261
  val Ex_binder = Mixfix.binder_name @{const_syntax Ex};
haftmann@38786
   262
  val impl = @{const_syntax HOL.implies};
haftmann@38795
   263
  val conj = @{const_syntax HOL.conj};
wenzelm@35115
   264
  val sbset = @{const_syntax subset};
wenzelm@35115
   265
  val sbset_eq = @{const_syntax subset_eq};
haftmann@21819
   266
haftmann@21819
   267
  val trans =
wenzelm@35115
   268
   [((All_binder, impl, sbset), @{syntax_const "_setlessAll"}),
wenzelm@35115
   269
    ((All_binder, impl, sbset_eq), @{syntax_const "_setleAll"}),
wenzelm@35115
   270
    ((Ex_binder, conj, sbset), @{syntax_const "_setlessEx"}),
wenzelm@35115
   271
    ((Ex_binder, conj, sbset_eq), @{syntax_const "_setleEx"})];
haftmann@21819
   272
wenzelm@49660
   273
  fun mk v (v', T) c n P =
haftmann@21819
   274
    if v = v' andalso not (Term.exists_subterm (fn Free (x, _) => x = v | _ => false) n)
wenzelm@49660
   275
    then Syntax.const c $ Syntax_Trans.mark_bound_body (v', T) $ n $ P else raise Match;
haftmann@21819
   276
haftmann@21819
   277
  fun tr' q = (q,
wenzelm@46137
   278
        fn [Const (@{syntax_const "_bound"}, _) $ Free (v, Type (@{type_name set}, _)),
wenzelm@35115
   279
            Const (c, _) $
wenzelm@49660
   280
              (Const (d, _) $ (Const (@{syntax_const "_bound"}, _) $ Free (v', T)) $ n) $ P] =>
wenzelm@46137
   281
            (case AList.lookup (op =) trans (q, c, d) of
wenzelm@46137
   282
              NONE => raise Match
wenzelm@49660
   283
            | SOME l => mk v (v', T) l n P)
wenzelm@35115
   284
         | _ => raise Match);
nipkow@14804
   285
in
haftmann@21819
   286
  [tr' All_binder, tr' Ex_binder]
nipkow@14804
   287
end
nipkow@14804
   288
*}
nipkow@14804
   289
haftmann@30531
   290
wenzelm@11979
   291
text {*
wenzelm@11979
   292
  \medskip Translate between @{text "{e | x1...xn. P}"} and @{text
wenzelm@11979
   293
  "{u. EX x1..xn. u = e & P}"}; @{text "{y. EX x1..xn. y = e & P}"} is
wenzelm@11979
   294
  only translated if @{text "[0..n] subset bvs(e)"}.
wenzelm@11979
   295
*}
wenzelm@11979
   296
wenzelm@35115
   297
syntax
wenzelm@35115
   298
  "_Setcompr" :: "'a => idts => bool => 'a set"    ("(1{_ |/_./ _})")
wenzelm@35115
   299
wenzelm@11979
   300
parse_translation {*
wenzelm@11979
   301
  let
wenzelm@42284
   302
    val ex_tr = snd (Syntax_Trans.mk_binder_tr ("EX ", @{const_syntax Ex}));
wenzelm@3947
   303
wenzelm@35115
   304
    fun nvars (Const (@{syntax_const "_idts"}, _) $ _ $ idts) = nvars idts + 1
wenzelm@11979
   305
      | nvars _ = 1;
wenzelm@11979
   306
wenzelm@11979
   307
    fun setcompr_tr [e, idts, b] =
wenzelm@11979
   308
      let
haftmann@38864
   309
        val eq = Syntax.const @{const_syntax HOL.eq} $ Bound (nvars idts) $ e;
haftmann@38795
   310
        val P = Syntax.const @{const_syntax HOL.conj} $ eq $ b;
wenzelm@11979
   311
        val exP = ex_tr [idts, P];
wenzelm@44241
   312
      in Syntax.const @{const_syntax Collect} $ absdummy dummyT exP end;
wenzelm@11979
   313
wenzelm@35115
   314
  in [(@{syntax_const "_Setcompr"}, setcompr_tr)] end;
wenzelm@11979
   315
*}
clasohm@923
   316
wenzelm@35115
   317
print_translation {*
wenzelm@42284
   318
 [Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax Ball} @{syntax_const "_Ball"},
wenzelm@42284
   319
  Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax Bex} @{syntax_const "_Bex"}]
wenzelm@35115
   320
*} -- {* to avoid eta-contraction of body *}
haftmann@30531
   321
nipkow@13763
   322
print_translation {*
nipkow@13763
   323
let
wenzelm@42284
   324
  val ex_tr' = snd (Syntax_Trans.mk_binder_tr' (@{const_syntax Ex}, "DUMMY"));
nipkow@13763
   325
nipkow@13763
   326
  fun setcompr_tr' [Abs (abs as (_, _, P))] =
nipkow@13763
   327
    let
wenzelm@35115
   328
      fun check (Const (@{const_syntax Ex}, _) $ Abs (_, _, P), n) = check (P, n + 1)
haftmann@38795
   329
        | check (Const (@{const_syntax HOL.conj}, _) $
haftmann@38864
   330
              (Const (@{const_syntax HOL.eq}, _) $ Bound m $ e) $ P, n) =
nipkow@13763
   331
            n > 0 andalso m = n andalso not (loose_bvar1 (P, n)) andalso
haftmann@33038
   332
            subset (op =) (0 upto (n - 1), add_loose_bnos (e, 0, []))
wenzelm@35115
   333
        | check _ = false;
clasohm@923
   334
wenzelm@11979
   335
        fun tr' (_ $ abs) =
wenzelm@11979
   336
          let val _ $ idts $ (_ $ (_ $ _ $ e) $ Q) = ex_tr' [abs]
wenzelm@35115
   337
          in Syntax.const @{syntax_const "_Setcompr"} $ e $ idts $ Q end;
wenzelm@35115
   338
    in
wenzelm@35115
   339
      if check (P, 0) then tr' P
wenzelm@35115
   340
      else
wenzelm@35115
   341
        let
wenzelm@42284
   342
          val (x as _ $ Free(xN, _), t) = Syntax_Trans.atomic_abs_tr' abs;
wenzelm@35115
   343
          val M = Syntax.const @{syntax_const "_Coll"} $ x $ t;
wenzelm@35115
   344
        in
wenzelm@35115
   345
          case t of
haftmann@38795
   346
            Const (@{const_syntax HOL.conj}, _) $
haftmann@37677
   347
              (Const (@{const_syntax Set.member}, _) $
wenzelm@35115
   348
                (Const (@{syntax_const "_bound"}, _) $ Free (yN, _)) $ A) $ P =>
wenzelm@35115
   349
            if xN = yN then Syntax.const @{syntax_const "_Collect"} $ x $ A $ P else M
wenzelm@35115
   350
          | _ => M
wenzelm@35115
   351
        end
nipkow@13763
   352
    end;
wenzelm@35115
   353
  in [(@{const_syntax Collect}, setcompr_tr')] end;
wenzelm@11979
   354
*}
wenzelm@11979
   355
wenzelm@42455
   356
simproc_setup defined_Bex ("EX x:A. P x & Q x") = {*
wenzelm@42455
   357
  let
wenzelm@42455
   358
    val unfold_bex_tac = unfold_tac @{thms Bex_def};
wenzelm@42455
   359
    fun prove_bex_tac ss = unfold_bex_tac ss THEN Quantifier1.prove_one_point_ex_tac;
wenzelm@42459
   360
  in fn _ => fn ss => Quantifier1.rearrange_bex (prove_bex_tac ss) ss end
wenzelm@42455
   361
*}
wenzelm@42455
   362
wenzelm@42455
   363
simproc_setup defined_All ("ALL x:A. P x --> Q x") = {*
wenzelm@42455
   364
  let
wenzelm@42455
   365
    val unfold_ball_tac = unfold_tac @{thms Ball_def};
wenzelm@42455
   366
    fun prove_ball_tac ss = unfold_ball_tac ss THEN Quantifier1.prove_one_point_all_tac;
wenzelm@42459
   367
  in fn _ => fn ss => Quantifier1.rearrange_ball (prove_ball_tac ss) ss end
haftmann@32117
   368
*}
haftmann@32117
   369
wenzelm@11979
   370
lemma ballI [intro!]: "(!!x. x:A ==> P x) ==> ALL x:A. P x"
wenzelm@11979
   371
  by (simp add: Ball_def)
wenzelm@11979
   372
wenzelm@11979
   373
lemmas strip = impI allI ballI
wenzelm@11979
   374
wenzelm@11979
   375
lemma bspec [dest?]: "ALL x:A. P x ==> x:A ==> P x"
wenzelm@11979
   376
  by (simp add: Ball_def)
wenzelm@11979
   377
wenzelm@11979
   378
text {*
wenzelm@11979
   379
  Gives better instantiation for bound:
wenzelm@11979
   380
*}
wenzelm@11979
   381
wenzelm@26339
   382
declaration {* fn _ =>
wenzelm@46459
   383
  Classical.map_cs (fn cs => cs addbefore ("bspec", dtac @{thm bspec} THEN' assume_tac))
wenzelm@11979
   384
*}
wenzelm@11979
   385
haftmann@32117
   386
ML {*
haftmann@32117
   387
structure Simpdata =
haftmann@32117
   388
struct
haftmann@32117
   389
haftmann@32117
   390
open Simpdata;
haftmann@32117
   391
haftmann@32117
   392
val mksimps_pairs = [(@{const_name Ball}, @{thms bspec})] @ mksimps_pairs;
haftmann@32117
   393
haftmann@32117
   394
end;
haftmann@32117
   395
haftmann@32117
   396
open Simpdata;
haftmann@32117
   397
*}
haftmann@32117
   398
haftmann@32117
   399
declaration {* fn _ =>
wenzelm@45625
   400
  Simplifier.map_ss (Simplifier.set_mksimps (mksimps mksimps_pairs))
haftmann@32117
   401
*}
haftmann@32117
   402
haftmann@32117
   403
lemma ballE [elim]: "ALL x:A. P x ==> (P x ==> Q) ==> (x ~: A ==> Q) ==> Q"
haftmann@32117
   404
  by (unfold Ball_def) blast
haftmann@32117
   405
wenzelm@11979
   406
lemma bexI [intro]: "P x ==> x:A ==> EX x:A. P x"
wenzelm@11979
   407
  -- {* Normally the best argument order: @{prop "P x"} constrains the
wenzelm@11979
   408
    choice of @{prop "x:A"}. *}
wenzelm@11979
   409
  by (unfold Bex_def) blast
wenzelm@11979
   410
wenzelm@13113
   411
lemma rev_bexI [intro?]: "x:A ==> P x ==> EX x:A. P x"
wenzelm@11979
   412
  -- {* The best argument order when there is only one @{prop "x:A"}. *}
wenzelm@11979
   413
  by (unfold Bex_def) blast
wenzelm@11979
   414
wenzelm@11979
   415
lemma bexCI: "(ALL x:A. ~P x ==> P a) ==> a:A ==> EX x:A. P x"
wenzelm@11979
   416
  by (unfold Bex_def) blast
wenzelm@11979
   417
wenzelm@11979
   418
lemma bexE [elim!]: "EX x:A. P x ==> (!!x. x:A ==> P x ==> Q) ==> Q"
wenzelm@11979
   419
  by (unfold Bex_def) blast
wenzelm@11979
   420
wenzelm@11979
   421
lemma ball_triv [simp]: "(ALL x:A. P) = ((EX x. x:A) --> P)"
wenzelm@11979
   422
  -- {* Trival rewrite rule. *}
wenzelm@11979
   423
  by (simp add: Ball_def)
wenzelm@11979
   424
wenzelm@11979
   425
lemma bex_triv [simp]: "(EX x:A. P) = ((EX x. x:A) & P)"
wenzelm@11979
   426
  -- {* Dual form for existentials. *}
wenzelm@11979
   427
  by (simp add: Bex_def)
wenzelm@11979
   428
wenzelm@11979
   429
lemma bex_triv_one_point1 [simp]: "(EX x:A. x = a) = (a:A)"
wenzelm@11979
   430
  by blast
wenzelm@11979
   431
wenzelm@11979
   432
lemma bex_triv_one_point2 [simp]: "(EX x:A. a = x) = (a:A)"
wenzelm@11979
   433
  by blast
wenzelm@11979
   434
wenzelm@11979
   435
lemma bex_one_point1 [simp]: "(EX x:A. x = a & P x) = (a:A & P a)"
wenzelm@11979
   436
  by blast
wenzelm@11979
   437
wenzelm@11979
   438
lemma bex_one_point2 [simp]: "(EX x:A. a = x & P x) = (a:A & P a)"
wenzelm@11979
   439
  by blast
wenzelm@11979
   440
wenzelm@11979
   441
lemma ball_one_point1 [simp]: "(ALL x:A. x = a --> P x) = (a:A --> P a)"
wenzelm@11979
   442
  by blast
wenzelm@11979
   443
wenzelm@11979
   444
lemma ball_one_point2 [simp]: "(ALL x:A. a = x --> P x) = (a:A --> P a)"
wenzelm@11979
   445
  by blast
wenzelm@11979
   446
haftmann@43818
   447
lemma ball_conj_distrib:
haftmann@43818
   448
  "(\<forall>x\<in>A. P x \<and> Q x) \<longleftrightarrow> ((\<forall>x\<in>A. P x) \<and> (\<forall>x\<in>A. Q x))"
haftmann@43818
   449
  by blast
haftmann@43818
   450
haftmann@43818
   451
lemma bex_disj_distrib:
haftmann@43818
   452
  "(\<exists>x\<in>A. P x \<or> Q x) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<or> (\<exists>x\<in>A. Q x))"
haftmann@43818
   453
  by blast
haftmann@43818
   454
wenzelm@11979
   455
haftmann@32081
   456
text {* Congruence rules *}
wenzelm@11979
   457
berghofe@16636
   458
lemma ball_cong:
wenzelm@11979
   459
  "A = B ==> (!!x. x:B ==> P x = Q x) ==>
wenzelm@11979
   460
    (ALL x:A. P x) = (ALL x:B. Q x)"
wenzelm@11979
   461
  by (simp add: Ball_def)
wenzelm@11979
   462
berghofe@16636
   463
lemma strong_ball_cong [cong]:
berghofe@16636
   464
  "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>
berghofe@16636
   465
    (ALL x:A. P x) = (ALL x:B. Q x)"
berghofe@16636
   466
  by (simp add: simp_implies_def Ball_def)
berghofe@16636
   467
berghofe@16636
   468
lemma bex_cong:
wenzelm@11979
   469
  "A = B ==> (!!x. x:B ==> P x = Q x) ==>
wenzelm@11979
   470
    (EX x:A. P x) = (EX x:B. Q x)"
wenzelm@11979
   471
  by (simp add: Bex_def cong: conj_cong)
regensbu@1273
   472
berghofe@16636
   473
lemma strong_bex_cong [cong]:
berghofe@16636
   474
  "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>
berghofe@16636
   475
    (EX x:A. P x) = (EX x:B. Q x)"
berghofe@16636
   476
  by (simp add: simp_implies_def Bex_def cong: conj_cong)
berghofe@16636
   477
haftmann@30531
   478
haftmann@32081
   479
subsection {* Basic operations *}
haftmann@32081
   480
haftmann@30531
   481
subsubsection {* Subsets *}
haftmann@30531
   482
paulson@33022
   483
lemma subsetI [intro!]: "(\<And>x. x \<in> A \<Longrightarrow> x \<in> B) \<Longrightarrow> A \<subseteq> B"
haftmann@45959
   484
  by (simp add: less_eq_set_def le_fun_def)
haftmann@30352
   485
wenzelm@11979
   486
text {*
haftmann@30531
   487
  \medskip Map the type @{text "'a set => anything"} to just @{typ
haftmann@30531
   488
  'a}; for overloading constants whose first argument has type @{typ
haftmann@30531
   489
  "'a set"}.
wenzelm@11979
   490
*}
wenzelm@11979
   491
haftmann@30596
   492
lemma subsetD [elim, intro?]: "A \<subseteq> B ==> c \<in> A ==> c \<in> B"
haftmann@45959
   493
  by (simp add: less_eq_set_def le_fun_def)
haftmann@30531
   494
  -- {* Rule in Modus Ponens style. *}
haftmann@30531
   495
blanchet@35828
   496
lemma rev_subsetD [no_atp,intro?]: "c \<in> A ==> A \<subseteq> B ==> c \<in> B"
haftmann@30531
   497
  -- {* The same, with reversed premises for use with @{text erule} --
haftmann@30531
   498
      cf @{text rev_mp}. *}
haftmann@30531
   499
  by (rule subsetD)
haftmann@30531
   500
wenzelm@11979
   501
text {*
haftmann@30531
   502
  \medskip Converts @{prop "A \<subseteq> B"} to @{prop "x \<in> A ==> x \<in> B"}.
haftmann@30531
   503
*}
haftmann@30531
   504
blanchet@35828
   505
lemma subsetCE [no_atp,elim]: "A \<subseteq> B ==> (c \<notin> A ==> P) ==> (c \<in> B ==> P) ==> P"
haftmann@30531
   506
  -- {* Classical elimination rule. *}
haftmann@45959
   507
  by (auto simp add: less_eq_set_def le_fun_def)
haftmann@30531
   508
haftmann@47398
   509
lemma subset_eq [no_atp]: "A \<le> B = (\<forall>x\<in>A. x \<in> B)" by blast
wenzelm@2388
   510
blanchet@35828
   511
lemma contra_subsetD [no_atp]: "A \<subseteq> B ==> c \<notin> B ==> c \<notin> A"
haftmann@30531
   512
  by blast
haftmann@30531
   513
huffman@45121
   514
lemma subset_refl: "A \<subseteq> A"
huffman@45121
   515
  by (fact order_refl) (* already [iff] *)
haftmann@30531
   516
haftmann@30531
   517
lemma subset_trans: "A \<subseteq> B ==> B \<subseteq> C ==> A \<subseteq> C"
haftmann@32081
   518
  by (fact order_trans)
haftmann@32081
   519
haftmann@32081
   520
lemma set_rev_mp: "x:A ==> A \<subseteq> B ==> x:B"
haftmann@32081
   521
  by (rule subsetD)
haftmann@32081
   522
haftmann@32081
   523
lemma set_mp: "A \<subseteq> B ==> x:A ==> x:B"
haftmann@32081
   524
  by (rule subsetD)
haftmann@32081
   525
haftmann@46146
   526
lemma subset_not_subset_eq [code]:
haftmann@46146
   527
  "A \<subset> B \<longleftrightarrow> A \<subseteq> B \<and> \<not> B \<subseteq> A"
haftmann@46146
   528
  by (fact less_le_not_le)
haftmann@46146
   529
paulson@33044
   530
lemma eq_mem_trans: "a=b ==> b \<in> A ==> a \<in> A"
paulson@33044
   531
  by simp
paulson@33044
   532
haftmann@32081
   533
lemmas basic_trans_rules [trans] =
paulson@33044
   534
  order_trans_rules set_rev_mp set_mp eq_mem_trans
haftmann@30531
   535
haftmann@30531
   536
haftmann@30531
   537
subsubsection {* Equality *}
haftmann@30531
   538
haftmann@30531
   539
lemma subset_antisym [intro!]: "A \<subseteq> B ==> B \<subseteq> A ==> A = B"
haftmann@30531
   540
  -- {* Anti-symmetry of the subset relation. *}
nipkow@39302
   541
  by (iprover intro: set_eqI subsetD)
haftmann@30531
   542
haftmann@30531
   543
text {*
haftmann@30531
   544
  \medskip Equality rules from ZF set theory -- are they appropriate
haftmann@30531
   545
  here?
haftmann@30531
   546
*}
haftmann@30531
   547
haftmann@30531
   548
lemma equalityD1: "A = B ==> A \<subseteq> B"
krauss@34209
   549
  by simp
haftmann@30531
   550
haftmann@30531
   551
lemma equalityD2: "A = B ==> B \<subseteq> A"
krauss@34209
   552
  by simp
haftmann@30531
   553
haftmann@30531
   554
text {*
haftmann@30531
   555
  \medskip Be careful when adding this to the claset as @{text
haftmann@30531
   556
  subset_empty} is in the simpset: @{prop "A = {}"} goes to @{prop "{}
haftmann@30531
   557
  \<subseteq> A"} and @{prop "A \<subseteq> {}"} and then back to @{prop "A = {}"}!
haftmann@30352
   558
*}
haftmann@30352
   559
haftmann@30531
   560
lemma equalityE: "A = B ==> (A \<subseteq> B ==> B \<subseteq> A ==> P) ==> P"
krauss@34209
   561
  by simp
haftmann@30531
   562
haftmann@30531
   563
lemma equalityCE [elim]:
haftmann@30531
   564
    "A = B ==> (c \<in> A ==> c \<in> B ==> P) ==> (c \<notin> A ==> c \<notin> B ==> P) ==> P"
haftmann@30531
   565
  by blast
haftmann@30531
   566
haftmann@30531
   567
lemma eqset_imp_iff: "A = B ==> (x : A) = (x : B)"
haftmann@30531
   568
  by simp
haftmann@30531
   569
haftmann@30531
   570
lemma eqelem_imp_iff: "x = y ==> (x : A) = (y : A)"
haftmann@30531
   571
  by simp
haftmann@30531
   572
haftmann@30531
   573
haftmann@41082
   574
subsubsection {* The empty set *}
haftmann@41082
   575
haftmann@41082
   576
lemma empty_def:
haftmann@41082
   577
  "{} = {x. False}"
haftmann@45959
   578
  by (simp add: bot_set_def bot_fun_def)
haftmann@41082
   579
haftmann@41082
   580
lemma empty_iff [simp]: "(c : {}) = False"
haftmann@41082
   581
  by (simp add: empty_def)
haftmann@41082
   582
haftmann@41082
   583
lemma emptyE [elim!]: "a : {} ==> P"
haftmann@41082
   584
  by simp
haftmann@41082
   585
haftmann@41082
   586
lemma empty_subsetI [iff]: "{} \<subseteq> A"
haftmann@41082
   587
    -- {* One effect is to delete the ASSUMPTION @{prop "{} <= A"} *}
haftmann@41082
   588
  by blast
haftmann@41082
   589
haftmann@41082
   590
lemma equals0I: "(!!y. y \<in> A ==> False) ==> A = {}"
haftmann@41082
   591
  by blast
haftmann@41082
   592
haftmann@41082
   593
lemma equals0D: "A = {} ==> a \<notin> A"
haftmann@41082
   594
    -- {* Use for reasoning about disjointness: @{text "A Int B = {}"} *}
haftmann@41082
   595
  by blast
haftmann@41082
   596
haftmann@41082
   597
lemma ball_empty [simp]: "Ball {} P = True"
haftmann@41082
   598
  by (simp add: Ball_def)
haftmann@41082
   599
haftmann@41082
   600
lemma bex_empty [simp]: "Bex {} P = False"
haftmann@41082
   601
  by (simp add: Bex_def)
haftmann@41082
   602
haftmann@41082
   603
haftmann@30531
   604
subsubsection {* The universal set -- UNIV *}
haftmann@30531
   605
haftmann@32264
   606
abbreviation UNIV :: "'a set" where
haftmann@32264
   607
  "UNIV \<equiv> top"
haftmann@32135
   608
haftmann@32135
   609
lemma UNIV_def:
haftmann@32117
   610
  "UNIV = {x. True}"
haftmann@45959
   611
  by (simp add: top_set_def top_fun_def)
haftmann@32081
   612
haftmann@30531
   613
lemma UNIV_I [simp]: "x : UNIV"
haftmann@30531
   614
  by (simp add: UNIV_def)
haftmann@30531
   615
haftmann@30531
   616
declare UNIV_I [intro]  -- {* unsafe makes it less likely to cause problems *}
haftmann@30531
   617
haftmann@30531
   618
lemma UNIV_witness [intro?]: "EX x. x : UNIV"
haftmann@30531
   619
  by simp
haftmann@30531
   620
huffman@45121
   621
lemma subset_UNIV: "A \<subseteq> UNIV"
huffman@45121
   622
  by (fact top_greatest) (* already simp *)
haftmann@30531
   623
haftmann@30531
   624
text {*
haftmann@30531
   625
  \medskip Eta-contracting these two rules (to remove @{text P})
haftmann@30531
   626
  causes them to be ignored because of their interaction with
haftmann@30531
   627
  congruence rules.
haftmann@30531
   628
*}
haftmann@30531
   629
haftmann@30531
   630
lemma ball_UNIV [simp]: "Ball UNIV P = All P"
haftmann@30531
   631
  by (simp add: Ball_def)
haftmann@30531
   632
haftmann@30531
   633
lemma bex_UNIV [simp]: "Bex UNIV P = Ex P"
haftmann@30531
   634
  by (simp add: Bex_def)
haftmann@30531
   635
haftmann@30531
   636
lemma UNIV_eq_I: "(\<And>x. x \<in> A) \<Longrightarrow> UNIV = A"
haftmann@30531
   637
  by auto
haftmann@30531
   638
haftmann@30531
   639
lemma UNIV_not_empty [iff]: "UNIV ~= {}"
haftmann@30531
   640
  by (blast elim: equalityE)
haftmann@30531
   641
nipkow@51334
   642
lemma empty_not_UNIV[simp]: "{} \<noteq> UNIV"
nipkow@51334
   643
by blast
nipkow@51334
   644
haftmann@30531
   645
haftmann@30531
   646
subsubsection {* The Powerset operator -- Pow *}
haftmann@30531
   647
haftmann@32077
   648
definition Pow :: "'a set => 'a set set" where
haftmann@32077
   649
  Pow_def: "Pow A = {B. B \<le> A}"
haftmann@32077
   650
haftmann@30531
   651
lemma Pow_iff [iff]: "(A \<in> Pow B) = (A \<subseteq> B)"
haftmann@30531
   652
  by (simp add: Pow_def)
haftmann@30531
   653
haftmann@30531
   654
lemma PowI: "A \<subseteq> B ==> A \<in> Pow B"
haftmann@30531
   655
  by (simp add: Pow_def)
haftmann@30531
   656
haftmann@30531
   657
lemma PowD: "A \<in> Pow B ==> A \<subseteq> B"
haftmann@30531
   658
  by (simp add: Pow_def)
haftmann@30531
   659
haftmann@30531
   660
lemma Pow_bottom: "{} \<in> Pow B"
haftmann@30531
   661
  by simp
haftmann@30531
   662
haftmann@30531
   663
lemma Pow_top: "A \<in> Pow A"
krauss@34209
   664
  by simp
haftmann@30531
   665
hoelzl@40703
   666
lemma Pow_not_empty: "Pow A \<noteq> {}"
hoelzl@40703
   667
  using Pow_top by blast
haftmann@30531
   668
haftmann@41076
   669
haftmann@30531
   670
subsubsection {* Set complement *}
haftmann@30531
   671
haftmann@30531
   672
lemma Compl_iff [simp]: "(c \<in> -A) = (c \<notin> A)"
haftmann@45959
   673
  by (simp add: fun_Compl_def uminus_set_def)
haftmann@30531
   674
haftmann@30531
   675
lemma ComplI [intro!]: "(c \<in> A ==> False) ==> c \<in> -A"
haftmann@45959
   676
  by (simp add: fun_Compl_def uminus_set_def) blast
clasohm@923
   677
wenzelm@11979
   678
text {*
haftmann@30531
   679
  \medskip This form, with negated conclusion, works well with the
haftmann@30531
   680
  Classical prover.  Negated assumptions behave like formulae on the
haftmann@30531
   681
  right side of the notional turnstile ... *}
haftmann@30531
   682
haftmann@30531
   683
lemma ComplD [dest!]: "c : -A ==> c~:A"
haftmann@45959
   684
  by simp
haftmann@30531
   685
haftmann@30531
   686
lemmas ComplE = ComplD [elim_format]
haftmann@30531
   687
haftmann@45959
   688
lemma Compl_eq: "- A = {x. ~ x : A}"
haftmann@45959
   689
  by blast
haftmann@30531
   690
haftmann@30531
   691
haftmann@41082
   692
subsubsection {* Binary intersection *}
haftmann@41082
   693
haftmann@41082
   694
abbreviation inter :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Int" 70) where
haftmann@41082
   695
  "op Int \<equiv> inf"
haftmann@41082
   696
haftmann@41082
   697
notation (xsymbols)
haftmann@41082
   698
  inter  (infixl "\<inter>" 70)
haftmann@41082
   699
haftmann@41082
   700
notation (HTML output)
haftmann@41082
   701
  inter  (infixl "\<inter>" 70)
haftmann@41082
   702
haftmann@41082
   703
lemma Int_def:
haftmann@41082
   704
  "A \<inter> B = {x. x \<in> A \<and> x \<in> B}"
haftmann@45959
   705
  by (simp add: inf_set_def inf_fun_def)
haftmann@41082
   706
haftmann@41082
   707
lemma Int_iff [simp]: "(c : A Int B) = (c:A & c:B)"
haftmann@41082
   708
  by (unfold Int_def) blast
haftmann@41082
   709
haftmann@41082
   710
lemma IntI [intro!]: "c:A ==> c:B ==> c : A Int B"
haftmann@41082
   711
  by simp
haftmann@41082
   712
haftmann@41082
   713
lemma IntD1: "c : A Int B ==> c:A"
haftmann@41082
   714
  by simp
haftmann@41082
   715
haftmann@41082
   716
lemma IntD2: "c : A Int B ==> c:B"
haftmann@41082
   717
  by simp
haftmann@41082
   718
haftmann@41082
   719
lemma IntE [elim!]: "c : A Int B ==> (c:A ==> c:B ==> P) ==> P"
haftmann@41082
   720
  by simp
haftmann@41082
   721
haftmann@41082
   722
lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"
haftmann@41082
   723
  by (fact mono_inf)
haftmann@41082
   724
haftmann@41082
   725
haftmann@41082
   726
subsubsection {* Binary union *}
haftmann@30531
   727
haftmann@32683
   728
abbreviation union :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Un" 65) where
haftmann@41076
   729
  "union \<equiv> sup"
haftmann@32081
   730
haftmann@32081
   731
notation (xsymbols)
haftmann@32135
   732
  union  (infixl "\<union>" 65)
haftmann@32081
   733
haftmann@32081
   734
notation (HTML output)
haftmann@32135
   735
  union  (infixl "\<union>" 65)
haftmann@32135
   736
haftmann@32135
   737
lemma Un_def:
haftmann@32135
   738
  "A \<union> B = {x. x \<in> A \<or> x \<in> B}"
haftmann@45959
   739
  by (simp add: sup_set_def sup_fun_def)
haftmann@32081
   740
haftmann@30531
   741
lemma Un_iff [simp]: "(c : A Un B) = (c:A | c:B)"
haftmann@30531
   742
  by (unfold Un_def) blast
haftmann@30531
   743
haftmann@30531
   744
lemma UnI1 [elim?]: "c:A ==> c : A Un B"
haftmann@30531
   745
  by simp
haftmann@30531
   746
haftmann@30531
   747
lemma UnI2 [elim?]: "c:B ==> c : A Un B"
haftmann@30531
   748
  by simp
haftmann@30531
   749
haftmann@30531
   750
text {*
haftmann@30531
   751
  \medskip Classical introduction rule: no commitment to @{prop A} vs
haftmann@30531
   752
  @{prop B}.
wenzelm@11979
   753
*}
wenzelm@11979
   754
haftmann@30531
   755
lemma UnCI [intro!]: "(c~:B ==> c:A) ==> c : A Un B"
haftmann@30531
   756
  by auto
haftmann@30531
   757
haftmann@30531
   758
lemma UnE [elim!]: "c : A Un B ==> (c:A ==> P) ==> (c:B ==> P) ==> P"
haftmann@30531
   759
  by (unfold Un_def) blast
haftmann@30531
   760
haftmann@32117
   761
lemma insert_def: "insert a B = {x. x = a} \<union> B"
haftmann@45959
   762
  by (simp add: insert_compr Un_def)
haftmann@32081
   763
haftmann@32081
   764
lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"
haftmann@32683
   765
  by (fact mono_sup)
haftmann@32081
   766
haftmann@30531
   767
haftmann@30531
   768
subsubsection {* Set difference *}
haftmann@30531
   769
haftmann@30531
   770
lemma Diff_iff [simp]: "(c : A - B) = (c:A & c~:B)"
haftmann@45959
   771
  by (simp add: minus_set_def fun_diff_def)
haftmann@30531
   772
haftmann@30531
   773
lemma DiffI [intro!]: "c : A ==> c ~: B ==> c : A - B"
haftmann@30531
   774
  by simp
haftmann@30531
   775
haftmann@30531
   776
lemma DiffD1: "c : A - B ==> c : A"
haftmann@30531
   777
  by simp
haftmann@30531
   778
haftmann@30531
   779
lemma DiffD2: "c : A - B ==> c : B ==> P"
haftmann@30531
   780
  by simp
haftmann@30531
   781
haftmann@30531
   782
lemma DiffE [elim!]: "c : A - B ==> (c:A ==> c~:B ==> P) ==> P"
haftmann@30531
   783
  by simp
haftmann@30531
   784
haftmann@30531
   785
lemma set_diff_eq: "A - B = {x. x : A & ~ x : B}" by blast
haftmann@30531
   786
haftmann@30531
   787
lemma Compl_eq_Diff_UNIV: "-A = (UNIV - A)"
haftmann@30531
   788
by blast
haftmann@30531
   789
haftmann@30531
   790
haftmann@31456
   791
subsubsection {* Augmenting a set -- @{const insert} *}
haftmann@30531
   792
haftmann@30531
   793
lemma insert_iff [simp]: "(a : insert b A) = (a = b | a:A)"
haftmann@30531
   794
  by (unfold insert_def) blast
haftmann@30531
   795
haftmann@30531
   796
lemma insertI1: "a : insert a B"
haftmann@30531
   797
  by simp
haftmann@30531
   798
haftmann@30531
   799
lemma insertI2: "a : B ==> a : insert b B"
haftmann@30531
   800
  by simp
haftmann@30531
   801
haftmann@30531
   802
lemma insertE [elim!]: "a : insert b A ==> (a = b ==> P) ==> (a:A ==> P) ==> P"
haftmann@30531
   803
  by (unfold insert_def) blast
haftmann@30531
   804
haftmann@30531
   805
lemma insertCI [intro!]: "(a~:B ==> a = b) ==> a: insert b B"
haftmann@30531
   806
  -- {* Classical introduction rule. *}
haftmann@30531
   807
  by auto
haftmann@30531
   808
haftmann@30531
   809
lemma subset_insert_iff: "(A \<subseteq> insert x B) = (if x:A then A - {x} \<subseteq> B else A \<subseteq> B)"
haftmann@30531
   810
  by auto
haftmann@30531
   811
haftmann@30531
   812
lemma set_insert:
haftmann@30531
   813
  assumes "x \<in> A"
haftmann@30531
   814
  obtains B where "A = insert x B" and "x \<notin> B"
haftmann@30531
   815
proof
haftmann@30531
   816
  from assms show "A = insert x (A - {x})" by blast
haftmann@30531
   817
next
haftmann@30531
   818
  show "x \<notin> A - {x}" by blast
haftmann@30531
   819
qed
haftmann@30531
   820
haftmann@30531
   821
lemma insert_ident: "x ~: A ==> x ~: B ==> (insert x A = insert x B) = (A = B)"
haftmann@30531
   822
by auto
haftmann@30531
   823
nipkow@44744
   824
lemma insert_eq_iff: assumes "a \<notin> A" "b \<notin> B"
nipkow@44744
   825
shows "insert a A = insert b B \<longleftrightarrow>
nipkow@44744
   826
  (if a=b then A=B else \<exists>C. A = insert b C \<and> b \<notin> C \<and> B = insert a C \<and> a \<notin> C)"
nipkow@44744
   827
  (is "?L \<longleftrightarrow> ?R")
nipkow@44744
   828
proof
nipkow@44744
   829
  assume ?L
nipkow@44744
   830
  show ?R
nipkow@44744
   831
  proof cases
nipkow@44744
   832
    assume "a=b" with assms `?L` show ?R by (simp add: insert_ident)
nipkow@44744
   833
  next
nipkow@44744
   834
    assume "a\<noteq>b"
nipkow@44744
   835
    let ?C = "A - {b}"
nipkow@44744
   836
    have "A = insert b ?C \<and> b \<notin> ?C \<and> B = insert a ?C \<and> a \<notin> ?C"
nipkow@44744
   837
      using assms `?L` `a\<noteq>b` by auto
nipkow@44744
   838
    thus ?R using `a\<noteq>b` by auto
nipkow@44744
   839
  qed
nipkow@44744
   840
next
haftmann@46128
   841
  assume ?R thus ?L by (auto split: if_splits)
nipkow@44744
   842
qed
nipkow@44744
   843
haftmann@30531
   844
subsubsection {* Singletons, using insert *}
haftmann@30531
   845
blanchet@35828
   846
lemma singletonI [intro!,no_atp]: "a : {a}"
haftmann@30531
   847
    -- {* Redundant? But unlike @{text insertCI}, it proves the subgoal immediately! *}
haftmann@30531
   848
  by (rule insertI1)
haftmann@30531
   849
blanchet@35828
   850
lemma singletonD [dest!,no_atp]: "b : {a} ==> b = a"
haftmann@30531
   851
  by blast
haftmann@30531
   852
haftmann@30531
   853
lemmas singletonE = singletonD [elim_format]
haftmann@30531
   854
haftmann@30531
   855
lemma singleton_iff: "(b : {a}) = (b = a)"
haftmann@30531
   856
  by blast
haftmann@30531
   857
haftmann@30531
   858
lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"
haftmann@30531
   859
  by blast
haftmann@30531
   860
blanchet@35828
   861
lemma singleton_insert_inj_eq [iff,no_atp]:
haftmann@30531
   862
     "({b} = insert a A) = (a = b & A \<subseteq> {b})"
haftmann@30531
   863
  by blast
haftmann@30531
   864
blanchet@35828
   865
lemma singleton_insert_inj_eq' [iff,no_atp]:
haftmann@30531
   866
     "(insert a A = {b}) = (a = b & A \<subseteq> {b})"
haftmann@30531
   867
  by blast
haftmann@30531
   868
haftmann@30531
   869
lemma subset_singletonD: "A \<subseteq> {x} ==> A = {} | A = {x}"
haftmann@30531
   870
  by fast
haftmann@30531
   871
haftmann@30531
   872
lemma singleton_conv [simp]: "{x. x = a} = {a}"
haftmann@30531
   873
  by blast
haftmann@30531
   874
haftmann@30531
   875
lemma singleton_conv2 [simp]: "{x. a = x} = {a}"
haftmann@30531
   876
  by blast
haftmann@30531
   877
bulwahn@46504
   878
lemma diff_single_insert: "A - {x} \<subseteq> B ==> A \<subseteq> insert x B"
haftmann@30531
   879
  by blast
haftmann@30531
   880
haftmann@30531
   881
lemma doubleton_eq_iff: "({a,b} = {c,d}) = (a=c & b=d | a=d & b=c)"
haftmann@30531
   882
  by (blast elim: equalityE)
haftmann@30531
   883
wenzelm@11979
   884
haftmann@32077
   885
subsubsection {* Image of a set under a function *}
haftmann@32077
   886
haftmann@32077
   887
text {*
haftmann@32077
   888
  Frequently @{term b} does not have the syntactic form of @{term "f x"}.
haftmann@32077
   889
*}
haftmann@32077
   890
haftmann@32077
   891
definition image :: "('a => 'b) => 'a set => 'b set" (infixr "`" 90) where
blanchet@35828
   892
  image_def [no_atp]: "f ` A = {y. EX x:A. y = f(x)}"
haftmann@32077
   893
haftmann@32077
   894
abbreviation
haftmann@32077
   895
  range :: "('a => 'b) => 'b set" where -- "of function"
haftmann@32077
   896
  "range f == f ` UNIV"
haftmann@32077
   897
haftmann@32077
   898
lemma image_eqI [simp, intro]: "b = f x ==> x:A ==> b : f`A"
haftmann@32077
   899
  by (unfold image_def) blast
haftmann@32077
   900
haftmann@32077
   901
lemma imageI: "x : A ==> f x : f ` A"
haftmann@32077
   902
  by (rule image_eqI) (rule refl)
haftmann@32077
   903
haftmann@32077
   904
lemma rev_image_eqI: "x:A ==> b = f x ==> b : f`A"
haftmann@32077
   905
  -- {* This version's more effective when we already have the
haftmann@32077
   906
    required @{term x}. *}
haftmann@32077
   907
  by (unfold image_def) blast
haftmann@32077
   908
haftmann@32077
   909
lemma imageE [elim!]:
haftmann@32077
   910
  "b : (%x. f x)`A ==> (!!x. b = f x ==> x:A ==> P) ==> P"
haftmann@32077
   911
  -- {* The eta-expansion gives variable-name preservation. *}
haftmann@32077
   912
  by (unfold image_def) blast
haftmann@32077
   913
haftmann@51173
   914
lemma Compr_image_eq:
haftmann@51173
   915
  "{x \<in> f ` A. P x} = f ` {x \<in> A. P (f x)}"
haftmann@51173
   916
  by auto
haftmann@51173
   917
haftmann@32077
   918
lemma image_Un: "f`(A Un B) = f`A Un f`B"
haftmann@32077
   919
  by blast
haftmann@32077
   920
haftmann@32077
   921
lemma image_iff: "(z : f`A) = (EX x:A. z = f x)"
haftmann@32077
   922
  by blast
haftmann@32077
   923
blanchet@38648
   924
lemma image_subset_iff [no_atp]: "(f`A \<subseteq> B) = (\<forall>x\<in>A. f x \<in> B)"
haftmann@32077
   925
  -- {* This rewrite rule would confuse users if made default. *}
haftmann@32077
   926
  by blast
haftmann@32077
   927
haftmann@32077
   928
lemma subset_image_iff: "(B \<subseteq> f`A) = (EX AA. AA \<subseteq> A & B = f`AA)"
haftmann@32077
   929
  apply safe
haftmann@32077
   930
   prefer 2 apply fast
haftmann@32077
   931
  apply (rule_tac x = "{a. a : A & f a : B}" in exI, fast)
haftmann@32077
   932
  done
haftmann@32077
   933
haftmann@32077
   934
lemma image_subsetI: "(!!x. x \<in> A ==> f x \<in> B) ==> f`A \<subseteq> B"
haftmann@32077
   935
  -- {* Replaces the three steps @{text subsetI}, @{text imageE},
haftmann@32077
   936
    @{text hypsubst}, but breaks too many existing proofs. *}
haftmann@32077
   937
  by blast
wenzelm@11979
   938
wenzelm@11979
   939
text {*
haftmann@32077
   940
  \medskip Range of a function -- just a translation for image!
haftmann@32077
   941
*}
haftmann@32077
   942
haftmann@43898
   943
lemma image_ident [simp]: "(%x. x) ` Y = Y"
haftmann@43898
   944
  by blast
haftmann@43898
   945
haftmann@32077
   946
lemma range_eqI: "b = f x ==> b \<in> range f"
haftmann@32077
   947
  by simp
haftmann@32077
   948
haftmann@32077
   949
lemma rangeI: "f x \<in> range f"
haftmann@32077
   950
  by simp
haftmann@32077
   951
haftmann@32077
   952
lemma rangeE [elim?]: "b \<in> range (\<lambda>x. f x) ==> (!!x. b = f x ==> P) ==> P"
haftmann@32077
   953
  by blast
haftmann@32077
   954
haftmann@32117
   955
subsubsection {* Some rules with @{text "if"} *}
haftmann@32081
   956
haftmann@32081
   957
text{* Elimination of @{text"{x. \<dots> & x=t & \<dots>}"}. *}
haftmann@32081
   958
haftmann@32081
   959
lemma Collect_conv_if: "{x. x=a & P x} = (if P a then {a} else {})"
haftmann@32117
   960
  by auto
haftmann@32081
   961
haftmann@32081
   962
lemma Collect_conv_if2: "{x. a=x & P x} = (if P a then {a} else {})"
haftmann@32117
   963
  by auto
haftmann@32081
   964
haftmann@32081
   965
text {*
haftmann@32081
   966
  Rewrite rules for boolean case-splitting: faster than @{text
haftmann@32081
   967
  "split_if [split]"}.
haftmann@32081
   968
*}
haftmann@32081
   969
haftmann@32081
   970
lemma split_if_eq1: "((if Q then x else y) = b) = ((Q --> x = b) & (~ Q --> y = b))"
haftmann@32081
   971
  by (rule split_if)
haftmann@32081
   972
haftmann@32081
   973
lemma split_if_eq2: "(a = (if Q then x else y)) = ((Q --> a = x) & (~ Q --> a = y))"
haftmann@32081
   974
  by (rule split_if)
haftmann@32081
   975
haftmann@32081
   976
text {*
haftmann@32081
   977
  Split ifs on either side of the membership relation.  Not for @{text
haftmann@32081
   978
  "[simp]"} -- can cause goals to blow up!
haftmann@32081
   979
*}
haftmann@32081
   980
haftmann@32081
   981
lemma split_if_mem1: "((if Q then x else y) : b) = ((Q --> x : b) & (~ Q --> y : b))"
haftmann@32081
   982
  by (rule split_if)
haftmann@32081
   983
haftmann@32081
   984
lemma split_if_mem2: "(a : (if Q then x else y)) = ((Q --> a : x) & (~ Q --> a : y))"
haftmann@32081
   985
  by (rule split_if [where P="%S. a : S"])
haftmann@32081
   986
haftmann@32081
   987
lemmas split_ifs = if_bool_eq_conj split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2
haftmann@32081
   988
haftmann@32081
   989
(*Would like to add these, but the existing code only searches for the
haftmann@37677
   990
  outer-level constant, which in this case is just Set.member; we instead need
haftmann@32081
   991
  to use term-nets to associate patterns with rules.  Also, if a rule fails to
haftmann@32081
   992
  apply, then the formula should be kept.
haftmann@34974
   993
  [("uminus", Compl_iff RS iffD1), ("minus", [Diff_iff RS iffD1]),
haftmann@32081
   994
   ("Int", [IntD1,IntD2]),
haftmann@32081
   995
   ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]
haftmann@32081
   996
 *)
haftmann@32081
   997
haftmann@32081
   998
haftmann@32135
   999
subsection {* Further operations and lemmas *}
haftmann@32135
  1000
haftmann@32135
  1001
subsubsection {* The ``proper subset'' relation *}
haftmann@32135
  1002
blanchet@35828
  1003
lemma psubsetI [intro!,no_atp]: "A \<subseteq> B ==> A \<noteq> B ==> A \<subset> B"
haftmann@32135
  1004
  by (unfold less_le) blast
haftmann@32135
  1005
blanchet@35828
  1006
lemma psubsetE [elim!,no_atp]: 
haftmann@32135
  1007
    "[|A \<subset> B;  [|A \<subseteq> B; ~ (B\<subseteq>A)|] ==> R|] ==> R"
haftmann@32135
  1008
  by (unfold less_le) blast
haftmann@32135
  1009
haftmann@32135
  1010
lemma psubset_insert_iff:
haftmann@32135
  1011
  "(A \<subset> insert x B) = (if x \<in> B then A \<subset> B else if x \<in> A then A - {x} \<subset> B else A \<subseteq> B)"
haftmann@32135
  1012
  by (auto simp add: less_le subset_insert_iff)
haftmann@32135
  1013
haftmann@32135
  1014
lemma psubset_eq: "(A \<subset> B) = (A \<subseteq> B & A \<noteq> B)"
haftmann@32135
  1015
  by (simp only: less_le)
haftmann@32135
  1016
haftmann@32135
  1017
lemma psubset_imp_subset: "A \<subset> B ==> A \<subseteq> B"
haftmann@32135
  1018
  by (simp add: psubset_eq)
haftmann@32135
  1019
haftmann@32135
  1020
lemma psubset_trans: "[| A \<subset> B; B \<subset> C |] ==> A \<subset> C"
haftmann@32135
  1021
apply (unfold less_le)
haftmann@32135
  1022
apply (auto dest: subset_antisym)
haftmann@32135
  1023
done
haftmann@32135
  1024
haftmann@32135
  1025
lemma psubsetD: "[| A \<subset> B; c \<in> A |] ==> c \<in> B"
haftmann@32135
  1026
apply (unfold less_le)
haftmann@32135
  1027
apply (auto dest: subsetD)
haftmann@32135
  1028
done
haftmann@32135
  1029
haftmann@32135
  1030
lemma psubset_subset_trans: "A \<subset> B ==> B \<subseteq> C ==> A \<subset> C"
haftmann@32135
  1031
  by (auto simp add: psubset_eq)
haftmann@32135
  1032
haftmann@32135
  1033
lemma subset_psubset_trans: "A \<subseteq> B ==> B \<subset> C ==> A \<subset> C"
haftmann@32135
  1034
  by (auto simp add: psubset_eq)
haftmann@32135
  1035
haftmann@32135
  1036
lemma psubset_imp_ex_mem: "A \<subset> B ==> \<exists>b. b \<in> (B - A)"
haftmann@32135
  1037
  by (unfold less_le) blast
haftmann@32135
  1038
haftmann@32135
  1039
lemma atomize_ball:
haftmann@32135
  1040
    "(!!x. x \<in> A ==> P x) == Trueprop (\<forall>x\<in>A. P x)"
haftmann@32135
  1041
  by (simp only: Ball_def atomize_all atomize_imp)
haftmann@32135
  1042
haftmann@32135
  1043
lemmas [symmetric, rulify] = atomize_ball
haftmann@32135
  1044
  and [symmetric, defn] = atomize_ball
haftmann@32135
  1045
hoelzl@40703
  1046
lemma image_Pow_mono:
hoelzl@40703
  1047
  assumes "f ` A \<le> B"
hoelzl@40703
  1048
  shows "(image f) ` (Pow A) \<le> Pow B"
hoelzl@40703
  1049
using assms by blast
hoelzl@40703
  1050
hoelzl@40703
  1051
lemma image_Pow_surj:
hoelzl@40703
  1052
  assumes "f ` A = B"
hoelzl@40703
  1053
  shows "(image f) ` (Pow A) = Pow B"
hoelzl@40703
  1054
using assms unfolding Pow_def proof(auto)
hoelzl@40703
  1055
  fix Y assume *: "Y \<le> f ` A"
hoelzl@40703
  1056
  obtain X where X_def: "X = {x \<in> A. f x \<in> Y}" by blast
hoelzl@40703
  1057
  have "f ` X = Y \<and> X \<le> A" unfolding X_def using * by auto
hoelzl@40703
  1058
  thus "Y \<in> (image f) ` {X. X \<le> A}" by blast
hoelzl@40703
  1059
qed
hoelzl@40703
  1060
haftmann@32135
  1061
subsubsection {* Derived rules involving subsets. *}
haftmann@32135
  1062
haftmann@32135
  1063
text {* @{text insert}. *}
haftmann@32135
  1064
haftmann@32135
  1065
lemma subset_insertI: "B \<subseteq> insert a B"
haftmann@32135
  1066
  by (rule subsetI) (erule insertI2)
haftmann@32135
  1067
haftmann@32135
  1068
lemma subset_insertI2: "A \<subseteq> B \<Longrightarrow> A \<subseteq> insert b B"
haftmann@32135
  1069
  by blast
haftmann@32135
  1070
haftmann@32135
  1071
lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"
haftmann@32135
  1072
  by blast
haftmann@32135
  1073
haftmann@32135
  1074
haftmann@32135
  1075
text {* \medskip Finite Union -- the least upper bound of two sets. *}
haftmann@32135
  1076
haftmann@32135
  1077
lemma Un_upper1: "A \<subseteq> A \<union> B"
huffman@36009
  1078
  by (fact sup_ge1)
haftmann@32135
  1079
haftmann@32135
  1080
lemma Un_upper2: "B \<subseteq> A \<union> B"
huffman@36009
  1081
  by (fact sup_ge2)
haftmann@32135
  1082
haftmann@32135
  1083
lemma Un_least: "A \<subseteq> C ==> B \<subseteq> C ==> A \<union> B \<subseteq> C"
huffman@36009
  1084
  by (fact sup_least)
haftmann@32135
  1085
haftmann@32135
  1086
haftmann@32135
  1087
text {* \medskip Finite Intersection -- the greatest lower bound of two sets. *}
haftmann@32135
  1088
haftmann@32135
  1089
lemma Int_lower1: "A \<inter> B \<subseteq> A"
huffman@36009
  1090
  by (fact inf_le1)
haftmann@32135
  1091
haftmann@32135
  1092
lemma Int_lower2: "A \<inter> B \<subseteq> B"
huffman@36009
  1093
  by (fact inf_le2)
haftmann@32135
  1094
haftmann@32135
  1095
lemma Int_greatest: "C \<subseteq> A ==> C \<subseteq> B ==> C \<subseteq> A \<inter> B"
huffman@36009
  1096
  by (fact inf_greatest)
haftmann@32135
  1097
haftmann@32135
  1098
haftmann@32135
  1099
text {* \medskip Set difference. *}
haftmann@32135
  1100
haftmann@32135
  1101
lemma Diff_subset: "A - B \<subseteq> A"
haftmann@32135
  1102
  by blast
haftmann@32135
  1103
haftmann@32135
  1104
lemma Diff_subset_conv: "(A - B \<subseteq> C) = (A \<subseteq> B \<union> C)"
haftmann@32135
  1105
by blast
haftmann@32135
  1106
haftmann@32135
  1107
haftmann@32135
  1108
subsubsection {* Equalities involving union, intersection, inclusion, etc. *}
haftmann@32135
  1109
haftmann@32135
  1110
text {* @{text "{}"}. *}
haftmann@32135
  1111
haftmann@32135
  1112
lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})"
haftmann@32135
  1113
  -- {* supersedes @{text "Collect_False_empty"} *}
haftmann@32135
  1114
  by auto
haftmann@32135
  1115
haftmann@32135
  1116
lemma subset_empty [simp]: "(A \<subseteq> {}) = (A = {})"
huffman@45121
  1117
  by (fact bot_unique)
haftmann@32135
  1118
haftmann@32135
  1119
lemma not_psubset_empty [iff]: "\<not> (A < {})"
huffman@45121
  1120
  by (fact not_less_bot) (* FIXME: already simp *)
haftmann@32135
  1121
haftmann@32135
  1122
lemma Collect_empty_eq [simp]: "(Collect P = {}) = (\<forall>x. \<not> P x)"
haftmann@32135
  1123
by blast
haftmann@32135
  1124
haftmann@32135
  1125
lemma empty_Collect_eq [simp]: "({} = Collect P) = (\<forall>x. \<not> P x)"
haftmann@32135
  1126
by blast
haftmann@32135
  1127
haftmann@32135
  1128
lemma Collect_neg_eq: "{x. \<not> P x} = - {x. P x}"
haftmann@32135
  1129
  by blast
haftmann@32135
  1130
haftmann@32135
  1131
lemma Collect_disj_eq: "{x. P x | Q x} = {x. P x} \<union> {x. Q x}"
haftmann@32135
  1132
  by blast
haftmann@32135
  1133
haftmann@32135
  1134
lemma Collect_imp_eq: "{x. P x --> Q x} = -{x. P x} \<union> {x. Q x}"
haftmann@32135
  1135
  by blast
haftmann@32135
  1136
haftmann@32135
  1137
lemma Collect_conj_eq: "{x. P x & Q x} = {x. P x} \<inter> {x. Q x}"
haftmann@32135
  1138
  by blast
haftmann@32135
  1139
haftmann@32135
  1140
haftmann@32135
  1141
text {* \medskip @{text insert}. *}
haftmann@32135
  1142
haftmann@32135
  1143
lemma insert_is_Un: "insert a A = {a} Un A"
haftmann@32135
  1144
  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a {}"} *}
haftmann@32135
  1145
  by blast
haftmann@32135
  1146
haftmann@32135
  1147
lemma insert_not_empty [simp]: "insert a A \<noteq> {}"
haftmann@32135
  1148
  by blast
haftmann@32135
  1149
wenzelm@45607
  1150
lemmas empty_not_insert = insert_not_empty [symmetric]
haftmann@32135
  1151
declare empty_not_insert [simp]
haftmann@32135
  1152
haftmann@32135
  1153
lemma insert_absorb: "a \<in> A ==> insert a A = A"
haftmann@32135
  1154
  -- {* @{text "[simp]"} causes recursive calls when there are nested inserts *}
haftmann@32135
  1155
  -- {* with \emph{quadratic} running time *}
haftmann@32135
  1156
  by blast
haftmann@32135
  1157
haftmann@32135
  1158
lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A"
haftmann@32135
  1159
  by blast
haftmann@32135
  1160
haftmann@32135
  1161
lemma insert_commute: "insert x (insert y A) = insert y (insert x A)"
haftmann@32135
  1162
  by blast
haftmann@32135
  1163
haftmann@32135
  1164
lemma insert_subset [simp]: "(insert x A \<subseteq> B) = (x \<in> B & A \<subseteq> B)"
haftmann@32135
  1165
  by blast
haftmann@32135
  1166
haftmann@32135
  1167
lemma mk_disjoint_insert: "a \<in> A ==> \<exists>B. A = insert a B & a \<notin> B"
haftmann@32135
  1168
  -- {* use new @{text B} rather than @{text "A - {a}"} to avoid infinite unfolding *}
haftmann@32135
  1169
  apply (rule_tac x = "A - {a}" in exI, blast)
haftmann@32135
  1170
  done
haftmann@32135
  1171
haftmann@32135
  1172
lemma insert_Collect: "insert a (Collect P) = {u. u \<noteq> a --> P u}"
haftmann@32135
  1173
  by auto
haftmann@32135
  1174
haftmann@32135
  1175
lemma insert_inter_insert[simp]: "insert a A \<inter> insert a B = insert a (A \<inter> B)"
haftmann@32135
  1176
  by blast
haftmann@32135
  1177
blanchet@35828
  1178
lemma insert_disjoint [simp,no_atp]:
haftmann@32135
  1179
 "(insert a A \<inter> B = {}) = (a \<notin> B \<and> A \<inter> B = {})"
haftmann@32135
  1180
 "({} = insert a A \<inter> B) = (a \<notin> B \<and> {} = A \<inter> B)"
haftmann@32135
  1181
  by auto
haftmann@32135
  1182
blanchet@35828
  1183
lemma disjoint_insert [simp,no_atp]:
haftmann@32135
  1184
 "(B \<inter> insert a A = {}) = (a \<notin> B \<and> B \<inter> A = {})"
haftmann@32135
  1185
 "({} = A \<inter> insert b B) = (b \<notin> A \<and> {} = A \<inter> B)"
haftmann@32135
  1186
  by auto
haftmann@32135
  1187
haftmann@32135
  1188
text {* \medskip @{text image}. *}
haftmann@32135
  1189
haftmann@32135
  1190
lemma image_empty [simp]: "f`{} = {}"
haftmann@32135
  1191
  by blast
haftmann@32135
  1192
haftmann@32135
  1193
lemma image_insert [simp]: "f ` insert a B = insert (f a) (f`B)"
haftmann@32135
  1194
  by blast
haftmann@32135
  1195
haftmann@32135
  1196
lemma image_constant: "x \<in> A ==> (\<lambda>x. c) ` A = {c}"
haftmann@32135
  1197
  by auto
haftmann@32135
  1198
haftmann@32135
  1199
lemma image_constant_conv: "(%x. c) ` A = (if A = {} then {} else {c})"
haftmann@32135
  1200
by auto
haftmann@32135
  1201
haftmann@32135
  1202
lemma image_image: "f ` (g ` A) = (\<lambda>x. f (g x)) ` A"
haftmann@32135
  1203
by blast
haftmann@32135
  1204
haftmann@32135
  1205
lemma insert_image [simp]: "x \<in> A ==> insert (f x) (f`A) = f`A"
haftmann@32135
  1206
by blast
haftmann@32135
  1207
haftmann@32135
  1208
lemma image_is_empty [iff]: "(f`A = {}) = (A = {})"
haftmann@32135
  1209
by blast
haftmann@32135
  1210
haftmann@32135
  1211
lemma empty_is_image[iff]: "({} = f ` A) = (A = {})"
haftmann@32135
  1212
by blast
haftmann@32135
  1213
haftmann@32135
  1214
blanchet@35828
  1215
lemma image_Collect [no_atp]: "f ` {x. P x} = {f x | x. P x}"
haftmann@32135
  1216
  -- {* NOT suitable as a default simprule: the RHS isn't simpler than the LHS,
haftmann@32135
  1217
      with its implicit quantifier and conjunction.  Also image enjoys better
haftmann@32135
  1218
      equational properties than does the RHS. *}
haftmann@32135
  1219
  by blast
haftmann@32135
  1220
haftmann@32135
  1221
lemma if_image_distrib [simp]:
haftmann@32135
  1222
  "(\<lambda>x. if P x then f x else g x) ` S
haftmann@32135
  1223
    = (f ` (S \<inter> {x. P x})) \<union> (g ` (S \<inter> {x. \<not> P x}))"
haftmann@32135
  1224
  by (auto simp add: image_def)
haftmann@32135
  1225
haftmann@32135
  1226
lemma image_cong: "M = N ==> (!!x. x \<in> N ==> f x = g x) ==> f`M = g`N"
haftmann@32135
  1227
  by (simp add: image_def)
haftmann@32135
  1228
haftmann@43898
  1229
lemma image_Int_subset: "f`(A Int B) <= f`A Int f`B"
haftmann@43898
  1230
by blast
haftmann@43898
  1231
haftmann@43898
  1232
lemma image_diff_subset: "f`A - f`B <= f`(A - B)"
haftmann@43898
  1233
by blast
haftmann@43898
  1234
haftmann@32135
  1235
haftmann@32135
  1236
text {* \medskip @{text range}. *}
haftmann@32135
  1237
blanchet@35828
  1238
lemma full_SetCompr_eq [no_atp]: "{u. \<exists>x. u = f x} = range f"
haftmann@32135
  1239
  by auto
haftmann@32135
  1240
haftmann@32135
  1241
lemma range_composition: "range (\<lambda>x. f (g x)) = f`range g"
haftmann@32135
  1242
by (subst image_image, simp)
haftmann@32135
  1243
haftmann@32135
  1244
haftmann@32135
  1245
text {* \medskip @{text Int} *}
haftmann@32135
  1246
huffman@45121
  1247
lemma Int_absorb: "A \<inter> A = A"
huffman@45121
  1248
  by (fact inf_idem) (* already simp *)
haftmann@32135
  1249
haftmann@32135
  1250
lemma Int_left_absorb: "A \<inter> (A \<inter> B) = A \<inter> B"
huffman@36009
  1251
  by (fact inf_left_idem)
haftmann@32135
  1252
haftmann@32135
  1253
lemma Int_commute: "A \<inter> B = B \<inter> A"
huffman@36009
  1254
  by (fact inf_commute)
haftmann@32135
  1255
haftmann@32135
  1256
lemma Int_left_commute: "A \<inter> (B \<inter> C) = B \<inter> (A \<inter> C)"
huffman@36009
  1257
  by (fact inf_left_commute)
haftmann@32135
  1258
haftmann@32135
  1259
lemma Int_assoc: "(A \<inter> B) \<inter> C = A \<inter> (B \<inter> C)"
huffman@36009
  1260
  by (fact inf_assoc)
haftmann@32135
  1261
haftmann@32135
  1262
lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute
haftmann@32135
  1263
  -- {* Intersection is an AC-operator *}
haftmann@32135
  1264
haftmann@32135
  1265
lemma Int_absorb1: "B \<subseteq> A ==> A \<inter> B = B"
huffman@36009
  1266
  by (fact inf_absorb2)
haftmann@32135
  1267
haftmann@32135
  1268
lemma Int_absorb2: "A \<subseteq> B ==> A \<inter> B = A"
huffman@36009
  1269
  by (fact inf_absorb1)
haftmann@32135
  1270
huffman@45121
  1271
lemma Int_empty_left: "{} \<inter> B = {}"
huffman@45121
  1272
  by (fact inf_bot_left) (* already simp *)
haftmann@32135
  1273
huffman@45121
  1274
lemma Int_empty_right: "A \<inter> {} = {}"
huffman@45121
  1275
  by (fact inf_bot_right) (* already simp *)
haftmann@32135
  1276
haftmann@32135
  1277
lemma disjoint_eq_subset_Compl: "(A \<inter> B = {}) = (A \<subseteq> -B)"
haftmann@32135
  1278
  by blast
haftmann@32135
  1279
haftmann@32135
  1280
lemma disjoint_iff_not_equal: "(A \<inter> B = {}) = (\<forall>x\<in>A. \<forall>y\<in>B. x \<noteq> y)"
haftmann@32135
  1281
  by blast
haftmann@32135
  1282
huffman@45121
  1283
lemma Int_UNIV_left: "UNIV \<inter> B = B"
huffman@45121
  1284
  by (fact inf_top_left) (* already simp *)
haftmann@32135
  1285
huffman@45121
  1286
lemma Int_UNIV_right: "A \<inter> UNIV = A"
huffman@45121
  1287
  by (fact inf_top_right) (* already simp *)
haftmann@32135
  1288
haftmann@32135
  1289
lemma Int_Un_distrib: "A \<inter> (B \<union> C) = (A \<inter> B) \<union> (A \<inter> C)"
huffman@36009
  1290
  by (fact inf_sup_distrib1)
haftmann@32135
  1291
haftmann@32135
  1292
lemma Int_Un_distrib2: "(B \<union> C) \<inter> A = (B \<inter> A) \<union> (C \<inter> A)"
huffman@36009
  1293
  by (fact inf_sup_distrib2)
haftmann@32135
  1294
blanchet@35828
  1295
lemma Int_UNIV [simp,no_atp]: "(A \<inter> B = UNIV) = (A = UNIV & B = UNIV)"
huffman@45121
  1296
  by (fact inf_eq_top_iff) (* already simp *)
haftmann@32135
  1297
blanchet@38648
  1298
lemma Int_subset_iff [no_atp, simp]: "(C \<subseteq> A \<inter> B) = (C \<subseteq> A & C \<subseteq> B)"
huffman@36009
  1299
  by (fact le_inf_iff)
haftmann@32135
  1300
haftmann@32135
  1301
lemma Int_Collect: "(x \<in> A \<inter> {x. P x}) = (x \<in> A & P x)"
haftmann@32135
  1302
  by blast
haftmann@32135
  1303
haftmann@32135
  1304
haftmann@32135
  1305
text {* \medskip @{text Un}. *}
haftmann@32135
  1306
huffman@45121
  1307
lemma Un_absorb: "A \<union> A = A"
huffman@45121
  1308
  by (fact sup_idem) (* already simp *)
haftmann@32135
  1309
haftmann@32135
  1310
lemma Un_left_absorb: "A \<union> (A \<union> B) = A \<union> B"
huffman@36009
  1311
  by (fact sup_left_idem)
haftmann@32135
  1312
haftmann@32135
  1313
lemma Un_commute: "A \<union> B = B \<union> A"
huffman@36009
  1314
  by (fact sup_commute)
haftmann@32135
  1315
haftmann@32135
  1316
lemma Un_left_commute: "A \<union> (B \<union> C) = B \<union> (A \<union> C)"
huffman@36009
  1317
  by (fact sup_left_commute)
haftmann@32135
  1318
haftmann@32135
  1319
lemma Un_assoc: "(A \<union> B) \<union> C = A \<union> (B \<union> C)"
huffman@36009
  1320
  by (fact sup_assoc)
haftmann@32135
  1321
haftmann@32135
  1322
lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute
haftmann@32135
  1323
  -- {* Union is an AC-operator *}
haftmann@32135
  1324
haftmann@32135
  1325
lemma Un_absorb1: "A \<subseteq> B ==> A \<union> B = B"
huffman@36009
  1326
  by (fact sup_absorb2)
haftmann@32135
  1327
haftmann@32135
  1328
lemma Un_absorb2: "B \<subseteq> A ==> A \<union> B = A"
huffman@36009
  1329
  by (fact sup_absorb1)
haftmann@32135
  1330
huffman@45121
  1331
lemma Un_empty_left: "{} \<union> B = B"
huffman@45121
  1332
  by (fact sup_bot_left) (* already simp *)
haftmann@32135
  1333
huffman@45121
  1334
lemma Un_empty_right: "A \<union> {} = A"
huffman@45121
  1335
  by (fact sup_bot_right) (* already simp *)
haftmann@32135
  1336
huffman@45121
  1337
lemma Un_UNIV_left: "UNIV \<union> B = UNIV"
huffman@45121
  1338
  by (fact sup_top_left) (* already simp *)
haftmann@32135
  1339
huffman@45121
  1340
lemma Un_UNIV_right: "A \<union> UNIV = UNIV"
huffman@45121
  1341
  by (fact sup_top_right) (* already simp *)
haftmann@32135
  1342
haftmann@32135
  1343
lemma Un_insert_left [simp]: "(insert a B) \<union> C = insert a (B \<union> C)"
haftmann@32135
  1344
  by blast
haftmann@32135
  1345
haftmann@32135
  1346
lemma Un_insert_right [simp]: "A \<union> (insert a B) = insert a (A \<union> B)"
haftmann@32135
  1347
  by blast
haftmann@32135
  1348
haftmann@32135
  1349
lemma Int_insert_left:
haftmann@32135
  1350
    "(insert a B) Int C = (if a \<in> C then insert a (B \<inter> C) else B \<inter> C)"
haftmann@32135
  1351
  by auto
haftmann@32135
  1352
nipkow@32456
  1353
lemma Int_insert_left_if0[simp]:
nipkow@32456
  1354
    "a \<notin> C \<Longrightarrow> (insert a B) Int C = B \<inter> C"
nipkow@32456
  1355
  by auto
nipkow@32456
  1356
nipkow@32456
  1357
lemma Int_insert_left_if1[simp]:
nipkow@32456
  1358
    "a \<in> C \<Longrightarrow> (insert a B) Int C = insert a (B Int C)"
nipkow@32456
  1359
  by auto
nipkow@32456
  1360
haftmann@32135
  1361
lemma Int_insert_right:
haftmann@32135
  1362
    "A \<inter> (insert a B) = (if a \<in> A then insert a (A \<inter> B) else A \<inter> B)"
haftmann@32135
  1363
  by auto
haftmann@32135
  1364
nipkow@32456
  1365
lemma Int_insert_right_if0[simp]:
nipkow@32456
  1366
    "a \<notin> A \<Longrightarrow> A Int (insert a B) = A Int B"
nipkow@32456
  1367
  by auto
nipkow@32456
  1368
nipkow@32456
  1369
lemma Int_insert_right_if1[simp]:
nipkow@32456
  1370
    "a \<in> A \<Longrightarrow> A Int (insert a B) = insert a (A Int B)"
nipkow@32456
  1371
  by auto
nipkow@32456
  1372
haftmann@32135
  1373
lemma Un_Int_distrib: "A \<union> (B \<inter> C) = (A \<union> B) \<inter> (A \<union> C)"
huffman@36009
  1374
  by (fact sup_inf_distrib1)
haftmann@32135
  1375
haftmann@32135
  1376
lemma Un_Int_distrib2: "(B \<inter> C) \<union> A = (B \<union> A) \<inter> (C \<union> A)"
huffman@36009
  1377
  by (fact sup_inf_distrib2)
haftmann@32135
  1378
haftmann@32135
  1379
lemma Un_Int_crazy:
haftmann@32135
  1380
    "(A \<inter> B) \<union> (B \<inter> C) \<union> (C \<inter> A) = (A \<union> B) \<inter> (B \<union> C) \<inter> (C \<union> A)"
haftmann@32135
  1381
  by blast
haftmann@32135
  1382
haftmann@32135
  1383
lemma subset_Un_eq: "(A \<subseteq> B) = (A \<union> B = B)"
huffman@36009
  1384
  by (fact le_iff_sup)
haftmann@32135
  1385
haftmann@32135
  1386
lemma Un_empty [iff]: "(A \<union> B = {}) = (A = {} & B = {})"
huffman@45121
  1387
  by (fact sup_eq_bot_iff) (* FIXME: already simp *)
haftmann@32135
  1388
blanchet@38648
  1389
lemma Un_subset_iff [no_atp, simp]: "(A \<union> B \<subseteq> C) = (A \<subseteq> C & B \<subseteq> C)"
huffman@36009
  1390
  by (fact le_sup_iff)
haftmann@32135
  1391
haftmann@32135
  1392
lemma Un_Diff_Int: "(A - B) \<union> (A \<inter> B) = A"
haftmann@32135
  1393
  by blast
haftmann@32135
  1394
haftmann@32135
  1395
lemma Diff_Int2: "A \<inter> C - B \<inter> C = A \<inter> C - B"
haftmann@32135
  1396
  by blast
haftmann@32135
  1397
haftmann@32135
  1398
haftmann@32135
  1399
text {* \medskip Set complement *}
haftmann@32135
  1400
haftmann@32135
  1401
lemma Compl_disjoint [simp]: "A \<inter> -A = {}"
huffman@36009
  1402
  by (fact inf_compl_bot)
haftmann@32135
  1403
haftmann@32135
  1404
lemma Compl_disjoint2 [simp]: "-A \<inter> A = {}"
huffman@36009
  1405
  by (fact compl_inf_bot)
haftmann@32135
  1406
haftmann@32135
  1407
lemma Compl_partition: "A \<union> -A = UNIV"
huffman@36009
  1408
  by (fact sup_compl_top)
haftmann@32135
  1409
haftmann@32135
  1410
lemma Compl_partition2: "-A \<union> A = UNIV"
huffman@36009
  1411
  by (fact compl_sup_top)
haftmann@32135
  1412
huffman@45121
  1413
lemma double_complement: "- (-A) = (A::'a set)"
huffman@45121
  1414
  by (fact double_compl) (* already simp *)
haftmann@32135
  1415
huffman@45121
  1416
lemma Compl_Un: "-(A \<union> B) = (-A) \<inter> (-B)"
huffman@45121
  1417
  by (fact compl_sup) (* already simp *)
haftmann@32135
  1418
huffman@45121
  1419
lemma Compl_Int: "-(A \<inter> B) = (-A) \<union> (-B)"
huffman@45121
  1420
  by (fact compl_inf) (* already simp *)
haftmann@32135
  1421
haftmann@32135
  1422
lemma subset_Compl_self_eq: "(A \<subseteq> -A) = (A = {})"
haftmann@32135
  1423
  by blast
haftmann@32135
  1424
haftmann@32135
  1425
lemma Un_Int_assoc_eq: "((A \<inter> B) \<union> C = A \<inter> (B \<union> C)) = (C \<subseteq> A)"
haftmann@32135
  1426
  -- {* Halmos, Naive Set Theory, page 16. *}
haftmann@32135
  1427
  by blast
haftmann@32135
  1428
huffman@45121
  1429
lemma Compl_UNIV_eq: "-UNIV = {}"
huffman@45121
  1430
  by (fact compl_top_eq) (* already simp *)
haftmann@32135
  1431
huffman@45121
  1432
lemma Compl_empty_eq: "-{} = UNIV"
huffman@45121
  1433
  by (fact compl_bot_eq) (* already simp *)
haftmann@32135
  1434
haftmann@32135
  1435
lemma Compl_subset_Compl_iff [iff]: "(-A \<subseteq> -B) = (B \<subseteq> A)"
huffman@45121
  1436
  by (fact compl_le_compl_iff) (* FIXME: already simp *)
haftmann@32135
  1437
haftmann@32135
  1438
lemma Compl_eq_Compl_iff [iff]: "(-A = -B) = (A = (B::'a set))"
huffman@45121
  1439
  by (fact compl_eq_compl_iff) (* FIXME: already simp *)
haftmann@32135
  1440
krauss@44490
  1441
lemma Compl_insert: "- insert x A = (-A) - {x}"
krauss@44490
  1442
  by blast
krauss@44490
  1443
haftmann@32135
  1444
text {* \medskip Bounded quantifiers.
haftmann@32135
  1445
haftmann@32135
  1446
  The following are not added to the default simpset because
haftmann@32135
  1447
  (a) they duplicate the body and (b) there are no similar rules for @{text Int}. *}
haftmann@32135
  1448
haftmann@32135
  1449
lemma ball_Un: "(\<forall>x \<in> A \<union> B. P x) = ((\<forall>x\<in>A. P x) & (\<forall>x\<in>B. P x))"
haftmann@32135
  1450
  by blast
haftmann@32135
  1451
haftmann@32135
  1452
lemma bex_Un: "(\<exists>x \<in> A \<union> B. P x) = ((\<exists>x\<in>A. P x) | (\<exists>x\<in>B. P x))"
haftmann@32135
  1453
  by blast
haftmann@32135
  1454
haftmann@32135
  1455
haftmann@32135
  1456
text {* \medskip Set difference. *}
haftmann@32135
  1457
haftmann@32135
  1458
lemma Diff_eq: "A - B = A \<inter> (-B)"
haftmann@32135
  1459
  by blast
haftmann@32135
  1460
blanchet@35828
  1461
lemma Diff_eq_empty_iff [simp,no_atp]: "(A - B = {}) = (A \<subseteq> B)"
haftmann@32135
  1462
  by blast
haftmann@32135
  1463
haftmann@32135
  1464
lemma Diff_cancel [simp]: "A - A = {}"
haftmann@32135
  1465
  by blast
haftmann@32135
  1466
haftmann@32135
  1467
lemma Diff_idemp [simp]: "(A - B) - B = A - (B::'a set)"
haftmann@32135
  1468
by blast
haftmann@32135
  1469
haftmann@32135
  1470
lemma Diff_triv: "A \<inter> B = {} ==> A - B = A"
haftmann@32135
  1471
  by (blast elim: equalityE)
haftmann@32135
  1472
haftmann@32135
  1473
lemma empty_Diff [simp]: "{} - A = {}"
haftmann@32135
  1474
  by blast
haftmann@32135
  1475
haftmann@32135
  1476
lemma Diff_empty [simp]: "A - {} = A"
haftmann@32135
  1477
  by blast
haftmann@32135
  1478
haftmann@32135
  1479
lemma Diff_UNIV [simp]: "A - UNIV = {}"
haftmann@32135
  1480
  by blast
haftmann@32135
  1481
blanchet@35828
  1482
lemma Diff_insert0 [simp,no_atp]: "x \<notin> A ==> A - insert x B = A - B"
haftmann@32135
  1483
  by blast
haftmann@32135
  1484
haftmann@32135
  1485
lemma Diff_insert: "A - insert a B = A - B - {a}"
haftmann@32135
  1486
  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
haftmann@32135
  1487
  by blast
haftmann@32135
  1488
haftmann@32135
  1489
lemma Diff_insert2: "A - insert a B = A - {a} - B"
haftmann@32135
  1490
  -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}
haftmann@32135
  1491
  by blast
haftmann@32135
  1492
haftmann@32135
  1493
lemma insert_Diff_if: "insert x A - B = (if x \<in> B then A - B else insert x (A - B))"
haftmann@32135
  1494
  by auto
haftmann@32135
  1495
haftmann@32135
  1496
lemma insert_Diff1 [simp]: "x \<in> B ==> insert x A - B = A - B"
haftmann@32135
  1497
  by blast
haftmann@32135
  1498
haftmann@32135
  1499
lemma insert_Diff_single[simp]: "insert a (A - {a}) = insert a A"
haftmann@32135
  1500
by blast
haftmann@32135
  1501
haftmann@32135
  1502
lemma insert_Diff: "a \<in> A ==> insert a (A - {a}) = A"
haftmann@32135
  1503
  by blast
haftmann@32135
  1504
haftmann@32135
  1505
lemma Diff_insert_absorb: "x \<notin> A ==> (insert x A) - {x} = A"
haftmann@32135
  1506
  by auto
haftmann@32135
  1507
haftmann@32135
  1508
lemma Diff_disjoint [simp]: "A \<inter> (B - A) = {}"
haftmann@32135
  1509
  by blast
haftmann@32135
  1510
haftmann@32135
  1511
lemma Diff_partition: "A \<subseteq> B ==> A \<union> (B - A) = B"
haftmann@32135
  1512
  by blast
haftmann@32135
  1513
haftmann@32135
  1514
lemma double_diff: "A \<subseteq> B ==> B \<subseteq> C ==> B - (C - A) = A"
haftmann@32135
  1515
  by blast
haftmann@32135
  1516
haftmann@32135
  1517
lemma Un_Diff_cancel [simp]: "A \<union> (B - A) = A \<union> B"
haftmann@32135
  1518
  by blast
haftmann@32135
  1519
haftmann@32135
  1520
lemma Un_Diff_cancel2 [simp]: "(B - A) \<union> A = B \<union> A"
haftmann@32135
  1521
  by blast
haftmann@32135
  1522
haftmann@32135
  1523
lemma Diff_Un: "A - (B \<union> C) = (A - B) \<inter> (A - C)"
haftmann@32135
  1524
  by blast
haftmann@32135
  1525
haftmann@32135
  1526
lemma Diff_Int: "A - (B \<inter> C) = (A - B) \<union> (A - C)"
haftmann@32135
  1527
  by blast
haftmann@32135
  1528
haftmann@32135
  1529
lemma Un_Diff: "(A \<union> B) - C = (A - C) \<union> (B - C)"
haftmann@32135
  1530
  by blast
haftmann@32135
  1531
haftmann@32135
  1532
lemma Int_Diff: "(A \<inter> B) - C = A \<inter> (B - C)"
haftmann@32135
  1533
  by blast
haftmann@32135
  1534
haftmann@32135
  1535
lemma Diff_Int_distrib: "C \<inter> (A - B) = (C \<inter> A) - (C \<inter> B)"
haftmann@32135
  1536
  by blast
haftmann@32135
  1537
haftmann@32135
  1538
lemma Diff_Int_distrib2: "(A - B) \<inter> C = (A \<inter> C) - (B \<inter> C)"
haftmann@32135
  1539
  by blast
haftmann@32135
  1540
haftmann@32135
  1541
lemma Diff_Compl [simp]: "A - (- B) = A \<inter> B"
haftmann@32135
  1542
  by auto
haftmann@32135
  1543
haftmann@32135
  1544
lemma Compl_Diff_eq [simp]: "- (A - B) = -A \<union> B"
haftmann@32135
  1545
  by blast
haftmann@32135
  1546
haftmann@32135
  1547
haftmann@32135
  1548
text {* \medskip Quantification over type @{typ bool}. *}
haftmann@32135
  1549
haftmann@32135
  1550
lemma bool_induct: "P True \<Longrightarrow> P False \<Longrightarrow> P x"
haftmann@32135
  1551
  by (cases x) auto
haftmann@32135
  1552
haftmann@32135
  1553
lemma all_bool_eq: "(\<forall>b. P b) \<longleftrightarrow> P True \<and> P False"
haftmann@32135
  1554
  by (auto intro: bool_induct)
haftmann@32135
  1555
haftmann@32135
  1556
lemma bool_contrapos: "P x \<Longrightarrow> \<not> P False \<Longrightarrow> P True"
haftmann@32135
  1557
  by (cases x) auto
haftmann@32135
  1558
haftmann@32135
  1559
lemma ex_bool_eq: "(\<exists>b. P b) \<longleftrightarrow> P True \<or> P False"
haftmann@32135
  1560
  by (auto intro: bool_contrapos)
haftmann@32135
  1561
haftmann@43866
  1562
lemma UNIV_bool [no_atp]: "UNIV = {False, True}"
haftmann@43866
  1563
  by (auto intro: bool_induct)
haftmann@43866
  1564
haftmann@32135
  1565
text {* \medskip @{text Pow} *}
haftmann@32135
  1566
haftmann@32135
  1567
lemma Pow_empty [simp]: "Pow {} = {{}}"
haftmann@32135
  1568
  by (auto simp add: Pow_def)
haftmann@32135
  1569
haftmann@32135
  1570
lemma Pow_insert: "Pow (insert a A) = Pow A \<union> (insert a ` Pow A)"
haftmann@32135
  1571
  by (blast intro: image_eqI [where ?x = "u - {a}", standard])
haftmann@32135
  1572
haftmann@32135
  1573
lemma Pow_Compl: "Pow (- A) = {-B | B. A \<in> Pow B}"
haftmann@32135
  1574
  by (blast intro: exI [where ?x = "- u", standard])
haftmann@32135
  1575
haftmann@32135
  1576
lemma Pow_UNIV [simp]: "Pow UNIV = UNIV"
haftmann@32135
  1577
  by blast
haftmann@32135
  1578
haftmann@32135
  1579
lemma Un_Pow_subset: "Pow A \<union> Pow B \<subseteq> Pow (A \<union> B)"
haftmann@32135
  1580
  by blast
haftmann@32135
  1581
haftmann@32135
  1582
lemma Pow_Int_eq [simp]: "Pow (A \<inter> B) = Pow A \<inter> Pow B"
haftmann@32135
  1583
  by blast
haftmann@32135
  1584
haftmann@32135
  1585
haftmann@32135
  1586
text {* \medskip Miscellany. *}
haftmann@32135
  1587
haftmann@32135
  1588
lemma set_eq_subset: "(A = B) = (A \<subseteq> B & B \<subseteq> A)"
haftmann@32135
  1589
  by blast
haftmann@32135
  1590
blanchet@38648
  1591
lemma subset_iff [no_atp]: "(A \<subseteq> B) = (\<forall>t. t \<in> A --> t \<in> B)"
haftmann@32135
  1592
  by blast
haftmann@32135
  1593
haftmann@32135
  1594
lemma subset_iff_psubset_eq: "(A \<subseteq> B) = ((A \<subset> B) | (A = B))"
haftmann@32135
  1595
  by (unfold less_le) blast
haftmann@32135
  1596
haftmann@32135
  1597
lemma all_not_in_conv [simp]: "(\<forall>x. x \<notin> A) = (A = {})"
haftmann@32135
  1598
  by blast
haftmann@32135
  1599
haftmann@32135
  1600
lemma ex_in_conv: "(\<exists>x. x \<in> A) = (A \<noteq> {})"
haftmann@32135
  1601
  by blast
haftmann@32135
  1602
haftmann@43967
  1603
lemma ball_simps [simp, no_atp]:
haftmann@43967
  1604
  "\<And>A P Q. (\<forall>x\<in>A. P x \<or> Q) \<longleftrightarrow> ((\<forall>x\<in>A. P x) \<or> Q)"
haftmann@43967
  1605
  "\<And>A P Q. (\<forall>x\<in>A. P \<or> Q x) \<longleftrightarrow> (P \<or> (\<forall>x\<in>A. Q x))"
haftmann@43967
  1606
  "\<And>A P Q. (\<forall>x\<in>A. P \<longrightarrow> Q x) \<longleftrightarrow> (P \<longrightarrow> (\<forall>x\<in>A. Q x))"
haftmann@43967
  1607
  "\<And>A P Q. (\<forall>x\<in>A. P x \<longrightarrow> Q) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<longrightarrow> Q)"
haftmann@43967
  1608
  "\<And>P. (\<forall>x\<in>{}. P x) \<longleftrightarrow> True"
haftmann@43967
  1609
  "\<And>P. (\<forall>x\<in>UNIV. P x) \<longleftrightarrow> (\<forall>x. P x)"
haftmann@43967
  1610
  "\<And>a B P. (\<forall>x\<in>insert a B. P x) \<longleftrightarrow> (P a \<and> (\<forall>x\<in>B. P x))"
haftmann@43967
  1611
  "\<And>P Q. (\<forall>x\<in>Collect Q. P x) \<longleftrightarrow> (\<forall>x. Q x \<longrightarrow> P x)"
haftmann@43967
  1612
  "\<And>A P f. (\<forall>x\<in>f`A. P x) \<longleftrightarrow> (\<forall>x\<in>A. P (f x))"
haftmann@43967
  1613
  "\<And>A P. (\<not> (\<forall>x\<in>A. P x)) \<longleftrightarrow> (\<exists>x\<in>A. \<not> P x)"
haftmann@43967
  1614
  by auto
haftmann@43967
  1615
haftmann@43967
  1616
lemma bex_simps [simp, no_atp]:
haftmann@43967
  1617
  "\<And>A P Q. (\<exists>x\<in>A. P x \<and> Q) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<and> Q)"
haftmann@43967
  1618
  "\<And>A P Q. (\<exists>x\<in>A. P \<and> Q x) \<longleftrightarrow> (P \<and> (\<exists>x\<in>A. Q x))"
haftmann@43967
  1619
  "\<And>P. (\<exists>x\<in>{}. P x) \<longleftrightarrow> False"
haftmann@43967
  1620
  "\<And>P. (\<exists>x\<in>UNIV. P x) \<longleftrightarrow> (\<exists>x. P x)"
haftmann@43967
  1621
  "\<And>a B P. (\<exists>x\<in>insert a B. P x) \<longleftrightarrow> (P a | (\<exists>x\<in>B. P x))"
haftmann@43967
  1622
  "\<And>P Q. (\<exists>x\<in>Collect Q. P x) \<longleftrightarrow> (\<exists>x. Q x \<and> P x)"
haftmann@43967
  1623
  "\<And>A P f. (\<exists>x\<in>f`A. P x) \<longleftrightarrow> (\<exists>x\<in>A. P (f x))"
haftmann@43967
  1624
  "\<And>A P. (\<not>(\<exists>x\<in>A. P x)) \<longleftrightarrow> (\<forall>x\<in>A. \<not> P x)"
haftmann@43967
  1625
  by auto
haftmann@43967
  1626
haftmann@32135
  1627
haftmann@32135
  1628
subsubsection {* Monotonicity of various operations *}
haftmann@32135
  1629
haftmann@32135
  1630
lemma image_mono: "A \<subseteq> B ==> f`A \<subseteq> f`B"
haftmann@32135
  1631
  by blast
haftmann@32135
  1632
haftmann@32135
  1633
lemma Pow_mono: "A \<subseteq> B ==> Pow A \<subseteq> Pow B"
haftmann@32135
  1634
  by blast
haftmann@32135
  1635
haftmann@32135
  1636
lemma insert_mono: "C \<subseteq> D ==> insert a C \<subseteq> insert a D"
haftmann@32135
  1637
  by blast
haftmann@32135
  1638
haftmann@32135
  1639
lemma Un_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<union> B \<subseteq> C \<union> D"
huffman@36009
  1640
  by (fact sup_mono)
haftmann@32135
  1641
haftmann@32135
  1642
lemma Int_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<inter> B \<subseteq> C \<inter> D"
huffman@36009
  1643
  by (fact inf_mono)
haftmann@32135
  1644
haftmann@32135
  1645
lemma Diff_mono: "A \<subseteq> C ==> D \<subseteq> B ==> A - B \<subseteq> C - D"
haftmann@32135
  1646
  by blast
haftmann@32135
  1647
haftmann@32135
  1648
lemma Compl_anti_mono: "A \<subseteq> B ==> -B \<subseteq> -A"
huffman@36009
  1649
  by (fact compl_mono)
haftmann@32135
  1650
haftmann@32135
  1651
text {* \medskip Monotonicity of implications. *}
haftmann@32135
  1652
haftmann@32135
  1653
lemma in_mono: "A \<subseteq> B ==> x \<in> A --> x \<in> B"
haftmann@32135
  1654
  apply (rule impI)
haftmann@32135
  1655
  apply (erule subsetD, assumption)
haftmann@32135
  1656
  done
haftmann@32135
  1657
haftmann@32135
  1658
lemma conj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 & P2) --> (Q1 & Q2)"
haftmann@32135
  1659
  by iprover
haftmann@32135
  1660
haftmann@32135
  1661
lemma disj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 | P2) --> (Q1 | Q2)"
haftmann@32135
  1662
  by iprover
haftmann@32135
  1663
haftmann@32135
  1664
lemma imp_mono: "Q1 --> P1 ==> P2 --> Q2 ==> (P1 --> P2) --> (Q1 --> Q2)"
haftmann@32135
  1665
  by iprover
haftmann@32135
  1666
haftmann@32135
  1667
lemma imp_refl: "P --> P" ..
haftmann@32135
  1668
berghofe@33935
  1669
lemma not_mono: "Q --> P ==> ~ P --> ~ Q"
berghofe@33935
  1670
  by iprover
berghofe@33935
  1671
haftmann@32135
  1672
lemma ex_mono: "(!!x. P x --> Q x) ==> (EX x. P x) --> (EX x. Q x)"
haftmann@32135
  1673
  by iprover
haftmann@32135
  1674
haftmann@32135
  1675
lemma all_mono: "(!!x. P x --> Q x) ==> (ALL x. P x) --> (ALL x. Q x)"
haftmann@32135
  1676
  by iprover
haftmann@32135
  1677
haftmann@32135
  1678
lemma Collect_mono: "(!!x. P x --> Q x) ==> Collect P \<subseteq> Collect Q"
haftmann@32135
  1679
  by blast
haftmann@32135
  1680
haftmann@32135
  1681
lemma Int_Collect_mono:
haftmann@32135
  1682
    "A \<subseteq> B ==> (!!x. x \<in> A ==> P x --> Q x) ==> A \<inter> Collect P \<subseteq> B \<inter> Collect Q"
haftmann@32135
  1683
  by blast
haftmann@32135
  1684
haftmann@32135
  1685
lemmas basic_monos =
haftmann@32135
  1686
  subset_refl imp_refl disj_mono conj_mono
haftmann@32135
  1687
  ex_mono Collect_mono in_mono
haftmann@32135
  1688
haftmann@32135
  1689
lemma eq_to_mono: "a = b ==> c = d ==> b --> d ==> a --> c"
haftmann@32135
  1690
  by iprover
haftmann@32135
  1691
haftmann@32135
  1692
haftmann@32135
  1693
subsubsection {* Inverse image of a function *}
haftmann@32135
  1694
haftmann@35416
  1695
definition vimage :: "('a => 'b) => 'b set => 'a set" (infixr "-`" 90) where
haftmann@37767
  1696
  "f -` B == {x. f x : B}"
haftmann@32135
  1697
haftmann@32135
  1698
lemma vimage_eq [simp]: "(a : f -` B) = (f a : B)"
haftmann@32135
  1699
  by (unfold vimage_def) blast
haftmann@32135
  1700
haftmann@32135
  1701
lemma vimage_singleton_eq: "(a : f -` {b}) = (f a = b)"
haftmann@32135
  1702
  by simp
haftmann@32135
  1703
haftmann@32135
  1704
lemma vimageI [intro]: "f a = b ==> b:B ==> a : f -` B"
haftmann@32135
  1705
  by (unfold vimage_def) blast
haftmann@32135
  1706
haftmann@32135
  1707
lemma vimageI2: "f a : A ==> a : f -` A"
haftmann@32135
  1708
  by (unfold vimage_def) fast
haftmann@32135
  1709
haftmann@32135
  1710
lemma vimageE [elim!]: "a: f -` B ==> (!!x. f a = x ==> x:B ==> P) ==> P"
haftmann@32135
  1711
  by (unfold vimage_def) blast
haftmann@32135
  1712
haftmann@32135
  1713
lemma vimageD: "a : f -` A ==> f a : A"
haftmann@32135
  1714
  by (unfold vimage_def) fast
haftmann@32135
  1715
haftmann@32135
  1716
lemma vimage_empty [simp]: "f -` {} = {}"
haftmann@32135
  1717
  by blast
haftmann@32135
  1718
haftmann@32135
  1719
lemma vimage_Compl: "f -` (-A) = -(f -` A)"
haftmann@32135
  1720
  by blast
haftmann@32135
  1721
haftmann@32135
  1722
lemma vimage_Un [simp]: "f -` (A Un B) = (f -` A) Un (f -` B)"
haftmann@32135
  1723
  by blast
haftmann@32135
  1724
haftmann@32135
  1725
lemma vimage_Int [simp]: "f -` (A Int B) = (f -` A) Int (f -` B)"
haftmann@32135
  1726
  by fast
haftmann@32135
  1727
haftmann@32135
  1728
lemma vimage_Collect_eq [simp]: "f -` Collect P = {y. P (f y)}"
haftmann@32135
  1729
  by blast
haftmann@32135
  1730
haftmann@32135
  1731
lemma vimage_Collect: "(!!x. P (f x) = Q x) ==> f -` (Collect P) = Collect Q"
haftmann@32135
  1732
  by blast
haftmann@32135
  1733
haftmann@32135
  1734
lemma vimage_insert: "f-`(insert a B) = (f-`{a}) Un (f-`B)"
haftmann@32135
  1735
  -- {* NOT suitable for rewriting because of the recurrence of @{term "{a}"}. *}
haftmann@32135
  1736
  by blast
haftmann@32135
  1737
haftmann@32135
  1738
lemma vimage_Diff: "f -` (A - B) = (f -` A) - (f -` B)"
haftmann@32135
  1739
  by blast
haftmann@32135
  1740
haftmann@32135
  1741
lemma vimage_UNIV [simp]: "f -` UNIV = UNIV"
haftmann@32135
  1742
  by blast
haftmann@32135
  1743
haftmann@32135
  1744
lemma vimage_mono: "A \<subseteq> B ==> f -` A \<subseteq> f -` B"
haftmann@32135
  1745
  -- {* monotonicity *}
haftmann@32135
  1746
  by blast
haftmann@32135
  1747
blanchet@35828
  1748
lemma vimage_image_eq [no_atp]: "f -` (f ` A) = {y. EX x:A. f x = f y}"
haftmann@32135
  1749
by (blast intro: sym)
haftmann@32135
  1750
haftmann@32135
  1751
lemma image_vimage_subset: "f ` (f -` A) <= A"
haftmann@32135
  1752
by blast
haftmann@32135
  1753
haftmann@32135
  1754
lemma image_vimage_eq [simp]: "f ` (f -` A) = A Int range f"
haftmann@32135
  1755
by blast
haftmann@32135
  1756
paulson@33533
  1757
lemma vimage_const [simp]: "((\<lambda>x. c) -` A) = (if c \<in> A then UNIV else {})"
paulson@33533
  1758
  by auto
paulson@33533
  1759
paulson@33533
  1760
lemma vimage_if [simp]: "((\<lambda>x. if x \<in> B then c else d) -` A) = 
paulson@33533
  1761
   (if c \<in> A then (if d \<in> A then UNIV else B)
paulson@33533
  1762
    else if d \<in> A then -B else {})"  
paulson@33533
  1763
  by (auto simp add: vimage_def) 
paulson@33533
  1764
hoelzl@35576
  1765
lemma vimage_inter_cong:
hoelzl@35576
  1766
  "(\<And> w. w \<in> S \<Longrightarrow> f w = g w) \<Longrightarrow> f -` y \<inter> S = g -` y \<inter> S"
hoelzl@35576
  1767
  by auto
hoelzl@35576
  1768
haftmann@43898
  1769
lemma vimage_ident [simp]: "(%x. x) -` Y = Y"
haftmann@43898
  1770
  by blast
haftmann@32135
  1771
haftmann@32135
  1772
haftmann@32135
  1773
subsubsection {* Getting the Contents of a Singleton Set *}
haftmann@32135
  1774
haftmann@39910
  1775
definition the_elem :: "'a set \<Rightarrow> 'a" where
haftmann@39910
  1776
  "the_elem X = (THE x. X = {x})"
haftmann@32135
  1777
haftmann@39910
  1778
lemma the_elem_eq [simp]: "the_elem {x} = x"
haftmann@39910
  1779
  by (simp add: the_elem_def)
haftmann@32135
  1780
haftmann@32135
  1781
haftmann@32135
  1782
subsubsection {* Least value operator *}
haftmann@32135
  1783
haftmann@32135
  1784
lemma Least_mono:
haftmann@32135
  1785
  "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y
haftmann@32135
  1786
    ==> (LEAST y. y : f ` S) = f (LEAST x. x : S)"
haftmann@32135
  1787
    -- {* Courtesy of Stephan Merz *}
haftmann@32135
  1788
  apply clarify
haftmann@32135
  1789
  apply (erule_tac P = "%x. x : S" in LeastI2_order, fast)
haftmann@32135
  1790
  apply (rule LeastI2_order)
haftmann@32135
  1791
  apply (auto elim: monoD intro!: order_antisym)
haftmann@32135
  1792
  done
haftmann@32135
  1793
haftmann@32135
  1794
haftmann@45959
  1795
subsubsection {* Monad operation *}
haftmann@32135
  1796
haftmann@45959
  1797
definition bind :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where
haftmann@45959
  1798
  "bind A f = {x. \<exists>B \<in> f`A. x \<in> B}"
haftmann@32135
  1799
haftmann@45959
  1800
hide_const (open) bind
haftmann@45959
  1801
haftmann@46036
  1802
lemma bind_bind:
haftmann@46036
  1803
  fixes A :: "'a set"
haftmann@46036
  1804
  shows "Set.bind (Set.bind A B) C = Set.bind A (\<lambda>x. Set.bind (B x) C)"
haftmann@46036
  1805
  by (auto simp add: bind_def)
haftmann@46036
  1806
haftmann@46036
  1807
lemma empty_bind [simp]:
haftmann@46128
  1808
  "Set.bind {} f = {}"
haftmann@46036
  1809
  by (simp add: bind_def)
haftmann@46036
  1810
haftmann@46036
  1811
lemma nonempty_bind_const:
haftmann@46036
  1812
  "A \<noteq> {} \<Longrightarrow> Set.bind A (\<lambda>_. B) = B"
haftmann@46036
  1813
  by (auto simp add: bind_def)
haftmann@46036
  1814
haftmann@46036
  1815
lemma bind_const: "Set.bind A (\<lambda>_. B) = (if A = {} then {} else B)"
haftmann@46036
  1816
  by (auto simp add: bind_def)
haftmann@46036
  1817
haftmann@45959
  1818
haftmann@45986
  1819
subsubsection {* Operations for execution *}
haftmann@45986
  1820
haftmann@45986
  1821
definition is_empty :: "'a set \<Rightarrow> bool" where
haftmann@46127
  1822
  [code_abbrev]: "is_empty A \<longleftrightarrow> A = {}"
haftmann@45986
  1823
haftmann@45986
  1824
hide_const (open) is_empty
haftmann@45986
  1825
haftmann@45986
  1826
definition remove :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" where
haftmann@46127
  1827
  [code_abbrev]: "remove x A = A - {x}"
haftmann@45986
  1828
haftmann@45986
  1829
hide_const (open) remove
haftmann@45986
  1830
haftmann@46128
  1831
lemma member_remove [simp]:
haftmann@46128
  1832
  "x \<in> Set.remove y A \<longleftrightarrow> x \<in> A \<and> x \<noteq> y"
haftmann@46128
  1833
  by (simp add: remove_def)
haftmann@46128
  1834
kuncar@49757
  1835
definition filter :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set" where
kuncar@49757
  1836
  [code_abbrev]: "filter P A = {a \<in> A. P a}"
kuncar@49757
  1837
kuncar@49757
  1838
hide_const (open) filter
kuncar@49757
  1839
kuncar@49757
  1840
lemma member_filter [simp]:
kuncar@49757
  1841
  "x \<in> Set.filter P A \<longleftrightarrow> x \<in> A \<and> P x"
kuncar@49757
  1842
  by (simp add: filter_def)
haftmann@46128
  1843
haftmann@45986
  1844
instantiation set :: (equal) equal
haftmann@45986
  1845
begin
haftmann@45986
  1846
haftmann@45986
  1847
definition
haftmann@45986
  1848
  "HOL.equal A B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A"
haftmann@45986
  1849
haftmann@45986
  1850
instance proof
haftmann@45986
  1851
qed (auto simp add: equal_set_def)
haftmann@45986
  1852
haftmann@45986
  1853
end
haftmann@45986
  1854
haftmann@46127
  1855
haftmann@45959
  1856
text {* Misc *}
haftmann@32135
  1857
haftmann@45152
  1858
hide_const (open) member not_member
haftmann@32135
  1859
haftmann@32135
  1860
lemmas equalityI = subset_antisym
haftmann@32135
  1861
haftmann@32135
  1862
ML {*
haftmann@32135
  1863
val Ball_def = @{thm Ball_def}
haftmann@32135
  1864
val Bex_def = @{thm Bex_def}
haftmann@32135
  1865
val CollectD = @{thm CollectD}
haftmann@32135
  1866
val CollectE = @{thm CollectE}
haftmann@32135
  1867
val CollectI = @{thm CollectI}
haftmann@32135
  1868
val Collect_conj_eq = @{thm Collect_conj_eq}
haftmann@32135
  1869
val Collect_mem_eq = @{thm Collect_mem_eq}
haftmann@32135
  1870
val IntD1 = @{thm IntD1}
haftmann@32135
  1871
val IntD2 = @{thm IntD2}
haftmann@32135
  1872
val IntE = @{thm IntE}
haftmann@32135
  1873
val IntI = @{thm IntI}
haftmann@32135
  1874
val Int_Collect = @{thm Int_Collect}
haftmann@32135
  1875
val UNIV_I = @{thm UNIV_I}
haftmann@32135
  1876
val UNIV_witness = @{thm UNIV_witness}
haftmann@32135
  1877
val UnE = @{thm UnE}
haftmann@32135
  1878
val UnI1 = @{thm UnI1}
haftmann@32135
  1879
val UnI2 = @{thm UnI2}
haftmann@32135
  1880
val ballE = @{thm ballE}
haftmann@32135
  1881
val ballI = @{thm ballI}
haftmann@32135
  1882
val bexCI = @{thm bexCI}
haftmann@32135
  1883
val bexE = @{thm bexE}
haftmann@32135
  1884
val bexI = @{thm bexI}
haftmann@32135
  1885
val bex_triv = @{thm bex_triv}
haftmann@32135
  1886
val bspec = @{thm bspec}
haftmann@32135
  1887
val contra_subsetD = @{thm contra_subsetD}
haftmann@32135
  1888
val equalityCE = @{thm equalityCE}
haftmann@32135
  1889
val equalityD1 = @{thm equalityD1}
haftmann@32135
  1890
val equalityD2 = @{thm equalityD2}
haftmann@32135
  1891
val equalityE = @{thm equalityE}
haftmann@32135
  1892
val equalityI = @{thm equalityI}
haftmann@32135
  1893
val imageE = @{thm imageE}
haftmann@32135
  1894
val imageI = @{thm imageI}
haftmann@32135
  1895
val image_Un = @{thm image_Un}
haftmann@32135
  1896
val image_insert = @{thm image_insert}
haftmann@32135
  1897
val insert_commute = @{thm insert_commute}
haftmann@32135
  1898
val insert_iff = @{thm insert_iff}
haftmann@32135
  1899
val mem_Collect_eq = @{thm mem_Collect_eq}
haftmann@32135
  1900
val rangeE = @{thm rangeE}
haftmann@32135
  1901
val rangeI = @{thm rangeI}
haftmann@32135
  1902
val range_eqI = @{thm range_eqI}
haftmann@32135
  1903
val subsetCE = @{thm subsetCE}
haftmann@32135
  1904
val subsetD = @{thm subsetD}
haftmann@32135
  1905
val subsetI = @{thm subsetI}
haftmann@32135
  1906
val subset_refl = @{thm subset_refl}
haftmann@32135
  1907
val subset_trans = @{thm subset_trans}
haftmann@32135
  1908
val vimageD = @{thm vimageD}
haftmann@32135
  1909
val vimageE = @{thm vimageE}
haftmann@32135
  1910
val vimageI = @{thm vimageI}
haftmann@32135
  1911
val vimageI2 = @{thm vimageI2}
haftmann@32135
  1912
val vimage_Collect = @{thm vimage_Collect}
haftmann@32135
  1913
val vimage_Int = @{thm vimage_Int}
haftmann@32135
  1914
val vimage_Un = @{thm vimage_Un}
haftmann@32135
  1915
*}
haftmann@32135
  1916
haftmann@32077
  1917
end
haftmann@46853
  1918