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