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