src/HOL/Limits.thy
author eberlm <eberlm@in.tum.de>
Thu Aug 17 14:52:56 2017 +0200 (2017-08-17)
changeset 66447 a1f5c5c26fa6
parent 65680 378a2f11bec9
child 66456 621897f47fab
permissions -rw-r--r--
Replaced subseq with strict_mono
wenzelm@52265
     1
(*  Title:      HOL/Limits.thy
hoelzl@51526
     2
    Author:     Brian Huffman
hoelzl@51526
     3
    Author:     Jacques D. Fleuriot, University of Cambridge
hoelzl@51526
     4
    Author:     Lawrence C Paulson
hoelzl@51526
     5
    Author:     Jeremy Avigad
huffman@31349
     6
*)
huffman@31349
     7
wenzelm@60758
     8
section \<open>Limits on Real Vector Spaces\<close>
huffman@31349
     9
huffman@31349
    10
theory Limits
wenzelm@63546
    11
  imports Real_Vector_Spaces
huffman@31349
    12
begin
huffman@31349
    13
wenzelm@60758
    14
subsection \<open>Filter going to infinity norm\<close>
hoelzl@51526
    15
wenzelm@63546
    16
definition at_infinity :: "'a::real_normed_vector filter"
wenzelm@63546
    17
  where "at_infinity = (INF r. principal {x. r \<le> norm x})"
hoelzl@50324
    18
hoelzl@57276
    19
lemma eventually_at_infinity: "eventually P at_infinity \<longleftrightarrow> (\<exists>b. \<forall>x. b \<le> norm x \<longrightarrow> P x)"
hoelzl@57276
    20
  unfolding at_infinity_def
hoelzl@57276
    21
  by (subst eventually_INF_base)
hoelzl@57276
    22
     (auto simp: subset_eq eventually_principal intro!: exI[of _ "max a b" for a b])
huffman@31392
    23
lp15@62379
    24
corollary eventually_at_infinity_pos:
wenzelm@63546
    25
  "eventually p at_infinity \<longleftrightarrow> (\<exists>b. 0 < b \<and> (\<forall>x. norm x \<ge> b \<longrightarrow> p x))"
wenzelm@63546
    26
  apply (simp add: eventually_at_infinity)
wenzelm@63546
    27
  apply auto
wenzelm@63546
    28
  apply (case_tac "b \<le> 0")
wenzelm@63546
    29
  using norm_ge_zero order_trans zero_less_one apply blast
wenzelm@63546
    30
  apply force
wenzelm@63546
    31
  done
wenzelm@63546
    32
wenzelm@63546
    33
lemma at_infinity_eq_at_top_bot: "(at_infinity :: real filter) = sup at_top at_bot"
hoelzl@57276
    34
  apply (simp add: filter_eq_iff eventually_sup eventually_at_infinity
wenzelm@63546
    35
      eventually_at_top_linorder eventually_at_bot_linorder)
hoelzl@57276
    36
  apply safe
wenzelm@63546
    37
    apply (rule_tac x="b" in exI)
wenzelm@63546
    38
    apply simp
wenzelm@63546
    39
   apply (rule_tac x="- b" in exI)
wenzelm@63546
    40
   apply simp
wenzelm@63546
    41
  apply (rule_tac x="max (- Na) N" in exI)
wenzelm@63546
    42
  apply (auto simp: abs_real_def)
hoelzl@57276
    43
  done
hoelzl@50325
    44
hoelzl@57276
    45
lemma at_top_le_at_infinity: "at_top \<le> (at_infinity :: real filter)"
hoelzl@50325
    46
  unfolding at_infinity_eq_at_top_bot by simp
hoelzl@50325
    47
hoelzl@57276
    48
lemma at_bot_le_at_infinity: "at_bot \<le> (at_infinity :: real filter)"
hoelzl@50325
    49
  unfolding at_infinity_eq_at_top_bot by simp
hoelzl@50325
    50
wenzelm@63546
    51
lemma filterlim_at_top_imp_at_infinity: "filterlim f at_top F \<Longrightarrow> filterlim f at_infinity F"
wenzelm@63546
    52
  for f :: "_ \<Rightarrow> real"
hoelzl@57275
    53
  by (rule filterlim_mono[OF _ at_top_le_at_infinity order_refl])
hoelzl@57275
    54
wenzelm@63546
    55
lemma lim_infinity_imp_sequentially: "(f \<longlongrightarrow> l) at_infinity \<Longrightarrow> ((\<lambda>n. f(n)) \<longlongrightarrow> l) sequentially"
wenzelm@63546
    56
  by (simp add: filterlim_at_top_imp_at_infinity filterlim_compose filterlim_real_sequentially)
lp15@59613
    57
lp15@59613
    58
wenzelm@60758
    59
subsubsection \<open>Boundedness\<close>
hoelzl@51531
    60
wenzelm@63546
    61
definition Bfun :: "('a \<Rightarrow> 'b::metric_space) \<Rightarrow> 'a filter \<Rightarrow> bool"
wenzelm@63546
    62
  where Bfun_metric_def: "Bfun f F = (\<exists>y. \<exists>K>0. eventually (\<lambda>x. dist (f x) y \<le> K) F)"
wenzelm@63546
    63
wenzelm@63546
    64
abbreviation Bseq :: "(nat \<Rightarrow> 'a::metric_space) \<Rightarrow> bool"
wenzelm@63546
    65
  where "Bseq X \<equiv> Bfun X sequentially"
hoelzl@51531
    66
hoelzl@51531
    67
lemma Bseq_conv_Bfun: "Bseq X \<longleftrightarrow> Bfun X sequentially" ..
hoelzl@51531
    68
hoelzl@51531
    69
lemma Bseq_ignore_initial_segment: "Bseq X \<Longrightarrow> Bseq (\<lambda>n. X (n + k))"
hoelzl@51531
    70
  unfolding Bfun_metric_def by (subst eventually_sequentially_seg)
hoelzl@51531
    71
hoelzl@51531
    72
lemma Bseq_offset: "Bseq (\<lambda>n. X (n + k)) \<Longrightarrow> Bseq X"
hoelzl@51531
    73
  unfolding Bfun_metric_def by (subst (asm) eventually_sequentially_seg)
huffman@31355
    74
wenzelm@63546
    75
lemma Bfun_def: "Bfun f F \<longleftrightarrow> (\<exists>K>0. eventually (\<lambda>x. norm (f x) \<le> K) F)"
hoelzl@51474
    76
  unfolding Bfun_metric_def norm_conv_dist
hoelzl@51474
    77
proof safe
wenzelm@63546
    78
  fix y K
wenzelm@63546
    79
  assume K: "0 < K" and *: "eventually (\<lambda>x. dist (f x) y \<le> K) F"
hoelzl@51474
    80
  moreover have "eventually (\<lambda>x. dist (f x) 0 \<le> dist (f x) y + dist 0 y) F"
hoelzl@51474
    81
    by (intro always_eventually) (metis dist_commute dist_triangle)
hoelzl@51474
    82
  with * have "eventually (\<lambda>x. dist (f x) 0 \<le> K + dist 0 y) F"
hoelzl@51474
    83
    by eventually_elim auto
wenzelm@60758
    84
  with \<open>0 < K\<close> show "\<exists>K>0. eventually (\<lambda>x. dist (f x) 0 \<le> K) F"
hoelzl@51474
    85
    by (intro exI[of _ "K + dist 0 y"] add_pos_nonneg conjI zero_le_dist) auto
lp15@62379
    86
qed (force simp del: norm_conv_dist [symmetric])
huffman@31355
    87
huffman@31487
    88
lemma BfunI:
wenzelm@63546
    89
  assumes K: "eventually (\<lambda>x. norm (f x) \<le> K) F"
wenzelm@63546
    90
  shows "Bfun f F"
wenzelm@63546
    91
  unfolding Bfun_def
huffman@31355
    92
proof (intro exI conjI allI)
huffman@31355
    93
  show "0 < max K 1" by simp
huffman@44195
    94
  show "eventually (\<lambda>x. norm (f x) \<le> max K 1) F"
wenzelm@63546
    95
    using K by (rule eventually_mono) simp
huffman@31355
    96
qed
huffman@31355
    97
huffman@31355
    98
lemma BfunE:
huffman@44195
    99
  assumes "Bfun f F"
huffman@44195
   100
  obtains B where "0 < B" and "eventually (\<lambda>x. norm (f x) \<le> B) F"
wenzelm@63546
   101
  using assms unfolding Bfun_def by blast
huffman@31355
   102
hoelzl@51531
   103
lemma Cauchy_Bseq: "Cauchy X \<Longrightarrow> Bseq X"
hoelzl@51531
   104
  unfolding Cauchy_def Bfun_metric_def eventually_sequentially
hoelzl@51531
   105
  apply (erule_tac x=1 in allE)
hoelzl@51531
   106
  apply simp
hoelzl@51531
   107
  apply safe
hoelzl@51531
   108
  apply (rule_tac x="X M" in exI)
hoelzl@51531
   109
  apply (rule_tac x=1 in exI)
hoelzl@51531
   110
  apply (erule_tac x=M in allE)
hoelzl@51531
   111
  apply simp
hoelzl@51531
   112
  apply (rule_tac x=M in exI)
hoelzl@51531
   113
  apply (auto simp: dist_commute)
hoelzl@51531
   114
  done
hoelzl@51531
   115
hoelzl@51531
   116
wenzelm@60758
   117
subsubsection \<open>Bounded Sequences\<close>
hoelzl@51531
   118
hoelzl@51531
   119
lemma BseqI': "(\<And>n. norm (X n) \<le> K) \<Longrightarrow> Bseq X"
hoelzl@51531
   120
  by (intro BfunI) (auto simp: eventually_sequentially)
hoelzl@51531
   121
hoelzl@51531
   122
lemma BseqI2': "\<forall>n\<ge>N. norm (X n) \<le> K \<Longrightarrow> Bseq X"
hoelzl@51531
   123
  by (intro BfunI) (auto simp: eventually_sequentially)
hoelzl@51531
   124
hoelzl@51531
   125
lemma Bseq_def: "Bseq X \<longleftrightarrow> (\<exists>K>0. \<forall>n. norm (X n) \<le> K)"
hoelzl@51531
   126
  unfolding Bfun_def eventually_sequentially
hoelzl@51531
   127
proof safe
wenzelm@63546
   128
  fix N K
wenzelm@63546
   129
  assume "0 < K" "\<forall>n\<ge>N. norm (X n) \<le> K"
hoelzl@51531
   130
  then show "\<exists>K>0. \<forall>n. norm (X n) \<le> K"
haftmann@54863
   131
    by (intro exI[of _ "max (Max (norm ` X ` {..N})) K"] max.strict_coboundedI2)
hoelzl@51531
   132
       (auto intro!: imageI not_less[where 'a=nat, THEN iffD1] Max_ge simp: le_max_iff_disj)
hoelzl@51531
   133
qed auto
hoelzl@51531
   134
wenzelm@63546
   135
lemma BseqE: "Bseq X \<Longrightarrow> (\<And>K. 0 < K \<Longrightarrow> \<forall>n. norm (X n) \<le> K \<Longrightarrow> Q) \<Longrightarrow> Q"
wenzelm@63546
   136
  unfolding Bseq_def by auto
wenzelm@63546
   137
wenzelm@63546
   138
lemma BseqD: "Bseq X \<Longrightarrow> \<exists>K. 0 < K \<and> (\<forall>n. norm (X n) \<le> K)"
wenzelm@63546
   139
  by (simp add: Bseq_def)
wenzelm@63546
   140
wenzelm@63546
   141
lemma BseqI: "0 < K \<Longrightarrow> \<forall>n. norm (X n) \<le> K \<Longrightarrow> Bseq X"
wenzelm@63546
   142
  by (auto simp add: Bseq_def)
wenzelm@63546
   143
wenzelm@63546
   144
lemma Bseq_bdd_above: "Bseq X \<Longrightarrow> bdd_above (range X)"
wenzelm@63546
   145
  for X :: "nat \<Rightarrow> real"
hoelzl@54263
   146
proof (elim BseqE, intro bdd_aboveI2)
wenzelm@63546
   147
  fix K n
wenzelm@63546
   148
  assume "0 < K" "\<forall>n. norm (X n) \<le> K"
wenzelm@63546
   149
  then show "X n \<le> K"
hoelzl@54263
   150
    by (auto elim!: allE[of _ n])
hoelzl@54263
   151
qed
hoelzl@54263
   152
wenzelm@63546
   153
lemma Bseq_bdd_above': "Bseq X \<Longrightarrow> bdd_above (range (\<lambda>n. norm (X n)))"
wenzelm@63546
   154
  for X :: "nat \<Rightarrow> 'a :: real_normed_vector"
eberlm@61531
   155
proof (elim BseqE, intro bdd_aboveI2)
wenzelm@63546
   156
  fix K n
wenzelm@63546
   157
  assume "0 < K" "\<forall>n. norm (X n) \<le> K"
wenzelm@63546
   158
  then show "norm (X n) \<le> K"
eberlm@61531
   159
    by (auto elim!: allE[of _ n])
eberlm@61531
   160
qed
eberlm@61531
   161
wenzelm@63546
   162
lemma Bseq_bdd_below: "Bseq X \<Longrightarrow> bdd_below (range X)"
wenzelm@63546
   163
  for X :: "nat \<Rightarrow> real"
hoelzl@54263
   164
proof (elim BseqE, intro bdd_belowI2)
wenzelm@63546
   165
  fix K n
wenzelm@63546
   166
  assume "0 < K" "\<forall>n. norm (X n) \<le> K"
wenzelm@63546
   167
  then show "- K \<le> X n"
hoelzl@54263
   168
    by (auto elim!: allE[of _ n])
hoelzl@54263
   169
qed
hoelzl@54263
   170
eberlm@61531
   171
lemma Bseq_eventually_mono:
eberlm@61531
   172
  assumes "eventually (\<lambda>n. norm (f n) \<le> norm (g n)) sequentially" "Bseq g"
wenzelm@63546
   173
  shows "Bseq f"
eberlm@61531
   174
proof -
eberlm@61531
   175
  from assms(1) obtain N where N: "\<And>n. n \<ge> N \<Longrightarrow> norm (f n) \<le> norm (g n)"
eberlm@61531
   176
    by (auto simp: eventually_at_top_linorder)
wenzelm@63546
   177
  moreover from assms(2) obtain K where K: "\<And>n. norm (g n) \<le> K"
wenzelm@63546
   178
    by (blast elim!: BseqE)
eberlm@61531
   179
  ultimately have "norm (f n) \<le> max K (Max {norm (f n) |n. n < N})" for n
eberlm@61531
   180
    apply (cases "n < N")
wenzelm@63546
   181
    subgoal by (rule max.coboundedI2, rule Max.coboundedI) auto
wenzelm@63546
   182
    subgoal by (rule max.coboundedI1) (force intro: order.trans[OF N K])
eberlm@61531
   183
    done
wenzelm@63546
   184
  then show ?thesis by (blast intro: BseqI')
eberlm@61531
   185
qed
eberlm@61531
   186
wenzelm@63546
   187
lemma lemma_NBseq_def: "(\<exists>K > 0. \<forall>n. norm (X n) \<le> K) \<longleftrightarrow> (\<exists>N. \<forall>n. norm (X n) \<le> real(Suc N))"
hoelzl@51531
   188
proof safe
hoelzl@51531
   189
  fix K :: real
hoelzl@51531
   190
  from reals_Archimedean2 obtain n :: nat where "K < real n" ..
hoelzl@51531
   191
  then have "K \<le> real (Suc n)" by auto
hoelzl@51531
   192
  moreover assume "\<forall>m. norm (X m) \<le> K"
hoelzl@51531
   193
  ultimately have "\<forall>m. norm (X m) \<le> real (Suc n)"
hoelzl@51531
   194
    by (blast intro: order_trans)
hoelzl@51531
   195
  then show "\<exists>N. \<forall>n. norm (X n) \<le> real (Suc N)" ..
lp15@61649
   196
next
lp15@61649
   197
  show "\<And>N. \<forall>n. norm (X n) \<le> real (Suc N) \<Longrightarrow> \<exists>K>0. \<forall>n. norm (X n) \<le> K"
lp15@61649
   198
    using of_nat_0_less_iff by blast
lp15@61649
   199
qed
hoelzl@51531
   200
wenzelm@63546
   201
text \<open>Alternative definition for \<open>Bseq\<close>.\<close>
wenzelm@63546
   202
lemma Bseq_iff: "Bseq X \<longleftrightarrow> (\<exists>N. \<forall>n. norm (X n) \<le> real(Suc N))"
wenzelm@63546
   203
  by (simp add: Bseq_def) (simp add: lemma_NBseq_def)
wenzelm@63546
   204
wenzelm@63546
   205
lemma lemma_NBseq_def2: "(\<exists>K > 0. \<forall>n. norm (X n) \<le> K) = (\<exists>N. \<forall>n. norm (X n) < real(Suc N))"
wenzelm@63546
   206
  apply (subst lemma_NBseq_def)
wenzelm@63546
   207
  apply auto
wenzelm@63546
   208
   apply (rule_tac x = "Suc N" in exI)
wenzelm@63546
   209
   apply (rule_tac [2] x = N in exI)
wenzelm@63546
   210
   apply auto
wenzelm@63546
   211
   prefer 2 apply (blast intro: order_less_imp_le)
wenzelm@63546
   212
  apply (drule_tac x = n in spec)
wenzelm@63546
   213
  apply simp
wenzelm@63546
   214
  done
wenzelm@63546
   215
wenzelm@63546
   216
text \<open>Yet another definition for Bseq.\<close>
wenzelm@63546
   217
lemma Bseq_iff1a: "Bseq X \<longleftrightarrow> (\<exists>N. \<forall>n. norm (X n) < real (Suc N))"
wenzelm@63546
   218
  by (simp add: Bseq_def lemma_NBseq_def2)
wenzelm@63546
   219
wenzelm@63546
   220
subsubsection \<open>A Few More Equivalence Theorems for Boundedness\<close>
wenzelm@63546
   221
wenzelm@63546
   222
text \<open>Alternative formulation for boundedness.\<close>
wenzelm@63546
   223
lemma Bseq_iff2: "Bseq X \<longleftrightarrow> (\<exists>k > 0. \<exists>x. \<forall>n. norm (X n + - x) \<le> k)"
wenzelm@63546
   224
  apply (unfold Bseq_def)
wenzelm@63546
   225
  apply safe
wenzelm@63546
   226
   apply (rule_tac [2] x = "k + norm x" in exI)
wenzelm@63546
   227
   apply (rule_tac x = K in exI)
wenzelm@63546
   228
   apply simp
wenzelm@63546
   229
   apply (rule exI [where x = 0])
wenzelm@63546
   230
   apply auto
wenzelm@63546
   231
   apply (erule order_less_le_trans)
wenzelm@63546
   232
   apply simp
wenzelm@63546
   233
  apply (drule_tac x=n in spec)
wenzelm@63546
   234
  apply (drule order_trans [OF norm_triangle_ineq2])
wenzelm@63546
   235
  apply simp
wenzelm@63546
   236
  done
wenzelm@63546
   237
wenzelm@63546
   238
text \<open>Alternative formulation for boundedness.\<close>
wenzelm@63546
   239
lemma Bseq_iff3: "Bseq X \<longleftrightarrow> (\<exists>k>0. \<exists>N. \<forall>n. norm (X n + - X N) \<le> k)"
wenzelm@63546
   240
  (is "?P \<longleftrightarrow> ?Q")
haftmann@53602
   241
proof
haftmann@53602
   242
  assume ?P
wenzelm@63546
   243
  then obtain K where *: "0 < K" and **: "\<And>n. norm (X n) \<le> K"
wenzelm@63546
   244
    by (auto simp add: Bseq_def)
haftmann@53602
   245
  from * have "0 < K + norm (X 0)" by (rule order_less_le_trans) simp
haftmann@54230
   246
  from ** have "\<forall>n. norm (X n - X 0) \<le> K + norm (X 0)"
haftmann@54230
   247
    by (auto intro: order_trans norm_triangle_ineq4)
haftmann@54230
   248
  then have "\<forall>n. norm (X n + - X 0) \<le> K + norm (X 0)"
haftmann@54230
   249
    by simp
wenzelm@60758
   250
  with \<open>0 < K + norm (X 0)\<close> show ?Q by blast
haftmann@53602
   251
next
wenzelm@63546
   252
  assume ?Q
wenzelm@63546
   253
  then show ?P by (auto simp add: Bseq_iff2)
haftmann@53602
   254
qed
hoelzl@51531
   255
wenzelm@63546
   256
lemma BseqI2: "\<forall>n. k \<le> f n \<and> f n \<le> K \<Longrightarrow> Bseq f"
wenzelm@63546
   257
  for k K :: real
wenzelm@63546
   258
  apply (simp add: Bseq_def)
wenzelm@63546
   259
  apply (rule_tac x = "(\<bar>k\<bar> + \<bar>K\<bar>) + 1" in exI)
wenzelm@63546
   260
  apply auto
wenzelm@63546
   261
  apply (drule_tac x = n in spec)
wenzelm@63546
   262
  apply arith
wenzelm@63546
   263
  done
wenzelm@63546
   264
wenzelm@63546
   265
wenzelm@63546
   266
subsubsection \<open>Upper Bounds and Lubs of Bounded Sequences\<close>
wenzelm@63546
   267
wenzelm@63546
   268
lemma Bseq_minus_iff: "Bseq (\<lambda>n. - (X n) :: 'a::real_normed_vector) \<longleftrightarrow> Bseq X"
hoelzl@51531
   269
  by (simp add: Bseq_def)
hoelzl@51531
   270
paulson@62087
   271
lemma Bseq_add:
wenzelm@63546
   272
  fixes f :: "nat \<Rightarrow> 'a::real_normed_vector"
wenzelm@63546
   273
  assumes "Bseq f"
wenzelm@63546
   274
  shows "Bseq (\<lambda>x. f x + c)"
eberlm@61531
   275
proof -
wenzelm@63546
   276
  from assms obtain K where K: "\<And>x. norm (f x) \<le> K"
wenzelm@63546
   277
    unfolding Bseq_def by blast
eberlm@61531
   278
  {
eberlm@61531
   279
    fix x :: nat
eberlm@61531
   280
    have "norm (f x + c) \<le> norm (f x) + norm c" by (rule norm_triangle_ineq)
eberlm@61531
   281
    also have "norm (f x) \<le> K" by (rule K)
eberlm@61531
   282
    finally have "norm (f x + c) \<le> K + norm c" by simp
eberlm@61531
   283
  }
wenzelm@63546
   284
  then show ?thesis by (rule BseqI')
eberlm@61531
   285
qed
eberlm@61531
   286
wenzelm@63546
   287
lemma Bseq_add_iff: "Bseq (\<lambda>x. f x + c) \<longleftrightarrow> Bseq f"
wenzelm@63546
   288
  for f :: "nat \<Rightarrow> 'a::real_normed_vector"
eberlm@61531
   289
  using Bseq_add[of f c] Bseq_add[of "\<lambda>x. f x + c" "-c"] by auto
eberlm@61531
   290
paulson@62087
   291
lemma Bseq_mult:
wenzelm@63546
   292
  fixes f g :: "nat \<Rightarrow> 'a::real_normed_field"
wenzelm@63546
   293
  assumes "Bseq f" and "Bseq g"
wenzelm@63546
   294
  shows "Bseq (\<lambda>x. f x * g x)"
eberlm@61531
   295
proof -
wenzelm@63546
   296
  from assms obtain K1 K2 where K: "norm (f x) \<le> K1" "K1 > 0" "norm (g x) \<le> K2" "K2 > 0"
wenzelm@63546
   297
    for x
eberlm@61531
   298
    unfolding Bseq_def by blast
wenzelm@63546
   299
  then have "norm (f x * g x) \<le> K1 * K2" for x
wenzelm@63546
   300
    by (auto simp: norm_mult intro!: mult_mono)
wenzelm@63546
   301
  then show ?thesis by (rule BseqI')
eberlm@61531
   302
qed
eberlm@61531
   303
eberlm@61531
   304
lemma Bfun_const [simp]: "Bfun (\<lambda>_. c) F"
eberlm@61531
   305
  unfolding Bfun_metric_def by (auto intro!: exI[of _ c] exI[of _ "1::real"])
eberlm@61531
   306
wenzelm@63546
   307
lemma Bseq_cmult_iff:
wenzelm@63546
   308
  fixes c :: "'a::real_normed_field"
wenzelm@63546
   309
  assumes "c \<noteq> 0"
wenzelm@63546
   310
  shows "Bseq (\<lambda>x. c * f x) \<longleftrightarrow> Bseq f"
eberlm@61531
   311
proof
wenzelm@63546
   312
  assume "Bseq (\<lambda>x. c * f x)"
wenzelm@63546
   313
  with Bfun_const have "Bseq (\<lambda>x. inverse c * (c * f x))"
wenzelm@63546
   314
    by (rule Bseq_mult)
wenzelm@63546
   315
  with \<open>c \<noteq> 0\<close> show "Bseq f"
wenzelm@63546
   316
    by (simp add: divide_simps)
eberlm@61531
   317
qed (intro Bseq_mult Bfun_const)
eberlm@61531
   318
wenzelm@63546
   319
lemma Bseq_subseq: "Bseq f \<Longrightarrow> Bseq (\<lambda>x. f (g x))"
wenzelm@63546
   320
  for f :: "nat \<Rightarrow> 'a::real_normed_vector"
eberlm@61531
   321
  unfolding Bseq_def by auto
eberlm@61531
   322
wenzelm@63546
   323
lemma Bseq_Suc_iff: "Bseq (\<lambda>n. f (Suc n)) \<longleftrightarrow> Bseq f"
wenzelm@63546
   324
  for f :: "nat \<Rightarrow> 'a::real_normed_vector"
eberlm@61531
   325
  using Bseq_offset[of f 1] by (auto intro: Bseq_subseq)
eberlm@61531
   326
eberlm@61531
   327
lemma increasing_Bseq_subseq_iff:
eberlm@66447
   328
  assumes "\<And>x y. x \<le> y \<Longrightarrow> norm (f x :: 'a::real_normed_vector) \<le> norm (f y)" "strict_mono g"
wenzelm@63546
   329
  shows "Bseq (\<lambda>x. f (g x)) \<longleftrightarrow> Bseq f"
eberlm@61531
   330
proof
eberlm@61531
   331
  assume "Bseq (\<lambda>x. f (g x))"
wenzelm@63546
   332
  then obtain K where K: "\<And>x. norm (f (g x)) \<le> K"
wenzelm@63546
   333
    unfolding Bseq_def by auto
eberlm@61531
   334
  {
eberlm@61531
   335
    fix x :: nat
eberlm@61531
   336
    from filterlim_subseq[OF assms(2)] obtain y where "g y \<ge> x"
eberlm@61531
   337
      by (auto simp: filterlim_at_top eventually_at_top_linorder)
wenzelm@63546
   338
    then have "norm (f x) \<le> norm (f (g y))"
wenzelm@63546
   339
      using assms(1) by blast
eberlm@61531
   340
    also have "norm (f (g y)) \<le> K" by (rule K)
eberlm@61531
   341
    finally have "norm (f x) \<le> K" .
eberlm@61531
   342
  }
wenzelm@63546
   343
  then show "Bseq f" by (rule BseqI')
wenzelm@63546
   344
qed (use Bseq_subseq[of f g] in simp_all)
eberlm@61531
   345
eberlm@61531
   346
lemma nonneg_incseq_Bseq_subseq_iff:
wenzelm@63546
   347
  fixes f :: "nat \<Rightarrow> real"
wenzelm@63546
   348
    and g :: "nat \<Rightarrow> nat"
eberlm@66447
   349
  assumes "\<And>x. f x \<ge> 0" "incseq f" "strict_mono g"
wenzelm@63546
   350
  shows "Bseq (\<lambda>x. f (g x)) \<longleftrightarrow> Bseq f"
eberlm@61531
   351
  using assms by (intro increasing_Bseq_subseq_iff) (auto simp: incseq_def)
eberlm@61531
   352
wenzelm@63546
   353
lemma Bseq_eq_bounded: "range f \<subseteq> {a..b} \<Longrightarrow> Bseq f"
wenzelm@63546
   354
  for a b :: real
hoelzl@51531
   355
  apply (simp add: subset_eq)
hoelzl@51531
   356
  apply (rule BseqI'[where K="max (norm a) (norm b)"])
hoelzl@51531
   357
  apply (erule_tac x=n in allE)
hoelzl@51531
   358
  apply auto
hoelzl@51531
   359
  done
hoelzl@51531
   360
wenzelm@63546
   361
lemma incseq_bounded: "incseq X \<Longrightarrow> \<forall>i. X i \<le> B \<Longrightarrow> Bseq X"
wenzelm@63546
   362
  for B :: real
hoelzl@51531
   363
  by (intro Bseq_eq_bounded[of X "X 0" B]) (auto simp: incseq_def)
hoelzl@51531
   364
wenzelm@63546
   365
lemma decseq_bounded: "decseq X \<Longrightarrow> \<forall>i. B \<le> X i \<Longrightarrow> Bseq X"
wenzelm@63546
   366
  for B :: real
hoelzl@51531
   367
  by (intro Bseq_eq_bounded[of X B "X 0"]) (auto simp: decseq_def)
hoelzl@51531
   368
wenzelm@63546
   369
wenzelm@60758
   370
subsection \<open>Bounded Monotonic Sequences\<close>
hoelzl@51531
   371
wenzelm@63546
   372
subsubsection \<open>A Bounded and Monotonic Sequence Converges\<close>
hoelzl@51531
   373
hoelzl@51531
   374
(* TODO: delete *)
hoelzl@51531
   375
(* FIXME: one use in NSA/HSEQ.thy *)
wenzelm@63546
   376
lemma Bmonoseq_LIMSEQ: "\<forall>n. m \<le> n \<longrightarrow> X n = X m \<Longrightarrow> \<exists>L. X \<longlonglongrightarrow> L"
hoelzl@51531
   377
  apply (rule_tac x="X m" in exI)
hoelzl@51531
   378
  apply (rule filterlim_cong[THEN iffD2, OF refl refl _ tendsto_const])
hoelzl@51531
   379
  unfolding eventually_sequentially
hoelzl@51531
   380
  apply blast
hoelzl@51531
   381
  done
hoelzl@51531
   382
wenzelm@63546
   383
wenzelm@60758
   384
subsection \<open>Convergence to Zero\<close>
huffman@31349
   385
huffman@44081
   386
definition Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
   387
  where "Zfun f F = (\<forall>r>0. eventually (\<lambda>x. norm (f x) < r) F)"
huffman@31349
   388
wenzelm@63546
   389
lemma ZfunI: "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F) \<Longrightarrow> Zfun f F"
wenzelm@63546
   390
  by (simp add: Zfun_def)
wenzelm@63546
   391
wenzelm@63546
   392
lemma ZfunD: "Zfun f F \<Longrightarrow> 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F"
wenzelm@63546
   393
  by (simp add: Zfun_def)
wenzelm@63546
   394
wenzelm@63546
   395
lemma Zfun_ssubst: "eventually (\<lambda>x. f x = g x) F \<Longrightarrow> Zfun g F \<Longrightarrow> Zfun f F"
huffman@44081
   396
  unfolding Zfun_def by (auto elim!: eventually_rev_mp)
huffman@31355
   397
huffman@44195
   398
lemma Zfun_zero: "Zfun (\<lambda>x. 0) F"
huffman@44081
   399
  unfolding Zfun_def by simp
huffman@31349
   400
huffman@44195
   401
lemma Zfun_norm_iff: "Zfun (\<lambda>x. norm (f x)) F = Zfun (\<lambda>x. f x) F"
huffman@44081
   402
  unfolding Zfun_def by simp
huffman@31349
   403
huffman@31349
   404
lemma Zfun_imp_Zfun:
huffman@44195
   405
  assumes f: "Zfun f F"
wenzelm@63546
   406
    and g: "eventually (\<lambda>x. norm (g x) \<le> norm (f x) * K) F"
huffman@44195
   407
  shows "Zfun (\<lambda>x. g x) F"
wenzelm@63546
   408
proof (cases "0 < K")
wenzelm@63546
   409
  case K: True
huffman@31349
   410
  show ?thesis
huffman@31349
   411
  proof (rule ZfunI)
wenzelm@63546
   412
    fix r :: real
wenzelm@63546
   413
    assume "0 < r"
wenzelm@63546
   414
    then have "0 < r / K" using K by simp
huffman@44195
   415
    then have "eventually (\<lambda>x. norm (f x) < r / K) F"
lp15@61649
   416
      using ZfunD [OF f] by blast
huffman@44195
   417
    with g show "eventually (\<lambda>x. norm (g x) < r) F"
noschinl@46887
   418
    proof eventually_elim
noschinl@46887
   419
      case (elim x)
wenzelm@63546
   420
      then have "norm (f x) * K < r"
huffman@31349
   421
        by (simp add: pos_less_divide_eq K)
wenzelm@63546
   422
      then show ?case
noschinl@46887
   423
        by (simp add: order_le_less_trans [OF elim(1)])
huffman@31349
   424
    qed
huffman@31349
   425
  qed
huffman@31349
   426
next
wenzelm@63546
   427
  case False
wenzelm@63546
   428
  then have K: "K \<le> 0" by (simp only: not_less)
huffman@31355
   429
  show ?thesis
huffman@31355
   430
  proof (rule ZfunI)
huffman@31355
   431
    fix r :: real
huffman@31355
   432
    assume "0 < r"
huffman@44195
   433
    from g show "eventually (\<lambda>x. norm (g x) < r) F"
noschinl@46887
   434
    proof eventually_elim
noschinl@46887
   435
      case (elim x)
noschinl@46887
   436
      also have "norm (f x) * K \<le> norm (f x) * 0"
huffman@31355
   437
        using K norm_ge_zero by (rule mult_left_mono)
noschinl@46887
   438
      finally show ?case
wenzelm@60758
   439
        using \<open>0 < r\<close> by simp
huffman@31355
   440
    qed
huffman@31355
   441
  qed
huffman@31349
   442
qed
huffman@31349
   443
wenzelm@63546
   444
lemma Zfun_le: "Zfun g F \<Longrightarrow> \<forall>x. norm (f x) \<le> norm (g x) \<Longrightarrow> Zfun f F"
wenzelm@63546
   445
  by (erule Zfun_imp_Zfun [where K = 1]) simp
huffman@31349
   446
huffman@31349
   447
lemma Zfun_add:
wenzelm@63546
   448
  assumes f: "Zfun f F"
wenzelm@63546
   449
    and g: "Zfun g F"
huffman@44195
   450
  shows "Zfun (\<lambda>x. f x + g x) F"
huffman@31349
   451
proof (rule ZfunI)
wenzelm@63546
   452
  fix r :: real
wenzelm@63546
   453
  assume "0 < r"
wenzelm@63546
   454
  then have r: "0 < r / 2" by simp
huffman@44195
   455
  have "eventually (\<lambda>x. norm (f x) < r/2) F"
huffman@31487
   456
    using f r by (rule ZfunD)
huffman@31349
   457
  moreover
huffman@44195
   458
  have "eventually (\<lambda>x. norm (g x) < r/2) F"
huffman@31487
   459
    using g r by (rule ZfunD)
huffman@31349
   460
  ultimately
huffman@44195
   461
  show "eventually (\<lambda>x. norm (f x + g x) < r) F"
noschinl@46887
   462
  proof eventually_elim
noschinl@46887
   463
    case (elim x)
huffman@31487
   464
    have "norm (f x + g x) \<le> norm (f x) + norm (g x)"
huffman@31349
   465
      by (rule norm_triangle_ineq)
huffman@31349
   466
    also have "\<dots> < r/2 + r/2"
noschinl@46887
   467
      using elim by (rule add_strict_mono)
noschinl@46887
   468
    finally show ?case
huffman@31349
   469
      by simp
huffman@31349
   470
  qed
huffman@31349
   471
qed
huffman@31349
   472
huffman@44195
   473
lemma Zfun_minus: "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. - f x) F"
huffman@44081
   474
  unfolding Zfun_def by simp
huffman@31349
   475
wenzelm@63546
   476
lemma Zfun_diff: "Zfun f F \<Longrightarrow> Zfun g F \<Longrightarrow> Zfun (\<lambda>x. f x - g x) F"
haftmann@54230
   477
  using Zfun_add [of f F "\<lambda>x. - g x"] by (simp add: Zfun_minus)
huffman@31349
   478
huffman@31349
   479
lemma (in bounded_linear) Zfun:
huffman@44195
   480
  assumes g: "Zfun g F"
huffman@44195
   481
  shows "Zfun (\<lambda>x. f (g x)) F"
huffman@31349
   482
proof -
wenzelm@63546
   483
  obtain K where "norm (f x) \<le> norm x * K" for x
lp15@61649
   484
    using bounded by blast
huffman@44195
   485
  then have "eventually (\<lambda>x. norm (f (g x)) \<le> norm (g x) * K) F"
huffman@31355
   486
    by simp
huffman@31487
   487
  with g show ?thesis
huffman@31349
   488
    by (rule Zfun_imp_Zfun)
huffman@31349
   489
qed
huffman@31349
   490
huffman@31349
   491
lemma (in bounded_bilinear) Zfun:
huffman@44195
   492
  assumes f: "Zfun f F"
wenzelm@63546
   493
    and g: "Zfun g F"
huffman@44195
   494
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31349
   495
proof (rule ZfunI)
wenzelm@63546
   496
  fix r :: real
wenzelm@63546
   497
  assume r: "0 < r"
huffman@31349
   498
  obtain K where K: "0 < K"
wenzelm@63546
   499
    and norm_le: "norm (x ** y) \<le> norm x * norm y * K" for x y
lp15@61649
   500
    using pos_bounded by blast
huffman@31349
   501
  from K have K': "0 < inverse K"
huffman@31349
   502
    by (rule positive_imp_inverse_positive)
huffman@44195
   503
  have "eventually (\<lambda>x. norm (f x) < r) F"
huffman@31487
   504
    using f r by (rule ZfunD)
huffman@31349
   505
  moreover
huffman@44195
   506
  have "eventually (\<lambda>x. norm (g x) < inverse K) F"
huffman@31487
   507
    using g K' by (rule ZfunD)
huffman@31349
   508
  ultimately
huffman@44195
   509
  show "eventually (\<lambda>x. norm (f x ** g x) < r) F"
noschinl@46887
   510
  proof eventually_elim
noschinl@46887
   511
    case (elim x)
huffman@31487
   512
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31349
   513
      by (rule norm_le)
huffman@31487
   514
    also have "norm (f x) * norm (g x) * K < r * inverse K * K"
noschinl@46887
   515
      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero elim K)
huffman@31349
   516
    also from K have "r * inverse K * K = r"
huffman@31349
   517
      by simp
noschinl@46887
   518
    finally show ?case .
huffman@31349
   519
  qed
huffman@31349
   520
qed
huffman@31349
   521
wenzelm@63546
   522
lemma (in bounded_bilinear) Zfun_left: "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. f x ** a) F"
huffman@44081
   523
  by (rule bounded_linear_left [THEN bounded_linear.Zfun])
huffman@31349
   524
wenzelm@63546
   525
lemma (in bounded_bilinear) Zfun_right: "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. a ** f x) F"
huffman@44081
   526
  by (rule bounded_linear_right [THEN bounded_linear.Zfun])
huffman@31349
   527
huffman@44282
   528
lemmas Zfun_mult = bounded_bilinear.Zfun [OF bounded_bilinear_mult]
huffman@44282
   529
lemmas Zfun_mult_right = bounded_bilinear.Zfun_right [OF bounded_bilinear_mult]
huffman@44282
   530
lemmas Zfun_mult_left = bounded_bilinear.Zfun_left [OF bounded_bilinear_mult]
huffman@31349
   531
wenzelm@61973
   532
lemma tendsto_Zfun_iff: "(f \<longlongrightarrow> a) F = Zfun (\<lambda>x. f x - a) F"
huffman@44081
   533
  by (simp only: tendsto_iff Zfun_def dist_norm)
huffman@31349
   534
wenzelm@63546
   535
lemma tendsto_0_le:
wenzelm@63546
   536
  "(f \<longlongrightarrow> 0) F \<Longrightarrow> eventually (\<lambda>x. norm (g x) \<le> norm (f x) * K) F \<Longrightarrow> (g \<longlongrightarrow> 0) F"
lp15@56366
   537
  by (simp add: Zfun_imp_Zfun tendsto_Zfun_iff)
lp15@56366
   538
wenzelm@63546
   539
wenzelm@60758
   540
subsubsection \<open>Distance and norms\<close>
huffman@36662
   541
hoelzl@51531
   542
lemma tendsto_dist [tendsto_intros]:
wenzelm@63546
   543
  fixes l m :: "'a::metric_space"
wenzelm@63546
   544
  assumes f: "(f \<longlongrightarrow> l) F"
wenzelm@63546
   545
    and g: "(g \<longlongrightarrow> m) F"
wenzelm@61973
   546
  shows "((\<lambda>x. dist (f x) (g x)) \<longlongrightarrow> dist l m) F"
hoelzl@51531
   547
proof (rule tendstoI)
wenzelm@63546
   548
  fix e :: real
wenzelm@63546
   549
  assume "0 < e"
wenzelm@63546
   550
  then have e2: "0 < e/2" by simp
hoelzl@51531
   551
  from tendstoD [OF f e2] tendstoD [OF g e2]
hoelzl@51531
   552
  show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) F"
hoelzl@51531
   553
  proof (eventually_elim)
hoelzl@51531
   554
    case (elim x)
hoelzl@51531
   555
    then show "dist (dist (f x) (g x)) (dist l m) < e"
hoelzl@51531
   556
      unfolding dist_real_def
hoelzl@51531
   557
      using dist_triangle2 [of "f x" "g x" "l"]
wenzelm@63546
   558
        and dist_triangle2 [of "g x" "l" "m"]
wenzelm@63546
   559
        and dist_triangle3 [of "l" "m" "f x"]
wenzelm@63546
   560
        and dist_triangle [of "f x" "m" "g x"]
hoelzl@51531
   561
      by arith
hoelzl@51531
   562
  qed
hoelzl@51531
   563
qed
hoelzl@51531
   564
hoelzl@51531
   565
lemma continuous_dist[continuous_intros]:
hoelzl@51531
   566
  fixes f g :: "_ \<Rightarrow> 'a :: metric_space"
hoelzl@51531
   567
  shows "continuous F f \<Longrightarrow> continuous F g \<Longrightarrow> continuous F (\<lambda>x. dist (f x) (g x))"
hoelzl@51531
   568
  unfolding continuous_def by (rule tendsto_dist)
hoelzl@51531
   569
hoelzl@56371
   570
lemma continuous_on_dist[continuous_intros]:
hoelzl@51531
   571
  fixes f g :: "_ \<Rightarrow> 'a :: metric_space"
hoelzl@51531
   572
  shows "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> continuous_on s (\<lambda>x. dist (f x) (g x))"
hoelzl@51531
   573
  unfolding continuous_on_def by (auto intro: tendsto_dist)
hoelzl@51531
   574
wenzelm@63546
   575
lemma tendsto_norm [tendsto_intros]: "(f \<longlongrightarrow> a) F \<Longrightarrow> ((\<lambda>x. norm (f x)) \<longlongrightarrow> norm a) F"
huffman@44081
   576
  unfolding norm_conv_dist by (intro tendsto_intros)
huffman@36662
   577
wenzelm@63546
   578
lemma continuous_norm [continuous_intros]: "continuous F f \<Longrightarrow> continuous F (\<lambda>x. norm (f x))"
hoelzl@51478
   579
  unfolding continuous_def by (rule tendsto_norm)
hoelzl@51478
   580
hoelzl@56371
   581
lemma continuous_on_norm [continuous_intros]:
hoelzl@51478
   582
  "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. norm (f x))"
hoelzl@51478
   583
  unfolding continuous_on_def by (auto intro: tendsto_norm)
hoelzl@51478
   584
wenzelm@63546
   585
lemma tendsto_norm_zero: "(f \<longlongrightarrow> 0) F \<Longrightarrow> ((\<lambda>x. norm (f x)) \<longlongrightarrow> 0) F"
wenzelm@63546
   586
  by (drule tendsto_norm) simp
wenzelm@63546
   587
wenzelm@63546
   588
lemma tendsto_norm_zero_cancel: "((\<lambda>x. norm (f x)) \<longlongrightarrow> 0) F \<Longrightarrow> (f \<longlongrightarrow> 0) F"
huffman@44081
   589
  unfolding tendsto_iff dist_norm by simp
huffman@36662
   590
wenzelm@63546
   591
lemma tendsto_norm_zero_iff: "((\<lambda>x. norm (f x)) \<longlongrightarrow> 0) F \<longleftrightarrow> (f \<longlongrightarrow> 0) F"
huffman@44081
   592
  unfolding tendsto_iff dist_norm by simp
huffman@31349
   593
wenzelm@63546
   594
lemma tendsto_rabs [tendsto_intros]: "(f \<longlongrightarrow> l) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) \<longlongrightarrow> \<bar>l\<bar>) F"
wenzelm@63546
   595
  for l :: real
wenzelm@63546
   596
  by (fold real_norm_def) (rule tendsto_norm)
huffman@44194
   597
hoelzl@51478
   598
lemma continuous_rabs [continuous_intros]:
hoelzl@51478
   599
  "continuous F f \<Longrightarrow> continuous F (\<lambda>x. \<bar>f x :: real\<bar>)"
hoelzl@51478
   600
  unfolding real_norm_def[symmetric] by (rule continuous_norm)
hoelzl@51478
   601
hoelzl@56371
   602
lemma continuous_on_rabs [continuous_intros]:
hoelzl@51478
   603
  "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. \<bar>f x :: real\<bar>)"
hoelzl@51478
   604
  unfolding real_norm_def[symmetric] by (rule continuous_on_norm)
hoelzl@51478
   605
wenzelm@63546
   606
lemma tendsto_rabs_zero: "(f \<longlongrightarrow> (0::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) \<longlongrightarrow> 0) F"
wenzelm@63546
   607
  by (fold real_norm_def) (rule tendsto_norm_zero)
wenzelm@63546
   608
wenzelm@63546
   609
lemma tendsto_rabs_zero_cancel: "((\<lambda>x. \<bar>f x\<bar>) \<longlongrightarrow> (0::real)) F \<Longrightarrow> (f \<longlongrightarrow> 0) F"
wenzelm@63546
   610
  by (fold real_norm_def) (rule tendsto_norm_zero_cancel)
wenzelm@63546
   611
wenzelm@63546
   612
lemma tendsto_rabs_zero_iff: "((\<lambda>x. \<bar>f x\<bar>) \<longlongrightarrow> (0::real)) F \<longleftrightarrow> (f \<longlongrightarrow> 0) F"
wenzelm@63546
   613
  by (fold real_norm_def) (rule tendsto_norm_zero_iff)
wenzelm@63546
   614
huffman@44194
   615
hoelzl@62368
   616
subsection \<open>Topological Monoid\<close>
hoelzl@62368
   617
hoelzl@62368
   618
class topological_monoid_add = topological_space + monoid_add +
hoelzl@62368
   619
  assumes tendsto_add_Pair: "LIM x (nhds a \<times>\<^sub>F nhds b). fst x + snd x :> nhds (a + b)"
hoelzl@62368
   620
hoelzl@62368
   621
class topological_comm_monoid_add = topological_monoid_add + comm_monoid_add
huffman@44194
   622
huffman@31565
   623
lemma tendsto_add [tendsto_intros]:
hoelzl@62368
   624
  fixes a b :: "'a::topological_monoid_add"
hoelzl@62368
   625
  shows "(f \<longlongrightarrow> a) F \<Longrightarrow> (g \<longlongrightarrow> b) F \<Longrightarrow> ((\<lambda>x. f x + g x) \<longlongrightarrow> a + b) F"
hoelzl@62368
   626
  using filterlim_compose[OF tendsto_add_Pair, of "\<lambda>x. (f x, g x)" a b F]
hoelzl@62368
   627
  by (simp add: nhds_prod[symmetric] tendsto_Pair)
huffman@31349
   628
hoelzl@51478
   629
lemma continuous_add [continuous_intros]:
hoelzl@62368
   630
  fixes f g :: "_ \<Rightarrow> 'b::topological_monoid_add"
hoelzl@51478
   631
  shows "continuous F f \<Longrightarrow> continuous F g \<Longrightarrow> continuous F (\<lambda>x. f x + g x)"
hoelzl@51478
   632
  unfolding continuous_def by (rule tendsto_add)
hoelzl@51478
   633
hoelzl@56371
   634
lemma continuous_on_add [continuous_intros]:
hoelzl@62368
   635
  fixes f g :: "_ \<Rightarrow> 'b::topological_monoid_add"
hoelzl@51478
   636
  shows "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> continuous_on s (\<lambda>x. f x + g x)"
hoelzl@51478
   637
  unfolding continuous_on_def by (auto intro: tendsto_add)
hoelzl@51478
   638
huffman@44194
   639
lemma tendsto_add_zero:
hoelzl@62368
   640
  fixes f g :: "_ \<Rightarrow> 'b::topological_monoid_add"
wenzelm@63546
   641
  shows "(f \<longlongrightarrow> 0) F \<Longrightarrow> (g \<longlongrightarrow> 0) F \<Longrightarrow> ((\<lambda>x. f x + g x) \<longlongrightarrow> 0) F"
wenzelm@63546
   642
  by (drule (1) tendsto_add) simp
huffman@44194
   643
nipkow@64267
   644
lemma tendsto_sum [tendsto_intros]:
hoelzl@62368
   645
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::topological_comm_monoid_add"
wenzelm@63915
   646
  shows "(\<And>i. i \<in> I \<Longrightarrow> (f i \<longlongrightarrow> a i) F) \<Longrightarrow> ((\<lambda>x. \<Sum>i\<in>I. f i x) \<longlongrightarrow> (\<Sum>i\<in>I. a i)) F"
wenzelm@63915
   647
  by (induct I rule: infinite_finite_induct) (simp_all add: tendsto_add)
hoelzl@62368
   648
nipkow@64267
   649
lemma continuous_sum [continuous_intros]:
hoelzl@62368
   650
  fixes f :: "'a \<Rightarrow> 'b::t2_space \<Rightarrow> 'c::topological_comm_monoid_add"
lp15@63301
   651
  shows "(\<And>i. i \<in> I \<Longrightarrow> continuous F (f i)) \<Longrightarrow> continuous F (\<lambda>x. \<Sum>i\<in>I. f i x)"
nipkow@64267
   652
  unfolding continuous_def by (rule tendsto_sum)
nipkow@64267
   653
nipkow@64267
   654
lemma continuous_on_sum [continuous_intros]:
hoelzl@62368
   655
  fixes f :: "'a \<Rightarrow> 'b::topological_space \<Rightarrow> 'c::topological_comm_monoid_add"
lp15@63301
   656
  shows "(\<And>i. i \<in> I \<Longrightarrow> continuous_on S (f i)) \<Longrightarrow> continuous_on S (\<lambda>x. \<Sum>i\<in>I. f i x)"
nipkow@64267
   657
  unfolding continuous_on_def by (auto intro: tendsto_sum)
hoelzl@62368
   658
hoelzl@62369
   659
instance nat :: topological_comm_monoid_add
wenzelm@63546
   660
  by standard
wenzelm@63546
   661
    (simp add: nhds_discrete principal_prod_principal filterlim_principal eventually_principal)
hoelzl@62369
   662
hoelzl@62369
   663
instance int :: topological_comm_monoid_add
wenzelm@63546
   664
  by standard
wenzelm@63546
   665
    (simp add: nhds_discrete principal_prod_principal filterlim_principal eventually_principal)
wenzelm@63546
   666
hoelzl@62369
   667
immler@63081
   668
subsubsection \<open>Topological group\<close>
immler@63081
   669
immler@63081
   670
class topological_group_add = topological_monoid_add + group_add +
immler@63081
   671
  assumes tendsto_uminus_nhds: "(uminus \<longlongrightarrow> - a) (nhds a)"
immler@63081
   672
begin
immler@63081
   673
wenzelm@63546
   674
lemma tendsto_minus [tendsto_intros]: "(f \<longlongrightarrow> a) F \<Longrightarrow> ((\<lambda>x. - f x) \<longlongrightarrow> - a) F"
immler@63081
   675
  by (rule filterlim_compose[OF tendsto_uminus_nhds])
immler@63081
   676
immler@63081
   677
end
immler@63081
   678
immler@63081
   679
class topological_ab_group_add = topological_group_add + ab_group_add
immler@63081
   680
immler@63081
   681
instance topological_ab_group_add < topological_comm_monoid_add ..
immler@63081
   682
wenzelm@63546
   683
lemma continuous_minus [continuous_intros]: "continuous F f \<Longrightarrow> continuous F (\<lambda>x. - f x)"
wenzelm@63546
   684
  for f :: "'a::t2_space \<Rightarrow> 'b::topological_group_add"
immler@63081
   685
  unfolding continuous_def by (rule tendsto_minus)
immler@63081
   686
wenzelm@63546
   687
lemma continuous_on_minus [continuous_intros]: "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. - f x)"
wenzelm@63546
   688
  for f :: "_ \<Rightarrow> 'b::topological_group_add"
immler@63081
   689
  unfolding continuous_on_def by (auto intro: tendsto_minus)
hoelzl@62368
   690
wenzelm@63546
   691
lemma tendsto_minus_cancel: "((\<lambda>x. - f x) \<longlongrightarrow> - a) F \<Longrightarrow> (f \<longlongrightarrow> a) F"
wenzelm@63546
   692
  for a :: "'a::topological_group_add"
wenzelm@63546
   693
  by (drule tendsto_minus) simp
immler@63081
   694
immler@63081
   695
lemma tendsto_minus_cancel_left:
wenzelm@63546
   696
  "(f \<longlongrightarrow> - (y::_::topological_group_add)) F \<longleftrightarrow> ((\<lambda>x. - f x) \<longlongrightarrow> y) F"
immler@63081
   697
  using tendsto_minus_cancel[of f "- y" F]  tendsto_minus[of f "- y" F]
immler@63081
   698
  by auto
immler@63081
   699
immler@63081
   700
lemma tendsto_diff [tendsto_intros]:
immler@63081
   701
  fixes a b :: "'a::topological_group_add"
wenzelm@63546
   702
  shows "(f \<longlongrightarrow> a) F \<Longrightarrow> (g \<longlongrightarrow> b) F \<Longrightarrow> ((\<lambda>x. f x - g x) \<longlongrightarrow> a - b) F"
immler@63081
   703
  using tendsto_add [of f a F "\<lambda>x. - g x" "- b"] by (simp add: tendsto_minus)
immler@63081
   704
immler@63081
   705
lemma continuous_diff [continuous_intros]:
immler@63081
   706
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::topological_group_add"
immler@63081
   707
  shows "continuous F f \<Longrightarrow> continuous F g \<Longrightarrow> continuous F (\<lambda>x. f x - g x)"
immler@63081
   708
  unfolding continuous_def by (rule tendsto_diff)
immler@63081
   709
immler@63081
   710
lemma continuous_on_diff [continuous_intros]:
immler@63081
   711
  fixes f g :: "_ \<Rightarrow> 'b::topological_group_add"
immler@63081
   712
  shows "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> continuous_on s (\<lambda>x. f x - g x)"
immler@63081
   713
  unfolding continuous_on_def by (auto intro: tendsto_diff)
immler@63081
   714
immler@63081
   715
lemma continuous_on_op_minus: "continuous_on (s::'a::topological_group_add set) (op - x)"
immler@63081
   716
  by (rule continuous_intros | simp)+
immler@63081
   717
immler@63081
   718
instance real_normed_vector < topological_ab_group_add
hoelzl@62368
   719
proof
wenzelm@63546
   720
  fix a b :: 'a
wenzelm@63546
   721
  show "((\<lambda>x. fst x + snd x) \<longlongrightarrow> a + b) (nhds a \<times>\<^sub>F nhds b)"
hoelzl@62368
   722
    unfolding tendsto_Zfun_iff add_diff_add
hoelzl@62368
   723
    using tendsto_fst[OF filterlim_ident, of "(a,b)"] tendsto_snd[OF filterlim_ident, of "(a,b)"]
hoelzl@62368
   724
    by (intro Zfun_add)
hoelzl@62368
   725
       (auto simp add: tendsto_Zfun_iff[symmetric] nhds_prod[symmetric] intro!: tendsto_fst)
immler@63081
   726
  show "(uminus \<longlongrightarrow> - a) (nhds a)"
immler@63081
   727
    unfolding tendsto_Zfun_iff minus_diff_minus
immler@63081
   728
    using filterlim_ident[of "nhds a"]
immler@63081
   729
    by (intro Zfun_minus) (simp add: tendsto_Zfun_iff)
hoelzl@62368
   730
qed
hoelzl@62368
   731
immler@65204
   732
lemmas real_tendsto_sandwich = tendsto_sandwich[where 'a=real]
hoelzl@50999
   733
wenzelm@63546
   734
wenzelm@60758
   735
subsubsection \<open>Linear operators and multiplication\<close>
huffman@44194
   736
wenzelm@63546
   737
lemma linear_times: "linear (\<lambda>x. c * x)"
wenzelm@63546
   738
  for c :: "'a::real_algebra"
lp15@61806
   739
  by (auto simp: linearI distrib_left)
lp15@61806
   740
wenzelm@63546
   741
lemma (in bounded_linear) tendsto: "(g \<longlongrightarrow> a) F \<Longrightarrow> ((\<lambda>x. f (g x)) \<longlongrightarrow> f a) F"
huffman@44081
   742
  by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
huffman@31349
   743
wenzelm@63546
   744
lemma (in bounded_linear) continuous: "continuous F g \<Longrightarrow> continuous F (\<lambda>x. f (g x))"
hoelzl@51478
   745
  using tendsto[of g _ F] by (auto simp: continuous_def)
hoelzl@51478
   746
wenzelm@63546
   747
lemma (in bounded_linear) continuous_on: "continuous_on s g \<Longrightarrow> continuous_on s (\<lambda>x. f (g x))"
hoelzl@51478
   748
  using tendsto[of g] by (auto simp: continuous_on_def)
hoelzl@51478
   749
wenzelm@63546
   750
lemma (in bounded_linear) tendsto_zero: "(g \<longlongrightarrow> 0) F \<Longrightarrow> ((\<lambda>x. f (g x)) \<longlongrightarrow> 0) F"
wenzelm@63546
   751
  by (drule tendsto) (simp only: zero)
huffman@44194
   752
huffman@44282
   753
lemma (in bounded_bilinear) tendsto:
wenzelm@63546
   754
  "(f \<longlongrightarrow> a) F \<Longrightarrow> (g \<longlongrightarrow> b) F \<Longrightarrow> ((\<lambda>x. f x ** g x) \<longlongrightarrow> a ** b) F"
wenzelm@63546
   755
  by (simp only: tendsto_Zfun_iff prod_diff_prod Zfun_add Zfun Zfun_left Zfun_right)
huffman@31349
   756
hoelzl@51478
   757
lemma (in bounded_bilinear) continuous:
hoelzl@51478
   758
  "continuous F f \<Longrightarrow> continuous F g \<Longrightarrow> continuous F (\<lambda>x. f x ** g x)"
hoelzl@51478
   759
  using tendsto[of f _ F g] by (auto simp: continuous_def)
hoelzl@51478
   760
hoelzl@51478
   761
lemma (in bounded_bilinear) continuous_on:
hoelzl@51478
   762
  "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> continuous_on s (\<lambda>x. f x ** g x)"
hoelzl@51478
   763
  using tendsto[of f _ _ g] by (auto simp: continuous_on_def)
hoelzl@51478
   764
huffman@44194
   765
lemma (in bounded_bilinear) tendsto_zero:
wenzelm@61973
   766
  assumes f: "(f \<longlongrightarrow> 0) F"
wenzelm@63546
   767
    and g: "(g \<longlongrightarrow> 0) F"
wenzelm@61973
   768
  shows "((\<lambda>x. f x ** g x) \<longlongrightarrow> 0) F"
huffman@44194
   769
  using tendsto [OF f g] by (simp add: zero_left)
huffman@31355
   770
huffman@44194
   771
lemma (in bounded_bilinear) tendsto_left_zero:
wenzelm@61973
   772
  "(f \<longlongrightarrow> 0) F \<Longrightarrow> ((\<lambda>x. f x ** c) \<longlongrightarrow> 0) F"
huffman@44194
   773
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_left])
huffman@44194
   774
huffman@44194
   775
lemma (in bounded_bilinear) tendsto_right_zero:
wenzelm@61973
   776
  "(f \<longlongrightarrow> 0) F \<Longrightarrow> ((\<lambda>x. c ** f x) \<longlongrightarrow> 0) F"
huffman@44194
   777
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_right])
huffman@44194
   778
huffman@44282
   779
lemmas tendsto_of_real [tendsto_intros] =
huffman@44282
   780
  bounded_linear.tendsto [OF bounded_linear_of_real]
huffman@44282
   781
huffman@44282
   782
lemmas tendsto_scaleR [tendsto_intros] =
huffman@44282
   783
  bounded_bilinear.tendsto [OF bounded_bilinear_scaleR]
huffman@44282
   784
huffman@44282
   785
lemmas tendsto_mult [tendsto_intros] =
huffman@44282
   786
  bounded_bilinear.tendsto [OF bounded_bilinear_mult]
huffman@44194
   787
wenzelm@63546
   788
lemma tendsto_mult_left: "(f \<longlongrightarrow> l) F \<Longrightarrow> ((\<lambda>x. c * (f x)) \<longlongrightarrow> c * l) F"
wenzelm@63546
   789
  for c :: "'a::real_normed_algebra"
wenzelm@63546
   790
  by (rule tendsto_mult [OF tendsto_const])
wenzelm@63546
   791
wenzelm@63546
   792
lemma tendsto_mult_right: "(f \<longlongrightarrow> l) F \<Longrightarrow> ((\<lambda>x. (f x) * c) \<longlongrightarrow> l * c) F"
wenzelm@63546
   793
  for c :: "'a::real_normed_algebra"
wenzelm@63546
   794
  by (rule tendsto_mult [OF _ tendsto_const])
lp15@61806
   795
hoelzl@51478
   796
lemmas continuous_of_real [continuous_intros] =
hoelzl@51478
   797
  bounded_linear.continuous [OF bounded_linear_of_real]
hoelzl@51478
   798
hoelzl@51478
   799
lemmas continuous_scaleR [continuous_intros] =
hoelzl@51478
   800
  bounded_bilinear.continuous [OF bounded_bilinear_scaleR]
hoelzl@51478
   801
hoelzl@51478
   802
lemmas continuous_mult [continuous_intros] =
hoelzl@51478
   803
  bounded_bilinear.continuous [OF bounded_bilinear_mult]
hoelzl@51478
   804
hoelzl@56371
   805
lemmas continuous_on_of_real [continuous_intros] =
hoelzl@51478
   806
  bounded_linear.continuous_on [OF bounded_linear_of_real]
hoelzl@51478
   807
hoelzl@56371
   808
lemmas continuous_on_scaleR [continuous_intros] =
hoelzl@51478
   809
  bounded_bilinear.continuous_on [OF bounded_bilinear_scaleR]
hoelzl@51478
   810
hoelzl@56371
   811
lemmas continuous_on_mult [continuous_intros] =
hoelzl@51478
   812
  bounded_bilinear.continuous_on [OF bounded_bilinear_mult]
hoelzl@51478
   813
huffman@44568
   814
lemmas tendsto_mult_zero =
huffman@44568
   815
  bounded_bilinear.tendsto_zero [OF bounded_bilinear_mult]
huffman@44568
   816
huffman@44568
   817
lemmas tendsto_mult_left_zero =
huffman@44568
   818
  bounded_bilinear.tendsto_left_zero [OF bounded_bilinear_mult]
huffman@44568
   819
huffman@44568
   820
lemmas tendsto_mult_right_zero =
huffman@44568
   821
  bounded_bilinear.tendsto_right_zero [OF bounded_bilinear_mult]
huffman@44568
   822
wenzelm@63546
   823
lemma tendsto_power [tendsto_intros]: "(f \<longlongrightarrow> a) F \<Longrightarrow> ((\<lambda>x. f x ^ n) \<longlongrightarrow> a ^ n) F"
wenzelm@63546
   824
  for f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra}"
hoelzl@58729
   825
  by (induct n) (simp_all add: tendsto_mult)
huffman@44194
   826
lp15@65680
   827
lemma tendsto_null_power: "\<lbrakk>(f \<longlongrightarrow> 0) F; 0 < n\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ^ n) \<longlongrightarrow> 0) F"
lp15@65680
   828
    for f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra_1}"
lp15@65680
   829
  using tendsto_power [of f 0 F n] by (simp add: power_0_left)
lp15@65680
   830
wenzelm@63546
   831
lemma continuous_power [continuous_intros]: "continuous F f \<Longrightarrow> continuous F (\<lambda>x. (f x)^n)"
wenzelm@63546
   832
  for f :: "'a::t2_space \<Rightarrow> 'b::{power,real_normed_algebra}"
hoelzl@51478
   833
  unfolding continuous_def by (rule tendsto_power)
hoelzl@51478
   834
hoelzl@56371
   835
lemma continuous_on_power [continuous_intros]:
hoelzl@51478
   836
  fixes f :: "_ \<Rightarrow> 'b::{power,real_normed_algebra}"
hoelzl@51478
   837
  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. (f x)^n)"
hoelzl@51478
   838
  unfolding continuous_on_def by (auto intro: tendsto_power)
hoelzl@51478
   839
nipkow@64272
   840
lemma tendsto_prod [tendsto_intros]:
huffman@44194
   841
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
wenzelm@63915
   842
  shows "(\<And>i. i \<in> S \<Longrightarrow> (f i \<longlongrightarrow> L i) F) \<Longrightarrow> ((\<lambda>x. \<Prod>i\<in>S. f i x) \<longlongrightarrow> (\<Prod>i\<in>S. L i)) F"
wenzelm@63915
   843
  by (induct S rule: infinite_finite_induct) (simp_all add: tendsto_mult)
huffman@44194
   844
nipkow@64272
   845
lemma continuous_prod [continuous_intros]:
hoelzl@51478
   846
  fixes f :: "'a \<Rightarrow> 'b::t2_space \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
hoelzl@51478
   847
  shows "(\<And>i. i \<in> S \<Longrightarrow> continuous F (f i)) \<Longrightarrow> continuous F (\<lambda>x. \<Prod>i\<in>S. f i x)"
nipkow@64272
   848
  unfolding continuous_def by (rule tendsto_prod)
nipkow@64272
   849
nipkow@64272
   850
lemma continuous_on_prod [continuous_intros]:
hoelzl@51478
   851
  fixes f :: "'a \<Rightarrow> _ \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
hoelzl@51478
   852
  shows "(\<And>i. i \<in> S \<Longrightarrow> continuous_on s (f i)) \<Longrightarrow> continuous_on s (\<lambda>x. \<Prod>i\<in>S. f i x)"
nipkow@64272
   853
  unfolding continuous_on_def by (auto intro: tendsto_prod)
hoelzl@51478
   854
eberlm@61531
   855
lemma tendsto_of_real_iff:
wenzelm@63546
   856
  "((\<lambda>x. of_real (f x) :: 'a::real_normed_div_algebra) \<longlongrightarrow> of_real c) F \<longleftrightarrow> (f \<longlongrightarrow> c) F"
eberlm@61531
   857
  unfolding tendsto_iff by simp
eberlm@61531
   858
eberlm@61531
   859
lemma tendsto_add_const_iff:
wenzelm@63546
   860
  "((\<lambda>x. c + f x :: 'a::real_normed_vector) \<longlongrightarrow> c + d) F \<longleftrightarrow> (f \<longlongrightarrow> d) F"
paulson@62087
   861
  using tendsto_add[OF tendsto_const[of c], of f d]
wenzelm@63546
   862
    and tendsto_add[OF tendsto_const[of "-c"], of "\<lambda>x. c + f x" "c + d"] by auto
eberlm@61531
   863
eberlm@61531
   864
wenzelm@60758
   865
subsubsection \<open>Inverse and division\<close>
huffman@31355
   866
huffman@31355
   867
lemma (in bounded_bilinear) Zfun_prod_Bfun:
huffman@44195
   868
  assumes f: "Zfun f F"
wenzelm@63546
   869
    and g: "Bfun g F"
huffman@44195
   870
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31355
   871
proof -
huffman@31355
   872
  obtain K where K: "0 \<le> K"
huffman@31355
   873
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
lp15@61649
   874
    using nonneg_bounded by blast
huffman@31355
   875
  obtain B where B: "0 < B"
huffman@44195
   876
    and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) F"
huffman@31487
   877
    using g by (rule BfunE)
huffman@44195
   878
  have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) F"
noschinl@46887
   879
  using norm_g proof eventually_elim
noschinl@46887
   880
    case (elim x)
huffman@31487
   881
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31355
   882
      by (rule norm_le)
huffman@31487
   883
    also have "\<dots> \<le> norm (f x) * B * K"
wenzelm@63546
   884
      by (intro mult_mono' order_refl norm_g norm_ge_zero mult_nonneg_nonneg K elim)
huffman@31487
   885
    also have "\<dots> = norm (f x) * (B * K)"
haftmann@57512
   886
      by (rule mult.assoc)
huffman@31487
   887
    finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
huffman@31355
   888
  qed
huffman@31487
   889
  with f show ?thesis
huffman@31487
   890
    by (rule Zfun_imp_Zfun)
huffman@31355
   891
qed
huffman@31355
   892
huffman@31355
   893
lemma (in bounded_bilinear) Bfun_prod_Zfun:
huffman@44195
   894
  assumes f: "Bfun f F"
wenzelm@63546
   895
    and g: "Zfun g F"
huffman@44195
   896
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@44081
   897
  using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
huffman@31355
   898
huffman@31355
   899
lemma Bfun_inverse_lemma:
huffman@31355
   900
  fixes x :: "'a::real_normed_div_algebra"
wenzelm@63546
   901
  shows "r \<le> norm x \<Longrightarrow> 0 < r \<Longrightarrow> norm (inverse x) \<le> inverse r"
wenzelm@63546
   902
  apply (subst nonzero_norm_inverse)
wenzelm@63546
   903
  apply clarsimp
huffman@44081
   904
  apply (erule (1) le_imp_inverse_le)
huffman@44081
   905
  done
huffman@31355
   906
huffman@31355
   907
lemma Bfun_inverse:
huffman@31355
   908
  fixes a :: "'a::real_normed_div_algebra"
wenzelm@61973
   909
  assumes f: "(f \<longlongrightarrow> a) F"
huffman@31355
   910
  assumes a: "a \<noteq> 0"
huffman@44195
   911
  shows "Bfun (\<lambda>x. inverse (f x)) F"
huffman@31355
   912
proof -
huffman@31355
   913
  from a have "0 < norm a" by simp
wenzelm@63546
   914
  then have "\<exists>r>0. r < norm a" by (rule dense)
wenzelm@63546
   915
  then obtain r where r1: "0 < r" and r2: "r < norm a"
wenzelm@63546
   916
    by blast
huffman@44195
   917
  have "eventually (\<lambda>x. dist (f x) a < r) F"
lp15@61649
   918
    using tendstoD [OF f r1] by blast
wenzelm@63546
   919
  then have "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) F"
noschinl@46887
   920
  proof eventually_elim
noschinl@46887
   921
    case (elim x)
wenzelm@63546
   922
    then have 1: "norm (f x - a) < r"
huffman@31355
   923
      by (simp add: dist_norm)
wenzelm@63546
   924
    then have 2: "f x \<noteq> 0" using r2 by auto
wenzelm@63546
   925
    then have "norm (inverse (f x)) = inverse (norm (f x))"
huffman@31355
   926
      by (rule nonzero_norm_inverse)
huffman@31355
   927
    also have "\<dots> \<le> inverse (norm a - r)"
huffman@31355
   928
    proof (rule le_imp_inverse_le)
wenzelm@63546
   929
      show "0 < norm a - r"
wenzelm@63546
   930
        using r2 by simp
huffman@31487
   931
      have "norm a - norm (f x) \<le> norm (a - f x)"
huffman@31355
   932
        by (rule norm_triangle_ineq2)
huffman@31487
   933
      also have "\<dots> = norm (f x - a)"
huffman@31355
   934
        by (rule norm_minus_commute)
huffman@31355
   935
      also have "\<dots> < r" using 1 .
wenzelm@63546
   936
      finally show "norm a - r \<le> norm (f x)"
wenzelm@63546
   937
        by simp
huffman@31355
   938
    qed
huffman@31487
   939
    finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
huffman@31355
   940
  qed
wenzelm@63546
   941
  then show ?thesis by (rule BfunI)
huffman@31355
   942
qed
huffman@31355
   943
huffman@31565
   944
lemma tendsto_inverse [tendsto_intros]:
huffman@31355
   945
  fixes a :: "'a::real_normed_div_algebra"
wenzelm@61973
   946
  assumes f: "(f \<longlongrightarrow> a) F"
wenzelm@63546
   947
    and a: "a \<noteq> 0"
wenzelm@61973
   948
  shows "((\<lambda>x. inverse (f x)) \<longlongrightarrow> inverse a) F"
huffman@31355
   949
proof -
huffman@31355
   950
  from a have "0 < norm a" by simp
huffman@44195
   951
  with f have "eventually (\<lambda>x. dist (f x) a < norm a) F"
huffman@31355
   952
    by (rule tendstoD)
huffman@44195
   953
  then have "eventually (\<lambda>x. f x \<noteq> 0) F"
lp15@61810
   954
    unfolding dist_norm by (auto elim!: eventually_mono)
huffman@44627
   955
  with a have "eventually (\<lambda>x. inverse (f x) - inverse a =
huffman@44627
   956
    - (inverse (f x) * (f x - a) * inverse a)) F"
lp15@61810
   957
    by (auto elim!: eventually_mono simp: inverse_diff_inverse)
huffman@44627
   958
  moreover have "Zfun (\<lambda>x. - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
   959
    by (intro Zfun_minus Zfun_mult_left
huffman@44627
   960
      bounded_bilinear.Bfun_prod_Zfun [OF bounded_bilinear_mult]
huffman@44627
   961
      Bfun_inverse [OF f a] f [unfolded tendsto_Zfun_iff])
huffman@44627
   962
  ultimately show ?thesis
huffman@44627
   963
    unfolding tendsto_Zfun_iff by (rule Zfun_ssubst)
huffman@31355
   964
qed
huffman@31355
   965
hoelzl@51478
   966
lemma continuous_inverse:
hoelzl@51478
   967
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_div_algebra"
wenzelm@63546
   968
  assumes "continuous F f"
wenzelm@63546
   969
    and "f (Lim F (\<lambda>x. x)) \<noteq> 0"
hoelzl@51478
   970
  shows "continuous F (\<lambda>x. inverse (f x))"
hoelzl@51478
   971
  using assms unfolding continuous_def by (rule tendsto_inverse)
hoelzl@51478
   972
hoelzl@51478
   973
lemma continuous_at_within_inverse[continuous_intros]:
hoelzl@51478
   974
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_div_algebra"
wenzelm@63546
   975
  assumes "continuous (at a within s) f"
wenzelm@63546
   976
    and "f a \<noteq> 0"
hoelzl@51478
   977
  shows "continuous (at a within s) (\<lambda>x. inverse (f x))"
hoelzl@51478
   978
  using assms unfolding continuous_within by (rule tendsto_inverse)
hoelzl@51478
   979
hoelzl@51478
   980
lemma isCont_inverse[continuous_intros, simp]:
hoelzl@51478
   981
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_div_algebra"
wenzelm@63546
   982
  assumes "isCont f a"
wenzelm@63546
   983
    and "f a \<noteq> 0"
hoelzl@51478
   984
  shows "isCont (\<lambda>x. inverse (f x)) a"
hoelzl@51478
   985
  using assms unfolding continuous_at by (rule tendsto_inverse)
hoelzl@51478
   986
hoelzl@56371
   987
lemma continuous_on_inverse[continuous_intros]:
hoelzl@51478
   988
  fixes f :: "'a::topological_space \<Rightarrow> 'b::real_normed_div_algebra"
wenzelm@63546
   989
  assumes "continuous_on s f"
wenzelm@63546
   990
    and "\<forall>x\<in>s. f x \<noteq> 0"
hoelzl@51478
   991
  shows "continuous_on s (\<lambda>x. inverse (f x))"
lp15@61649
   992
  using assms unfolding continuous_on_def by (blast intro: tendsto_inverse)
hoelzl@51478
   993
huffman@31565
   994
lemma tendsto_divide [tendsto_intros]:
huffman@31355
   995
  fixes a b :: "'a::real_normed_field"
wenzelm@63546
   996
  shows "(f \<longlongrightarrow> a) F \<Longrightarrow> (g \<longlongrightarrow> b) F \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> ((\<lambda>x. f x / g x) \<longlongrightarrow> a / b) F"
huffman@44282
   997
  by (simp add: tendsto_mult tendsto_inverse divide_inverse)
huffman@31355
   998
hoelzl@51478
   999
lemma continuous_divide:
hoelzl@51478
  1000
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_field"
wenzelm@63546
  1001
  assumes "continuous F f"
wenzelm@63546
  1002
    and "continuous F g"
wenzelm@63546
  1003
    and "g (Lim F (\<lambda>x. x)) \<noteq> 0"
hoelzl@51478
  1004
  shows "continuous F (\<lambda>x. (f x) / (g x))"
hoelzl@51478
  1005
  using assms unfolding continuous_def by (rule tendsto_divide)
hoelzl@51478
  1006
hoelzl@51478
  1007
lemma continuous_at_within_divide[continuous_intros]:
hoelzl@51478
  1008
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_field"
wenzelm@63546
  1009
  assumes "continuous (at a within s) f" "continuous (at a within s) g"
wenzelm@63546
  1010
    and "g a \<noteq> 0"
hoelzl@51478
  1011
  shows "continuous (at a within s) (\<lambda>x. (f x) / (g x))"
hoelzl@51478
  1012
  using assms unfolding continuous_within by (rule tendsto_divide)
hoelzl@51478
  1013
hoelzl@51478
  1014
lemma isCont_divide[continuous_intros, simp]:
hoelzl@51478
  1015
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_field"
hoelzl@51478
  1016
  assumes "isCont f a" "isCont g a" "g a \<noteq> 0"
hoelzl@51478
  1017
  shows "isCont (\<lambda>x. (f x) / g x) a"
hoelzl@51478
  1018
  using assms unfolding continuous_at by (rule tendsto_divide)
hoelzl@51478
  1019
hoelzl@56371
  1020
lemma continuous_on_divide[continuous_intros]:
hoelzl@51478
  1021
  fixes f :: "'a::topological_space \<Rightarrow> 'b::real_normed_field"
wenzelm@63546
  1022
  assumes "continuous_on s f" "continuous_on s g"
wenzelm@63546
  1023
    and "\<forall>x\<in>s. g x \<noteq> 0"
hoelzl@51478
  1024
  shows "continuous_on s (\<lambda>x. (f x) / (g x))"
lp15@61649
  1025
  using assms unfolding continuous_on_def by (blast intro: tendsto_divide)
hoelzl@51478
  1026
wenzelm@63546
  1027
lemma tendsto_sgn [tendsto_intros]: "(f \<longlongrightarrow> l) F \<Longrightarrow> l \<noteq> 0 \<Longrightarrow> ((\<lambda>x. sgn (f x)) \<longlongrightarrow> sgn l) F"
wenzelm@63546
  1028
  for l :: "'a::real_normed_vector"
huffman@44194
  1029
  unfolding sgn_div_norm by (simp add: tendsto_intros)
huffman@44194
  1030
hoelzl@51478
  1031
lemma continuous_sgn:
hoelzl@51478
  1032
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
wenzelm@63546
  1033
  assumes "continuous F f"
wenzelm@63546
  1034
    and "f (Lim F (\<lambda>x. x)) \<noteq> 0"
hoelzl@51478
  1035
  shows "continuous F (\<lambda>x. sgn (f x))"
hoelzl@51478
  1036
  using assms unfolding continuous_def by (rule tendsto_sgn)
hoelzl@51478
  1037
hoelzl@51478
  1038
lemma continuous_at_within_sgn[continuous_intros]:
hoelzl@51478
  1039
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
wenzelm@63546
  1040
  assumes "continuous (at a within s) f"
wenzelm@63546
  1041
    and "f a \<noteq> 0"
hoelzl@51478
  1042
  shows "continuous (at a within s) (\<lambda>x. sgn (f x))"
hoelzl@51478
  1043
  using assms unfolding continuous_within by (rule tendsto_sgn)
hoelzl@51478
  1044
hoelzl@51478
  1045
lemma isCont_sgn[continuous_intros]:
hoelzl@51478
  1046
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
wenzelm@63546
  1047
  assumes "isCont f a"
wenzelm@63546
  1048
    and "f a \<noteq> 0"
hoelzl@51478
  1049
  shows "isCont (\<lambda>x. sgn (f x)) a"
hoelzl@51478
  1050
  using assms unfolding continuous_at by (rule tendsto_sgn)
hoelzl@51478
  1051
hoelzl@56371
  1052
lemma continuous_on_sgn[continuous_intros]:
hoelzl@51478
  1053
  fixes f :: "'a::topological_space \<Rightarrow> 'b::real_normed_vector"
wenzelm@63546
  1054
  assumes "continuous_on s f"
wenzelm@63546
  1055
    and "\<forall>x\<in>s. f x \<noteq> 0"
hoelzl@51478
  1056
  shows "continuous_on s (\<lambda>x. sgn (f x))"
lp15@61649
  1057
  using assms unfolding continuous_on_def by (blast intro: tendsto_sgn)
hoelzl@51478
  1058
hoelzl@50325
  1059
lemma filterlim_at_infinity:
wenzelm@61076
  1060
  fixes f :: "_ \<Rightarrow> 'a::real_normed_vector"
hoelzl@50325
  1061
  assumes "0 \<le> c"
hoelzl@50325
  1062
  shows "(LIM x F. f x :> at_infinity) \<longleftrightarrow> (\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F)"
hoelzl@50325
  1063
  unfolding filterlim_iff eventually_at_infinity
hoelzl@50325
  1064
proof safe
wenzelm@63546
  1065
  fix P :: "'a \<Rightarrow> bool"
wenzelm@63546
  1066
  fix b
hoelzl@50325
  1067
  assume *: "\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F"
wenzelm@63546
  1068
  assume P: "\<forall>x. b \<le> norm x \<longrightarrow> P x"
hoelzl@50325
  1069
  have "max b (c + 1) > c" by auto
hoelzl@50325
  1070
  with * have "eventually (\<lambda>x. max b (c + 1) \<le> norm (f x)) F"
hoelzl@50325
  1071
    by auto
hoelzl@50325
  1072
  then show "eventually (\<lambda>x. P (f x)) F"
hoelzl@50325
  1073
  proof eventually_elim
wenzelm@63546
  1074
    case (elim x)
hoelzl@50325
  1075
    with P show "P (f x)" by auto
hoelzl@50325
  1076
  qed
hoelzl@50325
  1077
qed force
hoelzl@50325
  1078
eberlm@61531
  1079
lemma not_tendsto_and_filterlim_at_infinity:
wenzelm@63546
  1080
  fixes c :: "'a::real_normed_vector"
eberlm@61531
  1081
  assumes "F \<noteq> bot"
wenzelm@63546
  1082
    and "(f \<longlongrightarrow> c) F"
wenzelm@63546
  1083
    and "filterlim f at_infinity F"
wenzelm@63546
  1084
  shows False
eberlm@61531
  1085
proof -
paulson@62087
  1086
  from tendstoD[OF assms(2), of "1/2"]
wenzelm@63546
  1087
  have "eventually (\<lambda>x. dist (f x) c < 1/2) F"
wenzelm@63546
  1088
    by simp
wenzelm@63546
  1089
  moreover
wenzelm@63546
  1090
  from filterlim_at_infinity[of "norm c" f F] assms(3)
wenzelm@63546
  1091
  have "eventually (\<lambda>x. norm (f x) \<ge> norm c + 1) F" by simp
eberlm@61531
  1092
  ultimately have "eventually (\<lambda>x. False) F"
eberlm@61531
  1093
  proof eventually_elim
wenzelm@63546
  1094
    fix x
wenzelm@63546
  1095
    assume A: "dist (f x) c < 1/2"
wenzelm@63546
  1096
    assume "norm (f x) \<ge> norm c + 1"
lp15@62379
  1097
    also have "norm (f x) = dist (f x) 0" by simp
wenzelm@63546
  1098
    also have "\<dots> \<le> dist (f x) c + dist c 0" by (rule dist_triangle)
lp15@62379
  1099
    finally show False using A by simp
eberlm@61531
  1100
  qed
eberlm@61531
  1101
  with assms show False by simp
eberlm@61531
  1102
qed
eberlm@61531
  1103
eberlm@61531
  1104
lemma filterlim_at_infinity_imp_not_convergent:
eberlm@61531
  1105
  assumes "filterlim f at_infinity sequentially"
wenzelm@63546
  1106
  shows "\<not> convergent f"
eberlm@61531
  1107
  by (rule notI, rule not_tendsto_and_filterlim_at_infinity[OF _ _ assms])
eberlm@61531
  1108
     (simp_all add: convergent_LIMSEQ_iff)
eberlm@61531
  1109
eberlm@61531
  1110
lemma filterlim_at_infinity_imp_eventually_ne:
eberlm@61531
  1111
  assumes "filterlim f at_infinity F"
wenzelm@63546
  1112
  shows "eventually (\<lambda>z. f z \<noteq> c) F"
eberlm@61531
  1113
proof -
wenzelm@63546
  1114
  have "norm c + 1 > 0"
wenzelm@63546
  1115
    by (intro add_nonneg_pos) simp_all
eberlm@61531
  1116
  with filterlim_at_infinity[OF order.refl, of f F] assms
wenzelm@63546
  1117
  have "eventually (\<lambda>z. norm (f z) \<ge> norm c + 1) F"
wenzelm@63546
  1118
    by blast
wenzelm@63546
  1119
  then show ?thesis
wenzelm@63546
  1120
    by eventually_elim auto
eberlm@61531
  1121
qed
eberlm@61531
  1122
paulson@62087
  1123
lemma tendsto_of_nat [tendsto_intros]:
wenzelm@63546
  1124
  "filterlim (of_nat :: nat \<Rightarrow> 'a::real_normed_algebra_1) at_infinity sequentially"
eberlm@61531
  1125
proof (subst filterlim_at_infinity[OF order.refl], intro allI impI)
wenzelm@63040
  1126
  fix r :: real
wenzelm@63040
  1127
  assume r: "r > 0"
wenzelm@63040
  1128
  define n where "n = nat \<lceil>r\<rceil>"
wenzelm@63546
  1129
  from r have n: "\<forall>m\<ge>n. of_nat m \<ge> r"
wenzelm@63546
  1130
    unfolding n_def by linarith
eberlm@61531
  1131
  from eventually_ge_at_top[of n] show "eventually (\<lambda>m. norm (of_nat m :: 'a) \<ge> r) sequentially"
wenzelm@63546
  1132
    by eventually_elim (use n in simp_all)
eberlm@61531
  1133
qed
eberlm@61531
  1134
eberlm@61531
  1135
wenzelm@60758
  1136
subsection \<open>Relate @{const at}, @{const at_left} and @{const at_right}\<close>
hoelzl@50347
  1137
wenzelm@60758
  1138
text \<open>
wenzelm@63546
  1139
  This lemmas are useful for conversion between @{term "at x"} to @{term "at_left x"} and
wenzelm@63546
  1140
  @{term "at_right x"} and also @{term "at_right 0"}.
wenzelm@60758
  1141
\<close>
hoelzl@50347
  1142
hoelzl@51471
  1143
lemmas filterlim_split_at_real = filterlim_split_at[where 'a=real]
hoelzl@50323
  1144
wenzelm@63546
  1145
lemma filtermap_nhds_shift: "filtermap (\<lambda>x. x - d) (nhds a) = nhds (a - d)"
wenzelm@63546
  1146
  for a d :: "'a::real_normed_vector"
hoelzl@60721
  1147
  by (rule filtermap_fun_inverse[where g="\<lambda>x. x + d"])
wenzelm@63546
  1148
    (auto intro!: tendsto_eq_intros filterlim_ident)
wenzelm@63546
  1149
wenzelm@63546
  1150
lemma filtermap_nhds_minus: "filtermap (\<lambda>x. - x) (nhds a) = nhds (- a)"
wenzelm@63546
  1151
  for a :: "'a::real_normed_vector"
hoelzl@60721
  1152
  by (rule filtermap_fun_inverse[where g=uminus])
wenzelm@63546
  1153
    (auto intro!: tendsto_eq_intros filterlim_ident)
wenzelm@63546
  1154
wenzelm@63546
  1155
lemma filtermap_at_shift: "filtermap (\<lambda>x. x - d) (at a) = at (a - d)"
wenzelm@63546
  1156
  for a d :: "'a::real_normed_vector"
hoelzl@51641
  1157
  by (simp add: filter_eq_iff eventually_filtermap eventually_at_filter filtermap_nhds_shift[symmetric])
hoelzl@50347
  1158
wenzelm@63546
  1159
lemma filtermap_at_right_shift: "filtermap (\<lambda>x. x - d) (at_right a) = at_right (a - d)"
wenzelm@63546
  1160
  for a d :: "real"
hoelzl@51641
  1161
  by (simp add: filter_eq_iff eventually_filtermap eventually_at_filter filtermap_nhds_shift[symmetric])
hoelzl@50323
  1162
wenzelm@63546
  1163
lemma at_right_to_0: "at_right a = filtermap (\<lambda>x. x + a) (at_right 0)"
wenzelm@63546
  1164
  for a :: real
hoelzl@50347
  1165
  using filtermap_at_right_shift[of "-a" 0] by simp
hoelzl@50347
  1166
hoelzl@50347
  1167
lemma filterlim_at_right_to_0:
wenzelm@63546
  1168
  "filterlim f F (at_right a) \<longleftrightarrow> filterlim (\<lambda>x. f (x + a)) F (at_right 0)"
wenzelm@63546
  1169
  for a :: real
hoelzl@50347
  1170
  unfolding filterlim_def filtermap_filtermap at_right_to_0[of a] ..
hoelzl@50347
  1171
hoelzl@50347
  1172
lemma eventually_at_right_to_0:
wenzelm@63546
  1173
  "eventually P (at_right a) \<longleftrightarrow> eventually (\<lambda>x. P (x + a)) (at_right 0)"
wenzelm@63546
  1174
  for a :: real
hoelzl@50347
  1175
  unfolding at_right_to_0[of a] by (simp add: eventually_filtermap)
hoelzl@50347
  1176
wenzelm@63546
  1177
lemma filtermap_at_minus: "filtermap (\<lambda>x. - x) (at a) = at (- a)"
wenzelm@63546
  1178
  for a :: "'a::real_normed_vector"
hoelzl@51641
  1179
  by (simp add: filter_eq_iff eventually_filtermap eventually_at_filter filtermap_nhds_minus[symmetric])
hoelzl@50347
  1180
wenzelm@63546
  1181
lemma at_left_minus: "at_left a = filtermap (\<lambda>x. - x) (at_right (- a))"
wenzelm@63546
  1182
  for a :: real
hoelzl@51641
  1183
  by (simp add: filter_eq_iff eventually_filtermap eventually_at_filter filtermap_nhds_minus[symmetric])
hoelzl@50323
  1184
wenzelm@63546
  1185
lemma at_right_minus: "at_right a = filtermap (\<lambda>x. - x) (at_left (- a))"
wenzelm@63546
  1186
  for a :: real
hoelzl@51641
  1187
  by (simp add: filter_eq_iff eventually_filtermap eventually_at_filter filtermap_nhds_minus[symmetric])
hoelzl@50347
  1188
hoelzl@50347
  1189
lemma filterlim_at_left_to_right:
wenzelm@63546
  1190
  "filterlim f F (at_left a) \<longleftrightarrow> filterlim (\<lambda>x. f (- x)) F (at_right (-a))"
wenzelm@63546
  1191
  for a :: real
hoelzl@50347
  1192
  unfolding filterlim_def filtermap_filtermap at_left_minus[of a] ..
hoelzl@50347
  1193
hoelzl@50347
  1194
lemma eventually_at_left_to_right:
wenzelm@63546
  1195
  "eventually P (at_left a) \<longleftrightarrow> eventually (\<lambda>x. P (- x)) (at_right (-a))"
wenzelm@63546
  1196
  for a :: real
hoelzl@50347
  1197
  unfolding at_left_minus[of a] by (simp add: eventually_filtermap)
hoelzl@50347
  1198
hoelzl@60721
  1199
lemma filterlim_uminus_at_top_at_bot: "LIM x at_bot. - x :: real :> at_top"
hoelzl@60721
  1200
  unfolding filterlim_at_top eventually_at_bot_dense
hoelzl@60721
  1201
  by (metis leI minus_less_iff order_less_asym)
hoelzl@60721
  1202
hoelzl@60721
  1203
lemma filterlim_uminus_at_bot_at_top: "LIM x at_top. - x :: real :> at_bot"
hoelzl@60721
  1204
  unfolding filterlim_at_bot eventually_at_top_dense
hoelzl@60721
  1205
  by (metis leI less_minus_iff order_less_asym)
hoelzl@60721
  1206
hoelzl@50346
  1207
lemma at_top_mirror: "at_top = filtermap uminus (at_bot :: real filter)"
hoelzl@60721
  1208
  by (rule filtermap_fun_inverse[symmetric, of uminus])
hoelzl@60721
  1209
     (auto intro: filterlim_uminus_at_bot_at_top filterlim_uminus_at_top_at_bot)
hoelzl@50346
  1210
hoelzl@50346
  1211
lemma at_bot_mirror: "at_bot = filtermap uminus (at_top :: real filter)"
hoelzl@50346
  1212
  unfolding at_top_mirror filtermap_filtermap by (simp add: filtermap_ident)
hoelzl@50346
  1213
hoelzl@50346
  1214
lemma filterlim_at_top_mirror: "(LIM x at_top. f x :> F) \<longleftrightarrow> (LIM x at_bot. f (-x::real) :> F)"
hoelzl@50346
  1215
  unfolding filterlim_def at_top_mirror filtermap_filtermap ..
hoelzl@50346
  1216
hoelzl@50346
  1217
lemma filterlim_at_bot_mirror: "(LIM x at_bot. f x :> F) \<longleftrightarrow> (LIM x at_top. f (-x::real) :> F)"
hoelzl@50346
  1218
  unfolding filterlim_def at_bot_mirror filtermap_filtermap ..
hoelzl@50346
  1219
hoelzl@50346
  1220
lemma filterlim_uminus_at_top: "(LIM x F. f x :> at_top) \<longleftrightarrow> (LIM x F. - (f x) :: real :> at_bot)"
hoelzl@50346
  1221
  using filterlim_compose[OF filterlim_uminus_at_bot_at_top, of f F]
wenzelm@63546
  1222
    and filterlim_compose[OF filterlim_uminus_at_top_at_bot, of "\<lambda>x. - f x" F]
hoelzl@50346
  1223
  by auto
hoelzl@50346
  1224
hoelzl@50346
  1225
lemma filterlim_uminus_at_bot: "(LIM x F. f x :> at_bot) \<longleftrightarrow> (LIM x F. - (f x) :: real :> at_top)"
hoelzl@50346
  1226
  unfolding filterlim_uminus_at_top by simp
hoelzl@50323
  1227
hoelzl@50347
  1228
lemma filterlim_inverse_at_top_right: "LIM x at_right (0::real). inverse x :> at_top"
hoelzl@51641
  1229
  unfolding filterlim_at_top_gt[where c=0] eventually_at_filter
hoelzl@50347
  1230
proof safe
wenzelm@63546
  1231
  fix Z :: real
wenzelm@63546
  1232
  assume [arith]: "0 < Z"
hoelzl@50347
  1233
  then have "eventually (\<lambda>x. x < inverse Z) (nhds 0)"
hoelzl@50347
  1234
    by (auto simp add: eventually_nhds_metric dist_real_def intro!: exI[of _ "\<bar>inverse Z\<bar>"])
hoelzl@51641
  1235
  then show "eventually (\<lambda>x. x \<noteq> 0 \<longrightarrow> x \<in> {0<..} \<longrightarrow> Z \<le> inverse x) (nhds 0)"
lp15@61810
  1236
    by (auto elim!: eventually_mono simp: inverse_eq_divide field_simps)
hoelzl@50347
  1237
qed
hoelzl@50347
  1238
hoelzl@50325
  1239
lemma tendsto_inverse_0:
wenzelm@61076
  1240
  fixes x :: "_ \<Rightarrow> 'a::real_normed_div_algebra"
wenzelm@61973
  1241
  shows "(inverse \<longlongrightarrow> (0::'a)) at_infinity"
hoelzl@50325
  1242
  unfolding tendsto_Zfun_iff diff_0_right Zfun_def eventually_at_infinity
hoelzl@50325
  1243
proof safe
wenzelm@63546
  1244
  fix r :: real
wenzelm@63546
  1245
  assume "0 < r"
hoelzl@50325
  1246
  show "\<exists>b. \<forall>x. b \<le> norm x \<longrightarrow> norm (inverse x :: 'a) < r"
hoelzl@50325
  1247
  proof (intro exI[of _ "inverse (r / 2)"] allI impI)
hoelzl@50325
  1248
    fix x :: 'a
wenzelm@60758
  1249
    from \<open>0 < r\<close> have "0 < inverse (r / 2)" by simp
hoelzl@50325
  1250
    also assume *: "inverse (r / 2) \<le> norm x"
hoelzl@50325
  1251
    finally show "norm (inverse x) < r"
wenzelm@63546
  1252
      using * \<open>0 < r\<close>
wenzelm@63546
  1253
      by (subst nonzero_norm_inverse) (simp_all add: inverse_eq_divide field_simps)
hoelzl@50325
  1254
  qed
hoelzl@50325
  1255
qed
hoelzl@50325
  1256
eberlm@61552
  1257
lemma tendsto_add_filterlim_at_infinity:
wenzelm@63546
  1258
  fixes c :: "'b::real_normed_vector"
wenzelm@63546
  1259
    and F :: "'a filter"
wenzelm@63546
  1260
  assumes "(f \<longlongrightarrow> c) F"
wenzelm@63546
  1261
    and "filterlim g at_infinity F"
wenzelm@63546
  1262
  shows "filterlim (\<lambda>x. f x + g x) at_infinity F"
eberlm@61552
  1263
proof (subst filterlim_at_infinity[OF order_refl], safe)
wenzelm@63546
  1264
  fix r :: real
wenzelm@63546
  1265
  assume r: "r > 0"
wenzelm@63546
  1266
  from assms(1) have "((\<lambda>x. norm (f x)) \<longlongrightarrow> norm c) F"
wenzelm@63546
  1267
    by (rule tendsto_norm)
wenzelm@63546
  1268
  then have "eventually (\<lambda>x. norm (f x) < norm c + 1) F"
wenzelm@63546
  1269
    by (rule order_tendstoD) simp_all
wenzelm@63546
  1270
  moreover from r have "r + norm c + 1 > 0"
wenzelm@63546
  1271
    by (intro add_pos_nonneg) simp_all
eberlm@61552
  1272
  with assms(2) have "eventually (\<lambda>x. norm (g x) \<ge> r + norm c + 1) F"
wenzelm@63546
  1273
    unfolding filterlim_at_infinity[OF order_refl]
wenzelm@63546
  1274
    by (elim allE[of _ "r + norm c + 1"]) simp_all
eberlm@61552
  1275
  ultimately show "eventually (\<lambda>x. norm (f x + g x) \<ge> r) F"
eberlm@61552
  1276
  proof eventually_elim
wenzelm@63546
  1277
    fix x :: 'a
wenzelm@63546
  1278
    assume A: "norm (f x) < norm c + 1" and B: "r + norm c + 1 \<le> norm (g x)"
wenzelm@63546
  1279
    from A B have "r \<le> norm (g x) - norm (f x)"
wenzelm@63546
  1280
      by simp
wenzelm@63546
  1281
    also have "norm (g x) - norm (f x) \<le> norm (g x + f x)"
wenzelm@63546
  1282
      by (rule norm_diff_ineq)
wenzelm@63546
  1283
    finally show "r \<le> norm (f x + g x)"
wenzelm@63546
  1284
      by (simp add: add_ac)
eberlm@61552
  1285
  qed
eberlm@61552
  1286
qed
eberlm@61552
  1287
eberlm@61552
  1288
lemma tendsto_add_filterlim_at_infinity':
wenzelm@63546
  1289
  fixes c :: "'b::real_normed_vector"
wenzelm@63546
  1290
    and F :: "'a filter"
eberlm@61552
  1291
  assumes "filterlim f at_infinity F"
wenzelm@63546
  1292
    and "(g \<longlongrightarrow> c) F"
wenzelm@63546
  1293
  shows "filterlim (\<lambda>x. f x + g x) at_infinity F"
eberlm@61552
  1294
  by (subst add.commute) (rule tendsto_add_filterlim_at_infinity assms)+
eberlm@61552
  1295
hoelzl@60721
  1296
lemma filterlim_inverse_at_right_top: "LIM x at_top. inverse x :> at_right (0::real)"
hoelzl@60721
  1297
  unfolding filterlim_at
hoelzl@60721
  1298
  by (auto simp: eventually_at_top_dense)
hoelzl@60721
  1299
     (metis tendsto_inverse_0 filterlim_mono at_top_le_at_infinity order_refl)
hoelzl@60721
  1300
hoelzl@60721
  1301
lemma filterlim_inverse_at_top:
wenzelm@61973
  1302
  "(f \<longlongrightarrow> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. 0 < f x) F \<Longrightarrow> LIM x F. inverse (f x) :> at_top"
hoelzl@60721
  1303
  by (intro filterlim_compose[OF filterlim_inverse_at_top_right])
lp15@61810
  1304
     (simp add: filterlim_def eventually_filtermap eventually_mono at_within_def le_principal)
hoelzl@60721
  1305
hoelzl@60721
  1306
lemma filterlim_inverse_at_bot_neg:
hoelzl@60721
  1307
  "LIM x (at_left (0::real)). inverse x :> at_bot"
hoelzl@60721
  1308
  by (simp add: filterlim_inverse_at_top_right filterlim_uminus_at_bot filterlim_at_left_to_right)
hoelzl@60721
  1309
hoelzl@60721
  1310
lemma filterlim_inverse_at_bot:
wenzelm@61973
  1311
  "(f \<longlongrightarrow> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. f x < 0) F \<Longrightarrow> LIM x F. inverse (f x) :> at_bot"
hoelzl@60721
  1312
  unfolding filterlim_uminus_at_bot inverse_minus_eq[symmetric]
hoelzl@60721
  1313
  by (rule filterlim_inverse_at_top) (simp_all add: tendsto_minus_cancel_left[symmetric])
hoelzl@60721
  1314
hoelzl@50347
  1315
lemma at_right_to_top: "(at_right (0::real)) = filtermap inverse at_top"
hoelzl@60721
  1316
  by (intro filtermap_fun_inverse[symmetric, where g=inverse])
hoelzl@60721
  1317
     (auto intro: filterlim_inverse_at_top_right filterlim_inverse_at_right_top)
hoelzl@50347
  1318
hoelzl@50347
  1319
lemma eventually_at_right_to_top:
hoelzl@50347
  1320
  "eventually P (at_right (0::real)) \<longleftrightarrow> eventually (\<lambda>x. P (inverse x)) at_top"
hoelzl@50347
  1321
  unfolding at_right_to_top eventually_filtermap ..
hoelzl@50347
  1322
hoelzl@50347
  1323
lemma filterlim_at_right_to_top:
hoelzl@50347
  1324
  "filterlim f F (at_right (0::real)) \<longleftrightarrow> (LIM x at_top. f (inverse x) :> F)"
hoelzl@50347
  1325
  unfolding filterlim_def at_right_to_top filtermap_filtermap ..
hoelzl@50347
  1326
hoelzl@50347
  1327
lemma at_top_to_right: "at_top = filtermap inverse (at_right (0::real))"
hoelzl@50347
  1328
  unfolding at_right_to_top filtermap_filtermap inverse_inverse_eq filtermap_ident ..
hoelzl@50347
  1329
hoelzl@50347
  1330
lemma eventually_at_top_to_right:
hoelzl@50347
  1331
  "eventually P at_top \<longleftrightarrow> eventually (\<lambda>x. P (inverse x)) (at_right (0::real))"
hoelzl@50347
  1332
  unfolding at_top_to_right eventually_filtermap ..
hoelzl@50347
  1333
hoelzl@50347
  1334
lemma filterlim_at_top_to_right:
hoelzl@50347
  1335
  "filterlim f F at_top \<longleftrightarrow> (LIM x (at_right (0::real)). f (inverse x) :> F)"
hoelzl@50347
  1336
  unfolding filterlim_def at_top_to_right filtermap_filtermap ..
hoelzl@50347
  1337
hoelzl@50325
  1338
lemma filterlim_inverse_at_infinity:
wenzelm@61076
  1339
  fixes x :: "_ \<Rightarrow> 'a::{real_normed_div_algebra, division_ring}"
hoelzl@50325
  1340
  shows "filterlim inverse at_infinity (at (0::'a))"
hoelzl@50325
  1341
  unfolding filterlim_at_infinity[OF order_refl]
hoelzl@50325
  1342
proof safe
wenzelm@63546
  1343
  fix r :: real
wenzelm@63546
  1344
  assume "0 < r"
hoelzl@50325
  1345
  then show "eventually (\<lambda>x::'a. r \<le> norm (inverse x)) (at 0)"
hoelzl@50325
  1346
    unfolding eventually_at norm_inverse
hoelzl@50325
  1347
    by (intro exI[of _ "inverse r"])
hoelzl@50325
  1348
       (auto simp: norm_conv_dist[symmetric] field_simps inverse_eq_divide)
hoelzl@50325
  1349
qed
hoelzl@50325
  1350
hoelzl@50325
  1351
lemma filterlim_inverse_at_iff:
wenzelm@61076
  1352
  fixes g :: "'a \<Rightarrow> 'b::{real_normed_div_algebra, division_ring}"
hoelzl@50325
  1353
  shows "(LIM x F. inverse (g x) :> at 0) \<longleftrightarrow> (LIM x F. g x :> at_infinity)"
hoelzl@50325
  1354
  unfolding filterlim_def filtermap_filtermap[symmetric]
hoelzl@50325
  1355
proof
hoelzl@50325
  1356
  assume "filtermap g F \<le> at_infinity"
hoelzl@50325
  1357
  then have "filtermap inverse (filtermap g F) \<le> filtermap inverse at_infinity"
hoelzl@50325
  1358
    by (rule filtermap_mono)
hoelzl@50325
  1359
  also have "\<dots> \<le> at 0"
hoelzl@51641
  1360
    using tendsto_inverse_0[where 'a='b]
hoelzl@51641
  1361
    by (auto intro!: exI[of _ 1]
wenzelm@63546
  1362
        simp: le_principal eventually_filtermap filterlim_def at_within_def eventually_at_infinity)
hoelzl@50325
  1363
  finally show "filtermap inverse (filtermap g F) \<le> at 0" .
hoelzl@50325
  1364
next
hoelzl@50325
  1365
  assume "filtermap inverse (filtermap g F) \<le> at 0"
hoelzl@50325
  1366
  then have "filtermap inverse (filtermap inverse (filtermap g F)) \<le> filtermap inverse (at 0)"
hoelzl@50325
  1367
    by (rule filtermap_mono)
hoelzl@50325
  1368
  with filterlim_inverse_at_infinity show "filtermap g F \<le> at_infinity"
hoelzl@50325
  1369
    by (auto intro: order_trans simp: filterlim_def filtermap_filtermap)
hoelzl@50325
  1370
qed
hoelzl@50325
  1371
eberlm@61531
  1372
lemma tendsto_mult_filterlim_at_infinity:
wenzelm@63546
  1373
  fixes c :: "'a::real_normed_field"
lp15@64394
  1374
  assumes  "(f \<longlongrightarrow> c) F" "c \<noteq> 0"
eberlm@61531
  1375
  assumes "filterlim g at_infinity F"
wenzelm@63546
  1376
  shows "filterlim (\<lambda>x. f x * g x) at_infinity F"
eberlm@61531
  1377
proof -
wenzelm@61973
  1378
  have "((\<lambda>x. inverse (f x) * inverse (g x)) \<longlongrightarrow> inverse c * 0) F"
eberlm@61531
  1379
    by (intro tendsto_mult tendsto_inverse assms filterlim_compose[OF tendsto_inverse_0])
wenzelm@63546
  1380
  then have "filterlim (\<lambda>x. inverse (f x) * inverse (g x)) (at (inverse c * 0)) F"
wenzelm@63546
  1381
    unfolding filterlim_at
wenzelm@63546
  1382
    using assms
eberlm@61531
  1383
    by (auto intro: filterlim_at_infinity_imp_eventually_ne tendsto_imp_eventually_ne eventually_conj)
wenzelm@63546
  1384
  then show ?thesis
wenzelm@63546
  1385
    by (subst filterlim_inverse_at_iff[symmetric]) simp_all
lp15@64394
  1386
qed  
eberlm@61531
  1387
wenzelm@61973
  1388
lemma tendsto_inverse_0_at_top: "LIM x F. f x :> at_top \<Longrightarrow> ((\<lambda>x. inverse (f x) :: real) \<longlongrightarrow> 0) F"
hoelzl@51641
  1389
 by (metis filterlim_at filterlim_mono[OF _ at_top_le_at_infinity order_refl] filterlim_inverse_at_iff)
hoelzl@50419
  1390
immler@63556
  1391
lemma real_tendsto_divide_at_top:
immler@63556
  1392
  fixes c::"real"
immler@63556
  1393
  assumes "(f \<longlongrightarrow> c) F"
immler@63556
  1394
  assumes "filterlim g at_top F"
immler@63556
  1395
  shows "((\<lambda>x. f x / g x) \<longlongrightarrow> 0) F"
immler@63556
  1396
  by (auto simp: divide_inverse_commute
immler@63556
  1397
      intro!: tendsto_mult[THEN tendsto_eq_rhs] tendsto_inverse_0_at_top assms)
immler@63556
  1398
wenzelm@63546
  1399
lemma mult_nat_left_at_top: "c > 0 \<Longrightarrow> filterlim (\<lambda>x. c * x) at_top sequentially"
wenzelm@63546
  1400
  for c :: nat
eberlm@66447
  1401
  by (rule filterlim_subseq) (auto simp: strict_mono_def)
lp15@59613
  1402
wenzelm@63546
  1403
lemma mult_nat_right_at_top: "c > 0 \<Longrightarrow> filterlim (\<lambda>x. x * c) at_top sequentially"
wenzelm@63546
  1404
  for c :: nat
eberlm@66447
  1405
  by (rule filterlim_subseq) (auto simp: strict_mono_def)
wenzelm@63546
  1406
wenzelm@63546
  1407
lemma at_to_infinity: "(at (0::'a::{real_normed_field,field})) = filtermap inverse at_infinity"
lp15@59613
  1408
proof (rule antisym)
wenzelm@61973
  1409
  have "(inverse \<longlongrightarrow> (0::'a)) at_infinity"
lp15@59613
  1410
    by (fact tendsto_inverse_0)
lp15@59613
  1411
  then show "filtermap inverse at_infinity \<le> at (0::'a)"
lp15@59613
  1412
    apply (simp add: le_principal eventually_filtermap eventually_at_infinity filterlim_def at_within_def)
wenzelm@63546
  1413
    apply (rule_tac x="1" in exI)
wenzelm@63546
  1414
    apply auto
lp15@59613
  1415
    done
lp15@59613
  1416
next
lp15@59613
  1417
  have "filtermap inverse (filtermap inverse (at (0::'a))) \<le> filtermap inverse at_infinity"
lp15@59613
  1418
    using filterlim_inverse_at_infinity unfolding filterlim_def
lp15@59613
  1419
    by (rule filtermap_mono)
lp15@59613
  1420
  then show "at (0::'a) \<le> filtermap inverse at_infinity"
lp15@59613
  1421
    by (simp add: filtermap_ident filtermap_filtermap)
lp15@59613
  1422
qed
lp15@59613
  1423
lp15@59613
  1424
lemma lim_at_infinity_0:
wenzelm@63546
  1425
  fixes l :: "'a::{real_normed_field,field}"
wenzelm@63546
  1426
  shows "(f \<longlongrightarrow> l) at_infinity \<longleftrightarrow> ((f \<circ> inverse) \<longlongrightarrow> l) (at (0::'a))"
wenzelm@63546
  1427
  by (simp add: tendsto_compose_filtermap at_to_infinity filtermap_filtermap)
lp15@59613
  1428
lp15@59613
  1429
lemma lim_zero_infinity:
wenzelm@63546
  1430
  fixes l :: "'a::{real_normed_field,field}"
wenzelm@61973
  1431
  shows "((\<lambda>x. f(1 / x)) \<longlongrightarrow> l) (at (0::'a)) \<Longrightarrow> (f \<longlongrightarrow> l) at_infinity"
wenzelm@63546
  1432
  by (simp add: inverse_eq_divide lim_at_infinity_0 comp_def)
lp15@59613
  1433
lp15@59613
  1434
wenzelm@60758
  1435
text \<open>
wenzelm@63546
  1436
  We only show rules for multiplication and addition when the functions are either against a real
wenzelm@63546
  1437
  value or against infinity. Further rules are easy to derive by using @{thm
wenzelm@63546
  1438
  filterlim_uminus_at_top}.
wenzelm@60758
  1439
\<close>
hoelzl@50324
  1440
lp15@60141
  1441
lemma filterlim_tendsto_pos_mult_at_top:
wenzelm@63546
  1442
  assumes f: "(f \<longlongrightarrow> c) F"
wenzelm@63546
  1443
    and c: "0 < c"
wenzelm@63546
  1444
    and g: "LIM x F. g x :> at_top"
hoelzl@50324
  1445
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
  1446
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1447
proof safe
wenzelm@63546
  1448
  fix Z :: real
wenzelm@63546
  1449
  assume "0 < Z"
wenzelm@60758
  1450
  from f \<open>0 < c\<close> have "eventually (\<lambda>x. c / 2 < f x) F"
lp15@61810
  1451
    by (auto dest!: tendstoD[where e="c / 2"] elim!: eventually_mono
wenzelm@63546
  1452
        simp: dist_real_def abs_real_def split: if_split_asm)
hoelzl@50346
  1453
  moreover from g have "eventually (\<lambda>x. (Z / c * 2) \<le> g x) F"
hoelzl@50324
  1454
    unfolding filterlim_at_top by auto
hoelzl@50346
  1455
  ultimately show "eventually (\<lambda>x. Z \<le> f x * g x) F"
hoelzl@50324
  1456
  proof eventually_elim
wenzelm@63546
  1457
    case (elim x)
wenzelm@60758
  1458
    with \<open>0 < Z\<close> \<open>0 < c\<close> have "c / 2 * (Z / c * 2) \<le> f x * g x"
hoelzl@50346
  1459
      by (intro mult_mono) (auto simp: zero_le_divide_iff)
wenzelm@60758
  1460
    with \<open>0 < c\<close> show "Z \<le> f x * g x"
hoelzl@50324
  1461
       by simp
hoelzl@50324
  1462
  qed
hoelzl@50324
  1463
qed
hoelzl@50324
  1464
lp15@60141
  1465
lemma filterlim_at_top_mult_at_top:
hoelzl@50324
  1466
  assumes f: "LIM x F. f x :> at_top"
wenzelm@63546
  1467
    and g: "LIM x F. g x :> at_top"
hoelzl@50324
  1468
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
  1469
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1470
proof safe
wenzelm@63546
  1471
  fix Z :: real
wenzelm@63546
  1472
  assume "0 < Z"
hoelzl@50346
  1473
  from f have "eventually (\<lambda>x. 1 \<le> f x) F"
hoelzl@50324
  1474
    unfolding filterlim_at_top by auto
hoelzl@50346
  1475
  moreover from g have "eventually (\<lambda>x. Z \<le> g x) F"
hoelzl@50324
  1476
    unfolding filterlim_at_top by auto
hoelzl@50346
  1477
  ultimately show "eventually (\<lambda>x. Z \<le> f x * g x) F"
hoelzl@50324
  1478
  proof eventually_elim
wenzelm@63546
  1479
    case (elim x)
wenzelm@60758
  1480
    with \<open>0 < Z\<close> have "1 * Z \<le> f x * g x"
hoelzl@50346
  1481
      by (intro mult_mono) (auto simp: zero_le_divide_iff)
hoelzl@50346
  1482
    then show "Z \<le> f x * g x"
hoelzl@50324
  1483
       by simp
hoelzl@50324
  1484
  qed
hoelzl@50324
  1485
qed
hoelzl@50324
  1486
immler@63556
  1487
lemma filterlim_at_top_mult_tendsto_pos:
immler@63556
  1488
  assumes f: "(f \<longlongrightarrow> c) F"
immler@63556
  1489
    and c: "0 < c"
immler@63556
  1490
    and g: "LIM x F. g x :> at_top"
immler@63556
  1491
  shows "LIM x F. (g x * f x:: real) :> at_top"
immler@63556
  1492
  by (auto simp: mult.commute intro!: filterlim_tendsto_pos_mult_at_top f c g)
immler@63556
  1493
hoelzl@50419
  1494
lemma filterlim_tendsto_pos_mult_at_bot:
wenzelm@63546
  1495
  fixes c :: real
wenzelm@63546
  1496
  assumes "(f \<longlongrightarrow> c) F" "0 < c" "filterlim g at_bot F"
hoelzl@50419
  1497
  shows "LIM x F. f x * g x :> at_bot"
hoelzl@50419
  1498
  using filterlim_tendsto_pos_mult_at_top[OF assms(1,2), of "\<lambda>x. - g x"] assms(3)
hoelzl@50419
  1499
  unfolding filterlim_uminus_at_bot by simp
hoelzl@50419
  1500
hoelzl@60182
  1501
lemma filterlim_tendsto_neg_mult_at_bot:
wenzelm@63546
  1502
  fixes c :: real
wenzelm@63546
  1503
  assumes c: "(f \<longlongrightarrow> c) F" "c < 0" and g: "filterlim g at_top F"
hoelzl@60182
  1504
  shows "LIM x F. f x * g x :> at_bot"
hoelzl@60182
  1505
  using c filterlim_tendsto_pos_mult_at_top[of "\<lambda>x. - f x" "- c" F, OF _ _ g]
hoelzl@60182
  1506
  unfolding filterlim_uminus_at_bot tendsto_minus_cancel_left by simp
hoelzl@60182
  1507
hoelzl@56330
  1508
lemma filterlim_pow_at_top:
eberlm@63721
  1509
  fixes f :: "'a \<Rightarrow> real"
wenzelm@63546
  1510
  assumes "0 < n"
wenzelm@63546
  1511
    and f: "LIM x F. f x :> at_top"
hoelzl@56330
  1512
  shows "LIM x F. (f x)^n :: real :> at_top"
wenzelm@63546
  1513
  using \<open>0 < n\<close>
wenzelm@63546
  1514
proof (induct n)
wenzelm@63546
  1515
  case 0
wenzelm@63546
  1516
  then show ?case by simp
wenzelm@63546
  1517
next
hoelzl@56330
  1518
  case (Suc n) with f show ?case
hoelzl@56330
  1519
    by (cases "n = 0") (auto intro!: filterlim_at_top_mult_at_top)
wenzelm@63546
  1520
qed
hoelzl@56330
  1521
hoelzl@56330
  1522
lemma filterlim_pow_at_bot_even:
hoelzl@56330
  1523
  fixes f :: "real \<Rightarrow> real"
hoelzl@56330
  1524
  shows "0 < n \<Longrightarrow> LIM x F. f x :> at_bot \<Longrightarrow> even n \<Longrightarrow> LIM x F. (f x)^n :> at_top"
hoelzl@56330
  1525
  using filterlim_pow_at_top[of n "\<lambda>x. - f x" F] by (simp add: filterlim_uminus_at_top)
hoelzl@56330
  1526
hoelzl@56330
  1527
lemma filterlim_pow_at_bot_odd:
hoelzl@56330
  1528
  fixes f :: "real \<Rightarrow> real"
hoelzl@56330
  1529
  shows "0 < n \<Longrightarrow> LIM x F. f x :> at_bot \<Longrightarrow> odd n \<Longrightarrow> LIM x F. (f x)^n :> at_bot"
hoelzl@56330
  1530
  using filterlim_pow_at_top[of n "\<lambda>x. - f x" F] by (simp add: filterlim_uminus_at_bot)
hoelzl@56330
  1531
lp15@60141
  1532
lemma filterlim_tendsto_add_at_top:
wenzelm@61973
  1533
  assumes f: "(f \<longlongrightarrow> c) F"
wenzelm@63546
  1534
    and g: "LIM x F. g x :> at_top"
hoelzl@50324
  1535
  shows "LIM x F. (f x + g x :: real) :> at_top"
hoelzl@50324
  1536
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1537
proof safe
wenzelm@63546
  1538
  fix Z :: real
wenzelm@63546
  1539
  assume "0 < Z"
hoelzl@50324
  1540
  from f have "eventually (\<lambda>x. c - 1 < f x) F"
lp15@61810
  1541
    by (auto dest!: tendstoD[where e=1] elim!: eventually_mono simp: dist_real_def)
hoelzl@50346
  1542
  moreover from g have "eventually (\<lambda>x. Z - (c - 1) \<le> g x) F"
hoelzl@50324
  1543
    unfolding filterlim_at_top by auto
hoelzl@50346
  1544
  ultimately show "eventually (\<lambda>x. Z \<le> f x + g x) F"
hoelzl@50324
  1545
    by eventually_elim simp
hoelzl@50324
  1546
qed
hoelzl@50324
  1547
hoelzl@50347
  1548
lemma LIM_at_top_divide:
hoelzl@50347
  1549
  fixes f g :: "'a \<Rightarrow> real"
wenzelm@61973
  1550
  assumes f: "(f \<longlongrightarrow> a) F" "0 < a"
wenzelm@63546
  1551
    and g: "(g \<longlongrightarrow> 0) F" "eventually (\<lambda>x. 0 < g x) F"
hoelzl@50347
  1552
  shows "LIM x F. f x / g x :> at_top"
hoelzl@50347
  1553
  unfolding divide_inverse
hoelzl@50347
  1554
  by (rule filterlim_tendsto_pos_mult_at_top[OF f]) (rule filterlim_inverse_at_top[OF g])
hoelzl@50347
  1555
lp15@60141
  1556
lemma filterlim_at_top_add_at_top:
hoelzl@50324
  1557
  assumes f: "LIM x F. f x :> at_top"
wenzelm@63546
  1558
    and g: "LIM x F. g x :> at_top"
hoelzl@50324
  1559
  shows "LIM x F. (f x + g x :: real) :> at_top"
hoelzl@50324
  1560
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1561
proof safe
wenzelm@63546
  1562
  fix Z :: real
wenzelm@63546
  1563
  assume "0 < Z"
hoelzl@50346
  1564
  from f have "eventually (\<lambda>x. 0 \<le> f x) F"
hoelzl@50324
  1565
    unfolding filterlim_at_top by auto
hoelzl@50346
  1566
  moreover from g have "eventually (\<lambda>x. Z \<le> g x) F"
hoelzl@50324
  1567
    unfolding filterlim_at_top by auto
hoelzl@50346
  1568
  ultimately show "eventually (\<lambda>x. Z \<le> f x + g x) F"
hoelzl@50324
  1569
    by eventually_elim simp
hoelzl@50324
  1570
qed
hoelzl@50324
  1571
hoelzl@50331
  1572
lemma tendsto_divide_0:
wenzelm@61076
  1573
  fixes f :: "_ \<Rightarrow> 'a::{real_normed_div_algebra, division_ring}"
wenzelm@61973
  1574
  assumes f: "(f \<longlongrightarrow> c) F"
wenzelm@63546
  1575
    and g: "LIM x F. g x :> at_infinity"
wenzelm@61973
  1576
  shows "((\<lambda>x. f x / g x) \<longlongrightarrow> 0) F"
wenzelm@63546
  1577
  using tendsto_mult[OF f filterlim_compose[OF tendsto_inverse_0 g]]
wenzelm@63546
  1578
  by (simp add: divide_inverse)
hoelzl@50331
  1579
hoelzl@50331
  1580
lemma linear_plus_1_le_power:
hoelzl@50331
  1581
  fixes x :: real
hoelzl@50331
  1582
  assumes x: "0 \<le> x"
hoelzl@50331
  1583
  shows "real n * x + 1 \<le> (x + 1) ^ n"
hoelzl@50331
  1584
proof (induct n)
wenzelm@63546
  1585
  case 0
wenzelm@63546
  1586
  then show ?case by simp
wenzelm@63546
  1587
next
hoelzl@50331
  1588
  case (Suc n)
wenzelm@63546
  1589
  from x have "real (Suc n) * x + 1 \<le> (x + 1) * (real n * x + 1)"
wenzelm@63546
  1590
    by (simp add: field_simps)
hoelzl@50331
  1591
  also have "\<dots> \<le> (x + 1)^Suc n"
hoelzl@50331
  1592
    using Suc x by (simp add: mult_left_mono)
hoelzl@50331
  1593
  finally show ?case .
wenzelm@63546
  1594
qed
hoelzl@50331
  1595
hoelzl@50331
  1596
lemma filterlim_realpow_sequentially_gt1:
hoelzl@50331
  1597
  fixes x :: "'a :: real_normed_div_algebra"
hoelzl@50331
  1598
  assumes x[arith]: "1 < norm x"
hoelzl@50331
  1599
  shows "LIM n sequentially. x ^ n :> at_infinity"
hoelzl@50331
  1600
proof (intro filterlim_at_infinity[THEN iffD2] allI impI)
wenzelm@63546
  1601
  fix y :: real
wenzelm@63546
  1602
  assume "0 < y"
hoelzl@50331
  1603
  have "0 < norm x - 1" by simp
wenzelm@63546
  1604
  then obtain N :: nat where "y < real N * (norm x - 1)"
wenzelm@63546
  1605
    by (blast dest: reals_Archimedean3)
wenzelm@63546
  1606
  also have "\<dots> \<le> real N * (norm x - 1) + 1"
wenzelm@63546
  1607
    by simp
wenzelm@63546
  1608
  also have "\<dots> \<le> (norm x - 1 + 1) ^ N"
wenzelm@63546
  1609
    by (rule linear_plus_1_le_power) simp
wenzelm@63546
  1610
  also have "\<dots> = norm x ^ N"
wenzelm@63546
  1611
    by simp
hoelzl@50331
  1612
  finally have "\<forall>n\<ge>N. y \<le> norm x ^ n"
hoelzl@50331
  1613
    by (metis order_less_le_trans power_increasing order_less_imp_le x)
hoelzl@50331
  1614
  then show "eventually (\<lambda>n. y \<le> norm (x ^ n)) sequentially"
hoelzl@50331
  1615
    unfolding eventually_sequentially
hoelzl@50331
  1616
    by (auto simp: norm_power)
hoelzl@50331
  1617
qed simp
hoelzl@50331
  1618
hoelzl@51471
  1619
immler@63263
  1620
subsection \<open>Floor and Ceiling\<close>
immler@63263
  1621
immler@63263
  1622
lemma eventually_floor_less:
wenzelm@63546
  1623
  fixes f :: "'a \<Rightarrow> 'b::{order_topology,floor_ceiling}"
immler@63263
  1624
  assumes f: "(f \<longlongrightarrow> l) F"
wenzelm@63546
  1625
    and l: "l \<notin> \<int>"
immler@63263
  1626
  shows "\<forall>\<^sub>F x in F. of_int (floor l) < f x"
immler@63263
  1627
  by (intro order_tendstoD[OF f]) (metis Ints_of_int antisym_conv2 floor_correct l)
immler@63263
  1628
immler@63263
  1629
lemma eventually_less_ceiling:
wenzelm@63546
  1630
  fixes f :: "'a \<Rightarrow> 'b::{order_topology,floor_ceiling}"
immler@63263
  1631
  assumes f: "(f \<longlongrightarrow> l) F"
wenzelm@63546
  1632
    and l: "l \<notin> \<int>"
immler@63263
  1633
  shows "\<forall>\<^sub>F x in F. f x < of_int (ceiling l)"
immler@63263
  1634
  by (intro order_tendstoD[OF f]) (metis Ints_of_int l le_of_int_ceiling less_le)
immler@63263
  1635
immler@63263
  1636
lemma eventually_floor_eq:
wenzelm@63546
  1637
  fixes f::"'a \<Rightarrow> 'b::{order_topology,floor_ceiling}"
immler@63263
  1638
  assumes f: "(f \<longlongrightarrow> l) F"
wenzelm@63546
  1639
    and l: "l \<notin> \<int>"
immler@63263
  1640
  shows "\<forall>\<^sub>F x in F. floor (f x) = floor l"
immler@63263
  1641
  using eventually_floor_less[OF assms] eventually_less_ceiling[OF assms]
immler@63263
  1642
  by eventually_elim (meson floor_less_iff less_ceiling_iff not_less_iff_gr_or_eq)
immler@63263
  1643
immler@63263
  1644
lemma eventually_ceiling_eq:
wenzelm@63546
  1645
  fixes f::"'a \<Rightarrow> 'b::{order_topology,floor_ceiling}"
immler@63263
  1646
  assumes f: "(f \<longlongrightarrow> l) F"
wenzelm@63546
  1647
    and l: "l \<notin> \<int>"
immler@63263
  1648
  shows "\<forall>\<^sub>F x in F. ceiling (f x) = ceiling l"
immler@63263
  1649
  using eventually_floor_less[OF assms] eventually_less_ceiling[OF assms]
immler@63263
  1650
  by eventually_elim (meson floor_less_iff less_ceiling_iff not_less_iff_gr_or_eq)
immler@63263
  1651
immler@63263
  1652
lemma tendsto_of_int_floor:
wenzelm@63546
  1653
  fixes f::"'a \<Rightarrow> 'b::{order_topology,floor_ceiling}"
immler@63263
  1654
  assumes "(f \<longlongrightarrow> l) F"
wenzelm@63546
  1655
    and "l \<notin> \<int>"
wenzelm@63546
  1656
  shows "((\<lambda>x. of_int (floor (f x)) :: 'c::{ring_1,topological_space}) \<longlongrightarrow> of_int (floor l)) F"
immler@63263
  1657
  using eventually_floor_eq[OF assms]
immler@63263
  1658
  by (simp add: eventually_mono topological_tendstoI)
immler@63263
  1659
immler@63263
  1660
lemma tendsto_of_int_ceiling:
wenzelm@63546
  1661
  fixes f::"'a \<Rightarrow> 'b::{order_topology,floor_ceiling}"
immler@63263
  1662
  assumes "(f \<longlongrightarrow> l) F"
wenzelm@63546
  1663
    and "l \<notin> \<int>"
wenzelm@63546
  1664
  shows "((\<lambda>x. of_int (ceiling (f x)):: 'c::{ring_1,topological_space}) \<longlongrightarrow> of_int (ceiling l)) F"
immler@63263
  1665
  using eventually_ceiling_eq[OF assms]
immler@63263
  1666
  by (simp add: eventually_mono topological_tendstoI)
immler@63263
  1667
immler@63263
  1668
lemma continuous_on_of_int_floor:
immler@63263
  1669
  "continuous_on (UNIV - \<int>::'a::{order_topology, floor_ceiling} set)
immler@63263
  1670
    (\<lambda>x. of_int (floor x)::'b::{ring_1, topological_space})"
immler@63263
  1671
  unfolding continuous_on_def
immler@63263
  1672
  by (auto intro!: tendsto_of_int_floor)
immler@63263
  1673
immler@63263
  1674
lemma continuous_on_of_int_ceiling:
immler@63263
  1675
  "continuous_on (UNIV - \<int>::'a::{order_topology, floor_ceiling} set)
immler@63263
  1676
    (\<lambda>x. of_int (ceiling x)::'b::{ring_1, topological_space})"
immler@63263
  1677
  unfolding continuous_on_def
immler@63263
  1678
  by (auto intro!: tendsto_of_int_ceiling)
immler@63263
  1679
immler@63263
  1680
wenzelm@60758
  1681
subsection \<open>Limits of Sequences\<close>
hoelzl@51526
  1682
hoelzl@62368
  1683
lemma [trans]: "X = Y \<Longrightarrow> Y \<longlonglongrightarrow> z \<Longrightarrow> X \<longlonglongrightarrow> z"
hoelzl@51526
  1684
  by simp
hoelzl@51526
  1685
hoelzl@51526
  1686
lemma LIMSEQ_iff:
hoelzl@51526
  1687
  fixes L :: "'a::real_normed_vector"
wenzelm@61969
  1688
  shows "(X \<longlonglongrightarrow> L) = (\<forall>r>0. \<exists>no. \<forall>n \<ge> no. norm (X n - L) < r)"
lp15@60017
  1689
unfolding lim_sequentially dist_norm ..
hoelzl@51526
  1690
wenzelm@63546
  1691
lemma LIMSEQ_I: "(\<And>r. 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n - L) < r) \<Longrightarrow> X \<longlonglongrightarrow> L"
wenzelm@63546
  1692
  for L :: "'a::real_normed_vector"
wenzelm@63546
  1693
  by (simp add: LIMSEQ_iff)
wenzelm@63546
  1694
wenzelm@63546
  1695
lemma LIMSEQ_D: "X \<longlonglongrightarrow> L \<Longrightarrow> 0 < r \<Longrightarrow> \<exists>no. \<forall>n\<ge>no. norm (X n - L) < r"
wenzelm@63546
  1696
  for L :: "'a::real_normed_vector"
wenzelm@63546
  1697
  by (simp add: LIMSEQ_iff)
wenzelm@63546
  1698
wenzelm@63546
  1699
lemma LIMSEQ_linear: "X \<longlonglongrightarrow> x \<Longrightarrow> l > 0 \<Longrightarrow> (\<lambda> n. X (n * l)) \<longlonglongrightarrow> x"
hoelzl@51526
  1700
  unfolding tendsto_def eventually_sequentially
haftmann@57512
  1701
  by (metis div_le_dividend div_mult_self1_is_m le_trans mult.commute)
hoelzl@51526
  1702
lp15@65036
  1703
lemma norm_inverse_le_norm: "r \<le> norm x \<Longrightarrow> 0 < r \<Longrightarrow> norm (inverse x) \<le> inverse r"
wenzelm@63546
  1704
  for x :: "'a::real_normed_div_algebra"
wenzelm@63546
  1705
  apply (subst nonzero_norm_inverse, clarsimp)
wenzelm@63546
  1706
  apply (erule (1) le_imp_inverse_le)
wenzelm@63546
  1707
  done
wenzelm@63546
  1708
wenzelm@63546
  1709
lemma Bseq_inverse: "X \<longlonglongrightarrow> a \<Longrightarrow> a \<noteq> 0 \<Longrightarrow> Bseq (\<lambda>n. inverse (X n))"
wenzelm@63546
  1710
  for a :: "'a::real_normed_div_algebra"
hoelzl@51526
  1711
  by (rule Bfun_inverse)
hoelzl@51526
  1712
wenzelm@63546
  1713
wenzelm@63546
  1714
text \<open>Transformation of limit.\<close>
wenzelm@63546
  1715
wenzelm@63546
  1716
lemma Lim_transform: "(g \<longlongrightarrow> a) F \<Longrightarrow> ((\<lambda>x. f x - g x) \<longlongrightarrow> 0) F \<Longrightarrow> (f \<longlongrightarrow> a) F"
wenzelm@63546
  1717
  for a b :: "'a::real_normed_vector"
lp15@60141
  1718
  using tendsto_add [of g a F "\<lambda>x. f x - g x" 0] by simp
lp15@60141
  1719
wenzelm@63546
  1720
lemma Lim_transform2: "(f \<longlongrightarrow> a) F \<Longrightarrow> ((\<lambda>x. f x - g x) \<longlongrightarrow> 0) F \<Longrightarrow> (g \<longlongrightarrow> a) F"
wenzelm@63546
  1721
  for a b :: "'a::real_normed_vector"
lp15@60141
  1722
  by (erule Lim_transform) (simp add: tendsto_minus_cancel)
lp15@60141
  1723
wenzelm@63546
  1724
proposition Lim_transform_eq: "((\<lambda>x. f x - g x) \<longlongrightarrow> 0) F \<Longrightarrow> (f \<longlongrightarrow> a) F \<longleftrightarrow> (g \<longlongrightarrow> a) F"
wenzelm@63546
  1725
  for a :: "'a::real_normed_vector"
wenzelm@63546
  1726
  using Lim_transform Lim_transform2 by blast
lp15@62379
  1727
lp15@60141
  1728
lemma Lim_transform_eventually:
wenzelm@61973
  1729
  "eventually (\<lambda>x. f x = g x) net \<Longrightarrow> (f \<longlongrightarrow> l) net \<Longrightarrow> (g \<longlongrightarrow> l) net"
lp15@60141
  1730
  apply (rule topological_tendstoI)
lp15@60141
  1731
  apply (drule (2) topological_tendstoD)
wenzelm@63546
  1732
  apply (erule (1) eventually_elim2)
wenzelm@63546
  1733
  apply simp
lp15@60141
  1734
  done
lp15@60141
  1735
lp15@60141
  1736
lemma Lim_transform_within:
paulson@62087
  1737
  assumes "(f \<longlongrightarrow> l) (at x within S)"
paulson@62087
  1738
    and "0 < d"
wenzelm@63546
  1739
    and "\<And>x'. x'\<in>S \<Longrightarrow> 0 < dist x' x \<Longrightarrow> dist x' x < d \<Longrightarrow> f x' = g x'"
wenzelm@61973
  1740
  shows "(g \<longlongrightarrow> l) (at x within S)"
lp15@60141
  1741
proof (rule Lim_transform_eventually)
lp15@60141
  1742
  show "eventually (\<lambda>x. f x = g x) (at x within S)"
paulson@62087
  1743
    using assms by (auto simp: eventually_at)
wenzelm@63546
  1744
  show "(f \<longlongrightarrow> l) (at x within S)"
wenzelm@63546
  1745
    by fact
lp15@60141
  1746
qed
lp15@60141
  1747
wenzelm@63546
  1748
text \<open>Common case assuming being away from some crucial point like 0.\<close>
lp15@60141
  1749
lemma Lim_transform_away_within:
lp15@60141
  1750
  fixes a b :: "'a::t1_space"
lp15@60141
  1751
  assumes "a \<noteq> b"
lp15@60141
  1752
    and "\<forall>x\<in>S. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
wenzelm@61973
  1753
    and "(f \<longlongrightarrow> l) (at a within S)"
wenzelm@61973
  1754
  shows "(g \<longlongrightarrow> l) (at a within S)"
lp15@60141
  1755
proof (rule Lim_transform_eventually)
wenzelm@63546
  1756
  show "(f \<longlongrightarrow> l) (at a within S)"
wenzelm@63546
  1757
    by fact
lp15@60141
  1758
  show "eventually (\<lambda>x. f x = g x) (at a within S)"
lp15@60141
  1759
    unfolding eventually_at_topological
wenzelm@63546
  1760
    by (rule exI [where x="- {b}"]) (simp add: open_Compl assms)
lp15@60141
  1761
qed
lp15@60141
  1762
lp15@60141
  1763
lemma Lim_transform_away_at:
lp15@60141
  1764
  fixes a b :: "'a::t1_space"
wenzelm@63546
  1765
  assumes ab: "a \<noteq> b"
lp15@60141
  1766
    and fg: "\<forall>x. x \<noteq> a \<and> x \<noteq> b \<longrightarrow> f x = g x"
wenzelm@61973
  1767
    and fl: "(f \<longlongrightarrow> l) (at a)"
wenzelm@61973
  1768
  shows "(g \<longlongrightarrow> l) (at a)"
lp15@60141
  1769
  using Lim_transform_away_within[OF ab, of UNIV f g l] fg fl by simp
lp15@60141
  1770
wenzelm@63546
  1771
text \<open>Alternatively, within an open set.\<close>
lp15@60141
  1772
lemma Lim_transform_within_open:
paulson@62087
  1773
  assumes "(f \<longlongrightarrow> l) (at a within T)"
paulson@62087
  1774
    and "open s" and "a \<in> s"
wenzelm@63546
  1775
    and "\<And>x. x\<in>s \<Longrightarrow> x \<noteq> a \<Longrightarrow> f x = g x"
paulson@62087
  1776
  shows "(g \<longlongrightarrow> l) (at a within T)"
lp15@60141
  1777
proof (rule Lim_transform_eventually)
paulson@62087
  1778
  show "eventually (\<lambda>x. f x = g x) (at a within T)"
lp15@60141
  1779
    unfolding eventually_at_topological
paulson@62087
  1780
    using assms by auto
paulson@62087
  1781
  show "(f \<longlongrightarrow> l) (at a within T)" by fact
lp15@60141
  1782
qed
lp15@60141
  1783
wenzelm@63546
  1784
wenzelm@63546
  1785
text \<open>A congruence rule allowing us to transform limits assuming not at point.\<close>
lp15@60141
  1786
lp15@60141
  1787
(* FIXME: Only one congruence rule for tendsto can be used at a time! *)
lp15@60141
  1788
lp15@60141
  1789
lemma Lim_cong_within(*[cong add]*):
lp15@60141
  1790
  assumes "a = b"
lp15@60141
  1791
    and "x = y"
lp15@60141
  1792
    and "S = T"
lp15@60141
  1793
    and "\<And>x. x \<noteq> b \<Longrightarrow> x \<in> T \<Longrightarrow> f x = g x"
wenzelm@61973
  1794
  shows "(f \<longlongrightarrow> x) (at a within S) \<longleftrightarrow> (g \<longlongrightarrow> y) (at b within T)"
lp15@60141
  1795
  unfolding tendsto_def eventually_at_topological
lp15@60141
  1796
  using assms by simp
lp15@60141
  1797
lp15@60141
  1798
lemma Lim_cong_at(*[cong add]*):
lp15@60141
  1799
  assumes "a = b" "x = y"
lp15@60141
  1800
    and "\<And>x. x \<noteq> a \<Longrightarrow> f x = g x"
wenzelm@61973
  1801
  shows "((\<lambda>x. f x) \<longlongrightarrow> x) (at a) \<longleftrightarrow> ((g \<longlongrightarrow> y) (at a))"
lp15@60141
  1802
  unfolding tendsto_def eventually_at_topological
lp15@60141
  1803
  using assms by simp
wenzelm@63546
  1804
wenzelm@63546
  1805
text \<open>An unbounded sequence's inverse tends to 0.\<close>
lp15@65578
  1806
lemma LIMSEQ_inverse_zero:
lp15@65578
  1807
  assumes "\<And>r::real. \<exists>N. \<forall>n\<ge>N. r < X n"
lp15@65578
  1808
  shows "(\<lambda>n. inverse (X n)) \<longlonglongrightarrow> 0"
hoelzl@51526
  1809
  apply (rule filterlim_compose[OF tendsto_inverse_0])
hoelzl@51526
  1810
  apply (simp add: filterlim_at_infinity[OF order_refl] eventually_sequentially)
lp15@65578
  1811
  apply (metis assms abs_le_D1 linorder_le_cases linorder_not_le)
hoelzl@51526
  1812
  done
hoelzl@51526
  1813
wenzelm@63546
  1814
text \<open>The sequence @{term "1/n"} tends to 0 as @{term n} tends to infinity.\<close>
wenzelm@63546
  1815
lemma LIMSEQ_inverse_real_of_nat: "(\<lambda>n. inverse (real (Suc n))) \<longlonglongrightarrow> 0"
hoelzl@51526
  1816
  by (metis filterlim_compose tendsto_inverse_0 filterlim_mono order_refl filterlim_Suc
wenzelm@63546
  1817
      filterlim_compose[OF filterlim_real_sequentially] at_top_le_at_infinity)
wenzelm@63546
  1818
wenzelm@63546
  1819
text \<open>
wenzelm@63546
  1820
  The sequence @{term "r + 1/n"} tends to @{term r} as @{term n} tends to
wenzelm@63546
  1821
  infinity is now easily proved.
wenzelm@63546
  1822
\<close>
wenzelm@63546
  1823
wenzelm@63546
  1824
lemma LIMSEQ_inverse_real_of_nat_add: "(\<lambda>n. r + inverse (real (Suc n))) \<longlonglongrightarrow> r"
hoelzl@51526
  1825
  using tendsto_add [OF tendsto_const LIMSEQ_inverse_real_of_nat] by auto
hoelzl@51526
  1826
wenzelm@63546
  1827
lemma LIMSEQ_inverse_real_of_nat_add_minus: "(\<lambda>n. r + -inverse (real (Suc n))) \<longlonglongrightarrow> r"
hoelzl@51526
  1828
  using tendsto_add [OF tendsto_const tendsto_minus [OF LIMSEQ_inverse_real_of_nat]]
hoelzl@51526
  1829
  by auto
hoelzl@51526
  1830
wenzelm@63546
  1831
lemma LIMSEQ_inverse_real_of_nat_add_minus_mult: "(\<lambda>n. r * (1 + - inverse (real (Suc n)))) \<longlonglongrightarrow> r"
hoelzl@51526
  1832
  using tendsto_mult [OF tendsto_const LIMSEQ_inverse_real_of_nat_add_minus [of 1]]
hoelzl@51526
  1833
  by auto
hoelzl@51526
  1834
wenzelm@61973
  1835
lemma lim_inverse_n: "((\<lambda>n. inverse(of_nat n)) \<longlongrightarrow> (0::'a::real_normed_field)) sequentially"
eberlm@61524
  1836
  using lim_1_over_n by (simp add: inverse_eq_divide)
eberlm@61524
  1837
wenzelm@61969
  1838
lemma LIMSEQ_Suc_n_over_n: "(\<lambda>n. of_nat (Suc n) / of_nat n :: 'a :: real_normed_field) \<longlonglongrightarrow> 1"
eberlm@61524
  1839
proof (rule Lim_transform_eventually)
eberlm@61524
  1840
  show "eventually (\<lambda>n. 1 + inverse (of_nat n :: 'a) = of_nat (Suc n) / of_nat n) sequentially"
wenzelm@63546
  1841
    using eventually_gt_at_top[of "0::nat"]
wenzelm@63546
  1842
    by eventually_elim (simp add: field_simps)
wenzelm@61969
  1843
  have "(\<lambda>n. 1 + inverse (of_nat n) :: 'a) \<longlonglongrightarrow> 1 + 0"
eberlm@61524
  1844
    by (intro tendsto_add tendsto_const lim_inverse_n)
wenzelm@63546
  1845
  then show "(\<lambda>n. 1 + inverse (of_nat n) :: 'a) \<longlonglongrightarrow> 1"
wenzelm@63546
  1846
    by simp
eberlm@61524
  1847
qed
eberlm@61524
  1848
wenzelm@61969
  1849
lemma LIMSEQ_n_over_Suc_n: "(\<lambda>n. of_nat n / of_nat (Suc n) :: 'a :: real_normed_field) \<longlonglongrightarrow> 1"
eberlm@61524
  1850
proof (rule Lim_transform_eventually)
paulson@62087
  1851
  show "eventually (\<lambda>n. inverse (of_nat (Suc n) / of_nat n :: 'a) =
wenzelm@63546
  1852
      of_nat n / of_nat (Suc n)) sequentially"
paulson@62087
  1853
    using eventually_gt_at_top[of "0::nat"]
eberlm@61524
  1854
    by eventually_elim (simp add: field_simps del: of_nat_Suc)
wenzelm@61969
  1855
  have "(\<lambda>n. inverse (of_nat (Suc n) / of_nat n :: 'a)) \<longlonglongrightarrow> inverse 1"
eberlm@61524
  1856
    by (intro tendsto_inverse LIMSEQ_Suc_n_over_n) simp_all
wenzelm@63546
  1857
  then show "(\<lambda>n. inverse (of_nat (Suc n) / of_nat n :: 'a)) \<longlonglongrightarrow> 1"
wenzelm@63546
  1858
    by simp
eberlm@61524
  1859
qed
eberlm@61524
  1860
wenzelm@63546
  1861
wenzelm@60758
  1862
subsection \<open>Convergence on sequences\<close>
hoelzl@51526
  1863
eberlm@61531
  1864
lemma convergent_cong:
eberlm@61531
  1865
  assumes "eventually (\<lambda>x. f x = g x) sequentially"
wenzelm@63546
  1866
  shows "convergent f \<longleftrightarrow> convergent g"
wenzelm@63546
  1867
  unfolding convergent_def
wenzelm@63546
  1868
  by (subst filterlim_cong[OF refl refl assms]) (rule refl)
eberlm@61531
  1869
eberlm@61531
  1870
lemma convergent_Suc_iff: "convergent (\<lambda>n. f (Suc n)) \<longleftrightarrow> convergent f"
eberlm@61531
  1871
  by (auto simp: convergent_def LIMSEQ_Suc_iff)
eberlm@61531
  1872
eberlm@61531
  1873
lemma convergent_ignore_initial_segment: "convergent (\<lambda>n. f (n + m)) = convergent f"
wenzelm@63546
  1874
proof (induct m arbitrary: f)
wenzelm@63546
  1875
  case 0
wenzelm@63546
  1876
  then show ?case by simp
wenzelm@63546
  1877
next
eberlm@61531
  1878
  case (Suc m)
wenzelm@63546
  1879
  have "convergent (\<lambda>n. f (n + Suc m)) \<longleftrightarrow> convergent (\<lambda>n. f (Suc n + m))"
wenzelm@63546
  1880
    by simp
wenzelm@63546
  1881
  also have "\<dots> \<longleftrightarrow> convergent (\<lambda>n. f (n + m))"
wenzelm@63546
  1882
    by (rule convergent_Suc_iff)
wenzelm@63546
  1883
  also have "\<dots> \<longleftrightarrow> convergent f"
wenzelm@63546
  1884
    by (rule Suc)
eberlm@61531
  1885
  finally show ?case .
wenzelm@63546
  1886
qed
eberlm@61531
  1887
hoelzl@51526
  1888
lemma convergent_add:
hoelzl@51526
  1889
  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@51526
  1890
  assumes "convergent (\<lambda>n. X n)"
wenzelm@63546
  1891
    and "convergent (\<lambda>n. Y n)"
hoelzl@51526
  1892
  shows "convergent (\<lambda>n. X n + Y n)"
lp15@61649
  1893
  using assms unfolding convergent_def by (blast intro: tendsto_add)
hoelzl@51526
  1894
nipkow@64267
  1895
lemma convergent_sum:
hoelzl@51526
  1896
  fixes X :: "'a \<Rightarrow> nat \<Rightarrow> 'b::real_normed_vector"
wenzelm@63915
  1897
  shows "(\<And>i. i \<in> A \<Longrightarrow> convergent (\<lambda>n. X i n)) \<Longrightarrow> convergent (\<lambda>n. \<Sum>i\<in>A. X i n)"
wenzelm@63915
  1898
  by (induct A rule: infinite_finite_induct) (simp_all add: convergent_const convergent_add)
hoelzl@51526
  1899
hoelzl@51526
  1900
lemma (in bounded_linear) convergent:
hoelzl@51526
  1901
  assumes "convergent (\<lambda>n. X n)"
hoelzl@51526
  1902
  shows "convergent (\<lambda>n. f (X n))"
lp15@61649
  1903
  using assms unfolding convergent_def by (blast intro: tendsto)
hoelzl@51526
  1904
hoelzl@51526
  1905
lemma (in bounded_bilinear) convergent:
wenzelm@63546
  1906
  assumes "convergent (\<lambda>n. X n)"
wenzelm@63546
  1907
    and "convergent (\<lambda>n. Y n)"
hoelzl@51526
  1908
  shows "convergent (\<lambda>n. X n ** Y n)"
lp15@61649
  1909
  using assms unfolding convergent_def by (blast intro: tendsto)
hoelzl@51526
  1910
wenzelm@63546
  1911
lemma convergent_minus_iff: "convergent X \<longleftrightarrow> convergent (\<lambda>n. - X n)"
wenzelm@63546
  1912
  for X :: "nat \<Rightarrow> 'a::real_normed_vector"
wenzelm@63546
  1913
  apply (simp add: convergent_def)
wenzelm@63546
  1914
  apply (auto dest: tendsto_minus)
wenzelm@63546
  1915
  apply (drule tendsto_minus)
wenzelm@63546
  1916
  apply auto
wenzelm@63546
  1917
  done
hoelzl@51526
  1918
eberlm@61531
  1919
lemma convergent_diff:
eberlm@61531
  1920
  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_vector"
eberlm@61531
  1921
  assumes "convergent (\<lambda>n. X n)"
eberlm@61531
  1922
  assumes "convergent (\<lambda>n. Y n)"
eberlm@61531
  1923
  shows "convergent (\<lambda>n. X n - Y n)"
lp15@61649
  1924
  using assms unfolding convergent_def by (blast intro: tendsto_diff)
eberlm@61531
  1925
eberlm@61531
  1926
lemma convergent_norm:
eberlm@61531
  1927
  assumes "convergent f"
wenzelm@63546
  1928
  shows "convergent (\<lambda>n. norm (f n))"
eberlm@61531
  1929
proof -
wenzelm@63546
  1930
  from assms have "f \<longlonglongrightarrow> lim f"
wenzelm@63546
  1931
    by (simp add: convergent_LIMSEQ_iff)
wenzelm@63546
  1932
  then have "(\<lambda>n. norm (f n)) \<longlonglongrightarrow> norm (lim f)"
wenzelm@63546
  1933
    by (rule tendsto_norm)
wenzelm@63546
  1934
  then show ?thesis
wenzelm@63546
  1935
    by (auto simp: convergent_def)
eberlm@61531
  1936
qed
eberlm@61531
  1937
paulson@62087
  1938
lemma convergent_of_real:
wenzelm@63546
  1939
  "convergent f \<Longrightarrow> convergent (\<lambda>n. of_real (f n) :: 'a::real_normed_algebra_1)"
eberlm@61531
  1940
  unfolding convergent_def by (blast intro!: tendsto_of_real)
eberlm@61531
  1941
paulson@62087
  1942
lemma convergent_add_const_iff:
wenzelm@63546
  1943
  "convergent (\<lambda>n. c + f n :: 'a::real_normed_vector) \<longleftrightarrow> convergent f"
eberlm@61531
  1944
proof
eberlm@61531
  1945
  assume "convergent (\<lambda>n. c + f n)"
wenzelm@63546
  1946
  from convergent_diff[OF this convergent_const[of c]] show "convergent f"
wenzelm@63546
  1947
    by simp
eberlm@61531
  1948
next
eberlm@61531
  1949
  assume "convergent f"
wenzelm@63546
  1950
  from convergent_add[OF convergent_const[of c] this] show "convergent (\<lambda>n. c + f n)"
wenzelm@63546
  1951
    by simp
eberlm@61531
  1952
qed
eberlm@61531
  1953
paulson@62087
  1954
lemma convergent_add_const_right_iff:
wenzelm@63546
  1955
  "convergent (\<lambda>n. f n + c :: 'a::real_normed_vector) \<longleftrightarrow> convergent f"
eberlm@61531
  1956
  using convergent_add_const_iff[of c f] by (simp add: add_ac)
eberlm@61531
  1957
paulson@62087
  1958
lemma convergent_diff_const_right_iff:
wenzelm@63546
  1959
  "convergent (\<lambda>n. f n - c :: 'a::real_normed_vector) \<longleftrightarrow> convergent f"
eberlm@61531
  1960
  using convergent_add_const_right_iff[of f "-c"] by (simp add: add_ac)
eberlm@61531
  1961
eberlm@61531
  1962
lemma convergent_mult:
eberlm@61531
  1963
  fixes X Y :: "nat \<Rightarrow> 'a::real_normed_field"
eberlm@61531
  1964
  assumes "convergent (\<lambda>n. X n)"
wenzelm@63546
  1965
    and "convergent (\<lambda>n. Y n)"
eberlm@61531
  1966
  shows "convergent (\<lambda>n. X n * Y n)"
lp15@61649
  1967
  using assms unfolding convergent_def by (blast intro: tendsto_mult)
eberlm@61531
  1968
eberlm@61531
  1969
lemma convergent_mult_const_iff:
eberlm@61531
  1970
  assumes "c \<noteq> 0"
wenzelm@63546
  1971
  shows "convergent (\<lambda>n. c * f n :: 'a::real_normed_field) \<longleftrightarrow> convergent f"
eberlm@61531
  1972
proof
eberlm@61531
  1973
  assume "convergent (\<lambda>n. c * f n)"
paulson@62087
  1974
  from assms convergent_mult[OF this convergent_const[of "inverse c"]]
eberlm@61531
  1975
    show "convergent f" by (simp add: field_simps)
eberlm@61531
  1976
next
eberlm@61531
  1977
  assume "convergent f"
wenzelm@63546
  1978
  from convergent_mult[OF convergent_const[of c] this] show "convergent (\<lambda>n. c * f n)"
wenzelm@63546
  1979
    by simp
eberlm@61531
  1980
qed
eberlm@61531
  1981
eberlm@61531
  1982
lemma convergent_mult_const_right_iff:
wenzelm@63546
  1983
  fixes c :: "'a::real_normed_field"
eberlm@61531
  1984
  assumes "c \<noteq> 0"
wenzelm@63546
  1985
  shows "convergent (\<lambda>n. f n * c) \<longleftrightarrow> convergent f"
eberlm@61531
  1986
  using convergent_mult_const_iff[OF assms, of f] by (simp add: mult_ac)
eberlm@61531
  1987
eberlm@61531
  1988
lemma convergent_imp_Bseq: "convergent f \<Longrightarrow> Bseq f"
eberlm@61531
  1989
  by (simp add: Cauchy_Bseq convergent_Cauchy)
eberlm@61531
  1990
hoelzl@51526
  1991
wenzelm@60758
  1992
text \<open>A monotone sequence converges to its least upper bound.\<close>
hoelzl@51526
  1993
hoelzl@54263
  1994
lemma LIMSEQ_incseq_SUP:
wenzelm@63546
  1995
  fixes X :: "nat \<Rightarrow> 'a::{conditionally_complete_linorder,linorder_topology}"
hoelzl@54263
  1996
  assumes u: "bdd_above (range X)"
wenzelm@63546
  1997
    and X: "incseq X"
wenzelm@61969
  1998
  shows "X \<longlonglongrightarrow> (SUP i. X i)"
hoelzl@54263
  1999
  by (rule order_tendstoI)
wenzelm@63546
  2000
    (auto simp: eventually_sequentially u less_cSUP_iff
wenzelm@63546
  2001
      intro: X[THEN incseqD] less_le_trans cSUP_lessD[OF u])
hoelzl@51526
  2002
hoelzl@54263
  2003
lemma LIMSEQ_decseq_INF:
hoelzl@54263
  2004
  fixes X :: "nat \<Rightarrow> 'a::{conditionally_complete_linorder, linorder_topology}"
hoelzl@54263
  2005
  assumes u: "bdd_below (range X)"
wenzelm@63546
  2006
    and X: "decseq X"
wenzelm@61969
  2007
  shows "X \<longlonglongrightarrow> (INF i. X i)"
hoelzl@54263
  2008
  by (rule order_tendstoI)
wenzelm@63546
  2009
     (auto simp: eventually_sequentially u cINF_less_iff
wenzelm@63546
  2010
       intro: X[THEN decseqD] le_less_trans less_cINF_D[OF u])
wenzelm@63546
  2011
wenzelm@63546
  2012
text \<open>Main monotonicity theorem.\<close>
wenzelm@63546
  2013
wenzelm@63546
  2014
lemma Bseq_monoseq_convergent: "Bseq X \<Longrightarrow> monoseq X \<Longrightarrow> convergent X"
wenzelm@63546
  2015
  for X :: "nat \<Rightarrow> real"
wenzelm@63546
  2016
  by (auto simp: monoseq_iff convergent_def intro: LIMSEQ_decseq_INF LIMSEQ_incseq_SUP
wenzelm@63546
  2017
      dest: Bseq_bdd_above Bseq_bdd_below)
wenzelm@63546
  2018
wenzelm@63546
  2019
lemma Bseq_mono_convergent: "Bseq X \<Longrightarrow> (\<forall>m n. m \<le> n \<longrightarrow> X m \<le> X n) \<Longrightarrow> convergent X"
wenzelm@63546
  2020
  for X :: "nat \<Rightarrow> real"
hoelzl@54263
  2021
  by (auto intro!: Bseq_monoseq_convergent incseq_imp_monoseq simp: incseq_def)
hoelzl@51526
  2022
wenzelm@63546
  2023
lemma monoseq_imp_convergent_iff_Bseq: "monoseq f \<Longrightarrow> convergent f \<longleftrightarrow> Bseq f"
wenzelm@63546
  2024
  for f :: "nat \<Rightarrow> real"
eberlm@61531
  2025
  using Bseq_monoseq_convergent[of f] convergent_imp_Bseq[of f] by blast
eberlm@61531
  2026
eberlm@61531
  2027
lemma Bseq_monoseq_convergent'_inc:
wenzelm@63546
  2028
  fixes f :: "nat \<Rightarrow> real"
wenzelm@63546
  2029
  shows "Bseq (\<lambda>n. f (n + M)) \<Longrightarrow> (\<And>m n. M \<le> m \<Longrightarrow> m \<le> n \<Longrightarrow> f m \<le> f n) \<Longrightarrow> convergent f"
eberlm@61531
  2030
  by (subst convergent_ignore_initial_segment [symmetric, of _ M])
eberlm@61531
  2031
     (auto intro!: Bseq_monoseq_convergent simp: monoseq_def)
eberlm@61531
  2032
eberlm@61531
  2033
lemma Bseq_monoseq_convergent'_dec:
wenzelm@63546
  2034
  fixes f :: "nat \<Rightarrow> real"
wenzelm@63546
  2035
  shows "Bseq (\<lambda>n. f (n + M)) \<Longrightarrow> (\<And>m n. M \<le> m \<Longrightarrow> m \<le> n \<Longrightarrow> f m \<ge> f n) \<Longrightarrow> convergent f"
eberlm@61531
  2036
  by (subst convergent_ignore_initial_segment [symmetric, of _ M])
wenzelm@63546
  2037
    (auto intro!: Bseq_monoseq_convergent simp: monoseq_def)
wenzelm@63546
  2038
wenzelm@63546
  2039
lemma Cauchy_iff: "Cauchy X \<longleftrightarrow> (\<forall>e>0. \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m - X n) < e)"
wenzelm@63546
  2040
  for X :: "nat \<Rightarrow> 'a::real_normed_vector"
hoelzl@51526
  2041
  unfolding Cauchy_def dist_norm ..
hoelzl@51526
  2042
wenzelm@63546
  2043
lemma CauchyI: "(\<And>e. 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m - X n) < e) \<Longrightarrow> Cauchy X"
wenzelm@63546
  2044
  for X :: "nat \<Rightarrow> 'a::real_normed_vector"
wenzelm@63546
  2045
  by (simp add: Cauchy_iff)
wenzelm@63546
  2046
wenzelm@63546
  2047
lemma CauchyD: "Cauchy X \<Longrightarrow> 0 < e \<Longrightarrow> \<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m - X n) < e"
wenzelm@63546
  2048
  for X :: "nat \<Rightarrow> 'a::real_normed_vector"
wenzelm@63546
  2049
  by (simp add: Cauchy_iff)
hoelzl@51526
  2050
hoelzl@51526
  2051
lemma incseq_convergent:
hoelzl@51526
  2052
  fixes X :: "nat \<Rightarrow> real"
wenzelm@63546
  2053
  assumes "incseq X"
wenzelm@63546
  2054
    and "\<forall>i. X i \<le> B"
wenzelm@61969
  2055
  obtains L where "X \<longlonglongrightarrow> L" "\<forall>i. X i \<le> L"
hoelzl@51526
  2056
proof atomize_elim
wenzelm@60758
  2057
  from incseq_bounded[OF assms] \<open>incseq X\<close> Bseq_monoseq_convergent[of X]
wenzelm@61969
  2058
  obtain L where "X \<longlonglongrightarrow> L"
hoelzl@51526
  2059
    by (auto simp: convergent_def monoseq_def incseq_def)
wenzelm@61969
  2060
  with \<open>incseq X\<close> show "\<exists>L. X \<longlonglongrightarrow> L \<and> (\<forall>i. X i \<le> L)"
hoelzl@51526
  2061
    by (auto intro!: exI[of _ L] incseq_le)
hoelzl@51526
  2062
qed
hoelzl@51526
  2063
hoelzl@51526
  2064
lemma decseq_convergent:
hoelzl@51526
  2065
  fixes X :: "nat \<Rightarrow> real"
wenzelm@63546
  2066
  assumes "decseq X"
wenzelm@63546
  2067
    and "\<forall>i. B \<le> X i"
wenzelm@61969
  2068
  obtains L where "X \<longlonglongrightarrow> L" "\<forall>i. L \<le> X i"
hoelzl@51526
  2069
proof atomize_elim
wenzelm@60758
  2070
  from decseq_bounded[OF assms] \<open>decseq X\<close> Bseq_monoseq_convergent[of X]
wenzelm@61969
  2071
  obtain L where "X \<longlonglongrightarrow> L"
hoelzl@51526
  2072
    by (auto simp: convergent_def monoseq_def decseq_def)
wenzelm@61969
  2073
  with \<open>decseq X\<close> show "\<exists>L. X \<longlonglongrightarrow> L \<and> (\<forall>i. L \<le> X i)"
hoelzl@51526
  2074
    by (auto intro!: exI[of _ L] decseq_le)
hoelzl@51526
  2075
qed
hoelzl@51526
  2076
wenzelm@63546
  2077
wenzelm@60758
  2078
subsection \<open>Power Sequences\<close>
hoelzl@51526
  2079
wenzelm@63546
  2080
text \<open>
wenzelm@63546
  2081
  The sequence @{term "x^n"} tends to 0 if @{term "0\<le>x"} and @{term
wenzelm@63546
  2082
  "x<1"}.  Proof will use (NS) Cauchy equivalence for convergence and
wenzelm@63546
  2083
  also fact that bounded and monotonic sequence converges.
wenzelm@63546
  2084
\<close>
wenzelm@63546
  2085
wenzelm@63546
  2086
lemma Bseq_realpow: "0 \<le> x \<Longrightarrow> x \<le> 1 \<Longrightarrow> Bseq (\<lambda>n. x ^ n)"
wenzelm@63546
  2087
  for x :: real
wenzelm@63546
  2088
  apply (simp add: Bseq_def)
wenzelm@63546
  2089
  apply (rule_tac x = 1 in exI)
wenzelm@63546
  2090
  apply (simp add: power_abs)
wenzelm@63546
  2091
  apply (auto dest: power_mono)
wenzelm@63546
  2092
  done
wenzelm@63546
  2093
wenzelm@63546
  2094
lemma monoseq_realpow: "0 \<le> x \<Longrightarrow> x \<le> 1 \<Longrightarrow> monoseq (\<lambda>n. x ^ n)"
wenzelm@63546
  2095
  for x :: real
wenzelm@63546
  2096
  apply (clarify intro!: mono_SucI2)
wenzelm@63546
  2097
  apply (cut_tac n = n and N = "Suc n" and a = x in power_decreasing)
wenzelm@63546
  2098
     apply auto
wenzelm@63546
  2099
  done
wenzelm@63546
  2100
wenzelm@63546
  2101
lemma convergent_realpow: "0 \<le> x \<Longrightarrow> x \<le> 1 \<Longrightarrow> convergent (\<lambda>n. x ^ n)"
wenzelm@63546
  2102
  for x :: real
wenzelm@63546
  2103
  by (blast intro!: Bseq_monoseq_convergent Bseq_realpow monoseq_realpow)
wenzelm@63546
  2104
wenzelm@63546
  2105
lemma LIMSEQ_inverse_realpow_zero: "1 < x \<Longrightarrow> (\<lambda>n. inverse (x ^ n)) \<longlonglongrightarrow> 0"
wenzelm@63546
  2106
  for x :: real
hoelzl@51526
  2107
  by (rule filterlim_compose[OF tendsto_inverse_0 filterlim_realpow_sequentially_gt1]) simp
hoelzl@51526
  2108
hoelzl@51526
  2109
lemma LIMSEQ_realpow_zero:
wenzelm@63546
  2110
  fixes x :: real
wenzelm@63546
  2111
  assumes "0 \<le> x" "x < 1"
wenzelm@63546
  2112
  shows "(\<lambda>n. x ^ n) \<longlonglongrightarrow> 0"
wenzelm@63546
  2113
proof (cases "x = 0")
wenzelm@63546
  2114
  case False
wenzelm@63546
  2115
  with \<open>0 \<le> x\<close> have x0: "0 < x" by simp
wenzelm@63546
  2116
  then have "1 < inverse x"
wenzelm@63546
  2117
    using \<open>x < 1\<close> by (rule one_less_inverse)
wenzelm@63546
  2118
  then have "(\<lambda>n. inverse (inverse x ^ n)) \<longlonglongrightarrow> 0"
hoelzl@51526
  2119
    by (rule LIMSEQ_inverse_realpow_zero)
wenzelm@63546
  2120
  then show ?thesis by (simp add: power_inverse)
wenzelm@63546
  2121
next
wenzelm@63546
  2122
  case True
wenzelm@63546
  2123
  show ?thesis
wenzelm@63546
  2124
    by (rule LIMSEQ_imp_Suc) (simp add: True)
wenzelm@63546
  2125
qed
wenzelm@63546
  2126
wenzelm@63546
  2127
lemma LIMSEQ_power_zero: "norm x < 1 \<Longrightarrow> (\<lambda>n. x ^ n) \<longlonglongrightarrow> 0"
wenzelm@63546
  2128
  for x :: "'a::real_normed_algebra_1"
wenzelm@63546
  2129
  apply (drule LIMSEQ_realpow_zero [OF norm_ge_zero])
wenzelm@63546
  2130
  apply (simp only: tendsto_Zfun_iff, erule Zfun_le)
wenzelm@63546
  2131
  apply (simp add: power_abs norm_power_ineq)
wenzelm@63546
  2132
  done
hoelzl@51526
  2133
wenzelm@61969
  2134
lemma LIMSEQ_divide_realpow_zero: "1 < x \<Longrightarrow> (\<lambda>n. a / (x ^ n) :: real) \<longlonglongrightarrow> 0"
hoelzl@51526
  2135
  by (rule tendsto_divide_0 [OF tendsto_const filterlim_realpow_sequentially_gt1]) simp
hoelzl@51526
  2136
immler@63556
  2137
lemma
immler@63556
  2138
  tendsto_power_zero:
immler@63556
  2139
  fixes x::"'a::real_normed_algebra_1"
immler@63556
  2140
  assumes "filterlim f at_top F"
immler@63556
  2141
  assumes "norm x < 1"
immler@63556
  2142
  shows "((\<lambda>y. x ^ (f y)) \<longlongrightarrow> 0) F"
immler@63556
  2143
proof (rule tendstoI)
immler@63556
  2144
  fix e::real assume "0 < e"
immler@63556
  2145
  from tendstoD[OF LIMSEQ_power_zero[OF \<open>norm x < 1\<close>] \<open>0 < e\<close>]
immler@63556
  2146
  have "\<forall>\<^sub>F xa in sequentially. norm (x ^ xa) < e"
immler@63556
  2147
    by simp
immler@63556
  2148
  then obtain N where N: "norm (x ^ n) < e" if "n \<ge> N" for n
immler@63556
  2149
    by (auto simp: eventually_sequentially)
immler@63556
  2150
  have "\<forall>\<^sub>F i in F. f i \<ge> N"
immler@63556
  2151
    using \<open>filterlim f sequentially F\<close>
immler@63556
  2152
    by (simp add: filterlim_at_top)
immler@63556
  2153
  then show "\<forall>\<^sub>F i in F. dist (x ^ f i) 0 < e"
immler@63556
  2154
    by (eventually_elim) (auto simp: N)
immler@63556
  2155
qed
immler@63556
  2156
wenzelm@63546
  2157
text \<open>Limit of @{term "c^n"} for @{term"\<bar>c\<bar> < 1"}.\<close>
hoelzl@51526
  2158
wenzelm@61969
  2159
lemma LIMSEQ_rabs_realpow_zero: "\<bar>c\<bar> < 1 \<Longrightarrow> (\<lambda>n. \<bar>c\<bar> ^ n :: real) \<longlonglongrightarrow> 0"
hoelzl@51526
  2160
  by (rule LIMSEQ_realpow_zero [OF abs_ge_zero])
hoelzl@51526
  2161
wenzelm@61969
  2162
lemma LIMSEQ_rabs_realpow_zero2: "\<bar>c\<bar> < 1 \<Longrightarrow> (\<lambda>n. c ^ n :: real) \<longlonglongrightarrow> 0"
hoelzl@51526
  2163
  by (rule LIMSEQ_power_zero) simp
hoelzl@51526
  2164
hoelzl@51526
  2165
wenzelm@60758
  2166
subsection \<open>Limits of Functions\<close>
hoelzl@51526
  2167
wenzelm@63546
  2168
lemma LIM_eq: "f \<midarrow>a\<rightarrow> L = (\<forall>r>0. \<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (f x - L) < r)"
wenzelm@63546
  2169
  for a :: "'a::real_normed_vector" and L :: "'b::real_normed_vector"
wenzelm@63546
  2170
  by (simp add: LIM_def dist_norm)
hoelzl@51526
  2171
hoelzl@51526
  2172
lemma LIM_I:
wenzelm@63546
  2173
  "(\<And>r. 0 < r \<Longrightarrow> \<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (f x - L) < r) \<Longrightarrow> f \<midarrow>a\<rightarrow> L"
wenzelm@63546
  2174
  for a :: "'a::real_normed_vector" and L :: "'b::real_normed_vector"
wenzelm@63546
  2175
  by (simp add: LIM_eq)
wenzelm@63546
  2176
wenzelm@63546
  2177
lemma LIM_D: "f \<midarrow>a\<rightarrow> L \<Longrightarrow> 0 < r \<Longrightarrow> \<exists>s>0.\<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (f x - L) < r"
wenzelm@63546
  2178
  for a :: "'a::real_normed_vector" and L :: "'b::real_normed_vector"
wenzelm@63546
  2179
  by (simp add: LIM_eq)
wenzelm@63546
  2180
wenzelm@63546
  2181
lemma LIM_offset: "f \<midarrow>a\<rightarrow> L \<Longrightarrow> (\<lambda>x. f (x + k)) \<midarrow>(a - k)\<rightarrow> L"
wenzelm@63546
  2182
  for a :: "'a::real_normed_vector"
wenzelm@63546
  2183
  by (simp add: filtermap_at_shift[symmetric, of a k] filterlim_def filtermap_filtermap)
wenzelm@63546
  2184
wenzelm@63546
  2185
lemma LIM_offset_zero: "f \<midarrow>a\<rightarrow> L \<Longrightarrow> (\<lambda>h. f (a + h)) \<midarrow>0\<rightarrow> L"
wenzelm@63546
  2186
  for a :: "'a::real_normed_vector"
wenzelm@63546
  2187
  by (drule LIM_offset [where k = a]) (simp add: add.commute)
wenzelm@63546
  2188
wenzelm@63546
  2189
lemma LIM_offset_zero_cancel: "(\<lambda>h. f (a + h)) \<midarrow>0\<rightarrow> L \<Longrightarrow> f \<midarrow>a\<rightarrow> L"
wenzelm@63546
  2190
  for a :: "'a::real_normed_vector"
wenzelm@63546
  2191
  by (drule LIM_offset [where k = "- a"]) simp
wenzelm@63546
  2192
wenzelm@63546
  2193
lemma LIM_offset_zero_iff: "f \<midarrow>a\<rightarrow> L \<longleftrightarrow> (\<lambda>h. f (a + h)) \<midarrow>0\<rightarrow> L"
wenzelm@63546
  2194
  for f :: "'a :: real_normed_vector \<Rightarrow> _"
hoelzl@51642
  2195
  using LIM_offset_zero_cancel[of f a L] LIM_offset_zero[of f L a] by auto
hoelzl@51642
  2196
wenzelm@63546
  2197
lemma LIM_zero: "(f \<longlongrightarrow> l) F \<Longrightarrow> ((\<lambda>x. f x - l) \<longlongrightarrow> 0) F"
lp15@65578
  2198
  for f :: "'a \<Rightarrow> 'b::real_normed_vector"
wenzelm@63546
  2199
  unfolding tendsto_iff dist_norm by simp
hoelzl@51526
  2200
hoelzl@51526
  2201
lemma LIM_zero_cancel:
lp15@65578
  2202
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
wenzelm@61973
  2203
  shows "((\<lambda>x. f x - l) \<longlongrightarrow> 0) F \<Longrightarrow> (f \<longlongrightarrow> l) F"
hoelzl@51526
  2204
unfolding tendsto_iff dist_norm by simp
hoelzl@51526
  2205
wenzelm@63546
  2206
lemma LIM_zero_iff: "((\<lambda>x. f x - l) \<longlongrightarrow> 0) F = (f \<longlongrightarrow> l) F"
lp15@65578
  2207
  for f :: "'a \<Rightarrow> 'b::real_normed_vector"
wenzelm@63546
  2208
  unfolding tendsto_iff dist_norm by simp
hoelzl@51526
  2209
hoelzl@51526
  2210
lemma LIM_imp_LIM:
hoelzl@51526
  2211
  fixes f :: "'a::topological_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51526
  2212
  fixes g :: "'a::topological_space \<Rightarrow> 'c::real_normed_vector"
wenzelm@61976
  2213
  assumes f: "f \<midarrow>a\<rightarrow> l"
wenzelm@63546
  2214
    and le: "\<And>x. x \<noteq> a \<Longrightarrow> norm (g x - m) \<le> norm (f x - l)"
wenzelm@61976
  2215
  shows "g \<midarrow>a\<rightarrow> m"
wenzelm@63546
  2216
  by (rule metric_LIM_imp_LIM [OF f]) (simp add: dist_norm le)
hoelzl@51526
  2217
hoelzl@51526
  2218
lemma LIM_equal2:
hoelzl@51526
  2219
  fixes f g :: "'a::real_normed_vector \<Rightarrow> 'b::topological_space"
wenzelm@63546
  2220
  assumes "0 < R"
wenzelm@63546
  2221
    and "\<And>x. x \<noteq> a \<Longrightarrow> norm (x - a) < R \<Longrightarrow> f x = g x"
wenzelm@61976
  2222
  shows "g \<midarrow>a\<rightarrow> l \<Longrightarrow> f \<midarrow>a\<rightarrow> l"
wenzelm@63546
  2223
  by (rule metric_LIM_equal2 [OF assms]) (simp_all add: dist_norm)
hoelzl@51526
  2224
hoelzl@51526
  2225
lemma LIM_compose2:
hoelzl@51526
  2226
  fixes a :: "'a::real_normed_vector"
wenzelm@61976
  2227
  assumes f: "f \<midarrow>a\<rightarrow> b"
wenzelm@63546
  2228
    and g: "g \<midarrow>b\<rightarrow> c"
wenzelm@63546
  2229
    and inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < d \<longrightarrow> f x \<noteq> b"
wenzelm@61976
  2230
  shows "(\<lambda>x. g (f x)) \<midarrow>a\<rightarrow> c"
wenzelm@63546
  2231
  by (rule metric_LIM_compose2 [OF f g inj [folded dist_norm]])
hoelzl@51526
  2232
hoelzl@51526
  2233
lemma real_LIM_sandwich_zero:
hoelzl@51526
  2234
  fixes f g :: "'a::topological_space \<Rightarrow> real"
wenzelm@61976
  2235
  assumes f: "f \<midarrow>a\<rightarrow> 0"
wenzelm@63546
  2236
    and 1: "\<And>x. x \<noteq> a \<Longrightarrow> 0 \<le> g x"
wenzelm@63546
  2237
    and 2: "\<And>x. x \<noteq> a \<Longrightarrow> g x \<le> f x"
wenzelm@61976
  2238
  shows "g \<midarrow>a\<rightarrow> 0"
hoelzl@51526
  2239
proof (rule LIM_imp_LIM [OF f]) (* FIXME: use tendsto_sandwich *)
wenzelm@63546
  2240
  fix x
wenzelm@63546
  2241
  assume x: "x \<noteq> a"
wenzelm@63546
  2242
  with 1 have "norm (g x - 0) = g x" by simp
hoelzl@51526
  2243
  also have "g x \<le> f x" by (rule 2 [OF x])
hoelzl@51526
  2244
  also have "f x \<le> \<bar>f x\<bar>" by (rule abs_ge_self)
hoelzl@51526
  2245
  also have "\<bar>f x\<bar> = norm (f x - 0)" by simp
hoelzl@51526
  2246
  finally show "norm (g x - 0) \<le> norm (f x - 0)" .
hoelzl@51526
  2247
qed
hoelzl@51526
  2248
hoelzl@51526
  2249
wenzelm@60758
  2250
subsection \<open>Continuity\<close>
hoelzl@51526
  2251
wenzelm@63546
  2252
lemma LIM_isCont_iff: "(f \<midarrow>a\<rightarrow> f a) = ((\<lambda>h. f (a + h)) \<midarrow>0\<rightarrow> f a)"
wenzelm@63546
  2253
  for f :: "'a::real_normed_vector \<Rightarrow> 'b::topological_space"
wenzelm@63546
  2254
  by (rule iffI [OF LIM_offset_zero LIM_offset_zero_cancel])
wenzelm@63546
  2255
wenzelm@63546
  2256
lemma isCont_iff: "isCont f x = (\<lambda>h. f (x + h)) \<midarrow>0\<rightarrow> f x"
wenzelm@63546
  2257
  for f :: "'a::real_normed_vector \<Rightarrow> 'b::topological_space"
wenzelm@63546
  2258
  by (simp add: isCont_def LIM_isCont_iff)
hoelzl@51526
  2259
hoelzl@51526
  2260
lemma isCont_LIM_compose2:
hoelzl@51526
  2261
  fixes a :: "'a::real_normed_vector"
hoelzl@51526
  2262
  assumes f [unfolded isCont_def]: "isCont f a"
wenzelm@63546
  2263
    and g: "g \<midarrow>f a\<rightarrow> l"
wenzelm@63546
  2264
    and inj: "\<exists>d>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < d \<longrightarrow> f x \<noteq> f a"
wenzelm@61976
  2265
  shows "(\<lambda>x. g (f x)) \<midarrow>a\<rightarrow> l"
wenzelm@63546
  2266
  by (rule LIM_compose2 [OF f g inj])
wenzelm@63546
  2267
wenzelm@63546
  2268
lemma isCont_norm [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. norm (f x)) a"
wenzelm@63546
  2269
  for f :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51526
  2270
  by (fact continuous_norm)
hoelzl@51526
  2271
wenzelm@63546
  2272
lemma isCont_rabs [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. \<bar>f x\<bar>) a"
wenzelm@63546
  2273
  for f :: "'a::t2_space \<Rightarrow> real"
hoelzl@51526
  2274
  by (fact continuous_rabs)
hoelzl@51526
  2275
wenzelm@63546
  2276
lemma isCont_add [simp]: "isCont f a \<Longrightarrow> isCont g a \<Longrightarrow> isCont (\<lambda>x. f x + g x) a"
wenzelm@63546
  2277
  for f :: "'a::t2_space \<Rightarrow> 'b::topological_monoid_add"
hoelzl@51526
  2278
  by (fact continuous_add)
hoelzl@51526
  2279
wenzelm@63546
  2280
lemma isCont_minus [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. - f x) a"
wenzelm@63546
  2281
  for f :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51526
  2282
  by (fact continuous_minus)
hoelzl@51526
  2283
wenzelm@63546
  2284
lemma isCont_diff [simp]: "isCont f a \<Longrightarrow> isCont g a \<Longrightarrow> isCont (\<lambda>x. f x - g x) a"
wenzelm@63546
  2285
  for f :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51526
  2286
  by (fact continuous_diff)
hoelzl@51526
  2287
wenzelm@63546
  2288
lemma isCont_mult [simp]: "isCont f a \<Longrightarrow> isCont g a \<Longrightarrow> isCont (\<lambda>x. f x * g x) a"
wenzelm@63546
  2289
  for f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_algebra"
hoelzl@51526
  2290
  by (fact continuous_mult)
hoelzl@51526
  2291
wenzelm@63546
  2292
lemma (in bounded_linear) isCont: "isCont g a \<Longrightarrow> isCont (\<lambda>x. f (g x)) a"
hoelzl@51526
  2293
  by (fact continuous)
hoelzl@51526
  2294
wenzelm@63546
  2295
lemma (in bounded_bilinear) isCont: "isCont f a \<Longrightarrow> isCont g a \<Longrightarrow> isCont (\<lambda>x. f x ** g x) a"
hoelzl@51526
  2296
  by (fact continuous)
hoelzl@51526
  2297
lp15@60141
  2298
lemmas isCont_scaleR [simp] =
hoelzl@51526
  2299
  bounded_bilinear.isCont [OF bounded_bilinear_scaleR]
hoelzl@51526
  2300
hoelzl@51526
  2301
lemmas isCont_of_real [simp] =
hoelzl@51526
  2302
  bounded_linear.isCont [OF bounded_linear_of_real]
hoelzl@51526
  2303
wenzelm@63546
  2304
lemma isCont_power [simp]: "isCont f a \<Longrightarrow> isCont (\<lambda>x. f x ^ n) a"
wenzelm@63546
  2305
  for f :: "'a::t2_space \<Rightarrow> 'b::{power,real_normed_algebra}"
hoelzl@51526
  2306
  by (fact continuous_power)
hoelzl@51526
  2307
nipkow@64267
  2308
lemma isCont_sum [simp]: "\<forall>i\<in>A. isCont (f i) a \<Longrightarrow> isCont (\<lambda>x. \<Sum>i\<in>A. f i x) a"
wenzelm@63546
  2309
  for f :: "'a \<Rightarrow> 'b::t2_space \<Rightarrow> 'c::topological_comm_monoid_add"
nipkow@64267
  2310
  by (auto intro: continuous_sum)
hoelzl@51526
  2311
wenzelm@63546
  2312
wenzelm@60758
  2313
subsection \<open>Uniform Continuity\<close>
hoelzl@51526
  2314
immler@63104
  2315
lemma uniformly_continuous_on_def:
immler@63104
  2316
  fixes f :: "'a::metric_space \<Rightarrow> 'b::metric_space"
immler@63104
  2317
  shows "uniformly_continuous_on s f \<longleftrightarrow>
immler@63104
  2318
    (\<forall>e>0. \<exists>d>0. \<forall>x\<in>s. \<forall>x'\<in>s. dist x' x < d \<longrightarrow> dist (f x') (f x) < e)"
immler@63104
  2319
  unfolding uniformly_continuous_on_uniformity
immler@63104
  2320
    uniformity_dist filterlim_INF filterlim_principal eventually_inf_principal
immler@63104
  2321
  by (force simp: Ball_def uniformity_dist[symmetric] eventually_uniformity_metric)
immler@63104
  2322
wenzelm@63546
  2323
abbreviation isUCont :: "['a::metric_space \<Rightarrow> 'b::metric_space] \<Rightarrow> bool"
wenzelm@63546
  2324
  where "isUCont f \<equiv> uniformly_continuous_on UNIV f"
wenzelm@63546
  2325
wenzelm@63546
  2326
lemma isUCont_def: "isUCont f \<longleftrightarrow> (\<forall>r>0. \<exists>s>0. \<forall>x y. dist x y < s \<longrightarrow> dist (f x) (f y) < r)"
immler@63104
  2327
  by (auto simp: uniformly_continuous_on_def dist_commute)
hoelzl@51531
  2328
wenzelm@63546
  2329
lemma isUCont_isCont: "isUCont f \<Longrightarrow> isCont f x"
immler@63104
  2330
  by (drule uniformly_continuous_imp_continuous) (simp add: continuous_on_eq_continuous_at)
immler@63104
  2331
immler@63104
  2332
lemma uniformly_continuous_on_Cauchy:
wenzelm@63546
  2333
  fixes f :: "'a::metric_space \<Rightarrow> 'b::metric_space"
immler@63104
  2334
  assumes "uniformly_continuous_on S f" "Cauchy X" "\<And>n. X n \<in> S"
immler@63104
  2335
  shows "Cauchy (\<lambda>n. f (X n))"
immler@63104
  2336
  using assms
wenzelm@63546
  2337
  apply (simp only: uniformly_continuous_on_def)
immler@63104
  2338
  apply (rule metric_CauchyI)
wenzelm@63546
  2339
  apply (drule_tac x=e in spec)
wenzelm@63546
  2340
  apply safe
wenzelm@63546
  2341
  apply (drule_tac e=d in metric_CauchyD)
wenzelm@63546
  2342
   apply safe
wenzelm@63546
  2343
  apply (rule_tac x=M in exI)
wenzelm@63546
  2344
  apply simp
immler@63104
  2345
  done
hoelzl@51531
  2346
wenzelm@63546
  2347
lemma isUCont_Cauchy: "isUCont f \<Longrightarrow> Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. f (X n))"
immler@63104
  2348
  by (rule uniformly_continuous_on_Cauchy[where S=UNIV and f=f]) simp_all
lp15@64287
  2349
  
lp15@64287
  2350
lemma uniformly_continuous_imp_Cauchy_continuous:
lp15@64287
  2351
  fixes f :: "'a::metric_space \<Rightarrow> 'b::metric_space"
lp15@64287
  2352
  shows "\<lbrakk>uniformly_continuous_on S f; Cauchy \<sigma>; \<And>n. (\<sigma> n) \<in> S\<rbrakk> \<Longrightarrow> Cauchy(f o \<sigma>)"
lp15@64287
  2353
  by (simp add: uniformly_continuous_on_def Cauchy_def) meson
hoelzl@51531
  2354
hoelzl@51526
  2355
lemma (in bounded_linear) isUCont: "isUCont f"
wenzelm@63546
  2356
  unfolding isUCont_def dist_norm
hoelzl@51526
  2357
proof (intro allI impI)
wenzelm@63546
  2358
  fix r :: real
wenzelm@63546
  2359
  assume r: "0 < r"
wenzelm@63546
  2360
  obtain K where K: "0 < K" and norm_le: "norm (f x) \<le> norm x * K" for x
lp15@61649
  2361
    using pos_bounded by blast
hoelzl@51526
  2362
  show "\<exists>s>0. \<forall>x y. norm (x - y) < s \<longrightarrow> norm (f x - f y) < r"
hoelzl@51526
  2363
  proof (rule exI, safe)
nipkow@56541
  2364
    from r K show "0 < r / K" by simp
hoelzl@51526
  2365
  next
hoelzl@51526
  2366
    fix x y :: 'a
hoelzl@51526
  2367
    assume xy: "norm (x - y) < r / K"
hoelzl@51526
  2368
    have "norm (f x - f y) = norm (f (x - y))" by (simp only: diff)
hoelzl@51526
  2369
    also have "\<dots> \<le> norm (x - y) * K" by (rule norm_le)
hoelzl@51526
  2370
    also from K xy have "\<dots> < r" by (simp only: pos_less_divide_eq)
hoelzl@51526
  2371
    finally show "norm (f x - f y) < r" .
hoelzl@51526
  2372
  qed
hoelzl@51526
  2373
qed
hoelzl@51526
  2374
hoelzl@51526
  2375
lemma (in bounded_linear) Cauchy: "Cauchy X \<Longrightarrow> Cauchy (\<lambda>n. f (X n))"
wenzelm@63546
  2376
  by (rule isUCont [THEN isUCont_Cauchy])
hoelzl@51526
  2377
lp15@60141
  2378
lemma LIM_less_bound:
hoelzl@51526
  2379
  fixes f :: "real \<Rightarrow> real"
hoelzl@51526
  2380
  assumes ev: "b < x" "\<forall> x' \<in> { b <..< x}. 0 \<le> f x'" and "isCont f x"
hoelzl@51526
  2381
  shows "0 \<le> f x"
lp15@63952
  2382
proof (rule tendsto_lowerbound)
wenzelm@61973
  2383
  show "(f \<longlongrightarrow> f x) (at_left x)"
wenzelm@60758
  2384
    using \<open>isCont f x\<close> by (simp add: filterlim_at_split isCont_def)
hoelzl@51526
  2385
  show "eventually (\<lambda>x. 0 \<le> f x) (at_left x)"
hoelzl@51641
  2386
    using ev by (auto simp: eventually_at dist_real_def intro!: exI[of _ "x - b"])
hoelzl@51526
  2387
qed simp
hoelzl@51471
  2388
hoelzl@51529
  2389
wenzelm@60758
  2390
subsection \<open>Nested Intervals and Bisection -- Needed for Compactness\<close>
hoelzl@51529
  2391
hoelzl@51529
  2392
lemma nested_sequence_unique:
wenzelm@61969
  2393
  assumes "\<forall>n. f n \<le> f (Suc n)" "\<forall>n. g (Suc n) \<le> g n" "\<forall>n. f n \<le> g n" "(\<lambda>n. f n - g n) \<longlonglongrightarrow> 0"
wenzelm@61969
  2394
  shows "\<exists>l::real. ((\<forall>n. f n \<le> l) \<and> f \<longlonglongrightarrow> l) \<and> ((\<forall>n. l \<le> g n) \<and> g \<longlonglongrightarrow> l)"
hoelzl@51529
  2395
proof -
hoelzl@51529
  2396
  have "incseq f" unfolding incseq_Suc_iff by fact
hoelzl@51529
  2397
  have "decseq g" unfolding decseq_Suc_iff by fact
wenzelm@63546
  2398
  have "f n \<le> g 0" for n
wenzelm@63546
  2399
  proof -
wenzelm@63546
  2400
    from \<open>decseq g\<close> have "g n \<le> g 0"
wenzelm@63546
  2401
      by (rule decseqD) simp
wenzelm@63546
  2402
    with \<open>\<forall>n. f n \<le> g n\<close>[THEN spec, of n] show ?thesis
wenzelm@63546
  2403
      by auto
wenzelm@63546
  2404
  qed
wenzelm@61969
  2405
  then obtain u where "f \<longlonglongrightarrow> u" "\<forall>i. f i \<le> u"
wenzelm@60758
  2406
    using incseq_convergent[OF \<open>incseq f\<close>] by auto
wenzelm@63546
  2407
  moreover have "f 0 \<le> g n" for n
wenzelm@63546
  2408
  proof -
wenzelm@60758
  2409
    from \<open>incseq f\<close> have "f 0 \<le> f n" by (rule incseqD) simp
wenzelm@63546
  2410
    with \<open>\<forall>n. f n \<le> g n\<close>[THEN spec, of n] show ?thesis
wenzelm@63546
  2411
      by simp
wenzelm@63546
  2412
  qed
wenzelm@61969
  2413
  then obtain l where "g \<longlonglongrightarrow> l" "\<forall>i. l \<le> g i"
wenzelm@60758
  2414
    using decseq_convergent[OF \<open>decseq g\<close>] by auto
wenzelm@61969
  2415
  moreover note LIMSEQ_unique[OF assms(4) tendsto_diff[OF \<open>f \<longlonglongrightarrow> u\<close> \<open>g \<longlonglongrightarrow> l\<close>]]
hoelzl@51529
  2416
  ultimately show ?thesis by auto
hoelzl@51529
  2417
qed
hoelzl@51529
  2418
hoelzl@51529
  2419
lemma Bolzano[consumes 1, case_names trans local]:
hoelzl@51529
  2420
  fixes P :: "real \<Rightarrow> real \<Rightarrow> bool"
hoelzl@51529
  2421
  assumes [arith]: "a \<le> b"
wenzelm@63546
  2422
    and trans: "\<And>a b c. P a b \<Longrightarrow> P b c \<Longrightarrow> a \<le> b \<Longrightarrow> b \<le> c \<Longrightarrow> P a c"
wenzelm@63546
  2423
    and local: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> \<exists>d>0. \<forall>a b. a \<le> x \<and> x \<le> b \<and> b - a < d \<longrightarrow> P a b"
hoelzl@51529
  2424
  shows "P a b"
hoelzl@51529
  2425
proof -
wenzelm@63040
  2426
  define bisect where "bisect =
wenzelm@63040
  2427
    rec_nat (a, b) (\<lambda>n (x, y). if P x ((x+y) / 2) then ((x+y)/2, y) else (x, (x+y)/2))"
wenzelm@63040
  2428
  define l u where "l n = fst (bisect n)" and "u n = snd (bisect n)" for n
hoelzl@51529
  2429
  have l[simp]: "l 0 = a" "\<And>n. l (Suc n) = (if P (l n) ((l n + u n) / 2) then (l n + u n) / 2 else l n)"
hoelzl@51529
  2430
    and u[simp]: "u 0 = b" "\<And>n. u (Suc n) = (if P (l n) ((l n + u n) / 2) then u n else (l n + u n) / 2)"
hoelzl@51529
  2431
    by (simp_all add: l_def u_def bisect_def split: prod.split)
hoelzl@51529
  2432
wenzelm@63546
  2433
  have [simp]: "l n \<le> u n" for n by (induct n) auto
hoelzl@51529
  2434
wenzelm@61969
  2435
  have "\<exists>x. ((\<forall>n. l n \<le> x) \<and> l \<longlonglongrightarrow> x) \<and> ((\<forall>n. x \<le> u n) \<and> u \<longlonglongrightarrow> x)"
hoelzl@51529
  2436
  proof (safe intro!: nested_sequence_unique)
wenzelm@63546
  2437
    show "l n \<le> l (Suc n)" "u (Suc n) \<le> u n" for n
wenzelm@63546
  2438
      by (induct n) auto
hoelzl@51529
  2439
  next
wenzelm@63546
  2440
    have "l n - u n = (a - b) / 2^n" for n
wenzelm@63546
  2441
      by (induct n) (auto simp: field_simps)
wenzelm@63546
  2442
    then show "(\<lambda>n. l n - u n) \<longlonglongrightarrow> 0"
wenzelm@63546
  2443
      by (simp add: LIMSEQ_divide_realpow_zero)
hoelzl@51529
  2444
  qed fact
wenzelm@63546
  2445
  then obtain x where x: "\<And>n. l n \<le> x" "\<And>n. x \<le> u n" and "l \<longlonglongrightarrow> x" "u \<longlonglongrightarrow> x"
wenzelm@63546
  2446
    by auto
wenzelm@63546
  2447
  obtain d where "0 < d" and d: "a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> b - a < d \<Longrightarrow> P a b" for a b
wenzelm@60758
  2448
    using \<open>l 0 \<le> x\<close> \<open>x \<le> u 0\<close> local[of x] by auto
hoelzl@51529
  2449
hoelzl@51529
  2450
  show "P a b"
hoelzl@51529
  2451
  proof (rule ccontr)
lp15@60141
  2452
    assume "\<not> P a b"
wenzelm@63546
  2453
    have "\<not> P (l n) (u n)" for n
wenzelm@63546
  2454
    proof (induct n)
wenzelm@63546
  2455
      case 0
wenzelm@63546
  2456
      then show ?case
wenzelm@63546
  2457
        by (simp add: \<open>\<not> P a b\<close>)
wenzelm@63546
  2458
    next
wenzelm@63546
  2459
      case (Suc n)
wenzelm@63546
  2460
      with trans[of "l n" "(l n + u n) / 2" "u n"] show ?case
wenzelm@63546
  2461
        by auto
wenzelm@63546
  2462
    qed
hoelzl@51529
  2463
    moreover
wenzelm@63546
  2464
    {
wenzelm@63546
  2465
      have "eventually (\<lambda>n. x - d / 2 < l n) sequentially"
wenzelm@61969
  2466
        using \<open>0 < d\<close> \<open>l \<longlonglongrightarrow> x\<close> by (intro order_tendstoD[of _ x]) auto
hoelzl@51529
  2467
      moreover have "eventually (\<lambda>n. u n < x + d / 2) sequentially"
wenzelm@61969
  2468
        using \<open>0 < d\<close> \<open>u \<longlonglongrightarrow> x\<close> by (intro order_tendstoD[of _ x]) auto
hoelzl@51529
  2469
      ultimately have "eventually (\<lambda>n. P (l n) (u n)) sequentially"
hoelzl@51529
  2470
      proof eventually_elim
wenzelm@63546
  2471
        case (elim n)
hoelzl@51529
  2472
        from add_strict_mono[OF this] have "u n - l n < d" by simp
hoelzl@51529
  2473
        with x show "P (l n) (u n)" by (rule d)
wenzelm@63546
  2474
      qed
wenzelm@63546
  2475
    }
hoelzl@51529
  2476
    ultimately show False by simp
hoelzl@51529
  2477
  qed
hoelzl@51529