author huffman Wed Feb 25 11:26:01 2009 -0800 (2009-02-25) changeset 30096 c5497842ee35 parent 30095 c6e184561159 child 30097 57df8626c23b
new theory of Archimedean fields
 src/HOL/Archimedean_Field.thy file | annotate | diff | revisions src/HOL/IsaMakefile file | annotate | diff | revisions
```     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/HOL/Archimedean_Field.thy	Wed Feb 25 11:26:01 2009 -0800
1.3 @@ -0,0 +1,400 @@
1.4 +(* Title:      Archimedean_Field.thy
1.5 +   Author:     Brian Huffman
1.6 +*)
1.7 +
1.8 +header {* Archimedean Fields, Floor and Ceiling Functions *}
1.9 +
1.10 +theory Archimedean_Field
1.11 +imports Main
1.12 +begin
1.13 +
1.14 +subsection {* Class of Archimedean fields *}
1.15 +
1.16 +text {* Archimedean fields have no infinite elements. *}
1.17 +
1.18 +class archimedean_field = ordered_field + number_ring +
1.19 +  assumes ex_le_of_int: "\<exists>z. x \<le> of_int z"
1.20 +
1.21 +lemma ex_less_of_int:
1.22 +  fixes x :: "'a::archimedean_field" shows "\<exists>z. x < of_int z"
1.23 +proof -
1.24 +  from ex_le_of_int obtain z where "x \<le> of_int z" ..
1.25 +  then have "x < of_int (z + 1)" by simp
1.26 +  then show ?thesis ..
1.27 +qed
1.28 +
1.29 +lemma ex_of_int_less:
1.30 +  fixes x :: "'a::archimedean_field" shows "\<exists>z. of_int z < x"
1.31 +proof -
1.32 +  from ex_less_of_int obtain z where "- x < of_int z" ..
1.33 +  then have "of_int (- z) < x" by simp
1.34 +  then show ?thesis ..
1.35 +qed
1.36 +
1.37 +lemma ex_less_of_nat:
1.38 +  fixes x :: "'a::archimedean_field" shows "\<exists>n. x < of_nat n"
1.39 +proof -
1.40 +  obtain z where "x < of_int z" using ex_less_of_int ..
1.41 +  also have "\<dots> \<le> of_int (int (nat z))" by simp
1.42 +  also have "\<dots> = of_nat (nat z)" by (simp only: of_int_of_nat_eq)
1.43 +  finally show ?thesis ..
1.44 +qed
1.45 +
1.46 +lemma ex_le_of_nat:
1.47 +  fixes x :: "'a::archimedean_field" shows "\<exists>n. x \<le> of_nat n"
1.48 +proof -
1.49 +  obtain n where "x < of_nat n" using ex_less_of_nat ..
1.50 +  then have "x \<le> of_nat n" by simp
1.51 +  then show ?thesis ..
1.52 +qed
1.53 +
1.54 +text {* Archimedean fields have no infinitesimal elements. *}
1.55 +
1.56 +lemma ex_inverse_of_nat_Suc_less:
1.57 +  fixes x :: "'a::archimedean_field"
1.58 +  assumes "0 < x" shows "\<exists>n. inverse (of_nat (Suc n)) < x"
1.59 +proof -
1.60 +  from `0 < x` have "0 < inverse x"
1.61 +    by (rule positive_imp_inverse_positive)
1.62 +  obtain n where "inverse x < of_nat n"
1.63 +    using ex_less_of_nat ..
1.64 +  then obtain m where "inverse x < of_nat (Suc m)"
1.65 +    using `0 < inverse x` by (cases n) (simp_all del: of_nat_Suc)
1.66 +  then have "inverse (of_nat (Suc m)) < inverse (inverse x)"
1.67 +    using `0 < inverse x` by (rule less_imp_inverse_less)
1.68 +  then have "inverse (of_nat (Suc m)) < x"
1.69 +    using `0 < x` by (simp add: nonzero_inverse_inverse_eq)
1.70 +  then show ?thesis ..
1.71 +qed
1.72 +
1.73 +lemma ex_inverse_of_nat_less:
1.74 +  fixes x :: "'a::archimedean_field"
1.75 +  assumes "0 < x" shows "\<exists>n>0. inverse (of_nat n) < x"
1.76 +  using ex_inverse_of_nat_Suc_less [OF `0 < x`] by auto
1.77 +
1.78 +lemma ex_less_of_nat_mult:
1.79 +  fixes x :: "'a::archimedean_field"
1.80 +  assumes "0 < x" shows "\<exists>n. y < of_nat n * x"
1.81 +proof -
1.82 +  obtain n where "y / x < of_nat n" using ex_less_of_nat ..
1.83 +  with `0 < x` have "y < of_nat n * x" by (simp add: pos_divide_less_eq)
1.84 +  then show ?thesis ..
1.85 +qed
1.86 +
1.87 +
1.88 +subsection {* Existence and uniqueness of floor function *}
1.89 +
1.90 +lemma exists_least_lemma:
1.91 +  assumes "\<not> P 0" and "\<exists>n. P n"
1.92 +  shows "\<exists>n. \<not> P n \<and> P (Suc n)"
1.93 +proof -
1.94 +  from `\<exists>n. P n` have "P (Least P)" by (rule LeastI_ex)
1.95 +  with `\<not> P 0` obtain n where "Least P = Suc n"
1.96 +    by (cases "Least P") auto
1.97 +  then have "n < Least P" by simp
1.98 +  then have "\<not> P n" by (rule not_less_Least)
1.99 +  then have "\<not> P n \<and> P (Suc n)"
1.100 +    using `P (Least P)` `Least P = Suc n` by simp
1.101 +  then show ?thesis ..
1.102 +qed
1.103 +
1.104 +lemma floor_exists:
1.105 +  fixes x :: "'a::archimedean_field"
1.106 +  shows "\<exists>z. of_int z \<le> x \<and> x < of_int (z + 1)"
1.107 +proof (cases)
1.108 +  assume "0 \<le> x"
1.109 +  then have "\<not> x < of_nat 0" by simp
1.110 +  then have "\<exists>n. \<not> x < of_nat n \<and> x < of_nat (Suc n)"
1.111 +    using ex_less_of_nat by (rule exists_least_lemma)
1.112 +  then obtain n where "\<not> x < of_nat n \<and> x < of_nat (Suc n)" ..
1.113 +  then have "of_int (int n) \<le> x \<and> x < of_int (int n + 1)" by simp
1.114 +  then show ?thesis ..
1.115 +next
1.116 +  assume "\<not> 0 \<le> x"
1.117 +  then have "\<not> - x \<le> of_nat 0" by simp
1.118 +  then have "\<exists>n. \<not> - x \<le> of_nat n \<and> - x \<le> of_nat (Suc n)"
1.119 +    using ex_le_of_nat by (rule exists_least_lemma)
1.120 +  then obtain n where "\<not> - x \<le> of_nat n \<and> - x \<le> of_nat (Suc n)" ..
1.121 +  then have "of_int (- int n - 1) \<le> x \<and> x < of_int (- int n - 1 + 1)" by simp
1.122 +  then show ?thesis ..
1.123 +qed
1.124 +
1.125 +lemma floor_exists1:
1.126 +  fixes x :: "'a::archimedean_field"
1.127 +  shows "\<exists>!z. of_int z \<le> x \<and> x < of_int (z + 1)"
1.128 +proof (rule ex_ex1I)
1.129 +  show "\<exists>z. of_int z \<le> x \<and> x < of_int (z + 1)"
1.130 +    by (rule floor_exists)
1.131 +next
1.132 +  fix y z assume
1.133 +    "of_int y \<le> x \<and> x < of_int (y + 1)"
1.134 +    "of_int z \<le> x \<and> x < of_int (z + 1)"
1.135 +  then have
1.136 +    "of_int y \<le> x" "x < of_int (y + 1)"
1.137 +    "of_int z \<le> x" "x < of_int (z + 1)"
1.138 +    by simp_all
1.139 +  from le_less_trans [OF `of_int y \<le> x` `x < of_int (z + 1)`]
1.140 +       le_less_trans [OF `of_int z \<le> x` `x < of_int (y + 1)`]
1.141 +  show "y = z" by (simp del: of_int_add)
1.142 +qed
1.143 +
1.144 +
1.145 +subsection {* Floor function *}
1.146 +
1.147 +definition
1.148 +  floor :: "'a::archimedean_field \<Rightarrow> int" where
1.149 +  [code del]: "floor x = (THE z. of_int z \<le> x \<and> x < of_int (z + 1))"
1.150 +
1.151 +notation (xsymbols)
1.152 +  floor  ("\<lfloor>_\<rfloor>")
1.153 +
1.154 +notation (HTML output)
1.155 +  floor  ("\<lfloor>_\<rfloor>")
1.156 +
1.157 +lemma floor_correct: "of_int (floor x) \<le> x \<and> x < of_int (floor x + 1)"
1.158 +  unfolding floor_def using floor_exists1 by (rule theI')
1.159 +
1.160 +lemma floor_unique: "\<lbrakk>of_int z \<le> x; x < of_int z + 1\<rbrakk> \<Longrightarrow> floor x = z"
1.161 +  using floor_correct [of x] floor_exists1 [of x] by auto
1.162 +
1.163 +lemma of_int_floor_le: "of_int (floor x) \<le> x"
1.164 +  using floor_correct ..
1.165 +
1.166 +lemma le_floor_iff: "z \<le> floor x \<longleftrightarrow> of_int z \<le> x"
1.167 +proof
1.168 +  assume "z \<le> floor x"
1.169 +  then have "(of_int z :: 'a) \<le> of_int (floor x)" by simp
1.170 +  also have "of_int (floor x) \<le> x" by (rule of_int_floor_le)
1.171 +  finally show "of_int z \<le> x" .
1.172 +next
1.173 +  assume "of_int z \<le> x"
1.174 +  also have "x < of_int (floor x + 1)" using floor_correct ..
1.175 +  finally show "z \<le> floor x" by (simp del: of_int_add)
1.176 +qed
1.177 +
1.178 +lemma floor_less_iff: "floor x < z \<longleftrightarrow> x < of_int z"
1.179 +  by (simp add: not_le [symmetric] le_floor_iff)
1.180 +
1.181 +lemma less_floor_iff: "z < floor x \<longleftrightarrow> of_int z + 1 \<le> x"
1.182 +  using le_floor_iff [of "z + 1" x] by auto
1.183 +
1.184 +lemma floor_le_iff: "floor x \<le> z \<longleftrightarrow> x < of_int z + 1"
1.185 +  by (simp add: not_less [symmetric] less_floor_iff)
1.186 +
1.187 +lemma floor_mono: assumes "x \<le> y" shows "floor x \<le> floor y"
1.188 +proof -
1.189 +  have "of_int (floor x) \<le> x" by (rule of_int_floor_le)
1.190 +  also note `x \<le> y`
1.191 +  finally show ?thesis by (simp add: le_floor_iff)
1.192 +qed
1.193 +
1.194 +lemma floor_less_cancel: "floor x < floor y \<Longrightarrow> x < y"
1.195 +  by (auto simp add: not_le [symmetric] floor_mono)
1.196 +
1.197 +lemma floor_of_int [simp]: "floor (of_int z) = z"
1.198 +  by (rule floor_unique) simp_all
1.199 +
1.200 +lemma floor_of_nat [simp]: "floor (of_nat n) = int n"
1.201 +  using floor_of_int [of "of_nat n"] by simp
1.202 +
1.203 +text {* Floor with numerals *}
1.204 +
1.205 +lemma floor_zero [simp]: "floor 0 = 0"
1.206 +  using floor_of_int [of 0] by simp
1.207 +
1.208 +lemma floor_one [simp]: "floor 1 = 1"
1.209 +  using floor_of_int [of 1] by simp
1.210 +
1.211 +lemma floor_number_of [simp]: "floor (number_of v) = number_of v"
1.212 +  using floor_of_int [of "number_of v"] by simp
1.213 +
1.214 +lemma zero_le_floor [simp]: "0 \<le> floor x \<longleftrightarrow> 0 \<le> x"
1.215 +  by (simp add: le_floor_iff)
1.216 +
1.217 +lemma one_le_floor [simp]: "1 \<le> floor x \<longleftrightarrow> 1 \<le> x"
1.218 +  by (simp add: le_floor_iff)
1.219 +
1.220 +lemma number_of_le_floor [simp]: "number_of v \<le> floor x \<longleftrightarrow> number_of v \<le> x"
1.221 +  by (simp add: le_floor_iff)
1.222 +
1.223 +lemma zero_less_floor [simp]: "0 < floor x \<longleftrightarrow> 1 \<le> x"
1.224 +  by (simp add: less_floor_iff)
1.225 +
1.226 +lemma one_less_floor [simp]: "1 < floor x \<longleftrightarrow> 2 \<le> x"
1.227 +  by (simp add: less_floor_iff)
1.228 +
1.229 +lemma number_of_less_floor [simp]:
1.230 +  "number_of v < floor x \<longleftrightarrow> number_of v + 1 \<le> x"
1.231 +  by (simp add: less_floor_iff)
1.232 +
1.233 +lemma floor_le_zero [simp]: "floor x \<le> 0 \<longleftrightarrow> x < 1"
1.234 +  by (simp add: floor_le_iff)
1.235 +
1.236 +lemma floor_le_one [simp]: "floor x \<le> 1 \<longleftrightarrow> x < 2"
1.237 +  by (simp add: floor_le_iff)
1.238 +
1.239 +lemma floor_le_number_of [simp]:
1.240 +  "floor x \<le> number_of v \<longleftrightarrow> x < number_of v + 1"
1.241 +  by (simp add: floor_le_iff)
1.242 +
1.243 +lemma floor_less_zero [simp]: "floor x < 0 \<longleftrightarrow> x < 0"
1.244 +  by (simp add: floor_less_iff)
1.245 +
1.246 +lemma floor_less_one [simp]: "floor x < 1 \<longleftrightarrow> x < 1"
1.247 +  by (simp add: floor_less_iff)
1.248 +
1.249 +lemma floor_less_number_of [simp]:
1.250 +  "floor x < number_of v \<longleftrightarrow> x < number_of v"
1.251 +  by (simp add: floor_less_iff)
1.252 +
1.253 +text {* Addition and subtraction of integers *}
1.254 +
1.255 +lemma floor_add_of_int [simp]: "floor (x + of_int z) = floor x + z"
1.256 +  using floor_correct [of x] by (simp add: floor_unique)
1.257 +
1.259 +    "floor (x + number_of v) = floor x + number_of v"
1.260 +  using floor_add_of_int [of x "number_of v"] by simp
1.261 +
1.262 +lemma floor_add_one [simp]: "floor (x + 1) = floor x + 1"
1.263 +  using floor_add_of_int [of x 1] by simp
1.264 +
1.265 +lemma floor_diff_of_int [simp]: "floor (x - of_int z) = floor x - z"
1.266 +  using floor_add_of_int [of x "- z"] by (simp add: algebra_simps)
1.267 +
1.268 +lemma floor_diff_number_of [simp]:
1.269 +  "floor (x - number_of v) = floor x - number_of v"
1.270 +  using floor_diff_of_int [of x "number_of v"] by simp
1.271 +
1.272 +lemma floor_diff_one [simp]: "floor (x - 1) = floor x - 1"
1.273 +  using floor_diff_of_int [of x 1] by simp
1.274 +
1.275 +
1.276 +subsection {* Ceiling function *}
1.277 +
1.278 +definition
1.279 +  ceiling :: "'a::archimedean_field \<Rightarrow> int" where
1.280 +  [code del]: "ceiling x = - floor (- x)"
1.281 +
1.282 +notation (xsymbols)
1.283 +  ceiling  ("\<lceil>_\<rceil>")
1.284 +
1.285 +notation (HTML output)
1.286 +  ceiling  ("\<lceil>_\<rceil>")
1.287 +
1.288 +lemma ceiling_correct: "of_int (ceiling x) - 1 < x \<and> x \<le> of_int (ceiling x)"
1.289 +  unfolding ceiling_def using floor_correct [of "- x"] by simp
1.290 +
1.291 +lemma ceiling_unique: "\<lbrakk>of_int z - 1 < x; x \<le> of_int z\<rbrakk> \<Longrightarrow> ceiling x = z"
1.292 +  unfolding ceiling_def using floor_unique [of "- z" "- x"] by simp
1.293 +
1.294 +lemma le_of_int_ceiling: "x \<le> of_int (ceiling x)"
1.295 +  using ceiling_correct ..
1.296 +
1.297 +lemma ceiling_le_iff: "ceiling x \<le> z \<longleftrightarrow> x \<le> of_int z"
1.298 +  unfolding ceiling_def using le_floor_iff [of "- z" "- x"] by auto
1.299 +
1.300 +lemma less_ceiling_iff: "z < ceiling x \<longleftrightarrow> of_int z < x"
1.301 +  by (simp add: not_le [symmetric] ceiling_le_iff)
1.302 +
1.303 +lemma ceiling_less_iff: "ceiling x < z \<longleftrightarrow> x \<le> of_int z - 1"
1.304 +  using ceiling_le_iff [of x "z - 1"] by simp
1.305 +
1.306 +lemma le_ceiling_iff: "z \<le> ceiling x \<longleftrightarrow> of_int z - 1 < x"
1.307 +  by (simp add: not_less [symmetric] ceiling_less_iff)
1.308 +
1.309 +lemma ceiling_mono: "x \<ge> y \<Longrightarrow> ceiling x \<ge> ceiling y"
1.310 +  unfolding ceiling_def by (simp add: floor_mono)
1.311 +
1.312 +lemma ceiling_less_cancel: "ceiling x < ceiling y \<Longrightarrow> x < y"
1.313 +  by (auto simp add: not_le [symmetric] ceiling_mono)
1.314 +
1.315 +lemma ceiling_of_int [simp]: "ceiling (of_int z) = z"
1.316 +  by (rule ceiling_unique) simp_all
1.317 +
1.318 +lemma ceiling_of_nat [simp]: "ceiling (of_nat n) = int n"
1.319 +  using ceiling_of_int [of "of_nat n"] by simp
1.320 +
1.321 +text {* Ceiling with numerals *}
1.322 +
1.323 +lemma ceiling_zero [simp]: "ceiling 0 = 0"
1.324 +  using ceiling_of_int [of 0] by simp
1.325 +
1.326 +lemma ceiling_one [simp]: "ceiling 1 = 1"
1.327 +  using ceiling_of_int [of 1] by simp
1.328 +
1.329 +lemma ceiling_number_of [simp]: "ceiling (number_of v) = number_of v"
1.330 +  using ceiling_of_int [of "number_of v"] by simp
1.331 +
1.332 +lemma ceiling_le_zero [simp]: "ceiling x \<le> 0 \<longleftrightarrow> x \<le> 0"
1.333 +  by (simp add: ceiling_le_iff)
1.334 +
1.335 +lemma ceiling_le_one [simp]: "ceiling x \<le> 1 \<longleftrightarrow> x \<le> 1"
1.336 +  by (simp add: ceiling_le_iff)
1.337 +
1.338 +lemma ceiling_le_number_of [simp]:
1.339 +  "ceiling x \<le> number_of v \<longleftrightarrow> x \<le> number_of v"
1.340 +  by (simp add: ceiling_le_iff)
1.341 +
1.342 +lemma ceiling_less_zero [simp]: "ceiling x < 0 \<longleftrightarrow> x \<le> -1"
1.343 +  by (simp add: ceiling_less_iff)
1.344 +
1.345 +lemma ceiling_less_one [simp]: "ceiling x < 1 \<longleftrightarrow> x \<le> 0"
1.346 +  by (simp add: ceiling_less_iff)
1.347 +
1.348 +lemma ceiling_less_number_of [simp]:
1.349 +  "ceiling x < number_of v \<longleftrightarrow> x \<le> number_of v - 1"
1.350 +  by (simp add: ceiling_less_iff)
1.351 +
1.352 +lemma zero_le_ceiling [simp]: "0 \<le> ceiling x \<longleftrightarrow> -1 < x"
1.353 +  by (simp add: le_ceiling_iff)
1.354 +
1.355 +lemma one_le_ceiling [simp]: "1 \<le> ceiling x \<longleftrightarrow> 0 < x"
1.356 +  by (simp add: le_ceiling_iff)
1.357 +
1.358 +lemma number_of_le_ceiling [simp]:
1.359 +  "number_of v \<le> ceiling x\<longleftrightarrow> number_of v - 1 < x"
1.360 +  by (simp add: le_ceiling_iff)
1.361 +
1.362 +lemma zero_less_ceiling [simp]: "0 < ceiling x \<longleftrightarrow> 0 < x"
1.363 +  by (simp add: less_ceiling_iff)
1.364 +
1.365 +lemma one_less_ceiling [simp]: "1 < ceiling x \<longleftrightarrow> 1 < x"
1.366 +  by (simp add: less_ceiling_iff)
1.367 +
1.368 +lemma number_of_less_ceiling [simp]:
1.369 +  "number_of v < ceiling x \<longleftrightarrow> number_of v < x"
1.370 +  by (simp add: less_ceiling_iff)
1.371 +
1.372 +text {* Addition and subtraction of integers *}
1.373 +
1.374 +lemma ceiling_add_of_int [simp]: "ceiling (x + of_int z) = ceiling x + z"
1.375 +  using ceiling_correct [of x] by (simp add: ceiling_unique)
1.376 +
1.378 +    "ceiling (x + number_of v) = ceiling x + number_of v"
1.379 +  using ceiling_add_of_int [of x "number_of v"] by simp
1.380 +
1.381 +lemma ceiling_add_one [simp]: "ceiling (x + 1) = ceiling x + 1"
1.382 +  using ceiling_add_of_int [of x 1] by simp
1.383 +
1.384 +lemma ceiling_diff_of_int [simp]: "ceiling (x - of_int z) = ceiling x - z"
1.385 +  using ceiling_add_of_int [of x "- z"] by (simp add: algebra_simps)
1.386 +
1.387 +lemma ceiling_diff_number_of [simp]:
1.388 +  "ceiling (x - number_of v) = ceiling x - number_of v"
1.389 +  using ceiling_diff_of_int [of x "number_of v"] by simp
1.390 +
1.391 +lemma ceiling_diff_one [simp]: "ceiling (x - 1) = ceiling x - 1"
1.392 +  using ceiling_diff_of_int [of x 1] by simp
1.393 +
1.394 +
1.395 +subsection {* Negation *}
1.396 +
1.397 +lemma floor_minus [simp]: "floor (- x) = - ceiling x"
1.398 +  unfolding ceiling_def by simp
1.399 +
1.400 +lemma ceiling_minus [simp]: "ceiling (- x) = - floor x"
1.401 +  unfolding ceiling_def by simp
1.402 +
1.403 +end
```
```     2.1 --- a/src/HOL/IsaMakefile	Wed Feb 25 09:09:50 2009 -0800
2.2 +++ b/src/HOL/IsaMakefile	Wed Feb 25 11:26:01 2009 -0800
2.3 @@ -267,6 +267,7 @@
2.4  	@\$(ISABELLE_TOOL) usedir -b -f main.ML -g true \$(OUT)/Pure HOL-Main
2.5
2.6  \$(OUT)/HOL: ROOT.ML \$(MAIN_DEPENDENCIES) \
2.7 +  Archimedean_Field.thy \
2.8    Complex_Main.thy \
2.9    Complex.thy \
2.10    Deriv.thy \
```