move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
1 (* Title: HOL/Library/Lubs_Glbs.thy
2 Author: Jacques D. Fleuriot, University of Cambridge
3 Author: Amine Chaieb, University of Cambridge *)
5 header {* Definitions of Least Upper Bounds and Greatest Lower Bounds *}
11 text {* Thanks to suggestions by James Margetson *}
13 definition setle :: "'a set \<Rightarrow> 'a::ord \<Rightarrow> bool" (infixl "*<=" 70)
14 where "S *<= x = (ALL y: S. y \<le> x)"
16 definition setge :: "'a::ord \<Rightarrow> 'a set \<Rightarrow> bool" (infixl "<=*" 70)
17 where "x <=* S = (ALL y: S. x \<le> y)"
20 subsection {* Rules for the Relations @{text "*<="} and @{text "<=*"} *}
22 lemma setleI: "ALL y: S. y \<le> x \<Longrightarrow> S *<= x"
23 by (simp add: setle_def)
25 lemma setleD: "S *<= x \<Longrightarrow> y: S \<Longrightarrow> y \<le> x"
26 by (simp add: setle_def)
28 lemma setgeI: "ALL y: S. x \<le> y \<Longrightarrow> x <=* S"
29 by (simp add: setge_def)
31 lemma setgeD: "x <=* S \<Longrightarrow> y: S \<Longrightarrow> x \<le> y"
32 by (simp add: setge_def)
35 definition leastP :: "('a \<Rightarrow> bool) \<Rightarrow> 'a::ord \<Rightarrow> bool"
36 where "leastP P x = (P x \<and> x <=* Collect P)"
38 definition isUb :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a::ord \<Rightarrow> bool"
39 where "isUb R S x = (S *<= x \<and> x: R)"
41 definition isLub :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a::ord \<Rightarrow> bool"
42 where "isLub R S x = leastP (isUb R S) x"
44 definition ubs :: "'a set \<Rightarrow> 'a::ord set \<Rightarrow> 'a set"
45 where "ubs R S = Collect (isUb R S)"
48 subsection {* Rules about the Operators @{term leastP}, @{term ub} and @{term lub} *}
50 lemma leastPD1: "leastP P x \<Longrightarrow> P x"
51 by (simp add: leastP_def)
53 lemma leastPD2: "leastP P x \<Longrightarrow> x <=* Collect P"
54 by (simp add: leastP_def)
56 lemma leastPD3: "leastP P x \<Longrightarrow> y: Collect P \<Longrightarrow> x \<le> y"
57 by (blast dest!: leastPD2 setgeD)
59 lemma isLubD1: "isLub R S x \<Longrightarrow> S *<= x"
60 by (simp add: isLub_def isUb_def leastP_def)
62 lemma isLubD1a: "isLub R S x \<Longrightarrow> x: R"
63 by (simp add: isLub_def isUb_def leastP_def)
65 lemma isLub_isUb: "isLub R S x \<Longrightarrow> isUb R S x"
66 unfolding isUb_def by (blast dest: isLubD1 isLubD1a)
68 lemma isLubD2: "isLub R S x \<Longrightarrow> y : S \<Longrightarrow> y \<le> x"
69 by (blast dest!: isLubD1 setleD)
71 lemma isLubD3: "isLub R S x \<Longrightarrow> leastP (isUb R S) x"
72 by (simp add: isLub_def)
74 lemma isLubI1: "leastP(isUb R S) x \<Longrightarrow> isLub R S x"
75 by (simp add: isLub_def)
77 lemma isLubI2: "isUb R S x \<Longrightarrow> x <=* Collect (isUb R S) \<Longrightarrow> isLub R S x"
78 by (simp add: isLub_def leastP_def)
80 lemma isUbD: "isUb R S x \<Longrightarrow> y : S \<Longrightarrow> y \<le> x"
81 by (simp add: isUb_def setle_def)
83 lemma isUbD2: "isUb R S x \<Longrightarrow> S *<= x"
84 by (simp add: isUb_def)
86 lemma isUbD2a: "isUb R S x \<Longrightarrow> x: R"
87 by (simp add: isUb_def)
89 lemma isUbI: "S *<= x \<Longrightarrow> x: R \<Longrightarrow> isUb R S x"
90 by (simp add: isUb_def)
92 lemma isLub_le_isUb: "isLub R S x \<Longrightarrow> isUb R S y \<Longrightarrow> x \<le> y"
93 unfolding isLub_def by (blast intro!: leastPD3)
95 lemma isLub_ubs: "isLub R S x \<Longrightarrow> x <=* ubs R S"
96 unfolding ubs_def isLub_def by (rule leastPD2)
98 lemma isLub_unique: "[| isLub R S x; isLub R S y |] ==> x = (y::'a::linorder)"
99 apply (frule isLub_isUb)
100 apply (frule_tac x = y in isLub_isUb)
101 apply (blast intro!: order_antisym dest!: isLub_le_isUb)
104 lemma isUb_UNIV_I: "(\<And>y. y \<in> S \<Longrightarrow> y \<le> u) \<Longrightarrow> isUb UNIV S u"
105 by (simp add: isUbI setleI)
108 definition greatestP :: "('a \<Rightarrow> bool) \<Rightarrow> 'a::ord \<Rightarrow> bool"
109 where "greatestP P x = (P x \<and> Collect P *<= x)"
111 definition isLb :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a::ord \<Rightarrow> bool"
112 where "isLb R S x = (x <=* S \<and> x: R)"
114 definition isGlb :: "'a set \<Rightarrow> 'a set \<Rightarrow> 'a::ord \<Rightarrow> bool"
115 where "isGlb R S x = greatestP (isLb R S) x"
117 definition lbs :: "'a set \<Rightarrow> 'a::ord set \<Rightarrow> 'a set"
118 where "lbs R S = Collect (isLb R S)"
121 subsection {* Rules about the Operators @{term greatestP}, @{term isLb} and @{term isGlb} *}
123 lemma greatestPD1: "greatestP P x \<Longrightarrow> P x"
124 by (simp add: greatestP_def)
126 lemma greatestPD2: "greatestP P x \<Longrightarrow> Collect P *<= x"
127 by (simp add: greatestP_def)
129 lemma greatestPD3: "greatestP P x \<Longrightarrow> y: Collect P \<Longrightarrow> x \<ge> y"
130 by (blast dest!: greatestPD2 setleD)
132 lemma isGlbD1: "isGlb R S x \<Longrightarrow> x <=* S"
133 by (simp add: isGlb_def isLb_def greatestP_def)
135 lemma isGlbD1a: "isGlb R S x \<Longrightarrow> x: R"
136 by (simp add: isGlb_def isLb_def greatestP_def)
138 lemma isGlb_isLb: "isGlb R S x \<Longrightarrow> isLb R S x"
139 unfolding isLb_def by (blast dest: isGlbD1 isGlbD1a)
141 lemma isGlbD2: "isGlb R S x \<Longrightarrow> y : S \<Longrightarrow> y \<ge> x"
142 by (blast dest!: isGlbD1 setgeD)
144 lemma isGlbD3: "isGlb R S x \<Longrightarrow> greatestP (isLb R S) x"
145 by (simp add: isGlb_def)
147 lemma isGlbI1: "greatestP (isLb R S) x \<Longrightarrow> isGlb R S x"
148 by (simp add: isGlb_def)
150 lemma isGlbI2: "isLb R S x \<Longrightarrow> Collect (isLb R S) *<= x \<Longrightarrow> isGlb R S x"
151 by (simp add: isGlb_def greatestP_def)
153 lemma isLbD: "isLb R S x \<Longrightarrow> y : S \<Longrightarrow> y \<ge> x"
154 by (simp add: isLb_def setge_def)
156 lemma isLbD2: "isLb R S x \<Longrightarrow> x <=* S "
157 by (simp add: isLb_def)
159 lemma isLbD2a: "isLb R S x \<Longrightarrow> x: R"
160 by (simp add: isLb_def)
162 lemma isLbI: "x <=* S \<Longrightarrow> x: R \<Longrightarrow> isLb R S x"
163 by (simp add: isLb_def)
165 lemma isGlb_le_isLb: "isGlb R S x \<Longrightarrow> isLb R S y \<Longrightarrow> x \<ge> y"
166 unfolding isGlb_def by (blast intro!: greatestPD3)
168 lemma isGlb_ubs: "isGlb R S x \<Longrightarrow> lbs R S *<= x"
169 unfolding lbs_def isGlb_def by (rule greatestPD2)
171 lemma isGlb_unique: "[| isGlb R S x; isGlb R S y |] ==> x = (y::'a::linorder)"
172 apply (frule isGlb_isLb)
173 apply (frule_tac x = y in isGlb_isLb)
174 apply (blast intro!: order_antisym dest!: isGlb_le_isLb)
177 lemma bdd_above_setle: "bdd_above A \<longleftrightarrow> (\<exists>a. A *<= a)"
178 by (auto simp: bdd_above_def setle_def)
180 lemma bdd_below_setge: "bdd_below A \<longleftrightarrow> (\<exists>a. a <=* A)"
181 by (auto simp: bdd_below_def setge_def)
184 "(S::'a :: conditionally_complete_lattice set) \<noteq> {} \<Longrightarrow> (\<exists>b. S *<= b) \<Longrightarrow> isLub UNIV S (Sup S)"
185 by (auto simp add: isLub_def setle_def leastP_def isUb_def
186 intro!: setgeI cSup_upper cSup_least)
189 "(S::'a :: conditionally_complete_lattice set) \<noteq> {} \<Longrightarrow> (\<exists>b. b <=* S) \<Longrightarrow> isGlb UNIV S (Inf S)"
190 by (auto simp add: isGlb_def setge_def greatestP_def isLb_def
191 intro!: setleI cInf_lower cInf_greatest)
193 lemma cSup_le: "(S::'a::conditionally_complete_lattice set) \<noteq> {} \<Longrightarrow> S *<= b \<Longrightarrow> Sup S \<le> b"
194 by (metis cSup_least setle_def)
196 lemma cInf_ge: "(S::'a :: conditionally_complete_lattice set) \<noteq> {} \<Longrightarrow> b <=* S \<Longrightarrow> Inf S \<ge> b"
197 by (metis cInf_greatest setge_def)
200 fixes S :: "'a :: conditionally_complete_lattice set"
201 shows "S \<noteq> {} \<Longrightarrow> a <=* S \<Longrightarrow> S *<= b \<Longrightarrow> a \<le> Sup S \<and> Sup S \<le> b"
202 using cSup_least[of S b] cSup_upper2[of _ S a]
203 by (auto simp: bdd_above_setle setge_def setle_def)
205 lemma cSup_unique: "(S::'a :: {conditionally_complete_linorder, no_bot} set) *<= b \<Longrightarrow> (\<forall>b'<b. \<exists>x\<in>S. b' < x) \<Longrightarrow> Sup S = b"
206 by (rule cSup_eq) (auto simp: not_le[symmetric] setle_def)
208 lemma cInf_unique: "b <=* (S::'a :: {conditionally_complete_linorder, no_top} set) \<Longrightarrow> (\<forall>b'>b. \<exists>x\<in>S. b' > x) \<Longrightarrow> Inf S = b"
209 by (rule cInf_eq) (auto simp: not_le[symmetric] setge_def)
211 text{* Use completeness of reals (supremum property) to show that any bounded sequence has a least upper bound*}
213 lemma reals_complete: "\<exists>X. X \<in> S \<Longrightarrow> \<exists>Y. isUb (UNIV::real set) S Y \<Longrightarrow> \<exists>t. isLub (UNIV :: real set) S t"
214 by (intro exI[of _ "Sup S"] isLub_cSup) (auto simp: setle_def isUb_def intro!: cSup_upper)
216 lemma Bseq_isUb: "\<And>X :: nat \<Rightarrow> real. Bseq X \<Longrightarrow> \<exists>U. isUb (UNIV::real set) {x. \<exists>n. X n = x} U"
217 by (auto intro: isUbI setleI simp add: Bseq_def abs_le_iff)
219 lemma Bseq_isLub: "\<And>X :: nat \<Rightarrow> real. Bseq X \<Longrightarrow> \<exists>U. isLub (UNIV::real set) {x. \<exists>n. X n = x} U"
220 by (blast intro: reals_complete Bseq_isUb)
222 lemma isLub_mono_imp_LIMSEQ:
223 fixes X :: "nat \<Rightarrow> real"
224 assumes u: "isLub UNIV {x. \<exists>n. X n = x} u" (* FIXME: use 'range X' *)
225 assumes X: "\<forall>m n. m \<le> n \<longrightarrow> X m \<le> X n"
228 have "X ----> (SUP i. X i)"
229 using u[THEN isLubD1] X
230 by (intro LIMSEQ_incseq_SUP) (auto simp: incseq_def image_def eq_commute bdd_above_setle)
231 also have "(SUP i. X i) = u"
232 using isLub_cSup[of "range X"] u[THEN isLubD1]
233 by (intro isLub_unique[OF _ u]) (auto simp add: SUP_def image_def eq_commute)
234 finally show ?thesis .
237 lemmas real_isGlb_unique = isGlb_unique[where 'a=real]
239 lemma real_le_inf_subset: "t \<noteq> {} \<Longrightarrow> t \<subseteq> s \<Longrightarrow> \<exists>b. b <=* s \<Longrightarrow> Inf s \<le> Inf (t::real set)"
240 by (rule cInf_superset_mono) (auto simp: bdd_below_setge)
242 lemma real_ge_sup_subset: "t \<noteq> {} \<Longrightarrow> t \<subseteq> s \<Longrightarrow> \<exists>b. s *<= b \<Longrightarrow> Sup s \<ge> Sup (t::real set)"
243 by (rule cSup_subset_mono) (auto simp: bdd_above_setle)