src/HOL/Complete_Lattice.thy
 author haftmann Sun Jul 17 20:29:54 2011 +0200 (2011-07-17) changeset 43870 92129f505125 parent 43868 9684251c7ec1 child 43871 79c3231e0593 permissions -rw-r--r--
structuring duals together
     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   "class.complete_lattice Sup Inf (op \<ge>) (op >) sup inf \<top> \<bottom>"

    37   by (auto intro!: class.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 [simp]:

    48   "\<Sqinter>{} = \<top>"

    49   by (auto intro: antisym Inf_greatest)

    50

    51 lemma Sup_empty [simp]:

    52   "\<Squnion>{} = \<bottom>"

    53   by (auto intro: antisym Sup_least)

    54

    55 lemma Inf_UNIV [simp]:

    56   "\<Sqinter>UNIV = \<bottom>"

    57   by (simp add: Sup_Inf Sup_empty [symmetric])

    58

    59 lemma Sup_UNIV [simp]:

    60   "\<Squnion>UNIV = \<top>"

    61   by (simp add: Inf_Sup Inf_empty [symmetric])

    62

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

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

    65

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

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

    68

    69 lemma Inf_singleton [simp]:

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

    71   by (auto intro: antisym Inf_lower Inf_greatest)

    72

    73 lemma Sup_singleton [simp]:

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

    75   by (auto intro: antisym Sup_upper Sup_least)

    76

    77 lemma Inf_binary:

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

    79   by (simp add: Inf_insert)

    80

    81 lemma Sup_binary:

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

    83   by (simp add: Sup_insert)

    84

    85 lemma le_Inf_iff: "b \<sqsubseteq> \<Sqinter>A \<longleftrightarrow> (\<forall>a\<in>A. b \<sqsubseteq> a)"

    86   by (auto intro: Inf_greatest dest: Inf_lower)

    87

    88 lemma Sup_le_iff: "\<Squnion>A \<sqsubseteq> b \<longleftrightarrow> (\<forall>a\<in>A. a \<sqsubseteq> b)"

    89   by (auto intro: Sup_least dest: Sup_upper)

    90

    91 lemma Inf_mono:

    92   assumes "\<And>b. b \<in> B \<Longrightarrow> \<exists>a\<in>A. a \<sqsubseteq> b"

    93   shows "\<Sqinter>A \<sqsubseteq> \<Sqinter>B"

    94 proof (rule Inf_greatest)

    95   fix b assume "b \<in> B"

    96   with assms obtain a where "a \<in> A" and "a \<sqsubseteq> b" by blast

    97   from a \<in> A have "\<Sqinter>A \<sqsubseteq> a" by (rule Inf_lower)

    98   with a \<sqsubseteq> b show "\<Sqinter>A \<sqsubseteq> b" by auto

    99 qed

   100

   101 lemma Sup_mono:

   102   assumes "\<And>a. a \<in> A \<Longrightarrow> \<exists>b\<in>B. a \<sqsubseteq> b"

   103   shows "\<Squnion>A \<sqsubseteq> \<Squnion>B"

   104 proof (rule Sup_least)

   105   fix a assume "a \<in> A"

   106   with assms obtain b where "b \<in> B" and "a \<sqsubseteq> b" by blast

   107   from b \<in> B have "b \<sqsubseteq> \<Squnion>B" by (rule Sup_upper)

   108   with a \<sqsubseteq> b show "a \<sqsubseteq> \<Squnion>B" by auto

   109 qed

   110

   111 lemma Sup_upper2: "u \<in> A \<Longrightarrow> v \<sqsubseteq> u \<Longrightarrow> v \<sqsubseteq> \<Squnion>A"

   112   using Sup_upper [of u A] by auto

   113

   114 lemma Inf_lower2: "u \<in> A \<Longrightarrow> u \<sqsubseteq> v \<Longrightarrow> \<Sqinter>A \<sqsubseteq> v"

   115   using Inf_lower [of u A] by auto

   116

   117 lemma Inf_less_eq:

   118   assumes "\<And>v. v \<in> A \<Longrightarrow> v \<sqsubseteq> u"

   119     and "A \<noteq> {}"

   120   shows "\<Sqinter>A \<sqsubseteq> u"

   121 proof -

   122   from A \<noteq> {} obtain v where "v \<in> A" by blast

   123   moreover with assms have "v \<sqsubseteq> u" by blast

   124   ultimately show ?thesis by (rule Inf_lower2)

   125 qed

   126

   127 lemma less_eq_Sup:

   128   assumes "\<And>v. v \<in> A \<Longrightarrow> u \<sqsubseteq> v"

   129     and "A \<noteq> {}"

   130   shows "u \<sqsubseteq> \<Squnion>A"

   131 proof -

   132   from A \<noteq> {} obtain v where "v \<in> A" by blast

   133   moreover with assms have "u \<sqsubseteq> v" by blast

   134   ultimately show ?thesis by (rule Sup_upper2)

   135 qed

   136

   137 lemma Inf_inter_less_eq: "\<Sqinter>A \<squnion> \<Sqinter>B \<sqsubseteq> \<Sqinter>(A \<inter> B)"

   138   by (auto intro: Inf_greatest Inf_lower)

   139

   140 lemma Sup_inter_greater_eq: "\<Squnion>(A \<inter> B) \<sqsubseteq> \<Squnion>A \<sqinter> \<Squnion>B "

   141   by (auto intro: Sup_least Sup_upper)

   142

   143 lemma Inf_union_distrib: "\<Sqinter>(A \<union> B) = \<Sqinter>A \<sqinter> \<Sqinter>B"

   144   by (rule antisym) (auto intro: Inf_greatest Inf_lower le_infI1 le_infI2)

   145

   146 lemma Sup_union_distrib: "\<Squnion>(A \<union> B) = \<Squnion>A \<squnion> \<Squnion>B"

   147   by (rule antisym) (auto intro: Sup_least Sup_upper le_supI1 le_supI2)

   148

   149 lemma Inf_top_conv [no_atp]:

   150   "\<Sqinter>A = \<top> \<longleftrightarrow> (\<forall>x\<in>A. x = \<top>)"

   151   "\<top> = \<Sqinter>A \<longleftrightarrow> (\<forall>x\<in>A. x = \<top>)"

   152 proof -

   153   show "\<Sqinter>A = \<top> \<longleftrightarrow> (\<forall>x\<in>A. x = \<top>)"

   154   proof

   155     assume "\<forall>x\<in>A. x = \<top>"

   156     then have "A = {} \<or> A = {\<top>}" by auto

   157     then show "\<Sqinter>A = \<top>" by auto

   158   next

   159     assume "\<Sqinter>A = \<top>"

   160     show "\<forall>x\<in>A. x = \<top>"

   161     proof (rule ccontr)

   162       assume "\<not> (\<forall>x\<in>A. x = \<top>)"

   163       then obtain x where "x \<in> A" and "x \<noteq> \<top>" by blast

   164       then obtain B where "A = insert x B" by blast

   165       with \<Sqinter>A = \<top> x \<noteq> \<top> show False by (simp add: Inf_insert)

   166     qed

   167   qed

   168   then show "\<top> = \<Sqinter>A \<longleftrightarrow> (\<forall>x\<in>A. x = \<top>)" by auto

   169 qed

   170

   171 lemma Sup_bot_conv [no_atp]:

   172   "\<Squnion>A = \<bottom> \<longleftrightarrow> (\<forall>x\<in>A. x = \<bottom>)" (is ?P)

   173   "\<bottom> = \<Squnion>A \<longleftrightarrow> (\<forall>x\<in>A. x = \<bottom>)" (is ?Q)

   174 proof -

   175   interpret dual: complete_lattice Sup Inf "op \<ge>" "op >" sup inf \<top> \<bottom>

   176     by (fact dual_complete_lattice)

   177   from dual.Inf_top_conv show ?P and ?Q by simp_all

   178 qed

   179

   180 lemma Inf_anti_mono: "B \<subseteq> A \<Longrightarrow> \<Sqinter>A \<sqsubseteq> \<Sqinter>B"

   181   by (auto intro: Inf_greatest Inf_lower)

   182

   183 lemma Sup_anti_mono: "A \<subseteq> B \<Longrightarrow> \<Squnion>A \<sqsubseteq> \<Squnion>B"

   184   by (auto intro: Sup_least Sup_upper)

   185

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

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

   188

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

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

   191

   192 end

   193

   194 syntax

   195   "_INF1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3INF _./ _)" [0, 10] 10)

   196   "_INF"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3INF _:_./ _)" [0, 0, 10] 10)

   197   "_SUP1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3SUP _./ _)" [0, 10] 10)

   198   "_SUP"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3SUP _:_./ _)" [0, 0, 10] 10)

   199

   200 syntax (xsymbols)

   201   "_INF1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3\<Sqinter>_./ _)" [0, 10] 10)

   202   "_INF"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Sqinter>_\<in>_./ _)" [0, 0, 10] 10)

   203   "_SUP1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3\<Squnion>_./ _)" [0, 10] 10)

   204   "_SUP"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Squnion>_\<in>_./ _)" [0, 0, 10] 10)

   205

   206 translations

   207   "INF x y. B"   == "INF x. INF y. B"

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

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

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

   211   "SUP x y. B"   == "SUP x. SUP y. B"

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

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

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

   215

   216 print_translation {*

   217   [Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax INFI} @{syntax_const "_INF"},

   218     Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax SUPR} @{syntax_const "_SUP"}]

   219 *} -- {* to avoid eta-contraction of body *}

   220

   221 context complete_lattice

   222 begin

   223

   224 lemma INF_empty: "(\<Sqinter>x\<in>{}. f x) = \<top>"

   225   by (simp add: INFI_def)

   226

   227 lemma SUP_empty: "(\<Squnion>x\<in>{}. f x) = \<bottom>"

   228   by (simp add: SUPR_def)

   229

   230 lemma INF_insert: "(\<Sqinter>x\<in>insert a A. f x) = f a \<sqinter> INFI A f"

   231   by (simp add: INFI_def Inf_insert)

   232

   233 lemma SUP_insert: "(\<Squnion>x\<in>insert a A. f x) = f a \<squnion> SUPR A f"

   234   by (simp add: SUPR_def Sup_insert)

   235

   236 lemma INF_leI: "i \<in> A \<Longrightarrow> (\<Sqinter>i\<in>A. f i) \<sqsubseteq> f i"

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

   238

   239 lemma le_SUPI: "i \<in> A \<Longrightarrow> f i \<sqsubseteq> (\<Squnion>i\<in>A. f i)"

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

   241

   242 lemma INF_leI2: "i \<in> A \<Longrightarrow> f i \<sqsubseteq> u \<Longrightarrow> (\<Sqinter>i\<in>A. f i) \<sqsubseteq> u"

   243   using INF_leI [of i A f] by auto

   244

   245 lemma le_SUPI2: "i \<in> A \<Longrightarrow> u \<sqsubseteq> f i \<Longrightarrow> u \<sqsubseteq> (\<Squnion>i\<in>A. f i)"

   246   using le_SUPI [of i A f] by auto

   247

   248 lemma le_INFI: "(\<And>i. i \<in> A \<Longrightarrow> u \<sqsubseteq> f i) \<Longrightarrow> u \<sqsubseteq> (\<Sqinter>i\<in>A. f i)"

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

   250

   251 lemma SUP_leI: "(\<And>i. i \<in> A \<Longrightarrow> f i \<sqsubseteq> u) \<Longrightarrow> (\<Squnion>i\<in>A. f i) \<sqsubseteq> u"

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

   253

   254 lemma le_INF_iff: "u \<sqsubseteq> (\<Sqinter>i\<in>A. f i) \<longleftrightarrow> (\<forall>i \<in> A. u \<sqsubseteq> f i)"

   255   by (auto simp add: INFI_def le_Inf_iff)

   256

   257 lemma SUP_le_iff: "(\<Squnion>i\<in>A. f i) \<sqsubseteq> u \<longleftrightarrow> (\<forall>i \<in> A. f i \<sqsubseteq> u)"

   258   by (auto simp add: SUPR_def Sup_le_iff)

   259

   260 lemma INF_const [simp]: "A \<noteq> {} \<Longrightarrow> (\<Sqinter>i\<in>A. f) = f"

   261   by (auto intro: antisym INF_leI le_INFI)

   262

   263 lemma SUP_const [simp]: "A \<noteq> {} \<Longrightarrow> (\<Squnion>i\<in>A. f) = f"

   264   by (auto intro: antisym SUP_leI le_SUPI)

   265

   266 lemma INF_cong:

   267   "A = B \<Longrightarrow> (\<And>x. x \<in> B \<Longrightarrow> C x = D x) \<Longrightarrow> (\<Sqinter>x\<in>A. C x) = (\<Sqinter>x\<in>B. D x)"

   268   by (simp add: INFI_def image_def)

   269

   270 lemma SUP_cong:

   271   "A = B \<Longrightarrow> (\<And>x. x \<in> B \<Longrightarrow> C x = D x) \<Longrightarrow> (\<Squnion>x\<in>A. C x) = (\<Squnion>x\<in>B. D x)"

   272   by (simp add: SUPR_def image_def)

   273

   274 lemma INF_mono:

   275   "(\<And>m. m \<in> B \<Longrightarrow> \<exists>n\<in>A. f n \<sqsubseteq> g m) \<Longrightarrow> (\<Sqinter>n\<in>A. f n) \<sqsubseteq> (\<Sqinter>n\<in>B. g n)"

   276   by (force intro!: Inf_mono simp: INFI_def)

   277

   278 lemma SUP_mono:

   279   "(\<And>n. n \<in> A \<Longrightarrow> \<exists>m\<in>B. f n \<sqsubseteq> g m) \<Longrightarrow> (\<Squnion>n\<in>A. f n) \<sqsubseteq> (\<Squnion>n\<in>B. g n)"

   280   by (force intro!: Sup_mono simp: SUPR_def)

   281

   282 lemma INF_subset:

   283   "A \<subseteq> B \<Longrightarrow> INFI B f \<sqsubseteq> INFI A f"

   284   by (intro INF_mono) auto

   285

   286 lemma SUP_subset:

   287   "A \<subseteq> B \<Longrightarrow> SUPR A f \<sqsubseteq> SUPR B f"

   288   by (intro SUP_mono) auto

   289

   290 lemma INF_commute: "(\<Sqinter>i\<in>A. \<Sqinter>j\<in>B. f i j) = (\<Sqinter>j\<in>B. \<Sqinter>i\<in>A. f i j)"

   291   by (iprover intro: INF_leI le_INFI order_trans antisym)

   292

   293 lemma SUP_commute: "(\<Squnion>i\<in>A. \<Squnion>j\<in>B. f i j) = (\<Squnion>j\<in>B. \<Squnion>i\<in>A. f i j)"

   294   by (iprover intro: SUP_leI le_SUPI order_trans antisym)

   295

   296 lemma (in complete_lattice) INFI_empty:

   297   "(\<Sqinter>x\<in>{}. B x) = \<top>"

   298   by (simp add: INFI_def)

   299

   300 lemma (in complete_lattice) INFI_absorb:

   301   assumes "k \<in> I"

   302   shows "A k \<sqinter> (\<Sqinter>i\<in>I. A i) = (\<Sqinter>i\<in>I. A i)"

   303 proof -

   304   from assms obtain J where "I = insert k J" by blast

   305   then show ?thesis by (simp add: INF_insert)

   306 qed

   307

   308 lemma (in complete_lattice) INF_union:

   309   "(\<Sqinter>i \<in> A \<union> B. M i) = (\<Sqinter>i \<in> A. M i) \<sqinter> (\<Sqinter>i\<in>B. M i)"

   310   by (auto intro!: antisym INF_mono intro: le_infI1 le_infI2 le_INFI INF_leI)

   311

   312 lemma (in complete_lattice) INF_constant:

   313   "(\<Sqinter>y\<in>A. c) = (if A = {} then \<top> else c)"

   314   by (simp add: INF_empty)

   315

   316 lemma (in complete_lattice) INF_eq:

   317   "(\<Sqinter>x\<in>A. B x) = \<Sqinter>({Y. \<exists>x\<in>A. Y = B x})"

   318   by (simp add: INFI_def image_def)

   319

   320 lemma (in complete_lattice) INF_top_conv:

   321  "\<top> = (\<Sqinter>x\<in>A. B x) \<longleftrightarrow> (\<forall>x\<in>A. B x = \<top>)"

   322  "(\<Sqinter>x\<in>A. B x) = \<top> \<longleftrightarrow> (\<forall>x\<in>A. B x = \<top>)"

   323   by (auto simp add: INFI_def Inf_top_conv)

   324

   325 lemma (in complete_lattice) INFI_UNIV_range:

   326   "(\<Sqinter>x\<in>UNIV. f x) = \<Sqinter>range f"

   327   by (simp add: INFI_def)

   328

   329 lemma (in complete_lattice) INF_bool_eq:

   330   "(\<Sqinter>b. A b) = A True \<sqinter> A False"

   331   by (simp add: UNIV_bool INF_empty INF_insert inf_commute)

   332

   333 lemma (in complete_lattice) INF_anti_mono:

   334   "B \<subseteq> A \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> f x \<sqsubseteq> g x) \<Longrightarrow> (\<Sqinter>x\<in>B. f x) \<sqsubseteq> (\<Sqinter>x\<in>B. g x)"

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

   336   by (blast intro: INF_mono dest: subsetD)

   337

   338 end

   339

   340 lemma Inf_less_iff:

   341   fixes a :: "'a\<Colon>{complete_lattice,linorder}"

   342   shows "\<Sqinter>S \<sqsubset> a \<longleftrightarrow> (\<exists>x\<in>S. x \<sqsubset> a)"

   343   unfolding not_le [symmetric] le_Inf_iff by auto

   344

   345 lemma INF_less_iff:

   346   fixes a :: "'a::{complete_lattice,linorder}"

   347   shows "(\<Sqinter>i\<in>A. f i) \<sqsubset> a \<longleftrightarrow> (\<exists>x\<in>A. f x \<sqsubset> a)"

   348   unfolding INFI_def Inf_less_iff by auto

   349

   350 lemma less_Sup_iff:

   351   fixes a :: "'a\<Colon>{complete_lattice,linorder}"

   352   shows "a \<sqsubset> \<Squnion>S \<longleftrightarrow> (\<exists>x\<in>S. a \<sqsubset> x)"

   353   unfolding not_le [symmetric] Sup_le_iff by auto

   354

   355 lemma less_SUP_iff:

   356   fixes a :: "'a::{complete_lattice,linorder}"

   357   shows "a \<sqsubset> (\<Squnion>i\<in>A. f i) \<longleftrightarrow> (\<exists>x\<in>A. a \<sqsubset> f x)"

   358   unfolding SUPR_def less_Sup_iff by auto

   359

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

   361

   362 instantiation bool :: complete_lattice

   363 begin

   364

   365 definition

   366   "\<Sqinter>A \<longleftrightarrow> (\<forall>x\<in>A. x)"

   367

   368 definition

   369   "\<Squnion>A \<longleftrightarrow> (\<exists>x\<in>A. x)"

   370

   371 instance proof

   372 qed (auto simp add: Inf_bool_def Sup_bool_def)

   373

   374 end

   375

   376 lemma INFI_bool_eq [simp]:

   377   "INFI = Ball"

   378 proof (rule ext)+

   379   fix A :: "'a set"

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

   381   show "(\<Sqinter>x\<in>A. P x) \<longleftrightarrow> (\<forall>x\<in>A. P x)"

   382     by (auto simp add: Ball_def INFI_def Inf_bool_def)

   383 qed

   384

   385 lemma SUPR_bool_eq [simp]:

   386   "SUPR = Bex"

   387 proof (rule ext)+

   388   fix A :: "'a set"

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

   390   show "(\<Squnion>x\<in>A. P x) \<longleftrightarrow> (\<exists>x\<in>A. P x)"

   391     by (auto simp add: Bex_def SUPR_def Sup_bool_def)

   392 qed

   393

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

   395 begin

   396

   397 definition

   398   "\<Sqinter>A = (\<lambda>x. \<Sqinter>{y. \<exists>f\<in>A. y = f x})"

   399

   400 lemma Inf_apply:

   401   "(\<Sqinter>A) x = \<Sqinter>{y. \<exists>f\<in>A. y = f x}"

   402   by (simp add: Inf_fun_def)

   403

   404 definition

   405   "\<Squnion>A = (\<lambda>x. \<Squnion>{y. \<exists>f\<in>A. y = f x})"

   406

   407 lemma Sup_apply:

   408   "(\<Squnion>A) x = \<Squnion>{y. \<exists>f\<in>A. y = f x}"

   409   by (simp add: Sup_fun_def)

   410

   411 instance proof

   412 qed (auto simp add: le_fun_def Inf_apply Sup_apply

   413   intro: Inf_lower Sup_upper Inf_greatest Sup_least)

   414

   415 end

   416

   417 lemma INFI_apply:

   418   "(\<Sqinter>y\<in>A. f y) x = (\<Sqinter>y\<in>A. f y x)"

   419   by (auto intro: arg_cong [of _ _ Inf] simp add: INFI_def Inf_apply)

   420

   421 lemma SUPR_apply:

   422   "(\<Squnion>y\<in>A. f y) x = (\<Squnion>y\<in>A. f y x)"

   423   by (auto intro: arg_cong [of _ _ Sup] simp add: SUPR_def Sup_apply)

   424

   425

   426 subsection {* Inter *}

   427

   428 abbreviation Inter :: "'a set set \<Rightarrow> 'a set" where

   429   "Inter S \<equiv> \<Sqinter>S"

   430

   431 notation (xsymbols)

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

   433

   434 lemma Inter_eq:

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

   436 proof (rule set_eqI)

   437   fix x

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

   439     by auto

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

   441     by (simp add: Inf_fun_def Inf_bool_def) (simp add: mem_def)

   442 qed

   443

   444 lemma Inter_iff [simp,no_atp]: "A \<in> \<Inter>C \<longleftrightarrow> (\<forall>X\<in>C. A \<in> X)"

   445   by (unfold Inter_eq) blast

   446

   447 lemma InterI [intro!]: "(\<And>X. X \<in> C \<Longrightarrow> A \<in> X) \<Longrightarrow> A \<in> \<Inter>C"

   448   by (simp add: Inter_eq)

   449

   450 text {*

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

   452   contains @{term A} as an element, but @{prop "A \<in> X"} can hold when

   453   @{prop "X \<in> C"} does not!  This rule is analogous to @{text spec}.

   454 *}

   455

   456 lemma InterD [elim, Pure.elim]: "A \<in> \<Inter>C \<Longrightarrow> X \<in> C \<Longrightarrow> A \<in> X"

   457   by auto

   458

   459 lemma InterE [elim]: "A \<in> \<Inter>C \<Longrightarrow> (X \<notin> C \<Longrightarrow> R) \<Longrightarrow> (A \<in> X \<Longrightarrow> R) \<Longrightarrow> R"

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

   461     @{prop "X \<in> C"}. *}

   462   by (unfold Inter_eq) blast

   463

   464 lemma Inter_lower: "B \<in> A \<Longrightarrow> \<Inter>A \<subseteq> B"

   465   by (fact Inf_lower)

   466

   467 lemma Inter_subset:

   468   "(\<And>X. X \<in> A \<Longrightarrow> X \<subseteq> B) \<Longrightarrow> A \<noteq> {} \<Longrightarrow> \<Inter>A \<subseteq> B"

   469   by (fact Inf_less_eq)

   470

   471 lemma Inter_greatest: "(\<And>X. X \<in> A \<Longrightarrow> C \<subseteq> X) \<Longrightarrow> C \<subseteq> Inter A"

   472   by (fact Inf_greatest)

   473

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

   475   by (fact Inf_binary [symmetric])

   476

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

   478   by (fact Inf_empty)

   479

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

   481   by (fact Inf_UNIV)

   482

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

   484   by (fact Inf_insert)

   485

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

   487   by (fact Inf_inter_less_eq)

   488

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

   490   by (fact Inf_union_distrib)

   491

   492 lemma Inter_UNIV_conv [simp, no_atp]:

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

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

   495   by (fact Inf_top_conv)+

   496

   497 lemma Inter_anti_mono: "B \<subseteq> A \<Longrightarrow> \<Inter>A \<subseteq> \<Inter>B"

   498   by (fact Inf_anti_mono)

   499

   500

   501 subsection {* Intersections of families *}

   502

   503 abbreviation INTER :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where

   504   "INTER \<equiv> INFI"

   505

   506 syntax

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

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

   509

   510 syntax (xsymbols)

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

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

   513

   514 syntax (latex output)

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

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

   517

   518 translations

   519   "INT x y. B"  == "INT x. INT y. B"

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

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

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

   523

   524 print_translation {*

   525   [Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax INTER} @{syntax_const "_INTER"}]

   526 *} -- {* to avoid eta-contraction of body *}

   527

   528 lemma INTER_eq_Inter_image:

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

   530   by (fact INFI_def)

   531

   532 lemma Inter_def:

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

   534   by (simp add: INTER_eq_Inter_image image_def)

   535

   536 lemma INTER_def:

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

   538   by (auto simp add: INTER_eq_Inter_image Inter_eq)

   539

   540 lemma Inter_image_eq [simp]:

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

   542   by (rule sym) (fact INFI_def)

   543

   544 lemma INT_iff [simp]: "b \<in> (\<Inter>x\<in>A. B x) \<longleftrightarrow> (\<forall>x\<in>A. b \<in> B x)"

   545   by (unfold INTER_def) blast

   546

   547 lemma INT_I [intro!]: "(\<And>x. x \<in> A \<Longrightarrow> b \<in> B x) \<Longrightarrow> b \<in> (\<Inter>x\<in>A. B x)"

   548   by (unfold INTER_def) blast

   549

   550 lemma INT_D [elim, Pure.elim]: "b \<in> (\<Inter>x\<in>A. B x) \<Longrightarrow> a \<in> A \<Longrightarrow> b \<in> B a"

   551   by auto

   552

   553 lemma INT_E [elim]: "b \<in> (\<Inter>x\<in>A. B x) \<Longrightarrow> (b \<in> B a \<Longrightarrow> R) \<Longrightarrow> (a \<notin> A \<Longrightarrow> R) \<Longrightarrow> R"

   554   -- {* "Classical" elimination -- by the Excluded Middle on @{prop "a\<in>A"}. *}

   555   by (unfold INTER_def) blast

   556

   557 lemma INT_cong [cong]:

   558   "A = B \<Longrightarrow> (\<And>x. x \<in> B \<Longrightarrow> C x = D x) \<Longrightarrow> (\<Inter>x\<in>A. C x) = (\<Inter>x\<in>B. D x)"

   559   by (fact INF_cong)

   560

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

   562   by blast

   563

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

   565   by blast

   566

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

   568   by (fact INF_leI)

   569

   570 lemma INT_greatest: "(\<And>x. x \<in> A \<Longrightarrow> C \<subseteq> B x) \<Longrightarrow> C \<subseteq> (\<Inter>x\<in>A. B x)"

   571   by (fact le_INFI)

   572

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

   574   by (fact INFI_empty)

   575

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

   577   by (fact INFI_absorb)

   578

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

   580   by (fact le_INF_iff)

   581

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

   583   by (fact INF_insert)

   584

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

   586   by (fact INF_union)

   587

   588 lemma INT_insert_distrib:

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

   590   by blast

   591

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

   593   by (fact INF_constant)

   594

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

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

   597   by (fact INF_eq)

   598

   599 lemma INTER_UNIV_conv [simp]:

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

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

   602   by (fact INF_top_conv)+

   603

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

   605   by (fact INF_bool_eq)

   606

   607 lemma INT_anti_mono:

   608   "B \<subseteq> A \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> f x \<subseteq> g x) \<Longrightarrow> (\<Inter>x\<in>B. f x) \<subseteq> (\<Inter>x\<in>B. g x)"

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

   610   by (fact INF_anti_mono)

   611

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

   613   by blast

   614

   615 lemma vimage_INT: "f - (\<Inter>x\<in>A. B x) = (\<Inter>x\<in>A. f - B x)"

   616   by blast

   617

   618

   619 subsection {* Union *}

   620

   621 abbreviation Union :: "'a set set \<Rightarrow> 'a set" where

   622   "Union S \<equiv> \<Squnion>S"

   623

   624 notation (xsymbols)

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

   626

   627 lemma Union_eq:

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

   629 proof (rule set_eqI)

   630   fix x

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

   632     by auto

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

   634     by (simp add: Sup_fun_def Sup_bool_def) (simp add: mem_def)

   635 qed

   636

   637 lemma Union_iff [simp, no_atp]:

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

   639   by (unfold Union_eq) blast

   640

   641 lemma UnionI [intro]:

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

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

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

   645   by auto

   646

   647 lemma UnionE [elim!]:

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

   649   by auto

   650

   651 lemma Union_upper: "B \<in> A \<Longrightarrow> B \<subseteq> \<Union>A"

   652   by (iprover intro: subsetI UnionI)

   653

   654 lemma Union_least: "(\<And>X. X \<in> A \<Longrightarrow> X \<subseteq> C) \<Longrightarrow> \<Union>A \<subseteq> C"

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

   656

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

   658   by blast

   659

   660 lemma Union_empty [simp]: "\<Union>{} = {}"

   661   by blast

   662

   663 lemma Union_UNIV [simp]: "\<Union>UNIV = UNIV"

   664   by blast

   665

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

   667   by blast

   668

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

   670   by blast

   671

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

   673   by blast

   674

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

   676   by blast

   677

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

   679   by blast

   680

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

   682   by blast

   683

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

   685   by blast

   686

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

   688   by blast

   689

   690 lemma Union_mono: "A \<subseteq> B \<Longrightarrow> \<Union>A \<subseteq> \<Union>B"

   691   by blast

   692

   693

   694 subsection {* Unions of families *}

   695

   696 abbreviation UNION :: "'a set \<Rightarrow> ('a \<Rightarrow> 'b set) \<Rightarrow> 'b set" where

   697   "UNION \<equiv> SUPR"

   698

   699 syntax

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

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

   702

   703 syntax (xsymbols)

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

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

   706

   707 syntax (latex output)

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

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

   710

   711 translations

   712   "UN x y. B"   == "UN x. UN y. B"

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

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

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

   716

   717 text {*

   718   Note the difference between ordinary xsymbol syntax of indexed

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

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

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

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

   723   subscripts in Proof General.

   724 *}

   725

   726 print_translation {*

   727   [Syntax_Trans.preserve_binder_abs2_tr' @{const_syntax UNION} @{syntax_const "_UNION"}]

   728 *} -- {* to avoid eta-contraction of body *}

   729

   730 lemma UNION_eq_Union_image:

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

   732   by (fact SUPR_def)

   733

   734 lemma Union_def:

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

   736   by (simp add: UNION_eq_Union_image image_def)

   737

   738 lemma UNION_def [no_atp]:

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

   740   by (auto simp add: UNION_eq_Union_image Union_eq)

   741

   742 lemma Union_image_eq [simp]:

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

   744   by (rule sym) (fact UNION_eq_Union_image)

   745

   746 lemma UN_iff [simp]: "(b \<in> (\<Union>x\<in>A. B x)) = (\<exists>x\<in>A. b \<in> B x)"

   747   by (unfold UNION_def) blast

   748

   749 lemma UN_I [intro]: "a \<in> A \<Longrightarrow> b \<in> B a \<Longrightarrow> b \<in> (\<Union>x\<in>A. B x)"

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

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

   752   by auto

   753

   754 lemma UN_E [elim!]: "b \<in> (\<Union>x\<in>A. B x) \<Longrightarrow> (\<And>x. x\<in>A \<Longrightarrow> b \<in> B x \<Longrightarrow> R) \<Longrightarrow> R"

   755   by (unfold UNION_def) blast

   756

   757 lemma UN_cong [cong]:

   758     "A = B \<Longrightarrow> (\<And>x. x \<in> B \<Longrightarrow> C x = D x) \<Longrightarrow> (\<Union>x\<in>A. C x) = (\<Union>x\<in>B. D x)"

   759   by (simp add: UNION_def)

   760

   761 lemma strong_UN_cong:

   762     "A = B \<Longrightarrow> (\<And>x. x \<in> B =simp=> C x = D x) \<Longrightarrow> (\<Union>x\<in>A. C x) = (\<Union>x\<in>B. D x)"

   763   by (simp add: UNION_def simp_implies_def)

   764

   765 lemma image_eq_UN: "f  A = (\<Union>x\<in>A. {f x})"

   766   by blast

   767

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

   769   by (fact le_SUPI)

   770

   771 lemma UN_least: "(\<And>x. x \<in> A \<Longrightarrow> B x \<subseteq> C) \<Longrightarrow> (\<Union>x\<in>A. B x) \<subseteq> C"

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

   773

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

   775   by blast

   776

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

   778   by blast

   779

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

   781   by blast

   782

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

   784   by blast

   785

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

   787   by blast

   788

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

   790   by auto

   791

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

   793   by blast

   794

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

   796   by blast

   797

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

   799   by blast

   800

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

   802   by (fact SUP_le_iff)

   803

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

   805   by blast

   806

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

   808   by auto

   809

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

   811   by blast

   812

   813 lemma UNION_empty_conv[simp]:

   814   "{} = (\<Union>x\<in>A. B x) \<longleftrightarrow> (\<forall>x\<in>A. B x = {})"

   815   "(\<Union>x\<in>A. B x) = {} \<longleftrightarrow> (\<forall>x\<in>A. B x = {})"

   816 by blast+

   817

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

   819   by blast

   820

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

   822   by blast

   823

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

   825   by blast

   826

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

   828   by (auto simp add: split_if_mem2)

   829

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

   831   by (auto intro: bool_contrapos)

   832

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

   834   by blast

   835

   836 lemma UN_mono:

   837   "A \<subseteq> B \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> f x \<subseteq> g x) \<Longrightarrow>

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

   839   by (blast dest: subsetD)

   840

   841 lemma vimage_Union: "f - (\<Union>A) = (\<Union>X\<in>A. f - X)"

   842   by blast

   843

   844 lemma vimage_UN: "f - (\<Union>x\<in>A. B x) = (\<Union>x\<in>A. f - B x)"

   845   by blast

   846

   847 lemma vimage_eq_UN: "f - B = (\<Union>y\<in>B. f - {y})"

   848   -- {* NOT suitable for rewriting *}

   849   by blast

   850

   851 lemma image_UN: "f  UNION A B = (\<Union>x\<in>A. f  B x)"

   852   by blast

   853

   854

   855 subsection {* Distributive laws *}

   856

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

   858   by blast

   859

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

   861   by blast

   862

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

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

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

   866   by blast

   867

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

   869   -- {* Equivalent version *}

   870   by blast

   871

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

   873   by blast

   874

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

   876   by blast

   877

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

   879   -- {* Equivalent version *}

   880   by blast

   881

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

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

   884   by blast

   885

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

   887   by blast

   888

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

   890   by blast

   891

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

   893   by blast

   894

   895

   896 subsection {* Complement *}

   897

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

   899   by blast

   900

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

   902   by blast

   903

   904

   905 subsection {* Miniscoping and maxiscoping *}

   906

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

   908            and Intersections. *}

   909

   910 lemma UN_simps [simp]:

   911   "\<And>a B C. (\<Union>x\<in>C. insert a (B x)) = (if C={} then {} else insert a (\<Union>x\<in>C. B x))"

   912   "\<And>A B C. (\<Union>x\<in>C. A x \<union>  B) = ((if C={} then {} else (\<Union>x\<in>C. A x) \<union> B))"

   913   "\<And>A B C. (\<Union>x\<in>C. A \<union> B x) = ((if C={} then {} else A \<union> (\<Union>x\<in>C. B x)))"

   914   "\<And>A B C. (\<Union>x\<in>C. A x \<inter> B) = ((\<Union>x\<in>C. A x) \<inter>B)"

   915   "\<And>A B C. (\<Union>x\<in>C. A \<inter> B x) = (A \<inter>(\<Union>x\<in>C. B x))"

   916   "\<And>A B C. (\<Union>x\<in>C. A x - B) = ((\<Union>x\<in>C. A x) - B)"

   917   "\<And>A B C. (\<Union>x\<in>C. A - B x) = (A - (\<Inter>x\<in>C. B x))"

   918   "\<And>A B. (\<Union>x\<in>\<Union>A. B x) = (\<Union>y\<in>A. \<Union>x\<in>y. B x)"

   919   "\<And>A B C. (\<Union>z\<in>UNION A B. C z) = (\<Union>x\<in>A. \<Union>z\<in>B x. C z)"

   920   "\<And>A B f. (\<Union>x\<in>fA. B x) = (\<Union>a\<in>A. B (f a))"

   921   by auto

   922

   923 lemma INT_simps [simp]:

   924   "\<And>A B C. (\<Inter>x\<in>C. A x \<inter> B) = (if C={} then UNIV else (\<Inter>x\<in>C. A x) \<inter>B)"

   925   "\<And>A B C. (\<Inter>x\<in>C. A \<inter> B x) = (if C={} then UNIV else A \<inter>(\<Inter>x\<in>C. B x))"

   926   "\<And>A B C. (\<Inter>x\<in>C. A x - B) = (if C={} then UNIV else (\<Inter>x\<in>C. A x) - B)"

   927   "\<And>A B C. (\<Inter>x\<in>C. A - B x) = (if C={} then UNIV else A - (\<Union>x\<in>C. B x))"

   928   "\<And>a B C. (\<Inter>x\<in>C. insert a (B x)) = insert a (\<Inter>x\<in>C. B x)"

   929   "\<And>A B C. (\<Inter>x\<in>C. A x \<union> B) = ((\<Inter>x\<in>C. A x) \<union> B)"

   930   "\<And>A B C. (\<Inter>x\<in>C. A \<union> B x) = (A \<union> (\<Inter>x\<in>C. B x))"

   931   "\<And>A B. (\<Inter>x\<in>\<Union>A. B x) = (\<Inter>y\<in>A. \<Inter>x\<in>y. B x)"

   932   "\<And>A B C. (\<Inter>z\<in>UNION A B. C z) = (\<Inter>x\<in>A. \<Inter>z\<in>B x. C z)"

   933   "\<And>A B f. (\<Inter>x\<in>fA. B x) = (\<Inter>a\<in>A. B (f a))"

   934   by auto

   935

   936 lemma ball_simps [simp,no_atp]:

   937   "\<And>A P Q. (\<forall>x\<in>A. P x \<or> Q) \<longleftrightarrow> ((\<forall>x\<in>A. P x) \<or> Q)"

   938   "\<And>A P Q. (\<forall>x\<in>A. P \<or> Q x) \<longleftrightarrow> (P \<or> (\<forall>x\<in>A. Q x))"

   939   "\<And>A P Q. (\<forall>x\<in>A. P \<longrightarrow> Q x) \<longleftrightarrow> (P \<longrightarrow> (\<forall>x\<in>A. Q x))"

   940   "\<And>A P Q. (\<forall>x\<in>A. P x \<longrightarrow> Q) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<longrightarrow> Q)"

   941   "\<And>P. (\<forall>x\<in>{}. P x) \<longleftrightarrow> True"

   942   "\<And>P. (\<forall>x\<in>UNIV. P x) \<longleftrightarrow> (\<forall>x. P x)"

   943   "\<And>a B P. (\<forall>x\<in>insert a B. P x) \<longleftrightarrow> (P a \<and> (\<forall>x\<in>B. P x))"

   944   "\<And>A P. (\<forall>x\<in>\<Union>A. P x) \<longleftrightarrow> (\<forall>y\<in>A. \<forall>x\<in>y. P x)"

   945   "\<And>A B P. (\<forall>x\<in> UNION A B. P x) = (\<forall>a\<in>A. \<forall>x\<in> B a. P x)"

   946   "\<And>P Q. (\<forall>x\<in>Collect Q. P x) \<longleftrightarrow> (\<forall>x. Q x \<longrightarrow> P x)"

   947   "\<And>A P f. (\<forall>x\<in>fA. P x) \<longleftrightarrow> (\<forall>x\<in>A. P (f x))"

   948   "\<And>A P. (\<not> (\<forall>x\<in>A. P x)) \<longleftrightarrow> (\<exists>x\<in>A. \<not> P x)"

   949   by auto

   950

   951 lemma bex_simps [simp,no_atp]:

   952   "\<And>A P Q. (\<exists>x\<in>A. P x \<and> Q) \<longleftrightarrow> ((\<exists>x\<in>A. P x) \<and> Q)"

   953   "\<And>A P Q. (\<exists>x\<in>A. P \<and> Q x) \<longleftrightarrow> (P \<and> (\<exists>x\<in>A. Q x))"

   954   "\<And>P. (\<exists>x\<in>{}. P x) \<longleftrightarrow> False"

   955   "\<And>P. (\<exists>x\<in>UNIV. P x) \<longleftrightarrow> (\<exists>x. P x)"

   956   "\<And>a B P. (\<exists>x\<in>insert a B. P x) \<longleftrightarrow> (P a | (\<exists>x\<in>B. P x))"

   957   "\<And>A P. (\<exists>x\<in>\<Union>A. P x) \<longleftrightarrow> (\<exists>y\<in>A. \<exists>x\<in>y. P x)"

   958   "\<And>A B P. (\<exists>x\<in>UNION A B. P x) \<longleftrightarrow> (\<exists>a\<in>A. \<exists>x\<in>B a. P x)"

   959   "\<And>P Q. (\<exists>x\<in>Collect Q. P x) \<longleftrightarrow> (\<exists>x. Q x \<and> P x)"

   960   "\<And>A P f. (\<exists>x\<in>fA. P x) \<longleftrightarrow> (\<exists>x\<in>A. P (f x))"

   961   "\<And>A P. (\<not>(\<exists>x\<in>A. P x)) \<longleftrightarrow> (\<forall>x\<in>A. \<not> P x)"

   962   by auto

   963

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

   965

   966 lemma UN_extend_simps:

   967   "\<And>a B C. insert a (\<Union>x\<in>C. B x) = (if C={} then {a} else (\<Union>x\<in>C. insert a (B x)))"

   968   "\<And>A B C. (\<Union>x\<in>C. A x) \<union>  B  = (if C={} then B else (\<Union>x\<in>C. A x \<union>  B))"

   969   "\<And>A B C. A \<union> (\<Union>x\<in>C. B x) = (if C={} then A else (\<Union>x\<in>C. A \<union> B x))"

   970   "\<And>A B C. ((\<Union>x\<in>C. A x) \<inter> B) = (\<Union>x\<in>C. A x \<inter> B)"

   971   "\<And>A B C. (A \<inter> (\<Union>x\<in>C. B x)) = (\<Union>x\<in>C. A \<inter> B x)"

   972   "\<And>A B C. ((\<Union>x\<in>C. A x) - B) = (\<Union>x\<in>C. A x - B)"

   973   "\<And>A B C. (A - (\<Inter>x\<in>C. B x)) = (\<Union>x\<in>C. A - B x)"

   974   "\<And>A B. (\<Union>y\<in>A. \<Union>x\<in>y. B x) = (\<Union>x\<in>\<Union>A. B x)"

   975   "\<And>A B C. (\<Union>x\<in>A. \<Union>z\<in>B x. C z) = (\<Union>z\<in>UNION A B. C z)"

   976   "\<And>A B f. (\<Union>a\<in>A. B (f a)) = (\<Union>x\<in>fA. B x)"

   977   by auto

   978

   979 lemma INT_extend_simps:

   980   "\<And>A B C. (\<Inter>x\<in>C. A x) \<inter> B = (if C={} then B else (\<Inter>x\<in>C. A x \<inter> B))"

   981   "\<And>A B C. A \<inter> (\<Inter>x\<in>C. B x) = (if C={} then A else (\<Inter>x\<in>C. A \<inter> B x))"

   982   "\<And>A B C. (\<Inter>x\<in>C. A x) - B = (if C={} then UNIV - B else (\<Inter>x\<in>C. A x - B))"

   983   "\<And>A B C. A - (\<Union>x\<in>C. B x) = (if C={} then A else (\<Inter>x\<in>C. A - B x))"

   984   "\<And>a B C. insert a (\<Inter>x\<in>C. B x) = (\<Inter>x\<in>C. insert a (B x))"

   985   "\<And>A B C. ((\<Inter>x\<in>C. A x) \<union> B) = (\<Inter>x\<in>C. A x \<union> B)"

   986   "\<And>A B C. A \<union> (\<Inter>x\<in>C. B x) = (\<Inter>x\<in>C. A \<union> B x)"

   987   "\<And>A B. (\<Inter>y\<in>A. \<Inter>x\<in>y. B x) = (\<Inter>x\<in>\<Union>A. B x)"

   988   "\<And>A B C. (\<Inter>x\<in>A. \<Inter>z\<in>B x. C z) = (\<Inter>z\<in>UNION A B. C z)"

   989   "\<And>A B f. (\<Inter>a\<in>A. B (f a)) = (\<Inter>x\<in>fA. B x)"

   990   by auto

   991

   992

   993 no_notation

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

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

   996   bot ("\<bottom>") and

   997   top ("\<top>") and

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

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

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

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

  1002

  1003 no_syntax (xsymbols)

  1004   "_INF1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3\<Sqinter>_./ _)" [0, 10] 10)

  1005   "_INF"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Sqinter>_\<in>_./ _)" [0, 0, 10] 10)

  1006   "_SUP1"     :: "pttrns \<Rightarrow> 'b \<Rightarrow> 'b"           ("(3\<Squnion>_./ _)" [0, 10] 10)

  1007   "_SUP"      :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Squnion>_\<in>_./ _)" [0, 0, 10] 10)

  1008

  1009 lemmas mem_simps =

  1010   insert_iff empty_iff Un_iff Int_iff Compl_iff Diff_iff

  1011   mem_Collect_eq UN_iff Union_iff INT_iff Inter_iff

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

  1013

  1014 end
`