src/HOL/Real/RComplete.thy
changeset 14641 79b7bd936264
parent 14476 758e7acdea2f
child 15131 c69542757a4d
equal deleted inserted replaced
14640:b31870c50c68 14641:79b7bd936264
     1 (*  Title       : RComplete.thy
     1 (*  Title       : RComplete.thy
     2     ID          : $Id$
     2     ID          : $Id$
     3     Author      : Jacques D. Fleuriot
     3     Author      : Jacques D. Fleuriot
     4     Copyright   : 1998  University of Cambridge
     4     Copyright   : 1998  University of Cambridge
     5     Description : Completeness theorems for positive
     5     Copyright   : 2001,2002  University of Edinburgh
     6                   reals and reals 
     6 Converted to Isar and polished by lcp
     7 *) 
     7 *) 
     8 
     8 
     9 header{*Completeness Theorems for Positive Reals and Reals.*}
     9 header{*Completeness of the Reals; Floor and Ceiling Functions*}
    10 
    10 
    11 theory RComplete = Lubs + RealDef:
    11 theory RComplete = Lubs + RealDef:
    12 
    12 
    13 lemma real_sum_of_halves: "x/2 + x/2 = (x::real)"
    13 lemma real_sum_of_halves: "x/2 + x/2 = (x::real)"
    14 by simp
    14 by simp
   213 val reals_Archimedean = thm "reals_Archimedean";
   213 val reals_Archimedean = thm "reals_Archimedean";
   214 val reals_Archimedean2 = thm "reals_Archimedean2";
   214 val reals_Archimedean2 = thm "reals_Archimedean2";
   215 val reals_Archimedean3 = thm "reals_Archimedean3";
   215 val reals_Archimedean3 = thm "reals_Archimedean3";
   216 *}
   216 *}
   217 
   217 
       
   218 
       
   219 subsection{*Floor and Ceiling Functions from the Reals to the Integers*}
       
   220 
       
   221 constdefs
       
   222 
       
   223   floor :: "real => int"
       
   224    "floor r == (LEAST n::int. r < real (n+1))"
       
   225 
       
   226   ceiling :: "real => int"
       
   227     "ceiling r == - floor (- r)"
       
   228 
       
   229 syntax (xsymbols)
       
   230   floor :: "real => int"     ("\<lfloor>_\<rfloor>")
       
   231   ceiling :: "real => int"   ("\<lceil>_\<rceil>")
       
   232 
       
   233 syntax (HTML output)
       
   234   floor :: "real => int"     ("\<lfloor>_\<rfloor>")
       
   235   ceiling :: "real => int"   ("\<lceil>_\<rceil>")
       
   236 
       
   237 
       
   238 lemma number_of_less_real_of_int_iff [simp]:
       
   239      "((number_of n) < real (m::int)) = (number_of n < m)"
       
   240 apply auto
       
   241 apply (rule real_of_int_less_iff [THEN iffD1])
       
   242 apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
       
   243 done
       
   244 
       
   245 lemma number_of_less_real_of_int_iff2 [simp]:
       
   246      "(real (m::int) < (number_of n)) = (m < number_of n)"
       
   247 apply auto
       
   248 apply (rule real_of_int_less_iff [THEN iffD1])
       
   249 apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
       
   250 done
       
   251 
       
   252 lemma number_of_le_real_of_int_iff [simp]:
       
   253      "((number_of n) \<le> real (m::int)) = (number_of n \<le> m)"
       
   254 by (simp add: linorder_not_less [symmetric])
       
   255 
       
   256 lemma number_of_le_real_of_int_iff2 [simp]:
       
   257      "(real (m::int) \<le> (number_of n)) = (m \<le> number_of n)"
       
   258 by (simp add: linorder_not_less [symmetric])
       
   259 
       
   260 lemma floor_zero [simp]: "floor 0 = 0"
       
   261 apply (simp add: floor_def)
       
   262 apply (rule Least_equality, auto)
       
   263 done
       
   264 
       
   265 lemma floor_real_of_nat_zero [simp]: "floor (real (0::nat)) = 0"
       
   266 by auto
       
   267 
       
   268 lemma floor_real_of_nat [simp]: "floor (real (n::nat)) = int n"
       
   269 apply (simp only: floor_def)
       
   270 apply (rule Least_equality)
       
   271 apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
       
   272 apply (drule_tac [2] real_of_int_less_iff [THEN iffD1])
       
   273 apply (simp_all add: real_of_int_real_of_nat)
       
   274 done
       
   275 
       
   276 lemma floor_minus_real_of_nat [simp]: "floor (- real (n::nat)) = - int n"
       
   277 apply (simp only: floor_def)
       
   278 apply (rule Least_equality)
       
   279 apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
       
   280 apply (drule_tac [2] real_of_int_minus [THEN subst])
       
   281 apply (drule_tac [2] real_of_int_less_iff [THEN iffD1])
       
   282 apply (simp_all add: real_of_int_real_of_nat)
       
   283 done
       
   284 
       
   285 lemma floor_real_of_int [simp]: "floor (real (n::int)) = n"
       
   286 apply (simp only: floor_def)
       
   287 apply (rule Least_equality)
       
   288 apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
       
   289 apply (drule_tac [2] real_of_int_less_iff [THEN iffD1], auto)
       
   290 done
       
   291 
       
   292 lemma floor_minus_real_of_int [simp]: "floor (- real (n::int)) = - n"
       
   293 apply (simp only: floor_def)
       
   294 apply (rule Least_equality)
       
   295 apply (drule_tac [2] real_of_int_minus [THEN subst])
       
   296 apply (drule_tac [2] real_of_int_real_of_nat [THEN ssubst])
       
   297 apply (drule_tac [2] real_of_int_less_iff [THEN iffD1], auto)
       
   298 done
       
   299 
       
   300 lemma reals_Archimedean6:
       
   301      "0 \<le> r ==> \<exists>(n::nat). real (n - 1) \<le> r & r < real (n)"
       
   302 apply (insert reals_Archimedean2 [of r], safe)
       
   303 apply (frule_tac P = "%k. r < real k" and k = n and m = "%x. x"
       
   304        in ex_has_least_nat, auto)
       
   305 apply (rule_tac x = x in exI)
       
   306 apply (case_tac x, simp)
       
   307 apply (rename_tac x')
       
   308 apply (drule_tac x = x' in spec, simp)
       
   309 done
       
   310 
       
   311 lemma reals_Archimedean6a: "0 \<le> r ==> \<exists>n. real (n) \<le> r & r < real (Suc n)"
       
   312 by (drule reals_Archimedean6, auto)
       
   313 
       
   314 lemma reals_Archimedean_6b_int:
       
   315      "0 \<le> r ==> \<exists>n::int. real n \<le> r & r < real (n+1)"
       
   316 apply (drule reals_Archimedean6a, auto)
       
   317 apply (rule_tac x = "int n" in exI)
       
   318 apply (simp add: real_of_int_real_of_nat real_of_nat_Suc)
       
   319 done
       
   320 
       
   321 lemma reals_Archimedean_6c_int:
       
   322      "r < 0 ==> \<exists>n::int. real n \<le> r & r < real (n+1)"
       
   323 apply (rule reals_Archimedean_6b_int [of "-r", THEN exE], simp, auto)
       
   324 apply (rename_tac n)
       
   325 apply (drule real_le_imp_less_or_eq, auto)
       
   326 apply (rule_tac x = "- n - 1" in exI)
       
   327 apply (rule_tac [2] x = "- n" in exI, auto)
       
   328 done
       
   329 
       
   330 lemma real_lb_ub_int: " \<exists>n::int. real n \<le> r & r < real (n+1)"
       
   331 apply (case_tac "r < 0")
       
   332 apply (blast intro: reals_Archimedean_6c_int)
       
   333 apply (simp only: linorder_not_less)
       
   334 apply (blast intro: reals_Archimedean_6b_int reals_Archimedean_6c_int)
       
   335 done
       
   336 
       
   337 lemma lemma_floor:
       
   338   assumes a1: "real m \<le> r" and a2: "r < real n + 1"
       
   339   shows "m \<le> (n::int)"
       
   340 proof -
       
   341   have "real m < real n + 1" by (rule order_le_less_trans)
       
   342   also have "... = real(n+1)" by simp
       
   343   finally have "m < n+1" by (simp only: real_of_int_less_iff)
       
   344   thus ?thesis by arith
       
   345 qed
       
   346 
       
   347 lemma real_of_int_floor_le [simp]: "real (floor r) \<le> r"
       
   348 apply (simp add: floor_def Least_def)
       
   349 apply (insert real_lb_ub_int [of r], safe)
       
   350 apply (rule theI2, auto)
       
   351 done
       
   352 
       
   353 lemma floor_le: "x < y ==> floor x \<le> floor y"
       
   354 apply (simp add: floor_def Least_def)
       
   355 apply (insert real_lb_ub_int [of x])
       
   356 apply (insert real_lb_ub_int [of y], safe)
       
   357 apply (rule theI2)
       
   358 apply (rule_tac [3] theI2, auto)
       
   359 done
       
   360 
       
   361 lemma floor_le2: "x \<le> y ==> floor x \<le> floor y"
       
   362 by (auto dest: real_le_imp_less_or_eq simp add: floor_le)
       
   363 
       
   364 lemma lemma_floor2: "real n < real (x::int) + 1 ==> n \<le> x"
       
   365 by (auto intro: lemma_floor)
       
   366 
       
   367 lemma real_of_int_floor_cancel [simp]:
       
   368     "(real (floor x) = x) = (\<exists>n::int. x = real n)"
       
   369 apply (simp add: floor_def Least_def)
       
   370 apply (insert real_lb_ub_int [of x], erule exE)
       
   371 apply (rule theI2)
       
   372 apply (auto intro: lemma_floor)
       
   373 done
       
   374 
       
   375 lemma floor_eq: "[| real n < x; x < real n + 1 |] ==> floor x = n"
       
   376 apply (simp add: floor_def)
       
   377 apply (rule Least_equality)
       
   378 apply (auto intro: lemma_floor)
       
   379 done
       
   380 
       
   381 lemma floor_eq2: "[| real n \<le> x; x < real n + 1 |] ==> floor x = n"
       
   382 apply (simp add: floor_def)
       
   383 apply (rule Least_equality)
       
   384 apply (auto intro: lemma_floor)
       
   385 done
       
   386 
       
   387 lemma floor_eq3: "[| real n < x; x < real (Suc n) |] ==> nat(floor x) = n"
       
   388 apply (rule inj_int [THEN injD])
       
   389 apply (simp add: real_of_nat_Suc)
       
   390 apply (simp add: real_of_nat_Suc floor_eq floor_eq [where n = "of_nat n"])
       
   391 done
       
   392 
       
   393 lemma floor_eq4: "[| real n \<le> x; x < real (Suc n) |] ==> nat(floor x) = n"
       
   394 apply (drule order_le_imp_less_or_eq)
       
   395 apply (auto intro: floor_eq3)
       
   396 done
       
   397 
       
   398 lemma floor_number_of_eq [simp]:
       
   399      "floor(number_of n :: real) = (number_of n :: int)"
       
   400 apply (subst real_number_of [symmetric])
       
   401 apply (rule floor_real_of_int)
       
   402 done
       
   403 
       
   404 lemma real_of_int_floor_ge_diff_one [simp]: "r - 1 \<le> real(floor r)"
       
   405 apply (simp add: floor_def Least_def)
       
   406 apply (insert real_lb_ub_int [of r], safe)
       
   407 apply (rule theI2)
       
   408 apply (auto intro: lemma_floor)
       
   409 done
       
   410 
       
   411 lemma real_of_int_floor_add_one_ge [simp]: "r \<le> real(floor r) + 1"
       
   412 apply (insert real_of_int_floor_ge_diff_one [of r])
       
   413 apply (auto simp del: real_of_int_floor_ge_diff_one)
       
   414 done
       
   415 
       
   416 
       
   417 subsection{*Ceiling Function for Positive Reals*}
       
   418 
       
   419 lemma ceiling_zero [simp]: "ceiling 0 = 0"
       
   420 by (simp add: ceiling_def)
       
   421 
       
   422 lemma ceiling_real_of_nat [simp]: "ceiling (real (n::nat)) = int n"
       
   423 by (simp add: ceiling_def)
       
   424 
       
   425 lemma ceiling_real_of_nat_zero [simp]: "ceiling (real (0::nat)) = 0"
       
   426 by auto
       
   427 
       
   428 lemma ceiling_floor [simp]: "ceiling (real (floor r)) = floor r"
       
   429 by (simp add: ceiling_def)
       
   430 
       
   431 lemma floor_ceiling [simp]: "floor (real (ceiling r)) = ceiling r"
       
   432 by (simp add: ceiling_def)
       
   433 
       
   434 lemma real_of_int_ceiling_ge [simp]: "r \<le> real (ceiling r)"
       
   435 apply (simp add: ceiling_def)
       
   436 apply (subst le_minus_iff, simp)
       
   437 done
       
   438 
       
   439 lemma ceiling_le: "x < y ==> ceiling x \<le> ceiling y"
       
   440 by (simp add: floor_le ceiling_def)
       
   441 
       
   442 lemma ceiling_le2: "x \<le> y ==> ceiling x \<le> ceiling y"
       
   443 by (simp add: floor_le2 ceiling_def)
       
   444 
       
   445 lemma real_of_int_ceiling_cancel [simp]:
       
   446      "(real (ceiling x) = x) = (\<exists>n::int. x = real n)"
       
   447 apply (auto simp add: ceiling_def)
       
   448 apply (drule arg_cong [where f = uminus], auto)
       
   449 apply (rule_tac x = "-n" in exI, auto)
       
   450 done
       
   451 
       
   452 lemma ceiling_eq: "[| real n < x; x < real n + 1 |] ==> ceiling x = n + 1"
       
   453 apply (simp add: ceiling_def)
       
   454 apply (rule minus_equation_iff [THEN iffD1])
       
   455 apply (simp add: floor_eq [where n = "-(n+1)"])
       
   456 done
       
   457 
       
   458 lemma ceiling_eq2: "[| real n < x; x \<le> real n + 1 |] ==> ceiling x = n + 1"
       
   459 by (simp add: ceiling_def floor_eq2 [where n = "-(n+1)"])
       
   460 
       
   461 lemma ceiling_eq3: "[| real n - 1 < x; x \<le> real n  |] ==> ceiling x = n"
       
   462 by (simp add: ceiling_def floor_eq2 [where n = "-n"])
       
   463 
       
   464 lemma ceiling_real_of_int [simp]: "ceiling (real (n::int)) = n"
       
   465 by (simp add: ceiling_def)
       
   466 
       
   467 lemma ceiling_number_of_eq [simp]:
       
   468      "ceiling (number_of n :: real) = (number_of n)"
       
   469 apply (subst real_number_of [symmetric])
       
   470 apply (rule ceiling_real_of_int)
       
   471 done
       
   472 
       
   473 lemma real_of_int_ceiling_diff_one_le [simp]: "real (ceiling r) - 1 \<le> r"
       
   474 apply (rule neg_le_iff_le [THEN iffD1])
       
   475 apply (simp add: ceiling_def diff_minus)
       
   476 done
       
   477 
       
   478 lemma real_of_int_ceiling_le_add_one [simp]: "real (ceiling r) \<le> r + 1"
       
   479 apply (insert real_of_int_ceiling_diff_one_le [of r])
       
   480 apply (simp del: real_of_int_ceiling_diff_one_le)
       
   481 done
       
   482 
       
   483 ML
       
   484 {*
       
   485 val number_of_less_real_of_int_iff = thm "number_of_less_real_of_int_iff";
       
   486 val number_of_less_real_of_int_iff2 = thm "number_of_less_real_of_int_iff2";
       
   487 val number_of_le_real_of_int_iff = thm "number_of_le_real_of_int_iff";
       
   488 val number_of_le_real_of_int_iff2 = thm "number_of_le_real_of_int_iff2";
       
   489 val floor_zero = thm "floor_zero";
       
   490 val floor_real_of_nat_zero = thm "floor_real_of_nat_zero";
       
   491 val floor_real_of_nat = thm "floor_real_of_nat";
       
   492 val floor_minus_real_of_nat = thm "floor_minus_real_of_nat";
       
   493 val floor_real_of_int = thm "floor_real_of_int";
       
   494 val floor_minus_real_of_int = thm "floor_minus_real_of_int";
       
   495 val reals_Archimedean6 = thm "reals_Archimedean6";
       
   496 val reals_Archimedean6a = thm "reals_Archimedean6a";
       
   497 val reals_Archimedean_6b_int = thm "reals_Archimedean_6b_int";
       
   498 val reals_Archimedean_6c_int = thm "reals_Archimedean_6c_int";
       
   499 val real_lb_ub_int = thm "real_lb_ub_int";
       
   500 val lemma_floor = thm "lemma_floor";
       
   501 val real_of_int_floor_le = thm "real_of_int_floor_le";
       
   502 val floor_le = thm "floor_le";
       
   503 val floor_le2 = thm "floor_le2";
       
   504 val lemma_floor2 = thm "lemma_floor2";
       
   505 val real_of_int_floor_cancel = thm "real_of_int_floor_cancel";
       
   506 val floor_eq = thm "floor_eq";
       
   507 val floor_eq2 = thm "floor_eq2";
       
   508 val floor_eq3 = thm "floor_eq3";
       
   509 val floor_eq4 = thm "floor_eq4";
       
   510 val floor_number_of_eq = thm "floor_number_of_eq";
       
   511 val real_of_int_floor_ge_diff_one = thm "real_of_int_floor_ge_diff_one";
       
   512 val real_of_int_floor_add_one_ge = thm "real_of_int_floor_add_one_ge";
       
   513 val ceiling_zero = thm "ceiling_zero";
       
   514 val ceiling_real_of_nat = thm "ceiling_real_of_nat";
       
   515 val ceiling_real_of_nat_zero = thm "ceiling_real_of_nat_zero";
       
   516 val ceiling_floor = thm "ceiling_floor";
       
   517 val floor_ceiling = thm "floor_ceiling";
       
   518 val real_of_int_ceiling_ge = thm "real_of_int_ceiling_ge";
       
   519 val ceiling_le = thm "ceiling_le";
       
   520 val ceiling_le2 = thm "ceiling_le2";
       
   521 val real_of_int_ceiling_cancel = thm "real_of_int_ceiling_cancel";
       
   522 val ceiling_eq = thm "ceiling_eq";
       
   523 val ceiling_eq2 = thm "ceiling_eq2";
       
   524 val ceiling_eq3 = thm "ceiling_eq3";
       
   525 val ceiling_real_of_int = thm "ceiling_real_of_int";
       
   526 val ceiling_number_of_eq = thm "ceiling_number_of_eq";
       
   527 val real_of_int_ceiling_diff_one_le = thm "real_of_int_ceiling_diff_one_le";
       
   528 val real_of_int_ceiling_le_add_one = thm "real_of_int_ceiling_le_add_one";
       
   529 *}
       
   530 
       
   531 
   218 end
   532 end
   219 
   533 
   220 
   534 
   221 
   535 
       
   536