src/HOL/Archimedean_Field.thy
 author hoelzl Wed Apr 18 14:29:05 2012 +0200 (2012-04-18) changeset 47592 a6b76247534d parent 47307 5e5ca36692b3 child 54281 b01057e72233 permissions -rw-r--r--
 wenzelm@41959 ` 1` ```(* Title: HOL/Archimedean_Field.thy ``` wenzelm@41959 ` 2` ``` Author: Brian Huffman ``` huffman@30096 ` 3` ```*) ``` huffman@30096 ` 4` huffman@30096 ` 5` ```header {* Archimedean Fields, Floor and Ceiling Functions *} ``` huffman@30096 ` 6` huffman@30096 ` 7` ```theory Archimedean_Field ``` huffman@30096 ` 8` ```imports Main ``` huffman@30096 ` 9` ```begin ``` huffman@30096 ` 10` huffman@30096 ` 11` ```subsection {* Class of Archimedean fields *} ``` huffman@30096 ` 12` huffman@30096 ` 13` ```text {* Archimedean fields have no infinite elements. *} ``` huffman@30096 ` 14` huffman@47108 ` 15` ```class archimedean_field = linordered_field + ``` huffman@30096 ` 16` ``` assumes ex_le_of_int: "\z. x \ of_int z" ``` huffman@30096 ` 17` huffman@30096 ` 18` ```lemma ex_less_of_int: ``` huffman@30096 ` 19` ``` fixes x :: "'a::archimedean_field" shows "\z. x < of_int z" ``` huffman@30096 ` 20` ```proof - ``` huffman@30096 ` 21` ``` from ex_le_of_int obtain z where "x \ of_int z" .. ``` huffman@30096 ` 22` ``` then have "x < of_int (z + 1)" by simp ``` huffman@30096 ` 23` ``` then show ?thesis .. ``` huffman@30096 ` 24` ```qed ``` huffman@30096 ` 25` huffman@30096 ` 26` ```lemma ex_of_int_less: ``` huffman@30096 ` 27` ``` fixes x :: "'a::archimedean_field" shows "\z. of_int z < x" ``` huffman@30096 ` 28` ```proof - ``` huffman@30096 ` 29` ``` from ex_less_of_int obtain z where "- x < of_int z" .. ``` huffman@30096 ` 30` ``` then have "of_int (- z) < x" by simp ``` huffman@30096 ` 31` ``` then show ?thesis .. ``` huffman@30096 ` 32` ```qed ``` huffman@30096 ` 33` huffman@30096 ` 34` ```lemma ex_less_of_nat: ``` huffman@30096 ` 35` ``` fixes x :: "'a::archimedean_field" shows "\n. x < of_nat n" ``` huffman@30096 ` 36` ```proof - ``` huffman@30096 ` 37` ``` obtain z where "x < of_int z" using ex_less_of_int .. ``` huffman@30096 ` 38` ``` also have "\ \ of_int (int (nat z))" by simp ``` huffman@30096 ` 39` ``` also have "\ = of_nat (nat z)" by (simp only: of_int_of_nat_eq) ``` huffman@30096 ` 40` ``` finally show ?thesis .. ``` huffman@30096 ` 41` ```qed ``` huffman@30096 ` 42` huffman@30096 ` 43` ```lemma ex_le_of_nat: ``` huffman@30096 ` 44` ``` fixes x :: "'a::archimedean_field" shows "\n. x \ of_nat n" ``` huffman@30096 ` 45` ```proof - ``` huffman@30096 ` 46` ``` obtain n where "x < of_nat n" using ex_less_of_nat .. ``` huffman@30096 ` 47` ``` then have "x \ of_nat n" by simp ``` huffman@30096 ` 48` ``` then show ?thesis .. ``` huffman@30096 ` 49` ```qed ``` huffman@30096 ` 50` huffman@30096 ` 51` ```text {* Archimedean fields have no infinitesimal elements. *} ``` huffman@30096 ` 52` huffman@30096 ` 53` ```lemma ex_inverse_of_nat_Suc_less: ``` huffman@30096 ` 54` ``` fixes x :: "'a::archimedean_field" ``` huffman@30096 ` 55` ``` assumes "0 < x" shows "\n. inverse (of_nat (Suc n)) < x" ``` huffman@30096 ` 56` ```proof - ``` huffman@30096 ` 57` ``` from `0 < x` have "0 < inverse x" ``` huffman@30096 ` 58` ``` by (rule positive_imp_inverse_positive) ``` huffman@30096 ` 59` ``` obtain n where "inverse x < of_nat n" ``` huffman@30096 ` 60` ``` using ex_less_of_nat .. ``` huffman@30096 ` 61` ``` then obtain m where "inverse x < of_nat (Suc m)" ``` huffman@30096 ` 62` ``` using `0 < inverse x` by (cases n) (simp_all del: of_nat_Suc) ``` huffman@30096 ` 63` ``` then have "inverse (of_nat (Suc m)) < inverse (inverse x)" ``` huffman@30096 ` 64` ``` using `0 < inverse x` by (rule less_imp_inverse_less) ``` huffman@30096 ` 65` ``` then have "inverse (of_nat (Suc m)) < x" ``` huffman@30096 ` 66` ``` using `0 < x` by (simp add: nonzero_inverse_inverse_eq) ``` huffman@30096 ` 67` ``` then show ?thesis .. ``` huffman@30096 ` 68` ```qed ``` huffman@30096 ` 69` huffman@30096 ` 70` ```lemma ex_inverse_of_nat_less: ``` huffman@30096 ` 71` ``` fixes x :: "'a::archimedean_field" ``` huffman@30096 ` 72` ``` assumes "0 < x" shows "\n>0. inverse (of_nat n) < x" ``` huffman@30096 ` 73` ``` using ex_inverse_of_nat_Suc_less [OF `0 < x`] by auto ``` huffman@30096 ` 74` huffman@30096 ` 75` ```lemma ex_less_of_nat_mult: ``` huffman@30096 ` 76` ``` fixes x :: "'a::archimedean_field" ``` huffman@30096 ` 77` ``` assumes "0 < x" shows "\n. y < of_nat n * x" ``` huffman@30096 ` 78` ```proof - ``` huffman@30096 ` 79` ``` obtain n where "y / x < of_nat n" using ex_less_of_nat .. ``` huffman@30096 ` 80` ``` with `0 < x` have "y < of_nat n * x" by (simp add: pos_divide_less_eq) ``` huffman@30096 ` 81` ``` then show ?thesis .. ``` huffman@30096 ` 82` ```qed ``` huffman@30096 ` 83` huffman@30096 ` 84` huffman@30096 ` 85` ```subsection {* Existence and uniqueness of floor function *} ``` huffman@30096 ` 86` huffman@30096 ` 87` ```lemma exists_least_lemma: ``` huffman@30096 ` 88` ``` assumes "\ P 0" and "\n. P n" ``` huffman@30096 ` 89` ``` shows "\n. \ P n \ P (Suc n)" ``` huffman@30096 ` 90` ```proof - ``` huffman@30096 ` 91` ``` from `\n. P n` have "P (Least P)" by (rule LeastI_ex) ``` huffman@30096 ` 92` ``` with `\ P 0` obtain n where "Least P = Suc n" ``` huffman@30096 ` 93` ``` by (cases "Least P") auto ``` huffman@30096 ` 94` ``` then have "n < Least P" by simp ``` huffman@30096 ` 95` ``` then have "\ P n" by (rule not_less_Least) ``` huffman@30096 ` 96` ``` then have "\ P n \ P (Suc n)" ``` huffman@30096 ` 97` ``` using `P (Least P)` `Least P = Suc n` by simp ``` huffman@30096 ` 98` ``` then show ?thesis .. ``` huffman@30096 ` 99` ```qed ``` huffman@30096 ` 100` huffman@30096 ` 101` ```lemma floor_exists: ``` huffman@30096 ` 102` ``` fixes x :: "'a::archimedean_field" ``` huffman@30096 ` 103` ``` shows "\z. of_int z \ x \ x < of_int (z + 1)" ``` huffman@30096 ` 104` ```proof (cases) ``` huffman@30096 ` 105` ``` assume "0 \ x" ``` huffman@30096 ` 106` ``` then have "\ x < of_nat 0" by simp ``` huffman@30096 ` 107` ``` then have "\n. \ x < of_nat n \ x < of_nat (Suc n)" ``` huffman@30096 ` 108` ``` using ex_less_of_nat by (rule exists_least_lemma) ``` huffman@30096 ` 109` ``` then obtain n where "\ x < of_nat n \ x < of_nat (Suc n)" .. ``` huffman@30096 ` 110` ``` then have "of_int (int n) \ x \ x < of_int (int n + 1)" by simp ``` huffman@30096 ` 111` ``` then show ?thesis .. ``` huffman@30096 ` 112` ```next ``` huffman@30096 ` 113` ``` assume "\ 0 \ x" ``` huffman@30096 ` 114` ``` then have "\ - x \ of_nat 0" by simp ``` huffman@30096 ` 115` ``` then have "\n. \ - x \ of_nat n \ - x \ of_nat (Suc n)" ``` huffman@30096 ` 116` ``` using ex_le_of_nat by (rule exists_least_lemma) ``` huffman@30096 ` 117` ``` then obtain n where "\ - x \ of_nat n \ - x \ of_nat (Suc n)" .. ``` huffman@30096 ` 118` ``` then have "of_int (- int n - 1) \ x \ x < of_int (- int n - 1 + 1)" by simp ``` huffman@30096 ` 119` ``` then show ?thesis .. ``` huffman@30096 ` 120` ```qed ``` huffman@30096 ` 121` huffman@30096 ` 122` ```lemma floor_exists1: ``` huffman@30096 ` 123` ``` fixes x :: "'a::archimedean_field" ``` huffman@30096 ` 124` ``` shows "\!z. of_int z \ x \ x < of_int (z + 1)" ``` huffman@30096 ` 125` ```proof (rule ex_ex1I) ``` huffman@30096 ` 126` ``` show "\z. of_int z \ x \ x < of_int (z + 1)" ``` huffman@30096 ` 127` ``` by (rule floor_exists) ``` huffman@30096 ` 128` ```next ``` huffman@30096 ` 129` ``` fix y z assume ``` huffman@30096 ` 130` ``` "of_int y \ x \ x < of_int (y + 1)" ``` huffman@30096 ` 131` ``` "of_int z \ x \ x < of_int (z + 1)" ``` huffman@30096 ` 132` ``` then have ``` huffman@30096 ` 133` ``` "of_int y \ x" "x < of_int (y + 1)" ``` huffman@30096 ` 134` ``` "of_int z \ x" "x < of_int (z + 1)" ``` huffman@30096 ` 135` ``` by simp_all ``` huffman@30096 ` 136` ``` from le_less_trans [OF `of_int y \ x` `x < of_int (z + 1)`] ``` huffman@30096 ` 137` ``` le_less_trans [OF `of_int z \ x` `x < of_int (y + 1)`] ``` huffman@30096 ` 138` ``` show "y = z" by (simp del: of_int_add) ``` huffman@30096 ` 139` ```qed ``` huffman@30096 ` 140` huffman@30096 ` 141` huffman@30096 ` 142` ```subsection {* Floor function *} ``` huffman@30096 ` 143` bulwahn@43732 ` 144` ```class floor_ceiling = archimedean_field + ``` bulwahn@43732 ` 145` ``` fixes floor :: "'a \ int" ``` bulwahn@43732 ` 146` ``` assumes floor_correct: "of_int (floor x) \ x \ x < of_int (floor x + 1)" ``` huffman@30096 ` 147` huffman@30096 ` 148` ```notation (xsymbols) ``` huffman@30096 ` 149` ``` floor ("\_\") ``` huffman@30096 ` 150` huffman@30096 ` 151` ```notation (HTML output) ``` huffman@30096 ` 152` ``` floor ("\_\") ``` huffman@30096 ` 153` huffman@30096 ` 154` ```lemma floor_unique: "\of_int z \ x; x < of_int z + 1\ \ floor x = z" ``` huffman@30096 ` 155` ``` using floor_correct [of x] floor_exists1 [of x] by auto ``` huffman@30096 ` 156` huffman@30096 ` 157` ```lemma of_int_floor_le: "of_int (floor x) \ x" ``` huffman@30096 ` 158` ``` using floor_correct .. ``` huffman@30096 ` 159` huffman@30096 ` 160` ```lemma le_floor_iff: "z \ floor x \ of_int z \ x" ``` huffman@30096 ` 161` ```proof ``` huffman@30096 ` 162` ``` assume "z \ floor x" ``` huffman@30096 ` 163` ``` then have "(of_int z :: 'a) \ of_int (floor x)" by simp ``` huffman@30096 ` 164` ``` also have "of_int (floor x) \ x" by (rule of_int_floor_le) ``` huffman@30096 ` 165` ``` finally show "of_int z \ x" . ``` huffman@30096 ` 166` ```next ``` huffman@30096 ` 167` ``` assume "of_int z \ x" ``` huffman@30096 ` 168` ``` also have "x < of_int (floor x + 1)" using floor_correct .. ``` huffman@30096 ` 169` ``` finally show "z \ floor x" by (simp del: of_int_add) ``` huffman@30096 ` 170` ```qed ``` huffman@30096 ` 171` huffman@30096 ` 172` ```lemma floor_less_iff: "floor x < z \ x < of_int z" ``` huffman@30096 ` 173` ``` by (simp add: not_le [symmetric] le_floor_iff) ``` huffman@30096 ` 174` huffman@30096 ` 175` ```lemma less_floor_iff: "z < floor x \ of_int z + 1 \ x" ``` huffman@30096 ` 176` ``` using le_floor_iff [of "z + 1" x] by auto ``` huffman@30096 ` 177` huffman@30096 ` 178` ```lemma floor_le_iff: "floor x \ z \ x < of_int z + 1" ``` huffman@30096 ` 179` ``` by (simp add: not_less [symmetric] less_floor_iff) ``` huffman@30096 ` 180` huffman@30096 ` 181` ```lemma floor_mono: assumes "x \ y" shows "floor x \ floor y" ``` huffman@30096 ` 182` ```proof - ``` huffman@30096 ` 183` ``` have "of_int (floor x) \ x" by (rule of_int_floor_le) ``` huffman@30096 ` 184` ``` also note `x \ y` ``` huffman@30096 ` 185` ``` finally show ?thesis by (simp add: le_floor_iff) ``` huffman@30096 ` 186` ```qed ``` huffman@30096 ` 187` huffman@30096 ` 188` ```lemma floor_less_cancel: "floor x < floor y \ x < y" ``` huffman@30096 ` 189` ``` by (auto simp add: not_le [symmetric] floor_mono) ``` huffman@30096 ` 190` huffman@30096 ` 191` ```lemma floor_of_int [simp]: "floor (of_int z) = z" ``` huffman@30096 ` 192` ``` by (rule floor_unique) simp_all ``` huffman@30096 ` 193` huffman@30096 ` 194` ```lemma floor_of_nat [simp]: "floor (of_nat n) = int n" ``` huffman@30096 ` 195` ``` using floor_of_int [of "of_nat n"] by simp ``` huffman@30096 ` 196` huffman@47307 ` 197` ```lemma le_floor_add: "floor x + floor y \ floor (x + y)" ``` huffman@47307 ` 198` ``` by (simp only: le_floor_iff of_int_add add_mono of_int_floor_le) ``` huffman@47307 ` 199` huffman@30096 ` 200` ```text {* Floor with numerals *} ``` huffman@30096 ` 201` huffman@30096 ` 202` ```lemma floor_zero [simp]: "floor 0 = 0" ``` huffman@30096 ` 203` ``` using floor_of_int [of 0] by simp ``` huffman@30096 ` 204` huffman@30096 ` 205` ```lemma floor_one [simp]: "floor 1 = 1" ``` huffman@30096 ` 206` ``` using floor_of_int [of 1] by simp ``` huffman@30096 ` 207` huffman@47108 ` 208` ```lemma floor_numeral [simp]: "floor (numeral v) = numeral v" ``` huffman@47108 ` 209` ``` using floor_of_int [of "numeral v"] by simp ``` huffman@47108 ` 210` huffman@47108 ` 211` ```lemma floor_neg_numeral [simp]: "floor (neg_numeral v) = neg_numeral v" ``` huffman@47108 ` 212` ``` using floor_of_int [of "neg_numeral v"] by simp ``` huffman@30096 ` 213` huffman@30096 ` 214` ```lemma zero_le_floor [simp]: "0 \ floor x \ 0 \ x" ``` huffman@30096 ` 215` ``` by (simp add: le_floor_iff) ``` huffman@30096 ` 216` huffman@30096 ` 217` ```lemma one_le_floor [simp]: "1 \ floor x \ 1 \ x" ``` huffman@30096 ` 218` ``` by (simp add: le_floor_iff) ``` huffman@30096 ` 219` huffman@47108 ` 220` ```lemma numeral_le_floor [simp]: ``` huffman@47108 ` 221` ``` "numeral v \ floor x \ numeral v \ x" ``` huffman@47108 ` 222` ``` by (simp add: le_floor_iff) ``` huffman@47108 ` 223` huffman@47108 ` 224` ```lemma neg_numeral_le_floor [simp]: ``` huffman@47108 ` 225` ``` "neg_numeral v \ floor x \ neg_numeral v \ x" ``` huffman@30096 ` 226` ``` by (simp add: le_floor_iff) ``` huffman@30096 ` 227` huffman@30096 ` 228` ```lemma zero_less_floor [simp]: "0 < floor x \ 1 \ x" ``` huffman@30096 ` 229` ``` by (simp add: less_floor_iff) ``` huffman@30096 ` 230` huffman@30096 ` 231` ```lemma one_less_floor [simp]: "1 < floor x \ 2 \ x" ``` huffman@30096 ` 232` ``` by (simp add: less_floor_iff) ``` huffman@30096 ` 233` huffman@47108 ` 234` ```lemma numeral_less_floor [simp]: ``` huffman@47108 ` 235` ``` "numeral v < floor x \ numeral v + 1 \ x" ``` huffman@47108 ` 236` ``` by (simp add: less_floor_iff) ``` huffman@47108 ` 237` huffman@47108 ` 238` ```lemma neg_numeral_less_floor [simp]: ``` huffman@47108 ` 239` ``` "neg_numeral v < floor x \ neg_numeral v + 1 \ x" ``` huffman@30096 ` 240` ``` by (simp add: less_floor_iff) ``` huffman@30096 ` 241` huffman@30096 ` 242` ```lemma floor_le_zero [simp]: "floor x \ 0 \ x < 1" ``` huffman@30096 ` 243` ``` by (simp add: floor_le_iff) ``` huffman@30096 ` 244` huffman@30096 ` 245` ```lemma floor_le_one [simp]: "floor x \ 1 \ x < 2" ``` huffman@30096 ` 246` ``` by (simp add: floor_le_iff) ``` huffman@30096 ` 247` huffman@47108 ` 248` ```lemma floor_le_numeral [simp]: ``` huffman@47108 ` 249` ``` "floor x \ numeral v \ x < numeral v + 1" ``` huffman@47108 ` 250` ``` by (simp add: floor_le_iff) ``` huffman@47108 ` 251` huffman@47108 ` 252` ```lemma floor_le_neg_numeral [simp]: ``` huffman@47108 ` 253` ``` "floor x \ neg_numeral v \ x < neg_numeral v + 1" ``` huffman@30096 ` 254` ``` by (simp add: floor_le_iff) ``` huffman@30096 ` 255` huffman@30096 ` 256` ```lemma floor_less_zero [simp]: "floor x < 0 \ x < 0" ``` huffman@30096 ` 257` ``` by (simp add: floor_less_iff) ``` huffman@30096 ` 258` huffman@30096 ` 259` ```lemma floor_less_one [simp]: "floor x < 1 \ x < 1" ``` huffman@30096 ` 260` ``` by (simp add: floor_less_iff) ``` huffman@30096 ` 261` huffman@47108 ` 262` ```lemma floor_less_numeral [simp]: ``` huffman@47108 ` 263` ``` "floor x < numeral v \ x < numeral v" ``` huffman@47108 ` 264` ``` by (simp add: floor_less_iff) ``` huffman@47108 ` 265` huffman@47108 ` 266` ```lemma floor_less_neg_numeral [simp]: ``` huffman@47108 ` 267` ``` "floor x < neg_numeral v \ x < neg_numeral v" ``` huffman@30096 ` 268` ``` by (simp add: floor_less_iff) ``` huffman@30096 ` 269` huffman@30096 ` 270` ```text {* Addition and subtraction of integers *} ``` huffman@30096 ` 271` huffman@30096 ` 272` ```lemma floor_add_of_int [simp]: "floor (x + of_int z) = floor x + z" ``` huffman@30096 ` 273` ``` using floor_correct [of x] by (simp add: floor_unique) ``` huffman@30096 ` 274` huffman@47108 ` 275` ```lemma floor_add_numeral [simp]: ``` huffman@47108 ` 276` ``` "floor (x + numeral v) = floor x + numeral v" ``` huffman@47108 ` 277` ``` using floor_add_of_int [of x "numeral v"] by simp ``` huffman@47108 ` 278` huffman@47108 ` 279` ```lemma floor_add_neg_numeral [simp]: ``` huffman@47108 ` 280` ``` "floor (x + neg_numeral v) = floor x + neg_numeral v" ``` huffman@47108 ` 281` ``` using floor_add_of_int [of x "neg_numeral v"] by simp ``` huffman@30096 ` 282` huffman@30096 ` 283` ```lemma floor_add_one [simp]: "floor (x + 1) = floor x + 1" ``` huffman@30096 ` 284` ``` using floor_add_of_int [of x 1] by simp ``` huffman@30096 ` 285` huffman@30096 ` 286` ```lemma floor_diff_of_int [simp]: "floor (x - of_int z) = floor x - z" ``` huffman@30096 ` 287` ``` using floor_add_of_int [of x "- z"] by (simp add: algebra_simps) ``` huffman@30096 ` 288` huffman@47108 ` 289` ```lemma floor_diff_numeral [simp]: ``` huffman@47108 ` 290` ``` "floor (x - numeral v) = floor x - numeral v" ``` huffman@47108 ` 291` ``` using floor_diff_of_int [of x "numeral v"] by simp ``` huffman@47108 ` 292` huffman@47108 ` 293` ```lemma floor_diff_neg_numeral [simp]: ``` huffman@47108 ` 294` ``` "floor (x - neg_numeral v) = floor x - neg_numeral v" ``` huffman@47108 ` 295` ``` using floor_diff_of_int [of x "neg_numeral v"] by simp ``` huffman@30096 ` 296` huffman@30096 ` 297` ```lemma floor_diff_one [simp]: "floor (x - 1) = floor x - 1" ``` huffman@30096 ` 298` ``` using floor_diff_of_int [of x 1] by simp ``` huffman@30096 ` 299` huffman@30096 ` 300` huffman@30096 ` 301` ```subsection {* Ceiling function *} ``` huffman@30096 ` 302` huffman@30096 ` 303` ```definition ``` bulwahn@43732 ` 304` ``` ceiling :: "'a::floor_ceiling \ int" where ``` bulwahn@43733 ` 305` ``` "ceiling x = - floor (- x)" ``` huffman@30096 ` 306` huffman@30096 ` 307` ```notation (xsymbols) ``` huffman@30096 ` 308` ``` ceiling ("\_\") ``` huffman@30096 ` 309` huffman@30096 ` 310` ```notation (HTML output) ``` huffman@30096 ` 311` ``` ceiling ("\_\") ``` huffman@30096 ` 312` huffman@30096 ` 313` ```lemma ceiling_correct: "of_int (ceiling x) - 1 < x \ x \ of_int (ceiling x)" ``` huffman@30096 ` 314` ``` unfolding ceiling_def using floor_correct [of "- x"] by simp ``` huffman@30096 ` 315` huffman@30096 ` 316` ```lemma ceiling_unique: "\of_int z - 1 < x; x \ of_int z\ \ ceiling x = z" ``` huffman@30096 ` 317` ``` unfolding ceiling_def using floor_unique [of "- z" "- x"] by simp ``` huffman@30096 ` 318` huffman@30096 ` 319` ```lemma le_of_int_ceiling: "x \ of_int (ceiling x)" ``` huffman@30096 ` 320` ``` using ceiling_correct .. ``` huffman@30096 ` 321` huffman@30096 ` 322` ```lemma ceiling_le_iff: "ceiling x \ z \ x \ of_int z" ``` huffman@30096 ` 323` ``` unfolding ceiling_def using le_floor_iff [of "- z" "- x"] by auto ``` huffman@30096 ` 324` huffman@30096 ` 325` ```lemma less_ceiling_iff: "z < ceiling x \ of_int z < x" ``` huffman@30096 ` 326` ``` by (simp add: not_le [symmetric] ceiling_le_iff) ``` huffman@30096 ` 327` huffman@30096 ` 328` ```lemma ceiling_less_iff: "ceiling x < z \ x \ of_int z - 1" ``` huffman@30096 ` 329` ``` using ceiling_le_iff [of x "z - 1"] by simp ``` huffman@30096 ` 330` huffman@30096 ` 331` ```lemma le_ceiling_iff: "z \ ceiling x \ of_int z - 1 < x" ``` huffman@30096 ` 332` ``` by (simp add: not_less [symmetric] ceiling_less_iff) ``` huffman@30096 ` 333` huffman@30096 ` 334` ```lemma ceiling_mono: "x \ y \ ceiling x \ ceiling y" ``` huffman@30096 ` 335` ``` unfolding ceiling_def by (simp add: floor_mono) ``` huffman@30096 ` 336` huffman@30096 ` 337` ```lemma ceiling_less_cancel: "ceiling x < ceiling y \ x < y" ``` huffman@30096 ` 338` ``` by (auto simp add: not_le [symmetric] ceiling_mono) ``` huffman@30096 ` 339` huffman@30096 ` 340` ```lemma ceiling_of_int [simp]: "ceiling (of_int z) = z" ``` huffman@30096 ` 341` ``` by (rule ceiling_unique) simp_all ``` huffman@30096 ` 342` huffman@30096 ` 343` ```lemma ceiling_of_nat [simp]: "ceiling (of_nat n) = int n" ``` huffman@30096 ` 344` ``` using ceiling_of_int [of "of_nat n"] by simp ``` huffman@30096 ` 345` huffman@47307 ` 346` ```lemma ceiling_add_le: "ceiling (x + y) \ ceiling x + ceiling y" ``` huffman@47307 ` 347` ``` by (simp only: ceiling_le_iff of_int_add add_mono le_of_int_ceiling) ``` huffman@47307 ` 348` huffman@30096 ` 349` ```text {* Ceiling with numerals *} ``` huffman@30096 ` 350` huffman@30096 ` 351` ```lemma ceiling_zero [simp]: "ceiling 0 = 0" ``` huffman@30096 ` 352` ``` using ceiling_of_int [of 0] by simp ``` huffman@30096 ` 353` huffman@30096 ` 354` ```lemma ceiling_one [simp]: "ceiling 1 = 1" ``` huffman@30096 ` 355` ``` using ceiling_of_int [of 1] by simp ``` huffman@30096 ` 356` huffman@47108 ` 357` ```lemma ceiling_numeral [simp]: "ceiling (numeral v) = numeral v" ``` huffman@47108 ` 358` ``` using ceiling_of_int [of "numeral v"] by simp ``` huffman@47108 ` 359` huffman@47108 ` 360` ```lemma ceiling_neg_numeral [simp]: "ceiling (neg_numeral v) = neg_numeral v" ``` huffman@47108 ` 361` ``` using ceiling_of_int [of "neg_numeral v"] by simp ``` huffman@30096 ` 362` huffman@30096 ` 363` ```lemma ceiling_le_zero [simp]: "ceiling x \ 0 \ x \ 0" ``` huffman@30096 ` 364` ``` by (simp add: ceiling_le_iff) ``` huffman@30096 ` 365` huffman@30096 ` 366` ```lemma ceiling_le_one [simp]: "ceiling x \ 1 \ x \ 1" ``` huffman@30096 ` 367` ``` by (simp add: ceiling_le_iff) ``` huffman@30096 ` 368` huffman@47108 ` 369` ```lemma ceiling_le_numeral [simp]: ``` huffman@47108 ` 370` ``` "ceiling x \ numeral v \ x \ numeral v" ``` huffman@47108 ` 371` ``` by (simp add: ceiling_le_iff) ``` huffman@47108 ` 372` huffman@47108 ` 373` ```lemma ceiling_le_neg_numeral [simp]: ``` huffman@47108 ` 374` ``` "ceiling x \ neg_numeral v \ x \ neg_numeral v" ``` huffman@30096 ` 375` ``` by (simp add: ceiling_le_iff) ``` huffman@30096 ` 376` huffman@30096 ` 377` ```lemma ceiling_less_zero [simp]: "ceiling x < 0 \ x \ -1" ``` huffman@30096 ` 378` ``` by (simp add: ceiling_less_iff) ``` huffman@30096 ` 379` huffman@30096 ` 380` ```lemma ceiling_less_one [simp]: "ceiling x < 1 \ x \ 0" ``` huffman@30096 ` 381` ``` by (simp add: ceiling_less_iff) ``` huffman@30096 ` 382` huffman@47108 ` 383` ```lemma ceiling_less_numeral [simp]: ``` huffman@47108 ` 384` ``` "ceiling x < numeral v \ x \ numeral v - 1" ``` huffman@47108 ` 385` ``` by (simp add: ceiling_less_iff) ``` huffman@47108 ` 386` huffman@47108 ` 387` ```lemma ceiling_less_neg_numeral [simp]: ``` huffman@47108 ` 388` ``` "ceiling x < neg_numeral v \ x \ neg_numeral v - 1" ``` huffman@30096 ` 389` ``` by (simp add: ceiling_less_iff) ``` huffman@30096 ` 390` huffman@30096 ` 391` ```lemma zero_le_ceiling [simp]: "0 \ ceiling x \ -1 < x" ``` huffman@30096 ` 392` ``` by (simp add: le_ceiling_iff) ``` huffman@30096 ` 393` huffman@30096 ` 394` ```lemma one_le_ceiling [simp]: "1 \ ceiling x \ 0 < x" ``` huffman@30096 ` 395` ``` by (simp add: le_ceiling_iff) ``` huffman@30096 ` 396` huffman@47108 ` 397` ```lemma numeral_le_ceiling [simp]: ``` huffman@47108 ` 398` ``` "numeral v \ ceiling x \ numeral v - 1 < x" ``` huffman@47108 ` 399` ``` by (simp add: le_ceiling_iff) ``` huffman@47108 ` 400` huffman@47108 ` 401` ```lemma neg_numeral_le_ceiling [simp]: ``` huffman@47108 ` 402` ``` "neg_numeral v \ ceiling x \ neg_numeral v - 1 < x" ``` huffman@30096 ` 403` ``` by (simp add: le_ceiling_iff) ``` huffman@30096 ` 404` huffman@30096 ` 405` ```lemma zero_less_ceiling [simp]: "0 < ceiling x \ 0 < x" ``` huffman@30096 ` 406` ``` by (simp add: less_ceiling_iff) ``` huffman@30096 ` 407` huffman@30096 ` 408` ```lemma one_less_ceiling [simp]: "1 < ceiling x \ 1 < x" ``` huffman@30096 ` 409` ``` by (simp add: less_ceiling_iff) ``` huffman@30096 ` 410` huffman@47108 ` 411` ```lemma numeral_less_ceiling [simp]: ``` huffman@47108 ` 412` ``` "numeral v < ceiling x \ numeral v < x" ``` huffman@47108 ` 413` ``` by (simp add: less_ceiling_iff) ``` huffman@47108 ` 414` huffman@47108 ` 415` ```lemma neg_numeral_less_ceiling [simp]: ``` huffman@47108 ` 416` ``` "neg_numeral v < ceiling x \ neg_numeral v < x" ``` huffman@30096 ` 417` ``` by (simp add: less_ceiling_iff) ``` huffman@30096 ` 418` huffman@30096 ` 419` ```text {* Addition and subtraction of integers *} ``` huffman@30096 ` 420` huffman@30096 ` 421` ```lemma ceiling_add_of_int [simp]: "ceiling (x + of_int z) = ceiling x + z" ``` huffman@30096 ` 422` ``` using ceiling_correct [of x] by (simp add: ceiling_unique) ``` huffman@30096 ` 423` huffman@47108 ` 424` ```lemma ceiling_add_numeral [simp]: ``` huffman@47108 ` 425` ``` "ceiling (x + numeral v) = ceiling x + numeral v" ``` huffman@47108 ` 426` ``` using ceiling_add_of_int [of x "numeral v"] by simp ``` huffman@47108 ` 427` huffman@47108 ` 428` ```lemma ceiling_add_neg_numeral [simp]: ``` huffman@47108 ` 429` ``` "ceiling (x + neg_numeral v) = ceiling x + neg_numeral v" ``` huffman@47108 ` 430` ``` using ceiling_add_of_int [of x "neg_numeral v"] by simp ``` huffman@30096 ` 431` huffman@30096 ` 432` ```lemma ceiling_add_one [simp]: "ceiling (x + 1) = ceiling x + 1" ``` huffman@30096 ` 433` ``` using ceiling_add_of_int [of x 1] by simp ``` huffman@30096 ` 434` huffman@30096 ` 435` ```lemma ceiling_diff_of_int [simp]: "ceiling (x - of_int z) = ceiling x - z" ``` huffman@30096 ` 436` ``` using ceiling_add_of_int [of x "- z"] by (simp add: algebra_simps) ``` huffman@30096 ` 437` huffman@47108 ` 438` ```lemma ceiling_diff_numeral [simp]: ``` huffman@47108 ` 439` ``` "ceiling (x - numeral v) = ceiling x - numeral v" ``` huffman@47108 ` 440` ``` using ceiling_diff_of_int [of x "numeral v"] by simp ``` huffman@47108 ` 441` huffman@47108 ` 442` ```lemma ceiling_diff_neg_numeral [simp]: ``` huffman@47108 ` 443` ``` "ceiling (x - neg_numeral v) = ceiling x - neg_numeral v" ``` huffman@47108 ` 444` ``` using ceiling_diff_of_int [of x "neg_numeral v"] by simp ``` huffman@30096 ` 445` huffman@30096 ` 446` ```lemma ceiling_diff_one [simp]: "ceiling (x - 1) = ceiling x - 1" ``` huffman@30096 ` 447` ``` using ceiling_diff_of_int [of x 1] by simp ``` huffman@30096 ` 448` hoelzl@47592 ` 449` ```lemma ceiling_diff_floor_le_1: "ceiling x - floor x \ 1" ``` hoelzl@47592 ` 450` ```proof - ``` hoelzl@47592 ` 451` ``` have "of_int \x\ - 1 < x" ``` hoelzl@47592 ` 452` ``` using ceiling_correct[of x] by simp ``` hoelzl@47592 ` 453` ``` also have "x < of_int \x\ + 1" ``` hoelzl@47592 ` 454` ``` using floor_correct[of x] by simp_all ``` hoelzl@47592 ` 455` ``` finally have "of_int (\x\ - \x\) < (of_int 2::'a)" ``` hoelzl@47592 ` 456` ``` by simp ``` hoelzl@47592 ` 457` ``` then show ?thesis ``` hoelzl@47592 ` 458` ``` unfolding of_int_less_iff by simp ``` hoelzl@47592 ` 459` ```qed ``` huffman@30096 ` 460` huffman@30096 ` 461` ```subsection {* Negation *} ``` huffman@30096 ` 462` huffman@30102 ` 463` ```lemma floor_minus: "floor (- x) = - ceiling x" ``` huffman@30096 ` 464` ``` unfolding ceiling_def by simp ``` huffman@30096 ` 465` huffman@30102 ` 466` ```lemma ceiling_minus: "ceiling (- x) = - floor x" ``` huffman@30096 ` 467` ``` unfolding ceiling_def by simp ``` huffman@30096 ` 468` huffman@30096 ` 469` ```end ```