src/HOL/RealDef.thy
author huffman
Sun Mar 25 20:15:39 2012 +0200 (2012-03-25)
changeset 47108 2a1953f0d20d
parent 46670 e9aa6d151329
child 47428 45b58fec9024
permissions -rw-r--r--
merged fork with new numeral representation (see NEWS)
haftmann@28952
     1
(*  Title       : HOL/RealDef.thy
huffman@36795
     2
    Author      : Jacques D. Fleuriot, 1998
paulson@14387
     3
    Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
avigad@16819
     4
    Additional contributions by Jeremy Avigad
huffman@36795
     5
    Construction of Cauchy Reals by Brian Huffman, 2010
paulson@14269
     6
*)
paulson@14269
     7
huffman@36795
     8
header {* Development of the Reals using Cauchy Sequences *}
paulson@14387
     9
nipkow@15131
    10
theory RealDef
huffman@36795
    11
imports Rat
nipkow@15131
    12
begin
paulson@5588
    13
huffman@36795
    14
text {*
huffman@36795
    15
  This theory contains a formalization of the real numbers as
huffman@36795
    16
  equivalence classes of Cauchy sequences of rationals.  See
huffman@40810
    17
  @{file "~~/src/HOL/ex/Dedekind_Real.thy"} for an alternative
huffman@40810
    18
  construction using Dedekind cuts.
huffman@36795
    19
*}
huffman@36795
    20
huffman@36795
    21
subsection {* Preliminary lemmas *}
huffman@36795
    22
huffman@36795
    23
lemma add_diff_add:
huffman@36795
    24
  fixes a b c d :: "'a::ab_group_add"
huffman@36795
    25
  shows "(a + c) - (b + d) = (a - b) + (c - d)"
huffman@36795
    26
  by simp
huffman@36795
    27
huffman@36795
    28
lemma minus_diff_minus:
huffman@36795
    29
  fixes a b :: "'a::ab_group_add"
huffman@36795
    30
  shows "- a - - b = - (a - b)"
huffman@36795
    31
  by simp
huffman@36795
    32
huffman@36795
    33
lemma mult_diff_mult:
huffman@36795
    34
  fixes x y a b :: "'a::ring"
huffman@36795
    35
  shows "(x * y - a * b) = x * (y - b) + (x - a) * b"
huffman@36795
    36
  by (simp add: algebra_simps)
huffman@36795
    37
huffman@36795
    38
lemma inverse_diff_inverse:
huffman@36795
    39
  fixes a b :: "'a::division_ring"
huffman@36795
    40
  assumes "a \<noteq> 0" and "b \<noteq> 0"
huffman@36795
    41
  shows "inverse a - inverse b = - (inverse a * (a - b) * inverse b)"
huffman@36795
    42
  using assms by (simp add: algebra_simps)
huffman@36795
    43
huffman@36795
    44
lemma obtain_pos_sum:
huffman@36795
    45
  fixes r :: rat assumes r: "0 < r"
huffman@36795
    46
  obtains s t where "0 < s" and "0 < t" and "r = s + t"
huffman@36795
    47
proof
huffman@36795
    48
    from r show "0 < r/2" by simp
huffman@36795
    49
    from r show "0 < r/2" by simp
huffman@36795
    50
    show "r = r/2 + r/2" by simp
huffman@36795
    51
qed
huffman@36795
    52
huffman@36795
    53
subsection {* Sequences that converge to zero *}
huffman@36795
    54
wenzelm@19765
    55
definition
huffman@36795
    56
  vanishes :: "(nat \<Rightarrow> rat) \<Rightarrow> bool"
huffman@36795
    57
where
huffman@36795
    58
  "vanishes X = (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r)"
huffman@36795
    59
huffman@36795
    60
lemma vanishesI: "(\<And>r. 0 < r \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r) \<Longrightarrow> vanishes X"
huffman@36795
    61
  unfolding vanishes_def by simp
huffman@36795
    62
huffman@36795
    63
lemma vanishesD: "\<lbrakk>vanishes X; 0 < r\<rbrakk> \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r"
huffman@36795
    64
  unfolding vanishes_def by simp
huffman@36795
    65
huffman@36795
    66
lemma vanishes_const [simp]: "vanishes (\<lambda>n. c) \<longleftrightarrow> c = 0"
huffman@36795
    67
  unfolding vanishes_def
huffman@36795
    68
  apply (cases "c = 0", auto)
huffman@36795
    69
  apply (rule exI [where x="\<bar>c\<bar>"], auto)
huffman@36795
    70
  done
huffman@36795
    71
huffman@36795
    72
lemma vanishes_minus: "vanishes X \<Longrightarrow> vanishes (\<lambda>n. - X n)"
huffman@36795
    73
  unfolding vanishes_def by simp
paulson@14269
    74
huffman@36795
    75
lemma vanishes_add:
huffman@36795
    76
  assumes X: "vanishes X" and Y: "vanishes Y"
huffman@36795
    77
  shows "vanishes (\<lambda>n. X n + Y n)"
huffman@36795
    78
proof (rule vanishesI)
huffman@36795
    79
  fix r :: rat assume "0 < r"
huffman@36795
    80
  then obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
huffman@36795
    81
    by (rule obtain_pos_sum)
huffman@36795
    82
  obtain i where i: "\<forall>n\<ge>i. \<bar>X n\<bar> < s"
huffman@36795
    83
    using vanishesD [OF X s] ..
huffman@36795
    84
  obtain j where j: "\<forall>n\<ge>j. \<bar>Y n\<bar> < t"
huffman@36795
    85
    using vanishesD [OF Y t] ..
huffman@36795
    86
  have "\<forall>n\<ge>max i j. \<bar>X n + Y n\<bar> < r"
huffman@36795
    87
  proof (clarsimp)
huffman@36795
    88
    fix n assume n: "i \<le> n" "j \<le> n"
huffman@36795
    89
    have "\<bar>X n + Y n\<bar> \<le> \<bar>X n\<bar> + \<bar>Y n\<bar>" by (rule abs_triangle_ineq)
huffman@36795
    90
    also have "\<dots> < s + t" by (simp add: add_strict_mono i j n)
huffman@36795
    91
    finally show "\<bar>X n + Y n\<bar> < r" unfolding r .
huffman@36795
    92
  qed
huffman@36795
    93
  thus "\<exists>k. \<forall>n\<ge>k. \<bar>X n + Y n\<bar> < r" ..
huffman@36795
    94
qed
huffman@36795
    95
huffman@36795
    96
lemma vanishes_diff:
huffman@36795
    97
  assumes X: "vanishes X" and Y: "vanishes Y"
huffman@36795
    98
  shows "vanishes (\<lambda>n. X n - Y n)"
huffman@36795
    99
unfolding diff_minus by (intro vanishes_add vanishes_minus X Y)
huffman@36795
   100
huffman@36795
   101
lemma vanishes_mult_bounded:
huffman@36795
   102
  assumes X: "\<exists>a>0. \<forall>n. \<bar>X n\<bar> < a"
huffman@36795
   103
  assumes Y: "vanishes (\<lambda>n. Y n)"
huffman@36795
   104
  shows "vanishes (\<lambda>n. X n * Y n)"
huffman@36795
   105
proof (rule vanishesI)
huffman@36795
   106
  fix r :: rat assume r: "0 < r"
huffman@36795
   107
  obtain a where a: "0 < a" "\<forall>n. \<bar>X n\<bar> < a"
huffman@36795
   108
    using X by fast
huffman@36795
   109
  obtain b where b: "0 < b" "r = a * b"
huffman@36795
   110
  proof
huffman@36795
   111
    show "0 < r / a" using r a by (simp add: divide_pos_pos)
huffman@36795
   112
    show "r = a * (r / a)" using a by simp
huffman@36795
   113
  qed
huffman@36795
   114
  obtain k where k: "\<forall>n\<ge>k. \<bar>Y n\<bar> < b"
huffman@36795
   115
    using vanishesD [OF Y b(1)] ..
huffman@36795
   116
  have "\<forall>n\<ge>k. \<bar>X n * Y n\<bar> < r"
huffman@36795
   117
    by (simp add: b(2) abs_mult mult_strict_mono' a k)
huffman@36795
   118
  thus "\<exists>k. \<forall>n\<ge>k. \<bar>X n * Y n\<bar> < r" ..
huffman@36795
   119
qed
huffman@36795
   120
huffman@36795
   121
subsection {* Cauchy sequences *}
paulson@5588
   122
wenzelm@19765
   123
definition
haftmann@44278
   124
  cauchy :: "(nat \<Rightarrow> rat) \<Rightarrow> bool"
huffman@36795
   125
where
huffman@36795
   126
  "cauchy X \<longleftrightarrow> (\<forall>r>0. \<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r)"
huffman@36795
   127
huffman@36795
   128
lemma cauchyI:
huffman@36795
   129
  "(\<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"
huffman@36795
   130
  unfolding cauchy_def by simp
huffman@36795
   131
huffman@36795
   132
lemma cauchyD:
huffman@36795
   133
  "\<lbrakk>cauchy X; 0 < r\<rbrakk> \<Longrightarrow> \<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r"
huffman@36795
   134
  unfolding cauchy_def by simp
huffman@36795
   135
huffman@36795
   136
lemma cauchy_const [simp]: "cauchy (\<lambda>n. x)"
huffman@36795
   137
  unfolding cauchy_def by simp
huffman@36795
   138
huffman@36795
   139
lemma cauchy_add [simp]:
huffman@36795
   140
  assumes X: "cauchy X" and Y: "cauchy Y"
huffman@36795
   141
  shows "cauchy (\<lambda>n. X n + Y n)"
huffman@36795
   142
proof (rule cauchyI)
huffman@36795
   143
  fix r :: rat assume "0 < r"
huffman@36795
   144
  then obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
huffman@36795
   145
    by (rule obtain_pos_sum)
huffman@36795
   146
  obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s"
huffman@36795
   147
    using cauchyD [OF X s] ..
huffman@36795
   148
  obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>Y m - Y n\<bar> < t"
huffman@36795
   149
    using cauchyD [OF Y t] ..
huffman@36795
   150
  have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>(X m + Y m) - (X n + Y n)\<bar> < r"
huffman@36795
   151
  proof (clarsimp)
huffman@36795
   152
    fix m n assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n"
huffman@36795
   153
    have "\<bar>(X m + Y m) - (X n + Y n)\<bar> \<le> \<bar>X m - X n\<bar> + \<bar>Y m - Y n\<bar>"
huffman@36795
   154
      unfolding add_diff_add by (rule abs_triangle_ineq)
huffman@36795
   155
    also have "\<dots> < s + t"
huffman@36795
   156
      by (rule add_strict_mono, simp_all add: i j *)
huffman@36795
   157
    finally show "\<bar>(X m + Y m) - (X n + Y n)\<bar> < r" unfolding r .
huffman@36795
   158
  qed
huffman@36795
   159
  thus "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>(X m + Y m) - (X n + Y n)\<bar> < r" ..
huffman@36795
   160
qed
huffman@36795
   161
huffman@36795
   162
lemma cauchy_minus [simp]:
huffman@36795
   163
  assumes X: "cauchy X"
huffman@36795
   164
  shows "cauchy (\<lambda>n. - X n)"
huffman@36795
   165
using assms unfolding cauchy_def
huffman@36795
   166
unfolding minus_diff_minus abs_minus_cancel .
huffman@36795
   167
huffman@36795
   168
lemma cauchy_diff [simp]:
huffman@36795
   169
  assumes X: "cauchy X" and Y: "cauchy Y"
huffman@36795
   170
  shows "cauchy (\<lambda>n. X n - Y n)"
huffman@36795
   171
using assms unfolding diff_minus by simp
huffman@36795
   172
huffman@36795
   173
lemma cauchy_imp_bounded:
huffman@36795
   174
  assumes "cauchy X" shows "\<exists>b>0. \<forall>n. \<bar>X n\<bar> < b"
huffman@36795
   175
proof -
huffman@36795
   176
  obtain k where k: "\<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < 1"
huffman@36795
   177
    using cauchyD [OF assms zero_less_one] ..
huffman@36795
   178
  show "\<exists>b>0. \<forall>n. \<bar>X n\<bar> < b"
huffman@36795
   179
  proof (intro exI conjI allI)
huffman@36795
   180
    have "0 \<le> \<bar>X 0\<bar>" by simp
huffman@36795
   181
    also have "\<bar>X 0\<bar> \<le> Max (abs ` X ` {..k})" by simp
huffman@36795
   182
    finally have "0 \<le> Max (abs ` X ` {..k})" .
huffman@36795
   183
    thus "0 < Max (abs ` X ` {..k}) + 1" by simp
huffman@36795
   184
  next
huffman@36795
   185
    fix n :: nat
huffman@36795
   186
    show "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1"
huffman@36795
   187
    proof (rule linorder_le_cases)
huffman@36795
   188
      assume "n \<le> k"
huffman@36795
   189
      hence "\<bar>X n\<bar> \<le> Max (abs ` X ` {..k})" by simp
huffman@36795
   190
      thus "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1" by simp
huffman@36795
   191
    next
huffman@36795
   192
      assume "k \<le> n"
huffman@36795
   193
      have "\<bar>X n\<bar> = \<bar>X k + (X n - X k)\<bar>" by simp
huffman@36795
   194
      also have "\<bar>X k + (X n - X k)\<bar> \<le> \<bar>X k\<bar> + \<bar>X n - X k\<bar>"
huffman@36795
   195
        by (rule abs_triangle_ineq)
huffman@36795
   196
      also have "\<dots> < Max (abs ` X ` {..k}) + 1"
huffman@36795
   197
        by (rule add_le_less_mono, simp, simp add: k `k \<le> n`)
huffman@36795
   198
      finally show "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1" .
huffman@36795
   199
    qed
huffman@36795
   200
  qed
huffman@36795
   201
qed
huffman@36795
   202
huffman@36795
   203
lemma cauchy_mult [simp]:
huffman@36795
   204
  assumes X: "cauchy X" and Y: "cauchy Y"
huffman@36795
   205
  shows "cauchy (\<lambda>n. X n * Y n)"
huffman@36795
   206
proof (rule cauchyI)
huffman@36795
   207
  fix r :: rat assume "0 < r"
huffman@36795
   208
  then obtain u v where u: "0 < u" and v: "0 < v" and "r = u + v"
huffman@36795
   209
    by (rule obtain_pos_sum)
huffman@36795
   210
  obtain a where a: "0 < a" "\<forall>n. \<bar>X n\<bar> < a"
huffman@36795
   211
    using cauchy_imp_bounded [OF X] by fast
huffman@36795
   212
  obtain b where b: "0 < b" "\<forall>n. \<bar>Y n\<bar> < b"
huffman@36795
   213
    using cauchy_imp_bounded [OF Y] by fast
huffman@36795
   214
  obtain s t where s: "0 < s" and t: "0 < t" and r: "r = a * t + s * b"
huffman@36795
   215
  proof
huffman@36795
   216
    show "0 < v/b" using v b(1) by (rule divide_pos_pos)
huffman@36795
   217
    show "0 < u/a" using u a(1) by (rule divide_pos_pos)
huffman@36795
   218
    show "r = a * (u/a) + (v/b) * b"
huffman@36795
   219
      using a(1) b(1) `r = u + v` by simp
huffman@36795
   220
  qed
huffman@36795
   221
  obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s"
huffman@36795
   222
    using cauchyD [OF X s] ..
huffman@36795
   223
  obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>Y m - Y n\<bar> < t"
huffman@36795
   224
    using cauchyD [OF Y t] ..
huffman@36795
   225
  have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>X m * Y m - X n * Y n\<bar> < r"
huffman@36795
   226
  proof (clarsimp)
huffman@36795
   227
    fix m n assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n"
huffman@36795
   228
    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>"
huffman@36795
   229
      unfolding mult_diff_mult ..
huffman@36795
   230
    also have "\<dots> \<le> \<bar>X m * (Y m - Y n)\<bar> + \<bar>(X m - X n) * Y n\<bar>"
huffman@36795
   231
      by (rule abs_triangle_ineq)
huffman@36795
   232
    also have "\<dots> = \<bar>X m\<bar> * \<bar>Y m - Y n\<bar> + \<bar>X m - X n\<bar> * \<bar>Y n\<bar>"
huffman@36795
   233
      unfolding abs_mult ..
huffman@36795
   234
    also have "\<dots> < a * t + s * b"
huffman@36795
   235
      by (simp_all add: add_strict_mono mult_strict_mono' a b i j *)
huffman@36795
   236
    finally show "\<bar>X m * Y m - X n * Y n\<bar> < r" unfolding r .
huffman@36795
   237
  qed
huffman@36795
   238
  thus "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m * Y m - X n * Y n\<bar> < r" ..
huffman@36795
   239
qed
huffman@36795
   240
huffman@36795
   241
lemma cauchy_not_vanishes_cases:
huffman@36795
   242
  assumes X: "cauchy X"
huffman@36795
   243
  assumes nz: "\<not> vanishes X"
huffman@36795
   244
  shows "\<exists>b>0. \<exists>k. (\<forall>n\<ge>k. b < - X n) \<or> (\<forall>n\<ge>k. b < X n)"
huffman@36795
   245
proof -
huffman@36795
   246
  obtain r where "0 < r" and r: "\<forall>k. \<exists>n\<ge>k. r \<le> \<bar>X n\<bar>"
huffman@36795
   247
    using nz unfolding vanishes_def by (auto simp add: not_less)
huffman@36795
   248
  obtain s t where s: "0 < s" and t: "0 < t" and "r = s + t"
huffman@36795
   249
    using `0 < r` by (rule obtain_pos_sum)
huffman@36795
   250
  obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s"
huffman@36795
   251
    using cauchyD [OF X s] ..
huffman@36795
   252
  obtain k where "i \<le> k" and "r \<le> \<bar>X k\<bar>"
huffman@36795
   253
    using r by fast
huffman@36795
   254
  have k: "\<forall>n\<ge>k. \<bar>X n - X k\<bar> < s"
huffman@36795
   255
    using i `i \<le> k` by auto
huffman@36795
   256
  have "X k \<le> - r \<or> r \<le> X k"
huffman@36795
   257
    using `r \<le> \<bar>X k\<bar>` by auto
huffman@36795
   258
  hence "(\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)"
huffman@36795
   259
    unfolding `r = s + t` using k by auto
huffman@36795
   260
  hence "\<exists>k. (\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)" ..
huffman@36795
   261
  thus "\<exists>t>0. \<exists>k. (\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)"
huffman@36795
   262
    using t by auto
huffman@36795
   263
qed
huffman@36795
   264
huffman@36795
   265
lemma cauchy_not_vanishes:
huffman@36795
   266
  assumes X: "cauchy X"
huffman@36795
   267
  assumes nz: "\<not> vanishes X"
huffman@36795
   268
  shows "\<exists>b>0. \<exists>k. \<forall>n\<ge>k. b < \<bar>X n\<bar>"
huffman@36795
   269
using cauchy_not_vanishes_cases [OF assms]
huffman@36795
   270
by clarify (rule exI, erule conjI, rule_tac x=k in exI, auto)
huffman@36795
   271
huffman@36795
   272
lemma cauchy_inverse [simp]:
huffman@36795
   273
  assumes X: "cauchy X"
huffman@36795
   274
  assumes nz: "\<not> vanishes X"
huffman@36795
   275
  shows "cauchy (\<lambda>n. inverse (X n))"
huffman@36795
   276
proof (rule cauchyI)
huffman@36795
   277
  fix r :: rat assume "0 < r"
huffman@36795
   278
  obtain b i where b: "0 < b" and i: "\<forall>n\<ge>i. b < \<bar>X n\<bar>"
huffman@36795
   279
    using cauchy_not_vanishes [OF X nz] by fast
huffman@36795
   280
  from b i have nz: "\<forall>n\<ge>i. X n \<noteq> 0" by auto
huffman@36795
   281
  obtain s where s: "0 < s" and r: "r = inverse b * s * inverse b"
huffman@36795
   282
  proof
huffman@36795
   283
    show "0 < b * r * b"
huffman@36795
   284
      by (simp add: `0 < r` b mult_pos_pos)
huffman@36795
   285
    show "r = inverse b * (b * r * b) * inverse b"
huffman@36795
   286
      using b by simp
huffman@36795
   287
  qed
huffman@36795
   288
  obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>X m - X n\<bar> < s"
huffman@36795
   289
    using cauchyD [OF X s] ..
huffman@36795
   290
  have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>inverse (X m) - inverse (X n)\<bar> < r"
huffman@36795
   291
  proof (clarsimp)
huffman@36795
   292
    fix m n assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n"
huffman@36795
   293
    have "\<bar>inverse (X m) - inverse (X n)\<bar> =
huffman@36795
   294
          inverse \<bar>X m\<bar> * \<bar>X m - X n\<bar> * inverse \<bar>X n\<bar>"
huffman@36795
   295
      by (simp add: inverse_diff_inverse nz * abs_mult)
huffman@36795
   296
    also have "\<dots> < inverse b * s * inverse b"
huffman@36795
   297
      by (simp add: mult_strict_mono less_imp_inverse_less
huffman@36795
   298
                    mult_pos_pos i j b * s)
huffman@36795
   299
    finally show "\<bar>inverse (X m) - inverse (X n)\<bar> < r" unfolding r .
huffman@36795
   300
  qed
huffman@36795
   301
  thus "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>inverse (X m) - inverse (X n)\<bar> < r" ..
huffman@36795
   302
qed
huffman@36795
   303
huffman@36795
   304
subsection {* Equivalence relation on Cauchy sequences *}
huffman@36795
   305
huffman@36795
   306
definition
huffman@36795
   307
  realrel :: "((nat \<Rightarrow> rat) \<times> (nat \<Rightarrow> rat)) set"
huffman@36795
   308
where
huffman@36795
   309
  "realrel = {(X, Y). cauchy X \<and> cauchy Y \<and> vanishes (\<lambda>n. X n - Y n)}"
huffman@36795
   310
huffman@36795
   311
lemma refl_realrel: "refl_on {X. cauchy X} realrel"
huffman@36795
   312
  unfolding realrel_def by (rule refl_onI, clarsimp, simp)
huffman@36795
   313
huffman@36795
   314
lemma sym_realrel: "sym realrel"
huffman@36795
   315
  unfolding realrel_def
huffman@36795
   316
  by (rule symI, clarify, drule vanishes_minus, simp)
paulson@14484
   317
huffman@36795
   318
lemma trans_realrel: "trans realrel"
huffman@36795
   319
  unfolding realrel_def
huffman@36795
   320
  apply (rule transI, clarify)
huffman@36795
   321
  apply (drule (1) vanishes_add)
huffman@36795
   322
  apply (simp add: algebra_simps)
huffman@36795
   323
  done
huffman@36795
   324
huffman@36795
   325
lemma equiv_realrel: "equiv {X. cauchy X} realrel"
huffman@36795
   326
  using refl_realrel sym_realrel trans_realrel
haftmann@40815
   327
  by (rule equivI)
huffman@36795
   328
huffman@36795
   329
subsection {* The field of real numbers *}
huffman@36795
   330
huffman@36795
   331
typedef (open) real = "{X. cauchy X} // realrel"
huffman@36795
   332
  by (fast intro: quotientI cauchy_const)
huffman@36795
   333
huffman@36795
   334
definition
huffman@36795
   335
  Real :: "(nat \<Rightarrow> rat) \<Rightarrow> real"
huffman@36795
   336
where
huffman@36795
   337
  "Real X = Abs_real (realrel `` {X})"
huffman@36795
   338
huffman@36795
   339
definition
huffman@36795
   340
  real_case :: "((nat \<Rightarrow> rat) \<Rightarrow> 'a) \<Rightarrow> real \<Rightarrow> 'a"
huffman@36795
   341
where
huffman@36795
   342
  "real_case f x = (THE y. \<forall>X\<in>Rep_real x. y = f X)"
huffman@36795
   343
huffman@36795
   344
lemma Real_induct [induct type: real]:
huffman@36795
   345
  "(\<And>X. cauchy X \<Longrightarrow> P (Real X)) \<Longrightarrow> P x"
huffman@36795
   346
  unfolding Real_def
huffman@36795
   347
  apply (induct x)
huffman@36795
   348
  apply (erule quotientE)
huffman@36795
   349
  apply (simp)
huffman@36795
   350
  done
huffman@36795
   351
huffman@36795
   352
lemma real_case_1:
huffman@36795
   353
  assumes f: "congruent realrel f"
huffman@36795
   354
  assumes X: "cauchy X"
huffman@36795
   355
  shows "real_case f (Real X) = f X"
huffman@36795
   356
  unfolding real_case_def Real_def
huffman@36795
   357
  apply (subst Abs_real_inverse)
huffman@36795
   358
  apply (simp add: quotientI X)
huffman@36795
   359
  apply (rule the_equality)
huffman@36795
   360
  apply clarsimp
haftmann@40816
   361
  apply (erule congruentD [OF f])
huffman@36795
   362
  apply (erule bspec)
huffman@36795
   363
  apply simp
huffman@36795
   364
  apply (rule refl_onD [OF refl_realrel])
huffman@36795
   365
  apply (simp add: X)
huffman@36795
   366
  done
huffman@36795
   367
huffman@36795
   368
lemma real_case_2:
huffman@36795
   369
  assumes f: "congruent2 realrel realrel f"
huffman@36795
   370
  assumes X: "cauchy X" and Y: "cauchy Y"
huffman@36795
   371
  shows "real_case (\<lambda>X. real_case (\<lambda>Y. f X Y) (Real Y)) (Real X) = f X Y"
huffman@36795
   372
 apply (subst real_case_1 [OF _ X])
haftmann@40816
   373
  apply (rule congruentI)
huffman@36795
   374
  apply (subst real_case_1 [OF _ Y])
huffman@36795
   375
   apply (rule congruent2_implies_congruent [OF equiv_realrel f])
huffman@36795
   376
   apply (simp add: realrel_def)
huffman@36795
   377
  apply (subst real_case_1 [OF _ Y])
huffman@36795
   378
   apply (rule congruent2_implies_congruent [OF equiv_realrel f])
huffman@36795
   379
   apply (simp add: realrel_def)
haftmann@40817
   380
  apply (erule congruent2D [OF f])
huffman@36795
   381
  apply (rule refl_onD [OF refl_realrel])
huffman@36795
   382
  apply (simp add: Y)
huffman@36795
   383
  apply (rule real_case_1 [OF _ Y])
huffman@36795
   384
  apply (rule congruent2_implies_congruent [OF equiv_realrel f])
huffman@36795
   385
  apply (simp add: X)
huffman@36795
   386
  done
huffman@36795
   387
huffman@36795
   388
lemma eq_Real:
huffman@36795
   389
  "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> Real X = Real Y \<longleftrightarrow> vanishes (\<lambda>n. X n - Y n)"
huffman@36795
   390
  unfolding Real_def
huffman@36795
   391
  apply (subst Abs_real_inject)
huffman@36795
   392
  apply (simp add: quotientI)
huffman@36795
   393
  apply (simp add: quotientI)
huffman@36795
   394
  apply (simp add: eq_equiv_class_iff [OF equiv_realrel])
huffman@36795
   395
  apply (simp add: realrel_def)
huffman@36795
   396
  done
huffman@36795
   397
huffman@36795
   398
lemma add_respects2_realrel:
huffman@36795
   399
  "(\<lambda>X Y. Real (\<lambda>n. X n + Y n)) respects2 realrel"
huffman@36795
   400
proof (rule congruent2_commuteI [OF equiv_realrel, unfolded mem_Collect_eq])
huffman@36795
   401
  fix X Y show "Real (\<lambda>n. X n + Y n) = Real (\<lambda>n. Y n + X n)"
huffman@36795
   402
    by (simp add: add_commute)
huffman@36795
   403
next
huffman@36795
   404
  fix X assume X: "cauchy X"
huffman@36795
   405
  fix Y Z assume "(Y, Z) \<in> realrel"
huffman@36795
   406
  hence Y: "cauchy Y" and Z: "cauchy Z" and YZ: "vanishes (\<lambda>n. Y n - Z n)"
huffman@36795
   407
    unfolding realrel_def by simp_all
huffman@36795
   408
  show "Real (\<lambda>n. X n + Y n) = Real (\<lambda>n. X n + Z n)"
huffman@36795
   409
  proof (rule eq_Real [THEN iffD2])
huffman@36795
   410
    show "cauchy (\<lambda>n. X n + Y n)" using X Y by (rule cauchy_add)
huffman@36795
   411
    show "cauchy (\<lambda>n. X n + Z n)" using X Z by (rule cauchy_add)
huffman@36795
   412
    show "vanishes (\<lambda>n. (X n + Y n) - (X n + Z n))"
huffman@36795
   413
      unfolding add_diff_add using YZ by simp
huffman@36795
   414
  qed
huffman@36795
   415
qed
huffman@36795
   416
huffman@36795
   417
lemma minus_respects_realrel:
huffman@36795
   418
  "(\<lambda>X. Real (\<lambda>n. - X n)) respects realrel"
haftmann@40816
   419
proof (rule congruentI)
huffman@36795
   420
  fix X Y assume "(X, Y) \<in> realrel"
huffman@36795
   421
  hence X: "cauchy X" and Y: "cauchy Y" and XY: "vanishes (\<lambda>n. X n - Y n)"
huffman@36795
   422
    unfolding realrel_def by simp_all
huffman@36795
   423
  show "Real (\<lambda>n. - X n) = Real (\<lambda>n. - Y n)"
huffman@36795
   424
  proof (rule eq_Real [THEN iffD2])
huffman@36795
   425
    show "cauchy (\<lambda>n. - X n)" using X by (rule cauchy_minus)
huffman@36795
   426
    show "cauchy (\<lambda>n. - Y n)" using Y by (rule cauchy_minus)
huffman@36795
   427
    show "vanishes (\<lambda>n. (- X n) - (- Y n))"
huffman@36795
   428
      unfolding minus_diff_minus using XY by (rule vanishes_minus)
huffman@36795
   429
  qed
huffman@36795
   430
qed
huffman@36795
   431
huffman@36795
   432
lemma mult_respects2_realrel:
huffman@36795
   433
  "(\<lambda>X Y. Real (\<lambda>n. X n * Y n)) respects2 realrel"
huffman@36795
   434
proof (rule congruent2_commuteI [OF equiv_realrel, unfolded mem_Collect_eq])
huffman@36795
   435
  fix X Y
huffman@36795
   436
  show "Real (\<lambda>n. X n * Y n) = Real (\<lambda>n. Y n * X n)"
huffman@36795
   437
    by (simp add: mult_commute)
huffman@36795
   438
next
huffman@36795
   439
  fix X assume X: "cauchy X"
huffman@36795
   440
  fix Y Z assume "(Y, Z) \<in> realrel"
huffman@36795
   441
  hence Y: "cauchy Y" and Z: "cauchy Z" and YZ: "vanishes (\<lambda>n. Y n - Z n)"
huffman@36795
   442
    unfolding realrel_def by simp_all
huffman@36795
   443
  show "Real (\<lambda>n. X n * Y n) = Real (\<lambda>n. X n * Z n)"
huffman@36795
   444
  proof (rule eq_Real [THEN iffD2])
huffman@36795
   445
    show "cauchy (\<lambda>n. X n * Y n)" using X Y by (rule cauchy_mult)
huffman@36795
   446
    show "cauchy (\<lambda>n. X n * Z n)" using X Z by (rule cauchy_mult)
huffman@36795
   447
    have "vanishes (\<lambda>n. X n * (Y n - Z n))"
huffman@36795
   448
      by (intro vanishes_mult_bounded cauchy_imp_bounded X YZ)
huffman@36795
   449
    thus "vanishes (\<lambda>n. X n * Y n - X n * Z n)"
huffman@36795
   450
      by (simp add: right_diff_distrib)
huffman@36795
   451
  qed
huffman@36795
   452
qed
huffman@36795
   453
huffman@36795
   454
lemma vanishes_diff_inverse:
huffman@36795
   455
  assumes X: "cauchy X" "\<not> vanishes X"
huffman@36795
   456
  assumes Y: "cauchy Y" "\<not> vanishes Y"
huffman@36795
   457
  assumes XY: "vanishes (\<lambda>n. X n - Y n)"
huffman@36795
   458
  shows "vanishes (\<lambda>n. inverse (X n) - inverse (Y n))"
huffman@36795
   459
proof (rule vanishesI)
huffman@36795
   460
  fix r :: rat assume r: "0 < r"
huffman@36795
   461
  obtain a i where a: "0 < a" and i: "\<forall>n\<ge>i. a < \<bar>X n\<bar>"
huffman@36795
   462
    using cauchy_not_vanishes [OF X] by fast
huffman@36795
   463
  obtain b j where b: "0 < b" and j: "\<forall>n\<ge>j. b < \<bar>Y n\<bar>"
huffman@36795
   464
    using cauchy_not_vanishes [OF Y] by fast
huffman@36795
   465
  obtain s where s: "0 < s" and "inverse a * s * inverse b = r"
huffman@36795
   466
  proof
huffman@36795
   467
    show "0 < a * r * b"
huffman@36795
   468
      using a r b by (simp add: mult_pos_pos)
huffman@36795
   469
    show "inverse a * (a * r * b) * inverse b = r"
huffman@36795
   470
      using a r b by simp
huffman@36795
   471
  qed
huffman@36795
   472
  obtain k where k: "\<forall>n\<ge>k. \<bar>X n - Y n\<bar> < s"
huffman@36795
   473
    using vanishesD [OF XY s] ..
huffman@36795
   474
  have "\<forall>n\<ge>max (max i j) k. \<bar>inverse (X n) - inverse (Y n)\<bar> < r"
huffman@36795
   475
  proof (clarsimp)
huffman@36795
   476
    fix n assume n: "i \<le> n" "j \<le> n" "k \<le> n"
huffman@36795
   477
    have "X n \<noteq> 0" and "Y n \<noteq> 0"
huffman@36795
   478
      using i j a b n by auto
huffman@36795
   479
    hence "\<bar>inverse (X n) - inverse (Y n)\<bar> =
huffman@36795
   480
        inverse \<bar>X n\<bar> * \<bar>X n - Y n\<bar> * inverse \<bar>Y n\<bar>"
huffman@36795
   481
      by (simp add: inverse_diff_inverse abs_mult)
huffman@36795
   482
    also have "\<dots> < inverse a * s * inverse b"
huffman@36795
   483
      apply (intro mult_strict_mono' less_imp_inverse_less)
huffman@36795
   484
      apply (simp_all add: a b i j k n mult_nonneg_nonneg)
huffman@36795
   485
      done
huffman@36795
   486
    also note `inverse a * s * inverse b = r`
huffman@36795
   487
    finally show "\<bar>inverse (X n) - inverse (Y n)\<bar> < r" .
huffman@36795
   488
  qed
huffman@36795
   489
  thus "\<exists>k. \<forall>n\<ge>k. \<bar>inverse (X n) - inverse (Y n)\<bar> < r" ..
huffman@36795
   490
qed
huffman@36795
   491
huffman@36795
   492
lemma inverse_respects_realrel:
huffman@36795
   493
  "(\<lambda>X. if vanishes X then c else Real (\<lambda>n. inverse (X n))) respects realrel"
huffman@36795
   494
    (is "?inv respects realrel")
haftmann@40816
   495
proof (rule congruentI)
huffman@36795
   496
  fix X Y assume "(X, Y) \<in> realrel"
huffman@36795
   497
  hence X: "cauchy X" and Y: "cauchy Y" and XY: "vanishes (\<lambda>n. X n - Y n)"
huffman@36795
   498
    unfolding realrel_def by simp_all
huffman@36795
   499
  have "vanishes X \<longleftrightarrow> vanishes Y"
huffman@36795
   500
  proof
huffman@36795
   501
    assume "vanishes X"
huffman@36795
   502
    from vanishes_diff [OF this XY] show "vanishes Y" by simp
huffman@36795
   503
  next
huffman@36795
   504
    assume "vanishes Y"
huffman@36795
   505
    from vanishes_add [OF this XY] show "vanishes X" by simp
huffman@36795
   506
  qed
huffman@36795
   507
  thus "?inv X = ?inv Y"
huffman@36795
   508
    by (simp add: vanishes_diff_inverse eq_Real X Y XY)
huffman@36795
   509
qed
huffman@36795
   510
huffman@36795
   511
instantiation real :: field_inverse_zero
haftmann@25571
   512
begin
paulson@5588
   513
haftmann@25571
   514
definition
huffman@36795
   515
  "0 = Real (\<lambda>n. 0)"
haftmann@25571
   516
haftmann@25571
   517
definition
huffman@36795
   518
  "1 = Real (\<lambda>n. 1)"
huffman@36795
   519
huffman@36795
   520
definition
huffman@36795
   521
  "x + y = real_case (\<lambda>X. real_case (\<lambda>Y. Real (\<lambda>n. X n + Y n)) y) x"
paulson@5588
   522
haftmann@25571
   523
definition
huffman@36795
   524
  "- x = real_case (\<lambda>X. Real (\<lambda>n. - X n)) x"
huffman@36795
   525
huffman@36795
   526
definition
huffman@36795
   527
  "x - y = (x::real) + - y"
bauerg@10606
   528
haftmann@25571
   529
definition
huffman@36795
   530
  "x * y = real_case (\<lambda>X. real_case (\<lambda>Y. Real (\<lambda>n. X n * Y n)) y) x"
haftmann@25571
   531
haftmann@25571
   532
definition
huffman@36795
   533
  "inverse =
huffman@36795
   534
    real_case (\<lambda>X. if vanishes X then 0 else Real (\<lambda>n. inverse (X n)))"
paulson@14484
   535
haftmann@25571
   536
definition
huffman@36795
   537
  "x / y = (x::real) * inverse y"
huffman@36795
   538
huffman@36795
   539
lemma add_Real:
huffman@36795
   540
  assumes X: "cauchy X" and Y: "cauchy Y"
huffman@36795
   541
  shows "Real X + Real Y = Real (\<lambda>n. X n + Y n)"
huffman@36795
   542
  unfolding plus_real_def
huffman@36795
   543
  by (rule real_case_2 [OF add_respects2_realrel X Y])
huffman@36795
   544
huffman@36795
   545
lemma minus_Real:
huffman@36795
   546
  assumes X: "cauchy X"
huffman@36795
   547
  shows "- Real X = Real (\<lambda>n. - X n)"
huffman@36795
   548
  unfolding uminus_real_def
huffman@36795
   549
  by (rule real_case_1 [OF minus_respects_realrel X])
paulson@5588
   550
huffman@36795
   551
lemma diff_Real:
huffman@36795
   552
  assumes X: "cauchy X" and Y: "cauchy Y"
huffman@36795
   553
  shows "Real X - Real Y = Real (\<lambda>n. X n - Y n)"
huffman@36795
   554
  unfolding minus_real_def diff_minus
huffman@36795
   555
  by (simp add: minus_Real add_Real X Y)
haftmann@25571
   556
huffman@36795
   557
lemma mult_Real:
huffman@36795
   558
  assumes X: "cauchy X" and Y: "cauchy Y"
huffman@36795
   559
  shows "Real X * Real Y = Real (\<lambda>n. X n * Y n)"
huffman@36795
   560
  unfolding times_real_def
huffman@36795
   561
  by (rule real_case_2 [OF mult_respects2_realrel X Y])
huffman@36795
   562
huffman@36795
   563
lemma inverse_Real:
huffman@36795
   564
  assumes X: "cauchy X"
huffman@36795
   565
  shows "inverse (Real X) =
huffman@36795
   566
    (if vanishes X then 0 else Real (\<lambda>n. inverse (X n)))"
huffman@36795
   567
  unfolding inverse_real_def
huffman@36795
   568
  by (rule real_case_1 [OF inverse_respects_realrel X])
paulson@14269
   569
huffman@36795
   570
instance proof
huffman@36795
   571
  fix a b c :: real
huffman@36795
   572
  show "a + b = b + a"
huffman@36795
   573
    by (induct a, induct b) (simp add: add_Real add_ac)
huffman@36795
   574
  show "(a + b) + c = a + (b + c)"
huffman@36795
   575
    by (induct a, induct b, induct c) (simp add: add_Real add_ac)
huffman@36795
   576
  show "0 + a = a"
huffman@36795
   577
    unfolding zero_real_def
huffman@36795
   578
    by (induct a) (simp add: add_Real)
huffman@36795
   579
  show "- a + a = 0"
huffman@36795
   580
    unfolding zero_real_def
huffman@36795
   581
    by (induct a) (simp add: minus_Real add_Real)
huffman@36795
   582
  show "a - b = a + - b"
huffman@36795
   583
    by (rule minus_real_def)
huffman@36795
   584
  show "(a * b) * c = a * (b * c)"
huffman@36795
   585
    by (induct a, induct b, induct c) (simp add: mult_Real mult_ac)
huffman@36795
   586
  show "a * b = b * a"
huffman@36795
   587
    by (induct a, induct b) (simp add: mult_Real mult_ac)
huffman@36795
   588
  show "1 * a = a"
huffman@36795
   589
    unfolding one_real_def
huffman@36795
   590
    by (induct a) (simp add: mult_Real)
huffman@36795
   591
  show "(a + b) * c = a * c + b * c"
huffman@36795
   592
    by (induct a, induct b, induct c)
huffman@36795
   593
       (simp add: mult_Real add_Real algebra_simps)
huffman@36795
   594
  show "(0\<Colon>real) \<noteq> (1\<Colon>real)"
huffman@36795
   595
    unfolding zero_real_def one_real_def
huffman@36795
   596
    by (simp add: eq_Real)
huffman@36795
   597
  show "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
huffman@36795
   598
    unfolding zero_real_def one_real_def
huffman@36795
   599
    apply (induct a)
huffman@36795
   600
    apply (simp add: eq_Real inverse_Real mult_Real)
huffman@36795
   601
    apply (rule vanishesI)
huffman@36795
   602
    apply (frule (1) cauchy_not_vanishes, clarify)
huffman@36795
   603
    apply (rule_tac x=k in exI, clarify)
huffman@36795
   604
    apply (drule_tac x=n in spec, simp)
huffman@36795
   605
    done
huffman@36795
   606
  show "a / b = a * inverse b"
huffman@36795
   607
    by (rule divide_real_def)
huffman@36795
   608
  show "inverse (0::real) = 0"
huffman@36795
   609
    by (simp add: zero_real_def inverse_Real)
huffman@36795
   610
qed
haftmann@25571
   611
haftmann@25571
   612
end
paulson@14334
   613
huffman@36795
   614
subsection {* Positive reals *}
paulson@14269
   615
huffman@36795
   616
definition
huffman@36795
   617
  positive :: "real \<Rightarrow> bool"
huffman@36795
   618
where
huffman@36795
   619
  "positive = real_case (\<lambda>X. \<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n)"
paulson@14269
   620
huffman@36795
   621
lemma bool_congruentI:
huffman@36795
   622
  assumes sym: "sym r"
huffman@36795
   623
  assumes P: "\<And>x y. (x, y) \<in> r \<Longrightarrow> P x \<Longrightarrow> P y"
huffman@36795
   624
  shows "P respects r"
haftmann@40816
   625
apply (rule congruentI)
huffman@36795
   626
apply (rule iffI)
huffman@36795
   627
apply (erule (1) P)
huffman@36795
   628
apply (erule (1) P [OF symD [OF sym]])
paulson@14269
   629
done
paulson@14269
   630
huffman@36795
   631
lemma positive_respects_realrel:
huffman@36795
   632
  "(\<lambda>X. \<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n) respects realrel"
huffman@36795
   633
proof (rule bool_congruentI)
huffman@36795
   634
  show "sym realrel" by (rule sym_realrel)
huffman@36795
   635
next
huffman@36795
   636
  fix X Y assume "(X, Y) \<in> realrel"
huffman@36795
   637
  hence XY: "vanishes (\<lambda>n. X n - Y n)"
huffman@36795
   638
    unfolding realrel_def by simp_all
huffman@36795
   639
  assume "\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n"
huffman@36795
   640
  then obtain r i where "0 < r" and i: "\<forall>n\<ge>i. r < X n"
huffman@36795
   641
    by fast
huffman@36795
   642
  obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
huffman@36795
   643
    using `0 < r` by (rule obtain_pos_sum)
huffman@36795
   644
  obtain j where j: "\<forall>n\<ge>j. \<bar>X n - Y n\<bar> < s"
huffman@36795
   645
    using vanishesD [OF XY s] ..
huffman@36795
   646
  have "\<forall>n\<ge>max i j. t < Y n"
huffman@36795
   647
  proof (clarsimp)
huffman@36795
   648
    fix n assume n: "i \<le> n" "j \<le> n"
huffman@36795
   649
    have "\<bar>X n - Y n\<bar> < s" and "r < X n"
huffman@36795
   650
      using i j n by simp_all
huffman@36795
   651
    thus "t < Y n" unfolding r by simp
huffman@36795
   652
  qed
huffman@36795
   653
  thus "\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < Y n" using t by fast
paulson@14484
   654
qed
paulson@14269
   655
huffman@36795
   656
lemma positive_Real:
huffman@36795
   657
  assumes X: "cauchy X"
huffman@36795
   658
  shows "positive (Real X) \<longleftrightarrow> (\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n)"
huffman@36795
   659
unfolding positive_def
huffman@36795
   660
by (rule real_case_1 [OF positive_respects_realrel X])
huffman@23287
   661
huffman@36795
   662
lemma positive_zero: "\<not> positive 0"
huffman@36795
   663
unfolding zero_real_def by (auto simp add: positive_Real)
paulson@14269
   664
huffman@36795
   665
lemma positive_add:
huffman@36795
   666
  "positive x \<Longrightarrow> positive y \<Longrightarrow> positive (x + y)"
huffman@36795
   667
apply (induct x, induct y, rename_tac Y X)
huffman@36795
   668
apply (simp add: add_Real positive_Real)
huffman@36795
   669
apply (clarify, rename_tac a b i j)
huffman@36795
   670
apply (rule_tac x="a + b" in exI, simp)
huffman@36795
   671
apply (rule_tac x="max i j" in exI, clarsimp)
huffman@36795
   672
apply (simp add: add_strict_mono)
paulson@14269
   673
done
paulson@14269
   674
huffman@36795
   675
lemma positive_mult:
huffman@36795
   676
  "positive x \<Longrightarrow> positive y \<Longrightarrow> positive (x * y)"
huffman@36795
   677
apply (induct x, induct y, rename_tac Y X)
huffman@36795
   678
apply (simp add: mult_Real positive_Real)
huffman@36795
   679
apply (clarify, rename_tac a b i j)
huffman@36795
   680
apply (rule_tac x="a * b" in exI, simp add: mult_pos_pos)
huffman@36795
   681
apply (rule_tac x="max i j" in exI, clarsimp)
huffman@36795
   682
apply (rule mult_strict_mono, auto)
huffman@36795
   683
done
huffman@36795
   684
huffman@36795
   685
lemma positive_minus:
huffman@36795
   686
  "\<not> positive x \<Longrightarrow> x \<noteq> 0 \<Longrightarrow> positive (- x)"
huffman@36795
   687
apply (induct x, rename_tac X)
huffman@36795
   688
apply (simp add: zero_real_def eq_Real minus_Real positive_Real)
huffman@36795
   689
apply (drule (1) cauchy_not_vanishes_cases, safe, fast, fast)
paulson@14269
   690
done
paulson@14334
   691
huffman@36795
   692
instantiation real :: linordered_field_inverse_zero
huffman@36795
   693
begin
paulson@14341
   694
huffman@36795
   695
definition
huffman@36795
   696
  "x < y \<longleftrightarrow> positive (y - x)"
paulson@14341
   697
huffman@36795
   698
definition
huffman@36795
   699
  "x \<le> (y::real) \<longleftrightarrow> x < y \<or> x = y"
paulson@14334
   700
huffman@36795
   701
definition
huffman@36795
   702
  "abs (a::real) = (if a < 0 then - a else a)"
paulson@14269
   703
huffman@36795
   704
definition
huffman@36795
   705
  "sgn (a::real) = (if a = 0 then 0 else if 0 < a then 1 else - 1)"
paulson@14269
   706
huffman@36795
   707
instance proof
huffman@36795
   708
  fix a b c :: real
huffman@36795
   709
  show "\<bar>a\<bar> = (if a < 0 then - a else a)"
huffman@36795
   710
    by (rule abs_real_def)
huffman@36795
   711
  show "a < b \<longleftrightarrow> a \<le> b \<and> \<not> b \<le> a"
huffman@36795
   712
    unfolding less_eq_real_def less_real_def
huffman@36795
   713
    by (auto, drule (1) positive_add, simp_all add: positive_zero)
huffman@36795
   714
  show "a \<le> a"
huffman@36795
   715
    unfolding less_eq_real_def by simp
huffman@36795
   716
  show "a \<le> b \<Longrightarrow> b \<le> c \<Longrightarrow> a \<le> c"
huffman@36795
   717
    unfolding less_eq_real_def less_real_def
huffman@36795
   718
    by (auto, drule (1) positive_add, simp add: algebra_simps)
huffman@36795
   719
  show "a \<le> b \<Longrightarrow> b \<le> a \<Longrightarrow> a = b"
huffman@36795
   720
    unfolding less_eq_real_def less_real_def
huffman@36795
   721
    by (auto, drule (1) positive_add, simp add: positive_zero)
huffman@36795
   722
  show "a \<le> b \<Longrightarrow> c + a \<le> c + b"
huffman@47108
   723
    unfolding less_eq_real_def less_real_def by (auto simp: diff_minus) (* by auto *)
huffman@47108
   724
    (* FIXME: Procedure int_combine_numerals: c + b - (c + a) \<equiv> b + - a *)
huffman@47108
   725
    (* Should produce c + b - (c + a) \<equiv> b - a *)
huffman@36795
   726
  show "sgn a = (if a = 0 then 0 else if 0 < a then 1 else - 1)"
huffman@36795
   727
    by (rule sgn_real_def)
huffman@36795
   728
  show "a \<le> b \<or> b \<le> a"
huffman@36795
   729
    unfolding less_eq_real_def less_real_def
huffman@36795
   730
    by (auto dest!: positive_minus)
huffman@36795
   731
  show "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
huffman@36795
   732
    unfolding less_real_def
huffman@36795
   733
    by (drule (1) positive_mult, simp add: algebra_simps)
huffman@23288
   734
qed
paulson@14378
   735
huffman@36795
   736
end
paulson@14334
   737
haftmann@25571
   738
instantiation real :: distrib_lattice
haftmann@25571
   739
begin
haftmann@25571
   740
haftmann@25571
   741
definition
huffman@36795
   742
  "(inf :: real \<Rightarrow> real \<Rightarrow> real) = min"
haftmann@25571
   743
haftmann@25571
   744
definition
huffman@36795
   745
  "(sup :: real \<Rightarrow> real \<Rightarrow> real) = max"
huffman@36795
   746
huffman@36795
   747
instance proof
huffman@36795
   748
qed (auto simp add: inf_real_def sup_real_def min_max.sup_inf_distrib1)
huffman@36795
   749
huffman@36795
   750
end
haftmann@25571
   751
huffman@36795
   752
lemma of_nat_Real: "of_nat x = Real (\<lambda>n. of_nat x)"
huffman@36795
   753
apply (induct x)
huffman@36795
   754
apply (simp add: zero_real_def)
huffman@36795
   755
apply (simp add: one_real_def add_Real)
huffman@36795
   756
done
paulson@14378
   757
huffman@36795
   758
lemma of_int_Real: "of_int x = Real (\<lambda>n. of_int x)"
huffman@36795
   759
apply (cases x rule: int_diff_cases)
huffman@36795
   760
apply (simp add: of_nat_Real diff_Real)
huffman@36795
   761
done
paulson@14334
   762
huffman@36795
   763
lemma of_rat_Real: "of_rat x = Real (\<lambda>n. x)"
huffman@36795
   764
apply (induct x)
huffman@36795
   765
apply (simp add: Fract_of_int_quotient of_rat_divide)
huffman@36795
   766
apply (simp add: of_int_Real divide_inverse)
huffman@36795
   767
apply (simp add: inverse_Real mult_Real)
huffman@36795
   768
done
huffman@36795
   769
huffman@36795
   770
instance real :: archimedean_field
paulson@14334
   771
proof
huffman@36795
   772
  fix x :: real
huffman@36795
   773
  show "\<exists>z. x \<le> of_int z"
huffman@36795
   774
    apply (induct x)
huffman@36795
   775
    apply (frule cauchy_imp_bounded, clarify)
huffman@36795
   776
    apply (rule_tac x="ceiling b + 1" in exI)
huffman@36795
   777
    apply (rule less_imp_le)
huffman@36795
   778
    apply (simp add: of_int_Real less_real_def diff_Real positive_Real)
huffman@36795
   779
    apply (rule_tac x=1 in exI, simp add: algebra_simps)
huffman@36795
   780
    apply (rule_tac x=0 in exI, clarsimp)
huffman@36795
   781
    apply (rule le_less_trans [OF abs_ge_self])
huffman@36795
   782
    apply (rule less_le_trans [OF _ le_of_int_ceiling])
huffman@36795
   783
    apply simp
huffman@36795
   784
    done
paulson@14334
   785
qed
paulson@14334
   786
bulwahn@43732
   787
instantiation real :: floor_ceiling
bulwahn@43732
   788
begin
bulwahn@43732
   789
bulwahn@43732
   790
definition [code del]:
bulwahn@43732
   791
  "floor (x::real) = (THE z. of_int z \<le> x \<and> x < of_int (z + 1))"
bulwahn@43732
   792
bulwahn@43732
   793
instance proof
bulwahn@43732
   794
  fix x :: real
bulwahn@43732
   795
  show "of_int (floor x) \<le> x \<and> x < of_int (floor x + 1)"
bulwahn@43732
   796
    unfolding floor_real_def using floor_exists1 by (rule theI')
bulwahn@43732
   797
qed
bulwahn@43732
   798
bulwahn@43732
   799
end
bulwahn@43732
   800
huffman@36795
   801
subsection {* Completeness *}
paulson@14365
   802
huffman@36795
   803
lemma not_positive_Real:
huffman@36795
   804
  assumes X: "cauchy X"
huffman@36795
   805
  shows "\<not> positive (Real X) \<longleftrightarrow> (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. X n \<le> r)"
huffman@36795
   806
unfolding positive_Real [OF X]
huffman@36795
   807
apply (auto, unfold not_less)
huffman@36795
   808
apply (erule obtain_pos_sum)
huffman@36795
   809
apply (drule_tac x=s in spec, simp)
huffman@36795
   810
apply (drule_tac r=t in cauchyD [OF X], clarify)
huffman@36795
   811
apply (drule_tac x=k in spec, clarsimp)
huffman@36795
   812
apply (rule_tac x=n in exI, clarify, rename_tac m)
huffman@36795
   813
apply (drule_tac x=m in spec, simp)
huffman@36795
   814
apply (drule_tac x=n in spec, simp)
huffman@36795
   815
apply (drule spec, drule (1) mp, clarify, rename_tac i)
huffman@36795
   816
apply (rule_tac x="max i k" in exI, simp)
huffman@36795
   817
done
huffman@36795
   818
huffman@36795
   819
lemma le_Real:
huffman@36795
   820
  assumes X: "cauchy X" and Y: "cauchy Y"
huffman@36795
   821
  shows "Real X \<le> Real Y = (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. X n \<le> Y n + r)"
huffman@36795
   822
unfolding not_less [symmetric, where 'a=real] less_real_def
huffman@36795
   823
apply (simp add: diff_Real not_positive_Real X Y)
huffman@36795
   824
apply (simp add: diff_le_eq add_ac)
huffman@36795
   825
done
paulson@14365
   826
huffman@36795
   827
lemma le_RealI:
huffman@36795
   828
  assumes Y: "cauchy Y"
huffman@36795
   829
  shows "\<forall>n. x \<le> of_rat (Y n) \<Longrightarrow> x \<le> Real Y"
huffman@36795
   830
proof (induct x)
huffman@36795
   831
  fix X assume X: "cauchy X" and "\<forall>n. Real X \<le> of_rat (Y n)"
huffman@36795
   832
  hence le: "\<And>m r. 0 < r \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. X n \<le> Y m + r"
huffman@36795
   833
    by (simp add: of_rat_Real le_Real)
huffman@36795
   834
  {
huffman@36795
   835
    fix r :: rat assume "0 < r"
huffman@36795
   836
    then obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
huffman@36795
   837
      by (rule obtain_pos_sum)
huffman@36795
   838
    obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>Y m - Y n\<bar> < s"
huffman@36795
   839
      using cauchyD [OF Y s] ..
huffman@36795
   840
    obtain j where j: "\<forall>n\<ge>j. X n \<le> Y i + t"
huffman@36795
   841
      using le [OF t] ..
huffman@36795
   842
    have "\<forall>n\<ge>max i j. X n \<le> Y n + r"
huffman@36795
   843
    proof (clarsimp)
huffman@36795
   844
      fix n assume n: "i \<le> n" "j \<le> n"
huffman@36795
   845
      have "X n \<le> Y i + t" using n j by simp
huffman@36795
   846
      moreover have "\<bar>Y i - Y n\<bar> < s" using n i by simp
huffman@36795
   847
      ultimately show "X n \<le> Y n + r" unfolding r by simp
huffman@36795
   848
    qed
huffman@36795
   849
    hence "\<exists>k. \<forall>n\<ge>k. X n \<le> Y n + r" ..
huffman@36795
   850
  }
huffman@36795
   851
  thus "Real X \<le> Real Y"
huffman@36795
   852
    by (simp add: of_rat_Real le_Real X Y)
huffman@36795
   853
qed
paulson@14365
   854
huffman@36795
   855
lemma Real_leI:
huffman@36795
   856
  assumes X: "cauchy X"
huffman@36795
   857
  assumes le: "\<forall>n. of_rat (X n) \<le> y"
huffman@36795
   858
  shows "Real X \<le> y"
huffman@36795
   859
proof -
huffman@36795
   860
  have "- y \<le> - Real X"
huffman@36795
   861
    by (simp add: minus_Real X le_RealI of_rat_minus le)
huffman@36795
   862
  thus ?thesis by simp
huffman@36795
   863
qed
huffman@36795
   864
huffman@36795
   865
lemma less_RealD:
huffman@36795
   866
  assumes Y: "cauchy Y"
huffman@36795
   867
  shows "x < Real Y \<Longrightarrow> \<exists>n. x < of_rat (Y n)"
huffman@36795
   868
by (erule contrapos_pp, simp add: not_less, erule Real_leI [OF Y])
huffman@36795
   869
huffman@36795
   870
lemma of_nat_less_two_power:
huffman@47108
   871
  "of_nat n < (2::'a::linordered_idom) ^ n"
huffman@36795
   872
apply (induct n)
huffman@36795
   873
apply simp
huffman@36795
   874
apply (subgoal_tac "(1::'a) \<le> 2 ^ n")
huffman@36795
   875
apply (drule (1) add_le_less_mono, simp)
huffman@36795
   876
apply simp
paulson@14365
   877
done
paulson@14365
   878
huffman@36795
   879
lemma complete_real:
huffman@36795
   880
  fixes S :: "real set"
huffman@36795
   881
  assumes "\<exists>x. x \<in> S" and "\<exists>z. \<forall>x\<in>S. x \<le> z"
huffman@36795
   882
  shows "\<exists>y. (\<forall>x\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> y \<le> z)"
huffman@36795
   883
proof -
huffman@36795
   884
  obtain x where x: "x \<in> S" using assms(1) ..
huffman@36795
   885
  obtain z where z: "\<forall>x\<in>S. x \<le> z" using assms(2) ..
paulson@14365
   886
huffman@36795
   887
  def P \<equiv> "\<lambda>x. \<forall>y\<in>S. y \<le> of_rat x"
huffman@36795
   888
  obtain a where a: "\<not> P a"
huffman@36795
   889
  proof
huffman@36795
   890
    have "of_int (floor (x - 1)) \<le> x - 1" by (rule of_int_floor_le)
huffman@36795
   891
    also have "x - 1 < x" by simp
huffman@36795
   892
    finally have "of_int (floor (x - 1)) < x" .
huffman@36795
   893
    hence "\<not> x \<le> of_int (floor (x - 1))" by (simp only: not_le)
huffman@36795
   894
    then show "\<not> P (of_int (floor (x - 1)))"
huffman@36795
   895
      unfolding P_def of_rat_of_int_eq using x by fast
huffman@36795
   896
  qed
huffman@36795
   897
  obtain b where b: "P b"
huffman@36795
   898
  proof
huffman@36795
   899
    show "P (of_int (ceiling z))"
huffman@36795
   900
    unfolding P_def of_rat_of_int_eq
huffman@36795
   901
    proof
huffman@36795
   902
      fix y assume "y \<in> S"
huffman@36795
   903
      hence "y \<le> z" using z by simp
huffman@36795
   904
      also have "z \<le> of_int (ceiling z)" by (rule le_of_int_ceiling)
huffman@36795
   905
      finally show "y \<le> of_int (ceiling z)" .
huffman@36795
   906
    qed
huffman@36795
   907
  qed
paulson@14365
   908
huffman@36795
   909
  def avg \<equiv> "\<lambda>x y :: rat. x/2 + y/2"
huffman@36795
   910
  def bisect \<equiv> "\<lambda>(x, y). if P (avg x y) then (x, avg x y) else (avg x y, y)"
huffman@36795
   911
  def A \<equiv> "\<lambda>n. fst ((bisect ^^ n) (a, b))"
huffman@36795
   912
  def B \<equiv> "\<lambda>n. snd ((bisect ^^ n) (a, b))"
huffman@36795
   913
  def C \<equiv> "\<lambda>n. avg (A n) (B n)"
huffman@36795
   914
  have A_0 [simp]: "A 0 = a" unfolding A_def by simp
huffman@36795
   915
  have B_0 [simp]: "B 0 = b" unfolding B_def by simp
huffman@36795
   916
  have A_Suc [simp]: "\<And>n. A (Suc n) = (if P (C n) then A n else C n)"
huffman@36795
   917
    unfolding A_def B_def C_def bisect_def split_def by simp
huffman@36795
   918
  have B_Suc [simp]: "\<And>n. B (Suc n) = (if P (C n) then C n else B n)"
huffman@36795
   919
    unfolding A_def B_def C_def bisect_def split_def by simp
paulson@14365
   920
huffman@36795
   921
  have width: "\<And>n. B n - A n = (b - a) / 2^n"
huffman@36795
   922
    apply (simp add: eq_divide_eq)
huffman@36795
   923
    apply (induct_tac n, simp)
huffman@36795
   924
    apply (simp add: C_def avg_def algebra_simps)
huffman@36795
   925
    done
huffman@36795
   926
huffman@36795
   927
  have twos: "\<And>y r :: rat. 0 < r \<Longrightarrow> \<exists>n. y / 2 ^ n < r"
huffman@36795
   928
    apply (simp add: divide_less_eq)
huffman@36795
   929
    apply (subst mult_commute)
huffman@36795
   930
    apply (frule_tac y=y in ex_less_of_nat_mult)
huffman@36795
   931
    apply clarify
huffman@36795
   932
    apply (rule_tac x=n in exI)
huffman@36795
   933
    apply (erule less_trans)
huffman@36795
   934
    apply (rule mult_strict_right_mono)
huffman@36795
   935
    apply (rule le_less_trans [OF _ of_nat_less_two_power])
huffman@36795
   936
    apply simp
huffman@36795
   937
    apply assumption
huffman@36795
   938
    done
paulson@14365
   939
huffman@36795
   940
  have PA: "\<And>n. \<not> P (A n)"
huffman@36795
   941
    by (induct_tac n, simp_all add: a)
huffman@36795
   942
  have PB: "\<And>n. P (B n)"
huffman@36795
   943
    by (induct_tac n, simp_all add: b)
huffman@36795
   944
  have ab: "a < b"
huffman@36795
   945
    using a b unfolding P_def
huffman@36795
   946
    apply (clarsimp simp add: not_le)
huffman@36795
   947
    apply (drule (1) bspec)
huffman@36795
   948
    apply (drule (1) less_le_trans)
huffman@36795
   949
    apply (simp add: of_rat_less)
huffman@36795
   950
    done
huffman@36795
   951
  have AB: "\<And>n. A n < B n"
huffman@36795
   952
    by (induct_tac n, simp add: ab, simp add: C_def avg_def)
huffman@36795
   953
  have A_mono: "\<And>i j. i \<le> j \<Longrightarrow> A i \<le> A j"
huffman@36795
   954
    apply (auto simp add: le_less [where 'a=nat])
huffman@36795
   955
    apply (erule less_Suc_induct)
huffman@36795
   956
    apply (clarsimp simp add: C_def avg_def)
huffman@36795
   957
    apply (simp add: add_divide_distrib [symmetric])
huffman@36795
   958
    apply (rule AB [THEN less_imp_le])
huffman@36795
   959
    apply simp
huffman@36795
   960
    done
huffman@36795
   961
  have B_mono: "\<And>i j. i \<le> j \<Longrightarrow> B j \<le> B i"
huffman@36795
   962
    apply (auto simp add: le_less [where 'a=nat])
huffman@36795
   963
    apply (erule less_Suc_induct)
huffman@36795
   964
    apply (clarsimp simp add: C_def avg_def)
huffman@36795
   965
    apply (simp add: add_divide_distrib [symmetric])
huffman@36795
   966
    apply (rule AB [THEN less_imp_le])
huffman@36795
   967
    apply simp
huffman@36795
   968
    done
huffman@36795
   969
  have cauchy_lemma:
huffman@36795
   970
    "\<And>X. \<forall>n. \<forall>i\<ge>n. A n \<le> X i \<and> X i \<le> B n \<Longrightarrow> cauchy X"
huffman@36795
   971
    apply (rule cauchyI)
huffman@36795
   972
    apply (drule twos [where y="b - a"])
huffman@36795
   973
    apply (erule exE)
huffman@36795
   974
    apply (rule_tac x=n in exI, clarify, rename_tac i j)
huffman@36795
   975
    apply (rule_tac y="B n - A n" in le_less_trans) defer
huffman@36795
   976
    apply (simp add: width)
huffman@36795
   977
    apply (drule_tac x=n in spec)
huffman@36795
   978
    apply (frule_tac x=i in spec, drule (1) mp)
huffman@36795
   979
    apply (frule_tac x=j in spec, drule (1) mp)
huffman@36795
   980
    apply (frule A_mono, drule B_mono)
huffman@36795
   981
    apply (frule A_mono, drule B_mono)
huffman@36795
   982
    apply arith
huffman@36795
   983
    done
huffman@36795
   984
  have "cauchy A"
huffman@36795
   985
    apply (rule cauchy_lemma [rule_format])
huffman@36795
   986
    apply (simp add: A_mono)
huffman@36795
   987
    apply (erule order_trans [OF less_imp_le [OF AB] B_mono])
huffman@36795
   988
    done
huffman@36795
   989
  have "cauchy B"
huffman@36795
   990
    apply (rule cauchy_lemma [rule_format])
huffman@36795
   991
    apply (simp add: B_mono)
huffman@36795
   992
    apply (erule order_trans [OF A_mono less_imp_le [OF AB]])
huffman@36795
   993
    done
huffman@36795
   994
  have 1: "\<forall>x\<in>S. x \<le> Real B"
huffman@36795
   995
  proof
huffman@36795
   996
    fix x assume "x \<in> S"
huffman@36795
   997
    then show "x \<le> Real B"
huffman@36795
   998
      using PB [unfolded P_def] `cauchy B`
huffman@36795
   999
      by (simp add: le_RealI)
huffman@36795
  1000
  qed
huffman@36795
  1001
  have 2: "\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> Real A \<le> z"
huffman@36795
  1002
    apply clarify
huffman@36795
  1003
    apply (erule contrapos_pp)
huffman@36795
  1004
    apply (simp add: not_le)
huffman@36795
  1005
    apply (drule less_RealD [OF `cauchy A`], clarify)
huffman@36795
  1006
    apply (subgoal_tac "\<not> P (A n)")
huffman@36795
  1007
    apply (simp add: P_def not_le, clarify)
huffman@36795
  1008
    apply (erule rev_bexI)
huffman@36795
  1009
    apply (erule (1) less_trans)
huffman@36795
  1010
    apply (simp add: PA)
huffman@36795
  1011
    done
huffman@36795
  1012
  have "vanishes (\<lambda>n. (b - a) / 2 ^ n)"
huffman@36795
  1013
  proof (rule vanishesI)
huffman@36795
  1014
    fix r :: rat assume "0 < r"
huffman@36795
  1015
    then obtain k where k: "\<bar>b - a\<bar> / 2 ^ k < r"
huffman@36795
  1016
      using twos by fast
huffman@36795
  1017
    have "\<forall>n\<ge>k. \<bar>(b - a) / 2 ^ n\<bar> < r"
huffman@36795
  1018
    proof (clarify)
huffman@36795
  1019
      fix n assume n: "k \<le> n"
huffman@36795
  1020
      have "\<bar>(b - a) / 2 ^ n\<bar> = \<bar>b - a\<bar> / 2 ^ n"
huffman@36795
  1021
        by simp
huffman@36795
  1022
      also have "\<dots> \<le> \<bar>b - a\<bar> / 2 ^ k"
huffman@36795
  1023
        using n by (simp add: divide_left_mono mult_pos_pos)
huffman@36795
  1024
      also note k
huffman@36795
  1025
      finally show "\<bar>(b - a) / 2 ^ n\<bar> < r" .
huffman@36795
  1026
    qed
huffman@36795
  1027
    thus "\<exists>k. \<forall>n\<ge>k. \<bar>(b - a) / 2 ^ n\<bar> < r" ..
huffman@36795
  1028
  qed
huffman@36795
  1029
  hence 3: "Real B = Real A"
huffman@36795
  1030
    by (simp add: eq_Real `cauchy A` `cauchy B` width)
huffman@36795
  1031
  show "\<exists>y. (\<forall>x\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> y \<le> z)"
huffman@36795
  1032
    using 1 2 3 by (rule_tac x="Real B" in exI, simp)
paulson@14484
  1033
qed
paulson@14365
  1034
huffman@36795
  1035
subsection {* Hiding implementation details *}
paulson@14365
  1036
huffman@36795
  1037
hide_const (open) vanishes cauchy positive Real real_case
paulson@14365
  1038
huffman@36795
  1039
declare Real_induct [induct del]
huffman@36795
  1040
declare Abs_real_induct [induct del]
huffman@36795
  1041
declare Abs_real_cases [cases del]
huffman@36795
  1042
paulson@14334
  1043
subsection{*More Lemmas*}
paulson@14334
  1044
huffman@36776
  1045
text {* BH: These lemmas should not be necessary; they should be
huffman@36776
  1046
covered by existing simp rules and simplification procedures. *}
huffman@36776
  1047
paulson@14334
  1048
lemma real_mult_left_cancel: "(c::real) \<noteq> 0 ==> (c*a=c*b) = (a=b)"
huffman@36776
  1049
by simp (* redundant with mult_cancel_left *)
paulson@14334
  1050
paulson@14334
  1051
lemma real_mult_right_cancel: "(c::real) \<noteq> 0 ==> (a*c=b*c) = (a=b)"
huffman@36776
  1052
by simp (* redundant with mult_cancel_right *)
paulson@14334
  1053
paulson@14334
  1054
lemma real_mult_less_iff1 [simp]: "(0::real) < z ==> (x*z < y*z) = (x < y)"
huffman@36776
  1055
by simp (* solved by linordered_ring_less_cancel_factor simproc *)
paulson@14334
  1056
paulson@14334
  1057
lemma real_mult_le_cancel_iff1 [simp]: "(0::real) < z ==> (x*z \<le> y*z) = (x\<le>y)"
huffman@36776
  1058
by simp (* solved by linordered_ring_le_cancel_factor simproc *)
paulson@14334
  1059
paulson@14334
  1060
lemma real_mult_le_cancel_iff2 [simp]: "(0::real) < z ==> (z*x \<le> z*y) = (x\<le>y)"
huffman@36776
  1061
by (rule mult_le_cancel_left_pos)
huffman@36776
  1062
(* BH: Why doesn't "simp" prove this one, like it does the last one? *)
paulson@14334
  1063
paulson@14334
  1064
haftmann@24198
  1065
subsection {* Embedding numbers into the Reals *}
haftmann@24198
  1066
haftmann@24198
  1067
abbreviation
haftmann@24198
  1068
  real_of_nat :: "nat \<Rightarrow> real"
haftmann@24198
  1069
where
haftmann@24198
  1070
  "real_of_nat \<equiv> of_nat"
haftmann@24198
  1071
haftmann@24198
  1072
abbreviation
haftmann@24198
  1073
  real_of_int :: "int \<Rightarrow> real"
haftmann@24198
  1074
where
haftmann@24198
  1075
  "real_of_int \<equiv> of_int"
haftmann@24198
  1076
haftmann@24198
  1077
abbreviation
haftmann@24198
  1078
  real_of_rat :: "rat \<Rightarrow> real"
haftmann@24198
  1079
where
haftmann@24198
  1080
  "real_of_rat \<equiv> of_rat"
haftmann@24198
  1081
haftmann@24198
  1082
consts
haftmann@24198
  1083
  (*overloaded constant for injecting other types into "real"*)
haftmann@24198
  1084
  real :: "'a => real"
paulson@14365
  1085
paulson@14378
  1086
defs (overloaded)
haftmann@31998
  1087
  real_of_nat_def [code_unfold]: "real == real_of_nat"
haftmann@31998
  1088
  real_of_int_def [code_unfold]: "real == real_of_int"
paulson@14365
  1089
wenzelm@40939
  1090
declare [[coercion_enabled]]
nipkow@40864
  1091
declare [[coercion "real::nat\<Rightarrow>real"]]
nipkow@40864
  1092
declare [[coercion "real::int\<Rightarrow>real"]]
nipkow@41022
  1093
declare [[coercion "int"]]
nipkow@40864
  1094
hoelzl@41024
  1095
declare [[coercion_map map]]
noschinl@42112
  1096
declare [[coercion_map "% f g h x. g (h (f x))"]]
hoelzl@41024
  1097
declare [[coercion_map "% f g (x,y) . (f x, g y)"]]
hoelzl@41024
  1098
avigad@16819
  1099
lemma real_eq_of_nat: "real = of_nat"
haftmann@24198
  1100
  unfolding real_of_nat_def ..
avigad@16819
  1101
avigad@16819
  1102
lemma real_eq_of_int: "real = of_int"
haftmann@24198
  1103
  unfolding real_of_int_def ..
avigad@16819
  1104
paulson@14365
  1105
lemma real_of_int_zero [simp]: "real (0::int) = 0"  
paulson@14378
  1106
by (simp add: real_of_int_def) 
paulson@14365
  1107
paulson@14365
  1108
lemma real_of_one [simp]: "real (1::int) = (1::real)"
paulson@14378
  1109
by (simp add: real_of_int_def) 
paulson@14334
  1110
avigad@16819
  1111
lemma real_of_int_add [simp]: "real(x + y) = real (x::int) + real y"
paulson@14378
  1112
by (simp add: real_of_int_def) 
paulson@14365
  1113
avigad@16819
  1114
lemma real_of_int_minus [simp]: "real(-x) = -real (x::int)"
paulson@14378
  1115
by (simp add: real_of_int_def) 
avigad@16819
  1116
avigad@16819
  1117
lemma real_of_int_diff [simp]: "real(x - y) = real (x::int) - real y"
avigad@16819
  1118
by (simp add: real_of_int_def) 
paulson@14365
  1119
avigad@16819
  1120
lemma real_of_int_mult [simp]: "real(x * y) = real (x::int) * real y"
paulson@14378
  1121
by (simp add: real_of_int_def) 
paulson@14334
  1122
huffman@35344
  1123
lemma real_of_int_power [simp]: "real (x ^ n) = real (x::int) ^ n"
huffman@35344
  1124
by (simp add: real_of_int_def of_int_power)
huffman@35344
  1125
huffman@35344
  1126
lemmas power_real_of_int = real_of_int_power [symmetric]
huffman@35344
  1127
avigad@16819
  1128
lemma real_of_int_setsum [simp]: "real ((SUM x:A. f x)::int) = (SUM x:A. real(f x))"
avigad@16819
  1129
  apply (subst real_eq_of_int)+
avigad@16819
  1130
  apply (rule of_int_setsum)
avigad@16819
  1131
done
avigad@16819
  1132
avigad@16819
  1133
lemma real_of_int_setprod [simp]: "real ((PROD x:A. f x)::int) = 
avigad@16819
  1134
    (PROD x:A. real(f x))"
avigad@16819
  1135
  apply (subst real_eq_of_int)+
avigad@16819
  1136
  apply (rule of_int_setprod)
avigad@16819
  1137
done
paulson@14365
  1138
chaieb@27668
  1139
lemma real_of_int_zero_cancel [simp, algebra, presburger]: "(real x = 0) = (x = (0::int))"
paulson@14378
  1140
by (simp add: real_of_int_def) 
paulson@14365
  1141
chaieb@27668
  1142
lemma real_of_int_inject [iff, algebra, presburger]: "(real (x::int) = real y) = (x = y)"
paulson@14378
  1143
by (simp add: real_of_int_def) 
paulson@14365
  1144
chaieb@27668
  1145
lemma real_of_int_less_iff [iff, presburger]: "(real (x::int) < real y) = (x < y)"
paulson@14378
  1146
by (simp add: real_of_int_def) 
paulson@14365
  1147
chaieb@27668
  1148
lemma real_of_int_le_iff [simp, presburger]: "(real (x::int) \<le> real y) = (x \<le> y)"
paulson@14378
  1149
by (simp add: real_of_int_def) 
paulson@14365
  1150
chaieb@27668
  1151
lemma real_of_int_gt_zero_cancel_iff [simp, presburger]: "(0 < real (n::int)) = (0 < n)"
avigad@16819
  1152
by (simp add: real_of_int_def) 
avigad@16819
  1153
chaieb@27668
  1154
lemma real_of_int_ge_zero_cancel_iff [simp, presburger]: "(0 <= real (n::int)) = (0 <= n)"
avigad@16819
  1155
by (simp add: real_of_int_def) 
avigad@16819
  1156
chaieb@27668
  1157
lemma real_of_int_lt_zero_cancel_iff [simp, presburger]: "(real (n::int) < 0) = (n < 0)" 
avigad@16819
  1158
by (simp add: real_of_int_def)
avigad@16819
  1159
chaieb@27668
  1160
lemma real_of_int_le_zero_cancel_iff [simp, presburger]: "(real (n::int) <= 0) = (n <= 0)"
avigad@16819
  1161
by (simp add: real_of_int_def)
avigad@16819
  1162
avigad@16888
  1163
lemma real_of_int_abs [simp]: "real (abs x) = abs(real (x::int))"
avigad@16888
  1164
by (auto simp add: abs_if)
avigad@16888
  1165
avigad@16819
  1166
lemma int_less_real_le: "((n::int) < m) = (real n + 1 <= real m)"
avigad@16819
  1167
  apply (subgoal_tac "real n + 1 = real (n + 1)")
avigad@16819
  1168
  apply (simp del: real_of_int_add)
avigad@16819
  1169
  apply auto
avigad@16819
  1170
done
avigad@16819
  1171
avigad@16819
  1172
lemma int_le_real_less: "((n::int) <= m) = (real n < real m + 1)"
avigad@16819
  1173
  apply (subgoal_tac "real m + 1 = real (m + 1)")
avigad@16819
  1174
  apply (simp del: real_of_int_add)
avigad@16819
  1175
  apply simp
avigad@16819
  1176
done
avigad@16819
  1177
bulwahn@46670
  1178
lemma real_of_int_div_aux: "(real (x::int)) / (real d) = 
avigad@16819
  1179
    real (x div d) + (real (x mod d)) / (real d)"
avigad@16819
  1180
proof -
avigad@16819
  1181
  have "x = (x div d) * d + x mod d"
avigad@16819
  1182
    by auto
avigad@16819
  1183
  then have "real x = real (x div d) * real d + real(x mod d)"
avigad@16819
  1184
    by (simp only: real_of_int_mult [THEN sym] real_of_int_add [THEN sym])
avigad@16819
  1185
  then have "real x / real d = ... / real d"
avigad@16819
  1186
    by simp
avigad@16819
  1187
  then show ?thesis
bulwahn@46670
  1188
    by (auto simp add: add_divide_distrib algebra_simps)
avigad@16819
  1189
qed
avigad@16819
  1190
bulwahn@46670
  1191
lemma real_of_int_div: "(d :: int) dvd n ==>
avigad@16819
  1192
    real(n div d) = real n / real d"
bulwahn@46670
  1193
  apply (subst real_of_int_div_aux)
avigad@16819
  1194
  apply simp
nipkow@30042
  1195
  apply (simp add: dvd_eq_mod_eq_0)
avigad@16819
  1196
done
avigad@16819
  1197
avigad@16819
  1198
lemma real_of_int_div2:
avigad@16819
  1199
  "0 <= real (n::int) / real (x) - real (n div x)"
avigad@16819
  1200
  apply (case_tac "x = 0")
avigad@16819
  1201
  apply simp
avigad@16819
  1202
  apply (case_tac "0 < x")
nipkow@29667
  1203
  apply (simp add: algebra_simps)
avigad@16819
  1204
  apply (subst real_of_int_div_aux)
avigad@16819
  1205
  apply simp
avigad@16819
  1206
  apply (subst zero_le_divide_iff)
avigad@16819
  1207
  apply auto
nipkow@29667
  1208
  apply (simp add: algebra_simps)
avigad@16819
  1209
  apply (subst real_of_int_div_aux)
avigad@16819
  1210
  apply simp
avigad@16819
  1211
  apply (subst zero_le_divide_iff)
avigad@16819
  1212
  apply auto
avigad@16819
  1213
done
avigad@16819
  1214
avigad@16819
  1215
lemma real_of_int_div3:
avigad@16819
  1216
  "real (n::int) / real (x) - real (n div x) <= 1"
nipkow@29667
  1217
  apply (simp add: algebra_simps)
avigad@16819
  1218
  apply (subst real_of_int_div_aux)
bulwahn@46670
  1219
  apply (auto simp add: divide_le_eq intro: order_less_imp_le)
avigad@16819
  1220
done
avigad@16819
  1221
avigad@16819
  1222
lemma real_of_int_div4: "real (n div x) <= real (n::int) / real x" 
nipkow@27964
  1223
by (insert real_of_int_div2 [of n x], simp)
nipkow@27964
  1224
huffman@35635
  1225
lemma Ints_real_of_int [simp]: "real (x::int) \<in> Ints"
huffman@35635
  1226
unfolding real_of_int_def by (rule Ints_of_int)
huffman@35635
  1227
nipkow@27964
  1228
paulson@14365
  1229
subsection{*Embedding the Naturals into the Reals*}
paulson@14365
  1230
paulson@14334
  1231
lemma real_of_nat_zero [simp]: "real (0::nat) = 0"
paulson@14365
  1232
by (simp add: real_of_nat_def)
paulson@14334
  1233
huffman@30082
  1234
lemma real_of_nat_1 [simp]: "real (1::nat) = 1"
huffman@30082
  1235
by (simp add: real_of_nat_def)
huffman@30082
  1236
paulson@14334
  1237
lemma real_of_nat_one [simp]: "real (Suc 0) = (1::real)"
paulson@14365
  1238
by (simp add: real_of_nat_def)
paulson@14334
  1239
paulson@14365
  1240
lemma real_of_nat_add [simp]: "real (m + n) = real (m::nat) + real n"
paulson@14378
  1241
by (simp add: real_of_nat_def)
paulson@14334
  1242
paulson@14334
  1243
(*Not for addsimps: often the LHS is used to represent a positive natural*)
paulson@14334
  1244
lemma real_of_nat_Suc: "real (Suc n) = real n + (1::real)"
paulson@14378
  1245
by (simp add: real_of_nat_def)
paulson@14334
  1246
paulson@14334
  1247
lemma real_of_nat_less_iff [iff]: 
paulson@14334
  1248
     "(real (n::nat) < real m) = (n < m)"
paulson@14365
  1249
by (simp add: real_of_nat_def)
paulson@14334
  1250
paulson@14334
  1251
lemma real_of_nat_le_iff [iff]: "(real (n::nat) \<le> real m) = (n \<le> m)"
paulson@14378
  1252
by (simp add: real_of_nat_def)
paulson@14334
  1253
paulson@14334
  1254
lemma real_of_nat_ge_zero [iff]: "0 \<le> real (n::nat)"
paulson@14378
  1255
by (simp add: real_of_nat_def zero_le_imp_of_nat)
paulson@14334
  1256
paulson@14365
  1257
lemma real_of_nat_Suc_gt_zero: "0 < real (Suc n)"
paulson@14378
  1258
by (simp add: real_of_nat_def del: of_nat_Suc)
paulson@14365
  1259
paulson@14334
  1260
lemma real_of_nat_mult [simp]: "real (m * n) = real (m::nat) * real n"
huffman@23431
  1261
by (simp add: real_of_nat_def of_nat_mult)
paulson@14334
  1262
huffman@35344
  1263
lemma real_of_nat_power [simp]: "real (m ^ n) = real (m::nat) ^ n"
huffman@35344
  1264
by (simp add: real_of_nat_def of_nat_power)
huffman@35344
  1265
huffman@35344
  1266
lemmas power_real_of_nat = real_of_nat_power [symmetric]
huffman@35344
  1267
avigad@16819
  1268
lemma real_of_nat_setsum [simp]: "real ((SUM x:A. f x)::nat) = 
avigad@16819
  1269
    (SUM x:A. real(f x))"
avigad@16819
  1270
  apply (subst real_eq_of_nat)+
avigad@16819
  1271
  apply (rule of_nat_setsum)
avigad@16819
  1272
done
avigad@16819
  1273
avigad@16819
  1274
lemma real_of_nat_setprod [simp]: "real ((PROD x:A. f x)::nat) = 
avigad@16819
  1275
    (PROD x:A. real(f x))"
avigad@16819
  1276
  apply (subst real_eq_of_nat)+
avigad@16819
  1277
  apply (rule of_nat_setprod)
avigad@16819
  1278
done
avigad@16819
  1279
avigad@16819
  1280
lemma real_of_card: "real (card A) = setsum (%x.1) A"
avigad@16819
  1281
  apply (subst card_eq_setsum)
avigad@16819
  1282
  apply (subst real_of_nat_setsum)
avigad@16819
  1283
  apply simp
avigad@16819
  1284
done
avigad@16819
  1285
paulson@14334
  1286
lemma real_of_nat_inject [iff]: "(real (n::nat) = real m) = (n = m)"
paulson@14378
  1287
by (simp add: real_of_nat_def)
paulson@14334
  1288
paulson@14387
  1289
lemma real_of_nat_zero_iff [iff]: "(real (n::nat) = 0) = (n = 0)"
paulson@14378
  1290
by (simp add: real_of_nat_def)
paulson@14334
  1291
paulson@14365
  1292
lemma real_of_nat_diff: "n \<le> m ==> real (m - n) = real (m::nat) - real n"
huffman@23438
  1293
by (simp add: add: real_of_nat_def of_nat_diff)
paulson@14334
  1294
nipkow@25162
  1295
lemma real_of_nat_gt_zero_cancel_iff [simp]: "(0 < real (n::nat)) = (0 < n)"
nipkow@25140
  1296
by (auto simp: real_of_nat_def)
paulson@14365
  1297
paulson@14365
  1298
lemma real_of_nat_le_zero_cancel_iff [simp]: "(real (n::nat) \<le> 0) = (n = 0)"
paulson@14378
  1299
by (simp add: add: real_of_nat_def)
paulson@14334
  1300
paulson@14365
  1301
lemma not_real_of_nat_less_zero [simp]: "~ real (n::nat) < 0"
paulson@14378
  1302
by (simp add: add: real_of_nat_def)
paulson@14334
  1303
avigad@16819
  1304
lemma nat_less_real_le: "((n::nat) < m) = (real n + 1 <= real m)"
avigad@16819
  1305
  apply (subgoal_tac "real n + 1 = real (Suc n)")
avigad@16819
  1306
  apply simp
avigad@16819
  1307
  apply (auto simp add: real_of_nat_Suc)
avigad@16819
  1308
done
avigad@16819
  1309
avigad@16819
  1310
lemma nat_le_real_less: "((n::nat) <= m) = (real n < real m + 1)"
avigad@16819
  1311
  apply (subgoal_tac "real m + 1 = real (Suc m)")
avigad@16819
  1312
  apply (simp add: less_Suc_eq_le)
avigad@16819
  1313
  apply (simp add: real_of_nat_Suc)
avigad@16819
  1314
done
avigad@16819
  1315
bulwahn@46670
  1316
lemma real_of_nat_div_aux: "(real (x::nat)) / (real d) = 
avigad@16819
  1317
    real (x div d) + (real (x mod d)) / (real d)"
avigad@16819
  1318
proof -
avigad@16819
  1319
  have "x = (x div d) * d + x mod d"
avigad@16819
  1320
    by auto
avigad@16819
  1321
  then have "real x = real (x div d) * real d + real(x mod d)"
avigad@16819
  1322
    by (simp only: real_of_nat_mult [THEN sym] real_of_nat_add [THEN sym])
avigad@16819
  1323
  then have "real x / real d = \<dots> / real d"
avigad@16819
  1324
    by simp
avigad@16819
  1325
  then show ?thesis
bulwahn@46670
  1326
    by (auto simp add: add_divide_distrib algebra_simps)
avigad@16819
  1327
qed
avigad@16819
  1328
bulwahn@46670
  1329
lemma real_of_nat_div: "(d :: nat) dvd n ==>
avigad@16819
  1330
    real(n div d) = real n / real d"
bulwahn@46670
  1331
  by (subst real_of_nat_div_aux)
bulwahn@46670
  1332
    (auto simp add: dvd_eq_mod_eq_0 [symmetric])
avigad@16819
  1333
avigad@16819
  1334
lemma real_of_nat_div2:
avigad@16819
  1335
  "0 <= real (n::nat) / real (x) - real (n div x)"
nipkow@29667
  1336
apply (simp add: algebra_simps)
nipkow@25134
  1337
apply (subst real_of_nat_div_aux)
nipkow@25134
  1338
apply simp
nipkow@25134
  1339
apply (subst zero_le_divide_iff)
nipkow@25134
  1340
apply simp
avigad@16819
  1341
done
avigad@16819
  1342
avigad@16819
  1343
lemma real_of_nat_div3:
avigad@16819
  1344
  "real (n::nat) / real (x) - real (n div x) <= 1"
nipkow@25134
  1345
apply(case_tac "x = 0")
nipkow@25134
  1346
apply (simp)
nipkow@29667
  1347
apply (simp add: algebra_simps)
nipkow@25134
  1348
apply (subst real_of_nat_div_aux)
nipkow@25134
  1349
apply simp
avigad@16819
  1350
done
avigad@16819
  1351
avigad@16819
  1352
lemma real_of_nat_div4: "real (n div x) <= real (n::nat) / real x" 
nipkow@29667
  1353
by (insert real_of_nat_div2 [of n x], simp)
avigad@16819
  1354
paulson@14426
  1355
lemma real_of_int_of_nat_eq [simp]: "real (of_nat n :: int) = real n"
paulson@14426
  1356
by (simp add: real_of_int_def real_of_nat_def)
paulson@14334
  1357
avigad@16819
  1358
lemma real_nat_eq_real [simp]: "0 <= x ==> real(nat x) = real x"
avigad@16819
  1359
  apply (subgoal_tac "real(int(nat x)) = real(nat x)")
avigad@16819
  1360
  apply force
huffman@44822
  1361
  apply (simp only: real_of_int_of_nat_eq)
avigad@16819
  1362
done
paulson@14387
  1363
huffman@35635
  1364
lemma Nats_real_of_nat [simp]: "real (n::nat) \<in> Nats"
huffman@35635
  1365
unfolding real_of_nat_def by (rule of_nat_in_Nats)
huffman@35635
  1366
huffman@35635
  1367
lemma Ints_real_of_nat [simp]: "real (n::nat) \<in> Ints"
huffman@35635
  1368
unfolding real_of_nat_def by (rule Ints_of_nat)
huffman@35635
  1369
nipkow@28001
  1370
nipkow@28001
  1371
subsection{* Rationals *}
nipkow@28001
  1372
nipkow@28091
  1373
lemma Rats_real_nat[simp]: "real(n::nat) \<in> \<rat>"
nipkow@28091
  1374
by (simp add: real_eq_of_nat)
nipkow@28091
  1375
nipkow@28091
  1376
nipkow@28001
  1377
lemma Rats_eq_int_div_int:
nipkow@28091
  1378
  "\<rat> = { real(i::int)/real(j::int) |i j. j \<noteq> 0}" (is "_ = ?S")
nipkow@28001
  1379
proof
nipkow@28091
  1380
  show "\<rat> \<subseteq> ?S"
nipkow@28001
  1381
  proof
nipkow@28091
  1382
    fix x::real assume "x : \<rat>"
nipkow@28001
  1383
    then obtain r where "x = of_rat r" unfolding Rats_def ..
nipkow@28001
  1384
    have "of_rat r : ?S"
nipkow@28001
  1385
      by (cases r)(auto simp add:of_rat_rat real_eq_of_int)
nipkow@28001
  1386
    thus "x : ?S" using `x = of_rat r` by simp
nipkow@28001
  1387
  qed
nipkow@28001
  1388
next
nipkow@28091
  1389
  show "?S \<subseteq> \<rat>"
nipkow@28001
  1390
  proof(auto simp:Rats_def)
nipkow@28001
  1391
    fix i j :: int assume "j \<noteq> 0"
nipkow@28001
  1392
    hence "real i / real j = of_rat(Fract i j)"
nipkow@28001
  1393
      by (simp add:of_rat_rat real_eq_of_int)
nipkow@28001
  1394
    thus "real i / real j \<in> range of_rat" by blast
nipkow@28001
  1395
  qed
nipkow@28001
  1396
qed
nipkow@28001
  1397
nipkow@28001
  1398
lemma Rats_eq_int_div_nat:
nipkow@28091
  1399
  "\<rat> = { real(i::int)/real(n::nat) |i n. n \<noteq> 0}"
nipkow@28001
  1400
proof(auto simp:Rats_eq_int_div_int)
nipkow@28001
  1401
  fix i j::int assume "j \<noteq> 0"
nipkow@28001
  1402
  show "EX (i'::int) (n::nat). real i/real j = real i'/real n \<and> 0<n"
nipkow@28001
  1403
  proof cases
nipkow@28001
  1404
    assume "j>0"
nipkow@28001
  1405
    hence "real i/real j = real i/real(nat j) \<and> 0<nat j"
nipkow@28001
  1406
      by (simp add: real_eq_of_int real_eq_of_nat of_nat_nat)
nipkow@28001
  1407
    thus ?thesis by blast
nipkow@28001
  1408
  next
nipkow@28001
  1409
    assume "~ j>0"
nipkow@28001
  1410
    hence "real i/real j = real(-i)/real(nat(-j)) \<and> 0<nat(-j)" using `j\<noteq>0`
nipkow@28001
  1411
      by (simp add: real_eq_of_int real_eq_of_nat of_nat_nat)
nipkow@28001
  1412
    thus ?thesis by blast
nipkow@28001
  1413
  qed
nipkow@28001
  1414
next
nipkow@28001
  1415
  fix i::int and n::nat assume "0 < n"
nipkow@28001
  1416
  hence "real i/real n = real i/real(int n) \<and> int n \<noteq> 0" by simp
nipkow@28001
  1417
  thus "\<exists>(i'::int) j::int. real i/real n = real i'/real j \<and> j \<noteq> 0" by blast
nipkow@28001
  1418
qed
nipkow@28001
  1419
nipkow@28001
  1420
lemma Rats_abs_nat_div_natE:
nipkow@28001
  1421
  assumes "x \<in> \<rat>"
huffman@31706
  1422
  obtains m n :: nat
huffman@31706
  1423
  where "n \<noteq> 0" and "\<bar>x\<bar> = real m / real n" and "gcd m n = 1"
nipkow@28001
  1424
proof -
nipkow@28001
  1425
  from `x \<in> \<rat>` obtain i::int and n::nat where "n \<noteq> 0" and "x = real i / real n"
nipkow@28001
  1426
    by(auto simp add: Rats_eq_int_div_nat)
nipkow@28001
  1427
  hence "\<bar>x\<bar> = real(nat(abs i)) / real n" by simp
nipkow@28001
  1428
  then obtain m :: nat where x_rat: "\<bar>x\<bar> = real m / real n" by blast
nipkow@28001
  1429
  let ?gcd = "gcd m n"
huffman@31706
  1430
  from `n\<noteq>0` have gcd: "?gcd \<noteq> 0" by simp
nipkow@28001
  1431
  let ?k = "m div ?gcd"
nipkow@28001
  1432
  let ?l = "n div ?gcd"
nipkow@28001
  1433
  let ?gcd' = "gcd ?k ?l"
nipkow@28001
  1434
  have "?gcd dvd m" .. then have gcd_k: "?gcd * ?k = m"
nipkow@28001
  1435
    by (rule dvd_mult_div_cancel)
nipkow@28001
  1436
  have "?gcd dvd n" .. then have gcd_l: "?gcd * ?l = n"
nipkow@28001
  1437
    by (rule dvd_mult_div_cancel)
nipkow@28001
  1438
  from `n\<noteq>0` and gcd_l have "?l \<noteq> 0" by (auto iff del: neq0_conv)
nipkow@28001
  1439
  moreover
nipkow@28001
  1440
  have "\<bar>x\<bar> = real ?k / real ?l"
nipkow@28001
  1441
  proof -
nipkow@28001
  1442
    from gcd have "real ?k / real ?l =
nipkow@28001
  1443
        real (?gcd * ?k) / real (?gcd * ?l)" by simp
nipkow@28001
  1444
    also from gcd_k and gcd_l have "\<dots> = real m / real n" by simp
nipkow@28001
  1445
    also from x_rat have "\<dots> = \<bar>x\<bar>" ..
nipkow@28001
  1446
    finally show ?thesis ..
nipkow@28001
  1447
  qed
nipkow@28001
  1448
  moreover
nipkow@28001
  1449
  have "?gcd' = 1"
nipkow@28001
  1450
  proof -
nipkow@28001
  1451
    have "?gcd * ?gcd' = gcd (?gcd * ?k) (?gcd * ?l)"
nipkow@31952
  1452
      by (rule gcd_mult_distrib_nat)
nipkow@28001
  1453
    with gcd_k gcd_l have "?gcd * ?gcd' = ?gcd" by simp
huffman@31706
  1454
    with gcd show ?thesis by auto
nipkow@28001
  1455
  qed
nipkow@28001
  1456
  ultimately show ?thesis ..
nipkow@28001
  1457
qed
nipkow@28001
  1458
nipkow@28001
  1459
paulson@14387
  1460
subsection{*Numerals and Arithmetic*}
paulson@14387
  1461
haftmann@46028
  1462
lemma [code_abbrev]:
huffman@47108
  1463
  "real_of_int (numeral k) = numeral k"
huffman@47108
  1464
  "real_of_int (neg_numeral k) = neg_numeral k"
huffman@47108
  1465
  by simp_all
paulson@14387
  1466
paulson@14387
  1467
text{*Collapse applications of @{term real} to @{term number_of}*}
huffman@47108
  1468
lemma real_numeral [simp]:
huffman@47108
  1469
  "real (numeral v :: int) = numeral v"
huffman@47108
  1470
  "real (neg_numeral v :: int) = neg_numeral v"
huffman@47108
  1471
by (simp_all add: real_of_int_def)
paulson@14387
  1472
huffman@47108
  1473
lemma real_of_nat_numeral [simp]:
huffman@47108
  1474
  "real (numeral v :: nat) = numeral v"
huffman@47108
  1475
by (simp add: real_of_nat_def)
paulson@14387
  1476
haftmann@31100
  1477
declaration {*
haftmann@31100
  1478
  K (Lin_Arith.add_inj_thms [@{thm real_of_nat_le_iff} RS iffD2, @{thm real_of_nat_inject} RS iffD2]
haftmann@31100
  1479
    (* not needed because x < (y::nat) can be rewritten as Suc x <= y: real_of_nat_less_iff RS iffD2 *)
haftmann@31100
  1480
  #> Lin_Arith.add_inj_thms [@{thm real_of_int_le_iff} RS iffD2, @{thm real_of_int_inject} RS iffD2]
haftmann@31100
  1481
    (* not needed because x < (y::int) can be rewritten as x + 1 <= y: real_of_int_less_iff RS iffD2 *)
haftmann@31100
  1482
  #> Lin_Arith.add_simps [@{thm real_of_nat_zero}, @{thm real_of_nat_Suc}, @{thm real_of_nat_add},
haftmann@31100
  1483
      @{thm real_of_nat_mult}, @{thm real_of_int_zero}, @{thm real_of_one},
haftmann@31100
  1484
      @{thm real_of_int_add}, @{thm real_of_int_minus}, @{thm real_of_int_diff},
haftmann@31100
  1485
      @{thm real_of_int_mult}, @{thm real_of_int_of_nat_eq},
huffman@47108
  1486
      @{thm real_of_nat_numeral}, @{thm real_numeral(1)}, @{thm real_numeral(2)}]
huffman@36795
  1487
  #> Lin_Arith.add_inj_const (@{const_name real}, @{typ "nat \<Rightarrow> real"})
huffman@36795
  1488
  #> Lin_Arith.add_inj_const (@{const_name real}, @{typ "int \<Rightarrow> real"}))
haftmann@31100
  1489
*}
paulson@14387
  1490
kleing@19023
  1491
paulson@14387
  1492
subsection{* Simprules combining x+y and 0: ARE THEY NEEDED?*}
paulson@14387
  1493
paulson@14387
  1494
lemma real_add_minus_iff [simp]: "(x + - a = (0::real)) = (x=a)" 
paulson@14387
  1495
by arith
paulson@14387
  1496
huffman@36839
  1497
text {* FIXME: redundant with @{text add_eq_0_iff} below *}
paulson@15085
  1498
lemma real_add_eq_0_iff: "(x+y = (0::real)) = (y = -x)"
paulson@14387
  1499
by auto
paulson@14387
  1500
paulson@15085
  1501
lemma real_add_less_0_iff: "(x+y < (0::real)) = (y < -x)"
paulson@14387
  1502
by auto
paulson@14387
  1503
paulson@15085
  1504
lemma real_0_less_add_iff: "((0::real) < x+y) = (-x < y)"
paulson@14387
  1505
by auto
paulson@14387
  1506
paulson@15085
  1507
lemma real_add_le_0_iff: "(x+y \<le> (0::real)) = (y \<le> -x)"
paulson@14387
  1508
by auto
paulson@14387
  1509
paulson@15085
  1510
lemma real_0_le_add_iff: "((0::real) \<le> x+y) = (-x \<le> y)"
paulson@14387
  1511
by auto
paulson@14387
  1512
huffman@36839
  1513
subsection {* Lemmas about powers *}
paulson@14387
  1514
huffman@36839
  1515
text {* FIXME: declare this in Rings.thy or not at all *}
huffman@36839
  1516
declare abs_mult_self [simp]
huffman@36839
  1517
huffman@36839
  1518
(* used by Import/HOL/real.imp *)
huffman@36839
  1519
lemma two_realpow_ge_one: "(1::real) \<le> 2 ^ n"
huffman@36839
  1520
by simp
huffman@36839
  1521
huffman@36839
  1522
lemma two_realpow_gt [simp]: "real (n::nat) < 2 ^ n"
huffman@36839
  1523
apply (induct "n")
huffman@36839
  1524
apply (auto simp add: real_of_nat_Suc)
huffman@36839
  1525
apply (subst mult_2)
huffman@36839
  1526
apply (erule add_less_le_mono)
huffman@36839
  1527
apply (rule two_realpow_ge_one)
huffman@36839
  1528
done
huffman@36839
  1529
huffman@36839
  1530
text {* TODO: no longer real-specific; rename and move elsewhere *}
huffman@36839
  1531
lemma realpow_Suc_le_self:
huffman@36839
  1532
  fixes r :: "'a::linordered_semidom"
huffman@36839
  1533
  shows "[| 0 \<le> r; r \<le> 1 |] ==> r ^ Suc n \<le> r"
huffman@36839
  1534
by (insert power_decreasing [of 1 "Suc n" r], simp)
huffman@36839
  1535
huffman@36839
  1536
text {* TODO: no longer real-specific; rename and move elsewhere *}
huffman@36839
  1537
lemma realpow_minus_mult:
huffman@36839
  1538
  fixes x :: "'a::monoid_mult"
huffman@36839
  1539
  shows "0 < n \<Longrightarrow> x ^ (n - 1) * x = x ^ n"
huffman@36839
  1540
by (simp add: power_commutes split add: nat_diff_split)
huffman@36839
  1541
huffman@36839
  1542
text {* FIXME: declare this [simp] for all types, or not at all *}
huffman@36839
  1543
lemma real_two_squares_add_zero_iff [simp]:
huffman@36839
  1544
  "(x * x + y * y = 0) = ((x::real) = 0 \<and> y = 0)"
huffman@36839
  1545
by (rule sum_squares_eq_zero_iff)
huffman@36839
  1546
huffman@36839
  1547
text {* FIXME: declare this [simp] for all types, or not at all *}
huffman@36839
  1548
lemma realpow_two_sum_zero_iff [simp]:
huffman@36839
  1549
     "(x ^ 2 + y ^ 2 = (0::real)) = (x = 0 & y = 0)"
huffman@36839
  1550
by (rule sum_power2_eq_zero_iff)
huffman@36839
  1551
huffman@36839
  1552
lemma real_minus_mult_self_le [simp]: "-(u * u) \<le> (x * (x::real))"
huffman@36839
  1553
by (rule_tac y = 0 in order_trans, auto)
huffman@36839
  1554
huffman@36839
  1555
lemma realpow_square_minus_le [simp]: "-(u ^ 2) \<le> (x::real) ^ 2"
huffman@36839
  1556
by (auto simp add: power2_eq_square)
huffman@36839
  1557
huffman@36839
  1558
huffman@36839
  1559
subsection{*Density of the Reals*}
paulson@14387
  1560
paulson@14387
  1561
lemma real_lbound_gt_zero:
paulson@14387
  1562
     "[| (0::real) < d1; 0 < d2 |] ==> \<exists>e. 0 < e & e < d1 & e < d2"
paulson@14387
  1563
apply (rule_tac x = " (min d1 d2) /2" in exI)
paulson@14387
  1564
apply (simp add: min_def)
paulson@14387
  1565
done
paulson@14387
  1566
paulson@14387
  1567
haftmann@35050
  1568
text{*Similar results are proved in @{text Fields}*}
paulson@14387
  1569
lemma real_less_half_sum: "x < y ==> x < (x+y) / (2::real)"
paulson@14387
  1570
  by auto
paulson@14387
  1571
paulson@14387
  1572
lemma real_gt_half_sum: "x < y ==> (x+y)/(2::real) < y"
paulson@14387
  1573
  by auto
paulson@14387
  1574
paulson@14387
  1575
paulson@14387
  1576
subsection{*Absolute Value Function for the Reals*}
paulson@14387
  1577
paulson@14387
  1578
lemma abs_minus_add_cancel: "abs(x + (-y)) = abs (y + (-(x::real)))"
paulson@15003
  1579
by (simp add: abs_if)
paulson@14387
  1580
huffman@23289
  1581
(* FIXME: redundant, but used by Integration/RealRandVar.thy in AFP *)
paulson@14387
  1582
lemma abs_le_interval_iff: "(abs x \<le> r) = (-r\<le>x & x\<le>(r::real))"
haftmann@35050
  1583
by (force simp add: abs_le_iff)
paulson@14387
  1584
huffman@44344
  1585
lemma abs_add_one_gt_zero: "(0::real) < 1 + abs(x)"
paulson@15003
  1586
by (simp add: abs_if)
paulson@14387
  1587
paulson@14387
  1588
lemma abs_real_of_nat_cancel [simp]: "abs (real x) = real (x::nat)"
huffman@22958
  1589
by (rule abs_of_nonneg [OF real_of_nat_ge_zero])
paulson@14387
  1590
huffman@44344
  1591
lemma abs_add_one_not_less_self: "~ abs(x) + (1::real) < x"
webertj@20217
  1592
by simp
paulson@14387
  1593
 
paulson@14387
  1594
lemma abs_sum_triangle_ineq: "abs ((x::real) + y + (-l + -m)) \<le> abs(x + -l) + abs(y + -m)"
webertj@20217
  1595
by simp
paulson@14387
  1596
berghofe@24534
  1597
haftmann@27544
  1598
subsection {* Implementation of rational real numbers *}
berghofe@24534
  1599
huffman@47108
  1600
text {* Formal constructor *}
huffman@47108
  1601
haftmann@27544
  1602
definition Ratreal :: "rat \<Rightarrow> real" where
huffman@47108
  1603
  [code_abbrev, simp]: "Ratreal = of_rat"
berghofe@24534
  1604
haftmann@24623
  1605
code_datatype Ratreal
berghofe@24534
  1606
huffman@47108
  1607
huffman@47108
  1608
text {* Numerals *}
huffman@47108
  1609
huffman@47108
  1610
lemma [code_abbrev]:
huffman@47108
  1611
  "(of_rat (of_int a) :: real) = of_int a"
huffman@47108
  1612
  by simp
huffman@47108
  1613
huffman@47108
  1614
lemma [code_abbrev]:
huffman@47108
  1615
  "(of_rat 0 :: real) = 0"
huffman@47108
  1616
  by simp
huffman@47108
  1617
huffman@47108
  1618
lemma [code_abbrev]:
huffman@47108
  1619
  "(of_rat 1 :: real) = 1"
huffman@47108
  1620
  by simp
huffman@47108
  1621
huffman@47108
  1622
lemma [code_abbrev]:
huffman@47108
  1623
  "(of_rat (numeral k) :: real) = numeral k"
huffman@47108
  1624
  by simp
berghofe@24534
  1625
huffman@47108
  1626
lemma [code_abbrev]:
huffman@47108
  1627
  "(of_rat (neg_numeral k) :: real) = neg_numeral k"
huffman@47108
  1628
  by simp
huffman@47108
  1629
huffman@47108
  1630
lemma [code_post]:
huffman@47108
  1631
  "(of_rat (0 / r)  :: real) = 0"
huffman@47108
  1632
  "(of_rat (r / 0)  :: real) = 0"
huffman@47108
  1633
  "(of_rat (1 / 1)  :: real) = 1"
huffman@47108
  1634
  "(of_rat (numeral k / 1) :: real) = numeral k"
huffman@47108
  1635
  "(of_rat (neg_numeral k / 1) :: real) = neg_numeral k"
huffman@47108
  1636
  "(of_rat (1 / numeral k) :: real) = 1 / numeral k"
huffman@47108
  1637
  "(of_rat (1 / neg_numeral k) :: real) = 1 / neg_numeral k"
huffman@47108
  1638
  "(of_rat (numeral k / numeral l)  :: real) = numeral k / numeral l"
huffman@47108
  1639
  "(of_rat (numeral k / neg_numeral l)  :: real) = numeral k / neg_numeral l"
huffman@47108
  1640
  "(of_rat (neg_numeral k / numeral l)  :: real) = neg_numeral k / numeral l"
huffman@47108
  1641
  "(of_rat (neg_numeral k / neg_numeral l)  :: real) = neg_numeral k / neg_numeral l"
huffman@47108
  1642
  by (simp_all add: of_rat_divide)
huffman@47108
  1643
huffman@47108
  1644
huffman@47108
  1645
text {* Operations *}
huffman@47108
  1646
huffman@47108
  1647
lemma zero_real_code [code]:
haftmann@27544
  1648
  "0 = Ratreal 0"
haftmann@27544
  1649
by simp
berghofe@24534
  1650
huffman@47108
  1651
lemma one_real_code [code]:
haftmann@27544
  1652
  "1 = Ratreal 1"
haftmann@27544
  1653
by simp
haftmann@27544
  1654
haftmann@38857
  1655
instantiation real :: equal
haftmann@26513
  1656
begin
haftmann@26513
  1657
haftmann@38857
  1658
definition "HOL.equal (x\<Colon>real) y \<longleftrightarrow> x - y = 0"
haftmann@26513
  1659
haftmann@38857
  1660
instance proof
haftmann@38857
  1661
qed (simp add: equal_real_def)
berghofe@24534
  1662
haftmann@38857
  1663
lemma real_equal_code [code]:
haftmann@38857
  1664
  "HOL.equal (Ratreal x) (Ratreal y) \<longleftrightarrow> HOL.equal x y"
haftmann@38857
  1665
  by (simp add: equal_real_def equal)
haftmann@26513
  1666
haftmann@38857
  1667
lemma [code nbe]:
haftmann@38857
  1668
  "HOL.equal (x::real) x \<longleftrightarrow> True"
haftmann@38857
  1669
  by (rule equal_refl)
haftmann@28351
  1670
haftmann@26513
  1671
end
berghofe@24534
  1672
haftmann@27544
  1673
lemma real_less_eq_code [code]: "Ratreal x \<le> Ratreal y \<longleftrightarrow> x \<le> y"
haftmann@27652
  1674
  by (simp add: of_rat_less_eq)
berghofe@24534
  1675
haftmann@27544
  1676
lemma real_less_code [code]: "Ratreal x < Ratreal y \<longleftrightarrow> x < y"
haftmann@27652
  1677
  by (simp add: of_rat_less)
berghofe@24534
  1678
haftmann@27544
  1679
lemma real_plus_code [code]: "Ratreal x + Ratreal y = Ratreal (x + y)"
haftmann@27544
  1680
  by (simp add: of_rat_add)
berghofe@24534
  1681
haftmann@27544
  1682
lemma real_times_code [code]: "Ratreal x * Ratreal y = Ratreal (x * y)"
haftmann@27544
  1683
  by (simp add: of_rat_mult)
haftmann@27544
  1684
haftmann@27544
  1685
lemma real_uminus_code [code]: "- Ratreal x = Ratreal (- x)"
haftmann@27544
  1686
  by (simp add: of_rat_minus)
berghofe@24534
  1687
haftmann@27544
  1688
lemma real_minus_code [code]: "Ratreal x - Ratreal y = Ratreal (x - y)"
haftmann@27544
  1689
  by (simp add: of_rat_diff)
berghofe@24534
  1690
haftmann@27544
  1691
lemma real_inverse_code [code]: "inverse (Ratreal x) = Ratreal (inverse x)"
haftmann@27544
  1692
  by (simp add: of_rat_inverse)
haftmann@27544
  1693
 
haftmann@27544
  1694
lemma real_divide_code [code]: "Ratreal x / Ratreal y = Ratreal (x / y)"
haftmann@27544
  1695
  by (simp add: of_rat_divide)
berghofe@24534
  1696
bulwahn@43733
  1697
lemma real_floor_code [code]: "floor (Ratreal x) = floor x"
bulwahn@43733
  1698
  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)
bulwahn@43733
  1699
huffman@47108
  1700
huffman@47108
  1701
text {* Quickcheck *}
huffman@47108
  1702
haftmann@31203
  1703
definition (in term_syntax)
haftmann@32657
  1704
  valterm_ratreal :: "rat \<times> (unit \<Rightarrow> Code_Evaluation.term) \<Rightarrow> real \<times> (unit \<Rightarrow> Code_Evaluation.term)" where
haftmann@32657
  1705
  [code_unfold]: "valterm_ratreal k = Code_Evaluation.valtermify Ratreal {\<cdot>} k"
haftmann@31203
  1706
haftmann@37751
  1707
notation fcomp (infixl "\<circ>>" 60)
haftmann@37751
  1708
notation scomp (infixl "\<circ>\<rightarrow>" 60)
haftmann@31203
  1709
haftmann@31203
  1710
instantiation real :: random
haftmann@31203
  1711
begin
haftmann@31203
  1712
haftmann@31203
  1713
definition
haftmann@37751
  1714
  "Quickcheck.random i = Quickcheck.random i \<circ>\<rightarrow> (\<lambda>r. Pair (valterm_ratreal r))"
haftmann@31203
  1715
haftmann@31203
  1716
instance ..
haftmann@31203
  1717
haftmann@31203
  1718
end
haftmann@31203
  1719
haftmann@37751
  1720
no_notation fcomp (infixl "\<circ>>" 60)
haftmann@37751
  1721
no_notation scomp (infixl "\<circ>\<rightarrow>" 60)
haftmann@31203
  1722
bulwahn@41920
  1723
instantiation real :: exhaustive
bulwahn@41231
  1724
begin
bulwahn@41231
  1725
bulwahn@41231
  1726
definition
bulwahn@45818
  1727
  "exhaustive_real f d = Quickcheck_Exhaustive.exhaustive (%r. f (Ratreal r)) d"
bulwahn@42311
  1728
bulwahn@42311
  1729
instance ..
bulwahn@42311
  1730
bulwahn@42311
  1731
end
bulwahn@42311
  1732
bulwahn@42311
  1733
instantiation real :: full_exhaustive
bulwahn@42311
  1734
begin
bulwahn@42311
  1735
bulwahn@42311
  1736
definition
bulwahn@45818
  1737
  "full_exhaustive_real f d = Quickcheck_Exhaustive.full_exhaustive (%r. f (valterm_ratreal r)) d"
bulwahn@41231
  1738
bulwahn@41231
  1739
instance ..
bulwahn@41231
  1740
bulwahn@41231
  1741
end
bulwahn@41231
  1742
bulwahn@43887
  1743
instantiation real :: narrowing
bulwahn@43887
  1744
begin
bulwahn@43887
  1745
bulwahn@43887
  1746
definition
bulwahn@43887
  1747
  "narrowing = Quickcheck_Narrowing.apply (Quickcheck_Narrowing.cons Ratreal) narrowing"
bulwahn@43887
  1748
bulwahn@43887
  1749
instance ..
bulwahn@43887
  1750
bulwahn@43887
  1751
end
bulwahn@43887
  1752
bulwahn@43887
  1753
bulwahn@45184
  1754
subsection {* Setup for Nitpick *}
berghofe@24534
  1755
blanchet@38287
  1756
declaration {*
blanchet@38287
  1757
  Nitpick_HOL.register_frac_type @{type_name real}
wenzelm@33209
  1758
   [(@{const_name zero_real_inst.zero_real}, @{const_name Nitpick.zero_frac}),
wenzelm@33209
  1759
    (@{const_name one_real_inst.one_real}, @{const_name Nitpick.one_frac}),
wenzelm@33209
  1760
    (@{const_name plus_real_inst.plus_real}, @{const_name Nitpick.plus_frac}),
wenzelm@33209
  1761
    (@{const_name times_real_inst.times_real}, @{const_name Nitpick.times_frac}),
wenzelm@33209
  1762
    (@{const_name uminus_real_inst.uminus_real}, @{const_name Nitpick.uminus_frac}),
wenzelm@33209
  1763
    (@{const_name inverse_real_inst.inverse_real}, @{const_name Nitpick.inverse_frac}),
blanchet@45859
  1764
    (@{const_name ord_real_inst.less_real}, @{const_name Nitpick.less_frac}),
wenzelm@33209
  1765
    (@{const_name ord_real_inst.less_eq_real}, @{const_name Nitpick.less_eq_frac})]
blanchet@33197
  1766
*}
blanchet@33197
  1767
huffman@47108
  1768
lemmas [nitpick_unfold] = inverse_real_inst.inverse_real one_real_inst.one_real
blanchet@37397
  1769
    ord_real_inst.less_real ord_real_inst.less_eq_real plus_real_inst.plus_real
blanchet@33197
  1770
    times_real_inst.times_real uminus_real_inst.uminus_real
blanchet@33197
  1771
    zero_real_inst.zero_real
blanchet@33197
  1772
paulson@5588
  1773
end