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