src/HOL/Set.thy
 author haftmann Mon Jul 20 09:52:09 2009 +0200 (2009-07-20) changeset 32078 1c14f77201d4 parent 32075 e8e0fb5da77a parent 32077 3698947146b2 child 32081 1b7a901e2edc permissions -rw-r--r--
merged
     1 (*  Title:      HOL/Set.thy

     2     Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel

     3 *)

     4

     5 header {* Set theory for higher-order logic *}

     6

     7 theory Set

     8 imports Lattices

     9 begin

    10

    11 text {* A set in HOL is simply a predicate. *}

    12

    13 subsection {* Basic definitions and syntax *}

    14

    15 global

    16

    17 types 'a set = "'a => bool"

    18

    19 consts

    20   Collect       :: "('a => bool) => 'a set"              -- "comprehension"

    21   "op :"        :: "'a => 'a set => bool"                -- "membership"

    22

    23 local

    24

    25 notation

    26   "op :"  ("op :") and

    27   "op :"  ("(_/ : _)" [50, 51] 50)

    28

    29 defs

    30   mem_def [code]: "x : S == S x"

    31   Collect_def [code]: "Collect P == P"

    32

    33 abbreviation

    34   "not_mem x A == ~ (x : A)" -- "non-membership"

    35

    36 notation

    37   not_mem  ("op ~:") and

    38   not_mem  ("(_/ ~: _)" [50, 51] 50)

    39

    40 notation (xsymbols)

    41   "op :"  ("op \<in>") and

    42   "op :"  ("(_/ \<in> _)" [50, 51] 50) and

    43   not_mem  ("op \<notin>") and

    44   not_mem  ("(_/ \<notin> _)" [50, 51] 50)

    45

    46 notation (HTML output)

    47   "op :"  ("op \<in>") and

    48   "op :"  ("(_/ \<in> _)" [50, 51] 50) and

    49   not_mem  ("op \<notin>") and

    50   not_mem  ("(_/ \<notin> _)" [50, 51] 50)

    51

    52 syntax

    53   "@Coll"       :: "pttrn => bool => 'a set"              ("(1{_./ _})")

    54

    55 translations

    56   "{x. P}"      == "Collect (%x. P)"

    57

    58 definition Int :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Int" 70) where

    59   "A Int B \<equiv> {x. x \<in> A \<and> x \<in> B}"

    60

    61 definition Un :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Un" 65) where

    62   "A Un B \<equiv> {x. x \<in> A \<or> x \<in> B}"

    63

    64 notation (xsymbols)

    65   "Int"  (infixl "\<inter>" 70) and

    66   "Un"  (infixl "\<union>" 65)

    67

    68 notation (HTML output)

    69   "Int"  (infixl "\<inter>" 70) and

    70   "Un"  (infixl "\<union>" 65)

    71

    72 definition empty :: "'a set" ("{}") where

    73   "empty \<equiv> {x. False}"

    74

    75 definition insert :: "'a \<Rightarrow> 'a set \<Rightarrow> 'a set" where

    76   "insert a B \<equiv> {x. x = a} \<union> B"

    77

    78 definition UNIV :: "'a set" where

    79   "UNIV \<equiv> {x. True}"

    80

    81 syntax

    82   "@Finset"     :: "args => 'a set"                       ("{(_)}")

    83

    84 translations

    85   "{x, xs}"     == "CONST insert x {xs}"

    86   "{x}"         == "CONST insert x {}"

    87

    88 global

    89

    90 consts

    91   Ball          :: "'a set => ('a => bool) => bool"      -- "bounded universal quantifiers"

    92   Bex           :: "'a set => ('a => bool) => bool"      -- "bounded existential quantifiers"

    93   Bex1          :: "'a set => ('a => bool) => bool"      -- "bounded unique existential quantifiers"

    94

    95 local

    96

    97 defs

    98   Ball_def:     "Ball A P       == ALL x. x:A --> P(x)"

    99   Bex_def:      "Bex A P        == EX x. x:A & P(x)"

   100   Bex1_def:     "Bex1 A P       == EX! x. x:A & P(x)"

   101

   102 syntax

   103   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3ALL _:_./ _)" [0, 0, 10] 10)

   104   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3EX _:_./ _)" [0, 0, 10] 10)

   105   "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3EX! _:_./ _)" [0, 0, 10] 10)

   106   "_Bleast"     :: "id => 'a set => bool => 'a"           ("(3LEAST _:_./ _)" [0, 0, 10] 10)

   107

   108 syntax (HOL)

   109   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3! _:_./ _)" [0, 0, 10] 10)

   110   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3? _:_./ _)" [0, 0, 10] 10)

   111   "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3?! _:_./ _)" [0, 0, 10] 10)

   112

   113 syntax (xsymbols)

   114   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)

   115   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)

   116   "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)

   117   "_Bleast"     :: "id => 'a set => bool => 'a"           ("(3LEAST_\<in>_./ _)" [0, 0, 10] 10)

   118

   119 syntax (HTML output)

   120   "_Ball"       :: "pttrn => 'a set => bool => bool"      ("(3\<forall>_\<in>_./ _)" [0, 0, 10] 10)

   121   "_Bex"        :: "pttrn => 'a set => bool => bool"      ("(3\<exists>_\<in>_./ _)" [0, 0, 10] 10)

   122   "_Bex1"       :: "pttrn => 'a set => bool => bool"      ("(3\<exists>!_\<in>_./ _)" [0, 0, 10] 10)

   123

   124 translations

   125   "ALL x:A. P"  == "Ball A (%x. P)"

   126   "EX x:A. P"   == "Bex A (%x. P)"

   127   "EX! x:A. P"  == "Bex1 A (%x. P)"

   128   "LEAST x:A. P" => "LEAST x. x:A & P"

   129

   130

   131 subsection {* Additional concrete syntax *}

   132

   133 syntax

   134   "@SetCompr"   :: "'a => idts => bool => 'a set"         ("(1{_ |/_./ _})")

   135   "@Collect"    :: "idt => 'a set => bool => 'a set"      ("(1{_ :/ _./ _})")

   136

   137 syntax (xsymbols)

   138   "@Collect"    :: "idt => 'a set => bool => 'a set"      ("(1{_ \<in>/ _./ _})")

   139

   140 translations

   141   "{x:A. P}"    => "{x. x:A & P}"

   142

   143 abbreviation

   144   subset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where

   145   "subset \<equiv> less"

   146

   147 abbreviation

   148   subset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where

   149   "subset_eq \<equiv> less_eq"

   150

   151 notation (output)

   152   subset  ("op <") and

   153   subset  ("(_/ < _)" [50, 51] 50) and

   154   subset_eq  ("op <=") and

   155   subset_eq  ("(_/ <= _)" [50, 51] 50)

   156

   157 notation (xsymbols)

   158   subset  ("op \<subset>") and

   159   subset  ("(_/ \<subset> _)" [50, 51] 50) and

   160   subset_eq  ("op \<subseteq>") and

   161   subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)

   162

   163 notation (HTML output)

   164   subset  ("op \<subset>") and

   165   subset  ("(_/ \<subset> _)" [50, 51] 50) and

   166   subset_eq  ("op \<subseteq>") and

   167   subset_eq  ("(_/ \<subseteq> _)" [50, 51] 50)

   168

   169 abbreviation (input)

   170   supset :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where

   171   "supset \<equiv> greater"

   172

   173 abbreviation (input)

   174   supset_eq :: "'a set \<Rightarrow> 'a set \<Rightarrow> bool" where

   175   "supset_eq \<equiv> greater_eq"

   176

   177 notation (xsymbols)

   178   supset  ("op \<supset>") and

   179   supset  ("(_/ \<supset> _)" [50, 51] 50) and

   180   supset_eq  ("op \<supseteq>") and

   181   supset_eq  ("(_/ \<supseteq> _)" [50, 51] 50)

   182

   183

   184

   185 subsubsection "Bounded quantifiers"

   186

   187 syntax (output)

   188   "_setlessAll" :: "[idt, 'a, bool] => bool"  ("(3ALL _<_./ _)"  [0, 0, 10] 10)

   189   "_setlessEx"  :: "[idt, 'a, bool] => bool"  ("(3EX _<_./ _)"  [0, 0, 10] 10)

   190   "_setleAll"   :: "[idt, 'a, bool] => bool"  ("(3ALL _<=_./ _)" [0, 0, 10] 10)

   191   "_setleEx"    :: "[idt, 'a, bool] => bool"  ("(3EX _<=_./ _)" [0, 0, 10] 10)

   192   "_setleEx1"   :: "[idt, 'a, bool] => bool"  ("(3EX! _<=_./ _)" [0, 0, 10] 10)

   193

   194 syntax (xsymbols)

   195   "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)

   196   "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)

   197   "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)

   198   "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)

   199   "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)

   200

   201 syntax (HOL output)

   202   "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3! _<_./ _)"  [0, 0, 10] 10)

   203   "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3? _<_./ _)"  [0, 0, 10] 10)

   204   "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3! _<=_./ _)" [0, 0, 10] 10)

   205   "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3? _<=_./ _)" [0, 0, 10] 10)

   206   "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3?! _<=_./ _)" [0, 0, 10] 10)

   207

   208 syntax (HTML output)

   209   "_setlessAll" :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subset>_./ _)"  [0, 0, 10] 10)

   210   "_setlessEx"  :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subset>_./ _)"  [0, 0, 10] 10)

   211   "_setleAll"   :: "[idt, 'a, bool] => bool"   ("(3\<forall>_\<subseteq>_./ _)" [0, 0, 10] 10)

   212   "_setleEx"    :: "[idt, 'a, bool] => bool"   ("(3\<exists>_\<subseteq>_./ _)" [0, 0, 10] 10)

   213   "_setleEx1"   :: "[idt, 'a, bool] => bool"   ("(3\<exists>!_\<subseteq>_./ _)" [0, 0, 10] 10)

   214

   215 translations

   216  "\<forall>A\<subset>B. P"   =>  "ALL A. A \<subset> B --> P"

   217  "\<exists>A\<subset>B. P"   =>  "EX A. A \<subset> B & P"

   218  "\<forall>A\<subseteq>B. P"   =>  "ALL A. A \<subseteq> B --> P"

   219  "\<exists>A\<subseteq>B. P"   =>  "EX A. A \<subseteq> B & P"

   220  "\<exists>!A\<subseteq>B. P"  =>  "EX! A. A \<subseteq> B & P"

   221

   222 print_translation {*

   223 let

   224   val Type (set_type, _) = @{typ "'a set"};

   225   val All_binder = Syntax.binder_name @{const_syntax "All"};

   226   val Ex_binder = Syntax.binder_name @{const_syntax "Ex"};

   227   val impl = @{const_syntax "op -->"};

   228   val conj = @{const_syntax "op &"};

   229   val sbset = @{const_syntax "subset"};

   230   val sbset_eq = @{const_syntax "subset_eq"};

   231

   232   val trans =

   233    [((All_binder, impl, sbset), "_setlessAll"),

   234     ((All_binder, impl, sbset_eq), "_setleAll"),

   235     ((Ex_binder, conj, sbset), "_setlessEx"),

   236     ((Ex_binder, conj, sbset_eq), "_setleEx")];

   237

   238   fun mk v v' c n P =

   239     if v = v' andalso not (Term.exists_subterm (fn Free (x, _) => x = v | _ => false) n)

   240     then Syntax.const c $Syntax.mark_bound v'$ n $P else raise Match;   241   242 fun tr' q = (q,   243 fn [Const ("_bound", _)$ Free (v, Type (T, _)), Const (c, _) $(Const (d, _)$ (Const ("_bound", _) $Free (v', _))$ n) $P] =>   244 if T = (set_type) then case AList.lookup (op =) trans (q, c, d)   245 of NONE => raise Match   246 | SOME l => mk v v' l n P   247 else raise Match   248 | _ => raise Match);   249 in   250 [tr' All_binder, tr' Ex_binder]   251 end   252 *}   253   254   255 text {*   256 \medskip Translate between @{text "{e | x1...xn. P}"} and @{text   257 "{u. EX x1..xn. u = e & P}"}; @{text "{y. EX x1..xn. y = e & P}"} is   258 only translated if @{text "[0..n] subset bvs(e)"}.   259 *}   260   261 parse_translation {*   262 let   263 val ex_tr = snd (mk_binder_tr ("EX ", "Ex"));   264   265 fun nvars (Const ("_idts", _)$ _ $idts) = nvars idts + 1   266 | nvars _ = 1;   267   268 fun setcompr_tr [e, idts, b] =   269 let   270 val eq = Syntax.const "op ="$ Bound (nvars idts) $e;   271 val P = Syntax.const "op &"$ eq $b;   272 val exP = ex_tr [idts, P];   273 in Syntax.const "Collect"$ Term.absdummy (dummyT, exP) end;

   274

   275   in [("@SetCompr", setcompr_tr)] end;

   276 *}

   277

   278 (* To avoid eta-contraction of body: *)

   279 print_translation {*

   280 let

   281   fun btr' syn [A, Abs abs] =

   282     let val (x, t) = atomic_abs_tr' abs

   283     in Syntax.const syn $x$ A $t end   284 in [(@{const_syntax Ball}, btr' "_Ball"), (@{const_syntax Bex}, btr' "_Bex")] end   285 *}   286   287 print_translation {*   288 let   289 val ex_tr' = snd (mk_binder_tr' ("Ex", "DUMMY"));   290   291 fun setcompr_tr' [Abs (abs as (_, _, P))] =   292 let   293 fun check (Const ("Ex", _)$ Abs (_, _, P), n) = check (P, n + 1)

   294         | check (Const ("op &", _) $(Const ("op =", _)$ Bound m $e)$ P, n) =

   295             n > 0 andalso m = n andalso not (loose_bvar1 (P, n)) andalso

   296             ((0 upto (n - 1)) subset add_loose_bnos (e, 0, []))

   297         | check _ = false

   298

   299         fun tr' (_ $abs) =   300 let val _$ idts $(_$ (_ $_$ e) $Q) = ex_tr' [abs]   301 in Syntax.const "@SetCompr"$ e $idts$ Q end;

   302     in if check (P, 0) then tr' P

   303        else let val (x as _ $Free(xN,_), t) = atomic_abs_tr' abs   304 val M = Syntax.const "@Coll"$ x $t   305 in case t of   306 Const("op &",_)   307$ (Const("op :",_) $(Const("_bound",_)$ Free(yN,_)) $A)   308$ P =>

   309                    if xN=yN then Syntax.const "@Collect" $x$ A $P else M   310 | _ => M   311 end   312 end;   313 in [("Collect", setcompr_tr')] end;   314 *}   315   316   317 subsection {* Lemmas and proof tool setup *}   318   319 subsubsection {* Relating predicates and sets *}   320   321 lemma mem_Collect_eq [iff]: "(a : {x. P(x)}) = P(a)"   322 by (simp add: Collect_def mem_def)   323   324 lemma Collect_mem_eq [simp]: "{x. x:A} = A"   325 by (simp add: Collect_def mem_def)   326   327 lemma CollectI: "P(a) ==> a : {x. P(x)}"   328 by simp   329   330 lemma CollectD: "a : {x. P(x)} ==> P(a)"   331 by simp   332   333 lemma Collect_cong: "(!!x. P x = Q x) ==> {x. P(x)} = {x. Q(x)}"   334 by simp   335   336 lemmas CollectE = CollectD [elim_format]   337   338   339 subsubsection {* Bounded quantifiers *}   340   341 lemma ballI [intro!]: "(!!x. x:A ==> P x) ==> ALL x:A. P x"   342 by (simp add: Ball_def)   343   344 lemmas strip = impI allI ballI   345   346 lemma bspec [dest?]: "ALL x:A. P x ==> x:A ==> P x"   347 by (simp add: Ball_def)   348   349 lemma ballE [elim]: "ALL x:A. P x ==> (P x ==> Q) ==> (x ~: A ==> Q) ==> Q"   350 by (unfold Ball_def) blast   351   352 ML {* bind_thm ("rev_ballE", Thm.permute_prems 1 1 @{thm ballE}) *}   353   354 text {*   355 \medskip This tactic takes assumptions @{prop "ALL x:A. P x"} and   356 @{prop "a:A"}; creates assumption @{prop "P a"}.   357 *}   358   359 ML {*   360 fun ball_tac i = etac @{thm ballE} i THEN contr_tac (i + 1)   361 *}   362   363 text {*   364 Gives better instantiation for bound:   365 *}   366   367 declaration {* fn _ =>   368 Classical.map_cs (fn cs => cs addbefore ("bspec", datac @{thm bspec} 1))   369 *}   370   371 lemma bexI [intro]: "P x ==> x:A ==> EX x:A. P x"   372 -- {* Normally the best argument order: @{prop "P x"} constrains the   373 choice of @{prop "x:A"}. *}   374 by (unfold Bex_def) blast   375   376 lemma rev_bexI [intro?]: "x:A ==> P x ==> EX x:A. P x"   377 -- {* The best argument order when there is only one @{prop "x:A"}. *}   378 by (unfold Bex_def) blast   379   380 lemma bexCI: "(ALL x:A. ~P x ==> P a) ==> a:A ==> EX x:A. P x"   381 by (unfold Bex_def) blast   382   383 lemma bexE [elim!]: "EX x:A. P x ==> (!!x. x:A ==> P x ==> Q) ==> Q"   384 by (unfold Bex_def) blast   385   386 lemma ball_triv [simp]: "(ALL x:A. P) = ((EX x. x:A) --> P)"   387 -- {* Trival rewrite rule. *}   388 by (simp add: Ball_def)   389   390 lemma bex_triv [simp]: "(EX x:A. P) = ((EX x. x:A) & P)"   391 -- {* Dual form for existentials. *}   392 by (simp add: Bex_def)   393   394 lemma bex_triv_one_point1 [simp]: "(EX x:A. x = a) = (a:A)"   395 by blast   396   397 lemma bex_triv_one_point2 [simp]: "(EX x:A. a = x) = (a:A)"   398 by blast   399   400 lemma bex_one_point1 [simp]: "(EX x:A. x = a & P x) = (a:A & P a)"   401 by blast   402   403 lemma bex_one_point2 [simp]: "(EX x:A. a = x & P x) = (a:A & P a)"   404 by blast   405   406 lemma ball_one_point1 [simp]: "(ALL x:A. x = a --> P x) = (a:A --> P a)"   407 by blast   408   409 lemma ball_one_point2 [simp]: "(ALL x:A. a = x --> P x) = (a:A --> P a)"   410 by blast   411   412 ML {*   413 local   414 val unfold_bex_tac = unfold_tac @{thms "Bex_def"};   415 fun prove_bex_tac ss = unfold_bex_tac ss THEN Quantifier1.prove_one_point_ex_tac;   416 val rearrange_bex = Quantifier1.rearrange_bex prove_bex_tac;   417   418 val unfold_ball_tac = unfold_tac @{thms "Ball_def"};   419 fun prove_ball_tac ss = unfold_ball_tac ss THEN Quantifier1.prove_one_point_all_tac;   420 val rearrange_ball = Quantifier1.rearrange_ball prove_ball_tac;   421 in   422 val defBEX_regroup = Simplifier.simproc @{theory}   423 "defined BEX" ["EX x:A. P x & Q x"] rearrange_bex;   424 val defBALL_regroup = Simplifier.simproc @{theory}   425 "defined BALL" ["ALL x:A. P x --> Q x"] rearrange_ball;   426 end;   427   428 Addsimprocs [defBALL_regroup, defBEX_regroup];   429 *}   430   431   432 subsubsection {* Congruence rules *}   433   434 lemma ball_cong:   435 "A = B ==> (!!x. x:B ==> P x = Q x) ==>   436 (ALL x:A. P x) = (ALL x:B. Q x)"   437 by (simp add: Ball_def)   438   439 lemma strong_ball_cong [cong]:   440 "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>   441 (ALL x:A. P x) = (ALL x:B. Q x)"   442 by (simp add: simp_implies_def Ball_def)   443   444 lemma bex_cong:   445 "A = B ==> (!!x. x:B ==> P x = Q x) ==>   446 (EX x:A. P x) = (EX x:B. Q x)"   447 by (simp add: Bex_def cong: conj_cong)   448   449 lemma strong_bex_cong [cong]:   450 "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>   451 (EX x:A. P x) = (EX x:B. Q x)"   452 by (simp add: simp_implies_def Bex_def cong: conj_cong)   453   454   455 subsubsection {* Subsets *}   456   457 lemma subsetI [atp,intro!]: "(!!x. x:A ==> x:B) ==> A \<subseteq> B"   458 by (auto simp add: mem_def intro: predicate1I)   459   460 text {*   461 \medskip Map the type @{text "'a set => anything"} to just @{typ   462 'a}; for overloading constants whose first argument has type @{typ   463 "'a set"}.   464 *}   465   466 lemma subsetD [elim, intro?]: "A \<subseteq> B ==> c \<in> A ==> c \<in> B"   467 -- {* Rule in Modus Ponens style. *}   468 by (unfold mem_def) blast   469   470 lemma rev_subsetD [intro?]: "c \<in> A ==> A \<subseteq> B ==> c \<in> B"   471 -- {* The same, with reversed premises for use with @{text erule} --   472 cf @{text rev_mp}. *}   473 by (rule subsetD)   474   475 text {*   476 \medskip Converts @{prop "A \<subseteq> B"} to @{prop "x \<in> A ==> x \<in> B"}.   477 *}   478   479 ML {*   480 fun impOfSubs th = th RSN (2, @{thm rev_subsetD})   481 *}   482   483 lemma subsetCE [elim]: "A \<subseteq> B ==> (c \<notin> A ==> P) ==> (c \<in> B ==> P) ==> P"   484 -- {* Classical elimination rule. *}   485 by (unfold mem_def) blast   486   487 lemma subset_eq: "A \<le> B = (\<forall>x\<in>A. x \<in> B)" by blast   488   489 text {*   490 \medskip Takes assumptions @{prop "A \<subseteq> B"}; @{prop "c \<in> A"} and   491 creates the assumption @{prop "c \<in> B"}.   492 *}   493   494 ML {*   495 fun set_mp_tac i = etac @{thm subsetCE} i THEN mp_tac i   496 *}   497   498 lemma contra_subsetD: "A \<subseteq> B ==> c \<notin> B ==> c \<notin> A"   499 by blast   500   501 lemma subset_refl [simp,atp]: "A \<subseteq> A"   502 by fast   503   504 lemma subset_trans: "A \<subseteq> B ==> B \<subseteq> C ==> A \<subseteq> C"   505 by blast   506   507   508 subsubsection {* Equality *}   509   510 lemma set_ext: assumes prem: "(!!x. (x:A) = (x:B))" shows "A = B"   511 apply (rule prem [THEN ext, THEN arg_cong, THEN box_equals])   512 apply (rule Collect_mem_eq)   513 apply (rule Collect_mem_eq)   514 done   515   516 (* Due to Brian Huffman *)   517 lemma expand_set_eq: "(A = B) = (ALL x. (x:A) = (x:B))"   518 by(auto intro:set_ext)   519   520 lemma subset_antisym [intro!]: "A \<subseteq> B ==> B \<subseteq> A ==> A = B"   521 -- {* Anti-symmetry of the subset relation. *}   522 by (iprover intro: set_ext subsetD)   523   524 text {*   525 \medskip Equality rules from ZF set theory -- are they appropriate   526 here?   527 *}   528   529 lemma equalityD1: "A = B ==> A \<subseteq> B"   530 by (simp add: subset_refl)   531   532 lemma equalityD2: "A = B ==> B \<subseteq> A"   533 by (simp add: subset_refl)   534   535 text {*   536 \medskip Be careful when adding this to the claset as @{text   537 subset_empty} is in the simpset: @{prop "A = {}"} goes to @{prop "{}   538 \<subseteq> A"} and @{prop "A \<subseteq> {}"} and then back to @{prop "A = {}"}!   539 *}   540   541 lemma equalityE: "A = B ==> (A \<subseteq> B ==> B \<subseteq> A ==> P) ==> P"   542 by (simp add: subset_refl)   543   544 lemma equalityCE [elim]:   545 "A = B ==> (c \<in> A ==> c \<in> B ==> P) ==> (c \<notin> A ==> c \<notin> B ==> P) ==> P"   546 by blast   547   548 lemma eqset_imp_iff: "A = B ==> (x : A) = (x : B)"   549 by simp   550   551 lemma eqelem_imp_iff: "x = y ==> (x : A) = (y : A)"   552 by simp   553   554   555 subsubsection {* The universal set -- UNIV *}   556   557 lemma UNIV_I [simp]: "x : UNIV"   558 by (simp add: UNIV_def)   559   560 declare UNIV_I [intro] -- {* unsafe makes it less likely to cause problems *}   561   562 lemma UNIV_witness [intro?]: "EX x. x : UNIV"   563 by simp   564   565 lemma subset_UNIV [simp]: "A \<subseteq> UNIV"   566 by (rule subsetI) (rule UNIV_I)   567   568 text {*   569 \medskip Eta-contracting these two rules (to remove @{text P})   570 causes them to be ignored because of their interaction with   571 congruence rules.   572 *}   573   574 lemma ball_UNIV [simp]: "Ball UNIV P = All P"   575 by (simp add: Ball_def)   576   577 lemma bex_UNIV [simp]: "Bex UNIV P = Ex P"   578 by (simp add: Bex_def)   579   580 lemma UNIV_eq_I: "(\<And>x. x \<in> A) \<Longrightarrow> UNIV = A"   581 by auto   582   583   584 subsubsection {* The empty set *}   585   586 lemma empty_iff [simp]: "(c : {}) = False"   587 by (simp add: empty_def)   588   589 lemma emptyE [elim!]: "a : {} ==> P"   590 by simp   591   592 lemma empty_subsetI [iff]: "{} \<subseteq> A"   593 -- {* One effect is to delete the ASSUMPTION @{prop "{} <= A"} *}   594 by blast   595   596 lemma equals0I: "(!!y. y \<in> A ==> False) ==> A = {}"   597 by blast   598   599 lemma equals0D: "A = {} ==> a \<notin> A"   600 -- {* Use for reasoning about disjointness: @{prop "A Int B = {}"} *}   601 by blast   602   603 lemma ball_empty [simp]: "Ball {} P = True"   604 by (simp add: Ball_def)   605   606 lemma bex_empty [simp]: "Bex {} P = False"   607 by (simp add: Bex_def)   608   609 lemma UNIV_not_empty [iff]: "UNIV ~= {}"   610 by (blast elim: equalityE)   611   612   613 subsubsection {* The Powerset operator -- Pow *}   614   615 definition Pow :: "'a set => 'a set set" where   616 Pow_def: "Pow A = {B. B \<le> A}"   617   618 lemma Pow_iff [iff]: "(A \<in> Pow B) = (A \<subseteq> B)"   619 by (simp add: Pow_def)   620   621 lemma PowI: "A \<subseteq> B ==> A \<in> Pow B"   622 by (simp add: Pow_def)   623   624 lemma PowD: "A \<in> Pow B ==> A \<subseteq> B"   625 by (simp add: Pow_def)   626   627 lemma Pow_bottom: "{} \<in> Pow B"   628 by simp   629   630 lemma Pow_top: "A \<in> Pow A"   631 by (simp add: subset_refl)   632   633   634 subsubsection {* Set complement *}   635   636 lemma Compl_iff [simp]: "(c \<in> -A) = (c \<notin> A)"   637 by (simp add: mem_def fun_Compl_def bool_Compl_def)   638   639 lemma ComplI [intro!]: "(c \<in> A ==> False) ==> c \<in> -A"   640 by (unfold mem_def fun_Compl_def bool_Compl_def) blast   641   642 text {*   643 \medskip This form, with negated conclusion, works well with the   644 Classical prover. Negated assumptions behave like formulae on the   645 right side of the notional turnstile ... *}   646   647 lemma ComplD [dest!]: "c : -A ==> c~:A"   648 by (simp add: mem_def fun_Compl_def bool_Compl_def)   649   650 lemmas ComplE = ComplD [elim_format]   651   652 lemma Compl_eq: "- A = {x. ~ x : A}" by blast   653   654   655 subsubsection {* Binary union -- Un *}   656   657 lemma Un_iff [simp]: "(c : A Un B) = (c:A | c:B)"   658 by (unfold Un_def) blast   659   660 lemma UnI1 [elim?]: "c:A ==> c : A Un B"   661 by simp   662   663 lemma UnI2 [elim?]: "c:B ==> c : A Un B"   664 by simp   665   666 text {*   667 \medskip Classical introduction rule: no commitment to @{prop A} vs   668 @{prop B}.   669 *}   670   671 lemma UnCI [intro!]: "(c~:B ==> c:A) ==> c : A Un B"   672 by auto   673   674 lemma UnE [elim!]: "c : A Un B ==> (c:A ==> P) ==> (c:B ==> P) ==> P"   675 by (unfold Un_def) blast   676   677   678 subsubsection {* Binary intersection -- Int *}   679   680 lemma Int_iff [simp]: "(c : A Int B) = (c:A & c:B)"   681 by (unfold Int_def) blast   682   683 lemma IntI [intro!]: "c:A ==> c:B ==> c : A Int B"   684 by simp   685   686 lemma IntD1: "c : A Int B ==> c:A"   687 by simp   688   689 lemma IntD2: "c : A Int B ==> c:B"   690 by simp   691   692 lemma IntE [elim!]: "c : A Int B ==> (c:A ==> c:B ==> P) ==> P"   693 by simp   694   695   696 subsubsection {* Set difference *}   697   698 lemma Diff_iff [simp]: "(c : A - B) = (c:A & c~:B)"   699 by (simp add: mem_def fun_diff_def bool_diff_def)   700   701 lemma DiffI [intro!]: "c : A ==> c ~: B ==> c : A - B"   702 by simp   703   704 lemma DiffD1: "c : A - B ==> c : A"   705 by simp   706   707 lemma DiffD2: "c : A - B ==> c : B ==> P"   708 by simp   709   710 lemma DiffE [elim!]: "c : A - B ==> (c:A ==> c~:B ==> P) ==> P"   711 by simp   712   713 lemma set_diff_eq: "A - B = {x. x : A & ~ x : B}" by blast   714   715 lemma Compl_eq_Diff_UNIV: "-A = (UNIV - A)"   716 by blast   717   718   719 subsubsection {* Augmenting a set -- @{const insert} *}   720   721 lemma insert_iff [simp]: "(a : insert b A) = (a = b | a:A)"   722 by (unfold insert_def) blast   723   724 lemma insertI1: "a : insert a B"   725 by simp   726   727 lemma insertI2: "a : B ==> a : insert b B"   728 by simp   729   730 lemma insertE [elim!]: "a : insert b A ==> (a = b ==> P) ==> (a:A ==> P) ==> P"   731 by (unfold insert_def) blast   732   733 lemma insertCI [intro!]: "(a~:B ==> a = b) ==> a: insert b B"   734 -- {* Classical introduction rule. *}   735 by auto   736   737 lemma subset_insert_iff: "(A \<subseteq> insert x B) = (if x:A then A - {x} \<subseteq> B else A \<subseteq> B)"   738 by auto   739   740 lemma set_insert:   741 assumes "x \<in> A"   742 obtains B where "A = insert x B" and "x \<notin> B"   743 proof   744 from assms show "A = insert x (A - {x})" by blast   745 next   746 show "x \<notin> A - {x}" by blast   747 qed   748   749 lemma insert_ident: "x ~: A ==> x ~: B ==> (insert x A = insert x B) = (A = B)"   750 by auto   751   752 subsubsection {* Singletons, using insert *}   753   754 lemma singletonI [intro!,noatp]: "a : {a}"   755 -- {* Redundant? But unlike @{text insertCI}, it proves the subgoal immediately! *}   756 by (rule insertI1)   757   758 lemma singletonD [dest!,noatp]: "b : {a} ==> b = a"   759 by blast   760   761 lemmas singletonE = singletonD [elim_format]   762   763 lemma singleton_iff: "(b : {a}) = (b = a)"   764 by blast   765   766 lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"   767 by blast   768   769 lemma singleton_insert_inj_eq [iff,noatp]:   770 "({b} = insert a A) = (a = b & A \<subseteq> {b})"   771 by blast   772   773 lemma singleton_insert_inj_eq' [iff,noatp]:   774 "(insert a A = {b}) = (a = b & A \<subseteq> {b})"   775 by blast   776   777 lemma subset_singletonD: "A \<subseteq> {x} ==> A = {} | A = {x}"   778 by fast   779   780 lemma singleton_conv [simp]: "{x. x = a} = {a}"   781 by blast   782   783 lemma singleton_conv2 [simp]: "{x. a = x} = {a}"   784 by blast   785   786 lemma diff_single_insert: "A - {x} \<subseteq> B ==> x \<in> A ==> A \<subseteq> insert x B"   787 by blast   788   789 lemma doubleton_eq_iff: "({a,b} = {c,d}) = (a=c & b=d | a=d & b=c)"   790 by (blast elim: equalityE)   791   792   793 subsubsection {* Image of a set under a function *}   794   795 text {*   796 Frequently @{term b} does not have the syntactic form of @{term "f x"}.   797 *}   798   799 definition image :: "('a => 'b) => 'a set => 'b set" (infixr "" 90) where   800 image_def [noatp]: "f  A = {y. EX x:A. y = f(x)}"   801   802 abbreviation   803 range :: "('a => 'b) => 'b set" where -- "of function"   804 "range f == f  UNIV"   805   806 lemma image_eqI [simp, intro]: "b = f x ==> x:A ==> b : fA"   807 by (unfold image_def) blast   808   809 lemma imageI: "x : A ==> f x : f  A"   810 by (rule image_eqI) (rule refl)   811   812 lemma rev_image_eqI: "x:A ==> b = f x ==> b : fA"   813 -- {* This version's more effective when we already have the   814 required @{term x}. *}   815 by (unfold image_def) blast   816   817 lemma imageE [elim!]:   818 "b : (%x. f x)A ==> (!!x. b = f x ==> x:A ==> P) ==> P"   819 -- {* The eta-expansion gives variable-name preservation. *}   820 by (unfold image_def) blast   821   822 lemma image_Un: "f(A Un B) = fA Un fB"   823 by blast   824   825 lemma image_iff: "(z : fA) = (EX x:A. z = f x)"   826 by blast   827   828 lemma image_subset_iff: "(fA \<subseteq> B) = (\<forall>x\<in>A. f x \<in> B)"   829 -- {* This rewrite rule would confuse users if made default. *}   830 by blast   831   832 lemma subset_image_iff: "(B \<subseteq> fA) = (EX AA. AA \<subseteq> A & B = fAA)"   833 apply safe   834 prefer 2 apply fast   835 apply (rule_tac x = "{a. a : A & f a : B}" in exI, fast)   836 done   837   838 lemma image_subsetI: "(!!x. x \<in> A ==> f x \<in> B) ==> fA \<subseteq> B"   839 -- {* Replaces the three steps @{text subsetI}, @{text imageE},   840 @{text hypsubst}, but breaks too many existing proofs. *}   841 by blast   842   843 text {*   844 \medskip Range of a function -- just a translation for image!   845 *}   846   847 lemma range_eqI: "b = f x ==> b \<in> range f"   848 by simp   849   850 lemma rangeI: "f x \<in> range f"   851 by simp   852   853 lemma rangeE [elim?]: "b \<in> range (\<lambda>x. f x) ==> (!!x. b = f x ==> P) ==> P"   854 by blast   855   856   857 subsection {* Complete lattices *}   858   859 notation   860 less_eq (infix "\<sqsubseteq>" 50) and   861 less (infix "\<sqsubset>" 50) and   862 inf (infixl "\<sqinter>" 70) and   863 sup (infixl "\<squnion>" 65)   864   865 class complete_lattice = lattice + bot + top +   866 fixes Inf :: "'a set \<Rightarrow> 'a" ("\<Sqinter>_" [900] 900)   867 and Sup :: "'a set \<Rightarrow> 'a" ("\<Squnion>_" [900] 900)   868 assumes Inf_lower: "x \<in> A \<Longrightarrow> \<Sqinter>A \<sqsubseteq> x"   869 and Inf_greatest: "(\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x) \<Longrightarrow> z \<sqsubseteq> \<Sqinter>A"   870 assumes Sup_upper: "x \<in> A \<Longrightarrow> x \<sqsubseteq> \<Squnion>A"   871 and Sup_least: "(\<And>x. x \<in> A \<Longrightarrow> x \<sqsubseteq> z) \<Longrightarrow> \<Squnion>A \<sqsubseteq> z"   872 begin   873   874 lemma Inf_Sup: "\<Sqinter>A = \<Squnion>{b. \<forall>a \<in> A. b \<le> a}"   875 by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)   876   877 lemma Sup_Inf: "\<Squnion>A = \<Sqinter>{b. \<forall>a \<in> A. a \<le> b}"   878 by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)   879   880 lemma Inf_Univ: "\<Sqinter>UNIV = \<Squnion>{}"   881 unfolding Sup_Inf by (auto simp add: UNIV_def)   882   883 lemma Sup_Univ: "\<Squnion>UNIV = \<Sqinter>{}"   884 unfolding Inf_Sup by (auto simp add: UNIV_def)   885   886 lemma Inf_insert: "\<Sqinter>insert a A = a \<sqinter> \<Sqinter>A"   887 by (auto intro: le_infI le_infI1 le_infI2 antisym Inf_greatest Inf_lower)   888   889 lemma Sup_insert: "\<Squnion>insert a A = a \<squnion> \<Squnion>A"   890 by (auto intro: le_supI le_supI1 le_supI2 antisym Sup_least Sup_upper)   891   892 lemma Inf_singleton [simp]:   893 "\<Sqinter>{a} = a"   894 by (auto intro: antisym Inf_lower Inf_greatest)   895   896 lemma Sup_singleton [simp]:   897 "\<Squnion>{a} = a"   898 by (auto intro: antisym Sup_upper Sup_least)   899   900 lemma Inf_insert_simp:   901 "\<Sqinter>insert a A = (if A = {} then a else a \<sqinter> \<Sqinter>A)"   902 by (cases "A = {}") (simp_all, simp add: Inf_insert)   903   904 lemma Sup_insert_simp:   905 "\<Squnion>insert a A = (if A = {} then a else a \<squnion> \<Squnion>A)"   906 by (cases "A = {}") (simp_all, simp add: Sup_insert)   907   908 lemma Inf_binary:   909 "\<Sqinter>{a, b} = a \<sqinter> b"   910 by (auto simp add: Inf_insert_simp)   911   912 lemma Sup_binary:   913 "\<Squnion>{a, b} = a \<squnion> b"   914 by (auto simp add: Sup_insert_simp)   915   916 lemma bot_def:   917 "bot = \<Squnion>{}"   918 by (auto intro: antisym Sup_least)   919   920 lemma top_def:   921 "top = \<Sqinter>{}"   922 by (auto intro: antisym Inf_greatest)   923   924 lemma sup_bot [simp]:   925 "x \<squnion> bot = x"   926 using bot_least [of x] by (simp add: le_iff_sup sup_commute)   927   928 lemma inf_top [simp]:   929 "x \<sqinter> top = x"   930 using top_greatest [of x] by (simp add: le_iff_inf inf_commute)   931   932 definition SUPR :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" where   933 "SUPR A f == \<Squnion> (f  A)"   934   935 definition INFI :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" where   936 "INFI A f == \<Sqinter> (f  A)"   937   938 end   939   940 syntax   941 "_SUP1" :: "pttrns => 'b => 'b" ("(3SUP _./ _)" [0, 10] 10)   942 "_SUP" :: "pttrn => 'a set => 'b => 'b" ("(3SUP _:_./ _)" [0, 10] 10)   943 "_INF1" :: "pttrns => 'b => 'b" ("(3INF _./ _)" [0, 10] 10)   944 "_INF" :: "pttrn => 'a set => 'b => 'b" ("(3INF _:_./ _)" [0, 10] 10)   945   946 translations   947 "SUP x y. B" == "SUP x. SUP y. B"   948 "SUP x. B" == "CONST SUPR CONST UNIV (%x. B)"   949 "SUP x. B" == "SUP x:CONST UNIV. B"   950 "SUP x:A. B" == "CONST SUPR A (%x. B)"   951 "INF x y. B" == "INF x. INF y. B"   952 "INF x. B" == "CONST INFI CONST UNIV (%x. B)"   953 "INF x. B" == "INF x:CONST UNIV. B"   954 "INF x:A. B" == "CONST INFI A (%x. B)"   955   956 (* To avoid eta-contraction of body: *)   957 print_translation {*   958 let   959 fun btr' syn (A :: Abs abs :: ts) =   960 let val (x,t) = atomic_abs_tr' abs   961 in list_comb (Syntax.const syn$ x $A$ t, ts) end

   962   val const_syntax_name = Sign.const_syntax_name @{theory} o fst o dest_Const

   963 in

   964 [(const_syntax_name @{term SUPR}, btr' "_SUP"),(const_syntax_name @{term "INFI"}, btr' "_INF")]

   965 end

   966 *}

   967

   968 context complete_lattice

   969 begin

   970

   971 lemma le_SUPI: "i : A \<Longrightarrow> M i \<le> (SUP i:A. M i)"

   972   by (auto simp add: SUPR_def intro: Sup_upper)

   973

   974 lemma SUP_leI: "(\<And>i. i : A \<Longrightarrow> M i \<le> u) \<Longrightarrow> (SUP i:A. M i) \<le> u"

   975   by (auto simp add: SUPR_def intro: Sup_least)

   976

   977 lemma INF_leI: "i : A \<Longrightarrow> (INF i:A. M i) \<le> M i"

   978   by (auto simp add: INFI_def intro: Inf_lower)

   979

   980 lemma le_INFI: "(\<And>i. i : A \<Longrightarrow> u \<le> M i) \<Longrightarrow> u \<le> (INF i:A. M i)"

   981   by (auto simp add: INFI_def intro: Inf_greatest)

   982

   983 lemma SUP_const[simp]: "A \<noteq> {} \<Longrightarrow> (SUP i:A. M) = M"

   984   by (auto intro: antisym SUP_leI le_SUPI)

   985

   986 lemma INF_const[simp]: "A \<noteq> {} \<Longrightarrow> (INF i:A. M) = M"

   987   by (auto intro: antisym INF_leI le_INFI)

   988

   989 end

   990

   991

   992 subsection {* Bool as complete lattice *}

   993

   994 instantiation bool :: complete_lattice

   995 begin

   996

   997 definition

   998   Inf_bool_def: "\<Sqinter>A \<longleftrightarrow> (\<forall>x\<in>A. x)"

   999

  1000 definition

  1001   Sup_bool_def: "\<Squnion>A \<longleftrightarrow> (\<exists>x\<in>A. x)"

  1002

  1003 instance proof

  1004 qed (auto simp add: Inf_bool_def Sup_bool_def le_bool_def)

  1005

  1006 end

  1007

  1008 lemma Inf_empty_bool [simp]:

  1009   "\<Sqinter>{}"

  1010   unfolding Inf_bool_def by auto

  1011

  1012 lemma not_Sup_empty_bool [simp]:

  1013   "\<not> \<Squnion>{}"

  1014   unfolding Sup_bool_def by auto

  1015

  1016

  1017 subsection {* Fun as complete lattice *}

  1018

  1019 instantiation "fun" :: (type, complete_lattice) complete_lattice

  1020 begin

  1021

  1022 definition

  1023   Inf_fun_def [code del]: "\<Sqinter>A = (\<lambda>x. \<Sqinter>{y. \<exists>f\<in>A. y = f x})"

  1024

  1025 definition

  1026   Sup_fun_def [code del]: "\<Squnion>A = (\<lambda>x. \<Squnion>{y. \<exists>f\<in>A. y = f x})"

  1027

  1028 instance proof

  1029 qed (auto simp add: Inf_fun_def Sup_fun_def le_fun_def

  1030   intro: Inf_lower Sup_upper Inf_greatest Sup_least)

  1031

  1032 end

  1033

  1034 lemma Inf_empty_fun:

  1035   "\<Sqinter>{} = (\<lambda>_. \<Sqinter>{})"

  1036   by rule (simp add: Inf_fun_def, simp add: empty_def)

  1037

  1038 lemma Sup_empty_fun:

  1039   "\<Squnion>{} = (\<lambda>_. \<Squnion>{})"

  1040   by rule (simp add: Sup_fun_def, simp add: empty_def)

  1041

  1042

  1043 subsection {* Set as lattice *}

  1044

  1045 definition INTER :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where

  1046   "INTER A B \<equiv> {y. \<forall>x\<in>A. y \<in> B x}"

  1047

  1048 definition UNION :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where

  1049   "UNION A B \<equiv> {y. \<exists>x\<in>A. y \<in> B x}"

  1050

  1051 definition Inter :: "'a set set \<Rightarrow> 'a set" where

  1052   "Inter S \<equiv> INTER S (\<lambda>x. x)"

  1053

  1054 definition Union :: "'a set set \<Rightarrow> 'a set" where

  1055   "Union S \<equiv> UNION S (\<lambda>x. x)"

  1056

  1057 notation (xsymbols)

  1058   Inter  ("\<Inter>_" [90] 90) and

  1059   Union  ("\<Union>_" [90] 90)

  1060

  1061 syntax

  1062   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3INT _./ _)" [0, 10] 10)

  1063   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3UN _./ _)" [0, 10] 10)

  1064   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3INT _:_./ _)" [0, 10] 10)

  1065   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3UN _:_./ _)" [0, 10] 10)

  1066

  1067 syntax (xsymbols)

  1068   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>_./ _)" [0, 10] 10)

  1069   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>_./ _)" [0, 10] 10)

  1070   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>_\<in>_./ _)" [0, 10] 10)

  1071   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>_\<in>_./ _)" [0, 10] 10)

  1072

  1073 syntax (latex output)

  1074   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>(00\<^bsub>_\<^esub>)/ _)" [0, 10] 10)

  1075   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>(00\<^bsub>_\<^esub>)/ _)" [0, 10] 10)

  1076   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>(00\<^bsub>_\<in>_\<^esub>)/ _)" [0, 10] 10)

  1077   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>(00\<^bsub>_\<in>_\<^esub>)/ _)" [0, 10] 10)

  1078

  1079 translations

  1080   "INT x y. B"  == "INT x. INT y. B"

  1081   "INT x. B"    == "CONST INTER CONST UNIV (%x. B)"

  1082   "INT x. B"    == "INT x:CONST UNIV. B"

  1083   "INT x:A. B"  == "CONST INTER A (%x. B)"

  1084   "UN x y. B"   == "UN x. UN y. B"

  1085   "UN x. B"     == "CONST UNION CONST UNIV (%x. B)"

  1086   "UN x. B"     == "UN x:CONST UNIV. B"

  1087   "UN x:A. B"   == "CONST UNION A (%x. B)"

  1088

  1089 text {*

  1090   Note the difference between ordinary xsymbol syntax of indexed

  1091   unions and intersections (e.g.\ @{text"\<Union>a\<^isub>1\<in>A\<^isub>1. B"})

  1092   and their \LaTeX\ rendition: @{term"\<Union>a\<^isub>1\<in>A\<^isub>1. B"}. The

  1093   former does not make the index expression a subscript of the

  1094   union/intersection symbol because this leads to problems with nested

  1095   subscripts in Proof General.

  1096 *}

  1097

  1098 (* To avoid eta-contraction of body: *)

  1099 print_translation {*

  1100 let

  1101   fun btr' syn [A, Abs abs] =

  1102     let val (x, t) = atomic_abs_tr' abs

  1103     in Syntax.const syn $x$ A \$ t end

  1104 in [(@{const_syntax UNION}, btr' "@UNION"),(@{const_syntax INTER}, btr' "@INTER")] end

  1105 *}

  1106

  1107 lemma Inter_image_eq [simp]:

  1108   "\<Inter>(BA) = (\<Inter>x\<in>A. B x)"

  1109   by (auto simp add: Inter_def INTER_def image_def)

  1110

  1111 lemma Union_image_eq [simp]:

  1112   "\<Union>(BA) = (\<Union>x\<in>A. B x)"

  1113   by (auto simp add: Union_def UNION_def image_def)

  1114

  1115 lemma inf_set_eq: "A \<sqinter> B = A \<inter> B"

  1116   by (simp add: inf_fun_eq inf_bool_eq Int_def Collect_def mem_def)

  1117

  1118 lemma sup_set_eq: "A \<squnion> B = A \<union> B"

  1119   by (simp add: sup_fun_eq sup_bool_eq Un_def Collect_def mem_def)

  1120

  1121 lemma mono_Int: "mono f \<Longrightarrow> f (A \<inter> B) \<subseteq> f A \<inter> f B"

  1122   apply (fold inf_set_eq sup_set_eq)

  1123   apply (erule mono_inf)

  1124   done

  1125

  1126 lemma mono_Un: "mono f \<Longrightarrow> f A \<union> f B \<subseteq> f (A \<union> B)"

  1127   apply (fold inf_set_eq sup_set_eq)

  1128   apply (erule mono_sup)

  1129   done

  1130

  1131 lemma top_set_eq: "top = UNIV"

  1132   by (iprover intro!: subset_antisym subset_UNIV top_greatest)

  1133

  1134 lemma bot_set_eq: "bot = {}"

  1135   by (iprover intro!: subset_antisym empty_subsetI bot_least)

  1136

  1137 lemma Inter_eq:

  1138   "\<Inter>A = {x. \<forall>B \<in> A. x \<in> B}"

  1139   by (simp add: Inter_def INTER_def)

  1140

  1141 lemma Union_eq:

  1142   "\<Union>A = {x. \<exists>B \<in> A. x \<in> B}"

  1143   by (simp add: Union_def UNION_def)

  1144

  1145 lemma Inf_set_eq:

  1146   "\<Sqinter>S = \<Inter>S"

  1147 proof (rule set_ext)

  1148   fix x

  1149   have "(\<forall>Q\<in>{P. \<exists>A\<in>S. P \<longleftrightarrow> x \<in> A}. Q) \<longleftrightarrow> (\<forall>A\<in>S. x \<in> A)"

  1150     by auto

  1151   then show "x \<in> \<Sqinter>S \<longleftrightarrow> x \<in> \<Inter>S"

  1152     by (simp add: Inter_eq Inf_fun_def Inf_bool_def) (simp add: mem_def)

  1153 qed

  1154

  1155 lemma Sup_set_eq:

  1156   "\<Squnion>S = \<Union>S"

  1157 proof (rule set_ext)

  1158   fix x

  1159   have "(\<exists>Q\<in>{P. \<exists>A\<in>S. P \<longleftrightarrow> x \<in> A}. Q) \<longleftrightarrow> (\<exists>A\<in>S. x \<in> A)"

  1160     by auto

  1161   then show "x \<in> \<Squnion>S \<longleftrightarrow> x \<in> \<Union>S"

  1162     by (simp add: Union_eq Sup_fun_def Sup_bool_def) (simp add: mem_def)

  1163 qed

  1164

  1165 lemma INFI_set_eq:

  1166   "(INF x:S. f x) = (\<Inter>x\<in>S. f x)"

  1167   by (simp add: INFI_def Inf_set_eq)

  1168

  1169 lemma SUPR_set_eq:

  1170   "(SUP x:S. f x) = (\<Union>x\<in>S. f x)"

  1171   by (simp add: SUPR_def Sup_set_eq)

  1172

  1173 no_notation

  1174   less_eq  (infix "\<sqsubseteq>" 50) and

  1175   less (infix "\<sqsubset>" 50) and

  1176   inf  (infixl "\<sqinter>" 70) and

  1177   sup  (infixl "\<squnion>" 65) and

  1178   Inf  ("\<Sqinter>_" [900] 900) and

  1179   Sup  ("\<Squnion>_" [900] 900)

  1180

  1181

  1182 subsubsection {* Unions of families *}

  1183

  1184 declare UNION_def [noatp]

  1185

  1186 lemma UN_iff [simp]: "(b: (UN x:A. B x)) = (EX x:A. b: B x)"

  1187   by (unfold UNION_def) blast

  1188

  1189 lemma UN_I [intro]: "a:A ==> b: B a ==> b: (UN x:A. B x)"

  1190   -- {* The order of the premises presupposes that @{term A} is rigid;

  1191     @{term b} may be flexible. *}

  1192   by auto

  1193

  1194 lemma UN_E [elim!]: "b : (UN x:A. B x) ==> (!!x. x:A ==> b: B x ==> R) ==> R"

  1195   by (unfold UNION_def) blast

  1196

  1197 lemma UN_cong [cong]:

  1198     "A = B ==> (!!x. x:B ==> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"

  1199   by (simp add: UNION_def)

  1200

  1201 lemma strong_UN_cong:

  1202     "A = B ==> (!!x. x:B =simp=> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"

  1203   by (simp add: UNION_def simp_implies_def)

  1204

  1205 lemma image_eq_UN: "fA = (UN x:A. {f x})"

  1206   by blast

  1207

  1208

  1209 subsubsection {* Intersections of families *}

  1210

  1211 lemma INT_iff [simp]: "(b: (INT x:A. B x)) = (ALL x:A. b: B x)"

  1212   by (unfold INTER_def) blast

  1213

  1214 lemma INT_I [intro!]: "(!!x. x:A ==> b: B x) ==> b : (INT x:A. B x)"

  1215   by (unfold INTER_def) blast

  1216

  1217 lemma INT_D [elim]: "b : (INT x:A. B x) ==> a:A ==> b: B a"

  1218   by auto

  1219

  1220 lemma INT_E [elim]: "b : (INT x:A. B x) ==> (b: B a ==> R) ==> (a~:A ==> R) ==> R"

  1221   -- {* "Classical" elimination -- by the Excluded Middle on @{prop "a:A"}. *}

  1222   by (unfold INTER_def) blast

  1223

  1224 lemma INT_cong [cong]:

  1225     "A = B ==> (!!x. x:B ==> C x = D x) ==> (INT x:A. C x) = (INT x:B. D x)"

  1226   by (simp add: INTER_def)

  1227

  1228

  1229 subsubsection {* Union *}

  1230

  1231 lemma Union_iff [simp,noatp]: "(A : Union C) = (EX X:C. A:X)"

  1232   by (unfold Union_def) blast

  1233

  1234 lemma UnionI [intro]: "X:C ==> A:X ==> A : Union C"

  1235   -- {* The order of the premises presupposes that @{term C} is rigid;

  1236     @{term A} may be flexible. *}

  1237   by auto

  1238

  1239 lemma UnionE [elim!]: "A : Union C ==> (!!X. A:X ==> X:C ==> R) ==> R"

  1240   by (unfold Union_def) blast

  1241

  1242

  1243 subsubsection {* Inter *}

  1244

  1245 lemma Inter_iff [simp,noatp]: "(A : Inter C) = (ALL X:C. A:X)"

  1246   by (unfold Inter_def) blast

  1247

  1248 lemma InterI [intro!]: "(!!X. X:C ==> A:X) ==> A : Inter C"

  1249   by (simp add: Inter_def)

  1250

  1251 text {*

  1252   \medskip A destruct'' rule -- every @{term X} in @{term C}

  1253   contains @{term A} as an element, but @{prop "A:X"} can hold when

  1254   @{prop "X:C"} does not!  This rule is analogous to @{text spec}.

  1255 *}

  1256

  1257 lemma InterD [elim]: "A : Inter C ==> X:C ==> A:X"

  1258   by auto

  1259

  1260 lemma InterE [elim]: "A : Inter C ==> (X~:C ==> R) ==> (A:X ==> R) ==> R"

  1261   -- {* Classical'' elimination rule -- does not require proving

  1262     @{prop "X:C"}. *}

  1263   by (unfold Inter_def) blast

  1264

  1265

  1266 subsubsection {* Set reasoning tools *}

  1267

  1268 text{* Elimination of @{text"{x. \<dots> & x=t & \<dots>}"}. *}

  1269

  1270 lemma Collect_conv_if: "{x. x=a & P x} = (if P a then {a} else {})"

  1271 by auto

  1272

  1273 lemma Collect_conv_if2: "{x. a=x & P x} = (if P a then {a} else {})"

  1274 by auto

  1275

  1276 text {*

  1277 Simproc for pulling @{text "x=t"} in @{text "{x. \<dots> & x=t & \<dots>}"}

  1278 to the front (and similarly for @{text "t=x"}):

  1279 *}

  1280

  1281 ML{*

  1282   local

  1283     val Coll_perm_tac = rtac @{thm Collect_cong} 1 THEN rtac @{thm iffI} 1 THEN

  1284     ALLGOALS(EVERY'[REPEAT_DETERM o (etac @{thm conjE}),

  1285                     DEPTH_SOLVE_1 o (ares_tac [@{thm conjI}])])

  1286   in

  1287     val defColl_regroup = Simplifier.simproc @{theory}

  1288       "defined Collect" ["{x. P x & Q x}"]

  1289       (Quantifier1.rearrange_Coll Coll_perm_tac)

  1290   end;

  1291

  1292   Addsimprocs [defColl_regroup];

  1293 *}

  1294

  1295 text {*

  1296   Rewrite rules for boolean case-splitting: faster than @{text

  1297   "split_if [split]"}.

  1298 *}

  1299

  1300 lemma split_if_eq1: "((if Q then x else y) = b) = ((Q --> x = b) & (~ Q --> y = b))"

  1301   by (rule split_if)

  1302

  1303 lemma split_if_eq2: "(a = (if Q then x else y)) = ((Q --> a = x) & (~ Q --> a = y))"

  1304   by (rule split_if)

  1305

  1306 text {*

  1307   Split ifs on either side of the membership relation.  Not for @{text

  1308   "[simp]"} -- can cause goals to blow up!

  1309 *}

  1310

  1311 lemma split_if_mem1: "((if Q then x else y) : b) = ((Q --> x : b) & (~ Q --> y : b))"

  1312   by (rule split_if)

  1313

  1314 lemma split_if_mem2: "(a : (if Q then x else y)) = ((Q --> a : x) & (~ Q --> a : y))"

  1315   by (rule split_if [where P="%S. a : S"])

  1316

  1317 lemmas split_ifs = if_bool_eq_conj split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2

  1318

  1319 (*Would like to add these, but the existing code only searches for the

  1320   outer-level constant, which in this case is just "op :"; we instead need

  1321   to use term-nets to associate patterns with rules.  Also, if a rule fails to

  1322   apply, then the formula should be kept.

  1323   [("HOL.uminus", Compl_iff RS iffD1), ("HOL.minus", [Diff_iff RS iffD1]),

  1324    ("Int", [IntD1,IntD2]),

  1325    ("Collect", [CollectD]), ("Inter", [InterD]), ("INTER", [INT_D])]

  1326  *)

  1327

  1328 ML {*

  1329   val mksimps_pairs = [(@{const_name Ball}, @{thms bspec})] @ mksimps_pairs;

  1330 *}

  1331 declaration {* fn _ =>

  1332   Simplifier.map_ss (fn ss => ss setmksimps (mksimps mksimps_pairs))

  1333 *}

  1334

  1335

  1336 subsubsection {* The proper subset'' relation *}

  1337

  1338 lemma psubsetI [intro!,noatp]: "A \<subseteq> B ==> A \<noteq> B ==> A \<subset> B"

  1339   by (unfold less_le) blast

  1340

  1341 lemma psubsetE [elim!,noatp]:

  1342     "[|A \<subset> B;  [|A \<subseteq> B; ~ (B\<subseteq>A)|] ==> R|] ==> R"

  1343   by (unfold less_le) blast

  1344

  1345 lemma psubset_insert_iff:

  1346   "(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)"

  1347   by (auto simp add: less_le subset_insert_iff)

  1348

  1349 lemma psubset_eq: "(A \<subset> B) = (A \<subseteq> B & A \<noteq> B)"

  1350   by (simp only: less_le)

  1351

  1352 lemma psubset_imp_subset: "A \<subset> B ==> A \<subseteq> B"

  1353   by (simp add: psubset_eq)

  1354

  1355 lemma psubset_trans: "[| A \<subset> B; B \<subset> C |] ==> A \<subset> C"

  1356 apply (unfold less_le)

  1357 apply (auto dest: subset_antisym)

  1358 done

  1359

  1360 lemma psubsetD: "[| A \<subset> B; c \<in> A |] ==> c \<in> B"

  1361 apply (unfold less_le)

  1362 apply (auto dest: subsetD)

  1363 done

  1364

  1365 lemma psubset_subset_trans: "A \<subset> B ==> B \<subseteq> C ==> A \<subset> C"

  1366   by (auto simp add: psubset_eq)

  1367

  1368 lemma subset_psubset_trans: "A \<subseteq> B ==> B \<subset> C ==> A \<subset> C"

  1369   by (auto simp add: psubset_eq)

  1370

  1371 lemma psubset_imp_ex_mem: "A \<subset> B ==> \<exists>b. b \<in> (B - A)"

  1372   by (unfold less_le) blast

  1373

  1374 lemma atomize_ball:

  1375     "(!!x. x \<in> A ==> P x) == Trueprop (\<forall>x\<in>A. P x)"

  1376   by (simp only: Ball_def atomize_all atomize_imp)

  1377

  1378 lemmas [symmetric, rulify] = atomize_ball

  1379   and [symmetric, defn] = atomize_ball

  1380

  1381

  1382 subsection {* Further set-theory lemmas *}

  1383

  1384 subsubsection {* Derived rules involving subsets. *}

  1385

  1386 text {* @{text insert}. *}

  1387

  1388 lemma subset_insertI: "B \<subseteq> insert a B"

  1389   by (rule subsetI) (erule insertI2)

  1390

  1391 lemma subset_insertI2: "A \<subseteq> B \<Longrightarrow> A \<subseteq> insert b B"

  1392   by blast

  1393

  1394 lemma subset_insert: "x \<notin> A ==> (A \<subseteq> insert x B) = (A \<subseteq> B)"

  1395   by blast

  1396

  1397

  1398 text {* \medskip Big Union -- least upper bound of a set. *}

  1399

  1400 lemma Union_upper: "B \<in> A ==> B \<subseteq> Union A"

  1401   by (iprover intro: subsetI UnionI)

  1402

  1403 lemma Union_least: "(!!X. X \<in> A ==> X \<subseteq> C) ==> Union A \<subseteq> C"

  1404   by (iprover intro: subsetI elim: UnionE dest: subsetD)

  1405

  1406

  1407 text {* \medskip General union. *}

  1408

  1409 lemma UN_upper: "a \<in> A ==> B a \<subseteq> (\<Union>x\<in>A. B x)"

  1410   by blast

  1411

  1412 lemma UN_least: "(!!x. x \<in> A ==> B x \<subseteq> C) ==> (\<Union>x\<in>A. B x) \<subseteq> C"

  1413   by (iprover intro: subsetI elim: UN_E dest: subsetD)

  1414

  1415

  1416 text {* \medskip Big Intersection -- greatest lower bound of a set. *}

  1417

  1418 lemma Inter_lower: "B \<in> A ==> Inter A \<subseteq> B"

  1419   by blast

  1420

  1421 lemma Inter_subset:

  1422   "[| !!X. X \<in> A ==> X \<subseteq> B; A ~= {} |] ==> \<Inter>A \<subseteq> B"

  1423   by blast

  1424

  1425 lemma Inter_greatest: "(!!X. X \<in> A ==> C \<subseteq> X) ==> C \<subseteq> Inter A"

  1426   by (iprover intro: InterI subsetI dest: subsetD)

  1427

  1428 lemma INT_lower: "a \<in> A ==> (\<Inter>x\<in>A. B x) \<subseteq> B a"

  1429   by blast

  1430

  1431 lemma INT_greatest: "(!!x. x \<in> A ==> C \<subseteq> B x) ==> C \<subseteq> (\<Inter>x\<in>A. B x)"

  1432   by (iprover intro: INT_I subsetI dest: subsetD)

  1433

  1434

  1435 text {* \medskip Finite Union -- the least upper bound of two sets. *}

  1436

  1437 lemma Un_upper1: "A \<subseteq> A \<union> B"

  1438   by blast

  1439

  1440 lemma Un_upper2: "B \<subseteq> A \<union> B"

  1441   by blast

  1442

  1443 lemma Un_least: "A \<subseteq> C ==> B \<subseteq> C ==> A \<union> B \<subseteq> C"

  1444   by blast

  1445

  1446

  1447 text {* \medskip Finite Intersection -- the greatest lower bound of two sets. *}

  1448

  1449 lemma Int_lower1: "A \<inter> B \<subseteq> A"

  1450   by blast

  1451

  1452 lemma Int_lower2: "A \<inter> B \<subseteq> B"

  1453   by blast

  1454

  1455 lemma Int_greatest: "C \<subseteq> A ==> C \<subseteq> B ==> C \<subseteq> A \<inter> B"

  1456   by blast

  1457

  1458

  1459 text {* \medskip Set difference. *}

  1460

  1461 lemma Diff_subset: "A - B \<subseteq> A"

  1462   by blast

  1463

  1464 lemma Diff_subset_conv: "(A - B \<subseteq> C) = (A \<subseteq> B \<union> C)"

  1465 by blast

  1466

  1467

  1468 subsubsection {* Equalities involving union, intersection, inclusion, etc. *}

  1469

  1470 text {* @{text "{}"}. *}

  1471

  1472 lemma Collect_const [simp]: "{s. P} = (if P then UNIV else {})"

  1473   -- {* supersedes @{text "Collect_False_empty"} *}

  1474   by auto

  1475

  1476 lemma subset_empty [simp]: "(A \<subseteq> {}) = (A = {})"

  1477   by blast

  1478

  1479 lemma not_psubset_empty [iff]: "\<not> (A < {})"

  1480   by (unfold less_le) blast

  1481

  1482 lemma Collect_empty_eq [simp]: "(Collect P = {}) = (\<forall>x. \<not> P x)"

  1483 by blast

  1484

  1485 lemma empty_Collect_eq [simp]: "({} = Collect P) = (\<forall>x. \<not> P x)"

  1486 by blast

  1487

  1488 lemma Collect_neg_eq: "{x. \<not> P x} = - {x. P x}"

  1489   by blast

  1490

  1491 lemma Collect_disj_eq: "{x. P x | Q x} = {x. P x} \<union> {x. Q x}"

  1492   by blast

  1493

  1494 lemma Collect_imp_eq: "{x. P x --> Q x} = -{x. P x} \<union> {x. Q x}"

  1495   by blast

  1496

  1497 lemma Collect_conj_eq: "{x. P x & Q x} = {x. P x} \<inter> {x. Q x}"

  1498   by blast

  1499

  1500 lemma Collect_all_eq: "{x. \<forall>y. P x y} = (\<Inter>y. {x. P x y})"

  1501   by blast

  1502

  1503 lemma Collect_ball_eq: "{x. \<forall>y\<in>A. P x y} = (\<Inter>y\<in>A. {x. P x y})"

  1504   by blast

  1505

  1506 lemma Collect_ex_eq [noatp]: "{x. \<exists>y. P x y} = (\<Union>y. {x. P x y})"

  1507   by blast

  1508

  1509 lemma Collect_bex_eq [noatp]: "{x. \<exists>y\<in>A. P x y} = (\<Union>y\<in>A. {x. P x y})"

  1510   by blast

  1511

  1512

  1513 text {* \medskip @{text insert}. *}

  1514

  1515 lemma insert_is_Un: "insert a A = {a} Un A"

  1516   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a {}"} *}

  1517   by blast

  1518

  1519 lemma insert_not_empty [simp]: "insert a A \<noteq> {}"

  1520   by blast

  1521

  1522 lemmas empty_not_insert = insert_not_empty [symmetric, standard]

  1523 declare empty_not_insert [simp]

  1524

  1525 lemma insert_absorb: "a \<in> A ==> insert a A = A"

  1526   -- {* @{text "[simp]"} causes recursive calls when there are nested inserts *}

  1527   -- {* with \emph{quadratic} running time *}

  1528   by blast

  1529

  1530 lemma insert_absorb2 [simp]: "insert x (insert x A) = insert x A"

  1531   by blast

  1532

  1533 lemma insert_commute: "insert x (insert y A) = insert y (insert x A)"

  1534   by blast

  1535

  1536 lemma insert_subset [simp]: "(insert x A \<subseteq> B) = (x \<in> B & A \<subseteq> B)"

  1537   by blast

  1538

  1539 lemma mk_disjoint_insert: "a \<in> A ==> \<exists>B. A = insert a B & a \<notin> B"

  1540   -- {* use new @{text B} rather than @{text "A - {a}"} to avoid infinite unfolding *}

  1541   apply (rule_tac x = "A - {a}" in exI, blast)

  1542   done

  1543

  1544 lemma insert_Collect: "insert a (Collect P) = {u. u \<noteq> a --> P u}"

  1545   by auto

  1546

  1547 lemma UN_insert_distrib: "u \<in> A ==> (\<Union>x\<in>A. insert a (B x)) = insert a (\<Union>x\<in>A. B x)"

  1548   by blast

  1549

  1550 lemma insert_inter_insert[simp]: "insert a A \<inter> insert a B = insert a (A \<inter> B)"

  1551   by blast

  1552

  1553 lemma insert_disjoint [simp,noatp]:

  1554  "(insert a A \<inter> B = {}) = (a \<notin> B \<and> A \<inter> B = {})"

  1555  "({} = insert a A \<inter> B) = (a \<notin> B \<and> {} = A \<inter> B)"

  1556   by auto

  1557

  1558 lemma disjoint_insert [simp,noatp]:

  1559  "(B \<inter> insert a A = {}) = (a \<notin> B \<and> B \<inter> A = {})"

  1560  "({} = A \<inter> insert b B) = (b \<notin> A \<and> {} = A \<inter> B)"

  1561   by auto

  1562

  1563 text {* \medskip @{text image}. *}

  1564

  1565 lemma image_empty [simp]: "f{} = {}"

  1566   by blast

  1567

  1568 lemma image_insert [simp]: "f  insert a B = insert (f a) (fB)"

  1569   by blast

  1570

  1571 lemma image_constant: "x \<in> A ==> (\<lambda>x. c)  A = {c}"

  1572   by auto

  1573

  1574 lemma image_constant_conv: "(%x. c)  A = (if A = {} then {} else {c})"

  1575 by auto

  1576

  1577 lemma image_image: "f  (g  A) = (\<lambda>x. f (g x))  A"

  1578 by blast

  1579

  1580 lemma insert_image [simp]: "x \<in> A ==> insert (f x) (fA) = fA"

  1581 by blast

  1582

  1583 lemma image_is_empty [iff]: "(fA = {}) = (A = {})"

  1584 by blast

  1585

  1586 lemma empty_is_image[iff]: "({} = f  A) = (A = {})"

  1587 by blast

  1588

  1589

  1590 lemma image_Collect [noatp]: "f  {x. P x} = {f x | x. P x}"

  1591   -- {* NOT suitable as a default simprule: the RHS isn't simpler than the LHS,

  1592       with its implicit quantifier and conjunction.  Also image enjoys better

  1593       equational properties than does the RHS. *}

  1594   by blast

  1595

  1596 lemma if_image_distrib [simp]:

  1597   "(\<lambda>x. if P x then f x else g x)  S

  1598     = (f  (S \<inter> {x. P x})) \<union> (g  (S \<inter> {x. \<not> P x}))"

  1599   by (auto simp add: image_def)

  1600

  1601 lemma image_cong: "M = N ==> (!!x. x \<in> N ==> f x = g x) ==> fM = gN"

  1602   by (simp add: image_def)

  1603

  1604

  1605 text {* \medskip @{text range}. *}

  1606

  1607 lemma full_SetCompr_eq [noatp]: "{u. \<exists>x. u = f x} = range f"

  1608   by auto

  1609

  1610 lemma range_composition: "range (\<lambda>x. f (g x)) = frange g"

  1611 by (subst image_image, simp)

  1612

  1613

  1614 text {* \medskip @{text Int} *}

  1615

  1616 lemma Int_absorb [simp]: "A \<inter> A = A"

  1617   by blast

  1618

  1619 lemma Int_left_absorb: "A \<inter> (A \<inter> B) = A \<inter> B"

  1620   by blast

  1621

  1622 lemma Int_commute: "A \<inter> B = B \<inter> A"

  1623   by blast

  1624

  1625 lemma Int_left_commute: "A \<inter> (B \<inter> C) = B \<inter> (A \<inter> C)"

  1626   by blast

  1627

  1628 lemma Int_assoc: "(A \<inter> B) \<inter> C = A \<inter> (B \<inter> C)"

  1629   by blast

  1630

  1631 lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute

  1632   -- {* Intersection is an AC-operator *}

  1633

  1634 lemma Int_absorb1: "B \<subseteq> A ==> A \<inter> B = B"

  1635   by blast

  1636

  1637 lemma Int_absorb2: "A \<subseteq> B ==> A \<inter> B = A"

  1638   by blast

  1639

  1640 lemma Int_empty_left [simp]: "{} \<inter> B = {}"

  1641   by blast

  1642

  1643 lemma Int_empty_right [simp]: "A \<inter> {} = {}"

  1644   by blast

  1645

  1646 lemma disjoint_eq_subset_Compl: "(A \<inter> B = {}) = (A \<subseteq> -B)"

  1647   by blast

  1648

  1649 lemma disjoint_iff_not_equal: "(A \<inter> B = {}) = (\<forall>x\<in>A. \<forall>y\<in>B. x \<noteq> y)"

  1650   by blast

  1651

  1652 lemma Int_UNIV_left [simp]: "UNIV \<inter> B = B"

  1653   by blast

  1654

  1655 lemma Int_UNIV_right [simp]: "A \<inter> UNIV = A"

  1656   by blast

  1657

  1658 lemma Int_eq_Inter: "A \<inter> B = \<Inter>{A, B}"

  1659   by blast

  1660

  1661 lemma Int_Un_distrib: "A \<inter> (B \<union> C) = (A \<inter> B) \<union> (A \<inter> C)"

  1662   by blast

  1663

  1664 lemma Int_Un_distrib2: "(B \<union> C) \<inter> A = (B \<inter> A) \<union> (C \<inter> A)"

  1665   by blast

  1666

  1667 lemma Int_UNIV [simp,noatp]: "(A \<inter> B = UNIV) = (A = UNIV & B = UNIV)"

  1668   by blast

  1669

  1670 lemma Int_subset_iff [simp]: "(C \<subseteq> A \<inter> B) = (C \<subseteq> A & C \<subseteq> B)"

  1671   by blast

  1672

  1673 lemma Int_Collect: "(x \<in> A \<inter> {x. P x}) = (x \<in> A & P x)"

  1674   by blast

  1675

  1676

  1677 text {* \medskip @{text Un}. *}

  1678

  1679 lemma Un_absorb [simp]: "A \<union> A = A"

  1680   by blast

  1681

  1682 lemma Un_left_absorb: "A \<union> (A \<union> B) = A \<union> B"

  1683   by blast

  1684

  1685 lemma Un_commute: "A \<union> B = B \<union> A"

  1686   by blast

  1687

  1688 lemma Un_left_commute: "A \<union> (B \<union> C) = B \<union> (A \<union> C)"

  1689   by blast

  1690

  1691 lemma Un_assoc: "(A \<union> B) \<union> C = A \<union> (B \<union> C)"

  1692   by blast

  1693

  1694 lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute

  1695   -- {* Union is an AC-operator *}

  1696

  1697 lemma Un_absorb1: "A \<subseteq> B ==> A \<union> B = B"

  1698   by blast

  1699

  1700 lemma Un_absorb2: "B \<subseteq> A ==> A \<union> B = A"

  1701   by blast

  1702

  1703 lemma Un_empty_left [simp]: "{} \<union> B = B"

  1704   by blast

  1705

  1706 lemma Un_empty_right [simp]: "A \<union> {} = A"

  1707   by blast

  1708

  1709 lemma Un_UNIV_left [simp]: "UNIV \<union> B = UNIV"

  1710   by blast

  1711

  1712 lemma Un_UNIV_right [simp]: "A \<union> UNIV = UNIV"

  1713   by blast

  1714

  1715 lemma Un_eq_Union: "A \<union> B = \<Union>{A, B}"

  1716   by blast

  1717

  1718 lemma Un_insert_left [simp]: "(insert a B) \<union> C = insert a (B \<union> C)"

  1719   by blast

  1720

  1721 lemma Un_insert_right [simp]: "A \<union> (insert a B) = insert a (A \<union> B)"

  1722   by blast

  1723

  1724 lemma Int_insert_left:

  1725     "(insert a B) Int C = (if a \<in> C then insert a (B \<inter> C) else B \<inter> C)"

  1726   by auto

  1727

  1728 lemma Int_insert_right:

  1729     "A \<inter> (insert a B) = (if a \<in> A then insert a (A \<inter> B) else A \<inter> B)"

  1730   by auto

  1731

  1732 lemma Un_Int_distrib: "A \<union> (B \<inter> C) = (A \<union> B) \<inter> (A \<union> C)"

  1733   by blast

  1734

  1735 lemma Un_Int_distrib2: "(B \<inter> C) \<union> A = (B \<union> A) \<inter> (C \<union> A)"

  1736   by blast

  1737

  1738 lemma Un_Int_crazy:

  1739     "(A \<inter> B) \<union> (B \<inter> C) \<union> (C \<inter> A) = (A \<union> B) \<inter> (B \<union> C) \<inter> (C \<union> A)"

  1740   by blast

  1741

  1742 lemma subset_Un_eq: "(A \<subseteq> B) = (A \<union> B = B)"

  1743   by blast

  1744

  1745 lemma Un_empty [iff]: "(A \<union> B = {}) = (A = {} & B = {})"

  1746   by blast

  1747

  1748 lemma Un_subset_iff [simp]: "(A \<union> B \<subseteq> C) = (A \<subseteq> C & B \<subseteq> C)"

  1749   by blast

  1750

  1751 lemma Un_Diff_Int: "(A - B) \<union> (A \<inter> B) = A"

  1752   by blast

  1753

  1754 lemma Diff_Int2: "A \<inter> C - B \<inter> C = A \<inter> C - B"

  1755   by blast

  1756

  1757

  1758 text {* \medskip Set complement *}

  1759

  1760 lemma Compl_disjoint [simp]: "A \<inter> -A = {}"

  1761   by blast

  1762

  1763 lemma Compl_disjoint2 [simp]: "-A \<inter> A = {}"

  1764   by blast

  1765

  1766 lemma Compl_partition: "A \<union> -A = UNIV"

  1767   by blast

  1768

  1769 lemma Compl_partition2: "-A \<union> A = UNIV"

  1770   by blast

  1771

  1772 lemma double_complement [simp]: "- (-A) = (A::'a set)"

  1773   by blast

  1774

  1775 lemma Compl_Un [simp]: "-(A \<union> B) = (-A) \<inter> (-B)"

  1776   by blast

  1777

  1778 lemma Compl_Int [simp]: "-(A \<inter> B) = (-A) \<union> (-B)"

  1779   by blast

  1780

  1781 lemma Compl_UN [simp]: "-(\<Union>x\<in>A. B x) = (\<Inter>x\<in>A. -B x)"

  1782   by blast

  1783

  1784 lemma Compl_INT [simp]: "-(\<Inter>x\<in>A. B x) = (\<Union>x\<in>A. -B x)"

  1785   by blast

  1786

  1787 lemma subset_Compl_self_eq: "(A \<subseteq> -A) = (A = {})"

  1788   by blast

  1789

  1790 lemma Un_Int_assoc_eq: "((A \<inter> B) \<union> C = A \<inter> (B \<union> C)) = (C \<subseteq> A)"

  1791   -- {* Halmos, Naive Set Theory, page 16. *}

  1792   by blast

  1793

  1794 lemma Compl_UNIV_eq [simp]: "-UNIV = {}"

  1795   by blast

  1796

  1797 lemma Compl_empty_eq [simp]: "-{} = UNIV"

  1798   by blast

  1799

  1800 lemma Compl_subset_Compl_iff [iff]: "(-A \<subseteq> -B) = (B \<subseteq> A)"

  1801   by blast

  1802

  1803 lemma Compl_eq_Compl_iff [iff]: "(-A = -B) = (A = (B::'a set))"

  1804   by blast

  1805

  1806

  1807 text {* \medskip @{text Union}. *}

  1808

  1809 lemma Union_empty [simp]: "Union({}) = {}"

  1810   by blast

  1811

  1812 lemma Union_UNIV [simp]: "Union UNIV = UNIV"

  1813   by blast

  1814

  1815 lemma Union_insert [simp]: "Union (insert a B) = a \<union> \<Union>B"

  1816   by blast

  1817

  1818 lemma Union_Un_distrib [simp]: "\<Union>(A Un B) = \<Union>A \<union> \<Union>B"

  1819   by blast

  1820

  1821 lemma Union_Int_subset: "\<Union>(A \<inter> B) \<subseteq> \<Union>A \<inter> \<Union>B"

  1822   by blast

  1823

  1824 lemma Union_empty_conv [simp,noatp]: "(\<Union>A = {}) = (\<forall>x\<in>A. x = {})"

  1825   by blast

  1826

  1827 lemma empty_Union_conv [simp,noatp]: "({} = \<Union>A) = (\<forall>x\<in>A. x = {})"

  1828   by blast

  1829

  1830 lemma Union_disjoint: "(\<Union>C \<inter> A = {}) = (\<forall>B\<in>C. B \<inter> A = {})"

  1831   by blast

  1832

  1833

  1834 text {* \medskip @{text Inter}. *}

  1835

  1836 lemma Inter_empty [simp]: "\<Inter>{} = UNIV"

  1837   by blast

  1838

  1839 lemma Inter_UNIV [simp]: "\<Inter>UNIV = {}"

  1840   by blast

  1841

  1842 lemma Inter_insert [simp]: "\<Inter>(insert a B) = a \<inter> \<Inter>B"

  1843   by blast

  1844

  1845 lemma Inter_Un_subset: "\<Inter>A \<union> \<Inter>B \<subseteq> \<Inter>(A \<inter> B)"

  1846   by blast

  1847

  1848 lemma Inter_Un_distrib: "\<Inter>(A \<union> B) = \<Inter>A \<inter> \<Inter>B"

  1849   by blast

  1850

  1851 lemma Inter_UNIV_conv [simp,noatp]:

  1852   "(\<Inter>A = UNIV) = (\<forall>x\<in>A. x = UNIV)"

  1853   "(UNIV = \<Inter>A) = (\<forall>x\<in>A. x = UNIV)"

  1854   by blast+

  1855

  1856

  1857 text {*

  1858   \medskip @{text UN} and @{text INT}.

  1859

  1860   Basic identities: *}

  1861

  1862 lemma UN_empty [simp,noatp]: "(\<Union>x\<in>{}. B x) = {}"

  1863   by blast

  1864

  1865 lemma UN_empty2 [simp]: "(\<Union>x\<in>A. {}) = {}"

  1866   by blast

  1867

  1868 lemma UN_singleton [simp]: "(\<Union>x\<in>A. {x}) = A"

  1869   by blast

  1870

  1871 lemma UN_absorb: "k \<in> I ==> A k \<union> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. A i)"

  1872   by auto

  1873

  1874 lemma INT_empty [simp]: "(\<Inter>x\<in>{}. B x) = UNIV"

  1875   by blast

  1876

  1877 lemma INT_absorb: "k \<in> I ==> A k \<inter> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. A i)"

  1878   by blast

  1879

  1880 lemma UN_insert [simp]: "(\<Union>x\<in>insert a A. B x) = B a \<union> UNION A B"

  1881   by blast

  1882

  1883 lemma UN_Un[simp]: "(\<Union>i \<in> A \<union> B. M i) = (\<Union>i\<in>A. M i) \<union> (\<Union>i\<in>B. M i)"

  1884   by blast

  1885

  1886 lemma UN_UN_flatten: "(\<Union>x \<in> (\<Union>y\<in>A. B y). C x) = (\<Union>y\<in>A. \<Union>x\<in>B y. C x)"

  1887   by blast

  1888

  1889 lemma UN_subset_iff: "((\<Union>i\<in>I. A i) \<subseteq> B) = (\<forall>i\<in>I. A i \<subseteq> B)"

  1890   by blast

  1891

  1892 lemma INT_subset_iff: "(B \<subseteq> (\<Inter>i\<in>I. A i)) = (\<forall>i\<in>I. B \<subseteq> A i)"

  1893   by blast

  1894

  1895 lemma INT_insert [simp]: "(\<Inter>x \<in> insert a A. B x) = B a \<inter> INTER A B"

  1896   by blast

  1897

  1898 lemma INT_Un: "(\<Inter>i \<in> A \<union> B. M i) = (\<Inter>i \<in> A. M i) \<inter> (\<Inter>i\<in>B. M i)"

  1899   by blast

  1900

  1901 lemma INT_insert_distrib:

  1902     "u \<in> A ==> (\<Inter>x\<in>A. insert a (B x)) = insert a (\<Inter>x\<in>A. B x)"

  1903   by blast

  1904

  1905 lemma image_Union: "f  \<Union>S = (\<Union>x\<in>S. f  x)"

  1906   by blast

  1907

  1908 lemma UN_constant [simp]: "(\<Union>y\<in>A. c) = (if A = {} then {} else c)"

  1909   by auto

  1910

  1911 lemma INT_constant [simp]: "(\<Inter>y\<in>A. c) = (if A = {} then UNIV else c)"

  1912   by auto

  1913

  1914 lemma UN_eq: "(\<Union>x\<in>A. B x) = \<Union>({Y. \<exists>x\<in>A. Y = B x})"

  1915   by blast

  1916

  1917 lemma INT_eq: "(\<Inter>x\<in>A. B x) = \<Inter>({Y. \<exists>x\<in>A. Y = B x})"

  1918   -- {* Look: it has an \emph{existential} quantifier *}

  1919   by blast

  1920

  1921 lemma UNION_empty_conv[simp]:

  1922   "({} = (UN x:A. B x)) = (\<forall>x\<in>A. B x = {})"

  1923   "((UN x:A. B x) = {}) = (\<forall>x\<in>A. B x = {})"

  1924 by blast+

  1925

  1926 lemma INTER_UNIV_conv[simp]:

  1927  "(UNIV = (INT x:A. B x)) = (\<forall>x\<in>A. B x = UNIV)"

  1928  "((INT x:A. B x) = UNIV) = (\<forall>x\<in>A. B x = UNIV)"

  1929 by blast+

  1930

  1931

  1932 text {* \medskip Distributive laws: *}

  1933

  1934 lemma Int_Union: "A \<inter> \<Union>B = (\<Union>C\<in>B. A \<inter> C)"

  1935   by blast

  1936

  1937 lemma Int_Union2: "\<Union>B \<inter> A = (\<Union>C\<in>B. C \<inter> A)"

  1938   by blast

  1939

  1940 lemma Un_Union_image: "(\<Union>x\<in>C. A x \<union> B x) = \<Union>(AC) \<union> \<Union>(BC)"

  1941   -- {* Devlin, Fundamentals of Contemporary Set Theory, page 12, exercise 5: *}

  1942   -- {* Union of a family of unions *}

  1943   by blast

  1944

  1945 lemma UN_Un_distrib: "(\<Union>i\<in>I. A i \<union> B i) = (\<Union>i\<in>I. A i) \<union> (\<Union>i\<in>I. B i)"

  1946   -- {* Equivalent version *}

  1947   by blast

  1948

  1949 lemma Un_Inter: "A \<union> \<Inter>B = (\<Inter>C\<in>B. A \<union> C)"

  1950   by blast

  1951

  1952 lemma Int_Inter_image: "(\<Inter>x\<in>C. A x \<inter> B x) = \<Inter>(AC) \<inter> \<Inter>(BC)"

  1953   by blast

  1954

  1955 lemma INT_Int_distrib: "(\<Inter>i\<in>I. A i \<inter> B i) = (\<Inter>i\<in>I. A i) \<inter> (\<Inter>i\<in>I. B i)"

  1956   -- {* Equivalent version *}

  1957   by blast

  1958

  1959 lemma Int_UN_distrib: "B \<inter> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. B \<inter> A i)"

  1960   -- {* Halmos, Naive Set Theory, page 35. *}

  1961   by blast

  1962

  1963 lemma Un_INT_distrib: "B \<union> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. B \<union> A i)"

  1964   by blast

  1965

  1966 lemma Int_UN_distrib2: "(\<Union>i\<in>I. A i) \<inter> (\<Union>j\<in>J. B j) = (\<Union>i\<in>I. \<Union>j\<in>J. A i \<inter> B j)"

  1967   by blast

  1968

  1969 lemma Un_INT_distrib2: "(\<Inter>i\<in>I. A i) \<union> (\<Inter>j\<in>J. B j) = (\<Inter>i\<in>I. \<Inter>j\<in>J. A i \<union> B j)"

  1970   by blast

  1971

  1972

  1973 text {* \medskip Bounded quantifiers.

  1974

  1975   The following are not added to the default simpset because

  1976   (a) they duplicate the body and (b) there are no similar rules for @{text Int}. *}

  1977

  1978 lemma ball_Un: "(\<forall>x \<in> A \<union> B. P x) = ((\<forall>x\<in>A. P x) & (\<forall>x\<in>B. P x))"

  1979   by blast

  1980

  1981 lemma bex_Un: "(\<exists>x \<in> A \<union> B. P x) = ((\<exists>x\<in>A. P x) | (\<exists>x\<in>B. P x))"

  1982   by blast

  1983

  1984 lemma ball_UN: "(\<forall>z \<in> UNION A B. P z) = (\<forall>x\<in>A. \<forall>z \<in> B x. P z)"

  1985   by blast

  1986

  1987 lemma bex_UN: "(\<exists>z \<in> UNION A B. P z) = (\<exists>x\<in>A. \<exists>z\<in>B x. P z)"

  1988   by blast

  1989

  1990

  1991 text {* \medskip Set difference. *}

  1992

  1993 lemma Diff_eq: "A - B = A \<inter> (-B)"

  1994   by blast

  1995

  1996 lemma Diff_eq_empty_iff [simp,noatp]: "(A - B = {}) = (A \<subseteq> B)"

  1997   by blast

  1998

  1999 lemma Diff_cancel [simp]: "A - A = {}"

  2000   by blast

  2001

  2002 lemma Diff_idemp [simp]: "(A - B) - B = A - (B::'a set)"

  2003 by blast

  2004

  2005 lemma Diff_triv: "A \<inter> B = {} ==> A - B = A"

  2006   by (blast elim: equalityE)

  2007

  2008 lemma empty_Diff [simp]: "{} - A = {}"

  2009   by blast

  2010

  2011 lemma Diff_empty [simp]: "A - {} = A"

  2012   by blast

  2013

  2014 lemma Diff_UNIV [simp]: "A - UNIV = {}"

  2015   by blast

  2016

  2017 lemma Diff_insert0 [simp,noatp]: "x \<notin> A ==> A - insert x B = A - B"

  2018   by blast

  2019

  2020 lemma Diff_insert: "A - insert a B = A - B - {a}"

  2021   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}

  2022   by blast

  2023

  2024 lemma Diff_insert2: "A - insert a B = A - {a} - B"

  2025   -- {* NOT SUITABLE FOR REWRITING since @{text "{a} == insert a 0"} *}

  2026   by blast

  2027

  2028 lemma insert_Diff_if: "insert x A - B = (if x \<in> B then A - B else insert x (A - B))"

  2029   by auto

  2030

  2031 lemma insert_Diff1 [simp]: "x \<in> B ==> insert x A - B = A - B"

  2032   by blast

  2033

  2034 lemma insert_Diff_single[simp]: "insert a (A - {a}) = insert a A"

  2035 by blast

  2036

  2037 lemma insert_Diff: "a \<in> A ==> insert a (A - {a}) = A"

  2038   by blast

  2039

  2040 lemma Diff_insert_absorb: "x \<notin> A ==> (insert x A) - {x} = A"

  2041   by auto

  2042

  2043 lemma Diff_disjoint [simp]: "A \<inter> (B - A) = {}"

  2044   by blast

  2045

  2046 lemma Diff_partition: "A \<subseteq> B ==> A \<union> (B - A) = B"

  2047   by blast

  2048

  2049 lemma double_diff: "A \<subseteq> B ==> B \<subseteq> C ==> B - (C - A) = A"

  2050   by blast

  2051

  2052 lemma Un_Diff_cancel [simp]: "A \<union> (B - A) = A \<union> B"

  2053   by blast

  2054

  2055 lemma Un_Diff_cancel2 [simp]: "(B - A) \<union> A = B \<union> A"

  2056   by blast

  2057

  2058 lemma Diff_Un: "A - (B \<union> C) = (A - B) \<inter> (A - C)"

  2059   by blast

  2060

  2061 lemma Diff_Int: "A - (B \<inter> C) = (A - B) \<union> (A - C)"

  2062   by blast

  2063

  2064 lemma Un_Diff: "(A \<union> B) - C = (A - C) \<union> (B - C)"

  2065   by blast

  2066

  2067 lemma Int_Diff: "(A \<inter> B) - C = A \<inter> (B - C)"

  2068   by blast

  2069

  2070 lemma Diff_Int_distrib: "C \<inter> (A - B) = (C \<inter> A) - (C \<inter> B)"

  2071   by blast

  2072

  2073 lemma Diff_Int_distrib2: "(A - B) \<inter> C = (A \<inter> C) - (B \<inter> C)"

  2074   by blast

  2075

  2076 lemma Diff_Compl [simp]: "A - (- B) = A \<inter> B"

  2077   by auto

  2078

  2079 lemma Compl_Diff_eq [simp]: "- (A - B) = -A \<union> B"

  2080   by blast

  2081

  2082

  2083 text {* \medskip Quantification over type @{typ bool}. *}

  2084

  2085 lemma bool_induct: "P True \<Longrightarrow> P False \<Longrightarrow> P x"

  2086   by (cases x) auto

  2087

  2088 lemma all_bool_eq: "(\<forall>b. P b) \<longleftrightarrow> P True \<and> P False"

  2089   by (auto intro: bool_induct)

  2090

  2091 lemma bool_contrapos: "P x \<Longrightarrow> \<not> P False \<Longrightarrow> P True"

  2092   by (cases x) auto

  2093

  2094 lemma ex_bool_eq: "(\<exists>b. P b) \<longleftrightarrow> P True \<or> P False"

  2095   by (auto intro: bool_contrapos)

  2096

  2097 lemma Un_eq_UN: "A \<union> B = (\<Union>b. if b then A else B)"

  2098   by (auto simp add: split_if_mem2)

  2099

  2100 lemma UN_bool_eq: "(\<Union>b::bool. A b) = (A True \<union> A False)"

  2101   by (auto intro: bool_contrapos)

  2102

  2103 lemma INT_bool_eq: "(\<Inter>b::bool. A b) = (A True \<inter> A False)"

  2104   by (auto intro: bool_induct)

  2105

  2106 text {* \medskip @{text Pow} *}

  2107

  2108 lemma Pow_empty [simp]: "Pow {} = {{}}"

  2109   by (auto simp add: Pow_def)

  2110

  2111 lemma Pow_insert: "Pow (insert a A) = Pow A \<union> (insert a  Pow A)"

  2112   by (blast intro: image_eqI [where ?x = "u - {a}", standard])

  2113

  2114 lemma Pow_Compl: "Pow (- A) = {-B | B. A \<in> Pow B}"

  2115   by (blast intro: exI [where ?x = "- u", standard])

  2116

  2117 lemma Pow_UNIV [simp]: "Pow UNIV = UNIV"

  2118   by blast

  2119

  2120 lemma Un_Pow_subset: "Pow A \<union> Pow B \<subseteq> Pow (A \<union> B)"

  2121   by blast

  2122

  2123 lemma UN_Pow_subset: "(\<Union>x\<in>A. Pow (B x)) \<subseteq> Pow (\<Union>x\<in>A. B x)"

  2124   by blast

  2125

  2126 lemma subset_Pow_Union: "A \<subseteq> Pow (\<Union>A)"

  2127   by blast

  2128

  2129 lemma Union_Pow_eq [simp]: "\<Union>(Pow A) = A"

  2130   by blast

  2131

  2132 lemma Pow_Int_eq [simp]: "Pow (A \<inter> B) = Pow A \<inter> Pow B"

  2133   by blast

  2134

  2135 lemma Pow_INT_eq: "Pow (\<Inter>x\<in>A. B x) = (\<Inter>x\<in>A. Pow (B x))"

  2136   by blast

  2137

  2138

  2139 text {* \medskip Miscellany. *}

  2140

  2141 lemma set_eq_subset: "(A = B) = (A \<subseteq> B & B \<subseteq> A)"

  2142   by blast

  2143

  2144 lemma subset_iff: "(A \<subseteq> B) = (\<forall>t. t \<in> A --> t \<in> B)"

  2145   by blast

  2146

  2147 lemma subset_iff_psubset_eq: "(A \<subseteq> B) = ((A \<subset> B) | (A = B))"

  2148   by (unfold less_le) blast

  2149

  2150 lemma all_not_in_conv [simp]: "(\<forall>x. x \<notin> A) = (A = {})"

  2151   by blast

  2152

  2153 lemma ex_in_conv: "(\<exists>x. x \<in> A) = (A \<noteq> {})"

  2154   by blast

  2155

  2156 lemma distinct_lemma: "f x \<noteq> f y ==> x \<noteq> y"

  2157   by iprover

  2158

  2159

  2160 text {* \medskip Miniscoping: pushing in quantifiers and big Unions

  2161            and Intersections. *}

  2162

  2163 lemma UN_simps [simp]:

  2164   "!!a B C. (UN x:C. insert a (B x)) = (if C={} then {} else insert a (UN x:C. B x))"

  2165   "!!A B C. (UN x:C. A x Un B)   = ((if C={} then {} else (UN x:C. A x) Un B))"

  2166   "!!A B C. (UN x:C. A Un B x)   = ((if C={} then {} else A Un (UN x:C. B x)))"

  2167   "!!A B C. (UN x:C. A x Int B)  = ((UN x:C. A x) Int B)"

  2168   "!!A B C. (UN x:C. A Int B x)  = (A Int (UN x:C. B x))"

  2169   "!!A B C. (UN x:C. A x - B)    = ((UN x:C. A x) - B)"

  2170   "!!A B C. (UN x:C. A - B x)    = (A - (INT x:C. B x))"

  2171   "!!A B. (UN x: Union A. B x) = (UN y:A. UN x:y. B x)"

  2172   "!!A B C. (UN z: UNION A B. C z) = (UN  x:A. UN z: B(x). C z)"

  2173   "!!A B f. (UN x:fA. B x)     = (UN a:A. B (f a))"

  2174   by auto

  2175

  2176 lemma INT_simps [simp]:

  2177   "!!A B C. (INT x:C. A x Int B) = (if C={} then UNIV else (INT x:C. A x) Int B)"

  2178   "!!A B C. (INT x:C. A Int B x) = (if C={} then UNIV else A Int (INT x:C. B x))"

  2179   "!!A B C. (INT x:C. A x - B)   = (if C={} then UNIV else (INT x:C. A x) - B)"

  2180   "!!A B C. (INT x:C. A - B x)   = (if C={} then UNIV else A - (UN x:C. B x))"

  2181   "!!a B C. (INT x:C. insert a (B x)) = insert a (INT x:C. B x)"

  2182   "!!A B C. (INT x:C. A x Un B)  = ((INT x:C. A x) Un B)"

  2183   "!!A B C. (INT x:C. A Un B x)  = (A Un (INT x:C. B x))"

  2184   "!!A B. (INT x: Union A. B x) = (INT y:A. INT x:y. B x)"

  2185   "!!A B C. (INT z: UNION A B. C z) = (INT x:A. INT z: B(x). C z)"

  2186   "!!A B f. (INT x:fA. B x)    = (INT a:A. B (f a))"

  2187   by auto

  2188

  2189 lemma ball_simps [simp,noatp]:

  2190   "!!A P Q. (ALL x:A. P x | Q) = ((ALL x:A. P x) | Q)"

  2191   "!!A P Q. (ALL x:A. P | Q x) = (P | (ALL x:A. Q x))"

  2192   "!!A P Q. (ALL x:A. P --> Q x) = (P --> (ALL x:A. Q x))"

  2193   "!!A P Q. (ALL x:A. P x --> Q) = ((EX x:A. P x) --> Q)"

  2194   "!!P. (ALL x:{}. P x) = True"

  2195   "!!P. (ALL x:UNIV. P x) = (ALL x. P x)"

  2196   "!!a B P. (ALL x:insert a B. P x) = (P a & (ALL x:B. P x))"

  2197   "!!A P. (ALL x:Union A. P x) = (ALL y:A. ALL x:y. P x)"

  2198   "!!A B P. (ALL x: UNION A B. P x) = (ALL a:A. ALL x: B a. P x)"

  2199   "!!P Q. (ALL x:Collect Q. P x) = (ALL x. Q x --> P x)"

  2200   "!!A P f. (ALL x:fA. P x) = (ALL x:A. P (f x))"

  2201   "!!A P. (~(ALL x:A. P x)) = (EX x:A. ~P x)"

  2202   by auto

  2203

  2204 lemma bex_simps [simp,noatp]:

  2205   "!!A P Q. (EX x:A. P x & Q) = ((EX x:A. P x) & Q)"

  2206   "!!A P Q. (EX x:A. P & Q x) = (P & (EX x:A. Q x))"

  2207   "!!P. (EX x:{}. P x) = False"

  2208   "!!P. (EX x:UNIV. P x) = (EX x. P x)"

  2209   "!!a B P. (EX x:insert a B. P x) = (P(a) | (EX x:B. P x))"

  2210   "!!A P. (EX x:Union A. P x) = (EX y:A. EX x:y. P x)"

  2211   "!!A B P. (EX x: UNION A B. P x) = (EX a:A. EX x:B a. P x)"

  2212   "!!P Q. (EX x:Collect Q. P x) = (EX x. Q x & P x)"

  2213   "!!A P f. (EX x:fA. P x) = (EX x:A. P (f x))"

  2214   "!!A P. (~(EX x:A. P x)) = (ALL x:A. ~P x)"

  2215   by auto

  2216

  2217 lemma ball_conj_distrib:

  2218   "(ALL x:A. P x & Q x) = ((ALL x:A. P x) & (ALL x:A. Q x))"

  2219   by blast

  2220

  2221 lemma bex_disj_distrib:

  2222   "(EX x:A. P x | Q x) = ((EX x:A. P x) | (EX x:A. Q x))"

  2223   by blast

  2224

  2225

  2226 text {* \medskip Maxiscoping: pulling out big Unions and Intersections. *}

  2227

  2228 lemma UN_extend_simps:

  2229   "!!a B C. insert a (UN x:C. B x) = (if C={} then {a} else (UN x:C. insert a (B x)))"

  2230   "!!A B C. (UN x:C. A x) Un B    = (if C={} then B else (UN x:C. A x Un B))"

  2231   "!!A B C. A Un (UN x:C. B x)   = (if C={} then A else (UN x:C. A Un B x))"

  2232   "!!A B C. ((UN x:C. A x) Int B) = (UN x:C. A x Int B)"

  2233   "!!A B C. (A Int (UN x:C. B x)) = (UN x:C. A Int B x)"

  2234   "!!A B C. ((UN x:C. A x) - B) = (UN x:C. A x - B)"

  2235   "!!A B C. (A - (INT x:C. B x)) = (UN x:C. A - B x)"

  2236   "!!A B. (UN y:A. UN x:y. B x) = (UN x: Union A. B x)"

  2237   "!!A B C. (UN  x:A. UN z: B(x). C z) = (UN z: UNION A B. C z)"

  2238   "!!A B f. (UN a:A. B (f a)) = (UN x:fA. B x)"

  2239   by auto

  2240

  2241 lemma INT_extend_simps:

  2242   "!!A B C. (INT x:C. A x) Int B = (if C={} then B else (INT x:C. A x Int B))"

  2243   "!!A B C. A Int (INT x:C. B x) = (if C={} then A else (INT x:C. A Int B x))"

  2244   "!!A B C. (INT x:C. A x) - B   = (if C={} then UNIV-B else (INT x:C. A x - B))"

  2245   "!!A B C. A - (UN x:C. B x)   = (if C={} then A else (INT x:C. A - B x))"

  2246   "!!a B C. insert a (INT x:C. B x) = (INT x:C. insert a (B x))"

  2247   "!!A B C. ((INT x:C. A x) Un B)  = (INT x:C. A x Un B)"

  2248   "!!A B C. A Un (INT x:C. B x)  = (INT x:C. A Un B x)"

  2249   "!!A B. (INT y:A. INT x:y. B x) = (INT x: Union A. B x)"

  2250   "!!A B C. (INT x:A. INT z: B(x). C z) = (INT z: UNION A B. C z)"

  2251   "!!A B f. (INT a:A. B (f a))    = (INT x:fA. B x)"

  2252   by auto

  2253

  2254

  2255 subsubsection {* Monotonicity of various operations *}

  2256

  2257 lemma image_mono: "A \<subseteq> B ==> fA \<subseteq> fB"

  2258   by blast

  2259

  2260 lemma Pow_mono: "A \<subseteq> B ==> Pow A \<subseteq> Pow B"

  2261   by blast

  2262

  2263 lemma Union_mono: "A \<subseteq> B ==> \<Union>A \<subseteq> \<Union>B"

  2264   by blast

  2265

  2266 lemma Inter_anti_mono: "B \<subseteq> A ==> \<Inter>A \<subseteq> \<Inter>B"

  2267   by blast

  2268

  2269 lemma UN_mono:

  2270   "A \<subseteq> B ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>

  2271     (\<Union>x\<in>A. f x) \<subseteq> (\<Union>x\<in>B. g x)"

  2272   by (blast dest: subsetD)

  2273

  2274 lemma INT_anti_mono:

  2275   "B \<subseteq> A ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>

  2276     (\<Inter>x\<in>A. f x) \<subseteq> (\<Inter>x\<in>A. g x)"

  2277   -- {* The last inclusion is POSITIVE! *}

  2278   by (blast dest: subsetD)

  2279

  2280 lemma insert_mono: "C \<subseteq> D ==> insert a C \<subseteq> insert a D"

  2281   by blast

  2282

  2283 lemma Un_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<union> B \<subseteq> C \<union> D"

  2284   by blast

  2285

  2286 lemma Int_mono: "A \<subseteq> C ==> B \<subseteq> D ==> A \<inter> B \<subseteq> C \<inter> D"

  2287   by blast

  2288

  2289 lemma Diff_mono: "A \<subseteq> C ==> D \<subseteq> B ==> A - B \<subseteq> C - D"

  2290   by blast

  2291

  2292 lemma Compl_anti_mono: "A \<subseteq> B ==> -B \<subseteq> -A"

  2293   by blast

  2294

  2295 text {* \medskip Monotonicity of implications. *}

  2296

  2297 lemma in_mono: "A \<subseteq> B ==> x \<in> A --> x \<in> B"

  2298   apply (rule impI)

  2299   apply (erule subsetD, assumption)

  2300   done

  2301

  2302 lemma conj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 & P2) --> (Q1 & Q2)"

  2303   by iprover

  2304

  2305 lemma disj_mono: "P1 --> Q1 ==> P2 --> Q2 ==> (P1 | P2) --> (Q1 | Q2)"

  2306   by iprover

  2307

  2308 lemma imp_mono: "Q1 --> P1 ==> P2 --> Q2 ==> (P1 --> P2) --> (Q1 --> Q2)"

  2309   by iprover

  2310

  2311 lemma imp_refl: "P --> P" ..

  2312

  2313 lemma ex_mono: "(!!x. P x --> Q x) ==> (EX x. P x) --> (EX x. Q x)"

  2314   by iprover

  2315

  2316 lemma all_mono: "(!!x. P x --> Q x) ==> (ALL x. P x) --> (ALL x. Q x)"

  2317   by iprover

  2318

  2319 lemma Collect_mono: "(!!x. P x --> Q x) ==> Collect P \<subseteq> Collect Q"

  2320   by blast

  2321

  2322 lemma Int_Collect_mono:

  2323     "A \<subseteq> B ==> (!!x. x \<in> A ==> P x --> Q x) ==> A \<inter> Collect P \<subseteq> B \<inter> Collect Q"

  2324   by blast

  2325

  2326 lemmas basic_monos =

  2327   subset_refl imp_refl disj_mono conj_mono

  2328   ex_mono Collect_mono in_mono

  2329

  2330 lemma eq_to_mono: "a = b ==> c = d ==> b --> d ==> a --> c"

  2331   by iprover

  2332

  2333 lemma eq_to_mono2: "a = b ==> c = d ==> ~ b --> ~ d ==> ~ a --> ~ c"

  2334   by iprover

  2335

  2336

  2337 subsection {* Inverse image of a function *}

  2338

  2339 constdefs

  2340   vimage :: "('a => 'b) => 'b set => 'a set"    (infixr "-" 90)

  2341   [code del]: "f - B == {x. f x : B}"

  2342

  2343

  2344 subsubsection {* Basic rules *}

  2345

  2346 lemma vimage_eq [simp]: "(a : f - B) = (f a : B)"

  2347   by (unfold vimage_def) blast

  2348

  2349 lemma vimage_singleton_eq: "(a : f - {b}) = (f a = b)"

  2350   by simp

  2351

  2352 lemma vimageI [intro]: "f a = b ==> b:B ==> a : f - B"

  2353   by (unfold vimage_def) blast

  2354

  2355 lemma vimageI2: "f a : A ==> a : f - A"

  2356   by (unfold vimage_def) fast

  2357

  2358 lemma vimageE [elim!]: "a: f - B ==> (!!x. f a = x ==> x:B ==> P) ==> P"

  2359   by (unfold vimage_def) blast

  2360

  2361 lemma vimageD: "a : f - A ==> f a : A"

  2362   by (unfold vimage_def) fast

  2363

  2364

  2365 subsubsection {* Equations *}

  2366

  2367 lemma vimage_empty [simp]: "f - {} = {}"

  2368   by blast

  2369

  2370 lemma vimage_Compl: "f - (-A) = -(f - A)"

  2371   by blast

  2372

  2373 lemma vimage_Un [simp]: "f - (A Un B) = (f - A) Un (f - B)"

  2374   by blast

  2375

  2376 lemma vimage_Int [simp]: "f - (A Int B) = (f - A) Int (f - B)"

  2377   by fast

  2378

  2379 lemma vimage_Union: "f - (Union A) = (UN X:A. f - X)"

  2380   by blast

  2381

  2382 lemma vimage_UN: "f-(UN x:A. B x) = (UN x:A. f - B x)"

  2383   by blast

  2384

  2385 lemma vimage_INT: "f-(INT x:A. B x) = (INT x:A. f - B x)"

  2386   by blast

  2387

  2388 lemma vimage_Collect_eq [simp]: "f - Collect P = {y. P (f y)}"

  2389   by blast

  2390

  2391 lemma vimage_Collect: "(!!x. P (f x) = Q x) ==> f - (Collect P) = Collect Q"

  2392   by blast

  2393

  2394 lemma vimage_insert: "f-(insert a B) = (f-{a}) Un (f-B)"

  2395   -- {* NOT suitable for rewriting because of the recurrence of @{term "{a}"}. *}

  2396   by blast

  2397

  2398 lemma vimage_Diff: "f - (A - B) = (f - A) - (f - B)"

  2399   by blast

  2400

  2401 lemma vimage_UNIV [simp]: "f - UNIV = UNIV"

  2402   by blast

  2403

  2404 lemma vimage_eq_UN: "f-B = (UN y: B. f-{y})"

  2405   -- {* NOT suitable for rewriting *}

  2406   by blast

  2407

  2408 lemma vimage_mono: "A \<subseteq> B ==> f - A \<subseteq> f - B"

  2409   -- {* monotonicity *}

  2410   by blast

  2411

  2412 lemma vimage_image_eq [noatp]: "f - (f  A) = {y. EX x:A. f x = f y}"

  2413 by (blast intro: sym)

  2414

  2415 lemma image_vimage_subset: "f  (f - A) <= A"

  2416 by blast

  2417

  2418 lemma image_vimage_eq [simp]: "f  (f - A) = A Int range f"

  2419 by blast

  2420

  2421 lemma image_Int_subset: "f(A Int B) <= fA Int fB"

  2422 by blast

  2423

  2424 lemma image_diff_subset: "fA - fB <= f(A - B)"

  2425 by blast

  2426

  2427 lemma image_UN: "(f  (UNION A B)) = (UN x:A.(f  (B x)))"

  2428 by blast

  2429

  2430

  2431 subsection {* Getting the Contents of a Singleton Set *}

  2432

  2433 definition contents :: "'a set \<Rightarrow> 'a" where

  2434   [code del]: "contents X = (THE x. X = {x})"

  2435

  2436 lemma contents_eq [simp]: "contents {x} = x"

  2437   by (simp add: contents_def)

  2438

  2439

  2440 subsection {* Transitivity rules for calculational reasoning *}

  2441

  2442 lemma set_rev_mp: "x:A ==> A \<subseteq> B ==> x:B"

  2443   by (rule subsetD)

  2444

  2445 lemma set_mp: "A \<subseteq> B ==> x:A ==> x:B"

  2446   by (rule subsetD)

  2447

  2448 lemmas basic_trans_rules [trans] =

  2449   order_trans_rules set_rev_mp set_mp

  2450

  2451

  2452 subsection {* Least value operator *}

  2453

  2454 lemma Least_mono:

  2455   "mono (f::'a::order => 'b::order) ==> EX x:S. ALL y:S. x <= y

  2456     ==> (LEAST y. y : f  S) = f (LEAST x. x : S)"

  2457     -- {* Courtesy of Stephan Merz *}

  2458   apply clarify

  2459   apply (erule_tac P = "%x. x : S" in LeastI2_order, fast)

  2460   apply (rule LeastI2_order)

  2461   apply (auto elim: monoD intro!: order_antisym)

  2462   done

  2463

  2464

  2465 subsection {* Rudimentary code generation *}

  2466

  2467 lemma empty_code [code]: "{} x \<longleftrightarrow> False"

  2468   unfolding empty_def Collect_def ..

  2469

  2470 lemma UNIV_code [code]: "UNIV x \<longleftrightarrow> True"

  2471   unfolding UNIV_def Collect_def ..

  2472

  2473 lemma insert_code [code]: "insert y A x \<longleftrightarrow> y = x \<or> A x"

  2474   unfolding insert_def Collect_def mem_def Un_def by auto

  2475

  2476 lemma inter_code [code]: "(A \<inter> B) x \<longleftrightarrow> A x \<and> B x"

  2477   unfolding Int_def Collect_def mem_def ..

  2478

  2479 lemma union_code [code]: "(A \<union> B) x \<longleftrightarrow> A x \<or> B x"

  2480   unfolding Un_def Collect_def mem_def ..

  2481

  2482 lemma vimage_code [code]: "(f - A) x = A (f x)"

  2483   unfolding vimage_def Collect_def mem_def ..

  2484

  2485

  2486 subsection {* Misc theorem and ML bindings *}

  2487

  2488 lemmas equalityI = subset_antisym

  2489 lemmas mem_simps =

  2490   insert_iff empty_iff Un_iff Int_iff Compl_iff Diff_iff

  2491   mem_Collect_eq UN_iff Union_iff INT_iff Inter_iff

  2492   -- {* Each of these has ALREADY been added @{text "[simp]"} above. *}

  2493

  2494 ML {*

  2495 val Ball_def = @{thm Ball_def}

  2496 val Bex_def = @{thm Bex_def}

  2497 val CollectD = @{thm CollectD}

  2498 val CollectE = @{thm CollectE}

  2499 val CollectI = @{thm CollectI}

  2500 val Collect_conj_eq = @{thm Collect_conj_eq}

  2501 val Collect_mem_eq = @{thm Collect_mem_eq}

  2502 val IntD1 = @{thm IntD1}

  2503 val IntD2 = @{thm IntD2}

  2504 val IntE = @{thm IntE}

  2505 val IntI = @{thm IntI}

  2506 val Int_Collect = @{thm Int_Collect}

  2507 val UNIV_I = @{thm UNIV_I}

  2508 val UNIV_witness = @{thm UNIV_witness}

  2509 val UnE = @{thm UnE}

  2510 val UnI1 = @{thm UnI1}

  2511 val UnI2 = @{thm UnI2}

  2512 val ballE = @{thm ballE}

  2513 val ballI = @{thm ballI}

  2514 val bexCI = @{thm bexCI}

  2515 val bexE = @{thm bexE}

  2516 val bexI = @{thm bexI}

  2517 val bex_triv = @{thm bex_triv}

  2518 val bspec = @{thm bspec}

  2519 val contra_subsetD = @{thm contra_subsetD}

  2520 val distinct_lemma = @{thm distinct_lemma}

  2521 val eq_to_mono = @{thm eq_to_mono}

  2522 val eq_to_mono2 = @{thm eq_to_mono2}

  2523 val equalityCE = @{thm equalityCE}

  2524 val equalityD1 = @{thm equalityD1}

  2525 val equalityD2 = @{thm equalityD2}

  2526 val equalityE = @{thm equalityE}

  2527 val equalityI = @{thm equalityI}

  2528 val imageE = @{thm imageE}

  2529 val imageI = @{thm imageI}

  2530 val image_Un = @{thm image_Un}

  2531 val image_insert = @{thm image_insert}

  2532 val insert_commute = @{thm insert_commute}

  2533 val insert_iff = @{thm insert_iff}

  2534 val mem_Collect_eq = @{thm mem_Collect_eq}

  2535 val rangeE = @{thm rangeE}

  2536 val rangeI = @{thm rangeI}

  2537 val range_eqI = @{thm range_eqI}

  2538 val subsetCE = @{thm subsetCE}

  2539 val subsetD = @{thm subsetD}

  2540 val subsetI = @{thm subsetI}

  2541 val subset_refl = @{thm subset_refl}

  2542 val subset_trans = @{thm subset_trans}

  2543 val vimageD = @{thm vimageD}

  2544 val vimageE = @{thm vimageE}

  2545 val vimageI = @{thm vimageI}

  2546 val vimageI2 = @{thm vimageI2}

  2547 val vimage_Collect = @{thm vimage_Collect}

  2548 val vimage_Int = @{thm vimage_Int}

  2549 val vimage_Un = @{thm vimage_Un}

  2550 *}

  2551

  2552 end