src/HOL/Set.thy
 author haftmann Wed Jul 22 14:20:32 2009 +0200 (2009-07-22) changeset 32135 f645b51e8e54 parent 32120 53a21a5e6889 child 32139 e271a64f03ff permissions -rw-r--r--
set intersection and union now named inter and union; closer connection between set and lattice operations; factored out complete lattice
     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 subsection {* Sets as predicates *}

    12

    13 global

    14

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

    16

    17 consts

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

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

    20

    21 local

    22

    23 notation

    24   "op :"  ("op :") and

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

    26

    27 defs

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

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

    30

    31 abbreviation

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

    33

    34 notation

    35   not_mem  ("op ~:") and

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

    37

    38 notation (xsymbols)

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

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

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

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

    43

    44 notation (HTML output)

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

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

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

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

    49

    50 text {* Set comprehensions *}

    51

    52 syntax

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

    54

    55 translations

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

    57

    58 syntax

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

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

    61

    62 syntax (xsymbols)

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

    64

    65 translations

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

    67

    68 lemma mem_Collect_eq [iff]: "(a : {x. P(x)}) = P(a)"

    69   by (simp add: Collect_def mem_def)

    70

    71 lemma Collect_mem_eq [simp]: "{x. x:A} = A"

    72   by (simp add: Collect_def mem_def)

    73

    74 lemma CollectI: "P(a) ==> a : {x. P(x)}"

    75   by simp

    76

    77 lemma CollectD: "a : {x. P(x)} ==> P(a)"

    78   by simp

    79

    80 lemma Collect_cong: "(!!x. P x = Q x) ==> {x. P(x)} = {x. Q(x)}"

    81   by simp

    82

    83 text {*

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

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

    86 *}

    87

    88 setup {*

    89 let

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

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

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

    93   val defColl_regroup = Simplifier.simproc @{theory}

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

    95     (Quantifier1.rearrange_Coll Coll_perm_tac)

    96 in

    97   Simplifier.map_simpset (fn ss => ss addsimprocs [defColl_regroup])

    98 end

    99 *}

   100

   101 lemmas CollectE = CollectD [elim_format]

   102

   103 text {* Set enumerations *}

   104

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

   106   bot_set_eq [symmetric]: "{} = bot"

   107

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

   109   insert_compr: "insert a B = {x. x = a \<or> x \<in> B}"

   110

   111 syntax

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

   113

   114 translations

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

   116   "{x}"         == "CONST insert x {}"

   117

   118

   119 subsection {* Subsets and bounded quantifiers *}

   120

   121 abbreviation

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

   123   "subset \<equiv> less"

   124

   125 abbreviation

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

   127   "subset_eq \<equiv> less_eq"

   128

   129 notation (output)

   130   subset  ("op <") and

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

   132   subset_eq  ("op <=") and

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

   134

   135 notation (xsymbols)

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

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

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

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

   140

   141 notation (HTML output)

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

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

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

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

   146

   147 abbreviation (input)

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

   149   "supset \<equiv> greater"

   150

   151 abbreviation (input)

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

   153   "supset_eq \<equiv> greater_eq"

   154

   155 notation (xsymbols)

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

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

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

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

   160

   161 global

   162

   163 consts

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

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

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

   167

   168 local

   169

   170 defs

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

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

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

   174

   175 syntax

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

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

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

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

   180

   181 syntax (HOL)

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

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

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

   185

   186 syntax (xsymbols)

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

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

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

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

   191

   192 syntax (HTML output)

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

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

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

   196

   197 translations

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

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

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

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

   202

   203 syntax (output)

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

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

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

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

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

   209

   210 syntax (xsymbols)

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

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

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

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

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

   216

   217 syntax (HOL output)

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

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

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

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

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

   223

   224 syntax (HTML output)

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

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

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

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

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

   230

   231 translations

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

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

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

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

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

   237

   238 print_translation {*

   239 let

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

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

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

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

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

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

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

   247

   248   val trans =

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

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

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

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

   253

   254   fun mk v v' c n P =

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

   256     then Syntax.const c $Syntax.mark_bound v'$ n $P else raise Match;   257   258 fun tr' q = (q,   259 fn [Const ("_bound", _)$ Free (v, Type (T, _)), Const (c, _) $(Const (d, _)$ (Const ("_bound", _) $Free (v', _))$ n) $P] =>   260 if T = (set_type) then case AList.lookup (op =) trans (q, c, d)   261 of NONE => raise Match   262 | SOME l => mk v v' l n P   263 else raise Match   264 | _ => raise Match);   265 in   266 [tr' All_binder, tr' Ex_binder]   267 end   268 *}   269   270   271 text {*   272 \medskip Translate between @{text "{e | x1...xn. P}"} and @{text   273 "{u. EX x1..xn. u = e & P}"}; @{text "{y. EX x1..xn. y = e & P}"} is   274 only translated if @{text "[0..n] subset bvs(e)"}.   275 *}   276   277 parse_translation {*   278 let   279 val ex_tr = snd (mk_binder_tr ("EX ", "Ex"));   280   281 fun nvars (Const ("_idts", _)$ _ $idts) = nvars idts + 1   282 | nvars _ = 1;   283   284 fun setcompr_tr [e, idts, b] =   285 let   286 val eq = Syntax.const "op ="$ Bound (nvars idts) $e;   287 val P = Syntax.const "op &"$ eq $b;   288 val exP = ex_tr [idts, P];   289 in Syntax.const "Collect"$ Term.absdummy (dummyT, exP) end;

   290

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

   292 *}

   293

   294 print_translation {* [

   295 Syntax.preserve_binder_abs2_tr' @{const_syntax Ball} "_Ball",

   296 Syntax.preserve_binder_abs2_tr' @{const_syntax Bex} "_Bex"

   297 ] *} -- {* to avoid eta-contraction of body *}

   298

   299 print_translation {*

   300 let

   301   val ex_tr' = snd (mk_binder_tr' ("Ex", "DUMMY"));

   302

   303   fun setcompr_tr' [Abs (abs as (_, _, P))] =

   304     let

   305       fun check (Const ("Ex", _) $Abs (_, _, P), n) = check (P, n + 1)   306 | check (Const ("op &", _)$ (Const ("op =", _) $Bound m$ e) $P, n) =   307 n > 0 andalso m = n andalso not (loose_bvar1 (P, n)) andalso   308 ((0 upto (n - 1)) subset add_loose_bnos (e, 0, []))   309 | check _ = false   310   311 fun tr' (_$ abs) =

   312           let val _ $idts$ (_ $(_$ _ $e)$ Q) = ex_tr' [abs]

   313           in Syntax.const "@SetCompr" $e$ idts $Q end;   314 in if check (P, 0) then tr' P   315 else let val (x as _$ Free(xN,_), t) = atomic_abs_tr' abs

   316                 val M = Syntax.const "@Coll" $x$ t

   317             in case t of

   318                  Const("op &",_)

   319                    $(Const("op :",_)$ (Const("_bound",_) $Free(yN,_))$ A)

   320                    $P =>   321 if xN=yN then Syntax.const "@Collect"$ x $A$ P else M

   322                | _ => M

   323             end

   324     end;

   325   in [("Collect", setcompr_tr')] end;

   326 *}

   327

   328 setup {*

   329 let

   330   val unfold_bex_tac = unfold_tac @{thms "Bex_def"};

   331   fun prove_bex_tac ss = unfold_bex_tac ss THEN Quantifier1.prove_one_point_ex_tac;

   332   val rearrange_bex = Quantifier1.rearrange_bex prove_bex_tac;

   333   val unfold_ball_tac = unfold_tac @{thms "Ball_def"};

   334   fun prove_ball_tac ss = unfold_ball_tac ss THEN Quantifier1.prove_one_point_all_tac;

   335   val rearrange_ball = Quantifier1.rearrange_ball prove_ball_tac;

   336   val defBEX_regroup = Simplifier.simproc @{theory}

   337     "defined BEX" ["EX x:A. P x & Q x"] rearrange_bex;

   338   val defBALL_regroup = Simplifier.simproc @{theory}

   339     "defined BALL" ["ALL x:A. P x --> Q x"] rearrange_ball;

   340 in

   341   Simplifier.map_simpset (fn ss => ss addsimprocs [defBALL_regroup, defBEX_regroup])

   342 end

   343 *}

   344

   345 lemma ballI [intro!]: "(!!x. x:A ==> P x) ==> ALL x:A. P x"

   346   by (simp add: Ball_def)

   347

   348 lemmas strip = impI allI ballI

   349

   350 lemma bspec [dest?]: "ALL x:A. P x ==> x:A ==> P x"

   351   by (simp add: Ball_def)

   352

   353 text {*

   354   Gives better instantiation for bound:

   355 *}

   356

   357 declaration {* fn _ =>

   358   Classical.map_cs (fn cs => cs addbefore ("bspec", datac @{thm bspec} 1))

   359 *}

   360

   361 ML {*

   362 structure Simpdata =

   363 struct

   364

   365 open Simpdata;

   366

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

   368

   369 end;

   370

   371 open Simpdata;

   372 *}

   373

   374 declaration {* fn _ =>

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

   376 *}

   377

   378 lemma ballE [elim]: "ALL x:A. P x ==> (P x ==> Q) ==> (x ~: A ==> Q) ==> Q"

   379   by (unfold Ball_def) blast

   380

   381 lemma bexI [intro]: "P x ==> x:A ==> EX x:A. P x"

   382   -- {* Normally the best argument order: @{prop "P x"} constrains the

   383     choice of @{prop "x:A"}. *}

   384   by (unfold Bex_def) blast

   385

   386 lemma rev_bexI [intro?]: "x:A ==> P x ==> EX x:A. P x"

   387   -- {* The best argument order when there is only one @{prop "x:A"}. *}

   388   by (unfold Bex_def) blast

   389

   390 lemma bexCI: "(ALL x:A. ~P x ==> P a) ==> a:A ==> EX x:A. P x"

   391   by (unfold Bex_def) blast

   392

   393 lemma bexE [elim!]: "EX x:A. P x ==> (!!x. x:A ==> P x ==> Q) ==> Q"

   394   by (unfold Bex_def) blast

   395

   396 lemma ball_triv [simp]: "(ALL x:A. P) = ((EX x. x:A) --> P)"

   397   -- {* Trival rewrite rule. *}

   398   by (simp add: Ball_def)

   399

   400 lemma bex_triv [simp]: "(EX x:A. P) = ((EX x. x:A) & P)"

   401   -- {* Dual form for existentials. *}

   402   by (simp add: Bex_def)

   403

   404 lemma bex_triv_one_point1 [simp]: "(EX x:A. x = a) = (a:A)"

   405   by blast

   406

   407 lemma bex_triv_one_point2 [simp]: "(EX x:A. a = x) = (a:A)"

   408   by blast

   409

   410 lemma bex_one_point1 [simp]: "(EX x:A. x = a & P x) = (a:A & P a)"

   411   by blast

   412

   413 lemma bex_one_point2 [simp]: "(EX x:A. a = x & P x) = (a:A & P a)"

   414   by blast

   415

   416 lemma ball_one_point1 [simp]: "(ALL x:A. x = a --> P x) = (a:A --> P a)"

   417   by blast

   418

   419 lemma ball_one_point2 [simp]: "(ALL x:A. a = x --> P x) = (a:A --> P a)"

   420   by blast

   421

   422

   423 text {* Congruence rules *}

   424

   425 lemma ball_cong:

   426   "A = B ==> (!!x. x:B ==> P x = Q x) ==>

   427     (ALL x:A. P x) = (ALL x:B. Q x)"

   428   by (simp add: Ball_def)

   429

   430 lemma strong_ball_cong [cong]:

   431   "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>

   432     (ALL x:A. P x) = (ALL x:B. Q x)"

   433   by (simp add: simp_implies_def Ball_def)

   434

   435 lemma bex_cong:

   436   "A = B ==> (!!x. x:B ==> P x = Q x) ==>

   437     (EX x:A. P x) = (EX x:B. Q x)"

   438   by (simp add: Bex_def cong: conj_cong)

   439

   440 lemma strong_bex_cong [cong]:

   441   "A = B ==> (!!x. x:B =simp=> P x = Q x) ==>

   442     (EX x:A. P x) = (EX x:B. Q x)"

   443   by (simp add: simp_implies_def Bex_def cong: conj_cong)

   444

   445

   446 subsection {* Basic operations *}

   447

   448 subsubsection {* Subsets *}

   449

   450 lemma subsetI [atp,intro!]: "(!!x. x:A ==> x:B) ==> A \<subseteq> B"

   451   by (auto simp add: mem_def intro: predicate1I)

   452

   453 text {*

   454   \medskip Map the type @{text "'a set => anything"} to just @{typ

   455   'a}; for overloading constants whose first argument has type @{typ

   456   "'a set"}.

   457 *}

   458

   459 lemma subsetD [elim, intro?]: "A \<subseteq> B ==> c \<in> A ==> c \<in> B"

   460   -- {* Rule in Modus Ponens style. *}

   461   by (unfold mem_def) blast

   462

   463 lemma rev_subsetD [intro?]: "c \<in> A ==> A \<subseteq> B ==> c \<in> B"

   464   -- {* The same, with reversed premises for use with @{text erule} --

   465       cf @{text rev_mp}. *}

   466   by (rule subsetD)

   467

   468 text {*

   469   \medskip Converts @{prop "A \<subseteq> B"} to @{prop "x \<in> A ==> x \<in> B"}.

   470 *}

   471

   472 lemma subsetCE [elim]: "A \<subseteq>  B ==> (c \<notin> A ==> P) ==> (c \<in> B ==> P) ==> P"

   473   -- {* Classical elimination rule. *}

   474   by (unfold mem_def) blast

   475

   476 lemma subset_eq: "A \<le> B = (\<forall>x\<in>A. x \<in> B)" by blast

   477

   478 lemma contra_subsetD: "A \<subseteq> B ==> c \<notin> B ==> c \<notin> A"

   479   by blast

   480

   481 lemma subset_refl [simp,atp]: "A \<subseteq> A"

   482   by (fact order_refl)

   483

   484 lemma subset_trans: "A \<subseteq> B ==> B \<subseteq> C ==> A \<subseteq> C"

   485   by (fact order_trans)

   486

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

   488   by (rule subsetD)

   489

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

   491   by (rule subsetD)

   492

   493 lemmas basic_trans_rules [trans] =

   494   order_trans_rules set_rev_mp set_mp

   495

   496

   497 subsubsection {* Equality *}

   498

   499 lemma set_ext: assumes prem: "(!!x. (x:A) = (x:B))" shows "A = B"

   500   apply (rule prem [THEN ext, THEN arg_cong, THEN box_equals])

   501    apply (rule Collect_mem_eq)

   502   apply (rule Collect_mem_eq)

   503   done

   504

   505 (* Due to Brian Huffman *)

   506 lemma expand_set_eq: "(A = B) = (ALL x. (x:A) = (x:B))"

   507 by(auto intro:set_ext)

   508

   509 lemma subset_antisym [intro!]: "A \<subseteq> B ==> B \<subseteq> A ==> A = B"

   510   -- {* Anti-symmetry of the subset relation. *}

   511   by (iprover intro: set_ext subsetD)

   512

   513 text {*

   514   \medskip Equality rules from ZF set theory -- are they appropriate

   515   here?

   516 *}

   517

   518 lemma equalityD1: "A = B ==> A \<subseteq> B"

   519   by (simp add: subset_refl)

   520

   521 lemma equalityD2: "A = B ==> B \<subseteq> A"

   522   by (simp add: subset_refl)

   523

   524 text {*

   525   \medskip Be careful when adding this to the claset as @{text

   526   subset_empty} is in the simpset: @{prop "A = {}"} goes to @{prop "{}

   527   \<subseteq> A"} and @{prop "A \<subseteq> {}"} and then back to @{prop "A = {}"}!

   528 *}

   529

   530 lemma equalityE: "A = B ==> (A \<subseteq> B ==> B \<subseteq> A ==> P) ==> P"

   531   by (simp add: subset_refl)

   532

   533 lemma equalityCE [elim]:

   534     "A = B ==> (c \<in> A ==> c \<in> B ==> P) ==> (c \<notin> A ==> c \<notin> B ==> P) ==> P"

   535   by blast

   536

   537 lemma eqset_imp_iff: "A = B ==> (x : A) = (x : B)"

   538   by simp

   539

   540 lemma eqelem_imp_iff: "x = y ==> (x : A) = (y : A)"

   541   by simp

   542

   543

   544 subsubsection {* The universal set -- UNIV *}

   545

   546 definition UNIV :: "'a set" where

   547   top_set_eq [symmetric]: "UNIV = top"

   548

   549 lemma UNIV_def:

   550   "UNIV = {x. True}"

   551   by (simp add: top_set_eq [symmetric] top_fun_eq top_bool_eq Collect_def)

   552

   553 lemma UNIV_I [simp]: "x : UNIV"

   554   by (simp add: UNIV_def)

   555

   556 declare UNIV_I [intro]  -- {* unsafe makes it less likely to cause problems *}

   557

   558 lemma UNIV_witness [intro?]: "EX x. x : UNIV"

   559   by simp

   560

   561 lemma subset_UNIV [simp]: "A \<subseteq> UNIV"

   562   by (rule subsetI) (rule UNIV_I)

   563

   564 text {*

   565   \medskip Eta-contracting these two rules (to remove @{text P})

   566   causes them to be ignored because of their interaction with

   567   congruence rules.

   568 *}

   569

   570 lemma ball_UNIV [simp]: "Ball UNIV P = All P"

   571   by (simp add: Ball_def)

   572

   573 lemma bex_UNIV [simp]: "Bex UNIV P = Ex P"

   574   by (simp add: Bex_def)

   575

   576 lemma UNIV_eq_I: "(\<And>x. x \<in> A) \<Longrightarrow> UNIV = A"

   577   by auto

   578

   579

   580 subsubsection {* The empty set *}

   581

   582 lemma empty_def:

   583   "{} = {x. False}"

   584   by (simp add: bot_set_eq [symmetric] bot_fun_eq bot_bool_eq Collect_def)

   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: @{text "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 definition union :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a set" (infixl "Un" 65) where

   658   sup_set_eq [symmetric]: "A Un B = sup A B"

   659

   660 notation (xsymbols)

   661   union  (infixl "\<union>" 65)

   662

   663 notation (HTML output)

   664   union  (infixl "\<union>" 65)

   665

   666 lemma Un_def:

   667   "A \<union> B = {x. x \<in> A \<or> x \<in> B}"

   668   by (simp add: sup_fun_eq sup_bool_eq sup_set_eq [symmetric] Collect_def mem_def)

   669

   670 lemma Un_iff [simp]: "(c : A Un B) = (c:A | c:B)"

   671   by (unfold Un_def) blast

   672

   673 lemma UnI1 [elim?]: "c:A ==> c : A Un B"

   674   by simp

   675

   676 lemma UnI2 [elim?]: "c:B ==> c : A Un B"

   677   by simp

   678

   679 text {*

   680   \medskip Classical introduction rule: no commitment to @{prop A} vs

   681   @{prop B}.

   682 *}

   683

   684 lemma UnCI [intro!]: "(c~:B ==> c:A) ==> c : A Un B"

   685   by auto

   686

   687 lemma UnE [elim!]: "c : A Un B ==> (c:A ==> P) ==> (c:B ==> P) ==> P"

   688   by (unfold Un_def) blast

   689

   690 lemma insert_def: "insert a B = {x. x = a} \<union> B"

   691   by (simp add: Collect_def mem_def insert_compr Un_def)

   692

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

   694   apply (fold sup_set_eq)

   695   apply (erule mono_sup)

   696   done

   697

   698

   699 subsubsection {* Binary intersection -- Int *}

   700

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

   702   inf_set_eq [symmetric]: "A Int B = inf A B"

   703

   704 notation (xsymbols)

   705   inter  (infixl "\<inter>" 70)

   706

   707 notation (HTML output)

   708   inter  (infixl "\<inter>" 70)

   709

   710 lemma Int_def:

   711   "A \<inter> B = {x. x \<in> A \<and> x \<in> B}"

   712   by (simp add: inf_fun_eq inf_bool_eq inf_set_eq [symmetric] Collect_def mem_def)

   713

   714 lemma Int_iff [simp]: "(c : A Int B) = (c:A & c:B)"

   715   by (unfold Int_def) blast

   716

   717 lemma IntI [intro!]: "c:A ==> c:B ==> c : A Int B"

   718   by simp

   719

   720 lemma IntD1: "c : A Int B ==> c:A"

   721   by simp

   722

   723 lemma IntD2: "c : A Int B ==> c:B"

   724   by simp

   725

   726 lemma IntE [elim!]: "c : A Int B ==> (c:A ==> c:B ==> P) ==> P"

   727   by simp

   728

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

   730   apply (fold inf_set_eq)

   731   apply (erule mono_inf)

   732   done

   733

   734

   735 subsubsection {* Set difference *}

   736

   737 lemma Diff_iff [simp]: "(c : A - B) = (c:A & c~:B)"

   738   by (simp add: mem_def fun_diff_def bool_diff_def)

   739

   740 lemma DiffI [intro!]: "c : A ==> c ~: B ==> c : A - B"

   741   by simp

   742

   743 lemma DiffD1: "c : A - B ==> c : A"

   744   by simp

   745

   746 lemma DiffD2: "c : A - B ==> c : B ==> P"

   747   by simp

   748

   749 lemma DiffE [elim!]: "c : A - B ==> (c:A ==> c~:B ==> P) ==> P"

   750   by simp

   751

   752 lemma set_diff_eq: "A - B = {x. x : A & ~ x : B}" by blast

   753

   754 lemma Compl_eq_Diff_UNIV: "-A = (UNIV - A)"

   755 by blast

   756

   757

   758 subsubsection {* Augmenting a set -- @{const insert} *}

   759

   760 lemma insert_iff [simp]: "(a : insert b A) = (a = b | a:A)"

   761   by (unfold insert_def) blast

   762

   763 lemma insertI1: "a : insert a B"

   764   by simp

   765

   766 lemma insertI2: "a : B ==> a : insert b B"

   767   by simp

   768

   769 lemma insertE [elim!]: "a : insert b A ==> (a = b ==> P) ==> (a:A ==> P) ==> P"

   770   by (unfold insert_def) blast

   771

   772 lemma insertCI [intro!]: "(a~:B ==> a = b) ==> a: insert b B"

   773   -- {* Classical introduction rule. *}

   774   by auto

   775

   776 lemma subset_insert_iff: "(A \<subseteq> insert x B) = (if x:A then A - {x} \<subseteq> B else A \<subseteq> B)"

   777   by auto

   778

   779 lemma set_insert:

   780   assumes "x \<in> A"

   781   obtains B where "A = insert x B" and "x \<notin> B"

   782 proof

   783   from assms show "A = insert x (A - {x})" by blast

   784 next

   785   show "x \<notin> A - {x}" by blast

   786 qed

   787

   788 lemma insert_ident: "x ~: A ==> x ~: B ==> (insert x A = insert x B) = (A = B)"

   789 by auto

   790

   791 subsubsection {* Singletons, using insert *}

   792

   793 lemma singletonI [intro!,noatp]: "a : {a}"

   794     -- {* Redundant? But unlike @{text insertCI}, it proves the subgoal immediately! *}

   795   by (rule insertI1)

   796

   797 lemma singletonD [dest!,noatp]: "b : {a} ==> b = a"

   798   by blast

   799

   800 lemmas singletonE = singletonD [elim_format]

   801

   802 lemma singleton_iff: "(b : {a}) = (b = a)"

   803   by blast

   804

   805 lemma singleton_inject [dest!]: "{a} = {b} ==> a = b"

   806   by blast

   807

   808 lemma singleton_insert_inj_eq [iff,noatp]:

   809      "({b} = insert a A) = (a = b & A \<subseteq> {b})"

   810   by blast

   811

   812 lemma singleton_insert_inj_eq' [iff,noatp]:

   813      "(insert a A = {b}) = (a = b & A \<subseteq> {b})"

   814   by blast

   815

   816 lemma subset_singletonD: "A \<subseteq> {x} ==> A = {} | A = {x}"

   817   by fast

   818

   819 lemma singleton_conv [simp]: "{x. x = a} = {a}"

   820   by blast

   821

   822 lemma singleton_conv2 [simp]: "{x. a = x} = {a}"

   823   by blast

   824

   825 lemma diff_single_insert: "A - {x} \<subseteq> B ==> x \<in> A ==> A \<subseteq> insert x B"

   826   by blast

   827

   828 lemma doubleton_eq_iff: "({a,b} = {c,d}) = (a=c & b=d | a=d & b=c)"

   829   by (blast elim: equalityE)

   830

   831

   832 subsubsection {* Image of a set under a function *}

   833

   834 text {*

   835   Frequently @{term b} does not have the syntactic form of @{term "f x"}.

   836 *}

   837

   838 definition image :: "('a => 'b) => 'a set => 'b set" (infixr "" 90) where

   839   image_def [noatp]: "f  A = {y. EX x:A. y = f(x)}"

   840

   841 abbreviation

   842   range :: "('a => 'b) => 'b set" where -- "of function"

   843   "range f == f  UNIV"

   844

   845 lemma image_eqI [simp, intro]: "b = f x ==> x:A ==> b : fA"

   846   by (unfold image_def) blast

   847

   848 lemma imageI: "x : A ==> f x : f  A"

   849   by (rule image_eqI) (rule refl)

   850

   851 lemma rev_image_eqI: "x:A ==> b = f x ==> b : fA"

   852   -- {* This version's more effective when we already have the

   853     required @{term x}. *}

   854   by (unfold image_def) blast

   855

   856 lemma imageE [elim!]:

   857   "b : (%x. f x)A ==> (!!x. b = f x ==> x:A ==> P) ==> P"

   858   -- {* The eta-expansion gives variable-name preservation. *}

   859   by (unfold image_def) blast

   860

   861 lemma image_Un: "f(A Un B) = fA Un fB"

   862   by blast

   863

   864 lemma image_iff: "(z : fA) = (EX x:A. z = f x)"

   865   by blast

   866

   867 lemma image_subset_iff: "(fA \<subseteq> B) = (\<forall>x\<in>A. f x \<in> B)"

   868   -- {* This rewrite rule would confuse users if made default. *}

   869   by blast

   870

   871 lemma subset_image_iff: "(B \<subseteq> fA) = (EX AA. AA \<subseteq> A & B = fAA)"

   872   apply safe

   873    prefer 2 apply fast

   874   apply (rule_tac x = "{a. a : A & f a : B}" in exI, fast)

   875   done

   876

   877 lemma image_subsetI: "(!!x. x \<in> A ==> f x \<in> B) ==> fA \<subseteq> B"

   878   -- {* Replaces the three steps @{text subsetI}, @{text imageE},

   879     @{text hypsubst}, but breaks too many existing proofs. *}

   880   by blast

   881

   882 text {*

   883   \medskip Range of a function -- just a translation for image!

   884 *}

   885

   886 lemma range_eqI: "b = f x ==> b \<in> range f"

   887   by simp

   888

   889 lemma rangeI: "f x \<in> range f"

   890   by simp

   891

   892 lemma rangeE [elim?]: "b \<in> range (\<lambda>x. f x) ==> (!!x. b = f x ==> P) ==> P"

   893   by blast

   894

   895

   896 subsubsection {* Some rules with @{text "if"} *}

   897

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

   899

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

   901   by auto

   902

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

   904   by auto

   905

   906 text {*

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

   908   "split_if [split]"}.

   909 *}

   910

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

   912   by (rule split_if)

   913

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

   915   by (rule split_if)

   916

   917 text {*

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

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

   920 *}

   921

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

   923   by (rule split_if)

   924

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

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

   927

   928 lemmas split_ifs = if_bool_eq_conj split_if_eq1 split_if_eq2 split_if_mem1 split_if_mem2

   929

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

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

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

   933   apply, then the formula should be kept.

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

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

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

   937  *)

   938

   939

   940 subsection {* Further operations and lemmas *}

   941

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

   943

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

   945   by (unfold less_le) blast

   946

   947 lemma psubsetE [elim!,noatp]:

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

   949   by (unfold less_le) blast

   950

   951 lemma psubset_insert_iff:

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

   953   by (auto simp add: less_le subset_insert_iff)

   954

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

   956   by (simp only: less_le)

   957

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

   959   by (simp add: psubset_eq)

   960

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

   962 apply (unfold less_le)

   963 apply (auto dest: subset_antisym)

   964 done

   965

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

   967 apply (unfold less_le)

   968 apply (auto dest: subsetD)

   969 done

   970

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

   972   by (auto simp add: psubset_eq)

   973

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

   975   by (auto simp add: psubset_eq)

   976

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

   978   by (unfold less_le) blast

   979

   980 lemma atomize_ball:

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

   982   by (simp only: Ball_def atomize_all atomize_imp)

   983

   984 lemmas [symmetric, rulify] = atomize_ball

   985   and [symmetric, defn] = atomize_ball

   986

   987 subsubsection {* Derived rules involving subsets. *}

   988

   989 text {* @{text insert}. *}

   990

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

   992   by (rule subsetI) (erule insertI2)

   993

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

   995   by blast

   996

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

   998   by blast

   999

  1000

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

  1002

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

  1004   by blast

  1005

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

  1007   by blast

  1008

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

  1010   by blast

  1011

  1012

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

  1014

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

  1016   by blast

  1017

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

  1019   by blast

  1020

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

  1022   by blast

  1023

  1024

  1025 text {* \medskip Set difference. *}

  1026

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

  1028   by blast

  1029

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

  1031 by blast

  1032

  1033

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

  1035

  1036 text {* @{text "{}"}. *}

  1037

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

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

  1040   by auto

  1041

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

  1043   by blast

  1044

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

  1046   by (unfold less_le) blast

  1047

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

  1049 by blast

  1050

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

  1052 by blast

  1053

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

  1055   by blast

  1056

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

  1058   by blast

  1059

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

  1061   by blast

  1062

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

  1064   by blast

  1065

  1066

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

  1068

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

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

  1071   by blast

  1072

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

  1074   by blast

  1075

  1076 lemmas empty_not_insert = insert_not_empty [symmetric, standard]

  1077 declare empty_not_insert [simp]

  1078

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

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

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

  1082   by blast

  1083

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

  1085   by blast

  1086

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

  1088   by blast

  1089

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

  1091   by blast

  1092

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

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

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

  1096   done

  1097

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

  1099   by auto

  1100

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

  1102   by blast

  1103

  1104 lemma insert_disjoint [simp,noatp]:

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

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

  1107   by auto

  1108

  1109 lemma disjoint_insert [simp,noatp]:

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

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

  1112   by auto

  1113

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

  1115

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

  1117   by blast

  1118

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

  1120   by blast

  1121

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

  1123   by auto

  1124

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

  1126 by auto

  1127

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

  1129 by blast

  1130

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

  1132 by blast

  1133

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

  1135 by blast

  1136

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

  1138 by blast

  1139

  1140

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

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

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

  1144       equational properties than does the RHS. *}

  1145   by blast

  1146

  1147 lemma if_image_distrib [simp]:

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

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

  1150   by (auto simp add: image_def)

  1151

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

  1153   by (simp add: image_def)

  1154

  1155

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

  1157

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

  1159   by auto

  1160

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

  1162 by (subst image_image, simp)

  1163

  1164

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

  1166

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

  1168   by blast

  1169

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

  1171   by blast

  1172

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

  1174   by blast

  1175

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

  1177   by blast

  1178

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

  1180   by blast

  1181

  1182 lemmas Int_ac = Int_assoc Int_left_absorb Int_commute Int_left_commute

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

  1184

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

  1186   by blast

  1187

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

  1189   by blast

  1190

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

  1192   by blast

  1193

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

  1195   by blast

  1196

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

  1198   by blast

  1199

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

  1201   by blast

  1202

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

  1204   by blast

  1205

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

  1207   by blast

  1208

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

  1210   by blast

  1211

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

  1213   by blast

  1214

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

  1216   by blast

  1217

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

  1219   by blast

  1220

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

  1222   by blast

  1223

  1224

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

  1226

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

  1228   by blast

  1229

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

  1231   by blast

  1232

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

  1234   by blast

  1235

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

  1237   by blast

  1238

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

  1240   by blast

  1241

  1242 lemmas Un_ac = Un_assoc Un_left_absorb Un_commute Un_left_commute

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

  1244

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

  1246   by blast

  1247

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

  1249   by blast

  1250

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

  1252   by blast

  1253

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

  1255   by blast

  1256

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

  1258   by blast

  1259

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

  1261   by blast

  1262

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

  1264   by blast

  1265

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

  1267   by blast

  1268

  1269 lemma Int_insert_left:

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

  1271   by auto

  1272

  1273 lemma Int_insert_right:

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

  1275   by auto

  1276

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

  1278   by blast

  1279

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

  1281   by blast

  1282

  1283 lemma Un_Int_crazy:

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

  1285   by blast

  1286

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

  1288   by blast

  1289

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

  1291   by blast

  1292

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

  1294   by blast

  1295

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

  1297   by blast

  1298

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

  1300   by blast

  1301

  1302

  1303 text {* \medskip Set complement *}

  1304

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

  1306   by blast

  1307

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

  1309   by blast

  1310

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

  1312   by blast

  1313

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

  1315   by blast

  1316

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

  1318   by blast

  1319

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

  1321   by blast

  1322

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

  1324   by blast

  1325

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

  1327   by blast

  1328

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

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

  1331   by blast

  1332

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

  1334   by blast

  1335

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

  1337   by blast

  1338

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

  1340   by blast

  1341

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

  1343   by blast

  1344

  1345 text {* \medskip Bounded quantifiers.

  1346

  1347   The following are not added to the default simpset because

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

  1349

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

  1351   by blast

  1352

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

  1354   by blast

  1355

  1356

  1357 text {* \medskip Set difference. *}

  1358

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

  1360   by blast

  1361

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

  1363   by blast

  1364

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

  1366   by blast

  1367

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

  1369 by blast

  1370

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

  1372   by (blast elim: equalityE)

  1373

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

  1375   by blast

  1376

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

  1378   by blast

  1379

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

  1381   by blast

  1382

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

  1384   by blast

  1385

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

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

  1388   by blast

  1389

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

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

  1392   by blast

  1393

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

  1395   by auto

  1396

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

  1398   by blast

  1399

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

  1401 by blast

  1402

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

  1404   by blast

  1405

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

  1407   by auto

  1408

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

  1410   by blast

  1411

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

  1413   by blast

  1414

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

  1416   by blast

  1417

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

  1419   by blast

  1420

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

  1422   by blast

  1423

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

  1425   by blast

  1426

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

  1428   by blast

  1429

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

  1431   by blast

  1432

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

  1434   by blast

  1435

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

  1437   by blast

  1438

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

  1440   by blast

  1441

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

  1443   by auto

  1444

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

  1446   by blast

  1447

  1448

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

  1450

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

  1452   by (cases x) auto

  1453

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

  1455   by (auto intro: bool_induct)

  1456

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

  1458   by (cases x) auto

  1459

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

  1461   by (auto intro: bool_contrapos)

  1462

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

  1464

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

  1466   by (auto simp add: Pow_def)

  1467

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

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

  1470

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

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

  1473

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

  1475   by blast

  1476

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

  1478   by blast

  1479

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

  1481   by blast

  1482

  1483

  1484 text {* \medskip Miscellany. *}

  1485

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

  1487   by blast

  1488

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

  1490   by blast

  1491

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

  1493   by (unfold less_le) blast

  1494

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

  1496   by blast

  1497

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

  1499   by blast

  1500

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

  1502   by iprover

  1503

  1504

  1505 subsubsection {* Monotonicity of various operations *}

  1506

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

  1508   by blast

  1509

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

  1511   by blast

  1512

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

  1514   by blast

  1515

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

  1517   by blast

  1518

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

  1520   by blast

  1521

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

  1523   by blast

  1524

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

  1526   by blast

  1527

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

  1529

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

  1531   apply (rule impI)

  1532   apply (erule subsetD, assumption)

  1533   done

  1534

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

  1536   by iprover

  1537

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

  1539   by iprover

  1540

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

  1542   by iprover

  1543

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

  1545

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

  1547   by iprover

  1548

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

  1550   by iprover

  1551

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

  1553   by blast

  1554

  1555 lemma Int_Collect_mono:

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

  1557   by blast

  1558

  1559 lemmas basic_monos =

  1560   subset_refl imp_refl disj_mono conj_mono

  1561   ex_mono Collect_mono in_mono

  1562

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

  1564   by iprover

  1565

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

  1567   by iprover

  1568

  1569

  1570 subsubsection {* Inverse image of a function *}

  1571

  1572 constdefs

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

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

  1575

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

  1577   by (unfold vimage_def) blast

  1578

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

  1580   by simp

  1581

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

  1583   by (unfold vimage_def) blast

  1584

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

  1586   by (unfold vimage_def) fast

  1587

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

  1589   by (unfold vimage_def) blast

  1590

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

  1592   by (unfold vimage_def) fast

  1593

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

  1595   by blast

  1596

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

  1598   by blast

  1599

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

  1601   by blast

  1602

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

  1604   by fast

  1605

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

  1607   by blast

  1608

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

  1610   by blast

  1611

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

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

  1614   by blast

  1615

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

  1617   by blast

  1618

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

  1620   by blast

  1621

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

  1623   -- {* monotonicity *}

  1624   by blast

  1625

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

  1627 by (blast intro: sym)

  1628

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

  1630 by blast

  1631

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

  1633 by blast

  1634

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

  1636 by blast

  1637

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

  1639 by blast

  1640

  1641

  1642 subsubsection {* Getting the Contents of a Singleton Set *}

  1643

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

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

  1646

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

  1648   by (simp add: contents_def)

  1649

  1650

  1651 subsubsection {* Least value operator *}

  1652

  1653 lemma Least_mono:

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

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

  1656     -- {* Courtesy of Stephan Merz *}

  1657   apply clarify

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

  1659   apply (rule LeastI2_order)

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

  1661   done

  1662

  1663 subsection {* Misc *}

  1664

  1665 text {* Rudimentary code generation *}

  1666

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

  1668   by (auto simp add: insert_compr Collect_def mem_def)

  1669

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

  1671   by (simp add: vimage_def Collect_def mem_def)

  1672

  1673

  1674 text {* Misc theorem and ML bindings *}

  1675

  1676 lemmas equalityI = subset_antisym

  1677

  1678 ML {*

  1679 val Ball_def = @{thm Ball_def}

  1680 val Bex_def = @{thm Bex_def}

  1681 val CollectD = @{thm CollectD}

  1682 val CollectE = @{thm CollectE}

  1683 val CollectI = @{thm CollectI}

  1684 val Collect_conj_eq = @{thm Collect_conj_eq}

  1685 val Collect_mem_eq = @{thm Collect_mem_eq}

  1686 val IntD1 = @{thm IntD1}

  1687 val IntD2 = @{thm IntD2}

  1688 val IntE = @{thm IntE}

  1689 val IntI = @{thm IntI}

  1690 val Int_Collect = @{thm Int_Collect}

  1691 val UNIV_I = @{thm UNIV_I}

  1692 val UNIV_witness = @{thm UNIV_witness}

  1693 val UnE = @{thm UnE}

  1694 val UnI1 = @{thm UnI1}

  1695 val UnI2 = @{thm UnI2}

  1696 val ballE = @{thm ballE}

  1697 val ballI = @{thm ballI}

  1698 val bexCI = @{thm bexCI}

  1699 val bexE = @{thm bexE}

  1700 val bexI = @{thm bexI}

  1701 val bex_triv = @{thm bex_triv}

  1702 val bspec = @{thm bspec}

  1703 val contra_subsetD = @{thm contra_subsetD}

  1704 val distinct_lemma = @{thm distinct_lemma}

  1705 val eq_to_mono = @{thm eq_to_mono}

  1706 val eq_to_mono2 = @{thm eq_to_mono2}

  1707 val equalityCE = @{thm equalityCE}

  1708 val equalityD1 = @{thm equalityD1}

  1709 val equalityD2 = @{thm equalityD2}

  1710 val equalityE = @{thm equalityE}

  1711 val equalityI = @{thm equalityI}

  1712 val imageE = @{thm imageE}

  1713 val imageI = @{thm imageI}

  1714 val image_Un = @{thm image_Un}

  1715 val image_insert = @{thm image_insert}

  1716 val insert_commute = @{thm insert_commute}

  1717 val insert_iff = @{thm insert_iff}

  1718 val mem_Collect_eq = @{thm mem_Collect_eq}

  1719 val rangeE = @{thm rangeE}

  1720 val rangeI = @{thm rangeI}

  1721 val range_eqI = @{thm range_eqI}

  1722 val subsetCE = @{thm subsetCE}

  1723 val subsetD = @{thm subsetD}

  1724 val subsetI = @{thm subsetI}

  1725 val subset_refl = @{thm subset_refl}

  1726 val subset_trans = @{thm subset_trans}

  1727 val vimageD = @{thm vimageD}

  1728 val vimageE = @{thm vimageE}

  1729 val vimageI = @{thm vimageI}

  1730 val vimageI2 = @{thm vimageI2}

  1731 val vimage_Collect = @{thm vimage_Collect}

  1732 val vimage_Int = @{thm vimage_Int}

  1733 val vimage_Un = @{thm vimage_Un}

  1734 *}

  1735

  1736

  1737 subsection {* Complete lattices *}

  1738

  1739 notation

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

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

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

  1743   sup  (infixl "\<squnion>" 65)

  1744

  1745 class complete_lattice = lattice + bot + top +

  1746   fixes Inf :: "'a set \<Rightarrow> 'a" ("\<Sqinter>_" [900] 900)

  1747     and Sup :: "'a set \<Rightarrow> 'a" ("\<Squnion>_" [900] 900)

  1748   assumes Inf_lower: "x \<in> A \<Longrightarrow> \<Sqinter>A \<sqsubseteq> x"

  1749      and Inf_greatest: "(\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x) \<Longrightarrow> z \<sqsubseteq> \<Sqinter>A"

  1750   assumes Sup_upper: "x \<in> A \<Longrightarrow> x \<sqsubseteq> \<Squnion>A"

  1751      and Sup_least: "(\<And>x. x \<in> A \<Longrightarrow> x \<sqsubseteq> z) \<Longrightarrow> \<Squnion>A \<sqsubseteq> z"

  1752 begin

  1753

  1754 lemma Inf_Sup: "\<Sqinter>A = \<Squnion>{b. \<forall>a \<in> A. b \<le> a}"

  1755   by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)

  1756

  1757 lemma Sup_Inf:  "\<Squnion>A = \<Sqinter>{b. \<forall>a \<in> A. a \<le> b}"

  1758   by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)

  1759

  1760 lemma Inf_Univ: "\<Sqinter>UNIV = \<Squnion>{}"

  1761   unfolding Sup_Inf by auto

  1762

  1763 lemma Sup_Univ: "\<Squnion>UNIV = \<Sqinter>{}"

  1764   unfolding Inf_Sup by auto

  1765

  1766 lemma Inf_insert: "\<Sqinter>insert a A = a \<sqinter> \<Sqinter>A"

  1767   by (auto intro: le_infI le_infI1 le_infI2 antisym Inf_greatest Inf_lower)

  1768

  1769 lemma Sup_insert: "\<Squnion>insert a A = a \<squnion> \<Squnion>A"

  1770   by (auto intro: le_supI le_supI1 le_supI2 antisym Sup_least Sup_upper)

  1771

  1772 lemma Inf_singleton [simp]:

  1773   "\<Sqinter>{a} = a"

  1774   by (auto intro: antisym Inf_lower Inf_greatest)

  1775

  1776 lemma Sup_singleton [simp]:

  1777   "\<Squnion>{a} = a"

  1778   by (auto intro: antisym Sup_upper Sup_least)

  1779

  1780 lemma Inf_insert_simp:

  1781   "\<Sqinter>insert a A = (if A = {} then a else a \<sqinter> \<Sqinter>A)"

  1782   by (cases "A = {}") (simp_all, simp add: Inf_insert)

  1783

  1784 lemma Sup_insert_simp:

  1785   "\<Squnion>insert a A = (if A = {} then a else a \<squnion> \<Squnion>A)"

  1786   by (cases "A = {}") (simp_all, simp add: Sup_insert)

  1787

  1788 lemma Inf_binary:

  1789   "\<Sqinter>{a, b} = a \<sqinter> b"

  1790   by (auto simp add: Inf_insert_simp)

  1791

  1792 lemma Sup_binary:

  1793   "\<Squnion>{a, b} = a \<squnion> b"

  1794   by (auto simp add: Sup_insert_simp)

  1795

  1796 lemma bot_def:

  1797   "bot = \<Squnion>{}"

  1798   by (auto intro: antisym Sup_least)

  1799

  1800 lemma top_def:

  1801   "top = \<Sqinter>{}"

  1802   by (auto intro: antisym Inf_greatest)

  1803

  1804 lemma sup_bot [simp]:

  1805   "x \<squnion> bot = x"

  1806   using bot_least [of x] by (simp add: le_iff_sup sup_commute)

  1807

  1808 lemma inf_top [simp]:

  1809   "x \<sqinter> top = x"

  1810   using top_greatest [of x] by (simp add: le_iff_inf inf_commute)

  1811

  1812 definition SUPR :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" where

  1813   "SUPR A f = \<Squnion> (f  A)"

  1814

  1815 definition INFI :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" where

  1816   "INFI A f = \<Sqinter> (f  A)"

  1817

  1818 end

  1819

  1820 syntax

  1821   "_SUP1"     :: "pttrns => 'b => 'b"           ("(3SUP _./ _)" [0, 10] 10)

  1822   "_SUP"      :: "pttrn => 'a set => 'b => 'b"  ("(3SUP _:_./ _)" [0, 10] 10)

  1823   "_INF1"     :: "pttrns => 'b => 'b"           ("(3INF _./ _)" [0, 10] 10)

  1824   "_INF"      :: "pttrn => 'a set => 'b => 'b"  ("(3INF _:_./ _)" [0, 10] 10)

  1825

  1826 translations

  1827   "SUP x y. B"   == "SUP x. SUP y. B"

  1828   "SUP x. B"     == "CONST SUPR CONST UNIV (%x. B)"

  1829   "SUP x. B"     == "SUP x:CONST UNIV. B"

  1830   "SUP x:A. B"   == "CONST SUPR A (%x. B)"

  1831   "INF x y. B"   == "INF x. INF y. B"

  1832   "INF x. B"     == "CONST INFI CONST UNIV (%x. B)"

  1833   "INF x. B"     == "INF x:CONST UNIV. B"

  1834   "INF x:A. B"   == "CONST INFI A (%x. B)"

  1835

  1836 print_translation {* [

  1837 Syntax.preserve_binder_abs2_tr' @{const_syntax SUPR} "_SUP",

  1838 Syntax.preserve_binder_abs2_tr' @{const_syntax INFI} "_INF"

  1839 ] *} -- {* to avoid eta-contraction of body *}

  1840

  1841 context complete_lattice

  1842 begin

  1843

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

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

  1846

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

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

  1849

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

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

  1852

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

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

  1855

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

  1857   by (auto intro: antisym SUP_leI le_SUPI)

  1858

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

  1860   by (auto intro: antisym INF_leI le_INFI)

  1861

  1862 end

  1863

  1864

  1865 subsubsection {* @{typ bool} and @{typ "_ \<Rightarrow> _"} as complete lattice *}

  1866

  1867 instantiation bool :: complete_lattice

  1868 begin

  1869

  1870 definition

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

  1872

  1873 definition

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

  1875

  1876 instance proof

  1877 qed (auto simp add: Inf_bool_def Sup_bool_def le_bool_def)

  1878

  1879 end

  1880

  1881 lemma Inf_empty_bool [simp]:

  1882   "\<Sqinter>{}"

  1883   unfolding Inf_bool_def by auto

  1884

  1885 lemma not_Sup_empty_bool [simp]:

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

  1887   unfolding Sup_bool_def by auto

  1888

  1889 lemma INFI_bool_eq:

  1890   "INFI = Ball"

  1891 proof (rule ext)+

  1892   fix A :: "'a set"

  1893   fix P :: "'a \<Rightarrow> bool"

  1894   show "(INF x:A. P x) \<longleftrightarrow> (\<forall>x \<in> A. P x)"

  1895     by (auto simp add: Ball_def INFI_def Inf_bool_def)

  1896 qed

  1897

  1898 lemma SUPR_bool_eq:

  1899   "SUPR = Bex"

  1900 proof (rule ext)+

  1901   fix A :: "'a set"

  1902   fix P :: "'a \<Rightarrow> bool"

  1903   show "(SUP x:A. P x) \<longleftrightarrow> (\<exists>x \<in> A. P x)"

  1904     by (auto simp add: Bex_def SUPR_def Sup_bool_def)

  1905 qed

  1906

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

  1908 begin

  1909

  1910 definition

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

  1912

  1913 definition

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

  1915

  1916 instance proof

  1917 qed (auto simp add: Inf_fun_def Sup_fun_def le_fun_def

  1918   intro: Inf_lower Sup_upper Inf_greatest Sup_least)

  1919

  1920 end

  1921

  1922 lemma Inf_empty_fun:

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

  1924   by (simp add: Inf_fun_def)

  1925

  1926 lemma Sup_empty_fun:

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

  1928   by (simp add: Sup_fun_def)

  1929

  1930

  1931 subsubsection {* Union *}

  1932

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

  1934   Sup_set_eq [symmetric]: "Union S = \<Squnion>S"

  1935

  1936 notation (xsymbols)

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

  1938

  1939 lemma Union_eq:

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

  1941 proof (rule set_ext)

  1942   fix x

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

  1944     by auto

  1945   then show "x \<in> \<Union>A \<longleftrightarrow> x \<in> {x. \<exists>B\<in>A. x \<in> B}"

  1946     by (simp add: Sup_set_eq [symmetric] Sup_fun_def Sup_bool_def) (simp add: mem_def)

  1947 qed

  1948

  1949 lemma Union_iff [simp, noatp]:

  1950   "A \<in> \<Union>C \<longleftrightarrow> (\<exists>X\<in>C. A\<in>X)"

  1951   by (unfold Union_eq) blast

  1952

  1953 lemma UnionI [intro]:

  1954   "X \<in> C \<Longrightarrow> A \<in> X \<Longrightarrow> A \<in> \<Union>C"

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

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

  1957   by auto

  1958

  1959 lemma UnionE [elim!]:

  1960   "A \<in> \<Union>C \<Longrightarrow> (\<And>X. A\<in>X \<Longrightarrow> X\<in>C \<Longrightarrow> R) \<Longrightarrow> R"

  1961   by auto

  1962

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

  1964   by (iprover intro: subsetI UnionI)

  1965

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

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

  1968

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

  1970   by blast

  1971

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

  1973   by blast

  1974

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

  1976   by blast

  1977

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

  1979   by blast

  1980

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

  1982   by blast

  1983

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

  1985   by blast

  1986

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

  1988   by blast

  1989

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

  1991   by blast

  1992

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

  1994   by blast

  1995

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

  1997   by blast

  1998

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

  2000   by blast

  2001

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

  2003   by blast

  2004

  2005

  2006 subsubsection {* Unions of families *}

  2007

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

  2009   SUPR_set_eq [symmetric]: "UNION S f = (SUP x:S. f x)"

  2010

  2011 syntax

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

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

  2014

  2015 syntax (xsymbols)

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

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

  2018

  2019 syntax (latex output)

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

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

  2022

  2023 translations

  2024   "UN x y. B"   == "UN x. UN y. B"

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

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

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

  2028

  2029 text {*

  2030   Note the difference between ordinary xsymbol syntax of indexed

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

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

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

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

  2035   subscripts in Proof General.

  2036 *}

  2037

  2038 print_translation {* [

  2039 Syntax.preserve_binder_abs2_tr' @{const_syntax UNION} "@UNION"

  2040 ] *} -- {* to avoid eta-contraction of body *}

  2041

  2042 lemma UNION_eq_Union_image:

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

  2044   by (simp add: SUPR_def SUPR_set_eq [symmetric] Sup_set_eq)

  2045

  2046 lemma Union_def:

  2047   "\<Union>S = (\<Union>x\<in>S. x)"

  2048   by (simp add: UNION_eq_Union_image image_def)

  2049

  2050 lemma UNION_def [noatp]:

  2051   "(\<Union>x\<in>A. B x) = {y. \<exists>x\<in>A. y \<in> B x}"

  2052   by (auto simp add: UNION_eq_Union_image Union_eq)

  2053

  2054 lemma Union_image_eq [simp]:

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

  2056   by (rule sym) (fact UNION_eq_Union_image)

  2057

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

  2059   by (unfold UNION_def) blast

  2060

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

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

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

  2064   by auto

  2065

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

  2067   by (unfold UNION_def) blast

  2068

  2069 lemma UN_cong [cong]:

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

  2071   by (simp add: UNION_def)

  2072

  2073 lemma strong_UN_cong:

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

  2075   by (simp add: UNION_def simp_implies_def)

  2076

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

  2078   by blast

  2079

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

  2081   by blast

  2082

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

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

  2085

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

  2087   by blast

  2088

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

  2090   by blast

  2091

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

  2093   by blast

  2094

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

  2096   by blast

  2097

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

  2099   by blast

  2100

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

  2102   by auto

  2103

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

  2105   by blast

  2106

  2107 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)"

  2108   by blast

  2109

  2110 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)"

  2111   by blast

  2112

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

  2114   by blast

  2115

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

  2117   by blast

  2118

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

  2120   by auto

  2121

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

  2123   by blast

  2124

  2125 lemma UNION_empty_conv[simp]:

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

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

  2128 by blast+

  2129

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

  2131   by blast

  2132

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

  2134   by blast

  2135

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

  2137   by blast

  2138

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

  2140   by (auto simp add: split_if_mem2)

  2141

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

  2143   by (auto intro: bool_contrapos)

  2144

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

  2146   by blast

  2147

  2148 lemma UN_mono:

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

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

  2151   by (blast dest: subsetD)

  2152

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

  2154   by blast

  2155

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

  2157   by blast

  2158

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

  2160   -- {* NOT suitable for rewriting *}

  2161   by blast

  2162

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

  2164 by blast

  2165

  2166

  2167 subsubsection {* Inter *}

  2168

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

  2170   Inf_set_eq [symmetric]: "Inter S = \<Sqinter>S"

  2171

  2172 notation (xsymbols)

  2173   Inter  ("\<Inter>_" [90] 90)

  2174

  2175 lemma Inter_eq [code del]:

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

  2177 proof (rule set_ext)

  2178   fix x

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

  2180     by auto

  2181   then show "x \<in> \<Inter>A \<longleftrightarrow> x \<in> {x. \<forall>B \<in> A. x \<in> B}"

  2182     by (simp add: Inf_fun_def Inf_bool_def Inf_set_eq [symmetric]) (simp add: mem_def)

  2183 qed

  2184

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

  2186   by (unfold Inter_eq) blast

  2187

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

  2189   by (simp add: Inter_eq)

  2190

  2191 text {*

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

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

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

  2195 *}

  2196

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

  2198   by auto

  2199

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

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

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

  2203   by (unfold Inter_eq) blast

  2204

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

  2206   by blast

  2207

  2208 lemma Inter_subset:

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

  2210   by blast

  2211

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

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

  2214

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

  2216   by blast

  2217

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

  2219   by blast

  2220

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

  2222   by blast

  2223

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

  2225   by blast

  2226

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

  2228   by blast

  2229

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

  2231   by blast

  2232

  2233 lemma Inter_UNIV_conv [simp,noatp]:

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

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

  2236   by blast+

  2237

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

  2239   by blast

  2240

  2241

  2242 subsubsection {* Intersections of families *}

  2243

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

  2245   INFI_set_eq [symmetric]: "INTER S f = (INF x:S. f x)"

  2246

  2247 syntax

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

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

  2250

  2251 syntax (xsymbols)

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

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

  2254

  2255 syntax (latex output)

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

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

  2258

  2259 translations

  2260   "INT x y. B"  == "INT x. INT y. B"

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

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

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

  2264

  2265 print_translation {* [

  2266 Syntax.preserve_binder_abs2_tr' @{const_syntax INTER} "@INTER"

  2267 ] *} -- {* to avoid eta-contraction of body *}

  2268

  2269 lemma INTER_eq_Inter_image:

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

  2271   by (simp add: INFI_def INFI_set_eq [symmetric] Inf_set_eq)

  2272

  2273 lemma Inter_def:

  2274   "\<Inter>S = (\<Inter>x\<in>S. x)"

  2275   by (simp add: INTER_eq_Inter_image image_def)

  2276

  2277 lemma INTER_def:

  2278   "(\<Inter>x\<in>A. B x) = {y. \<forall>x\<in>A. y \<in> B x}"

  2279   by (auto simp add: INTER_eq_Inter_image Inter_eq)

  2280

  2281 lemma Inter_image_eq [simp]:

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

  2283   by (rule sym) (fact INTER_eq_Inter_image)

  2284

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

  2286   by (unfold INTER_def) blast

  2287

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

  2289   by (unfold INTER_def) blast

  2290

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

  2292   by auto

  2293

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

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

  2296   by (unfold INTER_def) blast

  2297

  2298 lemma INT_cong [cong]:

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

  2300   by (simp add: INTER_def)

  2301

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

  2303   by blast

  2304

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

  2306   by blast

  2307

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

  2309   by blast

  2310

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

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

  2313

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

  2315   by blast

  2316

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

  2318   by blast

  2319

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

  2321   by blast

  2322

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

  2324   by blast

  2325

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

  2327   by blast

  2328

  2329 lemma INT_insert_distrib:

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

  2331   by blast

  2332

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

  2334   by auto

  2335

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

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

  2338   by blast

  2339

  2340 lemma INTER_UNIV_conv[simp]:

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

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

  2343 by blast+

  2344

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

  2346   by (auto intro: bool_induct)

  2347

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

  2349   by blast

  2350

  2351 lemma INT_anti_mono:

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

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

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

  2355   by (blast dest: subsetD)

  2356

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

  2358   by blast

  2359

  2360

  2361 subsubsection {* Distributive laws *}

  2362

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

  2364   by blast

  2365

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

  2367   by blast

  2368

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

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

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

  2372   by blast

  2373

  2374 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)"

  2375   -- {* Equivalent version *}

  2376   by blast

  2377

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

  2379   by blast

  2380

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

  2382   by blast

  2383

  2384 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)"

  2385   -- {* Equivalent version *}

  2386   by blast

  2387

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

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

  2390   by blast

  2391

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

  2393   by blast

  2394

  2395 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)"

  2396   by blast

  2397

  2398 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)"

  2399   by blast

  2400

  2401

  2402 subsubsection {* Complement *}

  2403

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

  2405   by blast

  2406

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

  2408   by blast

  2409

  2410

  2411 subsubsection {* Miniscoping and maxiscoping *}

  2412

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

  2414            and Intersections. *}

  2415

  2416 lemma UN_simps [simp]:

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

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

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

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

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

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

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

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

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

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

  2427   by auto

  2428

  2429 lemma INT_simps [simp]:

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

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

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

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

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

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

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

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

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

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

  2440   by auto

  2441

  2442 lemma ball_simps [simp,noatp]:

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

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

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

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

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

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

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

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

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

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

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

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

  2455   by auto

  2456

  2457 lemma bex_simps [simp,noatp]:

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

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

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

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

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

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

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

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

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

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

  2468   by auto

  2469

  2470 lemma ball_conj_distrib:

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

  2472   by blast

  2473

  2474 lemma bex_disj_distrib:

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

  2476   by blast

  2477

  2478

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

  2480

  2481 lemma UN_extend_simps:

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

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

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

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

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

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

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

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

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

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

  2492   by auto

  2493

  2494 lemma INT_extend_simps:

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

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

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

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

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

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

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

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

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

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

  2505   by auto

  2506

  2507

  2508 no_notation

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

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

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

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

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

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

  2515

  2516 lemmas mem_simps =

  2517   insert_iff empty_iff Un_iff Int_iff Compl_iff Diff_iff

  2518   mem_Collect_eq UN_iff Union_iff INT_iff Inter_iff

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

  2520

  2521 end