src/HOL/Real.thy
author haftmann
Wed, 09 Oct 2019 14:51:54 +0000
changeset 70817 dd675800469d
parent 70356 4a327c061870
child 71043 2fab72ab919a
permissions -rw-r--r--
dedicated fact collections for algebraic simplification rules potentially splitting goals
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     1
(*  Title:      HOL/Real.thy
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     2
    Author:     Jacques D. Fleuriot, University of Edinburgh, 1998
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     3
    Author:     Larry Paulson, University of Cambridge
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     4
    Author:     Jeremy Avigad, Carnegie Mellon University
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     5
    Author:     Florian Zuleger, Johannes Hoelzl, and Simon Funke, TU Muenchen
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     6
    Conversion to Isar and new proofs by Lawrence C Paulson, 2003/4
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     7
    Construction of Cauchy Reals by Brian Huffman, 2010
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     8
*)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
     9
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
    10
section \<open>Development of the Reals using Cauchy Sequences\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    11
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    12
theory Real
63961
2fd9656c4c82 invoke argo as part of the tried automatic proof methods
boehmes
parents: 63960
diff changeset
    13
imports Rat
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    14
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    15
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
    16
text \<open>
63680
6e1e8b5abbfa more symbols;
wenzelm
parents: 63601
diff changeset
    17
  This theory contains a formalization of the real numbers as equivalence
6e1e8b5abbfa more symbols;
wenzelm
parents: 63601
diff changeset
    18
  classes of Cauchy sequences of rationals. See
6e1e8b5abbfa more symbols;
wenzelm
parents: 63601
diff changeset
    19
  \<^file>\<open>~~/src/HOL/ex/Dedekind_Real.thy\<close> for an alternative construction using
6e1e8b5abbfa more symbols;
wenzelm
parents: 63601
diff changeset
    20
  Dedekind cuts.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
    21
\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    22
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    23
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
    24
subsection \<open>Preliminary lemmas\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    25
67226
ec32cdaab97b isabelle update_cartouches -c -t;
wenzelm
parents: 67051
diff changeset
    26
text\<open>Useful in convergence arguments\<close>
66793
deabce3ccf1f new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents: 66515
diff changeset
    27
lemma inverse_of_nat_le:
deabce3ccf1f new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents: 66515
diff changeset
    28
  fixes n::nat shows "\<lbrakk>n \<le> m; n\<noteq>0\<rbrakk> \<Longrightarrow> 1 / of_nat m \<le> (1::'a::linordered_field) / of_nat n"
deabce3ccf1f new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents: 66515
diff changeset
    29
  by (simp add: frac_le)
deabce3ccf1f new material about connectedness, etc.
paulson <lp15@cam.ac.uk>
parents: 66515
diff changeset
    30
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
    31
lemma add_diff_add: "(a + c) - (b + d) = (a - b) + (c - d)"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
    32
  for a b c d :: "'a::ab_group_add"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    33
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    34
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
    35
lemma minus_diff_minus: "- a - - b = - (a - b)"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
    36
  for a b :: "'a::ab_group_add"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    37
  by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    38
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
    39
lemma mult_diff_mult: "(x * y - a * b) = x * (y - b) + (x - a) * b"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
    40
  for x y a b :: "'a::ring"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    41
  by (simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    42
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    43
lemma inverse_diff_inverse:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    44
  fixes a b :: "'a::division_ring"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    45
  assumes "a \<noteq> 0" and "b \<noteq> 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    46
  shows "inverse a - inverse b = - (inverse a * (a - b) * inverse b)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    47
  using assms by (simp add: algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    48
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    49
lemma obtain_pos_sum:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    50
  fixes r :: rat assumes r: "0 < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    51
  obtains s t where "0 < s" and "0 < t" and "r = s + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    52
proof
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    53
  from r show "0 < r/2" by simp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    54
  from r show "0 < r/2" by simp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    55
  show "r = r/2 + r/2" by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    56
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    57
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    58
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
    59
subsection \<open>Sequences that converge to zero\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    60
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    61
definition vanishes :: "(nat \<Rightarrow> rat) \<Rightarrow> bool"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    62
  where "vanishes X \<longleftrightarrow> (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    63
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    64
lemma vanishesI: "(\<And>r. 0 < r \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r) \<Longrightarrow> vanishes X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    65
  unfolding vanishes_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    66
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    67
lemma vanishesD: "vanishes X \<Longrightarrow> 0 < r \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. \<bar>X n\<bar> < r"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    68
  unfolding vanishes_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    69
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    70
lemma vanishes_const [simp]: "vanishes (\<lambda>n. c) \<longleftrightarrow> c = 0"
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
    71
proof (cases "c = 0")
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
    72
  case True
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
    73
  then show ?thesis
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
    74
    by (simp add: vanishesI)    
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
    75
next
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
    76
  case False
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
    77
  then show ?thesis
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
    78
    unfolding vanishes_def
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
    79
    using zero_less_abs_iff by blast
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
    80
qed
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    81
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    82
lemma vanishes_minus: "vanishes X \<Longrightarrow> vanishes (\<lambda>n. - X n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    83
  unfolding vanishes_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    84
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    85
lemma vanishes_add:
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    86
  assumes X: "vanishes X"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    87
    and Y: "vanishes Y"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    88
  shows "vanishes (\<lambda>n. X n + Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    89
proof (rule vanishesI)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    90
  fix r :: rat
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    91
  assume "0 < r"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    92
  then obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    93
    by (rule obtain_pos_sum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    94
  obtain i where i: "\<forall>n\<ge>i. \<bar>X n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    95
    using vanishesD [OF X s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    96
  obtain j where j: "\<forall>n\<ge>j. \<bar>Y n\<bar> < t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    97
    using vanishesD [OF Y t] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
    98
  have "\<forall>n\<ge>max i j. \<bar>X n + Y n\<bar> < r"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
    99
  proof clarsimp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   100
    fix n
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   101
    assume n: "i \<le> n" "j \<le> n"
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   102
    have "\<bar>X n + Y n\<bar> \<le> \<bar>X n\<bar> + \<bar>Y n\<bar>"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   103
      by (rule abs_triangle_ineq)
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   104
    also have "\<dots> < s + t"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   105
      by (simp add: add_strict_mono i j n)
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   106
    finally show "\<bar>X n + Y n\<bar> < r"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   107
      by (simp only: r)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   108
  qed
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   109
  then show "\<exists>k. \<forall>n\<ge>k. \<bar>X n + Y n\<bar> < r" ..
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   110
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   111
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   112
lemma vanishes_diff:
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   113
  assumes "vanishes X" "vanishes Y"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   114
  shows "vanishes (\<lambda>n. X n - Y n)"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   115
  unfolding diff_conv_add_uminus by (intro vanishes_add vanishes_minus assms)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   116
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   117
lemma vanishes_mult_bounded:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   118
  assumes X: "\<exists>a>0. \<forall>n. \<bar>X n\<bar> < a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   119
  assumes Y: "vanishes (\<lambda>n. Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   120
  shows "vanishes (\<lambda>n. X n * Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   121
proof (rule vanishesI)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   122
  fix r :: rat
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   123
  assume r: "0 < r"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   124
  obtain a where a: "0 < a" "\<forall>n. \<bar>X n\<bar> < a"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
   125
    using X by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   126
  obtain b where b: "0 < b" "r = a * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   127
  proof
56541
0e3abadbef39 made divide_pos_pos a simp rule
nipkow
parents: 56536
diff changeset
   128
    show "0 < r / a" using r a by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   129
    show "r = a * (r / a)" using a by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   130
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   131
  obtain k where k: "\<forall>n\<ge>k. \<bar>Y n\<bar> < b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   132
    using vanishesD [OF Y b(1)] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   133
  have "\<forall>n\<ge>k. \<bar>X n * Y n\<bar> < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   134
    by (simp add: b(2) abs_mult mult_strict_mono' a k)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   135
  then show "\<exists>k. \<forall>n\<ge>k. \<bar>X n * Y n\<bar> < r" ..
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   136
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   137
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   138
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   139
subsection \<open>Cauchy sequences\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   140
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   141
definition cauchy :: "(nat \<Rightarrow> rat) \<Rightarrow> bool"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   142
  where "cauchy X \<longleftrightarrow> (\<forall>r>0. \<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   143
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   144
lemma cauchyI: "(\<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"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   145
  unfolding cauchy_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   146
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   147
lemma cauchyD: "cauchy X \<Longrightarrow> 0 < r \<Longrightarrow> \<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   148
  unfolding cauchy_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   149
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   150
lemma cauchy_const [simp]: "cauchy (\<lambda>n. x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   151
  unfolding cauchy_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   152
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   153
lemma cauchy_add [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   154
  assumes X: "cauchy X" and Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   155
  shows "cauchy (\<lambda>n. X n + Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   156
proof (rule cauchyI)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   157
  fix r :: rat
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   158
  assume "0 < r"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   159
  then obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   160
    by (rule obtain_pos_sum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   161
  obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   162
    using cauchyD [OF X s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   163
  obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>Y m - Y n\<bar> < t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   164
    using cauchyD [OF Y t] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   165
  have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>(X m + Y m) - (X n + Y n)\<bar> < r"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   166
  proof clarsimp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   167
    fix m n
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   168
    assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   169
    have "\<bar>(X m + Y m) - (X n + Y n)\<bar> \<le> \<bar>X m - X n\<bar> + \<bar>Y m - Y n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   170
      unfolding add_diff_add by (rule abs_triangle_ineq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   171
    also have "\<dots> < s + t"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   172
      by (rule add_strict_mono) (simp_all add: i j *)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   173
    finally show "\<bar>(X m + Y m) - (X n + Y n)\<bar> < r" by (simp only: r)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   174
  qed
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   175
  then show "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>(X m + Y m) - (X n + Y n)\<bar> < r" ..
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   176
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   177
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   178
lemma cauchy_minus [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   179
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   180
  shows "cauchy (\<lambda>n. - X n)"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   181
  using assms unfolding cauchy_def
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   182
  unfolding minus_diff_minus abs_minus_cancel .
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   183
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   184
lemma cauchy_diff [simp]:
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   185
  assumes "cauchy X" "cauchy Y"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   186
  shows "cauchy (\<lambda>n. X n - Y n)"
54230
b1d955791529 more simplification rules on unary and binary minus
haftmann
parents: 53652
diff changeset
   187
  using assms unfolding diff_conv_add_uminus by (simp del: add_uminus_conv_diff)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   188
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   189
lemma cauchy_imp_bounded:
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   190
  assumes "cauchy X"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   191
  shows "\<exists>b>0. \<forall>n. \<bar>X n\<bar> < b"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   192
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   193
  obtain k where k: "\<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   194
    using cauchyD [OF assms zero_less_one] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   195
  show "\<exists>b>0. \<forall>n. \<bar>X n\<bar> < b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   196
  proof (intro exI conjI allI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   197
    have "0 \<le> \<bar>X 0\<bar>" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   198
    also have "\<bar>X 0\<bar> \<le> Max (abs ` X ` {..k})" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   199
    finally have "0 \<le> Max (abs ` X ` {..k})" .
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   200
    then show "0 < Max (abs ` X ` {..k}) + 1" by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   201
  next
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   202
    fix n :: nat
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   203
    show "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   204
    proof (rule linorder_le_cases)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   205
      assume "n \<le> k"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   206
      then have "\<bar>X n\<bar> \<le> Max (abs ` X ` {..k})" by simp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   207
      then show "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1" by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   208
    next
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   209
      assume "k \<le> n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   210
      have "\<bar>X n\<bar> = \<bar>X k + (X n - X k)\<bar>" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   211
      also have "\<bar>X k + (X n - X k)\<bar> \<le> \<bar>X k\<bar> + \<bar>X n - X k\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   212
        by (rule abs_triangle_ineq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   213
      also have "\<dots> < Max (abs ` X ` {..k}) + 1"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   214
        by (rule add_le_less_mono) (simp_all add: k \<open>k \<le> n\<close>)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   215
      finally show "\<bar>X n\<bar> < Max (abs ` X ` {..k}) + 1" .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   216
    qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   217
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   218
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   219
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   220
lemma cauchy_mult [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   221
  assumes X: "cauchy X" and Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   222
  shows "cauchy (\<lambda>n. X n * Y n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   223
proof (rule cauchyI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   224
  fix r :: rat assume "0 < r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   225
  then obtain u v where u: "0 < u" and v: "0 < v" and "r = u + v"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   226
    by (rule obtain_pos_sum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   227
  obtain a where a: "0 < a" "\<forall>n. \<bar>X n\<bar> < a"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
   228
    using cauchy_imp_bounded [OF X] by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   229
  obtain b where b: "0 < b" "\<forall>n. \<bar>Y n\<bar> < b"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
   230
    using cauchy_imp_bounded [OF Y] by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   231
  obtain s t where s: "0 < s" and t: "0 < t" and r: "r = a * t + s * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   232
  proof
56541
0e3abadbef39 made divide_pos_pos a simp rule
nipkow
parents: 56536
diff changeset
   233
    show "0 < v/b" using v b(1) by simp
0e3abadbef39 made divide_pos_pos a simp rule
nipkow
parents: 56536
diff changeset
   234
    show "0 < u/a" using u a(1) by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   235
    show "r = a * (u/a) + (v/b) * b"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   236
      using a(1) b(1) \<open>r = u + v\<close> by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   237
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   238
  obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   239
    using cauchyD [OF X s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   240
  obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>Y m - Y n\<bar> < t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   241
    using cauchyD [OF Y t] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   242
  have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>X m * Y m - X n * Y n\<bar> < r"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   243
  proof clarsimp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   244
    fix m n
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   245
    assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   246
    have "\<bar>X m * Y m - X n * Y n\<bar> = \<bar>X m * (Y m - Y n) + (X m - X n) * Y n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   247
      unfolding mult_diff_mult ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   248
    also have "\<dots> \<le> \<bar>X m * (Y m - Y n)\<bar> + \<bar>(X m - X n) * Y n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   249
      by (rule abs_triangle_ineq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   250
    also have "\<dots> = \<bar>X m\<bar> * \<bar>Y m - Y n\<bar> + \<bar>X m - X n\<bar> * \<bar>Y n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   251
      unfolding abs_mult ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   252
    also have "\<dots> < a * t + s * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   253
      by (simp_all add: add_strict_mono mult_strict_mono' a b i j *)
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   254
    finally show "\<bar>X m * Y m - X n * Y n\<bar> < r"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   255
      by (simp only: r)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   256
  qed
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   257
  then show "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m * Y m - X n * Y n\<bar> < r" ..
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   258
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   259
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   260
lemma cauchy_not_vanishes_cases:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   261
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   262
  assumes nz: "\<not> vanishes X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   263
  shows "\<exists>b>0. \<exists>k. (\<forall>n\<ge>k. b < - X n) \<or> (\<forall>n\<ge>k. b < X n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   264
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   265
  obtain r where "0 < r" and r: "\<forall>k. \<exists>n\<ge>k. r \<le> \<bar>X n\<bar>"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   266
    using nz unfolding vanishes_def by (auto simp add: not_less)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   267
  obtain s t where s: "0 < s" and t: "0 < t" and "r = s + t"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   268
    using \<open>0 < r\<close> by (rule obtain_pos_sum)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   269
  obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>X m - X n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   270
    using cauchyD [OF X s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   271
  obtain k where "i \<le> k" and "r \<le> \<bar>X k\<bar>"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
   272
    using r by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   273
  have k: "\<forall>n\<ge>k. \<bar>X n - X k\<bar> < s"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   274
    using i \<open>i \<le> k\<close> by auto
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   275
  have "X k \<le> - r \<or> r \<le> X k"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   276
    using \<open>r \<le> \<bar>X k\<bar>\<close> by auto
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   277
  then have "(\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   278
    unfolding \<open>r = s + t\<close> using k by auto
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   279
  then have "\<exists>k. (\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)" ..
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   280
  then show "\<exists>t>0. \<exists>k. (\<forall>n\<ge>k. t < - X n) \<or> (\<forall>n\<ge>k. t < X n)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   281
    using t by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   282
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   283
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   284
lemma cauchy_not_vanishes:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   285
  assumes X: "cauchy X"
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   286
    and nz: "\<not> vanishes X"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   287
  shows "\<exists>b>0. \<exists>k. \<forall>n\<ge>k. b < \<bar>X n\<bar>"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   288
  using cauchy_not_vanishes_cases [OF assms]
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   289
  by (elim ex_forward conj_forward asm_rl) auto
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   290
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   291
lemma cauchy_inverse [simp]:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   292
  assumes X: "cauchy X"
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   293
    and nz: "\<not> vanishes X"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   294
  shows "cauchy (\<lambda>n. inverse (X n))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   295
proof (rule cauchyI)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   296
  fix r :: rat
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   297
  assume "0 < r"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   298
  obtain b i where b: "0 < b" and i: "\<forall>n\<ge>i. b < \<bar>X n\<bar>"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
   299
    using cauchy_not_vanishes [OF X nz] by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   300
  from b i have nz: "\<forall>n\<ge>i. X n \<noteq> 0" by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   301
  obtain s where s: "0 < s" and r: "r = inverse b * s * inverse b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   302
  proof
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   303
    show "0 < b * r * b" by (simp add: \<open>0 < r\<close> b)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   304
    show "r = inverse b * (b * r * b) * inverse b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   305
      using b by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   306
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   307
  obtain j where j: "\<forall>m\<ge>j. \<forall>n\<ge>j. \<bar>X m - X n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   308
    using cauchyD [OF X s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   309
  have "\<forall>m\<ge>max i j. \<forall>n\<ge>max i j. \<bar>inverse (X m) - inverse (X n)\<bar> < r"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   310
  proof clarsimp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   311
    fix m n
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   312
    assume *: "i \<le> m" "j \<le> m" "i \<le> n" "j \<le> n"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   313
    have "\<bar>inverse (X m) - inverse (X n)\<bar> = inverse \<bar>X m\<bar> * \<bar>X m - X n\<bar> * inverse \<bar>X n\<bar>"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   314
      by (simp add: inverse_diff_inverse nz * abs_mult)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   315
    also have "\<dots> < inverse b * s * inverse b"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   316
      by (simp add: mult_strict_mono less_imp_inverse_less i j b * s)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   317
    finally show "\<bar>inverse (X m) - inverse (X n)\<bar> < r" by (simp only: r)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   318
  qed
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   319
  then show "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>inverse (X m) - inverse (X n)\<bar> < r" ..
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   320
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   321
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   322
lemma vanishes_diff_inverse:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   323
  assumes X: "cauchy X" "\<not> vanishes X"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   324
    and Y: "cauchy Y" "\<not> vanishes Y"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   325
    and XY: "vanishes (\<lambda>n. X n - Y n)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   326
  shows "vanishes (\<lambda>n. inverse (X n) - inverse (Y n))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   327
proof (rule vanishesI)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   328
  fix r :: rat
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   329
  assume r: "0 < r"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   330
  obtain a i where a: "0 < a" and i: "\<forall>n\<ge>i. a < \<bar>X n\<bar>"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
   331
    using cauchy_not_vanishes [OF X] by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   332
  obtain b j where b: "0 < b" and j: "\<forall>n\<ge>j. b < \<bar>Y n\<bar>"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
   333
    using cauchy_not_vanishes [OF Y] by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   334
  obtain s where s: "0 < s" and "inverse a * s * inverse b = r"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   335
  proof
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   336
    show "0 < a * r * b"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   337
      using a r b by simp
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   338
    show "inverse a * (a * r * b) * inverse b = r"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   339
      using a r b by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   340
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   341
  obtain k where k: "\<forall>n\<ge>k. \<bar>X n - Y n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   342
    using vanishesD [OF XY s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   343
  have "\<forall>n\<ge>max (max i j) k. \<bar>inverse (X n) - inverse (Y n)\<bar> < r"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   344
  proof clarsimp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   345
    fix n
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   346
    assume n: "i \<le> n" "j \<le> n" "k \<le> n"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   347
    with i j a b have "X n \<noteq> 0" and "Y n \<noteq> 0"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   348
      by auto
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   349
    then have "\<bar>inverse (X n) - inverse (Y n)\<bar> = inverse \<bar>X n\<bar> * \<bar>X n - Y n\<bar> * inverse \<bar>Y n\<bar>"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   350
      by (simp add: inverse_diff_inverse abs_mult)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   351
    also have "\<dots> < inverse a * s * inverse b"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   352
      by (intro mult_strict_mono' less_imp_inverse_less) (simp_all add: a b i j k n)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   353
    also note \<open>inverse a * s * inverse b = r\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   354
    finally show "\<bar>inverse (X n) - inverse (Y n)\<bar> < r" .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   355
  qed
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   356
  then show "\<exists>k. \<forall>n\<ge>k. \<bar>inverse (X n) - inverse (Y n)\<bar> < r" ..
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   357
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   358
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   359
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   360
subsection \<open>Equivalence relation on Cauchy sequences\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   361
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   362
definition realrel :: "(nat \<Rightarrow> rat) \<Rightarrow> (nat \<Rightarrow> rat) \<Rightarrow> bool"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   363
  where "realrel = (\<lambda>X Y. cauchy X \<and> cauchy Y \<and> vanishes (\<lambda>n. X n - Y n))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   364
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   365
lemma realrelI [intro?]: "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> vanishes (\<lambda>n. X n - Y n) \<Longrightarrow> realrel X Y"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   366
  by (simp add: realrel_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   367
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   368
lemma realrel_refl: "cauchy X \<Longrightarrow> realrel X X"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   369
  by (simp add: realrel_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   370
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   371
lemma symp_realrel: "symp realrel"
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   372
  by (simp add: abs_minus_commute realrel_def symp_def vanishes_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   373
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   374
lemma transp_realrel: "transp realrel"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   375
  unfolding realrel_def
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   376
  by (rule transpI) (force simp add: dest: vanishes_add)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   377
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   378
lemma part_equivp_realrel: "part_equivp realrel"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   379
  by (blast intro: part_equivpI symp_realrel transp_realrel realrel_refl cauchy_const)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   380
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   381
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   382
subsection \<open>The field of real numbers\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   383
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   384
quotient_type real = "nat \<Rightarrow> rat" / partial: realrel
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   385
  morphisms rep_real Real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   386
  by (rule part_equivp_realrel)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   387
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   388
lemma cr_real_eq: "pcr_real = (\<lambda>x y. cauchy x \<and> Real x = y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   389
  unfolding real.pcr_cr_eq cr_real_def realrel_def by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   390
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   391
lemma Real_induct [induct type: real]: (* TODO: generate automatically *)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   392
  assumes "\<And>X. cauchy X \<Longrightarrow> P (Real X)"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   393
  shows "P x"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   394
proof (induct x)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   395
  case (1 X)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   396
  then have "cauchy X" by (simp add: realrel_def)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   397
  then show "P (Real X)" by (rule assms)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   398
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   399
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   400
lemma eq_Real: "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> Real X = Real Y \<longleftrightarrow> vanishes (\<lambda>n. X n - Y n)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   401
  using real.rel_eq_transfer
55945
e96383acecf9 renamed 'fun_rel' to 'rel_fun'
blanchet
parents: 54863
diff changeset
   402
  unfolding real.pcr_cr_eq cr_real_def rel_fun_def realrel_def by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   403
51956
a4d81cdebf8b better support for domains in Lifting/Transfer = replace Domainp T by the actual invariant in a transferred goal
kuncar
parents: 51775
diff changeset
   404
lemma Domainp_pcr_real [transfer_domain_rule]: "Domainp pcr_real = cauchy"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   405
  by (simp add: real.domain_eq realrel_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   406
59867
58043346ca64 given up separate type classes demanding `inverse 0 = 0`
haftmann
parents: 59587
diff changeset
   407
instantiation real :: field
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   408
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   409
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   410
lift_definition zero_real :: "real" is "\<lambda>n. 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   411
  by (simp add: realrel_refl)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   412
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   413
lift_definition one_real :: "real" is "\<lambda>n. 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   414
  by (simp add: realrel_refl)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   415
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   416
lift_definition plus_real :: "real \<Rightarrow> real \<Rightarrow> real" is "\<lambda>X Y n. X n + Y n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   417
  unfolding realrel_def add_diff_add
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   418
  by (simp only: cauchy_add vanishes_add simp_thms)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   419
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   420
lift_definition uminus_real :: "real \<Rightarrow> real" is "\<lambda>X n. - X n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   421
  unfolding realrel_def minus_diff_minus
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   422
  by (simp only: cauchy_minus vanishes_minus simp_thms)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   423
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   424
lift_definition times_real :: "real \<Rightarrow> real \<Rightarrow> real" is "\<lambda>X Y n. X n * Y n"
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   425
proof -
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   426
  fix f1 f2 f3 f4
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   427
  have "\<lbrakk>cauchy f1; cauchy f4; vanishes (\<lambda>n. f1 n - f2 n); vanishes (\<lambda>n. f3 n - f4 n)\<rbrakk>
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   428
       \<Longrightarrow> vanishes (\<lambda>n. f1 n * (f3 n - f4 n) + f4 n * (f1 n - f2 n))"
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   429
    by (simp add: vanishes_add vanishes_mult_bounded cauchy_imp_bounded)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   430
  then show "\<lbrakk>realrel f1 f2; realrel f3 f4\<rbrakk> \<Longrightarrow> realrel (\<lambda>n. f1 n * f3 n) (\<lambda>n. f2 n * f4 n)"
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   431
    by (simp add: mult.commute realrel_def mult_diff_mult)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   432
qed
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   433
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   434
lift_definition inverse_real :: "real \<Rightarrow> real"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   435
  is "\<lambda>X. if vanishes X then (\<lambda>n. 0) else (\<lambda>n. inverse (X n))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   436
proof -
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   437
  fix X Y
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   438
  assume "realrel X Y"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   439
  then have X: "cauchy X" and Y: "cauchy Y" and XY: "vanishes (\<lambda>n. X n - Y n)"
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   440
    by (simp_all add: realrel_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   441
  have "vanishes X \<longleftrightarrow> vanishes Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   442
  proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   443
    assume "vanishes X"
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   444
    from vanishes_diff [OF this XY] show "vanishes Y"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   445
      by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   446
  next
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   447
    assume "vanishes Y"
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   448
    from vanishes_add [OF this XY] show "vanishes X"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   449
      by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   450
  qed
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   451
  then show "?thesis X Y"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   452
    by (simp add: vanishes_diff_inverse X Y XY realrel_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   453
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   454
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   455
definition "x - y = x + - y" for x y :: real
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   456
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   457
definition "x div y = x * inverse y" for x y :: real
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   458
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   459
lemma add_Real: "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> Real X + Real Y = Real (\<lambda>n. X n + Y n)"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   460
  using plus_real.transfer by (simp add: cr_real_eq rel_fun_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   461
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   462
lemma minus_Real: "cauchy X \<Longrightarrow> - Real X = Real (\<lambda>n. - X n)"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   463
  using uminus_real.transfer by (simp add: cr_real_eq rel_fun_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   464
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   465
lemma diff_Real: "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> Real X - Real Y = Real (\<lambda>n. X n - Y n)"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   466
  by (simp add: minus_Real add_Real minus_real_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   467
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   468
lemma mult_Real: "cauchy X \<Longrightarrow> cauchy Y \<Longrightarrow> Real X * Real Y = Real (\<lambda>n. X n * Y n)"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   469
  using times_real.transfer by (simp add: cr_real_eq rel_fun_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   470
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   471
lemma inverse_Real:
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   472
  "cauchy X \<Longrightarrow> inverse (Real X) = (if vanishes X then 0 else Real (\<lambda>n. inverse (X n)))"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   473
  using inverse_real.transfer zero_real.transfer
62390
842917225d56 more canonical names
nipkow
parents: 62348
diff changeset
   474
  unfolding cr_real_eq rel_fun_def by (simp split: if_split_asm, metis)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   475
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   476
instance
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   477
proof
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   478
  fix a b c :: real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   479
  show "a + b = b + a"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   480
    by transfer (simp add: ac_simps realrel_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   481
  show "(a + b) + c = a + (b + c)"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   482
    by transfer (simp add: ac_simps realrel_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   483
  show "0 + a = a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   484
    by transfer (simp add: realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   485
  show "- a + a = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   486
    by transfer (simp add: realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   487
  show "a - b = a + - b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   488
    by (rule minus_real_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   489
  show "(a * b) * c = a * (b * c)"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   490
    by transfer (simp add: ac_simps realrel_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   491
  show "a * b = b * a"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   492
    by transfer (simp add: ac_simps realrel_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   493
  show "1 * a = a"
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   494
    by transfer (simp add: ac_simps realrel_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   495
  show "(a + b) * c = a * c + b * c"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   496
    by transfer (simp add: distrib_right realrel_def)
61076
bdc1e2f0a86a eliminated \<Colon>;
wenzelm
parents: 61070
diff changeset
   497
  show "(0::real) \<noteq> (1::real)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   498
    by transfer (simp add: realrel_def)
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   499
  have "vanishes (\<lambda>n. inverse (X n) * X n - 1)" if X: "cauchy X" "\<not> vanishes X" for X
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   500
  proof (rule vanishesI)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   501
    fix r::rat
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   502
    assume "0 < r"
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   503
    obtain b k where "b>0" "\<forall>n\<ge>k. b < \<bar>X n\<bar>"
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   504
      using X cauchy_not_vanishes by blast
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   505
    then show "\<exists>k. \<forall>n\<ge>k. \<bar>inverse (X n) * X n - 1\<bar> < r" 
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   506
      using \<open>0 < r\<close> by force
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   507
  qed
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   508
  then show "a \<noteq> 0 \<Longrightarrow> inverse a * a = 1"
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   509
    by transfer (simp add: realrel_def)
60429
d3d1e185cd63 uniform _ div _ as infix syntax for ring division
haftmann
parents: 60352
diff changeset
   510
  show "a div b = a * inverse b"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   511
    by (rule divide_real_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   512
  show "inverse (0::real) = 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   513
    by transfer (simp add: realrel_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   514
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   515
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   516
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   517
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   518
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   519
subsection \<open>Positive reals\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   520
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   521
lift_definition positive :: "real \<Rightarrow> bool"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   522
  is "\<lambda>X. \<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   523
proof -
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   524
  have 1: "\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < Y n"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   525
    if *: "realrel X Y" and **: "\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n" for X Y
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   526
  proof -
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   527
    from * have XY: "vanishes (\<lambda>n. X n - Y n)"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   528
      by (simp_all add: realrel_def)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   529
    from ** obtain r i where "0 < r" and i: "\<forall>n\<ge>i. r < X n"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
   530
      by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   531
    obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   532
      using \<open>0 < r\<close> by (rule obtain_pos_sum)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   533
    obtain j where j: "\<forall>n\<ge>j. \<bar>X n - Y n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   534
      using vanishesD [OF XY s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   535
    have "\<forall>n\<ge>max i j. t < Y n"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   536
    proof clarsimp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   537
      fix n
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   538
      assume n: "i \<le> n" "j \<le> n"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   539
      have "\<bar>X n - Y n\<bar> < s" and "r < X n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   540
        using i j n by simp_all
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   541
      then show "t < Y n" by (simp add: r)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   542
    qed
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   543
    then show ?thesis using t by blast
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   544
  qed
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   545
  fix X Y assume "realrel X Y"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   546
  then have "realrel X Y" and "realrel Y X"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   547
    using symp_realrel by (auto simp: symp_def)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   548
  then show "?thesis X Y"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   549
    by (safe elim!: 1)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   550
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   551
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   552
lemma positive_Real: "cauchy X \<Longrightarrow> positive (Real X) \<longleftrightarrow> (\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n)"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   553
  using positive.transfer by (simp add: cr_real_eq rel_fun_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   554
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   555
lemma positive_zero: "\<not> positive 0"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   556
  by transfer auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   557
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   558
lemma positive_add: 
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   559
  assumes "positive x" "positive y" shows "positive (x + y)"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   560
proof -
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   561
  have *: "\<lbrakk>\<forall>n\<ge>i. a < x n; \<forall>n\<ge>j. b < y n; 0 < a; 0 < b; n \<ge> max i j\<rbrakk>
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   562
       \<Longrightarrow> a+b < x n + y n" for x y and a b::rat and i j n::nat
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   563
    by (simp add: add_strict_mono)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   564
  show ?thesis
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   565
    using assms
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   566
    by transfer (blast intro: * pos_add_strict)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   567
qed
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   568
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   569
lemma positive_mult: 
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   570
  assumes "positive x" "positive y" shows "positive (x * y)"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   571
proof -
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   572
  have *: "\<lbrakk>\<forall>n\<ge>i. a < x n; \<forall>n\<ge>j. b < y n; 0 < a; 0 < b; n \<ge> max i j\<rbrakk>
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   573
       \<Longrightarrow> a*b < x n * y n" for x y and a b::rat and i j n::nat
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   574
    by (simp add: mult_strict_mono')
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   575
  show ?thesis
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   576
    using assms
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   577
    by transfer (blast intro: *  mult_pos_pos)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   578
qed
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   579
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   580
lemma positive_minus: "\<not> positive x \<Longrightarrow> x \<noteq> 0 \<Longrightarrow> positive (- x)"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   581
  apply transfer
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   582
  apply (simp add: realrel_def)
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   583
  apply (blast dest: cauchy_not_vanishes_cases)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   584
  done
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   585
59867
58043346ca64 given up separate type classes demanding `inverse 0 = 0`
haftmann
parents: 59587
diff changeset
   586
instantiation real :: linordered_field
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   587
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   588
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   589
definition "x < y \<longleftrightarrow> positive (y - x)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   590
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   591
definition "x \<le> y \<longleftrightarrow> x < y \<or> x = y" for x y :: real
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   592
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   593
definition "\<bar>a\<bar> = (if a < 0 then - a else a)" for a :: real
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   594
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   595
definition "sgn a = (if a = 0 then 0 else if 0 < a then 1 else - 1)" for a :: real
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   596
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   597
instance
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   598
proof
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   599
  fix a b c :: real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   600
  show "\<bar>a\<bar> = (if a < 0 then - a else a)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   601
    by (rule abs_real_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   602
  show "a < b \<longleftrightarrow> a \<le> b \<and> \<not> b \<le> a"
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   603
       "a \<le> b \<Longrightarrow> b \<le> c \<Longrightarrow> a \<le> c"  "a \<le> a" 
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   604
       "a \<le> b \<Longrightarrow> b \<le> a \<Longrightarrow> a = b"
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   605
       "a \<le> b \<Longrightarrow> c + a \<le> c + b"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   606
    unfolding less_eq_real_def less_real_def
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   607
    by (force simp add: positive_zero dest: positive_add)+
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   608
  show "sgn a = (if a = 0 then 0 else if 0 < a then 1 else - 1)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   609
    by (rule sgn_real_def)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   610
  show "a \<le> b \<or> b \<le> a"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   611
    by (auto dest!: positive_minus simp: less_eq_real_def less_real_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   612
  show "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   613
    unfolding less_real_def
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   614
    by (force simp add: algebra_simps dest: positive_mult)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   615
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   616
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   617
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   618
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   619
instantiation real :: distrib_lattice
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   620
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   621
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   622
definition "(inf :: real \<Rightarrow> real \<Rightarrow> real) = min"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   623
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   624
definition "(sup :: real \<Rightarrow> real \<Rightarrow> real) = max"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   625
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   626
instance
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   627
  by standard (auto simp add: inf_real_def sup_real_def max_min_distrib2)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   628
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   629
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   630
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   631
lemma of_nat_Real: "of_nat x = Real (\<lambda>n. of_nat x)"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   632
  by (induct x) (simp_all add: zero_real_def one_real_def add_Real)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   633
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   634
lemma of_int_Real: "of_int x = Real (\<lambda>n. of_int x)"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   635
  by (cases x rule: int_diff_cases) (simp add: of_nat_Real diff_Real)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   636
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   637
lemma of_rat_Real: "of_rat x = Real (\<lambda>n. x)"
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   638
proof (induct x)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   639
  case (Fract a b)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   640
  then show ?case 
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   641
  apply (simp add: Fract_of_int_quotient of_rat_divide)
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   642
  apply (simp add: of_int_Real divide_inverse inverse_Real mult_Real)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   643
  done
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   644
qed
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   645
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   646
instance real :: archimedean_field
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   647
proof
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   648
  show "\<exists>z. x \<le> of_int z" for x :: real
68662
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   649
  proof (induct x)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   650
    case (1 X)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   651
    then obtain b where "0 < b" and b: "\<And>n. \<bar>X n\<bar> < b"
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   652
      by (blast dest: cauchy_imp_bounded)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   653
    then have "Real X < of_int (\<lceil>b\<rceil> + 1)"
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   654
      using 1
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   655
      apply (simp add: of_int_Real less_real_def diff_Real positive_Real)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   656
      apply (rule_tac x=1 in exI)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   657
      apply (simp add: algebra_simps)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   658
      by (metis abs_ge_self le_less_trans le_of_int_ceiling less_le)
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   659
    then show ?case
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   660
      using less_eq_real_def by blast 
227f85b1b98c de-applying
paulson <lp15@cam.ac.uk>
parents: 68529
diff changeset
   661
  qed
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   662
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   663
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   664
instantiation real :: floor_ceiling
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   665
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   666
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   667
definition [code del]: "\<lfloor>x::real\<rfloor> = (THE z. of_int z \<le> x \<and> x < of_int (z + 1))"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   668
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
   669
instance
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
   670
proof
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   671
  show "of_int \<lfloor>x\<rfloor> \<le> x \<and> x < of_int (\<lfloor>x\<rfloor> + 1)" for x :: real
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   672
    unfolding floor_real_def using floor_exists1 by (rule theI')
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   673
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   674
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   675
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   676
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   677
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   678
subsection \<open>Completeness\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   679
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   680
lemma not_positive_Real: 
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   681
  assumes "cauchy X" shows "\<not> positive (Real X) \<longleftrightarrow> (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. X n \<le> r)" (is "?lhs = ?rhs")
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   682
  unfolding positive_Real [OF assms]
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   683
proof (intro iffI allI notI impI)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   684
  show "\<exists>k. \<forall>n\<ge>k. X n \<le> r" if r: "\<not> (\<exists>r>0. \<exists>k. \<forall>n\<ge>k. r < X n)" and "0 < r" for r
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   685
  proof -
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   686
    obtain s t where "s > 0" "t > 0" "r = s+t"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   687
      using \<open>r > 0\<close> obtain_pos_sum by blast
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   688
    obtain k where k: "\<And>m n. \<lbrakk>m\<ge>k; n\<ge>k\<rbrakk> \<Longrightarrow> \<bar>X m - X n\<bar> < t"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   689
      using cauchyD [OF assms \<open>t > 0\<close>] by blast
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   690
    obtain n where "n \<ge> k" "X n \<le> s"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   691
      by (meson r \<open>0 < s\<close> not_less)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   692
    then have "X l \<le> r" if "l \<ge> n" for l
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   693
      using k [OF \<open>n \<ge> k\<close>, of l] that \<open>r = s+t\<close> by linarith
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   694
    then show ?thesis
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   695
      by blast
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   696
    qed
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   697
qed (meson le_cases not_le)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   698
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   699
lemma le_Real:
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   700
  assumes "cauchy X" "cauchy Y"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   701
  shows "Real X \<le> Real Y = (\<forall>r>0. \<exists>k. \<forall>n\<ge>k. X n \<le> Y n + r)"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   702
  unfolding not_less [symmetric, where 'a=real] less_real_def
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   703
  apply (simp add: diff_Real not_positive_Real assms)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   704
  apply (simp add: diff_le_eq ac_simps)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   705
  done
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   706
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   707
lemma le_RealI:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   708
  assumes Y: "cauchy Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   709
  shows "\<forall>n. x \<le> of_rat (Y n) \<Longrightarrow> x \<le> Real Y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   710
proof (induct x)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   711
  fix X
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   712
  assume X: "cauchy X" and "\<forall>n. Real X \<le> of_rat (Y n)"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   713
  then have le: "\<And>m r. 0 < r \<Longrightarrow> \<exists>k. \<forall>n\<ge>k. X n \<le> Y m + r"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   714
    by (simp add: of_rat_Real le_Real)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   715
  then have "\<exists>k. \<forall>n\<ge>k. X n \<le> Y n + r" if "0 < r" for r :: rat
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   716
  proof -
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   717
    from that obtain s t where s: "0 < s" and t: "0 < t" and r: "r = s + t"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   718
      by (rule obtain_pos_sum)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   719
    obtain i where i: "\<forall>m\<ge>i. \<forall>n\<ge>i. \<bar>Y m - Y n\<bar> < s"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   720
      using cauchyD [OF Y s] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   721
    obtain j where j: "\<forall>n\<ge>j. X n \<le> Y i + t"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   722
      using le [OF t] ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   723
    have "\<forall>n\<ge>max i j. X n \<le> Y n + r"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   724
    proof clarsimp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   725
      fix n
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   726
      assume n: "i \<le> n" "j \<le> n"
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   727
      have "X n \<le> Y i + t"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   728
        using n j by simp
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   729
      moreover have "\<bar>Y i - Y n\<bar> < s"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   730
        using n i by simp
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   731
      ultimately show "X n \<le> Y n + r"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   732
        unfolding r by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   733
    qed
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   734
    then show ?thesis ..
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   735
  qed
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   736
  then show "Real X \<le> Real Y"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   737
    by (simp add: of_rat_Real le_Real X Y)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   738
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   739
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   740
lemma Real_leI:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   741
  assumes X: "cauchy X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   742
  assumes le: "\<forall>n. of_rat (X n) \<le> y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   743
  shows "Real X \<le> y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   744
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   745
  have "- y \<le> - Real X"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   746
    by (simp add: minus_Real X le_RealI of_rat_minus le)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   747
  then show ?thesis by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   748
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   749
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   750
lemma less_RealD:
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   751
  assumes "cauchy Y"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   752
  shows "x < Real Y \<Longrightarrow> \<exists>n. x < of_rat (Y n)"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   753
  apply (erule contrapos_pp)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   754
  apply (simp add: not_less)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   755
  apply (erule Real_leI [OF assms])
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   756
  done
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   757
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   758
lemma of_nat_less_two_power [simp]: "of_nat n < (2::'a::linordered_idom) ^ n"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   759
  apply (induct n)
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   760
   apply simp
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   761
  apply (metis add_le_less_mono mult_2 of_nat_Suc one_le_numeral one_le_power power_Suc)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   762
  done
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   763
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   764
lemma complete_real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   765
  fixes S :: "real set"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   766
  assumes "\<exists>x. x \<in> S" and "\<exists>z. \<forall>x\<in>S. x \<le> z"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   767
  shows "\<exists>y. (\<forall>x\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> y \<le> z)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   768
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   769
  obtain x where x: "x \<in> S" using assms(1) ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   770
  obtain z where z: "\<forall>x\<in>S. x \<le> z" using assms(2) ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   771
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62626
diff changeset
   772
  define P where "P x \<longleftrightarrow> (\<forall>y\<in>S. y \<le> of_rat x)" for x
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   773
  obtain a where a: "\<not> P a"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   774
  proof
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
   775
    have "of_int \<lfloor>x - 1\<rfloor> \<le> x - 1" by (rule of_int_floor_le)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   776
    also have "x - 1 < x" by simp
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
   777
    finally have "of_int \<lfloor>x - 1\<rfloor> < x" .
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   778
    then have "\<not> x \<le> of_int \<lfloor>x - 1\<rfloor>" by (simp only: not_le)
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
   779
    then show "\<not> P (of_int \<lfloor>x - 1\<rfloor>)"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
   780
      unfolding P_def of_rat_of_int_eq using x by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   781
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   782
  obtain b where b: "P b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   783
  proof
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
   784
    show "P (of_int \<lceil>z\<rceil>)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   785
    unfolding P_def of_rat_of_int_eq
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   786
    proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   787
      fix y assume "y \<in> S"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   788
      then have "y \<le> z" using z by simp
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
   789
      also have "z \<le> of_int \<lceil>z\<rceil>" by (rule le_of_int_ceiling)
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
   790
      finally show "y \<le> of_int \<lceil>z\<rceil>" .
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   791
    qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   792
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   793
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62626
diff changeset
   794
  define avg where "avg x y = x/2 + y/2" for x y :: rat
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62626
diff changeset
   795
  define bisect where "bisect = (\<lambda>(x, y). if P (avg x y) then (x, avg x y) else (avg x y, y))"
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62626
diff changeset
   796
  define A where "A n = fst ((bisect ^^ n) (a, b))" for n
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62626
diff changeset
   797
  define B where "B n = snd ((bisect ^^ n) (a, b))" for n
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62626
diff changeset
   798
  define C where "C n = avg (A n) (B n)" for n
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   799
  have A_0 [simp]: "A 0 = a" unfolding A_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   800
  have B_0 [simp]: "B 0 = b" unfolding B_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   801
  have A_Suc [simp]: "\<And>n. A (Suc n) = (if P (C n) then A n else C n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   802
    unfolding A_def B_def C_def bisect_def split_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   803
  have B_Suc [simp]: "\<And>n. B (Suc n) = (if P (C n) then C n else B n)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   804
    unfolding A_def B_def C_def bisect_def split_def by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   805
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   806
  have width: "B n - A n = (b - a) / 2^n" for n
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   807
  proof (induct n)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   808
    case (Suc n)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   809
    then show ?case
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   810
      by (simp add: C_def eq_divide_eq avg_def algebra_simps)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   811
  qed simp
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   812
  have twos: "\<exists>n. y / 2 ^ n < r" if "0 < r" for y r :: rat
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   813
  proof -
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   814
    obtain n where "y / r < rat_of_nat n"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   815
      using \<open>0 < r\<close> reals_Archimedean2 by blast
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   816
    then have "\<exists>n. y < r * 2 ^ n"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   817
      by (metis divide_less_eq less_trans mult.commute of_nat_less_two_power that)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   818
    then show ?thesis
70817
dd675800469d dedicated fact collections for algebraic simplification rules potentially splitting goals
haftmann
parents: 70356
diff changeset
   819
      by (simp add: field_split_simps)
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   820
  qed
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   821
  have PA: "\<not> P (A n)" for n
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   822
    by (induct n) (simp_all add: a)
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   823
  have PB: "P (B n)" for n
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   824
    by (induct n) (simp_all add: b)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   825
  have ab: "a < b"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   826
    using a b unfolding P_def
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   827
    by (meson leI less_le_trans of_rat_less)
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   828
  have AB: "A n < B n" for n
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   829
    by (induct n) (simp_all add: ab C_def avg_def)
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   830
  have  "A i \<le> A j \<and>  B j \<le> B i" if "i < j" for i j
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   831
    using that
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   832
  proof (induction rule: less_Suc_induct)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   833
    case (1 i)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   834
    then show ?case
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   835
      apply (clarsimp simp add: C_def avg_def add_divide_distrib [symmetric])
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   836
      apply (rule AB [THEN less_imp_le])
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   837
      done  
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   838
  qed simp
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   839
  then have A_mono: "A i \<le> A j" and B_mono: "B j \<le> B i" if "i \<le> j" for i j
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   840
    by (metis eq_refl le_neq_implies_less that)+
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   841
  have cauchy_lemma: "cauchy X" if *: "\<And>n i. i\<ge>n \<Longrightarrow> A n \<le> X i \<and> X i \<le> B n" for X
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   842
  proof (rule cauchyI)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   843
    fix r::rat
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   844
    assume "0 < r"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   845
    then obtain k where k: "(b - a) / 2 ^ k < r"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   846
      using twos by blast
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   847
    have "\<bar>X m - X n\<bar> < r" if "m\<ge>k" "n\<ge>k" for m n
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   848
    proof -
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   849
      have "\<bar>X m - X n\<bar> \<le> B k - A k"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   850
        by (simp add: * abs_rat_def diff_mono that)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   851
      also have "... < r"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   852
        by (simp add: k width)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   853
      finally show ?thesis .
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   854
    qed
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   855
    then show "\<exists>k. \<forall>m\<ge>k. \<forall>n\<ge>k. \<bar>X m - X n\<bar> < r"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   856
      by blast 
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   857
  qed
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   858
  have "cauchy A"
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   859
    by (rule cauchy_lemma) (meson AB A_mono B_mono dual_order.strict_implies_order less_le_trans)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   860
  have "cauchy B"
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   861
    by (rule cauchy_lemma) (meson AB A_mono B_mono dual_order.strict_implies_order le_less_trans)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   862
  have "\<forall>x\<in>S. x \<le> Real B"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   863
  proof
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   864
    fix x
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   865
    assume "x \<in> S"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   866
    then show "x \<le> Real B"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   867
      using PB [unfolded P_def] \<open>cauchy B\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   868
      by (simp add: le_RealI)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   869
  qed
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   870
  moreover have "\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> Real A \<le> z"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   871
    by (meson PA Real_leI P_def \<open>cauchy A\<close> le_cases order.trans)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   872
  moreover have "vanishes (\<lambda>n. (b - a) / 2 ^ n)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   873
  proof (rule vanishesI)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   874
    fix r :: rat
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   875
    assume "0 < r"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   876
    then obtain k where k: "\<bar>b - a\<bar> / 2 ^ k < r"
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
   877
      using twos by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   878
    have "\<forall>n\<ge>k. \<bar>(b - a) / 2 ^ n\<bar> < r"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   879
    proof clarify
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   880
      fix n
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   881
      assume n: "k \<le> n"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   882
      have "\<bar>(b - a) / 2 ^ n\<bar> = \<bar>b - a\<bar> / 2 ^ n"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   883
        by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   884
      also have "\<dots> \<le> \<bar>b - a\<bar> / 2 ^ k"
56544
b60d5d119489 made mult_pos_pos a simp rule
nipkow
parents: 56541
diff changeset
   885
        using n by (simp add: divide_left_mono)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   886
      also note k
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   887
      finally show "\<bar>(b - a) / 2 ^ n\<bar> < r" .
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   888
    qed
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   889
    then show "\<exists>k. \<forall>n\<ge>k. \<bar>(b - a) / 2 ^ n\<bar> < r" ..
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   890
  qed
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   891
  then have "Real B = Real A"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   892
    by (simp add: eq_Real \<open>cauchy A\<close> \<open>cauchy B\<close> width)
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   893
  ultimately show "\<exists>y. (\<forall>x\<in>S. x \<le> y) \<and> (\<forall>z. (\<forall>x\<in>S. x \<le> z) \<longrightarrow> y \<le> z)"
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
   894
    by force
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   895
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   896
51775
408d937c9486 revert #916271d52466; add non-topological linear_continuum type class; show linear_continuum_topology is a perfect_space
hoelzl
parents: 51773
diff changeset
   897
instantiation real :: linear_continuum
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   898
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   899
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   900
subsection \<open>Supremum of a set of reals\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   901
54281
b01057e72233 int and nat are conditionally_complete_lattices
hoelzl
parents: 54263
diff changeset
   902
definition "Sup X = (LEAST z::real. \<forall>x\<in>X. x \<le> z)"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   903
definition "Inf X = - Sup (uminus ` X)" for X :: "real set"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   904
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   905
instance
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   906
proof
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   907
  show Sup_upper: "x \<le> Sup X"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   908
    if "x \<in> X" "bdd_above X"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   909
    for x :: real and X :: "real set"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   910
  proof -
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   911
    from that obtain s where s: "\<forall>y\<in>X. y \<le> s" "\<And>z. \<forall>y\<in>X. y \<le> z \<Longrightarrow> s \<le> z"
54258
adfc759263ab use bdd_above and bdd_below for conditionally complete lattices
hoelzl
parents: 54230
diff changeset
   912
      using complete_real[of X] unfolding bdd_above_def by blast
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   913
    then show ?thesis
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   914
      unfolding Sup_real_def by (rule LeastI2_order) (auto simp: that)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   915
  qed
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   916
  show Sup_least: "Sup X \<le> z"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   917
    if "X \<noteq> {}" and z: "\<And>x. x \<in> X \<Longrightarrow> x \<le> z"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   918
    for z :: real and X :: "real set"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   919
  proof -
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   920
    from that obtain s where s: "\<forall>y\<in>X. y \<le> s" "\<And>z. \<forall>y\<in>X. y \<le> z \<Longrightarrow> s \<le> z"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   921
      using complete_real [of X] by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   922
    then have "Sup X = s"
61284
2314c2f62eb1 real_of_nat_Suc is now a simprule
paulson <lp15@cam.ac.uk>
parents: 61204
diff changeset
   923
      unfolding Sup_real_def by (best intro: Least_equality)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   924
    also from s z have "\<dots> \<le> z"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   925
      by blast
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   926
    finally show ?thesis .
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   927
  qed
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   928
  show "Inf X \<le> x" if "x \<in> X" "bdd_below X"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   929
    for x :: real and X :: "real set"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   930
    using Sup_upper [of "-x" "uminus ` X"] by (auto simp: Inf_real_def that)
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   931
  show "z \<le> Inf X" if "X \<noteq> {}" "\<And>x. x \<in> X \<Longrightarrow> z \<le> x"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   932
    for z :: real and X :: "real set"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   933
    using Sup_least [of "uminus ` X" "- z"] by (force simp: Inf_real_def that)
51775
408d937c9486 revert #916271d52466; add non-topological linear_continuum type class; show linear_continuum_topology is a perfect_space
hoelzl
parents: 51773
diff changeset
   934
  show "\<exists>a b::real. a \<noteq> b"
408d937c9486 revert #916271d52466; add non-topological linear_continuum type class; show linear_continuum_topology is a perfect_space
hoelzl
parents: 51773
diff changeset
   935
    using zero_neq_one by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   936
qed
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   937
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   938
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   939
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   940
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   941
subsection \<open>Hiding implementation details\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   942
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   943
hide_const (open) vanishes cauchy positive Real
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   944
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   945
declare Real_induct [induct del]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   946
declare Abs_real_induct [induct del]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   947
declare Abs_real_cases [cases del]
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   948
53652
18fbca265e2e use lifting_forget for deregistering numeric types as a quotient type
kuncar
parents: 53374
diff changeset
   949
lifting_update real.lifting
18fbca265e2e use lifting_forget for deregistering numeric types as a quotient type
kuncar
parents: 53374
diff changeset
   950
lifting_forget real.lifting
61284
2314c2f62eb1 real_of_nat_Suc is now a simprule
paulson <lp15@cam.ac.uk>
parents: 61204
diff changeset
   951
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   952
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   953
subsection \<open>More Lemmas\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   954
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   955
text \<open>BH: These lemmas should not be necessary; they should be
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   956
  covered by existing simp rules and simplification procedures.\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   957
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   958
lemma real_mult_less_iff1 [simp]: "0 < z \<Longrightarrow> x * z < y * z \<longleftrightarrow> x < y"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   959
  for x y z :: real
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   960
  by simp (* solved by linordered_ring_less_cancel_factor simproc *)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   961
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   962
lemma real_mult_le_cancel_iff1 [simp]: "0 < z \<Longrightarrow> x * z \<le> y * z \<longleftrightarrow> x \<le> y"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   963
  for x y z :: real
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   964
  by simp (* solved by linordered_ring_le_cancel_factor simproc *)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   965
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   966
lemma real_mult_le_cancel_iff2 [simp]: "0 < z \<Longrightarrow> z * x \<le> z * y \<longleftrightarrow> x \<le> y"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
   967
  for x y z :: real
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   968
  by simp (* solved by linordered_ring_le_cancel_factor simproc *)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   969
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   970
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
   971
subsection \<open>Embedding numbers into the Reals\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   972
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   973
abbreviation real_of_nat :: "nat \<Rightarrow> real"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   974
  where "real_of_nat \<equiv> of_nat"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   975
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   976
abbreviation real :: "nat \<Rightarrow> real"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   977
  where "real \<equiv> of_nat"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
   978
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   979
abbreviation real_of_int :: "int \<Rightarrow> real"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   980
  where "real_of_int \<equiv> of_int"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   981
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   982
abbreviation real_of_rat :: "rat \<Rightarrow> real"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
   983
  where "real_of_rat \<equiv> of_rat"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   984
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   985
declare [[coercion_enabled]]
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58983
diff changeset
   986
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58983
diff changeset
   987
declare [[coercion "of_nat :: nat \<Rightarrow> int"]]
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
   988
declare [[coercion "of_nat :: nat \<Rightarrow> real"]]
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
   989
declare [[coercion "of_int :: int \<Rightarrow> real"]]
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58983
diff changeset
   990
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58983
diff changeset
   991
(* We do not add rat to the coerced types, this has often unpleasant side effects when writing
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58983
diff changeset
   992
inverse (Suc n) which sometimes gets two coercions: of_rat (inverse (of_nat (Suc n))) *)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   993
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   994
declare [[coercion_map map]]
59000
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58983
diff changeset
   995
declare [[coercion_map "\<lambda>f g h x. g (h (f x))"]]
6eb0725503fc import general theorems from AFP/Markov_Models
hoelzl
parents: 58983
diff changeset
   996
declare [[coercion_map "\<lambda>f g (x,y). (f x, g y)"]]
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
   997
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
   998
declare of_int_eq_0_iff [algebra, presburger]
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
   999
declare of_int_eq_1_iff [algebra, presburger]
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1000
declare of_int_eq_iff [algebra, presburger]
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1001
declare of_int_less_0_iff [algebra, presburger]
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1002
declare of_int_less_1_iff [algebra, presburger]
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1003
declare of_int_less_iff [algebra, presburger]
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1004
declare of_int_le_0_iff [algebra, presburger]
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1005
declare of_int_le_1_iff [algebra, presburger]
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1006
declare of_int_le_iff [algebra, presburger]
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1007
declare of_int_0_less_iff [algebra, presburger]
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1008
declare of_int_0_le_iff [algebra, presburger]
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1009
declare of_int_1_less_iff [algebra, presburger]
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1010
declare of_int_1_le_iff [algebra, presburger]
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1011
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1012
lemma int_less_real_le: "n < m \<longleftrightarrow> real_of_int n + 1 \<le> real_of_int m"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1013
proof -
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1014
  have "(0::real) \<le> 1"
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1015
    by (metis less_eq_real_def zero_less_one)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1016
  then show ?thesis
61694
6571c78c9667 Removed some legacy theorems; minor adjustments to simplification rules; new material on homotopic paths
paulson <lp15@cam.ac.uk>
parents: 61649
diff changeset
  1017
    by (metis floor_of_int less_floor_iff)
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1018
qed
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1019
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1020
lemma int_le_real_less: "n \<le> m \<longleftrightarrow> real_of_int n < real_of_int m + 1"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1021
  by (meson int_less_real_le not_le)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1022
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1023
lemma real_of_int_div_aux:
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1024
  "(real_of_int x) / (real_of_int d) =
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1025
    real_of_int (x div d) + (real_of_int (x mod d)) / (real_of_int d)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1026
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1027
  have "x = (x div d) * d + x mod d"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1028
    by auto
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1029
  then have "real_of_int x = real_of_int (x div d) * real_of_int d + real_of_int(x mod d)"
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1030
    by (metis of_int_add of_int_mult)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1031
  then have "real_of_int x / real_of_int d = \<dots> / real_of_int d"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1032
    by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1033
  then show ?thesis
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1034
    by (auto simp add: add_divide_distrib algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1035
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1036
58834
773b378d9313 more simp rules concerning dvd and even/odd
haftmann
parents: 58789
diff changeset
  1037
lemma real_of_int_div:
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1038
  "d dvd n \<Longrightarrow> real_of_int (n div d) = real_of_int n / real_of_int d" for d n :: int
58834
773b378d9313 more simp rules concerning dvd and even/odd
haftmann
parents: 58789
diff changeset
  1039
  by (simp add: real_of_int_div_aux)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1040
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1041
lemma real_of_int_div2: "0 \<le> real_of_int n / real_of_int x - real_of_int (n div x)"
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1042
proof (cases "x = 0")
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1043
  case False
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1044
  then show ?thesis
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1045
    by (metis diff_ge_0_iff_ge floor_divide_of_int_eq of_int_floor_le)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1046
qed simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1047
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1048
lemma real_of_int_div3: "real_of_int n / real_of_int x - real_of_int (n div x) \<le> 1"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1049
  apply (simp add: algebra_simps)
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1050
  by (metis add.commute floor_correct floor_divide_of_int_eq less_eq_real_def of_int_1 of_int_add)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1051
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1052
lemma real_of_int_div4: "real_of_int (n div x) \<le> real_of_int n / real_of_int x"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1053
  using real_of_int_div2 [of n x] by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1054
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1055
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1056
subsection \<open>Embedding the Naturals into the Reals\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1057
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63961
diff changeset
  1058
lemma real_of_card: "real (card A) = sum (\<lambda>x. 1) A"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1059
  by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1060
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1061
lemma nat_less_real_le: "n < m \<longleftrightarrow> real n + 1 \<le> real m"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1062
  by (metis discrete of_nat_1 of_nat_add of_nat_le_iff)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1063
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1064
lemma nat_le_real_less: "n \<le> m \<longleftrightarrow> real n < real m + 1"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1065
  for m n :: nat
61284
2314c2f62eb1 real_of_nat_Suc is now a simprule
paulson <lp15@cam.ac.uk>
parents: 61204
diff changeset
  1066
  by (meson nat_less_real_le not_le)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1067
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1068
lemma real_of_nat_div_aux: "real x / real d = real (x div d) + real (x mod d) / real d"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1069
proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1070
  have "x = (x div d) * d + x mod d"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1071
    by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1072
  then have "real x = real (x div d) * real d + real(x mod d)"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1073
    by (metis of_nat_add of_nat_mult)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1074
  then have "real x / real d = \<dots> / real d"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1075
    by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1076
  then show ?thesis
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1077
    by (auto simp add: add_divide_distrib algebra_simps)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1078
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1079
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1080
lemma real_of_nat_div: "d dvd n \<Longrightarrow> real(n div d) = real n / real d"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1081
  by (subst real_of_nat_div_aux) (auto simp add: dvd_eq_mod_eq_0 [symmetric])
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1082
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1083
lemma real_of_nat_div2: "0 \<le> real n / real x - real (n div x)" for n x :: nat
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1084
  apply (simp add: algebra_simps)
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1085
  by (metis floor_divide_of_nat_eq of_int_floor_le of_int_of_nat_eq)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1086
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1087
lemma real_of_nat_div3: "real n / real x - real (n div x) \<le> 1" for n x :: nat
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1088
proof (cases "x = 0")
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1089
  case False
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1090
  then show ?thesis
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1091
    by (metis of_int_of_nat_eq real_of_int_div3 zdiv_int)
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1092
qed auto
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1093
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1094
lemma real_of_nat_div4: "real (n div x) \<le> real n / real x" for n x :: nat
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1095
  using real_of_nat_div2 [of n x] by simp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1096
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1097
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1098
subsection \<open>The Archimedean Property of the Reals\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1099
62623
dbc62f86a1a9 rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents: 62398
diff changeset
  1100
lemma real_arch_inverse: "0 < e \<longleftrightarrow> (\<exists>n::nat. n \<noteq> 0 \<and> 0 < inverse (real n) \<and> inverse (real n) < e)"
dbc62f86a1a9 rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents: 62398
diff changeset
  1101
  using reals_Archimedean[of e] less_trans[of 0 "1 / real n" e for n::nat]
dbc62f86a1a9 rationalisation of theorem names esp about "real Archimedian" etc.
paulson <lp15@cam.ac.uk>
parents: 62398
diff changeset
  1102
  by (auto simp add: field_simps cong: conj_cong simp del: of_nat_Suc)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1103
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1104
lemma reals_Archimedean3: "0 < x \<Longrightarrow> \<forall>y. \<exists>n. y < real n * x"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1105
  by (auto intro: ex_less_of_nat_mult)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1106
62397
5ae24f33d343 Substantial new material for multivariate analysis. Also removal of some duplicates.
paulson <lp15@cam.ac.uk>
parents: 62348
diff changeset
  1107
lemma real_archimedian_rdiv_eq_0:
5ae24f33d343 Substantial new material for multivariate analysis. Also removal of some duplicates.
paulson <lp15@cam.ac.uk>
parents: 62348
diff changeset
  1108
  assumes x0: "x \<ge> 0"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1109
    and c: "c \<ge> 0"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1110
    and xc: "\<And>m::nat. m > 0 \<Longrightarrow> real m * x \<le> c"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1111
  shows "x = 0"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1112
  by (metis reals_Archimedean3 dual_order.order_iff_strict le0 le_less_trans not_le x0 xc)
62397
5ae24f33d343 Substantial new material for multivariate analysis. Also removal of some duplicates.
paulson <lp15@cam.ac.uk>
parents: 62348
diff changeset
  1113
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1114
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1115
subsection \<open>Rationals\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1116
68529
29235951f104 added lemmas
nipkow
parents: 68527
diff changeset
  1117
lemma Rats_abs_iff[simp]:
29235951f104 added lemmas
nipkow
parents: 68527
diff changeset
  1118
  "\<bar>(x::real)\<bar> \<in> \<rat> \<longleftrightarrow> x \<in> \<rat>"
29235951f104 added lemmas
nipkow
parents: 68527
diff changeset
  1119
by(simp add: abs_real_def split: if_splits)
29235951f104 added lemmas
nipkow
parents: 68527
diff changeset
  1120
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1121
lemma Rats_eq_int_div_int: "\<rat> = {real_of_int i / real_of_int j | i j. j \<noteq> 0}"  (is "_ = ?S")
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1122
proof
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1123
  show "\<rat> \<subseteq> ?S"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1124
  proof
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1125
    fix x :: real
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1126
    assume "x \<in> \<rat>"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1127
    then obtain r where "x = of_rat r"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1128
      unfolding Rats_def ..
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1129
    have "of_rat r \<in> ?S"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1130
      by (cases r) (auto simp add: of_rat_rat)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1131
    then show "x \<in> ?S"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1132
      using \<open>x = of_rat r\<close> by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1133
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1134
next
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1135
  show "?S \<subseteq> \<rat>"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1136
  proof (auto simp: Rats_def)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1137
    fix i j :: int
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1138
    assume "j \<noteq> 0"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1139
    then have "real_of_int i / real_of_int j = of_rat (Fract i j)"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1140
      by (simp add: of_rat_rat)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1141
    then show "real_of_int i / real_of_int j \<in> range of_rat"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1142
      by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1143
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1144
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1145
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1146
lemma Rats_eq_int_div_nat: "\<rat> = { real_of_int i / real n | i n. n \<noteq> 0}"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1147
proof (auto simp: Rats_eq_int_div_int)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1148
  fix i j :: int
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1149
  assume "j \<noteq> 0"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1150
  show "\<exists>(i'::int) (n::nat). real_of_int i / real_of_int j = real_of_int i' / real n \<and> 0 < n"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1151
  proof (cases "j > 0")
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1152
    case True
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1153
    then have "real_of_int i / real_of_int j = real_of_int i / real (nat j) \<and> 0 < nat j"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1154
      by simp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1155
    then show ?thesis by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1156
  next
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1157
    case False
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1158
    with \<open>j \<noteq> 0\<close>
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1159
    have "real_of_int i / real_of_int j = real_of_int (- i) / real (nat (- j)) \<and> 0 < nat (- j)"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1160
      by simp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1161
    then show ?thesis by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1162
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1163
next
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1164
  fix i :: int and n :: nat
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1165
  assume "0 < n"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1166
  then have "real_of_int i / real n = real_of_int i / real_of_int(int n) \<and> int n \<noteq> 0"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1167
    by simp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1168
  then show "\<exists>i' j. real_of_int i / real n = real_of_int i' / real_of_int j \<and> j \<noteq> 0"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1169
    by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1170
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1171
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1172
lemma Rats_abs_nat_div_natE:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1173
  assumes "x \<in> \<rat>"
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66912
diff changeset
  1174
  obtains m n :: nat where "n \<noteq> 0" and "\<bar>x\<bar> = real m / real n" and "coprime m n"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1175
proof -
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1176
  from \<open>x \<in> \<rat>\<close> obtain i :: int and n :: nat where "n \<noteq> 0" and "x = real_of_int i / real n"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1177
    by (auto simp add: Rats_eq_int_div_nat)
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1178
  then have "\<bar>x\<bar> = real (nat \<bar>i\<bar>) / real n" by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1179
  then obtain m :: nat where x_rat: "\<bar>x\<bar> = real m / real n" by blast
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1180
  let ?gcd = "gcd m n"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1181
  from \<open>n \<noteq> 0\<close> have gcd: "?gcd \<noteq> 0" by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1182
  let ?k = "m div ?gcd"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1183
  let ?l = "n div ?gcd"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1184
  let ?gcd' = "gcd ?k ?l"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1185
  have "?gcd dvd m" ..
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1186
  then have gcd_k: "?gcd * ?k = m"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1187
    by (rule dvd_mult_div_cancel)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1188
  have "?gcd dvd n" ..
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1189
  then have gcd_l: "?gcd * ?l = n"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1190
    by (rule dvd_mult_div_cancel)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1191
  from \<open>n \<noteq> 0\<close> and gcd_l have "?gcd * ?l \<noteq> 0" by simp
61284
2314c2f62eb1 real_of_nat_Suc is now a simprule
paulson <lp15@cam.ac.uk>
parents: 61204
diff changeset
  1192
  then have "?l \<noteq> 0" by (blast dest!: mult_not_zero)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1193
  moreover
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1194
  have "\<bar>x\<bar> = real ?k / real ?l"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1195
  proof -
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1196
    from gcd have "real ?k / real ?l = real (?gcd * ?k) / real (?gcd * ?l)"
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1197
      by (simp add: real_of_nat_div)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1198
    also from gcd_k and gcd_l have "\<dots> = real m / real n" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1199
    also from x_rat have "\<dots> = \<bar>x\<bar>" ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1200
    finally show ?thesis ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1201
  qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1202
  moreover
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1203
  have "?gcd' = 1"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1204
  proof -
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1205
    have "?gcd * ?gcd' = gcd (?gcd * ?k) (?gcd * ?l)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1206
      by (rule gcd_mult_distrib_nat)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1207
    with gcd_k gcd_l have "?gcd * ?gcd' = ?gcd" by simp
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1208
    with gcd show ?thesis by auto
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1209
  qed
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66912
diff changeset
  1210
  then have "coprime ?k ?l"
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66912
diff changeset
  1211
    by (simp only: coprime_iff_gcd_eq_1)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1212
  ultimately show ?thesis ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1213
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1214
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1215
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1216
subsection \<open>Density of the Rational Reals in the Reals\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1217
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1218
text \<open>
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1219
  This density proof is due to Stefan Richter and was ported by TN.  The
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1220
  original source is \<^emph>\<open>Real Analysis\<close> by H.L. Royden.
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1221
  It employs the Archimedean property of the reals.\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1222
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1223
lemma Rats_dense_in_real:
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1224
  fixes x :: real
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1225
  assumes "x < y"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1226
  shows "\<exists>r\<in>\<rat>. x < r \<and> r < y"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1227
proof -
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1228
  from \<open>x < y\<close> have "0 < y - x" by simp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1229
  with reals_Archimedean obtain q :: nat where q: "inverse (real q) < y - x" and "0 < q"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1230
    by blast
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62626
diff changeset
  1231
  define p where "p = \<lceil>y * real q\<rceil> - 1"
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62626
diff changeset
  1232
  define r where "r = of_int p / real q"
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1233
  from q have "x < y - inverse (real q)"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1234
    by simp
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1235
  also from \<open>0 < q\<close> have "y - inverse (real q) \<le> r"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1236
    by (simp add: r_def p_def le_divide_eq left_diff_distrib)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1237
  finally have "x < r" .
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1238
  moreover from \<open>0 < q\<close> have "r < y"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1239
    by (simp add: r_def p_def divide_less_eq diff_less_eq less_ceiling_iff [symmetric])
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1240
  moreover have "r \<in> \<rat>"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1241
    by (simp add: r_def)
61649
268d88ec9087 Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
paulson <lp15@cam.ac.uk>
parents: 61609
diff changeset
  1242
  ultimately show ?thesis by blast
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1243
qed
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1244
57447
87429bdecad5 import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents: 57275
diff changeset
  1245
lemma of_rat_dense:
87429bdecad5 import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents: 57275
diff changeset
  1246
  fixes x y :: real
87429bdecad5 import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents: 57275
diff changeset
  1247
  assumes "x < y"
87429bdecad5 import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents: 57275
diff changeset
  1248
  shows "\<exists>q :: rat. x < of_rat q \<and> of_rat q < y"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1249
  using Rats_dense_in_real [OF \<open>x < y\<close>]
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1250
  by (auto elim: Rats_cases)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1251
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1252
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1253
subsection \<open>Numerals and Arithmetic\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1254
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1255
declaration \<open>
70356
4a327c061870 streamlined setup for linear algebra, particularly removed redundant rule declarations
haftmann
parents: 70270
diff changeset
  1256
  K (Lin_Arith.add_inj_const (\<^const_name>\<open>of_nat\<close>, \<^typ>\<open>nat \<Rightarrow> real\<close>)
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1257
  #> Lin_Arith.add_inj_const (\<^const_name>\<open>of_int\<close>, \<^typ>\<open>int \<Rightarrow> real\<close>))
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1258
\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1259
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1260
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1261
subsection \<open>Simprules combining \<open>x + y\<close> and \<open>0\<close>\<close> (* FIXME ARE THEY NEEDED? *)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1262
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1263
lemma real_add_minus_iff [simp]: "x + - a = 0 \<longleftrightarrow> x = a"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1264
  for x a :: real
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1265
  by arith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1266
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1267
lemma real_add_less_0_iff: "x + y < 0 \<longleftrightarrow> y < - x"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1268
  for x y :: real
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1269
  by auto
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1270
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1271
lemma real_0_less_add_iff: "0 < x + y \<longleftrightarrow> - x < y"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1272
  for x y :: real
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1273
  by auto
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1274
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1275
lemma real_add_le_0_iff: "x + y \<le> 0 \<longleftrightarrow> y \<le> - x"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1276
  for x y :: real
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1277
  by auto
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1278
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1279
lemma real_0_le_add_iff: "0 \<le> x + y \<longleftrightarrow> - x \<le> y"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1280
  for x y :: real
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1281
  by auto
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1282
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1283
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1284
subsection \<open>Lemmas about powers\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1285
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1286
lemma two_realpow_ge_one: "(1::real) \<le> 2 ^ n"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1287
  by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1288
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1289
(* FIXME: declare this [simp] for all types, or not at all *)
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1290
declare sum_squares_eq_zero_iff [simp] sum_power2_eq_zero_iff [simp]
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1291
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1292
lemma real_minus_mult_self_le [simp]: "- (u * u) \<le> x * x"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1293
  for u x :: real
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1294
  by (rule order_trans [where y = 0]) auto
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1295
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1296
lemma realpow_square_minus_le [simp]: "- u\<^sup>2 \<le> x\<^sup>2"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1297
  for u x :: real
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1298
  by (auto simp add: power2_eq_square)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1299
56889
48a745e1bde7 avoid the Complex constructor, use the more natural Re/Im view; moved csqrt to Complex.
hoelzl
parents: 56571
diff changeset
  1300
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1301
subsection \<open>Density of the Reals\<close>
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1302
68527
2f4e2aab190a Generalising and renaming some basic results
paulson <lp15@cam.ac.uk>
parents: 68484
diff changeset
  1303
lemma field_lbound_gt_zero: "0 < d1 \<Longrightarrow> 0 < d2 \<Longrightarrow> \<exists>e. 0 < e \<and> e < d1 \<and> e < d2"
2f4e2aab190a Generalising and renaming some basic results
paulson <lp15@cam.ac.uk>
parents: 68484
diff changeset
  1304
  for d1 d2 :: "'a::linordered_field"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1305
  by (rule exI [where x = "min d1 d2 / 2"]) (simp add: min_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1306
68527
2f4e2aab190a Generalising and renaming some basic results
paulson <lp15@cam.ac.uk>
parents: 68484
diff changeset
  1307
lemma field_less_half_sum: "x < y \<Longrightarrow> x < (x + y) / 2"
2f4e2aab190a Generalising and renaming some basic results
paulson <lp15@cam.ac.uk>
parents: 68484
diff changeset
  1308
  for x y :: "'a::linordered_field"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1309
  by auto
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1310
68527
2f4e2aab190a Generalising and renaming some basic results
paulson <lp15@cam.ac.uk>
parents: 68484
diff changeset
  1311
lemma field_sum_of_halves: "x / 2 + x / 2 = x"
2f4e2aab190a Generalising and renaming some basic results
paulson <lp15@cam.ac.uk>
parents: 68484
diff changeset
  1312
  for x :: "'a::linordered_field"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1313
  by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1314
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1315
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1316
subsection \<open>Floor and Ceiling Functions from the Reals to the Integers\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1317
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1318
(* FIXME: theorems for negative numerals. Many duplicates, e.g. from Archimedean_Field.thy. *)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1319
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1320
lemma real_of_nat_less_numeral_iff [simp]: "real n < numeral w \<longleftrightarrow> n < numeral w"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1321
  for n :: nat
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1322
  by (metis of_nat_less_iff of_nat_numeral)
56889
48a745e1bde7 avoid the Complex constructor, use the more natural Re/Im view; moved csqrt to Complex.
hoelzl
parents: 56571
diff changeset
  1323
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1324
lemma numeral_less_real_of_nat_iff [simp]: "numeral w < real n \<longleftrightarrow> numeral w < n"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1325
  for n :: nat
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1326
  by (metis of_nat_less_iff of_nat_numeral)
56889
48a745e1bde7 avoid the Complex constructor, use the more natural Re/Im view; moved csqrt to Complex.
hoelzl
parents: 56571
diff changeset
  1327
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1328
lemma numeral_le_real_of_nat_iff [simp]: "numeral n \<le> real m \<longleftrightarrow> numeral n \<le> m"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1329
  for m :: nat
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1330
  by (metis not_le real_of_nat_less_numeral_iff)
59587
8ea7b22525cb Removed the obsolete functions "natfloor" and "natceiling"
nipkow
parents: 59000
diff changeset
  1331
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1332
lemma of_int_floor_cancel [simp]: "of_int \<lfloor>x\<rfloor> = x \<longleftrightarrow> (\<exists>n::int. x = of_int n)"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1333
  by (metis floor_of_int)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1334
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1335
lemma floor_eq: "real_of_int n < x \<Longrightarrow> x < real_of_int n + 1 \<Longrightarrow> \<lfloor>x\<rfloor> = n"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1336
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1337
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1338
lemma floor_eq2: "real_of_int n \<le> x \<Longrightarrow> x < real_of_int n + 1 \<Longrightarrow> \<lfloor>x\<rfloor> = n"
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66912
diff changeset
  1339
  by (fact floor_unique)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1340
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1341
lemma floor_eq3: "real n < x \<Longrightarrow> x < real (Suc n) \<Longrightarrow> nat \<lfloor>x\<rfloor> = n"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1342
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1343
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1344
lemma floor_eq4: "real n \<le> x \<Longrightarrow> x < real (Suc n) \<Longrightarrow> nat \<lfloor>x\<rfloor> = n"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1345
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1346
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1347
lemma real_of_int_floor_ge_diff_one [simp]: "r - 1 \<le> real_of_int \<lfloor>r\<rfloor>"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1348
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1349
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1350
lemma real_of_int_floor_gt_diff_one [simp]: "r - 1 < real_of_int \<lfloor>r\<rfloor>"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1351
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1352
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1353
lemma real_of_int_floor_add_one_ge [simp]: "r \<le> real_of_int \<lfloor>r\<rfloor> + 1"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1354
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1355
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1356
lemma real_of_int_floor_add_one_gt [simp]: "r < real_of_int \<lfloor>r\<rfloor> + 1"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1357
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1358
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1359
lemma floor_divide_real_eq_div:
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1360
  assumes "0 \<le> b"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1361
  shows "\<lfloor>a / real_of_int b\<rfloor> = \<lfloor>a\<rfloor> div b"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1362
proof (cases "b = 0")
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1363
  case True
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1364
  then show ?thesis by simp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1365
next
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1366
  case False
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1367
  with assms have b: "b > 0" by simp
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1368
  have "j = i div b"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1369
    if "real_of_int i \<le> a" "a < 1 + real_of_int i"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1370
      "real_of_int j * real_of_int b \<le> a" "a < real_of_int b + real_of_int j * real_of_int b"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1371
    for i j :: int
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1372
  proof -
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1373
    from that have "i < b + j * b"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1374
      by (metis le_less_trans of_int_add of_int_less_iff of_int_mult)
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1375
    moreover have "j * b < 1 + i"
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1376
    proof -
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1377
      have "real_of_int (j * b) < real_of_int i + 1"
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61694
diff changeset
  1378
        using \<open>a < 1 + real_of_int i\<close> \<open>real_of_int j * real_of_int b \<le> a\<close> by force
63597
bef0277ec73b tuned floor lemmas
nipkow
parents: 63494
diff changeset
  1379
      then show "j * b < 1 + i" by linarith
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1380
    qed
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1381
    ultimately have "(j - i div b) * b \<le> i mod b" "i mod b < ((j - i div b) + 1) * b"
58788
d17b3844b726 generalize natfloor_div_nat, add floor variant: floor_divide_real_eq_div
hoelzl
parents: 58134
diff changeset
  1382
      by (auto simp: field_simps)
d17b3844b726 generalize natfloor_div_nat, add floor variant: floor_divide_real_eq_div
hoelzl
parents: 58134
diff changeset
  1383
    then have "(j - i div b) * b < 1 * b" "0 * b < ((j - i div b) + 1) * b"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1384
      using pos_mod_bound [OF b, of i] pos_mod_sign [OF b, of i]
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1385
      by linarith+
63597
bef0277ec73b tuned floor lemmas
nipkow
parents: 63494
diff changeset
  1386
    then show ?thesis using b unfolding mult_less_cancel_right by auto
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1387
  qed
63597
bef0277ec73b tuned floor lemmas
nipkow
parents: 63494
diff changeset
  1388
  with b show ?thesis by (auto split: floor_split simp: field_simps)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1389
qed
58788
d17b3844b726 generalize natfloor_div_nat, add floor variant: floor_divide_real_eq_div
hoelzl
parents: 58134
diff changeset
  1390
63601
ae810a755cd2 added missing lemmas
nipkow
parents: 63597
diff changeset
  1391
lemma floor_one_divide_eq_div_numeral [simp]:
ae810a755cd2 added missing lemmas
nipkow
parents: 63597
diff changeset
  1392
  "\<lfloor>1 / numeral b::real\<rfloor> = 1 div numeral b"
ae810a755cd2 added missing lemmas
nipkow
parents: 63597
diff changeset
  1393
by (metis floor_divide_of_int_eq of_int_1 of_int_numeral)
ae810a755cd2 added missing lemmas
nipkow
parents: 63597
diff changeset
  1394
ae810a755cd2 added missing lemmas
nipkow
parents: 63597
diff changeset
  1395
lemma floor_minus_one_divide_eq_div_numeral [simp]:
ae810a755cd2 added missing lemmas
nipkow
parents: 63597
diff changeset
  1396
  "\<lfloor>- (1 / numeral b)::real\<rfloor> = - 1 div numeral b"
ae810a755cd2 added missing lemmas
nipkow
parents: 63597
diff changeset
  1397
by (metis (mono_tags, hide_lams) div_minus_right minus_divide_right
ae810a755cd2 added missing lemmas
nipkow
parents: 63597
diff changeset
  1398
    floor_divide_of_int_eq of_int_neg_numeral of_int_1)
ae810a755cd2 added missing lemmas
nipkow
parents: 63597
diff changeset
  1399
63597
bef0277ec73b tuned floor lemmas
nipkow
parents: 63494
diff changeset
  1400
lemma floor_divide_eq_div_numeral [simp]:
bef0277ec73b tuned floor lemmas
nipkow
parents: 63494
diff changeset
  1401
  "\<lfloor>numeral a / numeral b::real\<rfloor> = numeral a div numeral b"
bef0277ec73b tuned floor lemmas
nipkow
parents: 63494
diff changeset
  1402
by (metis floor_divide_of_int_eq of_int_numeral)
58097
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58061
diff changeset
  1403
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1404
lemma floor_minus_divide_eq_div_numeral [simp]:
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1405
  "\<lfloor>- (numeral a / numeral b)::real\<rfloor> = - numeral a div numeral b"
63597
bef0277ec73b tuned floor lemmas
nipkow
parents: 63494
diff changeset
  1406
by (metis divide_minus_left floor_divide_of_int_eq of_int_neg_numeral of_int_numeral)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1407
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1408
lemma of_int_ceiling_cancel [simp]: "of_int \<lceil>x\<rceil> = x \<longleftrightarrow> (\<exists>n::int. x = of_int n)"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1409
  using ceiling_of_int by metis
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1410
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1411
lemma ceiling_eq: "of_int n < x \<Longrightarrow> x \<le> of_int n + 1 \<Longrightarrow> \<lceil>x\<rceil> = n + 1"
61694
6571c78c9667 Removed some legacy theorems; minor adjustments to simplification rules; new material on homotopic paths
paulson <lp15@cam.ac.uk>
parents: 61649
diff changeset
  1412
  by (simp add: ceiling_unique)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1413
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1414
lemma of_int_ceiling_diff_one_le [simp]: "of_int \<lceil>r\<rceil> - 1 \<le> r"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1415
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1416
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1417
lemma of_int_ceiling_le_add_one [simp]: "of_int \<lceil>r\<rceil> \<le> r + 1"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1418
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1419
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1420
lemma ceiling_le: "x \<le> of_int a \<Longrightarrow> \<lceil>x\<rceil> \<le> a"
61694
6571c78c9667 Removed some legacy theorems; minor adjustments to simplification rules; new material on homotopic paths
paulson <lp15@cam.ac.uk>
parents: 61649
diff changeset
  1421
  by (simp add: ceiling_le_iff)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1422
61694
6571c78c9667 Removed some legacy theorems; minor adjustments to simplification rules; new material on homotopic paths
paulson <lp15@cam.ac.uk>
parents: 61649
diff changeset
  1423
lemma ceiling_divide_eq_div: "\<lceil>of_int a / of_int b\<rceil> = - (- a div b)"
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1424
  by (metis ceiling_def floor_divide_of_int_eq minus_divide_left of_int_minus)
58097
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58061
diff changeset
  1425
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58061
diff changeset
  1426
lemma ceiling_divide_eq_div_numeral [simp]:
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58061
diff changeset
  1427
  "\<lceil>numeral a / numeral b :: real\<rceil> = - (- numeral a div numeral b)"
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58061
diff changeset
  1428
  using ceiling_divide_eq_div[of "numeral a" "numeral b"] by simp
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58061
diff changeset
  1429
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58061
diff changeset
  1430
lemma ceiling_minus_divide_eq_div_numeral [simp]:
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58061
diff changeset
  1431
  "\<lceil>- (numeral a / numeral b :: real)\<rceil> = - (numeral a div numeral b)"
cfd3cff9387b add simp rules for divisions of numerals in floor and ceiling.
hoelzl
parents: 58061
diff changeset
  1432
  using ceiling_divide_eq_div[of "- numeral a" "numeral b"] by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1433
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1434
text \<open>
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1435
  The following lemmas are remnants of the erstwhile functions natfloor
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1436
  and natceiling.
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1437
\<close>
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1438
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1439
lemma nat_floor_neg: "x \<le> 0 \<Longrightarrow> nat \<lfloor>x\<rfloor> = 0"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1440
  for x :: real
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1441
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1442
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1443
lemma le_nat_floor: "real x \<le> a \<Longrightarrow> x \<le> nat \<lfloor>a\<rfloor>"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1444
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1445
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1446
lemma le_mult_nat_floor: "nat \<lfloor>a\<rfloor> * nat \<lfloor>b\<rfloor> \<le> nat \<lfloor>a * b\<rfloor>"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1447
  by (cases "0 \<le> a \<and> 0 \<le> b")
59587
8ea7b22525cb Removed the obsolete functions "natfloor" and "natceiling"
nipkow
parents: 59000
diff changeset
  1448
     (auto simp add: nat_mult_distrib[symmetric] nat_mono le_mult_floor)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1449
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1450
lemma nat_ceiling_le_eq [simp]: "nat \<lceil>x\<rceil> \<le> a \<longleftrightarrow> x \<le> real a"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1451
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1452
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1453
lemma real_nat_ceiling_ge: "x \<le> real (nat \<lceil>x\<rceil>)"
58040
9a867afaab5a better linarith support for floor, ceiling, natfloor, and natceiling
hoelzl
parents: 57514
diff changeset
  1454
  by linarith
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1455
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1456
lemma Rats_no_top_le: "\<exists>q \<in> \<rat>. x \<le> q"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1457
  for x :: real
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1458
  by (auto intro!: bexI[of _ "of_nat (nat \<lceil>x\<rceil>)"]) linarith
57275
0ddb5b755cdc moved lemmas from the proof of the Central Limit Theorem by Jeremy Avigad and Luke Serafin
hoelzl
parents: 56889
diff changeset
  1459
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1460
lemma Rats_no_bot_less: "\<exists>q \<in> \<rat>. q < x" for x :: real
68669
7ddf297cfcde de-applying and removing junk
paulson <lp15@cam.ac.uk>
parents: 68662
diff changeset
  1461
  by (auto intro!: bexI[of _ "of_int (\<lfloor>x\<rfloor> - 1)"]) linarith
57447
87429bdecad5 import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
hoelzl
parents: 57275
diff changeset
  1462
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1463
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1464
subsection \<open>Exponentiation with floor\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1465
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1466
lemma floor_power:
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1467
  assumes "x = of_int \<lfloor>x\<rfloor>"
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1468
  shows "\<lfloor>x ^ n\<rfloor> = \<lfloor>x\<rfloor> ^ n"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1469
proof -
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1470
  have "x ^ n = of_int (\<lfloor>x\<rfloor> ^ n)"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1471
    using assms by (induct n arbitrary: x) simp_all
62626
de25474ce728 Contractible sets. Also removal of obsolete theorems and refactoring
paulson <lp15@cam.ac.uk>
parents: 62623
diff changeset
  1472
  then show ?thesis by (metis floor_of_int)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1473
qed
61609
77b453bd616f Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents: 61284
diff changeset
  1474
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1475
lemma floor_numeral_power [simp]: "\<lfloor>numeral x ^ n\<rfloor> = numeral x ^ n"
58983
9c390032e4eb cancel real of power of numeral also for equality and strict inequality;
immler
parents: 58889
diff changeset
  1476
  by (metis floor_of_int of_int_numeral of_int_power)
9c390032e4eb cancel real of power of numeral also for equality and strict inequality;
immler
parents: 58889
diff changeset
  1477
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1478
lemma ceiling_numeral_power [simp]: "\<lceil>numeral x ^ n\<rceil> = numeral x ^ n"
58983
9c390032e4eb cancel real of power of numeral also for equality and strict inequality;
immler
parents: 58889
diff changeset
  1479
  by (metis ceiling_of_int of_int_numeral of_int_power)
9c390032e4eb cancel real of power of numeral also for equality and strict inequality;
immler
parents: 58889
diff changeset
  1480
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1481
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1482
subsection \<open>Implementation of rational real numbers\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1483
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1484
text \<open>Formal constructor\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1485
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1486
definition Ratreal :: "rat \<Rightarrow> real"
66155
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1487
  where [code_abbrev, simp]: "Ratreal = real_of_rat"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1488
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1489
code_datatype Ratreal
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1490
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1491
66155
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1492
text \<open>Quasi-Numerals\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1493
66155
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1494
lemma [code_abbrev]:
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1495
  "real_of_rat (numeral k) = numeral k"
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1496
  "real_of_rat (- numeral k) = - numeral k"
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1497
  "real_of_rat (rat_of_int a) = real_of_int a"
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1498
  by simp_all
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1499
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1500
lemma [code_post]:
66155
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1501
  "real_of_rat 0 = 0"
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1502
  "real_of_rat 1 = 1"
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1503
  "real_of_rat (- 1) = - 1"
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1504
  "real_of_rat (1 / numeral k) = 1 / numeral k"
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1505
  "real_of_rat (numeral k / numeral l) = numeral k / numeral l"
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1506
  "real_of_rat (- (1 / numeral k)) = - (1 / numeral k)"
2463cba9f18f stripped code pre/postprocessor setup for real from superfluous rules
haftmann
parents: 65885
diff changeset
  1507
  "real_of_rat (- (numeral k / numeral l)) = - (numeral k / numeral l)"
54489
03ff4d1e6784 eliminiated neg_numeral in favour of - (numeral _)
haftmann
parents: 54281
diff changeset
  1508
  by (simp_all add: of_rat_divide of_rat_minus)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1509
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1510
text \<open>Operations\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1511
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1512
lemma zero_real_code [code]: "0 = Ratreal 0"
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1513
  by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1514
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1515
lemma one_real_code [code]: "1 = Ratreal 1"
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1516
  by simp
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1517
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1518
instantiation real :: equal
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1519
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1520
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1521
definition "HOL.equal x y \<longleftrightarrow> x - y = 0" for x :: real
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1522
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1523
instance by standard (simp add: equal_real_def)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1524
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1525
lemma real_equal_code [code]: "HOL.equal (Ratreal x) (Ratreal y) \<longleftrightarrow> HOL.equal x y"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1526
  by (simp add: equal_real_def equal)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1527
63494
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1528
lemma [code nbe]: "HOL.equal x x \<longleftrightarrow> True"
ac0a3b9c6dae misc tuning and modernization;
wenzelm
parents: 63353
diff changeset
  1529
  for x :: real
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1530
  by (rule equal_refl)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1531
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1532
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1533
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1534
lemma real_less_eq_code [code]: "Ratreal x \<le> Ratreal y \<longleftrightarrow> x \<le> y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1535
  by (simp add: of_rat_less_eq)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1536
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1537
lemma real_less_code [code]: "Ratreal x < Ratreal y \<longleftrightarrow> x < y"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1538
  by (simp add: of_rat_less)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1539
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1540
lemma real_plus_code [code]: "Ratreal x + Ratreal y = Ratreal (x + y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1541
  by (simp add: of_rat_add)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1542
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1543
lemma real_times_code [code]: "Ratreal x * Ratreal y = Ratreal (x * y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1544
  by (simp add: of_rat_mult)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1545
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1546
lemma real_uminus_code [code]: "- Ratreal x = Ratreal (- x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1547
  by (simp add: of_rat_minus)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1548
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1549
lemma real_minus_code [code]: "Ratreal x - Ratreal y = Ratreal (x - y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1550
  by (simp add: of_rat_diff)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1551
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1552
lemma real_inverse_code [code]: "inverse (Ratreal x) = Ratreal (inverse x)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1553
  by (simp add: of_rat_inverse)
61284
2314c2f62eb1 real_of_nat_Suc is now a simprule
paulson <lp15@cam.ac.uk>
parents: 61204
diff changeset
  1554
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1555
lemma real_divide_code [code]: "Ratreal x / Ratreal y = Ratreal (x / y)"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1556
  by (simp add: of_rat_divide)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1557
61942
f02b26f7d39d prefer symbols for "floor", "ceiling";
wenzelm
parents: 61799
diff changeset
  1558
lemma real_floor_code [code]: "\<lfloor>Ratreal x\<rfloor> = \<lfloor>x\<rfloor>"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1559
  by (metis Ratreal_def floor_le_iff floor_unique le_floor_iff
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1560
      of_int_floor_le of_rat_of_int_eq real_less_eq_code)
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1561
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1562
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1563
text \<open>Quickcheck\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1564
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1565
definition (in term_syntax)
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1566
  valterm_ratreal :: "rat \<times> (unit \<Rightarrow> Code_Evaluation.term) \<Rightarrow> real \<times> (unit \<Rightarrow> Code_Evaluation.term)"
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1567
  where [code_unfold]: "valterm_ratreal k = Code_Evaluation.valtermify Ratreal {\<cdot>} k"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1568
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1569
notation fcomp (infixl "\<circ>>" 60)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1570
notation scomp (infixl "\<circ>\<rightarrow>" 60)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1571
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1572
instantiation real :: random
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1573
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1574
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1575
definition
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1576
  "Quickcheck_Random.random i = Quickcheck_Random.random i \<circ>\<rightarrow> (\<lambda>r. Pair (valterm_ratreal r))"
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1577
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1578
instance ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1579
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1580
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1581
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1582
no_notation fcomp (infixl "\<circ>>" 60)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1583
no_notation scomp (infixl "\<circ>\<rightarrow>" 60)
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1584
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1585
instantiation real :: exhaustive
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1586
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1587
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1588
definition
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1589
  "exhaustive_real f d = Quickcheck_Exhaustive.exhaustive (\<lambda>r. f (Ratreal r)) d"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1590
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1591
instance ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1592
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1593
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1594
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1595
instantiation real :: full_exhaustive
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1596
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1597
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1598
definition
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1599
  "full_exhaustive_real f d = Quickcheck_Exhaustive.full_exhaustive (\<lambda>r. f (valterm_ratreal r)) d"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1600
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1601
instance ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1602
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1603
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1604
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1605
instantiation real :: narrowing
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1606
begin
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1607
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1608
definition
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1609
  "narrowing_real = Quickcheck_Narrowing.apply (Quickcheck_Narrowing.cons Ratreal) narrowing"
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1610
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1611
instance ..
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1612
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1613
end
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1614
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1615
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1616
subsection \<open>Setup for Nitpick\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1617
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1618
declaration \<open>
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1619
  Nitpick_HOL.register_frac_type \<^type_name>\<open>real\<close>
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1620
    [(\<^const_name>\<open>zero_real_inst.zero_real\<close>, \<^const_name>\<open>Nitpick.zero_frac\<close>),
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1621
     (\<^const_name>\<open>one_real_inst.one_real\<close>, \<^const_name>\<open>Nitpick.one_frac\<close>),
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1622
     (\<^const_name>\<open>plus_real_inst.plus_real\<close>, \<^const_name>\<open>Nitpick.plus_frac\<close>),
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1623
     (\<^const_name>\<open>times_real_inst.times_real\<close>, \<^const_name>\<open>Nitpick.times_frac\<close>),
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1624
     (\<^const_name>\<open>uminus_real_inst.uminus_real\<close>, \<^const_name>\<open>Nitpick.uminus_frac\<close>),
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1625
     (\<^const_name>\<open>inverse_real_inst.inverse_real\<close>, \<^const_name>\<open>Nitpick.inverse_frac\<close>),
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1626
     (\<^const_name>\<open>ord_real_inst.less_real\<close>, \<^const_name>\<open>Nitpick.less_frac\<close>),
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 69502
diff changeset
  1627
     (\<^const_name>\<open>ord_real_inst.less_eq_real\<close>, \<^const_name>\<open>Nitpick.less_eq_frac\<close>)]
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1628
\<close>
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1629
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1630
lemmas [nitpick_unfold] = inverse_real_inst.inverse_real one_real_inst.one_real
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1631
  ord_real_inst.less_real ord_real_inst.less_eq_real plus_real_inst.plus_real
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1632
  times_real_inst.times_real uminus_real_inst.uminus_real
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1633
  zero_real_inst.zero_real
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1634
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents: 55945
diff changeset
  1635
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60429
diff changeset
  1636
subsection \<open>Setup for SMT\<close>
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents: 55945
diff changeset
  1637
69605
a96320074298 isabelle update -u path_cartouches;
wenzelm
parents: 69593
diff changeset
  1638
ML_file \<open>Tools/SMT/smt_real.ML\<close>
a96320074298 isabelle update -u path_cartouches;
wenzelm
parents: 69593
diff changeset
  1639
ML_file \<open>Tools/SMT/z3_real.ML\<close>
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents: 55945
diff changeset
  1640
58061
3d060f43accb renamed new SMT module from 'SMT2' to 'SMT'
blanchet
parents: 58055
diff changeset
  1641
lemma [z3_rule]:
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1642
  "0 + x = x"
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents: 55945
diff changeset
  1643
  "x + 0 = x"
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents: 55945
diff changeset
  1644
  "0 * x = 0"
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents: 55945
diff changeset
  1645
  "1 * x = x"
65885
77d922eff5ac added one more simplification to help replay
blanchet
parents: 64267
diff changeset
  1646
  "-x = -1 * x"
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents: 55945
diff changeset
  1647
  "x + y = y + x"
63353
176d1f408696 misc tuning and modernization;
wenzelm
parents: 63331
diff changeset
  1648
  for x y :: real
56078
624faeda77b5 moved 'SMT2' (SMT-LIB-2-based SMT module) into Isabelle
blanchet
parents: 55945
diff changeset
  1649
  by auto
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1650
63960
3daf02070be5 new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
boehmes
parents: 63680
diff changeset
  1651
3daf02070be5 new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
boehmes
parents: 63680
diff changeset
  1652
subsection \<open>Setup for Argo\<close>
3daf02070be5 new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
boehmes
parents: 63680
diff changeset
  1653
69605
a96320074298 isabelle update -u path_cartouches;
wenzelm
parents: 69593
diff changeset
  1654
ML_file \<open>Tools/Argo/argo_real.ML\<close>
63960
3daf02070be5 new proof method "argo" for a combination of quantifier-free propositional logic with equality and linear real arithmetic
boehmes
parents: 63680
diff changeset
  1655
51523
97b5e8a1291c rename RealDef to Real
hoelzl
parents:
diff changeset
  1656
end