src/HOL/Complete_Lattice.thy
author haftmann
Thu Sep 24 18:29:28 2009 +0200 (2009-09-24)
changeset 32678 de1f7d4da21a
parent 32642 026e7c6a6d08
child 32879 7f5ce7af45fd
permissions -rw-r--r--
added dual for complete lattice
     1 (*  Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel; Florian Haftmann, TU Muenchen *)
     2 
     3 header {* Complete lattices, with special focus on sets *}
     4 
     5 theory Complete_Lattice
     6 imports Set
     7 begin
     8 
     9 notation
    10   less_eq  (infix "\<sqsubseteq>" 50) and
    11   less (infix "\<sqsubset>" 50) and
    12   inf  (infixl "\<sqinter>" 70) and
    13   sup  (infixl "\<squnion>" 65) and
    14   top ("\<top>") and
    15   bot ("\<bottom>")
    16 
    17 
    18 subsection {* Abstract complete lattices *}
    19 
    20 class complete_lattice = lattice + bot + top +
    21   fixes Inf :: "'a set \<Rightarrow> 'a" ("\<Sqinter>_" [900] 900)
    22     and Sup :: "'a set \<Rightarrow> 'a" ("\<Squnion>_" [900] 900)
    23   assumes Inf_lower: "x \<in> A \<Longrightarrow> \<Sqinter>A \<sqsubseteq> x"
    24      and Inf_greatest: "(\<And>x. x \<in> A \<Longrightarrow> z \<sqsubseteq> x) \<Longrightarrow> z \<sqsubseteq> \<Sqinter>A"
    25   assumes Sup_upper: "x \<in> A \<Longrightarrow> x \<sqsubseteq> \<Squnion>A"
    26      and Sup_least: "(\<And>x. x \<in> A \<Longrightarrow> x \<sqsubseteq> z) \<Longrightarrow> \<Squnion>A \<sqsubseteq> z"
    27 begin
    28 
    29 term complete_lattice
    30 
    31 lemma dual_complete_lattice:
    32   "complete_lattice (op \<ge>) (op >) (op \<squnion>) (op \<sqinter>) \<top> \<bottom> Sup Inf"
    33   by (auto intro!: complete_lattice.intro dual_lattice
    34     bot.intro top.intro dual_preorder, unfold_locales)
    35       (fact bot_least top_greatest
    36         Sup_upper Sup_least Inf_lower Inf_greatest)+
    37 
    38 lemma Inf_Sup: "\<Sqinter>A = \<Squnion>{b. \<forall>a \<in> A. b \<le> a}"
    39   by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)
    40 
    41 lemma Sup_Inf:  "\<Squnion>A = \<Sqinter>{b. \<forall>a \<in> A. a \<le> b}"
    42   by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)
    43 
    44 lemma Inf_Univ: "\<Sqinter>UNIV = \<Squnion>{}"
    45   unfolding Sup_Inf by auto
    46 
    47 lemma Sup_Univ: "\<Squnion>UNIV = \<Sqinter>{}"
    48   unfolding Inf_Sup by auto
    49 
    50 lemma Inf_insert: "\<Sqinter>insert a A = a \<sqinter> \<Sqinter>A"
    51   by (auto intro: le_infI le_infI1 le_infI2 antisym Inf_greatest Inf_lower)
    52 
    53 lemma Sup_insert: "\<Squnion>insert a A = a \<squnion> \<Squnion>A"
    54   by (auto intro: le_supI le_supI1 le_supI2 antisym Sup_least Sup_upper)
    55 
    56 lemma Inf_singleton [simp]:
    57   "\<Sqinter>{a} = a"
    58   by (auto intro: antisym Inf_lower Inf_greatest)
    59 
    60 lemma Sup_singleton [simp]:
    61   "\<Squnion>{a} = a"
    62   by (auto intro: antisym Sup_upper Sup_least)
    63 
    64 lemma Inf_insert_simp:
    65   "\<Sqinter>insert a A = (if A = {} then a else a \<sqinter> \<Sqinter>A)"
    66   by (cases "A = {}") (simp_all, simp add: Inf_insert)
    67 
    68 lemma Sup_insert_simp:
    69   "\<Squnion>insert a A = (if A = {} then a else a \<squnion> \<Squnion>A)"
    70   by (cases "A = {}") (simp_all, simp add: Sup_insert)
    71 
    72 lemma Inf_binary:
    73   "\<Sqinter>{a, b} = a \<sqinter> b"
    74   by (auto simp add: Inf_insert_simp)
    75 
    76 lemma Sup_binary:
    77   "\<Squnion>{a, b} = a \<squnion> b"
    78   by (auto simp add: Sup_insert_simp)
    79 
    80 lemma bot_def:
    81   "bot = \<Squnion>{}"
    82   by (auto intro: antisym Sup_least)
    83 
    84 lemma top_def:
    85   "top = \<Sqinter>{}"
    86   by (auto intro: antisym Inf_greatest)
    87 
    88 lemma sup_bot [simp]:
    89   "x \<squnion> bot = x"
    90   using bot_least [of x] by (simp add: sup_commute sup_absorb2)
    91 
    92 lemma inf_top [simp]:
    93   "x \<sqinter> top = x"
    94   using top_greatest [of x] by (simp add: inf_commute inf_absorb2)
    95 
    96 definition SUPR :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" where
    97   "SUPR A f = \<Squnion> (f ` A)"
    98 
    99 definition INFI :: "'b set \<Rightarrow> ('b \<Rightarrow> 'a) \<Rightarrow> 'a" where
   100   "INFI A f = \<Sqinter> (f ` A)"
   101 
   102 end
   103 
   104 syntax
   105   "_SUP1"     :: "pttrns => 'b => 'b"           ("(3SUP _./ _)" [0, 10] 10)
   106   "_SUP"      :: "pttrn => 'a set => 'b => 'b"  ("(3SUP _:_./ _)" [0, 10] 10)
   107   "_INF1"     :: "pttrns => 'b => 'b"           ("(3INF _./ _)" [0, 10] 10)
   108   "_INF"      :: "pttrn => 'a set => 'b => 'b"  ("(3INF _:_./ _)" [0, 10] 10)
   109 
   110 translations
   111   "SUP x y. B"   == "SUP x. SUP y. B"
   112   "SUP x. B"     == "CONST SUPR CONST UNIV (%x. B)"
   113   "SUP x. B"     == "SUP x:CONST UNIV. B"
   114   "SUP x:A. B"   == "CONST SUPR A (%x. B)"
   115   "INF x y. B"   == "INF x. INF y. B"
   116   "INF x. B"     == "CONST INFI CONST UNIV (%x. B)"
   117   "INF x. B"     == "INF x:CONST UNIV. B"
   118   "INF x:A. B"   == "CONST INFI A (%x. B)"
   119 
   120 print_translation {* [
   121 Syntax.preserve_binder_abs2_tr' @{const_syntax SUPR} "_SUP",
   122 Syntax.preserve_binder_abs2_tr' @{const_syntax INFI} "_INF"
   123 ] *} -- {* to avoid eta-contraction of body *}
   124 
   125 context complete_lattice
   126 begin
   127 
   128 lemma le_SUPI: "i : A \<Longrightarrow> M i \<le> (SUP i:A. M i)"
   129   by (auto simp add: SUPR_def intro: Sup_upper)
   130 
   131 lemma SUP_leI: "(\<And>i. i : A \<Longrightarrow> M i \<le> u) \<Longrightarrow> (SUP i:A. M i) \<le> u"
   132   by (auto simp add: SUPR_def intro: Sup_least)
   133 
   134 lemma INF_leI: "i : A \<Longrightarrow> (INF i:A. M i) \<le> M i"
   135   by (auto simp add: INFI_def intro: Inf_lower)
   136 
   137 lemma le_INFI: "(\<And>i. i : A \<Longrightarrow> u \<le> M i) \<Longrightarrow> u \<le> (INF i:A. M i)"
   138   by (auto simp add: INFI_def intro: Inf_greatest)
   139 
   140 lemma SUP_const[simp]: "A \<noteq> {} \<Longrightarrow> (SUP i:A. M) = M"
   141   by (auto intro: antisym SUP_leI le_SUPI)
   142 
   143 lemma INF_const[simp]: "A \<noteq> {} \<Longrightarrow> (INF i:A. M) = M"
   144   by (auto intro: antisym INF_leI le_INFI)
   145 
   146 end
   147 
   148 
   149 subsection {* @{typ bool} and @{typ "_ \<Rightarrow> _"} as complete lattice *}
   150 
   151 instantiation bool :: complete_lattice
   152 begin
   153 
   154 definition
   155   Inf_bool_def: "\<Sqinter>A \<longleftrightarrow> (\<forall>x\<in>A. x)"
   156 
   157 definition
   158   Sup_bool_def: "\<Squnion>A \<longleftrightarrow> (\<exists>x\<in>A. x)"
   159 
   160 instance proof
   161 qed (auto simp add: Inf_bool_def Sup_bool_def le_bool_def)
   162 
   163 end
   164 
   165 lemma Inf_empty_bool [simp]:
   166   "\<Sqinter>{}"
   167   unfolding Inf_bool_def by auto
   168 
   169 lemma not_Sup_empty_bool [simp]:
   170   "\<not> \<Squnion>{}"
   171   unfolding Sup_bool_def by auto
   172 
   173 lemma INFI_bool_eq:
   174   "INFI = Ball"
   175 proof (rule ext)+
   176   fix A :: "'a set"
   177   fix P :: "'a \<Rightarrow> bool"
   178   show "(INF x:A. P x) \<longleftrightarrow> (\<forall>x \<in> A. P x)"
   179     by (auto simp add: Ball_def INFI_def Inf_bool_def)
   180 qed
   181 
   182 lemma SUPR_bool_eq:
   183   "SUPR = Bex"
   184 proof (rule ext)+
   185   fix A :: "'a set"
   186   fix P :: "'a \<Rightarrow> bool"
   187   show "(SUP x:A. P x) \<longleftrightarrow> (\<exists>x \<in> A. P x)"
   188     by (auto simp add: Bex_def SUPR_def Sup_bool_def)
   189 qed
   190 
   191 instantiation "fun" :: (type, complete_lattice) complete_lattice
   192 begin
   193 
   194 definition
   195   Inf_fun_def [code del]: "\<Sqinter>A = (\<lambda>x. \<Sqinter>{y. \<exists>f\<in>A. y = f x})"
   196 
   197 definition
   198   Sup_fun_def [code del]: "\<Squnion>A = (\<lambda>x. \<Squnion>{y. \<exists>f\<in>A. y = f x})"
   199 
   200 instance proof
   201 qed (auto simp add: Inf_fun_def Sup_fun_def le_fun_def
   202   intro: Inf_lower Sup_upper Inf_greatest Sup_least)
   203 
   204 end
   205 
   206 lemma Inf_empty_fun:
   207   "\<Sqinter>{} = (\<lambda>_. \<Sqinter>{})"
   208   by (simp add: Inf_fun_def)
   209 
   210 lemma Sup_empty_fun:
   211   "\<Squnion>{} = (\<lambda>_. \<Squnion>{})"
   212   by (simp add: Sup_fun_def)
   213 
   214 
   215 subsection {* Union *}
   216 
   217 abbreviation Union :: "'a set set \<Rightarrow> 'a set" where
   218   "Union S \<equiv> \<Squnion>S"
   219 
   220 notation (xsymbols)
   221   Union  ("\<Union>_" [90] 90)
   222 
   223 lemma Union_eq:
   224   "\<Union>A = {x. \<exists>B \<in> A. x \<in> B}"
   225 proof (rule set_ext)
   226   fix x
   227   have "(\<exists>Q\<in>{P. \<exists>B\<in>A. P \<longleftrightarrow> x \<in> B}. Q) \<longleftrightarrow> (\<exists>B\<in>A. x \<in> B)"
   228     by auto
   229   then show "x \<in> \<Union>A \<longleftrightarrow> x \<in> {x. \<exists>B\<in>A. x \<in> B}"
   230     by (simp add: Sup_fun_def Sup_bool_def) (simp add: mem_def)
   231 qed
   232 
   233 lemma Union_iff [simp, noatp]:
   234   "A \<in> \<Union>C \<longleftrightarrow> (\<exists>X\<in>C. A\<in>X)"
   235   by (unfold Union_eq) blast
   236 
   237 lemma UnionI [intro]:
   238   "X \<in> C \<Longrightarrow> A \<in> X \<Longrightarrow> A \<in> \<Union>C"
   239   -- {* The order of the premises presupposes that @{term C} is rigid;
   240     @{term A} may be flexible. *}
   241   by auto
   242 
   243 lemma UnionE [elim!]:
   244   "A \<in> \<Union>C \<Longrightarrow> (\<And>X. A\<in>X \<Longrightarrow> X\<in>C \<Longrightarrow> R) \<Longrightarrow> R"
   245   by auto
   246 
   247 lemma Union_upper: "B \<in> A ==> B \<subseteq> Union A"
   248   by (iprover intro: subsetI UnionI)
   249 
   250 lemma Union_least: "(!!X. X \<in> A ==> X \<subseteq> C) ==> Union A \<subseteq> C"
   251   by (iprover intro: subsetI elim: UnionE dest: subsetD)
   252 
   253 lemma Un_eq_Union: "A \<union> B = \<Union>{A, B}"
   254   by blast
   255 
   256 lemma Union_empty [simp]: "Union({}) = {}"
   257   by blast
   258 
   259 lemma Union_UNIV [simp]: "Union UNIV = UNIV"
   260   by blast
   261 
   262 lemma Union_insert [simp]: "Union (insert a B) = a \<union> \<Union>B"
   263   by blast
   264 
   265 lemma Union_Un_distrib [simp]: "\<Union>(A Un B) = \<Union>A \<union> \<Union>B"
   266   by blast
   267 
   268 lemma Union_Int_subset: "\<Union>(A \<inter> B) \<subseteq> \<Union>A \<inter> \<Union>B"
   269   by blast
   270 
   271 lemma Union_empty_conv [simp,noatp]: "(\<Union>A = {}) = (\<forall>x\<in>A. x = {})"
   272   by blast
   273 
   274 lemma empty_Union_conv [simp,noatp]: "({} = \<Union>A) = (\<forall>x\<in>A. x = {})"
   275   by blast
   276 
   277 lemma Union_disjoint: "(\<Union>C \<inter> A = {}) = (\<forall>B\<in>C. B \<inter> A = {})"
   278   by blast
   279 
   280 lemma subset_Pow_Union: "A \<subseteq> Pow (\<Union>A)"
   281   by blast
   282 
   283 lemma Union_Pow_eq [simp]: "\<Union>(Pow A) = A"
   284   by blast
   285 
   286 lemma Union_mono: "A \<subseteq> B ==> \<Union>A \<subseteq> \<Union>B"
   287   by blast
   288 
   289 
   290 subsection {* Unions of families *}
   291 
   292 abbreviation UNION :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where
   293   "UNION \<equiv> SUPR"
   294 
   295 syntax
   296   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3UN _./ _)" [0, 10] 10)
   297   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3UN _:_./ _)" [0, 10] 10)
   298 
   299 syntax (xsymbols)
   300   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>_./ _)" [0, 10] 10)
   301   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>_\<in>_./ _)" [0, 10] 10)
   302 
   303 syntax (latex output)
   304   "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>(00\<^bsub>_\<^esub>)/ _)" [0, 10] 10)
   305   "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>(00\<^bsub>_\<in>_\<^esub>)/ _)" [0, 10] 10)
   306 
   307 translations
   308   "UN x y. B"   == "UN x. UN y. B"
   309   "UN x. B"     == "CONST UNION CONST UNIV (%x. B)"
   310   "UN x. B"     == "UN x:CONST UNIV. B"
   311   "UN x:A. B"   == "CONST UNION A (%x. B)"
   312 
   313 text {*
   314   Note the difference between ordinary xsymbol syntax of indexed
   315   unions and intersections (e.g.\ @{text"\<Union>a\<^isub>1\<in>A\<^isub>1. B"})
   316   and their \LaTeX\ rendition: @{term"\<Union>a\<^isub>1\<in>A\<^isub>1. B"}. The
   317   former does not make the index expression a subscript of the
   318   union/intersection symbol because this leads to problems with nested
   319   subscripts in Proof General.
   320 *}
   321 
   322 print_translation {* [
   323 Syntax.preserve_binder_abs2_tr' @{const_syntax UNION} "@UNION"
   324 ] *} -- {* to avoid eta-contraction of body *}
   325 
   326 lemma UNION_eq_Union_image:
   327   "(\<Union>x\<in>A. B x) = \<Union>(B`A)"
   328   by (fact SUPR_def)
   329 
   330 lemma Union_def:
   331   "\<Union>S = (\<Union>x\<in>S. x)"
   332   by (simp add: UNION_eq_Union_image image_def)
   333 
   334 lemma UNION_def [noatp]:
   335   "(\<Union>x\<in>A. B x) = {y. \<exists>x\<in>A. y \<in> B x}"
   336   by (auto simp add: UNION_eq_Union_image Union_eq)
   337   
   338 lemma Union_image_eq [simp]:
   339   "\<Union>(B`A) = (\<Union>x\<in>A. B x)"
   340   by (rule sym) (fact UNION_eq_Union_image)
   341   
   342 lemma UN_iff [simp]: "(b: (UN x:A. B x)) = (EX x:A. b: B x)"
   343   by (unfold UNION_def) blast
   344 
   345 lemma UN_I [intro]: "a:A ==> b: B a ==> b: (UN x:A. B x)"
   346   -- {* The order of the premises presupposes that @{term A} is rigid;
   347     @{term b} may be flexible. *}
   348   by auto
   349 
   350 lemma UN_E [elim!]: "b : (UN x:A. B x) ==> (!!x. x:A ==> b: B x ==> R) ==> R"
   351   by (unfold UNION_def) blast
   352 
   353 lemma UN_cong [cong]:
   354     "A = B ==> (!!x. x:B ==> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"
   355   by (simp add: UNION_def)
   356 
   357 lemma strong_UN_cong:
   358     "A = B ==> (!!x. x:B =simp=> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"
   359   by (simp add: UNION_def simp_implies_def)
   360 
   361 lemma image_eq_UN: "f`A = (UN x:A. {f x})"
   362   by blast
   363 
   364 lemma UN_upper: "a \<in> A ==> B a \<subseteq> (\<Union>x\<in>A. B x)"
   365   by (fact le_SUPI)
   366 
   367 lemma UN_least: "(!!x. x \<in> A ==> B x \<subseteq> C) ==> (\<Union>x\<in>A. B x) \<subseteq> C"
   368   by (iprover intro: subsetI elim: UN_E dest: subsetD)
   369 
   370 lemma Collect_bex_eq [noatp]: "{x. \<exists>y\<in>A. P x y} = (\<Union>y\<in>A. {x. P x y})"
   371   by blast
   372 
   373 lemma UN_insert_distrib: "u \<in> A ==> (\<Union>x\<in>A. insert a (B x)) = insert a (\<Union>x\<in>A. B x)"
   374   by blast
   375 
   376 lemma UN_empty [simp,noatp]: "(\<Union>x\<in>{}. B x) = {}"
   377   by blast
   378 
   379 lemma UN_empty2 [simp]: "(\<Union>x\<in>A. {}) = {}"
   380   by blast
   381 
   382 lemma UN_singleton [simp]: "(\<Union>x\<in>A. {x}) = A"
   383   by blast
   384 
   385 lemma UN_absorb: "k \<in> I ==> A k \<union> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. A i)"
   386   by auto
   387 
   388 lemma UN_insert [simp]: "(\<Union>x\<in>insert a A. B x) = B a \<union> UNION A B"
   389   by blast
   390 
   391 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)"
   392   by blast
   393 
   394 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)"
   395   by blast
   396 
   397 lemma UN_subset_iff: "((\<Union>i\<in>I. A i) \<subseteq> B) = (\<forall>i\<in>I. A i \<subseteq> B)"
   398   by blast
   399 
   400 lemma image_Union: "f ` \<Union>S = (\<Union>x\<in>S. f ` x)"
   401   by blast
   402 
   403 lemma UN_constant [simp]: "(\<Union>y\<in>A. c) = (if A = {} then {} else c)"
   404   by auto
   405 
   406 lemma UN_eq: "(\<Union>x\<in>A. B x) = \<Union>({Y. \<exists>x\<in>A. Y = B x})"
   407   by blast
   408 
   409 lemma UNION_empty_conv[simp]:
   410   "({} = (UN x:A. B x)) = (\<forall>x\<in>A. B x = {})"
   411   "((UN x:A. B x) = {}) = (\<forall>x\<in>A. B x = {})"
   412 by blast+
   413 
   414 lemma Collect_ex_eq [noatp]: "{x. \<exists>y. P x y} = (\<Union>y. {x. P x y})"
   415   by blast
   416 
   417 lemma ball_UN: "(\<forall>z \<in> UNION A B. P z) = (\<forall>x\<in>A. \<forall>z \<in> B x. P z)"
   418   by blast
   419 
   420 lemma bex_UN: "(\<exists>z \<in> UNION A B. P z) = (\<exists>x\<in>A. \<exists>z\<in>B x. P z)"
   421   by blast
   422 
   423 lemma Un_eq_UN: "A \<union> B = (\<Union>b. if b then A else B)"
   424   by (auto simp add: split_if_mem2)
   425 
   426 lemma UN_bool_eq: "(\<Union>b::bool. A b) = (A True \<union> A False)"
   427   by (auto intro: bool_contrapos)
   428 
   429 lemma UN_Pow_subset: "(\<Union>x\<in>A. Pow (B x)) \<subseteq> Pow (\<Union>x\<in>A. B x)"
   430   by blast
   431 
   432 lemma UN_mono:
   433   "A \<subseteq> B ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>
   434     (\<Union>x\<in>A. f x) \<subseteq> (\<Union>x\<in>B. g x)"
   435   by (blast dest: subsetD)
   436 
   437 lemma vimage_Union: "f -` (Union A) = (UN X:A. f -` X)"
   438   by blast
   439 
   440 lemma vimage_UN: "f-`(UN x:A. B x) = (UN x:A. f -` B x)"
   441   by blast
   442 
   443 lemma vimage_eq_UN: "f-`B = (UN y: B. f-`{y})"
   444   -- {* NOT suitable for rewriting *}
   445   by blast
   446 
   447 lemma image_UN: "(f ` (UNION A B)) = (UN x:A.(f ` (B x)))"
   448 by blast
   449 
   450 
   451 subsection {* Inter *}
   452 
   453 abbreviation Inter :: "'a set set \<Rightarrow> 'a set" where
   454   "Inter S \<equiv> \<Sqinter>S"
   455   
   456 notation (xsymbols)
   457   Inter  ("\<Inter>_" [90] 90)
   458 
   459 lemma Inter_eq [code del]:
   460   "\<Inter>A = {x. \<forall>B \<in> A. x \<in> B}"
   461 proof (rule set_ext)
   462   fix x
   463   have "(\<forall>Q\<in>{P. \<exists>B\<in>A. P \<longleftrightarrow> x \<in> B}. Q) \<longleftrightarrow> (\<forall>B\<in>A. x \<in> B)"
   464     by auto
   465   then show "x \<in> \<Inter>A \<longleftrightarrow> x \<in> {x. \<forall>B \<in> A. x \<in> B}"
   466     by (simp add: Inf_fun_def Inf_bool_def) (simp add: mem_def)
   467 qed
   468 
   469 lemma Inter_iff [simp,noatp]: "(A : Inter C) = (ALL X:C. A:X)"
   470   by (unfold Inter_eq) blast
   471 
   472 lemma InterI [intro!]: "(!!X. X:C ==> A:X) ==> A : Inter C"
   473   by (simp add: Inter_eq)
   474 
   475 text {*
   476   \medskip A ``destruct'' rule -- every @{term X} in @{term C}
   477   contains @{term A} as an element, but @{prop "A:X"} can hold when
   478   @{prop "X:C"} does not!  This rule is analogous to @{text spec}.
   479 *}
   480 
   481 lemma InterD [elim]: "A : Inter C ==> X:C ==> A:X"
   482   by auto
   483 
   484 lemma InterE [elim]: "A : Inter C ==> (X~:C ==> R) ==> (A:X ==> R) ==> R"
   485   -- {* ``Classical'' elimination rule -- does not require proving
   486     @{prop "X:C"}. *}
   487   by (unfold Inter_eq) blast
   488 
   489 lemma Inter_lower: "B \<in> A ==> Inter A \<subseteq> B"
   490   by blast
   491 
   492 lemma Inter_subset:
   493   "[| !!X. X \<in> A ==> X \<subseteq> B; A ~= {} |] ==> \<Inter>A \<subseteq> B"
   494   by blast
   495 
   496 lemma Inter_greatest: "(!!X. X \<in> A ==> C \<subseteq> X) ==> C \<subseteq> Inter A"
   497   by (iprover intro: InterI subsetI dest: subsetD)
   498 
   499 lemma Int_eq_Inter: "A \<inter> B = \<Inter>{A, B}"
   500   by blast
   501 
   502 lemma Inter_empty [simp]: "\<Inter>{} = UNIV"
   503   by blast
   504 
   505 lemma Inter_UNIV [simp]: "\<Inter>UNIV = {}"
   506   by blast
   507 
   508 lemma Inter_insert [simp]: "\<Inter>(insert a B) = a \<inter> \<Inter>B"
   509   by blast
   510 
   511 lemma Inter_Un_subset: "\<Inter>A \<union> \<Inter>B \<subseteq> \<Inter>(A \<inter> B)"
   512   by blast
   513 
   514 lemma Inter_Un_distrib: "\<Inter>(A \<union> B) = \<Inter>A \<inter> \<Inter>B"
   515   by blast
   516 
   517 lemma Inter_UNIV_conv [simp,noatp]:
   518   "(\<Inter>A = UNIV) = (\<forall>x\<in>A. x = UNIV)"
   519   "(UNIV = \<Inter>A) = (\<forall>x\<in>A. x = UNIV)"
   520   by blast+
   521 
   522 lemma Inter_anti_mono: "B \<subseteq> A ==> \<Inter>A \<subseteq> \<Inter>B"
   523   by blast
   524 
   525 
   526 subsection {* Intersections of families *}
   527 
   528 abbreviation INTER :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where
   529   "INTER \<equiv> INFI"
   530 
   531 syntax
   532   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3INT _./ _)" [0, 10] 10)
   533   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3INT _:_./ _)" [0, 10] 10)
   534 
   535 syntax (xsymbols)
   536   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>_./ _)" [0, 10] 10)
   537   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>_\<in>_./ _)" [0, 10] 10)
   538 
   539 syntax (latex output)
   540   "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>(00\<^bsub>_\<^esub>)/ _)" [0, 10] 10)
   541   "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>(00\<^bsub>_\<in>_\<^esub>)/ _)" [0, 10] 10)
   542 
   543 translations
   544   "INT x y. B"  == "INT x. INT y. B"
   545   "INT x. B"    == "CONST INTER CONST UNIV (%x. B)"
   546   "INT x. B"    == "INT x:CONST UNIV. B"
   547   "INT x:A. B"  == "CONST INTER A (%x. B)"
   548 
   549 print_translation {* [
   550 Syntax.preserve_binder_abs2_tr' @{const_syntax INTER} "@INTER"
   551 ] *} -- {* to avoid eta-contraction of body *}
   552 
   553 lemma INTER_eq_Inter_image:
   554   "(\<Inter>x\<in>A. B x) = \<Inter>(B`A)"
   555   by (fact INFI_def)
   556   
   557 lemma Inter_def:
   558   "\<Inter>S = (\<Inter>x\<in>S. x)"
   559   by (simp add: INTER_eq_Inter_image image_def)
   560 
   561 lemma INTER_def:
   562   "(\<Inter>x\<in>A. B x) = {y. \<forall>x\<in>A. y \<in> B x}"
   563   by (auto simp add: INTER_eq_Inter_image Inter_eq)
   564 
   565 lemma Inter_image_eq [simp]:
   566   "\<Inter>(B`A) = (\<Inter>x\<in>A. B x)"
   567   by (rule sym) (fact INTER_eq_Inter_image)
   568 
   569 lemma INT_iff [simp]: "(b: (INT x:A. B x)) = (ALL x:A. b: B x)"
   570   by (unfold INTER_def) blast
   571 
   572 lemma INT_I [intro!]: "(!!x. x:A ==> b: B x) ==> b : (INT x:A. B x)"
   573   by (unfold INTER_def) blast
   574 
   575 lemma INT_D [elim]: "b : (INT x:A. B x) ==> a:A ==> b: B a"
   576   by auto
   577 
   578 lemma INT_E [elim]: "b : (INT x:A. B x) ==> (b: B a ==> R) ==> (a~:A ==> R) ==> R"
   579   -- {* "Classical" elimination -- by the Excluded Middle on @{prop "a:A"}. *}
   580   by (unfold INTER_def) blast
   581 
   582 lemma INT_cong [cong]:
   583     "A = B ==> (!!x. x:B ==> C x = D x) ==> (INT x:A. C x) = (INT x:B. D x)"
   584   by (simp add: INTER_def)
   585 
   586 lemma Collect_ball_eq: "{x. \<forall>y\<in>A. P x y} = (\<Inter>y\<in>A. {x. P x y})"
   587   by blast
   588 
   589 lemma Collect_all_eq: "{x. \<forall>y. P x y} = (\<Inter>y. {x. P x y})"
   590   by blast
   591 
   592 lemma INT_lower: "a \<in> A ==> (\<Inter>x\<in>A. B x) \<subseteq> B a"
   593   by (fact INF_leI)
   594 
   595 lemma INT_greatest: "(!!x. x \<in> A ==> C \<subseteq> B x) ==> C \<subseteq> (\<Inter>x\<in>A. B x)"
   596   by (fact le_INFI)
   597 
   598 lemma INT_empty [simp]: "(\<Inter>x\<in>{}. B x) = UNIV"
   599   by blast
   600 
   601 lemma INT_absorb: "k \<in> I ==> A k \<inter> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. A i)"
   602   by blast
   603 
   604 lemma INT_subset_iff: "(B \<subseteq> (\<Inter>i\<in>I. A i)) = (\<forall>i\<in>I. B \<subseteq> A i)"
   605   by blast
   606 
   607 lemma INT_insert [simp]: "(\<Inter>x \<in> insert a A. B x) = B a \<inter> INTER A B"
   608   by blast
   609 
   610 lemma INT_Un: "(\<Inter>i \<in> A \<union> B. M i) = (\<Inter>i \<in> A. M i) \<inter> (\<Inter>i\<in>B. M i)"
   611   by blast
   612 
   613 lemma INT_insert_distrib:
   614     "u \<in> A ==> (\<Inter>x\<in>A. insert a (B x)) = insert a (\<Inter>x\<in>A. B x)"
   615   by blast
   616 
   617 lemma INT_constant [simp]: "(\<Inter>y\<in>A. c) = (if A = {} then UNIV else c)"
   618   by auto
   619 
   620 lemma INT_eq: "(\<Inter>x\<in>A. B x) = \<Inter>({Y. \<exists>x\<in>A. Y = B x})"
   621   -- {* Look: it has an \emph{existential} quantifier *}
   622   by blast
   623 
   624 lemma INTER_UNIV_conv[simp]:
   625  "(UNIV = (INT x:A. B x)) = (\<forall>x\<in>A. B x = UNIV)"
   626  "((INT x:A. B x) = UNIV) = (\<forall>x\<in>A. B x = UNIV)"
   627 by blast+
   628 
   629 lemma INT_bool_eq: "(\<Inter>b::bool. A b) = (A True \<inter> A False)"
   630   by (auto intro: bool_induct)
   631 
   632 lemma Pow_INT_eq: "Pow (\<Inter>x\<in>A. B x) = (\<Inter>x\<in>A. Pow (B x))"
   633   by blast
   634 
   635 lemma INT_anti_mono:
   636   "B \<subseteq> A ==> (!!x. x \<in> A ==> f x \<subseteq> g x) ==>
   637     (\<Inter>x\<in>A. f x) \<subseteq> (\<Inter>x\<in>A. g x)"
   638   -- {* The last inclusion is POSITIVE! *}
   639   by (blast dest: subsetD)
   640 
   641 lemma vimage_INT: "f-`(INT x:A. B x) = (INT x:A. f -` B x)"
   642   by blast
   643 
   644 
   645 subsection {* Distributive laws *}
   646 
   647 lemma Int_Union: "A \<inter> \<Union>B = (\<Union>C\<in>B. A \<inter> C)"
   648   by blast
   649 
   650 lemma Int_Union2: "\<Union>B \<inter> A = (\<Union>C\<in>B. C \<inter> A)"
   651   by blast
   652 
   653 lemma Un_Union_image: "(\<Union>x\<in>C. A x \<union> B x) = \<Union>(A`C) \<union> \<Union>(B`C)"
   654   -- {* Devlin, Fundamentals of Contemporary Set Theory, page 12, exercise 5: *}
   655   -- {* Union of a family of unions *}
   656   by blast
   657 
   658 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)"
   659   -- {* Equivalent version *}
   660   by blast
   661 
   662 lemma Un_Inter: "A \<union> \<Inter>B = (\<Inter>C\<in>B. A \<union> C)"
   663   by blast
   664 
   665 lemma Int_Inter_image: "(\<Inter>x\<in>C. A x \<inter> B x) = \<Inter>(A`C) \<inter> \<Inter>(B`C)"
   666   by blast
   667 
   668 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)"
   669   -- {* Equivalent version *}
   670   by blast
   671 
   672 lemma Int_UN_distrib: "B \<inter> (\<Union>i\<in>I. A i) = (\<Union>i\<in>I. B \<inter> A i)"
   673   -- {* Halmos, Naive Set Theory, page 35. *}
   674   by blast
   675 
   676 lemma Un_INT_distrib: "B \<union> (\<Inter>i\<in>I. A i) = (\<Inter>i\<in>I. B \<union> A i)"
   677   by blast
   678 
   679 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)"
   680   by blast
   681 
   682 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)"
   683   by blast
   684 
   685 
   686 subsection {* Complement *}
   687 
   688 lemma Compl_UN [simp]: "-(\<Union>x\<in>A. B x) = (\<Inter>x\<in>A. -B x)"
   689   by blast
   690 
   691 lemma Compl_INT [simp]: "-(\<Inter>x\<in>A. B x) = (\<Union>x\<in>A. -B x)"
   692   by blast
   693 
   694 
   695 subsection {* Miniscoping and maxiscoping *}
   696 
   697 text {* \medskip Miniscoping: pushing in quantifiers and big Unions
   698            and Intersections. *}
   699 
   700 lemma UN_simps [simp]:
   701   "!!a B C. (UN x:C. insert a (B x)) = (if C={} then {} else insert a (UN x:C. B x))"
   702   "!!A B C. (UN x:C. A x Un B)   = ((if C={} then {} else (UN x:C. A x) Un B))"
   703   "!!A B C. (UN x:C. A Un B x)   = ((if C={} then {} else A Un (UN x:C. B x)))"
   704   "!!A B C. (UN x:C. A x Int B)  = ((UN x:C. A x) Int B)"
   705   "!!A B C. (UN x:C. A Int B x)  = (A Int (UN x:C. B x))"
   706   "!!A B C. (UN x:C. A x - B)    = ((UN x:C. A x) - B)"
   707   "!!A B C. (UN x:C. A - B x)    = (A - (INT x:C. B x))"
   708   "!!A B. (UN x: Union A. B x) = (UN y:A. UN x:y. B x)"
   709   "!!A B C. (UN z: UNION A B. C z) = (UN  x:A. UN z: B(x). C z)"
   710   "!!A B f. (UN x:f`A. B x)     = (UN a:A. B (f a))"
   711   by auto
   712 
   713 lemma INT_simps [simp]:
   714   "!!A B C. (INT x:C. A x Int B) = (if C={} then UNIV else (INT x:C. A x) Int B)"
   715   "!!A B C. (INT x:C. A Int B x) = (if C={} then UNIV else A Int (INT x:C. B x))"
   716   "!!A B C. (INT x:C. A x - B)   = (if C={} then UNIV else (INT x:C. A x) - B)"
   717   "!!A B C. (INT x:C. A - B x)   = (if C={} then UNIV else A - (UN x:C. B x))"
   718   "!!a B C. (INT x:C. insert a (B x)) = insert a (INT x:C. B x)"
   719   "!!A B C. (INT x:C. A x Un B)  = ((INT x:C. A x) Un B)"
   720   "!!A B C. (INT x:C. A Un B x)  = (A Un (INT x:C. B x))"
   721   "!!A B. (INT x: Union A. B x) = (INT y:A. INT x:y. B x)"
   722   "!!A B C. (INT z: UNION A B. C z) = (INT x:A. INT z: B(x). C z)"
   723   "!!A B f. (INT x:f`A. B x)    = (INT a:A. B (f a))"
   724   by auto
   725 
   726 lemma ball_simps [simp,noatp]:
   727   "!!A P Q. (ALL x:A. P x | Q) = ((ALL x:A. P x) | Q)"
   728   "!!A P Q. (ALL x:A. P | Q x) = (P | (ALL x:A. Q x))"
   729   "!!A P Q. (ALL x:A. P --> Q x) = (P --> (ALL x:A. Q x))"
   730   "!!A P Q. (ALL x:A. P x --> Q) = ((EX x:A. P x) --> Q)"
   731   "!!P. (ALL x:{}. P x) = True"
   732   "!!P. (ALL x:UNIV. P x) = (ALL x. P x)"
   733   "!!a B P. (ALL x:insert a B. P x) = (P a & (ALL x:B. P x))"
   734   "!!A P. (ALL x:Union A. P x) = (ALL y:A. ALL x:y. P x)"
   735   "!!A B P. (ALL x: UNION A B. P x) = (ALL a:A. ALL x: B a. P x)"
   736   "!!P Q. (ALL x:Collect Q. P x) = (ALL x. Q x --> P x)"
   737   "!!A P f. (ALL x:f`A. P x) = (ALL x:A. P (f x))"
   738   "!!A P. (~(ALL x:A. P x)) = (EX x:A. ~P x)"
   739   by auto
   740 
   741 lemma bex_simps [simp,noatp]:
   742   "!!A P Q. (EX x:A. P x & Q) = ((EX x:A. P x) & Q)"
   743   "!!A P Q. (EX x:A. P & Q x) = (P & (EX x:A. Q x))"
   744   "!!P. (EX x:{}. P x) = False"
   745   "!!P. (EX x:UNIV. P x) = (EX x. P x)"
   746   "!!a B P. (EX x:insert a B. P x) = (P(a) | (EX x:B. P x))"
   747   "!!A P. (EX x:Union A. P x) = (EX y:A. EX x:y. P x)"
   748   "!!A B P. (EX x: UNION A B. P x) = (EX a:A. EX x:B a. P x)"
   749   "!!P Q. (EX x:Collect Q. P x) = (EX x. Q x & P x)"
   750   "!!A P f. (EX x:f`A. P x) = (EX x:A. P (f x))"
   751   "!!A P. (~(EX x:A. P x)) = (ALL x:A. ~P x)"
   752   by auto
   753 
   754 lemma ball_conj_distrib:
   755   "(ALL x:A. P x & Q x) = ((ALL x:A. P x) & (ALL x:A. Q x))"
   756   by blast
   757 
   758 lemma bex_disj_distrib:
   759   "(EX x:A. P x | Q x) = ((EX x:A. P x) | (EX x:A. Q x))"
   760   by blast
   761 
   762 
   763 text {* \medskip Maxiscoping: pulling out big Unions and Intersections. *}
   764 
   765 lemma UN_extend_simps:
   766   "!!a B C. insert a (UN x:C. B x) = (if C={} then {a} else (UN x:C. insert a (B x)))"
   767   "!!A B C. (UN x:C. A x) Un B    = (if C={} then B else (UN x:C. A x Un B))"
   768   "!!A B C. A Un (UN x:C. B x)   = (if C={} then A else (UN x:C. A Un B x))"
   769   "!!A B C. ((UN x:C. A x) Int B) = (UN x:C. A x Int B)"
   770   "!!A B C. (A Int (UN x:C. B x)) = (UN x:C. A Int B x)"
   771   "!!A B C. ((UN x:C. A x) - B) = (UN x:C. A x - B)"
   772   "!!A B C. (A - (INT x:C. B x)) = (UN x:C. A - B x)"
   773   "!!A B. (UN y:A. UN x:y. B x) = (UN x: Union A. B x)"
   774   "!!A B C. (UN  x:A. UN z: B(x). C z) = (UN z: UNION A B. C z)"
   775   "!!A B f. (UN a:A. B (f a)) = (UN x:f`A. B x)"
   776   by auto
   777 
   778 lemma INT_extend_simps:
   779   "!!A B C. (INT x:C. A x) Int B = (if C={} then B else (INT x:C. A x Int B))"
   780   "!!A B C. A Int (INT x:C. B x) = (if C={} then A else (INT x:C. A Int B x))"
   781   "!!A B C. (INT x:C. A x) - B   = (if C={} then UNIV-B else (INT x:C. A x - B))"
   782   "!!A B C. A - (UN x:C. B x)   = (if C={} then A else (INT x:C. A - B x))"
   783   "!!a B C. insert a (INT x:C. B x) = (INT x:C. insert a (B x))"
   784   "!!A B C. ((INT x:C. A x) Un B)  = (INT x:C. A x Un B)"
   785   "!!A B C. A Un (INT x:C. B x)  = (INT x:C. A Un B x)"
   786   "!!A B. (INT y:A. INT x:y. B x) = (INT x: Union A. B x)"
   787   "!!A B C. (INT x:A. INT z: B(x). C z) = (INT z: UNION A B. C z)"
   788   "!!A B f. (INT a:A. B (f a))    = (INT x:f`A. B x)"
   789   by auto
   790 
   791 
   792 no_notation
   793   less_eq  (infix "\<sqsubseteq>" 50) and
   794   less (infix "\<sqsubset>" 50) and
   795   inf  (infixl "\<sqinter>" 70) and
   796   sup  (infixl "\<squnion>" 65) and
   797   Inf  ("\<Sqinter>_" [900] 900) and
   798   Sup  ("\<Squnion>_" [900] 900) and
   799   top ("\<top>") and
   800   bot ("\<bottom>")
   801 
   802 lemmas mem_simps =
   803   insert_iff empty_iff Un_iff Int_iff Compl_iff Diff_iff
   804   mem_Collect_eq UN_iff Union_iff INT_iff Inter_iff
   805   -- {* Each of these has ALREADY been added @{text "[simp]"} above. *}
   806 
   807 end