| author | wenzelm | 
| Wed, 05 Jul 2023 15:01:46 +0200 | |
| changeset 78255 | 3e11f510b3f6 | 
| parent 78250 | 400aecdfd71f | 
| child 78669 | 18ea58bdcf77 | 
| permissions | -rw-r--r-- | 
| 51523 | 1 | (* Title: HOL/Real.thy | 
| 2 | Author: Jacques D. Fleuriot, University of Edinburgh, 1998 | |
| 3 | Author: Larry Paulson, University of Cambridge | |
| 4 | Author: Jeremy Avigad, Carnegie Mellon University | |
| 5 | Author: Florian Zuleger, Johannes Hoelzl, and Simon Funke, TU Muenchen | |
| 6 | Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4 | |
| 7 | Construction of Cauchy Reals by Brian Huffman, 2010 | |
| 8 | *) | |
| 9 | ||
| 60758 | 10 | section \<open>Development of the Reals using Cauchy Sequences\<close> | 
| 51523 | 11 | |
| 12 | theory Real | |
| 63961 
2fd9656c4c82
invoke argo as part of the tried automatic proof methods
 boehmes parents: 
63960diff
changeset | 13 | imports Rat | 
| 51523 | 14 | begin | 
| 15 | ||
| 60758 | 16 | text \<open> | 
| 63680 | 17 | This theory contains a formalization of the real numbers as equivalence | 
| 75327 | 18 | classes of Cauchy sequences of rationals. See the AFP entry | 
| 19 |   @{text Dedekind_Real} for an alternative construction using
 | |
| 63680 | 20 | Dedekind cuts. | 
| 60758 | 21 | \<close> | 
| 51523 | 22 | |
| 63353 | 23 | |
| 60758 | 24 | subsection \<open>Preliminary lemmas\<close> | 
| 51523 | 25 | |
| 67226 | 26 | text\<open>Useful in convergence arguments\<close> | 
| 66793 
deabce3ccf1f
new material about connectedness, etc.
 paulson <lp15@cam.ac.uk> parents: 
66515diff
changeset | 27 | lemma inverse_of_nat_le: | 
| 
deabce3ccf1f
new material about connectedness, etc.
 paulson <lp15@cam.ac.uk> parents: 
66515diff
changeset | 28 | fixes n::nat shows "\<lbrakk>n \<le> m; n\<noteq>0\<rbrakk> \<Longrightarrow> 1 / of_nat m \<le> (1::'a::linordered_field) / of_nat n" | 
| 
deabce3ccf1f
new material about connectedness, etc.
 paulson <lp15@cam.ac.uk> parents: 
66515diff
changeset | 29 | by (simp add: frac_le) | 
| 
deabce3ccf1f
new material about connectedness, etc.
 paulson <lp15@cam.ac.uk> parents: 
66515diff
changeset | 30 | |
| 63494 | 31 | lemma add_diff_add: "(a + c) - (b + d) = (a - b) + (c - d)" | 
| 32 | for a b c d :: "'a::ab_group_add" | |
| 51523 | 33 | by simp | 
| 34 | ||
| 63494 | 35 | lemma minus_diff_minus: "- a - - b = - (a - b)" | 
| 36 | for a b :: "'a::ab_group_add" | |
| 51523 | 37 | by simp | 
| 38 | ||
| 63494 | 39 | lemma mult_diff_mult: "(x * y - a * b) = x * (y - b) + (x - a) * b" | 
| 40 | for x y a b :: "'a::ring" | |
| 51523 | 41 | by (simp add: algebra_simps) | 
| 42 | ||
| 43 | lemma inverse_diff_inverse: | |
| 44 | fixes a b :: "'a::division_ring" | |
| 45 | assumes "a \<noteq> 0" and "b \<noteq> 0" | |
| 46 | shows "inverse a - inverse b = - (inverse a * (a - b) * inverse b)" | |
| 47 | using assms by (simp add: algebra_simps) | |
| 48 | ||
| 49 | lemma obtain_pos_sum: | |
| 50 | fixes r :: rat assumes r: "0 < r" | |
| 51 | obtains s t where "0 < s" and "0 < t" and "r = s + t" | |
| 52 | proof | |
| 63353 | 53 | from r show "0 < r/2" by simp | 
| 54 | from r show "0 < r/2" by simp | |
| 55 | show "r = r/2 + r/2" by simp | |
| 51523 | 56 | qed | 
| 57 | ||
| 63353 | 58 | |
| 60758 | 59 | subsection \<open>Sequences that converge to zero\<close> | 
| 51523 | 60 | |
| 63353 | 61 | definition vanishes :: "(nat \<Rightarrow> rat) \<Rightarrow> bool" | 
| 62 | where "vanishes X \<longleftrightarrow> (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r)" | |
| 51523 | 63 | |
| 64 | lemma vanishesI: "(\<And>r. 0 < r \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r) \<Longrightarrow> vanishes X" | |
| 65 | unfolding vanishes_def by simp | |
| 66 | ||
| 63353 | 67 | lemma vanishesD: "vanishes X \<Longrightarrow> 0 < r \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r" | 
| 51523 | 68 | unfolding vanishes_def by simp | 
| 69 | ||
| 70 | lemma vanishes_const [simp]: "vanishes (\<lambda>n. c) \<longleftrightarrow> c = 0" | |
| 68662 | 71 | proof (cases "c = 0") | 
| 72 | case True | |
| 73 | then show ?thesis | |
| 74 | by (simp add: vanishesI) | |
| 75 | next | |
| 76 | case False | |
| 77 | then show ?thesis | |
| 78 | unfolding vanishes_def | |
| 79 | using zero_less_abs_iff by blast | |
| 80 | qed | |
| 51523 | 81 | |
| 82 | lemma vanishes_minus: "vanishes X \<Longrightarrow> vanishes (\<lambda>n. - X n)" | |
| 83 | unfolding vanishes_def by simp | |
| 84 | ||
| 85 | lemma vanishes_add: | |
| 63353 | 86 | assumes X: "vanishes X" | 
| 87 | and Y: "vanishes Y" | |
| 51523 | 88 | shows "vanishes (\<lambda>n. X n + Y n)" | 
| 89 | proof (rule vanishesI) | |
| 63353 | 90 | fix r :: rat | 
| 91 | assume "0 < r" | |
| 51523 | 92 | then obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t" | 
| 93 | by (rule obtain_pos_sum) | |
| 94 | obtain i where i: "\<forall>n\<ge>i. \<bar>X n\<bar> < s" | |
| 95 | using vanishesD [OF X s] .. | |
| 96 | obtain j where j: "\<forall>n\<ge>j. \<bar>Y n\<bar> < t" | |
| 97 | using vanishesD [OF Y t] .. | |
| 98 | have "\<forall>n\<ge>max i j. \<bar>X n + Y n\<bar> < r" | |
| 63353 | 99 | proof clarsimp | 
| 100 | fix n | |
| 101 | assume n: "i \<le> n" "j \<le> n" | |
| 63494 | 102 | have "\<bar>X n + Y n\<bar> \<le> \<bar>X n\<bar> + \<bar>Y n\<bar>" | 
| 103 | by (rule abs_triangle_ineq) | |
| 104 | also have "\<dots> < s + t" | |
| 105 | by (simp add: add_strict_mono i j n) | |
| 106 | finally show "\<bar>X n + Y n\<bar> < r" | |
| 107 | by (simp only: r) | |
| 51523 | 108 | qed | 
| 63353 | 109 | then show "\<exists>k. \<forall>n\<ge>k. \<bar>X n + Y n\<bar> < r" .. | 
| 51523 | 110 | qed | 
| 111 | ||
| 112 | lemma vanishes_diff: | |
| 63353 | 113 | assumes "vanishes X" "vanishes Y" | 
| 51523 | 114 | shows "vanishes (\<lambda>n. X n - Y n)" | 
| 63353 | 115 | unfolding diff_conv_add_uminus by (intro vanishes_add vanishes_minus assms) | 
| 51523 | 116 | |
| 117 | lemma vanishes_mult_bounded: | |
| 118 | assumes X: "\<exists>a>0. \<forall>n. \<bar>X n\<bar> < a" | |
| 119 | assumes Y: "vanishes (\<lambda>n. Y n)" | |
| 120 | shows "vanishes (\<lambda>n. X n * Y n)" | |
| 121 | proof (rule vanishesI) | |
| 63353 | 122 | fix r :: rat | 
| 123 | assume r: "0 < r" | |
| 51523 | 124 | obtain a where a: "0 < a" "\<forall>n. \<bar>X n\<bar> < a" | 
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 125 | using X by blast | 
| 51523 | 126 | obtain b where b: "0 < b" "r = a * b" | 
| 127 | proof | |
| 56541 | 128 | show "0 < r / a" using r a by simp | 
| 51523 | 129 | show "r = a * (r / a)" using a by simp | 
| 130 | qed | |
| 131 | obtain k where k: "\<forall>n\<ge>k. \<bar>Y n\<bar> < b" | |
| 132 | using vanishesD [OF Y b(1)] .. | |
| 133 | have "\<forall>n\<ge>k. \<bar>X n * Y n\<bar> < r" | |
| 134 | by (simp add: b(2) abs_mult mult_strict_mono' a k) | |
| 63353 | 135 | then show "\<exists>k. \<forall>n\<ge>k. \<bar>X n * Y n\<bar> < r" .. | 
| 51523 | 136 | qed | 
| 137 | ||
| 63353 | 138 | |
| 60758 | 139 | subsection \<open>Cauchy sequences\<close> | 
| 51523 | 140 | |
| 63353 | 141 | definition cauchy :: "(nat \<Rightarrow> rat) \<Rightarrow> bool" | 
| 142 | where "cauchy X \<longleftrightarrow> (\<forall>r>0. \<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r)" | |
| 51523 | 143 | |
| 63353 | 144 | lemma cauchyI: "(\<And>r. 0 < r \<Longrightarrow> \<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r) \<Longrightarrow> cauchy X" | 
| 51523 | 145 | unfolding cauchy_def by simp | 
| 146 | ||
| 63353 | 147 | lemma cauchyD: "cauchy X \<Longrightarrow> 0 < r \<Longrightarrow> \<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r" | 
| 51523 | 148 | unfolding cauchy_def by simp | 
| 149 | ||
| 150 | lemma cauchy_const [simp]: "cauchy (\<lambda>n. x)" | |
| 151 | unfolding cauchy_def by simp | |
| 152 | ||
| 153 | lemma cauchy_add [simp]: | |
| 154 | assumes X: "cauchy X" and Y: "cauchy Y" | |
| 155 | shows "cauchy (\<lambda>n. X n + Y n)" | |
| 156 | proof (rule cauchyI) | |
| 63353 | 157 | fix r :: rat | 
| 158 | assume "0 < r" | |
| 51523 | 159 | then obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t" | 
| 160 | by (rule obtain_pos_sum) | |
| 161 | obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s" | |
| 162 | using cauchyD [OF X s] .. | |
| 163 | obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>Y m - Y n\<bar> < t" | |
| 164 | using cauchyD [OF Y t] .. | |
| 165 | have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>(X m + Y m) - (X n + Y n)\<bar> < r" | |
| 63353 | 166 | proof clarsimp | 
| 167 | fix m n | |
| 168 | assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n" | |
| 51523 | 169 | have "\<bar>(X m + Y m) - (X n + Y n)\<bar> \<le> \<bar>X m - X n\<bar> + \<bar>Y m - Y n\<bar>" | 
| 170 | unfolding add_diff_add by (rule abs_triangle_ineq) | |
| 171 | also have "\<dots> < s + t" | |
| 63353 | 172 | by (rule add_strict_mono) (simp_all add: i j *) | 
| 173 | finally show "\<bar>(X m + Y m) - (X n + Y n)\<bar> < r" by (simp only: r) | |
| 51523 | 174 | qed | 
| 63353 | 175 | then show "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>(X m + Y m) - (X n + Y n)\<bar> < r" .. | 
| 51523 | 176 | qed | 
| 177 | ||
| 178 | lemma cauchy_minus [simp]: | |
| 179 | assumes X: "cauchy X" | |
| 180 | shows "cauchy (\<lambda>n. - X n)" | |
| 63353 | 181 | using assms unfolding cauchy_def | 
| 182 | unfolding minus_diff_minus abs_minus_cancel . | |
| 51523 | 183 | |
| 184 | lemma cauchy_diff [simp]: | |
| 63353 | 185 | assumes "cauchy X" "cauchy Y" | 
| 51523 | 186 | shows "cauchy (\<lambda>n. X n - Y n)" | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53652diff
changeset | 187 | using assms unfolding diff_conv_add_uminus by (simp del: add_uminus_conv_diff) | 
| 51523 | 188 | |
| 189 | lemma cauchy_imp_bounded: | |
| 63353 | 190 | assumes "cauchy X" | 
| 191 | shows "\<exists>b>0. \<forall>n. \<bar>X n\<bar> < b" | |
| 51523 | 192 | proof - | 
| 193 | obtain k where k: "\<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < 1" | |
| 194 | using cauchyD [OF assms zero_less_one] .. | |
| 195 | show "\<exists>b>0. \<forall>n. \<bar>X n\<bar> < b" | |
| 196 | proof (intro exI conjI allI) | |
| 197 | have "0 \<le> \<bar>X 0\<bar>" by simp | |
| 198 |     also have "\<bar>X 0\<bar> \<le> Max (abs ` X ` {..k})" by simp
 | |
| 199 |     finally have "0 \<le> Max (abs ` X ` {..k})" .
 | |
| 63353 | 200 |     then show "0 < Max (abs ` X ` {..k}) + 1" by simp
 | 
| 51523 | 201 | next | 
| 202 | fix n :: nat | |
| 203 |     show "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1"
 | |
| 204 | proof (rule linorder_le_cases) | |
| 205 | assume "n \<le> k" | |
| 63353 | 206 |       then have "\<bar>X n\<bar> \<le> Max (abs ` X ` {..k})" by simp
 | 
| 207 |       then show "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1" by simp
 | |
| 51523 | 208 | next | 
| 209 | assume "k \<le> n" | |
| 210 | have "\<bar>X n\<bar> = \<bar>X k + (X n - X k)\<bar>" by simp | |
| 211 | also have "\<bar>X k + (X n - X k)\<bar> \<le> \<bar>X k\<bar> + \<bar>X n - X k\<bar>" | |
| 212 | by (rule abs_triangle_ineq) | |
| 213 |       also have "\<dots> < Max (abs ` X ` {..k}) + 1"
 | |
| 63353 | 214 | by (rule add_le_less_mono) (simp_all add: k \<open>k \<le> n\<close>) | 
| 51523 | 215 |       finally show "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1" .
 | 
| 216 | qed | |
| 217 | qed | |
| 218 | qed | |
| 219 | ||
| 220 | lemma cauchy_mult [simp]: | |
| 221 | assumes X: "cauchy X" and Y: "cauchy Y" | |
| 222 | shows "cauchy (\<lambda>n. X n * Y n)" | |
| 223 | proof (rule cauchyI) | |
| 224 | fix r :: rat assume "0 < r" | |
| 225 | then obtain u v where u: "0 < u" and v: "0 < v" and "r = u + v" | |
| 226 | by (rule obtain_pos_sum) | |
| 227 | obtain a where a: "0 < a" "\<forall>n. \<bar>X n\<bar> < a" | |
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 228 | using cauchy_imp_bounded [OF X] by blast | 
| 51523 | 229 | obtain b where b: "0 < b" "\<forall>n. \<bar>Y n\<bar> < b" | 
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 230 | using cauchy_imp_bounded [OF Y] by blast | 
| 51523 | 231 | obtain s t where s: "0 < s" and t: "0 < t" and r: "r = a * t + s * b" | 
| 232 | proof | |
| 56541 | 233 | show "0 < v/b" using v b(1) by simp | 
| 234 | show "0 < u/a" using u a(1) by simp | |
| 51523 | 235 | show "r = a * (u/a) + (v/b) * b" | 
| 60758 | 236 | using a(1) b(1) \<open>r = u + v\<close> by simp | 
| 51523 | 237 | qed | 
| 238 | obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s" | |
| 239 | using cauchyD [OF X s] .. | |
| 240 | obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>Y m - Y n\<bar> < t" | |
| 241 | using cauchyD [OF Y t] .. | |
| 242 | have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>X m * Y m - X n * Y n\<bar> < r" | |
| 63353 | 243 | proof clarsimp | 
| 244 | fix m n | |
| 245 | assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n" | |
| 51523 | 246 | have "\<bar>X m * Y m - X n * Y n\<bar> = \<bar>X m * (Y m - Y n) + (X m - X n) * Y n\<bar>" | 
| 247 | unfolding mult_diff_mult .. | |
| 248 | also have "\<dots> \<le> \<bar>X m * (Y m - Y n)\<bar> + \<bar>(X m - X n) * Y n\<bar>" | |
| 249 | by (rule abs_triangle_ineq) | |
| 250 | also have "\<dots> = \<bar>X m\<bar> * \<bar>Y m - Y n\<bar> + \<bar>X m - X n\<bar> * \<bar>Y n\<bar>" | |
| 251 | unfolding abs_mult .. | |
| 252 | also have "\<dots> < a * t + s * b" | |
| 253 | by (simp_all add: add_strict_mono mult_strict_mono' a b i j *) | |
| 63494 | 254 | finally show "\<bar>X m * Y m - X n * Y n\<bar> < r" | 
| 255 | by (simp only: r) | |
| 51523 | 256 | qed | 
| 63353 | 257 | then show "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m * Y m - X n * Y n\<bar> < r" .. | 
| 51523 | 258 | qed | 
| 259 | ||
| 260 | lemma cauchy_not_vanishes_cases: | |
| 261 | assumes X: "cauchy X" | |
| 262 | assumes nz: "\<not> vanishes X" | |
| 263 | shows "\<exists>b>0. \<exists>k. (\<forall>n\<ge>k. b < - X n) \<or> (\<forall>n\<ge>k. b < X n)" | |
| 264 | proof - | |
| 265 | obtain r where "0 < r" and r: "\<forall>k. \<exists>n\<ge>k. r \<le> \<bar>X n\<bar>" | |
| 266 | using nz unfolding vanishes_def by (auto simp add: not_less) | |
| 267 | obtain s t where s: "0 < s" and t: "0 < t" and "r = s + t" | |
| 60758 | 268 | using \<open>0 < r\<close> by (rule obtain_pos_sum) | 
| 51523 | 269 | obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s" | 
| 270 | using cauchyD [OF X s] .. | |
| 271 | obtain k where "i \<le> k" and "r \<le> \<bar>X k\<bar>" | |
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 272 | using r by blast | 
| 51523 | 273 | have k: "\<forall>n\<ge>k. \<bar>X n - X k\<bar> < s" | 
| 60758 | 274 | using i \<open>i \<le> k\<close> by auto | 
| 51523 | 275 | have "X k \<le> - r \<or> r \<le> X k" | 
| 60758 | 276 | using \<open>r \<le> \<bar>X k\<bar>\<close> by auto | 
| 63353 | 277 | then have "(\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)" | 
| 60758 | 278 | unfolding \<open>r = s + t\<close> using k by auto | 
| 63353 | 279 | then have "\<exists>k. (\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)" .. | 
| 280 | then show "\<exists>t>0. \<exists>k. (\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)" | |
| 51523 | 281 | using t by auto | 
| 282 | qed | |
| 283 | ||
| 284 | lemma cauchy_not_vanishes: | |
| 285 | assumes X: "cauchy X" | |
| 63494 | 286 | and nz: "\<not> vanishes X" | 
| 51523 | 287 | shows "\<exists>b>0. \<exists>k. \<forall>n\<ge>k. b < \<bar>X n\<bar>" | 
| 63353 | 288 | using cauchy_not_vanishes_cases [OF assms] | 
| 68662 | 289 | by (elim ex_forward conj_forward asm_rl) auto | 
| 51523 | 290 | |
| 291 | lemma cauchy_inverse [simp]: | |
| 292 | assumes X: "cauchy X" | |
| 63494 | 293 | and nz: "\<not> vanishes X" | 
| 51523 | 294 | shows "cauchy (\<lambda>n. inverse (X n))" | 
| 295 | proof (rule cauchyI) | |
| 63353 | 296 | fix r :: rat | 
| 297 | assume "0 < r" | |
| 51523 | 298 | obtain b i where b: "0 < b" and i: "\<forall>n\<ge>i. b < \<bar>X n\<bar>" | 
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 299 | using cauchy_not_vanishes [OF X nz] by blast | 
| 51523 | 300 | from b i have nz: "\<forall>n\<ge>i. X n \<noteq> 0" by auto | 
| 301 | obtain s where s: "0 < s" and r: "r = inverse b * s * inverse b" | |
| 302 | proof | |
| 60758 | 303 | show "0 < b * r * b" by (simp add: \<open>0 < r\<close> b) | 
| 51523 | 304 | show "r = inverse b * (b * r * b) * inverse b" | 
| 305 | using b by simp | |
| 306 | qed | |
| 307 | obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>X m - X n\<bar> < s" | |
| 308 | using cauchyD [OF X s] .. | |
| 309 | have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>inverse (X m) - inverse (X n)\<bar> < r" | |
| 63353 | 310 | proof clarsimp | 
| 311 | fix m n | |
| 312 | assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n" | |
| 313 | have "\<bar>inverse (X m) - inverse (X n)\<bar> = inverse \<bar>X m\<bar> * \<bar>X m - X n\<bar> * inverse \<bar>X n\<bar>" | |
| 51523 | 314 | by (simp add: inverse_diff_inverse nz * abs_mult) | 
| 315 | also have "\<dots> < inverse b * s * inverse b" | |
| 63353 | 316 | by (simp add: mult_strict_mono less_imp_inverse_less i j b * s) | 
| 317 | finally show "\<bar>inverse (X m) - inverse (X n)\<bar> < r" by (simp only: r) | |
| 51523 | 318 | qed | 
| 63353 | 319 | then show "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>inverse (X m) - inverse (X n)\<bar> < r" .. | 
| 51523 | 320 | qed | 
| 321 | ||
| 322 | lemma vanishes_diff_inverse: | |
| 323 | assumes X: "cauchy X" "\<not> vanishes X" | |
| 63353 | 324 | and Y: "cauchy Y" "\<not> vanishes Y" | 
| 325 | and XY: "vanishes (\<lambda>n. X n - Y n)" | |
| 51523 | 326 | shows "vanishes (\<lambda>n. inverse (X n) - inverse (Y n))" | 
| 327 | proof (rule vanishesI) | |
| 63353 | 328 | fix r :: rat | 
| 329 | assume r: "0 < r" | |
| 51523 | 330 | obtain a i where a: "0 < a" and i: "\<forall>n\<ge>i. a < \<bar>X n\<bar>" | 
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 331 | using cauchy_not_vanishes [OF X] by blast | 
| 51523 | 332 | obtain b j where b: "0 < b" and j: "\<forall>n\<ge>j. b < \<bar>Y n\<bar>" | 
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 333 | using cauchy_not_vanishes [OF Y] by blast | 
| 51523 | 334 | obtain s where s: "0 < s" and "inverse a * s * inverse b = r" | 
| 335 | proof | |
| 63494 | 336 | show "0 < a * r * b" | 
| 337 | using a r b by simp | |
| 338 | show "inverse a * (a * r * b) * inverse b = r" | |
| 339 | using a r b by simp | |
| 51523 | 340 | qed | 
| 341 | obtain k where k: "\<forall>n\<ge>k. \<bar>X n - Y n\<bar> < s" | |
| 342 | using vanishesD [OF XY s] .. | |
| 343 | have "\<forall>n\<ge>max (max i j) k. \<bar>inverse (X n) - inverse (Y n)\<bar> < r" | |
| 63353 | 344 | proof clarsimp | 
| 345 | fix n | |
| 346 | assume n: "i \<le> n" "j \<le> n" "k \<le> n" | |
| 347 | with i j a b have "X n \<noteq> 0" and "Y n \<noteq> 0" | |
| 348 | by auto | |
| 349 | then have "\<bar>inverse (X n) - inverse (Y n)\<bar> = inverse \<bar>X n\<bar> * \<bar>X n - Y n\<bar> * inverse \<bar>Y n\<bar>" | |
| 51523 | 350 | by (simp add: inverse_diff_inverse abs_mult) | 
| 351 | also have "\<dots> < inverse a * s * inverse b" | |
| 63353 | 352 | by (intro mult_strict_mono' less_imp_inverse_less) (simp_all add: a b i j k n) | 
| 60758 | 353 | also note \<open>inverse a * s * inverse b = r\<close> | 
| 51523 | 354 | finally show "\<bar>inverse (X n) - inverse (Y n)\<bar> < r" . | 
| 355 | qed | |
| 63353 | 356 | then show "\<exists>k. \<forall>n\<ge>k. \<bar>inverse (X n) - inverse (Y n)\<bar> < r" .. | 
| 51523 | 357 | qed | 
| 358 | ||
| 63353 | 359 | |
| 60758 | 360 | subsection \<open>Equivalence relation on Cauchy sequences\<close> | 
| 51523 | 361 | |
| 362 | definition realrel :: "(nat \<Rightarrow> rat) \<Rightarrow> (nat \<Rightarrow> rat) \<Rightarrow> bool" | |
| 363 | where "realrel = (\<lambda>X Y. cauchy X \<and> cauchy Y \<and> vanishes (\<lambda>n. X n - Y n))" | |
| 364 | ||
| 63353 | 365 | lemma realrelI [intro?]: "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> vanishes (\<lambda>n. X n - Y n) \<Longrightarrow> realrel X Y" | 
| 366 | by (simp add: realrel_def) | |
| 51523 | 367 | |
| 368 | lemma realrel_refl: "cauchy X \<Longrightarrow> realrel X X" | |
| 63353 | 369 | by (simp add: realrel_def) | 
| 51523 | 370 | |
| 371 | lemma symp_realrel: "symp realrel" | |
| 68662 | 372 | by (simp add: abs_minus_commute realrel_def symp_def vanishes_def) | 
| 51523 | 373 | |
| 374 | lemma transp_realrel: "transp realrel" | |
| 375 | unfolding realrel_def | |
| 68669 | 376 | by (rule transpI) (force simp add: dest: vanishes_add) | 
| 51523 | 377 | |
| 378 | lemma part_equivp_realrel: "part_equivp realrel" | |
| 63353 | 379 | by (blast intro: part_equivpI symp_realrel transp_realrel realrel_refl cauchy_const) | 
| 380 | ||
| 51523 | 381 | |
| 60758 | 382 | subsection \<open>The field of real numbers\<close> | 
| 51523 | 383 | |
| 384 | quotient_type real = "nat \<Rightarrow> rat" / partial: realrel | |
| 385 | morphisms rep_real Real | |
| 386 | by (rule part_equivp_realrel) | |
| 387 | ||
| 388 | lemma cr_real_eq: "pcr_real = (\<lambda>x y. cauchy x \<and> Real x = y)" | |
| 389 | unfolding real.pcr_cr_eq cr_real_def realrel_def by auto | |
| 390 | ||
| 391 | lemma Real_induct [induct type: real]: (* TODO: generate automatically *) | |
| 63353 | 392 | assumes "\<And>X. cauchy X \<Longrightarrow> P (Real X)" | 
| 393 | shows "P x" | |
| 51523 | 394 | proof (induct x) | 
| 395 | case (1 X) | |
| 63353 | 396 | then have "cauchy X" by (simp add: realrel_def) | 
| 397 | then show "P (Real X)" by (rule assms) | |
| 51523 | 398 | qed | 
| 399 | ||
| 63353 | 400 | lemma eq_Real: "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> Real X = Real Y \<longleftrightarrow> vanishes (\<lambda>n. X n - Y n)" | 
| 51523 | 401 | using real.rel_eq_transfer | 
| 55945 | 402 | unfolding real.pcr_cr_eq cr_real_def rel_fun_def realrel_def by simp | 
| 51523 | 403 | |
| 51956 
a4d81cdebf8b
better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
 kuncar parents: 
51775diff
changeset | 404 | lemma Domainp_pcr_real [transfer_domain_rule]: "Domainp pcr_real = cauchy" | 
| 63353 | 405 | by (simp add: real.domain_eq realrel_def) | 
| 51523 | 406 | |
| 59867 
58043346ca64
given up separate type classes demanding `inverse 0 = 0`
 haftmann parents: 
59587diff
changeset | 407 | instantiation real :: field | 
| 51523 | 408 | begin | 
| 409 | ||
| 410 | lift_definition zero_real :: "real" is "\<lambda>n. 0" | |
| 411 | by (simp add: realrel_refl) | |
| 412 | ||
| 413 | lift_definition one_real :: "real" is "\<lambda>n. 1" | |
| 414 | by (simp add: realrel_refl) | |
| 415 | ||
| 416 | lift_definition plus_real :: "real \<Rightarrow> real \<Rightarrow> real" is "\<lambda>X Y n. X n + Y n" | |
| 417 | unfolding realrel_def add_diff_add | |
| 418 | by (simp only: cauchy_add vanishes_add simp_thms) | |
| 419 | ||
| 420 | lift_definition uminus_real :: "real \<Rightarrow> real" is "\<lambda>X n. - X n" | |
| 421 | unfolding realrel_def minus_diff_minus | |
| 422 | by (simp only: cauchy_minus vanishes_minus simp_thms) | |
| 423 | ||
| 424 | lift_definition times_real :: "real \<Rightarrow> real \<Rightarrow> real" is "\<lambda>X Y n. X n * Y n" | |
| 68662 | 425 | proof - | 
| 426 | fix f1 f2 f3 f4 | |
| 427 | have "\<lbrakk>cauchy f1; cauchy f4; vanishes (\<lambda>n. f1 n - f2 n); vanishes (\<lambda>n. f3 n - f4 n)\<rbrakk> | |
| 428 | \<Longrightarrow> vanishes (\<lambda>n. f1 n * (f3 n - f4 n) + f4 n * (f1 n - f2 n))" | |
| 429 | by (simp add: vanishes_add vanishes_mult_bounded cauchy_imp_bounded) | |
| 430 | then show "\<lbrakk>realrel f1 f2; realrel f3 f4\<rbrakk> \<Longrightarrow> realrel (\<lambda>n. f1 n * f3 n) (\<lambda>n. f2 n * f4 n)" | |
| 431 | by (simp add: mult.commute realrel_def mult_diff_mult) | |
| 432 | qed | |
| 51523 | 433 | |
| 434 | lift_definition inverse_real :: "real \<Rightarrow> real" | |
| 435 | is "\<lambda>X. if vanishes X then (\<lambda>n. 0) else (\<lambda>n. inverse (X n))" | |
| 436 | proof - | |
| 63353 | 437 | fix X Y | 
| 438 | assume "realrel X Y" | |
| 439 | then have X: "cauchy X" and Y: "cauchy Y" and XY: "vanishes (\<lambda>n. X n - Y n)" | |
| 63494 | 440 | by (simp_all add: realrel_def) | 
| 51523 | 441 | have "vanishes X \<longleftrightarrow> vanishes Y" | 
| 442 | proof | |
| 443 | assume "vanishes X" | |
| 63494 | 444 | from vanishes_diff [OF this XY] show "vanishes Y" | 
| 445 | by simp | |
| 51523 | 446 | next | 
| 447 | assume "vanishes Y" | |
| 63494 | 448 | from vanishes_add [OF this XY] show "vanishes X" | 
| 449 | by simp | |
| 51523 | 450 | qed | 
| 63494 | 451 | then show "?thesis X Y" | 
| 452 | by (simp add: vanishes_diff_inverse X Y XY realrel_def) | |
| 51523 | 453 | qed | 
| 454 | ||
| 63353 | 455 | definition "x - y = x + - y" for x y :: real | 
| 51523 | 456 | |
| 63353 | 457 | definition "x div y = x * inverse y" for x y :: real | 
| 458 | ||
| 459 | lemma add_Real: "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> Real X + Real Y = Real (\<lambda>n. X n + Y n)" | |
| 460 | using plus_real.transfer by (simp add: cr_real_eq rel_fun_def) | |
| 51523 | 461 | |
| 63353 | 462 | lemma minus_Real: "cauchy X \<Longrightarrow> - Real X = Real (\<lambda>n. - X n)" | 
| 463 | using uminus_real.transfer by (simp add: cr_real_eq rel_fun_def) | |
| 51523 | 464 | |
| 63353 | 465 | lemma diff_Real: "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> Real X - Real Y = Real (\<lambda>n. X n - Y n)" | 
| 466 | by (simp add: minus_Real add_Real minus_real_def) | |
| 51523 | 467 | |
| 63353 | 468 | lemma mult_Real: "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> Real X * Real Y = Real (\<lambda>n. X n * Y n)" | 
| 469 | using times_real.transfer by (simp add: cr_real_eq rel_fun_def) | |
| 51523 | 470 | |
| 471 | lemma inverse_Real: | |
| 63353 | 472 | "cauchy X \<Longrightarrow> inverse (Real X) = (if vanishes X then 0 else Real (\<lambda>n. inverse (X n)))" | 
| 473 | using inverse_real.transfer zero_real.transfer | |
| 62390 | 474 | unfolding cr_real_eq rel_fun_def by (simp split: if_split_asm, metis) | 
| 51523 | 475 | |
| 63353 | 476 | instance | 
| 477 | proof | |
| 51523 | 478 | fix a b c :: real | 
| 479 | show "a + b = b + a" | |
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 480 | by transfer (simp add: ac_simps realrel_def) | 
| 51523 | 481 | show "(a + b) + c = a + (b + c)" | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 482 | by transfer (simp add: ac_simps realrel_def) | 
| 51523 | 483 | show "0 + a = a" | 
| 484 | by transfer (simp add: realrel_def) | |
| 485 | show "- a + a = 0" | |
| 486 | by transfer (simp add: realrel_def) | |
| 487 | show "a - b = a + - b" | |
| 488 | by (rule minus_real_def) | |
| 489 | show "(a * b) * c = a * (b * c)" | |
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 490 | by transfer (simp add: ac_simps realrel_def) | 
| 51523 | 491 | show "a * b = b * a" | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 492 | by transfer (simp add: ac_simps realrel_def) | 
| 51523 | 493 | show "1 * a = a" | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 494 | by transfer (simp add: ac_simps realrel_def) | 
| 51523 | 495 | show "(a + b) * c = a * c + b * c" | 
| 496 | by transfer (simp add: distrib_right realrel_def) | |
| 61076 | 497 | show "(0::real) \<noteq> (1::real)" | 
| 51523 | 498 | by transfer (simp add: realrel_def) | 
| 68662 | 499 | have "vanishes (\<lambda>n. inverse (X n) * X n - 1)" if X: "cauchy X" "\<not> vanishes X" for X | 
| 500 | proof (rule vanishesI) | |
| 501 | fix r::rat | |
| 502 | assume "0 < r" | |
| 503 | obtain b k where "b>0" "\<forall>n\<ge>k. b < \<bar>X n\<bar>" | |
| 504 | using X cauchy_not_vanishes by blast | |
| 505 | then show "\<exists>k. \<forall>n\<ge>k. \<bar>inverse (X n) * X n - 1\<bar> < r" | |
| 506 | using \<open>0 < r\<close> by force | |
| 507 | qed | |
| 508 | then show "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1" | |
| 509 | by transfer (simp add: realrel_def) | |
| 60429 
d3d1e185cd63
uniform _ div _ as infix syntax for ring division
 haftmann parents: 
60352diff
changeset | 510 | show "a div b = a * inverse b" | 
| 51523 | 511 | by (rule divide_real_def) | 
| 512 | show "inverse (0::real) = 0" | |
| 513 | by transfer (simp add: realrel_def) | |
| 514 | qed | |
| 515 | ||
| 516 | end | |
| 517 | ||
| 63353 | 518 | |
| 60758 | 519 | subsection \<open>Positive reals\<close> | 
| 51523 | 520 | |
| 521 | lift_definition positive :: "real \<Rightarrow> bool" | |
| 522 | is "\<lambda>X. \<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n" | |
| 523 | proof - | |
| 63353 | 524 | have 1: "\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < Y n" | 
| 525 | if *: "realrel X Y" and **: "\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n" for X Y | |
| 526 | proof - | |
| 527 | from * have XY: "vanishes (\<lambda>n. X n - Y n)" | |
| 528 | by (simp_all add: realrel_def) | |
| 529 | from ** obtain r i where "0 < r" and i: "\<forall>n\<ge>i. r < X n" | |
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 530 | by blast | 
| 51523 | 531 | obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t" | 
| 60758 | 532 | using \<open>0 < r\<close> by (rule obtain_pos_sum) | 
| 51523 | 533 | obtain j where j: "\<forall>n\<ge>j. \<bar>X n - Y n\<bar> < s" | 
| 534 | using vanishesD [OF XY s] .. | |
| 535 | have "\<forall>n\<ge>max i j. t < Y n" | |
| 63353 | 536 | proof clarsimp | 
| 537 | fix n | |
| 538 | assume n: "i \<le> n" "j \<le> n" | |
| 51523 | 539 | have "\<bar>X n - Y n\<bar> < s" and "r < X n" | 
| 540 | using i j n by simp_all | |
| 63353 | 541 | then show "t < Y n" by (simp add: r) | 
| 51523 | 542 | qed | 
| 63353 | 543 | then show ?thesis using t by blast | 
| 544 | qed | |
| 51523 | 545 | fix X Y assume "realrel X Y" | 
| 63353 | 546 | then have "realrel X Y" and "realrel Y X" | 
| 547 | using symp_realrel by (auto simp: symp_def) | |
| 548 | then show "?thesis X Y" | |
| 51523 | 549 | by (safe elim!: 1) | 
| 550 | qed | |
| 551 | ||
| 63353 | 552 | lemma positive_Real: "cauchy X \<Longrightarrow> positive (Real X) \<longleftrightarrow> (\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n)" | 
| 553 | using positive.transfer by (simp add: cr_real_eq rel_fun_def) | |
| 51523 | 554 | |
| 555 | lemma positive_zero: "\<not> positive 0" | |
| 556 | by transfer auto | |
| 557 | ||
| 68669 | 558 | lemma positive_add: | 
| 559 | assumes "positive x" "positive y" shows "positive (x + y)" | |
| 560 | proof - | |
| 561 | have *: "\<lbrakk>\<forall>n\<ge>i. a < x n; \<forall>n\<ge>j. b < y n; 0 < a; 0 < b; n \<ge> max i j\<rbrakk> | |
| 562 | \<Longrightarrow> a+b < x n + y n" for x y and a b::rat and i j n::nat | |
| 563 | by (simp add: add_strict_mono) | |
| 564 | show ?thesis | |
| 565 | using assms | |
| 566 | by transfer (blast intro: * pos_add_strict) | |
| 567 | qed | |
| 51523 | 568 | |
| 68669 | 569 | lemma positive_mult: | 
| 570 | assumes "positive x" "positive y" shows "positive (x * y)" | |
| 571 | proof - | |
| 572 | have *: "\<lbrakk>\<forall>n\<ge>i. a < x n; \<forall>n\<ge>j. b < y n; 0 < a; 0 < b; n \<ge> max i j\<rbrakk> | |
| 573 | \<Longrightarrow> a*b < x n * y n" for x y and a b::rat and i j n::nat | |
| 574 | by (simp add: mult_strict_mono') | |
| 575 | show ?thesis | |
| 576 | using assms | |
| 577 | by transfer (blast intro: * mult_pos_pos) | |
| 578 | qed | |
| 51523 | 579 | |
| 63353 | 580 | lemma positive_minus: "\<not> positive x \<Longrightarrow> x \<noteq> 0 \<Longrightarrow> positive (- x)" | 
| 581 | apply transfer | |
| 582 | apply (simp add: realrel_def) | |
| 68669 | 583 | apply (blast dest: cauchy_not_vanishes_cases) | 
| 63353 | 584 | done | 
| 51523 | 585 | |
| 59867 
58043346ca64
given up separate type classes demanding `inverse 0 = 0`
 haftmann parents: 
59587diff
changeset | 586 | instantiation real :: linordered_field | 
| 51523 | 587 | begin | 
| 588 | ||
| 63353 | 589 | definition "x < y \<longleftrightarrow> positive (y - x)" | 
| 51523 | 590 | |
| 63353 | 591 | definition "x \<le> y \<longleftrightarrow> x < y \<or> x = y" for x y :: real | 
| 51523 | 592 | |
| 63353 | 593 | definition "\<bar>a\<bar> = (if a < 0 then - a else a)" for a :: real | 
| 51523 | 594 | |
| 63353 | 595 | definition "sgn a = (if a = 0 then 0 else if 0 < a then 1 else - 1)" for a :: real | 
| 51523 | 596 | |
| 63353 | 597 | instance | 
| 598 | proof | |
| 51523 | 599 | fix a b c :: real | 
| 600 | show "\<bar>a\<bar> = (if a < 0 then - a else a)" | |
| 601 | by (rule abs_real_def) | |
| 602 | show "a < b \<longleftrightarrow> a \<le> b \<and> \<not> b \<le> a" | |
| 68662 | 603 | "a \<le> b \<Longrightarrow> b \<le> c \<Longrightarrow> a \<le> c" "a \<le> a" | 
| 604 | "a \<le> b \<Longrightarrow> b \<le> a \<Longrightarrow> a = b" | |
| 605 | "a \<le> b \<Longrightarrow> c + a \<le> c + b" | |
| 51523 | 606 | unfolding less_eq_real_def less_real_def | 
| 68662 | 607 | by (force simp add: positive_zero dest: positive_add)+ | 
| 51523 | 608 | show "sgn a = (if a = 0 then 0 else if 0 < a then 1 else - 1)" | 
| 609 | by (rule sgn_real_def) | |
| 610 | show "a \<le> b \<or> b \<le> a" | |
| 63353 | 611 | by (auto dest!: positive_minus simp: less_eq_real_def less_real_def) | 
| 51523 | 612 | show "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b" | 
| 613 | unfolding less_real_def | |
| 68662 | 614 | by (force simp add: algebra_simps dest: positive_mult) | 
| 51523 | 615 | qed | 
| 616 | ||
| 617 | end | |
| 618 | ||
| 619 | instantiation real :: distrib_lattice | |
| 620 | begin | |
| 621 | ||
| 63353 | 622 | definition "(inf :: real \<Rightarrow> real \<Rightarrow> real) = min" | 
| 51523 | 623 | |
| 63353 | 624 | definition "(sup :: real \<Rightarrow> real \<Rightarrow> real) = max" | 
| 51523 | 625 | |
| 63494 | 626 | instance | 
| 627 | by standard (auto simp add: inf_real_def sup_real_def max_min_distrib2) | |
| 51523 | 628 | |
| 629 | end | |
| 630 | ||
| 631 | lemma of_nat_Real: "of_nat x = Real (\<lambda>n. of_nat x)" | |
| 63353 | 632 | by (induct x) (simp_all add: zero_real_def one_real_def add_Real) | 
| 51523 | 633 | |
| 634 | lemma of_int_Real: "of_int x = Real (\<lambda>n. of_int x)" | |
| 63353 | 635 | by (cases x rule: int_diff_cases) (simp add: of_nat_Real diff_Real) | 
| 51523 | 636 | |
| 637 | lemma of_rat_Real: "of_rat x = Real (\<lambda>n. x)" | |
| 68662 | 638 | proof (induct x) | 
| 639 | case (Fract a b) | |
| 640 | then show ?case | |
| 63353 | 641 | apply (simp add: Fract_of_int_quotient of_rat_divide) | 
| 68662 | 642 | apply (simp add: of_int_Real divide_inverse inverse_Real mult_Real) | 
| 63353 | 643 | done | 
| 68662 | 644 | qed | 
| 51523 | 645 | |
| 646 | instance real :: archimedean_field | |
| 647 | proof | |
| 63494 | 648 | show "\<exists>z. x \<le> of_int z" for x :: real | 
| 68662 | 649 | proof (induct x) | 
| 650 | case (1 X) | |
| 651 | then obtain b where "0 < b" and b: "\<And>n. \<bar>X n\<bar> < b" | |
| 652 | by (blast dest: cauchy_imp_bounded) | |
| 653 | then have "Real X < of_int (\<lceil>b\<rceil> + 1)" | |
| 654 | using 1 | |
| 655 | apply (simp add: of_int_Real less_real_def diff_Real positive_Real) | |
| 656 | apply (rule_tac x=1 in exI) | |
| 657 | apply (simp add: algebra_simps) | |
| 658 | by (metis abs_ge_self le_less_trans le_of_int_ceiling less_le) | |
| 659 | then show ?case | |
| 660 | using less_eq_real_def by blast | |
| 661 | qed | |
| 51523 | 662 | qed | 
| 663 | ||
| 664 | instantiation real :: floor_ceiling | |
| 665 | begin | |
| 666 | ||
| 63353 | 667 | definition [code del]: "\<lfloor>x::real\<rfloor> = (THE z. of_int z \<le> x \<and> x < of_int (z + 1))" | 
| 51523 | 668 | |
| 61942 | 669 | instance | 
| 670 | proof | |
| 63353 | 671 | show "of_int \<lfloor>x\<rfloor> \<le> x \<and> x < of_int (\<lfloor>x\<rfloor> + 1)" for x :: real | 
| 51523 | 672 | unfolding floor_real_def using floor_exists1 by (rule theI') | 
| 673 | qed | |
| 674 | ||
| 675 | end | |
| 676 | ||
| 63353 | 677 | |
| 60758 | 678 | subsection \<open>Completeness\<close> | 
| 51523 | 679 | |
| 68669 | 680 | lemma not_positive_Real: | 
| 681 | assumes "cauchy X" shows "\<not> positive (Real X) \<longleftrightarrow> (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. X n \<le> r)" (is "?lhs = ?rhs") | |
| 682 | unfolding positive_Real [OF assms] | |
| 683 | proof (intro iffI allI notI impI) | |
| 684 | show "\<exists>k. \<forall>n\<ge>k. X n \<le> r" if r: "\<not> (\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n)" and "0 < r" for r | |
| 685 | proof - | |
| 686 | obtain s t where "s > 0" "t > 0" "r = s+t" | |
| 687 | using \<open>r > 0\<close> obtain_pos_sum by blast | |
| 688 | obtain k where k: "\<And>m n. \<lbrakk>m\<ge>k; n\<ge>k\<rbrakk> \<Longrightarrow> \<bar>X m - X n\<bar> < t" | |
| 689 | using cauchyD [OF assms \<open>t > 0\<close>] by blast | |
| 690 | obtain n where "n \<ge> k" "X n \<le> s" | |
| 691 | by (meson r \<open>0 < s\<close> not_less) | |
| 692 | then have "X l \<le> r" if "l \<ge> n" for l | |
| 693 | using k [OF \<open>n \<ge> k\<close>, of l] that \<open>r = s+t\<close> by linarith | |
| 694 | then show ?thesis | |
| 695 | by blast | |
| 696 | qed | |
| 697 | qed (meson le_cases not_le) | |
| 51523 | 698 | |
| 699 | lemma le_Real: | |
| 63353 | 700 | assumes "cauchy X" "cauchy Y" | 
| 51523 | 701 | shows "Real X \<le> Real Y = (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. X n \<le> Y n + r)" | 
| 63353 | 702 | unfolding not_less [symmetric, where 'a=real] less_real_def | 
| 703 | apply (simp add: diff_Real not_positive_Real assms) | |
| 704 | apply (simp add: diff_le_eq ac_simps) | |
| 705 | done | |
| 51523 | 706 | |
| 707 | lemma le_RealI: | |
| 708 | assumes Y: "cauchy Y" | |
| 709 | shows "\<forall>n. x \<le> of_rat (Y n) \<Longrightarrow> x \<le> Real Y" | |
| 710 | proof (induct x) | |
| 63353 | 711 | fix X | 
| 712 | assume X: "cauchy X" and "\<forall>n. Real X \<le> of_rat (Y n)" | |
| 713 | then have le: "\<And>m r. 0 < r \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. X n \<le> Y m + r" | |
| 51523 | 714 | by (simp add: of_rat_Real le_Real) | 
| 63353 | 715 | then have "\<exists>k. \<forall>n\<ge>k. X n \<le> Y n + r" if "0 < r" for r :: rat | 
| 716 | proof - | |
| 717 | from that obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t" | |
| 51523 | 718 | by (rule obtain_pos_sum) | 
| 719 | obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>Y m - Y n\<bar> < s" | |
| 720 | using cauchyD [OF Y s] .. | |
| 721 | obtain j where j: "\<forall>n\<ge>j. X n \<le> Y i + t" | |
| 722 | using le [OF t] .. | |
| 723 | have "\<forall>n\<ge>max i j. X n \<le> Y n + r" | |
| 63353 | 724 | proof clarsimp | 
| 725 | fix n | |
| 726 | assume n: "i \<le> n" "j \<le> n" | |
| 63494 | 727 | have "X n \<le> Y i + t" | 
| 728 | using n j by simp | |
| 729 | moreover have "\<bar>Y i - Y n\<bar> < s" | |
| 730 | using n i by simp | |
| 731 | ultimately show "X n \<le> Y n + r" | |
| 732 | unfolding r by simp | |
| 51523 | 733 | qed | 
| 63353 | 734 | then show ?thesis .. | 
| 735 | qed | |
| 736 | then show "Real X \<le> Real Y" | |
| 51523 | 737 | by (simp add: of_rat_Real le_Real X Y) | 
| 738 | qed | |
| 739 | ||
| 740 | lemma Real_leI: | |
| 741 | assumes X: "cauchy X" | |
| 742 | assumes le: "\<forall>n. of_rat (X n) \<le> y" | |
| 743 | shows "Real X \<le> y" | |
| 744 | proof - | |
| 745 | have "- y \<le> - Real X" | |
| 746 | by (simp add: minus_Real X le_RealI of_rat_minus le) | |
| 63353 | 747 | then show ?thesis by simp | 
| 51523 | 748 | qed | 
| 749 | ||
| 750 | lemma less_RealD: | |
| 63353 | 751 | assumes "cauchy Y" | 
| 51523 | 752 | shows "x < Real Y \<Longrightarrow> \<exists>n. x < of_rat (Y n)" | 
| 63353 | 753 | apply (erule contrapos_pp) | 
| 754 | apply (simp add: not_less) | |
| 755 | apply (erule Real_leI [OF assms]) | |
| 756 | done | |
| 51523 | 757 | |
| 63353 | 758 | lemma of_nat_less_two_power [simp]: "of_nat n < (2::'a::linordered_idom) ^ n" | 
| 759 | apply (induct n) | |
| 63494 | 760 | apply simp | 
| 63353 | 761 | apply (metis add_le_less_mono mult_2 of_nat_Suc one_le_numeral one_le_power power_Suc) | 
| 762 | done | |
| 51523 | 763 | |
| 764 | lemma complete_real: | |
| 765 | fixes S :: "real set" | |
| 766 | assumes "\<exists>x. x \<in> S" and "\<exists>z. \<forall>x\<in>S. x \<le> z" | |
| 767 | shows "\<exists>y. (\<forall>x\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> y \<le> z)" | |
| 768 | proof - | |
| 769 | obtain x where x: "x \<in> S" using assms(1) .. | |
| 770 | obtain z where z: "\<forall>x\<in>S. x \<le> z" using assms(2) .. | |
| 771 | ||
| 63040 | 772 | define P where "P x \<longleftrightarrow> (\<forall>y\<in>S. y \<le> of_rat x)" for x | 
| 51523 | 773 | obtain a where a: "\<not> P a" | 
| 774 | proof | |
| 61942 | 775 | have "of_int \<lfloor>x - 1\<rfloor> \<le> x - 1" by (rule of_int_floor_le) | 
| 51523 | 776 | also have "x - 1 < x" by simp | 
| 61942 | 777 | finally have "of_int \<lfloor>x - 1\<rfloor> < x" . | 
| 63353 | 778 | then have "\<not> x \<le> of_int \<lfloor>x - 1\<rfloor>" by (simp only: not_le) | 
| 61942 | 779 | then show "\<not> P (of_int \<lfloor>x - 1\<rfloor>)" | 
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 780 | unfolding P_def of_rat_of_int_eq using x by blast | 
| 51523 | 781 | qed | 
| 782 | obtain b where b: "P b" | |
| 783 | proof | |
| 61942 | 784 | show "P (of_int \<lceil>z\<rceil>)" | 
| 51523 | 785 | unfolding P_def of_rat_of_int_eq | 
| 786 | proof | |
| 787 | fix y assume "y \<in> S" | |
| 63353 | 788 | then have "y \<le> z" using z by simp | 
| 61942 | 789 | also have "z \<le> of_int \<lceil>z\<rceil>" by (rule le_of_int_ceiling) | 
| 790 | finally show "y \<le> of_int \<lceil>z\<rceil>" . | |
| 51523 | 791 | qed | 
| 792 | qed | |
| 793 | ||
| 63040 | 794 | define avg where "avg x y = x/2 + y/2" for x y :: rat | 
| 795 | define bisect where "bisect = (\<lambda>(x, y). if P (avg x y) then (x, avg x y) else (avg x y, y))" | |
| 796 | define A where "A n = fst ((bisect ^^ n) (a, b))" for n | |
| 797 | define B where "B n = snd ((bisect ^^ n) (a, b))" for n | |
| 798 | define C where "C n = avg (A n) (B n)" for n | |
| 51523 | 799 | have A_0 [simp]: "A 0 = a" unfolding A_def by simp | 
| 800 | have B_0 [simp]: "B 0 = b" unfolding B_def by simp | |
| 801 | have A_Suc [simp]: "\<And>n. A (Suc n) = (if P (C n) then A n else C n)" | |
| 802 | unfolding A_def B_def C_def bisect_def split_def by simp | |
| 803 | have B_Suc [simp]: "\<And>n. B (Suc n) = (if P (C n) then C n else B n)" | |
| 804 | unfolding A_def B_def C_def bisect_def split_def by simp | |
| 805 | ||
| 63353 | 806 | have width: "B n - A n = (b - a) / 2^n" for n | 
| 68669 | 807 | proof (induct n) | 
| 808 | case (Suc n) | |
| 809 | then show ?case | |
| 810 | by (simp add: C_def eq_divide_eq avg_def algebra_simps) | |
| 811 | qed simp | |
| 812 | have twos: "\<exists>n. y / 2 ^ n < r" if "0 < r" for y r :: rat | |
| 813 | proof - | |
| 814 | obtain n where "y / r < rat_of_nat n" | |
| 815 | using \<open>0 < r\<close> reals_Archimedean2 by blast | |
| 816 | then have "\<exists>n. y < r * 2 ^ n" | |
| 817 | by (metis divide_less_eq less_trans mult.commute of_nat_less_two_power that) | |
| 818 | then show ?thesis | |
| 70817 
dd675800469d
dedicated fact collections for algebraic simplification rules potentially splitting goals
 haftmann parents: 
70356diff
changeset | 819 | by (simp add: field_split_simps) | 
| 68669 | 820 | qed | 
| 63494 | 821 | have PA: "\<not> P (A n)" for n | 
| 822 | by (induct n) (simp_all add: a) | |
| 823 | have PB: "P (B n)" for n | |
| 824 | by (induct n) (simp_all add: b) | |
| 51523 | 825 | have ab: "a < b" | 
| 826 | using a b unfolding P_def | |
| 68669 | 827 | by (meson leI less_le_trans of_rat_less) | 
| 63494 | 828 | have AB: "A n < B n" for n | 
| 829 | by (induct n) (simp_all add: ab C_def avg_def) | |
| 68669 | 830 | have "A i \<le> A j \<and> B j \<le> B i" if "i < j" for i j | 
| 831 | using that | |
| 832 | proof (induction rule: less_Suc_induct) | |
| 833 | case (1 i) | |
| 834 | then show ?case | |
| 835 | apply (clarsimp simp add: C_def avg_def add_divide_distrib [symmetric]) | |
| 836 | apply (rule AB [THEN less_imp_le]) | |
| 837 | done | |
| 838 | qed simp | |
| 839 | then have A_mono: "A i \<le> A j" and B_mono: "B j \<le> B i" if "i \<le> j" for i j | |
| 840 | by (metis eq_refl le_neq_implies_less that)+ | |
| 841 | have cauchy_lemma: "cauchy X" if *: "\<And>n i. i\<ge>n \<Longrightarrow> A n \<le> X i \<and> X i \<le> B n" for X | |
| 842 | proof (rule cauchyI) | |
| 843 | fix r::rat | |
| 844 | assume "0 < r" | |
| 845 | then obtain k where k: "(b - a) / 2 ^ k < r" | |
| 846 | using twos by blast | |
| 847 | have "\<bar>X m - X n\<bar> < r" if "m\<ge>k" "n\<ge>k" for m n | |
| 848 | proof - | |
| 849 | have "\<bar>X m - X n\<bar> \<le> B k - A k" | |
| 850 | by (simp add: * abs_rat_def diff_mono that) | |
| 851 | also have "... < r" | |
| 852 | by (simp add: k width) | |
| 853 | finally show ?thesis . | |
| 854 | qed | |
| 855 | then show "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r" | |
| 856 | by blast | |
| 857 | qed | |
| 51523 | 858 | have "cauchy A" | 
| 68669 | 859 | by (rule cauchy_lemma) (meson AB A_mono B_mono dual_order.strict_implies_order less_le_trans) | 
| 51523 | 860 | have "cauchy B" | 
| 68669 | 861 | by (rule cauchy_lemma) (meson AB A_mono B_mono dual_order.strict_implies_order le_less_trans) | 
| 862 | have "\<forall>x\<in>S. x \<le> Real B" | |
| 51523 | 863 | proof | 
| 63353 | 864 | fix x | 
| 865 | assume "x \<in> S" | |
| 51523 | 866 | then show "x \<le> Real B" | 
| 60758 | 867 | using PB [unfolded P_def] \<open>cauchy B\<close> | 
| 51523 | 868 | by (simp add: le_RealI) | 
| 869 | qed | |
| 68669 | 870 | moreover have "\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> Real A \<le> z" | 
| 871 | by (meson PA Real_leI P_def \<open>cauchy A\<close> le_cases order.trans) | |
| 872 | moreover have "vanishes (\<lambda>n. (b - a) / 2 ^ n)" | |
| 51523 | 873 | proof (rule vanishesI) | 
| 63353 | 874 | fix r :: rat | 
| 875 | assume "0 < r" | |
| 51523 | 876 | then obtain k where k: "\<bar>b - a\<bar> / 2 ^ k < r" | 
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 877 | using twos by blast | 
| 51523 | 878 | have "\<forall>n\<ge>k. \<bar>(b - a) / 2 ^ n\<bar> < r" | 
| 63353 | 879 | proof clarify | 
| 880 | fix n | |
| 881 | assume n: "k \<le> n" | |
| 51523 | 882 | have "\<bar>(b - a) / 2 ^ n\<bar> = \<bar>b - a\<bar> / 2 ^ n" | 
| 883 | by simp | |
| 884 | also have "\<dots> \<le> \<bar>b - a\<bar> / 2 ^ k" | |
| 56544 | 885 | using n by (simp add: divide_left_mono) | 
| 51523 | 886 | also note k | 
| 887 | finally show "\<bar>(b - a) / 2 ^ n\<bar> < r" . | |
| 888 | qed | |
| 63353 | 889 | then show "\<exists>k. \<forall>n\<ge>k. \<bar>(b - a) / 2 ^ n\<bar> < r" .. | 
| 51523 | 890 | qed | 
| 68669 | 891 | then have "Real B = Real A" | 
| 60758 | 892 | by (simp add: eq_Real \<open>cauchy A\<close> \<open>cauchy B\<close> width) | 
| 68669 | 893 | ultimately show "\<exists>y. (\<forall>x\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> y \<le> z)" | 
| 894 | by force | |
| 51523 | 895 | qed | 
| 896 | ||
| 51775 
408d937c9486
revert #916271d52466; add non-topological linear_continuum type class; show linear_continuum_topology is a perfect_space
 hoelzl parents: 
51773diff
changeset | 897 | instantiation real :: linear_continuum | 
| 51523 | 898 | begin | 
| 899 | ||
| 63353 | 900 | subsection \<open>Supremum of a set of reals\<close> | 
| 51523 | 901 | |
| 54281 | 902 | definition "Sup X = (LEAST z::real. \<forall>x\<in>X. x \<le> z)" | 
| 63353 | 903 | definition "Inf X = - Sup (uminus ` X)" for X :: "real set" | 
| 51523 | 904 | |
| 905 | instance | |
| 906 | proof | |
| 63494 | 907 | show Sup_upper: "x \<le> Sup X" | 
| 908 | if "x \<in> X" "bdd_above X" | |
| 909 | for x :: real and X :: "real set" | |
| 63353 | 910 | proof - | 
| 911 | from that obtain s where s: "\<forall>y\<in>X. y \<le> s" "\<And>z. \<forall>y\<in>X. y \<le> z \<Longrightarrow> s \<le> z" | |
| 54258 
adfc759263ab
use bdd_above and bdd_below for conditionally complete lattices
 hoelzl parents: 
54230diff
changeset | 912 | using complete_real[of X] unfolding bdd_above_def by blast | 
| 63494 | 913 | then show ?thesis | 
| 914 | unfolding Sup_real_def by (rule LeastI2_order) (auto simp: that) | |
| 63353 | 915 | qed | 
| 63494 | 916 | show Sup_least: "Sup X \<le> z" | 
| 917 |     if "X \<noteq> {}" and z: "\<And>x. x \<in> X \<Longrightarrow> x \<le> z"
 | |
| 63353 | 918 | for z :: real and X :: "real set" | 
| 919 | proof - | |
| 920 | from that obtain s where s: "\<forall>y\<in>X. y \<le> s" "\<And>z. \<forall>y\<in>X. y \<le> z \<Longrightarrow> s \<le> z" | |
| 921 | using complete_real [of X] by blast | |
| 51523 | 922 | then have "Sup X = s" | 
| 61284 
2314c2f62eb1
real_of_nat_Suc is now a simprule
 paulson <lp15@cam.ac.uk> parents: 
61204diff
changeset | 923 | unfolding Sup_real_def by (best intro: Least_equality) | 
| 63353 | 924 | also from s z have "\<dots> \<le> z" | 
| 51523 | 925 | by blast | 
| 63353 | 926 | finally show ?thesis . | 
| 927 | qed | |
| 63494 | 928 | show "Inf X \<le> x" if "x \<in> X" "bdd_below X" | 
| 929 | for x :: real and X :: "real set" | |
| 63353 | 930 | using Sup_upper [of "-x" "uminus ` X"] by (auto simp: Inf_real_def that) | 
| 63494 | 931 |   show "z \<le> Inf X" if "X \<noteq> {}" "\<And>x. x \<in> X \<Longrightarrow> z \<le> x"
 | 
| 932 | for z :: real and X :: "real set" | |
| 63353 | 933 | using Sup_least [of "uminus ` X" "- z"] by (force simp: Inf_real_def that) | 
| 51775 
408d937c9486
revert #916271d52466; add non-topological linear_continuum type class; show linear_continuum_topology is a perfect_space
 hoelzl parents: 
51773diff
changeset | 934 | show "\<exists>a b::real. a \<noteq> b" | 
| 
408d937c9486
revert #916271d52466; add non-topological linear_continuum type class; show linear_continuum_topology is a perfect_space
 hoelzl parents: 
51773diff
changeset | 935 | using zero_neq_one by blast | 
| 51523 | 936 | qed | 
| 63353 | 937 | |
| 51523 | 938 | end | 
| 939 | ||
| 63353 | 940 | |
| 60758 | 941 | subsection \<open>Hiding implementation details\<close> | 
| 51523 | 942 | |
| 943 | hide_const (open) vanishes cauchy positive Real | |
| 944 | ||
| 945 | declare Real_induct [induct del] | |
| 946 | declare Abs_real_induct [induct del] | |
| 947 | declare Abs_real_cases [cases del] | |
| 948 | ||
| 53652 
18fbca265e2e
use lifting_forget for deregistering numeric types as a quotient type
 kuncar parents: 
53374diff
changeset | 949 | lifting_update real.lifting | 
| 
18fbca265e2e
use lifting_forget for deregistering numeric types as a quotient type
 kuncar parents: 
53374diff
changeset | 950 | lifting_forget real.lifting | 
| 61284 
2314c2f62eb1
real_of_nat_Suc is now a simprule
 paulson <lp15@cam.ac.uk> parents: 
61204diff
changeset | 951 | |
| 63353 | 952 | |
| 60758 | 953 | subsection \<open>Embedding numbers into the Reals\<close> | 
| 51523 | 954 | |
| 63353 | 955 | abbreviation real_of_nat :: "nat \<Rightarrow> real" | 
| 956 | where "real_of_nat \<equiv> of_nat" | |
| 51523 | 957 | |
| 63353 | 958 | abbreviation real :: "nat \<Rightarrow> real" | 
| 959 | where "real \<equiv> of_nat" | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 960 | |
| 63353 | 961 | abbreviation real_of_int :: "int \<Rightarrow> real" | 
| 962 | where "real_of_int \<equiv> of_int" | |
| 51523 | 963 | |
| 63353 | 964 | abbreviation real_of_rat :: "rat \<Rightarrow> real" | 
| 965 | where "real_of_rat \<equiv> of_rat" | |
| 51523 | 966 | |
| 967 | declare [[coercion_enabled]] | |
| 59000 | 968 | |
| 969 | declare [[coercion "of_nat :: nat \<Rightarrow> int"]] | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 970 | declare [[coercion "of_nat :: nat \<Rightarrow> real"]] | 
| 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 971 | declare [[coercion "of_int :: int \<Rightarrow> real"]] | 
| 59000 | 972 | |
| 973 | (* We do not add rat to the coerced types, this has often unpleasant side effects when writing | |
| 974 | inverse (Suc n) which sometimes gets two coercions: of_rat (inverse (of_nat (Suc n))) *) | |
| 51523 | 975 | |
| 976 | declare [[coercion_map map]] | |
| 59000 | 977 | declare [[coercion_map "\<lambda>f g h x. g (h (f x))"]] | 
| 978 | declare [[coercion_map "\<lambda>f g (x,y). (f x, g y)"]] | |
| 51523 | 979 | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 980 | declare of_int_eq_0_iff [algebra, presburger] | 
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 981 | declare of_int_eq_1_iff [algebra, presburger] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 982 | declare of_int_eq_iff [algebra, presburger] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 983 | declare of_int_less_0_iff [algebra, presburger] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 984 | declare of_int_less_1_iff [algebra, presburger] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 985 | declare of_int_less_iff [algebra, presburger] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 986 | declare of_int_le_0_iff [algebra, presburger] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 987 | declare of_int_le_1_iff [algebra, presburger] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 988 | declare of_int_le_iff [algebra, presburger] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 989 | declare of_int_0_less_iff [algebra, presburger] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 990 | declare of_int_0_le_iff [algebra, presburger] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 991 | declare of_int_1_less_iff [algebra, presburger] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 992 | declare of_int_1_le_iff [algebra, presburger] | 
| 51523 | 993 | |
| 63353 | 994 | lemma int_less_real_le: "n < m \<longleftrightarrow> real_of_int n + 1 \<le> real_of_int m" | 
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 995 | proof - | 
| 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 996 | have "(0::real) \<le> 1" | 
| 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 997 | by (metis less_eq_real_def zero_less_one) | 
| 63353 | 998 | then show ?thesis | 
| 61694 
6571c78c9667
Removed some legacy theorems; minor adjustments to simplification rules; new material on homotopic paths
 paulson <lp15@cam.ac.uk> parents: 
61649diff
changeset | 999 | by (metis floor_of_int less_floor_iff) | 
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1000 | qed | 
| 51523 | 1001 | |
| 63353 | 1002 | lemma int_le_real_less: "n \<le> m \<longleftrightarrow> real_of_int n < real_of_int m + 1" | 
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1003 | by (meson int_less_real_le not_le) | 
| 51523 | 1004 | |
| 63353 | 1005 | lemma real_of_int_div_aux: | 
| 1006 | "(real_of_int x) / (real_of_int d) = | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1007 | real_of_int (x div d) + (real_of_int (x mod d)) / (real_of_int d)" | 
| 51523 | 1008 | proof - | 
| 1009 | have "x = (x div d) * d + x mod d" | |
| 1010 | by auto | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1011 | then have "real_of_int x = real_of_int (x div d) * real_of_int d + real_of_int(x mod d)" | 
| 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1012 | by (metis of_int_add of_int_mult) | 
| 63353 | 1013 | then have "real_of_int x / real_of_int d = \<dots> / real_of_int d" | 
| 51523 | 1014 | by simp | 
| 1015 | then show ?thesis | |
| 1016 | by (auto simp add: add_divide_distrib algebra_simps) | |
| 1017 | qed | |
| 1018 | ||
| 58834 | 1019 | lemma real_of_int_div: | 
| 63353 | 1020 | "d dvd n \<Longrightarrow> real_of_int (n div d) = real_of_int n / real_of_int d" for d n :: int | 
| 58834 | 1021 | by (simp add: real_of_int_div_aux) | 
| 51523 | 1022 | |
| 63353 | 1023 | lemma real_of_int_div2: "0 \<le> real_of_int n / real_of_int x - real_of_int (n div x)" | 
| 68669 | 1024 | proof (cases "x = 0") | 
| 1025 | case False | |
| 1026 | then show ?thesis | |
| 1027 | by (metis diff_ge_0_iff_ge floor_divide_of_int_eq of_int_floor_le) | |
| 1028 | qed simp | |
| 51523 | 1029 | |
| 63353 | 1030 | lemma real_of_int_div3: "real_of_int n / real_of_int x - real_of_int (n div x) \<le> 1" | 
| 51523 | 1031 | apply (simp add: algebra_simps) | 
| 68669 | 1032 | by (metis add.commute floor_correct floor_divide_of_int_eq less_eq_real_def of_int_1 of_int_add) | 
| 51523 | 1033 | |
| 63353 | 1034 | lemma real_of_int_div4: "real_of_int (n div x) \<le> real_of_int n / real_of_int x" | 
| 1035 | using real_of_int_div2 [of n x] by simp | |
| 51523 | 1036 | |
| 1037 | ||
| 63353 | 1038 | subsection \<open>Embedding the Naturals into the Reals\<close> | 
| 51523 | 1039 | |
| 64267 | 1040 | lemma real_of_card: "real (card A) = sum (\<lambda>x. 1) A" | 
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1041 | by simp | 
| 51523 | 1042 | |
| 63353 | 1043 | lemma nat_less_real_le: "n < m \<longleftrightarrow> real n + 1 \<le> real m" | 
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1044 | by (metis discrete of_nat_1 of_nat_add of_nat_le_iff) | 
| 51523 | 1045 | |
| 63494 | 1046 | lemma nat_le_real_less: "n \<le> m \<longleftrightarrow> real n < real m + 1" | 
| 1047 | for m n :: nat | |
| 61284 
2314c2f62eb1
real_of_nat_Suc is now a simprule
 paulson <lp15@cam.ac.uk> parents: 
61204diff
changeset | 1048 | by (meson nat_less_real_le not_le) | 
| 51523 | 1049 | |
| 63353 | 1050 | lemma real_of_nat_div_aux: "real x / real d = real (x div d) + real (x mod d) / real d" | 
| 51523 | 1051 | proof - | 
| 1052 | have "x = (x div d) * d + x mod d" | |
| 1053 | by auto | |
| 1054 | then have "real x = real (x div d) * real d + real(x mod d)" | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1055 | by (metis of_nat_add of_nat_mult) | 
| 51523 | 1056 | then have "real x / real d = \<dots> / real d" | 
| 1057 | by simp | |
| 1058 | then show ?thesis | |
| 1059 | by (auto simp add: add_divide_distrib algebra_simps) | |
| 1060 | qed | |
| 1061 | ||
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1062 | lemma real_of_nat_div: "d dvd n \<Longrightarrow> real(n div d) = real n / real d" | 
| 63353 | 1063 | by (subst real_of_nat_div_aux) (auto simp add: dvd_eq_mod_eq_0 [symmetric]) | 
| 51523 | 1064 | |
| 63353 | 1065 | lemma real_of_nat_div2: "0 \<le> real n / real x - real (n div x)" for n x :: nat | 
| 1066 | apply (simp add: algebra_simps) | |
| 68669 | 1067 | by (metis floor_divide_of_nat_eq of_int_floor_le of_int_of_nat_eq) | 
| 51523 | 1068 | |
| 63353 | 1069 | lemma real_of_nat_div3: "real n / real x - real (n div x) \<le> 1" for n x :: nat | 
| 77490 
2c86ea8961b5
Some new lemmas. Some tidying up
 paulson <lp15@cam.ac.uk> parents: 
75864diff
changeset | 1070 | by (metis of_int_of_nat_eq real_of_int_div3 of_nat_div) | 
| 51523 | 1071 | |
| 63353 | 1072 | lemma real_of_nat_div4: "real (n div x) \<le> real n / real x" for n x :: nat | 
| 1073 | using real_of_nat_div2 [of n x] by simp | |
| 1074 | ||
| 75864 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75543diff
changeset | 1075 | lemma real_binomial_eq_mult_binomial_Suc: | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75543diff
changeset | 1076 | assumes "k \<le> n" | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75543diff
changeset | 1077 | shows "real(n choose k) = (n + 1 - k) / (n + 1) * (Suc n choose k)" | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75543diff
changeset | 1078 | using assms | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75543diff
changeset | 1079 | by (simp add: of_nat_binomial_eq_mult_binomial_Suc [of k n] add.commute of_nat_diff) | 
| 
3842556b757c
moved some material from Sum_of_Powers
 paulson <lp15@cam.ac.uk> parents: 
75543diff
changeset | 1080 | |
| 51523 | 1081 | |
| 60758 | 1082 | subsection \<open>The Archimedean Property of the Reals\<close> | 
| 51523 | 1083 | |
| 62623 
dbc62f86a1a9
rationalisation of theorem names esp about "real Archimedian" etc.
 paulson <lp15@cam.ac.uk> parents: 
62398diff
changeset | 1084 | lemma real_arch_inverse: "0 < e \<longleftrightarrow> (\<exists>n::nat. n \<noteq> 0 \<and> 0 < inverse (real n) \<and> inverse (real n) < e)" | 
| 
dbc62f86a1a9
rationalisation of theorem names esp about "real Archimedian" etc.
 paulson <lp15@cam.ac.uk> parents: 
62398diff
changeset | 1085 | using reals_Archimedean[of e] less_trans[of 0 "1 / real n" e for n::nat] | 
| 
dbc62f86a1a9
rationalisation of theorem names esp about "real Archimedian" etc.
 paulson <lp15@cam.ac.uk> parents: 
62398diff
changeset | 1086 | by (auto simp add: field_simps cong: conj_cong simp del: of_nat_Suc) | 
| 51523 | 1087 | |
| 63494 | 1088 | lemma reals_Archimedean3: "0 < x \<Longrightarrow> \<forall>y. \<exists>n. y < real n * x" | 
| 1089 | by (auto intro: ex_less_of_nat_mult) | |
| 51523 | 1090 | |
| 62397 
5ae24f33d343
Substantial new material for multivariate analysis. Also removal of some duplicates.
 paulson <lp15@cam.ac.uk> parents: 
62348diff
changeset | 1091 | lemma real_archimedian_rdiv_eq_0: | 
| 
5ae24f33d343
Substantial new material for multivariate analysis. Also removal of some duplicates.
 paulson <lp15@cam.ac.uk> parents: 
62348diff
changeset | 1092 | assumes x0: "x \<ge> 0" | 
| 63353 | 1093 | and c: "c \<ge> 0" | 
| 1094 | and xc: "\<And>m::nat. m > 0 \<Longrightarrow> real m * x \<le> c" | |
| 1095 | shows "x = 0" | |
| 1096 | by (metis reals_Archimedean3 dual_order.order_iff_strict le0 le_less_trans not_le x0 xc) | |
| 62397 
5ae24f33d343
Substantial new material for multivariate analysis. Also removal of some duplicates.
 paulson <lp15@cam.ac.uk> parents: 
62348diff
changeset | 1097 | |
| 77934 | 1098 | lemma inverse_Suc: "inverse (Suc n) > 0" | 
| 1099 | using of_nat_0_less_iff positive_imp_inverse_positive zero_less_Suc by blast | |
| 1100 | ||
| 1101 | lemma Archimedean_eventually_inverse: | |
| 1102 | fixes \<epsilon>::real shows "(\<forall>\<^sub>F n in sequentially. inverse (real (Suc n)) < \<epsilon>) \<longleftrightarrow> 0 < \<epsilon>" | |
| 1103 | (is "?lhs=?rhs") | |
| 1104 | proof | |
| 1105 | assume ?lhs | |
| 1106 | then show ?rhs | |
| 1107 | unfolding eventually_at_top_dense using inverse_Suc order_less_trans by blast | |
| 1108 | next | |
| 1109 | assume ?rhs | |
| 1110 | then obtain N where "inverse (Suc N) < \<epsilon>" | |
| 1111 | using reals_Archimedean by blast | |
| 1112 | moreover have "inverse (Suc n) \<le> inverse (Suc N)" if "n \<ge> N" for n | |
| 1113 | using inverse_Suc that by fastforce | |
| 1114 | ultimately show ?lhs | |
| 1115 | unfolding eventually_sequentially | |
| 1116 | using order_le_less_trans by blast | |
| 1117 | qed | |
| 1118 | ||
| 78250 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1119 | (*HOL Light's FORALL_POS_MONO_1_EQ*) | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1120 | text \<open>On the relationship between two different ways of converting to 0\<close> | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1121 | lemma Inter_eq_Inter_inverse_Suc: | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1122 | assumes "\<And>r' r. r' < r \<Longrightarrow> A r' \<subseteq> A r" | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1123 |   shows "\<Inter> (A ` {0<..}) = (\<Inter>n. A(inverse(Suc n)))"
 | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1124 | proof | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1125 | have "x \<in> A \<epsilon>" | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1126 | if x: "\<forall>n. x \<in> A (inverse (Suc n))" and "\<epsilon>>0" for x and \<epsilon> :: real | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1127 | proof - | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1128 | obtain n where "inverse (Suc n) < \<epsilon>" | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1129 | using \<open>\<epsilon>>0\<close> reals_Archimedean by blast | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1130 | with assms x show ?thesis | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1131 | by blast | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1132 | qed | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1133 |   then show "(\<Inter>n. A(inverse(Suc n))) \<subseteq> (\<Inter>\<epsilon>\<in>{0<..}. A \<epsilon>)"
 | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1134 | by auto | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1135 | qed (use inverse_Suc in fastforce) | 
| 
400aecdfd71f
Another tranche of HOL Light material on metric and topological spaces
 paulson <lp15@cam.ac.uk> parents: 
77943diff
changeset | 1136 | |
| 63353 | 1137 | subsection \<open>Rationals\<close> | 
| 51523 | 1138 | |
| 68529 | 1139 | lemma Rats_abs_iff[simp]: | 
| 1140 | "\<bar>(x::real)\<bar> \<in> \<rat> \<longleftrightarrow> x \<in> \<rat>" | |
| 1141 | by(simp add: abs_real_def split: if_splits) | |
| 1142 | ||
| 63353 | 1143 | lemma Rats_eq_int_div_int: "\<rat> = {real_of_int i / real_of_int j | i j. j \<noteq> 0}"  (is "_ = ?S")
 | 
| 51523 | 1144 | proof | 
| 1145 | show "\<rat> \<subseteq> ?S" | |
| 1146 | proof | |
| 63353 | 1147 | fix x :: real | 
| 1148 | assume "x \<in> \<rat>" | |
| 1149 | then obtain r where "x = of_rat r" | |
| 1150 | unfolding Rats_def .. | |
| 1151 | have "of_rat r \<in> ?S" | |
| 1152 | by (cases r) (auto simp add: of_rat_rat) | |
| 1153 | then show "x \<in> ?S" | |
| 1154 | using \<open>x = of_rat r\<close> by simp | |
| 51523 | 1155 | qed | 
| 1156 | next | |
| 1157 | show "?S \<subseteq> \<rat>" | |
| 63353 | 1158 | proof (auto simp: Rats_def) | 
| 1159 | fix i j :: int | |
| 1160 | assume "j \<noteq> 0" | |
| 1161 | then have "real_of_int i / real_of_int j = of_rat (Fract i j)" | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1162 | by (simp add: of_rat_rat) | 
| 63353 | 1163 | then show "real_of_int i / real_of_int j \<in> range of_rat" | 
| 1164 | by blast | |
| 51523 | 1165 | qed | 
| 1166 | qed | |
| 1167 | ||
| 63353 | 1168 | lemma Rats_eq_int_div_nat: "\<rat> = { real_of_int i / real n | i n. n \<noteq> 0}"
 | 
| 1169 | proof (auto simp: Rats_eq_int_div_int) | |
| 1170 | fix i j :: int | |
| 1171 | assume "j \<noteq> 0" | |
| 1172 | show "\<exists>(i'::int) (n::nat). real_of_int i / real_of_int j = real_of_int i' / real n \<and> 0 < n" | |
| 1173 | proof (cases "j > 0") | |
| 1174 | case True | |
| 1175 | then have "real_of_int i / real_of_int j = real_of_int i / real (nat j) \<and> 0 < nat j" | |
| 1176 | by simp | |
| 1177 | then show ?thesis by blast | |
| 51523 | 1178 | next | 
| 63353 | 1179 | case False | 
| 1180 | with \<open>j \<noteq> 0\<close> | |
| 1181 | have "real_of_int i / real_of_int j = real_of_int (- i) / real (nat (- j)) \<and> 0 < nat (- j)" | |
| 1182 | by simp | |
| 1183 | then show ?thesis by blast | |
| 51523 | 1184 | qed | 
| 1185 | next | |
| 63353 | 1186 | fix i :: int and n :: nat | 
| 1187 | assume "0 < n" | |
| 1188 | then have "real_of_int i / real n = real_of_int i / real_of_int(int n) \<and> int n \<noteq> 0" | |
| 1189 | by simp | |
| 1190 | then show "\<exists>i' j. real_of_int i / real n = real_of_int i' / real_of_int j \<and> j \<noteq> 0" | |
| 1191 | by blast | |
| 51523 | 1192 | qed | 
| 1193 | ||
| 1194 | lemma Rats_abs_nat_div_natE: | |
| 1195 | assumes "x \<in> \<rat>" | |
| 67051 | 1196 | obtains m n :: nat where "n \<noteq> 0" and "\<bar>x\<bar> = real m / real n" and "coprime m n" | 
| 51523 | 1197 | proof - | 
| 63353 | 1198 | from \<open>x \<in> \<rat>\<close> obtain i :: int and n :: nat where "n \<noteq> 0" and "x = real_of_int i / real n" | 
| 1199 | by (auto simp add: Rats_eq_int_div_nat) | |
| 1200 | then have "\<bar>x\<bar> = real (nat \<bar>i\<bar>) / real n" by simp | |
| 51523 | 1201 | then obtain m :: nat where x_rat: "\<bar>x\<bar> = real m / real n" by blast | 
| 1202 | let ?gcd = "gcd m n" | |
| 63353 | 1203 | from \<open>n \<noteq> 0\<close> have gcd: "?gcd \<noteq> 0" by simp | 
| 51523 | 1204 | let ?k = "m div ?gcd" | 
| 1205 | let ?l = "n div ?gcd" | |
| 1206 | let ?gcd' = "gcd ?k ?l" | |
| 63353 | 1207 | have "?gcd dvd m" .. | 
| 1208 | then have gcd_k: "?gcd * ?k = m" | |
| 51523 | 1209 | by (rule dvd_mult_div_cancel) | 
| 63353 | 1210 | have "?gcd dvd n" .. | 
| 1211 | then have gcd_l: "?gcd * ?l = n" | |
| 51523 | 1212 | by (rule dvd_mult_div_cancel) | 
| 63353 | 1213 | from \<open>n \<noteq> 0\<close> and gcd_l have "?gcd * ?l \<noteq> 0" by simp | 
| 61284 
2314c2f62eb1
real_of_nat_Suc is now a simprule
 paulson <lp15@cam.ac.uk> parents: 
61204diff
changeset | 1214 | then have "?l \<noteq> 0" by (blast dest!: mult_not_zero) | 
| 51523 | 1215 | moreover | 
| 1216 | have "\<bar>x\<bar> = real ?k / real ?l" | |
| 1217 | proof - | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1218 | from gcd have "real ?k / real ?l = real (?gcd * ?k) / real (?gcd * ?l)" | 
| 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1219 | by (simp add: real_of_nat_div) | 
| 51523 | 1220 | also from gcd_k and gcd_l have "\<dots> = real m / real n" by simp | 
| 1221 | also from x_rat have "\<dots> = \<bar>x\<bar>" .. | |
| 1222 | finally show ?thesis .. | |
| 1223 | qed | |
| 1224 | moreover | |
| 1225 | have "?gcd' = 1" | |
| 1226 | proof - | |
| 1227 | have "?gcd * ?gcd' = gcd (?gcd * ?k) (?gcd * ?l)" | |
| 1228 | by (rule gcd_mult_distrib_nat) | |
| 1229 | with gcd_k gcd_l have "?gcd * ?gcd' = ?gcd" by simp | |
| 1230 | with gcd show ?thesis by auto | |
| 1231 | qed | |
| 67051 | 1232 | then have "coprime ?k ?l" | 
| 1233 | by (simp only: coprime_iff_gcd_eq_1) | |
| 51523 | 1234 | ultimately show ?thesis .. | 
| 1235 | qed | |
| 1236 | ||
| 63353 | 1237 | |
| 1238 | subsection \<open>Density of the Rational Reals in the Reals\<close> | |
| 51523 | 1239 | |
| 63353 | 1240 | text \<open> | 
| 1241 | This density proof is due to Stefan Richter and was ported by TN. The | |
| 63494 | 1242 | original source is \<^emph>\<open>Real Analysis\<close> by H.L. Royden. | 
| 63353 | 1243 | It employs the Archimedean property of the reals.\<close> | 
| 51523 | 1244 | |
| 1245 | lemma Rats_dense_in_real: | |
| 1246 | fixes x :: real | |
| 63353 | 1247 | assumes "x < y" | 
| 1248 | shows "\<exists>r\<in>\<rat>. x < r \<and> r < y" | |
| 51523 | 1249 | proof - | 
| 63353 | 1250 | from \<open>x < y\<close> have "0 < y - x" by simp | 
| 1251 | with reals_Archimedean obtain q :: nat where q: "inverse (real q) < y - x" and "0 < q" | |
| 1252 | by blast | |
| 63040 | 1253 | define p where "p = \<lceil>y * real q\<rceil> - 1" | 
| 1254 | define r where "r = of_int p / real q" | |
| 63494 | 1255 | from q have "x < y - inverse (real q)" | 
| 1256 | by simp | |
| 1257 | also from \<open>0 < q\<close> have "y - inverse (real q) \<le> r" | |
| 1258 | by (simp add: r_def p_def le_divide_eq left_diff_distrib) | |
| 51523 | 1259 | finally have "x < r" . | 
| 63494 | 1260 | moreover from \<open>0 < q\<close> have "r < y" | 
| 1261 | by (simp add: r_def p_def divide_less_eq diff_less_eq less_ceiling_iff [symmetric]) | |
| 1262 | moreover have "r \<in> \<rat>" | |
| 1263 | by (simp add: r_def) | |
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61609diff
changeset | 1264 | ultimately show ?thesis by blast | 
| 51523 | 1265 | qed | 
| 1266 | ||
| 57447 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57275diff
changeset | 1267 | lemma of_rat_dense: | 
| 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57275diff
changeset | 1268 | fixes x y :: real | 
| 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57275diff
changeset | 1269 | assumes "x < y" | 
| 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57275diff
changeset | 1270 | shows "\<exists>q :: rat. x < of_rat q \<and> of_rat q < y" | 
| 63353 | 1271 | using Rats_dense_in_real [OF \<open>x < y\<close>] | 
| 1272 | by (auto elim: Rats_cases) | |
| 51523 | 1273 | |
| 1274 | ||
| 63353 | 1275 | subsection \<open>Numerals and Arithmetic\<close> | 
| 51523 | 1276 | |
| 60758 | 1277 | declaration \<open> | 
| 70356 
4a327c061870
streamlined setup for linear algebra, particularly removed redundant rule declarations
 haftmann parents: 
70270diff
changeset | 1278 | K (Lin_Arith.add_inj_const (\<^const_name>\<open>of_nat\<close>, \<^typ>\<open>nat \<Rightarrow> real\<close>) | 
| 69593 | 1279 | #> Lin_Arith.add_inj_const (\<^const_name>\<open>of_int\<close>, \<^typ>\<open>int \<Rightarrow> real\<close>)) | 
| 60758 | 1280 | \<close> | 
| 51523 | 1281 | |
| 63353 | 1282 | |
| 1283 | subsection \<open>Simprules combining \<open>x + y\<close> and \<open>0\<close>\<close> (* FIXME ARE THEY NEEDED? *) | |
| 51523 | 1284 | |
| 63494 | 1285 | lemma real_add_minus_iff [simp]: "x + - a = 0 \<longleftrightarrow> x = a" | 
| 1286 | for x a :: real | |
| 63353 | 1287 | by arith | 
| 51523 | 1288 | |
| 63494 | 1289 | lemma real_add_less_0_iff: "x + y < 0 \<longleftrightarrow> y < - x" | 
| 1290 | for x y :: real | |
| 63353 | 1291 | by auto | 
| 51523 | 1292 | |
| 63494 | 1293 | lemma real_0_less_add_iff: "0 < x + y \<longleftrightarrow> - x < y" | 
| 1294 | for x y :: real | |
| 63353 | 1295 | by auto | 
| 51523 | 1296 | |
| 63494 | 1297 | lemma real_add_le_0_iff: "x + y \<le> 0 \<longleftrightarrow> y \<le> - x" | 
| 1298 | for x y :: real | |
| 63353 | 1299 | by auto | 
| 51523 | 1300 | |
| 63494 | 1301 | lemma real_0_le_add_iff: "0 \<le> x + y \<longleftrightarrow> - x \<le> y" | 
| 1302 | for x y :: real | |
| 63353 | 1303 | by auto | 
| 1304 | ||
| 51523 | 1305 | |
| 60758 | 1306 | subsection \<open>Lemmas about powers\<close> | 
| 51523 | 1307 | |
| 1308 | lemma two_realpow_ge_one: "(1::real) \<le> 2 ^ n" | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1309 | by simp | 
| 51523 | 1310 | |
| 63353 | 1311 | (* FIXME: declare this [simp] for all types, or not at all *) | 
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1312 | declare sum_squares_eq_zero_iff [simp] sum_power2_eq_zero_iff [simp] | 
| 51523 | 1313 | |
| 63494 | 1314 | lemma real_minus_mult_self_le [simp]: "- (u * u) \<le> x * x" | 
| 1315 | for u x :: real | |
| 63353 | 1316 | by (rule order_trans [where y = 0]) auto | 
| 51523 | 1317 | |
| 63494 | 1318 | lemma realpow_square_minus_le [simp]: "- u\<^sup>2 \<le> x\<^sup>2" | 
| 1319 | for u x :: real | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1320 | by (auto simp add: power2_eq_square) | 
| 51523 | 1321 | |
| 56889 
48a745e1bde7
avoid the Complex constructor, use the more natural Re/Im view; moved csqrt to Complex.
 hoelzl parents: 
56571diff
changeset | 1322 | |
| 63353 | 1323 | subsection \<open>Density of the Reals\<close> | 
| 1324 | ||
| 68527 
2f4e2aab190a
Generalising and renaming some basic results
 paulson <lp15@cam.ac.uk> parents: 
68484diff
changeset | 1325 | lemma field_lbound_gt_zero: "0 < d1 \<Longrightarrow> 0 < d2 \<Longrightarrow> \<exists>e. 0 < e \<and> e < d1 \<and> e < d2" | 
| 
2f4e2aab190a
Generalising and renaming some basic results
 paulson <lp15@cam.ac.uk> parents: 
68484diff
changeset | 1326 | for d1 d2 :: "'a::linordered_field" | 
| 63353 | 1327 | by (rule exI [where x = "min d1 d2 / 2"]) (simp add: min_def) | 
| 51523 | 1328 | |
| 68527 
2f4e2aab190a
Generalising and renaming some basic results
 paulson <lp15@cam.ac.uk> parents: 
68484diff
changeset | 1329 | lemma field_less_half_sum: "x < y \<Longrightarrow> x < (x + y) / 2" | 
| 
2f4e2aab190a
Generalising and renaming some basic results
 paulson <lp15@cam.ac.uk> parents: 
68484diff
changeset | 1330 | for x y :: "'a::linordered_field" | 
| 63353 | 1331 | by auto | 
| 1332 | ||
| 68527 
2f4e2aab190a
Generalising and renaming some basic results
 paulson <lp15@cam.ac.uk> parents: 
68484diff
changeset | 1333 | lemma field_sum_of_halves: "x / 2 + x / 2 = x" | 
| 
2f4e2aab190a
Generalising and renaming some basic results
 paulson <lp15@cam.ac.uk> parents: 
68484diff
changeset | 1334 | for x :: "'a::linordered_field" | 
| 63353 | 1335 | by simp | 
| 51523 | 1336 | |
| 1337 | ||
| 71043 | 1338 | subsection \<open>Archimedean properties and useful consequences\<close> | 
| 1339 | ||
| 1340 | text\<open>Bernoulli's inequality\<close> | |
| 1341 | proposition Bernoulli_inequality: | |
| 1342 | fixes x :: real | |
| 1343 | assumes "-1 \<le> x" | |
| 1344 | shows "1 + n * x \<le> (1 + x) ^ n" | |
| 1345 | proof (induct n) | |
| 1346 | case 0 | |
| 1347 | then show ?case by simp | |
| 1348 | next | |
| 1349 | case (Suc n) | |
| 1350 | have "1 + Suc n * x \<le> 1 + (Suc n)*x + n * x^2" | |
| 1351 | by (simp add: algebra_simps) | |
| 1352 | also have "... = (1 + x) * (1 + n*x)" | |
| 1353 | by (auto simp: power2_eq_square algebra_simps) | |
| 1354 | also have "... \<le> (1 + x) ^ Suc n" | |
| 1355 | using Suc.hyps assms mult_left_mono by fastforce | |
| 1356 | finally show ?case . | |
| 1357 | qed | |
| 1358 | ||
| 1359 | corollary Bernoulli_inequality_even: | |
| 1360 | fixes x :: real | |
| 1361 | assumes "even n" | |
| 1362 | shows "1 + n * x \<le> (1 + x) ^ n" | |
| 1363 | proof (cases "-1 \<le> x \<or> n=0") | |
| 1364 | case True | |
| 1365 | then show ?thesis | |
| 1366 | by (auto simp: Bernoulli_inequality) | |
| 1367 | next | |
| 1368 | case False | |
| 1369 | then have "real n \<ge> 1" | |
| 1370 | by simp | |
| 1371 | with False have "n * x \<le> -1" | |
| 1372 | by (metis linear minus_zero mult.commute mult.left_neutral mult_left_mono_neg neg_le_iff_le order_trans zero_le_one) | |
| 1373 | then have "1 + n * x \<le> 0" | |
| 1374 | by auto | |
| 1375 | also have "... \<le> (1 + x) ^ n" | |
| 1376 | using assms | |
| 1377 | using zero_le_even_power by blast | |
| 1378 | finally show ?thesis . | |
| 1379 | qed | |
| 1380 | ||
| 1381 | corollary real_arch_pow: | |
| 1382 | fixes x :: real | |
| 1383 | assumes x: "1 < x" | |
| 1384 | shows "\<exists>n. y < x^n" | |
| 1385 | proof - | |
| 1386 | from x have x0: "x - 1 > 0" | |
| 1387 | by arith | |
| 1388 | from reals_Archimedean3[OF x0, rule_format, of y] | |
| 1389 | obtain n :: nat where n: "y < real n * (x - 1)" by metis | |
| 1390 | from x0 have x00: "x- 1 \<ge> -1" by arith | |
| 1391 | from Bernoulli_inequality[OF x00, of n] n | |
| 1392 | have "y < x^n" by auto | |
| 1393 | then show ?thesis by metis | |
| 1394 | qed | |
| 1395 | ||
| 1396 | corollary real_arch_pow_inv: | |
| 1397 | fixes x y :: real | |
| 1398 | assumes y: "y > 0" | |
| 1399 | and x1: "x < 1" | |
| 1400 | shows "\<exists>n. x^n < y" | |
| 1401 | proof (cases "x > 0") | |
| 1402 | case True | |
| 1403 | with x1 have ix: "1 < 1/x" by (simp add: field_simps) | |
| 1404 | from real_arch_pow[OF ix, of "1/y"] | |
| 1405 | obtain n where n: "1/y < (1/x)^n" by blast | |
| 1406 | then show ?thesis using y \<open>x > 0\<close> | |
| 1407 | by (auto simp add: field_simps) | |
| 1408 | next | |
| 1409 | case False | |
| 1410 | with y x1 show ?thesis | |
| 1411 | by (metis less_le_trans not_less power_one_right) | |
| 1412 | qed | |
| 1413 | ||
| 1414 | lemma forall_pos_mono: | |
| 1415 | "(\<And>d e::real. d < e \<Longrightarrow> P d \<Longrightarrow> P e) \<Longrightarrow> | |
| 1416 | (\<And>n::nat. n \<noteq> 0 \<Longrightarrow> P (inverse (real n))) \<Longrightarrow> (\<And>e. 0 < e \<Longrightarrow> P e)" | |
| 1417 | by (metis real_arch_inverse) | |
| 1418 | ||
| 1419 | lemma forall_pos_mono_1: | |
| 1420 | "(\<And>d e::real. d < e \<Longrightarrow> P d \<Longrightarrow> P e) \<Longrightarrow> | |
| 1421 | (\<And>n. P (inverse (real (Suc n)))) \<Longrightarrow> 0 < e \<Longrightarrow> P e" | |
| 77943 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1422 | using reals_Archimedean by blast | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1423 | |
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1424 | lemma Archimedean_eventually_pow: | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1425 | fixes x::real | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1426 | assumes "1 < x" | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1427 | shows "\<forall>\<^sub>F n in sequentially. b < x ^ n" | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1428 | proof - | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1429 | obtain N where "\<And>n. n\<ge>N \<Longrightarrow> b < x ^ n" | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1430 | by (metis assms le_less order_less_trans power_strict_increasing_iff real_arch_pow) | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1431 | then show ?thesis | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1432 | using eventually_sequentially by blast | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1433 | qed | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1434 | |
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1435 | lemma Archimedean_eventually_pow_inverse: | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1436 | fixes x::real | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1437 | assumes "\<bar>x\<bar> < 1" "\<epsilon> > 0" | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1438 | shows "\<forall>\<^sub>F n in sequentially. \<bar>x^n\<bar> < \<epsilon>" | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1439 | proof (cases "x = 0") | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1440 | case True | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1441 | then show ?thesis | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1442 | by (simp add: assms eventually_at_top_dense zero_power) | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1443 | next | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1444 | case False | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1445 | then have "\<forall>\<^sub>F n in sequentially. inverse \<epsilon> < inverse \<bar>x\<bar> ^ n" | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1446 | by (simp add: Archimedean_eventually_pow assms(1) one_less_inverse) | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1447 | then show ?thesis | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1448 | by eventually_elim (metis \<open>\<epsilon> > 0\<close> inverse_less_imp_less power_abs power_inverse) | 
| 
ffdad62bc235
Importation of additional lemmas from metric.ml
 paulson <lp15@cam.ac.uk> parents: 
77934diff
changeset | 1449 | qed | 
| 71043 | 1450 | |
| 1451 | ||
| 63353 | 1452 | subsection \<open>Floor and Ceiling Functions from the Reals to the Integers\<close> | 
| 51523 | 1453 | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1454 | (* FIXME: theorems for negative numerals. Many duplicates, e.g. from Archimedean_Field.thy. *) | 
| 51523 | 1455 | |
| 63494 | 1456 | lemma real_of_nat_less_numeral_iff [simp]: "real n < numeral w \<longleftrightarrow> n < numeral w" | 
| 1457 | for n :: nat | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1458 | by (metis of_nat_less_iff of_nat_numeral) | 
| 56889 
48a745e1bde7
avoid the Complex constructor, use the more natural Re/Im view; moved csqrt to Complex.
 hoelzl parents: 
56571diff
changeset | 1459 | |
| 63494 | 1460 | lemma numeral_less_real_of_nat_iff [simp]: "numeral w < real n \<longleftrightarrow> numeral w < n" | 
| 1461 | for n :: nat | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1462 | by (metis of_nat_less_iff of_nat_numeral) | 
| 56889 
48a745e1bde7
avoid the Complex constructor, use the more natural Re/Im view; moved csqrt to Complex.
 hoelzl parents: 
56571diff
changeset | 1463 | |
| 63494 | 1464 | lemma numeral_le_real_of_nat_iff [simp]: "numeral n \<le> real m \<longleftrightarrow> numeral n \<le> m" | 
| 1465 | for m :: nat | |
| 63353 | 1466 | by (metis not_le real_of_nat_less_numeral_iff) | 
| 59587 
8ea7b22525cb
Removed the obsolete functions "natfloor" and "natceiling"
 nipkow parents: 
59000diff
changeset | 1467 | |
| 63353 | 1468 | lemma of_int_floor_cancel [simp]: "of_int \<lfloor>x\<rfloor> = x \<longleftrightarrow> (\<exists>n::int. x = of_int n)" | 
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1469 | by (metis floor_of_int) | 
| 51523 | 1470 | |
| 75543 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1471 | lemma of_int_floor [simp]: "a \<in> \<int> \<Longrightarrow> of_int (floor a) = a" | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1472 | by (metis Ints_cases of_int_floor_cancel) | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1473 | |
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1474 | lemma floor_frac [simp]: "\<lfloor>frac r\<rfloor> = 0" | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1475 | by (simp add: frac_def) | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1476 | |
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1477 | lemma frac_1 [simp]: "frac 1 = 0" | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1478 | by (simp add: frac_def) | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1479 | |
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1480 | lemma frac_in_Rats_iff [simp]: | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1481 |   fixes r::"'a::{floor_ceiling,field_char_0}"
 | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1482 | shows "frac r \<in> \<rat> \<longleftrightarrow> r \<in> \<rat>" | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1483 | by (metis Rats_add Rats_diff Rats_of_int diff_add_cancel frac_def) | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1484 | |
| 63353 | 1485 | lemma floor_eq: "real_of_int n < x \<Longrightarrow> x < real_of_int n + 1 \<Longrightarrow> \<lfloor>x\<rfloor> = n" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1486 | by linarith | 
| 51523 | 1487 | |
| 63353 | 1488 | lemma floor_eq2: "real_of_int n \<le> x \<Longrightarrow> x < real_of_int n + 1 \<Longrightarrow> \<lfloor>x\<rfloor> = n" | 
| 67051 | 1489 | by (fact floor_unique) | 
| 51523 | 1490 | |
| 63353 | 1491 | lemma floor_eq3: "real n < x \<Longrightarrow> x < real (Suc n) \<Longrightarrow> nat \<lfloor>x\<rfloor> = n" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1492 | by linarith | 
| 51523 | 1493 | |
| 63353 | 1494 | lemma floor_eq4: "real n \<le> x \<Longrightarrow> x < real (Suc n) \<Longrightarrow> nat \<lfloor>x\<rfloor> = n" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1495 | by linarith | 
| 51523 | 1496 | |
| 61942 | 1497 | lemma real_of_int_floor_ge_diff_one [simp]: "r - 1 \<le> real_of_int \<lfloor>r\<rfloor>" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1498 | by linarith | 
| 51523 | 1499 | |
| 61942 | 1500 | lemma real_of_int_floor_gt_diff_one [simp]: "r - 1 < real_of_int \<lfloor>r\<rfloor>" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1501 | by linarith | 
| 51523 | 1502 | |
| 61942 | 1503 | lemma real_of_int_floor_add_one_ge [simp]: "r \<le> real_of_int \<lfloor>r\<rfloor> + 1" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1504 | by linarith | 
| 51523 | 1505 | |
| 61942 | 1506 | lemma real_of_int_floor_add_one_gt [simp]: "r < real_of_int \<lfloor>r\<rfloor> + 1" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1507 | by linarith | 
| 51523 | 1508 | |
| 63353 | 1509 | lemma floor_divide_real_eq_div: | 
| 1510 | assumes "0 \<le> b" | |
| 1511 | shows "\<lfloor>a / real_of_int b\<rfloor> = \<lfloor>a\<rfloor> div b" | |
| 1512 | proof (cases "b = 0") | |
| 1513 | case True | |
| 1514 | then show ?thesis by simp | |
| 1515 | next | |
| 1516 | case False | |
| 1517 | with assms have b: "b > 0" by simp | |
| 1518 | have "j = i div b" | |
| 1519 | if "real_of_int i \<le> a" "a < 1 + real_of_int i" | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1520 | "real_of_int j * real_of_int b \<le> a" "a < real_of_int b + real_of_int j * real_of_int b" | 
| 63353 | 1521 | for i j :: int | 
| 1522 | proof - | |
| 1523 | from that have "i < b + j * b" | |
| 1524 | by (metis le_less_trans of_int_add of_int_less_iff of_int_mult) | |
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1525 | moreover have "j * b < 1 + i" | 
| 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1526 | proof - | 
| 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1527 | have "real_of_int (j * b) < real_of_int i + 1" | 
| 61799 | 1528 | using \<open>a < 1 + real_of_int i\<close> \<open>real_of_int j * real_of_int b \<le> a\<close> by force | 
| 63597 | 1529 | then show "j * b < 1 + i" by linarith | 
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1530 | qed | 
| 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1531 | ultimately have "(j - i div b) * b \<le> i mod b" "i mod b < ((j - i div b) + 1) * b" | 
| 58788 
d17b3844b726
generalize natfloor_div_nat, add floor variant: floor_divide_real_eq_div
 hoelzl parents: 
58134diff
changeset | 1532 | by (auto simp: field_simps) | 
| 
d17b3844b726
generalize natfloor_div_nat, add floor variant: floor_divide_real_eq_div
 hoelzl parents: 
58134diff
changeset | 1533 | then have "(j - i div b) * b < 1 * b" "0 * b < ((j - i div b) + 1) * b" | 
| 63353 | 1534 | using pos_mod_bound [OF b, of i] pos_mod_sign [OF b, of i] | 
| 1535 | by linarith+ | |
| 63597 | 1536 | then show ?thesis using b unfolding mult_less_cancel_right by auto | 
| 63353 | 1537 | qed | 
| 63597 | 1538 | with b show ?thesis by (auto split: floor_split simp: field_simps) | 
| 63353 | 1539 | qed | 
| 58788 
d17b3844b726
generalize natfloor_div_nat, add floor variant: floor_divide_real_eq_div
 hoelzl parents: 
58134diff
changeset | 1540 | |
| 63601 | 1541 | lemma floor_one_divide_eq_div_numeral [simp]: | 
| 1542 | "\<lfloor>1 / numeral b::real\<rfloor> = 1 div numeral b" | |
| 1543 | by (metis floor_divide_of_int_eq of_int_1 of_int_numeral) | |
| 1544 | ||
| 1545 | lemma floor_minus_one_divide_eq_div_numeral [simp]: | |
| 1546 | "\<lfloor>- (1 / numeral b)::real\<rfloor> = - 1 div numeral b" | |
| 73932 
fd21b4a93043
added opaque_combs and renamed hide_lams to opaque_lifting
 desharna parents: 
72607diff
changeset | 1547 | by (metis (mono_tags, opaque_lifting) div_minus_right minus_divide_right | 
| 63601 | 1548 | floor_divide_of_int_eq of_int_neg_numeral of_int_1) | 
| 1549 | ||
| 63597 | 1550 | lemma floor_divide_eq_div_numeral [simp]: | 
| 1551 | "\<lfloor>numeral a / numeral b::real\<rfloor> = numeral a div numeral b" | |
| 1552 | by (metis floor_divide_of_int_eq of_int_numeral) | |
| 58097 
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
 hoelzl parents: 
58061diff
changeset | 1553 | |
| 63353 | 1554 | lemma floor_minus_divide_eq_div_numeral [simp]: | 
| 1555 | "\<lfloor>- (numeral a / numeral b)::real\<rfloor> = - numeral a div numeral b" | |
| 63597 | 1556 | by (metis divide_minus_left floor_divide_of_int_eq of_int_neg_numeral of_int_numeral) | 
| 51523 | 1557 | |
| 63353 | 1558 | lemma of_int_ceiling_cancel [simp]: "of_int \<lceil>x\<rceil> = x \<longleftrightarrow> (\<exists>n::int. x = of_int n)" | 
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1559 | using ceiling_of_int by metis | 
| 51523 | 1560 | |
| 75543 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1561 | lemma of_int_ceiling [simp]: "a \<in> \<int> \<Longrightarrow> of_int (ceiling a) = a" | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1562 | by (metis Ints_cases of_int_ceiling_cancel) | 
| 
1910054f8c39
some additional lemmas and a little tidying up
 paulson <lp15@cam.ac.uk> parents: 
75327diff
changeset | 1563 | |
| 63353 | 1564 | lemma ceiling_eq: "of_int n < x \<Longrightarrow> x \<le> of_int n + 1 \<Longrightarrow> \<lceil>x\<rceil> = n + 1" | 
| 61694 
6571c78c9667
Removed some legacy theorems; minor adjustments to simplification rules; new material on homotopic paths
 paulson <lp15@cam.ac.uk> parents: 
61649diff
changeset | 1565 | by (simp add: ceiling_unique) | 
| 51523 | 1566 | |
| 61942 | 1567 | lemma of_int_ceiling_diff_one_le [simp]: "of_int \<lceil>r\<rceil> - 1 \<le> r" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1568 | by linarith | 
| 51523 | 1569 | |
| 61942 | 1570 | lemma of_int_ceiling_le_add_one [simp]: "of_int \<lceil>r\<rceil> \<le> r + 1" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1571 | by linarith | 
| 51523 | 1572 | |
| 63353 | 1573 | lemma ceiling_le: "x \<le> of_int a \<Longrightarrow> \<lceil>x\<rceil> \<le> a" | 
| 61694 
6571c78c9667
Removed some legacy theorems; minor adjustments to simplification rules; new material on homotopic paths
 paulson <lp15@cam.ac.uk> parents: 
61649diff
changeset | 1574 | by (simp add: ceiling_le_iff) | 
| 51523 | 1575 | |
| 61694 
6571c78c9667
Removed some legacy theorems; minor adjustments to simplification rules; new material on homotopic paths
 paulson <lp15@cam.ac.uk> parents: 
61649diff
changeset | 1576 | lemma ceiling_divide_eq_div: "\<lceil>of_int a / of_int b\<rceil> = - (- a div b)" | 
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1577 | by (metis ceiling_def floor_divide_of_int_eq minus_divide_left of_int_minus) | 
| 58097 
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
 hoelzl parents: 
58061diff
changeset | 1578 | |
| 
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
 hoelzl parents: 
58061diff
changeset | 1579 | lemma ceiling_divide_eq_div_numeral [simp]: | 
| 
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
 hoelzl parents: 
58061diff
changeset | 1580 | "\<lceil>numeral a / numeral b :: real\<rceil> = - (- numeral a div numeral b)" | 
| 
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
 hoelzl parents: 
58061diff
changeset | 1581 | using ceiling_divide_eq_div[of "numeral a" "numeral b"] by simp | 
| 
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
 hoelzl parents: 
58061diff
changeset | 1582 | |
| 
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
 hoelzl parents: 
58061diff
changeset | 1583 | lemma ceiling_minus_divide_eq_div_numeral [simp]: | 
| 
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
 hoelzl parents: 
58061diff
changeset | 1584 | "\<lceil>- (numeral a / numeral b :: real)\<rceil> = - (numeral a div numeral b)" | 
| 
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
 hoelzl parents: 
58061diff
changeset | 1585 | using ceiling_divide_eq_div[of "- numeral a" "numeral b"] by simp | 
| 51523 | 1586 | |
| 63353 | 1587 | text \<open> | 
| 1588 | The following lemmas are remnants of the erstwhile functions natfloor | |
| 1589 | and natceiling. | |
| 1590 | \<close> | |
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1591 | |
| 63494 | 1592 | lemma nat_floor_neg: "x \<le> 0 \<Longrightarrow> nat \<lfloor>x\<rfloor> = 0" | 
| 1593 | for x :: real | |
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1594 | by linarith | 
| 51523 | 1595 | |
| 63353 | 1596 | lemma le_nat_floor: "real x \<le> a \<Longrightarrow> x \<le> nat \<lfloor>a\<rfloor>" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1597 | by linarith | 
| 51523 | 1598 | |
| 61942 | 1599 | lemma le_mult_nat_floor: "nat \<lfloor>a\<rfloor> * nat \<lfloor>b\<rfloor> \<le> nat \<lfloor>a * b\<rfloor>" | 
| 63353 | 1600 | by (cases "0 \<le> a \<and> 0 \<le> b") | 
| 59587 
8ea7b22525cb
Removed the obsolete functions "natfloor" and "natceiling"
 nipkow parents: 
59000diff
changeset | 1601 | (auto simp add: nat_mult_distrib[symmetric] nat_mono le_mult_floor) | 
| 51523 | 1602 | |
| 63353 | 1603 | lemma nat_ceiling_le_eq [simp]: "nat \<lceil>x\<rceil> \<le> a \<longleftrightarrow> x \<le> real a" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1604 | by linarith | 
| 51523 | 1605 | |
| 63353 | 1606 | lemma real_nat_ceiling_ge: "x \<le> real (nat \<lceil>x\<rceil>)" | 
| 58040 
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
 hoelzl parents: 
57514diff
changeset | 1607 | by linarith | 
| 51523 | 1608 | |
| 63494 | 1609 | lemma Rats_no_top_le: "\<exists>q \<in> \<rat>. x \<le> q" | 
| 1610 | for x :: real | |
| 61942 | 1611 | by (auto intro!: bexI[of _ "of_nat (nat \<lceil>x\<rceil>)"]) linarith | 
| 57275 
0ddb5b755cdc
moved lemmas from the proof of the Central Limit Theorem by Jeremy Avigad and Luke Serafin
 hoelzl parents: 
56889diff
changeset | 1612 | |
| 63353 | 1613 | lemma Rats_no_bot_less: "\<exists>q \<in> \<rat>. q < x" for x :: real | 
| 68669 | 1614 | by (auto intro!: bexI[of _ "of_int (\<lfloor>x\<rfloor> - 1)"]) linarith | 
| 57447 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57275diff
changeset | 1615 | |
| 63353 | 1616 | |
| 60758 | 1617 | subsection \<open>Exponentiation with floor\<close> | 
| 51523 | 1618 | |
| 1619 | lemma floor_power: | |
| 61942 | 1620 | assumes "x = of_int \<lfloor>x\<rfloor>" | 
| 1621 | shows "\<lfloor>x ^ n\<rfloor> = \<lfloor>x\<rfloor> ^ n" | |
| 51523 | 1622 | proof - | 
| 61942 | 1623 | have "x ^ n = of_int (\<lfloor>x\<rfloor> ^ n)" | 
| 51523 | 1624 | using assms by (induct n arbitrary: x) simp_all | 
| 62626 
de25474ce728
Contractible sets. Also removal of obsolete theorems and refactoring
 paulson <lp15@cam.ac.uk> parents: 
62623diff
changeset | 1625 | then show ?thesis by (metis floor_of_int) | 
| 51523 | 1626 | qed | 
| 61609 
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
 paulson <lp15@cam.ac.uk> parents: 
61284diff
changeset | 1627 | |
| 63353 | 1628 | lemma floor_numeral_power [simp]: "\<lfloor>numeral x ^ n\<rfloor> = numeral x ^ n" | 
| 58983 
9c390032e4eb
cancel real of power of numeral also for equality and strict inequality;
 immler parents: 
58889diff
changeset | 1629 | by (metis floor_of_int of_int_numeral of_int_power) | 
| 
9c390032e4eb
cancel real of power of numeral also for equality and strict inequality;
 immler parents: 
58889diff
changeset | 1630 | |
| 63353 | 1631 | lemma ceiling_numeral_power [simp]: "\<lceil>numeral x ^ n\<rceil> = numeral x ^ n" | 
| 58983 
9c390032e4eb
cancel real of power of numeral also for equality and strict inequality;
 immler parents: 
58889diff
changeset | 1632 | by (metis ceiling_of_int of_int_numeral of_int_power) | 
| 
9c390032e4eb
cancel real of power of numeral also for equality and strict inequality;
 immler parents: 
58889diff
changeset | 1633 | |
| 63353 | 1634 | |
| 60758 | 1635 | subsection \<open>Implementation of rational real numbers\<close> | 
| 51523 | 1636 | |
| 60758 | 1637 | text \<open>Formal constructor\<close> | 
| 51523 | 1638 | |
| 63353 | 1639 | definition Ratreal :: "rat \<Rightarrow> real" | 
| 66155 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1640 | where [code_abbrev, simp]: "Ratreal = real_of_rat" | 
| 51523 | 1641 | |
| 1642 | code_datatype Ratreal | |
| 1643 | ||
| 1644 | ||
| 66155 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1645 | text \<open>Quasi-Numerals\<close> | 
| 51523 | 1646 | |
| 66155 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1647 | lemma [code_abbrev]: | 
| 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1648 | "real_of_rat (numeral k) = numeral k" | 
| 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1649 | "real_of_rat (- numeral k) = - numeral k" | 
| 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1650 | "real_of_rat (rat_of_int a) = real_of_int a" | 
| 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1651 | by simp_all | 
| 51523 | 1652 | |
| 1653 | lemma [code_post]: | |
| 66155 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1654 | "real_of_rat 0 = 0" | 
| 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1655 | "real_of_rat 1 = 1" | 
| 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1656 | "real_of_rat (- 1) = - 1" | 
| 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1657 | "real_of_rat (1 / numeral k) = 1 / numeral k" | 
| 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1658 | "real_of_rat (numeral k / numeral l) = numeral k / numeral l" | 
| 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1659 | "real_of_rat (- (1 / numeral k)) = - (1 / numeral k)" | 
| 
2463cba9f18f
stripped code pre/postprocessor setup for real from superfluous rules
 haftmann parents: 
65885diff
changeset | 1660 | "real_of_rat (- (numeral k / numeral l)) = - (numeral k / numeral l)" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54281diff
changeset | 1661 | by (simp_all add: of_rat_divide of_rat_minus) | 
| 51523 | 1662 | |
| 60758 | 1663 | text \<open>Operations\<close> | 
| 51523 | 1664 | |
| 63353 | 1665 | lemma zero_real_code [code]: "0 = Ratreal 0" | 
| 63494 | 1666 | by simp | 
| 51523 | 1667 | |
| 63353 | 1668 | lemma one_real_code [code]: "1 = Ratreal 1" | 
| 63494 | 1669 | by simp | 
| 51523 | 1670 | |
| 1671 | instantiation real :: equal | |
| 1672 | begin | |
| 1673 | ||
| 63353 | 1674 | definition "HOL.equal x y \<longleftrightarrow> x - y = 0" for x :: real | 
| 51523 | 1675 | |
| 63353 | 1676 | instance by standard (simp add: equal_real_def) | 
| 51523 | 1677 | |
| 63353 | 1678 | lemma real_equal_code [code]: "HOL.equal (Ratreal x) (Ratreal y) \<longleftrightarrow> HOL.equal x y" | 
| 51523 | 1679 | by (simp add: equal_real_def equal) | 
| 1680 | ||
| 63494 | 1681 | lemma [code nbe]: "HOL.equal x x \<longleftrightarrow> True" | 
| 1682 | for x :: real | |
| 51523 | 1683 | by (rule equal_refl) | 
| 1684 | ||
| 1685 | end | |
| 1686 | ||
| 1687 | lemma real_less_eq_code [code]: "Ratreal x \<le> Ratreal y \<longleftrightarrow> x \<le> y" | |
| 1688 | by (simp add: of_rat_less_eq) | |
| 1689 | ||
| 1690 | lemma real_less_code [code]: "Ratreal x < Ratreal y \<longleftrightarrow> x < y" | |
| 1691 | by (simp add: of_rat_less) | |
| 1692 | ||
| 1693 | lemma real_plus_code [code]: "Ratreal x + Ratreal y = Ratreal (x + y)" | |
| 1694 | by (simp add: of_rat_add) | |
| 1695 | ||
| 1696 | lemma real_times_code [code]: "Ratreal x * Ratreal y = Ratreal (x * y)" | |
| 1697 | by (simp add: of_rat_mult) | |
| 1698 | ||
| 1699 | lemma real_uminus_code [code]: "- Ratreal x = Ratreal (- x)" | |
| 1700 | by (simp add: of_rat_minus) | |
| 1701 | ||
| 1702 | lemma real_minus_code [code]: "Ratreal x - Ratreal y = Ratreal (x - y)" | |
| 1703 | by (simp add: of_rat_diff) | |
| 1704 | ||
| 1705 | lemma real_inverse_code [code]: "inverse (Ratreal x) = Ratreal (inverse x)" | |
| 1706 | by (simp add: of_rat_inverse) | |
| 61284 
2314c2f62eb1
real_of_nat_Suc is now a simprule
 paulson <lp15@cam.ac.uk> parents: 
61204diff
changeset | 1707 | |
| 51523 | 1708 | lemma real_divide_code [code]: "Ratreal x / Ratreal y = Ratreal (x / y)" | 
| 1709 | by (simp add: of_rat_divide) | |
| 1710 | ||
| 61942 | 1711 | lemma real_floor_code [code]: "\<lfloor>Ratreal x\<rfloor> = \<lfloor>x\<rfloor>" | 
| 63353 | 1712 | by (metis Ratreal_def floor_le_iff floor_unique le_floor_iff | 
| 1713 | of_int_floor_le of_rat_of_int_eq real_less_eq_code) | |
| 51523 | 1714 | |
| 1715 | ||
| 60758 | 1716 | text \<open>Quickcheck\<close> | 
| 51523 | 1717 | |
| 72607 | 1718 | context | 
| 1719 | includes term_syntax | |
| 1720 | begin | |
| 1721 | ||
| 1722 | definition | |
| 63353 | 1723 | valterm_ratreal :: "rat \<times> (unit \<Rightarrow> Code_Evaluation.term) \<Rightarrow> real \<times> (unit \<Rightarrow> Code_Evaluation.term)" | 
| 1724 |   where [code_unfold]: "valterm_ratreal k = Code_Evaluation.valtermify Ratreal {\<cdot>} k"
 | |
| 51523 | 1725 | |
| 72607 | 1726 | end | 
| 1727 | ||
| 72581 | 1728 | instantiation real :: random | 
| 1729 | begin | |
| 51523 | 1730 | |
| 72581 | 1731 | context | 
| 1732 | includes state_combinator_syntax | |
| 51523 | 1733 | begin | 
| 1734 | ||
| 1735 | definition | |
| 1736 | "Quickcheck_Random.random i = Quickcheck_Random.random i \<circ>\<rightarrow> (\<lambda>r. Pair (valterm_ratreal r))" | |
| 1737 | ||
| 1738 | instance .. | |
| 1739 | ||
| 1740 | end | |
| 1741 | ||
| 72581 | 1742 | end | 
| 51523 | 1743 | |
| 1744 | instantiation real :: exhaustive | |
| 1745 | begin | |
| 1746 | ||
| 1747 | definition | |
| 63353 | 1748 | "exhaustive_real f d = Quickcheck_Exhaustive.exhaustive (\<lambda>r. f (Ratreal r)) d" | 
| 51523 | 1749 | |
| 1750 | instance .. | |
| 1751 | ||
| 1752 | end | |
| 1753 | ||
| 1754 | instantiation real :: full_exhaustive | |
| 1755 | begin | |
| 1756 | ||
| 1757 | definition | |
| 63353 | 1758 | "full_exhaustive_real f d = Quickcheck_Exhaustive.full_exhaustive (\<lambda>r. f (valterm_ratreal r)) d" | 
| 51523 | 1759 | |
| 1760 | instance .. | |
| 1761 | ||
| 1762 | end | |
| 1763 | ||
| 1764 | instantiation real :: narrowing | |
| 1765 | begin | |
| 1766 | ||
| 1767 | definition | |
| 63353 | 1768 | "narrowing_real = Quickcheck_Narrowing.apply (Quickcheck_Narrowing.cons Ratreal) narrowing" | 
| 51523 | 1769 | |
| 1770 | instance .. | |
| 1771 | ||
| 1772 | end | |
| 1773 | ||
| 1774 | ||
| 60758 | 1775 | subsection \<open>Setup for Nitpick\<close> | 
| 51523 | 1776 | |
| 60758 | 1777 | declaration \<open> | 
| 69593 | 1778 | Nitpick_HOL.register_frac_type \<^type_name>\<open>real\<close> | 
| 1779 | [(\<^const_name>\<open>zero_real_inst.zero_real\<close>, \<^const_name>\<open>Nitpick.zero_frac\<close>), | |
| 1780 | (\<^const_name>\<open>one_real_inst.one_real\<close>, \<^const_name>\<open>Nitpick.one_frac\<close>), | |
| 1781 | (\<^const_name>\<open>plus_real_inst.plus_real\<close>, \<^const_name>\<open>Nitpick.plus_frac\<close>), | |
| 1782 | (\<^const_name>\<open>times_real_inst.times_real\<close>, \<^const_name>\<open>Nitpick.times_frac\<close>), | |
| 1783 | (\<^const_name>\<open>uminus_real_inst.uminus_real\<close>, \<^const_name>\<open>Nitpick.uminus_frac\<close>), | |
| 1784 | (\<^const_name>\<open>inverse_real_inst.inverse_real\<close>, \<^const_name>\<open>Nitpick.inverse_frac\<close>), | |
| 1785 | (\<^const_name>\<open>ord_real_inst.less_real\<close>, \<^const_name>\<open>Nitpick.less_frac\<close>), | |
| 1786 | (\<^const_name>\<open>ord_real_inst.less_eq_real\<close>, \<^const_name>\<open>Nitpick.less_eq_frac\<close>)] | |
| 60758 | 1787 | \<close> | 
| 51523 | 1788 | |
| 1789 | lemmas [nitpick_unfold] = inverse_real_inst.inverse_real one_real_inst.one_real | |
| 63353 | 1790 | ord_real_inst.less_real ord_real_inst.less_eq_real plus_real_inst.plus_real | 
| 1791 | times_real_inst.times_real uminus_real_inst.uminus_real | |
| 1792 | zero_real_inst.zero_real | |
| 51523 | 1793 | |
| 56078 
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
 blanchet parents: 
55945diff
changeset | 1794 | |
| 60758 | 1795 | subsection \<open>Setup for SMT\<close> | 
| 56078 
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
 blanchet parents: 
55945diff
changeset | 1796 | |
| 69605 | 1797 | ML_file \<open>Tools/SMT/smt_real.ML\<close> | 
| 1798 | ML_file \<open>Tools/SMT/z3_real.ML\<close> | |
| 56078 
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
 blanchet parents: 
55945diff
changeset | 1799 | |
| 58061 | 1800 | lemma [z3_rule]: | 
| 63353 | 1801 | "0 + x = x" | 
| 56078 
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
 blanchet parents: 
55945diff
changeset | 1802 | "x + 0 = x" | 
| 
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
 blanchet parents: 
55945diff
changeset | 1803 | "0 * x = 0" | 
| 
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
 blanchet parents: 
55945diff
changeset | 1804 | "1 * x = x" | 
| 65885 | 1805 | "-x = -1 * x" | 
| 56078 
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
 blanchet parents: 
55945diff
changeset | 1806 | "x + y = y + x" | 
| 63353 | 1807 | for x y :: real | 
| 56078 
624faeda77b5
moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
 blanchet parents: 
55945diff
changeset | 1808 | by auto | 
| 51523 | 1809 | |
| 72458 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1810 | lemma [smt_arith_multiplication]: | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1811 | fixes A B :: real and p n :: real | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1812 | assumes "A \<le> B" "0 < n" "p > 0" | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1813 | shows "(A / n) * p \<le> (B / n) * p" | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1814 | using assms by (auto simp: field_simps) | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1815 | |
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1816 | lemma [smt_arith_multiplication]: | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1817 | fixes A B :: real and p n :: real | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1818 | assumes "A < B" "0 < n" "p > 0" | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1819 | shows "(A / n) * p < (B / n) * p" | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1820 | using assms by (auto simp: field_simps) | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1821 | |
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1822 | lemma [smt_arith_multiplication]: | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1823 | fixes A B :: real and p n :: int | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1824 | assumes "A \<le> B" "0 < n" "p > 0" | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1825 | shows "(A / n) * p \<le> (B / n) * p" | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1826 | using assms by (auto simp: field_simps) | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1827 | |
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1828 | lemma [smt_arith_multiplication]: | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1829 | fixes A B :: real and p n :: int | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1830 | assumes "A < B" "0 < n" "p > 0" | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1831 | shows "(A / n) * p < (B / n) * p" | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1832 | using assms by (auto simp: field_simps) | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1833 | |
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1834 | lemmas [smt_arith_multiplication] = | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1835 | verit_le_mono_div[THEN mult_left_mono, unfolded int_distrib, of _ _ \<open>nat (floor (_ :: real))\<close> \<open>nat (floor (_ :: real))\<close>] | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1836 | div_le_mono[THEN mult_left_mono, unfolded int_distrib, of _ _ \<open>nat (floor (_ :: real))\<close> \<open>nat (floor (_ :: real))\<close>] | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1837 | verit_le_mono_div_int[THEN mult_left_mono, unfolded int_distrib, of _ _ \<open>floor (_ :: real)\<close> \<open>floor (_ :: real)\<close>] | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1838 | zdiv_mono1[THEN mult_left_mono, unfolded int_distrib, of _ _ \<open>floor (_ :: real)\<close> \<open>floor (_ :: real)\<close>] | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1839 | arg_cong[of _ _ \<open>\<lambda>a :: real. a / real (n::nat) * real (p::nat)\<close> for n p :: nat, THEN sym] | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1840 | arg_cong[of _ _ \<open>\<lambda>a :: real. a / real_of_int n * real_of_int p\<close> for n p :: int, THEN sym] | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1841 | arg_cong[of _ _ \<open>\<lambda>a :: real. a / n * p\<close> for n p :: real, THEN sym] | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1842 | |
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1843 | lemmas [smt_arith_simplify] = | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1844 | floor_one floor_numeral div_by_1 times_divide_eq_right | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1845 | nonzero_mult_div_cancel_left division_ring_divide_zero div_0 | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1846 | divide_minus_left zero_less_divide_iff | 
| 
b44e894796d5
add reconstruction for the SMT solver veriT
 Mathias Fleury <Mathias.Fleury@mpi-inf.mpg.de> parents: 
71043diff
changeset | 1847 | |
| 63960 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 boehmes parents: 
63680diff
changeset | 1848 | |
| 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 boehmes parents: 
63680diff
changeset | 1849 | subsection \<open>Setup for Argo\<close> | 
| 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 boehmes parents: 
63680diff
changeset | 1850 | |
| 69605 | 1851 | ML_file \<open>Tools/Argo/argo_real.ML\<close> | 
| 63960 
3daf02070be5
new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
 boehmes parents: 
63680diff
changeset | 1852 | |
| 51523 | 1853 | end |