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