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