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