Theory Complete_Lattice

Up to index of Isabelle/HOL

theory Complete_Lattice
imports Set

(*  Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel; Florian Haftmann, TU Muenchen *)

header {* Complete lattices, with special focus on sets *}

theory Complete_Lattice
imports Set
begin

notation
  less_eq  (infix "\<sqsubseteq>" 50) and
  less (infix "\<sqsubset>" 50) and
  inf  (infixl "\<sqinter>" 70) and
  sup  (infixl "\<squnion>" 65) and
  top ("\<top>") and
  bot ("⊥")


subsection {* Syntactic infimum and supremum operations *}

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

class Sup =
  fixes Sup :: "'a set => 'a" ("\<Squnion>_" [900] 900)

subsection {* Abstract complete lattices *}

class complete_lattice = lattice + bot + top + Inf + Sup +
  assumes Inf_lower: "x ∈ A ==> \<Sqinter>A \<sqsubseteq> x"
     and Inf_greatest: "(!!x. x ∈ A ==> z \<sqsubseteq> x) ==> z \<sqsubseteq> \<Sqinter>A"
  assumes Sup_upper: "x ∈ A ==> x \<sqsubseteq> \<Squnion>A"
     and Sup_least: "(!!x. x ∈ A ==> x \<sqsubseteq> z) ==> \<Squnion>A \<sqsubseteq> z"
begin

lemma dual_complete_lattice:
  "complete_lattice Sup Inf (op ≥) (op >) (op \<squnion>) (op \<sqinter>) \<top> ⊥"
  by (auto intro!: complete_lattice.intro dual_lattice
    bot.intro top.intro dual_preorder, unfold_locales)
      (fact bot_least top_greatest
        Sup_upper Sup_least Inf_lower Inf_greatest)+

lemma Inf_Sup: "\<Sqinter>A = \<Squnion>{b. ∀a ∈ A. b ≤ a}"
  by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)

lemma Sup_Inf:  "\<Squnion>A = \<Sqinter>{b. ∀a ∈ A. a ≤ b}"
  by (auto intro: antisym Inf_lower Inf_greatest Sup_upper Sup_least)

lemma Inf_Univ: "\<Sqinter>UNIV = \<Squnion>{}"
  unfolding Sup_Inf by auto

lemma Sup_Univ: "\<Squnion>UNIV = \<Sqinter>{}"
  unfolding Inf_Sup by auto

lemma Inf_insert: "\<Sqinter>insert a A = a \<sqinter> \<Sqinter>A"
  by (auto intro: le_infI le_infI1 le_infI2 antisym Inf_greatest Inf_lower)

lemma Sup_insert: "\<Squnion>insert a A = a \<squnion> \<Squnion>A"
  by (auto intro: le_supI le_supI1 le_supI2 antisym Sup_least Sup_upper)

lemma Inf_singleton [simp]:
  "\<Sqinter>{a} = a"
  by (auto intro: antisym Inf_lower Inf_greatest)

lemma Sup_singleton [simp]:
  "\<Squnion>{a} = a"
  by (auto intro: antisym Sup_upper Sup_least)

lemma Inf_insert_simp:
  "\<Sqinter>insert a A = (if A = {} then a else a \<sqinter> \<Sqinter>A)"
  by (cases "A = {}") (simp_all, simp add: Inf_insert)

lemma Sup_insert_simp:
  "\<Squnion>insert a A = (if A = {} then a else a \<squnion> \<Squnion>A)"
  by (cases "A = {}") (simp_all, simp add: Sup_insert)

lemma Inf_binary:
  "\<Sqinter>{a, b} = a \<sqinter> b"
  by (auto simp add: Inf_insert_simp)

lemma Sup_binary:
  "\<Squnion>{a, b} = a \<squnion> b"
  by (auto simp add: Sup_insert_simp)

lemma bot_def:
  "bot = \<Squnion>{}"
  by (auto intro: antisym Sup_least)

lemma top_def:
  "top = \<Sqinter>{}"
  by (auto intro: antisym Inf_greatest)

lemma sup_bot [simp]:
  "x \<squnion> bot = x"
  using bot_least [of x] by (simp add: sup_commute sup_absorb2)

lemma inf_top [simp]:
  "x \<sqinter> top = x"
  using top_greatest [of x] by (simp add: inf_commute inf_absorb2)

definition SUPR :: "'b set => ('b => 'a) => 'a" where
  "SUPR A f = \<Squnion> (f ` A)"

definition INFI :: "'b set => ('b => 'a) => 'a" where
  "INFI A f = \<Sqinter> (f ` A)"

end

syntax
  "_SUP1"     :: "pttrns => 'b => 'b"           ("(3SUP _./ _)" [0, 10] 10)
  "_SUP"      :: "pttrn => 'a set => 'b => 'b"  ("(3SUP _:_./ _)" [0, 10] 10)
  "_INF1"     :: "pttrns => 'b => 'b"           ("(3INF _./ _)" [0, 10] 10)
  "_INF"      :: "pttrn => 'a set => 'b => 'b"  ("(3INF _:_./ _)" [0, 10] 10)

translations
  "SUP x y. B"   == "SUP x. SUP y. B"
  "SUP x. B"     == "CONST SUPR CONST UNIV (%x. B)"
  "SUP x. B"     == "SUP x:CONST UNIV. B"
  "SUP x:A. B"   == "CONST SUPR A (%x. B)"
  "INF x y. B"   == "INF x. INF y. B"
  "INF x. B"     == "CONST INFI CONST UNIV (%x. B)"
  "INF x. B"     == "INF x:CONST UNIV. B"
  "INF x:A. B"   == "CONST INFI A (%x. B)"

print_translation {* [
Syntax.preserve_binder_abs2_tr' @{const_syntax SUPR} "_SUP",
Syntax.preserve_binder_abs2_tr' @{const_syntax INFI} "_INF"
] *} -- {* to avoid eta-contraction of body *}

context complete_lattice
begin

lemma le_SUPI: "i : A ==> M i ≤ (SUP i:A. M i)"
  by (auto simp add: SUPR_def intro: Sup_upper)

lemma SUP_leI: "(!!i. i : A ==> M i ≤ u) ==> (SUP i:A. M i) ≤ u"
  by (auto simp add: SUPR_def intro: Sup_least)

lemma INF_leI: "i : A ==> (INF i:A. M i) ≤ M i"
  by (auto simp add: INFI_def intro: Inf_lower)

lemma le_INFI: "(!!i. i : A ==> u ≤ M i) ==> u ≤ (INF i:A. M i)"
  by (auto simp add: INFI_def intro: Inf_greatest)

lemma SUP_const[simp]: "A ≠ {} ==> (SUP i:A. M) = M"
  by (auto intro: antisym SUP_leI le_SUPI)

lemma INF_const[simp]: "A ≠ {} ==> (INF i:A. M) = M"
  by (auto intro: antisym INF_leI le_INFI)

end


subsection {* @{typ bool} and @{typ "_ => _"} as complete lattice *}

instantiation bool :: complete_lattice
begin

definition
  Inf_bool_def: "\<Sqinter>A <-> (∀x∈A. x)"

definition
  Sup_bool_def: "\<Squnion>A <-> (∃x∈A. x)"

instance proof
qed (auto simp add: Inf_bool_def Sup_bool_def le_bool_def)

end

lemma Inf_empty_bool [simp]:
  "\<Sqinter>{}"
  unfolding Inf_bool_def by auto

lemma not_Sup_empty_bool [simp]:
  "¬ \<Squnion>{}"
  unfolding Sup_bool_def by auto

lemma INFI_bool_eq:
  "INFI = Ball"
proof (rule ext)+
  fix A :: "'a set"
  fix P :: "'a => bool"
  show "(INF x:A. P x) <-> (∀x ∈ A. P x)"
    by (auto simp add: Ball_def INFI_def Inf_bool_def)
qed

lemma SUPR_bool_eq:
  "SUPR = Bex"
proof (rule ext)+
  fix A :: "'a set"
  fix P :: "'a => bool"
  show "(SUP x:A. P x) <-> (∃x ∈ A. P x)"
    by (auto simp add: Bex_def SUPR_def Sup_bool_def)
qed

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

definition
  Inf_fun_def [code del]: "\<Sqinter>A = (λx. \<Sqinter>{y. ∃f∈A. y = f x})"

definition
  Sup_fun_def [code del]: "\<Squnion>A = (λx. \<Squnion>{y. ∃f∈A. y = f x})"

instance proof
qed (auto simp add: Inf_fun_def Sup_fun_def le_fun_def
  intro: Inf_lower Sup_upper Inf_greatest Sup_least)

end

lemma Inf_empty_fun:
  "\<Sqinter>{} = (λ_. \<Sqinter>{})"
  by (simp add: Inf_fun_def)

lemma Sup_empty_fun:
  "\<Squnion>{} = (λ_. \<Squnion>{})"
  by (simp add: Sup_fun_def)


subsection {* Union *}

abbreviation Union :: "'a set set => 'a set" where
  "Union S ≡ \<Squnion>S"

notation (xsymbols)
  Union  ("\<Union>_" [90] 90)

lemma Union_eq:
  "\<Union>A = {x. ∃B ∈ A. x ∈ B}"
proof (rule set_ext)
  fix x
  have "(∃Q∈{P. ∃B∈A. P <-> x ∈ B}. Q) <-> (∃B∈A. x ∈ B)"
    by auto
  then show "x ∈ \<Union>A <-> x ∈ {x. ∃B∈A. x ∈ B}"
    by (simp add: Sup_fun_def Sup_bool_def) (simp add: mem_def)
qed

lemma Union_iff [simp, noatp]:
  "A ∈ \<Union>C <-> (∃X∈C. A∈X)"
  by (unfold Union_eq) blast

lemma UnionI [intro]:
  "X ∈ C ==> A ∈ X ==> A ∈ \<Union>C"
  -- {* The order of the premises presupposes that @{term C} is rigid;
    @{term A} may be flexible. *}
  by auto

lemma UnionE [elim!]:
  "A ∈ \<Union>C ==> (!!X. A∈X ==> X∈C ==> R) ==> R"
  by auto

lemma Union_upper: "B ∈ A ==> B ⊆ Union A"
  by (iprover intro: subsetI UnionI)

lemma Union_least: "(!!X. X ∈ A ==> X ⊆ C) ==> Union A ⊆ C"
  by (iprover intro: subsetI elim: UnionE dest: subsetD)

lemma Un_eq_Union: "A ∪ B = \<Union>{A, B}"
  by blast

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

lemma Union_UNIV [simp]: "Union UNIV = UNIV"
  by blast

lemma Union_insert [simp]: "Union (insert a B) = a ∪ \<Union>B"
  by blast

lemma Union_Un_distrib [simp]: "\<Union>(A Un B) = \<Union>A ∪ \<Union>B"
  by blast

lemma Union_Int_subset: "\<Union>(A ∩ B) ⊆ \<Union>A ∩ \<Union>B"
  by blast

lemma Union_empty_conv [simp,noatp]: "(\<Union>A = {}) = (∀x∈A. x = {})"
  by blast

lemma empty_Union_conv [simp,noatp]: "({} = \<Union>A) = (∀x∈A. x = {})"
  by blast

lemma Union_disjoint: "(\<Union>C ∩ A = {}) = (∀B∈C. B ∩ A = {})"
  by blast

lemma subset_Pow_Union: "A ⊆ Pow (\<Union>A)"
  by blast

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

lemma Union_mono: "A ⊆ B ==> \<Union>A ⊆ \<Union>B"
  by blast


subsection {* Unions of families *}

abbreviation UNION :: "'a set => ('a => 'b set) => 'b set" where
  "UNION ≡ SUPR"

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

syntax (xsymbols)
  "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>_./ _)" [0, 10] 10)
  "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>_∈_./ _)" [0, 10] 10)

syntax (latex output)
  "@UNION1"     :: "pttrns => 'b set => 'b set"           ("(3\<Union>(00_)/ _)" [0, 10] 10)
  "@UNION"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Union>(00_∈_)/ _)" [0, 10] 10)

translations
  "UN x y. B"   == "UN x. UN y. B"
  "UN x. B"     == "CONST UNION CONST UNIV (%x. B)"
  "UN x. B"     == "UN x:CONST UNIV. B"
  "UN x:A. B"   == "CONST UNION A (%x. B)"

text {*
  Note the difference between ordinary xsymbol syntax of indexed
  unions and intersections (e.g.\ @{text"\<Union>a1∈A1. B"})
  and their \LaTeX\ rendition: @{term"\<Union>a1∈A1. B"}. The
  former does not make the index expression a subscript of the
  union/intersection symbol because this leads to problems with nested
  subscripts in Proof General.
*}

print_translation {* [
Syntax.preserve_binder_abs2_tr' @{const_syntax UNION} "@UNION"
] *} -- {* to avoid eta-contraction of body *}

lemma UNION_eq_Union_image:
  "(\<Union>x∈A. B x) = \<Union>(B`A)"
  by (fact SUPR_def)

lemma Union_def:
  "\<Union>S = (\<Union>x∈S. x)"
  by (simp add: UNION_eq_Union_image image_def)

lemma UNION_def [noatp]:
  "(\<Union>x∈A. B x) = {y. ∃x∈A. y ∈ B x}"
  by (auto simp add: UNION_eq_Union_image Union_eq)
  
lemma Union_image_eq [simp]:
  "\<Union>(B`A) = (\<Union>x∈A. B x)"
  by (rule sym) (fact UNION_eq_Union_image)
  
lemma UN_iff [simp]: "(b: (UN x:A. B x)) = (EX x:A. b: B x)"
  by (unfold UNION_def) blast

lemma UN_I [intro]: "a:A ==> b: B a ==> b: (UN x:A. B x)"
  -- {* The order of the premises presupposes that @{term A} is rigid;
    @{term b} may be flexible. *}
  by auto

lemma UN_E [elim!]: "b : (UN x:A. B x) ==> (!!x. x:A ==> b: B x ==> R) ==> R"
  by (unfold UNION_def) blast

lemma UN_cong [cong]:
    "A = B ==> (!!x. x:B ==> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"
  by (simp add: UNION_def)

lemma strong_UN_cong:
    "A = B ==> (!!x. x:B =simp=> C x = D x) ==> (UN x:A. C x) = (UN x:B. D x)"
  by (simp add: UNION_def simp_implies_def)

lemma image_eq_UN: "f`A = (UN x:A. {f x})"
  by blast

lemma UN_upper: "a ∈ A ==> B a ⊆ (\<Union>x∈A. B x)"
  by (fact le_SUPI)

lemma UN_least: "(!!x. x ∈ A ==> B x ⊆ C) ==> (\<Union>x∈A. B x) ⊆ C"
  by (iprover intro: subsetI elim: UN_E dest: subsetD)

lemma Collect_bex_eq [noatp]: "{x. ∃y∈A. P x y} = (\<Union>y∈A. {x. P x y})"
  by blast

lemma UN_insert_distrib: "u ∈ A ==> (\<Union>x∈A. insert a (B x)) = insert a (\<Union>x∈A. B x)"
  by blast

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

lemma UN_empty2 [simp]: "(\<Union>x∈A. {}) = {}"
  by blast

lemma UN_singleton [simp]: "(\<Union>x∈A. {x}) = A"
  by blast

lemma UN_absorb: "k ∈ I ==> A k ∪ (\<Union>i∈I. A i) = (\<Union>i∈I. A i)"
  by auto

lemma UN_insert [simp]: "(\<Union>x∈insert a A. B x) = B a ∪ UNION A B"
  by blast

lemma UN_Un[simp]: "(\<Union>i ∈ A ∪ B. M i) = (\<Union>i∈A. M i) ∪ (\<Union>i∈B. M i)"
  by blast

lemma UN_UN_flatten: "(\<Union>x ∈ (\<Union>y∈A. B y). C x) = (\<Union>y∈A. \<Union>x∈B y. C x)"
  by blast

lemma UN_subset_iff: "((\<Union>i∈I. A i) ⊆ B) = (∀i∈I. A i ⊆ B)"
  by blast

lemma image_Union: "f ` \<Union>S = (\<Union>x∈S. f ` x)"
  by blast

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

lemma UN_eq: "(\<Union>x∈A. B x) = \<Union>({Y. ∃x∈A. Y = B x})"
  by blast

lemma UNION_empty_conv[simp]:
  "({} = (UN x:A. B x)) = (∀x∈A. B x = {})"
  "((UN x:A. B x) = {}) = (∀x∈A. B x = {})"
by blast+

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

lemma ball_UN: "(∀z ∈ UNION A B. P z) = (∀x∈A. ∀z ∈ B x. P z)"
  by blast

lemma bex_UN: "(∃z ∈ UNION A B. P z) = (∃x∈A. ∃z∈B x. P z)"
  by blast

lemma Un_eq_UN: "A ∪ B = (\<Union>b. if b then A else B)"
  by (auto simp add: split_if_mem2)

lemma UN_bool_eq: "(\<Union>b::bool. A b) = (A True ∪ A False)"
  by (auto intro: bool_contrapos)

lemma UN_Pow_subset: "(\<Union>x∈A. Pow (B x)) ⊆ Pow (\<Union>x∈A. B x)"
  by blast

lemma UN_mono:
  "A ⊆ B ==> (!!x. x ∈ A ==> f x ⊆ g x) ==>
    (\<Union>x∈A. f x) ⊆ (\<Union>x∈B. g x)"
  by (blast dest: subsetD)

lemma vimage_Union: "f -` (Union A) = (UN X:A. f -` X)"
  by blast

lemma vimage_UN: "f-`(UN x:A. B x) = (UN x:A. f -` B x)"
  by blast

lemma vimage_eq_UN: "f-`B = (UN y: B. f-`{y})"
  -- {* NOT suitable for rewriting *}
  by blast

lemma image_UN: "(f ` (UNION A B)) = (UN x:A.(f ` (B x)))"
by blast


subsection {* Inter *}

abbreviation Inter :: "'a set set => 'a set" where
  "Inter S ≡ \<Sqinter>S"
  
notation (xsymbols)
  Inter  ("\<Inter>_" [90] 90)

lemma Inter_eq [code del]:
  "\<Inter>A = {x. ∀B ∈ A. x ∈ B}"
proof (rule set_ext)
  fix x
  have "(∀Q∈{P. ∃B∈A. P <-> x ∈ B}. Q) <-> (∀B∈A. x ∈ B)"
    by auto
  then show "x ∈ \<Inter>A <-> x ∈ {x. ∀B ∈ A. x ∈ B}"
    by (simp add: Inf_fun_def Inf_bool_def) (simp add: mem_def)
qed

lemma Inter_iff [simp,noatp]: "(A : Inter C) = (ALL X:C. A:X)"
  by (unfold Inter_eq) blast

lemma InterI [intro!]: "(!!X. X:C ==> A:X) ==> A : Inter C"
  by (simp add: Inter_eq)

text {*
  \medskip A ``destruct'' rule -- every @{term X} in @{term C}
  contains @{term A} as an element, but @{prop "A:X"} can hold when
  @{prop "X:C"} does not!  This rule is analogous to @{text spec}.
*}

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

lemma InterE [elim]: "A : Inter C ==> (X~:C ==> R) ==> (A:X ==> R) ==> R"
  -- {* ``Classical'' elimination rule -- does not require proving
    @{prop "X:C"}. *}
  by (unfold Inter_eq) blast

lemma Inter_lower: "B ∈ A ==> Inter A ⊆ B"
  by blast

lemma Inter_subset:
  "[| !!X. X ∈ A ==> X ⊆ B; A ~= {} |] ==> \<Inter>A ⊆ B"
  by blast

lemma Inter_greatest: "(!!X. X ∈ A ==> C ⊆ X) ==> C ⊆ Inter A"
  by (iprover intro: InterI subsetI dest: subsetD)

lemma Int_eq_Inter: "A ∩ B = \<Inter>{A, B}"
  by blast

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

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

lemma Inter_insert [simp]: "\<Inter>(insert a B) = a ∩ \<Inter>B"
  by blast

lemma Inter_Un_subset: "\<Inter>A ∪ \<Inter>B ⊆ \<Inter>(A ∩ B)"
  by blast

lemma Inter_Un_distrib: "\<Inter>(A ∪ B) = \<Inter>A ∩ \<Inter>B"
  by blast

lemma Inter_UNIV_conv [simp,noatp]:
  "(\<Inter>A = UNIV) = (∀x∈A. x = UNIV)"
  "(UNIV = \<Inter>A) = (∀x∈A. x = UNIV)"
  by blast+

lemma Inter_anti_mono: "B ⊆ A ==> \<Inter>A ⊆ \<Inter>B"
  by blast


subsection {* Intersections of families *}

abbreviation INTER :: "'a set => ('a => 'b set) => 'b set" where
  "INTER ≡ INFI"

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

syntax (xsymbols)
  "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>_./ _)" [0, 10] 10)
  "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>_∈_./ _)" [0, 10] 10)

syntax (latex output)
  "@INTER1"     :: "pttrns => 'b set => 'b set"           ("(3\<Inter>(00_)/ _)" [0, 10] 10)
  "@INTER"      :: "pttrn => 'a set => 'b set => 'b set"  ("(3\<Inter>(00_∈_)/ _)" [0, 10] 10)

translations
  "INT x y. B"  == "INT x. INT y. B"
  "INT x. B"    == "CONST INTER CONST UNIV (%x. B)"
  "INT x. B"    == "INT x:CONST UNIV. B"
  "INT x:A. B"  == "CONST INTER A (%x. B)"

print_translation {* [
Syntax.preserve_binder_abs2_tr' @{const_syntax INTER} "@INTER"
] *} -- {* to avoid eta-contraction of body *}

lemma INTER_eq_Inter_image:
  "(\<Inter>x∈A. B x) = \<Inter>(B`A)"
  by (fact INFI_def)
  
lemma Inter_def:
  "\<Inter>S = (\<Inter>x∈S. x)"
  by (simp add: INTER_eq_Inter_image image_def)

lemma INTER_def:
  "(\<Inter>x∈A. B x) = {y. ∀x∈A. y ∈ B x}"
  by (auto simp add: INTER_eq_Inter_image Inter_eq)

lemma Inter_image_eq [simp]:
  "\<Inter>(B`A) = (\<Inter>x∈A. B x)"
  by (rule sym) (fact INTER_eq_Inter_image)

lemma INT_iff [simp]: "(b: (INT x:A. B x)) = (ALL x:A. b: B x)"
  by (unfold INTER_def) blast

lemma INT_I [intro!]: "(!!x. x:A ==> b: B x) ==> b : (INT x:A. B x)"
  by (unfold INTER_def) blast

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

lemma INT_E [elim]: "b : (INT x:A. B x) ==> (b: B a ==> R) ==> (a~:A ==> R) ==> R"
  -- {* "Classical" elimination -- by the Excluded Middle on @{prop "a:A"}. *}
  by (unfold INTER_def) blast

lemma INT_cong [cong]:
    "A = B ==> (!!x. x:B ==> C x = D x) ==> (INT x:A. C x) = (INT x:B. D x)"
  by (simp add: INTER_def)

lemma Collect_ball_eq: "{x. ∀y∈A. P x y} = (\<Inter>y∈A. {x. P x y})"
  by blast

lemma Collect_all_eq: "{x. ∀y. P x y} = (\<Inter>y. {x. P x y})"
  by blast

lemma INT_lower: "a ∈ A ==> (\<Inter>x∈A. B x) ⊆ B a"
  by (fact INF_leI)

lemma INT_greatest: "(!!x. x ∈ A ==> C ⊆ B x) ==> C ⊆ (\<Inter>x∈A. B x)"
  by (fact le_INFI)

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

lemma INT_absorb: "k ∈ I ==> A k ∩ (\<Inter>i∈I. A i) = (\<Inter>i∈I. A i)"
  by blast

lemma INT_subset_iff: "(B ⊆ (\<Inter>i∈I. A i)) = (∀i∈I. B ⊆ A i)"
  by blast

lemma INT_insert [simp]: "(\<Inter>x ∈ insert a A. B x) = B a ∩ INTER A B"
  by blast

lemma INT_Un: "(\<Inter>i ∈ A ∪ B. M i) = (\<Inter>i ∈ A. M i) ∩ (\<Inter>i∈B. M i)"
  by blast

lemma INT_insert_distrib:
    "u ∈ A ==> (\<Inter>x∈A. insert a (B x)) = insert a (\<Inter>x∈A. B x)"
  by blast

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

lemma INT_eq: "(\<Inter>x∈A. B x) = \<Inter>({Y. ∃x∈A. Y = B x})"
  -- {* Look: it has an \emph{existential} quantifier *}
  by blast

lemma INTER_UNIV_conv[simp]:
 "(UNIV = (INT x:A. B x)) = (∀x∈A. B x = UNIV)"
 "((INT x:A. B x) = UNIV) = (∀x∈A. B x = UNIV)"
by blast+

lemma INT_bool_eq: "(\<Inter>b::bool. A b) = (A True ∩ A False)"
  by (auto intro: bool_induct)

lemma Pow_INT_eq: "Pow (\<Inter>x∈A. B x) = (\<Inter>x∈A. Pow (B x))"
  by blast

lemma INT_anti_mono:
  "B ⊆ A ==> (!!x. x ∈ A ==> f x ⊆ g x) ==>
    (\<Inter>x∈A. f x) ⊆ (\<Inter>x∈A. g x)"
  -- {* The last inclusion is POSITIVE! *}
  by (blast dest: subsetD)

lemma vimage_INT: "f-`(INT x:A. B x) = (INT x:A. f -` B x)"
  by blast


subsection {* Distributive laws *}

lemma Int_Union: "A ∩ \<Union>B = (\<Union>C∈B. A ∩ C)"
  by blast

lemma Int_Union2: "\<Union>B ∩ A = (\<Union>C∈B. C ∩ A)"
  by blast

lemma Un_Union_image: "(\<Union>x∈C. A x ∪ B x) = \<Union>(A`C) ∪ \<Union>(B`C)"
  -- {* Devlin, Fundamentals of Contemporary Set Theory, page 12, exercise 5: *}
  -- {* Union of a family of unions *}
  by blast

lemma UN_Un_distrib: "(\<Union>i∈I. A i ∪ B i) = (\<Union>i∈I. A i) ∪ (\<Union>i∈I. B i)"
  -- {* Equivalent version *}
  by blast

lemma Un_Inter: "A ∪ \<Inter>B = (\<Inter>C∈B. A ∪ C)"
  by blast

lemma Int_Inter_image: "(\<Inter>x∈C. A x ∩ B x) = \<Inter>(A`C) ∩ \<Inter>(B`C)"
  by blast

lemma INT_Int_distrib: "(\<Inter>i∈I. A i ∩ B i) = (\<Inter>i∈I. A i) ∩ (\<Inter>i∈I. B i)"
  -- {* Equivalent version *}
  by blast

lemma Int_UN_distrib: "B ∩ (\<Union>i∈I. A i) = (\<Union>i∈I. B ∩ A i)"
  -- {* Halmos, Naive Set Theory, page 35. *}
  by blast

lemma Un_INT_distrib: "B ∪ (\<Inter>i∈I. A i) = (\<Inter>i∈I. B ∪ A i)"
  by blast

lemma Int_UN_distrib2: "(\<Union>i∈I. A i) ∩ (\<Union>j∈J. B j) = (\<Union>i∈I. \<Union>j∈J. A i ∩ B j)"
  by blast

lemma Un_INT_distrib2: "(\<Inter>i∈I. A i) ∪ (\<Inter>j∈J. B j) = (\<Inter>i∈I. \<Inter>j∈J. A i ∪ B j)"
  by blast


subsection {* Complement *}

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

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


subsection {* Miniscoping and maxiscoping *}

text {* \medskip Miniscoping: pushing in quantifiers and big Unions
           and Intersections. *}

lemma UN_simps [simp]:
  "!!a B C. (UN x:C. insert a (B x)) = (if C={} then {} else insert a (UN x:C. B x))"
  "!!A B C. (UN x:C. A x Un B)   = ((if C={} then {} else (UN x:C. A x) Un B))"
  "!!A B C. (UN x:C. A Un B x)   = ((if C={} then {} else A Un (UN x:C. B x)))"
  "!!A B C. (UN x:C. A x Int B)  = ((UN x:C. A x) Int B)"
  "!!A B C. (UN x:C. A Int B x)  = (A Int (UN x:C. B x))"
  "!!A B C. (UN x:C. A x - B)    = ((UN x:C. A x) - B)"
  "!!A B C. (UN x:C. A - B x)    = (A - (INT x:C. B x))"
  "!!A B. (UN x: Union A. B x) = (UN y:A. UN x:y. B x)"
  "!!A B C. (UN z: UNION A B. C z) = (UN  x:A. UN z: B(x). C z)"
  "!!A B f. (UN x:f`A. B x)     = (UN a:A. B (f a))"
  by auto

lemma INT_simps [simp]:
  "!!A B C. (INT x:C. A x Int B) = (if C={} then UNIV else (INT x:C. A x) Int B)"
  "!!A B C. (INT x:C. A Int B x) = (if C={} then UNIV else A Int (INT x:C. B x))"
  "!!A B C. (INT x:C. A x - B)   = (if C={} then UNIV else (INT x:C. A x) - B)"
  "!!A B C. (INT x:C. A - B x)   = (if C={} then UNIV else A - (UN x:C. B x))"
  "!!a B C. (INT x:C. insert a (B x)) = insert a (INT x:C. B x)"
  "!!A B C. (INT x:C. A x Un B)  = ((INT x:C. A x) Un B)"
  "!!A B C. (INT x:C. A Un B x)  = (A Un (INT x:C. B x))"
  "!!A B. (INT x: Union A. B x) = (INT y:A. INT x:y. B x)"
  "!!A B C. (INT z: UNION A B. C z) = (INT x:A. INT z: B(x). C z)"
  "!!A B f. (INT x:f`A. B x)    = (INT a:A. B (f a))"
  by auto

lemma ball_simps [simp,noatp]:
  "!!A P Q. (ALL x:A. P x | Q) = ((ALL x:A. P x) | Q)"
  "!!A P Q. (ALL x:A. P | Q x) = (P | (ALL x:A. Q x))"
  "!!A P Q. (ALL x:A. P --> Q x) = (P --> (ALL x:A. Q x))"
  "!!A P Q. (ALL x:A. P x --> Q) = ((EX x:A. P x) --> Q)"
  "!!P. (ALL x:{}. P x) = True"
  "!!P. (ALL x:UNIV. P x) = (ALL x. P x)"
  "!!a B P. (ALL x:insert a B. P x) = (P a & (ALL x:B. P x))"
  "!!A P. (ALL x:Union A. P x) = (ALL y:A. ALL x:y. P x)"
  "!!A B P. (ALL x: UNION A B. P x) = (ALL a:A. ALL x: B a. P x)"
  "!!P Q. (ALL x:Collect Q. P x) = (ALL x. Q x --> P x)"
  "!!A P f. (ALL x:f`A. P x) = (ALL x:A. P (f x))"
  "!!A P. (~(ALL x:A. P x)) = (EX x:A. ~P x)"
  by auto

lemma bex_simps [simp,noatp]:
  "!!A P Q. (EX x:A. P x & Q) = ((EX x:A. P x) & Q)"
  "!!A P Q. (EX x:A. P & Q x) = (P & (EX x:A. Q x))"
  "!!P. (EX x:{}. P x) = False"
  "!!P. (EX x:UNIV. P x) = (EX x. P x)"
  "!!a B P. (EX x:insert a B. P x) = (P(a) | (EX x:B. P x))"
  "!!A P. (EX x:Union A. P x) = (EX y:A. EX x:y. P x)"
  "!!A B P. (EX x: UNION A B. P x) = (EX a:A. EX x:B a. P x)"
  "!!P Q. (EX x:Collect Q. P x) = (EX x. Q x & P x)"
  "!!A P f. (EX x:f`A. P x) = (EX x:A. P (f x))"
  "!!A P. (~(EX x:A. P x)) = (ALL x:A. ~P x)"
  by auto

lemma ball_conj_distrib:
  "(ALL x:A. P x & Q x) = ((ALL x:A. P x) & (ALL x:A. Q x))"
  by blast

lemma bex_disj_distrib:
  "(EX x:A. P x | Q x) = ((EX x:A. P x) | (EX x:A. Q x))"
  by blast


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

lemma UN_extend_simps:
  "!!a B C. insert a (UN x:C. B x) = (if C={} then {a} else (UN x:C. insert a (B x)))"
  "!!A B C. (UN x:C. A x) Un B    = (if C={} then B else (UN x:C. A x Un B))"
  "!!A B C. A Un (UN x:C. B x)   = (if C={} then A else (UN x:C. A Un B x))"
  "!!A B C. ((UN x:C. A x) Int B) = (UN x:C. A x Int B)"
  "!!A B C. (A Int (UN x:C. B x)) = (UN x:C. A Int B x)"
  "!!A B C. ((UN x:C. A x) - B) = (UN x:C. A x - B)"
  "!!A B C. (A - (INT x:C. B x)) = (UN x:C. A - B x)"
  "!!A B. (UN y:A. UN x:y. B x) = (UN x: Union A. B x)"
  "!!A B C. (UN  x:A. UN z: B(x). C z) = (UN z: UNION A B. C z)"
  "!!A B f. (UN a:A. B (f a)) = (UN x:f`A. B x)"
  by auto

lemma INT_extend_simps:
  "!!A B C. (INT x:C. A x) Int B = (if C={} then B else (INT x:C. A x Int B))"
  "!!A B C. A Int (INT x:C. B x) = (if C={} then A else (INT x:C. A Int B x))"
  "!!A B C. (INT x:C. A x) - B   = (if C={} then UNIV-B else (INT x:C. A x - B))"
  "!!A B C. A - (UN x:C. B x)   = (if C={} then A else (INT x:C. A - B x))"
  "!!a B C. insert a (INT x:C. B x) = (INT x:C. insert a (B x))"
  "!!A B C. ((INT x:C. A x) Un B)  = (INT x:C. A x Un B)"
  "!!A B C. A Un (INT x:C. B x)  = (INT x:C. A Un B x)"
  "!!A B. (INT y:A. INT x:y. B x) = (INT x: Union A. B x)"
  "!!A B C. (INT x:A. INT z: B(x). C z) = (INT z: UNION A B. C z)"
  "!!A B f. (INT a:A. B (f a))    = (INT x:f`A. B x)"
  by auto


no_notation
  less_eq  (infix "\<sqsubseteq>" 50) and
  less (infix "\<sqsubset>" 50) and
  inf  (infixl "\<sqinter>" 70) and
  sup  (infixl "\<squnion>" 65) and
  Inf  ("\<Sqinter>_" [900] 900) and
  Sup  ("\<Squnion>_" [900] 900) and
  top ("\<top>") and
  bot ("⊥")

lemmas mem_simps =
  insert_iff empty_iff Un_iff Int_iff Compl_iff Diff_iff
  mem_Collect_eq UN_iff Union_iff INT_iff Inter_iff
  -- {* Each of these has ALREADY been added @{text "[simp]"} above. *}

end