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