author | paulson <lp15@cam.ac.uk> |
Fri, 06 Jun 2025 16:18:44 +0100 | |
changeset 82689 | 817f97d8cd26 |
parent 82542 | 32a6228f543d |
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) |
|
77934 | 19 |
have "\<And>x. x \<in> S \<Longrightarrow> bdd_above (uminus ` S)" |
20 |
using bdd by (force simp: abs_le_iff bdd_above_def) |
|
21 |
then show "- (Inf S) \<le> Sup (uminus ` S)" |
|
22 |
by (meson cInf_greatest [OF \<open>S \<noteq> {}\<close>] cSUP_upper minus_le_iff) |
|
63331 | 23 |
next |
70365
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
68721
diff
changeset
|
24 |
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
|
25 |
by (meson abs_le_iff bdd bdd_below_def cInf_lower minus_le_iff) |
63331 | 26 |
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
|
27 |
using \<open>S \<noteq> {}\<close> by (force intro: * cSup_least) |
63331 | 28 |
qed |
63489 | 29 |
with cSup_abs_le [of "uminus ` S"] assms show ?thesis |
30 |
by fastforce |
|
63331 | 31 |
qed |
32 |
||
33 |
lemma cSup_asclose: |
|
63489 | 34 |
fixes S :: "'a::{linordered_idom,conditionally_complete_linorder} set" |
63331 | 35 |
assumes S: "S \<noteq> {}" |
36 |
and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e" |
|
37 |
shows "\<bar>Sup S - l\<bar> \<le> e" |
|
38 |
proof - |
|
63489 | 39 |
have *: "\<bar>x - l\<bar> \<le> e \<longleftrightarrow> l - e \<le> x \<and> x \<le> l + e" for x l e :: 'a |
63331 | 40 |
by arith |
41 |
have "bdd_above S" |
|
42 |
using b by (auto intro!: bdd_aboveI[of _ "l + e"]) |
|
43 |
with S b show ?thesis |
|
63489 | 44 |
unfolding * by (auto intro!: cSup_upper2 cSup_least) |
63331 | 45 |
qed |
46 |
||
47 |
lemma cInf_asclose: |
|
63489 | 48 |
fixes S :: "'a::{linordered_idom,conditionally_complete_linorder} set" |
63331 | 49 |
assumes S: "S \<noteq> {}" |
50 |
and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e" |
|
51 |
shows "\<bar>Inf S - l\<bar> \<le> e" |
|
52 |
proof - |
|
63489 | 53 |
have *: "\<bar>x - l\<bar> \<le> e \<longleftrightarrow> l - e \<le> x \<and> x \<le> l + e" for x l e :: 'a |
63331 | 54 |
by arith |
55 |
have "bdd_below S" |
|
56 |
using b by (auto intro!: bdd_belowI[of _ "l - e"]) |
|
57 |
with S b show ?thesis |
|
63489 | 58 |
unfolding * by (auto intro!: cInf_lower2 cInf_greatest) |
63331 | 59 |
qed |
60 |
||
63489 | 61 |
|
60758 | 62 |
subsection \<open>Class of Archimedean fields\<close> |
30096 | 63 |
|
60758 | 64 |
text \<open>Archimedean fields have no infinite elements.\<close> |
30096 | 65 |
|
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
66 |
class archimedean_field = linordered_field + |
30096 | 67 |
assumes ex_le_of_int: "\<exists>z. x \<le> of_int z" |
68 |
||
63489 | 69 |
lemma ex_less_of_int: "\<exists>z. x < of_int z" |
70 |
for x :: "'a::archimedean_field" |
|
30096 | 71 |
proof - |
72 |
from ex_le_of_int obtain z where "x \<le> of_int z" .. |
|
73 |
then have "x < of_int (z + 1)" by simp |
|
74 |
then show ?thesis .. |
|
75 |
qed |
|
76 |
||
63489 | 77 |
lemma ex_of_int_less: "\<exists>z. of_int z < x" |
78 |
for x :: "'a::archimedean_field" |
|
30096 | 79 |
proof - |
80 |
from ex_less_of_int obtain z where "- x < of_int z" .. |
|
81 |
then have "of_int (- z) < x" by simp |
|
82 |
then show ?thesis .. |
|
83 |
qed |
|
84 |
||
63489 | 85 |
lemma reals_Archimedean2: "\<exists>n. x < of_nat n" |
86 |
for x :: "'a::archimedean_field" |
|
30096 | 87 |
proof - |
63489 | 88 |
obtain z where "x < of_int z" |
89 |
using ex_less_of_int .. |
|
90 |
also have "\<dots> \<le> of_int (int (nat z))" |
|
91 |
by simp |
|
92 |
also have "\<dots> = of_nat (nat z)" |
|
93 |
by (simp only: of_int_of_nat_eq) |
|
30096 | 94 |
finally show ?thesis .. |
95 |
qed |
|
96 |
||
63489 | 97 |
lemma real_arch_simple: "\<exists>n. x \<le> of_nat n" |
98 |
for x :: "'a::archimedean_field" |
|
30096 | 99 |
proof - |
63489 | 100 |
obtain n where "x < of_nat n" |
101 |
using reals_Archimedean2 .. |
|
102 |
then have "x \<le> of_nat n" |
|
103 |
by simp |
|
30096 | 104 |
then show ?thesis .. |
105 |
qed |
|
106 |
||
60758 | 107 |
text \<open>Archimedean fields have no infinitesimal elements.\<close> |
30096 | 108 |
|
62623
dbc62f86a1a9
rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents:
62348
diff
changeset
|
109 |
lemma reals_Archimedean: |
30096 | 110 |
fixes x :: "'a::archimedean_field" |
63489 | 111 |
assumes "0 < x" |
112 |
shows "\<exists>n. inverse (of_nat (Suc n)) < x" |
|
30096 | 113 |
proof - |
60758 | 114 |
from \<open>0 < x\<close> have "0 < inverse x" |
30096 | 115 |
by (rule positive_imp_inverse_positive) |
116 |
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
|
117 |
using reals_Archimedean2 .. |
30096 | 118 |
then obtain m where "inverse x < of_nat (Suc m)" |
60758 | 119 |
using \<open>0 < inverse x\<close> by (cases n) (simp_all del: of_nat_Suc) |
30096 | 120 |
then have "inverse (of_nat (Suc m)) < inverse (inverse x)" |
60758 | 121 |
using \<open>0 < inverse x\<close> by (rule less_imp_inverse_less) |
30096 | 122 |
then have "inverse (of_nat (Suc m)) < x" |
60758 | 123 |
using \<open>0 < x\<close> by (simp add: nonzero_inverse_inverse_eq) |
30096 | 124 |
then show ?thesis .. |
125 |
qed |
|
126 |
||
127 |
lemma ex_inverse_of_nat_less: |
|
128 |
fixes x :: "'a::archimedean_field" |
|
63489 | 129 |
assumes "0 < x" |
130 |
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
|
131 |
using reals_Archimedean [OF \<open>0 < x\<close>] by auto |
30096 | 132 |
|
133 |
lemma ex_less_of_nat_mult: |
|
134 |
fixes x :: "'a::archimedean_field" |
|
63489 | 135 |
assumes "0 < x" |
136 |
shows "\<exists>n. y < of_nat n * x" |
|
30096 | 137 |
proof - |
63489 | 138 |
obtain n where "y / x < of_nat n" |
139 |
using reals_Archimedean2 .. |
|
140 |
with \<open>0 < x\<close> have "y < of_nat n * x" |
|
141 |
by (simp add: pos_divide_less_eq) |
|
30096 | 142 |
then show ?thesis .. |
143 |
qed |
|
144 |
||
145 |
||
60758 | 146 |
subsection \<open>Existence and uniqueness of floor function\<close> |
30096 | 147 |
|
148 |
lemma exists_least_lemma: |
|
149 |
assumes "\<not> P 0" and "\<exists>n. P n" |
|
150 |
shows "\<exists>n. \<not> P n \<and> P (Suc n)" |
|
151 |
proof - |
|
63489 | 152 |
from \<open>\<exists>n. P n\<close> have "P (Least P)" |
153 |
by (rule LeastI_ex) |
|
60758 | 154 |
with \<open>\<not> P 0\<close> obtain n where "Least P = Suc n" |
30096 | 155 |
by (cases "Least P") auto |
63489 | 156 |
then have "n < Least P" |
157 |
by simp |
|
158 |
then have "\<not> P n" |
|
159 |
by (rule not_less_Least) |
|
30096 | 160 |
then have "\<not> P n \<and> P (Suc n)" |
60758 | 161 |
using \<open>P (Least P)\<close> \<open>Least P = Suc n\<close> by simp |
30096 | 162 |
then show ?thesis .. |
163 |
qed |
|
164 |
||
165 |
lemma floor_exists: |
|
166 |
fixes x :: "'a::archimedean_field" |
|
167 |
shows "\<exists>z. of_int z \<le> x \<and> x < of_int (z + 1)" |
|
63489 | 168 |
proof (cases "0 \<le> x") |
169 |
case True |
|
170 |
then have "\<not> x < of_nat 0" |
|
171 |
by simp |
|
30096 | 172 |
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
|
173 |
using reals_Archimedean2 by (rule exists_least_lemma) |
30096 | 174 |
then obtain n where "\<not> x < of_nat n \<and> x < of_nat (Suc n)" .. |
63489 | 175 |
then have "of_int (int n) \<le> x \<and> x < of_int (int n + 1)" |
176 |
by simp |
|
30096 | 177 |
then show ?thesis .. |
178 |
next |
|
63489 | 179 |
case False |
180 |
then have "\<not> - x \<le> of_nat 0" |
|
181 |
by simp |
|
30096 | 182 |
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
|
183 |
using real_arch_simple by (rule exists_least_lemma) |
30096 | 184 |
then obtain n where "\<not> - x \<le> of_nat n \<and> - x \<le> of_nat (Suc n)" .. |
63489 | 185 |
then have "of_int (- int n - 1) \<le> x \<and> x < of_int (- int n - 1 + 1)" |
186 |
by simp |
|
30096 | 187 |
then show ?thesis .. |
188 |
qed |
|
189 |
||
63489 | 190 |
lemma floor_exists1: "\<exists>!z. of_int z \<le> x \<and> x < of_int (z + 1)" |
191 |
for x :: "'a::archimedean_field" |
|
30096 | 192 |
proof (rule ex_ex1I) |
193 |
show "\<exists>z. of_int z \<le> x \<and> x < of_int (z + 1)" |
|
194 |
by (rule floor_exists) |
|
195 |
next |
|
63489 | 196 |
fix y z |
197 |
assume "of_int y \<le> x \<and> x < of_int (y + 1)" |
|
198 |
and "of_int z \<le> x \<and> x < of_int (z + 1)" |
|
54281 | 199 |
with le_less_trans [of "of_int y" "x" "of_int (z + 1)"] |
63489 | 200 |
le_less_trans [of "of_int z" "x" "of_int (y + 1)"] show "y = z" |
201 |
by (simp del: of_int_add) |
|
30096 | 202 |
qed |
203 |
||
204 |
||
60758 | 205 |
subsection \<open>Floor function\<close> |
30096 | 206 |
|
43732
6b2bdc57155b
adding a floor_ceiling type class for different instantiations of floor (changeset from Brian Huffman)
bulwahn
parents:
43704
diff
changeset
|
207 |
class floor_ceiling = archimedean_field + |
81125 | 208 |
fixes floor :: "'a \<Rightarrow> int" (\<open>(\<open>open_block notation=\<open>mixfix floor\<close>\<close>\<lfloor>_\<rfloor>)\<close>) |
61942 | 209 |
assumes floor_correct: "of_int \<lfloor>x\<rfloor> \<le> x \<and> x < of_int (\<lfloor>x\<rfloor> + 1)" |
30096 | 210 |
|
63489 | 211 |
lemma floor_unique: "of_int z \<le> x \<Longrightarrow> x < of_int z + 1 \<Longrightarrow> \<lfloor>x\<rfloor> = z" |
30096 | 212 |
using floor_correct [of x] floor_exists1 [of x] by auto |
213 |
||
66515 | 214 |
lemma floor_eq_iff: "\<lfloor>x\<rfloor> = a \<longleftrightarrow> of_int a \<le> x \<and> x < of_int a + 1" |
82689
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
215 |
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
|
216 |
|
61942 | 217 |
lemma of_int_floor_le [simp]: "of_int \<lfloor>x\<rfloor> \<le> x" |
30096 | 218 |
using floor_correct .. |
219 |
||
61942 | 220 |
lemma le_floor_iff: "z \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> of_int z \<le> x" |
30096 | 221 |
proof |
61942 | 222 |
assume "z \<le> \<lfloor>x\<rfloor>" |
223 |
then have "(of_int z :: 'a) \<le> of_int \<lfloor>x\<rfloor>" by simp |
|
224 |
also have "of_int \<lfloor>x\<rfloor> \<le> x" by (rule of_int_floor_le) |
|
30096 | 225 |
finally show "of_int z \<le> x" . |
226 |
next |
|
227 |
assume "of_int z \<le> x" |
|
61942 | 228 |
also have "x < of_int (\<lfloor>x\<rfloor> + 1)" using floor_correct .. |
229 |
finally show "z \<le> \<lfloor>x\<rfloor>" by (simp del: of_int_add) |
|
30096 | 230 |
qed |
231 |
||
61942 | 232 |
lemma floor_less_iff: "\<lfloor>x\<rfloor> < z \<longleftrightarrow> x < of_int z" |
30096 | 233 |
by (simp add: not_le [symmetric] le_floor_iff) |
234 |
||
61942 | 235 |
lemma less_floor_iff: "z < \<lfloor>x\<rfloor> \<longleftrightarrow> of_int z + 1 \<le> x" |
30096 | 236 |
using le_floor_iff [of "z + 1" x] by auto |
237 |
||
61942 | 238 |
lemma floor_le_iff: "\<lfloor>x\<rfloor> \<le> z \<longleftrightarrow> x < of_int z + 1" |
30096 | 239 |
by (simp add: not_less [symmetric] less_floor_iff) |
240 |
||
75878 | 241 |
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
|
242 |
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
|
243 |
|
82689
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
244 |
lemma floor_eq_imp_diff_1: "\<lfloor>x\<rfloor> = \<lfloor>y\<rfloor> \<Longrightarrow> \<bar>x-y\<bar> < 1" |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
245 |
unfolding floor_eq_iff by linarith |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
246 |
|
61942 | 247 |
lemma floor_mono: |
248 |
assumes "x \<le> y" |
|
249 |
shows "\<lfloor>x\<rfloor> \<le> \<lfloor>y\<rfloor>" |
|
82689
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
250 |
using assms le_floor_iff of_int_floor_le order.trans by blast |
30096 | 251 |
|
61942 | 252 |
lemma floor_less_cancel: "\<lfloor>x\<rfloor> < \<lfloor>y\<rfloor> \<Longrightarrow> x < y" |
30096 | 253 |
by (auto simp add: not_le [symmetric] floor_mono) |
254 |
||
61942 | 255 |
lemma floor_of_int [simp]: "\<lfloor>of_int z\<rfloor> = z" |
30096 | 256 |
by (rule floor_unique) simp_all |
257 |
||
61942 | 258 |
lemma floor_of_nat [simp]: "\<lfloor>of_nat n\<rfloor> = int n" |
30096 | 259 |
using floor_of_int [of "of_nat n"] by simp |
260 |
||
61942 | 261 |
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
|
262 |
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
|
263 |
|
63489 | 264 |
|
265 |
text \<open>Floor with numerals.\<close> |
|
30096 | 266 |
|
61942 | 267 |
lemma floor_zero [simp]: "\<lfloor>0\<rfloor> = 0" |
30096 | 268 |
using floor_of_int [of 0] by simp |
269 |
||
61942 | 270 |
lemma floor_one [simp]: "\<lfloor>1\<rfloor> = 1" |
30096 | 271 |
using floor_of_int [of 1] by simp |
272 |
||
61942 | 273 |
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
|
274 |
using floor_of_int [of "numeral v"] by simp |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
275 |
|
61942 | 276 |
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
|
277 |
using floor_of_int [of "- numeral v"] by simp |
30096 | 278 |
|
61942 | 279 |
lemma zero_le_floor [simp]: "0 \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> 0 \<le> x" |
30096 | 280 |
by (simp add: le_floor_iff) |
281 |
||
61942 | 282 |
lemma one_le_floor [simp]: "1 \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> 1 \<le> x" |
30096 | 283 |
by (simp add: le_floor_iff) |
284 |
||
63489 | 285 |
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
|
286 |
by (simp add: le_floor_iff) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
287 |
|
63489 | 288 |
lemma neg_numeral_le_floor [simp]: "- numeral v \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> - numeral v \<le> x" |
30096 | 289 |
by (simp add: le_floor_iff) |
290 |
||
61942 | 291 |
lemma zero_less_floor [simp]: "0 < \<lfloor>x\<rfloor> \<longleftrightarrow> 1 \<le> x" |
30096 | 292 |
by (simp add: less_floor_iff) |
293 |
||
61942 | 294 |
lemma one_less_floor [simp]: "1 < \<lfloor>x\<rfloor> \<longleftrightarrow> 2 \<le> x" |
30096 | 295 |
by (simp add: less_floor_iff) |
296 |
||
63489 | 297 |
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
|
298 |
by (simp add: less_floor_iff) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
299 |
|
63489 | 300 |
lemma neg_numeral_less_floor [simp]: "- numeral v < \<lfloor>x\<rfloor> \<longleftrightarrow> - numeral v + 1 \<le> x" |
30096 | 301 |
by (simp add: less_floor_iff) |
302 |
||
61942 | 303 |
lemma floor_le_zero [simp]: "\<lfloor>x\<rfloor> \<le> 0 \<longleftrightarrow> x < 1" |
30096 | 304 |
by (simp add: floor_le_iff) |
305 |
||
61942 | 306 |
lemma floor_le_one [simp]: "\<lfloor>x\<rfloor> \<le> 1 \<longleftrightarrow> x < 2" |
30096 | 307 |
by (simp add: floor_le_iff) |
308 |
||
63489 | 309 |
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
|
310 |
by (simp add: floor_le_iff) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
311 |
|
63489 | 312 |
lemma floor_le_neg_numeral [simp]: "\<lfloor>x\<rfloor> \<le> - numeral v \<longleftrightarrow> x < - numeral v + 1" |
30096 | 313 |
by (simp add: floor_le_iff) |
314 |
||
61942 | 315 |
lemma floor_less_zero [simp]: "\<lfloor>x\<rfloor> < 0 \<longleftrightarrow> x < 0" |
30096 | 316 |
by (simp add: floor_less_iff) |
317 |
||
61942 | 318 |
lemma floor_less_one [simp]: "\<lfloor>x\<rfloor> < 1 \<longleftrightarrow> x < 1" |
30096 | 319 |
by (simp add: floor_less_iff) |
320 |
||
63489 | 321 |
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
|
322 |
by (simp add: floor_less_iff) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
323 |
|
63489 | 324 |
lemma floor_less_neg_numeral [simp]: "\<lfloor>x\<rfloor> < - numeral v \<longleftrightarrow> x < - numeral v" |
30096 | 325 |
by (simp add: floor_less_iff) |
326 |
||
66154
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
327 |
lemma le_mult_floor_Ints: |
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
328 |
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
|
329 |
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
|
330 |
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
|
331 |
|
63489 | 332 |
|
333 |
text \<open>Addition and subtraction of integers.\<close> |
|
30096 | 334 |
|
63599 | 335 |
lemma floor_add_int: "\<lfloor>x\<rfloor> + z = \<lfloor>x + of_int z\<rfloor>" |
336 |
using floor_correct [of x] by (simp add: floor_unique[symmetric]) |
|
30096 | 337 |
|
63599 | 338 |
lemma int_add_floor: "z + \<lfloor>x\<rfloor> = \<lfloor>of_int z + x\<rfloor>" |
339 |
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
|
340 |
|
63599 | 341 |
lemma one_add_floor: "\<lfloor>x\<rfloor> + 1 = \<lfloor>x + 1\<rfloor>" |
342 |
using floor_add_int [of x 1] by simp |
|
30096 | 343 |
|
61942 | 344 |
lemma floor_diff_of_int [simp]: "\<lfloor>x - of_int z\<rfloor> = \<lfloor>x\<rfloor> - z" |
63599 | 345 |
using floor_add_int [of x "- z"] by (simp add: algebra_simps) |
30096 | 346 |
|
61942 | 347 |
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
|
348 |
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
|
349 |
|
63489 | 350 |
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
|
351 |
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
|
352 |
|
61942 | 353 |
lemma floor_diff_one [simp]: "\<lfloor>x - 1\<rfloor> = \<lfloor>x\<rfloor> - 1" |
30096 | 354 |
using floor_diff_of_int [of x 1] by simp |
355 |
||
58097
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents:
58040
diff
changeset
|
356 |
lemma le_mult_floor: |
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents:
58040
diff
changeset
|
357 |
assumes "0 \<le> a" and "0 \<le> b" |
61942 | 358 |
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
|
359 |
proof - |
63489 | 360 |
have "of_int \<lfloor>a\<rfloor> \<le> a" and "of_int \<lfloor>b\<rfloor> \<le> b" |
361 |
by (auto intro: of_int_floor_le) |
|
362 |
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
|
363 |
using assms by (auto intro!: mult_mono) |
61942 | 364 |
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
|
365 |
using floor_correct[of "a * b"] by auto |
63489 | 366 |
finally show ?thesis |
367 |
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
|
368 |
qed |
cfd3cff9387b
add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents:
58040
diff
changeset
|
369 |
|
63489 | 370 |
lemma floor_divide_of_int_eq: "\<lfloor>of_int k / of_int l\<rfloor> = k div l" |
371 |
for k l :: int |
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
372 |
proof (cases "l = 0") |
63489 | 373 |
case True |
374 |
then show ?thesis by simp |
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
375 |
next |
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
376 |
case False |
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
377 |
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
|
378 |
proof (cases "l > 0") |
63489 | 379 |
case True |
380 |
then show ?thesis |
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
381 |
by (auto intro: floor_unique) |
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
382 |
next |
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
383 |
case False |
63489 | 384 |
obtain r where "r = - l" |
385 |
by blast |
|
386 |
then have l: "l = - r" |
|
387 |
by simp |
|
63540 | 388 |
with \<open>l \<noteq> 0\<close> False have "r > 0" |
63489 | 389 |
by simp |
63540 | 390 |
with l show ?thesis |
63489 | 391 |
using pos_mod_bound [of r] |
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
392 |
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
|
393 |
qed |
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
394 |
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
|
395 |
by simp |
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
396 |
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
|
397 |
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
|
398 |
finally have "(of_int k / of_int l :: 'a) = \<dots> / of_int l" |
63331 | 399 |
by simp |
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
400 |
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
|
401 |
using False by (simp only:) (simp add: field_simps) |
63331 | 402 |
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
|
403 |
by simp |
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
404 |
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
|
405 |
by (simp add: ac_simps) |
60128 | 406 |
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 | 407 |
by (simp add: floor_add_int) |
63489 | 408 |
with * show ?thesis |
409 |
by simp |
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
410 |
qed |
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
411 |
|
63489 | 412 |
lemma floor_divide_of_nat_eq: "\<lfloor>of_nat m / of_nat n\<rfloor> = of_nat (m div n)" |
413 |
for m n :: nat |
|
78937
5e6b195eee83
slightly less technical formulation of very specific type class
haftmann
parents:
78748
diff
changeset
|
414 |
by (metis floor_divide_of_int_eq of_int_of_nat_eq linordered_euclidean_semiring_class.of_nat_div) |
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
415 |
|
68499
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
416 |
lemma floor_divide_lower: |
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
417 |
fixes q :: "'a::floor_ceiling" |
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
418 |
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
|
419 |
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
|
420 |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
421 |
lemma floor_divide_upper: |
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
422 |
fixes q :: "'a::floor_ceiling" |
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
423 |
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
|
424 |
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
|
425 |
|
59984
4f1eccec320c
conversion between division on nat/int and division in archmedean fields
haftmann
parents:
59613
diff
changeset
|
426 |
|
60758 | 427 |
subsection \<open>Ceiling function\<close> |
30096 | 428 |
|
81125 | 429 |
definition ceiling :: "'a::floor_ceiling \<Rightarrow> int" (\<open>(\<open>open_block notation=\<open>mixfix ceiling\<close>\<close>\<lceil>_\<rceil>)\<close>) |
61942 | 430 |
where "\<lceil>x\<rceil> = - \<lfloor>- x\<rfloor>" |
30096 | 431 |
|
61942 | 432 |
lemma ceiling_correct: "of_int \<lceil>x\<rceil> - 1 < x \<and> x \<le> of_int \<lceil>x\<rceil>" |
63489 | 433 |
unfolding ceiling_def using floor_correct [of "- x"] |
434 |
by (simp add: le_minus_iff) |
|
30096 | 435 |
|
63489 | 436 |
lemma ceiling_unique: "of_int z - 1 < x \<Longrightarrow> x \<le> of_int z \<Longrightarrow> \<lceil>x\<rceil> = z" |
30096 | 437 |
unfolding ceiling_def using floor_unique [of "- z" "- x"] by simp |
438 |
||
66515 | 439 |
lemma ceiling_eq_iff: "\<lceil>x\<rceil> = a \<longleftrightarrow> of_int a - 1 < x \<and> x \<le> of_int a" |
440 |
using ceiling_correct ceiling_unique by auto |
|
441 |
||
61942 | 442 |
lemma le_of_int_ceiling [simp]: "x \<le> of_int \<lceil>x\<rceil>" |
30096 | 443 |
using ceiling_correct .. |
444 |
||
61942 | 445 |
lemma ceiling_le_iff: "\<lceil>x\<rceil> \<le> z \<longleftrightarrow> x \<le> of_int z" |
30096 | 446 |
unfolding ceiling_def using le_floor_iff [of "- z" "- x"] by auto |
447 |
||
61942 | 448 |
lemma less_ceiling_iff: "z < \<lceil>x\<rceil> \<longleftrightarrow> of_int z < x" |
30096 | 449 |
by (simp add: not_le [symmetric] ceiling_le_iff) |
450 |
||
61942 | 451 |
lemma ceiling_less_iff: "\<lceil>x\<rceil> < z \<longleftrightarrow> x \<le> of_int z - 1" |
30096 | 452 |
using ceiling_le_iff [of x "z - 1"] by simp |
453 |
||
61942 | 454 |
lemma le_ceiling_iff: "z \<le> \<lceil>x\<rceil> \<longleftrightarrow> of_int z - 1 < x" |
30096 | 455 |
by (simp add: not_less [symmetric] ceiling_less_iff) |
456 |
||
61942 | 457 |
lemma ceiling_mono: "x \<ge> y \<Longrightarrow> \<lceil>x\<rceil> \<ge> \<lceil>y\<rceil>" |
30096 | 458 |
unfolding ceiling_def by (simp add: floor_mono) |
459 |
||
61942 | 460 |
lemma ceiling_less_cancel: "\<lceil>x\<rceil> < \<lceil>y\<rceil> \<Longrightarrow> x < y" |
30096 | 461 |
by (auto simp add: not_le [symmetric] ceiling_mono) |
462 |
||
61942 | 463 |
lemma ceiling_of_int [simp]: "\<lceil>of_int z\<rceil> = z" |
30096 | 464 |
by (rule ceiling_unique) simp_all |
465 |
||
61942 | 466 |
lemma ceiling_of_nat [simp]: "\<lceil>of_nat n\<rceil> = int n" |
30096 | 467 |
using ceiling_of_int [of "of_nat n"] by simp |
468 |
||
61942 | 469 |
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
|
470 |
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
|
471 |
|
66154
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
472 |
lemma mult_ceiling_le: |
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
473 |
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
|
474 |
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
|
475 |
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
|
476 |
|
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
477 |
lemma mult_ceiling_le_Ints: |
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
478 |
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
|
479 |
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
|
480 |
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
|
481 |
|
63879
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
482 |
lemma finite_int_segment: |
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
483 |
fixes a :: "'a::floor_ceiling" |
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
484 |
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
|
485 |
proof - |
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
486 |
have "finite {ceiling a..floor b}" |
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
487 |
by simp |
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
488 |
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
|
489 |
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
|
490 |
ultimately show ?thesis |
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
491 |
by simp |
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
492 |
qed |
15bbf6360339
simple new lemmas, mostly about sets
paulson <lp15@cam.ac.uk>
parents:
63621
diff
changeset
|
493 |
|
66154
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
494 |
corollary finite_abs_int_segment: |
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
495 |
fixes a :: "'a::floor_ceiling" |
bc5e6461f759
Tidying up integration theory and some new theorems
paulson <lp15@cam.ac.uk>
parents:
64317
diff
changeset
|
496 |
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
|
497 |
using finite_int_segment [of "-a" a] by (auto simp add: abs_le_iff conj_commute minus_le_iff) |
63489 | 498 |
|
66793
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
499 |
|
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
500 |
subsubsection \<open>Ceiling with numerals.\<close> |
30096 | 501 |
|
61942 | 502 |
lemma ceiling_zero [simp]: "\<lceil>0\<rceil> = 0" |
30096 | 503 |
using ceiling_of_int [of 0] by simp |
504 |
||
61942 | 505 |
lemma ceiling_one [simp]: "\<lceil>1\<rceil> = 1" |
30096 | 506 |
using ceiling_of_int [of 1] by simp |
507 |
||
61942 | 508 |
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
|
509 |
using ceiling_of_int [of "numeral v"] by simp |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
510 |
|
61942 | 511 |
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
|
512 |
using ceiling_of_int [of "- numeral v"] by simp |
30096 | 513 |
|
61942 | 514 |
lemma ceiling_le_zero [simp]: "\<lceil>x\<rceil> \<le> 0 \<longleftrightarrow> x \<le> 0" |
30096 | 515 |
by (simp add: ceiling_le_iff) |
516 |
||
61942 | 517 |
lemma ceiling_le_one [simp]: "\<lceil>x\<rceil> \<le> 1 \<longleftrightarrow> x \<le> 1" |
30096 | 518 |
by (simp add: ceiling_le_iff) |
519 |
||
63489 | 520 |
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
|
521 |
by (simp add: ceiling_le_iff) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
522 |
|
63489 | 523 |
lemma ceiling_le_neg_numeral [simp]: "\<lceil>x\<rceil> \<le> - numeral v \<longleftrightarrow> x \<le> - numeral v" |
30096 | 524 |
by (simp add: ceiling_le_iff) |
525 |
||
61942 | 526 |
lemma ceiling_less_zero [simp]: "\<lceil>x\<rceil> < 0 \<longleftrightarrow> x \<le> -1" |
30096 | 527 |
by (simp add: ceiling_less_iff) |
528 |
||
61942 | 529 |
lemma ceiling_less_one [simp]: "\<lceil>x\<rceil> < 1 \<longleftrightarrow> x \<le> 0" |
30096 | 530 |
by (simp add: ceiling_less_iff) |
531 |
||
63489 | 532 |
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
|
533 |
by (simp add: ceiling_less_iff) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
534 |
|
63489 | 535 |
lemma ceiling_less_neg_numeral [simp]: "\<lceil>x\<rceil> < - numeral v \<longleftrightarrow> x \<le> - numeral v - 1" |
30096 | 536 |
by (simp add: ceiling_less_iff) |
537 |
||
61942 | 538 |
lemma zero_le_ceiling [simp]: "0 \<le> \<lceil>x\<rceil> \<longleftrightarrow> -1 < x" |
30096 | 539 |
by (simp add: le_ceiling_iff) |
540 |
||
61942 | 541 |
lemma one_le_ceiling [simp]: "1 \<le> \<lceil>x\<rceil> \<longleftrightarrow> 0 < x" |
30096 | 542 |
by (simp add: le_ceiling_iff) |
543 |
||
63489 | 544 |
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
|
545 |
by (simp add: le_ceiling_iff) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
546 |
|
63489 | 547 |
lemma neg_numeral_le_ceiling [simp]: "- numeral v \<le> \<lceil>x\<rceil> \<longleftrightarrow> - numeral v - 1 < x" |
30096 | 548 |
by (simp add: le_ceiling_iff) |
549 |
||
61942 | 550 |
lemma zero_less_ceiling [simp]: "0 < \<lceil>x\<rceil> \<longleftrightarrow> 0 < x" |
30096 | 551 |
by (simp add: less_ceiling_iff) |
552 |
||
61942 | 553 |
lemma one_less_ceiling [simp]: "1 < \<lceil>x\<rceil> \<longleftrightarrow> 1 < x" |
30096 | 554 |
by (simp add: less_ceiling_iff) |
555 |
||
63489 | 556 |
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
|
557 |
by (simp add: less_ceiling_iff) |
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
43733
diff
changeset
|
558 |
|
63489 | 559 |
lemma neg_numeral_less_ceiling [simp]: "- numeral v < \<lceil>x\<rceil> \<longleftrightarrow> - numeral v < x" |
30096 | 560 |
by (simp add: less_ceiling_iff) |
561 |
||
61942 | 562 |
lemma ceiling_altdef: "\<lceil>x\<rceil> = (if x = of_int \<lfloor>x\<rfloor> then \<lfloor>x\<rfloor> else \<lfloor>x\<rfloor> + 1)" |
63489 | 563 |
by (intro ceiling_unique; simp, linarith?) |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
564 |
|
61942 | 565 |
lemma floor_le_ceiling [simp]: "\<lfloor>x\<rfloor> \<le> \<lceil>x\<rceil>" |
566 |
by (simp add: ceiling_altdef) |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
567 |
|
63489 | 568 |
|
66793
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
569 |
subsubsection \<open>Addition and subtraction of integers.\<close> |
30096 | 570 |
|
61942 | 571 |
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
|
572 |
using ceiling_correct [of x] by (simp add: ceiling_def) |
30096 | 573 |
|
61942 | 574 |
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
|
575 |
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
|
576 |
|
61942 | 577 |
lemma ceiling_add_one [simp]: "\<lceil>x + 1\<rceil> = \<lceil>x\<rceil> + 1" |
30096 | 578 |
using ceiling_add_of_int [of x 1] by simp |
579 |
||
61942 | 580 |
lemma ceiling_diff_of_int [simp]: "\<lceil>x - of_int z\<rceil> = \<lceil>x\<rceil> - z" |
30096 | 581 |
using ceiling_add_of_int [of x "- z"] by (simp add: algebra_simps) |
582 |
||
61942 | 583 |
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
|
584 |
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
|
585 |
|
61942 | 586 |
lemma ceiling_diff_one [simp]: "\<lceil>x - 1\<rceil> = \<lceil>x\<rceil> - 1" |
30096 | 587 |
using ceiling_diff_of_int [of x 1] by simp |
588 |
||
75878 | 589 |
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
|
590 |
by (auto simp add: ceiling_unique ceiling_correct) |
9a867afaab5a
better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents:
54489
diff
changeset
|
591 |
|
82689
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
592 |
lemma ceiling_eq_imp_diff_1: "\<lceil>x\<rceil> = \<lceil>y\<rceil> \<Longrightarrow> \<bar>x-y\<bar> < 1" |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
593 |
unfolding ceiling_eq_iff by linarith |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
594 |
|
61942 | 595 |
lemma ceiling_diff_floor_le_1: "\<lceil>x\<rceil> - \<lfloor>x\<rfloor> \<le> 1" |
82689
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
596 |
by (simp add: ceiling_altdef) |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
597 |
|
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
598 |
lemma floor_eq_ceiling_imp_diff_2: "\<lfloor>x\<rfloor> = \<lceil>y\<rceil> \<Longrightarrow> \<bar>x-y\<bar> < 2" |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
599 |
unfolding floor_eq_iff by linarith |
30096 | 600 |
|
66793
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
601 |
lemma nat_approx_posE: |
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
602 |
fixes e:: "'a::{archimedean_field,floor_ceiling}" |
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
603 |
assumes "0 < e" |
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
604 |
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
|
605 |
proof |
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
606 |
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
|
607 |
proof (rule divide_strict_left_mono) |
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
608 |
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
|
609 |
using assms by (simp add: field_simps) |
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
610 |
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
|
611 |
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
|
612 |
qed auto |
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
613 |
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
|
614 |
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
|
615 |
also have "\<dots> = e" by simp |
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
616 |
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
|
617 |
by metis |
deabce3ccf1f
new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents:
66515
diff
changeset
|
618 |
qed |
63489 | 619 |
|
68499
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
620 |
lemma ceiling_divide_upper: |
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
621 |
fixes q :: "'a::floor_ceiling" |
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
622 |
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
|
623 |
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
|
624 |
|
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
625 |
lemma ceiling_divide_lower: |
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
626 |
fixes q :: "'a::floor_ceiling" |
d4312962161a
Rationalisation of complex transcendentals, esp the Arg function
paulson <lp15@cam.ac.uk>
parents:
66793
diff
changeset
|
627 |
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
|
628 |
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
|
629 |
|
60758 | 630 |
subsection \<open>Negation\<close> |
30096 | 631 |
|
61942 | 632 |
lemma floor_minus: "\<lfloor>- x\<rfloor> = - \<lceil>x\<rceil>" |
30096 | 633 |
unfolding ceiling_def by simp |
634 |
||
61942 | 635 |
lemma ceiling_minus: "\<lceil>- x\<rceil> = - \<lfloor>x\<rfloor>" |
30096 | 636 |
unfolding ceiling_def by simp |
637 |
||
63945
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
638 |
subsection \<open>Natural numbers\<close> |
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
639 |
|
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
640 |
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
|
641 |
by simp |
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
642 |
|
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
643 |
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
|
644 |
by (cases "r\<ge>0") auto |
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
645 |
|
79945
ca004ccf2352
New material from a variety of sources (including AFP)
paulson <lp15@cam.ac.uk>
parents:
78937
diff
changeset
|
646 |
lemma of_nat_int_floor [simp]: "x\<ge>0 \<Longrightarrow> of_nat (nat\<lfloor>x\<rfloor>) = of_int \<lfloor>x\<rfloor>" |
ca004ccf2352
New material from a variety of sources (including AFP)
paulson <lp15@cam.ac.uk>
parents:
78937
diff
changeset
|
647 |
by auto |
ca004ccf2352
New material from a variety of sources (including AFP)
paulson <lp15@cam.ac.uk>
parents:
78937
diff
changeset
|
648 |
|
ca004ccf2352
New material from a variety of sources (including AFP)
paulson <lp15@cam.ac.uk>
parents:
78937
diff
changeset
|
649 |
lemma of_nat_int_ceiling [simp]: "x\<ge>0 \<Longrightarrow> of_nat (nat \<lceil>x\<rceil>) = of_int \<lceil>x\<rceil>" |
ca004ccf2352
New material from a variety of sources (including AFP)
paulson <lp15@cam.ac.uk>
parents:
78937
diff
changeset
|
650 |
by auto |
63945
444eafb6e864
a few new theorems and a renaming
paulson <lp15@cam.ac.uk>
parents:
63879
diff
changeset
|
651 |
|
60758 | 652 |
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
|
653 |
|
63489 | 654 |
definition frac :: "'a \<Rightarrow> 'a::floor_ceiling" |
655 |
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
|
656 |
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
657 |
lemma frac_lt_1: "frac x < 1" |
63489 | 658 |
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
|
659 |
|
61070 | 660 |
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
|
661 |
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
|
662 |
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
663 |
lemma frac_ge_0 [simp]: "frac x \<ge> 0" |
63489 | 664 |
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
|
665 |
|
61070 | 666 |
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
|
667 |
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
|
668 |
|
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
669 |
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
|
670 |
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
|
671 |
|
68721 | 672 |
lemma frac_frac [simp]: "frac (frac x) = frac x" |
673 |
by (simp add: frac_def) |
|
674 |
||
63331 | 675 |
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
|
676 |
proof - |
63599 | 677 |
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>" |
678 |
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
|
679 |
moreover |
63599 | 680 |
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 | 681 |
apply (simp add: floor_eq_iff) |
63489 | 682 |
apply (auto simp add: algebra_simps) |
683 |
apply linarith |
|
684 |
done |
|
63599 | 685 |
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
|
686 |
qed |
7103019278f0
The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents:
58889
diff
changeset
|
687 |
|
63621 | 688 |
lemma floor_add2[simp]: "x \<in> \<int> \<or> y \<in> \<int> \<Longrightarrow> \<lfloor>x + y\<rfloor> = \<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>" |
689 |
by (metis add.commute add.left_neutral frac_lt_1 floor_add frac_eq_0_iff) |
|
63597 | 690 |
|
63489 | 691 |
lemma frac_add: |
692 |
"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
|
693 |
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
|
694 |
|
63489 | 695 |
lemma frac_unique_iff: "frac x = a \<longleftrightarrow> x - a \<in> \<int> \<and> 0 \<le> a \<and> a < 1" |
696 |
for x :: "'a::floor_ceiling" |
|
82689
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
697 |
by (auto simp: Ints_def frac_def algebra_simps floor_unique; linarith) |
59613
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_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
|
700 |
by (simp add: frac_unique_iff) |
63331 | 701 |
|
82542
32a6228f543d
a few small lemmas for HOL and HOL-Analysis
Manuel Eberl <eberlm@in.tum.de>
parents:
82518
diff
changeset
|
702 |
lemma frac_eq_id [simp]: "x \<in> {0..<1} \<Longrightarrow> frac x = x" |
32a6228f543d
a few small lemmas for HOL and HOL-Analysis
Manuel Eberl <eberlm@in.tum.de>
parents:
82518
diff
changeset
|
703 |
by (simp add: frac_eq) |
32a6228f543d
a few small lemmas for HOL and HOL-Analysis
Manuel Eberl <eberlm@in.tum.de>
parents:
82518
diff
changeset
|
704 |
|
82689
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
705 |
lemma frac_in_Ints_iff [simp]: "frac x \<in> \<int> \<longleftrightarrow> x \<in> \<int>" |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
706 |
by (metis frac_eq_0_iff frac_frac) |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
707 |
|
63489 | 708 |
lemma frac_neg: "frac (- x) = (if x \<in> \<int> then 0 else 1 - frac x)" |
709 |
for x :: "'a::floor_ceiling" |
|
82689
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
710 |
unfolding frac_unique_iff using frac_lt_1 [of x] |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
711 |
apply (simp add: frac_def) |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
712 |
by (metis Ints_of_int floor_eq_iff nless_le) |
68721 | 713 |
|
70365
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
68721
diff
changeset
|
714 |
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
|
715 |
by (simp add: frac_def) |
4df0628e8545
a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents:
68721
diff
changeset
|
716 |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
717 |
|
78748
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
718 |
subsection \<open>Fractional part arithmetic\<close> |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
719 |
text \<open>Many thanks to Stepan Holub\<close> |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
720 |
|
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
721 |
lemma frac_non_zero: "frac x \<noteq> 0 \<Longrightarrow> frac (-x) = 1 - frac x" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
722 |
using frac_eq_0_iff frac_neg by metis |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
723 |
|
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
724 |
lemma frac_add_simps [simp]: |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
725 |
"frac (frac a + b) = frac (a + b)" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
726 |
"frac (a + frac b) = frac (a + b)" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
727 |
by (simp_all add: frac_add) |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
728 |
|
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
729 |
lemma frac_neg_frac: "frac (- frac x) = frac (-x)" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
730 |
unfolding frac_neg frac_frac by force |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
731 |
|
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
732 |
lemma frac_diff_simp: "frac (y - frac x) = frac (y - x)" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
733 |
unfolding diff_conv_add_uminus frac_add frac_neg_frac.. |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
734 |
|
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
735 |
lemma frac_diff: "frac (a - b) = frac (frac a + (- frac b))" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
736 |
unfolding frac_add_simps(1) |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
737 |
unfolding ab_group_add_class.ab_diff_conv_add_uminus[symmetric] frac_diff_simp.. |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
738 |
|
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
739 |
lemma frac_diff_pos: "frac x \<le> frac y \<Longrightarrow> frac (y - x) = frac y - frac x" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
740 |
unfolding diff_conv_add_uminus frac_add frac_neg |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
741 |
using frac_lt_1 by force |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
742 |
|
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
743 |
lemma frac_diff_neg: assumes "frac y < frac x" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
744 |
shows "frac (y - x) = frac y + 1 - frac x" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
745 |
proof- |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
746 |
have "x \<notin> \<int>" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
747 |
unfolding frac_gt_0_iff[symmetric] |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
748 |
using assms frac_ge_0[of y] by order |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
749 |
have "frac y + (1 + - frac x) < 1" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
750 |
using frac_lt_1[of x] assms by fastforce |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
751 |
show ?thesis |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
752 |
unfolding diff_conv_add_uminus frac_add frac_neg |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
753 |
if_not_P[OF \<open>x \<notin> \<int>\<close>] if_P[OF \<open>frac y + (1 + - frac x) < 1\<close>] |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
754 |
by simp |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
755 |
qed |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
756 |
|
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
757 |
lemma frac_diff_eq: assumes "frac y = frac x" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
758 |
shows "frac (y - x) = 0" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
759 |
by (simp add: assms frac_diff_pos) |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
760 |
|
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
761 |
lemma frac_diff_zero: assumes "frac (x - y) = 0" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
762 |
shows "frac x = frac y" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
763 |
using frac_add_simps(1)[of "x - y" y, symmetric] |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
764 |
unfolding assms add.group_left_neutral diff_add_cancel. |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
765 |
|
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
766 |
lemma frac_neg_eq_iff: "frac (-x) = frac (-y) \<longleftrightarrow> frac x = frac y" |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
767 |
using add.inverse_inverse frac_neg_frac by metis |
ca486ee0e4c5
New proofs also some slightly faster existing proofs
paulson <lp15@cam.ac.uk>
parents:
77934
diff
changeset
|
768 |
|
82518
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
769 |
lemma frac_eqE: |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
770 |
assumes "frac x = frac y" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
771 |
obtains n where "x = y + of_int n" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
772 |
by (rule that[of "floor x - floor y"]) (use assms in \<open>auto simp: frac_def\<close>) |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
773 |
|
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
774 |
lemma frac_add_of_int_right [simp]: "frac (x + of_int n) = frac x" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
775 |
by (auto simp: frac_def) |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
776 |
|
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
777 |
lemma frac_add_of_int_left [simp]: "frac (of_int n + x) = frac x" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
778 |
by (auto simp: frac_def) |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
779 |
|
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
780 |
lemma frac_add_int_right: "y \<in> \<int> \<Longrightarrow> frac (x + y) = frac x" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
781 |
by (elim Ints_cases) auto |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
782 |
|
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
783 |
lemma frac_add_int_left: "x \<in> \<int> \<Longrightarrow> frac (x + y) = frac y" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
784 |
by (elim Ints_cases) auto |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
785 |
|
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
786 |
lemma bij_betw_frac: "bij_betw frac {x..<x+1} {0..<1}" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
787 |
unfolding bij_betw_def |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
788 |
proof |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
789 |
show "inj_on frac {x..<x+1}" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
790 |
proof |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
791 |
fix a b assume *: "a \<in> {x..<x+1}" "b \<in> {x..<x+1}" "frac a = frac b" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
792 |
then obtain n where n: "a = b + of_int n" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
793 |
by (elim frac_eqE) |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
794 |
have "\<bar>of_int n\<bar> = \<bar>a - b\<bar>" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
795 |
using n by (simp add: algebra_simps) |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
796 |
also have "\<dots> < 1" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
797 |
using * by auto |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
798 |
finally have "n = 0" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
799 |
by (simp flip: of_int_abs) |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
800 |
with n show "a = b" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
801 |
by auto |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
802 |
qed |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
803 |
next |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
804 |
show "frac ` {x..<x + 1} = {0..<1}" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
805 |
proof (intro equalityI subsetI) |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
806 |
fix t :: 'a assume t: "t \<in> {0..<1}" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
807 |
have "t = frac (if t \<ge> frac x then x + t - frac x else x + t - frac x + 1)" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
808 |
using frac_eq[of t] t by (auto simp: frac_def) |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
809 |
moreover have "(if t \<ge> frac x then x + t - frac x else x + t - frac x + 1) \<in> {x..<x+1}" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
810 |
using frac_lt_1[of x] frac_ge_0[of x] t by (auto simp del: frac_ge_0) |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
811 |
ultimately show "t \<in> frac ` {x..<x + 1}" |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
812 |
by blast |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
813 |
qed (auto intro: frac_lt_1) |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
814 |
qed |
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
815 |
|
da14e77a48b2
lots of lemmas for HOL, HOL-{Complex_}Analysis, HOL-Number_Theory
Manuel Eberl <manuel@pruvisto.org>
parents:
81125
diff
changeset
|
816 |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
817 |
subsection \<open>Rounding to the nearest integer\<close> |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
818 |
|
63489 | 819 |
definition round :: "'a::floor_ceiling \<Rightarrow> int" |
820 |
where "round x = \<lfloor>x + 1/2\<rfloor>" |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
821 |
|
82689
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
822 |
lemma round_eq_imp_diff_1: "round x = round y \<Longrightarrow> \<bar>x-y\<bar> < 1" |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
823 |
unfolding round_def |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
824 |
using floor_eq_imp_diff_1 by fastforce |
817f97d8cd26
New lemmas for floor/ceiling/round, plus tidying
paulson <lp15@cam.ac.uk>
parents:
82542
diff
changeset
|
825 |
|
63489 | 826 |
lemma of_int_round_ge: "of_int (round x) \<ge> x - 1/2" |
827 |
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
|
828 |
and of_int_round_abs_le: "\<bar>of_int (round x) - x\<bar> \<le> 1/2" |
63489 | 829 |
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
|
830 |
proof - |
63489 | 831 |
from floor_correct[of "x + 1/2"] have "x + 1/2 < of_int (round x) + 1" |
832 |
by (simp add: round_def) |
|
833 |
from add_strict_right_mono[OF this, of "-1"] show A: "of_int (round x) > x - 1/2" |
|
834 |
by simp |
|
835 |
then show "of_int (round x) \<ge> x - 1/2" |
|
836 |
by simp |
|
837 |
from floor_correct[of "x + 1/2"] show "of_int (round x) \<le> x + 1/2" |
|
838 |
by (simp add: round_def) |
|
839 |
with A show "\<bar>of_int (round x) - x\<bar> \<le> 1/2" |
|
840 |
by linarith |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
841 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
842 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
843 |
lemma round_of_int [simp]: "round (of_int n) = n" |
66515 | 844 |
unfolding round_def by (subst floor_eq_iff) force |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
845 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
846 |
lemma round_0 [simp]: "round 0 = 0" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
847 |
using round_of_int[of 0] by simp |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
848 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
849 |
lemma round_1 [simp]: "round 1 = 1" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
850 |
using round_of_int[of 1] by simp |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
851 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
852 |
lemma round_numeral [simp]: "round (numeral n) = numeral n" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
853 |
using round_of_int[of "numeral n"] by simp |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
854 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
855 |
lemma round_neg_numeral [simp]: "round (-numeral n) = -numeral n" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
856 |
using round_of_int[of "-numeral n"] by simp |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
857 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
858 |
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
|
859 |
using round_of_int[of "int n"] by simp |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
860 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
861 |
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
|
862 |
unfolding round_def by (intro floor_mono) simp |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
863 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
864 |
lemma round_unique: "of_int y > x - 1/2 \<Longrightarrow> of_int y \<le> x + 1/2 \<Longrightarrow> round x = y" |
63489 | 865 |
unfolding round_def |
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
866 |
proof (rule floor_unique) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
867 |
assume "x - 1 / 2 < of_int y" |
63489 | 868 |
from add_strict_left_mono[OF this, of 1] show "x + 1 / 2 < of_int y + 1" |
869 |
by simp |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
870 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
871 |
|
64317 | 872 |
lemma round_unique': "\<bar>x - of_int n\<bar> < 1/2 \<Longrightarrow> round x = n" |
873 |
by (subst (asm) abs_less_iff, rule round_unique) (simp_all add: field_simps) |
|
874 |
||
61942 | 875 |
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
|
876 |
by (cases "frac x \<ge> 1/2") |
63489 | 877 |
(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
|
878 |
|
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
879 |
lemma floor_le_round: "\<lfloor>x\<rfloor> \<le> round x" |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
880 |
unfolding round_def by (intro floor_mono) simp |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
881 |
|
63489 | 882 |
lemma ceiling_ge_round: "\<lceil>x\<rceil> \<ge> round x" |
883 |
unfolding round_altdef by simp |
|
63331 | 884 |
|
63489 | 885 |
lemma round_diff_minimal: "\<bar>z - of_int (round z)\<bar> \<le> \<bar>z - of_int m\<bar>" |
886 |
for z :: "'a::floor_ceiling" |
|
61531
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
887 |
proof (cases "of_int m \<ge> z") |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
888 |
case True |
63489 | 889 |
then have "\<bar>z - of_int (round z)\<bar> \<le> \<bar>of_int \<lceil>z\<rceil> - z\<bar>" |
890 |
unfolding round_altdef by (simp add: field_simps ceiling_altdef frac_def) linarith |
|
891 |
also have "of_int \<lceil>z\<rceil> - z \<ge> 0" |
|
892 |
by linarith |
|
61942 | 893 |
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
|
894 |
by (simp add: ceiling_le_iff) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
895 |
finally show ?thesis . |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
896 |
next |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
897 |
case False |
63489 | 898 |
then have "\<bar>z - of_int (round z)\<bar> \<le> \<bar>of_int \<lfloor>z\<rfloor> - z\<bar>" |
899 |
unfolding round_altdef by (simp add: field_simps ceiling_altdef frac_def) linarith |
|
900 |
also have "z - of_int \<lfloor>z\<rfloor> \<ge> 0" |
|
901 |
by linarith |
|
61942 | 902 |
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
|
903 |
by (simp add: le_floor_iff) |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
904 |
finally show ?thesis . |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
905 |
qed |
ab2e862263e7
Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents:
61378
diff
changeset
|
906 |
|
81125 | 907 |
bundle floor_ceiling_syntax |
908 |
begin |
|
909 |
notation floor (\<open>(\<open>open_block notation=\<open>mixfix floor\<close>\<close>\<lfloor>_\<rfloor>)\<close>) |
|
910 |
and ceiling (\<open>(\<open>open_block notation=\<open>mixfix ceiling\<close>\<close>\<lceil>_\<rceil>)\<close>) |
|
30096 | 911 |
end |
81125 | 912 |
|
913 |
end |