src/HOL/Metric_Spaces.thy
author hoelzl
Fri, 22 Mar 2013 10:41:43 +0100
changeset 51473 1210309fddab
parent 51472 adb441e4b9e9
child 51474 1e9e68247ad1
permissions -rw-r--r--
move first_countable_topology to the HOL image
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51472
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
     1
(*  Title:      HOL/Metric_Spaces.thy
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
     2
    Author:     Brian Huffman
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
     3
    Author:     Johannes Hölzl
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
     4
*)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
     5
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
     6
header {* Metric Spaces *}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
     7
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
     8
theory Metric_Spaces
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
     9
imports RComplete Topological_Spaces
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    10
begin
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    11
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    12
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    13
subsection {* Metric spaces *}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    14
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    15
class dist =
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    16
  fixes dist :: "'a \<Rightarrow> 'a \<Rightarrow> real"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    17
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    18
class open_dist = "open" + dist +
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    19
  assumes open_dist: "open S \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    20
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    21
class metric_space = open_dist +
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    22
  assumes dist_eq_0_iff [simp]: "dist x y = 0 \<longleftrightarrow> x = y"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    23
  assumes dist_triangle2: "dist x y \<le> dist x z + dist y z"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    24
begin
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    25
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    26
lemma dist_self [simp]: "dist x x = 0"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    27
by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    28
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    29
lemma zero_le_dist [simp]: "0 \<le> dist x y"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    30
using dist_triangle2 [of x x y] by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    31
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    32
lemma zero_less_dist_iff: "0 < dist x y \<longleftrightarrow> x \<noteq> y"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    33
by (simp add: less_le)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    34
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    35
lemma dist_not_less_zero [simp]: "\<not> dist x y < 0"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    36
by (simp add: not_less)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    37
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    38
lemma dist_le_zero_iff [simp]: "dist x y \<le> 0 \<longleftrightarrow> x = y"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    39
by (simp add: le_less)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    40
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    41
lemma dist_commute: "dist x y = dist y x"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    42
proof (rule order_antisym)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    43
  show "dist x y \<le> dist y x"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    44
    using dist_triangle2 [of x y x] by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    45
  show "dist y x \<le> dist x y"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    46
    using dist_triangle2 [of y x y] by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    47
qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    48
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    49
lemma dist_triangle: "dist x z \<le> dist x y + dist y z"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    50
using dist_triangle2 [of x z y] by (simp add: dist_commute)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    51
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    52
lemma dist_triangle3: "dist x y \<le> dist a x + dist a y"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    53
using dist_triangle2 [of x y a] by (simp add: dist_commute)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    54
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    55
lemma dist_triangle_alt:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    56
  shows "dist y z <= dist x y + dist x z"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    57
by (rule dist_triangle3)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    58
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    59
lemma dist_pos_lt:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    60
  shows "x \<noteq> y ==> 0 < dist x y"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    61
by (simp add: zero_less_dist_iff)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    62
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    63
lemma dist_nz:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    64
  shows "x \<noteq> y \<longleftrightarrow> 0 < dist x y"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    65
by (simp add: zero_less_dist_iff)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    66
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    67
lemma dist_triangle_le:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    68
  shows "dist x z + dist y z <= e \<Longrightarrow> dist x y <= e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    69
by (rule order_trans [OF dist_triangle2])
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    70
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    71
lemma dist_triangle_lt:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    72
  shows "dist x z + dist y z < e ==> dist x y < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    73
by (rule le_less_trans [OF dist_triangle2])
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    74
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    75
lemma dist_triangle_half_l:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    76
  shows "dist x1 y < e / 2 \<Longrightarrow> dist x2 y < e / 2 \<Longrightarrow> dist x1 x2 < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    77
by (rule dist_triangle_lt [where z=y], simp)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    78
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    79
lemma dist_triangle_half_r:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    80
  shows "dist y x1 < e / 2 \<Longrightarrow> dist y x2 < e / 2 \<Longrightarrow> dist x1 x2 < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    81
by (rule dist_triangle_half_l, simp_all add: dist_commute)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    82
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    83
subclass topological_space
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    84
proof
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    85
  have "\<exists>e::real. 0 < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    86
    by (fast intro: zero_less_one)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    87
  then show "open UNIV"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    88
    unfolding open_dist by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    89
next
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    90
  fix S T assume "open S" "open T"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    91
  then show "open (S \<inter> T)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    92
    unfolding open_dist
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    93
    apply clarify
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    94
    apply (drule (1) bspec)+
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    95
    apply (clarify, rename_tac r s)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    96
    apply (rule_tac x="min r s" in exI, simp)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    97
    done
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    98
next
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
    99
  fix K assume "\<forall>S\<in>K. open S" thus "open (\<Union>K)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   100
    unfolding open_dist by fast
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   101
qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   102
51473
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   103
lemma open_ball: "open {y. dist x y < d}"
51472
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   104
proof (unfold open_dist, intro ballI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   105
  fix y assume *: "y \<in> {y. dist x y < d}"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   106
  then show "\<exists>e>0. \<forall>z. dist z y < e \<longrightarrow> z \<in> {y. dist x y < d}"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   107
    by (auto intro!: exI[of _ "d - dist x y"] simp: field_simps dist_triangle_lt)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   108
qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   109
51473
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   110
subclass first_countable_topology
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   111
proof
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   112
  fix x 
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   113
  show "\<exists>A::nat \<Rightarrow> 'a set. (\<forall>i. x \<in> A i \<and> open (A i)) \<and> (\<forall>S. open S \<and> x \<in> S \<longrightarrow> (\<exists>i. A i \<subseteq> S))"
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   114
  proof (safe intro!: exI[of _ "\<lambda>n. {y. dist x y < inverse (Suc n)}"])
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   115
    fix S assume "open S" "x \<in> S"
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   116
    then obtain e where "0 < e" "{y. dist x y < e} \<subseteq> S"
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   117
      by (auto simp: open_dist subset_eq dist_commute)
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   118
    moreover
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   119
    then obtain i where "inverse (Suc i) < e"
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   120
      by (auto dest!: reals_Archimedean)
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   121
    then have "{y. dist x y < inverse (Suc i)} \<subseteq> {y. dist x y < e}"
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   122
      by auto
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   123
    ultimately show "\<exists>i. {y. dist x y < inverse (Suc i)} \<subseteq> S"
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   124
      by blast
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   125
  qed (auto intro: open_ball)
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   126
qed
1210309fddab move first_countable_topology to the HOL image
hoelzl
parents: 51472
diff changeset
   127
51472
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   128
end
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   129
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   130
instance metric_space \<subseteq> t2_space
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   131
proof
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   132
  fix x y :: "'a::metric_space"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   133
  assume xy: "x \<noteq> y"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   134
  let ?U = "{y'. dist x y' < dist x y / 2}"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   135
  let ?V = "{x'. dist y x' < dist x y / 2}"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   136
  have th0: "\<And>d x y z. (d x z :: real) \<le> d x y + d y z \<Longrightarrow> d y z = d z y
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   137
               \<Longrightarrow> \<not>(d x y * 2 < d x z \<and> d z y * 2 < d x z)" by arith
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   138
  have "open ?U \<and> open ?V \<and> x \<in> ?U \<and> y \<in> ?V \<and> ?U \<inter> ?V = {}"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   139
    using dist_pos_lt[OF xy] th0[of dist, OF dist_triangle dist_commute]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   140
    using open_ball[of _ "dist x y / 2"] by auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   141
  then show "\<exists>U V. open U \<and> open V \<and> x \<in> U \<and> y \<in> V \<and> U \<inter> V = {}"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   142
    by blast
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   143
qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   144
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   145
lemma eventually_nhds_metric:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   146
  fixes a :: "'a :: metric_space"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   147
  shows "eventually P (nhds a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. dist x a < d \<longrightarrow> P x)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   148
unfolding eventually_nhds open_dist
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   149
apply safe
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   150
apply fast
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   151
apply (rule_tac x="{x. dist x a < d}" in exI, simp)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   152
apply clarsimp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   153
apply (rule_tac x="d - dist x a" in exI, clarsimp)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   154
apply (simp only: less_diff_eq)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   155
apply (erule le_less_trans [OF dist_triangle])
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   156
done
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   157
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   158
lemma eventually_at:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   159
  fixes a :: "'a::metric_space"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   160
  shows "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> P x)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   161
unfolding at_def eventually_within eventually_nhds_metric by auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   162
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   163
lemma eventually_within_less: (* COPY FROM Topo/eventually_within *)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   164
  fixes a :: "'a :: metric_space"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   165
  shows "eventually P (at a within S) \<longleftrightarrow> (\<exists>d>0. \<forall>x\<in>S. 0 < dist x a \<and> dist x a < d \<longrightarrow> P x)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   166
  unfolding eventually_within eventually_at dist_nz by auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   167
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   168
lemma eventually_within_le: (* COPY FROM Topo/eventually_within_le *)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   169
  fixes a :: "'a :: metric_space"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   170
  shows "eventually P (at a within S) \<longleftrightarrow> (\<exists>d>0. \<forall>x\<in>S. 0 < dist x a \<and> dist x a <= d \<longrightarrow> P x)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   171
  unfolding eventually_within_less by auto (metis dense order_le_less_trans)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   172
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   173
lemma tendstoI:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   174
  fixes l :: "'a :: metric_space"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   175
  assumes "\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   176
  shows "(f ---> l) F"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   177
  apply (rule topological_tendstoI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   178
  apply (simp add: open_dist)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   179
  apply (drule (1) bspec, clarify)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   180
  apply (drule assms)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   181
  apply (erule eventually_elim1, simp)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   182
  done
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   183
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   184
lemma tendstoD:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   185
  fixes l :: "'a :: metric_space"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   186
  shows "(f ---> l) F \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   187
  apply (drule_tac S="{x. dist x l < e}" in topological_tendstoD)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   188
  apply (clarsimp simp add: open_dist)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   189
  apply (rule_tac x="e - dist x l" in exI, clarsimp)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   190
  apply (simp only: less_diff_eq)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   191
  apply (erule le_less_trans [OF dist_triangle])
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   192
  apply simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   193
  apply simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   194
  done
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   195
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   196
lemma tendsto_iff:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   197
  fixes l :: "'a :: metric_space"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   198
  shows "(f ---> l) F \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) F)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   199
  using tendstoI tendstoD by fast
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   200
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   201
lemma metric_tendsto_imp_tendsto:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   202
  fixes a :: "'a :: metric_space" and b :: "'b :: metric_space"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   203
  assumes f: "(f ---> a) F"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   204
  assumes le: "eventually (\<lambda>x. dist (g x) b \<le> dist (f x) a) F"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   205
  shows "(g ---> b) F"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   206
proof (rule tendstoI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   207
  fix e :: real assume "0 < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   208
  with f have "eventually (\<lambda>x. dist (f x) a < e) F" by (rule tendstoD)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   209
  with le show "eventually (\<lambda>x. dist (g x) b < e) F"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   210
    using le_less_trans by (rule eventually_elim2)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   211
qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   212
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   213
lemma filterlim_real_sequentially: "LIM x sequentially. real x :> at_top"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   214
  unfolding filterlim_at_top
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   215
  apply (intro allI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   216
  apply (rule_tac c="natceiling (Z + 1)" in eventually_sequentiallyI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   217
  apply (auto simp: natceiling_le_eq)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   218
  done
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   219
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   220
subsubsection {* Limits of Sequences *}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   221
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   222
lemma LIMSEQ_def: "X ----> (L::'a::metric_space) \<longleftrightarrow> (\<forall>r>0. \<exists>no. \<forall>n\<ge>no. dist (X n) L < r)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   223
  unfolding tendsto_iff eventually_sequentially ..
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   224
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   225
lemma LIMSEQ_iff_nz: "X ----> (L::'a::metric_space) = (\<forall>r>0. \<exists>no>0. \<forall>n\<ge>no. dist (X n) L < r)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   226
  unfolding LIMSEQ_def by (metis Suc_leD zero_less_Suc)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   227
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   228
lemma metric_LIMSEQ_I:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   229
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. dist (X n) L < r) \<Longrightarrow> X ----> (L::'a::metric_space)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   230
by (simp add: LIMSEQ_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   231
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   232
lemma metric_LIMSEQ_D:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   233
  "\<lbrakk>X ----> (L::'a::metric_space); 0 < r\<rbrakk> \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. dist (X n) L < r"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   234
by (simp add: LIMSEQ_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   235
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   236
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   237
subsubsection {* Limits of Functions *}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   238
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   239
lemma LIM_def: "f -- (a::'a::metric_space) --> (L::'b::metric_space) =
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   240
     (\<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & dist x a < s
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   241
        --> dist (f x) L < r)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   242
unfolding tendsto_iff eventually_at ..
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   243
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   244
lemma metric_LIM_I:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   245
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x) L < r)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   246
    \<Longrightarrow> f -- (a::'a::metric_space) --> (L::'b::metric_space)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   247
by (simp add: LIM_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   248
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   249
lemma metric_LIM_D:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   250
  "\<lbrakk>f -- (a::'a::metric_space) --> (L::'b::metric_space); 0 < r\<rbrakk>
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   251
    \<Longrightarrow> \<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x) L < r"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   252
by (simp add: LIM_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   253
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   254
lemma metric_LIM_imp_LIM:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   255
  assumes f: "f -- a --> (l::'a::metric_space)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   256
  assumes le: "\<And>x. x \<noteq> a \<Longrightarrow> dist (g x) m \<le> dist (f x) l"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   257
  shows "g -- a --> (m::'b::metric_space)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   258
  by (rule metric_tendsto_imp_tendsto [OF f]) (auto simp add: eventually_at_topological le)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   259
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   260
lemma metric_LIM_equal2:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   261
  assumes 1: "0 < R"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   262
  assumes 2: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < R\<rbrakk> \<Longrightarrow> f x = g x"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   263
  shows "g -- a --> l \<Longrightarrow> f -- (a::'a::metric_space) --> l"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   264
apply (rule topological_tendstoI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   265
apply (drule (2) topological_tendstoD)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   266
apply (simp add: eventually_at, safe)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   267
apply (rule_tac x="min d R" in exI, safe)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   268
apply (simp add: 1)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   269
apply (simp add: 2)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   270
done
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   271
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   272
lemma metric_LIM_compose2:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   273
  assumes f: "f -- (a::'a::metric_space) --> b"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   274
  assumes g: "g -- b --> c"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   275
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> b"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   276
  shows "(\<lambda>x. g (f x)) -- a --> c"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   277
  using g f inj [folded eventually_at]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   278
  by (rule tendsto_compose_eventually)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   279
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   280
lemma metric_isCont_LIM_compose2:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   281
  fixes f :: "'a :: metric_space \<Rightarrow> _"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   282
  assumes f [unfolded isCont_def]: "isCont f a"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   283
  assumes g: "g -- f a --> l"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   284
  assumes inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> f x \<noteq> f a"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   285
  shows "(\<lambda>x. g (f x)) -- a --> l"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   286
by (rule metric_LIM_compose2 [OF f g inj])
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   287
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   288
subsection {* Complete metric spaces *}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   289
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   290
subsection {* Cauchy sequences *}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   291
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   292
definition (in metric_space) Cauchy :: "(nat \<Rightarrow> 'a) \<Rightarrow> bool" where
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   293
  "Cauchy X = (\<forall>e>0. \<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. dist (X m) (X n) < e)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   294
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   295
subsection {* Cauchy Sequences *}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   296
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   297
lemma metric_CauchyI:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   298
  "(\<And>e. 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < e) \<Longrightarrow> Cauchy X"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   299
  by (simp add: Cauchy_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   300
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   301
lemma metric_CauchyD:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   302
  "Cauchy X \<Longrightarrow> 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (X m) (X n) < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   303
  by (simp add: Cauchy_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   304
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   305
lemma metric_Cauchy_iff2:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   306
  "Cauchy X = (\<forall>j. (\<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. dist (X m) (X n) < inverse(real (Suc j))))"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   307
apply (simp add: Cauchy_def, auto)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   308
apply (drule reals_Archimedean, safe)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   309
apply (drule_tac x = n in spec, auto)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   310
apply (rule_tac x = M in exI, auto)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   311
apply (drule_tac x = m in spec, simp)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   312
apply (drule_tac x = na in spec, auto)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   313
done
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   314
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   315
lemma Cauchy_subseq_Cauchy:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   316
  "\<lbrakk> Cauchy X; subseq f \<rbrakk> \<Longrightarrow> Cauchy (X o f)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   317
apply (auto simp add: Cauchy_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   318
apply (drule_tac x=e in spec, clarify)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   319
apply (rule_tac x=M in exI, clarify)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   320
apply (blast intro: le_trans [OF _ seq_suble] dest!: spec)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   321
done
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   322
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   323
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   324
subsubsection {* Cauchy Sequences are Convergent *}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   325
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   326
class complete_space = metric_space +
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   327
  assumes Cauchy_convergent: "Cauchy X \<Longrightarrow> convergent X"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   328
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   329
theorem LIMSEQ_imp_Cauchy:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   330
  assumes X: "X ----> a" shows "Cauchy X"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   331
proof (rule metric_CauchyI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   332
  fix e::real assume "0 < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   333
  hence "0 < e/2" by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   334
  with X have "\<exists>N. \<forall>n\<ge>N. dist (X n) a < e/2" by (rule metric_LIMSEQ_D)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   335
  then obtain N where N: "\<forall>n\<ge>N. dist (X n) a < e/2" ..
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   336
  show "\<exists>N. \<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m) (X n) < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   337
  proof (intro exI allI impI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   338
    fix m assume "N \<le> m"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   339
    hence m: "dist (X m) a < e/2" using N by fast
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   340
    fix n assume "N \<le> n"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   341
    hence n: "dist (X n) a < e/2" using N by fast
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   342
    have "dist (X m) (X n) \<le> dist (X m) a + dist (X n) a"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   343
      by (rule dist_triangle2)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   344
    also from m n have "\<dots> < e" by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   345
    finally show "dist (X m) (X n) < e" .
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   346
  qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   347
qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   348
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   349
lemma convergent_Cauchy: "convergent X \<Longrightarrow> Cauchy X"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   350
unfolding convergent_def
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   351
by (erule exE, erule LIMSEQ_imp_Cauchy)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   352
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   353
lemma Cauchy_convergent_iff:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   354
  fixes X :: "nat \<Rightarrow> 'a::complete_space"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   355
  shows "Cauchy X = convergent X"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   356
by (fast intro: Cauchy_convergent convergent_Cauchy)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   357
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   358
subsection {* Uniform Continuity *}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   359
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   360
definition
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   361
  isUCont :: "['a::metric_space \<Rightarrow> 'b::metric_space] \<Rightarrow> bool" where
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   362
  "isUCont f = (\<forall>r>0. \<exists>s>0. \<forall>x y. dist x y < s \<longrightarrow> dist (f x) (f y) < r)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   363
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   364
lemma isUCont_isCont: "isUCont f ==> isCont f x"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   365
by (simp add: isUCont_def isCont_def LIM_def, force)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   366
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   367
lemma isUCont_Cauchy:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   368
  "\<lbrakk>isUCont f; Cauchy X\<rbrakk> \<Longrightarrow> Cauchy (\<lambda>n. f (X n))"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   369
unfolding isUCont_def
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   370
apply (rule metric_CauchyI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   371
apply (drule_tac x=e in spec, safe)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   372
apply (drule_tac e=s in metric_CauchyD, safe)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   373
apply (rule_tac x=M in exI, simp)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   374
done
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   375
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   376
subsection {* The set of real numbers is a complete metric space *}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   377
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   378
instantiation real :: metric_space
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   379
begin
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   380
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   381
definition dist_real_def:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   382
  "dist x y = \<bar>x - y\<bar>"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   383
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   384
definition open_real_def:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   385
  "open (S :: real set) \<longleftrightarrow> (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   386
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   387
instance
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   388
  by default (auto simp: open_real_def dist_real_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   389
end
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   390
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   391
instance real :: linorder_topology
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   392
proof
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   393
  show "(open :: real set \<Rightarrow> bool) = generate_topology (range lessThan \<union> range greaterThan)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   394
  proof (rule ext, safe)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   395
    fix S :: "real set" assume "open S"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   396
    then guess f unfolding open_real_def bchoice_iff ..
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   397
    then have *: "S = (\<Union>x\<in>S. {x - f x <..} \<inter> {..< x + f x})"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   398
      by (fastforce simp: dist_real_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   399
    show "generate_topology (range lessThan \<union> range greaterThan) S"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   400
      apply (subst *)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   401
      apply (intro generate_topology_Union generate_topology.Int)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   402
      apply (auto intro: generate_topology.Basis)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   403
      done
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   404
  next
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   405
    fix S :: "real set" assume "generate_topology (range lessThan \<union> range greaterThan) S"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   406
    moreover have "\<And>a::real. open {..<a}"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   407
      unfolding open_real_def dist_real_def
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   408
    proof clarify
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   409
      fix x a :: real assume "x < a"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   410
      hence "0 < a - x \<and> (\<forall>y. \<bar>y - x\<bar> < a - x \<longrightarrow> y \<in> {..<a})" by auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   411
      thus "\<exists>e>0. \<forall>y. \<bar>y - x\<bar> < e \<longrightarrow> y \<in> {..<a}" ..
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   412
    qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   413
    moreover have "\<And>a::real. open {a <..}"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   414
      unfolding open_real_def dist_real_def
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   415
    proof clarify
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   416
      fix x a :: real assume "a < x"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   417
      hence "0 < x - a \<and> (\<forall>y. \<bar>y - x\<bar> < x - a \<longrightarrow> y \<in> {a<..})" by auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   418
      thus "\<exists>e>0. \<forall>y. \<bar>y - x\<bar> < e \<longrightarrow> y \<in> {a<..}" ..
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   419
    qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   420
    ultimately show "open S"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   421
      by induct auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   422
  qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   423
qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   424
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   425
lemmas open_real_greaterThan = open_greaterThan[where 'a=real]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   426
lemmas open_real_lessThan = open_lessThan[where 'a=real]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   427
lemmas open_real_greaterThanLessThan = open_greaterThanLessThan[where 'a=real]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   428
lemmas closed_real_atMost = closed_atMost[where 'a=real]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   429
lemmas closed_real_atLeast = closed_atLeast[where 'a=real]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   430
lemmas closed_real_atLeastAtMost = closed_atLeastAtMost[where 'a=real]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   431
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   432
text {*
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   433
Proof that Cauchy sequences converge based on the one from
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   434
http://pirate.shu.edu/~wachsmut/ira/numseq/proofs/cauconv.html
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   435
*}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   436
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   437
text {*
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   438
  If sequence @{term "X"} is Cauchy, then its limit is the lub of
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   439
  @{term "{r::real. \<exists>N. \<forall>n\<ge>N. r < X n}"}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   440
*}
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   441
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   442
lemma isUb_UNIV_I: "(\<And>y. y \<in> S \<Longrightarrow> y \<le> u) \<Longrightarrow> isUb UNIV S u"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   443
by (simp add: isUbI setleI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   444
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   445
lemma increasing_LIMSEQ:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   446
  fixes f :: "nat \<Rightarrow> real"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   447
  assumes inc: "\<And>n. f n \<le> f (Suc n)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   448
      and bdd: "\<And>n. f n \<le> l"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   449
      and en: "\<And>e. 0 < e \<Longrightarrow> \<exists>n. l \<le> f n + e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   450
  shows "f ----> l"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   451
proof (rule increasing_tendsto)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   452
  fix x assume "x < l"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   453
  with dense[of 0 "l - x"] obtain e where "0 < e" "e < l - x"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   454
    by auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   455
  from en[OF `0 < e`] obtain n where "l - e \<le> f n"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   456
    by (auto simp: field_simps)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   457
  with `e < l - x` `0 < e` have "x < f n" by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   458
  with incseq_SucI[of f, OF inc] show "eventually (\<lambda>n. x < f n) sequentially"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   459
    by (auto simp: eventually_sequentially incseq_def intro: less_le_trans)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   460
qed (insert bdd, auto)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   461
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   462
lemma real_Cauchy_convergent:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   463
  fixes X :: "nat \<Rightarrow> real"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   464
  assumes X: "Cauchy X"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   465
  shows "convergent X"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   466
proof -
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   467
  def S \<equiv> "{x::real. \<exists>N. \<forall>n\<ge>N. x < X n}"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   468
  then have mem_S: "\<And>N x. \<forall>n\<ge>N. x < X n \<Longrightarrow> x \<in> S" by auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   469
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   470
  { fix N x assume N: "\<forall>n\<ge>N. X n < x"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   471
  have "isUb UNIV S x"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   472
  proof (rule isUb_UNIV_I)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   473
  fix y::real assume "y \<in> S"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   474
  hence "\<exists>M. \<forall>n\<ge>M. y < X n"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   475
    by (simp add: S_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   476
  then obtain M where "\<forall>n\<ge>M. y < X n" ..
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   477
  hence "y < X (max M N)" by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   478
  also have "\<dots> < x" using N by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   479
  finally show "y \<le> x"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   480
    by (rule order_less_imp_le)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   481
  qed }
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   482
  note bound_isUb = this 
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   483
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   484
  have "\<exists>u. isLub UNIV S u"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   485
  proof (rule reals_complete)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   486
  obtain N where "\<forall>m\<ge>N. \<forall>n\<ge>N. dist (X m) (X n) < 1"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   487
    using X[THEN metric_CauchyD, OF zero_less_one] by auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   488
  hence N: "\<forall>n\<ge>N. dist (X n) (X N) < 1" by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   489
  show "\<exists>x. x \<in> S"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   490
  proof
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   491
    from N have "\<forall>n\<ge>N. X N - 1 < X n"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   492
      by (simp add: abs_diff_less_iff dist_real_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   493
    thus "X N - 1 \<in> S" by (rule mem_S)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   494
  qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   495
  show "\<exists>u. isUb UNIV S u"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   496
  proof
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   497
    from N have "\<forall>n\<ge>N. X n < X N + 1"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   498
      by (simp add: abs_diff_less_iff dist_real_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   499
    thus "isUb UNIV S (X N + 1)"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   500
      by (rule bound_isUb)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   501
  qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   502
  qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   503
  then obtain x where x: "isLub UNIV S x" ..
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   504
  have "X ----> x"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   505
  proof (rule metric_LIMSEQ_I)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   506
  fix r::real assume "0 < r"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   507
  hence r: "0 < r/2" by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   508
  obtain N where "\<forall>n\<ge>N. \<forall>m\<ge>N. dist (X n) (X m) < r/2"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   509
    using metric_CauchyD [OF X r] by auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   510
  hence "\<forall>n\<ge>N. dist (X n) (X N) < r/2" by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   511
  hence N: "\<forall>n\<ge>N. X N - r/2 < X n \<and> X n < X N + r/2"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   512
    by (simp only: dist_real_def abs_diff_less_iff)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   513
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   514
  from N have "\<forall>n\<ge>N. X N - r/2 < X n" by fast
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   515
  hence "X N - r/2 \<in> S" by (rule mem_S)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   516
  hence 1: "X N - r/2 \<le> x" using x isLub_isUb isUbD by fast
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   517
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   518
  from N have "\<forall>n\<ge>N. X n < X N + r/2" by fast
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   519
  hence "isUb UNIV S (X N + r/2)" by (rule bound_isUb)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   520
  hence 2: "x \<le> X N + r/2" using x isLub_le_isUb by fast
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   521
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   522
  show "\<exists>N. \<forall>n\<ge>N. dist (X n) x < r"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   523
  proof (intro exI allI impI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   524
    fix n assume n: "N \<le> n"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   525
    from N n have "X n < X N + r/2" and "X N - r/2 < X n" by simp+
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   526
    thus "dist (X n) x < r" using 1 2
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   527
      by (simp add: abs_diff_less_iff dist_real_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   528
  qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   529
  qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   530
  then show ?thesis unfolding convergent_def by auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   531
qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   532
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   533
instance real :: complete_space
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   534
  by intro_classes (rule real_Cauchy_convergent)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   535
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   536
lemma tendsto_dist [tendsto_intros]:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   537
  fixes l m :: "'a :: metric_space"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   538
  assumes f: "(f ---> l) F" and g: "(g ---> m) F"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   539
  shows "((\<lambda>x. dist (f x) (g x)) ---> dist l m) F"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   540
proof (rule tendstoI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   541
  fix e :: real assume "0 < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   542
  hence e2: "0 < e/2" by simp
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   543
  from tendstoD [OF f e2] tendstoD [OF g e2]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   544
  show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) F"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   545
  proof (eventually_elim)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   546
    case (elim x)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   547
    then show "dist (dist (f x) (g x)) (dist l m) < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   548
      unfolding dist_real_def
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   549
      using dist_triangle2 [of "f x" "g x" "l"]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   550
      using dist_triangle2 [of "g x" "l" "m"]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   551
      using dist_triangle3 [of "l" "m" "f x"]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   552
      using dist_triangle [of "f x" "m" "g x"]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   553
      by arith
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   554
  qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   555
qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   556
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   557
lemma tendsto_at_topI_sequentially:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   558
  fixes f :: "real \<Rightarrow> real"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   559
  assumes mono: "mono f"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   560
  assumes limseq: "(\<lambda>n. f (real n)) ----> y"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   561
  shows "(f ---> y) at_top"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   562
proof (rule tendstoI)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   563
  fix e :: real assume "0 < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   564
  with limseq obtain N :: nat where N: "\<And>n. N \<le> n \<Longrightarrow> \<bar>f (real n) - y\<bar> < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   565
    by (auto simp: LIMSEQ_def dist_real_def)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   566
  { fix x :: real
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   567
    from ex_le_of_nat[of x] guess n ..
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   568
    note monoD[OF mono this]
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   569
    also have "f (real_of_nat n) \<le> y"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   570
      by (rule LIMSEQ_le_const[OF limseq])
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   571
         (auto intro: exI[of _ n] monoD[OF mono] simp: real_eq_of_nat[symmetric])
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   572
    finally have "f x \<le> y" . }
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   573
  note le = this
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   574
  have "eventually (\<lambda>x. real N \<le> x) at_top"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   575
    by (rule eventually_ge_at_top)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   576
  then show "eventually (\<lambda>x. dist (f x) y < e) at_top"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   577
  proof eventually_elim
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   578
    fix x assume N': "real N \<le> x"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   579
    with N[of N] le have "y - f (real N) < e" by auto
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   580
    moreover note monoD[OF mono N']
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   581
    ultimately show "dist (f x) y < e"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   582
      using le[of x] by (auto simp: dist_real_def field_simps)
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   583
  qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   584
qed
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   585
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   586
lemma Cauchy_iff2:
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   587
  "Cauchy X = (\<forall>j. (\<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. \<bar>X m - X n\<bar> < inverse(real (Suc j))))"
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   588
  unfolding metric_Cauchy_iff2 dist_real_def ..
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   589
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   590
end
adb441e4b9e9 move metric_space to its own theory
hoelzl
parents:
diff changeset
   591