src/HOL/Real.thy
author kuncar
Fri, 27 Sep 2013 14:43:26 +0200
changeset 53952 b2781a3ce958
parent 53652 18fbca265e2e
child 54230 b1d955791529
permissions -rw-r--r--
new parametricity rules and useful lemmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     1
(*  Title:      HOL/Real.thy
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     2
    Author:     Jacques D. Fleuriot, University of Edinburgh, 1998
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     3
    Author:     Larry Paulson, University of Cambridge
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     4
    Author:     Jeremy Avigad, Carnegie Mellon University
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     5
    Author:     Florian Zuleger, Johannes Hoelzl, and Simon Funke, TU Muenchen
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     6
    Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     7
    Construction of Cauchy Reals by Brian Huffman, 2010
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     8
*)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     9
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    10
header {* Development of the Reals using Cauchy Sequences *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    11
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    12
theory Real
51773
9328c6681f3c spell conditional_ly_-complete lattices correct
hoelzl
parents: 51539
diff changeset
    13
imports Rat Conditionally_Complete_Lattices
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    14
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    15
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    16
text {*
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    17
  This theory contains a formalization of the real numbers as
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    18
  equivalence classes of Cauchy sequences of rationals.  See
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    19
  @{file "~~/src/HOL/ex/Dedekind_Real.thy"} for an alternative
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    20
  construction using Dedekind cuts.
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    21
*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    22
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    23
subsection {* Preliminary lemmas *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    24
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    25
lemma add_diff_add:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    26
  fixes a b c d :: "'a::ab_group_add"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    27
  shows "(a + c) - (b + d) = (a - b) + (c - d)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    28
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    29
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    30
lemma minus_diff_minus:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    31
  fixes a b :: "'a::ab_group_add"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    32
  shows "- a - - b = - (a - b)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    33
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    34
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    35
lemma mult_diff_mult:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    36
  fixes x y a b :: "'a::ring"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    37
  shows "(x * y - a * b) = x * (y - b) + (x - a) * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    38
  by (simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    39
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    40
lemma inverse_diff_inverse:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    41
  fixes a b :: "'a::division_ring"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    42
  assumes "a \<noteq> 0" and "b \<noteq> 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    43
  shows "inverse a - inverse b = - (inverse a * (a - b) * inverse b)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    44
  using assms by (simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    45
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    46
lemma obtain_pos_sum:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    47
  fixes r :: rat assumes r: "0 < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    48
  obtains s t where "0 < s" and "0 < t" and "r = s + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    49
proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    50
    from r show "0 < r/2" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    51
    from r show "0 < r/2" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    52
    show "r = r/2 + r/2" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    53
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    54
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    55
subsection {* Sequences that converge to zero *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    56
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    57
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    58
  vanishes :: "(nat \<Rightarrow> rat) \<Rightarrow> bool"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    59
where
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    60
  "vanishes X = (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    61
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    62
lemma vanishesI: "(\<And>r. 0 < r \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r) \<Longrightarrow> vanishes X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    63
  unfolding vanishes_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    64
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    65
lemma vanishesD: "\<lbrakk>vanishes X; 0 < r\<rbrakk> \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    66
  unfolding vanishes_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    67
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    68
lemma vanishes_const [simp]: "vanishes (\<lambda>n. c) \<longleftrightarrow> c = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    69
  unfolding vanishes_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    70
  apply (cases "c = 0", auto)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    71
  apply (rule exI [where x="\<bar>c\<bar>"], auto)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    72
  done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    73
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    74
lemma vanishes_minus: "vanishes X \<Longrightarrow> vanishes (\<lambda>n. - X n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    75
  unfolding vanishes_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    76
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    77
lemma vanishes_add:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    78
  assumes X: "vanishes X" and Y: "vanishes Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    79
  shows "vanishes (\<lambda>n. X n + Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    80
proof (rule vanishesI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    81
  fix r :: rat assume "0 < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    82
  then obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    83
    by (rule obtain_pos_sum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    84
  obtain i where i: "\<forall>n\<ge>i. \<bar>X n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    85
    using vanishesD [OF X s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    86
  obtain j where j: "\<forall>n\<ge>j. \<bar>Y n\<bar> < t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    87
    using vanishesD [OF Y t] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    88
  have "\<forall>n\<ge>max i j. \<bar>X n + Y n\<bar> < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    89
  proof (clarsimp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    90
    fix n assume n: "i \<le> n" "j \<le> n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    91
    have "\<bar>X n + Y n\<bar> \<le> \<bar>X n\<bar> + \<bar>Y n\<bar>" by (rule abs_triangle_ineq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    92
    also have "\<dots> < s + t" by (simp add: add_strict_mono i j n)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    93
    finally show "\<bar>X n + Y n\<bar> < r" unfolding r .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    94
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    95
  thus "\<exists>k. \<forall>n\<ge>k. \<bar>X n + Y n\<bar> < r" ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    96
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    97
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    98
lemma vanishes_diff:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    99
  assumes X: "vanishes X" and Y: "vanishes Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   100
  shows "vanishes (\<lambda>n. X n - Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   101
unfolding diff_minus by (intro vanishes_add vanishes_minus X Y)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   102
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   103
lemma vanishes_mult_bounded:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   104
  assumes X: "\<exists>a>0. \<forall>n. \<bar>X n\<bar> < a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   105
  assumes Y: "vanishes (\<lambda>n. Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   106
  shows "vanishes (\<lambda>n. X n * Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   107
proof (rule vanishesI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   108
  fix r :: rat assume r: "0 < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   109
  obtain a where a: "0 < a" "\<forall>n. \<bar>X n\<bar> < a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   110
    using X by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   111
  obtain b where b: "0 < b" "r = a * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   112
  proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   113
    show "0 < r / a" using r a by (simp add: divide_pos_pos)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   114
    show "r = a * (r / a)" using a by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   115
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   116
  obtain k where k: "\<forall>n\<ge>k. \<bar>Y n\<bar> < b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   117
    using vanishesD [OF Y b(1)] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   118
  have "\<forall>n\<ge>k. \<bar>X n * Y n\<bar> < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   119
    by (simp add: b(2) abs_mult mult_strict_mono' a k)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   120
  thus "\<exists>k. \<forall>n\<ge>k. \<bar>X n * Y n\<bar> < r" ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   121
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   122
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   123
subsection {* Cauchy sequences *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   124
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   125
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   126
  cauchy :: "(nat \<Rightarrow> rat) \<Rightarrow> bool"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   127
where
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   128
  "cauchy X \<longleftrightarrow> (\<forall>r>0. \<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   129
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   130
lemma cauchyI:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   131
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r) \<Longrightarrow> cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   132
  unfolding cauchy_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   133
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   134
lemma cauchyD:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   135
  "\<lbrakk>cauchy X; 0 < r\<rbrakk> \<Longrightarrow> \<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   136
  unfolding cauchy_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   137
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   138
lemma cauchy_const [simp]: "cauchy (\<lambda>n. x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   139
  unfolding cauchy_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   140
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   141
lemma cauchy_add [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   142
  assumes X: "cauchy X" and Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   143
  shows "cauchy (\<lambda>n. X n + Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   144
proof (rule cauchyI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   145
  fix r :: rat assume "0 < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   146
  then obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   147
    by (rule obtain_pos_sum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   148
  obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   149
    using cauchyD [OF X s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   150
  obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>Y m - Y n\<bar> < t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   151
    using cauchyD [OF Y t] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   152
  have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>(X m + Y m) - (X n + Y n)\<bar> < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   153
  proof (clarsimp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   154
    fix m n assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   155
    have "\<bar>(X m + Y m) - (X n + Y n)\<bar> \<le> \<bar>X m - X n\<bar> + \<bar>Y m - Y n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   156
      unfolding add_diff_add by (rule abs_triangle_ineq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   157
    also have "\<dots> < s + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   158
      by (rule add_strict_mono, simp_all add: i j *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   159
    finally show "\<bar>(X m + Y m) - (X n + Y n)\<bar> < r" unfolding r .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   160
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   161
  thus "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>(X m + Y m) - (X n + Y n)\<bar> < r" ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   162
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   163
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   164
lemma cauchy_minus [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   165
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   166
  shows "cauchy (\<lambda>n. - X n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   167
using assms unfolding cauchy_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   168
unfolding minus_diff_minus abs_minus_cancel .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   169
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   170
lemma cauchy_diff [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   171
  assumes X: "cauchy X" and Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   172
  shows "cauchy (\<lambda>n. X n - Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   173
using assms unfolding diff_minus by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   174
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   175
lemma cauchy_imp_bounded:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   176
  assumes "cauchy X" shows "\<exists>b>0. \<forall>n. \<bar>X n\<bar> < b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   177
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   178
  obtain k where k: "\<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   179
    using cauchyD [OF assms zero_less_one] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   180
  show "\<exists>b>0. \<forall>n. \<bar>X n\<bar> < b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   181
  proof (intro exI conjI allI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   182
    have "0 \<le> \<bar>X 0\<bar>" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   183
    also have "\<bar>X 0\<bar> \<le> Max (abs ` X ` {..k})" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   184
    finally have "0 \<le> Max (abs ` X ` {..k})" .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   185
    thus "0 < Max (abs ` X ` {..k}) + 1" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   186
  next
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   187
    fix n :: nat
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   188
    show "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   189
    proof (rule linorder_le_cases)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   190
      assume "n \<le> k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   191
      hence "\<bar>X n\<bar> \<le> Max (abs ` X ` {..k})" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   192
      thus "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   193
    next
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   194
      assume "k \<le> n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   195
      have "\<bar>X n\<bar> = \<bar>X k + (X n - X k)\<bar>" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   196
      also have "\<bar>X k + (X n - X k)\<bar> \<le> \<bar>X k\<bar> + \<bar>X n - X k\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   197
        by (rule abs_triangle_ineq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   198
      also have "\<dots> < Max (abs ` X ` {..k}) + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   199
        by (rule add_le_less_mono, simp, simp add: k `k \<le> n`)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   200
      finally show "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1" .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   201
    qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   202
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   203
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   204
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   205
lemma cauchy_mult [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   206
  assumes X: "cauchy X" and Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   207
  shows "cauchy (\<lambda>n. X n * Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   208
proof (rule cauchyI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   209
  fix r :: rat assume "0 < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   210
  then obtain u v where u: "0 < u" and v: "0 < v" and "r = u + v"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   211
    by (rule obtain_pos_sum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   212
  obtain a where a: "0 < a" "\<forall>n. \<bar>X n\<bar> < a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   213
    using cauchy_imp_bounded [OF X] by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   214
  obtain b where b: "0 < b" "\<forall>n. \<bar>Y n\<bar> < b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   215
    using cauchy_imp_bounded [OF Y] by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   216
  obtain s t where s: "0 < s" and t: "0 < t" and r: "r = a * t + s * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   217
  proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   218
    show "0 < v/b" using v b(1) by (rule divide_pos_pos)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   219
    show "0 < u/a" using u a(1) by (rule divide_pos_pos)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   220
    show "r = a * (u/a) + (v/b) * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   221
      using a(1) b(1) `r = u + v` by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   222
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   223
  obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   224
    using cauchyD [OF X s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   225
  obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>Y m - Y n\<bar> < t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   226
    using cauchyD [OF Y t] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   227
  have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>X m * Y m - X n * Y n\<bar> < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   228
  proof (clarsimp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   229
    fix m n assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   230
    have "\<bar>X m * Y m - X n * Y n\<bar> = \<bar>X m * (Y m - Y n) + (X m - X n) * Y n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   231
      unfolding mult_diff_mult ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   232
    also have "\<dots> \<le> \<bar>X m * (Y m - Y n)\<bar> + \<bar>(X m - X n) * Y n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   233
      by (rule abs_triangle_ineq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   234
    also have "\<dots> = \<bar>X m\<bar> * \<bar>Y m - Y n\<bar> + \<bar>X m - X n\<bar> * \<bar>Y n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   235
      unfolding abs_mult ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   236
    also have "\<dots> < a * t + s * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   237
      by (simp_all add: add_strict_mono mult_strict_mono' a b i j *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   238
    finally show "\<bar>X m * Y m - X n * Y n\<bar> < r" unfolding r .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   239
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   240
  thus "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m * Y m - X n * Y n\<bar> < r" ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   241
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   242
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   243
lemma cauchy_not_vanishes_cases:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   244
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   245
  assumes nz: "\<not> vanishes X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   246
  shows "\<exists>b>0. \<exists>k. (\<forall>n\<ge>k. b < - X n) \<or> (\<forall>n\<ge>k. b < X n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   247
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   248
  obtain r where "0 < r" and r: "\<forall>k. \<exists>n\<ge>k. r \<le> \<bar>X n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   249
    using nz unfolding vanishes_def by (auto simp add: not_less)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   250
  obtain s t where s: "0 < s" and t: "0 < t" and "r = s + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   251
    using `0 < r` by (rule obtain_pos_sum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   252
  obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   253
    using cauchyD [OF X s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   254
  obtain k where "i \<le> k" and "r \<le> \<bar>X k\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   255
    using r by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   256
  have k: "\<forall>n\<ge>k. \<bar>X n - X k\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   257
    using i `i \<le> k` by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   258
  have "X k \<le> - r \<or> r \<le> X k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   259
    using `r \<le> \<bar>X k\<bar>` by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   260
  hence "(\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   261
    unfolding `r = s + t` using k by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   262
  hence "\<exists>k. (\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)" ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   263
  thus "\<exists>t>0. \<exists>k. (\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   264
    using t by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   265
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   266
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   267
lemma cauchy_not_vanishes:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   268
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   269
  assumes nz: "\<not> vanishes X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   270
  shows "\<exists>b>0. \<exists>k. \<forall>n\<ge>k. b < \<bar>X n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   271
using cauchy_not_vanishes_cases [OF assms]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   272
by clarify (rule exI, erule conjI, rule_tac x=k in exI, auto)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   273
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   274
lemma cauchy_inverse [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   275
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   276
  assumes nz: "\<not> vanishes X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   277
  shows "cauchy (\<lambda>n. inverse (X n))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   278
proof (rule cauchyI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   279
  fix r :: rat assume "0 < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   280
  obtain b i where b: "0 < b" and i: "\<forall>n\<ge>i. b < \<bar>X n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   281
    using cauchy_not_vanishes [OF X nz] by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   282
  from b i have nz: "\<forall>n\<ge>i. X n \<noteq> 0" by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   283
  obtain s where s: "0 < s" and r: "r = inverse b * s * inverse b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   284
  proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   285
    show "0 < b * r * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   286
      by (simp add: `0 < r` b mult_pos_pos)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   287
    show "r = inverse b * (b * r * b) * inverse b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   288
      using b by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   289
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   290
  obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>X m - X n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   291
    using cauchyD [OF X s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   292
  have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>inverse (X m) - inverse (X n)\<bar> < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   293
  proof (clarsimp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   294
    fix m n assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   295
    have "\<bar>inverse (X m) - inverse (X n)\<bar> =
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   296
          inverse \<bar>X m\<bar> * \<bar>X m - X n\<bar> * inverse \<bar>X n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   297
      by (simp add: inverse_diff_inverse nz * abs_mult)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   298
    also have "\<dots> < inverse b * s * inverse b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   299
      by (simp add: mult_strict_mono less_imp_inverse_less
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   300
                    mult_pos_pos i j b * s)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   301
    finally show "\<bar>inverse (X m) - inverse (X n)\<bar> < r" unfolding r .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   302
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   303
  thus "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>inverse (X m) - inverse (X n)\<bar> < r" ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   304
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   305
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   306
lemma vanishes_diff_inverse:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   307
  assumes X: "cauchy X" "\<not> vanishes X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   308
  assumes Y: "cauchy Y" "\<not> vanishes Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   309
  assumes XY: "vanishes (\<lambda>n. X n - Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   310
  shows "vanishes (\<lambda>n. inverse (X n) - inverse (Y n))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   311
proof (rule vanishesI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   312
  fix r :: rat assume r: "0 < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   313
  obtain a i where a: "0 < a" and i: "\<forall>n\<ge>i. a < \<bar>X n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   314
    using cauchy_not_vanishes [OF X] by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   315
  obtain b j where b: "0 < b" and j: "\<forall>n\<ge>j. b < \<bar>Y n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   316
    using cauchy_not_vanishes [OF Y] by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   317
  obtain s where s: "0 < s" and "inverse a * s * inverse b = r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   318
  proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   319
    show "0 < a * r * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   320
      using a r b by (simp add: mult_pos_pos)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   321
    show "inverse a * (a * r * b) * inverse b = r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   322
      using a r b by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   323
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   324
  obtain k where k: "\<forall>n\<ge>k. \<bar>X n - Y n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   325
    using vanishesD [OF XY s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   326
  have "\<forall>n\<ge>max (max i j) k. \<bar>inverse (X n) - inverse (Y n)\<bar> < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   327
  proof (clarsimp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   328
    fix n assume n: "i \<le> n" "j \<le> n" "k \<le> n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   329
    have "X n \<noteq> 0" and "Y n \<noteq> 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   330
      using i j a b n by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   331
    hence "\<bar>inverse (X n) - inverse (Y n)\<bar> =
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   332
        inverse \<bar>X n\<bar> * \<bar>X n - Y n\<bar> * inverse \<bar>Y n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   333
      by (simp add: inverse_diff_inverse abs_mult)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   334
    also have "\<dots> < inverse a * s * inverse b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   335
      apply (intro mult_strict_mono' less_imp_inverse_less)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   336
      apply (simp_all add: a b i j k n mult_nonneg_nonneg)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   337
      done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   338
    also note `inverse a * s * inverse b = r`
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   339
    finally show "\<bar>inverse (X n) - inverse (Y n)\<bar> < r" .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   340
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   341
  thus "\<exists>k. \<forall>n\<ge>k. \<bar>inverse (X n) - inverse (Y n)\<bar> < r" ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   342
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   343
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   344
subsection {* Equivalence relation on Cauchy sequences *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   345
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   346
definition realrel :: "(nat \<Rightarrow> rat) \<Rightarrow> (nat \<Rightarrow> rat) \<Rightarrow> bool"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   347
  where "realrel = (\<lambda>X Y. cauchy X \<and> cauchy Y \<and> vanishes (\<lambda>n. X n - Y n))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   348
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   349
lemma realrelI [intro?]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   350
  assumes "cauchy X" and "cauchy Y" and "vanishes (\<lambda>n. X n - Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   351
  shows "realrel X Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   352
  using assms unfolding realrel_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   353
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   354
lemma realrel_refl: "cauchy X \<Longrightarrow> realrel X X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   355
  unfolding realrel_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   356
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   357
lemma symp_realrel: "symp realrel"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   358
  unfolding realrel_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   359
  by (rule sympI, clarify, drule vanishes_minus, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   360
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   361
lemma transp_realrel: "transp realrel"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   362
  unfolding realrel_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   363
  apply (rule transpI, clarify)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   364
  apply (drule (1) vanishes_add)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   365
  apply (simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   366
  done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   367
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   368
lemma part_equivp_realrel: "part_equivp realrel"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   369
  by (fast intro: part_equivpI symp_realrel transp_realrel
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   370
    realrel_refl cauchy_const)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   371
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   372
subsection {* The field of real numbers *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   373
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   374
quotient_type real = "nat \<Rightarrow> rat" / partial: realrel
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   375
  morphisms rep_real Real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   376
  by (rule part_equivp_realrel)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   377
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   378
lemma cr_real_eq: "pcr_real = (\<lambda>x y. cauchy x \<and> Real x = y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   379
  unfolding real.pcr_cr_eq cr_real_def realrel_def by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   380
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   381
lemma Real_induct [induct type: real]: (* TODO: generate automatically *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   382
  assumes "\<And>X. cauchy X \<Longrightarrow> P (Real X)" shows "P x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   383
proof (induct x)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   384
  case (1 X)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   385
  hence "cauchy X" by (simp add: realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   386
  thus "P (Real X)" by (rule assms)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   387
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   388
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   389
lemma eq_Real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   390
  "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> Real X = Real Y \<longleftrightarrow> vanishes (\<lambda>n. X n - Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   391
  using real.rel_eq_transfer
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   392
  unfolding real.pcr_cr_eq cr_real_def fun_rel_def realrel_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   393
51956
a4d81cdebf8b better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
kuncar
parents: 51775
diff changeset
   394
lemma Domainp_pcr_real [transfer_domain_rule]: "Domainp pcr_real = cauchy"
a4d81cdebf8b better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
kuncar
parents: 51775
diff changeset
   395
by (simp add: real.domain_eq realrel_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   396
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   397
instantiation real :: field_inverse_zero
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   398
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   399
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   400
lift_definition zero_real :: "real" is "\<lambda>n. 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   401
  by (simp add: realrel_refl)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   402
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   403
lift_definition one_real :: "real" is "\<lambda>n. 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   404
  by (simp add: realrel_refl)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   405
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   406
lift_definition plus_real :: "real \<Rightarrow> real \<Rightarrow> real" is "\<lambda>X Y n. X n + Y n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   407
  unfolding realrel_def add_diff_add
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   408
  by (simp only: cauchy_add vanishes_add simp_thms)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   409
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   410
lift_definition uminus_real :: "real \<Rightarrow> real" is "\<lambda>X n. - X n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   411
  unfolding realrel_def minus_diff_minus
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   412
  by (simp only: cauchy_minus vanishes_minus simp_thms)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   413
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   414
lift_definition times_real :: "real \<Rightarrow> real \<Rightarrow> real" is "\<lambda>X Y n. X n * Y n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   415
  unfolding realrel_def mult_diff_mult
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   416
  by (subst (4) mult_commute, simp only: cauchy_mult vanishes_add
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   417
    vanishes_mult_bounded cauchy_imp_bounded simp_thms)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   418
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   419
lift_definition inverse_real :: "real \<Rightarrow> real"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   420
  is "\<lambda>X. if vanishes X then (\<lambda>n. 0) else (\<lambda>n. inverse (X n))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   421
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   422
  fix X Y assume "realrel X Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   423
  hence X: "cauchy X" and Y: "cauchy Y" and XY: "vanishes (\<lambda>n. X n - Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   424
    unfolding realrel_def by simp_all
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   425
  have "vanishes X \<longleftrightarrow> vanishes Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   426
  proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   427
    assume "vanishes X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   428
    from vanishes_diff [OF this XY] show "vanishes Y" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   429
  next
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   430
    assume "vanishes Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   431
    from vanishes_add [OF this XY] show "vanishes X" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   432
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   433
  thus "?thesis X Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   434
    unfolding realrel_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   435
    by (simp add: vanishes_diff_inverse X Y XY)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   436
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   437
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   438
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   439
  "x - y = (x::real) + - y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   440
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   441
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   442
  "x / y = (x::real) * inverse y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   443
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   444
lemma add_Real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   445
  assumes X: "cauchy X" and Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   446
  shows "Real X + Real Y = Real (\<lambda>n. X n + Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   447
  using assms plus_real.transfer
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   448
  unfolding cr_real_eq fun_rel_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   449
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   450
lemma minus_Real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   451
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   452
  shows "- Real X = Real (\<lambda>n. - X n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   453
  using assms uminus_real.transfer
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   454
  unfolding cr_real_eq fun_rel_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   455
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   456
lemma diff_Real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   457
  assumes X: "cauchy X" and Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   458
  shows "Real X - Real Y = Real (\<lambda>n. X n - Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   459
  unfolding minus_real_def diff_minus
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   460
  by (simp add: minus_Real add_Real X Y)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   461
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   462
lemma mult_Real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   463
  assumes X: "cauchy X" and Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   464
  shows "Real X * Real Y = Real (\<lambda>n. X n * Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   465
  using assms times_real.transfer
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   466
  unfolding cr_real_eq fun_rel_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   467
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   468
lemma inverse_Real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   469
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   470
  shows "inverse (Real X) =
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   471
    (if vanishes X then 0 else Real (\<lambda>n. inverse (X n)))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   472
  using assms inverse_real.transfer zero_real.transfer
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   473
  unfolding cr_real_eq fun_rel_def by (simp split: split_if_asm, metis)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   474
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   475
instance proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   476
  fix a b c :: real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   477
  show "a + b = b + a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   478
    by transfer (simp add: add_ac realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   479
  show "(a + b) + c = a + (b + c)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   480
    by transfer (simp add: add_ac realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   481
  show "0 + a = a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   482
    by transfer (simp add: realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   483
  show "- a + a = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   484
    by transfer (simp add: realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   485
  show "a - b = a + - b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   486
    by (rule minus_real_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   487
  show "(a * b) * c = a * (b * c)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   488
    by transfer (simp add: mult_ac realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   489
  show "a * b = b * a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   490
    by transfer (simp add: mult_ac realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   491
  show "1 * a = a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   492
    by transfer (simp add: mult_ac realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   493
  show "(a + b) * c = a * c + b * c"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   494
    by transfer (simp add: distrib_right realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   495
  show "(0\<Colon>real) \<noteq> (1\<Colon>real)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   496
    by transfer (simp add: realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   497
  show "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   498
    apply transfer
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   499
    apply (simp add: realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   500
    apply (rule vanishesI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   501
    apply (frule (1) cauchy_not_vanishes, clarify)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   502
    apply (rule_tac x=k in exI, clarify)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   503
    apply (drule_tac x=n in spec, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   504
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   505
  show "a / b = a * inverse b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   506
    by (rule divide_real_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   507
  show "inverse (0::real) = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   508
    by transfer (simp add: realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   509
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   510
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   511
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   512
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   513
subsection {* Positive reals *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   514
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   515
lift_definition positive :: "real \<Rightarrow> bool"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   516
  is "\<lambda>X. \<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   517
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   518
  { fix X Y
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   519
    assume "realrel X Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   520
    hence XY: "vanishes (\<lambda>n. X n - Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   521
      unfolding realrel_def by simp_all
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   522
    assume "\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   523
    then obtain r i where "0 < r" and i: "\<forall>n\<ge>i. r < X n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   524
      by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   525
    obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   526
      using `0 < r` by (rule obtain_pos_sum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   527
    obtain j where j: "\<forall>n\<ge>j. \<bar>X n - Y n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   528
      using vanishesD [OF XY s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   529
    have "\<forall>n\<ge>max i j. t < Y n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   530
    proof (clarsimp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   531
      fix n assume n: "i \<le> n" "j \<le> n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   532
      have "\<bar>X n - Y n\<bar> < s" and "r < X n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   533
        using i j n by simp_all
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   534
      thus "t < Y n" unfolding r by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   535
    qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   536
    hence "\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < Y n" using t by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   537
  } note 1 = this
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   538
  fix X Y assume "realrel X Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   539
  hence "realrel X Y" and "realrel Y X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   540
    using symp_realrel unfolding symp_def by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   541
  thus "?thesis X Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   542
    by (safe elim!: 1)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   543
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   544
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   545
lemma positive_Real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   546
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   547
  shows "positive (Real X) \<longleftrightarrow> (\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   548
  using assms positive.transfer
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   549
  unfolding cr_real_eq fun_rel_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   550
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   551
lemma positive_zero: "\<not> positive 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   552
  by transfer auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   553
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   554
lemma positive_add:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   555
  "positive x \<Longrightarrow> positive y \<Longrightarrow> positive (x + y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   556
apply transfer
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   557
apply (clarify, rename_tac a b i j)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   558
apply (rule_tac x="a + b" in exI, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   559
apply (rule_tac x="max i j" in exI, clarsimp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   560
apply (simp add: add_strict_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   561
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   562
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   563
lemma positive_mult:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   564
  "positive x \<Longrightarrow> positive y \<Longrightarrow> positive (x * y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   565
apply transfer
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   566
apply (clarify, rename_tac a b i j)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   567
apply (rule_tac x="a * b" in exI, simp add: mult_pos_pos)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   568
apply (rule_tac x="max i j" in exI, clarsimp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   569
apply (rule mult_strict_mono, auto)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   570
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   571
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   572
lemma positive_minus:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   573
  "\<not> positive x \<Longrightarrow> x \<noteq> 0 \<Longrightarrow> positive (- x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   574
apply transfer
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   575
apply (simp add: realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   576
apply (drule (1) cauchy_not_vanishes_cases, safe, fast, fast)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   577
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   578
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   579
instantiation real :: linordered_field_inverse_zero
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   580
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   581
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   582
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   583
  "x < y \<longleftrightarrow> positive (y - x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   584
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   585
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   586
  "x \<le> (y::real) \<longleftrightarrow> x < y \<or> x = y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   587
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   588
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   589
  "abs (a::real) = (if a < 0 then - a else a)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   590
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   591
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   592
  "sgn (a::real) = (if a = 0 then 0 else if 0 < a then 1 else - 1)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   593
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   594
instance proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   595
  fix a b c :: real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   596
  show "\<bar>a\<bar> = (if a < 0 then - a else a)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   597
    by (rule abs_real_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   598
  show "a < b \<longleftrightarrow> a \<le> b \<and> \<not> b \<le> a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   599
    unfolding less_eq_real_def less_real_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   600
    by (auto, drule (1) positive_add, simp_all add: positive_zero)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   601
  show "a \<le> a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   602
    unfolding less_eq_real_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   603
  show "a \<le> b \<Longrightarrow> b \<le> c \<Longrightarrow> a \<le> c"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   604
    unfolding less_eq_real_def less_real_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   605
    by (auto, drule (1) positive_add, simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   606
  show "a \<le> b \<Longrightarrow> b \<le> a \<Longrightarrow> a = b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   607
    unfolding less_eq_real_def less_real_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   608
    by (auto, drule (1) positive_add, simp add: positive_zero)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   609
  show "a \<le> b \<Longrightarrow> c + a \<le> c + b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   610
    unfolding less_eq_real_def less_real_def by (auto simp: diff_minus) (* by auto *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   611
    (* FIXME: Procedure int_combine_numerals: c + b - (c + a) \<equiv> b + - a *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   612
    (* Should produce c + b - (c + a) \<equiv> b - a *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   613
  show "sgn a = (if a = 0 then 0 else if 0 < a then 1 else - 1)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   614
    by (rule sgn_real_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   615
  show "a \<le> b \<or> b \<le> a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   616
    unfolding less_eq_real_def less_real_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   617
    by (auto dest!: positive_minus)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   618
  show "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   619
    unfolding less_real_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   620
    by (drule (1) positive_mult, simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   621
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   622
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   623
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   624
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   625
instantiation real :: distrib_lattice
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   626
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   627
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   628
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   629
  "(inf :: real \<Rightarrow> real \<Rightarrow> real) = min"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   630
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   631
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   632
  "(sup :: real \<Rightarrow> real \<Rightarrow> real) = max"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   633
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   634
instance proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   635
qed (auto simp add: inf_real_def sup_real_def min_max.sup_inf_distrib1)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   636
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   637
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   638
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   639
lemma of_nat_Real: "of_nat x = Real (\<lambda>n. of_nat x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   640
apply (induct x)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   641
apply (simp add: zero_real_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   642
apply (simp add: one_real_def add_Real)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   643
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   644
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   645
lemma of_int_Real: "of_int x = Real (\<lambda>n. of_int x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   646
apply (cases x rule: int_diff_cases)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   647
apply (simp add: of_nat_Real diff_Real)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   648
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   649
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   650
lemma of_rat_Real: "of_rat x = Real (\<lambda>n. x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   651
apply (induct x)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   652
apply (simp add: Fract_of_int_quotient of_rat_divide)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   653
apply (simp add: of_int_Real divide_inverse)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   654
apply (simp add: inverse_Real mult_Real)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   655
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   656
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   657
instance real :: archimedean_field
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   658
proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   659
  fix x :: real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   660
  show "\<exists>z. x \<le> of_int z"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   661
    apply (induct x)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   662
    apply (frule cauchy_imp_bounded, clarify)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   663
    apply (rule_tac x="ceiling b + 1" in exI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   664
    apply (rule less_imp_le)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   665
    apply (simp add: of_int_Real less_real_def diff_Real positive_Real)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   666
    apply (rule_tac x=1 in exI, simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   667
    apply (rule_tac x=0 in exI, clarsimp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   668
    apply (rule le_less_trans [OF abs_ge_self])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   669
    apply (rule less_le_trans [OF _ le_of_int_ceiling])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   670
    apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   671
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   672
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   673
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   674
instantiation real :: floor_ceiling
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   675
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   676
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   677
definition [code del]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   678
  "floor (x::real) = (THE z. of_int z \<le> x \<and> x < of_int (z + 1))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   679
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   680
instance proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   681
  fix x :: real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   682
  show "of_int (floor x) \<le> x \<and> x < of_int (floor x + 1)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   683
    unfolding floor_real_def using floor_exists1 by (rule theI')
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   684
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   685
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   686
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   687
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   688
subsection {* Completeness *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   689
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   690
lemma not_positive_Real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   691
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   692
  shows "\<not> positive (Real X) \<longleftrightarrow> (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. X n \<le> r)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   693
unfolding positive_Real [OF X]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   694
apply (auto, unfold not_less)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   695
apply (erule obtain_pos_sum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   696
apply (drule_tac x=s in spec, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   697
apply (drule_tac r=t in cauchyD [OF X], clarify)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   698
apply (drule_tac x=k in spec, clarsimp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   699
apply (rule_tac x=n in exI, clarify, rename_tac m)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   700
apply (drule_tac x=m in spec, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   701
apply (drule_tac x=n in spec, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   702
apply (drule spec, drule (1) mp, clarify, rename_tac i)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   703
apply (rule_tac x="max i k" in exI, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   704
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   705
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   706
lemma le_Real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   707
  assumes X: "cauchy X" and Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   708
  shows "Real X \<le> Real Y = (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. X n \<le> Y n + r)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   709
unfolding not_less [symmetric, where 'a=real] less_real_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   710
apply (simp add: diff_Real not_positive_Real X Y)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   711
apply (simp add: diff_le_eq add_ac)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   712
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   713
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   714
lemma le_RealI:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   715
  assumes Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   716
  shows "\<forall>n. x \<le> of_rat (Y n) \<Longrightarrow> x \<le> Real Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   717
proof (induct x)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   718
  fix X assume X: "cauchy X" and "\<forall>n. Real X \<le> of_rat (Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   719
  hence le: "\<And>m r. 0 < r \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. X n \<le> Y m + r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   720
    by (simp add: of_rat_Real le_Real)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   721
  {
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   722
    fix r :: rat assume "0 < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   723
    then obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   724
      by (rule obtain_pos_sum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   725
    obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>Y m - Y n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   726
      using cauchyD [OF Y s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   727
    obtain j where j: "\<forall>n\<ge>j. X n \<le> Y i + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   728
      using le [OF t] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   729
    have "\<forall>n\<ge>max i j. X n \<le> Y n + r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   730
    proof (clarsimp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   731
      fix n assume n: "i \<le> n" "j \<le> n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   732
      have "X n \<le> Y i + t" using n j by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   733
      moreover have "\<bar>Y i - Y n\<bar> < s" using n i by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   734
      ultimately show "X n \<le> Y n + r" unfolding r by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   735
    qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   736
    hence "\<exists>k. \<forall>n\<ge>k. X n \<le> Y n + r" ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   737
  }
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   738
  thus "Real X \<le> Real Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   739
    by (simp add: of_rat_Real le_Real X Y)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   740
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   741
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   742
lemma Real_leI:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   743
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   744
  assumes le: "\<forall>n. of_rat (X n) \<le> y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   745
  shows "Real X \<le> y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   746
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   747
  have "- y \<le> - Real X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   748
    by (simp add: minus_Real X le_RealI of_rat_minus le)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   749
  thus ?thesis by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   750
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   751
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   752
lemma less_RealD:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   753
  assumes Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   754
  shows "x < Real Y \<Longrightarrow> \<exists>n. x < of_rat (Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   755
by (erule contrapos_pp, simp add: not_less, erule Real_leI [OF Y])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   756
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   757
lemma of_nat_less_two_power:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   758
  "of_nat n < (2::'a::linordered_idom) ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   759
apply (induct n)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   760
apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   761
apply (subgoal_tac "(1::'a) \<le> 2 ^ n")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   762
apply (drule (1) add_le_less_mono, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   763
apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   764
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   765
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   766
lemma complete_real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   767
  fixes S :: "real set"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   768
  assumes "\<exists>x. x \<in> S" and "\<exists>z. \<forall>x\<in>S. x \<le> z"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   769
  shows "\<exists>y. (\<forall>x\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> y \<le> z)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   770
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   771
  obtain x where x: "x \<in> S" using assms(1) ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   772
  obtain z where z: "\<forall>x\<in>S. x \<le> z" using assms(2) ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   773
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   774
  def P \<equiv> "\<lambda>x. \<forall>y\<in>S. y \<le> of_rat x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   775
  obtain a where a: "\<not> P a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   776
  proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   777
    have "of_int (floor (x - 1)) \<le> x - 1" by (rule of_int_floor_le)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   778
    also have "x - 1 < x" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   779
    finally have "of_int (floor (x - 1)) < x" .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   780
    hence "\<not> x \<le> of_int (floor (x - 1))" by (simp only: not_le)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   781
    then show "\<not> P (of_int (floor (x - 1)))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   782
      unfolding P_def of_rat_of_int_eq using x by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   783
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   784
  obtain b where b: "P b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   785
  proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   786
    show "P (of_int (ceiling z))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   787
    unfolding P_def of_rat_of_int_eq
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   788
    proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   789
      fix y assume "y \<in> S"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   790
      hence "y \<le> z" using z by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   791
      also have "z \<le> of_int (ceiling z)" by (rule le_of_int_ceiling)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   792
      finally show "y \<le> of_int (ceiling z)" .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   793
    qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   794
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   795
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   796
  def avg \<equiv> "\<lambda>x y :: rat. x/2 + y/2"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   797
  def bisect \<equiv> "\<lambda>(x, y). if P (avg x y) then (x, avg x y) else (avg x y, y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   798
  def A \<equiv> "\<lambda>n. fst ((bisect ^^ n) (a, b))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   799
  def B \<equiv> "\<lambda>n. snd ((bisect ^^ n) (a, b))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   800
  def C \<equiv> "\<lambda>n. avg (A n) (B n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   801
  have A_0 [simp]: "A 0 = a" unfolding A_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   802
  have B_0 [simp]: "B 0 = b" unfolding B_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   803
  have A_Suc [simp]: "\<And>n. A (Suc n) = (if P (C n) then A n else C n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   804
    unfolding A_def B_def C_def bisect_def split_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   805
  have B_Suc [simp]: "\<And>n. B (Suc n) = (if P (C n) then C n else B n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   806
    unfolding A_def B_def C_def bisect_def split_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   807
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   808
  have width: "\<And>n. B n - A n = (b - a) / 2^n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   809
    apply (simp add: eq_divide_eq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   810
    apply (induct_tac n, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   811
    apply (simp add: C_def avg_def algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   812
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   813
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   814
  have twos: "\<And>y r :: rat. 0 < r \<Longrightarrow> \<exists>n. y / 2 ^ n < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   815
    apply (simp add: divide_less_eq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   816
    apply (subst mult_commute)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   817
    apply (frule_tac y=y in ex_less_of_nat_mult)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   818
    apply clarify
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   819
    apply (rule_tac x=n in exI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   820
    apply (erule less_trans)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   821
    apply (rule mult_strict_right_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   822
    apply (rule le_less_trans [OF _ of_nat_less_two_power])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   823
    apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   824
    apply assumption
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   825
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   826
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   827
  have PA: "\<And>n. \<not> P (A n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   828
    by (induct_tac n, simp_all add: a)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   829
  have PB: "\<And>n. P (B n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   830
    by (induct_tac n, simp_all add: b)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   831
  have ab: "a < b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   832
    using a b unfolding P_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   833
    apply (clarsimp simp add: not_le)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   834
    apply (drule (1) bspec)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   835
    apply (drule (1) less_le_trans)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   836
    apply (simp add: of_rat_less)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   837
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   838
  have AB: "\<And>n. A n < B n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   839
    by (induct_tac n, simp add: ab, simp add: C_def avg_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   840
  have A_mono: "\<And>i j. i \<le> j \<Longrightarrow> A i \<le> A j"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   841
    apply (auto simp add: le_less [where 'a=nat])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   842
    apply (erule less_Suc_induct)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   843
    apply (clarsimp simp add: C_def avg_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   844
    apply (simp add: add_divide_distrib [symmetric])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   845
    apply (rule AB [THEN less_imp_le])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   846
    apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   847
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   848
  have B_mono: "\<And>i j. i \<le> j \<Longrightarrow> B j \<le> B i"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   849
    apply (auto simp add: le_less [where 'a=nat])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   850
    apply (erule less_Suc_induct)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   851
    apply (clarsimp simp add: C_def avg_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   852
    apply (simp add: add_divide_distrib [symmetric])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   853
    apply (rule AB [THEN less_imp_le])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   854
    apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   855
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   856
  have cauchy_lemma:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   857
    "\<And>X. \<forall>n. \<forall>i\<ge>n. A n \<le> X i \<and> X i \<le> B n \<Longrightarrow> cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   858
    apply (rule cauchyI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   859
    apply (drule twos [where y="b - a"])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   860
    apply (erule exE)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   861
    apply (rule_tac x=n in exI, clarify, rename_tac i j)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   862
    apply (rule_tac y="B n - A n" in le_less_trans) defer
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   863
    apply (simp add: width)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   864
    apply (drule_tac x=n in spec)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   865
    apply (frule_tac x=i in spec, drule (1) mp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   866
    apply (frule_tac x=j in spec, drule (1) mp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   867
    apply (frule A_mono, drule B_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   868
    apply (frule A_mono, drule B_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   869
    apply arith
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   870
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   871
  have "cauchy A"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   872
    apply (rule cauchy_lemma [rule_format])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   873
    apply (simp add: A_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   874
    apply (erule order_trans [OF less_imp_le [OF AB] B_mono])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   875
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   876
  have "cauchy B"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   877
    apply (rule cauchy_lemma [rule_format])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   878
    apply (simp add: B_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   879
    apply (erule order_trans [OF A_mono less_imp_le [OF AB]])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   880
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   881
  have 1: "\<forall>x\<in>S. x \<le> Real B"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   882
  proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   883
    fix x assume "x \<in> S"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   884
    then show "x \<le> Real B"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   885
      using PB [unfolded P_def] `cauchy B`
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   886
      by (simp add: le_RealI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   887
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   888
  have 2: "\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> Real A \<le> z"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   889
    apply clarify
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   890
    apply (erule contrapos_pp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   891
    apply (simp add: not_le)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   892
    apply (drule less_RealD [OF `cauchy A`], clarify)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   893
    apply (subgoal_tac "\<not> P (A n)")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   894
    apply (simp add: P_def not_le, clarify)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   895
    apply (erule rev_bexI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   896
    apply (erule (1) less_trans)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   897
    apply (simp add: PA)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   898
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   899
  have "vanishes (\<lambda>n. (b - a) / 2 ^ n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   900
  proof (rule vanishesI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   901
    fix r :: rat assume "0 < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   902
    then obtain k where k: "\<bar>b - a\<bar> / 2 ^ k < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   903
      using twos by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   904
    have "\<forall>n\<ge>k. \<bar>(b - a) / 2 ^ n\<bar> < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   905
    proof (clarify)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   906
      fix n assume n: "k \<le> n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   907
      have "\<bar>(b - a) / 2 ^ n\<bar> = \<bar>b - a\<bar> / 2 ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   908
        by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   909
      also have "\<dots> \<le> \<bar>b - a\<bar> / 2 ^ k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   910
        using n by (simp add: divide_left_mono mult_pos_pos)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   911
      also note k
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   912
      finally show "\<bar>(b - a) / 2 ^ n\<bar> < r" .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   913
    qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   914
    thus "\<exists>k. \<forall>n\<ge>k. \<bar>(b - a) / 2 ^ n\<bar> < r" ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   915
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   916
  hence 3: "Real B = Real A"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   917
    by (simp add: eq_Real `cauchy A` `cauchy B` width)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   918
  show "\<exists>y. (\<forall>x\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> y \<le> z)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   919
    using 1 2 3 by (rule_tac x="Real B" in exI, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   920
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   921
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   922
51775
408d937c9486 revert #916271d52466; add non-topological linear_continuum type class; show linear_continuum_topology is a perfect_space
hoelzl
parents: 51773
diff changeset
   923
instantiation real :: linear_continuum
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   924
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   925
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   926
subsection{*Supremum of a set of reals*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   927
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   928
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   929
  Sup_real_def: "Sup X \<equiv> LEAST z::real. \<forall>x\<in>X. x\<le>z"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   930
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   931
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   932
  Inf_real_def: "Inf (X::real set) \<equiv> - Sup (uminus ` X)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   933
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   934
instance
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   935
proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   936
  { fix z x :: real and X :: "real set"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   937
    assume x: "x \<in> X" and z: "\<And>x. x \<in> X \<Longrightarrow> x \<le> z"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   938
    then obtain s where s: "\<forall>y\<in>X. y \<le> s" "\<And>z. \<forall>y\<in>X. y \<le> z \<Longrightarrow> s \<le> z"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   939
      using complete_real[of X] by blast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   940
    then show "x \<le> Sup X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   941
      unfolding Sup_real_def by (rule LeastI2_order) (auto simp: x) }
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   942
  note Sup_upper = this
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   943
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   944
  { fix z :: real and X :: "real set"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   945
    assume x: "X \<noteq> {}" and z: "\<And>x. x \<in> X \<Longrightarrow> x \<le> z"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   946
    then obtain s where s: "\<forall>y\<in>X. y \<le> s" "\<And>z. \<forall>y\<in>X. y \<le> z \<Longrightarrow> s \<le> z"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   947
      using complete_real[of X] by blast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   948
    then have "Sup X = s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   949
      unfolding Sup_real_def by (best intro: Least_equality)  
53374
a14d2a854c02 tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents: 53076
diff changeset
   950
    also from s z have "... \<le> z"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   951
      by blast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   952
    finally show "Sup X \<le> z" . }
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   953
  note Sup_least = this
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   954
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   955
  { fix x z :: real and X :: "real set"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   956
    assume x: "x \<in> X" and z: "\<And>x. x \<in> X \<Longrightarrow> z \<le> x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   957
    have "-x \<le> Sup (uminus ` X)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   958
      by (rule Sup_upper[of _ _ "- z"]) (auto simp add: image_iff x z)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   959
    then show "Inf X \<le> x" 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   960
      by (auto simp add: Inf_real_def) }
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   961
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   962
  { fix z :: real and X :: "real set"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   963
    assume x: "X \<noteq> {}" and z: "\<And>x. x \<in> X \<Longrightarrow> z \<le> x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   964
    have "Sup (uminus ` X) \<le> -z"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   965
      using x z by (force intro: Sup_least)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   966
    then show "z \<le> Inf X" 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   967
        by (auto simp add: Inf_real_def) }
51775
408d937c9486 revert #916271d52466; add non-topological linear_continuum type class; show linear_continuum_topology is a perfect_space
hoelzl
parents: 51773
diff changeset
   968
408d937c9486 revert #916271d52466; add non-topological linear_continuum type class; show linear_continuum_topology is a perfect_space
hoelzl
parents: 51773
diff changeset
   969
  show "\<exists>a b::real. a \<noteq> b"
408d937c9486 revert #916271d52466; add non-topological linear_continuum type class; show linear_continuum_topology is a perfect_space
hoelzl
parents: 51773
diff changeset
   970
    using zero_neq_one by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   971
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   972
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   973
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   974
text {*
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   975
  \medskip Completeness properties using @{text "isUb"}, @{text "isLub"}:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   976
*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   977
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   978
lemma reals_complete: "\<exists>X. X \<in> S \<Longrightarrow> \<exists>Y. isUb (UNIV::real set) S Y \<Longrightarrow> \<exists>t. isLub (UNIV :: real set) S t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   979
  by (intro exI[of _ "Sup S"] isLub_cSup) (auto simp: setle_def isUb_def intro: cSup_upper)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   980
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   981
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   982
subsection {* Hiding implementation details *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   983
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   984
hide_const (open) vanishes cauchy positive Real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   985
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   986
declare Real_induct [induct del]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   987
declare Abs_real_induct [induct del]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   988
declare Abs_real_cases [cases del]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   989
53652
18fbca265e2e use lifting_forget for deregistering numeric types as a quotient type
kuncar
parents: 53374
diff changeset
   990
lifting_update real.lifting
18fbca265e2e use lifting_forget for deregistering numeric types as a quotient type
kuncar
parents: 53374
diff changeset
   991
lifting_forget real.lifting
51956
a4d81cdebf8b better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
kuncar
parents: 51775
diff changeset
   992
  
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   993
subsection{*More Lemmas*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   994
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   995
text {* BH: These lemmas should not be necessary; they should be
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   996
covered by existing simp rules and simplification procedures. *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   997
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   998
lemma real_mult_left_cancel: "(c::real) \<noteq> 0 ==> (c*a=c*b) = (a=b)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   999
by simp (* redundant with mult_cancel_left *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1000
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1001
lemma real_mult_right_cancel: "(c::real) \<noteq> 0 ==> (a*c=b*c) = (a=b)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1002
by simp (* redundant with mult_cancel_right *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1003
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1004
lemma real_mult_less_iff1 [simp]: "(0::real) < z ==> (x*z < y*z) = (x < y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1005
by simp (* solved by linordered_ring_less_cancel_factor simproc *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1006
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1007
lemma real_mult_le_cancel_iff1 [simp]: "(0::real) < z ==> (x*z \<le> y*z) = (x\<le>y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1008
by simp (* solved by linordered_ring_le_cancel_factor simproc *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1009
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1010
lemma real_mult_le_cancel_iff2 [simp]: "(0::real) < z ==> (z*x \<le> z*y) = (x\<le>y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1011
by simp (* solved by linordered_ring_le_cancel_factor simproc *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1012
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1013
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1014
subsection {* Embedding numbers into the Reals *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1015
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1016
abbreviation
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1017
  real_of_nat :: "nat \<Rightarrow> real"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1018
where
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1019
  "real_of_nat \<equiv> of_nat"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1020
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1021
abbreviation
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1022
  real_of_int :: "int \<Rightarrow> real"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1023
where
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1024
  "real_of_int \<equiv> of_int"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1025
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1026
abbreviation
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1027
  real_of_rat :: "rat \<Rightarrow> real"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1028
where
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1029
  "real_of_rat \<equiv> of_rat"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1030
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1031
consts
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1032
  (*overloaded constant for injecting other types into "real"*)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1033
  real :: "'a => real"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1034
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1035
defs (overloaded)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1036
  real_of_nat_def [code_unfold]: "real == real_of_nat"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1037
  real_of_int_def [code_unfold]: "real == real_of_int"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1038
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1039
declare [[coercion_enabled]]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1040
declare [[coercion "real::nat\<Rightarrow>real"]]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1041
declare [[coercion "real::int\<Rightarrow>real"]]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1042
declare [[coercion "int"]]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1043
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1044
declare [[coercion_map map]]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1045
declare [[coercion_map "% f g h x. g (h (f x))"]]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1046
declare [[coercion_map "% f g (x,y) . (f x, g y)"]]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1047
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1048
lemma real_eq_of_nat: "real = of_nat"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1049
  unfolding real_of_nat_def ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1050
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1051
lemma real_eq_of_int: "real = of_int"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1052
  unfolding real_of_int_def ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1053
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1054
lemma real_of_int_zero [simp]: "real (0::int) = 0"  
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1055
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1056
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1057
lemma real_of_one [simp]: "real (1::int) = (1::real)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1058
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1059
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1060
lemma real_of_int_add [simp]: "real(x + y) = real (x::int) + real y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1061
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1062
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1063
lemma real_of_int_minus [simp]: "real(-x) = -real (x::int)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1064
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1065
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1066
lemma real_of_int_diff [simp]: "real(x - y) = real (x::int) - real y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1067
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1068
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1069
lemma real_of_int_mult [simp]: "real(x * y) = real (x::int) * real y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1070
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1071
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1072
lemma real_of_int_power [simp]: "real (x ^ n) = real (x::int) ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1073
by (simp add: real_of_int_def of_int_power)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1074
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1075
lemmas power_real_of_int = real_of_int_power [symmetric]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1076
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1077
lemma real_of_int_setsum [simp]: "real ((SUM x:A. f x)::int) = (SUM x:A. real(f x))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1078
  apply (subst real_eq_of_int)+
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1079
  apply (rule of_int_setsum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1080
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1081
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1082
lemma real_of_int_setprod [simp]: "real ((PROD x:A. f x)::int) = 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1083
    (PROD x:A. real(f x))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1084
  apply (subst real_eq_of_int)+
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1085
  apply (rule of_int_setprod)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1086
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1087
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1088
lemma real_of_int_zero_cancel [simp, algebra, presburger]: "(real x = 0) = (x = (0::int))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1089
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1090
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1091
lemma real_of_int_inject [iff, algebra, presburger]: "(real (x::int) = real y) = (x = y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1092
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1093
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1094
lemma real_of_int_less_iff [iff, presburger]: "(real (x::int) < real y) = (x < y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1095
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1096
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1097
lemma real_of_int_le_iff [simp, presburger]: "(real (x::int) \<le> real y) = (x \<le> y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1098
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1099
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1100
lemma real_of_int_gt_zero_cancel_iff [simp, presburger]: "(0 < real (n::int)) = (0 < n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1101
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1102
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1103
lemma real_of_int_ge_zero_cancel_iff [simp, presburger]: "(0 <= real (n::int)) = (0 <= n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1104
by (simp add: real_of_int_def) 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1105
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1106
lemma real_of_int_lt_zero_cancel_iff [simp, presburger]: "(real (n::int) < 0) = (n < 0)" 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1107
by (simp add: real_of_int_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1108
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1109
lemma real_of_int_le_zero_cancel_iff [simp, presburger]: "(real (n::int) <= 0) = (n <= 0)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1110
by (simp add: real_of_int_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1111
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1112
lemma one_less_real_of_int_cancel_iff: "1 < real (i :: int) \<longleftrightarrow> 1 < i"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1113
  unfolding real_of_one[symmetric] real_of_int_less_iff ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1114
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1115
lemma one_le_real_of_int_cancel_iff: "1 \<le> real (i :: int) \<longleftrightarrow> 1 \<le> i"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1116
  unfolding real_of_one[symmetric] real_of_int_le_iff ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1117
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1118
lemma real_of_int_less_one_cancel_iff: "real (i :: int) < 1 \<longleftrightarrow> i < 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1119
  unfolding real_of_one[symmetric] real_of_int_less_iff ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1120
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1121
lemma real_of_int_le_one_cancel_iff: "real (i :: int) \<le> 1 \<longleftrightarrow> i \<le> 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1122
  unfolding real_of_one[symmetric] real_of_int_le_iff ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1123
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1124
lemma real_of_int_abs [simp]: "real (abs x) = abs(real (x::int))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1125
by (auto simp add: abs_if)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1126
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1127
lemma int_less_real_le: "((n::int) < m) = (real n + 1 <= real m)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1128
  apply (subgoal_tac "real n + 1 = real (n + 1)")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1129
  apply (simp del: real_of_int_add)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1130
  apply auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1131
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1132
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1133
lemma int_le_real_less: "((n::int) <= m) = (real n < real m + 1)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1134
  apply (subgoal_tac "real m + 1 = real (m + 1)")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1135
  apply (simp del: real_of_int_add)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1136
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1137
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1138
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1139
lemma real_of_int_div_aux: "(real (x::int)) / (real d) = 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1140
    real (x div d) + (real (x mod d)) / (real d)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1141
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1142
  have "x = (x div d) * d + x mod d"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1143
    by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1144
  then have "real x = real (x div d) * real d + real(x mod d)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1145
    by (simp only: real_of_int_mult [THEN sym] real_of_int_add [THEN sym])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1146
  then have "real x / real d = ... / real d"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1147
    by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1148
  then show ?thesis
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1149
    by (auto simp add: add_divide_distrib algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1150
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1151
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1152
lemma real_of_int_div: "(d :: int) dvd n ==>
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1153
    real(n div d) = real n / real d"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1154
  apply (subst real_of_int_div_aux)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1155
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1156
  apply (simp add: dvd_eq_mod_eq_0)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1157
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1158
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1159
lemma real_of_int_div2:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1160
  "0 <= real (n::int) / real (x) - real (n div x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1161
  apply (case_tac "x = 0")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1162
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1163
  apply (case_tac "0 < x")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1164
  apply (simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1165
  apply (subst real_of_int_div_aux)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1166
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1167
  apply (subst zero_le_divide_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1168
  apply auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1169
  apply (simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1170
  apply (subst real_of_int_div_aux)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1171
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1172
  apply (subst zero_le_divide_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1173
  apply auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1174
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1175
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1176
lemma real_of_int_div3:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1177
  "real (n::int) / real (x) - real (n div x) <= 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1178
  apply (simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1179
  apply (subst real_of_int_div_aux)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1180
  apply (auto simp add: divide_le_eq intro: order_less_imp_le)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1181
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1182
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1183
lemma real_of_int_div4: "real (n div x) <= real (n::int) / real x" 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1184
by (insert real_of_int_div2 [of n x], simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1185
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1186
lemma Ints_real_of_int [simp]: "real (x::int) \<in> Ints"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1187
unfolding real_of_int_def by (rule Ints_of_int)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1188
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1189
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1190
subsection{*Embedding the Naturals into the Reals*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1191
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1192
lemma real_of_nat_zero [simp]: "real (0::nat) = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1193
by (simp add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1194
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1195
lemma real_of_nat_1 [simp]: "real (1::nat) = 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1196
by (simp add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1197
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1198
lemma real_of_nat_one [simp]: "real (Suc 0) = (1::real)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1199
by (simp add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1200
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1201
lemma real_of_nat_add [simp]: "real (m + n) = real (m::nat) + real n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1202
by (simp add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1203
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1204
(*Not for addsimps: often the LHS is used to represent a positive natural*)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1205
lemma real_of_nat_Suc: "real (Suc n) = real n + (1::real)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1206
by (simp add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1207
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1208
lemma real_of_nat_less_iff [iff]: 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1209
     "(real (n::nat) < real m) = (n < m)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1210
by (simp add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1211
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1212
lemma real_of_nat_le_iff [iff]: "(real (n::nat) \<le> real m) = (n \<le> m)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1213
by (simp add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1214
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1215
lemma real_of_nat_ge_zero [iff]: "0 \<le> real (n::nat)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1216
by (simp add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1217
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1218
lemma real_of_nat_Suc_gt_zero: "0 < real (Suc n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1219
by (simp add: real_of_nat_def del: of_nat_Suc)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1220
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1221
lemma real_of_nat_mult [simp]: "real (m * n) = real (m::nat) * real n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1222
by (simp add: real_of_nat_def of_nat_mult)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1223
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1224
lemma real_of_nat_power [simp]: "real (m ^ n) = real (m::nat) ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1225
by (simp add: real_of_nat_def of_nat_power)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1226
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1227
lemmas power_real_of_nat = real_of_nat_power [symmetric]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1228
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1229
lemma real_of_nat_setsum [simp]: "real ((SUM x:A. f x)::nat) = 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1230
    (SUM x:A. real(f x))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1231
  apply (subst real_eq_of_nat)+
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1232
  apply (rule of_nat_setsum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1233
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1234
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1235
lemma real_of_nat_setprod [simp]: "real ((PROD x:A. f x)::nat) = 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1236
    (PROD x:A. real(f x))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1237
  apply (subst real_eq_of_nat)+
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1238
  apply (rule of_nat_setprod)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1239
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1240
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1241
lemma real_of_card: "real (card A) = setsum (%x.1) A"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1242
  apply (subst card_eq_setsum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1243
  apply (subst real_of_nat_setsum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1244
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1245
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1246
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1247
lemma real_of_nat_inject [iff]: "(real (n::nat) = real m) = (n = m)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1248
by (simp add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1249
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1250
lemma real_of_nat_zero_iff [iff]: "(real (n::nat) = 0) = (n = 0)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1251
by (simp add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1252
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1253
lemma real_of_nat_diff: "n \<le> m ==> real (m - n) = real (m::nat) - real n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1254
by (simp add: add: real_of_nat_def of_nat_diff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1255
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1256
lemma real_of_nat_gt_zero_cancel_iff [simp]: "(0 < real (n::nat)) = (0 < n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1257
by (auto simp: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1258
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1259
lemma real_of_nat_le_zero_cancel_iff [simp]: "(real (n::nat) \<le> 0) = (n = 0)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1260
by (simp add: add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1261
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1262
lemma not_real_of_nat_less_zero [simp]: "~ real (n::nat) < 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1263
by (simp add: add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1264
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1265
lemma nat_less_real_le: "((n::nat) < m) = (real n + 1 <= real m)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1266
  apply (subgoal_tac "real n + 1 = real (Suc n)")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1267
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1268
  apply (auto simp add: real_of_nat_Suc)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1269
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1270
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1271
lemma nat_le_real_less: "((n::nat) <= m) = (real n < real m + 1)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1272
  apply (subgoal_tac "real m + 1 = real (Suc m)")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1273
  apply (simp add: less_Suc_eq_le)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1274
  apply (simp add: real_of_nat_Suc)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1275
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1276
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1277
lemma real_of_nat_div_aux: "(real (x::nat)) / (real d) = 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1278
    real (x div d) + (real (x mod d)) / (real d)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1279
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1280
  have "x = (x div d) * d + x mod d"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1281
    by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1282
  then have "real x = real (x div d) * real d + real(x mod d)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1283
    by (simp only: real_of_nat_mult [THEN sym] real_of_nat_add [THEN sym])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1284
  then have "real x / real d = \<dots> / real d"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1285
    by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1286
  then show ?thesis
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1287
    by (auto simp add: add_divide_distrib algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1288
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1289
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1290
lemma real_of_nat_div: "(d :: nat) dvd n ==>
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1291
    real(n div d) = real n / real d"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1292
  by (subst real_of_nat_div_aux)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1293
    (auto simp add: dvd_eq_mod_eq_0 [symmetric])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1294
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1295
lemma real_of_nat_div2:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1296
  "0 <= real (n::nat) / real (x) - real (n div x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1297
apply (simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1298
apply (subst real_of_nat_div_aux)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1299
apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1300
apply (subst zero_le_divide_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1301
apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1302
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1303
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1304
lemma real_of_nat_div3:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1305
  "real (n::nat) / real (x) - real (n div x) <= 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1306
apply(case_tac "x = 0")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1307
apply (simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1308
apply (simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1309
apply (subst real_of_nat_div_aux)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1310
apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1311
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1312
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1313
lemma real_of_nat_div4: "real (n div x) <= real (n::nat) / real x" 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1314
by (insert real_of_nat_div2 [of n x], simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1315
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1316
lemma real_of_int_of_nat_eq [simp]: "real (of_nat n :: int) = real n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1317
by (simp add: real_of_int_def real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1318
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1319
lemma real_nat_eq_real [simp]: "0 <= x ==> real(nat x) = real x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1320
  apply (subgoal_tac "real(int(nat x)) = real(nat x)")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1321
  apply force
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1322
  apply (simp only: real_of_int_of_nat_eq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1323
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1324
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1325
lemma Nats_real_of_nat [simp]: "real (n::nat) \<in> Nats"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1326
unfolding real_of_nat_def by (rule of_nat_in_Nats)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1327
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1328
lemma Ints_real_of_nat [simp]: "real (n::nat) \<in> Ints"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1329
unfolding real_of_nat_def by (rule Ints_of_nat)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1330
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1331
subsection {* The Archimedean Property of the Reals *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1332
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1333
theorem reals_Archimedean:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1334
  assumes x_pos: "0 < x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1335
  shows "\<exists>n. inverse (real (Suc n)) < x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1336
  unfolding real_of_nat_def using x_pos
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1337
  by (rule ex_inverse_of_nat_Suc_less)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1338
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1339
lemma reals_Archimedean2: "\<exists>n. (x::real) < real (n::nat)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1340
  unfolding real_of_nat_def by (rule ex_less_of_nat)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1341
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1342
lemma reals_Archimedean3:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1343
  assumes x_greater_zero: "0 < x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1344
  shows "\<forall>(y::real). \<exists>(n::nat). y < real n * x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1345
  unfolding real_of_nat_def using `0 < x`
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1346
  by (auto intro: ex_less_of_nat_mult)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1347
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1348
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1349
subsection{* Rationals *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1350
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1351
lemma Rats_real_nat[simp]: "real(n::nat) \<in> \<rat>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1352
by (simp add: real_eq_of_nat)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1353
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1354
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1355
lemma Rats_eq_int_div_int:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1356
  "\<rat> = { real(i::int)/real(j::int) |i j. j \<noteq> 0}" (is "_ = ?S")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1357
proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1358
  show "\<rat> \<subseteq> ?S"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1359
  proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1360
    fix x::real assume "x : \<rat>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1361
    then obtain r where "x = of_rat r" unfolding Rats_def ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1362
    have "of_rat r : ?S"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1363
      by (cases r)(auto simp add:of_rat_rat real_eq_of_int)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1364
    thus "x : ?S" using `x = of_rat r` by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1365
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1366
next
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1367
  show "?S \<subseteq> \<rat>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1368
  proof(auto simp:Rats_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1369
    fix i j :: int assume "j \<noteq> 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1370
    hence "real i / real j = of_rat(Fract i j)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1371
      by (simp add:of_rat_rat real_eq_of_int)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1372
    thus "real i / real j \<in> range of_rat" by blast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1373
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1374
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1375
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1376
lemma Rats_eq_int_div_nat:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1377
  "\<rat> = { real(i::int)/real(n::nat) |i n. n \<noteq> 0}"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1378
proof(auto simp:Rats_eq_int_div_int)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1379
  fix i j::int assume "j \<noteq> 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1380
  show "EX (i'::int) (n::nat). real i/real j = real i'/real n \<and> 0<n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1381
  proof cases
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1382
    assume "j>0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1383
    hence "real i/real j = real i/real(nat j) \<and> 0<nat j"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1384
      by (simp add: real_eq_of_int real_eq_of_nat of_nat_nat)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1385
    thus ?thesis by blast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1386
  next
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1387
    assume "~ j>0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1388
    hence "real i/real j = real(-i)/real(nat(-j)) \<and> 0<nat(-j)" using `j\<noteq>0`
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1389
      by (simp add: real_eq_of_int real_eq_of_nat of_nat_nat)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1390
    thus ?thesis by blast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1391
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1392
next
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1393
  fix i::int and n::nat assume "0 < n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1394
  hence "real i/real n = real i/real(int n) \<and> int n \<noteq> 0" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1395
  thus "\<exists>(i'::int) j::int. real i/real n = real i'/real j \<and> j \<noteq> 0" by blast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1396
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1397
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1398
lemma Rats_abs_nat_div_natE:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1399
  assumes "x \<in> \<rat>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1400
  obtains m n :: nat
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1401
  where "n \<noteq> 0" and "\<bar>x\<bar> = real m / real n" and "gcd m n = 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1402
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1403
  from `x \<in> \<rat>` obtain i::int and n::nat where "n \<noteq> 0" and "x = real i / real n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1404
    by(auto simp add: Rats_eq_int_div_nat)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1405
  hence "\<bar>x\<bar> = real(nat(abs i)) / real n" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1406
  then obtain m :: nat where x_rat: "\<bar>x\<bar> = real m / real n" by blast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1407
  let ?gcd = "gcd m n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1408
  from `n\<noteq>0` have gcd: "?gcd \<noteq> 0" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1409
  let ?k = "m div ?gcd"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1410
  let ?l = "n div ?gcd"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1411
  let ?gcd' = "gcd ?k ?l"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1412
  have "?gcd dvd m" .. then have gcd_k: "?gcd * ?k = m"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1413
    by (rule dvd_mult_div_cancel)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1414
  have "?gcd dvd n" .. then have gcd_l: "?gcd * ?l = n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1415
    by (rule dvd_mult_div_cancel)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1416
  from `n\<noteq>0` and gcd_l have "?l \<noteq> 0" by (auto iff del: neq0_conv)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1417
  moreover
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1418
  have "\<bar>x\<bar> = real ?k / real ?l"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1419
  proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1420
    from gcd have "real ?k / real ?l =
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1421
        real (?gcd * ?k) / real (?gcd * ?l)" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1422
    also from gcd_k and gcd_l have "\<dots> = real m / real n" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1423
    also from x_rat have "\<dots> = \<bar>x\<bar>" ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1424
    finally show ?thesis ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1425
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1426
  moreover
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1427
  have "?gcd' = 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1428
  proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1429
    have "?gcd * ?gcd' = gcd (?gcd * ?k) (?gcd * ?l)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1430
      by (rule gcd_mult_distrib_nat)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1431
    with gcd_k gcd_l have "?gcd * ?gcd' = ?gcd" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1432
    with gcd show ?thesis by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1433
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1434
  ultimately show ?thesis ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1435
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1436
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1437
subsection{*Density of the Rational Reals in the Reals*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1438
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1439
text{* This density proof is due to Stefan Richter and was ported by TN.  The
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1440
original source is \emph{Real Analysis} by H.L. Royden.
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1441
It employs the Archimedean property of the reals. *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1442
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1443
lemma Rats_dense_in_real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1444
  fixes x :: real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1445
  assumes "x < y" shows "\<exists>r\<in>\<rat>. x < r \<and> r < y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1446
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1447
  from `x<y` have "0 < y-x" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1448
  with reals_Archimedean obtain q::nat 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1449
    where q: "inverse (real q) < y-x" and "0 < q" by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1450
  def p \<equiv> "ceiling (y * real q) - 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1451
  def r \<equiv> "of_int p / real q"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1452
  from q have "x < y - inverse (real q)" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1453
  also have "y - inverse (real q) \<le> r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1454
    unfolding r_def p_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1455
    by (simp add: le_divide_eq left_diff_distrib le_of_int_ceiling `0 < q`)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1456
  finally have "x < r" .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1457
  moreover have "r < y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1458
    unfolding r_def p_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1459
    by (simp add: divide_less_eq diff_less_eq `0 < q`
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1460
      less_ceiling_iff [symmetric])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1461
  moreover from r_def have "r \<in> \<rat>" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1462
  ultimately show ?thesis by fast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1463
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1464
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1465
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1466
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1467
subsection{*Numerals and Arithmetic*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1468
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1469
lemma [code_abbrev]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1470
  "real_of_int (numeral k) = numeral k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1471
  "real_of_int (neg_numeral k) = neg_numeral k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1472
  by simp_all
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1473
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1474
text{*Collapse applications of @{term real} to @{term number_of}*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1475
lemma real_numeral [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1476
  "real (numeral v :: int) = numeral v"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1477
  "real (neg_numeral v :: int) = neg_numeral v"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1478
by (simp_all add: real_of_int_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1479
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1480
lemma real_of_nat_numeral [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1481
  "real (numeral v :: nat) = numeral v"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1482
by (simp add: real_of_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1483
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1484
declaration {*
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1485
  K (Lin_Arith.add_inj_thms [@{thm real_of_nat_le_iff} RS iffD2, @{thm real_of_nat_inject} RS iffD2]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1486
    (* not needed because x < (y::nat) can be rewritten as Suc x <= y: real_of_nat_less_iff RS iffD2 *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1487
  #> Lin_Arith.add_inj_thms [@{thm real_of_int_le_iff} RS iffD2, @{thm real_of_int_inject} RS iffD2]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1488
    (* not needed because x < (y::int) can be rewritten as x + 1 <= y: real_of_int_less_iff RS iffD2 *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1489
  #> Lin_Arith.add_simps [@{thm real_of_nat_zero}, @{thm real_of_nat_Suc}, @{thm real_of_nat_add},
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1490
      @{thm real_of_nat_mult}, @{thm real_of_int_zero}, @{thm real_of_one},
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1491
      @{thm real_of_int_add}, @{thm real_of_int_minus}, @{thm real_of_int_diff},
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1492
      @{thm real_of_int_mult}, @{thm real_of_int_of_nat_eq},
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1493
      @{thm real_of_nat_numeral}, @{thm real_numeral(1)}, @{thm real_numeral(2)}]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1494
  #> Lin_Arith.add_inj_const (@{const_name real}, @{typ "nat \<Rightarrow> real"})
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1495
  #> Lin_Arith.add_inj_const (@{const_name real}, @{typ "int \<Rightarrow> real"}))
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1496
*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1497
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1498
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1499
subsection{* Simprules combining x+y and 0: ARE THEY NEEDED?*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1500
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1501
lemma real_add_minus_iff [simp]: "(x + - a = (0::real)) = (x=a)" 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1502
by arith
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1503
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1504
text {* FIXME: redundant with @{text add_eq_0_iff} below *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1505
lemma real_add_eq_0_iff: "(x+y = (0::real)) = (y = -x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1506
by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1507
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1508
lemma real_add_less_0_iff: "(x+y < (0::real)) = (y < -x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1509
by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1510
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1511
lemma real_0_less_add_iff: "((0::real) < x+y) = (-x < y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1512
by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1513
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1514
lemma real_add_le_0_iff: "(x+y \<le> (0::real)) = (y \<le> -x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1515
by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1516
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1517
lemma real_0_le_add_iff: "((0::real) \<le> x+y) = (-x \<le> y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1518
by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1519
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1520
subsection {* Lemmas about powers *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1521
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1522
text {* FIXME: declare this in Rings.thy or not at all *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1523
declare abs_mult_self [simp]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1524
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1525
(* used by Import/HOL/real.imp *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1526
lemma two_realpow_ge_one: "(1::real) \<le> 2 ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1527
by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1528
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1529
lemma two_realpow_gt [simp]: "real (n::nat) < 2 ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1530
apply (induct "n")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1531
apply (auto simp add: real_of_nat_Suc)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1532
apply (subst mult_2)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1533
apply (erule add_less_le_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1534
apply (rule two_realpow_ge_one)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1535
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1536
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1537
text {* TODO: no longer real-specific; rename and move elsewhere *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1538
lemma realpow_Suc_le_self:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1539
  fixes r :: "'a::linordered_semidom"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1540
  shows "[| 0 \<le> r; r \<le> 1 |] ==> r ^ Suc n \<le> r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1541
by (insert power_decreasing [of 1 "Suc n" r], simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1542
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1543
text {* TODO: no longer real-specific; rename and move elsewhere *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1544
lemma realpow_minus_mult:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1545
  fixes x :: "'a::monoid_mult"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1546
  shows "0 < n \<Longrightarrow> x ^ (n - 1) * x = x ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1547
by (simp add: power_commutes split add: nat_diff_split)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1548
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1549
text {* FIXME: declare this [simp] for all types, or not at all *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1550
lemma real_two_squares_add_zero_iff [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1551
  "(x * x + y * y = 0) = ((x::real) = 0 \<and> y = 0)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1552
by (rule sum_squares_eq_zero_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1553
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1554
text {* FIXME: declare this [simp] for all types, or not at all *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1555
lemma realpow_two_sum_zero_iff [simp]:
53076
47c9aff07725 more symbols;
wenzelm
parents: 51956
diff changeset
  1556
     "(x\<^sup>2 + y\<^sup>2 = (0::real)) = (x = 0 & y = 0)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1557
by (rule sum_power2_eq_zero_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1558
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1559
lemma real_minus_mult_self_le [simp]: "-(u * u) \<le> (x * (x::real))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1560
by (rule_tac y = 0 in order_trans, auto)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1561
53076
47c9aff07725 more symbols;
wenzelm
parents: 51956
diff changeset
  1562
lemma realpow_square_minus_le [simp]: "- u\<^sup>2 \<le> (x::real)\<^sup>2"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1563
by (auto simp add: power2_eq_square)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1564
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1565
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1566
lemma numeral_power_le_real_of_nat_cancel_iff[simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1567
  "(numeral x::real) ^ n \<le> real a \<longleftrightarrow> (numeral x::nat) ^ n \<le> a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1568
  unfolding real_of_nat_le_iff[symmetric] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1569
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1570
lemma real_of_nat_le_numeral_power_cancel_iff[simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1571
  "real a \<le> (numeral x::real) ^ n \<longleftrightarrow> a \<le> (numeral x::nat) ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1572
  unfolding real_of_nat_le_iff[symmetric] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1573
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1574
lemma numeral_power_le_real_of_int_cancel_iff[simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1575
  "(numeral x::real) ^ n \<le> real a \<longleftrightarrow> (numeral x::int) ^ n \<le> a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1576
  unfolding real_of_int_le_iff[symmetric] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1577
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1578
lemma real_of_int_le_numeral_power_cancel_iff[simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1579
  "real a \<le> (numeral x::real) ^ n \<longleftrightarrow> a \<le> (numeral x::int) ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1580
  unfolding real_of_int_le_iff[symmetric] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1581
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1582
lemma neg_numeral_power_le_real_of_int_cancel_iff[simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1583
  "(neg_numeral x::real) ^ n \<le> real a \<longleftrightarrow> (neg_numeral x::int) ^ n \<le> a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1584
  unfolding real_of_int_le_iff[symmetric] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1585
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1586
lemma real_of_int_le_neg_numeral_power_cancel_iff[simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1587
  "real a \<le> (neg_numeral x::real) ^ n \<longleftrightarrow> a \<le> (neg_numeral x::int) ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1588
  unfolding real_of_int_le_iff[symmetric] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1589
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1590
subsection{*Density of the Reals*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1591
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1592
lemma real_lbound_gt_zero:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1593
     "[| (0::real) < d1; 0 < d2 |] ==> \<exists>e. 0 < e & e < d1 & e < d2"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1594
apply (rule_tac x = " (min d1 d2) /2" in exI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1595
apply (simp add: min_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1596
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1597
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1598
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1599
text{*Similar results are proved in @{text Fields}*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1600
lemma real_less_half_sum: "x < y ==> x < (x+y) / (2::real)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1601
  by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1602
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1603
lemma real_gt_half_sum: "x < y ==> (x+y)/(2::real) < y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1604
  by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1605
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1606
lemma real_sum_of_halves: "x/2 + x/2 = (x::real)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1607
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1608
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1609
subsection{*Absolute Value Function for the Reals*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1610
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1611
lemma abs_minus_add_cancel: "abs(x + (-y)) = abs (y + (-(x::real)))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1612
by (simp add: abs_if)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1613
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1614
(* FIXME: redundant, but used by Integration/RealRandVar.thy in AFP *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1615
lemma abs_le_interval_iff: "(abs x \<le> r) = (-r\<le>x & x\<le>(r::real))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1616
by (force simp add: abs_le_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1617
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1618
lemma abs_add_one_gt_zero: "(0::real) < 1 + abs(x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1619
by (simp add: abs_if)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1620
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1621
lemma abs_real_of_nat_cancel [simp]: "abs (real x) = real (x::nat)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1622
by (rule abs_of_nonneg [OF real_of_nat_ge_zero])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1623
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1624
lemma abs_add_one_not_less_self: "~ abs(x) + (1::real) < x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1625
by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1626
 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1627
lemma abs_sum_triangle_ineq: "abs ((x::real) + y + (-l + -m)) \<le> abs(x + -l) + abs(y + -m)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1628
by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1629
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1630
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1631
subsection{*Floor and Ceiling Functions from the Reals to the Integers*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1632
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1633
(* FIXME: theorems for negative numerals *)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1634
lemma numeral_less_real_of_int_iff [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1635
     "((numeral n) < real (m::int)) = (numeral n < m)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1636
apply auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1637
apply (rule real_of_int_less_iff [THEN iffD1])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1638
apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1639
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1640
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1641
lemma numeral_less_real_of_int_iff2 [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1642
     "(real (m::int) < (numeral n)) = (m < numeral n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1643
apply auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1644
apply (rule real_of_int_less_iff [THEN iffD1])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1645
apply (drule_tac [2] real_of_int_less_iff [THEN iffD2], auto)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1646
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1647
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1648
lemma numeral_le_real_of_int_iff [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1649
     "((numeral n) \<le> real (m::int)) = (numeral n \<le> m)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1650
by (simp add: linorder_not_less [symmetric])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1651
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1652
lemma numeral_le_real_of_int_iff2 [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1653
     "(real (m::int) \<le> (numeral n)) = (m \<le> numeral n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1654
by (simp add: linorder_not_less [symmetric])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1655
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1656
lemma floor_real_of_nat [simp]: "floor (real (n::nat)) = int n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1657
unfolding real_of_nat_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1658
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1659
lemma floor_minus_real_of_nat [simp]: "floor (- real (n::nat)) = - int n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1660
unfolding real_of_nat_def by (simp add: floor_minus)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1661
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1662
lemma floor_real_of_int [simp]: "floor (real (n::int)) = n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1663
unfolding real_of_int_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1664
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1665
lemma floor_minus_real_of_int [simp]: "floor (- real (n::int)) = - n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1666
unfolding real_of_int_def by (simp add: floor_minus)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1667
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1668
lemma real_lb_ub_int: " \<exists>n::int. real n \<le> r & r < real (n+1)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1669
unfolding real_of_int_def by (rule floor_exists)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1670
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1671
lemma lemma_floor:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1672
  assumes a1: "real m \<le> r" and a2: "r < real n + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1673
  shows "m \<le> (n::int)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1674
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1675
  have "real m < real n + 1" using a1 a2 by (rule order_le_less_trans)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1676
  also have "... = real (n + 1)" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1677
  finally have "m < n + 1" by (simp only: real_of_int_less_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1678
  thus ?thesis by arith
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1679
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1680
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1681
lemma real_of_int_floor_le [simp]: "real (floor r) \<le> r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1682
unfolding real_of_int_def by (rule of_int_floor_le)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1683
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1684
lemma lemma_floor2: "real n < real (x::int) + 1 ==> n \<le> x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1685
by (auto intro: lemma_floor)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1686
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1687
lemma real_of_int_floor_cancel [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1688
    "(real (floor x) = x) = (\<exists>n::int. x = real n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1689
  using floor_real_of_int by metis
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1690
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1691
lemma floor_eq: "[| real n < x; x < real n + 1 |] ==> floor x = n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1692
  unfolding real_of_int_def using floor_unique [of n x] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1693
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1694
lemma floor_eq2: "[| real n \<le> x; x < real n + 1 |] ==> floor x = n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1695
  unfolding real_of_int_def by (rule floor_unique)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1696
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1697
lemma floor_eq3: "[| real n < x; x < real (Suc n) |] ==> nat(floor x) = n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1698
apply (rule inj_int [THEN injD])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1699
apply (simp add: real_of_nat_Suc)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1700
apply (simp add: real_of_nat_Suc floor_eq floor_eq [where n = "int n"])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1701
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1702
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1703
lemma floor_eq4: "[| real n \<le> x; x < real (Suc n) |] ==> nat(floor x) = n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1704
apply (drule order_le_imp_less_or_eq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1705
apply (auto intro: floor_eq3)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1706
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1707
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1708
lemma real_of_int_floor_ge_diff_one [simp]: "r - 1 \<le> real(floor r)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1709
  unfolding real_of_int_def using floor_correct [of r] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1710
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1711
lemma real_of_int_floor_gt_diff_one [simp]: "r - 1 < real(floor r)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1712
  unfolding real_of_int_def using floor_correct [of r] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1713
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1714
lemma real_of_int_floor_add_one_ge [simp]: "r \<le> real(floor r) + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1715
  unfolding real_of_int_def using floor_correct [of r] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1716
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1717
lemma real_of_int_floor_add_one_gt [simp]: "r < real(floor r) + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1718
  unfolding real_of_int_def using floor_correct [of r] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1719
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1720
lemma le_floor: "real a <= x ==> a <= floor x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1721
  unfolding real_of_int_def by (simp add: le_floor_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1722
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1723
lemma real_le_floor: "a <= floor x ==> real a <= x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1724
  unfolding real_of_int_def by (simp add: le_floor_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1725
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1726
lemma le_floor_eq: "(a <= floor x) = (real a <= x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1727
  unfolding real_of_int_def by (rule le_floor_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1728
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1729
lemma floor_less_eq: "(floor x < a) = (x < real a)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1730
  unfolding real_of_int_def by (rule floor_less_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1731
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1732
lemma less_floor_eq: "(a < floor x) = (real a + 1 <= x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1733
  unfolding real_of_int_def by (rule less_floor_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1734
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1735
lemma floor_le_eq: "(floor x <= a) = (x < real a + 1)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1736
  unfolding real_of_int_def by (rule floor_le_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1737
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1738
lemma floor_add [simp]: "floor (x + real a) = floor x + a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1739
  unfolding real_of_int_def by (rule floor_add_of_int)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1740
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1741
lemma floor_subtract [simp]: "floor (x - real a) = floor x - a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1742
  unfolding real_of_int_def by (rule floor_diff_of_int)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1743
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1744
lemma le_mult_floor:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1745
  assumes "0 \<le> (a :: real)" and "0 \<le> b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1746
  shows "floor a * floor b \<le> floor (a * b)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1747
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1748
  have "real (floor a) \<le> a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1749
    and "real (floor b) \<le> b" by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1750
  hence "real (floor a * floor b) \<le> a * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1751
    using assms by (auto intro!: mult_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1752
  also have "a * b < real (floor (a * b) + 1)" by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1753
  finally show ?thesis unfolding real_of_int_less_iff by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1754
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1755
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1756
lemma floor_divide_eq_div:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1757
  "floor (real a / real b) = a div b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1758
proof cases
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1759
  assume "b \<noteq> 0 \<or> b dvd a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1760
  with real_of_int_div3[of a b] show ?thesis
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1761
    by (auto simp: real_of_int_div[symmetric] intro!: floor_eq2 real_of_int_div4 neq_le_trans)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1762
       (metis add_left_cancel zero_neq_one real_of_int_div_aux real_of_int_inject
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1763
              real_of_int_zero_cancel right_inverse_eq div_self mod_div_trivial)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1764
qed (auto simp: real_of_int_div)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1765
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1766
lemma ceiling_real_of_nat [simp]: "ceiling (real (n::nat)) = int n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1767
  unfolding real_of_nat_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1768
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1769
lemma real_of_int_ceiling_ge [simp]: "r \<le> real (ceiling r)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1770
  unfolding real_of_int_def by (rule le_of_int_ceiling)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1771
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1772
lemma ceiling_real_of_int [simp]: "ceiling (real (n::int)) = n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1773
  unfolding real_of_int_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1774
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1775
lemma real_of_int_ceiling_cancel [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1776
     "(real (ceiling x) = x) = (\<exists>n::int. x = real n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1777
  using ceiling_real_of_int by metis
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1778
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1779
lemma ceiling_eq: "[| real n < x; x < real n + 1 |] ==> ceiling x = n + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1780
  unfolding real_of_int_def using ceiling_unique [of "n + 1" x] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1781
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1782
lemma ceiling_eq2: "[| real n < x; x \<le> real n + 1 |] ==> ceiling x = n + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1783
  unfolding real_of_int_def using ceiling_unique [of "n + 1" x] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1784
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1785
lemma ceiling_eq3: "[| real n - 1 < x; x \<le> real n  |] ==> ceiling x = n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1786
  unfolding real_of_int_def using ceiling_unique [of n x] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1787
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1788
lemma real_of_int_ceiling_diff_one_le [simp]: "real (ceiling r) - 1 \<le> r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1789
  unfolding real_of_int_def using ceiling_correct [of r] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1790
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1791
lemma real_of_int_ceiling_le_add_one [simp]: "real (ceiling r) \<le> r + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1792
  unfolding real_of_int_def using ceiling_correct [of r] by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1793
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1794
lemma ceiling_le: "x <= real a ==> ceiling x <= a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1795
  unfolding real_of_int_def by (simp add: ceiling_le_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1796
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1797
lemma ceiling_le_real: "ceiling x <= a ==> x <= real a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1798
  unfolding real_of_int_def by (simp add: ceiling_le_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1799
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1800
lemma ceiling_le_eq: "(ceiling x <= a) = (x <= real a)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1801
  unfolding real_of_int_def by (rule ceiling_le_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1802
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1803
lemma less_ceiling_eq: "(a < ceiling x) = (real a < x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1804
  unfolding real_of_int_def by (rule less_ceiling_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1805
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1806
lemma ceiling_less_eq: "(ceiling x < a) = (x <= real a - 1)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1807
  unfolding real_of_int_def by (rule ceiling_less_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1808
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1809
lemma le_ceiling_eq: "(a <= ceiling x) = (real a - 1 < x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1810
  unfolding real_of_int_def by (rule le_ceiling_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1811
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1812
lemma ceiling_add [simp]: "ceiling (x + real a) = ceiling x + a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1813
  unfolding real_of_int_def by (rule ceiling_add_of_int)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1814
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1815
lemma ceiling_subtract [simp]: "ceiling (x - real a) = ceiling x - a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1816
  unfolding real_of_int_def by (rule ceiling_diff_of_int)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1817
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1818
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1819
subsubsection {* Versions for the natural numbers *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1820
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1821
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1822
  natfloor :: "real => nat" where
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1823
  "natfloor x = nat(floor x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1824
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1825
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1826
  natceiling :: "real => nat" where
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1827
  "natceiling x = nat(ceiling x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1828
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1829
lemma natfloor_zero [simp]: "natfloor 0 = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1830
  by (unfold natfloor_def, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1831
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1832
lemma natfloor_one [simp]: "natfloor 1 = 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1833
  by (unfold natfloor_def, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1834
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1835
lemma zero_le_natfloor [simp]: "0 <= natfloor x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1836
  by (unfold natfloor_def, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1837
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1838
lemma natfloor_numeral_eq [simp]: "natfloor (numeral n) = numeral n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1839
  by (unfold natfloor_def, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1840
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1841
lemma natfloor_real_of_nat [simp]: "natfloor(real n) = n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1842
  by (unfold natfloor_def, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1843
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1844
lemma real_natfloor_le: "0 <= x ==> real(natfloor x) <= x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1845
  by (unfold natfloor_def, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1846
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1847
lemma natfloor_neg: "x <= 0 ==> natfloor x = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1848
  unfolding natfloor_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1849
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1850
lemma natfloor_mono: "x <= y ==> natfloor x <= natfloor y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1851
  unfolding natfloor_def by (intro nat_mono floor_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1852
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1853
lemma le_natfloor: "real x <= a ==> x <= natfloor a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1854
  apply (unfold natfloor_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1855
  apply (subst nat_int [THEN sym])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1856
  apply (rule nat_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1857
  apply (rule le_floor)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1858
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1859
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1860
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1861
lemma natfloor_less_iff: "0 \<le> x \<Longrightarrow> natfloor x < n \<longleftrightarrow> x < real n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1862
  unfolding natfloor_def real_of_nat_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1863
  by (simp add: nat_less_iff floor_less_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1864
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1865
lemma less_natfloor:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1866
  assumes "0 \<le> x" and "x < real (n :: nat)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1867
  shows "natfloor x < n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1868
  using assms by (simp add: natfloor_less_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1869
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1870
lemma le_natfloor_eq: "0 <= x ==> (a <= natfloor x) = (real a <= x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1871
  apply (rule iffI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1872
  apply (rule order_trans)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1873
  prefer 2
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1874
  apply (erule real_natfloor_le)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1875
  apply (subst real_of_nat_le_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1876
  apply assumption
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1877
  apply (erule le_natfloor)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1878
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1879
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1880
lemma le_natfloor_eq_numeral [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1881
    "~ neg((numeral n)::int) ==> 0 <= x ==>
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1882
      (numeral n <= natfloor x) = (numeral n <= x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1883
  apply (subst le_natfloor_eq, assumption)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1884
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1885
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1886
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1887
lemma le_natfloor_eq_one [simp]: "(1 <= natfloor x) = (1 <= x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1888
  apply (case_tac "0 <= x")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1889
  apply (subst le_natfloor_eq, assumption, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1890
  apply (rule iffI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1891
  apply (subgoal_tac "natfloor x <= natfloor 0")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1892
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1893
  apply (rule natfloor_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1894
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1895
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1896
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1897
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1898
lemma natfloor_eq: "real n <= x ==> x < real n + 1 ==> natfloor x = n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1899
  unfolding natfloor_def by (simp add: floor_eq2 [where n="int n"])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1900
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1901
lemma real_natfloor_add_one_gt: "x < real(natfloor x) + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1902
  apply (case_tac "0 <= x")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1903
  apply (unfold natfloor_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1904
  apply simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1905
  apply simp_all
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1906
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1907
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1908
lemma real_natfloor_gt_diff_one: "x - 1 < real(natfloor x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1909
using real_natfloor_add_one_gt by (simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1910
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1911
lemma ge_natfloor_plus_one_imp_gt: "natfloor z + 1 <= n ==> z < real n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1912
  apply (subgoal_tac "z < real(natfloor z) + 1")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1913
  apply arith
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1914
  apply (rule real_natfloor_add_one_gt)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1915
done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1916
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1917
lemma natfloor_add [simp]: "0 <= x ==> natfloor (x + real a) = natfloor x + a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1918
  unfolding natfloor_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1919
  unfolding real_of_int_of_nat_eq [symmetric] floor_add
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1920
  by (simp add: nat_add_distrib)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1921
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1922
lemma natfloor_add_numeral [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1923
    "~neg ((numeral n)::int) ==> 0 <= x ==>
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1924
      natfloor (x + numeral n) = natfloor x + numeral n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1925
  by (simp add: natfloor_add [symmetric])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1926
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1927
lemma natfloor_add_one: "0 <= x ==> natfloor(x + 1) = natfloor x + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1928
  by (simp add: natfloor_add [symmetric] del: One_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1929
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1930
lemma natfloor_subtract [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1931
    "natfloor(x - real a) = natfloor x - a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1932
  unfolding natfloor_def real_of_int_of_nat_eq [symmetric] floor_subtract
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1933
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1934
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1935
lemma natfloor_div_nat:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1936
  assumes "1 <= x" and "y > 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1937
  shows "natfloor (x / real y) = natfloor x div y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1938
proof (rule natfloor_eq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1939
  have "(natfloor x) div y * y \<le> natfloor x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1940
    by (rule add_leD1 [where k="natfloor x mod y"], simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1941
  thus "real (natfloor x div y) \<le> x / real y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1942
    using assms by (simp add: le_divide_eq le_natfloor_eq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1943
  have "natfloor x < (natfloor x) div y * y + y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1944
    apply (subst mod_div_equality [symmetric])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1945
    apply (rule add_strict_left_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1946
    apply (rule mod_less_divisor)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1947
    apply fact
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1948
    done
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1949
  thus "x / real y < real (natfloor x div y) + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1950
    using assms
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1951
    by (simp add: divide_less_eq natfloor_less_iff distrib_right)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1952
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1953
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1954
lemma le_mult_natfloor:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1955
  shows "natfloor a * natfloor b \<le> natfloor (a * b)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1956
  by (cases "0 <= a & 0 <= b")
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1957
    (auto simp add: le_natfloor_eq mult_nonneg_nonneg mult_mono' real_natfloor_le natfloor_neg)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1958
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1959
lemma natceiling_zero [simp]: "natceiling 0 = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1960
  by (unfold natceiling_def, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1961
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1962
lemma natceiling_one [simp]: "natceiling 1 = 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1963
  by (unfold natceiling_def, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1964
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1965
lemma zero_le_natceiling [simp]: "0 <= natceiling x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1966
  by (unfold natceiling_def, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1967
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1968
lemma natceiling_numeral_eq [simp]: "natceiling (numeral n) = numeral n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1969
  by (unfold natceiling_def, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1970
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1971
lemma natceiling_real_of_nat [simp]: "natceiling(real n) = n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1972
  by (unfold natceiling_def, simp)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1973
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1974
lemma real_natceiling_ge: "x <= real(natceiling x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1975
  unfolding natceiling_def by (cases "x < 0", simp_all)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1976
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1977
lemma natceiling_neg: "x <= 0 ==> natceiling x = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1978
  unfolding natceiling_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1979
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1980
lemma natceiling_mono: "x <= y ==> natceiling x <= natceiling y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1981
  unfolding natceiling_def by (intro nat_mono ceiling_mono)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1982
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1983
lemma natceiling_le: "x <= real a ==> natceiling x <= a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1984
  unfolding natceiling_def real_of_nat_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1985
  by (simp add: nat_le_iff ceiling_le_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1986
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1987
lemma natceiling_le_eq: "(natceiling x <= a) = (x <= real a)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1988
  unfolding natceiling_def real_of_nat_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1989
  by (simp add: nat_le_iff ceiling_le_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1990
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1991
lemma natceiling_le_eq_numeral [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1992
    "~ neg((numeral n)::int) ==>
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1993
      (natceiling x <= numeral n) = (x <= numeral n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1994
  by (simp add: natceiling_le_eq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1995
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1996
lemma natceiling_le_eq_one: "(natceiling x <= 1) = (x <= 1)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1997
  unfolding natceiling_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1998
  by (simp add: nat_le_iff ceiling_le_iff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1999
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2000
lemma natceiling_eq: "real n < x ==> x <= real n + 1 ==> natceiling x = n + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2001
  unfolding natceiling_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2002
  by (simp add: ceiling_eq2 [where n="int n"])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2003
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2004
lemma natceiling_add [simp]: "0 <= x ==>
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2005
    natceiling (x + real a) = natceiling x + a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2006
  unfolding natceiling_def
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2007
  unfolding real_of_int_of_nat_eq [symmetric] ceiling_add
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2008
  by (simp add: nat_add_distrib)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2009
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2010
lemma natceiling_add_numeral [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2011
    "~ neg ((numeral n)::int) ==> 0 <= x ==>
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2012
      natceiling (x + numeral n) = natceiling x + numeral n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2013
  by (simp add: natceiling_add [symmetric])
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2014
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2015
lemma natceiling_add_one: "0 <= x ==> natceiling(x + 1) = natceiling x + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2016
  by (simp add: natceiling_add [symmetric] del: One_nat_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2017
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2018
lemma natceiling_subtract [simp]: "natceiling(x - real a) = natceiling x - a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2019
  unfolding natceiling_def real_of_int_of_nat_eq [symmetric] ceiling_subtract
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2020
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2021
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2022
subsection {* Exponentiation with floor *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2023
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2024
lemma floor_power:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2025
  assumes "x = real (floor x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2026
  shows "floor (x ^ n) = floor x ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2027
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2028
  have *: "x ^ n = real (floor x ^ n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2029
    using assms by (induct n arbitrary: x) simp_all
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2030
  show ?thesis unfolding real_of_int_inject[symmetric]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2031
    unfolding * floor_real_of_int ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2032
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2033
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2034
lemma natfloor_power:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2035
  assumes "x = real (natfloor x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2036
  shows "natfloor (x ^ n) = natfloor x ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2037
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2038
  from assms have "0 \<le> floor x" by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2039
  note assms[unfolded natfloor_def real_nat_eq_real[OF `0 \<le> floor x`]]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2040
  from floor_power[OF this]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2041
  show ?thesis unfolding natfloor_def nat_power_eq[OF `0 \<le> floor x`, symmetric]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2042
    by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2043
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2044
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2045
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2046
subsection {* Implementation of rational real numbers *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2047
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2048
text {* Formal constructor *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2049
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2050
definition Ratreal :: "rat \<Rightarrow> real" where
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2051
  [code_abbrev, simp]: "Ratreal = of_rat"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2052
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2053
code_datatype Ratreal
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2054
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2055
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2056
text {* Numerals *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2057
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2058
lemma [code_abbrev]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2059
  "(of_rat (of_int a) :: real) = of_int a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2060
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2061
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2062
lemma [code_abbrev]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2063
  "(of_rat 0 :: real) = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2064
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2065
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2066
lemma [code_abbrev]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2067
  "(of_rat 1 :: real) = 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2068
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2069
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2070
lemma [code_abbrev]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2071
  "(of_rat (numeral k) :: real) = numeral k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2072
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2073
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2074
lemma [code_abbrev]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2075
  "(of_rat (neg_numeral k) :: real) = neg_numeral k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2076
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2077
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2078
lemma [code_post]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2079
  "(of_rat (0 / r)  :: real) = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2080
  "(of_rat (r / 0)  :: real) = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2081
  "(of_rat (1 / 1)  :: real) = 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2082
  "(of_rat (numeral k / 1) :: real) = numeral k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2083
  "(of_rat (neg_numeral k / 1) :: real) = neg_numeral k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2084
  "(of_rat (1 / numeral k) :: real) = 1 / numeral k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2085
  "(of_rat (1 / neg_numeral k) :: real) = 1 / neg_numeral k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2086
  "(of_rat (numeral k / numeral l)  :: real) = numeral k / numeral l"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2087
  "(of_rat (numeral k / neg_numeral l)  :: real) = numeral k / neg_numeral l"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2088
  "(of_rat (neg_numeral k / numeral l)  :: real) = neg_numeral k / numeral l"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2089
  "(of_rat (neg_numeral k / neg_numeral l)  :: real) = neg_numeral k / neg_numeral l"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2090
  by (simp_all add: of_rat_divide)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2091
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2092
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2093
text {* Operations *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2094
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2095
lemma zero_real_code [code]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2096
  "0 = Ratreal 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2097
by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2098
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2099
lemma one_real_code [code]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2100
  "1 = Ratreal 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2101
by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2102
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2103
instantiation real :: equal
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2104
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2105
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2106
definition "HOL.equal (x\<Colon>real) y \<longleftrightarrow> x - y = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2107
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2108
instance proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2109
qed (simp add: equal_real_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2110
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2111
lemma real_equal_code [code]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2112
  "HOL.equal (Ratreal x) (Ratreal y) \<longleftrightarrow> HOL.equal x y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2113
  by (simp add: equal_real_def equal)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2114
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2115
lemma [code nbe]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2116
  "HOL.equal (x::real) x \<longleftrightarrow> True"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2117
  by (rule equal_refl)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2118
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2119
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2120
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2121
lemma real_less_eq_code [code]: "Ratreal x \<le> Ratreal y \<longleftrightarrow> x \<le> y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2122
  by (simp add: of_rat_less_eq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2123
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2124
lemma real_less_code [code]: "Ratreal x < Ratreal y \<longleftrightarrow> x < y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2125
  by (simp add: of_rat_less)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2126
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2127
lemma real_plus_code [code]: "Ratreal x + Ratreal y = Ratreal (x + y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2128
  by (simp add: of_rat_add)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2129
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2130
lemma real_times_code [code]: "Ratreal x * Ratreal y = Ratreal (x * y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2131
  by (simp add: of_rat_mult)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2132
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2133
lemma real_uminus_code [code]: "- Ratreal x = Ratreal (- x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2134
  by (simp add: of_rat_minus)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2135
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2136
lemma real_minus_code [code]: "Ratreal x - Ratreal y = Ratreal (x - y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2137
  by (simp add: of_rat_diff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2138
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2139
lemma real_inverse_code [code]: "inverse (Ratreal x) = Ratreal (inverse x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2140
  by (simp add: of_rat_inverse)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2141
 
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2142
lemma real_divide_code [code]: "Ratreal x / Ratreal y = Ratreal (x / y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2143
  by (simp add: of_rat_divide)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2144
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2145
lemma real_floor_code [code]: "floor (Ratreal x) = floor x"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2146
  by (metis Ratreal_def floor_le_iff floor_unique le_floor_iff of_int_floor_le of_rat_of_int_eq real_less_eq_code)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2147
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2148
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2149
text {* Quickcheck *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2150
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2151
definition (in term_syntax)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2152
  valterm_ratreal :: "rat \<times> (unit \<Rightarrow> Code_Evaluation.term) \<Rightarrow> real \<times> (unit \<Rightarrow> Code_Evaluation.term)" where
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2153
  [code_unfold]: "valterm_ratreal k = Code_Evaluation.valtermify Ratreal {\<cdot>} k"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2154
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2155
notation fcomp (infixl "\<circ>>" 60)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2156
notation scomp (infixl "\<circ>\<rightarrow>" 60)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2157
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2158
instantiation real :: random
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2159
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2160
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2161
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2162
  "Quickcheck_Random.random i = Quickcheck_Random.random i \<circ>\<rightarrow> (\<lambda>r. Pair (valterm_ratreal r))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2163
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2164
instance ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2165
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2166
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2167
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2168
no_notation fcomp (infixl "\<circ>>" 60)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2169
no_notation scomp (infixl "\<circ>\<rightarrow>" 60)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2170
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2171
instantiation real :: exhaustive
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2172
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2173
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2174
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2175
  "exhaustive_real f d = Quickcheck_Exhaustive.exhaustive (%r. f (Ratreal r)) d"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2176
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2177
instance ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2178
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2179
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2180
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2181
instantiation real :: full_exhaustive
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2182
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2183
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2184
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2185
  "full_exhaustive_real f d = Quickcheck_Exhaustive.full_exhaustive (%r. f (valterm_ratreal r)) d"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2186
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2187
instance ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2188
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2189
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2190
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2191
instantiation real :: narrowing
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2192
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2193
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2194
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2195
  "narrowing = Quickcheck_Narrowing.apply (Quickcheck_Narrowing.cons Ratreal) narrowing"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2196
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2197
instance ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2198
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2199
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2200
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2201
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2202
subsection {* Setup for Nitpick *}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2203
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2204
declaration {*
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2205
  Nitpick_HOL.register_frac_type @{type_name real}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2206
   [(@{const_name zero_real_inst.zero_real}, @{const_name Nitpick.zero_frac}),
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2207
    (@{const_name one_real_inst.one_real}, @{const_name Nitpick.one_frac}),
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2208
    (@{const_name plus_real_inst.plus_real}, @{const_name Nitpick.plus_frac}),
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2209
    (@{const_name times_real_inst.times_real}, @{const_name Nitpick.times_frac}),
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2210
    (@{const_name uminus_real_inst.uminus_real}, @{const_name Nitpick.uminus_frac}),
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2211
    (@{const_name inverse_real_inst.inverse_real}, @{const_name Nitpick.inverse_frac}),
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2212
    (@{const_name ord_real_inst.less_real}, @{const_name Nitpick.less_frac}),
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2213
    (@{const_name ord_real_inst.less_eq_real}, @{const_name Nitpick.less_eq_frac})]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2214
*}
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2215
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2216
lemmas [nitpick_unfold] = inverse_real_inst.inverse_real one_real_inst.one_real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2217
    ord_real_inst.less_real ord_real_inst.less_eq_real plus_real_inst.plus_real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2218
    times_real_inst.times_real uminus_real_inst.uminus_real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2219
    zero_real_inst.zero_real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2220
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2221
ML_file "Tools/SMT/smt_real.ML"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2222
setup SMT_Real.setup
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2223
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  2224
end