src/HOL/Limits.thy
author hoelzl
Tue Mar 26 12:20:57 2013 +0100 (2013-03-26)
changeset 51524 7cb5ac44ca9e
parent 51478 270b21f3ae0a
child 51526 155263089e7b
permissions -rw-r--r--
rename RealVector.thy to Real_Vector_Spaces.thy
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
hoelzl@51524
     8
imports Real_Vector_Spaces
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
hoelzl@51478
   239
lemma continuous_norm [continuous_intros]:
hoelzl@51478
   240
  "continuous F f \<Longrightarrow> continuous F (\<lambda>x. norm (f x))"
hoelzl@51478
   241
  unfolding continuous_def by (rule tendsto_norm)
hoelzl@51478
   242
hoelzl@51478
   243
lemma continuous_on_norm [continuous_on_intros]:
hoelzl@51478
   244
  "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. norm (f x))"
hoelzl@51478
   245
  unfolding continuous_on_def by (auto intro: tendsto_norm)
hoelzl@51478
   246
huffman@36662
   247
lemma tendsto_norm_zero:
huffman@44195
   248
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> 0) F"
huffman@44081
   249
  by (drule tendsto_norm, simp)
huffman@36662
   250
huffman@36662
   251
lemma tendsto_norm_zero_cancel:
huffman@44195
   252
  "((\<lambda>x. norm (f x)) ---> 0) F \<Longrightarrow> (f ---> 0) F"
huffman@44081
   253
  unfolding tendsto_iff dist_norm by simp
huffman@36662
   254
huffman@36662
   255
lemma tendsto_norm_zero_iff:
huffman@44195
   256
  "((\<lambda>x. norm (f x)) ---> 0) F \<longleftrightarrow> (f ---> 0) F"
huffman@44081
   257
  unfolding tendsto_iff dist_norm by simp
huffman@31349
   258
huffman@44194
   259
lemma tendsto_rabs [tendsto_intros]:
huffman@44195
   260
  "(f ---> (l::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> \<bar>l\<bar>) F"
huffman@44194
   261
  by (fold real_norm_def, rule tendsto_norm)
huffman@44194
   262
hoelzl@51478
   263
lemma continuous_rabs [continuous_intros]:
hoelzl@51478
   264
  "continuous F f \<Longrightarrow> continuous F (\<lambda>x. \<bar>f x :: real\<bar>)"
hoelzl@51478
   265
  unfolding real_norm_def[symmetric] by (rule continuous_norm)
hoelzl@51478
   266
hoelzl@51478
   267
lemma continuous_on_rabs [continuous_on_intros]:
hoelzl@51478
   268
  "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. \<bar>f x :: real\<bar>)"
hoelzl@51478
   269
  unfolding real_norm_def[symmetric] by (rule continuous_on_norm)
hoelzl@51478
   270
huffman@44194
   271
lemma tendsto_rabs_zero:
huffman@44195
   272
  "(f ---> (0::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> 0) F"
huffman@44194
   273
  by (fold real_norm_def, rule tendsto_norm_zero)
huffman@44194
   274
huffman@44194
   275
lemma tendsto_rabs_zero_cancel:
huffman@44195
   276
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<Longrightarrow> (f ---> 0) F"
huffman@44194
   277
  by (fold real_norm_def, rule tendsto_norm_zero_cancel)
huffman@44194
   278
huffman@44194
   279
lemma tendsto_rabs_zero_iff:
huffman@44195
   280
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<longleftrightarrow> (f ---> 0) F"
huffman@44194
   281
  by (fold real_norm_def, rule tendsto_norm_zero_iff)
huffman@44194
   282
huffman@44194
   283
subsubsection {* Addition and subtraction *}
huffman@44194
   284
huffman@31565
   285
lemma tendsto_add [tendsto_intros]:
huffman@31349
   286
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   287
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> a + b) F"
huffman@44081
   288
  by (simp only: tendsto_Zfun_iff add_diff_add Zfun_add)
huffman@31349
   289
hoelzl@51478
   290
lemma continuous_add [continuous_intros]:
hoelzl@51478
   291
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51478
   292
  shows "continuous F f \<Longrightarrow> continuous F g \<Longrightarrow> continuous F (\<lambda>x. f x + g x)"
hoelzl@51478
   293
  unfolding continuous_def by (rule tendsto_add)
hoelzl@51478
   294
hoelzl@51478
   295
lemma continuous_on_add [continuous_on_intros]:
hoelzl@51478
   296
  fixes f g :: "_ \<Rightarrow> 'b::real_normed_vector"
hoelzl@51478
   297
  shows "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> continuous_on s (\<lambda>x. f x + g x)"
hoelzl@51478
   298
  unfolding continuous_on_def by (auto intro: tendsto_add)
hoelzl@51478
   299
huffman@44194
   300
lemma tendsto_add_zero:
hoelzl@51478
   301
  fixes f g :: "_ \<Rightarrow> 'b::real_normed_vector"
huffman@44195
   302
  shows "\<lbrakk>(f ---> 0) F; (g ---> 0) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> 0) F"
huffman@44194
   303
  by (drule (1) tendsto_add, simp)
huffman@44194
   304
huffman@31565
   305
lemma tendsto_minus [tendsto_intros]:
huffman@31349
   306
  fixes a :: "'a::real_normed_vector"
huffman@44195
   307
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. - f x) ---> - a) F"
huffman@44081
   308
  by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
huffman@31349
   309
hoelzl@51478
   310
lemma continuous_minus [continuous_intros]:
hoelzl@51478
   311
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51478
   312
  shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. - f x)"
hoelzl@51478
   313
  unfolding continuous_def by (rule tendsto_minus)
hoelzl@51478
   314
hoelzl@51478
   315
lemma continuous_on_minus [continuous_on_intros]:
hoelzl@51478
   316
  fixes f :: "_ \<Rightarrow> 'b::real_normed_vector"
hoelzl@51478
   317
  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. - f x)"
hoelzl@51478
   318
  unfolding continuous_on_def by (auto intro: tendsto_minus)
hoelzl@51478
   319
huffman@31349
   320
lemma tendsto_minus_cancel:
huffman@31349
   321
  fixes a :: "'a::real_normed_vector"
huffman@44195
   322
  shows "((\<lambda>x. - f x) ---> - a) F \<Longrightarrow> (f ---> a) F"
huffman@44081
   323
  by (drule tendsto_minus, simp)
huffman@31349
   324
hoelzl@50330
   325
lemma tendsto_minus_cancel_left:
hoelzl@50330
   326
    "(f ---> - (y::_::real_normed_vector)) F \<longleftrightarrow> ((\<lambda>x. - f x) ---> y) F"
hoelzl@50330
   327
  using tendsto_minus_cancel[of f "- y" F]  tendsto_minus[of f "- y" F]
hoelzl@50330
   328
  by auto
hoelzl@50330
   329
huffman@31565
   330
lemma tendsto_diff [tendsto_intros]:
huffman@31349
   331
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   332
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x - g x) ---> a - b) F"
huffman@44081
   333
  by (simp add: diff_minus tendsto_add tendsto_minus)
huffman@31349
   334
hoelzl@51478
   335
lemma continuous_diff [continuous_intros]:
hoelzl@51478
   336
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51478
   337
  shows "continuous F f \<Longrightarrow> continuous F g \<Longrightarrow> continuous F (\<lambda>x. f x - g x)"
hoelzl@51478
   338
  unfolding continuous_def by (rule tendsto_diff)
hoelzl@51478
   339
hoelzl@51478
   340
lemma continuous_on_diff [continuous_on_intros]:
hoelzl@51478
   341
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51478
   342
  shows "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> continuous_on s (\<lambda>x. f x - g x)"
hoelzl@51478
   343
  unfolding continuous_on_def by (auto intro: tendsto_diff)
hoelzl@51478
   344
huffman@31588
   345
lemma tendsto_setsum [tendsto_intros]:
huffman@31588
   346
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
huffman@44195
   347
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> a i) F"
huffman@44195
   348
  shows "((\<lambda>x. \<Sum>i\<in>S. f i x) ---> (\<Sum>i\<in>S. a i)) F"
huffman@31588
   349
proof (cases "finite S")
huffman@31588
   350
  assume "finite S" thus ?thesis using assms
huffman@44194
   351
    by (induct, simp add: tendsto_const, simp add: tendsto_add)
huffman@31588
   352
next
huffman@31588
   353
  assume "\<not> finite S" thus ?thesis
huffman@31588
   354
    by (simp add: tendsto_const)
huffman@31588
   355
qed
huffman@31588
   356
hoelzl@51478
   357
lemma continuous_setsum [continuous_intros]:
hoelzl@51478
   358
  fixes f :: "'a \<Rightarrow> 'b::t2_space \<Rightarrow> 'c::real_normed_vector"
hoelzl@51478
   359
  shows "(\<And>i. i \<in> S \<Longrightarrow> continuous F (f i)) \<Longrightarrow> continuous F (\<lambda>x. \<Sum>i\<in>S. f i x)"
hoelzl@51478
   360
  unfolding continuous_def by (rule tendsto_setsum)
hoelzl@51478
   361
hoelzl@51478
   362
lemma continuous_on_setsum [continuous_intros]:
hoelzl@51478
   363
  fixes f :: "'a \<Rightarrow> _ \<Rightarrow> 'c::real_normed_vector"
hoelzl@51478
   364
  shows "(\<And>i. i \<in> S \<Longrightarrow> continuous_on s (f i)) \<Longrightarrow> continuous_on s (\<lambda>x. \<Sum>i\<in>S. f i x)"
hoelzl@51478
   365
  unfolding continuous_on_def by (auto intro: tendsto_setsum)
hoelzl@51478
   366
hoelzl@50999
   367
lemmas real_tendsto_sandwich = tendsto_sandwich[where 'b=real]
hoelzl@50999
   368
huffman@44194
   369
subsubsection {* Linear operators and multiplication *}
huffman@44194
   370
huffman@44282
   371
lemma (in bounded_linear) tendsto:
huffman@44195
   372
  "(g ---> a) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> f a) F"
huffman@44081
   373
  by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
huffman@31349
   374
hoelzl@51478
   375
lemma (in bounded_linear) continuous:
hoelzl@51478
   376
  "continuous F g \<Longrightarrow> continuous F (\<lambda>x. f (g x))"
hoelzl@51478
   377
  using tendsto[of g _ F] by (auto simp: continuous_def)
hoelzl@51478
   378
hoelzl@51478
   379
lemma (in bounded_linear) continuous_on:
hoelzl@51478
   380
  "continuous_on s g \<Longrightarrow> continuous_on s (\<lambda>x. f (g x))"
hoelzl@51478
   381
  using tendsto[of g] by (auto simp: continuous_on_def)
hoelzl@51478
   382
huffman@44194
   383
lemma (in bounded_linear) tendsto_zero:
huffman@44195
   384
  "(g ---> 0) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> 0) F"
huffman@44194
   385
  by (drule tendsto, simp only: zero)
huffman@44194
   386
huffman@44282
   387
lemma (in bounded_bilinear) tendsto:
huffman@44195
   388
  "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ** g x) ---> a ** b) F"
huffman@44081
   389
  by (simp only: tendsto_Zfun_iff prod_diff_prod
huffman@44081
   390
                 Zfun_add Zfun Zfun_left Zfun_right)
huffman@31349
   391
hoelzl@51478
   392
lemma (in bounded_bilinear) continuous:
hoelzl@51478
   393
  "continuous F f \<Longrightarrow> continuous F g \<Longrightarrow> continuous F (\<lambda>x. f x ** g x)"
hoelzl@51478
   394
  using tendsto[of f _ F g] by (auto simp: continuous_def)
hoelzl@51478
   395
hoelzl@51478
   396
lemma (in bounded_bilinear) continuous_on:
hoelzl@51478
   397
  "continuous_on s f \<Longrightarrow> continuous_on s g \<Longrightarrow> continuous_on s (\<lambda>x. f x ** g x)"
hoelzl@51478
   398
  using tendsto[of f _ _ g] by (auto simp: continuous_on_def)
hoelzl@51478
   399
huffman@44194
   400
lemma (in bounded_bilinear) tendsto_zero:
huffman@44195
   401
  assumes f: "(f ---> 0) F"
huffman@44195
   402
  assumes g: "(g ---> 0) F"
huffman@44195
   403
  shows "((\<lambda>x. f x ** g x) ---> 0) F"
huffman@44194
   404
  using tendsto [OF f g] by (simp add: zero_left)
huffman@31355
   405
huffman@44194
   406
lemma (in bounded_bilinear) tendsto_left_zero:
huffman@44195
   407
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. f x ** c) ---> 0) F"
huffman@44194
   408
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_left])
huffman@44194
   409
huffman@44194
   410
lemma (in bounded_bilinear) tendsto_right_zero:
huffman@44195
   411
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. c ** f x) ---> 0) F"
huffman@44194
   412
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_right])
huffman@44194
   413
huffman@44282
   414
lemmas tendsto_of_real [tendsto_intros] =
huffman@44282
   415
  bounded_linear.tendsto [OF bounded_linear_of_real]
huffman@44282
   416
huffman@44282
   417
lemmas tendsto_scaleR [tendsto_intros] =
huffman@44282
   418
  bounded_bilinear.tendsto [OF bounded_bilinear_scaleR]
huffman@44282
   419
huffman@44282
   420
lemmas tendsto_mult [tendsto_intros] =
huffman@44282
   421
  bounded_bilinear.tendsto [OF bounded_bilinear_mult]
huffman@44194
   422
hoelzl@51478
   423
lemmas continuous_of_real [continuous_intros] =
hoelzl@51478
   424
  bounded_linear.continuous [OF bounded_linear_of_real]
hoelzl@51478
   425
hoelzl@51478
   426
lemmas continuous_scaleR [continuous_intros] =
hoelzl@51478
   427
  bounded_bilinear.continuous [OF bounded_bilinear_scaleR]
hoelzl@51478
   428
hoelzl@51478
   429
lemmas continuous_mult [continuous_intros] =
hoelzl@51478
   430
  bounded_bilinear.continuous [OF bounded_bilinear_mult]
hoelzl@51478
   431
hoelzl@51478
   432
lemmas continuous_on_of_real [continuous_on_intros] =
hoelzl@51478
   433
  bounded_linear.continuous_on [OF bounded_linear_of_real]
hoelzl@51478
   434
hoelzl@51478
   435
lemmas continuous_on_scaleR [continuous_on_intros] =
hoelzl@51478
   436
  bounded_bilinear.continuous_on [OF bounded_bilinear_scaleR]
hoelzl@51478
   437
hoelzl@51478
   438
lemmas continuous_on_mult [continuous_on_intros] =
hoelzl@51478
   439
  bounded_bilinear.continuous_on [OF bounded_bilinear_mult]
hoelzl@51478
   440
huffman@44568
   441
lemmas tendsto_mult_zero =
huffman@44568
   442
  bounded_bilinear.tendsto_zero [OF bounded_bilinear_mult]
huffman@44568
   443
huffman@44568
   444
lemmas tendsto_mult_left_zero =
huffman@44568
   445
  bounded_bilinear.tendsto_left_zero [OF bounded_bilinear_mult]
huffman@44568
   446
huffman@44568
   447
lemmas tendsto_mult_right_zero =
huffman@44568
   448
  bounded_bilinear.tendsto_right_zero [OF bounded_bilinear_mult]
huffman@44568
   449
huffman@44194
   450
lemma tendsto_power [tendsto_intros]:
huffman@44194
   451
  fixes f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra}"
huffman@44195
   452
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. f x ^ n) ---> a ^ n) F"
huffman@44194
   453
  by (induct n) (simp_all add: tendsto_const tendsto_mult)
huffman@44194
   454
hoelzl@51478
   455
lemma continuous_power [continuous_intros]:
hoelzl@51478
   456
  fixes f :: "'a::t2_space \<Rightarrow> 'b::{power,real_normed_algebra}"
hoelzl@51478
   457
  shows "continuous F f \<Longrightarrow> continuous F (\<lambda>x. (f x)^n)"
hoelzl@51478
   458
  unfolding continuous_def by (rule tendsto_power)
hoelzl@51478
   459
hoelzl@51478
   460
lemma continuous_on_power [continuous_on_intros]:
hoelzl@51478
   461
  fixes f :: "_ \<Rightarrow> 'b::{power,real_normed_algebra}"
hoelzl@51478
   462
  shows "continuous_on s f \<Longrightarrow> continuous_on s (\<lambda>x. (f x)^n)"
hoelzl@51478
   463
  unfolding continuous_on_def by (auto intro: tendsto_power)
hoelzl@51478
   464
huffman@44194
   465
lemma tendsto_setprod [tendsto_intros]:
huffman@44194
   466
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
huffman@44195
   467
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> L i) F"
huffman@44195
   468
  shows "((\<lambda>x. \<Prod>i\<in>S. f i x) ---> (\<Prod>i\<in>S. L i)) F"
huffman@44194
   469
proof (cases "finite S")
huffman@44194
   470
  assume "finite S" thus ?thesis using assms
huffman@44194
   471
    by (induct, simp add: tendsto_const, simp add: tendsto_mult)
huffman@44194
   472
next
huffman@44194
   473
  assume "\<not> finite S" thus ?thesis
huffman@44194
   474
    by (simp add: tendsto_const)
huffman@44194
   475
qed
huffman@44194
   476
hoelzl@51478
   477
lemma continuous_setprod [continuous_intros]:
hoelzl@51478
   478
  fixes f :: "'a \<Rightarrow> 'b::t2_space \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
hoelzl@51478
   479
  shows "(\<And>i. i \<in> S \<Longrightarrow> continuous F (f i)) \<Longrightarrow> continuous F (\<lambda>x. \<Prod>i\<in>S. f i x)"
hoelzl@51478
   480
  unfolding continuous_def by (rule tendsto_setprod)
hoelzl@51478
   481
hoelzl@51478
   482
lemma continuous_on_setprod [continuous_intros]:
hoelzl@51478
   483
  fixes f :: "'a \<Rightarrow> _ \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
hoelzl@51478
   484
  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)"
hoelzl@51478
   485
  unfolding continuous_on_def by (auto intro: tendsto_setprod)
hoelzl@51478
   486
huffman@44194
   487
subsubsection {* Inverse and division *}
huffman@31355
   488
huffman@31355
   489
lemma (in bounded_bilinear) Zfun_prod_Bfun:
huffman@44195
   490
  assumes f: "Zfun f F"
huffman@44195
   491
  assumes g: "Bfun g F"
huffman@44195
   492
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31355
   493
proof -
huffman@31355
   494
  obtain K where K: "0 \<le> K"
huffman@31355
   495
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31355
   496
    using nonneg_bounded by fast
huffman@31355
   497
  obtain B where B: "0 < B"
huffman@44195
   498
    and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) F"
huffman@31487
   499
    using g by (rule BfunE)
huffman@44195
   500
  have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) F"
noschinl@46887
   501
  using norm_g proof eventually_elim
noschinl@46887
   502
    case (elim x)
huffman@31487
   503
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31355
   504
      by (rule norm_le)
huffman@31487
   505
    also have "\<dots> \<le> norm (f x) * B * K"
huffman@31487
   506
      by (intro mult_mono' order_refl norm_g norm_ge_zero
noschinl@46887
   507
                mult_nonneg_nonneg K elim)
huffman@31487
   508
    also have "\<dots> = norm (f x) * (B * K)"
huffman@31355
   509
      by (rule mult_assoc)
huffman@31487
   510
    finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
huffman@31355
   511
  qed
huffman@31487
   512
  with f show ?thesis
huffman@31487
   513
    by (rule Zfun_imp_Zfun)
huffman@31355
   514
qed
huffman@31355
   515
huffman@31355
   516
lemma (in bounded_bilinear) flip:
huffman@31355
   517
  "bounded_bilinear (\<lambda>x y. y ** x)"
huffman@44081
   518
  apply default
huffman@44081
   519
  apply (rule add_right)
huffman@44081
   520
  apply (rule add_left)
huffman@44081
   521
  apply (rule scaleR_right)
huffman@44081
   522
  apply (rule scaleR_left)
huffman@44081
   523
  apply (subst mult_commute)
huffman@44081
   524
  using bounded by fast
huffman@31355
   525
huffman@31355
   526
lemma (in bounded_bilinear) Bfun_prod_Zfun:
huffman@44195
   527
  assumes f: "Bfun f F"
huffman@44195
   528
  assumes g: "Zfun g F"
huffman@44195
   529
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@44081
   530
  using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
huffman@31355
   531
huffman@31355
   532
lemma Bfun_inverse_lemma:
huffman@31355
   533
  fixes x :: "'a::real_normed_div_algebra"
huffman@31355
   534
  shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
huffman@44081
   535
  apply (subst nonzero_norm_inverse, clarsimp)
huffman@44081
   536
  apply (erule (1) le_imp_inverse_le)
huffman@44081
   537
  done
huffman@31355
   538
huffman@31355
   539
lemma Bfun_inverse:
huffman@31355
   540
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
   541
  assumes f: "(f ---> a) F"
huffman@31355
   542
  assumes a: "a \<noteq> 0"
huffman@44195
   543
  shows "Bfun (\<lambda>x. inverse (f x)) F"
huffman@31355
   544
proof -
huffman@31355
   545
  from a have "0 < norm a" by simp
huffman@31355
   546
  hence "\<exists>r>0. r < norm a" by (rule dense)
huffman@31355
   547
  then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
huffman@44195
   548
  have "eventually (\<lambda>x. dist (f x) a < r) F"
huffman@31487
   549
    using tendstoD [OF f r1] by fast
huffman@44195
   550
  hence "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) F"
noschinl@46887
   551
  proof eventually_elim
noschinl@46887
   552
    case (elim x)
huffman@31487
   553
    hence 1: "norm (f x - a) < r"
huffman@31355
   554
      by (simp add: dist_norm)
huffman@31487
   555
    hence 2: "f x \<noteq> 0" using r2 by auto
huffman@31487
   556
    hence "norm (inverse (f x)) = inverse (norm (f x))"
huffman@31355
   557
      by (rule nonzero_norm_inverse)
huffman@31355
   558
    also have "\<dots> \<le> inverse (norm a - r)"
huffman@31355
   559
    proof (rule le_imp_inverse_le)
huffman@31355
   560
      show "0 < norm a - r" using r2 by simp
huffman@31355
   561
    next
huffman@31487
   562
      have "norm a - norm (f x) \<le> norm (a - f x)"
huffman@31355
   563
        by (rule norm_triangle_ineq2)
huffman@31487
   564
      also have "\<dots> = norm (f x - a)"
huffman@31355
   565
        by (rule norm_minus_commute)
huffman@31355
   566
      also have "\<dots> < r" using 1 .
huffman@31487
   567
      finally show "norm a - r \<le> norm (f x)" by simp
huffman@31355
   568
    qed
huffman@31487
   569
    finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
huffman@31355
   570
  qed
huffman@31355
   571
  thus ?thesis by (rule BfunI)
huffman@31355
   572
qed
huffman@31355
   573
huffman@31565
   574
lemma tendsto_inverse [tendsto_intros]:
huffman@31355
   575
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
   576
  assumes f: "(f ---> a) F"
huffman@31355
   577
  assumes a: "a \<noteq> 0"
huffman@44195
   578
  shows "((\<lambda>x. inverse (f x)) ---> inverse a) F"
huffman@31355
   579
proof -
huffman@31355
   580
  from a have "0 < norm a" by simp
huffman@44195
   581
  with f have "eventually (\<lambda>x. dist (f x) a < norm a) F"
huffman@31355
   582
    by (rule tendstoD)
huffman@44195
   583
  then have "eventually (\<lambda>x. f x \<noteq> 0) F"
huffman@31355
   584
    unfolding dist_norm by (auto elim!: eventually_elim1)
huffman@44627
   585
  with a have "eventually (\<lambda>x. inverse (f x) - inverse a =
huffman@44627
   586
    - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
   587
    by (auto elim!: eventually_elim1 simp: inverse_diff_inverse)
huffman@44627
   588
  moreover have "Zfun (\<lambda>x. - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
   589
    by (intro Zfun_minus Zfun_mult_left
huffman@44627
   590
      bounded_bilinear.Bfun_prod_Zfun [OF bounded_bilinear_mult]
huffman@44627
   591
      Bfun_inverse [OF f a] f [unfolded tendsto_Zfun_iff])
huffman@44627
   592
  ultimately show ?thesis
huffman@44627
   593
    unfolding tendsto_Zfun_iff by (rule Zfun_ssubst)
huffman@31355
   594
qed
huffman@31355
   595
hoelzl@51478
   596
lemma continuous_inverse:
hoelzl@51478
   597
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_div_algebra"
hoelzl@51478
   598
  assumes "continuous F f" and "f (Lim F (\<lambda>x. x)) \<noteq> 0"
hoelzl@51478
   599
  shows "continuous F (\<lambda>x. inverse (f x))"
hoelzl@51478
   600
  using assms unfolding continuous_def by (rule tendsto_inverse)
hoelzl@51478
   601
hoelzl@51478
   602
lemma continuous_at_within_inverse[continuous_intros]:
hoelzl@51478
   603
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_div_algebra"
hoelzl@51478
   604
  assumes "continuous (at a within s) f" and "f a \<noteq> 0"
hoelzl@51478
   605
  shows "continuous (at a within s) (\<lambda>x. inverse (f x))"
hoelzl@51478
   606
  using assms unfolding continuous_within by (rule tendsto_inverse)
hoelzl@51478
   607
hoelzl@51478
   608
lemma isCont_inverse[continuous_intros, simp]:
hoelzl@51478
   609
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_div_algebra"
hoelzl@51478
   610
  assumes "isCont f a" and "f a \<noteq> 0"
hoelzl@51478
   611
  shows "isCont (\<lambda>x. inverse (f x)) a"
hoelzl@51478
   612
  using assms unfolding continuous_at by (rule tendsto_inverse)
hoelzl@51478
   613
hoelzl@51478
   614
lemma continuous_on_inverse[continuous_on_intros]:
hoelzl@51478
   615
  fixes f :: "'a::topological_space \<Rightarrow> 'b::real_normed_div_algebra"
hoelzl@51478
   616
  assumes "continuous_on s f" and "\<forall>x\<in>s. f x \<noteq> 0"
hoelzl@51478
   617
  shows "continuous_on s (\<lambda>x. inverse (f x))"
hoelzl@51478
   618
  using assms unfolding continuous_on_def by (fast intro: tendsto_inverse)
hoelzl@51478
   619
huffman@31565
   620
lemma tendsto_divide [tendsto_intros]:
huffman@31355
   621
  fixes a b :: "'a::real_normed_field"
huffman@44195
   622
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F; b \<noteq> 0\<rbrakk>
huffman@44195
   623
    \<Longrightarrow> ((\<lambda>x. f x / g x) ---> a / b) F"
huffman@44282
   624
  by (simp add: tendsto_mult tendsto_inverse divide_inverse)
huffman@31355
   625
hoelzl@51478
   626
lemma continuous_divide:
hoelzl@51478
   627
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_field"
hoelzl@51478
   628
  assumes "continuous F f" and "continuous F g" and "g (Lim F (\<lambda>x. x)) \<noteq> 0"
hoelzl@51478
   629
  shows "continuous F (\<lambda>x. (f x) / (g x))"
hoelzl@51478
   630
  using assms unfolding continuous_def by (rule tendsto_divide)
hoelzl@51478
   631
hoelzl@51478
   632
lemma continuous_at_within_divide[continuous_intros]:
hoelzl@51478
   633
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_field"
hoelzl@51478
   634
  assumes "continuous (at a within s) f" "continuous (at a within s) g" and "g a \<noteq> 0"
hoelzl@51478
   635
  shows "continuous (at a within s) (\<lambda>x. (f x) / (g x))"
hoelzl@51478
   636
  using assms unfolding continuous_within by (rule tendsto_divide)
hoelzl@51478
   637
hoelzl@51478
   638
lemma isCont_divide[continuous_intros, simp]:
hoelzl@51478
   639
  fixes f g :: "'a::t2_space \<Rightarrow> 'b::real_normed_field"
hoelzl@51478
   640
  assumes "isCont f a" "isCont g a" "g a \<noteq> 0"
hoelzl@51478
   641
  shows "isCont (\<lambda>x. (f x) / g x) a"
hoelzl@51478
   642
  using assms unfolding continuous_at by (rule tendsto_divide)
hoelzl@51478
   643
hoelzl@51478
   644
lemma continuous_on_divide[continuous_on_intros]:
hoelzl@51478
   645
  fixes f :: "'a::topological_space \<Rightarrow> 'b::real_normed_field"
hoelzl@51478
   646
  assumes "continuous_on s f" "continuous_on s g" and "\<forall>x\<in>s. g x \<noteq> 0"
hoelzl@51478
   647
  shows "continuous_on s (\<lambda>x. (f x) / (g x))"
hoelzl@51478
   648
  using assms unfolding continuous_on_def by (fast intro: tendsto_divide)
hoelzl@51478
   649
huffman@44194
   650
lemma tendsto_sgn [tendsto_intros]:
huffman@44194
   651
  fixes l :: "'a::real_normed_vector"
huffman@44195
   652
  shows "\<lbrakk>(f ---> l) F; l \<noteq> 0\<rbrakk> \<Longrightarrow> ((\<lambda>x. sgn (f x)) ---> sgn l) F"
huffman@44194
   653
  unfolding sgn_div_norm by (simp add: tendsto_intros)
huffman@44194
   654
hoelzl@51478
   655
lemma continuous_sgn:
hoelzl@51478
   656
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51478
   657
  assumes "continuous F f" and "f (Lim F (\<lambda>x. x)) \<noteq> 0"
hoelzl@51478
   658
  shows "continuous F (\<lambda>x. sgn (f x))"
hoelzl@51478
   659
  using assms unfolding continuous_def by (rule tendsto_sgn)
hoelzl@51478
   660
hoelzl@51478
   661
lemma continuous_at_within_sgn[continuous_intros]:
hoelzl@51478
   662
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51478
   663
  assumes "continuous (at a within s) f" and "f a \<noteq> 0"
hoelzl@51478
   664
  shows "continuous (at a within s) (\<lambda>x. sgn (f x))"
hoelzl@51478
   665
  using assms unfolding continuous_within by (rule tendsto_sgn)
hoelzl@51478
   666
hoelzl@51478
   667
lemma isCont_sgn[continuous_intros]:
hoelzl@51478
   668
  fixes f :: "'a::t2_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51478
   669
  assumes "isCont f a" and "f a \<noteq> 0"
hoelzl@51478
   670
  shows "isCont (\<lambda>x. sgn (f x)) a"
hoelzl@51478
   671
  using assms unfolding continuous_at by (rule tendsto_sgn)
hoelzl@51478
   672
hoelzl@51478
   673
lemma continuous_on_sgn[continuous_on_intros]:
hoelzl@51478
   674
  fixes f :: "'a::topological_space \<Rightarrow> 'b::real_normed_vector"
hoelzl@51478
   675
  assumes "continuous_on s f" and "\<forall>x\<in>s. f x \<noteq> 0"
hoelzl@51478
   676
  shows "continuous_on s (\<lambda>x. sgn (f x))"
hoelzl@51478
   677
  using assms unfolding continuous_on_def by (fast intro: tendsto_sgn)
hoelzl@51478
   678
hoelzl@50325
   679
lemma filterlim_at_infinity:
hoelzl@50325
   680
  fixes f :: "_ \<Rightarrow> 'a\<Colon>real_normed_vector"
hoelzl@50325
   681
  assumes "0 \<le> c"
hoelzl@50325
   682
  shows "(LIM x F. f x :> at_infinity) \<longleftrightarrow> (\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F)"
hoelzl@50325
   683
  unfolding filterlim_iff eventually_at_infinity
hoelzl@50325
   684
proof safe
hoelzl@50325
   685
  fix P :: "'a \<Rightarrow> bool" and b
hoelzl@50325
   686
  assume *: "\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F"
hoelzl@50325
   687
    and P: "\<forall>x. b \<le> norm x \<longrightarrow> P x"
hoelzl@50325
   688
  have "max b (c + 1) > c" by auto
hoelzl@50325
   689
  with * have "eventually (\<lambda>x. max b (c + 1) \<le> norm (f x)) F"
hoelzl@50325
   690
    by auto
hoelzl@50325
   691
  then show "eventually (\<lambda>x. P (f x)) F"
hoelzl@50325
   692
  proof eventually_elim
hoelzl@50325
   693
    fix x assume "max b (c + 1) \<le> norm (f x)"
hoelzl@50325
   694
    with P show "P (f x)" by auto
hoelzl@50325
   695
  qed
hoelzl@50325
   696
qed force
hoelzl@50325
   697
hoelzl@50347
   698
subsection {* Relate @{const at}, @{const at_left} and @{const at_right} *}
hoelzl@50347
   699
hoelzl@50347
   700
text {*
hoelzl@50347
   701
hoelzl@50347
   702
This lemmas are useful for conversion between @{term "at x"} to @{term "at_left x"} and
hoelzl@50347
   703
@{term "at_right x"} and also @{term "at_right 0"}.
hoelzl@50347
   704
hoelzl@50347
   705
*}
hoelzl@50347
   706
hoelzl@51471
   707
lemmas filterlim_split_at_real = filterlim_split_at[where 'a=real]
hoelzl@50323
   708
hoelzl@50347
   709
lemma filtermap_nhds_shift: "filtermap (\<lambda>x. x - d) (nhds a) = nhds (a - d::real)"
hoelzl@50347
   710
  unfolding filter_eq_iff eventually_filtermap eventually_nhds_metric
hoelzl@50347
   711
  by (intro allI ex_cong) (auto simp: dist_real_def field_simps)
hoelzl@50347
   712
hoelzl@50347
   713
lemma filtermap_nhds_minus: "filtermap (\<lambda>x. - x) (nhds a) = nhds (- a::real)"
hoelzl@50347
   714
  unfolding filter_eq_iff eventually_filtermap eventually_nhds_metric
hoelzl@50347
   715
  apply (intro allI ex_cong)
hoelzl@50347
   716
  apply (auto simp: dist_real_def field_simps)
hoelzl@50347
   717
  apply (erule_tac x="-x" in allE)
hoelzl@50347
   718
  apply simp
hoelzl@50347
   719
  done
hoelzl@50347
   720
hoelzl@50347
   721
lemma filtermap_at_shift: "filtermap (\<lambda>x. x - d) (at a) = at (a - d::real)"
hoelzl@50347
   722
  unfolding at_def filtermap_nhds_shift[symmetric]
hoelzl@50347
   723
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50347
   724
hoelzl@50347
   725
lemma filtermap_at_right_shift: "filtermap (\<lambda>x. x - d) (at_right a) = at_right (a - d::real)"
hoelzl@50347
   726
  unfolding filtermap_at_shift[symmetric]
hoelzl@50347
   727
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50323
   728
hoelzl@50347
   729
lemma at_right_to_0: "at_right (a::real) = filtermap (\<lambda>x. x + a) (at_right 0)"
hoelzl@50347
   730
  using filtermap_at_right_shift[of "-a" 0] by simp
hoelzl@50347
   731
hoelzl@50347
   732
lemma filterlim_at_right_to_0:
hoelzl@50347
   733
  "filterlim f F (at_right (a::real)) \<longleftrightarrow> filterlim (\<lambda>x. f (x + a)) F (at_right 0)"
hoelzl@50347
   734
  unfolding filterlim_def filtermap_filtermap at_right_to_0[of a] ..
hoelzl@50347
   735
hoelzl@50347
   736
lemma eventually_at_right_to_0:
hoelzl@50347
   737
  "eventually P (at_right (a::real)) \<longleftrightarrow> eventually (\<lambda>x. P (x + a)) (at_right 0)"
hoelzl@50347
   738
  unfolding at_right_to_0[of a] by (simp add: eventually_filtermap)
hoelzl@50347
   739
hoelzl@50347
   740
lemma filtermap_at_minus: "filtermap (\<lambda>x. - x) (at a) = at (- a::real)"
hoelzl@50347
   741
  unfolding at_def filtermap_nhds_minus[symmetric]
hoelzl@50347
   742
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50347
   743
hoelzl@50347
   744
lemma at_left_minus: "at_left (a::real) = filtermap (\<lambda>x. - x) (at_right (- a))"
hoelzl@50347
   745
  by (simp add: filter_eq_iff eventually_filtermap eventually_within filtermap_at_minus[symmetric])
hoelzl@50323
   746
hoelzl@50347
   747
lemma at_right_minus: "at_right (a::real) = filtermap (\<lambda>x. - x) (at_left (- a))"
hoelzl@50347
   748
  by (simp add: filter_eq_iff eventually_filtermap eventually_within filtermap_at_minus[symmetric])
hoelzl@50347
   749
hoelzl@50347
   750
lemma filterlim_at_left_to_right:
hoelzl@50347
   751
  "filterlim f F (at_left (a::real)) \<longleftrightarrow> filterlim (\<lambda>x. f (- x)) F (at_right (-a))"
hoelzl@50347
   752
  unfolding filterlim_def filtermap_filtermap at_left_minus[of a] ..
hoelzl@50347
   753
hoelzl@50347
   754
lemma eventually_at_left_to_right:
hoelzl@50347
   755
  "eventually P (at_left (a::real)) \<longleftrightarrow> eventually (\<lambda>x. P (- x)) (at_right (-a))"
hoelzl@50347
   756
  unfolding at_left_minus[of a] by (simp add: eventually_filtermap)
hoelzl@50347
   757
hoelzl@50346
   758
lemma at_top_mirror: "at_top = filtermap uminus (at_bot :: real filter)"
hoelzl@50346
   759
  unfolding filter_eq_iff eventually_filtermap eventually_at_top_linorder eventually_at_bot_linorder
hoelzl@50346
   760
  by (metis le_minus_iff minus_minus)
hoelzl@50346
   761
hoelzl@50346
   762
lemma at_bot_mirror: "at_bot = filtermap uminus (at_top :: real filter)"
hoelzl@50346
   763
  unfolding at_top_mirror filtermap_filtermap by (simp add: filtermap_ident)
hoelzl@50346
   764
hoelzl@50346
   765
lemma filterlim_at_top_mirror: "(LIM x at_top. f x :> F) \<longleftrightarrow> (LIM x at_bot. f (-x::real) :> F)"
hoelzl@50346
   766
  unfolding filterlim_def at_top_mirror filtermap_filtermap ..
hoelzl@50346
   767
hoelzl@50346
   768
lemma filterlim_at_bot_mirror: "(LIM x at_bot. f x :> F) \<longleftrightarrow> (LIM x at_top. f (-x::real) :> F)"
hoelzl@50346
   769
  unfolding filterlim_def at_bot_mirror filtermap_filtermap ..
hoelzl@50346
   770
hoelzl@50323
   771
lemma filterlim_uminus_at_top_at_bot: "LIM x at_bot. - x :: real :> at_top"
hoelzl@50323
   772
  unfolding filterlim_at_top eventually_at_bot_dense
hoelzl@50346
   773
  by (metis leI minus_less_iff order_less_asym)
hoelzl@50323
   774
hoelzl@50323
   775
lemma filterlim_uminus_at_bot_at_top: "LIM x at_top. - x :: real :> at_bot"
hoelzl@50323
   776
  unfolding filterlim_at_bot eventually_at_top_dense
hoelzl@50346
   777
  by (metis leI less_minus_iff order_less_asym)
hoelzl@50323
   778
hoelzl@50346
   779
lemma filterlim_uminus_at_top: "(LIM x F. f x :> at_top) \<longleftrightarrow> (LIM x F. - (f x) :: real :> at_bot)"
hoelzl@50346
   780
  using filterlim_compose[OF filterlim_uminus_at_bot_at_top, of f F]
hoelzl@50346
   781
  using filterlim_compose[OF filterlim_uminus_at_top_at_bot, of "\<lambda>x. - f x" F]
hoelzl@50346
   782
  by auto
hoelzl@50346
   783
hoelzl@50346
   784
lemma filterlim_uminus_at_bot: "(LIM x F. f x :> at_bot) \<longleftrightarrow> (LIM x F. - (f x) :: real :> at_top)"
hoelzl@50346
   785
  unfolding filterlim_uminus_at_top by simp
hoelzl@50323
   786
hoelzl@50347
   787
lemma filterlim_inverse_at_top_right: "LIM x at_right (0::real). inverse x :> at_top"
hoelzl@50347
   788
  unfolding filterlim_at_top_gt[where c=0] eventually_within at_def
hoelzl@50347
   789
proof safe
hoelzl@50347
   790
  fix Z :: real assume [arith]: "0 < Z"
hoelzl@50347
   791
  then have "eventually (\<lambda>x. x < inverse Z) (nhds 0)"
hoelzl@50347
   792
    by (auto simp add: eventually_nhds_metric dist_real_def intro!: exI[of _ "\<bar>inverse Z\<bar>"])
hoelzl@50347
   793
  then show "eventually (\<lambda>x. x \<in> - {0} \<longrightarrow> x \<in> {0<..} \<longrightarrow> Z \<le> inverse x) (nhds 0)"
hoelzl@50347
   794
    by (auto elim!: eventually_elim1 simp: inverse_eq_divide field_simps)
hoelzl@50347
   795
qed
hoelzl@50347
   796
hoelzl@50347
   797
lemma filterlim_inverse_at_top:
hoelzl@50347
   798
  "(f ---> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. 0 < f x) F \<Longrightarrow> LIM x F. inverse (f x) :> at_top"
hoelzl@50347
   799
  by (intro filterlim_compose[OF filterlim_inverse_at_top_right])
hoelzl@50347
   800
     (simp add: filterlim_def eventually_filtermap le_within_iff at_def eventually_elim1)
hoelzl@50347
   801
hoelzl@50347
   802
lemma filterlim_inverse_at_bot_neg:
hoelzl@50347
   803
  "LIM x (at_left (0::real)). inverse x :> at_bot"
hoelzl@50347
   804
  by (simp add: filterlim_inverse_at_top_right filterlim_uminus_at_bot filterlim_at_left_to_right)
hoelzl@50347
   805
hoelzl@50347
   806
lemma filterlim_inverse_at_bot:
hoelzl@50347
   807
  "(f ---> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. f x < 0) F \<Longrightarrow> LIM x F. inverse (f x) :> at_bot"
hoelzl@50347
   808
  unfolding filterlim_uminus_at_bot inverse_minus_eq[symmetric]
hoelzl@50347
   809
  by (rule filterlim_inverse_at_top) (simp_all add: tendsto_minus_cancel_left[symmetric])
hoelzl@50347
   810
hoelzl@50325
   811
lemma tendsto_inverse_0:
hoelzl@50325
   812
  fixes x :: "_ \<Rightarrow> 'a\<Colon>real_normed_div_algebra"
hoelzl@50325
   813
  shows "(inverse ---> (0::'a)) at_infinity"
hoelzl@50325
   814
  unfolding tendsto_Zfun_iff diff_0_right Zfun_def eventually_at_infinity
hoelzl@50325
   815
proof safe
hoelzl@50325
   816
  fix r :: real assume "0 < r"
hoelzl@50325
   817
  show "\<exists>b. \<forall>x. b \<le> norm x \<longrightarrow> norm (inverse x :: 'a) < r"
hoelzl@50325
   818
  proof (intro exI[of _ "inverse (r / 2)"] allI impI)
hoelzl@50325
   819
    fix x :: 'a
hoelzl@50325
   820
    from `0 < r` have "0 < inverse (r / 2)" by simp
hoelzl@50325
   821
    also assume *: "inverse (r / 2) \<le> norm x"
hoelzl@50325
   822
    finally show "norm (inverse x) < r"
hoelzl@50325
   823
      using * `0 < r` by (subst nonzero_norm_inverse) (simp_all add: inverse_eq_divide field_simps)
hoelzl@50325
   824
  qed
hoelzl@50325
   825
qed
hoelzl@50325
   826
hoelzl@50347
   827
lemma at_right_to_top: "(at_right (0::real)) = filtermap inverse at_top"
hoelzl@50347
   828
proof (rule antisym)
hoelzl@50347
   829
  have "(inverse ---> (0::real)) at_top"
hoelzl@50347
   830
    by (metis tendsto_inverse_0 filterlim_mono at_top_le_at_infinity order_refl)
hoelzl@50347
   831
  then show "filtermap inverse at_top \<le> at_right (0::real)"
hoelzl@50347
   832
    unfolding at_within_eq
hoelzl@50347
   833
    by (intro le_withinI) (simp_all add: eventually_filtermap eventually_gt_at_top filterlim_def)
hoelzl@50347
   834
next
hoelzl@50347
   835
  have "filtermap inverse (filtermap inverse (at_right (0::real))) \<le> filtermap inverse at_top"
hoelzl@50347
   836
    using filterlim_inverse_at_top_right unfolding filterlim_def by (rule filtermap_mono)
hoelzl@50347
   837
  then show "at_right (0::real) \<le> filtermap inverse at_top"
hoelzl@50347
   838
    by (simp add: filtermap_ident filtermap_filtermap)
hoelzl@50347
   839
qed
hoelzl@50347
   840
hoelzl@50347
   841
lemma eventually_at_right_to_top:
hoelzl@50347
   842
  "eventually P (at_right (0::real)) \<longleftrightarrow> eventually (\<lambda>x. P (inverse x)) at_top"
hoelzl@50347
   843
  unfolding at_right_to_top eventually_filtermap ..
hoelzl@50347
   844
hoelzl@50347
   845
lemma filterlim_at_right_to_top:
hoelzl@50347
   846
  "filterlim f F (at_right (0::real)) \<longleftrightarrow> (LIM x at_top. f (inverse x) :> F)"
hoelzl@50347
   847
  unfolding filterlim_def at_right_to_top filtermap_filtermap ..
hoelzl@50347
   848
hoelzl@50347
   849
lemma at_top_to_right: "at_top = filtermap inverse (at_right (0::real))"
hoelzl@50347
   850
  unfolding at_right_to_top filtermap_filtermap inverse_inverse_eq filtermap_ident ..
hoelzl@50347
   851
hoelzl@50347
   852
lemma eventually_at_top_to_right:
hoelzl@50347
   853
  "eventually P at_top \<longleftrightarrow> eventually (\<lambda>x. P (inverse x)) (at_right (0::real))"
hoelzl@50347
   854
  unfolding at_top_to_right eventually_filtermap ..
hoelzl@50347
   855
hoelzl@50347
   856
lemma filterlim_at_top_to_right:
hoelzl@50347
   857
  "filterlim f F at_top \<longleftrightarrow> (LIM x (at_right (0::real)). f (inverse x) :> F)"
hoelzl@50347
   858
  unfolding filterlim_def at_top_to_right filtermap_filtermap ..
hoelzl@50347
   859
hoelzl@50325
   860
lemma filterlim_inverse_at_infinity:
hoelzl@50325
   861
  fixes x :: "_ \<Rightarrow> 'a\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50325
   862
  shows "filterlim inverse at_infinity (at (0::'a))"
hoelzl@50325
   863
  unfolding filterlim_at_infinity[OF order_refl]
hoelzl@50325
   864
proof safe
hoelzl@50325
   865
  fix r :: real assume "0 < r"
hoelzl@50325
   866
  then show "eventually (\<lambda>x::'a. r \<le> norm (inverse x)) (at 0)"
hoelzl@50325
   867
    unfolding eventually_at norm_inverse
hoelzl@50325
   868
    by (intro exI[of _ "inverse r"])
hoelzl@50325
   869
       (auto simp: norm_conv_dist[symmetric] field_simps inverse_eq_divide)
hoelzl@50325
   870
qed
hoelzl@50325
   871
hoelzl@50325
   872
lemma filterlim_inverse_at_iff:
hoelzl@50325
   873
  fixes g :: "'a \<Rightarrow> 'b\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50325
   874
  shows "(LIM x F. inverse (g x) :> at 0) \<longleftrightarrow> (LIM x F. g x :> at_infinity)"
hoelzl@50325
   875
  unfolding filterlim_def filtermap_filtermap[symmetric]
hoelzl@50325
   876
proof
hoelzl@50325
   877
  assume "filtermap g F \<le> at_infinity"
hoelzl@50325
   878
  then have "filtermap inverse (filtermap g F) \<le> filtermap inverse at_infinity"
hoelzl@50325
   879
    by (rule filtermap_mono)
hoelzl@50325
   880
  also have "\<dots> \<le> at 0"
hoelzl@50325
   881
    using tendsto_inverse_0
hoelzl@50325
   882
    by (auto intro!: le_withinI exI[of _ 1]
hoelzl@50325
   883
             simp: eventually_filtermap eventually_at_infinity filterlim_def at_def)
hoelzl@50325
   884
  finally show "filtermap inverse (filtermap g F) \<le> at 0" .
hoelzl@50325
   885
next
hoelzl@50325
   886
  assume "filtermap inverse (filtermap g F) \<le> at 0"
hoelzl@50325
   887
  then have "filtermap inverse (filtermap inverse (filtermap g F)) \<le> filtermap inverse (at 0)"
hoelzl@50325
   888
    by (rule filtermap_mono)
hoelzl@50325
   889
  with filterlim_inverse_at_infinity show "filtermap g F \<le> at_infinity"
hoelzl@50325
   890
    by (auto intro: order_trans simp: filterlim_def filtermap_filtermap)
hoelzl@50325
   891
qed
hoelzl@50325
   892
hoelzl@50419
   893
lemma tendsto_inverse_0_at_top:
hoelzl@50419
   894
  "LIM x F. f x :> at_top \<Longrightarrow> ((\<lambda>x. inverse (f x) :: real) ---> 0) F"
hoelzl@50419
   895
 by (metis at_top_le_at_infinity filterlim_at filterlim_inverse_at_iff filterlim_mono order_refl)
hoelzl@50419
   896
hoelzl@50324
   897
text {*
hoelzl@50324
   898
hoelzl@50324
   899
We only show rules for multiplication and addition when the functions are either against a real
hoelzl@50324
   900
value or against infinity. Further rules are easy to derive by using @{thm filterlim_uminus_at_top}.
hoelzl@50324
   901
hoelzl@50324
   902
*}
hoelzl@50324
   903
hoelzl@50324
   904
lemma filterlim_tendsto_pos_mult_at_top: 
hoelzl@50324
   905
  assumes f: "(f ---> c) F" and c: "0 < c"
hoelzl@50324
   906
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
   907
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
   908
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
   909
proof safe
hoelzl@50324
   910
  fix Z :: real assume "0 < Z"
hoelzl@50324
   911
  from f `0 < c` have "eventually (\<lambda>x. c / 2 < f x) F"
hoelzl@50324
   912
    by (auto dest!: tendstoD[where e="c / 2"] elim!: eventually_elim1
hoelzl@50324
   913
             simp: dist_real_def abs_real_def split: split_if_asm)
hoelzl@50346
   914
  moreover from g have "eventually (\<lambda>x. (Z / c * 2) \<le> g x) F"
hoelzl@50324
   915
    unfolding filterlim_at_top by auto
hoelzl@50346
   916
  ultimately show "eventually (\<lambda>x. Z \<le> f x * g x) F"
hoelzl@50324
   917
  proof eventually_elim
hoelzl@50346
   918
    fix x assume "c / 2 < f x" "Z / c * 2 \<le> g x"
hoelzl@50346
   919
    with `0 < Z` `0 < c` have "c / 2 * (Z / c * 2) \<le> f x * g x"
hoelzl@50346
   920
      by (intro mult_mono) (auto simp: zero_le_divide_iff)
hoelzl@50346
   921
    with `0 < c` show "Z \<le> f x * g x"
hoelzl@50324
   922
       by simp
hoelzl@50324
   923
  qed
hoelzl@50324
   924
qed
hoelzl@50324
   925
hoelzl@50324
   926
lemma filterlim_at_top_mult_at_top: 
hoelzl@50324
   927
  assumes f: "LIM x F. f x :> at_top"
hoelzl@50324
   928
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
   929
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
   930
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
   931
proof safe
hoelzl@50324
   932
  fix Z :: real assume "0 < Z"
hoelzl@50346
   933
  from f have "eventually (\<lambda>x. 1 \<le> f x) F"
hoelzl@50324
   934
    unfolding filterlim_at_top by auto
hoelzl@50346
   935
  moreover from g have "eventually (\<lambda>x. Z \<le> g x) F"
hoelzl@50324
   936
    unfolding filterlim_at_top by auto
hoelzl@50346
   937
  ultimately show "eventually (\<lambda>x. Z \<le> f x * g x) F"
hoelzl@50324
   938
  proof eventually_elim
hoelzl@50346
   939
    fix x assume "1 \<le> f x" "Z \<le> g x"
hoelzl@50346
   940
    with `0 < Z` have "1 * Z \<le> f x * g x"
hoelzl@50346
   941
      by (intro mult_mono) (auto simp: zero_le_divide_iff)
hoelzl@50346
   942
    then show "Z \<le> f x * g x"
hoelzl@50324
   943
       by simp
hoelzl@50324
   944
  qed
hoelzl@50324
   945
qed
hoelzl@50324
   946
hoelzl@50419
   947
lemma filterlim_tendsto_pos_mult_at_bot:
hoelzl@50419
   948
  assumes "(f ---> c) F" "0 < (c::real)" "filterlim g at_bot F"
hoelzl@50419
   949
  shows "LIM x F. f x * g x :> at_bot"
hoelzl@50419
   950
  using filterlim_tendsto_pos_mult_at_top[OF assms(1,2), of "\<lambda>x. - g x"] assms(3)
hoelzl@50419
   951
  unfolding filterlim_uminus_at_bot by simp
hoelzl@50419
   952
hoelzl@50324
   953
lemma filterlim_tendsto_add_at_top: 
hoelzl@50324
   954
  assumes f: "(f ---> c) F"
hoelzl@50324
   955
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
   956
  shows "LIM x F. (f x + g x :: real) :> at_top"
hoelzl@50324
   957
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
   958
proof safe
hoelzl@50324
   959
  fix Z :: real assume "0 < Z"
hoelzl@50324
   960
  from f have "eventually (\<lambda>x. c - 1 < f x) F"
hoelzl@50324
   961
    by (auto dest!: tendstoD[where e=1] elim!: eventually_elim1 simp: dist_real_def)
hoelzl@50346
   962
  moreover from g have "eventually (\<lambda>x. Z - (c - 1) \<le> g x) F"
hoelzl@50324
   963
    unfolding filterlim_at_top by auto
hoelzl@50346
   964
  ultimately show "eventually (\<lambda>x. Z \<le> f x + g x) F"
hoelzl@50324
   965
    by eventually_elim simp
hoelzl@50324
   966
qed
hoelzl@50324
   967
hoelzl@50347
   968
lemma LIM_at_top_divide:
hoelzl@50347
   969
  fixes f g :: "'a \<Rightarrow> real"
hoelzl@50347
   970
  assumes f: "(f ---> a) F" "0 < a"
hoelzl@50347
   971
  assumes g: "(g ---> 0) F" "eventually (\<lambda>x. 0 < g x) F"
hoelzl@50347
   972
  shows "LIM x F. f x / g x :> at_top"
hoelzl@50347
   973
  unfolding divide_inverse
hoelzl@50347
   974
  by (rule filterlim_tendsto_pos_mult_at_top[OF f]) (rule filterlim_inverse_at_top[OF g])
hoelzl@50347
   975
hoelzl@50324
   976
lemma filterlim_at_top_add_at_top: 
hoelzl@50324
   977
  assumes f: "LIM x F. f x :> at_top"
hoelzl@50324
   978
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
   979
  shows "LIM x F. (f x + g x :: real) :> at_top"
hoelzl@50324
   980
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
   981
proof safe
hoelzl@50324
   982
  fix Z :: real assume "0 < Z"
hoelzl@50346
   983
  from f have "eventually (\<lambda>x. 0 \<le> f x) F"
hoelzl@50324
   984
    unfolding filterlim_at_top by auto
hoelzl@50346
   985
  moreover from g have "eventually (\<lambda>x. Z \<le> g x) F"
hoelzl@50324
   986
    unfolding filterlim_at_top by auto
hoelzl@50346
   987
  ultimately show "eventually (\<lambda>x. Z \<le> f x + g x) F"
hoelzl@50324
   988
    by eventually_elim simp
hoelzl@50324
   989
qed
hoelzl@50324
   990
hoelzl@50331
   991
lemma tendsto_divide_0:
hoelzl@50331
   992
  fixes f :: "_ \<Rightarrow> 'a\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50331
   993
  assumes f: "(f ---> c) F"
hoelzl@50331
   994
  assumes g: "LIM x F. g x :> at_infinity"
hoelzl@50331
   995
  shows "((\<lambda>x. f x / g x) ---> 0) F"
hoelzl@50331
   996
  using tendsto_mult[OF f filterlim_compose[OF tendsto_inverse_0 g]] by (simp add: divide_inverse)
hoelzl@50331
   997
hoelzl@50331
   998
lemma linear_plus_1_le_power:
hoelzl@50331
   999
  fixes x :: real
hoelzl@50331
  1000
  assumes x: "0 \<le> x"
hoelzl@50331
  1001
  shows "real n * x + 1 \<le> (x + 1) ^ n"
hoelzl@50331
  1002
proof (induct n)
hoelzl@50331
  1003
  case (Suc n)
hoelzl@50331
  1004
  have "real (Suc n) * x + 1 \<le> (x + 1) * (real n * x + 1)"
hoelzl@50331
  1005
    by (simp add: field_simps real_of_nat_Suc mult_nonneg_nonneg x)
hoelzl@50331
  1006
  also have "\<dots> \<le> (x + 1)^Suc n"
hoelzl@50331
  1007
    using Suc x by (simp add: mult_left_mono)
hoelzl@50331
  1008
  finally show ?case .
hoelzl@50331
  1009
qed simp
hoelzl@50331
  1010
hoelzl@50331
  1011
lemma filterlim_realpow_sequentially_gt1:
hoelzl@50331
  1012
  fixes x :: "'a :: real_normed_div_algebra"
hoelzl@50331
  1013
  assumes x[arith]: "1 < norm x"
hoelzl@50331
  1014
  shows "LIM n sequentially. x ^ n :> at_infinity"
hoelzl@50331
  1015
proof (intro filterlim_at_infinity[THEN iffD2] allI impI)
hoelzl@50331
  1016
  fix y :: real assume "0 < y"
hoelzl@50331
  1017
  have "0 < norm x - 1" by simp
hoelzl@50331
  1018
  then obtain N::nat where "y < real N * (norm x - 1)" by (blast dest: reals_Archimedean3)
hoelzl@50331
  1019
  also have "\<dots> \<le> real N * (norm x - 1) + 1" by simp
hoelzl@50331
  1020
  also have "\<dots> \<le> (norm x - 1 + 1) ^ N" by (rule linear_plus_1_le_power) simp
hoelzl@50331
  1021
  also have "\<dots> = norm x ^ N" by simp
hoelzl@50331
  1022
  finally have "\<forall>n\<ge>N. y \<le> norm x ^ n"
hoelzl@50331
  1023
    by (metis order_less_le_trans power_increasing order_less_imp_le x)
hoelzl@50331
  1024
  then show "eventually (\<lambda>n. y \<le> norm (x ^ n)) sequentially"
hoelzl@50331
  1025
    unfolding eventually_sequentially
hoelzl@50331
  1026
    by (auto simp: norm_power)
hoelzl@50331
  1027
qed simp
hoelzl@50331
  1028
hoelzl@51471
  1029
hoelzl@51471
  1030
(* Unfortunately eventually_within was overwritten by Multivariate_Analysis.
hoelzl@51471
  1031
   Hence it was references as Limits.within, but now it is Basic_Topology.eventually_within *)
hoelzl@51471
  1032
lemmas eventually_within = eventually_within
hoelzl@51471
  1033
huffman@31349
  1034
end
hoelzl@50324
  1035