(* Title: HOL/Real.thy Author: Jacques D. Fleuriot, University of Edinburgh, 1998 Author: Larry Paulson, University of Cambridge Author: Jeremy Avigad, Carnegie Mellon University Author: Florian Zuleger, Johannes Hoelzl, and Simon Funke, TU Muenchen Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4 Construction of Cauchy Reals by Brian Huffman, 2010 *)
section‹Development of the Reals using Cauchy Sequences›
theory Real imports Rat begin
text‹ This theory contains a formalization of the real numbers as equivalence classes of Cauchy sequences of rationals. See the AFP entry @{text Dedekind_Real} for an alternative construction using Dedekind cuts. ›
subsection‹Preliminary lemmas›
text‹Useful in convergence arguments› lemma inverse_of_nat_le: fixes n::nat shows"[n ≤ m; n≠0]==> 1 / of_nat m ≤ (1::'a::linordered_field) / of_nat n" by (simp add: frac_le)
lemma add_diff_add: "(a + c) - (b + d) = (a - b) + (c - d)" for a b c d :: "'a::ab_group_add" by simp
lemma minus_diff_minus: "- a - - b = - (a - b)" for a b :: "'a::ab_group_add" by simp
lemma mult_diff_mult: "(x * y - a * b) = x * (y - b) + (x - a) * b" for x y a b :: "'a::ring" by (simp add: algebra_simps)
lemma inverse_diff_inverse: fixes a b :: "'a::division_ring" assumes"a ≠ 0"and"b ≠ 0" shows"inverse a - inverse b = - (inverse a * (a - b) * inverse b)" using assms by (simp add: algebra_simps)
lemma obtain_pos_sum: fixes r :: rat assumes r: "0 < r" obtains s t where"0 < s"and"0 < t"and"r = s + t" proof from r show"0 < r/2"by simp from r show"0 < r/2"by simp show"r = r/2 + r/2"by simp qed
lemma vanishesI: "(∧r. 0 < r ==>∃k. ∀n≥k. ∣X n∣ < r) ==> vanishes X" unfolding vanishes_def by simp
lemma vanishesD: "vanishes X ==> 0 < r ==>∃k. ∀n≥k. ∣X n∣ < r" unfolding vanishes_def by simp
lemma vanishes_const [simp]: "vanishes (λn. c) ⟷ c = 0" proof (cases "c = 0") case True thenshow ?thesis by (simp add: vanishesI) next case False thenshow ?thesis unfolding vanishes_def using zero_less_abs_iff by blast qed
lemma vanishes_minus: "vanishes X ==> vanishes (λn. - X n)" unfolding vanishes_def by simp
lemma vanishes_add: assumes X: "vanishes X" and Y: "vanishes Y" shows"vanishes (λn. X n + Y n)" proof (rule vanishesI) fix r :: rat assume"0 < r" thenobtain s t where s: "0 < s"and t: "0 < t"and r: "r = s + t" by (rule obtain_pos_sum) obtain i where i: "∀n≥i. ∣X n∣ < s" using vanishesD [OF X s] .. obtain j where j: "∀n≥j. ∣Y n∣ < t" using vanishesD [OF Y t] .. have"∀n≥max i j. ∣X n + Y n∣ < r" proof clarsimp fix n assume n: "i ≤ n""j ≤ n" have"∣X n + Y n∣≤∣X n∣ + ∣Y n∣" by (rule abs_triangle_ineq) alsohave"… < s + t" by (simp add: add_strict_mono i j n) finallyshow"∣X n + Y n∣ < r" by (simp only: r) qed thenshow"∃k. ∀n≥k. ∣X n + Y n∣ < r" .. qed
lemma vanishes_diff: assumes"vanishes X""vanishes Y" shows"vanishes (λn. X n - Y n)" unfolding diff_conv_add_uminus by (intro vanishes_add vanishes_minus assms)
lemma vanishes_mult_bounded: assumes X: "∃a>0. ∀n. ∣X n∣ < a" assumes Y: "vanishes (λn. Y n)" shows"vanishes (λn. X n * Y n)" proof (rule vanishesI) fix r :: rat assume r: "0 < r" obtain a where a: "0 < a""∀n. ∣X n∣ < a" using X by blast obtain b where b: "0 < b""r = a * b" proof show"0 < r / a"using r a by simp show"r = a * (r / a)"using a by simp qed obtain k where k: "∀n≥k. ∣Y n∣ < b" using vanishesD [OF Y b(1)] .. have"∀n≥k. ∣X n * Y n∣ < r" by (simp add: b(2) abs_mult mult_strict_mono' a k) thenshow"∃k. ∀n≥k. ∣X n * Y n∣ < r" .. qed
subsection‹Cauchy sequences›
definition cauchy :: "(nat ==> rat) ==> bool" where"cauchy X ⟷ (∀r>0. ∃k. ∀m≥k. ∀n≥k. ∣X m - X n∣ < r)"
lemma cauchyI: "(∧r. 0 < r ==>∃k. ∀m≥k. ∀n≥k. ∣X m - X n∣ < r) ==> cauchy X" unfolding cauchy_def by simp
lemma cauchyD: "cauchy X ==> 0 < r ==>∃k. ∀m≥k. ∀n≥k. ∣X m - X n∣ < r" unfolding cauchy_def by simp
lemma cauchy_const [simp]: "cauchy (λn. x)" unfolding cauchy_def by simp
lemma cauchy_add [simp]: assumes X: "cauchy X"and Y: "cauchy Y" shows"cauchy (λn. X n + Y n)" proof (rule cauchyI) fix r :: rat assume"0 < r" thenobtain s t where s: "0 < s"and t: "0 < t"and r: "r = s + t" by (rule obtain_pos_sum) obtain i where i: "∀m≥i. ∀n≥i. ∣X m - X n∣ < s" using cauchyD [OF X s] .. obtain j where j: "∀m≥j. ∀n≥j. ∣Y m - Y n∣ < t" using cauchyD [OF Y t] .. have"∀m≥max i j. ∀n≥max i j. ∣(X m + Y m) - (X n + Y n)∣ < r" proof clarsimp fix m n assume *: "i ≤ m""j ≤ m""i ≤ n""j ≤ n" have"∣(X m + Y m) - (X n + Y n)∣≤∣X m - X n∣ + ∣Y m - Y n∣" unfolding add_diff_add by (rule abs_triangle_ineq) alsohave"… < s + t" by (rule add_strict_mono) (simp_all add: i j *) finallyshow"∣(X m + Y m) - (X n + Y n)∣ < r"by (simp only: r) qed thenshow"∃k. ∀m≥k. ∀n≥k. ∣(X m + Y m) - (X n + Y n)∣ < r" .. qed
lemma cauchy_minus [simp]: assumes X: "cauchy X" shows"cauchy (λn. - X n)" using assms unfolding cauchy_def unfolding minus_diff_minus abs_minus_cancel .
lemma cauchy_diff [simp]: assumes"cauchy X""cauchy Y" shows"cauchy (λn. X n - Y n)" using assms unfolding diff_conv_add_uminus by (simp del: add_uminus_conv_diff)
lemma cauchy_imp_bounded: assumes"cauchy X" shows"∃b>0. ∀n. ∣X n∣ < b" proof - obtain k where k: "∀m≥k. ∀n≥k. ∣X m - X n∣ < 1" using cauchyD [OF assms zero_less_one] .. show"∃b>0. ∀n. ∣X n∣ < b" proof (intro exI conjI allI) have"0 ≤∣X 0∣"by simp alsohave"∣X 0∣≤ Max (abs ` X ` {..k})"by simp finallyhave"0 ≤ Max (abs ` X ` {..k})" . thenshow"0 < Max (abs ` X ` {..k}) + 1"by simp next fix n :: nat show"∣X n∣ < Max (abs ` X ` {..k}) + 1" proof (rule linorder_le_cases) assume"n ≤ k" thenhave"∣X n∣≤ Max (abs ` X ` {..k})"by simp thenshow"∣X n∣ < Max (abs ` X ` {..k}) + 1"by simp next assume"k ≤ n" have"∣X n∣ = ∣X k + (X n - X k)∣"by simp alsohave"∣X k + (X n - X k)∣≤∣X k∣ + ∣X n - X k∣" by (rule abs_triangle_ineq) alsohave"… < Max (abs ` X ` {..k}) + 1" by (rule add_le_less_mono) (simp_all add: k ‹k ≤ n›) finallyshow"∣X n∣ < Max (abs ` X ` {..k}) + 1" . qed qed qed
lemma cauchy_mult [simp]: assumes X: "cauchy X"and Y: "cauchy Y" shows"cauchy (λn. X n * Y n)" proof (rule cauchyI) fix r :: rat assume"0 < r" thenobtain u v where u: "0 < u"and v: "0 < v"and"r = u + v" by (rule obtain_pos_sum) obtain a where a: "0 < a""∀n. ∣X n∣ < a" using cauchy_imp_bounded [OF X] by blast obtain b where b: "0 < b""∀n. ∣Y n∣ < b" using cauchy_imp_bounded [OF Y] by blast obtain s t where s: "0 < s"and t: "0 < t"and r: "r = a * t + s * b" proof show"0 < v/b"using v b(1) by simp show"0 < u/a"using u a(1) by simp show"r = a * (u/a) + (v/b) * b" using a(1) b(1) ‹r = u + v›by simp qed obtain i where i: "∀m≥i. ∀n≥i. ∣X m - X n∣ < s" using cauchyD [OF X s] .. obtain j where j: "∀m≥j. ∀n≥j. ∣Y m - Y n∣ < t" using cauchyD [OF Y t] .. have"∀m≥max i j. ∀n≥max i j. ∣X m * Y m - X n * Y n∣ < r" proof clarsimp fix m n assume *: "i ≤ m""j ≤ m""i ≤ n""j ≤ n" have"∣X m * Y m - X n * Y n∣ = ∣X m * (Y m - Y n) + (X m - X n) * Y n∣" unfolding mult_diff_mult .. alsohave"…≤∣X m * (Y m - Y n)∣ + ∣(X m - X n) * Y n∣" by (rule abs_triangle_ineq) alsohave"… = ∣X m∣ * ∣Y m - Y n∣ + ∣X m - X n∣ * ∣Y n∣" unfolding abs_mult .. alsohave"… < a * t + s * b" by (simp_all add: add_strict_mono mult_strict_mono' a b i j *) finallyshow"∣X m * Y m - X n * Y n∣ < r" by (simp only: r) qed thenshow"∃k. ∀m≥k. ∀n≥k. ∣X m * Y m - X n * Y n∣ < r" .. qed
lemma cauchy_not_vanishes_cases: assumes X: "cauchy X" assumes nz: "¬ vanishes X" shows"∃b>0. ∃k. (∀n≥k. b < - X n) ∨ (∀n≥k. b < X n)" proof - obtain r where"0 < r"and r: "∀k. ∃n≥k. r ≤∣X n∣" using nz unfolding vanishes_def by (auto simp add: not_less) obtain s t where s: "0 < s"and t: "0 < t"and"r = s + t" using‹0 🚫›by (rule obtain_pos_sum) obtain i where i: "∀m≥i. ∀n≥i. ∣X m - X n∣ < s" using cauchyD [OF X s] .. obtain k where"i ≤ k"and"r ≤∣X k∣" using r by blast have k: "∀n≥k. ∣X n - X k∣ < s" using i ‹i ≤ k›by auto have"X k ≤ - r ∨ r ≤ X k" using‹r ≤∣X k∣›by auto thenhave"(∀n≥k. t < - X n) ∨ (∀n≥k. t < X n)" unfolding‹r = s + t›using k by auto thenhave"∃k. (∀n≥k. t < - X n) ∨ (∀n≥k. t < X n)" .. thenshow"∃t>0. ∃k. (∀n≥k. t < - X n) ∨ (∀n≥k. t < X n)" using t by auto qed
lemma cauchy_not_vanishes: assumes X: "cauchy X" and nz: "¬ vanishes X" shows"∃b>0. ∃k. ∀n≥k. b < ∣X n∣" using cauchy_not_vanishes_cases [OF assms] by (elim ex_forward conj_forward asm_rl) auto
lemma cauchy_inverse [simp]: assumes X: "cauchy X" and nz: "¬ vanishes X" shows"cauchy (λn. inverse (X n))" proof (rule cauchyI) fix r :: rat assume"0 < r" obtain b i where b: "0 < b"and i: "∀n≥i. b < ∣X n∣" using cauchy_not_vanishes [OF X nz] by blast from b i have nz: "∀n≥i. X n ≠ 0"by auto obtain s where s: "0 < s"and r: "r = inverse b * s * inverse b" proof show"0 < b * r * b"by (simp add: ‹0 🚫› b) show"r = inverse b * (b * r * b) * inverse b" using b by simp qed obtain j where j: "∀m≥j. ∀n≥j. ∣X m - X n∣ < s" using cauchyD [OF X s] .. have"∀m≥max i j. ∀n≥max i j. ∣inverse (X m) - inverse (X n)∣ < r" proof clarsimp fix m n assume *: "i ≤ m""j ≤ m""i ≤ n""j ≤ n" have"∣inverse (X m) - inverse (X n)∣ = inverse ∣X m∣ * ∣X m - X n∣ * inverse ∣X n∣" by (simp add: inverse_diff_inverse nz * abs_mult) alsohave"… < inverse b * s * inverse b" by (simp add: mult_strict_mono less_imp_inverse_less i j b * s) finallyshow"∣inverse (X m) - inverse (X n)∣ < r"by (simp only: r) qed thenshow"∃k. ∀m≥k. ∀n≥k. ∣inverse (X m) - inverse (X n)∣ < r" .. qed
lemma vanishes_diff_inverse: assumes X: "cauchy X""¬ vanishes X" and Y: "cauchy Y""¬ vanishes Y" and XY: "vanishes (λn. X n - Y n)" shows"vanishes (λn. inverse (X n) - inverse (Y n))" proof (rule vanishesI) fix r :: rat assume r: "0 < r" obtain a i where a: "0 < a"and i: "∀n≥i. a < ∣X n∣" using cauchy_not_vanishes [OF X] by blast obtain b j where b: "0 < b"and j: "∀n≥j. b < ∣Y n∣" using cauchy_not_vanishes [OF Y] by blast obtain s where s: "0 < s"and"inverse a * s * inverse b = r" proof show"0 < a * r * b" using a r b by simp show"inverse a * (a * r * b) * inverse b = r" using a r b by simp qed obtain k where k: "∀n≥k. ∣X n - Y n∣ < s" using vanishesD [OF XY s] .. have"∀n≥max (max i j) k. ∣inverse (X n) - inverse (Y n)∣ < r" proof clarsimp fix n assume n: "i ≤ n""j ≤ n""k ≤ n" with i j a b have"X n ≠ 0"and"Y n ≠ 0" by auto thenhave"∣inverse (X n) - inverse (Y n)∣ = inverse ∣X n∣ * ∣X n - Y n∣ * inverse∣Y n∣" by (simp add: inverse_diff_inverse abs_mult) alsohave"… < inverse a * s * inverse b" by (intro mult_strict_mono' less_imp_inverse_less) (simp_all add: a b i j k n) alsonote‹inverse a * s * inverse b = r› finallyshow"∣inverse (X n) - inverse (Y n)∣ < r" . qed thenshow"∃k. ∀n≥k. ∣inverse (X n) - inverse (Y n)∣ < r" .. qed
subsection‹Equivalence relation on Cauchy sequences›
definition realrel :: "(nat ==> rat) ==> (nat ==> rat) ==> bool" where"realrel = (λX Y. cauchy X ∧ cauchy Y ∧ vanishes (λn. X n - Y n))"
lemma realrelI [intro?]: "cauchy X ==> cauchy Y ==> vanishes (λn. X n - Y n) ==> realrel X Y" by (simp add: realrel_def)
lemma realrel_refl: "cauchy X ==> realrel X X" by (simp add: realrel_def)
quotient_type real = "nat ==> rat" / partial: realrel morphisms rep_real Real by (rule part_equivp_realrel)
lemma cr_real_eq: "pcr_real = (λx y. cauchy x ∧ Real x = y)" unfolding real.pcr_cr_eq cr_real_def realrel_def by auto
lemma Real_induct [induct type: real]: (* TODO: generate automatically *) assumes"∧X. cauchy X ==> P (Real X)" shows"P x" proof (induct x) case (1 X) thenhave"cauchy X"by (simp add: realrel_def) thenshow"P (Real X)"by (rule assms) qed
lemma eq_Real: "cauchy X ==> cauchy Y ==> Real X = Real Y ⟷ vanishes (λn. X n - Y n)" using real.rel_eq_transfer unfolding real.pcr_cr_eq cr_real_def rel_fun_def realrel_def by simp
lift_definition zero_real :: "real"is"λn. 0" by (simp add: realrel_refl)
lift_definition one_real :: "real"is"λn. 1" by (simp add: realrel_refl)
lift_definition plus_real :: "real ==> real ==> real"is"λX Y n. X n + Y n" unfolding realrel_def add_diff_add by (simp only: cauchy_add vanishes_add simp_thms)
lift_definition uminus_real :: "real ==> real"is"λX n. - X n" unfolding realrel_def minus_diff_minus by (simp only: cauchy_minus vanishes_minus simp_thms)
lift_definition times_real :: "real ==> real ==> real"is"λX Y n. X n * Y n" proof - fix f1 f2 f3 f4 have"[cauchy f1; cauchy f4; vanishes (λn. f1 n - f2 n); vanishes (λn. f3 n - f4 n)] ==> vanishes (λn. f1 n * (f3 n - f4 n) + f4 n * (f1 n - f2 n))" by (simp add: vanishes_add vanishes_mult_bounded cauchy_imp_bounded) thenshow"[realrel f1 f2; realrel f3 f4]==> realrel (λn. f1 n * f3 n) (λn. f2 n * f4 n)" by (simp add: mult.commute realrel_def mult_diff_mult) qed
lift_definition inverse_real :: "real ==> real" is"λX. if vanishes X then (λn. 0) else (λn. inverse (X n))" proof - fix X Y assume"realrel X Y" thenhave X: "cauchy X"and Y: "cauchy Y"and XY: "vanishes (λn. X n - Y n)" by (simp_all add: realrel_def) have"vanishes X ⟷ vanishes Y" proof assume"vanishes X" from vanishes_diff [OF this XY] show"vanishes Y" by simp next assume"vanishes Y" from vanishes_add [OF this XY] show"vanishes X" by simp qed thenshow"?thesis X Y" by (simp add: vanishes_diff_inverse X Y XY realrel_def) qed
definition"x - y = x + - y"for x y :: real
definition"x div y = x * inverse y"for x y :: real
lemma add_Real: "cauchy X ==> cauchy Y ==> Real X + Real Y = Real (λn. X n + Y n)" using plus_real.transfer by (simp add: cr_real_eq rel_fun_def)
lemma minus_Real: "cauchy X ==> - Real X = Real (λn. - X n)" using uminus_real.transfer by (simp add: cr_real_eq rel_fun_def)
lemma diff_Real: "cauchy X ==> cauchy Y ==> Real X - Real Y = Real (λn. X n - Y n)" by (simp add: minus_Real add_Real minus_real_def)
lemma mult_Real: "cauchy X ==> cauchy Y ==> Real X * Real Y = Real (λn. X n * Y n)" using times_real.transfer by (simp add: cr_real_eq rel_fun_def)
lemma inverse_Real: "cauchy X ==> inverse (Real X) = (if vanishes X then 0 else Real (λn. inverse (X n)))" using inverse_real.transfer zero_real.transfer unfolding cr_real_eq rel_fun_def by (simp split: if_split_asm, metis)
instance proof fix a b c :: real show"a + b = b + a" by transfer (simp add: ac_simps realrel_def) show"(a + b) + c = a + (b + c)" by transfer (simp add: ac_simps realrel_def) show"0 + a = a" by transfer (simp add: realrel_def) show"- a + a = 0" by transfer (simp add: realrel_def) show"a - b = a + - b" by (rule minus_real_def) show"(a * b) * c = a * (b * c)" by transfer (simp add: ac_simps realrel_def) show"a * b = b * a" by transfer (simp add: ac_simps realrel_def) show"1 * a = a" by transfer (simp add: ac_simps realrel_def) show"(a + b) * c = a * c + b * c" by transfer (simp add: distrib_right realrel_def) show"(0::real) ≠ (1::real)" by transfer (simp add: realrel_def) have"vanishes (λn. inverse (X n) * X n - 1)"if X: "cauchy X""¬ vanishes X"for X proof (rule vanishesI) fix r::rat assume"0 < r" obtain b k where"b>0""∀n≥k. b < ∣X n∣" using X cauchy_not_vanishes by blast thenshow"∃k. ∀n≥k. ∣inverse (X n) * X n - 1∣ < r" using‹0 🚫›by force qed thenshow"a ≠ 0 ==> inverse a * a = 1" by transfer (simp add: realrel_def) show"a div b = a * inverse b" by (rule divide_real_def) show"inverse (0::real) = 0" by transfer (simp add: realrel_def) qed
end
subsection‹Positive reals›
lift_definition positive :: "real ==> bool" is"λX. ∃r>0. ∃k. ∀n≥k. r < X n" proof - have 1: "∃r>0. ∃k. ∀n≥k. r < Y n" if *: "realrel X Y"and **: "∃r>0. ∃k. ∀n≥k. r < X n"for X Y proof - from * have XY: "vanishes (λn. X n - Y n)" by (simp_all add: realrel_def) from ** obtain r i where"0 < r"and i: "∀n≥i. r < X n" by blast obtain s t where s: "0 < s"and t: "0 < t"and r: "r = s + t" using‹0 🚫›by (rule obtain_pos_sum) obtain j where j: "∀n≥j. ∣X n - Y n∣ < s" using vanishesD [OF XY s] .. have"∀n≥max i j. t < Y n" proof clarsimp fix n assume n: "i ≤ n""j ≤ n" have"∣X n - Y n∣ < s"and"r < X n" using i j n by simp_all thenshow"t < Y n"by (simp add: r) qed thenshow ?thesis using t by blast qed fix X Y assume"realrel X Y" thenhave"realrel X Y"and"realrel Y X" using symp_realrel by (auto simp: symp_def) thenshow"?thesis X Y" by (safe elim!: 1) qed
lemma positive_Real: "cauchy X ==> positive (Real X) ⟷ (∃r>0. ∃k. ∀n≥k. r < X n)" using positive.transfer by (simp add: cr_real_eq rel_fun_def)
lemma positive_zero: "¬ positive 0" by transfer auto
lemma positive_add: assumes"positive x""positive y"shows"positive (x + y)" proof - have *: "[∀n≥i. a < x n; ∀n≥j. b < y n; 0 < a; 0 < b; n ≥ max i j] ==> a+b < x n + y n"for x y and a b::rat and i j n::nat by (simp add: add_strict_mono) show ?thesis using assms by transfer (blast intro: * pos_add_strict) qed
lemma positive_mult: assumes"positive x""positive y"shows"positive (x * y)" proof - have *: "[∀n≥i. a < x n; ∀n≥j. b < y n; 0 < a; 0 < b; n ≥ max i j] ==> a*b < x n * y n"for x y and a b::rat and i j n::nat by (simp add: mult_strict_mono') show ?thesis using assms by transfer (blast intro: * mult_pos_pos) qed
lemma positive_minus: "¬ positive x ==> x ≠ 0 ==> positive (- x)" apply transfer apply (simp add: realrel_def) apply (blast dest: cauchy_not_vanishes_cases) done
instantiation real :: linordered_field begin
definition"x < y ⟷ positive (y - x)"
definition"x ≤ y ⟷ x < y ∨ x = y"for x y :: real
definition"∣a∣ = (if a < 0 then - a else a)"for a :: real
definition"sgn a = (if a = 0 then 0 else if 0 < a then 1 else - 1)"for a :: real
instance proof fix a b c :: real show"∣a∣ = (if a < 0 then - a else a)" by (rule abs_real_def) show"a < b ⟷ a ≤ b ∧¬ b ≤ a" "a ≤ b ==> b ≤ c ==> a ≤ c""a ≤ a" "a ≤ b ==> b ≤ a ==> a = b" "a ≤ b ==> c + a ≤ c + b" unfolding less_eq_real_def less_real_def by (force simp add: positive_zero dest: positive_add)+ show"sgn a = (if a = 0 then 0 else if 0 < a then 1 else - 1)" by (rule sgn_real_def) show"a ≤ b ∨ b ≤ a" by (auto dest!: positive_minus simp: less_eq_real_def less_real_def) show"a < b ==> 0 < c ==> c * a < c * b" unfolding less_real_def by (force simp add: algebra_simps dest: positive_mult) qed
end
instantiation real :: distrib_lattice begin
definition"(inf :: real ==> real ==> real) = min"
definition"(sup :: real ==> real ==> real) = max"
instance by standard (auto simp add: inf_real_def sup_real_def max_min_distrib2)
end
lemma of_nat_Real: "of_nat x = Real (λn. of_nat x)" by (induct x) (simp_all add: zero_real_def one_real_def add_Real)
lemma of_int_Real: "of_int x = Real (λn. of_int x)" by (cases x rule: int_diff_cases) (simp add: of_nat_Real diff_Real)
lemma of_rat_Real: "of_rat x = Real (λn. x)" proof (induct x) case (Fract a b) thenshow ?case apply (simp add: Fract_of_int_quotient of_rat_divide) apply (simp add: of_int_Real divide_inverse inverse_Real mult_Real) done qed
instance real :: archimedean_field proof show"∃z. x ≤ of_int z"for x :: real proof (induct x) case (1 X) thenobtain b where"0 < b"and b: "∧n. ∣X n∣ < b" by (blast dest: cauchy_imp_bounded) thenhave"Real X < of_int (⌈b⌉ + 1)" using 1 apply (simp add: of_int_Real less_real_def diff_Real positive_Real) apply (rule_tac x=1 in exI) apply (simp add: algebra_simps) by (metis abs_ge_self le_less_trans le_of_int_ceiling less_le) thenshow ?case using less_eq_real_def by blast qed qed
instantiation real :: floor_ceiling begin
definition [code del]: "⌊x::real⌋ = (THE z. of_int z ≤ x ∧ x < of_int (z + 1))"
instance proof show"of_int ⌊x⌋≤ x ∧ x < of_int (⌊x⌋ + 1)"for x :: real unfolding floor_real_def using floor_exists1 by (rule theI') qed
end
subsection‹Completeness›
lemma not_positive_Real: assumes"cauchy X"shows"¬ positive (Real X) ⟷ (∀r>0. ∃k. ∀n≥k. X n ≤ r)" (is"?lhs = ?rhs") unfolding positive_Real [OF assms] proof (intro iffI allI notI impI) show"∃k. ∀n≥k. X n ≤ r"if r: "¬ (∃r>0. ∃k. ∀n≥k. r < X n)"and"0 < r"for r proof - obtain s t where"s > 0""t > 0""r = s+t" using‹r > 0› obtain_pos_sum by blast obtain k where k: "∧m n. [m≥k; n≥k]==>∣X m - X n∣ < t" using cauchyD [OF assms ‹t > 0›] by blast obtain n where"n ≥ k""X n ≤ s" by (meson r ‹0 🚫› not_less) thenhave"X l ≤ r"if"l ≥ n"for l using k [OF ‹n ≥ k›, of l] that ‹r = s+t›by linarith thenshow ?thesis by blast qed qed (meson le_cases not_le)
lemma le_Real: assumes"cauchy X""cauchy Y" shows"Real X ≤ Real Y = (∀r>0. ∃k. ∀n≥k. X n ≤ Y n + r)" unfolding not_less [symmetric, where 'a=real] less_real_def apply (simp add: diff_Real not_positive_Real assms) apply (simp add: diff_le_eq ac_simps) done
lemma le_RealI: assumes Y: "cauchy Y" shows"∀n. x ≤ of_rat (Y n) ==> x ≤ Real Y" proof (induct x) fix X assume X: "cauchy X"and"∀n. Real X ≤ of_rat (Y n)" thenhave le: "∧m r. 0 < r ==>∃k. ∀n≥k. X n ≤ Y m + r" by (simp add: of_rat_Real le_Real) thenhave"∃k. ∀n≥k. X n ≤ Y n + r"if"0 < r"for r :: rat proof - from that obtain s t where s: "0 < s"and t: "0 < t"and r: "r = s + t" by (rule obtain_pos_sum) obtain i where i: "∀m≥i. ∀n≥i. ∣Y m - Y n∣ < s" using cauchyD [OF Y s] .. obtain j where j: "∀n≥j. X n ≤ Y i + t" using le [OF t] .. have"∀n≥max i j. X n ≤ Y n + r" proof clarsimp fix n assume n: "i ≤ n""j ≤ n" have"X n ≤ Y i + t" using n j by simp moreoverhave"∣Y i - Y n∣ < s" using n i by simp ultimatelyshow"X n ≤ Y n + r" unfolding r by simp qed thenshow ?thesis .. qed thenshow"Real X ≤ Real Y" by (simp add: of_rat_Real le_Real X Y) qed
lemma Real_leI: assumes X: "cauchy X" assumes le: "∀n. of_rat (X n) ≤ y" shows"Real X ≤ y" proof - have"- y ≤ - Real X" by (simp add: minus_Real X le_RealI of_rat_minus le) thenshow ?thesis by simp qed
lemma less_RealD: assumes"cauchy Y" shows"x < Real Y ==>∃n. x < of_rat (Y n)" by (meson Real_leI assms leD leI)
lemma of_nat_less_two_power [simp]: "of_nat n < (2::'a::linordered_idom) ^ n" by auto
lemma complete_real: fixes S :: "real set" assumes"∃x. x ∈ S"and"∃z. ∀x∈S. x ≤ z" shows"∃y. (∀x∈S. x ≤ y) ∧ (∀z. (∀x∈S. x ≤ z) ⟶ y ≤ z)" proof - obtain x where x: "x ∈ S"using assms(1) .. obtain z where z: "∀x∈S. x ≤ z"using assms(2) ..
define P where"P x ⟷ (∀y∈S. y ≤ of_rat x)"for x obtain a where a: "¬ P a" proof have"of_int ⌊x - 1⌋≤ x - 1"by (rule of_int_floor_le) alsohave"x - 1 < x"by simp finallyhave"of_int ⌊x - 1⌋ < x" . thenhave"¬ x ≤ of_int ⌊x - 1⌋"by (simp only: not_le) thenshow"¬ P (of_int ⌊x - 1⌋)" unfolding P_def of_rat_of_int_eq using x by blast qed obtain b where b: "P b" proof show"P (of_int ⌈z⌉)" unfolding P_def of_rat_of_int_eq proof fix y assume"y ∈ S" thenhave"y ≤ z"using z by simp alsohave"z ≤ of_int ⌈z⌉"by (rule le_of_int_ceiling) finallyshow"y ≤ of_int ⌈z⌉" . qed qed
define avg where"avg x y = x/2 + y/2"for x y :: rat
define bisect where"bisect = (λ(x, y). if P (avg x y) then (x, avg x y) else (avg x y, y))"
define A where"A n = fst ((bisect ^^ n) (a, b))"for n
define B where"B n = snd ((bisect ^^ n) (a, b))"for n
define C where"C n = avg (A n) (B n)"for n have A_0 [simp]: "A 0 = a"unfolding A_def by simp have B_0 [simp]: "B 0 = b"unfolding B_def by simp have A_Suc [simp]: "∧n. A (Suc n) = (if P (C n) then A n else C n)" unfolding A_def B_def C_def bisect_def split_def by simp have B_Suc [simp]: "∧n. B (Suc n) = (if P (C n) then C n else B n)" unfolding A_def B_def C_def bisect_def split_def by simp
have width: "B n - A n = (b - a) / 2^n"for n proof (induct n) case (Suc n) thenshow ?case by (simp add: C_def eq_divide_eq avg_def algebra_simps) qed simp have twos: "∃n. y / 2 ^ n < r"if"0 < r"for y r :: rat proof - obtain n where"y / r < rat_of_nat n" using‹0 🚫› reals_Archimedean2 by blast thenhave"∃n. y < r * 2 ^ n" by (metis divide_less_eq less_trans mult.commute of_nat_less_two_power that) thenshow ?thesis by (simp add: field_split_simps) qed have PA: "¬ P (A n)"for n by (induct n) (simp_all add: a) have PB: "P (B n)"for n by (induct n) (simp_all add: b) have ab: "a < b" using a b unfolding P_def by (meson leI less_le_trans of_rat_less) have AB: "A n < B n"for n by (induct n) (simp_all add: ab C_def avg_def) have"A i ≤ A j ∧ B j ≤ B i"if"i < j"for i j using that proof (induction rule: less_Suc_induct) case (1 i) thenshow ?case apply (clarsimp simp add: C_def avg_def add_divide_distrib [symmetric]) apply (rule AB [THEN less_imp_le]) done qed simp thenhave A_mono: "A i ≤ A j"and B_mono: "B j ≤ B i"if"i ≤ j"for i j by (metis eq_refl le_neq_implies_less that)+ have cauchy_lemma: "cauchy X"if *: "∧n i. i≥n ==> A n ≤ X i ∧ X i ≤ B n"for X proof (rule cauchyI) fix r::rat assume"0 < r" thenobtain k where k: "(b - a) / 2 ^ k < r" using twos by blast have"∣X m - X n∣ < r"if"m≥k""n≥k"for m n proof - have"∣X m - X n∣≤ B k - A k" by (simp add: * abs_rat_def diff_mono that) alsohave"... < r" by (simp add: k width) finallyshow ?thesis . qed thenshow"∃k. ∀m≥k. ∀n≥k. ∣X m - X n∣ < r" by blast qed have"cauchy A" by (rule cauchy_lemma) (meson AB A_mono B_mono dual_order.strict_implies_order less_le_trans) have"cauchy B" by (rule cauchy_lemma) (meson AB A_mono B_mono dual_order.strict_implies_order le_less_trans) have"∀x∈S. x ≤ Real B" proof fix x assume"x ∈ S" thenshow"x ≤ Real B" using PB [unfolded P_def] ‹cauchy B› by (simp add: le_RealI) qed moreoverhave"∀z. (∀x∈S. x ≤ z) ⟶ Real A ≤ z" by (meson PA Real_leI P_def ‹cauchy A› le_cases order.trans) moreoverhave"vanishes (λn. (b - a) / 2 ^ n)" proof (rule vanishesI) fix r :: rat assume"0 < r" thenobtain k where k: "∣b - a∣ / 2 ^ k < r" using twos by blast have"∀n≥k. ∣(b - a) / 2 ^ n∣ < r" proof clarify fix n assume n: "k ≤ n" have"∣(b - a) / 2 ^ n∣ = ∣b - a∣ / 2 ^ n" by simp alsohave"…≤∣b - a∣ / 2 ^ k" using n by (simp add: divide_left_mono) alsonote k finallyshow"∣(b - a) / 2 ^ n∣ < r" . qed thenshow"∃k. ∀n≥k. ∣(b - a) / 2 ^ n∣ < r" .. qed thenhave"Real B = Real A" by (simp add: eq_Real ‹cauchy A›‹cauchy B› width) ultimatelyshow"∃y. (∀x∈S. x ≤ y) ∧ (∀z. (∀x∈S. x ≤ z) ⟶ y ≤ z)" by force qed
instantiation real :: linear_continuum begin
subsection‹Supremum of a set of reals›
definition"Sup X = (LEAST z::real. ∀x∈X. x ≤ z)" definition"Inf X = - Sup (uminus ` X)"for X :: "real set"
instance proof show Sup_upper: "x ≤ Sup X" if"x ∈ X""bdd_above X" for x :: real and X :: "real set" proof - from that obtain s where s: "∀y∈X. y ≤ s""∧z. ∀y∈X. y ≤ z ==> s ≤ z" using complete_real[of X] unfolding bdd_above_def by blast thenshow ?thesis unfolding Sup_real_def by (rule LeastI2_order) (auto simp: that) qed show Sup_least: "Sup X ≤ z" if"X ≠ {}"and z: "∧x. x ∈ X ==> x ≤ z" for z :: real and X :: "real set" proof - from that obtain s where s: "∀y∈X. y ≤ s""∧z. ∀y∈X. y ≤ z ==> s ≤ z" using complete_real [of X] by blast thenhave"Sup X = s" unfolding Sup_real_def by (best intro: Least_equality) alsofrom s z have"…≤ z" by blast finallyshow ?thesis . qed show"Inf X ≤ x"if"x ∈ X""bdd_below X" for x :: real and X :: "real set" using Sup_upper [of "-x""uminus ` X"] by (auto simp: Inf_real_def that) show"z ≤ Inf X"if"X ≠ {}""∧x. x ∈ X ==> z ≤ x" for z :: real and X :: "real set" using Sup_least [of "uminus ` X""- z"] by (force simp: Inf_real_def that) show"∃a b::real. a ≠ b" using zero_neq_one by blast qed
(* We do not add rat to the coerced types, this has often unpleasant side effects when writing inverse (Suc n) which sometimes gets two coercions: of_rat (inverse (of_nat (Suc n))) *)
declare [[coercion_map map]] declare [[coercion_map "λf g h x. g (h (f x))"]] declare [[coercion_map "λf g (x,y). (f x, g y)"]]
lemma int_less_real_le: "n < m ⟷ real_of_int n + 1 ≤ real_of_int m" proof - have"(0::real) ≤ 1" by (metis less_eq_real_def zero_less_one) thenshow ?thesis by (metis floor_of_int less_floor_iff) qed
lemma int_le_real_less: "n ≤ m ⟷ real_of_int n < real_of_int m + 1" by (meson int_less_real_le not_le)
lemma (in field_char_0) of_int_div_aux: "(of_int x) / (of_int d) = of_int (x div d) + (of_int (x mod d)) / (of_int d)" proof - have"x = (x div d) * d + x mod d" by auto thenhave"of_int x = of_int (x div d) * of_int d + of_int(x mod d)" by (metis local.of_int_add local.of_int_mult) thenshow ?thesis by (simp add: divide_simps) qed
lemma real_of_int_div: "d dvd n ==> real_of_int (n div d) = real_of_int n / real_of_int d"for d n :: int by auto
lemma real_of_int_div2: "0 ≤ real_of_int n / real_of_int x - real_of_int (n div x)" proof (cases "x = 0") case False thenshow ?thesis by (metis diff_ge_0_iff_ge floor_divide_of_int_eq of_int_floor_le) qed simp
lemma real_of_int_div3: "real_of_int n / real_of_int x - real_of_int (n div x) ≤ 1" apply (simp add: algebra_simps) by (metis add.commute floor_correct floor_divide_of_int_eq less_eq_real_def of_int_1 of_int_add)
lemma real_of_int_div4: "real_of_int (n div x) ≤ real_of_int n / real_of_int x" using real_of_int_div2 [of n x] by simp
subsection‹Embedding the Naturals into the Reals›
lemma (in field_char_0) of_nat_of_nat_div_aux: "of_nat x / of_nat d = of_nat (x div d) + of_nat (x mod d) / of_nat d" by (metis add_divide_distrib diff_add_cancel of_nat_div)
lemma(in field_char_0) of_nat_of_nat_div: "d dvd n ==> of_nat(n div d) = of_nat n / of_nat d" by auto
lemma (in linordered_field) of_nat_div_le_of_nat: "of_nat (n div x) ≤ of_nat n / of_nat x" by (metis le_add_same_cancel1 of_nat_0_le_iff of_nat_of_nat_div_aux zero_le_divide_iff)
lemma real_of_card: "real (card A) = sum (λx. 1) A" by simp
lemma nat_less_real_le: "n < m ⟷ real n + 1 ≤ real m" by (metis less_iff_succ_less_eq of_nat_1 of_nat_add of_nat_le_iff)
lemma nat_le_real_less: "n ≤ m ⟷ real n < real m + 1" by (meson nat_less_real_le not_le)
lemma real_of_nat_div: "d dvd n ==> real(n div d) = real n / real d" by auto
lemma real_binomial_eq_mult_binomial_Suc: assumes"k ≤ n" shows"real(n choose k) = (n + 1 - k) / (n + 1) * (Suc n choose k)" using assms by (simp add: of_nat_binomial_eq_mult_binomial_Suc [of k n] add.commute)
subsection‹The Archimedean Property of the Reals›
text‹Not actually the reals any more!› lemma real_arch_inverse: fixes e::"'a::archimedean_field" shows"0 < e ⟷ (∃n::nat. n ≠ 0 ∧ 0 < inverse (real n) ∧ inverse (of_nat n) < e)" using reals_Archimedean[of e] less_trans[of 0 "1 / of_nat n" e for n::nat] by (auto simp add: field_simps cong: conj_cong simp del: of_nat_Suc)
lemma reals_Archimedean3: fixes x::"'a::archimedean_field" shows"0 < x ==>∀y. ∃n. y < of_nat n * x" by (auto intro: ex_less_of_nat_mult)
lemma real_archimedian_rdiv_eq_0: fixes x::"'a::archimedean_field" assumes"x ≥ 0"and"∧m::nat. m > 0 ==> of_nat m * x ≤ c" shows"x = 0" by (metis (no_types, opaque_lifting) reals_Archimedean3 order.order_iff_strict le0 le_less_trans not_le assms)
lemma inverse_Suc: "inverse (of_nat (Suc n)) > (0::'a::archimedean_field)" using of_nat_0_less_iff positive_imp_inverse_positive zero_less_Suc by blast
lemma Archimedean_eventually_inverse: fixes ε::"'a::archimedean_field"shows"(∀🪙F n in sequentially. inverse (of_nat (Suc n)) < ε) ⟷ 0 < ε"
(is"?lhs=?rhs") proof assume ?lhs thenshow ?rhs unfolding eventually_at_top_dense by (metis (no_types, lifting) gt_ex inverse_Suc nat.distinct(1) real_arch_inverse) next assume ?rhs thenobtain N where"inverse (of_nat (Suc N)) < ε" using reals_Archimedean by blast thenhave"inverse (of_nat (Suc n)) < ε"if"n ≥ N"for n using that Suc_le_mono inverse_Suc inverse_less_imp_less by (meson inverse_positive_iff_positive linorder_not_less of_nat_less_iff order_le_less_trans) thenshow ?lhs unfolding eventually_sequentially by blast qed
(*HOL Light's FORALL_POS_MONO_1_EQ*) text‹On the relationship between two different ways of converting to 0› lemma Inter_eq_Inter_inverse_Suc: assumes"∧r' r. r' < r ==> A r' ⊆ A r" shows"∩ (A ` {0<..}) = (∩n. A(inverse(Suc n)))" proof have"x ∈ A ε" if x: "∀n. x ∈ A (inverse (Suc n))"and"ε>0"for x and ε :: real proof - obtain n where"inverse (Suc n) < ε" using‹ε>0› reals_Archimedean by blast with assms x show ?thesis by blast qed thenshow"(∩n. A(inverse(Suc n))) ⊆ (∩ε∈{0<..}. A ε)" by auto qed (use inverse_Suc in fastforce)
subsection‹Rationals›
lemma Rats_abs_iff[simp]: "∣(x::real)∣∈ℚ⟷ x ∈ℚ" by(simp add: abs_real_def split: if_splits)
lemma Rats_eq_int_div_int: "ℚ = {real_of_int i / real_of_int j | i j. j ≠ 0}" (is"_ = ?S") proof show"ℚ⊆ ?S" proof fix x :: real assume"x ∈ℚ" thenobtain r where"x = of_rat r" unfolding Rats_def .. have"of_rat r ∈ ?S" by (cases r) (auto simp add: of_rat_rat) thenshow"x ∈ ?S" using‹x = of_rat r›by simp qed next show"?S ⊆ℚ" proof (auto simp: Rats_def) fix i j :: int assume"j ≠ 0" thenhave"real_of_int i / real_of_int j = of_rat (Fract i j)" by (simp add: of_rat_rat) thenshow"real_of_int i / real_of_int j ∈ range of_rat" by blast qed qed
lemma Rats_eq_int_div_nat: "ℚ = { real_of_int i / real n | i n. n ≠ 0}" proof (auto simp: Rats_eq_int_div_int) fix i j :: int assume"j ≠ 0" show"∃(i'::int) (n::nat). real_of_int i / real_of_int j = real_of_int i' / real n ∧ 0 < n" proof (cases "j > 0") case True thenhave"real_of_int i / real_of_int j = real_of_int i / real (nat j) ∧ 0 < nat j" by simp thenshow ?thesis by blast next case False with‹j ≠ 0› have"real_of_int i / real_of_int j = real_of_int (- i) / real (nat (- j)) ∧ 0 < nat (- j)" by simp thenshow ?thesis by blast qed next fix i :: int and n :: nat assume"0 < n" thenhave"real_of_int i / real n = real_of_int i / real_of_int(int n) ∧ int n ≠ 0" by simp thenshow"∃i' j. real_of_int i / real n = real_of_int i' / real_of_int j ∧ j ≠ 0" by blast qed
lemma Rats_abs_nat_div_natE: assumes"x ∈ℚ" obtains m n :: nat where"n ≠ 0"and"∣x∣ = real m / real n"and"coprime m n" proof - from‹x ∈ℚ›obtain i :: int and n :: nat where"n ≠ 0"and"x = real_of_int i / real n" by (auto simp add: Rats_eq_int_div_nat) thenhave"∣x∣ = real (nat ∣i∣) / real n"by simp thenobtain m :: nat where x_rat: "∣x∣ = real m / real n"by blast let ?gcd = "gcd m n" from‹n ≠ 0›have gcd: "?gcd ≠ 0"by simp let ?k = "m div ?gcd" let ?l = "n div ?gcd" let ?gcd' = "gcd ?k ?l" have"?gcd dvd m" .. thenhave gcd_k: "?gcd * ?k = m" by (rule dvd_mult_div_cancel) have"?gcd dvd n" .. thenhave gcd_l: "?gcd * ?l = n" by (rule dvd_mult_div_cancel) from‹n ≠ 0›and gcd_l have"?gcd * ?l ≠ 0"by simp thenhave"?l ≠ 0"by (blast dest!: mult_not_zero) moreover have"∣x∣ = real ?k / real ?l" proof - from gcd have"real ?k / real ?l = real (?gcd * ?k) / real (?gcd * ?l)" by (simp add: real_of_nat_div) alsofrom gcd_k and gcd_l have"… = real m / real n"by simp alsofrom x_rat have"… = ∣x∣" .. finallyshow ?thesis .. qed moreover have"?gcd' = 1" proof - have"?gcd * ?gcd' = gcd (?gcd * ?k) (?gcd * ?l)" by (rule gcd_mult_distrib_nat) with gcd_k gcd_l have"?gcd * ?gcd' = ?gcd"by simp with gcd show ?thesis by auto qed thenhave"coprime ?k ?l" by (simp only: coprime_iff_gcd_eq_1) ultimatelyshow ?thesis .. qed
subsection‹Density of the Rational Reals in the Reals›
text‹ This density proof is due to Stefan Richter and was ported by TN. The original source is 🪙‹Real Analysis› b
It employs the Archimedean property of the reals.›
lemma Rats_dense_in_real: fixes x :: real assumes"x < y" shows"∃r∈ℚ. x < r ∧ r < y" proof - from‹x 🚫›have"0 < y - x"by simp with reals_Archimedean obtain q :: nat where q: "inverse (real q) < y - x"and"0 < q" by blast
define p where"p = ⌈y * real q⌉ - 1"
define r where"r = of_int p / real q" from q have"x < y - inverse (real q)" by simp alsofrom‹0 🚫›have"y - inverse (real q) ≤ r" by (simp add: r_def p_def le_divide_eq left_diff_distrib) finallyhave"x < r" . moreoverfrom‹0 🚫›have"r < y" by (simp add: r_def p_def divide_less_eq diff_less_eq less_ceiling_iff [symmetric]) moreoverhave"r ∈ℚ" by (simp add: r_def) ultimatelyshow ?thesis by blast qed
lemma of_rat_dense: fixes x y :: real assumes"x < y" shows"∃q :: rat. x < of_rat q ∧ of_rat q < y" using Rats_dense_in_real [OF ‹x 🚫›] by (auto elim: Rats_cases)
lemma real_minus_mult_self_le [simp]: "- (u * u) ≤ x * x" for u x :: real by (rule order_trans [where y = 0]) auto
lemma realpow_square_minus_le [simp]: "- u🪙2 ≤ x🪙2" for u x :: real by (auto simp add: power2_eq_square)
subsection‹Density of the Reals›
lemma field_lbound_gt_zero: "0 < d1 ==> 0 < d2 ==>∃e. 0 < e ∧ e < d1 ∧ e < d2" for d1 d2 :: "'a::linordered_field" by (rule exI [where x = "min d1 d2 / 2"]) (simp add: min_def)
lemma field_less_half_sum: "x < y ==> x < (x + y) / 2" for x y :: "'a::linordered_field" by auto
lemma field_sum_of_halves: "x / 2 + x / 2 = x" for x :: "'a::linordered_field" by simp
subsection‹Archimedean properties and useful consequences›
text‹Bernoulli's inequality›
proposition Bernoulli_inequality: fixes x :: "'a :: linordered_field" assumes"-1 ≤ x" shows"1 + of_nat n * x ≤ (1 + x) ^ n" proof (induct n) case 0 thenshow ?caseby simp next case (Suc n) have"1 + of_nat (Suc n) * x ≤ 1 + of_nat(Suc n) * x + of_nat n * x^2" by simp alsohave"... = (1 + x) * (1 + of_nat n * x)" by (auto simp: power2_eq_square algebra_simps) alsohave"…≤ (1 + x) ^ Suc n" using Suc.hyps assms mult_left_mono by fastforce finallyshow ?case . qed
corollary Bernoulli_inequality_even: fixes x :: "'a :: linordered_field" assumes"even n" shows"1 + of_nat n * x ≤ (1 + x) ^ n" proof (cases "-1 ≤ x ∨ n=0") case True thenshow ?thesis by (auto simp: Bernoulli_inequality) next case False thenhave"of_nat n ≥ (1::'a)" by simp with False have"of_nat n * x ≤ -1" by (metis linear minus_zero mult.commute mult.left_neutral mult_left_mono_neg neg_le_iff_le order_trans zero_le_one) thenhave"1 + of_nat n * x ≤ 0" by auto alsohave"... ≤ (1 + x) ^ n" using assms zero_le_even_power by blast finallyshow ?thesis . qed
corollary real_arch_pow: fixes x :: real assumes x: "1 < x" shows"∃n. y < x^n" proof - from x have x0: "x - 1 > 0" by arith from reals_Archimedean3[OF x0, rule_format, of y] obtain n :: nat where n: "y < real n * (x - 1)"by metis from x0 have x00: "x- 1 ≥ -1"by arith from Bernoulli_inequality[OF x00, of n] n have"y < x^n"by auto thenshow ?thesis by metis qed
corollary real_arch_pow_inv: fixes x y :: real assumes y: "y > 0" and x1: "x < 1" shows"∃n. x^n < y" proof (cases "x > 0") case True with x1 have ix: "1 < 1/x"by (simp add: field_simps) from real_arch_pow[OF ix, of "1/y"] obtain n where n: "1/y < (1/x)^n"by blast thenshow ?thesis using y ‹x > 0› by (auto simp add: field_simps) next case False with y x1 show ?thesis by (metis less_le_trans not_less power_one_right) qed
lemma forall_pos_mono: "(∧d e::real. d < e ==> P d ==> P e) ==> (∧n::nat. n ≠ 0 ==> P (inverse (real n))) ==> (∧e. 0 < e ==> P e)" by (metis real_arch_inverse)
lemma forall_pos_mono_1: "(∧d e::real. d < e ==> P d ==> P e) ==> (∧n. P (inverse (real (Suc n)))) ==> 0 < e ==> P e" using reals_Archimedean by blast
lemma Archimedean_eventually_pow: fixes x::real assumes"1 < x" shows"∀🪙F n in sequentially. b < x ^ n" proof - obtain N where"∧n. n≥N ==> b < x ^ n" by (metis assms le_less order_less_trans power_strict_increasing_iff real_arch_pow) thenshow ?thesis using eventually_sequentially by blast qed
lemma Archimedean_eventually_pow_inverse: fixes x::real assumes"∣x∣ < 1""ε > 0" shows"∀🪙F n in sequentially. ∣x^n∣ < ε" proof (cases "x = 0") case True thenshow ?thesis by (simp add: assms eventually_at_top_dense zero_power) next case False thenhave"∀🪙F n in sequentially. inverse ε < inverse ∣x∣ ^ n" by (simp add: Archimedean_eventually_pow assms(1) one_less_inverse) thenshow ?thesis by eventually_elim (metis ‹ε > 0› inverse_less_imp_less power_abs power_inverse) qed
subsection‹Floor and Ceiling Functions from the Reals to the Integers›
(* FIXME: theorems for negative numerals. Many duplicates, e.g. from Archimedean_Field.thy. *)
lemma real_of_nat_less_numeral_iff [simp]: "real n < numeral w ⟷ n < numeral w" for n :: nat by (metis of_nat_less_iff of_nat_numeral)
lemma numeral_less_real_of_nat_iff [simp]: "numeral w < real n ⟷ numeral w < n" for n :: nat by (metis of_nat_less_iff of_nat_numeral)
lemma numeral_le_real_of_nat_iff [simp]: "numeral n ≤ real m ⟷ numeral n ≤ m" for m :: nat by (metis not_le real_of_nat_less_numeral_iff)
lemma of_int_floor_cancel [simp]: "of_int ⌊x⌋ = x ⟷ (∃n::int. x = of_int n)" by (metis floor_of_int)
lemma of_int_floor [simp]: "a ∈ℤ==> of_int (floor a) = a" by (metis Ints_cases of_int_floor_cancel)
lemma floor_divide_real_eq_div: assumes"0 ≤ b" shows"⌊a / real_of_int b⌋ = ⌊a⌋ div b" proof (cases "b = 0") case True thenshow ?thesis by simp next case False with assms have b: "b > 0"by simp have"j = i div b" if"real_of_int i ≤ a""a < 1 + real_of_int i" "real_of_int j * real_of_int b ≤ a""a < real_of_int b + real_of_int j * real_of_int b" for i j :: int proof - from that have"i < b + j * b" by (metis le_less_trans of_int_add of_int_less_iff of_int_mult) moreoverhave"j * b < 1 + i" proof - have"real_of_int (j * b) < real_of_int i + 1" using‹a 🚫 + real_of_int i›‹real_of_int j * real_of_int b ≤ a›by force thenshow"j * b < 1 + i"by linarith qed ultimatelyhave"(j - i div b) * b ≤ i mod b""i mod b < ((j - i div b) + 1) * b" by (auto simp: field_simps) thenhave"(j - i div b) * b < 1 * b""0 * b < ((j - i div b) + 1) * b" using pos_mod_bound [OF b, of i] pos_mod_sign [OF b, of i] by linarith+ thenshow ?thesis using b unfolding mult_less_cancel_right by auto qed with b show ?thesis by (auto split: floor_split simp: field_simps) qed
lemma floor_one_divide_eq_div_numeral [simp]: "⌊1 / numeral b::real⌋ = 1 div numeral b" by (metis floor_divide_of_int_eq of_int_1 of_int_numeral)
lemma of_int_ceiling_le_add_one [simp]: "of_int ⌈r⌉≤ r + 1" by linarith
lemma ceiling_le: "x ≤ of_int a ==>⌈x⌉≤ a" by (simp add: ceiling_le_iff)
lemma ceiling_divide_eq_div: "⌈of_int a / of_int b⌉ = - (- a div b)" by (metis ceiling_def floor_divide_of_int_eq minus_divide_left of_int_minus)
lemma ceiling_divide_eq_div_numeral [simp]: "⌈numeral a / numeral b :: real⌉ = - (- numeral a div numeral b)" using ceiling_divide_eq_div[of "numeral a""numeral b"] by simp
lemma ceiling_minus_divide_eq_div_numeral [simp]: "⌈- (numeral a / numeral b :: real)⌉ = - (numeral a div numeral b)" using ceiling_divide_eq_div[of "- numeral a""numeral b"] by simp
text‹ The following lemmas are remnants of the erstwhile functions natfloor and natceiling. ›
lemma nat_floor_neg: "x ≤ 0 ==> nat ⌊x⌋ = 0" for x :: real by linarith
lemma le_nat_floor: "real x ≤ a ==> x ≤ nat ⌊a⌋" by linarith
lemma [z3_rule]: "0 + x = x" "x + 0 = x" "0 * x = 0" "1 * x = x" "-x = -1 * x" "x + y = y + x" for x y :: real by auto
lemma [smt_arith_multiplication]: fixes A B :: real and p n :: real assumes"A ≤ B""0 < n""p > 0" shows"(A / n) * p ≤ (B / n) * p" using assms by (auto simp: field_simps)
lemma [smt_arith_multiplication]: fixes A B :: real and p n :: real assumes"A < B""0 < n""p > 0" shows"(A / n) * p < (B / n) * p" using assms by (auto simp: field_simps)
lemma [smt_arith_multiplication]: fixes A B :: real and p n :: int assumes"A ≤ B""0 < n""p > 0" shows"(A / n) * p ≤ (B / n) * p" using assms by (auto simp: field_simps)
lemma [smt_arith_multiplication]: fixes A B :: real and p n :: int assumes"A < B""0 < n""p > 0" shows"(A / n) * p < (B / n) * p" using assms by (auto simp: field_simps)
lemmas [smt_arith_multiplication] =
verit_le_mono_div[THEN mult_left_mono, unfolded int_distrib, of _ _ ‹nat (floor (_ :: real))›‹nat (floor (_ :: real))›]
div_le_mono[THEN mult_left_mono, unfolded int_distrib, of _ _ ‹nat (floor (_ :: real))›‹nat (floor (_ :: real))›]
verit_le_mono_div_int[THEN mult_left_mono, unfolded int_distrib, of _ _ ‹floor (_ :: real)›‹floor (_ :: real)›]
zdiv_mono1[THEN mult_left_mono, unfolded int_distrib, of _ _ ‹floor (_ :: real)›‹floor (_ :: real)›]
arg_cong[of _ _ ‹λa :: real. a / real (n::nat) * real (p::nat)›for n p :: nat, THEN sym]
arg_cong[of _ _ ‹λa :: real. a / real_of_int n * real_of_int p›for n p :: int, THEN sym]
arg_cong[of _ _ ‹λa :: real. a / n * p›for n p :: real, THEN sym]
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.47Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-04-26)
¤
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 und die Messung sind noch experimentell.