src/HOL/RealDef.thy
author kuncar
Fri Dec 09 18:07:04 2011 +0100 (2011-12-09)
changeset 45802 b16f976db515
parent 45184 426dbd896c9e
child 45818 53a697f5454a
permissions -rw-r--r--
Quotient_Info stores only relation maps
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@36795
   723
    unfolding less_eq_real_def less_real_def by auto
huffman@36795
   724
  show "sgn a = (if a = 0 then 0 else if 0 < a then 1 else - 1)"
huffman@36795
   725
    by (rule sgn_real_def)
huffman@36795
   726
  show "a \<le> b \<or> b \<le> a"
huffman@36795
   727
    unfolding less_eq_real_def less_real_def
huffman@36795
   728
    by (auto dest!: positive_minus)
huffman@36795
   729
  show "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
huffman@36795
   730
    unfolding less_real_def
huffman@36795
   731
    by (drule (1) positive_mult, simp add: algebra_simps)
huffman@23288
   732
qed
paulson@14378
   733
huffman@36795
   734
end
paulson@14334
   735
haftmann@25571
   736
instantiation real :: distrib_lattice
haftmann@25571
   737
begin
haftmann@25571
   738
haftmann@25571
   739
definition
huffman@36795
   740
  "(inf :: real \<Rightarrow> real \<Rightarrow> real) = min"
haftmann@25571
   741
haftmann@25571
   742
definition
huffman@36795
   743
  "(sup :: real \<Rightarrow> real \<Rightarrow> real) = max"
huffman@36795
   744
huffman@36795
   745
instance proof
huffman@36795
   746
qed (auto simp add: inf_real_def sup_real_def min_max.sup_inf_distrib1)
huffman@36795
   747
huffman@36795
   748
end
haftmann@25571
   749
huffman@36795
   750
instantiation real :: number_ring
huffman@36795
   751
begin
huffman@36795
   752
huffman@36795
   753
definition
haftmann@37767
   754
  "(number_of x :: real) = of_int x"
huffman@36795
   755
huffman@36795
   756
instance proof
huffman@36795
   757
qed (rule number_of_real_def)
haftmann@22456
   758
haftmann@25571
   759
end
haftmann@25571
   760
huffman@36795
   761
lemma of_nat_Real: "of_nat x = Real (\<lambda>n. of_nat x)"
huffman@36795
   762
apply (induct x)
huffman@36795
   763
apply (simp add: zero_real_def)
huffman@36795
   764
apply (simp add: one_real_def add_Real)
huffman@36795
   765
done
paulson@14378
   766
huffman@36795
   767
lemma of_int_Real: "of_int x = Real (\<lambda>n. of_int x)"
huffman@36795
   768
apply (cases x rule: int_diff_cases)
huffman@36795
   769
apply (simp add: of_nat_Real diff_Real)
huffman@36795
   770
done
paulson@14334
   771
huffman@36795
   772
lemma of_rat_Real: "of_rat x = Real (\<lambda>n. x)"
huffman@36795
   773
apply (induct x)
huffman@36795
   774
apply (simp add: Fract_of_int_quotient of_rat_divide)
huffman@36795
   775
apply (simp add: of_int_Real divide_inverse)
huffman@36795
   776
apply (simp add: inverse_Real mult_Real)
huffman@36795
   777
done
huffman@36795
   778
huffman@36795
   779
instance real :: archimedean_field
paulson@14334
   780
proof
huffman@36795
   781
  fix x :: real
huffman@36795
   782
  show "\<exists>z. x \<le> of_int z"
huffman@36795
   783
    apply (induct x)
huffman@36795
   784
    apply (frule cauchy_imp_bounded, clarify)
huffman@36795
   785
    apply (rule_tac x="ceiling b + 1" in exI)
huffman@36795
   786
    apply (rule less_imp_le)
huffman@36795
   787
    apply (simp add: of_int_Real less_real_def diff_Real positive_Real)
huffman@36795
   788
    apply (rule_tac x=1 in exI, simp add: algebra_simps)
huffman@36795
   789
    apply (rule_tac x=0 in exI, clarsimp)
huffman@36795
   790
    apply (rule le_less_trans [OF abs_ge_self])
huffman@36795
   791
    apply (rule less_le_trans [OF _ le_of_int_ceiling])
huffman@36795
   792
    apply simp
huffman@36795
   793
    done
paulson@14334
   794
qed
paulson@14334
   795
bulwahn@43732
   796
instantiation real :: floor_ceiling
bulwahn@43732
   797
begin
bulwahn@43732
   798
bulwahn@43732
   799
definition [code del]:
bulwahn@43732
   800
  "floor (x::real) = (THE z. of_int z \<le> x \<and> x < of_int (z + 1))"
bulwahn@43732
   801
bulwahn@43732
   802
instance proof
bulwahn@43732
   803
  fix x :: real
bulwahn@43732
   804
  show "of_int (floor x) \<le> x \<and> x < of_int (floor x + 1)"
bulwahn@43732
   805
    unfolding floor_real_def using floor_exists1 by (rule theI')
bulwahn@43732
   806
qed
bulwahn@43732
   807
bulwahn@43732
   808
end
bulwahn@43732
   809
huffman@36795
   810
subsection {* Completeness *}
paulson@14365
   811
huffman@36795
   812
lemma not_positive_Real:
huffman@36795
   813
  assumes X: "cauchy X"
huffman@36795
   814
  shows "\<not> positive (Real X) \<longleftrightarrow> (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. X n \<le> r)"
huffman@36795
   815
unfolding positive_Real [OF X]
huffman@36795
   816
apply (auto, unfold not_less)
huffman@36795
   817
apply (erule obtain_pos_sum)
huffman@36795
   818
apply (drule_tac x=s in spec, simp)
huffman@36795
   819
apply (drule_tac r=t in cauchyD [OF X], clarify)
huffman@36795
   820
apply (drule_tac x=k in spec, clarsimp)
huffman@36795
   821
apply (rule_tac x=n in exI, clarify, rename_tac m)
huffman@36795
   822
apply (drule_tac x=m in spec, simp)
huffman@36795
   823
apply (drule_tac x=n in spec, simp)
huffman@36795
   824
apply (drule spec, drule (1) mp, clarify, rename_tac i)
huffman@36795
   825
apply (rule_tac x="max i k" in exI, simp)
huffman@36795
   826
done
huffman@36795
   827
huffman@36795
   828
lemma le_Real:
huffman@36795
   829
  assumes X: "cauchy X" and Y: "cauchy Y"
huffman@36795
   830
  shows "Real X \<le> Real Y = (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. X n \<le> Y n + r)"
huffman@36795
   831
unfolding not_less [symmetric, where 'a=real] less_real_def
huffman@36795
   832
apply (simp add: diff_Real not_positive_Real X Y)
huffman@36795
   833
apply (simp add: diff_le_eq add_ac)
huffman@36795
   834
done
paulson@14365
   835
huffman@36795
   836
lemma le_RealI:
huffman@36795
   837
  assumes Y: "cauchy Y"
huffman@36795
   838
  shows "\<forall>n. x \<le> of_rat (Y n) \<Longrightarrow> x \<le> Real Y"
huffman@36795
   839
proof (induct x)
huffman@36795
   840
  fix X assume X: "cauchy X" and "\<forall>n. Real X \<le> of_rat (Y n)"
huffman@36795
   841
  hence le: "\<And>m r. 0 < r \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. X n \<le> Y m + r"
huffman@36795
   842
    by (simp add: of_rat_Real le_Real)
huffman@36795
   843
  {
huffman@36795
   844
    fix r :: rat assume "0 < r"
huffman@36795
   845
    then obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
huffman@36795
   846
      by (rule obtain_pos_sum)
huffman@36795
   847
    obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>Y m - Y n\<bar> < s"
huffman@36795
   848
      using cauchyD [OF Y s] ..
huffman@36795
   849
    obtain j where j: "\<forall>n\<ge>j. X n \<le> Y i + t"
huffman@36795
   850
      using le [OF t] ..
huffman@36795
   851
    have "\<forall>n\<ge>max i j. X n \<le> Y n + r"
huffman@36795
   852
    proof (clarsimp)
huffman@36795
   853
      fix n assume n: "i \<le> n" "j \<le> n"
huffman@36795
   854
      have "X n \<le> Y i + t" using n j by simp
huffman@36795
   855
      moreover have "\<bar>Y i - Y n\<bar> < s" using n i by simp
huffman@36795
   856
      ultimately show "X n \<le> Y n + r" unfolding r by simp
huffman@36795
   857
    qed
huffman@36795
   858
    hence "\<exists>k. \<forall>n\<ge>k. X n \<le> Y n + r" ..
huffman@36795
   859
  }
huffman@36795
   860
  thus "Real X \<le> Real Y"
huffman@36795
   861
    by (simp add: of_rat_Real le_Real X Y)
huffman@36795
   862
qed
paulson@14365
   863
huffman@36795
   864
lemma Real_leI:
huffman@36795
   865
  assumes X: "cauchy X"
huffman@36795
   866
  assumes le: "\<forall>n. of_rat (X n) \<le> y"
huffman@36795
   867
  shows "Real X \<le> y"
huffman@36795
   868
proof -
huffman@36795
   869
  have "- y \<le> - Real X"
huffman@36795
   870
    by (simp add: minus_Real X le_RealI of_rat_minus le)
huffman@36795
   871
  thus ?thesis by simp
huffman@36795
   872
qed
huffman@36795
   873
huffman@36795
   874
lemma less_RealD:
huffman@36795
   875
  assumes Y: "cauchy Y"
huffman@36795
   876
  shows "x < Real Y \<Longrightarrow> \<exists>n. x < of_rat (Y n)"
huffman@36795
   877
by (erule contrapos_pp, simp add: not_less, erule Real_leI [OF Y])
huffman@36795
   878
huffman@36795
   879
lemma of_nat_less_two_power:
huffman@36795
   880
  "of_nat n < (2::'a::{linordered_idom,number_ring}) ^ n"
huffman@36795
   881
apply (induct n)
huffman@36795
   882
apply simp
huffman@36795
   883
apply (subgoal_tac "(1::'a) \<le> 2 ^ n")
huffman@36795
   884
apply (drule (1) add_le_less_mono, simp)
huffman@36795
   885
apply simp
paulson@14365
   886
done
paulson@14365
   887
huffman@36795
   888
lemma complete_real:
huffman@36795
   889
  fixes S :: "real set"
huffman@36795
   890
  assumes "\<exists>x. x \<in> S" and "\<exists>z. \<forall>x\<in>S. x \<le> z"
huffman@36795
   891
  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
   892
proof -
huffman@36795
   893
  obtain x where x: "x \<in> S" using assms(1) ..
huffman@36795
   894
  obtain z where z: "\<forall>x\<in>S. x \<le> z" using assms(2) ..
paulson@14365
   895
huffman@36795
   896
  def P \<equiv> "\<lambda>x. \<forall>y\<in>S. y \<le> of_rat x"
huffman@36795
   897
  obtain a where a: "\<not> P a"
huffman@36795
   898
  proof
huffman@36795
   899
    have "of_int (floor (x - 1)) \<le> x - 1" by (rule of_int_floor_le)
huffman@36795
   900
    also have "x - 1 < x" by simp
huffman@36795
   901
    finally have "of_int (floor (x - 1)) < x" .
huffman@36795
   902
    hence "\<not> x \<le> of_int (floor (x - 1))" by (simp only: not_le)
huffman@36795
   903
    then show "\<not> P (of_int (floor (x - 1)))"
huffman@36795
   904
      unfolding P_def of_rat_of_int_eq using x by fast
huffman@36795
   905
  qed
huffman@36795
   906
  obtain b where b: "P b"
huffman@36795
   907
  proof
huffman@36795
   908
    show "P (of_int (ceiling z))"
huffman@36795
   909
    unfolding P_def of_rat_of_int_eq
huffman@36795
   910
    proof
huffman@36795
   911
      fix y assume "y \<in> S"
huffman@36795
   912
      hence "y \<le> z" using z by simp
huffman@36795
   913
      also have "z \<le> of_int (ceiling z)" by (rule le_of_int_ceiling)
huffman@36795
   914
      finally show "y \<le> of_int (ceiling z)" .
huffman@36795
   915
    qed
huffman@36795
   916
  qed
paulson@14365
   917
huffman@36795
   918
  def avg \<equiv> "\<lambda>x y :: rat. x/2 + y/2"
huffman@36795
   919
  def bisect \<equiv> "\<lambda>(x, y). if P (avg x y) then (x, avg x y) else (avg x y, y)"
huffman@36795
   920
  def A \<equiv> "\<lambda>n. fst ((bisect ^^ n) (a, b))"
huffman@36795
   921
  def B \<equiv> "\<lambda>n. snd ((bisect ^^ n) (a, b))"
huffman@36795
   922
  def C \<equiv> "\<lambda>n. avg (A n) (B n)"
huffman@36795
   923
  have A_0 [simp]: "A 0 = a" unfolding A_def by simp
huffman@36795
   924
  have B_0 [simp]: "B 0 = b" unfolding B_def by simp
huffman@36795
   925
  have A_Suc [simp]: "\<And>n. A (Suc n) = (if P (C n) then A n else C n)"
huffman@36795
   926
    unfolding A_def B_def C_def bisect_def split_def by simp
huffman@36795
   927
  have B_Suc [simp]: "\<And>n. B (Suc n) = (if P (C n) then C n else B n)"
huffman@36795
   928
    unfolding A_def B_def C_def bisect_def split_def by simp
paulson@14365
   929
huffman@36795
   930
  have width: "\<And>n. B n - A n = (b - a) / 2^n"
huffman@36795
   931
    apply (simp add: eq_divide_eq)
huffman@36795
   932
    apply (induct_tac n, simp)
huffman@36795
   933
    apply (simp add: C_def avg_def algebra_simps)
huffman@36795
   934
    done
huffman@36795
   935
huffman@36795
   936
  have twos: "\<And>y r :: rat. 0 < r \<Longrightarrow> \<exists>n. y / 2 ^ n < r"
huffman@36795
   937
    apply (simp add: divide_less_eq)
huffman@36795
   938
    apply (subst mult_commute)
huffman@36795
   939
    apply (frule_tac y=y in ex_less_of_nat_mult)
huffman@36795
   940
    apply clarify
huffman@36795
   941
    apply (rule_tac x=n in exI)
huffman@36795
   942
    apply (erule less_trans)
huffman@36795
   943
    apply (rule mult_strict_right_mono)
huffman@36795
   944
    apply (rule le_less_trans [OF _ of_nat_less_two_power])
huffman@36795
   945
    apply simp
huffman@36795
   946
    apply assumption
huffman@36795
   947
    done
paulson@14365
   948
huffman@36795
   949
  have PA: "\<And>n. \<not> P (A n)"
huffman@36795
   950
    by (induct_tac n, simp_all add: a)
huffman@36795
   951
  have PB: "\<And>n. P (B n)"
huffman@36795
   952
    by (induct_tac n, simp_all add: b)
huffman@36795
   953
  have ab: "a < b"
huffman@36795
   954
    using a b unfolding P_def
huffman@36795
   955
    apply (clarsimp simp add: not_le)
huffman@36795
   956
    apply (drule (1) bspec)
huffman@36795
   957
    apply (drule (1) less_le_trans)
huffman@36795
   958
    apply (simp add: of_rat_less)
huffman@36795
   959
    done
huffman@36795
   960
  have AB: "\<And>n. A n < B n"
huffman@36795
   961
    by (induct_tac n, simp add: ab, simp add: C_def avg_def)
huffman@36795
   962
  have A_mono: "\<And>i j. i \<le> j \<Longrightarrow> A i \<le> A j"
huffman@36795
   963
    apply (auto simp add: le_less [where 'a=nat])
huffman@36795
   964
    apply (erule less_Suc_induct)
huffman@36795
   965
    apply (clarsimp simp add: C_def avg_def)
huffman@36795
   966
    apply (simp add: add_divide_distrib [symmetric])
huffman@36795
   967
    apply (rule AB [THEN less_imp_le])
huffman@36795
   968
    apply simp
huffman@36795
   969
    done
huffman@36795
   970
  have B_mono: "\<And>i j. i \<le> j \<Longrightarrow> B j \<le> B i"
huffman@36795
   971
    apply (auto simp add: le_less [where 'a=nat])
huffman@36795
   972
    apply (erule less_Suc_induct)
huffman@36795
   973
    apply (clarsimp simp add: C_def avg_def)
huffman@36795
   974
    apply (simp add: add_divide_distrib [symmetric])
huffman@36795
   975
    apply (rule AB [THEN less_imp_le])
huffman@36795
   976
    apply simp
huffman@36795
   977
    done
huffman@36795
   978
  have cauchy_lemma:
huffman@36795
   979
    "\<And>X. \<forall>n. \<forall>i\<ge>n. A n \<le> X i \<and> X i \<le> B n \<Longrightarrow> cauchy X"
huffman@36795
   980
    apply (rule cauchyI)
huffman@36795
   981
    apply (drule twos [where y="b - a"])
huffman@36795
   982
    apply (erule exE)
huffman@36795
   983
    apply (rule_tac x=n in exI, clarify, rename_tac i j)
huffman@36795
   984
    apply (rule_tac y="B n - A n" in le_less_trans) defer
huffman@36795
   985
    apply (simp add: width)
huffman@36795
   986
    apply (drule_tac x=n in spec)
huffman@36795
   987
    apply (frule_tac x=i in spec, drule (1) mp)
huffman@36795
   988
    apply (frule_tac x=j in spec, drule (1) mp)
huffman@36795
   989
    apply (frule A_mono, drule B_mono)
huffman@36795
   990
    apply (frule A_mono, drule B_mono)
huffman@36795
   991
    apply arith
huffman@36795
   992
    done
huffman@36795
   993
  have "cauchy A"
huffman@36795
   994
    apply (rule cauchy_lemma [rule_format])
huffman@36795
   995
    apply (simp add: A_mono)
huffman@36795
   996
    apply (erule order_trans [OF less_imp_le [OF AB] B_mono])
huffman@36795
   997
    done
huffman@36795
   998
  have "cauchy B"
huffman@36795
   999
    apply (rule cauchy_lemma [rule_format])
huffman@36795
  1000
    apply (simp add: B_mono)
huffman@36795
  1001
    apply (erule order_trans [OF A_mono less_imp_le [OF AB]])
huffman@36795
  1002
    done
huffman@36795
  1003
  have 1: "\<forall>x\<in>S. x \<le> Real B"
huffman@36795
  1004
  proof
huffman@36795
  1005
    fix x assume "x \<in> S"
huffman@36795
  1006
    then show "x \<le> Real B"
huffman@36795
  1007
      using PB [unfolded P_def] `cauchy B`
huffman@36795
  1008
      by (simp add: le_RealI)
huffman@36795
  1009
  qed
huffman@36795
  1010
  have 2: "\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> Real A \<le> z"
huffman@36795
  1011
    apply clarify
huffman@36795
  1012
    apply (erule contrapos_pp)
huffman@36795
  1013
    apply (simp add: not_le)
huffman@36795
  1014
    apply (drule less_RealD [OF `cauchy A`], clarify)
huffman@36795
  1015
    apply (subgoal_tac "\<not> P (A n)")
huffman@36795
  1016
    apply (simp add: P_def not_le, clarify)
huffman@36795
  1017
    apply (erule rev_bexI)
huffman@36795
  1018
    apply (erule (1) less_trans)
huffman@36795
  1019
    apply (simp add: PA)
huffman@36795
  1020
    done
huffman@36795
  1021
  have "vanishes (\<lambda>n. (b - a) / 2 ^ n)"
huffman@36795
  1022
  proof (rule vanishesI)
huffman@36795
  1023
    fix r :: rat assume "0 < r"
huffman@36795
  1024
    then obtain k where k: "\<bar>b - a\<bar> / 2 ^ k < r"
huffman@36795
  1025
      using twos by fast
huffman@36795
  1026
    have "\<forall>n\<ge>k. \<bar>(b - a) / 2 ^ n\<bar> < r"
huffman@36795
  1027
    proof (clarify)
huffman@36795
  1028
      fix n assume n: "k \<le> n"
huffman@36795
  1029
      have "\<bar>(b - a) / 2 ^ n\<bar> = \<bar>b - a\<bar> / 2 ^ n"
huffman@36795
  1030
        by simp
huffman@36795
  1031
      also have "\<dots> \<le> \<bar>b - a\<bar> / 2 ^ k"
huffman@36795
  1032
        using n by (simp add: divide_left_mono mult_pos_pos)
huffman@36795
  1033
      also note k
huffman@36795
  1034
      finally show "\<bar>(b - a) / 2 ^ n\<bar> < r" .
huffman@36795
  1035
    qed
huffman@36795
  1036
    thus "\<exists>k. \<forall>n\<ge>k. \<bar>(b - a) / 2 ^ n\<bar> < r" ..
huffman@36795
  1037
  qed
huffman@36795
  1038
  hence 3: "Real B = Real A"
huffman@36795
  1039
    by (simp add: eq_Real `cauchy A` `cauchy B` width)
huffman@36795
  1040
  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
  1041
    using 1 2 3 by (rule_tac x="Real B" in exI, simp)
paulson@14484
  1042
qed
paulson@14365
  1043
huffman@36795
  1044
subsection {* Hiding implementation details *}
paulson@14365
  1045
huffman@36795
  1046
hide_const (open) vanishes cauchy positive Real real_case
paulson@14365
  1047
huffman@36795
  1048
declare Real_induct [induct del]
huffman@36795
  1049
declare Abs_real_induct [induct del]
huffman@36795
  1050
declare Abs_real_cases [cases del]
huffman@36795
  1051
paulson@14334
  1052
subsection{*More Lemmas*}
paulson@14334
  1053
huffman@36776
  1054
text {* BH: These lemmas should not be necessary; they should be
huffman@36776
  1055
covered by existing simp rules and simplification procedures. *}
huffman@36776
  1056
paulson@14334
  1057
lemma real_mult_left_cancel: "(c::real) \<noteq> 0 ==> (c*a=c*b) = (a=b)"
huffman@36776
  1058
by simp (* redundant with mult_cancel_left *)
paulson@14334
  1059
paulson@14334
  1060
lemma real_mult_right_cancel: "(c::real) \<noteq> 0 ==> (a*c=b*c) = (a=b)"
huffman@36776
  1061
by simp (* redundant with mult_cancel_right *)
paulson@14334
  1062
paulson@14334
  1063
lemma real_mult_less_iff1 [simp]: "(0::real) < z ==> (x*z < y*z) = (x < y)"
huffman@36776
  1064
by simp (* solved by linordered_ring_less_cancel_factor simproc *)
paulson@14334
  1065
paulson@14334
  1066
lemma real_mult_le_cancel_iff1 [simp]: "(0::real) < z ==> (x*z \<le> y*z) = (x\<le>y)"
huffman@36776
  1067
by simp (* solved by linordered_ring_le_cancel_factor simproc *)
paulson@14334
  1068
paulson@14334
  1069
lemma real_mult_le_cancel_iff2 [simp]: "(0::real) < z ==> (z*x \<le> z*y) = (x\<le>y)"
huffman@36776
  1070
by (rule mult_le_cancel_left_pos)
huffman@36776
  1071
(* BH: Why doesn't "simp" prove this one, like it does the last one? *)
paulson@14334
  1072
paulson@14334
  1073
haftmann@24198
  1074
subsection {* Embedding numbers into the Reals *}
haftmann@24198
  1075
haftmann@24198
  1076
abbreviation
haftmann@24198
  1077
  real_of_nat :: "nat \<Rightarrow> real"
haftmann@24198
  1078
where
haftmann@24198
  1079
  "real_of_nat \<equiv> of_nat"
haftmann@24198
  1080
haftmann@24198
  1081
abbreviation
haftmann@24198
  1082
  real_of_int :: "int \<Rightarrow> real"
haftmann@24198
  1083
where
haftmann@24198
  1084
  "real_of_int \<equiv> of_int"
haftmann@24198
  1085
haftmann@24198
  1086
abbreviation
haftmann@24198
  1087
  real_of_rat :: "rat \<Rightarrow> real"
haftmann@24198
  1088
where
haftmann@24198
  1089
  "real_of_rat \<equiv> of_rat"
haftmann@24198
  1090
haftmann@24198
  1091
consts
haftmann@24198
  1092
  (*overloaded constant for injecting other types into "real"*)
haftmann@24198
  1093
  real :: "'a => real"
paulson@14365
  1094
paulson@14378
  1095
defs (overloaded)
haftmann@31998
  1096
  real_of_nat_def [code_unfold]: "real == real_of_nat"
haftmann@31998
  1097
  real_of_int_def [code_unfold]: "real == real_of_int"
paulson@14365
  1098
wenzelm@40939
  1099
declare [[coercion_enabled]]
nipkow@40864
  1100
declare [[coercion "real::nat\<Rightarrow>real"]]
nipkow@40864
  1101
declare [[coercion "real::int\<Rightarrow>real"]]
nipkow@41022
  1102
declare [[coercion "int"]]
nipkow@40864
  1103
hoelzl@41024
  1104
declare [[coercion_map map]]
noschinl@42112
  1105
declare [[coercion_map "% f g h x. g (h (f x))"]]
hoelzl@41024
  1106
declare [[coercion_map "% f g (x,y) . (f x, g y)"]]
hoelzl@41024
  1107
avigad@16819
  1108
lemma real_eq_of_nat: "real = of_nat"
haftmann@24198
  1109
  unfolding real_of_nat_def ..
avigad@16819
  1110
avigad@16819
  1111
lemma real_eq_of_int: "real = of_int"
haftmann@24198
  1112
  unfolding real_of_int_def ..
avigad@16819
  1113
paulson@14365
  1114
lemma real_of_int_zero [simp]: "real (0::int) = 0"  
paulson@14378
  1115
by (simp add: real_of_int_def) 
paulson@14365
  1116
paulson@14365
  1117
lemma real_of_one [simp]: "real (1::int) = (1::real)"
paulson@14378
  1118
by (simp add: real_of_int_def) 
paulson@14334
  1119
avigad@16819
  1120
lemma real_of_int_add [simp]: "real(x + y) = real (x::int) + real y"
paulson@14378
  1121
by (simp add: real_of_int_def) 
paulson@14365
  1122
avigad@16819
  1123
lemma real_of_int_minus [simp]: "real(-x) = -real (x::int)"
paulson@14378
  1124
by (simp add: real_of_int_def) 
avigad@16819
  1125
avigad@16819
  1126
lemma real_of_int_diff [simp]: "real(x - y) = real (x::int) - real y"
avigad@16819
  1127
by (simp add: real_of_int_def) 
paulson@14365
  1128
avigad@16819
  1129
lemma real_of_int_mult [simp]: "real(x * y) = real (x::int) * real y"
paulson@14378
  1130
by (simp add: real_of_int_def) 
paulson@14334
  1131
huffman@35344
  1132
lemma real_of_int_power [simp]: "real (x ^ n) = real (x::int) ^ n"
huffman@35344
  1133
by (simp add: real_of_int_def of_int_power)
huffman@35344
  1134
huffman@35344
  1135
lemmas power_real_of_int = real_of_int_power [symmetric]
huffman@35344
  1136
avigad@16819
  1137
lemma real_of_int_setsum [simp]: "real ((SUM x:A. f x)::int) = (SUM x:A. real(f x))"
avigad@16819
  1138
  apply (subst real_eq_of_int)+
avigad@16819
  1139
  apply (rule of_int_setsum)
avigad@16819
  1140
done
avigad@16819
  1141
avigad@16819
  1142
lemma real_of_int_setprod [simp]: "real ((PROD x:A. f x)::int) = 
avigad@16819
  1143
    (PROD x:A. real(f x))"
avigad@16819
  1144
  apply (subst real_eq_of_int)+
avigad@16819
  1145
  apply (rule of_int_setprod)
avigad@16819
  1146
done
paulson@14365
  1147
chaieb@27668
  1148
lemma real_of_int_zero_cancel [simp, algebra, presburger]: "(real x = 0) = (x = (0::int))"
paulson@14378
  1149
by (simp add: real_of_int_def) 
paulson@14365
  1150
chaieb@27668
  1151
lemma real_of_int_inject [iff, algebra, presburger]: "(real (x::int) = real y) = (x = y)"
paulson@14378
  1152
by (simp add: real_of_int_def) 
paulson@14365
  1153
chaieb@27668
  1154
lemma real_of_int_less_iff [iff, presburger]: "(real (x::int) < real y) = (x < y)"
paulson@14378
  1155
by (simp add: real_of_int_def) 
paulson@14365
  1156
chaieb@27668
  1157
lemma real_of_int_le_iff [simp, presburger]: "(real (x::int) \<le> real y) = (x \<le> y)"
paulson@14378
  1158
by (simp add: real_of_int_def) 
paulson@14365
  1159
chaieb@27668
  1160
lemma real_of_int_gt_zero_cancel_iff [simp, presburger]: "(0 < real (n::int)) = (0 < n)"
avigad@16819
  1161
by (simp add: real_of_int_def) 
avigad@16819
  1162
chaieb@27668
  1163
lemma real_of_int_ge_zero_cancel_iff [simp, presburger]: "(0 <= real (n::int)) = (0 <= n)"
avigad@16819
  1164
by (simp add: real_of_int_def) 
avigad@16819
  1165
chaieb@27668
  1166
lemma real_of_int_lt_zero_cancel_iff [simp, presburger]: "(real (n::int) < 0) = (n < 0)" 
avigad@16819
  1167
by (simp add: real_of_int_def)
avigad@16819
  1168
chaieb@27668
  1169
lemma real_of_int_le_zero_cancel_iff [simp, presburger]: "(real (n::int) <= 0) = (n <= 0)"
avigad@16819
  1170
by (simp add: real_of_int_def)
avigad@16819
  1171
avigad@16888
  1172
lemma real_of_int_abs [simp]: "real (abs x) = abs(real (x::int))"
avigad@16888
  1173
by (auto simp add: abs_if)
avigad@16888
  1174
avigad@16819
  1175
lemma int_less_real_le: "((n::int) < m) = (real n + 1 <= real m)"
avigad@16819
  1176
  apply (subgoal_tac "real n + 1 = real (n + 1)")
avigad@16819
  1177
  apply (simp del: real_of_int_add)
avigad@16819
  1178
  apply auto
avigad@16819
  1179
done
avigad@16819
  1180
avigad@16819
  1181
lemma int_le_real_less: "((n::int) <= m) = (real n < real m + 1)"
avigad@16819
  1182
  apply (subgoal_tac "real m + 1 = real (m + 1)")
avigad@16819
  1183
  apply (simp del: real_of_int_add)
avigad@16819
  1184
  apply simp
avigad@16819
  1185
done
avigad@16819
  1186
avigad@16819
  1187
lemma real_of_int_div_aux: "d ~= 0 ==> (real (x::int)) / (real d) = 
avigad@16819
  1188
    real (x div d) + (real (x mod d)) / (real d)"
avigad@16819
  1189
proof -
wenzelm@41550
  1190
  assume d: "d ~= 0"
avigad@16819
  1191
  have "x = (x div d) * d + x mod d"
avigad@16819
  1192
    by auto
avigad@16819
  1193
  then have "real x = real (x div d) * real d + real(x mod d)"
avigad@16819
  1194
    by (simp only: real_of_int_mult [THEN sym] real_of_int_add [THEN sym])
avigad@16819
  1195
  then have "real x / real d = ... / real d"
avigad@16819
  1196
    by simp
avigad@16819
  1197
  then show ?thesis
wenzelm@41550
  1198
    by (auto simp add: add_divide_distrib algebra_simps d)
avigad@16819
  1199
qed
avigad@16819
  1200
avigad@16819
  1201
lemma real_of_int_div: "(d::int) ~= 0 ==> d dvd n ==>
avigad@16819
  1202
    real(n div d) = real n / real d"
avigad@16819
  1203
  apply (frule real_of_int_div_aux [of d n])
avigad@16819
  1204
  apply simp
nipkow@30042
  1205
  apply (simp add: dvd_eq_mod_eq_0)
avigad@16819
  1206
done
avigad@16819
  1207
avigad@16819
  1208
lemma real_of_int_div2:
avigad@16819
  1209
  "0 <= real (n::int) / real (x) - real (n div x)"
avigad@16819
  1210
  apply (case_tac "x = 0")
avigad@16819
  1211
  apply simp
avigad@16819
  1212
  apply (case_tac "0 < x")
nipkow@29667
  1213
  apply (simp add: algebra_simps)
avigad@16819
  1214
  apply (subst real_of_int_div_aux)
avigad@16819
  1215
  apply simp
avigad@16819
  1216
  apply simp
avigad@16819
  1217
  apply (subst zero_le_divide_iff)
avigad@16819
  1218
  apply auto
nipkow@29667
  1219
  apply (simp add: algebra_simps)
avigad@16819
  1220
  apply (subst real_of_int_div_aux)
avigad@16819
  1221
  apply simp
avigad@16819
  1222
  apply simp
avigad@16819
  1223
  apply (subst zero_le_divide_iff)
avigad@16819
  1224
  apply auto
avigad@16819
  1225
done
avigad@16819
  1226
avigad@16819
  1227
lemma real_of_int_div3:
avigad@16819
  1228
  "real (n::int) / real (x) - real (n div x) <= 1"
avigad@16819
  1229
  apply(case_tac "x = 0")
avigad@16819
  1230
  apply simp
nipkow@29667
  1231
  apply (simp add: algebra_simps)
avigad@16819
  1232
  apply (subst real_of_int_div_aux)
avigad@16819
  1233
  apply assumption
avigad@16819
  1234
  apply simp
avigad@16819
  1235
  apply (subst divide_le_eq)
avigad@16819
  1236
  apply clarsimp
avigad@16819
  1237
  apply (rule conjI)
avigad@16819
  1238
  apply (rule impI)
avigad@16819
  1239
  apply (rule order_less_imp_le)
avigad@16819
  1240
  apply simp
avigad@16819
  1241
  apply (rule impI)
avigad@16819
  1242
  apply (rule order_less_imp_le)
avigad@16819
  1243
  apply simp
avigad@16819
  1244
done
avigad@16819
  1245
avigad@16819
  1246
lemma real_of_int_div4: "real (n div x) <= real (n::int) / real x" 
nipkow@27964
  1247
by (insert real_of_int_div2 [of n x], simp)
nipkow@27964
  1248
huffman@35635
  1249
lemma Ints_real_of_int [simp]: "real (x::int) \<in> Ints"
huffman@35635
  1250
unfolding real_of_int_def by (rule Ints_of_int)
huffman@35635
  1251
nipkow@27964
  1252
paulson@14365
  1253
subsection{*Embedding the Naturals into the Reals*}
paulson@14365
  1254
paulson@14334
  1255
lemma real_of_nat_zero [simp]: "real (0::nat) = 0"
paulson@14365
  1256
by (simp add: real_of_nat_def)
paulson@14334
  1257
huffman@30082
  1258
lemma real_of_nat_1 [simp]: "real (1::nat) = 1"
huffman@30082
  1259
by (simp add: real_of_nat_def)
huffman@30082
  1260
paulson@14334
  1261
lemma real_of_nat_one [simp]: "real (Suc 0) = (1::real)"
paulson@14365
  1262
by (simp add: real_of_nat_def)
paulson@14334
  1263
paulson@14365
  1264
lemma real_of_nat_add [simp]: "real (m + n) = real (m::nat) + real n"
paulson@14378
  1265
by (simp add: real_of_nat_def)
paulson@14334
  1266
paulson@14334
  1267
(*Not for addsimps: often the LHS is used to represent a positive natural*)
paulson@14334
  1268
lemma real_of_nat_Suc: "real (Suc n) = real n + (1::real)"
paulson@14378
  1269
by (simp add: real_of_nat_def)
paulson@14334
  1270
paulson@14334
  1271
lemma real_of_nat_less_iff [iff]: 
paulson@14334
  1272
     "(real (n::nat) < real m) = (n < m)"
paulson@14365
  1273
by (simp add: real_of_nat_def)
paulson@14334
  1274
paulson@14334
  1275
lemma real_of_nat_le_iff [iff]: "(real (n::nat) \<le> real m) = (n \<le> m)"
paulson@14378
  1276
by (simp add: real_of_nat_def)
paulson@14334
  1277
paulson@14334
  1278
lemma real_of_nat_ge_zero [iff]: "0 \<le> real (n::nat)"
paulson@14378
  1279
by (simp add: real_of_nat_def zero_le_imp_of_nat)
paulson@14334
  1280
paulson@14365
  1281
lemma real_of_nat_Suc_gt_zero: "0 < real (Suc n)"
paulson@14378
  1282
by (simp add: real_of_nat_def del: of_nat_Suc)
paulson@14365
  1283
paulson@14334
  1284
lemma real_of_nat_mult [simp]: "real (m * n) = real (m::nat) * real n"
huffman@23431
  1285
by (simp add: real_of_nat_def of_nat_mult)
paulson@14334
  1286
huffman@35344
  1287
lemma real_of_nat_power [simp]: "real (m ^ n) = real (m::nat) ^ n"
huffman@35344
  1288
by (simp add: real_of_nat_def of_nat_power)
huffman@35344
  1289
huffman@35344
  1290
lemmas power_real_of_nat = real_of_nat_power [symmetric]
huffman@35344
  1291
avigad@16819
  1292
lemma real_of_nat_setsum [simp]: "real ((SUM x:A. f x)::nat) = 
avigad@16819
  1293
    (SUM x:A. real(f x))"
avigad@16819
  1294
  apply (subst real_eq_of_nat)+
avigad@16819
  1295
  apply (rule of_nat_setsum)
avigad@16819
  1296
done
avigad@16819
  1297
avigad@16819
  1298
lemma real_of_nat_setprod [simp]: "real ((PROD x:A. f x)::nat) = 
avigad@16819
  1299
    (PROD x:A. real(f x))"
avigad@16819
  1300
  apply (subst real_eq_of_nat)+
avigad@16819
  1301
  apply (rule of_nat_setprod)
avigad@16819
  1302
done
avigad@16819
  1303
avigad@16819
  1304
lemma real_of_card: "real (card A) = setsum (%x.1) A"
avigad@16819
  1305
  apply (subst card_eq_setsum)
avigad@16819
  1306
  apply (subst real_of_nat_setsum)
avigad@16819
  1307
  apply simp
avigad@16819
  1308
done
avigad@16819
  1309
paulson@14334
  1310
lemma real_of_nat_inject [iff]: "(real (n::nat) = real m) = (n = m)"
paulson@14378
  1311
by (simp add: real_of_nat_def)
paulson@14334
  1312
paulson@14387
  1313
lemma real_of_nat_zero_iff [iff]: "(real (n::nat) = 0) = (n = 0)"
paulson@14378
  1314
by (simp add: real_of_nat_def)
paulson@14334
  1315
paulson@14365
  1316
lemma real_of_nat_diff: "n \<le> m ==> real (m - n) = real (m::nat) - real n"
huffman@23438
  1317
by (simp add: add: real_of_nat_def of_nat_diff)
paulson@14334
  1318
nipkow@25162
  1319
lemma real_of_nat_gt_zero_cancel_iff [simp]: "(0 < real (n::nat)) = (0 < n)"
nipkow@25140
  1320
by (auto simp: real_of_nat_def)
paulson@14365
  1321
paulson@14365
  1322
lemma real_of_nat_le_zero_cancel_iff [simp]: "(real (n::nat) \<le> 0) = (n = 0)"
paulson@14378
  1323
by (simp add: add: real_of_nat_def)
paulson@14334
  1324
paulson@14365
  1325
lemma not_real_of_nat_less_zero [simp]: "~ real (n::nat) < 0"
paulson@14378
  1326
by (simp add: add: real_of_nat_def)
paulson@14334
  1327
avigad@16819
  1328
lemma nat_less_real_le: "((n::nat) < m) = (real n + 1 <= real m)"
avigad@16819
  1329
  apply (subgoal_tac "real n + 1 = real (Suc n)")
avigad@16819
  1330
  apply simp
avigad@16819
  1331
  apply (auto simp add: real_of_nat_Suc)
avigad@16819
  1332
done
avigad@16819
  1333
avigad@16819
  1334
lemma nat_le_real_less: "((n::nat) <= m) = (real n < real m + 1)"
avigad@16819
  1335
  apply (subgoal_tac "real m + 1 = real (Suc m)")
avigad@16819
  1336
  apply (simp add: less_Suc_eq_le)
avigad@16819
  1337
  apply (simp add: real_of_nat_Suc)
avigad@16819
  1338
done
avigad@16819
  1339
avigad@16819
  1340
lemma real_of_nat_div_aux: "0 < d ==> (real (x::nat)) / (real d) = 
avigad@16819
  1341
    real (x div d) + (real (x mod d)) / (real d)"
avigad@16819
  1342
proof -
wenzelm@41550
  1343
  assume d: "0 < d"
avigad@16819
  1344
  have "x = (x div d) * d + x mod d"
avigad@16819
  1345
    by auto
avigad@16819
  1346
  then have "real x = real (x div d) * real d + real(x mod d)"
avigad@16819
  1347
    by (simp only: real_of_nat_mult [THEN sym] real_of_nat_add [THEN sym])
avigad@16819
  1348
  then have "real x / real d = \<dots> / real d"
avigad@16819
  1349
    by simp
avigad@16819
  1350
  then show ?thesis
wenzelm@41550
  1351
    by (auto simp add: add_divide_distrib algebra_simps d)
avigad@16819
  1352
qed
avigad@16819
  1353
avigad@16819
  1354
lemma real_of_nat_div: "0 < (d::nat) ==> d dvd n ==>
avigad@16819
  1355
    real(n div d) = real n / real d"
avigad@16819
  1356
  apply (frule real_of_nat_div_aux [of d n])
avigad@16819
  1357
  apply simp
avigad@16819
  1358
  apply (subst dvd_eq_mod_eq_0 [THEN sym])
avigad@16819
  1359
  apply assumption
avigad@16819
  1360
done
avigad@16819
  1361
avigad@16819
  1362
lemma real_of_nat_div2:
avigad@16819
  1363
  "0 <= real (n::nat) / real (x) - real (n div x)"
nipkow@25134
  1364
apply(case_tac "x = 0")
nipkow@25134
  1365
 apply (simp)
nipkow@29667
  1366
apply (simp add: algebra_simps)
nipkow@25134
  1367
apply (subst real_of_nat_div_aux)
nipkow@25134
  1368
 apply simp
nipkow@25134
  1369
apply simp
nipkow@25134
  1370
apply (subst zero_le_divide_iff)
nipkow@25134
  1371
apply simp
avigad@16819
  1372
done
avigad@16819
  1373
avigad@16819
  1374
lemma real_of_nat_div3:
avigad@16819
  1375
  "real (n::nat) / real (x) - real (n div x) <= 1"
nipkow@25134
  1376
apply(case_tac "x = 0")
nipkow@25134
  1377
apply (simp)
nipkow@29667
  1378
apply (simp add: algebra_simps)
nipkow@25134
  1379
apply (subst real_of_nat_div_aux)
nipkow@25134
  1380
 apply simp
nipkow@25134
  1381
apply simp
avigad@16819
  1382
done
avigad@16819
  1383
avigad@16819
  1384
lemma real_of_nat_div4: "real (n div x) <= real (n::nat) / real x" 
nipkow@29667
  1385
by (insert real_of_nat_div2 [of n x], simp)
avigad@16819
  1386
paulson@14426
  1387
lemma real_of_int_of_nat_eq [simp]: "real (of_nat n :: int) = real n"
paulson@14426
  1388
by (simp add: real_of_int_def real_of_nat_def)
paulson@14334
  1389
avigad@16819
  1390
lemma real_nat_eq_real [simp]: "0 <= x ==> real(nat x) = real x"
avigad@16819
  1391
  apply (subgoal_tac "real(int(nat x)) = real(nat x)")
avigad@16819
  1392
  apply force
huffman@44822
  1393
  apply (simp only: real_of_int_of_nat_eq)
avigad@16819
  1394
done
paulson@14387
  1395
huffman@35635
  1396
lemma Nats_real_of_nat [simp]: "real (n::nat) \<in> Nats"
huffman@35635
  1397
unfolding real_of_nat_def by (rule of_nat_in_Nats)
huffman@35635
  1398
huffman@35635
  1399
lemma Ints_real_of_nat [simp]: "real (n::nat) \<in> Ints"
huffman@35635
  1400
unfolding real_of_nat_def by (rule Ints_of_nat)
huffman@35635
  1401
nipkow@28001
  1402
nipkow@28001
  1403
subsection{* Rationals *}
nipkow@28001
  1404
nipkow@28091
  1405
lemma Rats_real_nat[simp]: "real(n::nat) \<in> \<rat>"
nipkow@28091
  1406
by (simp add: real_eq_of_nat)
nipkow@28091
  1407
nipkow@28091
  1408
nipkow@28001
  1409
lemma Rats_eq_int_div_int:
nipkow@28091
  1410
  "\<rat> = { real(i::int)/real(j::int) |i j. j \<noteq> 0}" (is "_ = ?S")
nipkow@28001
  1411
proof
nipkow@28091
  1412
  show "\<rat> \<subseteq> ?S"
nipkow@28001
  1413
  proof
nipkow@28091
  1414
    fix x::real assume "x : \<rat>"
nipkow@28001
  1415
    then obtain r where "x = of_rat r" unfolding Rats_def ..
nipkow@28001
  1416
    have "of_rat r : ?S"
nipkow@28001
  1417
      by (cases r)(auto simp add:of_rat_rat real_eq_of_int)
nipkow@28001
  1418
    thus "x : ?S" using `x = of_rat r` by simp
nipkow@28001
  1419
  qed
nipkow@28001
  1420
next
nipkow@28091
  1421
  show "?S \<subseteq> \<rat>"
nipkow@28001
  1422
  proof(auto simp:Rats_def)
nipkow@28001
  1423
    fix i j :: int assume "j \<noteq> 0"
nipkow@28001
  1424
    hence "real i / real j = of_rat(Fract i j)"
nipkow@28001
  1425
      by (simp add:of_rat_rat real_eq_of_int)
nipkow@28001
  1426
    thus "real i / real j \<in> range of_rat" by blast
nipkow@28001
  1427
  qed
nipkow@28001
  1428
qed
nipkow@28001
  1429
nipkow@28001
  1430
lemma Rats_eq_int_div_nat:
nipkow@28091
  1431
  "\<rat> = { real(i::int)/real(n::nat) |i n. n \<noteq> 0}"
nipkow@28001
  1432
proof(auto simp:Rats_eq_int_div_int)
nipkow@28001
  1433
  fix i j::int assume "j \<noteq> 0"
nipkow@28001
  1434
  show "EX (i'::int) (n::nat). real i/real j = real i'/real n \<and> 0<n"
nipkow@28001
  1435
  proof cases
nipkow@28001
  1436
    assume "j>0"
nipkow@28001
  1437
    hence "real i/real j = real i/real(nat j) \<and> 0<nat j"
nipkow@28001
  1438
      by (simp add: real_eq_of_int real_eq_of_nat of_nat_nat)
nipkow@28001
  1439
    thus ?thesis by blast
nipkow@28001
  1440
  next
nipkow@28001
  1441
    assume "~ j>0"
nipkow@28001
  1442
    hence "real i/real j = real(-i)/real(nat(-j)) \<and> 0<nat(-j)" using `j\<noteq>0`
nipkow@28001
  1443
      by (simp add: real_eq_of_int real_eq_of_nat of_nat_nat)
nipkow@28001
  1444
    thus ?thesis by blast
nipkow@28001
  1445
  qed
nipkow@28001
  1446
next
nipkow@28001
  1447
  fix i::int and n::nat assume "0 < n"
nipkow@28001
  1448
  hence "real i/real n = real i/real(int n) \<and> int n \<noteq> 0" by simp
nipkow@28001
  1449
  thus "\<exists>(i'::int) j::int. real i/real n = real i'/real j \<and> j \<noteq> 0" by blast
nipkow@28001
  1450
qed
nipkow@28001
  1451
nipkow@28001
  1452
lemma Rats_abs_nat_div_natE:
nipkow@28001
  1453
  assumes "x \<in> \<rat>"
huffman@31706
  1454
  obtains m n :: nat
huffman@31706
  1455
  where "n \<noteq> 0" and "\<bar>x\<bar> = real m / real n" and "gcd m n = 1"
nipkow@28001
  1456
proof -
nipkow@28001
  1457
  from `x \<in> \<rat>` obtain i::int and n::nat where "n \<noteq> 0" and "x = real i / real n"
nipkow@28001
  1458
    by(auto simp add: Rats_eq_int_div_nat)
nipkow@28001
  1459
  hence "\<bar>x\<bar> = real(nat(abs i)) / real n" by simp
nipkow@28001
  1460
  then obtain m :: nat where x_rat: "\<bar>x\<bar> = real m / real n" by blast
nipkow@28001
  1461
  let ?gcd = "gcd m n"
huffman@31706
  1462
  from `n\<noteq>0` have gcd: "?gcd \<noteq> 0" by simp
nipkow@28001
  1463
  let ?k = "m div ?gcd"
nipkow@28001
  1464
  let ?l = "n div ?gcd"
nipkow@28001
  1465
  let ?gcd' = "gcd ?k ?l"
nipkow@28001
  1466
  have "?gcd dvd m" .. then have gcd_k: "?gcd * ?k = m"
nipkow@28001
  1467
    by (rule dvd_mult_div_cancel)
nipkow@28001
  1468
  have "?gcd dvd n" .. then have gcd_l: "?gcd * ?l = n"
nipkow@28001
  1469
    by (rule dvd_mult_div_cancel)
nipkow@28001
  1470
  from `n\<noteq>0` and gcd_l have "?l \<noteq> 0" by (auto iff del: neq0_conv)
nipkow@28001
  1471
  moreover
nipkow@28001
  1472
  have "\<bar>x\<bar> = real ?k / real ?l"
nipkow@28001
  1473
  proof -
nipkow@28001
  1474
    from gcd have "real ?k / real ?l =
nipkow@28001
  1475
        real (?gcd * ?k) / real (?gcd * ?l)" by simp
nipkow@28001
  1476
    also from gcd_k and gcd_l have "\<dots> = real m / real n" by simp
nipkow@28001
  1477
    also from x_rat have "\<dots> = \<bar>x\<bar>" ..
nipkow@28001
  1478
    finally show ?thesis ..
nipkow@28001
  1479
  qed
nipkow@28001
  1480
  moreover
nipkow@28001
  1481
  have "?gcd' = 1"
nipkow@28001
  1482
  proof -
nipkow@28001
  1483
    have "?gcd * ?gcd' = gcd (?gcd * ?k) (?gcd * ?l)"
nipkow@31952
  1484
      by (rule gcd_mult_distrib_nat)
nipkow@28001
  1485
    with gcd_k gcd_l have "?gcd * ?gcd' = ?gcd" by simp
huffman@31706
  1486
    with gcd show ?thesis by auto
nipkow@28001
  1487
  qed
nipkow@28001
  1488
  ultimately show ?thesis ..
nipkow@28001
  1489
qed
nipkow@28001
  1490
nipkow@28001
  1491
paulson@14387
  1492
subsection{*Numerals and Arithmetic*}
paulson@14387
  1493
haftmann@32069
  1494
lemma [code_unfold_post]:
haftmann@24198
  1495
  "number_of k = real_of_int (number_of k)"
huffman@36795
  1496
  unfolding number_of_is_id number_of_real_def ..
paulson@14387
  1497
paulson@14387
  1498
paulson@14387
  1499
text{*Collapse applications of @{term real} to @{term number_of}*}
paulson@14387
  1500
lemma real_number_of [simp]: "real (number_of v :: int) = number_of v"
huffman@35216
  1501
by (simp add: real_of_int_def)
paulson@14387
  1502
paulson@14387
  1503
lemma real_of_nat_number_of [simp]:
paulson@14387
  1504
     "real (number_of v :: nat) =  
paulson@14387
  1505
        (if neg (number_of v :: int) then 0  
paulson@14387
  1506
         else (number_of v :: real))"
huffman@44822
  1507
by (simp add: real_of_int_of_nat_eq [symmetric])
paulson@14387
  1508
haftmann@31100
  1509
declaration {*
haftmann@31100
  1510
  K (Lin_Arith.add_inj_thms [@{thm real_of_nat_le_iff} RS iffD2, @{thm real_of_nat_inject} RS iffD2]
haftmann@31100
  1511
    (* not needed because x < (y::nat) can be rewritten as Suc x <= y: real_of_nat_less_iff RS iffD2 *)
haftmann@31100
  1512
  #> Lin_Arith.add_inj_thms [@{thm real_of_int_le_iff} RS iffD2, @{thm real_of_int_inject} RS iffD2]
haftmann@31100
  1513
    (* not needed because x < (y::int) can be rewritten as x + 1 <= y: real_of_int_less_iff RS iffD2 *)
haftmann@31100
  1514
  #> Lin_Arith.add_simps [@{thm real_of_nat_zero}, @{thm real_of_nat_Suc}, @{thm real_of_nat_add},
haftmann@31100
  1515
      @{thm real_of_nat_mult}, @{thm real_of_int_zero}, @{thm real_of_one},
haftmann@31100
  1516
      @{thm real_of_int_add}, @{thm real_of_int_minus}, @{thm real_of_int_diff},
haftmann@31100
  1517
      @{thm real_of_int_mult}, @{thm real_of_int_of_nat_eq},
haftmann@31100
  1518
      @{thm real_of_nat_number_of}, @{thm real_number_of}]
huffman@36795
  1519
  #> Lin_Arith.add_inj_const (@{const_name real}, @{typ "nat \<Rightarrow> real"})
huffman@36795
  1520
  #> Lin_Arith.add_inj_const (@{const_name real}, @{typ "int \<Rightarrow> real"}))
haftmann@31100
  1521
*}
paulson@14387
  1522
kleing@19023
  1523
paulson@14387
  1524
subsection{* Simprules combining x+y and 0: ARE THEY NEEDED?*}
paulson@14387
  1525
paulson@14387
  1526
lemma real_add_minus_iff [simp]: "(x + - a = (0::real)) = (x=a)" 
paulson@14387
  1527
by arith
paulson@14387
  1528
huffman@36839
  1529
text {* FIXME: redundant with @{text add_eq_0_iff} below *}
paulson@15085
  1530
lemma real_add_eq_0_iff: "(x+y = (0::real)) = (y = -x)"
paulson@14387
  1531
by auto
paulson@14387
  1532
paulson@15085
  1533
lemma real_add_less_0_iff: "(x+y < (0::real)) = (y < -x)"
paulson@14387
  1534
by auto
paulson@14387
  1535
paulson@15085
  1536
lemma real_0_less_add_iff: "((0::real) < x+y) = (-x < y)"
paulson@14387
  1537
by auto
paulson@14387
  1538
paulson@15085
  1539
lemma real_add_le_0_iff: "(x+y \<le> (0::real)) = (y \<le> -x)"
paulson@14387
  1540
by auto
paulson@14387
  1541
paulson@15085
  1542
lemma real_0_le_add_iff: "((0::real) \<le> x+y) = (-x \<le> y)"
paulson@14387
  1543
by auto
paulson@14387
  1544
huffman@36839
  1545
subsection {* Lemmas about powers *}
paulson@14387
  1546
huffman@36839
  1547
text {* FIXME: declare this in Rings.thy or not at all *}
huffman@36839
  1548
declare abs_mult_self [simp]
huffman@36839
  1549
huffman@36839
  1550
(* used by Import/HOL/real.imp *)
huffman@36839
  1551
lemma two_realpow_ge_one: "(1::real) \<le> 2 ^ n"
huffman@36839
  1552
by simp
huffman@36839
  1553
huffman@36839
  1554
lemma two_realpow_gt [simp]: "real (n::nat) < 2 ^ n"
huffman@36839
  1555
apply (induct "n")
huffman@36839
  1556
apply (auto simp add: real_of_nat_Suc)
huffman@36839
  1557
apply (subst mult_2)
huffman@36839
  1558
apply (erule add_less_le_mono)
huffman@36839
  1559
apply (rule two_realpow_ge_one)
huffman@36839
  1560
done
huffman@36839
  1561
huffman@36839
  1562
text {* TODO: no longer real-specific; rename and move elsewhere *}
huffman@36839
  1563
lemma realpow_Suc_le_self:
huffman@36839
  1564
  fixes r :: "'a::linordered_semidom"
huffman@36839
  1565
  shows "[| 0 \<le> r; r \<le> 1 |] ==> r ^ Suc n \<le> r"
huffman@36839
  1566
by (insert power_decreasing [of 1 "Suc n" r], simp)
huffman@36839
  1567
huffman@36839
  1568
text {* TODO: no longer real-specific; rename and move elsewhere *}
huffman@36839
  1569
lemma realpow_minus_mult:
huffman@36839
  1570
  fixes x :: "'a::monoid_mult"
huffman@36839
  1571
  shows "0 < n \<Longrightarrow> x ^ (n - 1) * x = x ^ n"
huffman@36839
  1572
by (simp add: power_commutes split add: nat_diff_split)
huffman@36839
  1573
huffman@36839
  1574
text {* FIXME: declare this [simp] for all types, or not at all *}
huffman@36839
  1575
lemma real_two_squares_add_zero_iff [simp]:
huffman@36839
  1576
  "(x * x + y * y = 0) = ((x::real) = 0 \<and> y = 0)"
huffman@36839
  1577
by (rule sum_squares_eq_zero_iff)
huffman@36839
  1578
huffman@36839
  1579
text {* FIXME: declare this [simp] for all types, or not at all *}
huffman@36839
  1580
lemma realpow_two_sum_zero_iff [simp]:
huffman@36839
  1581
     "(x ^ 2 + y ^ 2 = (0::real)) = (x = 0 & y = 0)"
huffman@36839
  1582
by (rule sum_power2_eq_zero_iff)
huffman@36839
  1583
huffman@36839
  1584
lemma real_minus_mult_self_le [simp]: "-(u * u) \<le> (x * (x::real))"
huffman@36839
  1585
by (rule_tac y = 0 in order_trans, auto)
huffman@36839
  1586
huffman@36839
  1587
lemma realpow_square_minus_le [simp]: "-(u ^ 2) \<le> (x::real) ^ 2"
huffman@36839
  1588
by (auto simp add: power2_eq_square)
huffman@36839
  1589
huffman@36839
  1590
huffman@36839
  1591
subsection{*Density of the Reals*}
paulson@14387
  1592
paulson@14387
  1593
lemma real_lbound_gt_zero:
paulson@14387
  1594
     "[| (0::real) < d1; 0 < d2 |] ==> \<exists>e. 0 < e & e < d1 & e < d2"
paulson@14387
  1595
apply (rule_tac x = " (min d1 d2) /2" in exI)
paulson@14387
  1596
apply (simp add: min_def)
paulson@14387
  1597
done
paulson@14387
  1598
paulson@14387
  1599
haftmann@35050
  1600
text{*Similar results are proved in @{text Fields}*}
paulson@14387
  1601
lemma real_less_half_sum: "x < y ==> x < (x+y) / (2::real)"
paulson@14387
  1602
  by auto
paulson@14387
  1603
paulson@14387
  1604
lemma real_gt_half_sum: "x < y ==> (x+y)/(2::real) < y"
paulson@14387
  1605
  by auto
paulson@14387
  1606
paulson@14387
  1607
paulson@14387
  1608
subsection{*Absolute Value Function for the Reals*}
paulson@14387
  1609
paulson@14387
  1610
lemma abs_minus_add_cancel: "abs(x + (-y)) = abs (y + (-(x::real)))"
paulson@15003
  1611
by (simp add: abs_if)
paulson@14387
  1612
huffman@23289
  1613
(* FIXME: redundant, but used by Integration/RealRandVar.thy in AFP *)
paulson@14387
  1614
lemma abs_le_interval_iff: "(abs x \<le> r) = (-r\<le>x & x\<le>(r::real))"
haftmann@35050
  1615
by (force simp add: abs_le_iff)
paulson@14387
  1616
huffman@44344
  1617
lemma abs_add_one_gt_zero: "(0::real) < 1 + abs(x)"
paulson@15003
  1618
by (simp add: abs_if)
paulson@14387
  1619
paulson@14387
  1620
lemma abs_real_of_nat_cancel [simp]: "abs (real x) = real (x::nat)"
huffman@22958
  1621
by (rule abs_of_nonneg [OF real_of_nat_ge_zero])
paulson@14387
  1622
huffman@44344
  1623
lemma abs_add_one_not_less_self: "~ abs(x) + (1::real) < x"
webertj@20217
  1624
by simp
paulson@14387
  1625
 
paulson@14387
  1626
lemma abs_sum_triangle_ineq: "abs ((x::real) + y + (-l + -m)) \<le> abs(x + -l) + abs(y + -m)"
webertj@20217
  1627
by simp
paulson@14387
  1628
berghofe@24534
  1629
haftmann@27544
  1630
subsection {* Implementation of rational real numbers *}
berghofe@24534
  1631
haftmann@27544
  1632
definition Ratreal :: "rat \<Rightarrow> real" where
haftmann@27544
  1633
  [simp]: "Ratreal = of_rat"
berghofe@24534
  1634
haftmann@24623
  1635
code_datatype Ratreal
berghofe@24534
  1636
haftmann@31998
  1637
lemma Ratreal_number_collapse [code_post]:
haftmann@27544
  1638
  "Ratreal 0 = 0"
haftmann@27544
  1639
  "Ratreal 1 = 1"
haftmann@27544
  1640
  "Ratreal (number_of k) = number_of k"
haftmann@27544
  1641
by simp_all
berghofe@24534
  1642
haftmann@31998
  1643
lemma zero_real_code [code, code_unfold]:
haftmann@27544
  1644
  "0 = Ratreal 0"
haftmann@27544
  1645
by simp
berghofe@24534
  1646
haftmann@31998
  1647
lemma one_real_code [code, code_unfold]:
haftmann@27544
  1648
  "1 = Ratreal 1"
haftmann@27544
  1649
by simp
haftmann@27544
  1650
haftmann@31998
  1651
lemma number_of_real_code [code_unfold]:
haftmann@27544
  1652
  "number_of k = Ratreal (number_of k)"
haftmann@27544
  1653
by simp
haftmann@27544
  1654
haftmann@31998
  1655
lemma Ratreal_number_of_quotient [code_post]:
haftmann@27544
  1656
  "Ratreal (number_of r) / Ratreal (number_of s) = number_of r / number_of s"
haftmann@27544
  1657
by simp
haftmann@27544
  1658
haftmann@31998
  1659
lemma Ratreal_number_of_quotient2 [code_post]:
haftmann@27544
  1660
  "Ratreal (number_of r / number_of s) = number_of r / number_of s"
haftmann@27544
  1661
unfolding Ratreal_number_of_quotient [symmetric] Ratreal_def of_rat_divide ..
berghofe@24534
  1662
haftmann@38857
  1663
instantiation real :: equal
haftmann@26513
  1664
begin
haftmann@26513
  1665
haftmann@38857
  1666
definition "HOL.equal (x\<Colon>real) y \<longleftrightarrow> x - y = 0"
haftmann@26513
  1667
haftmann@38857
  1668
instance proof
haftmann@38857
  1669
qed (simp add: equal_real_def)
berghofe@24534
  1670
haftmann@38857
  1671
lemma real_equal_code [code]:
haftmann@38857
  1672
  "HOL.equal (Ratreal x) (Ratreal y) \<longleftrightarrow> HOL.equal x y"
haftmann@38857
  1673
  by (simp add: equal_real_def equal)
haftmann@26513
  1674
haftmann@38857
  1675
lemma [code nbe]:
haftmann@38857
  1676
  "HOL.equal (x::real) x \<longleftrightarrow> True"
haftmann@38857
  1677
  by (rule equal_refl)
haftmann@28351
  1678
haftmann@26513
  1679
end
berghofe@24534
  1680
haftmann@27544
  1681
lemma real_less_eq_code [code]: "Ratreal x \<le> Ratreal y \<longleftrightarrow> x \<le> y"
haftmann@27652
  1682
  by (simp add: of_rat_less_eq)
berghofe@24534
  1683
haftmann@27544
  1684
lemma real_less_code [code]: "Ratreal x < Ratreal y \<longleftrightarrow> x < y"
haftmann@27652
  1685
  by (simp add: of_rat_less)
berghofe@24534
  1686
haftmann@27544
  1687
lemma real_plus_code [code]: "Ratreal x + Ratreal y = Ratreal (x + y)"
haftmann@27544
  1688
  by (simp add: of_rat_add)
berghofe@24534
  1689
haftmann@27544
  1690
lemma real_times_code [code]: "Ratreal x * Ratreal y = Ratreal (x * y)"
haftmann@27544
  1691
  by (simp add: of_rat_mult)
haftmann@27544
  1692
haftmann@27544
  1693
lemma real_uminus_code [code]: "- Ratreal x = Ratreal (- x)"
haftmann@27544
  1694
  by (simp add: of_rat_minus)
berghofe@24534
  1695
haftmann@27544
  1696
lemma real_minus_code [code]: "Ratreal x - Ratreal y = Ratreal (x - y)"
haftmann@27544
  1697
  by (simp add: of_rat_diff)
berghofe@24534
  1698
haftmann@27544
  1699
lemma real_inverse_code [code]: "inverse (Ratreal x) = Ratreal (inverse x)"
haftmann@27544
  1700
  by (simp add: of_rat_inverse)
haftmann@27544
  1701
 
haftmann@27544
  1702
lemma real_divide_code [code]: "Ratreal x / Ratreal y = Ratreal (x / y)"
haftmann@27544
  1703
  by (simp add: of_rat_divide)
berghofe@24534
  1704
bulwahn@43733
  1705
lemma real_floor_code [code]: "floor (Ratreal x) = floor x"
bulwahn@43733
  1706
  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
  1707
haftmann@31203
  1708
definition (in term_syntax)
haftmann@32657
  1709
  valterm_ratreal :: "rat \<times> (unit \<Rightarrow> Code_Evaluation.term) \<Rightarrow> real \<times> (unit \<Rightarrow> Code_Evaluation.term)" where
haftmann@32657
  1710
  [code_unfold]: "valterm_ratreal k = Code_Evaluation.valtermify Ratreal {\<cdot>} k"
haftmann@31203
  1711
haftmann@37751
  1712
notation fcomp (infixl "\<circ>>" 60)
haftmann@37751
  1713
notation scomp (infixl "\<circ>\<rightarrow>" 60)
haftmann@31203
  1714
haftmann@31203
  1715
instantiation real :: random
haftmann@31203
  1716
begin
haftmann@31203
  1717
haftmann@31203
  1718
definition
haftmann@37751
  1719
  "Quickcheck.random i = Quickcheck.random i \<circ>\<rightarrow> (\<lambda>r. Pair (valterm_ratreal r))"
haftmann@31203
  1720
haftmann@31203
  1721
instance ..
haftmann@31203
  1722
haftmann@31203
  1723
end
haftmann@31203
  1724
haftmann@37751
  1725
no_notation fcomp (infixl "\<circ>>" 60)
haftmann@37751
  1726
no_notation scomp (infixl "\<circ>\<rightarrow>" 60)
haftmann@31203
  1727
bulwahn@41920
  1728
instantiation real :: exhaustive
bulwahn@41231
  1729
begin
bulwahn@41231
  1730
bulwahn@41231
  1731
definition
bulwahn@42311
  1732
  "exhaustive f d = exhaustive (%r. f (Ratreal r)) d"
bulwahn@42311
  1733
bulwahn@42311
  1734
instance ..
bulwahn@42311
  1735
bulwahn@42311
  1736
end
bulwahn@42311
  1737
bulwahn@42311
  1738
instantiation real :: full_exhaustive
bulwahn@42311
  1739
begin
bulwahn@42311
  1740
bulwahn@42311
  1741
definition
bulwahn@42311
  1742
  "full_exhaustive f d = full_exhaustive (%r. f (valterm_ratreal r)) d"
bulwahn@41231
  1743
bulwahn@41231
  1744
instance ..
bulwahn@41231
  1745
bulwahn@41231
  1746
end
bulwahn@41231
  1747
bulwahn@43887
  1748
instantiation real :: narrowing
bulwahn@43887
  1749
begin
bulwahn@43887
  1750
bulwahn@43887
  1751
definition
bulwahn@43887
  1752
  "narrowing = Quickcheck_Narrowing.apply (Quickcheck_Narrowing.cons Ratreal) narrowing"
bulwahn@43887
  1753
bulwahn@43887
  1754
instance ..
bulwahn@43887
  1755
bulwahn@43887
  1756
end
bulwahn@43887
  1757
bulwahn@43887
  1758
bulwahn@45184
  1759
subsection {* Setup for Nitpick *}
berghofe@24534
  1760
blanchet@38287
  1761
declaration {*
blanchet@38287
  1762
  Nitpick_HOL.register_frac_type @{type_name real}
wenzelm@33209
  1763
   [(@{const_name zero_real_inst.zero_real}, @{const_name Nitpick.zero_frac}),
wenzelm@33209
  1764
    (@{const_name one_real_inst.one_real}, @{const_name Nitpick.one_frac}),
wenzelm@33209
  1765
    (@{const_name plus_real_inst.plus_real}, @{const_name Nitpick.plus_frac}),
wenzelm@33209
  1766
    (@{const_name times_real_inst.times_real}, @{const_name Nitpick.times_frac}),
wenzelm@33209
  1767
    (@{const_name uminus_real_inst.uminus_real}, @{const_name Nitpick.uminus_frac}),
wenzelm@33209
  1768
    (@{const_name number_real_inst.number_of_real}, @{const_name Nitpick.number_of_frac}),
wenzelm@33209
  1769
    (@{const_name inverse_real_inst.inverse_real}, @{const_name Nitpick.inverse_frac}),
blanchet@37397
  1770
    (@{const_name ord_real_inst.less_real}, @{const_name Nitpick.less_eq_frac}),
wenzelm@33209
  1771
    (@{const_name ord_real_inst.less_eq_real}, @{const_name Nitpick.less_eq_frac})]
blanchet@33197
  1772
*}
blanchet@33197
  1773
blanchet@41792
  1774
lemmas [nitpick_unfold] = inverse_real_inst.inverse_real
blanchet@33197
  1775
    number_real_inst.number_of_real one_real_inst.one_real
blanchet@37397
  1776
    ord_real_inst.less_real ord_real_inst.less_eq_real plus_real_inst.plus_real
blanchet@33197
  1777
    times_real_inst.times_real uminus_real_inst.uminus_real
blanchet@33197
  1778
    zero_real_inst.zero_real
blanchet@33197
  1779
paulson@5588
  1780
end