(* Title: HOL/Archimedean_Field.thy Author: Brian Huffman
*)
section \<open>Archimedean Fields, Floor and Ceiling Functions\<close>
theory Archimedean_Field imports Main begin
lemma cInf_abs_ge: fixes S :: "'a::{linordered_idom,conditionally_complete_linorder} set" assumes"S \ {}" and bdd: "\x. x\S \ \x\ \ a" shows"\Inf S\ \ a" proof - have"Sup (uminus ` S) = - (Inf S)" proof (rule antisym) have"\x. x \ S \ bdd_above (uminus ` S)" using bdd by (force simp: abs_le_iff bdd_above_def) thenshow"- (Inf S) \ Sup (uminus ` S)" by (meson cInf_greatest [OF \<open>S \<noteq> {}\<close>] cSUP_upper minus_le_iff) next have *: "\x. x \ S \ Inf S \ x" by (meson abs_le_iff bdd bdd_below_def cInf_lower minus_le_iff) show"Sup (uminus ` S) \ - Inf S" using\<open>S \<noteq> {}\<close> by (force intro: * cSup_least) qed with cSup_abs_le [of "uminus ` S"] assms show ?thesis by fastforce qed
lemma cSup_asclose: fixes S :: "'a::{linordered_idom,conditionally_complete_linorder} set" assumes S: "S \ {}" and b: "\x\S. \x - l\ \ e" shows"\Sup S - l\ \ e" proof - have *: "\x - l\ \ e \ l - e \ x \ x \ l + e" for x l e :: 'a by arith have"bdd_above S" using b by (auto intro!: bdd_aboveI[of _ "l + e"]) with S b show ?thesis unfolding * by (auto intro!: cSup_upper2 cSup_least) qed
lemma cInf_asclose: fixes S :: "'a::{linordered_idom,conditionally_complete_linorder} set" assumes S: "S \ {}" and b: "\x\S. \x - l\ \ e" shows"\Inf S - l\ \ e" proof - have *: "\x - l\ \ e \ l - e \ x \ x \ l + e" for x l e :: 'a by arith have"bdd_below S" using b by (auto intro!: bdd_belowI[of _ "l - e"]) with S b show ?thesis unfolding * by (auto intro!: cInf_lower2 cInf_greatest) qed
subsection \<open>Class of Archimedean fields\<close>
text\<open>Archimedean fields have no infinite elements.\<close>
class archimedean_field = linordered_field + assumes ex_le_of_int: "\z. x \ of_int z"
lemma ex_less_of_int: "\z. x < of_int z" for x :: "'a::archimedean_field" proof - from ex_le_of_int obtain z where"x \ of_int z" .. thenhave"x < of_int (z + 1)"by simp thenshow ?thesis .. qed
lemma ex_of_int_less: "\z. of_int z < x" for x :: "'a::archimedean_field" proof - from ex_less_of_int obtain z where"- x < of_int z" .. thenhave"of_int (- z) < x"by simp thenshow ?thesis .. qed
lemma reals_Archimedean2: "\n. x < of_nat n" for x :: "'a::archimedean_field" proof - obtain z where"x < of_int z" using ex_less_of_int .. alsohave"\ \ of_int (int (nat z))" by simp alsohave"\ = of_nat (nat z)" by (simp only: of_int_of_nat_eq) finallyshow ?thesis .. qed
lemma real_arch_simple: "\n. x \ of_nat n" for x :: "'a::archimedean_field" proof - obtain n where"x < of_nat n" using reals_Archimedean2 .. thenhave"x \ of_nat n" by simp thenshow ?thesis .. qed
text\<open>Archimedean fields have no infinitesimal elements.\<close>
lemma reals_Archimedean: fixes x :: "'a::archimedean_field" assumes"0 < x" shows"\n. inverse (of_nat (Suc n)) < x" proof - from\<open>0 < x\<close> have "0 < inverse x" by (rule positive_imp_inverse_positive) obtain n where"inverse x < of_nat n" using reals_Archimedean2 .. thenobtain m where"inverse x < of_nat (Suc m)" using\<open>0 < inverse x\<close> by (cases n) (simp_all del: of_nat_Suc) thenhave"inverse (of_nat (Suc m)) < inverse (inverse x)" using\<open>0 < inverse x\<close> by (rule less_imp_inverse_less) thenhave"inverse (of_nat (Suc m)) < x" using\<open>0 < x\<close> by (simp add: nonzero_inverse_inverse_eq) thenshow ?thesis .. qed
lemma ex_inverse_of_nat_less: fixes x :: "'a::archimedean_field" assumes"0 < x" shows"\n>0. inverse (of_nat n) < x" using reals_Archimedean [OF \<open>0 < x\<close>] by auto
lemma ex_less_of_nat_mult: fixes x :: "'a::archimedean_field" assumes"0 < x" shows"\n. y < of_nat n * x" proof - obtain n where"y / x < of_nat n" using reals_Archimedean2 .. with\<open>0 < x\<close> have "y < of_nat n * x" by (simp add: pos_divide_less_eq) thenshow ?thesis .. qed
subsection \<open>Existence and uniqueness of floor function\<close>
lemma exists_least_lemma: assumes"\ P 0" and "\n. P n" shows"\n. \ P n \ P (Suc n)" proof - from\<open>\<exists>n. P n\<close> have "P (Least P)" by (rule LeastI_ex) with\<open>\<not> P 0\<close> obtain n where "Least P = Suc n" by (cases "Least P") auto thenhave"n < Least P" by simp thenhave"\ P n" by (rule not_less_Least) thenhave"\ P n \ P (Suc n)" using\<open>P (Least P)\<close> \<open>Least P = Suc n\<close> by simp thenshow ?thesis .. qed
lemma floor_exists: fixes x :: "'a::archimedean_field" shows"\z. of_int z \ x \ x < of_int (z + 1)" proof (cases "0 \ x") case True thenhave"\ x < of_nat 0" by simp thenhave"\n. \ x < of_nat n \ x < of_nat (Suc n)" using reals_Archimedean2 by (rule exists_least_lemma) thenobtain n where"\ x < of_nat n \ x < of_nat (Suc n)" .. thenhave"of_int (int n) \ x \ x < of_int (int n + 1)" by simp thenshow ?thesis .. next case False thenhave"\ - x \ of_nat 0" by simp thenhave"\n. \ - x \ of_nat n \ - x \ of_nat (Suc n)" using real_arch_simple by (rule exists_least_lemma) thenobtain n where"\ - x \ of_nat n \ - x \ of_nat (Suc n)" .. thenhave"of_int (- int n - 1) \ x \ x < of_int (- int n - 1 + 1)" by simp thenshow ?thesis .. qed
lemma floor_exists1: "\!z. of_int z \ x \ x < of_int (z + 1)" for x :: "'a::archimedean_field" proof (rule ex_ex1I) show"\z. of_int z \ x \ x < of_int (z + 1)" by (rule floor_exists) next fix y z assume"of_int y \ x \ x < of_int (y + 1)" and"of_int z \ x \ x < of_int (z + 1)" with le_less_trans [of "of_int y""x""of_int (z + 1)"]
le_less_trans [of "of_int z""x""of_int (y + 1)"] show"y = z" by (simp del: of_int_add) qed
subsection \<open>Floor function\<close>
class floor_ceiling = archimedean_field + fixes floor :: "'a \ int" (\(\open_block notation=\mixfix floor\\\_\)\) assumes floor_correct: "of_int \x\ \ x \ x < of_int (\x\ + 1)"
lemma floor_unique: "of_int z \ x \ x < of_int z + 1 \ \x\ = z" using floor_correct [of x] floor_exists1 [of x] by auto
lemma floor_eq_iff: "\x\ = a \ of_int a \ x \ x < of_int a + 1" using floor_correct floor_unique by auto
lemma of_int_floor_le [simp]: "of_int \x\ \ x" using floor_correct ..
lemma le_floor_iff: "z \ \x\ \ of_int z \ x" proof assume"z \ \x\" thenhave"(of_int z :: 'a) \ of_int \x\" by simp alsohave"of_int \x\ \ x" by (rule of_int_floor_le) finallyshow"of_int z \ x" . next assume"of_int z \ x" alsohave"x < of_int (\x\ + 1)" using floor_correct .. finallyshow"z \ \x\" by (simp del: of_int_add) qed
lemma floor_less_iff: "\x\ < z \ x < of_int z" by (simp add: not_le [symmetric] le_floor_iff)
lemma less_floor_iff: "z < \x\ \ of_int z + 1 \ x" using le_floor_iff [of "z + 1" x] by auto
lemma floor_le_iff: "\x\ \ z \ x < of_int z + 1" by (simp add: not_less [symmetric] less_floor_iff)
lemma floor_split[linarith_split]: "P \t\ \ (\i. of_int i \ t \ t < of_int i + 1 \ P i)" by (metis floor_correct floor_unique less_floor_iff not_le order_refl)
lemma floor_diff_numeral [simp]: "\x - numeral v\ = \x\ - numeral v" using floor_diff_of_int [of x "numeral v"] by simp
lemma floor_diff_one [simp]: "\x - 1\ = \x\ - 1" using floor_diff_of_int [of x 1] by simp
lemma le_mult_floor: assumes"0 \ a" and "0 \ b" shows"\a\ * \b\ \ \a * b\" proof - have"of_int \a\ \ a" and "of_int \b\ \ b" by (auto intro: of_int_floor_le) thenhave"of_int (\a\ * \b\) \ a * b" using assms by (auto intro!: mult_mono) alsohave"a * b < of_int (\a * b\ + 1)" using floor_correct[of "a * b"] by auto finallyshow ?thesis unfolding of_int_less_iff by simp qed
lemma floor_divide_of_int_eq: "\of_int k / of_int l\ = k div l" for k l :: int proof (cases "l = 0") case True thenshow ?thesis by simp next case False have *: "\of_int (k mod l) / of_int l :: 'a\ = 0" proof (cases "l > 0") case True thenshow ?thesis by (auto intro: floor_unique) next case False obtain r where"r = - l" by blast thenhave l: "l = - r" by simp with\<open>l \<noteq> 0\<close> False have "r > 0" by simp with l show ?thesis using pos_mod_bound [of r] by (auto simp add: zmod_zminus2_eq_if less_le field_simps intro: floor_unique) qed have"(of_int k :: 'a) = of_int (k div l * l + k mod l)" by simp alsohave"\ = (of_int (k div l) + of_int (k mod l) / of_int l) * of_int l" using False by (simp only: of_int_add) (simp add: field_simps) finallyhave"(of_int k / of_int l :: 'a) = \ / of_int l" by simp thenhave"(of_int k / of_int l :: 'a) = of_int (k div l) + of_int (k mod l) / of_int l" using False by (simp only:) (simp add: field_simps) thenhave"\of_int k / of_int l :: 'a\ = \of_int (k div l) + of_int (k mod l) / of_int l :: 'a\" by simp thenhave"\of_int k / of_int l :: 'a\ = \of_int (k mod l) / of_int l + of_int (k div l) :: 'a\" by (simp add: ac_simps) thenhave"\of_int k / of_int l :: 'a\ = \of_int (k mod l) / of_int l :: 'a\ + k div l" by (simp add: floor_add_int) with * show ?thesis by simp qed
lemma floor_divide_of_nat_eq: "\of_nat m / of_nat n\ = of_nat (m div n)" for m n :: nat by (metis floor_divide_of_int_eq of_int_of_nat_eq linordered_euclidean_semiring_class.of_nat_div)
lemma mult_ceiling_le_Ints: assumes"0 \ a" "a \ Ints" shows"(of_int \a * b\ :: 'a :: linordered_idom) \ of_int(\a\ * \b\)" by (metis Ints_cases assms ceiling_le_iff ceiling_of_int le_of_int_ceiling mult_left_mono of_int_le_iff of_int_mult)
lemma finite_int_segment: fixes a :: "'a::floor_ceiling" shows"finite {x \ \. a \ x \ x \ b}" proof - have"finite {ceiling a..floor b}" by simp moreoverhave"{x \ \. a \ x \ x \ b} = of_int ` {ceiling a..floor b}" by (auto simp: le_floor_iff ceiling_le_iff elim!: Ints_cases) ultimatelyshow ?thesis by simp qed
corollary finite_abs_int_segment: fixes a :: "'a::floor_ceiling" shows"finite {k \ \. \k\ \ a}" using finite_int_segment [of "-a" a] by (auto simp add: abs_le_iff conj_commute minus_le_iff)
subsubsection \<open>Ceiling with numerals.\<close>
lemma ceiling_zero [simp]: "\0\ = 0" using ceiling_of_int [of 0] by simp
lemma ceiling_one [simp]: "\1\ = 1" using ceiling_of_int [of 1] by simp
lemma ceiling_numeral [simp]: "\numeral v\ = numeral v" using ceiling_of_int [of "numeral v"] by simp
lemma ceiling_neg_numeral [simp]: "\- numeral v\ = - numeral v" using ceiling_of_int [of "- numeral v"] by simp
lemma ceiling_le_zero [simp]: "\x\ \ 0 \ x \ 0" by (simp add: ceiling_le_iff)
lemma ceiling_le_one [simp]: "\x\ \ 1 \ x \ 1" by (simp add: ceiling_le_iff)
lemma ceiling_le_numeral [simp]: "\x\ \ numeral v \ x \ numeral v" by (simp add: ceiling_le_iff)
lemma ceiling_le_neg_numeral [simp]: "\x\ \ - numeral v \ x \ - numeral v" by (simp add: ceiling_le_iff)
lemma ceiling_less_zero [simp]: "\x\ < 0 \ x \ -1" by (simp add: ceiling_less_iff)
lemma ceiling_less_one [simp]: "\x\ < 1 \ x \ 0" by (simp add: ceiling_less_iff)
lemma ceiling_less_numeral [simp]: "\x\ < numeral v \ x \ numeral v - 1" by (simp add: ceiling_less_iff)
lemma ceiling_less_neg_numeral [simp]: "\x\ < - numeral v \ x \ - numeral v - 1" by (simp add: ceiling_less_iff)
lemma frac_add: "frac (x + y) = (if frac x + frac y < 1 then frac x + frac y else (frac x + frac y) - 1)" by (simp add: frac_def floor_add)
lemma frac_unique_iff: "frac x = a \ x - a \ \ \ 0 \ a \ a < 1" for x :: "'a::floor_ceiling" by (auto simp: Ints_def frac_def algebra_simps floor_unique; linarith)
lemma frac_eq: "frac x = x \ 0 \ x \ x < 1" by (simp add: frac_unique_iff)
lemma frac_eq_id [simp]: "x \ {0..<1} \ frac x = x" by (simp add: frac_eq)
lemma frac_in_Ints_iff [simp]: "frac x \ \ \ x \ \" by (metis frac_eq_0_iff frac_frac)
lemma frac_neg: "frac (- x) = (if x \ \ then 0 else 1 - frac x)" for x :: "'a::floor_ceiling" unfolding frac_unique_iff using frac_lt_1 [of x] apply (simp add: frac_def) by (metis Ints_of_int floor_eq_iff nless_le)
lemma frac_add_of_int_left [simp]: "frac (of_int n + x) = frac x" by (auto simp: frac_def)
lemma frac_add_int_right: "y \ \ \ frac (x + y) = frac x" by (elim Ints_cases) auto
lemma frac_add_int_left: "x \ \ \ frac (x + y) = frac y" by (elim Ints_cases) auto
lemma bij_betw_frac: "bij_betw frac {x.. unfolding bij_betw_def proof show"inj_on frac {x.. proof fix a b assume *: "a \ {x.. {x.. thenobtain n where n: "a = b + of_int n" by (elim frac_eqE) have"\of_int n\ = \a - b\" using n by (simp add: algebra_simps) alsohave"\ < 1" using * by auto finallyhave"n = 0" by (simp flip: of_int_abs) with n show"a = b" by auto qed next show"frac ` {x.. proof (intro equalityI subsetI) fix t :: 'a assume t: "t \ {0..<1}" have"t = frac (if t \ frac x then x + t - frac x else x + t - frac x + 1)" using frac_eq[of t] t by (auto simp: frac_def) moreoverhave"(if t \ frac x then x + t - frac x else x + t - frac x + 1) \ {x.. using frac_lt_1[of x] frac_ge_0[of x] t by (auto simp del: frac_ge_0) ultimatelyshow"t \ frac ` {x.. by blast qed (auto intro: frac_lt_1) qed
subsection \<open>Rounding to the nearest integer\<close>
lemma round_eq_imp_diff_1: "round x = round y \ \x-y\ < 1" unfolding round_def using floor_eq_imp_diff_1 by fastforce
lemma of_int_round_ge: "of_int (round x) \ x - 1/2" and of_int_round_le: "of_int (round x) \ x + 1/2" and of_int_round_abs_le: "\of_int (round x) - x\ \ 1/2" and of_int_round_gt: "of_int (round x) > x - 1/2" proof - from floor_correct[of "x + 1/2"] have"x + 1/2 < of_int (round x) + 1" by (simp add: round_def) from add_strict_right_mono[OF this, of "-1"] show A: "of_int (round x) > x - 1/2" by simp thenshow"of_int (round x) \ x - 1/2" by simp from floor_correct[of "x + 1/2"] show"of_int (round x) \ x + 1/2" by (simp add: round_def) with A show"\of_int (round x) - x\ \ 1/2" by linarith qed
lemma round_of_int [simp]: "round (of_int n) = n" unfolding round_def by (subst floor_eq_iff) force
lemma round_0 [simp]: "round 0 = 0" using round_of_int[of 0] by simp
lemma round_1 [simp]: "round 1 = 1" using round_of_int[of 1] by simp
lemma round_numeral [simp]: "round (numeral n) = numeral n" using round_of_int[of "numeral n"] by simp
lemma round_neg_numeral [simp]: "round (-numeral n) = -numeral n" using round_of_int[of "-numeral n"] by simp
lemma round_of_nat [simp]: "round (of_nat n) = of_nat n" using round_of_int[of "int n"] by simp
lemma round_mono: "x \ y \ round x \ round y" unfolding round_def by (intro floor_mono) simp
lemma round_unique: "of_int y > x - 1/2 \ of_int y \ x + 1/2 \ round x = y" unfolding round_def proof (rule floor_unique) assume"x - 1 / 2 < of_int y" from add_strict_left_mono[OF this, of 1] show"x + 1 / 2 < of_int y + 1" by simp qed
lemma ceiling_ge_round: "\x\ \ round x" unfolding round_altdef by simp
lemma round_diff_minimal: "\z - of_int (round z)\ \ \z - of_int m\" for z :: "'a::floor_ceiling" proof (cases "of_int m \ z") case True thenhave"\z - of_int (round z)\ \ \of_int \z\ - z\" unfolding round_altdef by (simp add: field_simps ceiling_altdef frac_def) linarith alsohave"of_int \z\ - z \ 0" by linarith with True have"\of_int \z\ - z\ \ \z - of_int m\" by (simp add: ceiling_le_iff) finallyshow ?thesis . next case False thenhave"\z - of_int (round z)\ \ \of_int \z\ - z\" unfolding round_altdef by (simp add: field_simps ceiling_altdef frac_def) linarith alsohave"z - of_int \z\ \ 0" by linarith with False have"\of_int \z\ - z\ \ \z - of_int m\" by (simp add: le_floor_iff) finallyshow ?thesis . qed
bundle floor_ceiling_syntax begin notation floor (\<open>(\<open>open_block notation=\<open>mixfix floor\<close>\<close>\<lfloor>_\<rfloor>)\<close>) and ceiling (\<open>(\<open>open_block notation=\<open>mixfix ceiling\<close>\<close>\<lceil>_\<rceil>)\<close>) end
end
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.