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