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