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