src/HOL/Archimedean_Field.thy
author Lars Hupel <lars.hupel@mytum.de>
Mon, 04 Jul 2016 18:20:51 +0200
changeset 63385 370cce7ad9b9
parent 63331 247eac9758dd
child 63489 cd540c8031a4
permissions -rw-r--r--
tuned
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41959
b460124855b8 tuned headers;
wenzelm
parents: 37765
diff changeset
     1
(*  Title:      HOL/Archimedean_Field.thy
b460124855b8 tuned headers;
wenzelm
parents: 37765
diff changeset
     2
    Author:     Brian Huffman
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
     3
*)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
     4
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
     5
section \<open>Archimedean Fields, Floor and Ceiling Functions\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
     6
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
     7
theory Archimedean_Field
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
     8
imports Main
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
     9
begin
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    10
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    11
lemma cInf_abs_ge:
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    12
  fixes S :: "('a::{linordered_idom,conditionally_complete_linorder}) set"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    13
  assumes "S \<noteq> {}" and bdd: "\<And>x. x\<in>S \<Longrightarrow> \<bar>x\<bar> \<le> a"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    14
  shows "\<bar>Inf S\<bar> \<le> a"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    15
proof -
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    16
  have "Sup (uminus ` S) = - (Inf S)"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    17
  proof (rule antisym)
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    18
    show "- (Inf S) \<le> Sup(uminus ` S)"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    19
      apply (subst minus_le_iff)
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    20
      apply (rule cInf_greatest [OF \<open>S \<noteq> {}\<close>])
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    21
      apply (subst minus_le_iff)
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    22
      apply (rule cSup_upper, force)
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    23
      using bdd apply (force simp add: abs_le_iff bdd_above_def)
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    24
      done
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    25
  next
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    26
    show "Sup (uminus ` S) \<le> - Inf S"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    27
      apply (rule cSup_least)
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    28
       using \<open>S \<noteq> {}\<close> apply (force simp add: )
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    29
      apply clarsimp
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    30
      apply (rule cInf_lower)
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    31
      apply assumption
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    32
      using bdd apply (simp add: bdd_below_def)
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    33
      apply (rule_tac x="-a" in exI)
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    34
      apply force
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    35
      done
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    36
  qed
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    37
  with cSup_abs_le [of "uminus ` S"] assms show ?thesis by fastforce
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    38
qed
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    39
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    40
lemma cSup_asclose:
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    41
  fixes S :: "('a::{linordered_idom,conditionally_complete_linorder}) set"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    42
  assumes S: "S \<noteq> {}"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    43
    and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    44
  shows "\<bar>Sup S - l\<bar> \<le> e"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    45
proof -
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    46
  have th: "\<And>(x::'a) l e. \<bar>x - l\<bar> \<le> e \<longleftrightarrow> l - e \<le> x \<and> x \<le> l + e"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    47
    by arith
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    48
  have "bdd_above S"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    49
    using b by (auto intro!: bdd_aboveI[of _ "l + e"])
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    50
  with S b show ?thesis
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    51
    unfolding th by (auto intro!: cSup_upper2 cSup_least)
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    52
qed
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    53
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    54
lemma cInf_asclose:
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    55
  fixes S :: "('a::{linordered_idom,conditionally_complete_linorder}) set"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    56
  assumes S: "S \<noteq> {}"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    57
    and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    58
  shows "\<bar>Inf S - l\<bar> \<le> e"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    59
proof -
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    60
  have th: "\<And>(x::'a) l e. \<bar>x - l\<bar> \<le> e \<longleftrightarrow> l - e \<le> x \<and> x \<le> l + e"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    61
    by arith
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    62
  have "bdd_below S"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    63
    using b by (auto intro!: bdd_belowI[of _ "l - e"])
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    64
  with S b show ?thesis
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    65
    unfolding th by (auto intro!: cInf_lower2 cInf_greatest)
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    66
qed
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    67
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
    68
subsection \<open>Class of Archimedean fields\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    69
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
    70
text \<open>Archimedean fields have no infinite elements.\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    71
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
    72
class archimedean_field = linordered_field +
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    73
  assumes ex_le_of_int: "\<exists>z. x \<le> of_int z"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    74
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    75
lemma ex_less_of_int:
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    76
  fixes x :: "'a::archimedean_field" shows "\<exists>z. x < of_int z"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    77
proof -
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    78
  from ex_le_of_int obtain z where "x \<le> of_int z" ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    79
  then have "x < of_int (z + 1)" by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    80
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    81
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    82
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    83
lemma ex_of_int_less:
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    84
  fixes x :: "'a::archimedean_field" shows "\<exists>z. of_int z < x"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    85
proof -
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    86
  from ex_less_of_int obtain z where "- x < of_int z" ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    87
  then have "of_int (- z) < x" by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    88
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    89
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    90
62623
dbc62f86a1a9 rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents: 62348
diff changeset
    91
lemma reals_Archimedean2:
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    92
  fixes x :: "'a::archimedean_field" shows "\<exists>n. x < of_nat n"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    93
proof -
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    94
  obtain z where "x < of_int z" using ex_less_of_int ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    95
  also have "\<dots> \<le> of_int (int (nat z))" by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    96
  also have "\<dots> = of_nat (nat z)" by (simp only: of_int_of_nat_eq)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    97
  finally show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    98
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    99
62623
dbc62f86a1a9 rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents: 62348
diff changeset
   100
lemma real_arch_simple:
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   101
  fixes x :: "'a::archimedean_field" shows "\<exists>n. x \<le> of_nat n"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   102
proof -
62623
dbc62f86a1a9 rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents: 62348
diff changeset
   103
  obtain n where "x < of_nat n" using reals_Archimedean2 ..
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   104
  then have "x \<le> of_nat n" by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   105
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   106
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   107
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   108
text \<open>Archimedean fields have no infinitesimal elements.\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   109
62623
dbc62f86a1a9 rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents: 62348
diff changeset
   110
lemma reals_Archimedean:
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   111
  fixes x :: "'a::archimedean_field"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   112
  assumes "0 < x" shows "\<exists>n. inverse (of_nat (Suc n)) < x"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   113
proof -
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   114
  from \<open>0 < x\<close> have "0 < inverse x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   115
    by (rule positive_imp_inverse_positive)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   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
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   118
  then obtain m where "inverse x < of_nat (Suc m)"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   119
    using \<open>0 < inverse x\<close> by (cases n) (simp_all del: of_nat_Suc)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   120
  then have "inverse (of_nat (Suc m)) < inverse (inverse x)"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   121
    using \<open>0 < inverse x\<close> by (rule less_imp_inverse_less)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   122
  then have "inverse (of_nat (Suc m)) < x"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   123
    using \<open>0 < x\<close> by (simp add: nonzero_inverse_inverse_eq)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   124
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   125
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   126
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   127
lemma ex_inverse_of_nat_less:
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   128
  fixes x :: "'a::archimedean_field"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   129
  assumes "0 < x" 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
   130
  using reals_Archimedean [OF \<open>0 < x\<close>] by auto
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   131
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   132
lemma ex_less_of_nat_mult:
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   133
  fixes x :: "'a::archimedean_field"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   134
  assumes "0 < x" shows "\<exists>n. y < of_nat n * x"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   135
proof -
62623
dbc62f86a1a9 rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents: 62348
diff changeset
   136
  obtain n where "y / x < of_nat n" using reals_Archimedean2 ..
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   137
  with \<open>0 < x\<close> have "y < of_nat n * x" by (simp add: pos_divide_less_eq)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   138
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   139
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   140
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   141
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   142
subsection \<open>Existence and uniqueness of floor function\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   143
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   144
lemma exists_least_lemma:
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   145
  assumes "\<not> P 0" and "\<exists>n. P n"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   146
  shows "\<exists>n. \<not> P n \<and> P (Suc n)"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   147
proof -
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   148
  from \<open>\<exists>n. P n\<close> have "P (Least P)" by (rule LeastI_ex)
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   149
  with \<open>\<not> P 0\<close> obtain n where "Least P = Suc n"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   150
    by (cases "Least P") auto
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   151
  then have "n < Least P" by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   152
  then have "\<not> P n" by (rule not_less_Least)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   153
  then have "\<not> P n \<and> P (Suc n)"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   154
    using \<open>P (Least P)\<close> \<open>Least P = Suc n\<close> by simp
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   155
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   156
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   157
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   158
lemma floor_exists:
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   159
  fixes x :: "'a::archimedean_field"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   160
  shows "\<exists>z. of_int z \<le> x \<and> x < of_int (z + 1)"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   161
proof (cases)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   162
  assume "0 \<le> x"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   163
  then have "\<not> x < of_nat 0" by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   164
  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
   165
    using reals_Archimedean2 by (rule exists_least_lemma)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   166
  then obtain n where "\<not> x < of_nat n \<and> x < of_nat (Suc n)" ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   167
  then have "of_int (int n) \<le> x \<and> x < of_int (int n + 1)" by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   168
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   169
next
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   170
  assume "\<not> 0 \<le> x"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   171
  then have "\<not> - x \<le> of_nat 0" by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   172
  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
   173
    using real_arch_simple by (rule exists_least_lemma)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   174
  then obtain n where "\<not> - x \<le> of_nat n \<and> - x \<le> of_nat (Suc n)" ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   175
  then have "of_int (- int n - 1) \<le> x \<and> x < of_int (- int n - 1 + 1)" by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   176
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   177
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   178
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   179
lemma floor_exists1:
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   180
  fixes x :: "'a::archimedean_field"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   181
  shows "\<exists>!z. of_int z \<le> x \<and> x < of_int (z + 1)"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   182
proof (rule ex_ex1I)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   183
  show "\<exists>z. of_int z \<le> x \<and> x < of_int (z + 1)"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   184
    by (rule floor_exists)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   185
next
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   186
  fix y z assume
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   187
    "of_int y \<le> x \<and> x < of_int (y + 1)"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   188
    "of_int z \<le> x \<and> x < of_int (z + 1)"
54281
b01057e72233 int and nat are conditionally_complete_lattices
hoelzl
parents: 47592
diff changeset
   189
  with le_less_trans [of "of_int y" "x" "of_int (z + 1)"]
b01057e72233 int and nat are conditionally_complete_lattices
hoelzl
parents: 47592
diff changeset
   190
       le_less_trans [of "of_int z" "x" "of_int (y + 1)"]
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   191
  show "y = z" by (simp del: of_int_add)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   192
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   193
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   194
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   195
subsection \<open>Floor function\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   196
43732
6b2bdc57155b adding a floor_ceiling type class for different instantiations of floor (changeset from Brian Huffman)
bulwahn
parents: 43704
diff changeset
   197
class floor_ceiling = archimedean_field +
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   198
  fixes floor :: "'a \<Rightarrow> int"  ("\<lfloor>_\<rfloor>")
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   199
  assumes floor_correct: "of_int \<lfloor>x\<rfloor> \<le> x \<and> x < of_int (\<lfloor>x\<rfloor> + 1)"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   200
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   201
lemma floor_unique: "\<lbrakk>of_int z \<le> x; x < of_int z + 1\<rbrakk> \<Longrightarrow> \<lfloor>x\<rfloor> = z"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   202
  using floor_correct [of x] floor_exists1 [of x] by auto
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   203
59613
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   204
lemma floor_unique_iff:
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   205
  fixes x :: "'a::floor_ceiling"
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   206
  shows  "\<lfloor>x\<rfloor> = a \<longleftrightarrow> of_int a \<le> x \<and> x < of_int a + 1"
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   207
using floor_correct floor_unique by auto
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   208
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   209
lemma of_int_floor_le [simp]: "of_int \<lfloor>x\<rfloor> \<le> x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   210
  using floor_correct ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   211
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   212
lemma le_floor_iff: "z \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> of_int z \<le> x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   213
proof
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   214
  assume "z \<le> \<lfloor>x\<rfloor>"
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   215
  then have "(of_int z :: 'a) \<le> of_int \<lfloor>x\<rfloor>" by simp
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   216
  also have "of_int \<lfloor>x\<rfloor> \<le> x" by (rule of_int_floor_le)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   217
  finally show "of_int z \<le> x" .
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   218
next
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   219
  assume "of_int z \<le> x"
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   220
  also have "x < of_int (\<lfloor>x\<rfloor> + 1)" using floor_correct ..
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   221
  finally show "z \<le> \<lfloor>x\<rfloor>" by (simp del: of_int_add)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   222
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   223
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   224
lemma floor_less_iff: "\<lfloor>x\<rfloor> < z \<longleftrightarrow> x < of_int z"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   225
  by (simp add: not_le [symmetric] le_floor_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   226
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   227
lemma less_floor_iff: "z < \<lfloor>x\<rfloor> \<longleftrightarrow> of_int z + 1 \<le> x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   228
  using le_floor_iff [of "z + 1" x] by auto
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   229
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   230
lemma floor_le_iff: "\<lfloor>x\<rfloor> \<le> z \<longleftrightarrow> x < of_int z + 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   231
  by (simp add: not_less [symmetric] less_floor_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   232
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   233
lemma floor_split[arith_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
   234
  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
   235
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   236
lemma floor_mono:
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   237
  assumes "x \<le> y"
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   238
  shows "\<lfloor>x\<rfloor> \<le> \<lfloor>y\<rfloor>"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   239
proof -
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   240
  have "of_int \<lfloor>x\<rfloor> \<le> x" by (rule of_int_floor_le)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   241
  also note \<open>x \<le> y\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   242
  finally show ?thesis by (simp add: le_floor_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   243
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   244
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   245
lemma floor_less_cancel: "\<lfloor>x\<rfloor> < \<lfloor>y\<rfloor> \<Longrightarrow> x < y"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   246
  by (auto simp add: not_le [symmetric] floor_mono)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   247
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   248
lemma floor_of_int [simp]: "\<lfloor>of_int z\<rfloor> = z"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   249
  by (rule floor_unique) simp_all
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   250
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   251
lemma floor_of_nat [simp]: "\<lfloor>of_nat n\<rfloor> = int n"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   252
  using floor_of_int [of "of_nat n"] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   253
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   254
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
   255
  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
   256
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   257
text \<open>Floor with numerals\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   258
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   259
lemma floor_zero [simp]: "\<lfloor>0\<rfloor> = 0"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   260
  using floor_of_int [of 0] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   261
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   262
lemma floor_one [simp]: "\<lfloor>1\<rfloor> = 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   263
  using floor_of_int [of 1] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   264
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   265
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
   266
  using floor_of_int [of "numeral v"] by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   267
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   268
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
   269
  using floor_of_int [of "- numeral v"] by simp
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   270
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   271
lemma zero_le_floor [simp]: "0 \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> 0 \<le> x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   272
  by (simp add: le_floor_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   273
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   274
lemma one_le_floor [simp]: "1 \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> 1 \<le> x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   275
  by (simp add: le_floor_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   276
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   277
lemma numeral_le_floor [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   278
  "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
   279
  by (simp add: le_floor_iff)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   280
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   281
lemma neg_numeral_le_floor [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   282
  "- numeral v \<le> \<lfloor>x\<rfloor> \<longleftrightarrow> - numeral v \<le> x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   283
  by (simp add: le_floor_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   284
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   285
lemma zero_less_floor [simp]: "0 < \<lfloor>x\<rfloor> \<longleftrightarrow> 1 \<le> x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   286
  by (simp add: less_floor_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   287
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   288
lemma one_less_floor [simp]: "1 < \<lfloor>x\<rfloor> \<longleftrightarrow> 2 \<le> x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   289
  by (simp add: less_floor_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   290
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   291
lemma numeral_less_floor [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   292
  "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
   293
  by (simp add: less_floor_iff)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   294
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   295
lemma neg_numeral_less_floor [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   296
  "- numeral v < \<lfloor>x\<rfloor> \<longleftrightarrow> - numeral v + 1 \<le> x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   297
  by (simp add: less_floor_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   298
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   299
lemma floor_le_zero [simp]: "\<lfloor>x\<rfloor> \<le> 0 \<longleftrightarrow> x < 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   300
  by (simp add: floor_le_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   301
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   302
lemma floor_le_one [simp]: "\<lfloor>x\<rfloor> \<le> 1 \<longleftrightarrow> x < 2"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   303
  by (simp add: floor_le_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   304
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   305
lemma floor_le_numeral [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   306
  "\<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
   307
  by (simp add: floor_le_iff)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   308
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   309
lemma floor_le_neg_numeral [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   310
  "\<lfloor>x\<rfloor> \<le> - numeral v \<longleftrightarrow> x < - numeral v + 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   311
  by (simp add: floor_le_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   312
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   313
lemma floor_less_zero [simp]: "\<lfloor>x\<rfloor> < 0 \<longleftrightarrow> x < 0"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   314
  by (simp add: floor_less_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   315
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   316
lemma floor_less_one [simp]: "\<lfloor>x\<rfloor> < 1 \<longleftrightarrow> x < 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   317
  by (simp add: floor_less_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   318
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   319
lemma floor_less_numeral [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   320
  "\<lfloor>x\<rfloor> < numeral v \<longleftrightarrow> x < numeral v"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   321
  by (simp add: floor_less_iff)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   322
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   323
lemma floor_less_neg_numeral [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   324
  "\<lfloor>x\<rfloor> < - numeral v \<longleftrightarrow> x < - numeral v"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   325
  by (simp add: floor_less_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   326
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   327
text \<open>Addition and subtraction of integers\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   328
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   329
lemma floor_add_of_int [simp]: "\<lfloor>x + of_int z\<rfloor> = \<lfloor>x\<rfloor> + z"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   330
  using floor_correct [of x] by (simp add: floor_unique)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   331
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   332
lemma floor_add_numeral [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   333
    "\<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
   334
  using floor_add_of_int [of x "numeral v"] by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   335
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   336
lemma floor_add_one [simp]: "\<lfloor>x + 1\<rfloor> = \<lfloor>x\<rfloor> + 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   337
  using floor_add_of_int [of x 1] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   338
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   339
lemma floor_diff_of_int [simp]: "\<lfloor>x - of_int z\<rfloor> = \<lfloor>x\<rfloor> - z"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   340
  using floor_add_of_int [of x "- z"] by (simp add: algebra_simps)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   341
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   342
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
   343
  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
   344
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   345
lemma floor_diff_numeral [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   346
  "\<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
   347
  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
   348
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   349
lemma floor_diff_one [simp]: "\<lfloor>x - 1\<rfloor> = \<lfloor>x\<rfloor> - 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   350
  using floor_diff_of_int [of x 1] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   351
58097
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58040
diff changeset
   352
lemma le_mult_floor:
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58040
diff changeset
   353
  assumes "0 \<le> a" and "0 \<le> b"
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   354
  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
   355
proof -
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   356
  have "of_int \<lfloor>a\<rfloor> \<le> a"
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   357
    and "of_int \<lfloor>b\<rfloor> \<le> b" by (auto intro: of_int_floor_le)
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   358
  hence "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
   359
    using assms by (auto intro!: mult_mono)
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   360
  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
   361
    using floor_correct[of "a * b"] by auto
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58040
diff changeset
   362
  finally show ?thesis unfolding of_int_less_iff by simp
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58040
diff changeset
   363
qed
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58040
diff changeset
   364
59984
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   365
lemma floor_divide_of_int_eq:
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   366
  fixes k l :: int
60128
3d696ccb7fa6 compactified proposition
haftmann
parents: 59984
diff changeset
   367
  shows "\<lfloor>of_int k / of_int l\<rfloor> = k div l"
59984
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   368
proof (cases "l = 0")
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   369
  case True then show ?thesis by simp
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   370
next
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   371
  case False
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   372
  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
   373
  proof (cases "l > 0")
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   374
    case True then show ?thesis
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   375
      by (auto intro: floor_unique)
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   376
  next
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   377
    case False
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   378
    obtain r where "r = - l" by blast
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   379
    then have l: "l = - r" by simp
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   380
    moreover with \<open>l \<noteq> 0\<close> False have "r > 0" by simp
59984
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   381
    ultimately show ?thesis using pos_mod_bound [of r]
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   382
      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
   383
  qed
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   384
  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
   385
    by simp
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   386
  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
   387
    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
   388
  finally have "(of_int k / of_int l :: 'a) = \<dots> / of_int l"
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   389
    by simp
59984
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   390
  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
   391
    using False by (simp only:) (simp add: field_simps)
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   392
  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
   393
    by simp
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   394
  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
   395
    by (simp add: ac_simps)
60128
3d696ccb7fa6 compactified proposition
haftmann
parents: 59984
diff changeset
   396
  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"
59984
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   397
    by simp
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   398
  with * show ?thesis by simp
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   399
qed
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   400
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   401
lemma floor_divide_of_nat_eq:
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   402
  fixes m n :: nat
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   403
  shows "\<lfloor>of_nat m / of_nat n\<rfloor> = of_nat (m div n)"
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   404
proof (cases "n = 0")
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   405
  case True then show ?thesis by simp
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   406
next
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   407
  case False
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   408
  then have *: "\<lfloor>of_nat (m mod n) / of_nat n :: 'a\<rfloor> = 0"
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   409
    by (auto intro: floor_unique)
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   410
  have "(of_nat m :: 'a) = of_nat (m div n * n + m mod n)"
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   411
    by simp
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   412
  also have "\<dots> = (of_nat (m div n) + of_nat (m mod n) / of_nat n) * of_nat n"
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   413
    using False by (simp only: of_nat_add) (simp add: field_simps of_nat_mult)
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   414
  finally have "(of_nat m / of_nat n :: 'a) = \<dots> / of_nat n"
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   415
    by simp
59984
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   416
  then have "(of_nat m / of_nat n :: 'a) = of_nat (m div n) + of_nat (m mod n) / of_nat n"
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   417
    using False by (simp only:) simp
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   418
  then have "\<lfloor>of_nat m / of_nat n :: 'a\<rfloor> = \<lfloor>of_nat (m div n) + of_nat (m mod n) / of_nat n :: 'a\<rfloor>"
59984
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   419
    by simp
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   420
  then have "\<lfloor>of_nat m / of_nat n :: 'a\<rfloor> = \<lfloor>of_nat (m mod n) / of_nat n + of_nat (m div n) :: 'a\<rfloor>"
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   421
    by (simp add: ac_simps)
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   422
  moreover have "(of_nat (m div n) :: 'a) = of_int (of_nat (m div n))"
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   423
    by simp
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   424
  ultimately have "\<lfloor>of_nat m / of_nat n :: 'a\<rfloor> = \<lfloor>of_nat (m mod n) / of_nat n :: 'a\<rfloor> + of_nat (m div n)"
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   425
    by (simp only: floor_add_of_int)
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   426
  with * show ?thesis by simp
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   427
qed
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   428
4f1eccec320c conversion between division on nat/int and division in archmedean fields
haftmann
parents: 59613
diff changeset
   429
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   430
subsection \<open>Ceiling function\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   431
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   432
definition ceiling :: "'a::floor_ceiling \<Rightarrow> int"  ("\<lceil>_\<rceil>")
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   433
  where "\<lceil>x\<rceil> = - \<lfloor>- x\<rfloor>"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   434
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   435
lemma ceiling_correct: "of_int \<lceil>x\<rceil> - 1 < x \<and> x \<le> of_int \<lceil>x\<rceil>"
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   436
  unfolding ceiling_def using floor_correct [of "- x"] by (simp add: le_minus_iff)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   437
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   438
lemma ceiling_unique: "\<lbrakk>of_int z - 1 < x; x \<le> of_int z\<rbrakk> \<Longrightarrow> \<lceil>x\<rceil> = z"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   439
  unfolding ceiling_def using floor_unique [of "- z" "- x"] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   440
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   441
lemma le_of_int_ceiling [simp]: "x \<le> of_int \<lceil>x\<rceil>"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   442
  using ceiling_correct ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   443
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   444
lemma ceiling_le_iff: "\<lceil>x\<rceil> \<le> z \<longleftrightarrow> x \<le> of_int z"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   445
  unfolding ceiling_def using le_floor_iff [of "- z" "- x"] by auto
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   446
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   447
lemma less_ceiling_iff: "z < \<lceil>x\<rceil> \<longleftrightarrow> of_int z < x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   448
  by (simp add: not_le [symmetric] ceiling_le_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   449
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   450
lemma ceiling_less_iff: "\<lceil>x\<rceil> < z \<longleftrightarrow> x \<le> of_int z - 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   451
  using ceiling_le_iff [of x "z - 1"] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   452
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   453
lemma le_ceiling_iff: "z \<le> \<lceil>x\<rceil> \<longleftrightarrow> of_int z - 1 < x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   454
  by (simp add: not_less [symmetric] ceiling_less_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   455
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   456
lemma ceiling_mono: "x \<ge> y \<Longrightarrow> \<lceil>x\<rceil> \<ge> \<lceil>y\<rceil>"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   457
  unfolding ceiling_def by (simp add: floor_mono)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   458
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   459
lemma ceiling_less_cancel: "\<lceil>x\<rceil> < \<lceil>y\<rceil> \<Longrightarrow> x < y"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   460
  by (auto simp add: not_le [symmetric] ceiling_mono)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   461
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   462
lemma ceiling_of_int [simp]: "\<lceil>of_int z\<rceil> = z"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   463
  by (rule ceiling_unique) simp_all
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   464
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   465
lemma ceiling_of_nat [simp]: "\<lceil>of_nat n\<rceil> = int n"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   466
  using ceiling_of_int [of "of_nat n"] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   467
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   468
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
   469
  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
   470
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   471
text \<open>Ceiling with numerals\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   472
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   473
lemma ceiling_zero [simp]: "\<lceil>0\<rceil> = 0"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   474
  using ceiling_of_int [of 0] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   475
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   476
lemma ceiling_one [simp]: "\<lceil>1\<rceil> = 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   477
  using ceiling_of_int [of 1] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   478
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   479
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
   480
  using ceiling_of_int [of "numeral v"] by simp
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   481
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   482
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
   483
  using ceiling_of_int [of "- numeral v"] by simp
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   484
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   485
lemma ceiling_le_zero [simp]: "\<lceil>x\<rceil> \<le> 0 \<longleftrightarrow> x \<le> 0"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   486
  by (simp add: ceiling_le_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   487
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   488
lemma ceiling_le_one [simp]: "\<lceil>x\<rceil> \<le> 1 \<longleftrightarrow> x \<le> 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   489
  by (simp add: ceiling_le_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   490
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   491
lemma ceiling_le_numeral [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   492
  "\<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
   493
  by (simp add: ceiling_le_iff)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   494
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   495
lemma ceiling_le_neg_numeral [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   496
  "\<lceil>x\<rceil> \<le> - numeral v \<longleftrightarrow> x \<le> - numeral v"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   497
  by (simp add: ceiling_le_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   498
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   499
lemma ceiling_less_zero [simp]: "\<lceil>x\<rceil> < 0 \<longleftrightarrow> x \<le> -1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   500
  by (simp add: ceiling_less_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   501
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   502
lemma ceiling_less_one [simp]: "\<lceil>x\<rceil> < 1 \<longleftrightarrow> x \<le> 0"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   503
  by (simp add: ceiling_less_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   504
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   505
lemma ceiling_less_numeral [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   506
  "\<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
   507
  by (simp add: ceiling_less_iff)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   508
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   509
lemma ceiling_less_neg_numeral [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   510
  "\<lceil>x\<rceil> < - numeral v \<longleftrightarrow> x \<le> - numeral v - 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   511
  by (simp add: ceiling_less_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   512
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   513
lemma zero_le_ceiling [simp]: "0 \<le> \<lceil>x\<rceil> \<longleftrightarrow> -1 < x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   514
  by (simp add: le_ceiling_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   515
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   516
lemma one_le_ceiling [simp]: "1 \<le> \<lceil>x\<rceil> \<longleftrightarrow> 0 < x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   517
  by (simp add: le_ceiling_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   518
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   519
lemma numeral_le_ceiling [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   520
  "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
   521
  by (simp add: le_ceiling_iff)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   522
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   523
lemma neg_numeral_le_ceiling [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   524
  "- numeral v \<le> \<lceil>x\<rceil> \<longleftrightarrow> - numeral v - 1 < x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   525
  by (simp add: le_ceiling_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   526
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   527
lemma zero_less_ceiling [simp]: "0 < \<lceil>x\<rceil> \<longleftrightarrow> 0 < x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   528
  by (simp add: less_ceiling_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   529
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   530
lemma one_less_ceiling [simp]: "1 < \<lceil>x\<rceil> \<longleftrightarrow> 1 < x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   531
  by (simp add: less_ceiling_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   532
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   533
lemma numeral_less_ceiling [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   534
  "numeral v < \<lceil>x\<rceil> \<longleftrightarrow> numeral v < x"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   535
  by (simp add: less_ceiling_iff)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   536
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
   537
lemma neg_numeral_less_ceiling [simp]:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   538
  "- numeral v < \<lceil>x\<rceil> \<longleftrightarrow> - numeral v < x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   539
  by (simp add: less_ceiling_iff)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   540
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   541
lemma ceiling_altdef: "\<lceil>x\<rceil> = (if x = of_int \<lfloor>x\<rfloor> then \<lfloor>x\<rfloor> else \<lfloor>x\<rfloor> + 1)"
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   542
  by (intro ceiling_unique, (simp, linarith?)+)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   543
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   544
lemma floor_le_ceiling [simp]: "\<lfloor>x\<rfloor> \<le> \<lceil>x\<rceil>"
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   545
  by (simp add: ceiling_altdef)
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   546
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   547
text \<open>Addition and subtraction of integers\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   548
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   549
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
   550
  using ceiling_correct [of x] by (simp add: ceiling_def)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   551
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   552
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
   553
  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
   554
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   555
lemma ceiling_add_one [simp]: "\<lceil>x + 1\<rceil> = \<lceil>x\<rceil> + 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   556
  using ceiling_add_of_int [of x 1] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   557
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   558
lemma ceiling_diff_of_int [simp]: "\<lceil>x - of_int z\<rceil> = \<lceil>x\<rceil> - z"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   559
  using ceiling_add_of_int [of x "- z"] by (simp add: algebra_simps)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   560
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   561
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
   562
  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
   563
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   564
lemma ceiling_diff_one [simp]: "\<lceil>x - 1\<rceil> = \<lceil>x\<rceil> - 1"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   565
  using ceiling_diff_of_int [of x 1] by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   566
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   567
lemma ceiling_split[arith_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
   568
  by (auto simp add: ceiling_unique ceiling_correct)
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 54489
diff changeset
   569
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   570
lemma ceiling_diff_floor_le_1: "\<lceil>x\<rceil> - \<lfloor>x\<rfloor> \<le> 1"
47592
a6b76247534d add ceiling_diff_floor_le_1
hoelzl
parents: 47307
diff changeset
   571
proof -
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   572
  have "of_int \<lceil>x\<rceil> - 1 < x"
47592
a6b76247534d add ceiling_diff_floor_le_1
hoelzl
parents: 47307
diff changeset
   573
    using ceiling_correct[of x] by simp
a6b76247534d add ceiling_diff_floor_le_1
hoelzl
parents: 47307
diff changeset
   574
  also have "x < of_int \<lfloor>x\<rfloor> + 1"
a6b76247534d add ceiling_diff_floor_le_1
hoelzl
parents: 47307
diff changeset
   575
    using floor_correct[of x] by simp_all
a6b76247534d add ceiling_diff_floor_le_1
hoelzl
parents: 47307
diff changeset
   576
  finally have "of_int (\<lceil>x\<rceil> - \<lfloor>x\<rfloor>) < (of_int 2::'a)"
a6b76247534d add ceiling_diff_floor_le_1
hoelzl
parents: 47307
diff changeset
   577
    by simp
a6b76247534d add ceiling_diff_floor_le_1
hoelzl
parents: 47307
diff changeset
   578
  then show ?thesis
a6b76247534d add ceiling_diff_floor_le_1
hoelzl
parents: 47307
diff changeset
   579
    unfolding of_int_less_iff by simp
a6b76247534d add ceiling_diff_floor_le_1
hoelzl
parents: 47307
diff changeset
   580
qed
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   581
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   582
subsection \<open>Negation\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   583
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   584
lemma floor_minus: "\<lfloor>- x\<rfloor> = - \<lceil>x\<rceil>"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   585
  unfolding ceiling_def by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   586
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   587
lemma ceiling_minus: "\<lceil>- x\<rceil> = - \<lfloor>x\<rfloor>"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   588
  unfolding ceiling_def by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   589
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   590
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   591
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
   592
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   593
definition frac :: "'a \<Rightarrow> 'a::floor_ceiling" where
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   594
  "frac x \<equiv> x - of_int \<lfloor>x\<rfloor>"
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   595
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   596
lemma frac_lt_1: "frac x < 1"
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   597
  by  (simp add: frac_def) linarith
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   598
61070
b72a990adfe2 prefer symbols;
wenzelm
parents: 60758
diff changeset
   599
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
   600
  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
   601
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   602
lemma frac_ge_0 [simp]: "frac x \<ge> 0"
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   603
  unfolding frac_def
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   604
  by linarith
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   605
61070
b72a990adfe2 prefer symbols;
wenzelm
parents: 60758
diff changeset
   606
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
   607
  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
   608
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   609
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
   610
  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
   611
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   612
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
   613
proof -
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   614
  {assume "x + y < 1 + (of_int \<lfloor>x\<rfloor> + of_int \<lfloor>y\<rfloor>)"
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   615
   then have "\<lfloor>x + y\<rfloor> = \<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>"
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   616
     by (metis add.commute floor_unique le_floor_add le_floor_iff of_int_add)
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   617
   }
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   618
  moreover
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   619
  { assume "\<not> x + y < 1 + (of_int \<lfloor>x\<rfloor> + of_int \<lfloor>y\<rfloor>)"
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   620
    then have "\<lfloor>x + y\<rfloor> = 1 + (\<lfloor>x\<rfloor> + \<lfloor>y\<rfloor>)"
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   621
      apply (simp add: floor_unique_iff)
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   622
      apply (auto simp add: algebra_simps)
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   623
      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
   624
  }
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   625
  ultimately show ?thesis
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   626
    by (auto simp add: frac_def algebra_simps)
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   627
qed
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   628
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   629
lemma frac_add: "frac (x + y) = (if frac x + frac y < 1 then frac x + frac y
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   630
                                 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
   631
  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
   632
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   633
lemma frac_unique_iff:
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   634
  fixes x :: "'a::floor_ceiling"
62348
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61944
diff changeset
   635
  shows  "frac x = a \<longleftrightarrow> x - a \<in> \<int> \<and> 0 \<le> a \<and> a < 1"
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61944
diff changeset
   636
  apply (auto simp: Ints_def frac_def algebra_simps floor_unique)
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61944
diff changeset
   637
  apply linarith+
9a5f43dac883 dropped various legacy fact bindings
haftmann
parents: 61944
diff changeset
   638
  done
59613
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   639
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   640
lemma frac_eq: "(frac x) = x \<longleftrightarrow> 0 \<le> x \<and> x < 1"
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   641
  by (simp add: frac_unique_iff)
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   642
59613
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   643
lemma frac_neg:
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   644
  fixes x :: "'a::floor_ceiling"
61070
b72a990adfe2 prefer symbols;
wenzelm
parents: 60758
diff changeset
   645
  shows  "frac (-x) = (if x \<in> \<int> then 0 else 1 - frac x)"
59613
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   646
  apply (auto simp add: frac_unique_iff)
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   647
  apply (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
   648
  by (meson frac_lt_1 less_iff_diff_less_0 not_le not_less_iff_gr_or_eq)
7103019278f0 The function frac. Various lemmas about limits, series, the exp function, etc.
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   649
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   650
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   651
subsection \<open>Rounding to the nearest integer\<close>
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   652
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   653
definition round where "round x = \<lfloor>x + 1/2\<rfloor>"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   654
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   655
lemma of_int_round_ge:     "of_int (round x) \<ge> x - 1/2"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   656
  and of_int_round_le:     "of_int (round x) \<le> x + 1/2"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   657
  and of_int_round_abs_le: "\<bar>of_int (round x) - x\<bar> \<le> 1/2"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   658
  and of_int_round_gt:     "of_int (round x) > x - 1/2"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   659
proof -
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   660
  from floor_correct[of "x + 1/2"] have "x + 1/2 < of_int (round x) + 1" by (simp add: round_def)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   661
  from add_strict_right_mono[OF this, of "-1"] show A: "of_int (round x) > x - 1/2" by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   662
  thus "of_int (round x) \<ge> x - 1/2" by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   663
  from floor_correct[of "x + 1/2"] show "of_int (round x) \<le> x + 1/2" by (simp add: round_def)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   664
  with A show "\<bar>of_int (round x) - x\<bar> \<le> 1/2" by linarith
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   665
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   666
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   667
lemma round_of_int [simp]: "round (of_int n) = n"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   668
  unfolding round_def by (subst floor_unique_iff) force
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   669
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   670
lemma round_0 [simp]: "round 0 = 0"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   671
  using round_of_int[of 0] by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   672
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   673
lemma round_1 [simp]: "round 1 = 1"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   674
  using round_of_int[of 1] by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   675
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   676
lemma round_numeral [simp]: "round (numeral n) = numeral n"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   677
  using round_of_int[of "numeral n"] by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   678
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   679
lemma round_neg_numeral [simp]: "round (-numeral n) = -numeral n"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   680
  using round_of_int[of "-numeral n"] by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   681
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   682
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
   683
  using round_of_int[of "int n"] by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   684
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   685
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
   686
  unfolding round_def by (intro floor_mono) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   687
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   688
lemma round_unique: "of_int y > x - 1/2 \<Longrightarrow> of_int y \<le> x + 1/2 \<Longrightarrow> round x = y"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   689
unfolding round_def
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   690
proof (rule floor_unique)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   691
  assume "x - 1 / 2 < of_int y"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   692
  from add_strict_left_mono[OF this, of 1] show "x + 1 / 2 < of_int y + 1" by simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   693
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   694
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   695
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
   696
  by (cases "frac x \<ge> 1/2")
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   697
     (rule round_unique, ((simp add: frac_def field_simps ceiling_altdef, linarith?)+)[2])+
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   698
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   699
lemma floor_le_round: "\<lfloor>x\<rfloor> \<le> round x"
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   700
  unfolding round_def by (intro floor_mono) simp
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   701
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   702
lemma ceiling_ge_round: "\<lceil>x\<rceil> \<ge> round x" unfolding round_altdef by simp
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   703
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
   704
lemma round_diff_minimal:
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   705
  fixes z :: "'a :: floor_ceiling"
61944
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61942
diff changeset
   706
  shows "\<bar>z - of_int (round z)\<bar> \<le> \<bar>z - of_int m\<bar>"
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   707
proof (cases "of_int m \<ge> z")
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   708
  case True
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   709
  hence "\<bar>z - of_int (round z)\<bar> \<le> \<bar>of_int \<lceil>z\<rceil> - z\<bar>"
61738
c4f6031f1310 New material about paths, winding numbers, etc. Added lemmas to divide_const_simps. Misc tuning.
paulson <lp15@cam.ac.uk>
parents: 61649
diff changeset
   710
    unfolding round_altdef by (simp add: field_simps ceiling_altdef frac_def) linarith?
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   711
  also have "of_int \<lceil>z\<rceil> - z \<ge> 0" by linarith
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   712
  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
   713
    by (simp add: ceiling_le_iff)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   714
  finally show ?thesis .
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   715
next
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   716
  case False
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   717
  hence "\<bar>z - of_int (round z)\<bar> \<le> \<bar>of_int \<lfloor>z\<rfloor> - z\<bar>"
61738
c4f6031f1310 New material about paths, winding numbers, etc. Added lemmas to divide_const_simps. Misc tuning.
paulson <lp15@cam.ac.uk>
parents: 61649
diff changeset
   718
    unfolding round_altdef by (simp add: field_simps ceiling_altdef frac_def) linarith?
61531
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   719
  also have "z - of_int \<lfloor>z\<rfloor> \<ge> 0" by linarith
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   720
  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
   721
    by (simp add: le_floor_iff)
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   722
  finally show ?thesis .
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   723
qed
ab2e862263e7 Rounding function, uniform limits, cotangent, binomial identities
eberlm
parents: 61378
diff changeset
   724
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   725
end