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