| author | wenzelm |
| Fri, 17 Mar 2023 12:10:14 +0100 | |
| changeset 77683 | 3e8e749935fc |
| parent 77490 | 2c86ea8961b5 |
| child 77934 | 01c88cf514fc |
| permissions | -rw-r--r-- |
| 41959 | 1 |
(* Title: HOL/Archimedean_Field.thy |
2 |
Author: Brian Huffman |
|
| 30096 | 3 |
*) |
4 |
||
| 60758 | 5 |
section \<open>Archimedean Fields, Floor and Ceiling Functions\<close> |
| 30096 | 6 |
|
7 |
theory Archimedean_Field |
|
8 |
imports Main |
|
9 |
begin |
|
10 |
||
| 63331 | 11 |
lemma cInf_abs_ge: |
| 63489 | 12 |
fixes S :: "'a::{linordered_idom,conditionally_complete_linorder} set"
|
13 |
assumes "S \<noteq> {}"
|
|
14 |
and bdd: "\<And>x. x\<in>S \<Longrightarrow> \<bar>x\<bar> \<le> a" |
|
| 63331 | 15 |
shows "\<bar>Inf S\<bar> \<le> a" |
16 |
proof - |
|
17 |
have "Sup (uminus ` S) = - (Inf S)" |
|
18 |
proof (rule antisym) |
|
| 63489 | 19 |
show "- (Inf S) \<le> Sup (uminus ` S)" |
| 63331 | 20 |
apply (subst minus_le_iff) |
21 |
apply (rule cInf_greatest [OF \<open>S \<noteq> {}\<close>])
|
|
22 |
apply (subst minus_le_iff) |
|
| 63489 | 23 |
apply (rule cSup_upper) |
24 |
apply force |
|
25 |
using bdd |
|
26 |
apply (force simp: abs_le_iff bdd_above_def) |
|
| 63331 | 27 |
done |
28 |
next |
|
|
70365
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
68721
diff
changeset
|
29 |
have *: "\<And>x. x \<in> S \<Longrightarrow> Inf S \<le> x" |
|
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
68721
diff
changeset
|
30 |
by (meson abs_le_iff bdd bdd_below_def cInf_lower minus_le_iff) |
| 63331 | 31 |
show "Sup (uminus ` S) \<le> - Inf S" |
|
70365
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
68721
diff
changeset
|
32 |
using \<open>S \<noteq> {}\<close> by (force intro: * cSup_least)
|
| 63331 | 33 |
qed |
| 63489 | 34 |
with cSup_abs_le [of "uminus ` S"] assms show ?thesis |
35 |
by fastforce |
|
| 63331 | 36 |
qed |
37 |
||
38 |
lemma cSup_asclose: |
|
| 63489 | 39 |
fixes S :: "'a::{linordered_idom,conditionally_complete_linorder} set"
|
| 63331 | 40 |
assumes S: "S \<noteq> {}"
|
41 |
and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e" |
|
42 |
shows "\<bar>Sup S - l\<bar> \<le> e" |
|
43 |
proof - |
|
| 63489 | 44 |
have *: "\<bar>x - l\<bar> \<le> e \<longleftrightarrow> l - e \<le> x \<and> x \<le> l + e" for x l e :: 'a |
| 63331 | 45 |
by arith |
46 |
have "bdd_above S" |
|
47 |
using b by (auto intro!: bdd_aboveI[of _ "l + e"]) |
|
48 |
with S b show ?thesis |
|
| 63489 | 49 |
unfolding * by (auto intro!: cSup_upper2 cSup_least) |
| 63331 | 50 |
qed |
51 |
||
52 |
lemma cInf_asclose: |
|
| 63489 | 53 |
fixes S :: "'a::{linordered_idom,conditionally_complete_linorder} set"
|
| 63331 | 54 |
assumes S: "S \<noteq> {}"
|
55 |
and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e" |
|
56 |
shows "\<bar>Inf S - l\<bar> \<le> e" |
|
57 |
proof - |
|
| 63489 | 58 |
have *: "\<bar>x - l\<bar> \<le> e \<longleftrightarrow> l - e \<le> x \<and> x \<le> l + e" for x l e :: 'a |
| 63331 | 59 |
by arith |
60 |
have "bdd_below S" |
|
61 |
using b by (auto intro!: bdd_belowI[of _ "l - e"]) |
|
62 |
with S b show ?thesis |
|
| 63489 | 63 |
unfolding * by (auto intro!: cInf_lower2 cInf_greatest) |
| 63331 | 64 |
qed |
65 |
||
| 63489 | 66 |
|
| 60758 | 67 |
subsection \<open>Class of Archimedean fields\<close> |
| 30096 | 68 |
|
| 60758 | 69 |
text \<open>Archimedean fields have no infinite elements.\<close> |
| 30096 | 70 |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
71 |
class archimedean_field = linordered_field + |
| 30096 | 72 |
assumes ex_le_of_int: "\<exists>z. x \<le> of_int z" |
73 |
||
| 63489 | 74 |
lemma ex_less_of_int: "\<exists>z. x < of_int z" |
75 |
for x :: "'a::archimedean_field" |
|
| 30096 | 76 |
proof - |
77 |
from ex_le_of_int obtain z where "x \<le> of_int z" .. |
|
78 |
then have "x < of_int (z + 1)" by simp |
|
79 |
then show ?thesis .. |
|
80 |
qed |
|
81 |
||
| 63489 | 82 |
lemma ex_of_int_less: "\<exists>z. of_int z < x" |
83 |
for x :: "'a::archimedean_field" |
|
| 30096 | 84 |
proof - |
85 |
from ex_less_of_int obtain z where "- x < of_int z" .. |
|
86 |
then have "of_int (- z) < x" by simp |
|
87 |
then show ?thesis .. |
|
88 |
qed |
|
89 |
||
| 63489 | 90 |
lemma reals_Archimedean2: "\<exists>n. x < of_nat n" |
91 |
for x :: "'a::archimedean_field" |
|
| 30096 | 92 |
proof - |
| 63489 | 93 |
obtain z where "x < of_int z" |
94 |
using ex_less_of_int .. |
|
95 |
also have "\<dots> \<le> of_int (int (nat z))" |
|
96 |
by simp |
|
97 |
also have "\<dots> = of_nat (nat z)" |
|
98 |
by (simp only: of_int_of_nat_eq) |
|
| 30096 | 99 |
finally show ?thesis .. |
100 |
qed |
|
101 |
||
| 63489 | 102 |
lemma real_arch_simple: "\<exists>n. x \<le> of_nat n" |
103 |
for x :: "'a::archimedean_field" |
|
| 30096 | 104 |
proof - |
| 63489 | 105 |
obtain n where "x < of_nat n" |
106 |
using reals_Archimedean2 .. |
|
107 |
then have "x \<le> of_nat n" |
|
108 |
by simp |
|
| 30096 | 109 |
then show ?thesis .. |
110 |
qed |
|
111 |
||
| 60758 | 112 |
text \<open>Archimedean fields have no infinitesimal elements.\<close> |
| 30096 | 113 |
|
|
62623
dbc62f86a1a9
rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents:
62348
diff
changeset
|
114 |
lemma reals_Archimedean: |
| 30096 | 115 |
fixes x :: "'a::archimedean_field" |
| 63489 | 116 |
assumes "0 < x" |
117 |
shows "\<exists>n. inverse (of_nat (Suc n)) < x" |
|
| 30096 | 118 |
proof - |
| 60758 | 119 |
from \<open>0 < x\<close> have "0 < inverse x" |
| 30096 | 120 |
by (rule positive_imp_inverse_positive) |
121 |
obtain n where "inverse x < of_nat n" |
|
|
62623
dbc62f86a1a9
rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents:
62348
diff
changeset
|
122 |
using reals_Archimedean2 .. |
| 30096 | 123 |
then obtain m where "inverse x < of_nat (Suc m)" |
| 60758 | 124 |
using \<open>0 < inverse x\<close> by (cases n) (simp_all del: of_nat_Suc) |
| 30096 | 125 |
then have "inverse (of_nat (Suc m)) < inverse (inverse x)" |
| 60758 | 126 |
using \<open>0 < inverse x\<close> by (rule less_imp_inverse_less) |
| 30096 | 127 |
then have "inverse (of_nat (Suc m)) < x" |
| 60758 | 128 |
using \<open>0 < x\<close> by (simp add: nonzero_inverse_inverse_eq) |
| 30096 | 129 |
then show ?thesis .. |
130 |
qed |
|
131 |
||
132 |
lemma ex_inverse_of_nat_less: |
|
133 |
fixes x :: "'a::archimedean_field" |
|
| 63489 | 134 |
assumes "0 < x" |
135 |
shows "\<exists>n>0. inverse (of_nat n) < x" |
|
|
62623
dbc62f86a1a9
rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents:
62348
diff
changeset
|
136 |
using reals_Archimedean [OF \<open>0 < x\<close>] by auto |
| 30096 | 137 |
|
138 |
lemma ex_less_of_nat_mult: |
|
139 |
fixes x :: "'a::archimedean_field" |
|
| 63489 | 140 |
assumes "0 < x" |
141 |
shows "\<exists>n. y < of_nat n * x" |
|
| 30096 | 142 |
proof - |
| 63489 | 143 |
obtain n where "y / x < of_nat n" |
144 |
using reals_Archimedean2 .. |
|
145 |
with \<open>0 < x\<close> have "y < of_nat n * x" |
|
146 |
by (simp add: pos_divide_less_eq) |
|
| 30096 | 147 |
then show ?thesis .. |
148 |
qed |
|
149 |
||
150 |
||
| 60758 | 151 |
subsection \<open>Existence and uniqueness of floor function\<close> |
| 30096 | 152 |
|
153 |
lemma exists_least_lemma: |
|
154 |
assumes "\<not> P 0" and "\<exists>n. P n" |
|
155 |
shows "\<exists>n. \<not> P n \<and> P (Suc n)" |
|
156 |
proof - |
|
| 63489 | 157 |
from \<open>\<exists>n. P n\<close> have "P (Least P)" |
158 |
by (rule LeastI_ex) |
|
| 60758 | 159 |
with \<open>\<not> P 0\<close> obtain n where "Least P = Suc n" |
| 30096 | 160 |
by (cases "Least P") auto |
| 63489 | 161 |
then have "n < Least P" |
162 |
by simp |
|
163 |
then have "\<not> P n" |
|
164 |
by (rule not_less_Least) |
|
| 30096 | 165 |
then have "\<not> P n \<and> P (Suc n)" |
| 60758 | 166 |
using \<open>P (Least P)\<close> \<open>Least P = Suc n\<close> by simp |
| 30096 | 167 |
then show ?thesis .. |
168 |
qed |
|
169 |
||
170 |
lemma floor_exists: |
|
171 |
fixes x :: "'a::archimedean_field" |
|
172 |
shows "\<exists>z. of_int z \<le> x \<and> x < of_int (z + 1)" |
|
| 63489 | 173 |
proof (cases "0 \<le> x") |
174 |
case True |
|
175 |
then have "\<not> x < of_nat 0" |
|
176 |
by simp |
|
| 30096 | 177 |
then have "\<exists>n. \<not> x < of_nat n \<and> x < of_nat (Suc n)" |
|
62623
dbc62f86a1a9
rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents:
62348
diff
changeset
|
178 |
using reals_Archimedean2 by (rule exists_least_lemma) |
| 30096 | 179 |
then obtain n where "\<not> x < of_nat n \<and> x < of_nat (Suc n)" .. |
| 63489 | 180 |
then have "of_int (int n) \<le> x \<and> x < of_int (int n + 1)" |
181 |
by simp |
|
| 30096 | 182 |
then show ?thesis .. |
183 |
next |
|
| 63489 | 184 |
case False |
185 |
then have "\<not> - x \<le> of_nat 0" |
|
186 |
by simp |
|
| 30096 | 187 |
then have "\<exists>n. \<not> - x \<le> of_nat n \<and> - x \<le> of_nat (Suc n)" |
|
62623
dbc62f86a1a9
rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents:
62348
diff
changeset
|
188 |
using real_arch_simple by (rule exists_least_lemma) |
| 30096 | 189 |
then obtain n where "\<not> - x \<le> of_nat n \<and> - x \<le> of_nat (Suc n)" .. |
| 63489 | 190 |
then have "of_int (- int n - 1) \<le> x \<and> x < of_int (- int n - 1 + 1)" |
191 |
by simp |
|
| 30096 | 192 |
then show ?thesis .. |
193 |
qed |
|
194 |
||
| 63489 | 195 |
lemma floor_exists1: "\<exists>!z. of_int z \<le> x \<and> x < of_int (z + 1)" |
196 |
for x :: "'a::archimedean_field" |
|
| 30096 | 197 |
proof (rule ex_ex1I) |
198 |
show "\<exists>z. of_int z \<le> x \<and> x < of_int (z + 1)" |
|
199 |
by (rule floor_exists) |
|
200 |
next |
|
| 63489 | 201 |
fix y z |
202 |
assume "of_int y \<le> x \<and> x < of_int (y + 1)" |
|
203 |
and "of_int z \<le> x \<and> x < of_int (z + 1)" |
|
| 54281 | 204 |
with le_less_trans [of "of_int y" "x" "of_int (z + 1)"] |
| 63489 | 205 |
le_less_trans [of "of_int z" "x" "of_int (y + 1)"] show "y = z" |
206 |
by (simp del: of_int_add) |
|
| 30096 | 207 |
qed |
208 |
||
209 |
||
| 60758 | 210 |
subsection \<open>Floor function\<close> |
| 30096 | 211 |
|
|
43732
6b2bdc57155b
adding a floor_ceiling type class for different instantiations of floor (changeset from Brian Huffman)
bulwahn
parents:
43704
diff
changeset
|
212 |
class floor_ceiling = archimedean_field + |
| 61942 | 213 |
fixes floor :: "'a \<Rightarrow> int" ("\<lfloor>_\<rfloor>")
|
214 |
assumes floor_correct: "of_int \<lfloor>x\<rfloor> \<le> x \<and> x < of_int (\<lfloor>x\<rfloor> + 1)" |
|
| 30096 | 215 |
|
| 63489 | 216 |
lemma floor_unique: "of_int z \<le> x \<Longrightarrow> x < of_int z + 1 \<Longrightarrow> \<lfloor>x\<rfloor> = z" |
| 30096 | 217 |
using floor_correct [of x] floor_exists1 [of x] by auto |
218 |
||
| 66515 | 219 |
lemma floor_eq_iff: "\<lfloor>x\<rfloor> = a \<longleftrightarrow> of_int a \<le> x \<and> x < of_int a + 1" |
220 |
using floor_correct floor_unique by auto |
|
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
221 |
|
| 61942 | 222 |
lemma of_int_floor_le [simp]: "of_int \<lfloor>x\<rfloor> \<le> x" |
| 30096 | 223 |
using floor_correct .. |
224 |
||
| 61942 | 225 |
lemma le_floor_iff: "z \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> of_int z \<le> x" |
| 30096 | 226 |
proof |
| 61942 | 227 |
assume "z \<le> \<lfloor>x\<rfloor>" |
228 |
then have "(of_int z :: 'a) \<le> of_int \<lfloor>x\<rfloor>" by simp |
|
229 |
also have "of_int \<lfloor>x\<rfloor> \<le> x" by (rule of_int_floor_le) |
|
| 30096 | 230 |
finally show "of_int z \<le> x" . |
231 |
next |
|
232 |
assume "of_int z \<le> x" |
|
| 61942 | 233 |
also have "x < of_int (\<lfloor>x\<rfloor> + 1)" using floor_correct .. |
234 |
finally show "z \<le> \<lfloor>x\<rfloor>" by (simp del: of_int_add) |
|
| 30096 | 235 |
qed |
236 |
||
| 61942 | 237 |
lemma floor_less_iff: "\<lfloor>x\<rfloor> < z \<longleftrightarrow> x < of_int z" |
| 30096 | 238 |
by (simp add: not_le [symmetric] le_floor_iff) |
239 |
||
| 61942 | 240 |
lemma less_floor_iff: "z < \<lfloor>x\<rfloor> \<longleftrightarrow> of_int z + 1 \<le> x" |
| 30096 | 241 |
using le_floor_iff [of "z + 1" x] by auto |
242 |
||
| 61942 | 243 |
lemma floor_le_iff: "\<lfloor>x\<rfloor> \<le> z \<longleftrightarrow> x < of_int z + 1" |
| 30096 | 244 |
by (simp add: not_less [symmetric] less_floor_iff) |
245 |
||
| 75878 | 246 |
lemma floor_split[linarith_split]: "P \<lfloor>t\<rfloor> \<longleftrightarrow> (\<forall>i. of_int i \<le> t \<and> t < of_int i + 1 \<longrightarrow> P i)" |
|
58040
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents:
54489
diff
changeset
|
247 |
by (metis floor_correct floor_unique less_floor_iff not_le order_refl) |
|
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents:
54489
diff
changeset
|
248 |
|
| 61942 | 249 |
lemma floor_mono: |
250 |
assumes "x \<le> y" |
|
251 |
shows "\<lfloor>x\<rfloor> \<le> \<lfloor>y\<rfloor>" |
|
| 30096 | 252 |
proof - |
| 61942 | 253 |
have "of_int \<lfloor>x\<rfloor> \<le> x" by (rule of_int_floor_le) |
| 60758 | 254 |
also note \<open>x \<le> y\<close> |
| 30096 | 255 |
finally show ?thesis by (simp add: le_floor_iff) |
256 |
qed |
|
257 |
||
| 61942 | 258 |
lemma floor_less_cancel: "\<lfloor>x\<rfloor> < \<lfloor>y\<rfloor> \<Longrightarrow> x < y" |
| 30096 | 259 |
by (auto simp add: not_le [symmetric] floor_mono) |
260 |
||
| 61942 | 261 |
lemma floor_of_int [simp]: "\<lfloor>of_int z\<rfloor> = z" |
| 30096 | 262 |
by (rule floor_unique) simp_all |
263 |
||
| 61942 | 264 |
lemma floor_of_nat [simp]: "\<lfloor>of_nat n\<rfloor> = int n" |
| 30096 | 265 |
using floor_of_int [of "of_nat n"] by simp |
266 |
||
| 61942 | 267 |
lemma le_floor_add: "\<lfloor>x\<rfloor> + \<lfloor>y\<rfloor> \<le> \<lfloor>x + y\<rfloor>" |
|
47307
5e5ca36692b3
add floor/ceiling lemmas suggested by René Thiemann
huffman
parents:
47108
diff
changeset
|
268 |
by (simp only: le_floor_iff of_int_add add_mono of_int_floor_le) |
|
5e5ca36692b3
add floor/ceiling lemmas suggested by René Thiemann
huffman
parents:
47108
diff
changeset
|
269 |
|
| 63489 | 270 |
|
271 |
text \<open>Floor with numerals.\<close> |
|
| 30096 | 272 |
|
| 61942 | 273 |
lemma floor_zero [simp]: "\<lfloor>0\<rfloor> = 0" |
| 30096 | 274 |
using floor_of_int [of 0] by simp |
275 |
||
| 61942 | 276 |
lemma floor_one [simp]: "\<lfloor>1\<rfloor> = 1" |
| 30096 | 277 |
using floor_of_int [of 1] by simp |
278 |
||
| 61942 | 279 |
lemma floor_numeral [simp]: "\<lfloor>numeral v\<rfloor> = numeral v" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
280 |
using floor_of_int [of "numeral v"] by simp |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
281 |
|
| 61942 | 282 |
lemma floor_neg_numeral [simp]: "\<lfloor>- numeral v\<rfloor> = - numeral v" |
|
54489
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54281
diff
changeset
|
283 |
using floor_of_int [of "- numeral v"] by simp |
| 30096 | 284 |
|
| 61942 | 285 |
lemma zero_le_floor [simp]: "0 \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> 0 \<le> x" |
| 30096 | 286 |
by (simp add: le_floor_iff) |
287 |
||
| 61942 | 288 |
lemma one_le_floor [simp]: "1 \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> 1 \<le> x" |
| 30096 | 289 |
by (simp add: le_floor_iff) |
290 |
||
| 63489 | 291 |
lemma numeral_le_floor [simp]: "numeral v \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> numeral v \<le> x" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
292 |
by (simp add: le_floor_iff) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
293 |
|
| 63489 | 294 |
lemma neg_numeral_le_floor [simp]: "- numeral v \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> - numeral v \<le> x" |
| 30096 | 295 |
by (simp add: le_floor_iff) |
296 |
||
| 61942 | 297 |
lemma zero_less_floor [simp]: "0 < \<lfloor>x\<rfloor> \<longleftrightarrow> 1 \<le> x" |
| 30096 | 298 |
by (simp add: less_floor_iff) |
299 |
||
| 61942 | 300 |
lemma one_less_floor [simp]: "1 < \<lfloor>x\<rfloor> \<longleftrightarrow> 2 \<le> x" |
| 30096 | 301 |
by (simp add: less_floor_iff) |
302 |
||
| 63489 | 303 |
lemma numeral_less_floor [simp]: "numeral v < \<lfloor>x\<rfloor> \<longleftrightarrow> numeral v + 1 \<le> x" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
304 |
by (simp add: less_floor_iff) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
305 |
|
| 63489 | 306 |
lemma neg_numeral_less_floor [simp]: "- numeral v < \<lfloor>x\<rfloor> \<longleftrightarrow> - numeral v + 1 \<le> x" |
| 30096 | 307 |
by (simp add: less_floor_iff) |
308 |
||
| 61942 | 309 |
lemma floor_le_zero [simp]: "\<lfloor>x\<rfloor> \<le> 0 \<longleftrightarrow> x < 1" |
| 30096 | 310 |
by (simp add: floor_le_iff) |
311 |
||
| 61942 | 312 |
lemma floor_le_one [simp]: "\<lfloor>x\<rfloor> \<le> 1 \<longleftrightarrow> x < 2" |
| 30096 | 313 |
by (simp add: floor_le_iff) |
314 |
||
| 63489 | 315 |
lemma floor_le_numeral [simp]: "\<lfloor>x\<rfloor> \<le> numeral v \<longleftrightarrow> x < numeral v + 1" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
316 |
by (simp add: floor_le_iff) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
317 |
|
| 63489 | 318 |
lemma floor_le_neg_numeral [simp]: "\<lfloor>x\<rfloor> \<le> - numeral v \<longleftrightarrow> x < - numeral v + 1" |
| 30096 | 319 |
by (simp add: floor_le_iff) |
320 |
||
| 61942 | 321 |
lemma floor_less_zero [simp]: "\<lfloor>x\<rfloor> < 0 \<longleftrightarrow> x < 0" |
| 30096 | 322 |
by (simp add: floor_less_iff) |
323 |
||
| 61942 | 324 |
lemma floor_less_one [simp]: "\<lfloor>x\<rfloor> < 1 \<longleftrightarrow> x < 1" |
| 30096 | 325 |
by (simp add: floor_less_iff) |
326 |
||
| 63489 | 327 |
lemma floor_less_numeral [simp]: "\<lfloor>x\<rfloor> < numeral v \<longleftrightarrow> x < numeral v" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
328 |
by (simp add: floor_less_iff) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
329 |
|
| 63489 | 330 |
lemma floor_less_neg_numeral [simp]: "\<lfloor>x\<rfloor> < - numeral v \<longleftrightarrow> x < - numeral v" |
| 30096 | 331 |
by (simp add: floor_less_iff) |
332 |
||
|
66154
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
333 |
lemma le_mult_floor_Ints: |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
334 |
assumes "0 \<le> a" "a \<in> Ints" |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
335 |
shows "of_int (\<lfloor>a\<rfloor> * \<lfloor>b\<rfloor>) \<le> (of_int\<lfloor>a * b\<rfloor> :: 'a :: linordered_idom)" |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
336 |
by (metis Ints_cases assms floor_less_iff floor_of_int linorder_not_less mult_left_mono of_int_floor_le of_int_less_iff of_int_mult) |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
337 |
|
| 63489 | 338 |
|
339 |
text \<open>Addition and subtraction of integers.\<close> |
|
| 30096 | 340 |
|
| 63599 | 341 |
lemma floor_add_int: "\<lfloor>x\<rfloor> + z = \<lfloor>x + of_int z\<rfloor>" |
342 |
using floor_correct [of x] by (simp add: floor_unique[symmetric]) |
|
| 30096 | 343 |
|
| 63599 | 344 |
lemma int_add_floor: "z + \<lfloor>x\<rfloor> = \<lfloor>of_int z + x\<rfloor>" |
345 |
using floor_correct [of x] by (simp add: floor_unique[symmetric]) |
|
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
346 |
|
| 63599 | 347 |
lemma one_add_floor: "\<lfloor>x\<rfloor> + 1 = \<lfloor>x + 1\<rfloor>" |
348 |
using floor_add_int [of x 1] by simp |
|
| 30096 | 349 |
|
| 61942 | 350 |
lemma floor_diff_of_int [simp]: "\<lfloor>x - of_int z\<rfloor> = \<lfloor>x\<rfloor> - z" |
| 63599 | 351 |
using floor_add_int [of x "- z"] by (simp add: algebra_simps) |
| 30096 | 352 |
|
| 61942 | 353 |
lemma floor_uminus_of_int [simp]: "\<lfloor>- (of_int z)\<rfloor> = - z" |
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
354 |
by (metis floor_diff_of_int [of 0] diff_0 floor_zero) |
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
355 |
|
| 63489 | 356 |
lemma floor_diff_numeral [simp]: "\<lfloor>x - numeral v\<rfloor> = \<lfloor>x\<rfloor> - numeral v" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
357 |
using floor_diff_of_int [of x "numeral v"] by simp |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
358 |
|
| 61942 | 359 |
lemma floor_diff_one [simp]: "\<lfloor>x - 1\<rfloor> = \<lfloor>x\<rfloor> - 1" |
| 30096 | 360 |
using floor_diff_of_int [of x 1] by simp |
361 |
||
|
58097
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents:
58040
diff
changeset
|
362 |
lemma le_mult_floor: |
|
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents:
58040
diff
changeset
|
363 |
assumes "0 \<le> a" and "0 \<le> b" |
| 61942 | 364 |
shows "\<lfloor>a\<rfloor> * \<lfloor>b\<rfloor> \<le> \<lfloor>a * b\<rfloor>" |
|
58097
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents:
58040
diff
changeset
|
365 |
proof - |
| 63489 | 366 |
have "of_int \<lfloor>a\<rfloor> \<le> a" and "of_int \<lfloor>b\<rfloor> \<le> b" |
367 |
by (auto intro: of_int_floor_le) |
|
368 |
then have "of_int (\<lfloor>a\<rfloor> * \<lfloor>b\<rfloor>) \<le> a * b" |
|
|
58097
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents:
58040
diff
changeset
|
369 |
using assms by (auto intro!: mult_mono) |
| 61942 | 370 |
also have "a * b < of_int (\<lfloor>a * b\<rfloor> + 1)" |
|
58097
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents:
58040
diff
changeset
|
371 |
using floor_correct[of "a * b"] by auto |
| 63489 | 372 |
finally show ?thesis |
373 |
unfolding of_int_less_iff by simp |
|
|
58097
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents:
58040
diff
changeset
|
374 |
qed |
|
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents:
58040
diff
changeset
|
375 |
|
| 63489 | 376 |
lemma floor_divide_of_int_eq: "\<lfloor>of_int k / of_int l\<rfloor> = k div l" |
377 |
for k l :: int |
|
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
378 |
proof (cases "l = 0") |
| 63489 | 379 |
case True |
380 |
then show ?thesis by simp |
|
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
381 |
next |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
382 |
case False |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
383 |
have *: "\<lfloor>of_int (k mod l) / of_int l :: 'a\<rfloor> = 0" |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
384 |
proof (cases "l > 0") |
| 63489 | 385 |
case True |
386 |
then show ?thesis |
|
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
387 |
by (auto intro: floor_unique) |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
388 |
next |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
389 |
case False |
| 63489 | 390 |
obtain r where "r = - l" |
391 |
by blast |
|
392 |
then have l: "l = - r" |
|
393 |
by simp |
|
| 63540 | 394 |
with \<open>l \<noteq> 0\<close> False have "r > 0" |
| 63489 | 395 |
by simp |
| 63540 | 396 |
with l show ?thesis |
| 63489 | 397 |
using pos_mod_bound [of r] |
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
398 |
by (auto simp add: zmod_zminus2_eq_if less_le field_simps intro: floor_unique) |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
399 |
qed |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
400 |
have "(of_int k :: 'a) = of_int (k div l * l + k mod l)" |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
401 |
by simp |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
402 |
also have "\<dots> = (of_int (k div l) + of_int (k mod l) / of_int l) * of_int l" |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
403 |
using False by (simp only: of_int_add) (simp add: field_simps) |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
404 |
finally have "(of_int k / of_int l :: 'a) = \<dots> / of_int l" |
| 63331 | 405 |
by simp |
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
406 |
then have "(of_int k / of_int l :: 'a) = of_int (k div l) + of_int (k mod l) / of_int l" |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
407 |
using False by (simp only:) (simp add: field_simps) |
| 63331 | 408 |
then have "\<lfloor>of_int k / of_int l :: 'a\<rfloor> = \<lfloor>of_int (k div l) + of_int (k mod l) / of_int l :: 'a\<rfloor>" |
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
409 |
by simp |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
410 |
then have "\<lfloor>of_int k / of_int l :: 'a\<rfloor> = \<lfloor>of_int (k mod l) / of_int l + of_int (k div l) :: 'a\<rfloor>" |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
411 |
by (simp add: ac_simps) |
| 60128 | 412 |
then have "\<lfloor>of_int k / of_int l :: 'a\<rfloor> = \<lfloor>of_int (k mod l) / of_int l :: 'a\<rfloor> + k div l" |
| 63599 | 413 |
by (simp add: floor_add_int) |
| 63489 | 414 |
with * show ?thesis |
415 |
by simp |
|
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
416 |
qed |
|
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
417 |
|
| 63489 | 418 |
lemma floor_divide_of_nat_eq: "\<lfloor>of_nat m / of_nat n\<rfloor> = of_nat (m div n)" |
419 |
for m n :: nat |
|
|
77490
2c86ea8961b5
Some new lemmas. Some tidying up
paulson <lp15@cam.ac.uk>
parents:
75878
diff
changeset
|
420 |
by (metis floor_divide_of_int_eq of_int_of_nat_eq unique_euclidean_semiring_with_nat_class.of_nat_div) |
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
421 |
|
|
68499
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
422 |
lemma floor_divide_lower: |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
423 |
fixes q :: "'a::floor_ceiling" |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
424 |
shows "q > 0 \<Longrightarrow> of_int \<lfloor>p / q\<rfloor> * q \<le> p" |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
425 |
using of_int_floor_le pos_le_divide_eq by blast |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
426 |
|
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
427 |
lemma floor_divide_upper: |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
428 |
fixes q :: "'a::floor_ceiling" |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
429 |
shows "q > 0 \<Longrightarrow> p < (of_int \<lfloor>p / q\<rfloor> + 1) * q" |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
430 |
by (meson floor_eq_iff pos_divide_less_eq) |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
431 |
|
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
432 |
|
| 60758 | 433 |
subsection \<open>Ceiling function\<close> |
| 30096 | 434 |
|
| 61942 | 435 |
definition ceiling :: "'a::floor_ceiling \<Rightarrow> int" ("\<lceil>_\<rceil>")
|
436 |
where "\<lceil>x\<rceil> = - \<lfloor>- x\<rfloor>" |
|
| 30096 | 437 |
|
| 61942 | 438 |
lemma ceiling_correct: "of_int \<lceil>x\<rceil> - 1 < x \<and> x \<le> of_int \<lceil>x\<rceil>" |
| 63489 | 439 |
unfolding ceiling_def using floor_correct [of "- x"] |
440 |
by (simp add: le_minus_iff) |
|
| 30096 | 441 |
|
| 63489 | 442 |
lemma ceiling_unique: "of_int z - 1 < x \<Longrightarrow> x \<le> of_int z \<Longrightarrow> \<lceil>x\<rceil> = z" |
| 30096 | 443 |
unfolding ceiling_def using floor_unique [of "- z" "- x"] by simp |
444 |
||
| 66515 | 445 |
lemma ceiling_eq_iff: "\<lceil>x\<rceil> = a \<longleftrightarrow> of_int a - 1 < x \<and> x \<le> of_int a" |
446 |
using ceiling_correct ceiling_unique by auto |
|
447 |
||
| 61942 | 448 |
lemma le_of_int_ceiling [simp]: "x \<le> of_int \<lceil>x\<rceil>" |
| 30096 | 449 |
using ceiling_correct .. |
450 |
||
| 61942 | 451 |
lemma ceiling_le_iff: "\<lceil>x\<rceil> \<le> z \<longleftrightarrow> x \<le> of_int z" |
| 30096 | 452 |
unfolding ceiling_def using le_floor_iff [of "- z" "- x"] by auto |
453 |
||
| 61942 | 454 |
lemma less_ceiling_iff: "z < \<lceil>x\<rceil> \<longleftrightarrow> of_int z < x" |
| 30096 | 455 |
by (simp add: not_le [symmetric] ceiling_le_iff) |
456 |
||
| 61942 | 457 |
lemma ceiling_less_iff: "\<lceil>x\<rceil> < z \<longleftrightarrow> x \<le> of_int z - 1" |
| 30096 | 458 |
using ceiling_le_iff [of x "z - 1"] by simp |
459 |
||
| 61942 | 460 |
lemma le_ceiling_iff: "z \<le> \<lceil>x\<rceil> \<longleftrightarrow> of_int z - 1 < x" |
| 30096 | 461 |
by (simp add: not_less [symmetric] ceiling_less_iff) |
462 |
||
| 61942 | 463 |
lemma ceiling_mono: "x \<ge> y \<Longrightarrow> \<lceil>x\<rceil> \<ge> \<lceil>y\<rceil>" |
| 30096 | 464 |
unfolding ceiling_def by (simp add: floor_mono) |
465 |
||
| 61942 | 466 |
lemma ceiling_less_cancel: "\<lceil>x\<rceil> < \<lceil>y\<rceil> \<Longrightarrow> x < y" |
| 30096 | 467 |
by (auto simp add: not_le [symmetric] ceiling_mono) |
468 |
||
| 61942 | 469 |
lemma ceiling_of_int [simp]: "\<lceil>of_int z\<rceil> = z" |
| 30096 | 470 |
by (rule ceiling_unique) simp_all |
471 |
||
| 61942 | 472 |
lemma ceiling_of_nat [simp]: "\<lceil>of_nat n\<rceil> = int n" |
| 30096 | 473 |
using ceiling_of_int [of "of_nat n"] by simp |
474 |
||
| 61942 | 475 |
lemma ceiling_add_le: "\<lceil>x + y\<rceil> \<le> \<lceil>x\<rceil> + \<lceil>y\<rceil>" |
|
47307
5e5ca36692b3
add floor/ceiling lemmas suggested by René Thiemann
huffman
parents:
47108
diff
changeset
|
476 |
by (simp only: ceiling_le_iff of_int_add add_mono le_of_int_ceiling) |
|
5e5ca36692b3
add floor/ceiling lemmas suggested by René Thiemann
huffman
parents:
47108
diff
changeset
|
477 |
|
|
66154
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
478 |
lemma mult_ceiling_le: |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
479 |
assumes "0 \<le> a" and "0 \<le> b" |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
480 |
shows "\<lceil>a * b\<rceil> \<le> \<lceil>a\<rceil> * \<lceil>b\<rceil>" |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
481 |
by (metis assms ceiling_le_iff ceiling_mono le_of_int_ceiling mult_mono of_int_mult) |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
482 |
|
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
483 |
lemma mult_ceiling_le_Ints: |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
484 |
assumes "0 \<le> a" "a \<in> Ints" |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
485 |
shows "(of_int \<lceil>a * b\<rceil> :: 'a :: linordered_idom) \<le> of_int(\<lceil>a\<rceil> * \<lceil>b\<rceil>)" |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
486 |
by (metis Ints_cases assms ceiling_le_iff ceiling_of_int le_of_int_ceiling mult_left_mono of_int_le_iff of_int_mult) |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
487 |
|
|
63879
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
488 |
lemma finite_int_segment: |
|
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
489 |
fixes a :: "'a::floor_ceiling" |
|
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
490 |
shows "finite {x \<in> \<int>. a \<le> x \<and> x \<le> b}"
|
|
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
491 |
proof - |
|
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
492 |
have "finite {ceiling a..floor b}"
|
|
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
493 |
by simp |
|
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
494 |
moreover have "{x \<in> \<int>. a \<le> x \<and> x \<le> b} = of_int ` {ceiling a..floor b}"
|
|
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
495 |
by (auto simp: le_floor_iff ceiling_le_iff elim!: Ints_cases) |
|
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
496 |
ultimately show ?thesis |
|
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
497 |
by simp |
|
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
498 |
qed |
|
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
499 |
|
|
66154
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
500 |
corollary finite_abs_int_segment: |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
501 |
fixes a :: "'a::floor_ceiling" |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
502 |
shows "finite {k \<in> \<int>. \<bar>k\<bar> \<le> a}"
|
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
503 |
using finite_int_segment [of "-a" a] by (auto simp add: abs_le_iff conj_commute minus_le_iff) |
| 63489 | 504 |
|
|
66793
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
505 |
|
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
506 |
subsubsection \<open>Ceiling with numerals.\<close> |
| 30096 | 507 |
|
| 61942 | 508 |
lemma ceiling_zero [simp]: "\<lceil>0\<rceil> = 0" |
| 30096 | 509 |
using ceiling_of_int [of 0] by simp |
510 |
||
| 61942 | 511 |
lemma ceiling_one [simp]: "\<lceil>1\<rceil> = 1" |
| 30096 | 512 |
using ceiling_of_int [of 1] by simp |
513 |
||
| 61942 | 514 |
lemma ceiling_numeral [simp]: "\<lceil>numeral v\<rceil> = numeral v" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
515 |
using ceiling_of_int [of "numeral v"] by simp |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
516 |
|
| 61942 | 517 |
lemma ceiling_neg_numeral [simp]: "\<lceil>- numeral v\<rceil> = - numeral v" |
|
54489
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents:
54281
diff
changeset
|
518 |
using ceiling_of_int [of "- numeral v"] by simp |
| 30096 | 519 |
|
| 61942 | 520 |
lemma ceiling_le_zero [simp]: "\<lceil>x\<rceil> \<le> 0 \<longleftrightarrow> x \<le> 0" |
| 30096 | 521 |
by (simp add: ceiling_le_iff) |
522 |
||
| 61942 | 523 |
lemma ceiling_le_one [simp]: "\<lceil>x\<rceil> \<le> 1 \<longleftrightarrow> x \<le> 1" |
| 30096 | 524 |
by (simp add: ceiling_le_iff) |
525 |
||
| 63489 | 526 |
lemma ceiling_le_numeral [simp]: "\<lceil>x\<rceil> \<le> numeral v \<longleftrightarrow> x \<le> numeral v" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
527 |
by (simp add: ceiling_le_iff) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
528 |
|
| 63489 | 529 |
lemma ceiling_le_neg_numeral [simp]: "\<lceil>x\<rceil> \<le> - numeral v \<longleftrightarrow> x \<le> - numeral v" |
| 30096 | 530 |
by (simp add: ceiling_le_iff) |
531 |
||
| 61942 | 532 |
lemma ceiling_less_zero [simp]: "\<lceil>x\<rceil> < 0 \<longleftrightarrow> x \<le> -1" |
| 30096 | 533 |
by (simp add: ceiling_less_iff) |
534 |
||
| 61942 | 535 |
lemma ceiling_less_one [simp]: "\<lceil>x\<rceil> < 1 \<longleftrightarrow> x \<le> 0" |
| 30096 | 536 |
by (simp add: ceiling_less_iff) |
537 |
||
| 63489 | 538 |
lemma ceiling_less_numeral [simp]: "\<lceil>x\<rceil> < numeral v \<longleftrightarrow> x \<le> numeral v - 1" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
539 |
by (simp add: ceiling_less_iff) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
540 |
|
| 63489 | 541 |
lemma ceiling_less_neg_numeral [simp]: "\<lceil>x\<rceil> < - numeral v \<longleftrightarrow> x \<le> - numeral v - 1" |
| 30096 | 542 |
by (simp add: ceiling_less_iff) |
543 |
||
| 61942 | 544 |
lemma zero_le_ceiling [simp]: "0 \<le> \<lceil>x\<rceil> \<longleftrightarrow> -1 < x" |
| 30096 | 545 |
by (simp add: le_ceiling_iff) |
546 |
||
| 61942 | 547 |
lemma one_le_ceiling [simp]: "1 \<le> \<lceil>x\<rceil> \<longleftrightarrow> 0 < x" |
| 30096 | 548 |
by (simp add: le_ceiling_iff) |
549 |
||
| 63489 | 550 |
lemma numeral_le_ceiling [simp]: "numeral v \<le> \<lceil>x\<rceil> \<longleftrightarrow> numeral v - 1 < x" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
551 |
by (simp add: le_ceiling_iff) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
552 |
|
| 63489 | 553 |
lemma neg_numeral_le_ceiling [simp]: "- numeral v \<le> \<lceil>x\<rceil> \<longleftrightarrow> - numeral v - 1 < x" |
| 30096 | 554 |
by (simp add: le_ceiling_iff) |
555 |
||
| 61942 | 556 |
lemma zero_less_ceiling [simp]: "0 < \<lceil>x\<rceil> \<longleftrightarrow> 0 < x" |
| 30096 | 557 |
by (simp add: less_ceiling_iff) |
558 |
||
| 61942 | 559 |
lemma one_less_ceiling [simp]: "1 < \<lceil>x\<rceil> \<longleftrightarrow> 1 < x" |
| 30096 | 560 |
by (simp add: less_ceiling_iff) |
561 |
||
| 63489 | 562 |
lemma numeral_less_ceiling [simp]: "numeral v < \<lceil>x\<rceil> \<longleftrightarrow> numeral v < x" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
563 |
by (simp add: less_ceiling_iff) |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
564 |
|
| 63489 | 565 |
lemma neg_numeral_less_ceiling [simp]: "- numeral v < \<lceil>x\<rceil> \<longleftrightarrow> - numeral v < x" |
| 30096 | 566 |
by (simp add: less_ceiling_iff) |
567 |
||
| 61942 | 568 |
lemma ceiling_altdef: "\<lceil>x\<rceil> = (if x = of_int \<lfloor>x\<rfloor> then \<lfloor>x\<rfloor> else \<lfloor>x\<rfloor> + 1)" |
| 63489 | 569 |
by (intro ceiling_unique; simp, linarith?) |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
570 |
|
| 61942 | 571 |
lemma floor_le_ceiling [simp]: "\<lfloor>x\<rfloor> \<le> \<lceil>x\<rceil>" |
572 |
by (simp add: ceiling_altdef) |
|
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
573 |
|
| 63489 | 574 |
|
|
66793
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
575 |
subsubsection \<open>Addition and subtraction of integers.\<close> |
| 30096 | 576 |
|
| 61942 | 577 |
lemma ceiling_add_of_int [simp]: "\<lceil>x + of_int z\<rceil> = \<lceil>x\<rceil> + z" |
|
61649
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents:
61531
diff
changeset
|
578 |
using ceiling_correct [of x] by (simp add: ceiling_def) |
| 30096 | 579 |
|
| 61942 | 580 |
lemma ceiling_add_numeral [simp]: "\<lceil>x + numeral v\<rceil> = \<lceil>x\<rceil> + numeral v" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
581 |
using ceiling_add_of_int [of x "numeral v"] by simp |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
582 |
|
| 61942 | 583 |
lemma ceiling_add_one [simp]: "\<lceil>x + 1\<rceil> = \<lceil>x\<rceil> + 1" |
| 30096 | 584 |
using ceiling_add_of_int [of x 1] by simp |
585 |
||
| 61942 | 586 |
lemma ceiling_diff_of_int [simp]: "\<lceil>x - of_int z\<rceil> = \<lceil>x\<rceil> - z" |
| 30096 | 587 |
using ceiling_add_of_int [of x "- z"] by (simp add: algebra_simps) |
588 |
||
| 61942 | 589 |
lemma ceiling_diff_numeral [simp]: "\<lceil>x - numeral v\<rceil> = \<lceil>x\<rceil> - numeral v" |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
590 |
using ceiling_diff_of_int [of x "numeral v"] by simp |
|
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
591 |
|
| 61942 | 592 |
lemma ceiling_diff_one [simp]: "\<lceil>x - 1\<rceil> = \<lceil>x\<rceil> - 1" |
| 30096 | 593 |
using ceiling_diff_of_int [of x 1] by simp |
594 |
||
| 75878 | 595 |
lemma ceiling_split[linarith_split]: "P \<lceil>t\<rceil> \<longleftrightarrow> (\<forall>i. of_int i - 1 < t \<and> t \<le> of_int i \<longrightarrow> P i)" |
|
58040
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents:
54489
diff
changeset
|
596 |
by (auto simp add: ceiling_unique ceiling_correct) |
|
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents:
54489
diff
changeset
|
597 |
|
| 61942 | 598 |
lemma ceiling_diff_floor_le_1: "\<lceil>x\<rceil> - \<lfloor>x\<rfloor> \<le> 1" |
| 47592 | 599 |
proof - |
| 63331 | 600 |
have "of_int \<lceil>x\<rceil> - 1 < x" |
| 47592 | 601 |
using ceiling_correct[of x] by simp |
602 |
also have "x < of_int \<lfloor>x\<rfloor> + 1" |
|
603 |
using floor_correct[of x] by simp_all |
|
604 |
finally have "of_int (\<lceil>x\<rceil> - \<lfloor>x\<rfloor>) < (of_int 2::'a)" |
|
605 |
by simp |
|
606 |
then show ?thesis |
|
607 |
unfolding of_int_less_iff by simp |
|
608 |
qed |
|
| 30096 | 609 |
|
|
66793
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
610 |
lemma nat_approx_posE: |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
611 |
fixes e:: "'a::{archimedean_field,floor_ceiling}"
|
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
612 |
assumes "0 < e" |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
613 |
obtains n :: nat where "1 / of_nat(Suc n) < e" |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
614 |
proof |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
615 |
have "(1::'a) / of_nat (Suc (nat \<lceil>1/e\<rceil>)) < 1 / of_int (\<lceil>1/e\<rceil>)" |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
616 |
proof (rule divide_strict_left_mono) |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
617 |
show "(of_int \<lceil>1 / e\<rceil>::'a) < of_nat (Suc (nat \<lceil>1 / e\<rceil>))" |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
618 |
using assms by (simp add: field_simps) |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
619 |
show "(0::'a) < of_nat (Suc (nat \<lceil>1 / e\<rceil>)) * of_int \<lceil>1 / e\<rceil>" |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
620 |
using assms by (auto simp: zero_less_mult_iff pos_add_strict) |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
621 |
qed auto |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
622 |
also have "1 / of_int (\<lceil>1/e\<rceil>) \<le> 1 / (1/e)" |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
623 |
by (rule divide_left_mono) (auto simp: \<open>0 < e\<close> ceiling_correct) |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
624 |
also have "\<dots> = e" by simp |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
625 |
finally show "1 / of_nat (Suc (nat \<lceil>1 / e\<rceil>)) < e" |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
626 |
by metis |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
627 |
qed |
| 63489 | 628 |
|
|
68499
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
629 |
lemma ceiling_divide_upper: |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
630 |
fixes q :: "'a::floor_ceiling" |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
631 |
shows "q > 0 \<Longrightarrow> p \<le> of_int (ceiling (p / q)) * q" |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
632 |
by (meson divide_le_eq le_of_int_ceiling) |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
633 |
|
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
634 |
lemma ceiling_divide_lower: |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
635 |
fixes q :: "'a::floor_ceiling" |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
636 |
shows "q > 0 \<Longrightarrow> (of_int \<lceil>p / q\<rceil> - 1) * q < p" |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
637 |
by (meson ceiling_eq_iff pos_less_divide_eq) |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
638 |
|
| 60758 | 639 |
subsection \<open>Negation\<close> |
| 30096 | 640 |
|
| 61942 | 641 |
lemma floor_minus: "\<lfloor>- x\<rfloor> = - \<lceil>x\<rceil>" |
| 30096 | 642 |
unfolding ceiling_def by simp |
643 |
||
| 61942 | 644 |
lemma ceiling_minus: "\<lceil>- x\<rceil> = - \<lfloor>x\<rfloor>" |
| 30096 | 645 |
unfolding ceiling_def by simp |
646 |
||
|
63945
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
647 |
subsection \<open>Natural numbers\<close> |
|
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
648 |
|
|
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
649 |
lemma of_nat_floor: "r\<ge>0 \<Longrightarrow> of_nat (nat \<lfloor>r\<rfloor>) \<le> r" |
|
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
650 |
by simp |
|
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
651 |
|
|
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
652 |
lemma of_nat_ceiling: "of_nat (nat \<lceil>r\<rceil>) \<ge> r" |
|
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
653 |
by (cases "r\<ge>0") auto |
|
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
654 |
|
|
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
655 |
|
| 60758 | 656 |
subsection \<open>Frac Function\<close> |
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
657 |
|
| 63489 | 658 |
definition frac :: "'a \<Rightarrow> 'a::floor_ceiling" |
659 |
where "frac x \<equiv> x - of_int \<lfloor>x\<rfloor>" |
|
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
660 |
|
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
661 |
lemma frac_lt_1: "frac x < 1" |
| 63489 | 662 |
by (simp add: frac_def) linarith |
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
663 |
|
| 61070 | 664 |
lemma frac_eq_0_iff [simp]: "frac x = 0 \<longleftrightarrow> x \<in> \<int>" |
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
665 |
by (simp add: frac_def) (metis Ints_cases Ints_of_int floor_of_int ) |
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
666 |
|
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
667 |
lemma frac_ge_0 [simp]: "frac x \<ge> 0" |
| 63489 | 668 |
unfolding frac_def by linarith |
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
669 |
|
| 61070 | 670 |
lemma frac_gt_0_iff [simp]: "frac x > 0 \<longleftrightarrow> x \<notin> \<int>" |
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
671 |
by (metis frac_eq_0_iff frac_ge_0 le_less less_irrefl) |
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
672 |
|
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
673 |
lemma frac_of_int [simp]: "frac (of_int z) = 0" |
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
674 |
by (simp add: frac_def) |
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
675 |
|
| 68721 | 676 |
lemma frac_frac [simp]: "frac (frac x) = frac x" |
677 |
by (simp add: frac_def) |
|
678 |
||
| 63331 | 679 |
lemma floor_add: "\<lfloor>x + y\<rfloor> = (if frac x + frac y < 1 then \<lfloor>x\<rfloor> + \<lfloor>y\<rfloor> else (\<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>) + 1)" |
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
680 |
proof - |
| 63599 | 681 |
have "x + y < 1 + (of_int \<lfloor>x\<rfloor> + of_int \<lfloor>y\<rfloor>) \<Longrightarrow> \<lfloor>x + y\<rfloor> = \<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>" |
682 |
by (metis add.commute floor_unique le_floor_add le_floor_iff of_int_add) |
|
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
683 |
moreover |
| 63599 | 684 |
have "\<not> x + y < 1 + (of_int \<lfloor>x\<rfloor> + of_int \<lfloor>y\<rfloor>) \<Longrightarrow> \<lfloor>x + y\<rfloor> = 1 + (\<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>)" |
| 66515 | 685 |
apply (simp add: floor_eq_iff) |
| 63489 | 686 |
apply (auto simp add: algebra_simps) |
687 |
apply linarith |
|
688 |
done |
|
| 63599 | 689 |
ultimately show ?thesis by (auto simp add: frac_def algebra_simps) |
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
690 |
qed |
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
691 |
|
| 63621 | 692 |
lemma floor_add2[simp]: "x \<in> \<int> \<or> y \<in> \<int> \<Longrightarrow> \<lfloor>x + y\<rfloor> = \<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>" |
693 |
by (metis add.commute add.left_neutral frac_lt_1 floor_add frac_eq_0_iff) |
|
| 63597 | 694 |
|
| 63489 | 695 |
lemma frac_add: |
696 |
"frac (x + y) = (if frac x + frac y < 1 then frac x + frac y else (frac x + frac y) - 1)" |
|
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
697 |
by (simp add: frac_def floor_add) |
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
698 |
|
| 63489 | 699 |
lemma frac_unique_iff: "frac x = a \<longleftrightarrow> x - a \<in> \<int> \<and> 0 \<le> a \<and> a < 1" |
700 |
for x :: "'a::floor_ceiling" |
|
| 62348 | 701 |
apply (auto simp: Ints_def frac_def algebra_simps floor_unique) |
| 63489 | 702 |
apply linarith+ |
| 62348 | 703 |
done |
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
704 |
|
| 63489 | 705 |
lemma frac_eq: "frac x = x \<longleftrightarrow> 0 \<le> x \<and> x < 1" |
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
706 |
by (simp add: frac_unique_iff) |
| 63331 | 707 |
|
| 63489 | 708 |
lemma frac_neg: "frac (- x) = (if x \<in> \<int> then 0 else 1 - frac x)" |
709 |
for x :: "'a::floor_ceiling" |
|
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
710 |
apply (auto simp add: frac_unique_iff) |
| 63489 | 711 |
apply (simp add: frac_def) |
712 |
apply (meson frac_lt_1 less_iff_diff_less_0 not_le not_less_iff_gr_or_eq) |
|
713 |
done |
|
|
59613
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
714 |
|
| 68721 | 715 |
lemma frac_in_Ints_iff [simp]: "frac x \<in> \<int> \<longleftrightarrow> x \<in> \<int>" |
716 |
proof safe |
|
717 |
assume "frac x \<in> \<int>" |
|
718 |
hence "of_int \<lfloor>x\<rfloor> + frac x \<in> \<int>" by auto |
|
719 |
also have "of_int \<lfloor>x\<rfloor> + frac x = x" by (simp add: frac_def) |
|
720 |
finally show "x \<in> \<int>" . |
|
721 |
qed (auto simp: frac_def) |
|
722 |
||
|
70365
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
68721
diff
changeset
|
723 |
lemma frac_1_eq: "frac (x+1) = frac x" |
|
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
68721
diff
changeset
|
724 |
by (simp add: frac_def) |
|
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
68721
diff
changeset
|
725 |
|
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
726 |
|
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
727 |
subsection \<open>Rounding to the nearest integer\<close> |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
728 |
|
| 63489 | 729 |
definition round :: "'a::floor_ceiling \<Rightarrow> int" |
730 |
where "round x = \<lfloor>x + 1/2\<rfloor>" |
|
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
731 |
|
| 63489 | 732 |
lemma of_int_round_ge: "of_int (round x) \<ge> x - 1/2" |
733 |
and of_int_round_le: "of_int (round x) \<le> x + 1/2" |
|
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
734 |
and of_int_round_abs_le: "\<bar>of_int (round x) - x\<bar> \<le> 1/2" |
| 63489 | 735 |
and of_int_round_gt: "of_int (round x) > x - 1/2" |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
736 |
proof - |
| 63489 | 737 |
from floor_correct[of "x + 1/2"] have "x + 1/2 < of_int (round x) + 1" |
738 |
by (simp add: round_def) |
|
739 |
from add_strict_right_mono[OF this, of "-1"] show A: "of_int (round x) > x - 1/2" |
|
740 |
by simp |
|
741 |
then show "of_int (round x) \<ge> x - 1/2" |
|
742 |
by simp |
|
743 |
from floor_correct[of "x + 1/2"] show "of_int (round x) \<le> x + 1/2" |
|
744 |
by (simp add: round_def) |
|
745 |
with A show "\<bar>of_int (round x) - x\<bar> \<le> 1/2" |
|
746 |
by linarith |
|
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
747 |
qed |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
748 |
|
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
749 |
lemma round_of_int [simp]: "round (of_int n) = n" |
| 66515 | 750 |
unfolding round_def by (subst floor_eq_iff) force |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
751 |
|
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
752 |
lemma round_0 [simp]: "round 0 = 0" |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
753 |
using round_of_int[of 0] by simp |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
754 |
|
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
755 |
lemma round_1 [simp]: "round 1 = 1" |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
756 |
using round_of_int[of 1] by simp |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
757 |
|
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
758 |
lemma round_numeral [simp]: "round (numeral n) = numeral n" |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
759 |
using round_of_int[of "numeral n"] by simp |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
760 |
|
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
761 |
lemma round_neg_numeral [simp]: "round (-numeral n) = -numeral n" |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
762 |
using round_of_int[of "-numeral n"] by simp |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
763 |
|
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
764 |
lemma round_of_nat [simp]: "round (of_nat n) = of_nat n" |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
765 |
using round_of_int[of "int n"] by simp |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
766 |
|
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
767 |
lemma round_mono: "x \<le> y \<Longrightarrow> round x \<le> round y" |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
768 |
unfolding round_def by (intro floor_mono) simp |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
769 |
|
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
770 |
lemma round_unique: "of_int y > x - 1/2 \<Longrightarrow> of_int y \<le> x + 1/2 \<Longrightarrow> round x = y" |
| 63489 | 771 |
unfolding round_def |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
772 |
proof (rule floor_unique) |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
773 |
assume "x - 1 / 2 < of_int y" |
| 63489 | 774 |
from add_strict_left_mono[OF this, of 1] show "x + 1 / 2 < of_int y + 1" |
775 |
by simp |
|
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
776 |
qed |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
777 |
|
| 64317 | 778 |
lemma round_unique': "\<bar>x - of_int n\<bar> < 1/2 \<Longrightarrow> round x = n" |
779 |
by (subst (asm) abs_less_iff, rule round_unique) (simp_all add: field_simps) |
|
780 |
||
| 61942 | 781 |
lemma round_altdef: "round x = (if frac x \<ge> 1/2 then \<lceil>x\<rceil> else \<lfloor>x\<rfloor>)" |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
782 |
by (cases "frac x \<ge> 1/2") |
| 63489 | 783 |
(rule round_unique, ((simp add: frac_def field_simps ceiling_altdef; linarith)+)[2])+ |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
784 |
|
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
785 |
lemma floor_le_round: "\<lfloor>x\<rfloor> \<le> round x" |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
786 |
unfolding round_def by (intro floor_mono) simp |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
787 |
|
| 63489 | 788 |
lemma ceiling_ge_round: "\<lceil>x\<rceil> \<ge> round x" |
789 |
unfolding round_altdef by simp |
|
| 63331 | 790 |
|
| 63489 | 791 |
lemma round_diff_minimal: "\<bar>z - of_int (round z)\<bar> \<le> \<bar>z - of_int m\<bar>" |
792 |
for z :: "'a::floor_ceiling" |
|
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
793 |
proof (cases "of_int m \<ge> z") |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
794 |
case True |
| 63489 | 795 |
then have "\<bar>z - of_int (round z)\<bar> \<le> \<bar>of_int \<lceil>z\<rceil> - z\<bar>" |
796 |
unfolding round_altdef by (simp add: field_simps ceiling_altdef frac_def) linarith |
|
797 |
also have "of_int \<lceil>z\<rceil> - z \<ge> 0" |
|
798 |
by linarith |
|
| 61942 | 799 |
with True have "\<bar>of_int \<lceil>z\<rceil> - z\<bar> \<le> \<bar>z - of_int m\<bar>" |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
800 |
by (simp add: ceiling_le_iff) |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
801 |
finally show ?thesis . |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
802 |
next |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
803 |
case False |
| 63489 | 804 |
then have "\<bar>z - of_int (round z)\<bar> \<le> \<bar>of_int \<lfloor>z\<rfloor> - z\<bar>" |
805 |
unfolding round_altdef by (simp add: field_simps ceiling_altdef frac_def) linarith |
|
806 |
also have "z - of_int \<lfloor>z\<rfloor> \<ge> 0" |
|
807 |
by linarith |
|
| 61942 | 808 |
with False have "\<bar>of_int \<lfloor>z\<rfloor> - z\<bar> \<le> \<bar>z - of_int m\<bar>" |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
809 |
by (simp add: le_floor_iff) |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
810 |
finally show ?thesis . |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
811 |
qed |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
812 |
|
| 30096 | 813 |
end |