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