src/HOL/Limits.thy
author hoelzl
Fri Mar 22 10:41:43 2013 +0100 (2013-03-22)
changeset 51474 1e9e68247ad1
parent 51472 adb441e4b9e9
child 51478 270b21f3ae0a
permissions -rw-r--r--
generalize Bfun and Bseq to metric spaces; Bseq is an abbreviation for Bfun
huffman@31349
     1
(*  Title       : Limits.thy
huffman@31349
     2
    Author      : Brian Huffman
huffman@31349
     3
*)
huffman@31349
     4
huffman@31349
     5
header {* Filters and Limits *}
huffman@31349
     6
huffman@31349
     7
theory Limits
huffman@36822
     8
imports RealVector
huffman@31349
     9
begin
huffman@31349
    10
hoelzl@50324
    11
definition at_infinity :: "'a::real_normed_vector filter" where
hoelzl@50324
    12
  "at_infinity = Abs_filter (\<lambda>P. \<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x)"
hoelzl@50324
    13
hoelzl@50324
    14
lemma eventually_at_infinity:
hoelzl@50325
    15
  "eventually P at_infinity \<longleftrightarrow> (\<exists>b. \<forall>x. b \<le> norm x \<longrightarrow> P x)"
hoelzl@50324
    16
unfolding at_infinity_def
hoelzl@50324
    17
proof (rule eventually_Abs_filter, rule is_filter.intro)
hoelzl@50324
    18
  fix P Q :: "'a \<Rightarrow> bool"
hoelzl@50324
    19
  assume "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x" and "\<exists>s. \<forall>x. s \<le> norm x \<longrightarrow> Q x"
hoelzl@50324
    20
  then obtain r s where
hoelzl@50324
    21
    "\<forall>x. r \<le> norm x \<longrightarrow> P x" and "\<forall>x. s \<le> norm x \<longrightarrow> Q x" by auto
hoelzl@50324
    22
  then have "\<forall>x. max r s \<le> norm x \<longrightarrow> P x \<and> Q x" by simp
hoelzl@50324
    23
  then show "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x \<and> Q x" ..
hoelzl@50324
    24
qed auto
huffman@31392
    25
hoelzl@50325
    26
lemma at_infinity_eq_at_top_bot:
hoelzl@50325
    27
  "(at_infinity \<Colon> real filter) = sup at_top at_bot"
hoelzl@50325
    28
  unfolding sup_filter_def at_infinity_def eventually_at_top_linorder eventually_at_bot_linorder
hoelzl@50325
    29
proof (intro arg_cong[where f=Abs_filter] ext iffI)
hoelzl@50325
    30
  fix P :: "real \<Rightarrow> bool" assume "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x"
hoelzl@50325
    31
  then guess r ..
hoelzl@50325
    32
  then have "(\<forall>x\<ge>r. P x) \<and> (\<forall>x\<le>-r. P x)" by auto
hoelzl@50325
    33
  then show "(\<exists>r. \<forall>x\<ge>r. P x) \<and> (\<exists>r. \<forall>x\<le>r. P x)" by auto
hoelzl@50325
    34
next
hoelzl@50325
    35
  fix P :: "real \<Rightarrow> bool" assume "(\<exists>r. \<forall>x\<ge>r. P x) \<and> (\<exists>r. \<forall>x\<le>r. P x)"
hoelzl@50325
    36
  then obtain p q where "\<forall>x\<ge>p. P x" "\<forall>x\<le>q. P x" by auto
hoelzl@50325
    37
  then show "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x"
hoelzl@50325
    38
    by (intro exI[of _ "max p (-q)"])
hoelzl@50325
    39
       (auto simp: abs_real_def)
hoelzl@50325
    40
qed
hoelzl@50325
    41
hoelzl@50325
    42
lemma at_top_le_at_infinity:
hoelzl@50325
    43
  "at_top \<le> (at_infinity :: real filter)"
hoelzl@50325
    44
  unfolding at_infinity_eq_at_top_bot by simp
hoelzl@50325
    45
hoelzl@50325
    46
lemma at_bot_le_at_infinity:
hoelzl@50325
    47
  "at_bot \<le> (at_infinity :: real filter)"
hoelzl@50325
    48
  unfolding at_infinity_eq_at_top_bot by simp
hoelzl@50325
    49
huffman@31355
    50
subsection {* Boundedness *}
huffman@31355
    51
hoelzl@51474
    52
lemma Bfun_def:
hoelzl@51474
    53
  "Bfun f F \<longleftrightarrow> (\<exists>K>0. eventually (\<lambda>x. norm (f x) \<le> K) F)"
hoelzl@51474
    54
  unfolding Bfun_metric_def norm_conv_dist
hoelzl@51474
    55
proof safe
hoelzl@51474
    56
  fix y K assume "0 < K" and *: "eventually (\<lambda>x. dist (f x) y \<le> K) F"
hoelzl@51474
    57
  moreover have "eventually (\<lambda>x. dist (f x) 0 \<le> dist (f x) y + dist 0 y) F"
hoelzl@51474
    58
    by (intro always_eventually) (metis dist_commute dist_triangle)
hoelzl@51474
    59
  with * have "eventually (\<lambda>x. dist (f x) 0 \<le> K + dist 0 y) F"
hoelzl@51474
    60
    by eventually_elim auto
hoelzl@51474
    61
  with `0 < K` show "\<exists>K>0. eventually (\<lambda>x. dist (f x) 0 \<le> K) F"
hoelzl@51474
    62
    by (intro exI[of _ "K + dist 0 y"] add_pos_nonneg conjI zero_le_dist) auto
hoelzl@51474
    63
qed auto
huffman@31355
    64
huffman@31487
    65
lemma BfunI:
huffman@44195
    66
  assumes K: "eventually (\<lambda>x. norm (f x) \<le> K) F" shows "Bfun f F"
huffman@31355
    67
unfolding Bfun_def
huffman@31355
    68
proof (intro exI conjI allI)
huffman@31355
    69
  show "0 < max K 1" by simp
huffman@31355
    70
next
huffman@44195
    71
  show "eventually (\<lambda>x. norm (f x) \<le> max K 1) F"
huffman@31355
    72
    using K by (rule eventually_elim1, simp)
huffman@31355
    73
qed
huffman@31355
    74
huffman@31355
    75
lemma BfunE:
huffman@44195
    76
  assumes "Bfun f F"
huffman@44195
    77
  obtains B where "0 < B" and "eventually (\<lambda>x. norm (f x) \<le> B) F"
huffman@31355
    78
using assms unfolding Bfun_def by fast
huffman@31355
    79
huffman@31349
    80
subsection {* Convergence to Zero *}
huffman@31349
    81
huffman@44081
    82
definition Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
    83
  where "Zfun f F = (\<forall>r>0. eventually (\<lambda>x. norm (f x) < r) F)"
huffman@31349
    84
huffman@31349
    85
lemma ZfunI:
huffman@44195
    86
  "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F) \<Longrightarrow> Zfun f F"
huffman@44081
    87
  unfolding Zfun_def by simp
huffman@31349
    88
huffman@31349
    89
lemma ZfunD:
huffman@44195
    90
  "\<lbrakk>Zfun f F; 0 < r\<rbrakk> \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F"
huffman@44081
    91
  unfolding Zfun_def by simp
huffman@31349
    92
huffman@31355
    93
lemma Zfun_ssubst:
huffman@44195
    94
  "eventually (\<lambda>x. f x = g x) F \<Longrightarrow> Zfun g F \<Longrightarrow> Zfun f F"
huffman@44081
    95
  unfolding Zfun_def by (auto elim!: eventually_rev_mp)
huffman@31355
    96
huffman@44195
    97
lemma Zfun_zero: "Zfun (\<lambda>x. 0) F"
huffman@44081
    98
  unfolding Zfun_def by simp
huffman@31349
    99
huffman@44195
   100
lemma Zfun_norm_iff: "Zfun (\<lambda>x. norm (f x)) F = Zfun (\<lambda>x. f x) F"
huffman@44081
   101
  unfolding Zfun_def by simp
huffman@31349
   102
huffman@31349
   103
lemma Zfun_imp_Zfun:
huffman@44195
   104
  assumes f: "Zfun f F"
huffman@44195
   105
  assumes g: "eventually (\<lambda>x. norm (g x) \<le> norm (f x) * K) F"
huffman@44195
   106
  shows "Zfun (\<lambda>x. g x) F"
huffman@31349
   107
proof (cases)
huffman@31349
   108
  assume K: "0 < K"
huffman@31349
   109
  show ?thesis
huffman@31349
   110
  proof (rule ZfunI)
huffman@31349
   111
    fix r::real assume "0 < r"
huffman@31349
   112
    hence "0 < r / K"
huffman@31349
   113
      using K by (rule divide_pos_pos)
huffman@44195
   114
    then have "eventually (\<lambda>x. norm (f x) < r / K) F"
huffman@31487
   115
      using ZfunD [OF f] by fast
huffman@44195
   116
    with g show "eventually (\<lambda>x. norm (g x) < r) F"
noschinl@46887
   117
    proof eventually_elim
noschinl@46887
   118
      case (elim x)
huffman@31487
   119
      hence "norm (f x) * K < r"
huffman@31349
   120
        by (simp add: pos_less_divide_eq K)
noschinl@46887
   121
      thus ?case
noschinl@46887
   122
        by (simp add: order_le_less_trans [OF elim(1)])
huffman@31349
   123
    qed
huffman@31349
   124
  qed
huffman@31349
   125
next
huffman@31349
   126
  assume "\<not> 0 < K"
huffman@31349
   127
  hence K: "K \<le> 0" by (simp only: not_less)
huffman@31355
   128
  show ?thesis
huffman@31355
   129
  proof (rule ZfunI)
huffman@31355
   130
    fix r :: real
huffman@31355
   131
    assume "0 < r"
huffman@44195
   132
    from g show "eventually (\<lambda>x. norm (g x) < r) F"
noschinl@46887
   133
    proof eventually_elim
noschinl@46887
   134
      case (elim x)
noschinl@46887
   135
      also have "norm (f x) * K \<le> norm (f x) * 0"
huffman@31355
   136
        using K norm_ge_zero by (rule mult_left_mono)
noschinl@46887
   137
      finally show ?case
huffman@31355
   138
        using `0 < r` by simp
huffman@31355
   139
    qed
huffman@31355
   140
  qed
huffman@31349
   141
qed
huffman@31349
   142
huffman@44195
   143
lemma Zfun_le: "\<lbrakk>Zfun g F; \<forall>x. norm (f x) \<le> norm (g x)\<rbrakk> \<Longrightarrow> Zfun f F"
huffman@44081
   144
  by (erule_tac K="1" in Zfun_imp_Zfun, simp)
huffman@31349
   145
huffman@31349
   146
lemma Zfun_add:
huffman@44195
   147
  assumes f: "Zfun f F" and g: "Zfun g F"
huffman@44195
   148
  shows "Zfun (\<lambda>x. f x + g x) F"
huffman@31349
   149
proof (rule ZfunI)
huffman@31349
   150
  fix r::real assume "0 < r"
huffman@31349
   151
  hence r: "0 < r / 2" by simp
huffman@44195
   152
  have "eventually (\<lambda>x. norm (f x) < r/2) F"
huffman@31487
   153
    using f r by (rule ZfunD)
huffman@31349
   154
  moreover
huffman@44195
   155
  have "eventually (\<lambda>x. norm (g x) < r/2) F"
huffman@31487
   156
    using g r by (rule ZfunD)
huffman@31349
   157
  ultimately
huffman@44195
   158
  show "eventually (\<lambda>x. norm (f x + g x) < r) F"
noschinl@46887
   159
  proof eventually_elim
noschinl@46887
   160
    case (elim x)
huffman@31487
   161
    have "norm (f x + g x) \<le> norm (f x) + norm (g x)"
huffman@31349
   162
      by (rule norm_triangle_ineq)
huffman@31349
   163
    also have "\<dots> < r/2 + r/2"
noschinl@46887
   164
      using elim by (rule add_strict_mono)
noschinl@46887
   165
    finally show ?case
huffman@31349
   166
      by simp
huffman@31349
   167
  qed
huffman@31349
   168
qed
huffman@31349
   169
huffman@44195
   170
lemma Zfun_minus: "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. - f x) F"
huffman@44081
   171
  unfolding Zfun_def by simp
huffman@31349
   172
huffman@44195
   173
lemma Zfun_diff: "\<lbrakk>Zfun f F; Zfun g F\<rbrakk> \<Longrightarrow> Zfun (\<lambda>x. f x - g x) F"
huffman@44081
   174
  by (simp only: diff_minus Zfun_add Zfun_minus)
huffman@31349
   175
huffman@31349
   176
lemma (in bounded_linear) Zfun:
huffman@44195
   177
  assumes g: "Zfun g F"
huffman@44195
   178
  shows "Zfun (\<lambda>x. f (g x)) F"
huffman@31349
   179
proof -
huffman@31349
   180
  obtain K where "\<And>x. norm (f x) \<le> norm x * K"
huffman@31349
   181
    using bounded by fast
huffman@44195
   182
  then have "eventually (\<lambda>x. norm (f (g x)) \<le> norm (g x) * K) F"
huffman@31355
   183
    by simp
huffman@31487
   184
  with g show ?thesis
huffman@31349
   185
    by (rule Zfun_imp_Zfun)
huffman@31349
   186
qed
huffman@31349
   187
huffman@31349
   188
lemma (in bounded_bilinear) Zfun:
huffman@44195
   189
  assumes f: "Zfun f F"
huffman@44195
   190
  assumes g: "Zfun g F"
huffman@44195
   191
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31349
   192
proof (rule ZfunI)
huffman@31349
   193
  fix r::real assume r: "0 < r"
huffman@31349
   194
  obtain K where K: "0 < K"
huffman@31349
   195
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31349
   196
    using pos_bounded by fast
huffman@31349
   197
  from K have K': "0 < inverse K"
huffman@31349
   198
    by (rule positive_imp_inverse_positive)
huffman@44195
   199
  have "eventually (\<lambda>x. norm (f x) < r) F"
huffman@31487
   200
    using f r by (rule ZfunD)
huffman@31349
   201
  moreover
huffman@44195
   202
  have "eventually (\<lambda>x. norm (g x) < inverse K) F"
huffman@31487
   203
    using g K' by (rule ZfunD)
huffman@31349
   204
  ultimately
huffman@44195
   205
  show "eventually (\<lambda>x. norm (f x ** g x) < r) F"
noschinl@46887
   206
  proof eventually_elim
noschinl@46887
   207
    case (elim x)
huffman@31487
   208
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31349
   209
      by (rule norm_le)
huffman@31487
   210
    also have "norm (f x) * norm (g x) * K < r * inverse K * K"
noschinl@46887
   211
      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero elim K)
huffman@31349
   212
    also from K have "r * inverse K * K = r"
huffman@31349
   213
      by simp
noschinl@46887
   214
    finally show ?case .
huffman@31349
   215
  qed
huffman@31349
   216
qed
huffman@31349
   217
huffman@31349
   218
lemma (in bounded_bilinear) Zfun_left:
huffman@44195
   219
  "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. f x ** a) F"
huffman@44081
   220
  by (rule bounded_linear_left [THEN bounded_linear.Zfun])
huffman@31349
   221
huffman@31349
   222
lemma (in bounded_bilinear) Zfun_right:
huffman@44195
   223
  "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. a ** f x) F"
huffman@44081
   224
  by (rule bounded_linear_right [THEN bounded_linear.Zfun])
huffman@31349
   225
huffman@44282
   226
lemmas Zfun_mult = bounded_bilinear.Zfun [OF bounded_bilinear_mult]
huffman@44282
   227
lemmas Zfun_mult_right = bounded_bilinear.Zfun_right [OF bounded_bilinear_mult]
huffman@44282
   228
lemmas Zfun_mult_left = bounded_bilinear.Zfun_left [OF bounded_bilinear_mult]
huffman@31349
   229
huffman@44195
   230
lemma tendsto_Zfun_iff: "(f ---> a) F = Zfun (\<lambda>x. f x - a) F"
huffman@44081
   231
  by (simp only: tendsto_iff Zfun_def dist_norm)
huffman@31349
   232
huffman@44205
   233
subsubsection {* Distance and norms *}
huffman@36662
   234
huffman@31565
   235
lemma tendsto_norm [tendsto_intros]:
huffman@44195
   236
  "(f ---> a) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> norm a) F"
huffman@44081
   237
  unfolding norm_conv_dist by (intro tendsto_intros)
huffman@36662
   238
huffman@36662
   239
lemma tendsto_norm_zero:
huffman@44195
   240
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> 0) F"
huffman@44081
   241
  by (drule tendsto_norm, simp)
huffman@36662
   242
huffman@36662
   243
lemma tendsto_norm_zero_cancel:
huffman@44195
   244
  "((\<lambda>x. norm (f x)) ---> 0) F \<Longrightarrow> (f ---> 0) F"
huffman@44081
   245
  unfolding tendsto_iff dist_norm by simp
huffman@36662
   246
huffman@36662
   247
lemma tendsto_norm_zero_iff:
huffman@44195
   248
  "((\<lambda>x. norm (f x)) ---> 0) F \<longleftrightarrow> (f ---> 0) F"
huffman@44081
   249
  unfolding tendsto_iff dist_norm by simp
huffman@31349
   250
huffman@44194
   251
lemma tendsto_rabs [tendsto_intros]:
huffman@44195
   252
  "(f ---> (l::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> \<bar>l\<bar>) F"
huffman@44194
   253
  by (fold real_norm_def, rule tendsto_norm)
huffman@44194
   254
huffman@44194
   255
lemma tendsto_rabs_zero:
huffman@44195
   256
  "(f ---> (0::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> 0) F"
huffman@44194
   257
  by (fold real_norm_def, rule tendsto_norm_zero)
huffman@44194
   258
huffman@44194
   259
lemma tendsto_rabs_zero_cancel:
huffman@44195
   260
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<Longrightarrow> (f ---> 0) F"
huffman@44194
   261
  by (fold real_norm_def, rule tendsto_norm_zero_cancel)
huffman@44194
   262
huffman@44194
   263
lemma tendsto_rabs_zero_iff:
huffman@44195
   264
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<longleftrightarrow> (f ---> 0) F"
huffman@44194
   265
  by (fold real_norm_def, rule tendsto_norm_zero_iff)
huffman@44194
   266
huffman@44194
   267
subsubsection {* Addition and subtraction *}
huffman@44194
   268
huffman@31565
   269
lemma tendsto_add [tendsto_intros]:
huffman@31349
   270
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   271
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> a + b) F"
huffman@44081
   272
  by (simp only: tendsto_Zfun_iff add_diff_add Zfun_add)
huffman@31349
   273
huffman@44194
   274
lemma tendsto_add_zero:
huffman@44194
   275
  fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
huffman@44195
   276
  shows "\<lbrakk>(f ---> 0) F; (g ---> 0) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> 0) F"
huffman@44194
   277
  by (drule (1) tendsto_add, simp)
huffman@44194
   278
huffman@31565
   279
lemma tendsto_minus [tendsto_intros]:
huffman@31349
   280
  fixes a :: "'a::real_normed_vector"
huffman@44195
   281
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. - f x) ---> - a) F"
huffman@44081
   282
  by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
huffman@31349
   283
huffman@31349
   284
lemma tendsto_minus_cancel:
huffman@31349
   285
  fixes a :: "'a::real_normed_vector"
huffman@44195
   286
  shows "((\<lambda>x. - f x) ---> - a) F \<Longrightarrow> (f ---> a) F"
huffman@44081
   287
  by (drule tendsto_minus, simp)
huffman@31349
   288
hoelzl@50330
   289
lemma tendsto_minus_cancel_left:
hoelzl@50330
   290
    "(f ---> - (y::_::real_normed_vector)) F \<longleftrightarrow> ((\<lambda>x. - f x) ---> y) F"
hoelzl@50330
   291
  using tendsto_minus_cancel[of f "- y" F]  tendsto_minus[of f "- y" F]
hoelzl@50330
   292
  by auto
hoelzl@50330
   293
huffman@31565
   294
lemma tendsto_diff [tendsto_intros]:
huffman@31349
   295
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   296
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x - g x) ---> a - b) F"
huffman@44081
   297
  by (simp add: diff_minus tendsto_add tendsto_minus)
huffman@31349
   298
huffman@31588
   299
lemma tendsto_setsum [tendsto_intros]:
huffman@31588
   300
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
huffman@44195
   301
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> a i) F"
huffman@44195
   302
  shows "((\<lambda>x. \<Sum>i\<in>S. f i x) ---> (\<Sum>i\<in>S. a i)) F"
huffman@31588
   303
proof (cases "finite S")
huffman@31588
   304
  assume "finite S" thus ?thesis using assms
huffman@44194
   305
    by (induct, simp add: tendsto_const, simp add: tendsto_add)
huffman@31588
   306
next
huffman@31588
   307
  assume "\<not> finite S" thus ?thesis
huffman@31588
   308
    by (simp add: tendsto_const)
huffman@31588
   309
qed
huffman@31588
   310
hoelzl@50999
   311
lemmas real_tendsto_sandwich = tendsto_sandwich[where 'b=real]
hoelzl@50999
   312
huffman@44194
   313
subsubsection {* Linear operators and multiplication *}
huffman@44194
   314
huffman@44282
   315
lemma (in bounded_linear) tendsto:
huffman@44195
   316
  "(g ---> a) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> f a) F"
huffman@44081
   317
  by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
huffman@31349
   318
huffman@44194
   319
lemma (in bounded_linear) tendsto_zero:
huffman@44195
   320
  "(g ---> 0) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> 0) F"
huffman@44194
   321
  by (drule tendsto, simp only: zero)
huffman@44194
   322
huffman@44282
   323
lemma (in bounded_bilinear) tendsto:
huffman@44195
   324
  "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ** g x) ---> a ** b) F"
huffman@44081
   325
  by (simp only: tendsto_Zfun_iff prod_diff_prod
huffman@44081
   326
                 Zfun_add Zfun Zfun_left Zfun_right)
huffman@31349
   327
huffman@44194
   328
lemma (in bounded_bilinear) tendsto_zero:
huffman@44195
   329
  assumes f: "(f ---> 0) F"
huffman@44195
   330
  assumes g: "(g ---> 0) F"
huffman@44195
   331
  shows "((\<lambda>x. f x ** g x) ---> 0) F"
huffman@44194
   332
  using tendsto [OF f g] by (simp add: zero_left)
huffman@31355
   333
huffman@44194
   334
lemma (in bounded_bilinear) tendsto_left_zero:
huffman@44195
   335
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. f x ** c) ---> 0) F"
huffman@44194
   336
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_left])
huffman@44194
   337
huffman@44194
   338
lemma (in bounded_bilinear) tendsto_right_zero:
huffman@44195
   339
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. c ** f x) ---> 0) F"
huffman@44194
   340
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_right])
huffman@44194
   341
huffman@44282
   342
lemmas tendsto_of_real [tendsto_intros] =
huffman@44282
   343
  bounded_linear.tendsto [OF bounded_linear_of_real]
huffman@44282
   344
huffman@44282
   345
lemmas tendsto_scaleR [tendsto_intros] =
huffman@44282
   346
  bounded_bilinear.tendsto [OF bounded_bilinear_scaleR]
huffman@44282
   347
huffman@44282
   348
lemmas tendsto_mult [tendsto_intros] =
huffman@44282
   349
  bounded_bilinear.tendsto [OF bounded_bilinear_mult]
huffman@44194
   350
huffman@44568
   351
lemmas tendsto_mult_zero =
huffman@44568
   352
  bounded_bilinear.tendsto_zero [OF bounded_bilinear_mult]
huffman@44568
   353
huffman@44568
   354
lemmas tendsto_mult_left_zero =
huffman@44568
   355
  bounded_bilinear.tendsto_left_zero [OF bounded_bilinear_mult]
huffman@44568
   356
huffman@44568
   357
lemmas tendsto_mult_right_zero =
huffman@44568
   358
  bounded_bilinear.tendsto_right_zero [OF bounded_bilinear_mult]
huffman@44568
   359
huffman@44194
   360
lemma tendsto_power [tendsto_intros]:
huffman@44194
   361
  fixes f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra}"
huffman@44195
   362
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. f x ^ n) ---> a ^ n) F"
huffman@44194
   363
  by (induct n) (simp_all add: tendsto_const tendsto_mult)
huffman@44194
   364
huffman@44194
   365
lemma tendsto_setprod [tendsto_intros]:
huffman@44194
   366
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
huffman@44195
   367
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> L i) F"
huffman@44195
   368
  shows "((\<lambda>x. \<Prod>i\<in>S. f i x) ---> (\<Prod>i\<in>S. L i)) F"
huffman@44194
   369
proof (cases "finite S")
huffman@44194
   370
  assume "finite S" thus ?thesis using assms
huffman@44194
   371
    by (induct, simp add: tendsto_const, simp add: tendsto_mult)
huffman@44194
   372
next
huffman@44194
   373
  assume "\<not> finite S" thus ?thesis
huffman@44194
   374
    by (simp add: tendsto_const)
huffman@44194
   375
qed
huffman@44194
   376
huffman@44194
   377
subsubsection {* Inverse and division *}
huffman@31355
   378
huffman@31355
   379
lemma (in bounded_bilinear) Zfun_prod_Bfun:
huffman@44195
   380
  assumes f: "Zfun f F"
huffman@44195
   381
  assumes g: "Bfun g F"
huffman@44195
   382
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31355
   383
proof -
huffman@31355
   384
  obtain K where K: "0 \<le> K"
huffman@31355
   385
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31355
   386
    using nonneg_bounded by fast
huffman@31355
   387
  obtain B where B: "0 < B"
huffman@44195
   388
    and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) F"
huffman@31487
   389
    using g by (rule BfunE)
huffman@44195
   390
  have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) F"
noschinl@46887
   391
  using norm_g proof eventually_elim
noschinl@46887
   392
    case (elim x)
huffman@31487
   393
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31355
   394
      by (rule norm_le)
huffman@31487
   395
    also have "\<dots> \<le> norm (f x) * B * K"
huffman@31487
   396
      by (intro mult_mono' order_refl norm_g norm_ge_zero
noschinl@46887
   397
                mult_nonneg_nonneg K elim)
huffman@31487
   398
    also have "\<dots> = norm (f x) * (B * K)"
huffman@31355
   399
      by (rule mult_assoc)
huffman@31487
   400
    finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
huffman@31355
   401
  qed
huffman@31487
   402
  with f show ?thesis
huffman@31487
   403
    by (rule Zfun_imp_Zfun)
huffman@31355
   404
qed
huffman@31355
   405
huffman@31355
   406
lemma (in bounded_bilinear) flip:
huffman@31355
   407
  "bounded_bilinear (\<lambda>x y. y ** x)"
huffman@44081
   408
  apply default
huffman@44081
   409
  apply (rule add_right)
huffman@44081
   410
  apply (rule add_left)
huffman@44081
   411
  apply (rule scaleR_right)
huffman@44081
   412
  apply (rule scaleR_left)
huffman@44081
   413
  apply (subst mult_commute)
huffman@44081
   414
  using bounded by fast
huffman@31355
   415
huffman@31355
   416
lemma (in bounded_bilinear) Bfun_prod_Zfun:
huffman@44195
   417
  assumes f: "Bfun f F"
huffman@44195
   418
  assumes g: "Zfun g F"
huffman@44195
   419
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@44081
   420
  using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
huffman@31355
   421
huffman@31355
   422
lemma Bfun_inverse_lemma:
huffman@31355
   423
  fixes x :: "'a::real_normed_div_algebra"
huffman@31355
   424
  shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
huffman@44081
   425
  apply (subst nonzero_norm_inverse, clarsimp)
huffman@44081
   426
  apply (erule (1) le_imp_inverse_le)
huffman@44081
   427
  done
huffman@31355
   428
huffman@31355
   429
lemma Bfun_inverse:
huffman@31355
   430
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
   431
  assumes f: "(f ---> a) F"
huffman@31355
   432
  assumes a: "a \<noteq> 0"
huffman@44195
   433
  shows "Bfun (\<lambda>x. inverse (f x)) F"
huffman@31355
   434
proof -
huffman@31355
   435
  from a have "0 < norm a" by simp
huffman@31355
   436
  hence "\<exists>r>0. r < norm a" by (rule dense)
huffman@31355
   437
  then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
huffman@44195
   438
  have "eventually (\<lambda>x. dist (f x) a < r) F"
huffman@31487
   439
    using tendstoD [OF f r1] by fast
huffman@44195
   440
  hence "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) F"
noschinl@46887
   441
  proof eventually_elim
noschinl@46887
   442
    case (elim x)
huffman@31487
   443
    hence 1: "norm (f x - a) < r"
huffman@31355
   444
      by (simp add: dist_norm)
huffman@31487
   445
    hence 2: "f x \<noteq> 0" using r2 by auto
huffman@31487
   446
    hence "norm (inverse (f x)) = inverse (norm (f x))"
huffman@31355
   447
      by (rule nonzero_norm_inverse)
huffman@31355
   448
    also have "\<dots> \<le> inverse (norm a - r)"
huffman@31355
   449
    proof (rule le_imp_inverse_le)
huffman@31355
   450
      show "0 < norm a - r" using r2 by simp
huffman@31355
   451
    next
huffman@31487
   452
      have "norm a - norm (f x) \<le> norm (a - f x)"
huffman@31355
   453
        by (rule norm_triangle_ineq2)
huffman@31487
   454
      also have "\<dots> = norm (f x - a)"
huffman@31355
   455
        by (rule norm_minus_commute)
huffman@31355
   456
      also have "\<dots> < r" using 1 .
huffman@31487
   457
      finally show "norm a - r \<le> norm (f x)" by simp
huffman@31355
   458
    qed
huffman@31487
   459
    finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
huffman@31355
   460
  qed
huffman@31355
   461
  thus ?thesis by (rule BfunI)
huffman@31355
   462
qed
huffman@31355
   463
huffman@31565
   464
lemma tendsto_inverse [tendsto_intros]:
huffman@31355
   465
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
   466
  assumes f: "(f ---> a) F"
huffman@31355
   467
  assumes a: "a \<noteq> 0"
huffman@44195
   468
  shows "((\<lambda>x. inverse (f x)) ---> inverse a) F"
huffman@31355
   469
proof -
huffman@31355
   470
  from a have "0 < norm a" by simp
huffman@44195
   471
  with f have "eventually (\<lambda>x. dist (f x) a < norm a) F"
huffman@31355
   472
    by (rule tendstoD)
huffman@44195
   473
  then have "eventually (\<lambda>x. f x \<noteq> 0) F"
huffman@31355
   474
    unfolding dist_norm by (auto elim!: eventually_elim1)
huffman@44627
   475
  with a have "eventually (\<lambda>x. inverse (f x) - inverse a =
huffman@44627
   476
    - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
   477
    by (auto elim!: eventually_elim1 simp: inverse_diff_inverse)
huffman@44627
   478
  moreover have "Zfun (\<lambda>x. - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
   479
    by (intro Zfun_minus Zfun_mult_left
huffman@44627
   480
      bounded_bilinear.Bfun_prod_Zfun [OF bounded_bilinear_mult]
huffman@44627
   481
      Bfun_inverse [OF f a] f [unfolded tendsto_Zfun_iff])
huffman@44627
   482
  ultimately show ?thesis
huffman@44627
   483
    unfolding tendsto_Zfun_iff by (rule Zfun_ssubst)
huffman@31355
   484
qed
huffman@31355
   485
huffman@31565
   486
lemma tendsto_divide [tendsto_intros]:
huffman@31355
   487
  fixes a b :: "'a::real_normed_field"
huffman@44195
   488
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F; b \<noteq> 0\<rbrakk>
huffman@44195
   489
    \<Longrightarrow> ((\<lambda>x. f x / g x) ---> a / b) F"
huffman@44282
   490
  by (simp add: tendsto_mult tendsto_inverse divide_inverse)
huffman@31355
   491
huffman@44194
   492
lemma tendsto_sgn [tendsto_intros]:
huffman@44194
   493
  fixes l :: "'a::real_normed_vector"
huffman@44195
   494
  shows "\<lbrakk>(f ---> l) F; l \<noteq> 0\<rbrakk> \<Longrightarrow> ((\<lambda>x. sgn (f x)) ---> sgn l) F"
huffman@44194
   495
  unfolding sgn_div_norm by (simp add: tendsto_intros)
huffman@44194
   496
hoelzl@50325
   497
lemma filterlim_at_infinity:
hoelzl@50325
   498
  fixes f :: "_ \<Rightarrow> 'a\<Colon>real_normed_vector"
hoelzl@50325
   499
  assumes "0 \<le> c"
hoelzl@50325
   500
  shows "(LIM x F. f x :> at_infinity) \<longleftrightarrow> (\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F)"
hoelzl@50325
   501
  unfolding filterlim_iff eventually_at_infinity
hoelzl@50325
   502
proof safe
hoelzl@50325
   503
  fix P :: "'a \<Rightarrow> bool" and b
hoelzl@50325
   504
  assume *: "\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F"
hoelzl@50325
   505
    and P: "\<forall>x. b \<le> norm x \<longrightarrow> P x"
hoelzl@50325
   506
  have "max b (c + 1) > c" by auto
hoelzl@50325
   507
  with * have "eventually (\<lambda>x. max b (c + 1) \<le> norm (f x)) F"
hoelzl@50325
   508
    by auto
hoelzl@50325
   509
  then show "eventually (\<lambda>x. P (f x)) F"
hoelzl@50325
   510
  proof eventually_elim
hoelzl@50325
   511
    fix x assume "max b (c + 1) \<le> norm (f x)"
hoelzl@50325
   512
    with P show "P (f x)" by auto
hoelzl@50325
   513
  qed
hoelzl@50325
   514
qed force
hoelzl@50325
   515
hoelzl@50347
   516
subsection {* Relate @{const at}, @{const at_left} and @{const at_right} *}
hoelzl@50347
   517
hoelzl@50347
   518
text {*
hoelzl@50347
   519
hoelzl@50347
   520
This lemmas are useful for conversion between @{term "at x"} to @{term "at_left x"} and
hoelzl@50347
   521
@{term "at_right x"} and also @{term "at_right 0"}.
hoelzl@50347
   522
hoelzl@50347
   523
*}
hoelzl@50347
   524
hoelzl@51471
   525
lemmas filterlim_split_at_real = filterlim_split_at[where 'a=real]
hoelzl@50323
   526
hoelzl@50347
   527
lemma filtermap_nhds_shift: "filtermap (\<lambda>x. x - d) (nhds a) = nhds (a - d::real)"
hoelzl@50347
   528
  unfolding filter_eq_iff eventually_filtermap eventually_nhds_metric
hoelzl@50347
   529
  by (intro allI ex_cong) (auto simp: dist_real_def field_simps)
hoelzl@50347
   530
hoelzl@50347
   531
lemma filtermap_nhds_minus: "filtermap (\<lambda>x. - x) (nhds a) = nhds (- a::real)"
hoelzl@50347
   532
  unfolding filter_eq_iff eventually_filtermap eventually_nhds_metric
hoelzl@50347
   533
  apply (intro allI ex_cong)
hoelzl@50347
   534
  apply (auto simp: dist_real_def field_simps)
hoelzl@50347
   535
  apply (erule_tac x="-x" in allE)
hoelzl@50347
   536
  apply simp
hoelzl@50347
   537
  done
hoelzl@50347
   538
hoelzl@50347
   539
lemma filtermap_at_shift: "filtermap (\<lambda>x. x - d) (at a) = at (a - d::real)"
hoelzl@50347
   540
  unfolding at_def filtermap_nhds_shift[symmetric]
hoelzl@50347
   541
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50347
   542
hoelzl@50347
   543
lemma filtermap_at_right_shift: "filtermap (\<lambda>x. x - d) (at_right a) = at_right (a - d::real)"
hoelzl@50347
   544
  unfolding filtermap_at_shift[symmetric]
hoelzl@50347
   545
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50323
   546
hoelzl@50347
   547
lemma at_right_to_0: "at_right (a::real) = filtermap (\<lambda>x. x + a) (at_right 0)"
hoelzl@50347
   548
  using filtermap_at_right_shift[of "-a" 0] by simp
hoelzl@50347
   549
hoelzl@50347
   550
lemma filterlim_at_right_to_0:
hoelzl@50347
   551
  "filterlim f F (at_right (a::real)) \<longleftrightarrow> filterlim (\<lambda>x. f (x + a)) F (at_right 0)"
hoelzl@50347
   552
  unfolding filterlim_def filtermap_filtermap at_right_to_0[of a] ..
hoelzl@50347
   553
hoelzl@50347
   554
lemma eventually_at_right_to_0:
hoelzl@50347
   555
  "eventually P (at_right (a::real)) \<longleftrightarrow> eventually (\<lambda>x. P (x + a)) (at_right 0)"
hoelzl@50347
   556
  unfolding at_right_to_0[of a] by (simp add: eventually_filtermap)
hoelzl@50347
   557
hoelzl@50347
   558
lemma filtermap_at_minus: "filtermap (\<lambda>x. - x) (at a) = at (- a::real)"
hoelzl@50347
   559
  unfolding at_def filtermap_nhds_minus[symmetric]
hoelzl@50347
   560
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50347
   561
hoelzl@50347
   562
lemma at_left_minus: "at_left (a::real) = filtermap (\<lambda>x. - x) (at_right (- a))"
hoelzl@50347
   563
  by (simp add: filter_eq_iff eventually_filtermap eventually_within filtermap_at_minus[symmetric])
hoelzl@50323
   564
hoelzl@50347
   565
lemma at_right_minus: "at_right (a::real) = filtermap (\<lambda>x. - x) (at_left (- a))"
hoelzl@50347
   566
  by (simp add: filter_eq_iff eventually_filtermap eventually_within filtermap_at_minus[symmetric])
hoelzl@50347
   567
hoelzl@50347
   568
lemma filterlim_at_left_to_right:
hoelzl@50347
   569
  "filterlim f F (at_left (a::real)) \<longleftrightarrow> filterlim (\<lambda>x. f (- x)) F (at_right (-a))"
hoelzl@50347
   570
  unfolding filterlim_def filtermap_filtermap at_left_minus[of a] ..
hoelzl@50347
   571
hoelzl@50347
   572
lemma eventually_at_left_to_right:
hoelzl@50347
   573
  "eventually P (at_left (a::real)) \<longleftrightarrow> eventually (\<lambda>x. P (- x)) (at_right (-a))"
hoelzl@50347
   574
  unfolding at_left_minus[of a] by (simp add: eventually_filtermap)
hoelzl@50347
   575
hoelzl@50346
   576
lemma at_top_mirror: "at_top = filtermap uminus (at_bot :: real filter)"
hoelzl@50346
   577
  unfolding filter_eq_iff eventually_filtermap eventually_at_top_linorder eventually_at_bot_linorder
hoelzl@50346
   578
  by (metis le_minus_iff minus_minus)
hoelzl@50346
   579
hoelzl@50346
   580
lemma at_bot_mirror: "at_bot = filtermap uminus (at_top :: real filter)"
hoelzl@50346
   581
  unfolding at_top_mirror filtermap_filtermap by (simp add: filtermap_ident)
hoelzl@50346
   582
hoelzl@50346
   583
lemma filterlim_at_top_mirror: "(LIM x at_top. f x :> F) \<longleftrightarrow> (LIM x at_bot. f (-x::real) :> F)"
hoelzl@50346
   584
  unfolding filterlim_def at_top_mirror filtermap_filtermap ..
hoelzl@50346
   585
hoelzl@50346
   586
lemma filterlim_at_bot_mirror: "(LIM x at_bot. f x :> F) \<longleftrightarrow> (LIM x at_top. f (-x::real) :> F)"
hoelzl@50346
   587
  unfolding filterlim_def at_bot_mirror filtermap_filtermap ..
hoelzl@50346
   588
hoelzl@50323
   589
lemma filterlim_uminus_at_top_at_bot: "LIM x at_bot. - x :: real :> at_top"
hoelzl@50323
   590
  unfolding filterlim_at_top eventually_at_bot_dense
hoelzl@50346
   591
  by (metis leI minus_less_iff order_less_asym)
hoelzl@50323
   592
hoelzl@50323
   593
lemma filterlim_uminus_at_bot_at_top: "LIM x at_top. - x :: real :> at_bot"
hoelzl@50323
   594
  unfolding filterlim_at_bot eventually_at_top_dense
hoelzl@50346
   595
  by (metis leI less_minus_iff order_less_asym)
hoelzl@50323
   596
hoelzl@50346
   597
lemma filterlim_uminus_at_top: "(LIM x F. f x :> at_top) \<longleftrightarrow> (LIM x F. - (f x) :: real :> at_bot)"
hoelzl@50346
   598
  using filterlim_compose[OF filterlim_uminus_at_bot_at_top, of f F]
hoelzl@50346
   599
  using filterlim_compose[OF filterlim_uminus_at_top_at_bot, of "\<lambda>x. - f x" F]
hoelzl@50346
   600
  by auto
hoelzl@50346
   601
hoelzl@50346
   602
lemma filterlim_uminus_at_bot: "(LIM x F. f x :> at_bot) \<longleftrightarrow> (LIM x F. - (f x) :: real :> at_top)"
hoelzl@50346
   603
  unfolding filterlim_uminus_at_top by simp
hoelzl@50323
   604
hoelzl@50347
   605
lemma filterlim_inverse_at_top_right: "LIM x at_right (0::real). inverse x :> at_top"
hoelzl@50347
   606
  unfolding filterlim_at_top_gt[where c=0] eventually_within at_def
hoelzl@50347
   607
proof safe
hoelzl@50347
   608
  fix Z :: real assume [arith]: "0 < Z"
hoelzl@50347
   609
  then have "eventually (\<lambda>x. x < inverse Z) (nhds 0)"
hoelzl@50347
   610
    by (auto simp add: eventually_nhds_metric dist_real_def intro!: exI[of _ "\<bar>inverse Z\<bar>"])
hoelzl@50347
   611
  then show "eventually (\<lambda>x. x \<in> - {0} \<longrightarrow> x \<in> {0<..} \<longrightarrow> Z \<le> inverse x) (nhds 0)"
hoelzl@50347
   612
    by (auto elim!: eventually_elim1 simp: inverse_eq_divide field_simps)
hoelzl@50347
   613
qed
hoelzl@50347
   614
hoelzl@50347
   615
lemma filterlim_inverse_at_top:
hoelzl@50347
   616
  "(f ---> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. 0 < f x) F \<Longrightarrow> LIM x F. inverse (f x) :> at_top"
hoelzl@50347
   617
  by (intro filterlim_compose[OF filterlim_inverse_at_top_right])
hoelzl@50347
   618
     (simp add: filterlim_def eventually_filtermap le_within_iff at_def eventually_elim1)
hoelzl@50347
   619
hoelzl@50347
   620
lemma filterlim_inverse_at_bot_neg:
hoelzl@50347
   621
  "LIM x (at_left (0::real)). inverse x :> at_bot"
hoelzl@50347
   622
  by (simp add: filterlim_inverse_at_top_right filterlim_uminus_at_bot filterlim_at_left_to_right)
hoelzl@50347
   623
hoelzl@50347
   624
lemma filterlim_inverse_at_bot:
hoelzl@50347
   625
  "(f ---> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. f x < 0) F \<Longrightarrow> LIM x F. inverse (f x) :> at_bot"
hoelzl@50347
   626
  unfolding filterlim_uminus_at_bot inverse_minus_eq[symmetric]
hoelzl@50347
   627
  by (rule filterlim_inverse_at_top) (simp_all add: tendsto_minus_cancel_left[symmetric])
hoelzl@50347
   628
hoelzl@50325
   629
lemma tendsto_inverse_0:
hoelzl@50325
   630
  fixes x :: "_ \<Rightarrow> 'a\<Colon>real_normed_div_algebra"
hoelzl@50325
   631
  shows "(inverse ---> (0::'a)) at_infinity"
hoelzl@50325
   632
  unfolding tendsto_Zfun_iff diff_0_right Zfun_def eventually_at_infinity
hoelzl@50325
   633
proof safe
hoelzl@50325
   634
  fix r :: real assume "0 < r"
hoelzl@50325
   635
  show "\<exists>b. \<forall>x. b \<le> norm x \<longrightarrow> norm (inverse x :: 'a) < r"
hoelzl@50325
   636
  proof (intro exI[of _ "inverse (r / 2)"] allI impI)
hoelzl@50325
   637
    fix x :: 'a
hoelzl@50325
   638
    from `0 < r` have "0 < inverse (r / 2)" by simp
hoelzl@50325
   639
    also assume *: "inverse (r / 2) \<le> norm x"
hoelzl@50325
   640
    finally show "norm (inverse x) < r"
hoelzl@50325
   641
      using * `0 < r` by (subst nonzero_norm_inverse) (simp_all add: inverse_eq_divide field_simps)
hoelzl@50325
   642
  qed
hoelzl@50325
   643
qed
hoelzl@50325
   644
hoelzl@50347
   645
lemma at_right_to_top: "(at_right (0::real)) = filtermap inverse at_top"
hoelzl@50347
   646
proof (rule antisym)
hoelzl@50347
   647
  have "(inverse ---> (0::real)) at_top"
hoelzl@50347
   648
    by (metis tendsto_inverse_0 filterlim_mono at_top_le_at_infinity order_refl)
hoelzl@50347
   649
  then show "filtermap inverse at_top \<le> at_right (0::real)"
hoelzl@50347
   650
    unfolding at_within_eq
hoelzl@50347
   651
    by (intro le_withinI) (simp_all add: eventually_filtermap eventually_gt_at_top filterlim_def)
hoelzl@50347
   652
next
hoelzl@50347
   653
  have "filtermap inverse (filtermap inverse (at_right (0::real))) \<le> filtermap inverse at_top"
hoelzl@50347
   654
    using filterlim_inverse_at_top_right unfolding filterlim_def by (rule filtermap_mono)
hoelzl@50347
   655
  then show "at_right (0::real) \<le> filtermap inverse at_top"
hoelzl@50347
   656
    by (simp add: filtermap_ident filtermap_filtermap)
hoelzl@50347
   657
qed
hoelzl@50347
   658
hoelzl@50347
   659
lemma eventually_at_right_to_top:
hoelzl@50347
   660
  "eventually P (at_right (0::real)) \<longleftrightarrow> eventually (\<lambda>x. P (inverse x)) at_top"
hoelzl@50347
   661
  unfolding at_right_to_top eventually_filtermap ..
hoelzl@50347
   662
hoelzl@50347
   663
lemma filterlim_at_right_to_top:
hoelzl@50347
   664
  "filterlim f F (at_right (0::real)) \<longleftrightarrow> (LIM x at_top. f (inverse x) :> F)"
hoelzl@50347
   665
  unfolding filterlim_def at_right_to_top filtermap_filtermap ..
hoelzl@50347
   666
hoelzl@50347
   667
lemma at_top_to_right: "at_top = filtermap inverse (at_right (0::real))"
hoelzl@50347
   668
  unfolding at_right_to_top filtermap_filtermap inverse_inverse_eq filtermap_ident ..
hoelzl@50347
   669
hoelzl@50347
   670
lemma eventually_at_top_to_right:
hoelzl@50347
   671
  "eventually P at_top \<longleftrightarrow> eventually (\<lambda>x. P (inverse x)) (at_right (0::real))"
hoelzl@50347
   672
  unfolding at_top_to_right eventually_filtermap ..
hoelzl@50347
   673
hoelzl@50347
   674
lemma filterlim_at_top_to_right:
hoelzl@50347
   675
  "filterlim f F at_top \<longleftrightarrow> (LIM x (at_right (0::real)). f (inverse x) :> F)"
hoelzl@50347
   676
  unfolding filterlim_def at_top_to_right filtermap_filtermap ..
hoelzl@50347
   677
hoelzl@50325
   678
lemma filterlim_inverse_at_infinity:
hoelzl@50325
   679
  fixes x :: "_ \<Rightarrow> 'a\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50325
   680
  shows "filterlim inverse at_infinity (at (0::'a))"
hoelzl@50325
   681
  unfolding filterlim_at_infinity[OF order_refl]
hoelzl@50325
   682
proof safe
hoelzl@50325
   683
  fix r :: real assume "0 < r"
hoelzl@50325
   684
  then show "eventually (\<lambda>x::'a. r \<le> norm (inverse x)) (at 0)"
hoelzl@50325
   685
    unfolding eventually_at norm_inverse
hoelzl@50325
   686
    by (intro exI[of _ "inverse r"])
hoelzl@50325
   687
       (auto simp: norm_conv_dist[symmetric] field_simps inverse_eq_divide)
hoelzl@50325
   688
qed
hoelzl@50325
   689
hoelzl@50325
   690
lemma filterlim_inverse_at_iff:
hoelzl@50325
   691
  fixes g :: "'a \<Rightarrow> 'b\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50325
   692
  shows "(LIM x F. inverse (g x) :> at 0) \<longleftrightarrow> (LIM x F. g x :> at_infinity)"
hoelzl@50325
   693
  unfolding filterlim_def filtermap_filtermap[symmetric]
hoelzl@50325
   694
proof
hoelzl@50325
   695
  assume "filtermap g F \<le> at_infinity"
hoelzl@50325
   696
  then have "filtermap inverse (filtermap g F) \<le> filtermap inverse at_infinity"
hoelzl@50325
   697
    by (rule filtermap_mono)
hoelzl@50325
   698
  also have "\<dots> \<le> at 0"
hoelzl@50325
   699
    using tendsto_inverse_0
hoelzl@50325
   700
    by (auto intro!: le_withinI exI[of _ 1]
hoelzl@50325
   701
             simp: eventually_filtermap eventually_at_infinity filterlim_def at_def)
hoelzl@50325
   702
  finally show "filtermap inverse (filtermap g F) \<le> at 0" .
hoelzl@50325
   703
next
hoelzl@50325
   704
  assume "filtermap inverse (filtermap g F) \<le> at 0"
hoelzl@50325
   705
  then have "filtermap inverse (filtermap inverse (filtermap g F)) \<le> filtermap inverse (at 0)"
hoelzl@50325
   706
    by (rule filtermap_mono)
hoelzl@50325
   707
  with filterlim_inverse_at_infinity show "filtermap g F \<le> at_infinity"
hoelzl@50325
   708
    by (auto intro: order_trans simp: filterlim_def filtermap_filtermap)
hoelzl@50325
   709
qed
hoelzl@50325
   710
hoelzl@50419
   711
lemma tendsto_inverse_0_at_top:
hoelzl@50419
   712
  "LIM x F. f x :> at_top \<Longrightarrow> ((\<lambda>x. inverse (f x) :: real) ---> 0) F"
hoelzl@50419
   713
 by (metis at_top_le_at_infinity filterlim_at filterlim_inverse_at_iff filterlim_mono order_refl)
hoelzl@50419
   714
hoelzl@50324
   715
text {*
hoelzl@50324
   716
hoelzl@50324
   717
We only show rules for multiplication and addition when the functions are either against a real
hoelzl@50324
   718
value or against infinity. Further rules are easy to derive by using @{thm filterlim_uminus_at_top}.
hoelzl@50324
   719
hoelzl@50324
   720
*}
hoelzl@50324
   721
hoelzl@50324
   722
lemma filterlim_tendsto_pos_mult_at_top: 
hoelzl@50324
   723
  assumes f: "(f ---> c) F" and c: "0 < c"
hoelzl@50324
   724
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
   725
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
   726
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
   727
proof safe
hoelzl@50324
   728
  fix Z :: real assume "0 < Z"
hoelzl@50324
   729
  from f `0 < c` have "eventually (\<lambda>x. c / 2 < f x) F"
hoelzl@50324
   730
    by (auto dest!: tendstoD[where e="c / 2"] elim!: eventually_elim1
hoelzl@50324
   731
             simp: dist_real_def abs_real_def split: split_if_asm)
hoelzl@50346
   732
  moreover from g have "eventually (\<lambda>x. (Z / c * 2) \<le> g x) F"
hoelzl@50324
   733
    unfolding filterlim_at_top by auto
hoelzl@50346
   734
  ultimately show "eventually (\<lambda>x. Z \<le> f x * g x) F"
hoelzl@50324
   735
  proof eventually_elim
hoelzl@50346
   736
    fix x assume "c / 2 < f x" "Z / c * 2 \<le> g x"
hoelzl@50346
   737
    with `0 < Z` `0 < c` have "c / 2 * (Z / c * 2) \<le> f x * g x"
hoelzl@50346
   738
      by (intro mult_mono) (auto simp: zero_le_divide_iff)
hoelzl@50346
   739
    with `0 < c` show "Z \<le> f x * g x"
hoelzl@50324
   740
       by simp
hoelzl@50324
   741
  qed
hoelzl@50324
   742
qed
hoelzl@50324
   743
hoelzl@50324
   744
lemma filterlim_at_top_mult_at_top: 
hoelzl@50324
   745
  assumes f: "LIM x F. f x :> at_top"
hoelzl@50324
   746
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
   747
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
   748
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
   749
proof safe
hoelzl@50324
   750
  fix Z :: real assume "0 < Z"
hoelzl@50346
   751
  from f have "eventually (\<lambda>x. 1 \<le> f x) F"
hoelzl@50324
   752
    unfolding filterlim_at_top by auto
hoelzl@50346
   753
  moreover from g have "eventually (\<lambda>x. Z \<le> g x) F"
hoelzl@50324
   754
    unfolding filterlim_at_top by auto
hoelzl@50346
   755
  ultimately show "eventually (\<lambda>x. Z \<le> f x * g x) F"
hoelzl@50324
   756
  proof eventually_elim
hoelzl@50346
   757
    fix x assume "1 \<le> f x" "Z \<le> g x"
hoelzl@50346
   758
    with `0 < Z` have "1 * Z \<le> f x * g x"
hoelzl@50346
   759
      by (intro mult_mono) (auto simp: zero_le_divide_iff)
hoelzl@50346
   760
    then show "Z \<le> f x * g x"
hoelzl@50324
   761
       by simp
hoelzl@50324
   762
  qed
hoelzl@50324
   763
qed
hoelzl@50324
   764
hoelzl@50419
   765
lemma filterlim_tendsto_pos_mult_at_bot:
hoelzl@50419
   766
  assumes "(f ---> c) F" "0 < (c::real)" "filterlim g at_bot F"
hoelzl@50419
   767
  shows "LIM x F. f x * g x :> at_bot"
hoelzl@50419
   768
  using filterlim_tendsto_pos_mult_at_top[OF assms(1,2), of "\<lambda>x. - g x"] assms(3)
hoelzl@50419
   769
  unfolding filterlim_uminus_at_bot by simp
hoelzl@50419
   770
hoelzl@50324
   771
lemma filterlim_tendsto_add_at_top: 
hoelzl@50324
   772
  assumes f: "(f ---> c) F"
hoelzl@50324
   773
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
   774
  shows "LIM x F. (f x + g x :: real) :> at_top"
hoelzl@50324
   775
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
   776
proof safe
hoelzl@50324
   777
  fix Z :: real assume "0 < Z"
hoelzl@50324
   778
  from f have "eventually (\<lambda>x. c - 1 < f x) F"
hoelzl@50324
   779
    by (auto dest!: tendstoD[where e=1] elim!: eventually_elim1 simp: dist_real_def)
hoelzl@50346
   780
  moreover from g have "eventually (\<lambda>x. Z - (c - 1) \<le> g x) F"
hoelzl@50324
   781
    unfolding filterlim_at_top by auto
hoelzl@50346
   782
  ultimately show "eventually (\<lambda>x. Z \<le> f x + g x) F"
hoelzl@50324
   783
    by eventually_elim simp
hoelzl@50324
   784
qed
hoelzl@50324
   785
hoelzl@50347
   786
lemma LIM_at_top_divide:
hoelzl@50347
   787
  fixes f g :: "'a \<Rightarrow> real"
hoelzl@50347
   788
  assumes f: "(f ---> a) F" "0 < a"
hoelzl@50347
   789
  assumes g: "(g ---> 0) F" "eventually (\<lambda>x. 0 < g x) F"
hoelzl@50347
   790
  shows "LIM x F. f x / g x :> at_top"
hoelzl@50347
   791
  unfolding divide_inverse
hoelzl@50347
   792
  by (rule filterlim_tendsto_pos_mult_at_top[OF f]) (rule filterlim_inverse_at_top[OF g])
hoelzl@50347
   793
hoelzl@50324
   794
lemma filterlim_at_top_add_at_top: 
hoelzl@50324
   795
  assumes f: "LIM x F. f x :> at_top"
hoelzl@50324
   796
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
   797
  shows "LIM x F. (f x + g x :: real) :> at_top"
hoelzl@50324
   798
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
   799
proof safe
hoelzl@50324
   800
  fix Z :: real assume "0 < Z"
hoelzl@50346
   801
  from f have "eventually (\<lambda>x. 0 \<le> f x) F"
hoelzl@50324
   802
    unfolding filterlim_at_top by auto
hoelzl@50346
   803
  moreover from g have "eventually (\<lambda>x. Z \<le> g x) F"
hoelzl@50324
   804
    unfolding filterlim_at_top by auto
hoelzl@50346
   805
  ultimately show "eventually (\<lambda>x. Z \<le> f x + g x) F"
hoelzl@50324
   806
    by eventually_elim simp
hoelzl@50324
   807
qed
hoelzl@50324
   808
hoelzl@50331
   809
lemma tendsto_divide_0:
hoelzl@50331
   810
  fixes f :: "_ \<Rightarrow> 'a\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50331
   811
  assumes f: "(f ---> c) F"
hoelzl@50331
   812
  assumes g: "LIM x F. g x :> at_infinity"
hoelzl@50331
   813
  shows "((\<lambda>x. f x / g x) ---> 0) F"
hoelzl@50331
   814
  using tendsto_mult[OF f filterlim_compose[OF tendsto_inverse_0 g]] by (simp add: divide_inverse)
hoelzl@50331
   815
hoelzl@50331
   816
lemma linear_plus_1_le_power:
hoelzl@50331
   817
  fixes x :: real
hoelzl@50331
   818
  assumes x: "0 \<le> x"
hoelzl@50331
   819
  shows "real n * x + 1 \<le> (x + 1) ^ n"
hoelzl@50331
   820
proof (induct n)
hoelzl@50331
   821
  case (Suc n)
hoelzl@50331
   822
  have "real (Suc n) * x + 1 \<le> (x + 1) * (real n * x + 1)"
hoelzl@50331
   823
    by (simp add: field_simps real_of_nat_Suc mult_nonneg_nonneg x)
hoelzl@50331
   824
  also have "\<dots> \<le> (x + 1)^Suc n"
hoelzl@50331
   825
    using Suc x by (simp add: mult_left_mono)
hoelzl@50331
   826
  finally show ?case .
hoelzl@50331
   827
qed simp
hoelzl@50331
   828
hoelzl@50331
   829
lemma filterlim_realpow_sequentially_gt1:
hoelzl@50331
   830
  fixes x :: "'a :: real_normed_div_algebra"
hoelzl@50331
   831
  assumes x[arith]: "1 < norm x"
hoelzl@50331
   832
  shows "LIM n sequentially. x ^ n :> at_infinity"
hoelzl@50331
   833
proof (intro filterlim_at_infinity[THEN iffD2] allI impI)
hoelzl@50331
   834
  fix y :: real assume "0 < y"
hoelzl@50331
   835
  have "0 < norm x - 1" by simp
hoelzl@50331
   836
  then obtain N::nat where "y < real N * (norm x - 1)" by (blast dest: reals_Archimedean3)
hoelzl@50331
   837
  also have "\<dots> \<le> real N * (norm x - 1) + 1" by simp
hoelzl@50331
   838
  also have "\<dots> \<le> (norm x - 1 + 1) ^ N" by (rule linear_plus_1_le_power) simp
hoelzl@50331
   839
  also have "\<dots> = norm x ^ N" by simp
hoelzl@50331
   840
  finally have "\<forall>n\<ge>N. y \<le> norm x ^ n"
hoelzl@50331
   841
    by (metis order_less_le_trans power_increasing order_less_imp_le x)
hoelzl@50331
   842
  then show "eventually (\<lambda>n. y \<le> norm (x ^ n)) sequentially"
hoelzl@50331
   843
    unfolding eventually_sequentially
hoelzl@50331
   844
    by (auto simp: norm_power)
hoelzl@50331
   845
qed simp
hoelzl@50331
   846
hoelzl@51471
   847
hoelzl@51471
   848
(* Unfortunately eventually_within was overwritten by Multivariate_Analysis.
hoelzl@51471
   849
   Hence it was references as Limits.within, but now it is Basic_Topology.eventually_within *)
hoelzl@51471
   850
lemmas eventually_within = eventually_within
hoelzl@51471
   851
huffman@31349
   852
end
hoelzl@50324
   853