src/HOL/Archimedean_Field.thy
author wenzelm
Tue, 10 Nov 2020 12:48:56 +0100
changeset 72571 ab4a0b19648a
parent 70365 4df0628e8545
child 75878 fcd118d9242f
permissions -rw-r--r--
tuned signature;
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
70365
4df0628e8545 a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents: 68721
diff changeset
    29
    have *: "\<And>x. x \<in> S \<Longrightarrow> Inf S \<le> x"
4df0628e8545 a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents: 68721
diff changeset
    30
      by (meson abs_le_iff bdd bdd_below_def cInf_lower minus_le_iff)
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    31
    show "Sup (uminus ` S) \<le> - Inf S"
70365
4df0628e8545 a few new lemmas and a bit of tidying
paulson <lp15@cam.ac.uk>
parents: 68721
diff changeset
    32
      using \<open>S \<noteq> {}\<close> by (force intro: * cSup_least)
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    33
  qed
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    34
  with cSup_abs_le [of "uminus ` S"] assms show ?thesis
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    35
    by fastforce
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    36
qed
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    37
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    38
lemma cSup_asclose:
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    39
  fixes S :: "'a::{linordered_idom,conditionally_complete_linorder} set"
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    40
  assumes S: "S \<noteq> {}"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    41
    and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    42
  shows "\<bar>Sup S - l\<bar> \<le> e"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    43
proof -
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    44
  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
    45
    by arith
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    46
  have "bdd_above S"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    47
    using b by (auto intro!: bdd_aboveI[of _ "l + e"])
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    48
  with S b show ?thesis
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    49
    unfolding * by (auto intro!: cSup_upper2 cSup_least)
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    50
qed
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    51
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    52
lemma cInf_asclose:
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    53
  fixes S :: "'a::{linordered_idom,conditionally_complete_linorder} set"
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    54
  assumes S: "S \<noteq> {}"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    55
    and b: "\<forall>x\<in>S. \<bar>x - l\<bar> \<le> e"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    56
  shows "\<bar>Inf S - l\<bar> \<le> e"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    57
proof -
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    58
  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
    59
    by arith
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    60
  have "bdd_below S"
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    61
    using b by (auto intro!: bdd_belowI[of _ "l - e"])
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    62
  with S b show ?thesis
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    63
    unfolding * by (auto intro!: cInf_lower2 cInf_greatest)
63331
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    64
qed
247eac9758dd move Conditional_Complete_Lattices to Main
hoelzl
parents: 62623
diff changeset
    65
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    66
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
    67
subsection \<open>Class of Archimedean fields\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    68
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
    69
text \<open>Archimedean fields have no infinite elements.\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    70
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 43733
diff changeset
    71
class archimedean_field = linordered_field +
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    72
  assumes ex_le_of_int: "\<exists>z. x \<le> of_int z"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    73
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    74
lemma ex_less_of_int: "\<exists>z. x < of_int z"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    75
  for x :: "'a::archimedean_field"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    76
proof -
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    77
  from ex_le_of_int obtain z where "x \<le> of_int z" ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    78
  then have "x < of_int (z + 1)" by simp
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    79
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    80
qed
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_of_int_less: "\<exists>z. of_int z < x"
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_less_of_int obtain z where "- x < of_int z" ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    86
  then have "of_int (- z) < x" 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 reals_Archimedean2: "\<exists>n. x < of_nat n"
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 -
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    93
  obtain z where "x < of_int z"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    94
    using ex_less_of_int ..
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    95
  also have "\<dots> \<le> of_int (int (nat z))"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    96
    by simp
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    97
  also have "\<dots> = of_nat (nat z)"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    98
    by (simp only: of_int_of_nat_eq)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
    99
  finally show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   100
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   101
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   102
lemma real_arch_simple: "\<exists>n. x \<le> of_nat n"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   103
  for x :: "'a::archimedean_field"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   104
proof -
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   105
  obtain n where "x < of_nat n"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   106
    using reals_Archimedean2 ..
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   107
  then have "x \<le> of_nat n"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   108
    by simp
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   109
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   110
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   111
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   112
text \<open>Archimedean fields have no infinitesimal elements.\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   113
62623
dbc62f86a1a9 rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents: 62348
diff changeset
   114
lemma reals_Archimedean:
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   115
  fixes x :: "'a::archimedean_field"
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   116
  assumes "0 < x"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   117
  shows "\<exists>n. inverse (of_nat (Suc n)) < x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   118
proof -
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   119
  from \<open>0 < x\<close> have "0 < inverse x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   120
    by (rule positive_imp_inverse_positive)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   121
  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
   122
    using reals_Archimedean2 ..
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   123
  then obtain m where "inverse x < of_nat (Suc m)"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   124
    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
   125
  then have "inverse (of_nat (Suc m)) < inverse (inverse x)"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   126
    using \<open>0 < inverse x\<close> by (rule less_imp_inverse_less)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   127
  then have "inverse (of_nat (Suc m)) < x"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   128
    using \<open>0 < x\<close> by (simp add: nonzero_inverse_inverse_eq)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   129
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   130
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   131
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   132
lemma ex_inverse_of_nat_less:
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   133
  fixes x :: "'a::archimedean_field"
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   134
  assumes "0 < x"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   135
  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
   136
  using reals_Archimedean [OF \<open>0 < x\<close>] by auto
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   137
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   138
lemma ex_less_of_nat_mult:
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   139
  fixes x :: "'a::archimedean_field"
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   140
  assumes "0 < x"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   141
  shows "\<exists>n. y < of_nat n * x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   142
proof -
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   143
  obtain n where "y / x < of_nat n"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   144
    using reals_Archimedean2 ..
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   145
  with \<open>0 < x\<close> have "y < of_nat n * x"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   146
    by (simp add: pos_divide_less_eq)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   147
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   148
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   149
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   150
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   151
subsection \<open>Existence and uniqueness of floor function\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   152
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   153
lemma exists_least_lemma:
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   154
  assumes "\<not> P 0" and "\<exists>n. P n"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   155
  shows "\<exists>n. \<not> P n \<and> P (Suc n)"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   156
proof -
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   157
  from \<open>\<exists>n. P n\<close> have "P (Least P)"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   158
    by (rule LeastI_ex)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   159
  with \<open>\<not> P 0\<close> obtain n where "Least P = Suc n"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   160
    by (cases "Least P") auto
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   161
  then have "n < Least P"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   162
    by simp
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   163
  then have "\<not> P n"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   164
    by (rule not_less_Least)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   165
  then have "\<not> P n \<and> P (Suc n)"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   166
    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
   167
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   168
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   169
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   170
lemma floor_exists:
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   171
  fixes x :: "'a::archimedean_field"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   172
  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
   173
proof (cases "0 \<le> x")
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   174
  case True
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   175
  then have "\<not> x < of_nat 0"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   176
    by simp
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   177
  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
   178
    using reals_Archimedean2 by (rule exists_least_lemma)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   179
  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
   180
  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
   181
    by simp
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   182
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   183
next
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   184
  case False
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   185
  then have "\<not> - x \<le> of_nat 0"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   186
    by simp
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   187
  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
   188
    using real_arch_simple by (rule exists_least_lemma)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   189
  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
   190
  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
   191
    by simp
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   192
  then show ?thesis ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   193
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   194
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   195
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
   196
  for x :: "'a::archimedean_field"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   197
proof (rule ex_ex1I)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   198
  show "\<exists>z. of_int z \<le> x \<and> x < of_int (z + 1)"
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   199
    by (rule floor_exists)
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   200
next
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   201
  fix y z
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   202
  assume "of_int y \<le> x \<and> x < of_int (y + 1)"
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   203
    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
   204
  with le_less_trans [of "of_int y" "x" "of_int (z + 1)"]
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   205
       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
   206
    by (simp del: of_int_add)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   207
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   208
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   209
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60128
diff changeset
   210
subsection \<open>Floor function\<close>
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   211
43732
6b2bdc57155b adding a floor_ceiling type class for different instantiations of floor (changeset from Brian Huffman)
bulwahn
parents: 43704
diff changeset
   212
class floor_ceiling = archimedean_field +
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   213
  fixes floor :: "'a \<Rightarrow> int"  ("\<lfloor>_\<rfloor>")
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   214
  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
   215
63489
cd540c8031a4 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   216
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
   217
  using floor_correct [of x] floor_exists1 [of x] by auto
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   218
66515
85c505c98332 reorganized and added log-related lemmas
nipkow
parents: 66154
diff changeset
   219
lemma floor_eq_iff: "\<lfloor>x\<rfloor> = a \<longleftrightarrow> of_int a \<le> x \<and> x < of_int a + 1"
85c505c98332 reorganized and added log-related lemmas
nipkow
parents: 66154
diff changeset
   220
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
   221
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   222
lemma of_int_floor_le [simp]: "of_int \<lfloor>x\<rfloor> \<le> x"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   223
  using floor_correct ..
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   224
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   225
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
   226
proof
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   227
  assume "z \<le> \<lfloor>x\<rfloor>"
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   228
  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
   229
  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
   230
  finally show "of_int z \<le> x" .
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   231
next
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   232
  assume "of_int z \<le> x"
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   233
  also have "x < of_int (\<lfloor>x\<rfloor> + 1)" using floor_correct ..
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   234
  finally show "z \<le> \<lfloor>x\<rfloor>" by (simp del: of_int_add)
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   235
qed
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   236
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61738
diff changeset
   237
lemma floor_less_iff: "\<lfloor>x\<rfloor> < z \<longleftrightarrow> x < of_int z"
30096
c5497842ee35 new theory of Archimedean fields
huffman
parents:
diff changeset
   238
  by (simp add: not_le [symmetric] le_floor_iff)