src/HOL/Set.thy
author wenzelm
Mon Aug 31 21:28:08 2015 +0200 (2015-08-31)
changeset 61070 b72a990adfe2
parent 60758 d8d85a8172b5
child 61306 9dd394c866fc
permissions -rw-r--r--
prefer symbols;
haftmann@32139
     1
(*  Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel *)
clasohm@923
     2
wenzelm@60758
     3
section \<open>Set theory for higher-order logic\<close>
wenzelm@11979
     4
nipkow@15131
     5
theory Set
haftmann@30304
     6
imports Lattices
nipkow@15131
     7
begin
wenzelm@11979
     8
wenzelm@60758
     9
subsection \<open>Sets as predicates\<close>
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
wenzelm@60758
    43
text \<open>Set comprehensions\<close>
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
wenzelm@60758
    66
text \<open>
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"}):
wenzelm@60758
    69
\<close>
wenzelm@60758
    70
wenzelm@60758
    71
simproc_setup defined_Collect ("{x. P x & Q x}") = \<open>
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@59499
    78
          DEPTH_SOLVE_1 o (assume_tac ctxt ORELSE' resolve_tac ctxt @{thms conjI})]))
wenzelm@60758
    79
\<close>
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
wenzelm@60758
    95
text \<open>Lifting of predicate class instances\<close>
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
wenzelm@60758
   133
text \<open>Set enumerations\<close>
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
wenzelm@60758
   148
subsection \<open>Subsets and bounded quantifiers\<close>
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
wenzelm@60758
   259
print_translation \<open>
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
wenzelm@60758
   290
\<close>
wenzelm@60758
   291
wenzelm@60758
   292
wenzelm@60758
   293
text \<open>
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@60758
   297
\<close>
wenzelm@11979
   298
wenzelm@35115
   299
syntax
wenzelm@35115
   300
  "_Setcompr" :: "'a => idts => bool => 'a set"    ("(1{_ |/_./ _})")
wenzelm@35115
   301
wenzelm@60758
   302
parse_translation \<open>
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@60758
   317
\<close>
wenzelm@60758
   318
wenzelm@60758
   319
print_translation \<open>
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@60758
   322
\<close> -- \<open>to avoid eta-contraction of body\<close>
wenzelm@60758
   323
wenzelm@60758
   324
print_translation \<open>
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@60758
   356
\<close>
wenzelm@60758
   357
wenzelm@60758
   358
simproc_setup defined_Bex ("EX x:A. P x & Q x") = \<open>
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@60758
   363
\<close>
wenzelm@60758
   364
wenzelm@60758
   365
simproc_setup defined_All ("ALL x:A. P x --> Q x") = \<open>
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)
wenzelm@60758
   370
\<close>
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@60758
   380
text \<open>
wenzelm@11979
   381
  Gives better instantiation for bound:
wenzelm@60758
   382
\<close>
wenzelm@60758
   383
wenzelm@60758
   384
setup \<open>
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@60758
   387
\<close>
wenzelm@60758
   388
wenzelm@60758
   389
ML \<open>
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;
wenzelm@60758
   400
\<close>
wenzelm@60758
   401
wenzelm@60758
   402
declaration \<open>fn _ =>
wenzelm@45625
   403
  Simplifier.map_ss (Simplifier.set_mksimps (mksimps mksimps_pairs))
wenzelm@60758
   404
\<close>
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@60758
   410
  -- \<open>Normally the best argument order: @{prop "P x"} constrains the
wenzelm@60758
   411
    choice of @{prop "x:A"}.\<close>
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@60758
   415
  -- \<open>The best argument order when there is only one @{prop "x:A"}.\<close>
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@60758
   425
  -- \<open>Trival rewrite rule.\<close>
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@60758
   429
  -- \<open>Dual form for existentials.\<close>
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
wenzelm@60758
   459
text \<open>Congruence rules\<close>
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
wenzelm@60758
   484
subsection \<open>Basic operations\<close>
wenzelm@60758
   485
wenzelm@60758
   486
subsubsection \<open>Subsets\<close>
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@60758
   491
text \<open>
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@60758
   495
\<close>
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)
wenzelm@60758
   499
  -- \<open>Rule in Modus Ponens style.\<close>
haftmann@30531
   500
blanchet@54147
   501
lemma rev_subsetD [intro?]: "c \<in> A ==> A \<subseteq> B ==> c \<in> B"
wenzelm@60758
   502
  -- \<open>The same, with reversed premises for use with @{text erule} --
wenzelm@60758
   503
      cf @{text rev_mp}.\<close>
haftmann@30531
   504
  by (rule subsetD)
haftmann@30531
   505
wenzelm@60758
   506
text \<open>
haftmann@30531
   507
  \medskip Converts @{prop "A \<subseteq> B"} to @{prop "x \<in> A ==> x \<in> B"}.
wenzelm@60758
   508
\<close>
haftmann@30531
   509
blanchet@54147
   510
lemma subsetCE [elim]: "A \<subseteq> B ==> (c \<notin> A ==> P) ==> (c \<in> B ==> P) ==> P"
wenzelm@60758
   511
  -- \<open>Classical elimination rule.\<close>
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
wenzelm@60758
   542
subsubsection \<open>Equality\<close>
haftmann@30531
   543
haftmann@30531
   544
lemma subset_antisym [intro!]: "A \<subseteq> B ==> B \<subseteq> A ==> A = B"
wenzelm@60758
   545
  -- \<open>Anti-symmetry of the subset relation.\<close>
nipkow@39302
   546
  by (iprover intro: set_eqI subsetD)
haftmann@30531
   547
wenzelm@60758
   548
text \<open>
haftmann@30531
   549
  \medskip Equality rules from ZF set theory -- are they appropriate
haftmann@30531
   550
  here?
wenzelm@60758
   551
\<close>
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
wenzelm@60758
   559
text \<open>
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 = {}"}!
wenzelm@60758
   563
\<close>
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
wenzelm@60758
   579
subsubsection \<open>The empty set\<close>
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"
wenzelm@60758
   592
    -- \<open>One effect is to delete the ASSUMPTION @{prop "{} <= A"}\<close>
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"
wenzelm@60758
   599
    -- \<open>Use for reasoning about disjointness: @{text "A Int B = {}"}\<close>
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
wenzelm@60758
   609
subsubsection \<open>The universal set -- UNIV\<close>
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
wenzelm@60758
   621
declare UNIV_I [intro]  -- \<open>unsafe makes it less likely to cause problems\<close>
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
wenzelm@60758
   629
text \<open>
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.
wenzelm@60758
   633
\<close>
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
wenzelm@60758
   650
subsubsection \<open>The Powerset operator -- Pow\<close>
haftmann@30531
   651
haftmann@32077
   652
definition Pow :: "'a set => 'a set set" where
haftmann@32077
   653
  Pow_def: "Pow A = {B. B \<le> A}"
haftmann@32077
   654
haftmann@30531
   655
lemma Pow_iff [iff]: "(A \<in> Pow B) = (A \<subseteq> B)"
haftmann@30531
   656
  by (simp add: Pow_def)
haftmann@30531
   657
haftmann@30531
   658
lemma PowI: "A \<subseteq> B ==> A \<in> Pow B"
haftmann@30531
   659
  by (simp add: Pow_def)
haftmann@30531
   660
haftmann@30531
   661
lemma PowD: "A \<in> Pow B ==> A \<subseteq> B"
haftmann@30531
   662
  by (simp add: Pow_def)
haftmann@30531
   663
haftmann@30531
   664
lemma Pow_bottom: "{} \<in> Pow B"
haftmann@30531
   665
  by simp
haftmann@30531
   666
haftmann@30531
   667
lemma Pow_top: "A \<in> Pow A"
krauss@34209
   668
  by simp
haftmann@30531
   669
hoelzl@40703
   670
lemma Pow_not_empty: "Pow A \<noteq> {}"
hoelzl@40703
   671
  using Pow_top by blast
haftmann@30531
   672
haftmann@41076
   673
wenzelm@60758
   674
subsubsection \<open>Set complement\<close>
haftmann@30531
   675
haftmann@30531
   676
lemma Compl_iff [simp]: "(c \<in> -A) = (c \<notin> A)"
haftmann@45959
   677
  by (simp add: fun_Compl_def uminus_set_def)
haftmann@30531
   678
haftmann@30531
   679
lemma ComplI [intro!]: "(c \<in> A ==> False) ==> c \<in> -A"
haftmann@45959
   680
  by (simp add: fun_Compl_def uminus_set_def) blast
clasohm@923
   681
wenzelm@60758
   682
text \<open>
haftmann@30531
   683
  \medskip This form, with negated conclusion, works well with the
haftmann@30531
   684
  Classical prover.  Negated assumptions behave like formulae on the
wenzelm@60758
   685
  right side of the notional turnstile ...\<close>
haftmann@30531
   686
haftmann@30531
   687
lemma ComplD [dest!]: "c : -A ==> c~:A"
haftmann@45959
   688
  by simp
haftmann@30531
   689
haftmann@30531
   690
lemmas ComplE = ComplD [elim_format]
haftmann@30531
   691
haftmann@45959
   692
lemma Compl_eq: "- A = {x. ~ x : A}"
haftmann@45959
   693
  by blast
haftmann@30531
   694
haftmann@30531
   695
wenzelm@60758
   696
subsubsection \<open>Binary intersection\<close>
haftmann@41082
   697
haftmann@41082
   698
abbreviation inter :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Int" 70) where
haftmann@41082
   699
  "op Int \<equiv> inf"
haftmann@41082
   700
haftmann@41082
   701
notation (xsymbols)
haftmann@41082
   702
  inter  (infixl "\<inter>" 70)
haftmann@41082
   703
haftmann@41082
   704
notation (HTML output)
haftmann@41082
   705
  inter  (infixl "\<inter>" 70)
haftmann@41082
   706
haftmann@41082
   707
lemma Int_def:
haftmann@41082
   708
  "A \<inter> B = {x. x \<in> A \<and> x \<in> B}"
haftmann@45959
   709
  by (simp add: inf_set_def inf_fun_def)
haftmann@41082
   710
haftmann@41082
   711
lemma Int_iff [simp]: "(c : A Int B) = (c:A & c:B)"
haftmann@41082
   712
  by (unfold Int_def) blast
haftmann@41082
   713
haftmann@41082
   714
lemma IntI [intro!]: "c:A ==> c:B ==> c : A Int B"
haftmann@41082
   715
  by simp
haftmann@41082
   716
haftmann@41082
   717
lemma IntD1: "c : A Int B ==> c:A"
haftmann@41082
   718
  by simp
haftmann@41082
   719
haftmann@41082
   720
lemma IntD2: "c : A Int B ==> c:B"
haftmann@41082
   721
  by simp
haftmann@41082
   722
haftmann@41082
   723
lemma IntE [elim!]: "c : A Int B ==> (c:A ==> c:B ==> P) ==> P"
haftmann@41082
   724
  by simp
haftmann@41082
   725
haftmann@41082
   726
lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"
haftmann@41082
   727
  by (fact mono_inf)
haftmann@41082
   728
haftmann@41082
   729
wenzelm@60758
   730
subsubsection \<open>Binary union\<close>
haftmann@30531
   731
haftmann@32683
   732
abbreviation union :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Un" 65) where
haftmann@41076
   733
  "union \<equiv> sup"
haftmann@32081
   734
haftmann@32081
   735
notation (xsymbols)
haftmann@32135
   736
  union  (infixl "\<union>" 65)
haftmann@32081
   737
haftmann@32081
   738
notation (HTML output)
haftmann@32135
   739
  union  (infixl "\<union>" 65)
haftmann@32135
   740
haftmann@32135
   741
lemma Un_def:
haftmann@32135
   742
  "A \<union> B = {x. x \<in> A \<or> x \<in> B}"
haftmann@45959
   743
  by (simp add: sup_set_def sup_fun_def)
haftmann@32081
   744
haftmann@30531
   745
lemma Un_iff [simp]: "(c : A Un B) = (c:A | c:B)"
haftmann@30531
   746
  by (unfold Un_def) blast
haftmann@30531
   747
haftmann@30531
   748
lemma UnI1 [elim?]: "c:A ==> c : A Un B"
haftmann@30531
   749
  by simp
haftmann@30531
   750
haftmann@30531
   751
lemma UnI2 [elim?]: "c:B ==> c : A Un B"
haftmann@30531
   752
  by simp
haftmann@30531
   753
wenzelm@60758
   754
text \<open>
haftmann@30531
   755
  \medskip Classical introduction rule: no commitment to @{prop A} vs
haftmann@30531
   756
  @{prop B}.
wenzelm@60758
   757
\<close>
wenzelm@11979
   758
haftmann@30531
   759
lemma UnCI [intro!]: "(c~:B ==> c:A) ==> c : A Un B"
haftmann@30531
   760
  by auto
haftmann@30531
   761
haftmann@30531
   762
lemma UnE [elim!]: "c : A Un B ==> (c:A ==> P) ==> (c:B ==> P) ==> P"
haftmann@30531
   763
  by (unfold Un_def) blast
haftmann@30531
   764
haftmann@32117
   765
lemma insert_def: "insert a B = {x. x = a} \<union> B"
haftmann@45959
   766
  by (simp add: insert_compr Un_def)
haftmann@32081
   767
haftmann@32081
   768
lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"
haftmann@32683
   769
  by (fact mono_sup)
haftmann@32081
   770
haftmann@30531
   771
wenzelm@60758
   772
subsubsection \<open>Set difference\<close>
haftmann@30531
   773
haftmann@30531
   774
lemma Diff_iff [simp]: "(c : A - B) = (c:A & c~:B)"
haftmann@45959
   775
  by (simp add: minus_set_def fun_diff_def)
haftmann@30531
   776
haftmann@30531
   777
lemma DiffI [intro!]: "c : A ==> c ~: B ==> c : A - B"
haftmann@30531
   778
  by simp
haftmann@30531
   779
haftmann@30531
   780
lemma DiffD1: "c : A - B ==> c : A"
haftmann@30531
   781
  by simp
haftmann@30531
   782
haftmann@30531
   783
lemma DiffD2: "c : A - B ==> c : B ==> P"
haftmann@30531
   784
  by simp
haftmann@30531
   785
haftmann@30531
   786
lemma DiffE [elim!]: "c : A - B ==> (c:A ==> c~:B ==> P) ==> P"
haftmann@30531
   787
  by simp
haftmann@30531
   788
haftmann@30531
   789
lemma set_diff_eq: "A - B = {x. x : A & ~ x : B}" by blast
haftmann@30531
   790
haftmann@30531
   791
lemma Compl_eq_Diff_UNIV: "-A = (UNIV - A)"
haftmann@30531
   792
by blast
haftmann@30531
   793
haftmann@30531
   794
wenzelm@60758
   795
subsubsection \<open>Augmenting a set -- @{const insert}\<close>
haftmann@30531
   796
haftmann@30531
   797
lemma insert_iff [simp]: "(a : insert b A) = (a = b | a:A)"
haftmann@30531
   798
  by (unfold insert_def) blast
haftmann@30531
   799
haftmann@30531
   800
lemma insertI1: "a : insert a B"
haftmann@30531
   801
  by simp
haftmann@30531
   802
haftmann@30531
   803
lemma insertI2: "a : B ==> a : insert b B"
haftmann@30531
   804
  by simp
haftmann@30531
   805
haftmann@30531
   806
lemma insertE [elim!]: "a : insert b A ==> (a = b ==> P) ==> (a:A ==> P) ==> P"
haftmann@30531
   807
  by (unfold insert_def) blast
haftmann@30531
   808
haftmann@30531
   809
lemma insertCI [intro!]: "(a~:B ==> a = b) ==> a: insert b B"
wenzelm@60758
   810
  -- \<open>Classical introduction rule.\<close>
haftmann@30531
   811
  by auto
haftmann@30531
   812
haftmann@30531
   813
lemma subset_insert_iff: "(A \<subseteq> insert x B) = (if x:A then A - {x} \<subseteq> B else A \<subseteq> B)"
haftmann@30531
   814
  by auto
haftmann@30531
   815
haftmann@30531
   816
lemma set_insert:
haftmann@30531
   817
  assumes "x \<in> A"
haftmann@30531
   818
  obtains B where "A = insert x B" and "x \<notin> B"
haftmann@30531
   819
proof
haftmann@30531
   820
  from assms show "A = insert x (A - {x})" by blast
haftmann@30531
   821
next
haftmann@30531
   822
  show "x \<notin> A - {x}" by blast
haftmann@30531
   823
qed
haftmann@30531
   824
haftmann@30531
   825
lemma insert_ident: "x ~: A ==> x ~: B ==> (insert x A = insert x B) = (A = B)"
haftmann@30531
   826
by auto
haftmann@30531
   827
nipkow@44744
   828
lemma insert_eq_iff: assumes "a \<notin> A" "b \<notin> B"
nipkow@44744
   829
shows "insert a A = insert b B \<longleftrightarrow>
nipkow@44744
   830
  (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
   831
  (is "?L \<longleftrightarrow> ?R")
nipkow@44744
   832
proof
nipkow@44744
   833
  assume ?L
nipkow@44744
   834
  show ?R
nipkow@44744
   835
  proof cases
wenzelm@60758
   836
    assume "a=b" with assms \<open>?L\<close> show ?R by (simp add: insert_ident)
nipkow@44744
   837
  next
nipkow@44744
   838
    assume "a\<noteq>b"
nipkow@44744
   839
    let ?C = "A - {b}"
nipkow@44744
   840
    have "A = insert b ?C \<and> b \<notin> ?C \<and> B = insert a ?C \<and> a \<notin> ?C"
wenzelm@60758
   841
      using assms \<open>?L\<close> \<open>a\<noteq>b\<close> by auto
wenzelm@60758
   842
    thus ?R using \<open>a\<noteq>b\<close> by auto
nipkow@44744
   843
  qed
nipkow@44744
   844
next
haftmann@46128
   845
  assume ?R thus ?L by (auto split: if_splits)
nipkow@44744
   846
qed
nipkow@44744
   847
Andreas@60057
   848
lemma insert_UNIV: "insert x UNIV = UNIV"
Andreas@60057
   849
by auto
Andreas@60057
   850
wenzelm@60758
   851
subsubsection \<open>Singletons, using insert\<close>
haftmann@30531
   852
blanchet@54147
   853
lemma singletonI [intro!]: "a : {a}"
wenzelm@60758
   854
    -- \<open>Redundant? But unlike @{text insertCI}, it proves the subgoal immediately!\<close>
haftmann@30531
   855
  by (rule insertI1)
haftmann@30531
   856
blanchet@54147
   857
lemma singletonD [dest!]: "b : {a} ==> b = a"
haftmann@30531
   858
  by blast
haftmann@30531
   859
haftmann@30531
   860
lemmas singletonE = singletonD [elim_format]
haftmann@30531
   861
haftmann@30531
   862
lemma singleton_iff: "(b : {a}) = (b = a)"
haftmann@30531
   863
  by blast
haftmann@30531
   864
haftmann@30531
   865
lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"
haftmann@30531
   866
  by blast
haftmann@30531
   867
blanchet@54147
   868
lemma singleton_insert_inj_eq [iff]:
haftmann@30531
   869
     "({b} = insert a A) = (a = b & A \<subseteq> {b})"
haftmann@30531
   870
  by blast
haftmann@30531
   871
blanchet@54147
   872
lemma singleton_insert_inj_eq' [iff]:
haftmann@30531
   873
     "(insert a A = {b}) = (a = b & A \<subseteq> {b})"
haftmann@30531
   874
  by blast
haftmann@30531
   875
haftmann@30531
   876
lemma subset_singletonD: "A \<subseteq> {x} ==> A = {} | A = {x}"
haftmann@30531
   877
  by fast
haftmann@30531
   878
haftmann@30531
   879
lemma singleton_conv [simp]: "{x. x = a} = {a}"
haftmann@30531
   880
  by blast
haftmann@30531
   881
haftmann@30531
   882
lemma singleton_conv2 [simp]: "{x. a = x} = {a}"
haftmann@30531
   883
  by blast
haftmann@30531
   884
bulwahn@46504
   885
lemma diff_single_insert: "A - {x} \<subseteq> B ==> A \<subseteq> insert x B"
haftmann@30531
   886
  by blast
haftmann@30531
   887
haftmann@30531
   888
lemma doubleton_eq_iff: "({a,b} = {c,d}) = (a=c & b=d | a=d & b=c)"
haftmann@30531
   889
  by (blast elim: equalityE)
haftmann@30531
   890
nipkow@53364
   891
lemma Un_singleton_iff:
nipkow@53364
   892
  "(A \<union> B = {x}) = (A = {} \<and> B = {x} \<or> A = {x} \<and> B = {} \<or> A = {x} \<and> B = {x})"
nipkow@53364
   893
by auto
nipkow@53364
   894
nipkow@53364
   895
lemma singleton_Un_iff:
nipkow@53364
   896
  "({x} = A \<union> B) = (A = {} \<and> B = {x} \<or> A = {x} \<and> B = {} \<or> A = {x} \<and> B = {x})"
nipkow@53364
   897
by auto
wenzelm@11979
   898
haftmann@56014
   899
wenzelm@60758
   900
subsubsection \<open>Image of a set under a function\<close>
wenzelm@60758
   901
wenzelm@60758
   902
text \<open>
haftmann@32077
   903
  Frequently @{term b} does not have the syntactic form of @{term "f x"}.
wenzelm@60758
   904
\<close>
haftmann@32077
   905
haftmann@56014
   906
definition image :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a set \<Rightarrow> 'b set" (infixr "`" 90)
haftmann@56014
   907
where
haftmann@56014
   908
  "f ` A = {y. \<exists>x\<in>A. y = f x}"
haftmann@56014
   909
haftmann@56014
   910
lemma image_eqI [simp, intro]:
haftmann@56014
   911
  "b = f x \<Longrightarrow> x \<in> A \<Longrightarrow> b \<in> f ` A"
haftmann@32077
   912
  by (unfold image_def) blast
haftmann@32077
   913
haftmann@56014
   914
lemma imageI:
haftmann@56014
   915
  "x \<in> A \<Longrightarrow> f x \<in> f ` A"
haftmann@32077
   916
  by (rule image_eqI) (rule refl)
haftmann@32077
   917
haftmann@56014
   918
lemma rev_image_eqI:
haftmann@56014
   919
  "x \<in> A \<Longrightarrow> b = f x \<Longrightarrow> b \<in> f ` A"
wenzelm@60758
   920
  -- \<open>This version's more effective when we already have the
wenzelm@60758
   921
    required @{term x}.\<close>
haftmann@56014
   922
  by (rule image_eqI)
haftmann@32077
   923
haftmann@32077
   924
lemma imageE [elim!]:
wenzelm@60758
   925
  assumes "b \<in> (\<lambda>x. f x) ` A" -- \<open>The eta-expansion gives variable-name preservation.\<close>
haftmann@56014
   926
  obtains x where "b = f x" and "x \<in> A"
haftmann@56014
   927
  using assms by (unfold image_def) blast
haftmann@32077
   928
haftmann@51173
   929
lemma Compr_image_eq:
haftmann@51173
   930
  "{x \<in> f ` A. P x} = f ` {x \<in> A. P (f x)}"
haftmann@51173
   931
  by auto
haftmann@51173
   932
haftmann@56014
   933
lemma image_Un:
haftmann@56014
   934
  "f ` (A \<union> B) = f ` A \<union> f ` B"
haftmann@32077
   935
  by blast
haftmann@32077
   936
haftmann@56014
   937
lemma image_iff:
haftmann@56014
   938
  "z \<in> f ` A \<longleftrightarrow> (\<exists>x\<in>A. z = f x)"
haftmann@56014
   939
  by blast
haftmann@56014
   940
haftmann@56014
   941
lemma image_subsetI:
haftmann@56014
   942
  "(\<And>x. x \<in> A \<Longrightarrow> f x \<in> B) \<Longrightarrow> f ` A \<subseteq> B"
wenzelm@60758
   943
  -- \<open>Replaces the three steps @{text subsetI}, @{text imageE},
wenzelm@60758
   944
    @{text hypsubst}, but breaks too many existing proofs.\<close>
haftmann@32077
   945
  by blast
wenzelm@11979
   946
haftmann@56014
   947
lemma image_subset_iff:
haftmann@56014
   948
  "f ` A \<subseteq> B \<longleftrightarrow> (\<forall>x\<in>A. f x \<in> B)"
wenzelm@60758
   949
  -- \<open>This rewrite rule would confuse users if made default.\<close>
haftmann@56014
   950
  by blast
haftmann@56014
   951
haftmann@56014
   952
lemma subset_imageE:
haftmann@56014
   953
  assumes "B \<subseteq> f ` A"
haftmann@56014
   954
  obtains C where "C \<subseteq> A" and "B = f ` C"
haftmann@56014
   955
proof -
haftmann@56014
   956
  from assms have "B = f ` {a \<in> A. f a \<in> B}" by fast
haftmann@56014
   957
  moreover have "{a \<in> A. f a \<in> B} \<subseteq> A" by blast
haftmann@56014
   958
  ultimately show thesis by (blast intro: that)
haftmann@56014
   959
qed
haftmann@56014
   960
haftmann@56014
   961
lemma subset_image_iff:
haftmann@56014
   962
  "B \<subseteq> f ` A \<longleftrightarrow> (\<exists>AA\<subseteq>A. B = f ` AA)"
haftmann@56014
   963
  by (blast elim: subset_imageE)
haftmann@56014
   964
haftmann@56014
   965
lemma image_ident [simp]:
haftmann@56014
   966
  "(\<lambda>x. x) ` Y = Y"
haftmann@56014
   967
  by blast
haftmann@56014
   968
haftmann@56014
   969
lemma image_empty [simp]:
haftmann@56014
   970
  "f ` {} = {}"
haftmann@56014
   971
  by blast
haftmann@56014
   972
haftmann@56014
   973
lemma image_insert [simp]:
haftmann@56014
   974
  "f ` insert a B = insert (f a) (f ` B)"
haftmann@56014
   975
  by blast
haftmann@56014
   976
haftmann@56014
   977
lemma image_constant:
haftmann@56014
   978
  "x \<in> A \<Longrightarrow> (\<lambda>x. c) ` A = {c}"
haftmann@56014
   979
  by auto
haftmann@56014
   980
haftmann@56014
   981
lemma image_constant_conv:
haftmann@56014
   982
  "(\<lambda>x. c) ` A = (if A = {} then {} else {c})"
haftmann@56014
   983
  by auto
haftmann@56014
   984
haftmann@56014
   985
lemma image_image:
haftmann@56014
   986
  "f ` (g ` A) = (\<lambda>x. f (g x)) ` A"
haftmann@56014
   987
  by blast
haftmann@56014
   988
haftmann@56014
   989
lemma insert_image [simp]:
haftmann@56014
   990
  "x \<in> A ==> insert (f x) (f ` A) = f ` A"
haftmann@56014
   991
  by blast
haftmann@56014
   992
haftmann@56014
   993
lemma image_is_empty [iff]:
haftmann@56014
   994
  "f ` A = {} \<longleftrightarrow> A = {}"
haftmann@56014
   995
  by blast
haftmann@56014
   996
haftmann@56014
   997
lemma empty_is_image [iff]:
haftmann@56014
   998
  "{} = f ` A \<longleftrightarrow> A = {}"
haftmann@56014
   999
  by blast
haftmann@56014
  1000
haftmann@56014
  1001
lemma image_Collect:
haftmann@56014
  1002
  "f ` {x. P x} = {f x | x. P x}"
wenzelm@60758
  1003
  -- \<open>NOT suitable as a default simprule: the RHS isn't simpler than the LHS,
haftmann@56014
  1004
      with its implicit quantifier and conjunction.  Also image enjoys better
wenzelm@60758
  1005
      equational properties than does the RHS.\<close>
haftmann@56014
  1006
  by blast
haftmann@56014
  1007
haftmann@56014
  1008
lemma if_image_distrib [simp]:
haftmann@56014
  1009
  "(\<lambda>x. if P x then f x else g x) ` S
haftmann@56014
  1010
    = (f ` (S \<inter> {x. P x})) \<union> (g ` (S \<inter> {x. \<not> P x}))"
haftmann@56077
  1011
  by auto
haftmann@56014
  1012
haftmann@56014
  1013
lemma image_cong:
haftmann@56014
  1014
  "M = N \<Longrightarrow> (\<And>x. x \<in> N \<Longrightarrow> f x = g x) \<Longrightarrow> f ` M = g ` N"
haftmann@56014
  1015
  by (simp add: image_def)
haftmann@56014
  1016
haftmann@56014
  1017
lemma image_Int_subset:
haftmann@56014
  1018
  "f ` (A \<inter> B) \<subseteq> f ` A \<inter> f ` B"
haftmann@56014
  1019
  by blast
haftmann@56014
  1020
haftmann@56014
  1021
lemma image_diff_subset:
haftmann@56014
  1022
  "f ` A - f ` B \<subseteq> f ` (A - B)"
haftmann@56014
  1023
  by blast
haftmann@56014
  1024
lp15@59504
  1025
lemma Setcompr_eq_image: "{f x | x. x \<in> A} = f ` A"
lp15@59504
  1026
  by blast
lp15@59504
  1027
haftmann@56014
  1028
lemma ball_imageD:
haftmann@56014
  1029
  assumes "\<forall>x\<in>f ` A. P x"
haftmann@56014
  1030
  shows "\<forall>x\<in>A. P (f x)"
haftmann@56014
  1031
  using assms by simp
haftmann@56014
  1032
haftmann@56014
  1033
lemma bex_imageD:
haftmann@56014
  1034
  assumes "\<exists>x\<in>f ` A. P x"
haftmann@56014
  1035
  shows "\<exists>x\<in>A. P (f x)"
haftmann@56014
  1036
  using assms by auto
haftmann@56014
  1037
haftmann@56014
  1038
wenzelm@60758
  1039
text \<open>
haftmann@32077
  1040
  \medskip Range of a function -- just a translation for image!
wenzelm@60758
  1041
\<close>
haftmann@32077
  1042
haftmann@56014
  1043
abbreviation range :: "('a \<Rightarrow> 'b) \<Rightarrow> 'b set"
haftmann@56014
  1044
where -- "of function"
haftmann@56014
  1045
  "range f \<equiv> f ` UNIV"
haftmann@56014
  1046
haftmann@56014
  1047
lemma range_eqI:
haftmann@56014
  1048
  "b = f x \<Longrightarrow> b \<in> range f"
haftmann@56014
  1049
  by simp
haftmann@56014
  1050
haftmann@56014
  1051
lemma rangeI:
haftmann@56014
  1052
  "f x \<in> range f"
haftmann@32077
  1053
  by simp
haftmann@32077
  1054
haftmann@56014
  1055
lemma rangeE [elim?]:
haftmann@56014
  1056
  "b \<in> range (\<lambda>x. f x) \<Longrightarrow> (\<And>x. b = f x \<Longrightarrow> P) \<Longrightarrow> P"
haftmann@56014
  1057
  by (rule imageE)
haftmann@56014
  1058
haftmann@56014
  1059
lemma full_SetCompr_eq:
haftmann@56014
  1060
  "{u. \<exists>x. u = f x} = range f"
haftmann@56014
  1061
  by auto
haftmann@56014
  1062
lp15@59506
  1063
lemma range_composition:
haftmann@56014
  1064
  "range (\<lambda>x. f (g x)) = f ` range g"
haftmann@56077
  1065
  by auto
haftmann@56014
  1066
haftmann@32077
  1067
wenzelm@60758
  1068
subsubsection \<open>Some rules with @{text "if"}\<close>
wenzelm@60758
  1069
wenzelm@60758
  1070
text\<open>Elimination of @{text"{x. \<dots> & x=t & \<dots>}"}.\<close>
haftmann@32081
  1071
haftmann@32081
  1072
lemma Collect_conv_if: "{x. x=a & P x} = (if P a then {a} else {})"
haftmann@32117
  1073
  by auto
haftmann@32081
  1074
haftmann@32081
  1075
lemma Collect_conv_if2: "{x. a=x & P x} = (if P a then {a} else {})"
haftmann@32117
  1076
  by auto
haftmann@32081
  1077
wenzelm@60758
  1078
text \<open>
haftmann@32081
  1079
  Rewrite rules for boolean case-splitting: faster than @{text
haftmann@32081
  1080
  "split_if [split]"}.
wenzelm@60758
  1081
\<close>
haftmann@32081
  1082
haftmann@32081
  1083
lemma split_if_eq1: "((if Q then x else y) = b) = ((Q --> x = b) & (~ Q --> y = b))"
haftmann@32081
  1084
  by (rule split_if)
haftmann@32081
  1085
haftmann@32081
  1086
lemma split_if_eq2: "(a = (if Q then x else y)) = ((Q --> a = x) & (~ Q --> a = y))"
haftmann@32081
  1087
  by (rule split_if)
haftmann@32081
  1088
wenzelm@60758
  1089
text \<open>
haftmann@32081
  1090
  Split ifs on either side of the membership relation.  Not for @{text
haftmann@32081
  1091
  "[simp]"} -- can cause goals to blow up!
wenzelm@60758
  1092
\<close>
haftmann@32081
  1093
haftmann@32081
  1094
lemma split_if_mem1: "((if Q then x else y) : b) = ((Q --> x : b) & (~ Q --> y : b))"
haftmann@32081
  1095
  by (rule split_if)
haftmann@32081
  1096
haftmann@32081
  1097
lemma split_if_mem2: "(a : (if Q then x else y)) = ((Q --> a : x) & (~ Q --> a : y))"
haftmann@32081
  1098
  by (rule split_if [where P="%S. a : S"])
haftmann@32081
  1099
haftmann@32081
  1100
lemmas split_ifs = if_bool_eq_conj split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2
haftmann@32081
  1101
haftmann@32081
  1102
(*Would like to add these, but the existing code only searches for the
haftmann@37677
  1103
  outer-level constant, which in this case is just Set.member; we instead need
haftmann@32081
  1104
  to use term-nets to associate patterns with rules.  Also, if a rule fails to
haftmann@32081
  1105
  apply, then the formula should be kept.
haftmann@34974
  1106
  [("uminus", Compl_iff RS iffD1), ("minus", [Diff_iff RS iffD1]),
haftmann@32081
  1107
   ("Int", [IntD1,IntD2]),
haftmann@32081
  1108
   ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]
haftmann@32081
  1109
 *)
haftmann@32081
  1110
haftmann@32081
  1111
wenzelm@60758
  1112
subsection \<open>Further operations and lemmas\<close>
wenzelm@60758
  1113
wenzelm@60758
  1114
subsubsection \<open>The ``proper subset'' relation\<close>
haftmann@32135
  1115
blanchet@54147
  1116
lemma psubsetI [intro!]: "A \<subseteq> B ==> A \<noteq> B ==> A \<subset> B"
haftmann@32135
  1117
  by (unfold less_le) blast
haftmann@32135
  1118
blanchet@54147
  1119
lemma psubsetE [elim!]:
haftmann@32135
  1120
    "[|A \<subset> B;  [|A \<subseteq> B; ~ (B\<subseteq>A)|] ==> R|] ==> R"
haftmann@32135
  1121
  by (unfold less_le) blast
haftmann@32135
  1122
haftmann@32135
  1123
lemma psubset_insert_iff:
haftmann@32135
  1124
  "(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
  1125
  by (auto simp add: less_le subset_insert_iff)
haftmann@32135
  1126
haftmann@32135
  1127
lemma psubset_eq: "(A \<subset> B) = (A \<subseteq> B & A \<noteq> B)"
haftmann@32135
  1128
  by (simp only: less_le)
haftmann@32135
  1129
haftmann@32135
  1130
lemma psubset_imp_subset: "A \<subset> B ==> A \<subseteq> B"
haftmann@32135
  1131
  by (simp add: psubset_eq)
haftmann@32135
  1132
haftmann@32135
  1133
lemma psubset_trans: "[| A \<subset> B; B \<subset> C |] ==> A \<subset> C"
haftmann@32135
  1134
apply (unfold less_le)
haftmann@32135
  1135
apply (auto dest: subset_antisym)
haftmann@32135
  1136
done
haftmann@32135
  1137
haftmann@32135
  1138
lemma psubsetD: "[| A \<subset> B; c \<in> A |] ==> c \<in> B"
haftmann@32135
  1139
apply (unfold less_le)
haftmann@32135
  1140
apply (auto dest: subsetD)
haftmann@32135
  1141
done
haftmann@32135
  1142
haftmann@32135
  1143
lemma psubset_subset_trans: "A \<subset> B ==> B \<subseteq> C ==> A \<subset> C"
haftmann@32135
  1144
  by (auto simp add: psubset_eq)
haftmann@32135
  1145
haftmann@32135
  1146
lemma subset_psubset_trans: "A \<subseteq> B ==> B \<subset> C ==> A \<subset> C"
haftmann@32135
  1147
  by (auto simp add: psubset_eq)
haftmann@32135
  1148
haftmann@32135
  1149
lemma psubset_imp_ex_mem: "A \<subset> B ==> \<exists>b. b \<in> (B - A)"
haftmann@32135
  1150
  by (unfold less_le) blast
haftmann@32135
  1151
haftmann@32135
  1152
lemma atomize_ball:
haftmann@32135
  1153
    "(!!x. x \<in> A ==> P x) == Trueprop (\<forall>x\<in>A. P x)"
haftmann@32135
  1154
  by (simp only: Ball_def atomize_all atomize_imp)
haftmann@32135
  1155
haftmann@32135
  1156
lemmas [symmetric, rulify] = atomize_ball
haftmann@32135
  1157
  and [symmetric, defn] = atomize_ball
haftmann@32135
  1158
hoelzl@40703
  1159
lemma image_Pow_mono:
haftmann@56014
  1160
  assumes "f ` A \<subseteq> B"
haftmann@56014
  1161
  shows "image f ` Pow A \<subseteq> Pow B"
haftmann@56014
  1162
  using assms by blast
hoelzl@40703
  1163
hoelzl@40703
  1164
lemma image_Pow_surj:
hoelzl@40703
  1165
  assumes "f ` A = B"
haftmann@56014
  1166
  shows "image f ` Pow A = Pow B"
haftmann@56014
  1167
  using assms by (blast elim: subset_imageE)
haftmann@56014
  1168
hoelzl@40703
  1169
wenzelm@60758
  1170
subsubsection \<open>Derived rules involving subsets.\<close>
wenzelm@60758
  1171
wenzelm@60758
  1172
text \<open>@{text insert}.\<close>
haftmann@32135
  1173
haftmann@32135
  1174
lemma subset_insertI: "B \<subseteq> insert a B"
haftmann@32135
  1175
  by (rule subsetI) (erule insertI2)
haftmann@32135
  1176
haftmann@32135
  1177
lemma subset_insertI2: "A \<subseteq> B \<Longrightarrow> A \<subseteq> insert b B"
haftmann@32135
  1178
  by blast
haftmann@32135
  1179
haftmann@32135
  1180
lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"
haftmann@32135
  1181
  by blast
haftmann@32135
  1182
haftmann@32135
  1183
wenzelm@60758
  1184
text \<open>\medskip Finite Union -- the least upper bound of two sets.\<close>
haftmann@32135
  1185
haftmann@32135
  1186
lemma Un_upper1: "A \<subseteq> A \<union> B"
huffman@36009
  1187
  by (fact sup_ge1)
haftmann@32135
  1188
haftmann@32135
  1189
lemma Un_upper2: "B \<subseteq> A \<union> B"
huffman@36009
  1190
  by (fact sup_ge2)
haftmann@32135
  1191
haftmann@32135
  1192
lemma Un_least: "A \<subseteq> C ==> B \<subseteq> C ==> A \<union> B \<subseteq> C"
huffman@36009
  1193
  by (fact sup_least)
haftmann@32135
  1194
haftmann@32135
  1195
wenzelm@60758
  1196
text \<open>\medskip Finite Intersection -- the greatest lower bound of two sets.\<close>
haftmann@32135
  1197
haftmann@32135
  1198
lemma Int_lower1: "A \<inter> B \<subseteq> A"
huffman@36009
  1199
  by (fact inf_le1)
haftmann@32135
  1200
haftmann@32135
  1201
lemma Int_lower2: "A \<inter> B \<subseteq> B"
huffman@36009
  1202
  by (fact inf_le2)
haftmann@32135
  1203
haftmann@32135
  1204
lemma Int_greatest: "C \<subseteq> A ==> C \<subseteq> B ==> C \<subseteq> A \<inter> B"
huffman@36009
  1205
  by (fact inf_greatest)
haftmann@32135
  1206
haftmann@32135
  1207
wenzelm@60758
  1208
text \<open>\medskip Set difference.\<close>
haftmann@32135
  1209
haftmann@32135
  1210
lemma Diff_subset: "A - B \<subseteq> A"
haftmann@32135
  1211
  by blast
haftmann@32135
  1212
haftmann@32135
  1213
lemma Diff_subset_conv: "(A - B \<subseteq> C) = (A \<subseteq> B \<union> C)"
haftmann@32135
  1214
by blast
haftmann@32135
  1215
haftmann@32135
  1216
wenzelm@60758
  1217
subsubsection \<open>Equalities involving union, intersection, inclusion, etc.\<close>
wenzelm@60758
  1218
wenzelm@60758
  1219
text \<open>@{text "{}"}.\<close>
haftmann@32135
  1220
haftmann@32135
  1221
lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})"
wenzelm@60758
  1222
  -- \<open>supersedes @{text "Collect_False_empty"}\<close>
haftmann@32135
  1223
  by auto
haftmann@32135
  1224
haftmann@32135
  1225
lemma subset_empty [simp]: "(A \<subseteq> {}) = (A = {})"
huffman@45121
  1226
  by (fact bot_unique)
haftmann@32135
  1227
haftmann@32135
  1228
lemma not_psubset_empty [iff]: "\<not> (A < {})"
huffman@45121
  1229
  by (fact not_less_bot) (* FIXME: already simp *)
haftmann@32135
  1230
haftmann@32135
  1231
lemma Collect_empty_eq [simp]: "(Collect P = {}) = (\<forall>x. \<not> P x)"
haftmann@32135
  1232
by blast
haftmann@32135
  1233
haftmann@32135
  1234
lemma empty_Collect_eq [simp]: "({} = Collect P) = (\<forall>x. \<not> P x)"
haftmann@32135
  1235
by blast
haftmann@32135
  1236
haftmann@32135
  1237
lemma Collect_neg_eq: "{x. \<not> P x} = - {x. P x}"
haftmann@32135
  1238
  by blast
haftmann@32135
  1239
haftmann@32135
  1240
lemma Collect_disj_eq: "{x. P x | Q x} = {x. P x} \<union> {x. Q x}"
haftmann@32135
  1241
  by blast
haftmann@32135
  1242
haftmann@32135
  1243
lemma Collect_imp_eq: "{x. P x --> Q x} = -{x. P x} \<union> {x. Q x}"
haftmann@32135
  1244
  by blast
haftmann@32135
  1245
haftmann@32135
  1246
lemma Collect_conj_eq: "{x. P x & Q x} = {x. P x} \<inter> {x. Q x}"
haftmann@32135
  1247
  by blast
haftmann@32135
  1248
lp15@59506
  1249
lemma Collect_mono_iff: "Collect P \<subseteq> Collect Q \<longleftrightarrow> (\<forall>x. P x \<longrightarrow> Q x)"
lp15@59504
  1250
  by blast
lp15@59504
  1251
haftmann@32135
  1252
wenzelm@60758
  1253
text \<open>\medskip @{text insert}.\<close>
haftmann@32135
  1254
haftmann@32135
  1255
lemma insert_is_Un: "insert a A = {a} Un A"
wenzelm@60758
  1256
  -- \<open>NOT SUITABLE FOR REWRITING since @{text "{a} == insert a {}"}\<close>
haftmann@32135
  1257
  by blast
haftmann@32135
  1258
haftmann@32135
  1259
lemma insert_not_empty [simp]: "insert a A \<noteq> {}"
haftmann@32135
  1260
  by blast
haftmann@32135
  1261
wenzelm@45607
  1262
lemmas empty_not_insert = insert_not_empty [symmetric]
haftmann@32135
  1263
declare empty_not_insert [simp]
haftmann@32135
  1264
haftmann@32135
  1265
lemma insert_absorb: "a \<in> A ==> insert a A = A"
wenzelm@60758
  1266
  -- \<open>@{text "[simp]"} causes recursive calls when there are nested inserts\<close>
wenzelm@60758
  1267
  -- \<open>with \emph{quadratic} running time\<close>
haftmann@32135
  1268
  by blast
haftmann@32135
  1269
haftmann@32135
  1270
lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A"
haftmann@32135
  1271
  by blast
haftmann@32135
  1272
haftmann@32135
  1273
lemma insert_commute: "insert x (insert y A) = insert y (insert x A)"
haftmann@32135
  1274
  by blast
haftmann@32135
  1275
haftmann@32135
  1276
lemma insert_subset [simp]: "(insert x A \<subseteq> B) = (x \<in> B & A \<subseteq> B)"
haftmann@32135
  1277
  by blast
haftmann@32135
  1278
haftmann@32135
  1279
lemma mk_disjoint_insert: "a \<in> A ==> \<exists>B. A = insert a B & a \<notin> B"
wenzelm@60758
  1280
  -- \<open>use new @{text B} rather than @{text "A - {a}"} to avoid infinite unfolding\<close>
haftmann@32135
  1281
  apply (rule_tac x = "A - {a}" in exI, blast)
haftmann@32135
  1282
  done
haftmann@32135
  1283
haftmann@32135
  1284
lemma insert_Collect: "insert a (Collect P) = {u. u \<noteq> a --> P u}"
haftmann@32135
  1285
  by auto
haftmann@32135
  1286
haftmann@32135
  1287
lemma insert_inter_insert[simp]: "insert a A \<inter> insert a B = insert a (A \<inter> B)"
haftmann@32135
  1288
  by blast
haftmann@32135
  1289
blanchet@54147
  1290
lemma insert_disjoint [simp]:
haftmann@32135
  1291
 "(insert a A \<inter> B = {}) = (a \<notin> B \<and> A \<inter> B = {})"
haftmann@32135
  1292
 "({} = insert a A \<inter> B) = (a \<notin> B \<and> {} = A \<inter> B)"
haftmann@32135
  1293
  by auto
haftmann@32135
  1294
blanchet@54147
  1295
lemma disjoint_insert [simp]:
haftmann@32135
  1296
 "(B \<inter> insert a A = {}) = (a \<notin> B \<and> B \<inter> A = {})"
haftmann@32135
  1297
 "({} = A \<inter> insert b B) = (b \<notin> A \<and> {} = A \<inter> B)"
haftmann@32135
  1298
  by auto
haftmann@32135
  1299
haftmann@32135
  1300
wenzelm@60758
  1301
text \<open>\medskip @{text Int}\<close>
haftmann@32135
  1302
huffman@45121
  1303
lemma Int_absorb: "A \<inter> A = A"
huffman@45121
  1304
  by (fact inf_idem) (* already simp *)
haftmann@32135
  1305
haftmann@32135
  1306
lemma Int_left_absorb: "A \<inter> (A \<inter> B) = A \<inter> B"
huffman@36009
  1307
  by (fact inf_left_idem)
haftmann@32135
  1308
haftmann@32135
  1309
lemma Int_commute: "A \<inter> B = B \<inter> A"
huffman@36009
  1310
  by (fact inf_commute)
haftmann@32135
  1311
haftmann@32135
  1312
lemma Int_left_commute: "A \<inter> (B \<inter> C) = B \<inter> (A \<inter> C)"
huffman@36009
  1313
  by (fact inf_left_commute)
haftmann@32135
  1314
haftmann@32135
  1315
lemma Int_assoc: "(A \<inter> B) \<inter> C = A \<inter> (B \<inter> C)"
huffman@36009
  1316
  by (fact inf_assoc)
haftmann@32135
  1317
haftmann@32135
  1318
lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute
wenzelm@60758
  1319
  -- \<open>Intersection is an AC-operator\<close>
haftmann@32135
  1320
haftmann@32135
  1321
lemma Int_absorb1: "B \<subseteq> A ==> A \<inter> B = B"
huffman@36009
  1322
  by (fact inf_absorb2)
haftmann@32135
  1323
haftmann@32135
  1324
lemma Int_absorb2: "A \<subseteq> B ==> A \<inter> B = A"
huffman@36009
  1325
  by (fact inf_absorb1)
haftmann@32135
  1326
huffman@45121
  1327
lemma Int_empty_left: "{} \<inter> B = {}"
huffman@45121
  1328
  by (fact inf_bot_left) (* already simp *)
haftmann@32135
  1329
huffman@45121
  1330
lemma Int_empty_right: "A \<inter> {} = {}"
huffman@45121
  1331
  by (fact inf_bot_right) (* already simp *)
haftmann@32135
  1332
haftmann@32135
  1333
lemma disjoint_eq_subset_Compl: "(A \<inter> B = {}) = (A \<subseteq> -B)"
haftmann@32135
  1334
  by blast
haftmann@32135
  1335
haftmann@32135
  1336
lemma disjoint_iff_not_equal: "(A \<inter> B = {}) = (\<forall>x\<in>A. \<forall>y\<in>B. x \<noteq> y)"
haftmann@32135
  1337
  by blast
haftmann@32135
  1338
huffman@45121
  1339
lemma Int_UNIV_left: "UNIV \<inter> B = B"
huffman@45121
  1340
  by (fact inf_top_left) (* already simp *)
haftmann@32135
  1341
huffman@45121
  1342
lemma Int_UNIV_right: "A \<inter> UNIV = A"
huffman@45121
  1343
  by (fact inf_top_right) (* already simp *)
haftmann@32135
  1344
haftmann@32135
  1345
lemma Int_Un_distrib: "A \<inter> (B \<union> C) = (A \<inter> B) \<union> (A \<inter> C)"
huffman@36009
  1346
  by (fact inf_sup_distrib1)
haftmann@32135
  1347
haftmann@32135
  1348
lemma Int_Un_distrib2: "(B \<union> C) \<inter> A = (B \<inter> A) \<union> (C \<inter> A)"
huffman@36009
  1349
  by (fact inf_sup_distrib2)
haftmann@32135
  1350
blanchet@54147
  1351
lemma Int_UNIV [simp]: "(A \<inter> B = UNIV) = (A = UNIV & B = UNIV)"
huffman@45121
  1352
  by (fact inf_eq_top_iff) (* already simp *)
haftmann@32135
  1353
blanchet@54147
  1354
lemma Int_subset_iff [simp]: "(C \<subseteq> A \<inter> B) = (C \<subseteq> A & C \<subseteq> B)"
huffman@36009
  1355
  by (fact le_inf_iff)
haftmann@32135
  1356
haftmann@32135
  1357
lemma Int_Collect: "(x \<in> A \<inter> {x. P x}) = (x \<in> A & P x)"
haftmann@32135
  1358
  by blast
haftmann@32135
  1359
haftmann@32135
  1360
wenzelm@60758
  1361
text \<open>\medskip @{text Un}.\<close>
haftmann@32135
  1362
huffman@45121
  1363
lemma Un_absorb: "A \<union> A = A"
huffman@45121
  1364
  by (fact sup_idem) (* already simp *)
haftmann@32135
  1365
haftmann@32135
  1366
lemma Un_left_absorb: "A \<union> (A \<union> B) = A \<union> B"
huffman@36009
  1367
  by (fact sup_left_idem)
haftmann@32135
  1368
haftmann@32135
  1369
lemma Un_commute: "A \<union> B = B \<union> A"
huffman@36009
  1370
  by (fact sup_commute)
haftmann@32135
  1371
haftmann@32135
  1372
lemma Un_left_commute: "A \<union> (B \<union> C) = B \<union> (A \<union> C)"
huffman@36009
  1373
  by (fact sup_left_commute)
haftmann@32135
  1374
haftmann@32135
  1375
lemma Un_assoc: "(A \<union> B) \<union> C = A \<union> (B \<union> C)"
huffman@36009
  1376
  by (fact sup_assoc)
haftmann@32135
  1377
haftmann@32135
  1378
lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute
wenzelm@60758
  1379
  -- \<open>Union is an AC-operator\<close>
haftmann@32135
  1380
haftmann@32135
  1381
lemma Un_absorb1: "A \<subseteq> B ==> A \<union> B = B"
huffman@36009
  1382
  by (fact sup_absorb2)
haftmann@32135
  1383
haftmann@32135
  1384
lemma Un_absorb2: "B \<subseteq> A ==> A \<union> B = A"
huffman@36009
  1385
  by (fact sup_absorb1)
haftmann@32135
  1386
huffman@45121
  1387
lemma Un_empty_left: "{} \<union> B = B"
huffman@45121
  1388
  by (fact sup_bot_left) (* already simp *)
haftmann@32135
  1389
huffman@45121
  1390
lemma Un_empty_right: "A \<union> {} = A"
huffman@45121
  1391
  by (fact sup_bot_right) (* already simp *)
haftmann@32135
  1392
huffman@45121
  1393
lemma Un_UNIV_left: "UNIV \<union> B = UNIV"
huffman@45121
  1394
  by (fact sup_top_left) (* already simp *)
haftmann@32135
  1395
huffman@45121
  1396
lemma Un_UNIV_right: "A \<union> UNIV = UNIV"
huffman@45121
  1397
  by (fact sup_top_right) (* already simp *)
haftmann@32135
  1398
haftmann@32135
  1399
lemma Un_insert_left [simp]: "(insert a B) \<union> C = insert a (B \<union> C)"
haftmann@32135
  1400
  by blast
haftmann@32135
  1401
haftmann@32135
  1402
lemma Un_insert_right [simp]: "A \<union> (insert a B) = insert a (A \<union> B)"
haftmann@32135
  1403
  by blast
haftmann@32135
  1404
haftmann@32135
  1405
lemma Int_insert_left:
haftmann@32135
  1406
    "(insert a B) Int C = (if a \<in> C then insert a (B \<inter> C) else B \<inter> C)"
haftmann@32135
  1407
  by auto
haftmann@32135
  1408
nipkow@32456
  1409
lemma Int_insert_left_if0[simp]:
nipkow@32456
  1410
    "a \<notin> C \<Longrightarrow> (insert a B) Int C = B \<inter> C"
nipkow@32456
  1411
  by auto
nipkow@32456
  1412
nipkow@32456
  1413
lemma Int_insert_left_if1[simp]:
nipkow@32456
  1414
    "a \<in> C \<Longrightarrow> (insert a B) Int C = insert a (B Int C)"
nipkow@32456
  1415
  by auto
nipkow@32456
  1416
haftmann@32135
  1417
lemma Int_insert_right:
haftmann@32135
  1418
    "A \<inter> (insert a B) = (if a \<in> A then insert a (A \<inter> B) else A \<inter> B)"
haftmann@32135
  1419
  by auto
haftmann@32135
  1420
nipkow@32456
  1421
lemma Int_insert_right_if0[simp]:
nipkow@32456
  1422
    "a \<notin> A \<Longrightarrow> A Int (insert a B) = A Int B"
nipkow@32456
  1423
  by auto
nipkow@32456
  1424
nipkow@32456
  1425
lemma Int_insert_right_if1[simp]:
nipkow@32456
  1426
    "a \<in> A \<Longrightarrow> A Int (insert a B) = insert a (A Int B)"
nipkow@32456
  1427
  by auto
nipkow@32456
  1428
haftmann@32135
  1429
lemma Un_Int_distrib: "A \<union> (B \<inter> C) = (A \<union> B) \<inter> (A \<union> C)"
huffman@36009
  1430
  by (fact sup_inf_distrib1)
haftmann@32135
  1431
haftmann@32135
  1432
lemma Un_Int_distrib2: "(B \<inter> C) \<union> A = (B \<union> A) \<inter> (C \<union> A)"
huffman@36009
  1433
  by (fact sup_inf_distrib2)
haftmann@32135
  1434
haftmann@32135
  1435
lemma Un_Int_crazy:
haftmann@32135
  1436
    "(A \<inter> B) \<union> (B \<inter> C) \<union> (C \<inter> A) = (A \<union> B) \<inter> (B \<union> C) \<inter> (C \<union> A)"
haftmann@32135
  1437
  by blast
haftmann@32135
  1438
haftmann@32135
  1439
lemma subset_Un_eq: "(A \<subseteq> B) = (A \<union> B = B)"
huffman@36009
  1440
  by (fact le_iff_sup)
haftmann@32135
  1441
haftmann@32135
  1442
lemma Un_empty [iff]: "(A \<union> B = {}) = (A = {} & B = {})"
huffman@45121
  1443
  by (fact sup_eq_bot_iff) (* FIXME: already simp *)
haftmann@32135
  1444
blanchet@54147
  1445
lemma Un_subset_iff [simp]: "(A \<union> B \<subseteq> C) = (A \<subseteq> C & B \<subseteq> C)"
huffman@36009
  1446
  by (fact le_sup_iff)
haftmann@32135
  1447
haftmann@32135
  1448
lemma Un_Diff_Int: "(A - B) \<union> (A \<inter> B) = A"
haftmann@32135
  1449
  by blast
haftmann@32135
  1450
haftmann@32135
  1451
lemma Diff_Int2: "A \<inter> C - B \<inter> C = A \<inter> C - B"
haftmann@32135
  1452
  by blast
haftmann@32135
  1453
haftmann@32135
  1454
wenzelm@60758
  1455
text \<open>\medskip Set complement\<close>
haftmann@32135
  1456
haftmann@32135
  1457
lemma Compl_disjoint [simp]: "A \<inter> -A = {}"
huffman@36009
  1458
  by (fact inf_compl_bot)
haftmann@32135
  1459
haftmann@32135
  1460
lemma Compl_disjoint2 [simp]: "-A \<inter> A = {}"
huffman@36009
  1461
  by (fact compl_inf_bot)
haftmann@32135
  1462
haftmann@32135
  1463
lemma Compl_partition: "A \<union> -A = UNIV"
huffman@36009
  1464
  by (fact sup_compl_top)
haftmann@32135
  1465
haftmann@32135
  1466
lemma Compl_partition2: "-A \<union> A = UNIV"
huffman@36009
  1467
  by (fact compl_sup_top)
haftmann@32135
  1468
huffman@45121
  1469
lemma double_complement: "- (-A) = (A::'a set)"
huffman@45121
  1470
  by (fact double_compl) (* already simp *)
haftmann@32135
  1471
huffman@45121
  1472
lemma Compl_Un: "-(A \<union> B) = (-A) \<inter> (-B)"
huffman@45121
  1473
  by (fact compl_sup) (* already simp *)
haftmann@32135
  1474
huffman@45121
  1475
lemma Compl_Int: "-(A \<inter> B) = (-A) \<union> (-B)"
huffman@45121
  1476
  by (fact compl_inf) (* already simp *)
haftmann@32135
  1477
haftmann@32135
  1478
lemma subset_Compl_self_eq: "(A \<subseteq> -A) = (A = {})"
haftmann@32135
  1479
  by blast
haftmann@32135
  1480
haftmann@32135
  1481
lemma Un_Int_assoc_eq: "((A \<inter> B) \<union> C = A \<inter> (B \<union> C)) = (C \<subseteq> A)"
wenzelm@60758
  1482
  -- \<open>Halmos, Naive Set Theory, page 16.\<close>
haftmann@32135
  1483
  by blast
haftmann@32135
  1484
huffman@45121
  1485
lemma Compl_UNIV_eq: "-UNIV = {}"
huffman@45121
  1486
  by (fact compl_top_eq) (* already simp *)
haftmann@32135
  1487
huffman@45121
  1488
lemma Compl_empty_eq: "-{} = UNIV"
huffman@45121
  1489
  by (fact compl_bot_eq) (* already simp *)
haftmann@32135
  1490
haftmann@32135
  1491
lemma Compl_subset_Compl_iff [iff]: "(-A \<subseteq> -B) = (B \<subseteq> A)"
huffman@45121
  1492
  by (fact compl_le_compl_iff) (* FIXME: already simp *)
haftmann@32135
  1493
haftmann@32135
  1494
lemma Compl_eq_Compl_iff [iff]: "(-A = -B) = (A = (B::'a set))"
huffman@45121
  1495
  by (fact compl_eq_compl_iff) (* FIXME: already simp *)
haftmann@32135
  1496
krauss@44490
  1497
lemma Compl_insert: "- insert x A = (-A) - {x}"
krauss@44490
  1498
  by blast
krauss@44490
  1499
wenzelm@60758
  1500
text \<open>\medskip Bounded quantifiers.
haftmann@32135
  1501
haftmann@32135
  1502
  The following are not added to the default simpset because
wenzelm@60758
  1503
  (a) they duplicate the body and (b) there are no similar rules for @{text Int}.\<close>
haftmann@32135
  1504
haftmann@32135
  1505
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
  1506
  by blast
haftmann@32135
  1507
haftmann@32135
  1508
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
  1509
  by blast
haftmann@32135
  1510
haftmann@32135
  1511
wenzelm@60758
  1512
text \<open>\medskip Set difference.\<close>
haftmann@32135
  1513
haftmann@32135
  1514
lemma Diff_eq: "A - B = A \<inter> (-B)"
haftmann@32135
  1515
  by blast
haftmann@32135
  1516
blanchet@54147
  1517
lemma Diff_eq_empty_iff [simp]: "(A - B = {}) = (A \<subseteq> B)"
haftmann@32135
  1518
  by blast
haftmann@32135
  1519
haftmann@32135
  1520
lemma Diff_cancel [simp]: "A - A = {}"
haftmann@32135
  1521
  by blast
haftmann@32135
  1522
haftmann@32135
  1523
lemma Diff_idemp [simp]: "(A - B) - B = A - (B::'a set)"
haftmann@32135
  1524
by blast
haftmann@32135
  1525
haftmann@32135
  1526
lemma Diff_triv: "A \<inter> B = {} ==> A - B = A"
haftmann@32135
  1527
  by (blast elim: equalityE)
haftmann@32135
  1528
haftmann@32135
  1529
lemma empty_Diff [simp]: "{} - A = {}"
haftmann@32135
  1530
  by blast
haftmann@32135
  1531
haftmann@32135
  1532
lemma Diff_empty [simp]: "A - {} = A"
haftmann@32135
  1533
  by blast
haftmann@32135
  1534
haftmann@32135
  1535
lemma Diff_UNIV [simp]: "A - UNIV = {}"
haftmann@32135
  1536
  by blast
haftmann@32135
  1537
blanchet@54147
  1538
lemma Diff_insert0 [simp]: "x \<notin> A ==> A - insert x B = A - B"
haftmann@32135
  1539
  by blast
haftmann@32135
  1540
haftmann@32135
  1541
lemma Diff_insert: "A - insert a B = A - B - {a}"
wenzelm@60758
  1542
  -- \<open>NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"}\<close>
haftmann@32135
  1543
  by blast
haftmann@32135
  1544
haftmann@32135
  1545
lemma Diff_insert2: "A - insert a B = A - {a} - B"
wenzelm@60758
  1546
  -- \<open>NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"}\<close>
haftmann@32135
  1547
  by blast
haftmann@32135
  1548
haftmann@32135
  1549
lemma insert_Diff_if: "insert x A - B = (if x \<in> B then A - B else insert x (A - B))"
haftmann@32135
  1550
  by auto
haftmann@32135
  1551
haftmann@32135
  1552
lemma insert_Diff1 [simp]: "x \<in> B ==> insert x A - B = A - B"
haftmann@32135
  1553
  by blast
haftmann@32135
  1554
haftmann@32135
  1555
lemma insert_Diff_single[simp]: "insert a (A - {a}) = insert a A"
haftmann@32135
  1556
by blast
haftmann@32135
  1557
haftmann@32135
  1558
lemma insert_Diff: "a \<in> A ==> insert a (A - {a}) = A"
haftmann@32135
  1559
  by blast
haftmann@32135
  1560
haftmann@32135
  1561
lemma Diff_insert_absorb: "x \<notin> A ==> (insert x A) - {x} = A"
haftmann@32135
  1562
  by auto
haftmann@32135
  1563
haftmann@32135
  1564
lemma Diff_disjoint [simp]: "A \<inter> (B - A) = {}"
haftmann@32135
  1565
  by blast
haftmann@32135
  1566
haftmann@32135
  1567
lemma Diff_partition: "A \<subseteq> B ==> A \<union> (B - A) = B"
haftmann@32135
  1568
  by blast
haftmann@32135
  1569
haftmann@32135
  1570
lemma double_diff: "A \<subseteq> B ==> B \<subseteq> C ==> B - (C - A) = A"
haftmann@32135
  1571
  by blast
haftmann@32135
  1572
haftmann@32135
  1573
lemma Un_Diff_cancel [simp]: "A \<union> (B - A) = A \<union> B"
haftmann@32135
  1574
  by blast
haftmann@32135
  1575
haftmann@32135
  1576
lemma Un_Diff_cancel2 [simp]: "(B - A) \<union> A = B \<union> A"
haftmann@32135
  1577
  by blast
haftmann@32135
  1578
haftmann@32135
  1579
lemma Diff_Un: "A - (B \<union> C) = (A - B) \<inter> (A - C)"
haftmann@32135
  1580
  by blast
haftmann@32135
  1581
haftmann@32135
  1582
lemma Diff_Int: "A - (B \<inter> C) = (A - B) \<union> (A - C)"
haftmann@32135
  1583
  by blast
haftmann@32135
  1584
haftmann@32135
  1585
lemma Un_Diff: "(A \<union> B) - C = (A - C) \<union> (B - C)"
haftmann@32135
  1586
  by blast
haftmann@32135
  1587
haftmann@32135
  1588
lemma Int_Diff: "(A \<inter> B) - C = A \<inter> (B - C)"
haftmann@32135
  1589
  by blast
haftmann@32135
  1590
haftmann@32135
  1591
lemma Diff_Int_distrib: "C \<inter> (A - B) = (C \<inter> A) - (C \<inter> B)"
haftmann@32135
  1592
  by blast
haftmann@32135
  1593
haftmann@32135
  1594
lemma Diff_Int_distrib2: "(A - B) \<inter> C = (A \<inter> C) - (B \<inter> C)"
haftmann@32135
  1595
  by blast
haftmann@32135
  1596
haftmann@32135
  1597
lemma Diff_Compl [simp]: "A - (- B) = A \<inter> B"
haftmann@32135
  1598
  by auto
haftmann@32135
  1599
haftmann@32135
  1600
lemma Compl_Diff_eq [simp]: "- (A - B) = -A \<union> B"
haftmann@32135
  1601
  by blast
haftmann@32135
  1602
haftmann@32135
  1603
wenzelm@60758
  1604
text \<open>\medskip Quantification over type @{typ bool}.\<close>
haftmann@32135
  1605
haftmann@32135
  1606
lemma bool_induct: "P True \<Longrightarrow> P False \<Longrightarrow> P x"
haftmann@32135
  1607
  by (cases x) auto
haftmann@32135
  1608
haftmann@32135
  1609
lemma all_bool_eq: "(\<forall>b. P b) \<longleftrightarrow> P True \<and> P False"
haftmann@32135
  1610
  by (auto intro: bool_induct)
haftmann@32135
  1611
haftmann@32135
  1612
lemma bool_contrapos: "P x \<Longrightarrow> \<not> P False \<Longrightarrow> P True"
haftmann@32135
  1613
  by (cases x) auto
haftmann@32135
  1614
haftmann@32135
  1615
lemma ex_bool_eq: "(\<exists>b. P b) \<longleftrightarrow> P True \<or> P False"
haftmann@32135
  1616
  by (auto intro: bool_contrapos)
haftmann@32135
  1617
blanchet@54147
  1618
lemma UNIV_bool: "UNIV = {False, True}"
haftmann@43866
  1619
  by (auto intro: bool_induct)
haftmann@43866
  1620
wenzelm@60758
  1621
text \<open>\medskip @{text Pow}\<close>
haftmann@32135
  1622
haftmann@32135
  1623
lemma Pow_empty [simp]: "Pow {} = {{}}"
haftmann@32135
  1624
  by (auto simp add: Pow_def)
haftmann@32135
  1625
nipkow@60161
  1626
lemma Pow_singleton_iff [simp]: "Pow X = {Y} \<longleftrightarrow> X = {} \<and> Y = {}"
nipkow@60161
  1627
by blast
nipkow@60161
  1628
haftmann@32135
  1629
lemma Pow_insert: "Pow (insert a A) = Pow A \<union> (insert a ` Pow A)"
wenzelm@55143
  1630
  by (blast intro: image_eqI [where ?x = "u - {a}" for u])
haftmann@32135
  1631
haftmann@32135
  1632
lemma Pow_Compl: "Pow (- A) = {-B | B. A \<in> Pow B}"
wenzelm@55143
  1633
  by (blast intro: exI [where ?x = "- u" for u])
haftmann@32135
  1634
haftmann@32135
  1635
lemma Pow_UNIV [simp]: "Pow UNIV = UNIV"
haftmann@32135
  1636
  by blast
haftmann@32135
  1637
haftmann@32135
  1638
lemma Un_Pow_subset: "Pow A \<union> Pow B \<subseteq> Pow (A \<union> B)"
haftmann@32135
  1639
  by blast
haftmann@32135
  1640
haftmann@32135
  1641
lemma Pow_Int_eq [simp]: "Pow (A \<inter> B) = Pow A \<inter> Pow B"
haftmann@32135
  1642
  by blast
haftmann@32135
  1643
haftmann@32135
  1644
wenzelm@60758
  1645
text \<open>\medskip Miscellany.\<close>
haftmann@32135
  1646
haftmann@32135
  1647
lemma set_eq_subset: "(A = B) = (A \<subseteq> B & B \<subseteq> A)"
haftmann@32135
  1648
  by blast
haftmann@32135
  1649
blanchet@54147
  1650
lemma subset_iff: "(A \<subseteq> B) = (\<forall>t. t \<in> A --> t \<in> B)"
haftmann@32135
  1651
  by blast
haftmann@32135
  1652
haftmann@32135
  1653
lemma subset_iff_psubset_eq: "(A \<subseteq> B) = ((A \<subset> B) | (A = B))"
haftmann@32135
  1654
  by (unfold less_le) blast
haftmann@32135
  1655
haftmann@32135
  1656
lemma all_not_in_conv [simp]: "(\<forall>x. x \<notin> A) = (A = {})"
haftmann@32135
  1657
  by blast
haftmann@32135
  1658
haftmann@32135
  1659
lemma ex_in_conv: "(\<exists>x. x \<in> A) = (A \<noteq> {})"
haftmann@32135
  1660
  by blast
haftmann@32135
  1661
haftmann@43967
  1662
lemma ball_simps [simp, no_atp]:
haftmann@43967
  1663
  "\<And>A P Q. (\<forall>x\<in>A. P x \<or> Q) \<longleftrightarrow> ((\<forall>x\<in>A. P x) \<or> Q)"
haftmann@43967
  1664
  "\<And>A P Q. (\<forall>x\<in>A. P \<or> Q x) \<longleftrightarrow> (P \<or> (\<forall>x\<in>A. Q x))"
haftmann@43967
  1665
  "\<And>A P Q. (\<forall>x\<in>A. P \<longrightarrow> Q x) \<longleftrightarrow> (P \<longrightarrow> (\<forall>x\<in>A. Q x))"
haftmann@43967
  1666
  "\<And>A P Q. (\<forall>x\<in>A. P x \<longrightarrow> Q) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<longrightarrow> Q)"
haftmann@43967
  1667
  "\<And>P. (\<forall>x\<in>{}. P x) \<longleftrightarrow> True"
haftmann@43967
  1668
  "\<And>P. (\<forall>x\<in>UNIV. P x) \<longleftrightarrow> (\<forall>x. P x)"
haftmann@43967
  1669
  "\<And>a B P. (\<forall>x\<in>insert a B. P x) \<longleftrightarrow> (P a \<and> (\<forall>x\<in>B. P x))"
haftmann@43967
  1670
  "\<And>P Q. (\<forall>x\<in>Collect Q. P x) \<longleftrightarrow> (\<forall>x. Q x \<longrightarrow> P x)"
haftmann@43967
  1671
  "\<And>A P f. (\<forall>x\<in>f`A. P x) \<longleftrightarrow> (\<forall>x\<in>A. P (f x))"
haftmann@43967
  1672
  "\<And>A P. (\<not> (\<forall>x\<in>A. P x)) \<longleftrightarrow> (\<exists>x\<in>A. \<not> P x)"
haftmann@43967
  1673
  by auto
haftmann@43967
  1674
haftmann@43967
  1675
lemma bex_simps [simp, no_atp]:
haftmann@43967
  1676
  "\<And>A P Q. (\<exists>x\<in>A. P x \<and> Q) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<and> Q)"
haftmann@43967
  1677
  "\<And>A P Q. (\<exists>x\<in>A. P \<and> Q x) \<longleftrightarrow> (P \<and> (\<exists>x\<in>A. Q x))"
haftmann@43967
  1678
  "\<And>P. (\<exists>x\<in>{}. P x) \<longleftrightarrow> False"
haftmann@43967
  1679
  "\<And>P. (\<exists>x\<in>UNIV. P x) \<longleftrightarrow> (\<exists>x. P x)"
haftmann@43967
  1680
  "\<And>a B P. (\<exists>x\<in>insert a B. P x) \<longleftrightarrow> (P a | (\<exists>x\<in>B. P x))"
haftmann@43967
  1681
  "\<And>P Q. (\<exists>x\<in>Collect Q. P x) \<longleftrightarrow> (\<exists>x. Q x \<and> P x)"
haftmann@43967
  1682
  "\<And>A P f. (\<exists>x\<in>f`A. P x) \<longleftrightarrow> (\<exists>x\<in>A. P (f x))"
haftmann@43967
  1683
  "\<And>A P. (\<not>(\<exists>x\<in>A. P x)) \<longleftrightarrow> (\<forall>x\<in>A. \<not> P x)"
haftmann@43967
  1684
  by auto
haftmann@43967
  1685
haftmann@32135
  1686
wenzelm@60758
  1687
subsubsection \<open>Monotonicity of various operations\<close>
haftmann@32135
  1688
haftmann@32135
  1689
lemma image_mono: "A \<subseteq> B ==> f`A \<subseteq> f`B"
haftmann@32135
  1690
  by blast
haftmann@32135
  1691
haftmann@32135
  1692
lemma Pow_mono: "A \<subseteq> B ==> Pow A \<subseteq> Pow B"
haftmann@32135
  1693
  by blast
haftmann@32135
  1694
haftmann@32135
  1695
lemma insert_mono: "C \<subseteq> D ==> insert a C \<subseteq> insert a D"
haftmann@32135
  1696
  by blast
haftmann@32135
  1697
haftmann@32135
  1698
lemma Un_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<union> B \<subseteq> C \<union> D"
huffman@36009
  1699
  by (fact sup_mono)
haftmann@32135
  1700
haftmann@32135
  1701
lemma Int_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<inter> B \<subseteq> C \<inter> D"
huffman@36009
  1702
  by (fact inf_mono)
haftmann@32135
  1703
haftmann@32135
  1704
lemma Diff_mono: "A \<subseteq> C ==> D \<subseteq> B ==> A - B \<subseteq> C - D"
haftmann@32135
  1705
  by blast
haftmann@32135
  1706
haftmann@32135
  1707
lemma Compl_anti_mono: "A \<subseteq> B ==> -B \<subseteq> -A"
huffman@36009
  1708
  by (fact compl_mono)
haftmann@32135
  1709
wenzelm@60758
  1710
text \<open>\medskip Monotonicity of implications.\<close>
haftmann@32135
  1711
haftmann@32135
  1712
lemma in_mono: "A \<subseteq> B ==> x \<in> A --> x \<in> B"
haftmann@32135
  1713
  apply (rule impI)
haftmann@32135
  1714
  apply (erule subsetD, assumption)
haftmann@32135
  1715
  done
haftmann@32135
  1716
haftmann@32135
  1717
lemma conj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 & P2) --> (Q1 & Q2)"
haftmann@32135
  1718
  by iprover
haftmann@32135
  1719
haftmann@32135
  1720
lemma disj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 | P2) --> (Q1 | Q2)"
haftmann@32135
  1721
  by iprover
haftmann@32135
  1722
haftmann@32135
  1723
lemma imp_mono: "Q1 --> P1 ==> P2 --> Q2 ==> (P1 --> P2) --> (Q1 --> Q2)"
haftmann@32135
  1724
  by iprover
haftmann@32135
  1725
haftmann@32135
  1726
lemma imp_refl: "P --> P" ..
haftmann@32135
  1727
berghofe@33935
  1728
lemma not_mono: "Q --> P ==> ~ P --> ~ Q"
berghofe@33935
  1729
  by iprover
berghofe@33935
  1730
haftmann@32135
  1731
lemma ex_mono: "(!!x. P x --> Q x) ==> (EX x. P x) --> (EX x. Q x)"
haftmann@32135
  1732
  by iprover
haftmann@32135
  1733
haftmann@32135
  1734
lemma all_mono: "(!!x. P x --> Q x) ==> (ALL x. P x) --> (ALL x. Q x)"
haftmann@32135
  1735
  by iprover
haftmann@32135
  1736
haftmann@32135
  1737
lemma Collect_mono: "(!!x. P x --> Q x) ==> Collect P \<subseteq> Collect Q"
haftmann@32135
  1738
  by blast
haftmann@32135
  1739
haftmann@32135
  1740
lemma Int_Collect_mono:
haftmann@32135
  1741
    "A \<subseteq> B ==> (!!x. x \<in> A ==> P x --> Q x) ==> A \<inter> Collect P \<subseteq> B \<inter> Collect Q"
haftmann@32135
  1742
  by blast
haftmann@32135
  1743
haftmann@32135
  1744
lemmas basic_monos =
haftmann@32135
  1745
  subset_refl imp_refl disj_mono conj_mono
haftmann@32135
  1746
  ex_mono Collect_mono in_mono
haftmann@32135
  1747
haftmann@32135
  1748
lemma eq_to_mono: "a = b ==> c = d ==> b --> d ==> a --> c"
haftmann@32135
  1749
  by iprover
haftmann@32135
  1750
haftmann@32135
  1751
wenzelm@60758
  1752
subsubsection \<open>Inverse image of a function\<close>
haftmann@32135
  1753
haftmann@35416
  1754
definition vimage :: "('a => 'b) => 'b set => 'a set" (infixr "-`" 90) where
haftmann@37767
  1755
  "f -` B == {x. f x : B}"
haftmann@32135
  1756
haftmann@32135
  1757
lemma vimage_eq [simp]: "(a : f -` B) = (f a : B)"
haftmann@32135
  1758
  by (unfold vimage_def) blast
haftmann@32135
  1759
haftmann@32135
  1760
lemma vimage_singleton_eq: "(a : f -` {b}) = (f a = b)"
haftmann@32135
  1761
  by simp
haftmann@32135
  1762
haftmann@32135
  1763
lemma vimageI [intro]: "f a = b ==> b:B ==> a : f -` B"
haftmann@32135
  1764
  by (unfold vimage_def) blast
haftmann@32135
  1765
haftmann@32135
  1766
lemma vimageI2: "f a : A ==> a : f -` A"
haftmann@32135
  1767
  by (unfold vimage_def) fast
haftmann@32135
  1768
haftmann@32135
  1769
lemma vimageE [elim!]: "a: f -` B ==> (!!x. f a = x ==> x:B ==> P) ==> P"
haftmann@32135
  1770
  by (unfold vimage_def) blast
haftmann@32135
  1771
haftmann@32135
  1772
lemma vimageD: "a : f -` A ==> f a : A"
haftmann@32135
  1773
  by (unfold vimage_def) fast
haftmann@32135
  1774
haftmann@32135
  1775
lemma vimage_empty [simp]: "f -` {} = {}"
haftmann@32135
  1776
  by blast
haftmann@32135
  1777
haftmann@32135
  1778
lemma vimage_Compl: "f -` (-A) = -(f -` A)"
haftmann@32135
  1779
  by blast
haftmann@32135
  1780
haftmann@32135
  1781
lemma vimage_Un [simp]: "f -` (A Un B) = (f -` A) Un (f -` B)"
haftmann@32135
  1782
  by blast
haftmann@32135
  1783
haftmann@32135
  1784
lemma vimage_Int [simp]: "f -` (A Int B) = (f -` A) Int (f -` B)"
haftmann@32135
  1785
  by fast
haftmann@32135
  1786
haftmann@32135
  1787
lemma vimage_Collect_eq [simp]: "f -` Collect P = {y. P (f y)}"
haftmann@32135
  1788
  by blast
haftmann@32135
  1789
haftmann@32135
  1790
lemma vimage_Collect: "(!!x. P (f x) = Q x) ==> f -` (Collect P) = Collect Q"
haftmann@32135
  1791
  by blast
haftmann@32135
  1792
haftmann@32135
  1793
lemma vimage_insert: "f-`(insert a B) = (f-`{a}) Un (f-`B)"
wenzelm@60758
  1794
  -- \<open>NOT suitable for rewriting because of the recurrence of @{term "{a}"}.\<close>
haftmann@32135
  1795
  by blast
haftmann@32135
  1796
haftmann@32135
  1797
lemma vimage_Diff: "f -` (A - B) = (f -` A) - (f -` B)"
haftmann@32135
  1798
  by blast
haftmann@32135
  1799
haftmann@32135
  1800
lemma vimage_UNIV [simp]: "f -` UNIV = UNIV"
haftmann@32135
  1801
  by blast
haftmann@32135
  1802
haftmann@32135
  1803
lemma vimage_mono: "A \<subseteq> B ==> f -` A \<subseteq> f -` B"
wenzelm@60758
  1804
  -- \<open>monotonicity\<close>
haftmann@32135
  1805
  by blast
haftmann@32135
  1806
blanchet@54147
  1807
lemma vimage_image_eq: "f -` (f ` A) = {y. EX x:A. f x = f y}"
haftmann@32135
  1808
by (blast intro: sym)
haftmann@32135
  1809
haftmann@32135
  1810
lemma image_vimage_subset: "f ` (f -` A) <= A"
haftmann@32135
  1811
by blast
haftmann@32135
  1812
haftmann@32135
  1813
lemma image_vimage_eq [simp]: "f ` (f -` A) = A Int range f"
haftmann@32135
  1814
by blast
haftmann@32135
  1815
lp15@55775
  1816
lemma image_subset_iff_subset_vimage: "f ` A \<subseteq> B \<longleftrightarrow> A \<subseteq> f -` B"
lp15@59506
  1817
  by blast
lp15@55775
  1818
paulson@33533
  1819
lemma vimage_const [simp]: "((\<lambda>x. c) -` A) = (if c \<in> A then UNIV else {})"
paulson@33533
  1820
  by auto
paulson@33533
  1821
wenzelm@52143
  1822
lemma vimage_if [simp]: "((\<lambda>x. if x \<in> B then c else d) -` A) =
paulson@33533
  1823
   (if c \<in> A then (if d \<in> A then UNIV else B)
wenzelm@52143
  1824
    else if d \<in> A then -B else {})"
wenzelm@52143
  1825
  by (auto simp add: vimage_def)
paulson@33533
  1826
hoelzl@35576
  1827
lemma vimage_inter_cong:
hoelzl@35576
  1828
  "(\<And> w. w \<in> S \<Longrightarrow> f w = g w) \<Longrightarrow> f -` y \<inter> S = g -` y \<inter> S"
hoelzl@35576
  1829
  by auto
hoelzl@35576
  1830
haftmann@43898
  1831
lemma vimage_ident [simp]: "(%x. x) -` Y = Y"
haftmann@43898
  1832
  by blast
haftmann@32135
  1833
haftmann@32135
  1834
wenzelm@60758
  1835
subsubsection \<open>Getting the Contents of a Singleton Set\<close>
haftmann@32135
  1836
haftmann@39910
  1837
definition the_elem :: "'a set \<Rightarrow> 'a" where
haftmann@39910
  1838
  "the_elem X = (THE x. X = {x})"
haftmann@32135
  1839
haftmann@39910
  1840
lemma the_elem_eq [simp]: "the_elem {x} = x"
haftmann@39910
  1841
  by (simp add: the_elem_def)
haftmann@32135
  1842
haftmann@56740
  1843
lemma the_elem_image_unique:
haftmann@56740
  1844
  assumes "A \<noteq> {}"
haftmann@56740
  1845
  assumes *: "\<And>y. y \<in> A \<Longrightarrow> f y = f x"
haftmann@56740
  1846
  shows "the_elem (f ` A) = f x"
haftmann@56740
  1847
unfolding the_elem_def proof (rule the1_equality)
wenzelm@60758
  1848
  from \<open>A \<noteq> {}\<close> obtain y where "y \<in> A" by auto
haftmann@56740
  1849
  with * have "f x = f y" by simp
wenzelm@60758
  1850
  with \<open>y \<in> A\<close> have "f x \<in> f ` A" by blast
haftmann@56740
  1851
  with * show "f ` A = {f x}" by auto
haftmann@56740
  1852
  then show "\<exists>!x. f ` A = {x}" by auto
haftmann@56740
  1853
qed
haftmann@56740
  1854
haftmann@32135
  1855
wenzelm@60758
  1856
subsubsection \<open>Least value operator\<close>
haftmann@32135
  1857
haftmann@32135
  1858
lemma Least_mono:
haftmann@32135
  1859
  "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y
haftmann@32135
  1860
    ==> (LEAST y. y : f ` S) = f (LEAST x. x : S)"
wenzelm@60758
  1861
    -- \<open>Courtesy of Stephan Merz\<close>
haftmann@32135
  1862
  apply clarify
haftmann@32135
  1863
  apply (erule_tac P = "%x. x : S" in LeastI2_order, fast)
haftmann@32135
  1864
  apply (rule LeastI2_order)
haftmann@32135
  1865
  apply (auto elim: monoD intro!: order_antisym)
haftmann@32135
  1866
  done
haftmann@32135
  1867
haftmann@32135
  1868
wenzelm@60758
  1869
subsubsection \<open>Monad operation\<close>
haftmann@32135
  1870
haftmann@45959
  1871
definition bind :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where
haftmann@45959
  1872
  "bind A f = {x. \<exists>B \<in> f`A. x \<in> B}"
haftmann@32135
  1873
haftmann@45959
  1874
hide_const (open) bind
haftmann@45959
  1875
haftmann@46036
  1876
lemma bind_bind:
haftmann@46036
  1877
  fixes A :: "'a set"
haftmann@46036
  1878
  shows "Set.bind (Set.bind A B) C = Set.bind A (\<lambda>x. Set.bind (B x) C)"
haftmann@46036
  1879
  by (auto simp add: bind_def)
haftmann@46036
  1880
haftmann@46036
  1881
lemma empty_bind [simp]:
haftmann@46128
  1882
  "Set.bind {} f = {}"
haftmann@46036
  1883
  by (simp add: bind_def)
haftmann@46036
  1884
haftmann@46036
  1885
lemma nonempty_bind_const:
haftmann@46036
  1886
  "A \<noteq> {} \<Longrightarrow> Set.bind A (\<lambda>_. B) = B"
haftmann@46036
  1887
  by (auto simp add: bind_def)
haftmann@46036
  1888
haftmann@46036
  1889
lemma bind_const: "Set.bind A (\<lambda>_. B) = (if A = {} then {} else B)"
haftmann@46036
  1890
  by (auto simp add: bind_def)
haftmann@46036
  1891
Andreas@60057
  1892
lemma bind_singleton_conv_image: "Set.bind A (\<lambda>x. {f x}) = f ` A"
Andreas@60057
  1893
  by(auto simp add: bind_def)
haftmann@45959
  1894
wenzelm@60758
  1895
subsubsection \<open>Operations for execution\<close>
haftmann@45986
  1896
haftmann@45986
  1897
definition is_empty :: "'a set \<Rightarrow> bool" where
haftmann@46127
  1898
  [code_abbrev]: "is_empty A \<longleftrightarrow> A = {}"
haftmann@45986
  1899
haftmann@45986
  1900
hide_const (open) is_empty
haftmann@45986
  1901
haftmann@45986
  1902
definition remove :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" where
haftmann@46127
  1903
  [code_abbrev]: "remove x A = A - {x}"
haftmann@45986
  1904
haftmann@45986
  1905
hide_const (open) remove
haftmann@45986
  1906
haftmann@46128
  1907
lemma member_remove [simp]:
haftmann@46128
  1908
  "x \<in> Set.remove y A \<longleftrightarrow> x \<in> A \<and> x \<noteq> y"
haftmann@46128
  1909
  by (simp add: remove_def)
haftmann@46128
  1910
kuncar@49757
  1911
definition filter :: "('a \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'a set" where
kuncar@49757
  1912
  [code_abbrev]: "filter P A = {a \<in> A. P a}"
kuncar@49757
  1913
kuncar@49757
  1914
hide_const (open) filter
kuncar@49757
  1915
kuncar@49757
  1916
lemma member_filter [simp]:
kuncar@49757
  1917
  "x \<in> Set.filter P A \<longleftrightarrow> x \<in> A \<and> P x"
kuncar@49757
  1918
  by (simp add: filter_def)
haftmann@46128
  1919
haftmann@45986
  1920
instantiation set :: (equal) equal
haftmann@45986
  1921
begin
haftmann@45986
  1922
haftmann@45986
  1923
definition
haftmann@45986
  1924
  "HOL.equal A B \<longleftrightarrow> A \<subseteq> B \<and> B \<subseteq> A"
haftmann@45986
  1925
haftmann@45986
  1926
instance proof
haftmann@45986
  1927
qed (auto simp add: equal_set_def)
haftmann@45986
  1928
haftmann@45986
  1929
end
haftmann@45986
  1930
haftmann@46127
  1931
wenzelm@60758
  1932
text \<open>Misc\<close>
haftmann@32135
  1933
haftmann@45152
  1934
hide_const (open) member not_member
haftmann@32135
  1935
haftmann@32135
  1936
lemmas equalityI = subset_antisym
haftmann@32135
  1937
wenzelm@60758
  1938
ML \<open>
haftmann@32135
  1939
val Ball_def = @{thm Ball_def}
haftmann@32135
  1940
val Bex_def = @{thm Bex_def}
haftmann@32135
  1941
val CollectD = @{thm CollectD}
haftmann@32135
  1942
val CollectE = @{thm CollectE}
haftmann@32135
  1943
val CollectI = @{thm CollectI}
haftmann@32135
  1944
val Collect_conj_eq = @{thm Collect_conj_eq}
haftmann@32135
  1945
val Collect_mem_eq = @{thm Collect_mem_eq}
haftmann@32135
  1946
val IntD1 = @{thm IntD1}
haftmann@32135
  1947
val IntD2 = @{thm IntD2}
haftmann@32135
  1948
val IntE = @{thm IntE}
haftmann@32135
  1949
val IntI = @{thm IntI}
haftmann@32135
  1950
val Int_Collect = @{thm Int_Collect}
haftmann@32135
  1951
val UNIV_I = @{thm UNIV_I}
haftmann@32135
  1952
val UNIV_witness = @{thm UNIV_witness}
haftmann@32135
  1953
val UnE = @{thm UnE}
haftmann@32135
  1954
val UnI1 = @{thm UnI1}
haftmann@32135
  1955
val UnI2 = @{thm UnI2}
haftmann@32135
  1956
val ballE = @{thm ballE}
haftmann@32135
  1957
val ballI = @{thm ballI}
haftmann@32135
  1958
val bexCI = @{thm bexCI}
haftmann@32135
  1959
val bexE = @{thm bexE}
haftmann@32135
  1960
val bexI = @{thm bexI}
haftmann@32135
  1961
val bex_triv = @{thm bex_triv}
haftmann@32135
  1962
val bspec = @{thm bspec}
haftmann@32135
  1963
val contra_subsetD = @{thm contra_subsetD}
haftmann@32135
  1964
val equalityCE = @{thm equalityCE}
haftmann@32135
  1965
val equalityD1 = @{thm equalityD1}
haftmann@32135
  1966
val equalityD2 = @{thm equalityD2}
haftmann@32135
  1967
val equalityE = @{thm equalityE}
haftmann@32135
  1968
val equalityI = @{thm equalityI}
haftmann@32135
  1969
val imageE = @{thm imageE}
haftmann@32135
  1970
val imageI = @{thm imageI}
haftmann@32135
  1971
val image_Un = @{thm image_Un}
haftmann@32135
  1972
val image_insert = @{thm image_insert}
haftmann@32135
  1973
val insert_commute = @{thm insert_commute}
haftmann@32135
  1974
val insert_iff = @{thm insert_iff}
haftmann@32135
  1975
val mem_Collect_eq = @{thm mem_Collect_eq}
haftmann@32135
  1976
val rangeE = @{thm rangeE}
haftmann@32135
  1977
val rangeI = @{thm rangeI}
haftmann@32135
  1978
val range_eqI = @{thm range_eqI}
haftmann@32135
  1979
val subsetCE = @{thm subsetCE}
haftmann@32135
  1980
val subsetD = @{thm subsetD}
haftmann@32135
  1981
val subsetI = @{thm subsetI}
haftmann@32135
  1982
val subset_refl = @{thm subset_refl}
haftmann@32135
  1983
val subset_trans = @{thm subset_trans}
haftmann@32135
  1984
val vimageD = @{thm vimageD}
haftmann@32135
  1985
val vimageE = @{thm vimageE}
haftmann@32135
  1986
val vimageI = @{thm vimageI}
haftmann@32135
  1987
val vimageI2 = @{thm vimageI2}
haftmann@32135
  1988
val vimage_Collect = @{thm vimage_Collect}
haftmann@32135
  1989
val vimage_Int = @{thm vimage_Int}
haftmann@32135
  1990
val vimage_Un = @{thm vimage_Un}
wenzelm@60758
  1991
\<close>
haftmann@32135
  1992
haftmann@32077
  1993
end
haftmann@46853
  1994