src/HOL/Real/RComplete.thy
 changeset 14641 79b7bd936264 parent 14476 758e7acdea2f child 15131 c69542757a4d
```     1.1 --- a/src/HOL/Real/RComplete.thy	Thu Apr 22 10:43:06 2004 +0200
1.2 +++ b/src/HOL/Real/RComplete.thy	Thu Apr 22 10:45:56 2004 +0200
1.3 @@ -2,11 +2,11 @@
1.4      ID          : \$Id\$
1.5      Author      : Jacques D. Fleuriot
1.6      Copyright   : 1998  University of Cambridge
1.7 -    Description : Completeness theorems for positive
1.8 -                  reals and reals
1.9 +    Copyright   : 2001,2002  University of Edinburgh
1.10 +Converted to Isar and polished by lcp
1.11  *)
1.12
1.13 -header{*Completeness Theorems for Positive Reals and Reals.*}
1.14 +header{*Completeness of the Reals; Floor and Ceiling Functions*}
1.15
1.16  theory RComplete = Lubs + RealDef:
1.17
1.18 @@ -215,7 +215,322 @@
1.19  val reals_Archimedean3 = thm "reals_Archimedean3";
1.20  *}
1.21
1.22 +
1.23 +subsection{*Floor and Ceiling Functions from the Reals to the Integers*}
1.24 +
1.25 +constdefs
1.26 +
1.27 +  floor :: "real => int"
1.28 +   "floor r == (LEAST n::int. r < real (n+1))"
1.29 +
1.30 +  ceiling :: "real => int"
1.31 +    "ceiling r == - floor (- r)"
1.32 +
1.33 +syntax (xsymbols)
1.34 +  floor :: "real => int"     ("\<lfloor>_\<rfloor>")
1.35 +  ceiling :: "real => int"   ("\<lceil>_\<rceil>")
1.36 +
1.37 +syntax (HTML output)
1.38 +  floor :: "real => int"     ("\<lfloor>_\<rfloor>")
1.39 +  ceiling :: "real => int"   ("\<lceil>_\<rceil>")
1.40 +
1.41 +
1.42 +lemma number_of_less_real_of_int_iff [simp]:
1.43 +     "((number_of n) < real (m::int)) = (number_of n < m)"
1.44 +apply auto
1.45 +apply (rule real_of_int_less_iff [THEN iffD1])
1.46 +apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
1.47 +done
1.48 +
1.49 +lemma number_of_less_real_of_int_iff2 [simp]:
1.50 +     "(real (m::int) < (number_of n)) = (m < number_of n)"
1.51 +apply auto
1.52 +apply (rule real_of_int_less_iff [THEN iffD1])
1.53 +apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
1.54 +done
1.55 +
1.56 +lemma number_of_le_real_of_int_iff [simp]:
1.57 +     "((number_of n) \<le> real (m::int)) = (number_of n \<le> m)"
1.58 +by (simp add: linorder_not_less [symmetric])
1.59 +
1.60 +lemma number_of_le_real_of_int_iff2 [simp]:
1.61 +     "(real (m::int) \<le> (number_of n)) = (m \<le> number_of n)"
1.62 +by (simp add: linorder_not_less [symmetric])
1.63 +
1.64 +lemma floor_zero [simp]: "floor 0 = 0"
1.66 +apply (rule Least_equality, auto)
1.67 +done
1.68 +
1.69 +lemma floor_real_of_nat_zero [simp]: "floor (real (0::nat)) = 0"
1.70 +by auto
1.71 +
1.72 +lemma floor_real_of_nat [simp]: "floor (real (n::nat)) = int n"
1.73 +apply (simp only: floor_def)
1.74 +apply (rule Least_equality)
1.75 +apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
1.76 +apply (drule_tac [2] real_of_int_less_iff [THEN iffD1])
1.78 +done
1.79 +
1.80 +lemma floor_minus_real_of_nat [simp]: "floor (- real (n::nat)) = - int n"
1.81 +apply (simp only: floor_def)
1.82 +apply (rule Least_equality)
1.83 +apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
1.84 +apply (drule_tac [2] real_of_int_minus [THEN subst])
1.85 +apply (drule_tac [2] real_of_int_less_iff [THEN iffD1])
1.87 +done
1.88 +
1.89 +lemma floor_real_of_int [simp]: "floor (real (n::int)) = n"
1.90 +apply (simp only: floor_def)
1.91 +apply (rule Least_equality)
1.92 +apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
1.93 +apply (drule_tac [2] real_of_int_less_iff [THEN iffD1], auto)
1.94 +done
1.95 +
1.96 +lemma floor_minus_real_of_int [simp]: "floor (- real (n::int)) = - n"
1.97 +apply (simp only: floor_def)
1.98 +apply (rule Least_equality)
1.99 +apply (drule_tac [2] real_of_int_minus [THEN subst])
1.100 +apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
1.101 +apply (drule_tac [2] real_of_int_less_iff [THEN iffD1], auto)
1.102 +done
1.103 +
1.104 +lemma reals_Archimedean6:
1.105 +     "0 \<le> r ==> \<exists>(n::nat). real (n - 1) \<le> r & r < real (n)"
1.106 +apply (insert reals_Archimedean2 [of r], safe)
1.107 +apply (frule_tac P = "%k. r < real k" and k = n and m = "%x. x"
1.108 +       in ex_has_least_nat, auto)
1.109 +apply (rule_tac x = x in exI)
1.110 +apply (case_tac x, simp)
1.111 +apply (rename_tac x')
1.112 +apply (drule_tac x = x' in spec, simp)
1.113 +done
1.114 +
1.115 +lemma reals_Archimedean6a: "0 \<le> r ==> \<exists>n. real (n) \<le> r & r < real (Suc n)"
1.116 +by (drule reals_Archimedean6, auto)
1.117 +
1.118 +lemma reals_Archimedean_6b_int:
1.119 +     "0 \<le> r ==> \<exists>n::int. real n \<le> r & r < real (n+1)"
1.120 +apply (drule reals_Archimedean6a, auto)
1.121 +apply (rule_tac x = "int n" in exI)
1.122 +apply (simp add: real_of_int_real_of_nat real_of_nat_Suc)
1.123 +done
1.124 +
1.125 +lemma reals_Archimedean_6c_int:
1.126 +     "r < 0 ==> \<exists>n::int. real n \<le> r & r < real (n+1)"
1.127 +apply (rule reals_Archimedean_6b_int [of "-r", THEN exE], simp, auto)
1.128 +apply (rename_tac n)
1.129 +apply (drule real_le_imp_less_or_eq, auto)
1.130 +apply (rule_tac x = "- n - 1" in exI)
1.131 +apply (rule_tac [2] x = "- n" in exI, auto)
1.132 +done
1.133 +
1.134 +lemma real_lb_ub_int: " \<exists>n::int. real n \<le> r & r < real (n+1)"
1.135 +apply (case_tac "r < 0")
1.136 +apply (blast intro: reals_Archimedean_6c_int)
1.137 +apply (simp only: linorder_not_less)
1.138 +apply (blast intro: reals_Archimedean_6b_int reals_Archimedean_6c_int)
1.139 +done
1.140 +
1.141 +lemma lemma_floor:
1.142 +  assumes a1: "real m \<le> r" and a2: "r < real n + 1"
1.143 +  shows "m \<le> (n::int)"
1.144 +proof -
1.145 +  have "real m < real n + 1" by (rule order_le_less_trans)
1.146 +  also have "... = real(n+1)" by simp
1.147 +  finally have "m < n+1" by (simp only: real_of_int_less_iff)
1.148 +  thus ?thesis by arith
1.149 +qed
1.150 +
1.151 +lemma real_of_int_floor_le [simp]: "real (floor r) \<le> r"
1.152 +apply (simp add: floor_def Least_def)
1.153 +apply (insert real_lb_ub_int [of r], safe)
1.154 +apply (rule theI2, auto)
1.155 +done
1.156 +
1.157 +lemma floor_le: "x < y ==> floor x \<le> floor y"
1.158 +apply (simp add: floor_def Least_def)
1.159 +apply (insert real_lb_ub_int [of x])
1.160 +apply (insert real_lb_ub_int [of y], safe)
1.161 +apply (rule theI2)
1.162 +apply (rule_tac [3] theI2, auto)
1.163 +done
1.164 +
1.165 +lemma floor_le2: "x \<le> y ==> floor x \<le> floor y"
1.166 +by (auto dest: real_le_imp_less_or_eq simp add: floor_le)
1.167 +
1.168 +lemma lemma_floor2: "real n < real (x::int) + 1 ==> n \<le> x"
1.169 +by (auto intro: lemma_floor)
1.170 +
1.171 +lemma real_of_int_floor_cancel [simp]:
1.172 +    "(real (floor x) = x) = (\<exists>n::int. x = real n)"
1.173 +apply (simp add: floor_def Least_def)
1.174 +apply (insert real_lb_ub_int [of x], erule exE)
1.175 +apply (rule theI2)
1.176 +apply (auto intro: lemma_floor)
1.177 +done
1.178 +
1.179 +lemma floor_eq: "[| real n < x; x < real n + 1 |] ==> floor x = n"
1.181 +apply (rule Least_equality)
1.182 +apply (auto intro: lemma_floor)
1.183 +done
1.184 +
1.185 +lemma floor_eq2: "[| real n \<le> x; x < real n + 1 |] ==> floor x = n"
1.187 +apply (rule Least_equality)
1.188 +apply (auto intro: lemma_floor)
1.189 +done
1.190 +
1.191 +lemma floor_eq3: "[| real n < x; x < real (Suc n) |] ==> nat(floor x) = n"
1.192 +apply (rule inj_int [THEN injD])
1.194 +apply (simp add: real_of_nat_Suc floor_eq floor_eq [where n = "of_nat n"])
1.195 +done
1.196 +
1.197 +lemma floor_eq4: "[| real n \<le> x; x < real (Suc n) |] ==> nat(floor x) = n"
1.198 +apply (drule order_le_imp_less_or_eq)
1.199 +apply (auto intro: floor_eq3)
1.200 +done
1.201 +
1.202 +lemma floor_number_of_eq [simp]:
1.203 +     "floor(number_of n :: real) = (number_of n :: int)"
1.204 +apply (subst real_number_of [symmetric])
1.205 +apply (rule floor_real_of_int)
1.206 +done
1.207 +
1.208 +lemma real_of_int_floor_ge_diff_one [simp]: "r - 1 \<le> real(floor r)"
1.209 +apply (simp add: floor_def Least_def)
1.210 +apply (insert real_lb_ub_int [of r], safe)
1.211 +apply (rule theI2)
1.212 +apply (auto intro: lemma_floor)
1.213 +done
1.214 +
1.215 +lemma real_of_int_floor_add_one_ge [simp]: "r \<le> real(floor r) + 1"
1.216 +apply (insert real_of_int_floor_ge_diff_one [of r])
1.217 +apply (auto simp del: real_of_int_floor_ge_diff_one)
1.218 +done
1.219 +
1.220 +
1.221 +subsection{*Ceiling Function for Positive Reals*}
1.222 +
1.223 +lemma ceiling_zero [simp]: "ceiling 0 = 0"
1.225 +
1.226 +lemma ceiling_real_of_nat [simp]: "ceiling (real (n::nat)) = int n"
1.228 +
1.229 +lemma ceiling_real_of_nat_zero [simp]: "ceiling (real (0::nat)) = 0"
1.230 +by auto
1.231 +
1.232 +lemma ceiling_floor [simp]: "ceiling (real (floor r)) = floor r"
1.234 +
1.235 +lemma floor_ceiling [simp]: "floor (real (ceiling r)) = ceiling r"
1.237 +
1.238 +lemma real_of_int_ceiling_ge [simp]: "r \<le> real (ceiling r)"
1.240 +apply (subst le_minus_iff, simp)
1.241 +done
1.242 +
1.243 +lemma ceiling_le: "x < y ==> ceiling x \<le> ceiling y"
1.244 +by (simp add: floor_le ceiling_def)
1.245 +
1.246 +lemma ceiling_le2: "x \<le> y ==> ceiling x \<le> ceiling y"
1.247 +by (simp add: floor_le2 ceiling_def)
1.248 +
1.249 +lemma real_of_int_ceiling_cancel [simp]:
1.250 +     "(real (ceiling x) = x) = (\<exists>n::int. x = real n)"
1.251 +apply (auto simp add: ceiling_def)
1.252 +apply (drule arg_cong [where f = uminus], auto)
1.253 +apply (rule_tac x = "-n" in exI, auto)
1.254 +done
1.255 +
1.256 +lemma ceiling_eq: "[| real n < x; x < real n + 1 |] ==> ceiling x = n + 1"
1.258 +apply (rule minus_equation_iff [THEN iffD1])
1.259 +apply (simp add: floor_eq [where n = "-(n+1)"])
1.260 +done
1.261 +
1.262 +lemma ceiling_eq2: "[| real n < x; x \<le> real n + 1 |] ==> ceiling x = n + 1"
1.263 +by (simp add: ceiling_def floor_eq2 [where n = "-(n+1)"])
1.264 +
1.265 +lemma ceiling_eq3: "[| real n - 1 < x; x \<le> real n  |] ==> ceiling x = n"
1.266 +by (simp add: ceiling_def floor_eq2 [where n = "-n"])
1.267 +
1.268 +lemma ceiling_real_of_int [simp]: "ceiling (real (n::int)) = n"
1.270 +
1.271 +lemma ceiling_number_of_eq [simp]:
1.272 +     "ceiling (number_of n :: real) = (number_of n)"
1.273 +apply (subst real_number_of [symmetric])
1.274 +apply (rule ceiling_real_of_int)
1.275 +done
1.276 +
1.277 +lemma real_of_int_ceiling_diff_one_le [simp]: "real (ceiling r) - 1 \<le> r"
1.278 +apply (rule neg_le_iff_le [THEN iffD1])
1.279 +apply (simp add: ceiling_def diff_minus)
1.280 +done
1.281 +
1.282 +lemma real_of_int_ceiling_le_add_one [simp]: "real (ceiling r) \<le> r + 1"
1.283 +apply (insert real_of_int_ceiling_diff_one_le [of r])
1.284 +apply (simp del: real_of_int_ceiling_diff_one_le)
1.285 +done
1.286 +
1.287 +ML
1.288 +{*
1.289 +val number_of_less_real_of_int_iff = thm "number_of_less_real_of_int_iff";
1.290 +val number_of_less_real_of_int_iff2 = thm "number_of_less_real_of_int_iff2";
1.291 +val number_of_le_real_of_int_iff = thm "number_of_le_real_of_int_iff";
1.292 +val number_of_le_real_of_int_iff2 = thm "number_of_le_real_of_int_iff2";
1.293 +val floor_zero = thm "floor_zero";
1.294 +val floor_real_of_nat_zero = thm "floor_real_of_nat_zero";
1.295 +val floor_real_of_nat = thm "floor_real_of_nat";
1.296 +val floor_minus_real_of_nat = thm "floor_minus_real_of_nat";
1.297 +val floor_real_of_int = thm "floor_real_of_int";
1.298 +val floor_minus_real_of_int = thm "floor_minus_real_of_int";
1.299 +val reals_Archimedean6 = thm "reals_Archimedean6";
1.300 +val reals_Archimedean6a = thm "reals_Archimedean6a";
1.301 +val reals_Archimedean_6b_int = thm "reals_Archimedean_6b_int";
1.302 +val reals_Archimedean_6c_int = thm "reals_Archimedean_6c_int";
1.303 +val real_lb_ub_int = thm "real_lb_ub_int";
1.304 +val lemma_floor = thm "lemma_floor";
1.305 +val real_of_int_floor_le = thm "real_of_int_floor_le";
1.306 +val floor_le = thm "floor_le";
1.307 +val floor_le2 = thm "floor_le2";
1.308 +val lemma_floor2 = thm "lemma_floor2";
1.309 +val real_of_int_floor_cancel = thm "real_of_int_floor_cancel";
1.310 +val floor_eq = thm "floor_eq";
1.311 +val floor_eq2 = thm "floor_eq2";
1.312 +val floor_eq3 = thm "floor_eq3";
1.313 +val floor_eq4 = thm "floor_eq4";
1.314 +val floor_number_of_eq = thm "floor_number_of_eq";
1.315 +val real_of_int_floor_ge_diff_one = thm "real_of_int_floor_ge_diff_one";
1.317 +val ceiling_zero = thm "ceiling_zero";
1.318 +val ceiling_real_of_nat = thm "ceiling_real_of_nat";
1.319 +val ceiling_real_of_nat_zero = thm "ceiling_real_of_nat_zero";
1.320 +val ceiling_floor = thm "ceiling_floor";
1.321 +val floor_ceiling = thm "floor_ceiling";
1.322 +val real_of_int_ceiling_ge = thm "real_of_int_ceiling_ge";
1.323 +val ceiling_le = thm "ceiling_le";
1.324 +val ceiling_le2 = thm "ceiling_le2";
1.325 +val real_of_int_ceiling_cancel = thm "real_of_int_ceiling_cancel";
1.326 +val ceiling_eq = thm "ceiling_eq";
1.327 +val ceiling_eq2 = thm "ceiling_eq2";
1.328 +val ceiling_eq3 = thm "ceiling_eq3";
1.329 +val ceiling_real_of_int = thm "ceiling_real_of_int";
1.330 +val ceiling_number_of_eq = thm "ceiling_number_of_eq";
1.331 +val real_of_int_ceiling_diff_one_le = thm "real_of_int_ceiling_diff_one_le";