src/HOL/Limits.thy
author hoelzl
Tue Dec 04 18:00:37 2012 +0100 (2012-12-04)
changeset 50347 77e3effa50b6
parent 50346 a75c6429c3c3
child 50419 3177d0374701
permissions -rw-r--r--
prove tendsto_power_div_exp_0
* * *
missing rename
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
huffman@44081
    11
subsection {* Filters *}
huffman@31392
    12
huffman@31392
    13
text {*
huffman@44081
    14
  This definition also allows non-proper filters.
huffman@31392
    15
*}
huffman@31392
    16
huffman@36358
    17
locale is_filter =
huffman@44081
    18
  fixes F :: "('a \<Rightarrow> bool) \<Rightarrow> bool"
huffman@44081
    19
  assumes True: "F (\<lambda>x. True)"
huffman@44081
    20
  assumes conj: "F (\<lambda>x. P x) \<Longrightarrow> F (\<lambda>x. Q x) \<Longrightarrow> F (\<lambda>x. P x \<and> Q x)"
huffman@44081
    21
  assumes mono: "\<forall>x. P x \<longrightarrow> Q x \<Longrightarrow> F (\<lambda>x. P x) \<Longrightarrow> F (\<lambda>x. Q x)"
huffman@36358
    22
wenzelm@49834
    23
typedef 'a filter = "{F :: ('a \<Rightarrow> bool) \<Rightarrow> bool. is_filter F}"
huffman@31392
    24
proof
huffman@44081
    25
  show "(\<lambda>x. True) \<in> ?filter" by (auto intro: is_filter.intro)
huffman@31392
    26
qed
huffman@31349
    27
huffman@44195
    28
lemma is_filter_Rep_filter: "is_filter (Rep_filter F)"
huffman@44195
    29
  using Rep_filter [of F] by simp
huffman@31392
    30
huffman@44081
    31
lemma Abs_filter_inverse':
huffman@44081
    32
  assumes "is_filter F" shows "Rep_filter (Abs_filter F) = F"
huffman@44081
    33
  using assms by (simp add: Abs_filter_inverse)
huffman@31392
    34
huffman@31392
    35
huffman@31392
    36
subsection {* Eventually *}
huffman@31349
    37
huffman@44081
    38
definition eventually :: "('a \<Rightarrow> bool) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
    39
  where "eventually P F \<longleftrightarrow> Rep_filter F P"
huffman@36358
    40
huffman@44081
    41
lemma eventually_Abs_filter:
huffman@44081
    42
  assumes "is_filter F" shows "eventually P (Abs_filter F) = F P"
huffman@44081
    43
  unfolding eventually_def using assms by (simp add: Abs_filter_inverse)
huffman@31349
    44
huffman@44081
    45
lemma filter_eq_iff:
huffman@44195
    46
  shows "F = F' \<longleftrightarrow> (\<forall>P. eventually P F = eventually P F')"
huffman@44081
    47
  unfolding Rep_filter_inject [symmetric] fun_eq_iff eventually_def ..
huffman@36360
    48
huffman@44195
    49
lemma eventually_True [simp]: "eventually (\<lambda>x. True) F"
huffman@44081
    50
  unfolding eventually_def
huffman@44081
    51
  by (rule is_filter.True [OF is_filter_Rep_filter])
huffman@31349
    52
huffman@44195
    53
lemma always_eventually: "\<forall>x. P x \<Longrightarrow> eventually P F"
huffman@36630
    54
proof -
huffman@36630
    55
  assume "\<forall>x. P x" hence "P = (\<lambda>x. True)" by (simp add: ext)
huffman@44195
    56
  thus "eventually P F" by simp
huffman@36630
    57
qed
huffman@36630
    58
huffman@31349
    59
lemma eventually_mono:
huffman@44195
    60
  "(\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually P F \<Longrightarrow> eventually Q F"
huffman@44081
    61
  unfolding eventually_def
huffman@44081
    62
  by (rule is_filter.mono [OF is_filter_Rep_filter])
huffman@31349
    63
huffman@31349
    64
lemma eventually_conj:
huffman@44195
    65
  assumes P: "eventually (\<lambda>x. P x) F"
huffman@44195
    66
  assumes Q: "eventually (\<lambda>x. Q x) F"
huffman@44195
    67
  shows "eventually (\<lambda>x. P x \<and> Q x) F"
huffman@44081
    68
  using assms unfolding eventually_def
huffman@44081
    69
  by (rule is_filter.conj [OF is_filter_Rep_filter])
huffman@31349
    70
huffman@31349
    71
lemma eventually_mp:
huffman@44195
    72
  assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
huffman@44195
    73
  assumes "eventually (\<lambda>x. P x) F"
huffman@44195
    74
  shows "eventually (\<lambda>x. Q x) F"
huffman@31349
    75
proof (rule eventually_mono)
huffman@31349
    76
  show "\<forall>x. (P x \<longrightarrow> Q x) \<and> P x \<longrightarrow> Q x" by simp
huffman@44195
    77
  show "eventually (\<lambda>x. (P x \<longrightarrow> Q x) \<and> P x) F"
huffman@31349
    78
    using assms by (rule eventually_conj)
huffman@31349
    79
qed
huffman@31349
    80
huffman@31349
    81
lemma eventually_rev_mp:
huffman@44195
    82
  assumes "eventually (\<lambda>x. P x) F"
huffman@44195
    83
  assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
huffman@44195
    84
  shows "eventually (\<lambda>x. Q x) F"
huffman@31349
    85
using assms(2) assms(1) by (rule eventually_mp)
huffman@31349
    86
huffman@31349
    87
lemma eventually_conj_iff:
huffman@44195
    88
  "eventually (\<lambda>x. P x \<and> Q x) F \<longleftrightarrow> eventually P F \<and> eventually Q F"
huffman@44081
    89
  by (auto intro: eventually_conj elim: eventually_rev_mp)
huffman@31349
    90
huffman@31349
    91
lemma eventually_elim1:
huffman@44195
    92
  assumes "eventually (\<lambda>i. P i) F"
huffman@31349
    93
  assumes "\<And>i. P i \<Longrightarrow> Q i"
huffman@44195
    94
  shows "eventually (\<lambda>i. Q i) F"
huffman@44081
    95
  using assms by (auto elim!: eventually_rev_mp)
huffman@31349
    96
huffman@31349
    97
lemma eventually_elim2:
huffman@44195
    98
  assumes "eventually (\<lambda>i. P i) F"
huffman@44195
    99
  assumes "eventually (\<lambda>i. Q i) F"
huffman@31349
   100
  assumes "\<And>i. P i \<Longrightarrow> Q i \<Longrightarrow> R i"
huffman@44195
   101
  shows "eventually (\<lambda>i. R i) F"
huffman@44081
   102
  using assms by (auto elim!: eventually_rev_mp)
huffman@31349
   103
noschinl@45892
   104
lemma eventually_subst:
noschinl@45892
   105
  assumes "eventually (\<lambda>n. P n = Q n) F"
noschinl@45892
   106
  shows "eventually P F = eventually Q F" (is "?L = ?R")
noschinl@45892
   107
proof -
noschinl@45892
   108
  from assms have "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
noschinl@45892
   109
      and "eventually (\<lambda>x. Q x \<longrightarrow> P x) F"
noschinl@45892
   110
    by (auto elim: eventually_elim1)
noschinl@45892
   111
  then show ?thesis by (auto elim: eventually_elim2)
noschinl@45892
   112
qed
noschinl@45892
   113
noschinl@46886
   114
ML {*
wenzelm@47432
   115
  fun eventually_elim_tac ctxt thms thm =
wenzelm@47432
   116
    let
noschinl@46886
   117
      val thy = Proof_Context.theory_of ctxt
noschinl@46886
   118
      val mp_thms = thms RL [@{thm eventually_rev_mp}]
noschinl@46886
   119
      val raw_elim_thm =
noschinl@46886
   120
        (@{thm allI} RS @{thm always_eventually})
noschinl@46886
   121
        |> fold (fn thm1 => fn thm2 => thm2 RS thm1) mp_thms
noschinl@46886
   122
        |> fold (fn _ => fn thm => @{thm impI} RS thm) thms
noschinl@46886
   123
      val cases_prop = prop_of (raw_elim_thm RS thm)
noschinl@46886
   124
      val cases = (Rule_Cases.make_common (thy, cases_prop) [(("elim", []), [])])
noschinl@46886
   125
    in
noschinl@46886
   126
      CASES cases (rtac raw_elim_thm 1) thm
noschinl@46886
   127
    end
noschinl@46886
   128
*}
noschinl@46886
   129
wenzelm@47432
   130
method_setup eventually_elim = {*
wenzelm@47432
   131
  Scan.succeed (fn ctxt => METHOD_CASES (eventually_elim_tac ctxt))
wenzelm@47432
   132
*} "elimination of eventually quantifiers"
noschinl@45892
   133
noschinl@45892
   134
huffman@36360
   135
subsection {* Finer-than relation *}
huffman@36360
   136
huffman@44195
   137
text {* @{term "F \<le> F'"} means that filter @{term F} is finer than
huffman@44195
   138
filter @{term F'}. *}
huffman@36360
   139
huffman@44081
   140
instantiation filter :: (type) complete_lattice
huffman@36360
   141
begin
huffman@36360
   142
huffman@44081
   143
definition le_filter_def:
huffman@44195
   144
  "F \<le> F' \<longleftrightarrow> (\<forall>P. eventually P F' \<longrightarrow> eventually P F)"
huffman@36360
   145
huffman@36360
   146
definition
huffman@44195
   147
  "(F :: 'a filter) < F' \<longleftrightarrow> F \<le> F' \<and> \<not> F' \<le> F"
huffman@36360
   148
huffman@36360
   149
definition
huffman@44081
   150
  "top = Abs_filter (\<lambda>P. \<forall>x. P x)"
huffman@36630
   151
huffman@36630
   152
definition
huffman@44081
   153
  "bot = Abs_filter (\<lambda>P. True)"
huffman@36360
   154
huffman@36630
   155
definition
huffman@44195
   156
  "sup F F' = Abs_filter (\<lambda>P. eventually P F \<and> eventually P F')"
huffman@36630
   157
huffman@36630
   158
definition
huffman@44195
   159
  "inf F F' = Abs_filter
huffman@44195
   160
      (\<lambda>P. \<exists>Q R. eventually Q F \<and> eventually R F' \<and> (\<forall>x. Q x \<and> R x \<longrightarrow> P x))"
huffman@36630
   161
huffman@36630
   162
definition
huffman@44195
   163
  "Sup S = Abs_filter (\<lambda>P. \<forall>F\<in>S. eventually P F)"
huffman@36630
   164
huffman@36630
   165
definition
huffman@44195
   166
  "Inf S = Sup {F::'a filter. \<forall>F'\<in>S. F \<le> F'}"
huffman@36630
   167
huffman@36630
   168
lemma eventually_top [simp]: "eventually P top \<longleftrightarrow> (\<forall>x. P x)"
huffman@44081
   169
  unfolding top_filter_def
huffman@44081
   170
  by (rule eventually_Abs_filter, rule is_filter.intro, auto)
huffman@36630
   171
huffman@36629
   172
lemma eventually_bot [simp]: "eventually P bot"
huffman@44081
   173
  unfolding bot_filter_def
huffman@44081
   174
  by (subst eventually_Abs_filter, rule is_filter.intro, auto)
huffman@36360
   175
huffman@36630
   176
lemma eventually_sup:
huffman@44195
   177
  "eventually P (sup F F') \<longleftrightarrow> eventually P F \<and> eventually P F'"
huffman@44081
   178
  unfolding sup_filter_def
huffman@44081
   179
  by (rule eventually_Abs_filter, rule is_filter.intro)
huffman@44081
   180
     (auto elim!: eventually_rev_mp)
huffman@36630
   181
huffman@36630
   182
lemma eventually_inf:
huffman@44195
   183
  "eventually P (inf F F') \<longleftrightarrow>
huffman@44195
   184
   (\<exists>Q R. eventually Q F \<and> eventually R F' \<and> (\<forall>x. Q x \<and> R x \<longrightarrow> P x))"
huffman@44081
   185
  unfolding inf_filter_def
huffman@44081
   186
  apply (rule eventually_Abs_filter, rule is_filter.intro)
huffman@44081
   187
  apply (fast intro: eventually_True)
huffman@44081
   188
  apply clarify
huffman@44081
   189
  apply (intro exI conjI)
huffman@44081
   190
  apply (erule (1) eventually_conj)
huffman@44081
   191
  apply (erule (1) eventually_conj)
huffman@44081
   192
  apply simp
huffman@44081
   193
  apply auto
huffman@44081
   194
  done
huffman@36630
   195
huffman@36630
   196
lemma eventually_Sup:
huffman@44195
   197
  "eventually P (Sup S) \<longleftrightarrow> (\<forall>F\<in>S. eventually P F)"
huffman@44081
   198
  unfolding Sup_filter_def
huffman@44081
   199
  apply (rule eventually_Abs_filter, rule is_filter.intro)
huffman@44081
   200
  apply (auto intro: eventually_conj elim!: eventually_rev_mp)
huffman@44081
   201
  done
huffman@36630
   202
huffman@36360
   203
instance proof
huffman@44195
   204
  fix F F' F'' :: "'a filter" and S :: "'a filter set"
huffman@44195
   205
  { show "F < F' \<longleftrightarrow> F \<le> F' \<and> \<not> F' \<le> F"
huffman@44195
   206
    by (rule less_filter_def) }
huffman@44195
   207
  { show "F \<le> F"
huffman@44195
   208
    unfolding le_filter_def by simp }
huffman@44195
   209
  { assume "F \<le> F'" and "F' \<le> F''" thus "F \<le> F''"
huffman@44195
   210
    unfolding le_filter_def by simp }
huffman@44195
   211
  { assume "F \<le> F'" and "F' \<le> F" thus "F = F'"
huffman@44195
   212
    unfolding le_filter_def filter_eq_iff by fast }
huffman@44195
   213
  { show "F \<le> top"
huffman@44195
   214
    unfolding le_filter_def eventually_top by (simp add: always_eventually) }
huffman@44195
   215
  { show "bot \<le> F"
huffman@44195
   216
    unfolding le_filter_def by simp }
huffman@44195
   217
  { show "F \<le> sup F F'" and "F' \<le> sup F F'"
huffman@44195
   218
    unfolding le_filter_def eventually_sup by simp_all }
huffman@44195
   219
  { assume "F \<le> F''" and "F' \<le> F''" thus "sup F F' \<le> F''"
huffman@44195
   220
    unfolding le_filter_def eventually_sup by simp }
huffman@44195
   221
  { show "inf F F' \<le> F" and "inf F F' \<le> F'"
huffman@44195
   222
    unfolding le_filter_def eventually_inf by (auto intro: eventually_True) }
huffman@44195
   223
  { assume "F \<le> F'" and "F \<le> F''" thus "F \<le> inf F' F''"
huffman@44081
   224
    unfolding le_filter_def eventually_inf
huffman@44195
   225
    by (auto elim!: eventually_mono intro: eventually_conj) }
huffman@44195
   226
  { assume "F \<in> S" thus "F \<le> Sup S"
huffman@44195
   227
    unfolding le_filter_def eventually_Sup by simp }
huffman@44195
   228
  { assume "\<And>F. F \<in> S \<Longrightarrow> F \<le> F'" thus "Sup S \<le> F'"
huffman@44195
   229
    unfolding le_filter_def eventually_Sup by simp }
huffman@44195
   230
  { assume "F'' \<in> S" thus "Inf S \<le> F''"
huffman@44195
   231
    unfolding le_filter_def Inf_filter_def eventually_Sup Ball_def by simp }
huffman@44195
   232
  { assume "\<And>F'. F' \<in> S \<Longrightarrow> F \<le> F'" thus "F \<le> Inf S"
huffman@44195
   233
    unfolding le_filter_def Inf_filter_def eventually_Sup Ball_def by simp }
huffman@36360
   234
qed
huffman@36360
   235
huffman@36360
   236
end
huffman@36360
   237
huffman@44081
   238
lemma filter_leD:
huffman@44195
   239
  "F \<le> F' \<Longrightarrow> eventually P F' \<Longrightarrow> eventually P F"
huffman@44081
   240
  unfolding le_filter_def by simp
huffman@36360
   241
huffman@44081
   242
lemma filter_leI:
huffman@44195
   243
  "(\<And>P. eventually P F' \<Longrightarrow> eventually P F) \<Longrightarrow> F \<le> F'"
huffman@44081
   244
  unfolding le_filter_def by simp
huffman@36360
   245
huffman@36360
   246
lemma eventually_False:
huffman@44195
   247
  "eventually (\<lambda>x. False) F \<longleftrightarrow> F = bot"
huffman@44081
   248
  unfolding filter_eq_iff by (auto elim: eventually_rev_mp)
huffman@36360
   249
huffman@44342
   250
abbreviation (input) trivial_limit :: "'a filter \<Rightarrow> bool"
huffman@44342
   251
  where "trivial_limit F \<equiv> F = bot"
huffman@44342
   252
huffman@44342
   253
lemma trivial_limit_def: "trivial_limit F \<longleftrightarrow> eventually (\<lambda>x. False) F"
huffman@44342
   254
  by (rule eventually_False [symmetric])
huffman@44342
   255
huffman@44342
   256
huffman@44081
   257
subsection {* Map function for filters *}
huffman@36654
   258
huffman@44081
   259
definition filtermap :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a filter \<Rightarrow> 'b filter"
huffman@44195
   260
  where "filtermap f F = Abs_filter (\<lambda>P. eventually (\<lambda>x. P (f x)) F)"
huffman@36654
   261
huffman@44081
   262
lemma eventually_filtermap:
huffman@44195
   263
  "eventually P (filtermap f F) = eventually (\<lambda>x. P (f x)) F"
huffman@44081
   264
  unfolding filtermap_def
huffman@44081
   265
  apply (rule eventually_Abs_filter)
huffman@44081
   266
  apply (rule is_filter.intro)
huffman@44081
   267
  apply (auto elim!: eventually_rev_mp)
huffman@44081
   268
  done
huffman@36654
   269
huffman@44195
   270
lemma filtermap_ident: "filtermap (\<lambda>x. x) F = F"
huffman@44081
   271
  by (simp add: filter_eq_iff eventually_filtermap)
huffman@36654
   272
huffman@44081
   273
lemma filtermap_filtermap:
huffman@44195
   274
  "filtermap f (filtermap g F) = filtermap (\<lambda>x. f (g x)) F"
huffman@44081
   275
  by (simp add: filter_eq_iff eventually_filtermap)
huffman@36654
   276
huffman@44195
   277
lemma filtermap_mono: "F \<le> F' \<Longrightarrow> filtermap f F \<le> filtermap f F'"
huffman@44081
   278
  unfolding le_filter_def eventually_filtermap by simp
huffman@44081
   279
huffman@44081
   280
lemma filtermap_bot [simp]: "filtermap f bot = bot"
huffman@44081
   281
  by (simp add: filter_eq_iff eventually_filtermap)
huffman@36654
   282
hoelzl@50330
   283
lemma filtermap_sup: "filtermap f (sup F1 F2) = sup (filtermap f F1) (filtermap f F2)"
hoelzl@50330
   284
  by (auto simp: filter_eq_iff eventually_filtermap eventually_sup)
hoelzl@50330
   285
hoelzl@50247
   286
subsection {* Order filters *}
huffman@31392
   287
hoelzl@50247
   288
definition at_top :: "('a::order) filter"
hoelzl@50247
   289
  where "at_top = Abs_filter (\<lambda>P. \<exists>k. \<forall>n\<ge>k. P n)"
huffman@31392
   290
hoelzl@50324
   291
lemma eventually_at_top_linorder: "eventually P at_top \<longleftrightarrow> (\<exists>N::'a::linorder. \<forall>n\<ge>N. P n)"
hoelzl@50247
   292
  unfolding at_top_def
huffman@44081
   293
proof (rule eventually_Abs_filter, rule is_filter.intro)
hoelzl@50247
   294
  fix P Q :: "'a \<Rightarrow> bool"
huffman@36662
   295
  assume "\<exists>i. \<forall>n\<ge>i. P n" and "\<exists>j. \<forall>n\<ge>j. Q n"
huffman@36662
   296
  then obtain i j where "\<forall>n\<ge>i. P n" and "\<forall>n\<ge>j. Q n" by auto
huffman@36662
   297
  then have "\<forall>n\<ge>max i j. P n \<and> Q n" by simp
huffman@36662
   298
  then show "\<exists>k. \<forall>n\<ge>k. P n \<and> Q n" ..
huffman@36662
   299
qed auto
huffman@36662
   300
hoelzl@50346
   301
lemma eventually_ge_at_top:
hoelzl@50346
   302
  "eventually (\<lambda>x. (c::_::linorder) \<le> x) at_top"
hoelzl@50346
   303
  unfolding eventually_at_top_linorder by auto
hoelzl@50346
   304
hoelzl@50324
   305
lemma eventually_at_top_dense: "eventually P at_top \<longleftrightarrow> (\<exists>N::'a::dense_linorder. \<forall>n>N. P n)"
hoelzl@50247
   306
  unfolding eventually_at_top_linorder
hoelzl@50247
   307
proof safe
hoelzl@50247
   308
  fix N assume "\<forall>n\<ge>N. P n" then show "\<exists>N. \<forall>n>N. P n" by (auto intro!: exI[of _ N])
hoelzl@50247
   309
next
hoelzl@50324
   310
  fix N assume "\<forall>n>N. P n"
hoelzl@50247
   311
  moreover from gt_ex[of N] guess y ..
hoelzl@50247
   312
  ultimately show "\<exists>N. \<forall>n\<ge>N. P n" by (auto intro!: exI[of _ y])
hoelzl@50247
   313
qed
hoelzl@50247
   314
hoelzl@50346
   315
lemma eventually_gt_at_top:
hoelzl@50346
   316
  "eventually (\<lambda>x. (c::_::dense_linorder) < x) at_top"
hoelzl@50346
   317
  unfolding eventually_at_top_dense by auto
hoelzl@50346
   318
hoelzl@50247
   319
definition at_bot :: "('a::order) filter"
hoelzl@50247
   320
  where "at_bot = Abs_filter (\<lambda>P. \<exists>k. \<forall>n\<le>k. P n)"
hoelzl@50247
   321
hoelzl@50247
   322
lemma eventually_at_bot_linorder:
hoelzl@50247
   323
  fixes P :: "'a::linorder \<Rightarrow> bool" shows "eventually P at_bot \<longleftrightarrow> (\<exists>N. \<forall>n\<le>N. P n)"
hoelzl@50247
   324
  unfolding at_bot_def
hoelzl@50247
   325
proof (rule eventually_Abs_filter, rule is_filter.intro)
hoelzl@50247
   326
  fix P Q :: "'a \<Rightarrow> bool"
hoelzl@50247
   327
  assume "\<exists>i. \<forall>n\<le>i. P n" and "\<exists>j. \<forall>n\<le>j. Q n"
hoelzl@50247
   328
  then obtain i j where "\<forall>n\<le>i. P n" and "\<forall>n\<le>j. Q n" by auto
hoelzl@50247
   329
  then have "\<forall>n\<le>min i j. P n \<and> Q n" by simp
hoelzl@50247
   330
  then show "\<exists>k. \<forall>n\<le>k. P n \<and> Q n" ..
hoelzl@50247
   331
qed auto
hoelzl@50247
   332
hoelzl@50346
   333
lemma eventually_le_at_bot:
hoelzl@50346
   334
  "eventually (\<lambda>x. x \<le> (c::_::linorder)) at_bot"
hoelzl@50346
   335
  unfolding eventually_at_bot_linorder by auto
hoelzl@50346
   336
hoelzl@50247
   337
lemma eventually_at_bot_dense:
hoelzl@50247
   338
  fixes P :: "'a::dense_linorder \<Rightarrow> bool" shows "eventually P at_bot \<longleftrightarrow> (\<exists>N. \<forall>n<N. P n)"
hoelzl@50247
   339
  unfolding eventually_at_bot_linorder
hoelzl@50247
   340
proof safe
hoelzl@50247
   341
  fix N assume "\<forall>n\<le>N. P n" then show "\<exists>N. \<forall>n<N. P n" by (auto intro!: exI[of _ N])
hoelzl@50247
   342
next
hoelzl@50247
   343
  fix N assume "\<forall>n<N. P n" 
hoelzl@50247
   344
  moreover from lt_ex[of N] guess y ..
hoelzl@50247
   345
  ultimately show "\<exists>N. \<forall>n\<le>N. P n" by (auto intro!: exI[of _ y])
hoelzl@50247
   346
qed
hoelzl@50247
   347
hoelzl@50346
   348
lemma eventually_gt_at_bot:
hoelzl@50346
   349
  "eventually (\<lambda>x. x < (c::_::dense_linorder)) at_bot"
hoelzl@50346
   350
  unfolding eventually_at_bot_dense by auto
hoelzl@50346
   351
hoelzl@50247
   352
subsection {* Sequentially *}
hoelzl@50247
   353
hoelzl@50247
   354
abbreviation sequentially :: "nat filter"
hoelzl@50247
   355
  where "sequentially == at_top"
hoelzl@50247
   356
hoelzl@50247
   357
lemma sequentially_def: "sequentially = Abs_filter (\<lambda>P. \<exists>k. \<forall>n\<ge>k. P n)"
hoelzl@50247
   358
  unfolding at_top_def by simp
hoelzl@50247
   359
hoelzl@50247
   360
lemma eventually_sequentially:
hoelzl@50247
   361
  "eventually P sequentially \<longleftrightarrow> (\<exists>N. \<forall>n\<ge>N. P n)"
hoelzl@50247
   362
  by (rule eventually_at_top_linorder)
hoelzl@50247
   363
huffman@44342
   364
lemma sequentially_bot [simp, intro]: "sequentially \<noteq> bot"
huffman@44081
   365
  unfolding filter_eq_iff eventually_sequentially by auto
huffman@36662
   366
huffman@44342
   367
lemmas trivial_limit_sequentially = sequentially_bot
huffman@44342
   368
huffman@36662
   369
lemma eventually_False_sequentially [simp]:
huffman@36662
   370
  "\<not> eventually (\<lambda>n. False) sequentially"
huffman@44081
   371
  by (simp add: eventually_False)
huffman@36662
   372
huffman@36662
   373
lemma le_sequentially:
huffman@44195
   374
  "F \<le> sequentially \<longleftrightarrow> (\<forall>N. eventually (\<lambda>n. N \<le> n) F)"
huffman@44081
   375
  unfolding le_filter_def eventually_sequentially
huffman@44081
   376
  by (safe, fast, drule_tac x=N in spec, auto elim: eventually_rev_mp)
huffman@36662
   377
noschinl@45892
   378
lemma eventually_sequentiallyI:
noschinl@45892
   379
  assumes "\<And>x. c \<le> x \<Longrightarrow> P x"
noschinl@45892
   380
  shows "eventually P sequentially"
noschinl@45892
   381
using assms by (auto simp: eventually_sequentially)
noschinl@45892
   382
huffman@36662
   383
huffman@44081
   384
subsection {* Standard filters *}
huffman@36662
   385
huffman@44081
   386
definition within :: "'a filter \<Rightarrow> 'a set \<Rightarrow> 'a filter" (infixr "within" 70)
huffman@44195
   387
  where "F within S = Abs_filter (\<lambda>P. eventually (\<lambda>x. x \<in> S \<longrightarrow> P x) F)"
huffman@31392
   388
huffman@44206
   389
definition (in topological_space) nhds :: "'a \<Rightarrow> 'a filter"
huffman@44081
   390
  where "nhds a = Abs_filter (\<lambda>P. \<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
huffman@36654
   391
huffman@44206
   392
definition (in topological_space) at :: "'a \<Rightarrow> 'a filter"
huffman@44081
   393
  where "at a = nhds a within - {a}"
huffman@31447
   394
hoelzl@50326
   395
abbreviation at_right :: "'a\<Colon>{topological_space, order} \<Rightarrow> 'a filter" where
hoelzl@50326
   396
  "at_right x \<equiv> at x within {x <..}"
hoelzl@50326
   397
hoelzl@50326
   398
abbreviation at_left :: "'a\<Colon>{topological_space, order} \<Rightarrow> 'a filter" where
hoelzl@50326
   399
  "at_left x \<equiv> at x within {..< x}"
hoelzl@50326
   400
hoelzl@50324
   401
definition at_infinity :: "'a::real_normed_vector filter" where
hoelzl@50324
   402
  "at_infinity = Abs_filter (\<lambda>P. \<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x)"
hoelzl@50324
   403
huffman@31392
   404
lemma eventually_within:
huffman@44195
   405
  "eventually P (F within S) = eventually (\<lambda>x. x \<in> S \<longrightarrow> P x) F"
huffman@44081
   406
  unfolding within_def
huffman@44081
   407
  by (rule eventually_Abs_filter, rule is_filter.intro)
huffman@44081
   408
     (auto elim!: eventually_rev_mp)
huffman@31392
   409
huffman@45031
   410
lemma within_UNIV [simp]: "F within UNIV = F"
huffman@45031
   411
  unfolding filter_eq_iff eventually_within by simp
huffman@45031
   412
huffman@45031
   413
lemma within_empty [simp]: "F within {} = bot"
huffman@44081
   414
  unfolding filter_eq_iff eventually_within by simp
huffman@36360
   415
hoelzl@50347
   416
lemma within_within_eq: "(F within S) within T = F within (S \<inter> T)"
hoelzl@50347
   417
  by (auto simp: filter_eq_iff eventually_within elim: eventually_elim1)
hoelzl@50347
   418
hoelzl@50347
   419
lemma at_within_eq: "at x within T = nhds x within (T - {x})"
hoelzl@50347
   420
  unfolding at_def within_within_eq by (simp add: ac_simps Diff_eq)
hoelzl@50347
   421
hoelzl@50247
   422
lemma within_le: "F within S \<le> F"
hoelzl@50247
   423
  unfolding le_filter_def eventually_within by (auto elim: eventually_elim1)
hoelzl@50247
   424
hoelzl@50323
   425
lemma le_withinI: "F \<le> F' \<Longrightarrow> eventually (\<lambda>x. x \<in> S) F \<Longrightarrow> F \<le> F' within S"
hoelzl@50323
   426
  unfolding le_filter_def eventually_within by (auto elim: eventually_elim2)
hoelzl@50323
   427
hoelzl@50323
   428
lemma le_within_iff: "eventually (\<lambda>x. x \<in> S) F \<Longrightarrow> F \<le> F' within S \<longleftrightarrow> F \<le> F'"
hoelzl@50323
   429
  by (blast intro: within_le le_withinI order_trans)
hoelzl@50323
   430
huffman@36654
   431
lemma eventually_nhds:
huffman@36654
   432
  "eventually P (nhds a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
huffman@36654
   433
unfolding nhds_def
huffman@44081
   434
proof (rule eventually_Abs_filter, rule is_filter.intro)
huffman@36654
   435
  have "open UNIV \<and> a \<in> UNIV \<and> (\<forall>x\<in>UNIV. True)" by simp
hoelzl@50324
   436
  thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. True)" ..
huffman@36358
   437
next
huffman@36358
   438
  fix P Q
huffman@36654
   439
  assume "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
huffman@36654
   440
     and "\<exists>T. open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)"
huffman@36358
   441
  then obtain S T where
huffman@36654
   442
    "open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
huffman@36654
   443
    "open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)" by auto
huffman@36654
   444
  hence "open (S \<inter> T) \<and> a \<in> S \<inter> T \<and> (\<forall>x\<in>(S \<inter> T). P x \<and> Q x)"
huffman@36358
   445
    by (simp add: open_Int)
hoelzl@50324
   446
  thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x \<and> Q x)" ..
huffman@36358
   447
qed auto
huffman@31447
   448
huffman@36656
   449
lemma eventually_nhds_metric:
huffman@36656
   450
  "eventually P (nhds a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. dist x a < d \<longrightarrow> P x)"
huffman@36656
   451
unfolding eventually_nhds open_dist
huffman@31447
   452
apply safe
huffman@31447
   453
apply fast
huffman@31492
   454
apply (rule_tac x="{x. dist x a < d}" in exI, simp)
huffman@31447
   455
apply clarsimp
huffman@31447
   456
apply (rule_tac x="d - dist x a" in exI, clarsimp)
huffman@31447
   457
apply (simp only: less_diff_eq)
huffman@31447
   458
apply (erule le_less_trans [OF dist_triangle])
huffman@31447
   459
done
huffman@31447
   460
huffman@44571
   461
lemma nhds_neq_bot [simp]: "nhds a \<noteq> bot"
huffman@44571
   462
  unfolding trivial_limit_def eventually_nhds by simp
huffman@44571
   463
huffman@36656
   464
lemma eventually_at_topological:
huffman@36656
   465
  "eventually P (at a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. x \<noteq> a \<longrightarrow> P x))"
huffman@36656
   466
unfolding at_def eventually_within eventually_nhds by simp
huffman@36656
   467
huffman@36656
   468
lemma eventually_at:
huffman@36656
   469
  fixes a :: "'a::metric_space"
huffman@36656
   470
  shows "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> P x)"
huffman@36656
   471
unfolding at_def eventually_within eventually_nhds_metric by auto
huffman@36656
   472
hoelzl@50327
   473
lemma eventually_within_less: (* COPY FROM Topo/eventually_within *)
hoelzl@50327
   474
  "eventually P (at a within S) \<longleftrightarrow> (\<exists>d>0. \<forall>x\<in>S. 0 < dist x a \<and> dist x a < d \<longrightarrow> P x)"
hoelzl@50327
   475
  unfolding eventually_within eventually_at dist_nz by auto
hoelzl@50327
   476
hoelzl@50327
   477
lemma eventually_within_le: (* COPY FROM Topo/eventually_within_le *)
hoelzl@50327
   478
  "eventually P (at a within S) \<longleftrightarrow> (\<exists>d>0. \<forall>x\<in>S. 0 < dist x a \<and> dist x a <= d \<longrightarrow> P x)"
hoelzl@50327
   479
  unfolding eventually_within_less by auto (metis dense order_le_less_trans)
hoelzl@50327
   480
huffman@44571
   481
lemma at_eq_bot_iff: "at a = bot \<longleftrightarrow> open {a}"
huffman@44571
   482
  unfolding trivial_limit_def eventually_at_topological
huffman@44571
   483
  by (safe, case_tac "S = {a}", simp, fast, fast)
huffman@44571
   484
huffman@44571
   485
lemma at_neq_bot [simp]: "at (a::'a::perfect_space) \<noteq> bot"
huffman@44571
   486
  by (simp add: at_eq_bot_iff not_open_singleton)
huffman@44571
   487
hoelzl@50331
   488
lemma trivial_limit_at_left_real [simp]: (* maybe generalize type *)
hoelzl@50331
   489
  "\<not> trivial_limit (at_left (x::real))"
hoelzl@50331
   490
  unfolding trivial_limit_def eventually_within_le
hoelzl@50331
   491
  apply clarsimp
hoelzl@50331
   492
  apply (rule_tac x="x - d/2" in bexI)
hoelzl@50331
   493
  apply (auto simp: dist_real_def)
hoelzl@50331
   494
  done
hoelzl@50331
   495
hoelzl@50331
   496
lemma trivial_limit_at_right_real [simp]: (* maybe generalize type *)
hoelzl@50331
   497
  "\<not> trivial_limit (at_right (x::real))"
hoelzl@50331
   498
  unfolding trivial_limit_def eventually_within_le
hoelzl@50331
   499
  apply clarsimp
hoelzl@50331
   500
  apply (rule_tac x="x + d/2" in bexI)
hoelzl@50331
   501
  apply (auto simp: dist_real_def)
hoelzl@50331
   502
  done
hoelzl@50331
   503
hoelzl@50324
   504
lemma eventually_at_infinity:
hoelzl@50325
   505
  "eventually P at_infinity \<longleftrightarrow> (\<exists>b. \<forall>x. b \<le> norm x \<longrightarrow> P x)"
hoelzl@50324
   506
unfolding at_infinity_def
hoelzl@50324
   507
proof (rule eventually_Abs_filter, rule is_filter.intro)
hoelzl@50324
   508
  fix P Q :: "'a \<Rightarrow> bool"
hoelzl@50324
   509
  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
   510
  then obtain r s where
hoelzl@50324
   511
    "\<forall>x. r \<le> norm x \<longrightarrow> P x" and "\<forall>x. s \<le> norm x \<longrightarrow> Q x" by auto
hoelzl@50324
   512
  then have "\<forall>x. max r s \<le> norm x \<longrightarrow> P x \<and> Q x" by simp
hoelzl@50324
   513
  then show "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x \<and> Q x" ..
hoelzl@50324
   514
qed auto
huffman@31392
   515
hoelzl@50325
   516
lemma at_infinity_eq_at_top_bot:
hoelzl@50325
   517
  "(at_infinity \<Colon> real filter) = sup at_top at_bot"
hoelzl@50325
   518
  unfolding sup_filter_def at_infinity_def eventually_at_top_linorder eventually_at_bot_linorder
hoelzl@50325
   519
proof (intro arg_cong[where f=Abs_filter] ext iffI)
hoelzl@50325
   520
  fix P :: "real \<Rightarrow> bool" assume "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x"
hoelzl@50325
   521
  then guess r ..
hoelzl@50325
   522
  then have "(\<forall>x\<ge>r. P x) \<and> (\<forall>x\<le>-r. P x)" by auto
hoelzl@50325
   523
  then show "(\<exists>r. \<forall>x\<ge>r. P x) \<and> (\<exists>r. \<forall>x\<le>r. P x)" by auto
hoelzl@50325
   524
next
hoelzl@50325
   525
  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
   526
  then obtain p q where "\<forall>x\<ge>p. P x" "\<forall>x\<le>q. P x" by auto
hoelzl@50325
   527
  then show "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x"
hoelzl@50325
   528
    by (intro exI[of _ "max p (-q)"])
hoelzl@50325
   529
       (auto simp: abs_real_def)
hoelzl@50325
   530
qed
hoelzl@50325
   531
hoelzl@50325
   532
lemma at_top_le_at_infinity:
hoelzl@50325
   533
  "at_top \<le> (at_infinity :: real filter)"
hoelzl@50325
   534
  unfolding at_infinity_eq_at_top_bot by simp
hoelzl@50325
   535
hoelzl@50325
   536
lemma at_bot_le_at_infinity:
hoelzl@50325
   537
  "at_bot \<le> (at_infinity :: real filter)"
hoelzl@50325
   538
  unfolding at_infinity_eq_at_top_bot by simp
hoelzl@50325
   539
huffman@31355
   540
subsection {* Boundedness *}
huffman@31355
   541
huffman@44081
   542
definition Bfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
   543
  where "Bfun f F = (\<exists>K>0. eventually (\<lambda>x. norm (f x) \<le> K) F)"
huffman@31355
   544
huffman@31487
   545
lemma BfunI:
huffman@44195
   546
  assumes K: "eventually (\<lambda>x. norm (f x) \<le> K) F" shows "Bfun f F"
huffman@31355
   547
unfolding Bfun_def
huffman@31355
   548
proof (intro exI conjI allI)
huffman@31355
   549
  show "0 < max K 1" by simp
huffman@31355
   550
next
huffman@44195
   551
  show "eventually (\<lambda>x. norm (f x) \<le> max K 1) F"
huffman@31355
   552
    using K by (rule eventually_elim1, simp)
huffman@31355
   553
qed
huffman@31355
   554
huffman@31355
   555
lemma BfunE:
huffman@44195
   556
  assumes "Bfun f F"
huffman@44195
   557
  obtains B where "0 < B" and "eventually (\<lambda>x. norm (f x) \<le> B) F"
huffman@31355
   558
using assms unfolding Bfun_def by fast
huffman@31355
   559
huffman@31355
   560
huffman@31349
   561
subsection {* Convergence to Zero *}
huffman@31349
   562
huffman@44081
   563
definition Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
   564
  where "Zfun f F = (\<forall>r>0. eventually (\<lambda>x. norm (f x) < r) F)"
huffman@31349
   565
huffman@31349
   566
lemma ZfunI:
huffman@44195
   567
  "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F) \<Longrightarrow> Zfun f F"
huffman@44081
   568
  unfolding Zfun_def by simp
huffman@31349
   569
huffman@31349
   570
lemma ZfunD:
huffman@44195
   571
  "\<lbrakk>Zfun f F; 0 < r\<rbrakk> \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F"
huffman@44081
   572
  unfolding Zfun_def by simp
huffman@31349
   573
huffman@31355
   574
lemma Zfun_ssubst:
huffman@44195
   575
  "eventually (\<lambda>x. f x = g x) F \<Longrightarrow> Zfun g F \<Longrightarrow> Zfun f F"
huffman@44081
   576
  unfolding Zfun_def by (auto elim!: eventually_rev_mp)
huffman@31355
   577
huffman@44195
   578
lemma Zfun_zero: "Zfun (\<lambda>x. 0) F"
huffman@44081
   579
  unfolding Zfun_def by simp
huffman@31349
   580
huffman@44195
   581
lemma Zfun_norm_iff: "Zfun (\<lambda>x. norm (f x)) F = Zfun (\<lambda>x. f x) F"
huffman@44081
   582
  unfolding Zfun_def by simp
huffman@31349
   583
huffman@31349
   584
lemma Zfun_imp_Zfun:
huffman@44195
   585
  assumes f: "Zfun f F"
huffman@44195
   586
  assumes g: "eventually (\<lambda>x. norm (g x) \<le> norm (f x) * K) F"
huffman@44195
   587
  shows "Zfun (\<lambda>x. g x) F"
huffman@31349
   588
proof (cases)
huffman@31349
   589
  assume K: "0 < K"
huffman@31349
   590
  show ?thesis
huffman@31349
   591
  proof (rule ZfunI)
huffman@31349
   592
    fix r::real assume "0 < r"
huffman@31349
   593
    hence "0 < r / K"
huffman@31349
   594
      using K by (rule divide_pos_pos)
huffman@44195
   595
    then have "eventually (\<lambda>x. norm (f x) < r / K) F"
huffman@31487
   596
      using ZfunD [OF f] by fast
huffman@44195
   597
    with g show "eventually (\<lambda>x. norm (g x) < r) F"
noschinl@46887
   598
    proof eventually_elim
noschinl@46887
   599
      case (elim x)
huffman@31487
   600
      hence "norm (f x) * K < r"
huffman@31349
   601
        by (simp add: pos_less_divide_eq K)
noschinl@46887
   602
      thus ?case
noschinl@46887
   603
        by (simp add: order_le_less_trans [OF elim(1)])
huffman@31349
   604
    qed
huffman@31349
   605
  qed
huffman@31349
   606
next
huffman@31349
   607
  assume "\<not> 0 < K"
huffman@31349
   608
  hence K: "K \<le> 0" by (simp only: not_less)
huffman@31355
   609
  show ?thesis
huffman@31355
   610
  proof (rule ZfunI)
huffman@31355
   611
    fix r :: real
huffman@31355
   612
    assume "0 < r"
huffman@44195
   613
    from g show "eventually (\<lambda>x. norm (g x) < r) F"
noschinl@46887
   614
    proof eventually_elim
noschinl@46887
   615
      case (elim x)
noschinl@46887
   616
      also have "norm (f x) * K \<le> norm (f x) * 0"
huffman@31355
   617
        using K norm_ge_zero by (rule mult_left_mono)
noschinl@46887
   618
      finally show ?case
huffman@31355
   619
        using `0 < r` by simp
huffman@31355
   620
    qed
huffman@31355
   621
  qed
huffman@31349
   622
qed
huffman@31349
   623
huffman@44195
   624
lemma Zfun_le: "\<lbrakk>Zfun g F; \<forall>x. norm (f x) \<le> norm (g x)\<rbrakk> \<Longrightarrow> Zfun f F"
huffman@44081
   625
  by (erule_tac K="1" in Zfun_imp_Zfun, simp)
huffman@31349
   626
huffman@31349
   627
lemma Zfun_add:
huffman@44195
   628
  assumes f: "Zfun f F" and g: "Zfun g F"
huffman@44195
   629
  shows "Zfun (\<lambda>x. f x + g x) F"
huffman@31349
   630
proof (rule ZfunI)
huffman@31349
   631
  fix r::real assume "0 < r"
huffman@31349
   632
  hence r: "0 < r / 2" by simp
huffman@44195
   633
  have "eventually (\<lambda>x. norm (f x) < r/2) F"
huffman@31487
   634
    using f r by (rule ZfunD)
huffman@31349
   635
  moreover
huffman@44195
   636
  have "eventually (\<lambda>x. norm (g x) < r/2) F"
huffman@31487
   637
    using g r by (rule ZfunD)
huffman@31349
   638
  ultimately
huffman@44195
   639
  show "eventually (\<lambda>x. norm (f x + g x) < r) F"
noschinl@46887
   640
  proof eventually_elim
noschinl@46887
   641
    case (elim x)
huffman@31487
   642
    have "norm (f x + g x) \<le> norm (f x) + norm (g x)"
huffman@31349
   643
      by (rule norm_triangle_ineq)
huffman@31349
   644
    also have "\<dots> < r/2 + r/2"
noschinl@46887
   645
      using elim by (rule add_strict_mono)
noschinl@46887
   646
    finally show ?case
huffman@31349
   647
      by simp
huffman@31349
   648
  qed
huffman@31349
   649
qed
huffman@31349
   650
huffman@44195
   651
lemma Zfun_minus: "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. - f x) F"
huffman@44081
   652
  unfolding Zfun_def by simp
huffman@31349
   653
huffman@44195
   654
lemma Zfun_diff: "\<lbrakk>Zfun f F; Zfun g F\<rbrakk> \<Longrightarrow> Zfun (\<lambda>x. f x - g x) F"
huffman@44081
   655
  by (simp only: diff_minus Zfun_add Zfun_minus)
huffman@31349
   656
huffman@31349
   657
lemma (in bounded_linear) Zfun:
huffman@44195
   658
  assumes g: "Zfun g F"
huffman@44195
   659
  shows "Zfun (\<lambda>x. f (g x)) F"
huffman@31349
   660
proof -
huffman@31349
   661
  obtain K where "\<And>x. norm (f x) \<le> norm x * K"
huffman@31349
   662
    using bounded by fast
huffman@44195
   663
  then have "eventually (\<lambda>x. norm (f (g x)) \<le> norm (g x) * K) F"
huffman@31355
   664
    by simp
huffman@31487
   665
  with g show ?thesis
huffman@31349
   666
    by (rule Zfun_imp_Zfun)
huffman@31349
   667
qed
huffman@31349
   668
huffman@31349
   669
lemma (in bounded_bilinear) Zfun:
huffman@44195
   670
  assumes f: "Zfun f F"
huffman@44195
   671
  assumes g: "Zfun g F"
huffman@44195
   672
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31349
   673
proof (rule ZfunI)
huffman@31349
   674
  fix r::real assume r: "0 < r"
huffman@31349
   675
  obtain K where K: "0 < K"
huffman@31349
   676
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31349
   677
    using pos_bounded by fast
huffman@31349
   678
  from K have K': "0 < inverse K"
huffman@31349
   679
    by (rule positive_imp_inverse_positive)
huffman@44195
   680
  have "eventually (\<lambda>x. norm (f x) < r) F"
huffman@31487
   681
    using f r by (rule ZfunD)
huffman@31349
   682
  moreover
huffman@44195
   683
  have "eventually (\<lambda>x. norm (g x) < inverse K) F"
huffman@31487
   684
    using g K' by (rule ZfunD)
huffman@31349
   685
  ultimately
huffman@44195
   686
  show "eventually (\<lambda>x. norm (f x ** g x) < r) F"
noschinl@46887
   687
  proof eventually_elim
noschinl@46887
   688
    case (elim x)
huffman@31487
   689
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31349
   690
      by (rule norm_le)
huffman@31487
   691
    also have "norm (f x) * norm (g x) * K < r * inverse K * K"
noschinl@46887
   692
      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero elim K)
huffman@31349
   693
    also from K have "r * inverse K * K = r"
huffman@31349
   694
      by simp
noschinl@46887
   695
    finally show ?case .
huffman@31349
   696
  qed
huffman@31349
   697
qed
huffman@31349
   698
huffman@31349
   699
lemma (in bounded_bilinear) Zfun_left:
huffman@44195
   700
  "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. f x ** a) F"
huffman@44081
   701
  by (rule bounded_linear_left [THEN bounded_linear.Zfun])
huffman@31349
   702
huffman@31349
   703
lemma (in bounded_bilinear) Zfun_right:
huffman@44195
   704
  "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. a ** f x) F"
huffman@44081
   705
  by (rule bounded_linear_right [THEN bounded_linear.Zfun])
huffman@31349
   706
huffman@44282
   707
lemmas Zfun_mult = bounded_bilinear.Zfun [OF bounded_bilinear_mult]
huffman@44282
   708
lemmas Zfun_mult_right = bounded_bilinear.Zfun_right [OF bounded_bilinear_mult]
huffman@44282
   709
lemmas Zfun_mult_left = bounded_bilinear.Zfun_left [OF bounded_bilinear_mult]
huffman@31349
   710
huffman@31349
   711
wenzelm@31902
   712
subsection {* Limits *}
huffman@31349
   713
hoelzl@50322
   714
definition filterlim :: "('a \<Rightarrow> 'b) \<Rightarrow> 'b filter \<Rightarrow> 'a filter \<Rightarrow> bool" where
hoelzl@50322
   715
  "filterlim f F2 F1 \<longleftrightarrow> filtermap f F1 \<le> F2"
hoelzl@50247
   716
hoelzl@50247
   717
syntax
hoelzl@50247
   718
  "_LIM" :: "pttrns \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> bool" ("(3LIM (_)/ (_)./ (_) :> (_))" [1000, 10, 0, 10] 10)
hoelzl@50247
   719
hoelzl@50247
   720
translations
hoelzl@50322
   721
  "LIM x F1. f :> F2"   == "CONST filterlim (%x. f) F2 F1"
hoelzl@50247
   722
hoelzl@50325
   723
lemma filterlim_iff:
hoelzl@50325
   724
  "(LIM x F1. f x :> F2) \<longleftrightarrow> (\<forall>P. eventually P F2 \<longrightarrow> eventually (\<lambda>x. P (f x)) F1)"
hoelzl@50325
   725
  unfolding filterlim_def le_filter_def eventually_filtermap ..
hoelzl@50247
   726
hoelzl@50327
   727
lemma filterlim_compose:
hoelzl@50323
   728
  "filterlim g F3 F2 \<Longrightarrow> filterlim f F2 F1 \<Longrightarrow> filterlim (\<lambda>x. g (f x)) F3 F1"
hoelzl@50323
   729
  unfolding filterlim_def filtermap_filtermap[symmetric] by (metis filtermap_mono order_trans)
hoelzl@50323
   730
hoelzl@50327
   731
lemma filterlim_mono:
hoelzl@50323
   732
  "filterlim f F2 F1 \<Longrightarrow> F2 \<le> F2' \<Longrightarrow> F1' \<le> F1 \<Longrightarrow> filterlim f F2' F1'"
hoelzl@50323
   733
  unfolding filterlim_def by (metis filtermap_mono order_trans)
hoelzl@50323
   734
hoelzl@50327
   735
lemma filterlim_cong:
hoelzl@50327
   736
  "F1 = F1' \<Longrightarrow> F2 = F2' \<Longrightarrow> eventually (\<lambda>x. f x = g x) F2 \<Longrightarrow> filterlim f F1 F2 = filterlim g F1' F2'"
hoelzl@50327
   737
  by (auto simp: filterlim_def le_filter_def eventually_filtermap elim: eventually_elim2)
hoelzl@50327
   738
hoelzl@50325
   739
lemma filterlim_within:
hoelzl@50325
   740
  "(LIM x F1. f x :> F2 within S) \<longleftrightarrow> (eventually (\<lambda>x. f x \<in> S) F1 \<and> (LIM x F1. f x :> F2))"
hoelzl@50325
   741
  unfolding filterlim_def
hoelzl@50325
   742
proof safe
hoelzl@50325
   743
  assume "filtermap f F1 \<le> F2 within S" then show "eventually (\<lambda>x. f x \<in> S) F1"
hoelzl@50325
   744
    by (auto simp: le_filter_def eventually_filtermap eventually_within elim!: allE[of _ "\<lambda>x. x \<in> S"])
hoelzl@50325
   745
qed (auto intro: within_le order_trans simp: le_within_iff eventually_filtermap)
hoelzl@50325
   746
hoelzl@50330
   747
lemma filterlim_filtermap: "filterlim f F1 (filtermap g F2) = filterlim (\<lambda>x. f (g x)) F1 F2"
hoelzl@50330
   748
  unfolding filterlim_def filtermap_filtermap ..
hoelzl@50330
   749
hoelzl@50330
   750
lemma filterlim_sup:
hoelzl@50330
   751
  "filterlim f F F1 \<Longrightarrow> filterlim f F F2 \<Longrightarrow> filterlim f F (sup F1 F2)"
hoelzl@50330
   752
  unfolding filterlim_def filtermap_sup by auto
hoelzl@50330
   753
hoelzl@50331
   754
lemma filterlim_Suc: "filterlim Suc sequentially sequentially"
hoelzl@50331
   755
  by (simp add: filterlim_iff eventually_sequentially) (metis le_Suc_eq)
hoelzl@50331
   756
hoelzl@50247
   757
abbreviation (in topological_space)
huffman@44206
   758
  tendsto :: "('b \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'b filter \<Rightarrow> bool" (infixr "--->" 55) where
hoelzl@50322
   759
  "(f ---> l) F \<equiv> filterlim f (nhds l) F"
noschinl@45892
   760
wenzelm@31902
   761
ML {*
wenzelm@31902
   762
structure Tendsto_Intros = Named_Thms
wenzelm@31902
   763
(
wenzelm@45294
   764
  val name = @{binding tendsto_intros}
wenzelm@31902
   765
  val description = "introduction rules for tendsto"
wenzelm@31902
   766
)
huffman@31565
   767
*}
huffman@31565
   768
wenzelm@31902
   769
setup Tendsto_Intros.setup
huffman@31565
   770
hoelzl@50247
   771
lemma tendsto_def: "(f ---> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
hoelzl@50322
   772
  unfolding filterlim_def
hoelzl@50247
   773
proof safe
hoelzl@50247
   774
  fix S assume "open S" "l \<in> S" "filtermap f F \<le> nhds l"
hoelzl@50247
   775
  then show "eventually (\<lambda>x. f x \<in> S) F"
hoelzl@50247
   776
    unfolding eventually_nhds eventually_filtermap le_filter_def
hoelzl@50247
   777
    by (auto elim!: allE[of _ "\<lambda>x. x \<in> S"] eventually_rev_mp)
hoelzl@50247
   778
qed (auto elim!: eventually_rev_mp simp: eventually_nhds eventually_filtermap le_filter_def)
hoelzl@50247
   779
hoelzl@50325
   780
lemma filterlim_at:
hoelzl@50325
   781
  "(LIM x F. f x :> at b) \<longleftrightarrow> (eventually (\<lambda>x. f x \<noteq> b) F \<and> (f ---> b) F)"
hoelzl@50325
   782
  by (simp add: at_def filterlim_within)
hoelzl@50325
   783
huffman@44195
   784
lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f ---> l) F' \<Longrightarrow> (f ---> l) F"
huffman@44081
   785
  unfolding tendsto_def le_filter_def by fast
huffman@36656
   786
huffman@31488
   787
lemma topological_tendstoI:
huffman@44195
   788
  "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F)
huffman@44195
   789
    \<Longrightarrow> (f ---> l) F"
huffman@31349
   790
  unfolding tendsto_def by auto
huffman@31349
   791
huffman@31488
   792
lemma topological_tendstoD:
huffman@44195
   793
  "(f ---> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
huffman@31488
   794
  unfolding tendsto_def by auto
huffman@31488
   795
huffman@31488
   796
lemma tendstoI:
huffman@44195
   797
  assumes "\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
huffman@44195
   798
  shows "(f ---> l) F"
huffman@44081
   799
  apply (rule topological_tendstoI)
huffman@44081
   800
  apply (simp add: open_dist)
huffman@44081
   801
  apply (drule (1) bspec, clarify)
huffman@44081
   802
  apply (drule assms)
huffman@44081
   803
  apply (erule eventually_elim1, simp)
huffman@44081
   804
  done
huffman@31488
   805
huffman@31349
   806
lemma tendstoD:
huffman@44195
   807
  "(f ---> l) F \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
huffman@44081
   808
  apply (drule_tac S="{x. dist x l < e}" in topological_tendstoD)
huffman@44081
   809
  apply (clarsimp simp add: open_dist)
huffman@44081
   810
  apply (rule_tac x="e - dist x l" in exI, clarsimp)
huffman@44081
   811
  apply (simp only: less_diff_eq)
huffman@44081
   812
  apply (erule le_less_trans [OF dist_triangle])
huffman@44081
   813
  apply simp
huffman@44081
   814
  apply simp
huffman@44081
   815
  done
huffman@31488
   816
huffman@31488
   817
lemma tendsto_iff:
huffman@44195
   818
  "(f ---> l) F \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) F)"
huffman@44081
   819
  using tendstoI tendstoD by fast
huffman@31349
   820
huffman@44195
   821
lemma tendsto_Zfun_iff: "(f ---> a) F = Zfun (\<lambda>x. f x - a) F"
huffman@44081
   822
  by (simp only: tendsto_iff Zfun_def dist_norm)
huffman@31349
   823
huffman@45031
   824
lemma tendsto_bot [simp]: "(f ---> a) bot"
huffman@45031
   825
  unfolding tendsto_def by simp
huffman@45031
   826
huffman@31565
   827
lemma tendsto_ident_at [tendsto_intros]: "((\<lambda>x. x) ---> a) (at a)"
huffman@44081
   828
  unfolding tendsto_def eventually_at_topological by auto
huffman@31565
   829
huffman@31565
   830
lemma tendsto_ident_at_within [tendsto_intros]:
huffman@36655
   831
  "((\<lambda>x. x) ---> a) (at a within S)"
huffman@44081
   832
  unfolding tendsto_def eventually_within eventually_at_topological by auto
huffman@31565
   833
huffman@44195
   834
lemma tendsto_const [tendsto_intros]: "((\<lambda>x. k) ---> k) F"
huffman@44081
   835
  by (simp add: tendsto_def)
huffman@31349
   836
huffman@44205
   837
lemma tendsto_unique:
huffman@44205
   838
  fixes f :: "'a \<Rightarrow> 'b::t2_space"
huffman@44205
   839
  assumes "\<not> trivial_limit F" and "(f ---> a) F" and "(f ---> b) F"
huffman@44205
   840
  shows "a = b"
huffman@44205
   841
proof (rule ccontr)
huffman@44205
   842
  assume "a \<noteq> b"
huffman@44205
   843
  obtain U V where "open U" "open V" "a \<in> U" "b \<in> V" "U \<inter> V = {}"
huffman@44205
   844
    using hausdorff [OF `a \<noteq> b`] by fast
huffman@44205
   845
  have "eventually (\<lambda>x. f x \<in> U) F"
huffman@44205
   846
    using `(f ---> a) F` `open U` `a \<in> U` by (rule topological_tendstoD)
huffman@44205
   847
  moreover
huffman@44205
   848
  have "eventually (\<lambda>x. f x \<in> V) F"
huffman@44205
   849
    using `(f ---> b) F` `open V` `b \<in> V` by (rule topological_tendstoD)
huffman@44205
   850
  ultimately
huffman@44205
   851
  have "eventually (\<lambda>x. False) F"
noschinl@46887
   852
  proof eventually_elim
noschinl@46887
   853
    case (elim x)
huffman@44205
   854
    hence "f x \<in> U \<inter> V" by simp
noschinl@46887
   855
    with `U \<inter> V = {}` show ?case by simp
huffman@44205
   856
  qed
huffman@44205
   857
  with `\<not> trivial_limit F` show "False"
huffman@44205
   858
    by (simp add: trivial_limit_def)
huffman@44205
   859
qed
huffman@44205
   860
huffman@36662
   861
lemma tendsto_const_iff:
huffman@44205
   862
  fixes a b :: "'a::t2_space"
huffman@44205
   863
  assumes "\<not> trivial_limit F" shows "((\<lambda>x. a) ---> b) F \<longleftrightarrow> a = b"
huffman@44205
   864
  by (safe intro!: tendsto_const tendsto_unique [OF assms tendsto_const])
huffman@44205
   865
hoelzl@50323
   866
lemma tendsto_at_iff_tendsto_nhds:
hoelzl@50323
   867
  "(g ---> g l) (at l) \<longleftrightarrow> (g ---> g l) (nhds l)"
hoelzl@50323
   868
  unfolding tendsto_def at_def eventually_within
hoelzl@50323
   869
  by (intro ext all_cong imp_cong) (auto elim!: eventually_elim1)
hoelzl@50323
   870
huffman@44218
   871
lemma tendsto_compose:
hoelzl@50323
   872
  "(g ---> g l) (at l) \<Longrightarrow> (f ---> l) F \<Longrightarrow> ((\<lambda>x. g (f x)) ---> g l) F"
hoelzl@50323
   873
  unfolding tendsto_at_iff_tendsto_nhds by (rule filterlim_compose[of g])
huffman@44218
   874
huffman@44253
   875
lemma tendsto_compose_eventually:
hoelzl@50325
   876
  "(g ---> m) (at l) \<Longrightarrow> (f ---> l) F \<Longrightarrow> eventually (\<lambda>x. f x \<noteq> l) F \<Longrightarrow> ((\<lambda>x. g (f x)) ---> m) F"
hoelzl@50325
   877
  by (rule filterlim_compose[of g _ "at l"]) (auto simp add: filterlim_at)
huffman@44253
   878
huffman@44251
   879
lemma metric_tendsto_imp_tendsto:
huffman@44251
   880
  assumes f: "(f ---> a) F"
huffman@44251
   881
  assumes le: "eventually (\<lambda>x. dist (g x) b \<le> dist (f x) a) F"
huffman@44251
   882
  shows "(g ---> b) F"
huffman@44251
   883
proof (rule tendstoI)
huffman@44251
   884
  fix e :: real assume "0 < e"
huffman@44251
   885
  with f have "eventually (\<lambda>x. dist (f x) a < e) F" by (rule tendstoD)
huffman@44251
   886
  with le show "eventually (\<lambda>x. dist (g x) b < e) F"
huffman@44251
   887
    using le_less_trans by (rule eventually_elim2)
huffman@44251
   888
qed
huffman@44251
   889
huffman@44205
   890
subsubsection {* Distance and norms *}
huffman@36662
   891
huffman@31565
   892
lemma tendsto_dist [tendsto_intros]:
huffman@44195
   893
  assumes f: "(f ---> l) F" and g: "(g ---> m) F"
huffman@44195
   894
  shows "((\<lambda>x. dist (f x) (g x)) ---> dist l m) F"
huffman@31565
   895
proof (rule tendstoI)
huffman@31565
   896
  fix e :: real assume "0 < e"
huffman@31565
   897
  hence e2: "0 < e/2" by simp
huffman@31565
   898
  from tendstoD [OF f e2] tendstoD [OF g e2]
huffman@44195
   899
  show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) F"
noschinl@46887
   900
  proof (eventually_elim)
noschinl@46887
   901
    case (elim x)
huffman@31565
   902
    then show "dist (dist (f x) (g x)) (dist l m) < e"
huffman@31565
   903
      unfolding dist_real_def
huffman@31565
   904
      using dist_triangle2 [of "f x" "g x" "l"]
huffman@31565
   905
      using dist_triangle2 [of "g x" "l" "m"]
huffman@31565
   906
      using dist_triangle3 [of "l" "m" "f x"]
huffman@31565
   907
      using dist_triangle [of "f x" "m" "g x"]
huffman@31565
   908
      by arith
huffman@31565
   909
  qed
huffman@31565
   910
qed
huffman@31565
   911
huffman@36662
   912
lemma norm_conv_dist: "norm x = dist x 0"
huffman@44081
   913
  unfolding dist_norm by simp
huffman@36662
   914
huffman@31565
   915
lemma tendsto_norm [tendsto_intros]:
huffman@44195
   916
  "(f ---> a) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> norm a) F"
huffman@44081
   917
  unfolding norm_conv_dist by (intro tendsto_intros)
huffman@36662
   918
huffman@36662
   919
lemma tendsto_norm_zero:
huffman@44195
   920
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> 0) F"
huffman@44081
   921
  by (drule tendsto_norm, simp)
huffman@36662
   922
huffman@36662
   923
lemma tendsto_norm_zero_cancel:
huffman@44195
   924
  "((\<lambda>x. norm (f x)) ---> 0) F \<Longrightarrow> (f ---> 0) F"
huffman@44081
   925
  unfolding tendsto_iff dist_norm by simp
huffman@36662
   926
huffman@36662
   927
lemma tendsto_norm_zero_iff:
huffman@44195
   928
  "((\<lambda>x. norm (f x)) ---> 0) F \<longleftrightarrow> (f ---> 0) F"
huffman@44081
   929
  unfolding tendsto_iff dist_norm by simp
huffman@31349
   930
huffman@44194
   931
lemma tendsto_rabs [tendsto_intros]:
huffman@44195
   932
  "(f ---> (l::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> \<bar>l\<bar>) F"
huffman@44194
   933
  by (fold real_norm_def, rule tendsto_norm)
huffman@44194
   934
huffman@44194
   935
lemma tendsto_rabs_zero:
huffman@44195
   936
  "(f ---> (0::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> 0) F"
huffman@44194
   937
  by (fold real_norm_def, rule tendsto_norm_zero)
huffman@44194
   938
huffman@44194
   939
lemma tendsto_rabs_zero_cancel:
huffman@44195
   940
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<Longrightarrow> (f ---> 0) F"
huffman@44194
   941
  by (fold real_norm_def, rule tendsto_norm_zero_cancel)
huffman@44194
   942
huffman@44194
   943
lemma tendsto_rabs_zero_iff:
huffman@44195
   944
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<longleftrightarrow> (f ---> 0) F"
huffman@44194
   945
  by (fold real_norm_def, rule tendsto_norm_zero_iff)
huffman@44194
   946
huffman@44194
   947
subsubsection {* Addition and subtraction *}
huffman@44194
   948
huffman@31565
   949
lemma tendsto_add [tendsto_intros]:
huffman@31349
   950
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   951
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> a + b) F"
huffman@44081
   952
  by (simp only: tendsto_Zfun_iff add_diff_add Zfun_add)
huffman@31349
   953
huffman@44194
   954
lemma tendsto_add_zero:
huffman@44194
   955
  fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
huffman@44195
   956
  shows "\<lbrakk>(f ---> 0) F; (g ---> 0) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> 0) F"
huffman@44194
   957
  by (drule (1) tendsto_add, simp)
huffman@44194
   958
huffman@31565
   959
lemma tendsto_minus [tendsto_intros]:
huffman@31349
   960
  fixes a :: "'a::real_normed_vector"
huffman@44195
   961
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. - f x) ---> - a) F"
huffman@44081
   962
  by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
huffman@31349
   963
huffman@31349
   964
lemma tendsto_minus_cancel:
huffman@31349
   965
  fixes a :: "'a::real_normed_vector"
huffman@44195
   966
  shows "((\<lambda>x. - f x) ---> - a) F \<Longrightarrow> (f ---> a) F"
huffman@44081
   967
  by (drule tendsto_minus, simp)
huffman@31349
   968
hoelzl@50330
   969
lemma tendsto_minus_cancel_left:
hoelzl@50330
   970
    "(f ---> - (y::_::real_normed_vector)) F \<longleftrightarrow> ((\<lambda>x. - f x) ---> y) F"
hoelzl@50330
   971
  using tendsto_minus_cancel[of f "- y" F]  tendsto_minus[of f "- y" F]
hoelzl@50330
   972
  by auto
hoelzl@50330
   973
huffman@31565
   974
lemma tendsto_diff [tendsto_intros]:
huffman@31349
   975
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   976
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x - g x) ---> a - b) F"
huffman@44081
   977
  by (simp add: diff_minus tendsto_add tendsto_minus)
huffman@31349
   978
huffman@31588
   979
lemma tendsto_setsum [tendsto_intros]:
huffman@31588
   980
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
huffman@44195
   981
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> a i) F"
huffman@44195
   982
  shows "((\<lambda>x. \<Sum>i\<in>S. f i x) ---> (\<Sum>i\<in>S. a i)) F"
huffman@31588
   983
proof (cases "finite S")
huffman@31588
   984
  assume "finite S" thus ?thesis using assms
huffman@44194
   985
    by (induct, simp add: tendsto_const, simp add: tendsto_add)
huffman@31588
   986
next
huffman@31588
   987
  assume "\<not> finite S" thus ?thesis
huffman@31588
   988
    by (simp add: tendsto_const)
huffman@31588
   989
qed
huffman@31588
   990
noschinl@45892
   991
lemma real_tendsto_sandwich:
noschinl@45892
   992
  fixes f g h :: "'a \<Rightarrow> real"
noschinl@45892
   993
  assumes ev: "eventually (\<lambda>n. f n \<le> g n) net" "eventually (\<lambda>n. g n \<le> h n) net"
noschinl@45892
   994
  assumes lim: "(f ---> c) net" "(h ---> c) net"
noschinl@45892
   995
  shows "(g ---> c) net"
noschinl@45892
   996
proof -
noschinl@45892
   997
  have "((\<lambda>n. g n - f n) ---> 0) net"
noschinl@45892
   998
  proof (rule metric_tendsto_imp_tendsto)
noschinl@45892
   999
    show "eventually (\<lambda>n. dist (g n - f n) 0 \<le> dist (h n - f n) 0) net"
noschinl@45892
  1000
      using ev by (rule eventually_elim2) (simp add: dist_real_def)
noschinl@45892
  1001
    show "((\<lambda>n. h n - f n) ---> 0) net"
noschinl@45892
  1002
      using tendsto_diff[OF lim(2,1)] by simp
noschinl@45892
  1003
  qed
noschinl@45892
  1004
  from tendsto_add[OF this lim(1)] show ?thesis by simp
noschinl@45892
  1005
qed
noschinl@45892
  1006
huffman@44194
  1007
subsubsection {* Linear operators and multiplication *}
huffman@44194
  1008
huffman@44282
  1009
lemma (in bounded_linear) tendsto:
huffman@44195
  1010
  "(g ---> a) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> f a) F"
huffman@44081
  1011
  by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
huffman@31349
  1012
huffman@44194
  1013
lemma (in bounded_linear) tendsto_zero:
huffman@44195
  1014
  "(g ---> 0) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> 0) F"
huffman@44194
  1015
  by (drule tendsto, simp only: zero)
huffman@44194
  1016
huffman@44282
  1017
lemma (in bounded_bilinear) tendsto:
huffman@44195
  1018
  "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ** g x) ---> a ** b) F"
huffman@44081
  1019
  by (simp only: tendsto_Zfun_iff prod_diff_prod
huffman@44081
  1020
                 Zfun_add Zfun Zfun_left Zfun_right)
huffman@31349
  1021
huffman@44194
  1022
lemma (in bounded_bilinear) tendsto_zero:
huffman@44195
  1023
  assumes f: "(f ---> 0) F"
huffman@44195
  1024
  assumes g: "(g ---> 0) F"
huffman@44195
  1025
  shows "((\<lambda>x. f x ** g x) ---> 0) F"
huffman@44194
  1026
  using tendsto [OF f g] by (simp add: zero_left)
huffman@31355
  1027
huffman@44194
  1028
lemma (in bounded_bilinear) tendsto_left_zero:
huffman@44195
  1029
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. f x ** c) ---> 0) F"
huffman@44194
  1030
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_left])
huffman@44194
  1031
huffman@44194
  1032
lemma (in bounded_bilinear) tendsto_right_zero:
huffman@44195
  1033
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. c ** f x) ---> 0) F"
huffman@44194
  1034
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_right])
huffman@44194
  1035
huffman@44282
  1036
lemmas tendsto_of_real [tendsto_intros] =
huffman@44282
  1037
  bounded_linear.tendsto [OF bounded_linear_of_real]
huffman@44282
  1038
huffman@44282
  1039
lemmas tendsto_scaleR [tendsto_intros] =
huffman@44282
  1040
  bounded_bilinear.tendsto [OF bounded_bilinear_scaleR]
huffman@44282
  1041
huffman@44282
  1042
lemmas tendsto_mult [tendsto_intros] =
huffman@44282
  1043
  bounded_bilinear.tendsto [OF bounded_bilinear_mult]
huffman@44194
  1044
huffman@44568
  1045
lemmas tendsto_mult_zero =
huffman@44568
  1046
  bounded_bilinear.tendsto_zero [OF bounded_bilinear_mult]
huffman@44568
  1047
huffman@44568
  1048
lemmas tendsto_mult_left_zero =
huffman@44568
  1049
  bounded_bilinear.tendsto_left_zero [OF bounded_bilinear_mult]
huffman@44568
  1050
huffman@44568
  1051
lemmas tendsto_mult_right_zero =
huffman@44568
  1052
  bounded_bilinear.tendsto_right_zero [OF bounded_bilinear_mult]
huffman@44568
  1053
huffman@44194
  1054
lemma tendsto_power [tendsto_intros]:
huffman@44194
  1055
  fixes f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra}"
huffman@44195
  1056
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. f x ^ n) ---> a ^ n) F"
huffman@44194
  1057
  by (induct n) (simp_all add: tendsto_const tendsto_mult)
huffman@44194
  1058
huffman@44194
  1059
lemma tendsto_setprod [tendsto_intros]:
huffman@44194
  1060
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
huffman@44195
  1061
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> L i) F"
huffman@44195
  1062
  shows "((\<lambda>x. \<Prod>i\<in>S. f i x) ---> (\<Prod>i\<in>S. L i)) F"
huffman@44194
  1063
proof (cases "finite S")
huffman@44194
  1064
  assume "finite S" thus ?thesis using assms
huffman@44194
  1065
    by (induct, simp add: tendsto_const, simp add: tendsto_mult)
huffman@44194
  1066
next
huffman@44194
  1067
  assume "\<not> finite S" thus ?thesis
huffman@44194
  1068
    by (simp add: tendsto_const)
huffman@44194
  1069
qed
huffman@44194
  1070
hoelzl@50331
  1071
lemma tendsto_le_const:
hoelzl@50331
  1072
  fixes f :: "_ \<Rightarrow> real" 
hoelzl@50331
  1073
  assumes F: "\<not> trivial_limit F"
hoelzl@50331
  1074
  assumes x: "(f ---> x) F" and a: "eventually (\<lambda>x. a \<le> f x) F"
hoelzl@50331
  1075
  shows "a \<le> x"
hoelzl@50331
  1076
proof (rule ccontr)
hoelzl@50331
  1077
  assume "\<not> a \<le> x"
hoelzl@50331
  1078
  with x have "eventually (\<lambda>x. f x < a) F"
hoelzl@50331
  1079
    by (auto simp add: tendsto_def elim!: allE[of _ "{..< a}"])
hoelzl@50331
  1080
  with a have "eventually (\<lambda>x. False) F"
hoelzl@50331
  1081
    by eventually_elim auto
hoelzl@50331
  1082
  with F show False
hoelzl@50331
  1083
    by (simp add: eventually_False)
hoelzl@50331
  1084
qed
hoelzl@50331
  1085
hoelzl@50331
  1086
lemma tendsto_le:
hoelzl@50331
  1087
  fixes f g :: "_ \<Rightarrow> real" 
hoelzl@50331
  1088
  assumes F: "\<not> trivial_limit F"
hoelzl@50331
  1089
  assumes x: "(f ---> x) F" and y: "(g ---> y) F"
hoelzl@50331
  1090
  assumes ev: "eventually (\<lambda>x. g x \<le> f x) F"
hoelzl@50331
  1091
  shows "y \<le> x"
hoelzl@50331
  1092
  using tendsto_le_const[OF F tendsto_diff[OF x y], of 0] ev
hoelzl@50331
  1093
  by (simp add: sign_simps)
hoelzl@50331
  1094
huffman@44194
  1095
subsubsection {* Inverse and division *}
huffman@31355
  1096
huffman@31355
  1097
lemma (in bounded_bilinear) Zfun_prod_Bfun:
huffman@44195
  1098
  assumes f: "Zfun f F"
huffman@44195
  1099
  assumes g: "Bfun g F"
huffman@44195
  1100
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31355
  1101
proof -
huffman@31355
  1102
  obtain K where K: "0 \<le> K"
huffman@31355
  1103
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31355
  1104
    using nonneg_bounded by fast
huffman@31355
  1105
  obtain B where B: "0 < B"
huffman@44195
  1106
    and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) F"
huffman@31487
  1107
    using g by (rule BfunE)
huffman@44195
  1108
  have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) F"
noschinl@46887
  1109
  using norm_g proof eventually_elim
noschinl@46887
  1110
    case (elim x)
huffman@31487
  1111
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31355
  1112
      by (rule norm_le)
huffman@31487
  1113
    also have "\<dots> \<le> norm (f x) * B * K"
huffman@31487
  1114
      by (intro mult_mono' order_refl norm_g norm_ge_zero
noschinl@46887
  1115
                mult_nonneg_nonneg K elim)
huffman@31487
  1116
    also have "\<dots> = norm (f x) * (B * K)"
huffman@31355
  1117
      by (rule mult_assoc)
huffman@31487
  1118
    finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
huffman@31355
  1119
  qed
huffman@31487
  1120
  with f show ?thesis
huffman@31487
  1121
    by (rule Zfun_imp_Zfun)
huffman@31355
  1122
qed
huffman@31355
  1123
huffman@31355
  1124
lemma (in bounded_bilinear) flip:
huffman@31355
  1125
  "bounded_bilinear (\<lambda>x y. y ** x)"
huffman@44081
  1126
  apply default
huffman@44081
  1127
  apply (rule add_right)
huffman@44081
  1128
  apply (rule add_left)
huffman@44081
  1129
  apply (rule scaleR_right)
huffman@44081
  1130
  apply (rule scaleR_left)
huffman@44081
  1131
  apply (subst mult_commute)
huffman@44081
  1132
  using bounded by fast
huffman@31355
  1133
huffman@31355
  1134
lemma (in bounded_bilinear) Bfun_prod_Zfun:
huffman@44195
  1135
  assumes f: "Bfun f F"
huffman@44195
  1136
  assumes g: "Zfun g F"
huffman@44195
  1137
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@44081
  1138
  using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
huffman@31355
  1139
huffman@31355
  1140
lemma Bfun_inverse_lemma:
huffman@31355
  1141
  fixes x :: "'a::real_normed_div_algebra"
huffman@31355
  1142
  shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
huffman@44081
  1143
  apply (subst nonzero_norm_inverse, clarsimp)
huffman@44081
  1144
  apply (erule (1) le_imp_inverse_le)
huffman@44081
  1145
  done
huffman@31355
  1146
huffman@31355
  1147
lemma Bfun_inverse:
huffman@31355
  1148
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
  1149
  assumes f: "(f ---> a) F"
huffman@31355
  1150
  assumes a: "a \<noteq> 0"
huffman@44195
  1151
  shows "Bfun (\<lambda>x. inverse (f x)) F"
huffman@31355
  1152
proof -
huffman@31355
  1153
  from a have "0 < norm a" by simp
huffman@31355
  1154
  hence "\<exists>r>0. r < norm a" by (rule dense)
huffman@31355
  1155
  then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
huffman@44195
  1156
  have "eventually (\<lambda>x. dist (f x) a < r) F"
huffman@31487
  1157
    using tendstoD [OF f r1] by fast
huffman@44195
  1158
  hence "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) F"
noschinl@46887
  1159
  proof eventually_elim
noschinl@46887
  1160
    case (elim x)
huffman@31487
  1161
    hence 1: "norm (f x - a) < r"
huffman@31355
  1162
      by (simp add: dist_norm)
huffman@31487
  1163
    hence 2: "f x \<noteq> 0" using r2 by auto
huffman@31487
  1164
    hence "norm (inverse (f x)) = inverse (norm (f x))"
huffman@31355
  1165
      by (rule nonzero_norm_inverse)
huffman@31355
  1166
    also have "\<dots> \<le> inverse (norm a - r)"
huffman@31355
  1167
    proof (rule le_imp_inverse_le)
huffman@31355
  1168
      show "0 < norm a - r" using r2 by simp
huffman@31355
  1169
    next
huffman@31487
  1170
      have "norm a - norm (f x) \<le> norm (a - f x)"
huffman@31355
  1171
        by (rule norm_triangle_ineq2)
huffman@31487
  1172
      also have "\<dots> = norm (f x - a)"
huffman@31355
  1173
        by (rule norm_minus_commute)
huffman@31355
  1174
      also have "\<dots> < r" using 1 .
huffman@31487
  1175
      finally show "norm a - r \<le> norm (f x)" by simp
huffman@31355
  1176
    qed
huffman@31487
  1177
    finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
huffman@31355
  1178
  qed
huffman@31355
  1179
  thus ?thesis by (rule BfunI)
huffman@31355
  1180
qed
huffman@31355
  1181
huffman@31565
  1182
lemma tendsto_inverse [tendsto_intros]:
huffman@31355
  1183
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
  1184
  assumes f: "(f ---> a) F"
huffman@31355
  1185
  assumes a: "a \<noteq> 0"
huffman@44195
  1186
  shows "((\<lambda>x. inverse (f x)) ---> inverse a) F"
huffman@31355
  1187
proof -
huffman@31355
  1188
  from a have "0 < norm a" by simp
huffman@44195
  1189
  with f have "eventually (\<lambda>x. dist (f x) a < norm a) F"
huffman@31355
  1190
    by (rule tendstoD)
huffman@44195
  1191
  then have "eventually (\<lambda>x. f x \<noteq> 0) F"
huffman@31355
  1192
    unfolding dist_norm by (auto elim!: eventually_elim1)
huffman@44627
  1193
  with a have "eventually (\<lambda>x. inverse (f x) - inverse a =
huffman@44627
  1194
    - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
  1195
    by (auto elim!: eventually_elim1 simp: inverse_diff_inverse)
huffman@44627
  1196
  moreover have "Zfun (\<lambda>x. - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
  1197
    by (intro Zfun_minus Zfun_mult_left
huffman@44627
  1198
      bounded_bilinear.Bfun_prod_Zfun [OF bounded_bilinear_mult]
huffman@44627
  1199
      Bfun_inverse [OF f a] f [unfolded tendsto_Zfun_iff])
huffman@44627
  1200
  ultimately show ?thesis
huffman@44627
  1201
    unfolding tendsto_Zfun_iff by (rule Zfun_ssubst)
huffman@31355
  1202
qed
huffman@31355
  1203
huffman@31565
  1204
lemma tendsto_divide [tendsto_intros]:
huffman@31355
  1205
  fixes a b :: "'a::real_normed_field"
huffman@44195
  1206
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F; b \<noteq> 0\<rbrakk>
huffman@44195
  1207
    \<Longrightarrow> ((\<lambda>x. f x / g x) ---> a / b) F"
huffman@44282
  1208
  by (simp add: tendsto_mult tendsto_inverse divide_inverse)
huffman@31355
  1209
huffman@44194
  1210
lemma tendsto_sgn [tendsto_intros]:
huffman@44194
  1211
  fixes l :: "'a::real_normed_vector"
huffman@44195
  1212
  shows "\<lbrakk>(f ---> l) F; l \<noteq> 0\<rbrakk> \<Longrightarrow> ((\<lambda>x. sgn (f x)) ---> sgn l) F"
huffman@44194
  1213
  unfolding sgn_div_norm by (simp add: tendsto_intros)
huffman@44194
  1214
hoelzl@50247
  1215
subsection {* Limits to @{const at_top} and @{const at_bot} *}
hoelzl@50247
  1216
hoelzl@50322
  1217
lemma filterlim_at_top:
hoelzl@50346
  1218
  fixes f :: "'a \<Rightarrow> ('b::linorder)"
hoelzl@50346
  1219
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. Z \<le> f x) F)"
hoelzl@50346
  1220
  by (auto simp: filterlim_iff eventually_at_top_linorder elim!: eventually_elim1)
hoelzl@50346
  1221
hoelzl@50346
  1222
lemma filterlim_at_top_dense:
hoelzl@50247
  1223
  fixes f :: "'a \<Rightarrow> ('b::dense_linorder)"
hoelzl@50247
  1224
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. Z < f x) F)"
hoelzl@50346
  1225
  by (metis eventually_elim1[of _ F] eventually_gt_at_top order_less_imp_le
hoelzl@50346
  1226
            filterlim_at_top[of f F] filterlim_iff[of f at_top F])
hoelzl@50247
  1227
hoelzl@50346
  1228
lemma filterlim_at_top_ge:
hoelzl@50346
  1229
  fixes f :: "'a \<Rightarrow> ('b::linorder)" and c :: "'b"
hoelzl@50346
  1230
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z\<ge>c. eventually (\<lambda>x. Z \<le> f x) F)"
hoelzl@50323
  1231
  unfolding filterlim_at_top
hoelzl@50323
  1232
proof safe
hoelzl@50346
  1233
  fix Z assume *: "\<forall>Z\<ge>c. eventually (\<lambda>x. Z \<le> f x) F"
hoelzl@50346
  1234
  with *[THEN spec, of "max Z c"] show "eventually (\<lambda>x. Z \<le> f x) F"
hoelzl@50323
  1235
    by (auto elim!: eventually_elim1)
hoelzl@50323
  1236
qed simp
hoelzl@50323
  1237
hoelzl@50346
  1238
lemma filterlim_at_top_at_top:
hoelzl@50346
  1239
  fixes f :: "'a::linorder \<Rightarrow> 'b::linorder"
hoelzl@50346
  1240
  assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@50346
  1241
  assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
hoelzl@50346
  1242
  assumes Q: "eventually Q at_top"
hoelzl@50346
  1243
  assumes P: "eventually P at_top"
hoelzl@50346
  1244
  shows "filterlim f at_top at_top"
hoelzl@50346
  1245
proof -
hoelzl@50346
  1246
  from P obtain x where x: "\<And>y. x \<le> y \<Longrightarrow> P y"
hoelzl@50346
  1247
    unfolding eventually_at_top_linorder by auto
hoelzl@50346
  1248
  show ?thesis
hoelzl@50346
  1249
  proof (intro filterlim_at_top_ge[THEN iffD2] allI impI)
hoelzl@50346
  1250
    fix z assume "x \<le> z"
hoelzl@50346
  1251
    with x have "P z" by auto
hoelzl@50346
  1252
    have "eventually (\<lambda>x. g z \<le> x) at_top"
hoelzl@50346
  1253
      by (rule eventually_ge_at_top)
hoelzl@50346
  1254
    with Q show "eventually (\<lambda>x. z \<le> f x) at_top"
hoelzl@50346
  1255
      by eventually_elim (metis mono bij `P z`)
hoelzl@50346
  1256
  qed
hoelzl@50346
  1257
qed
hoelzl@50346
  1258
hoelzl@50346
  1259
lemma filterlim_at_top_gt:
hoelzl@50346
  1260
  fixes f :: "'a \<Rightarrow> ('b::dense_linorder)" and c :: "'b"
hoelzl@50346
  1261
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z>c. eventually (\<lambda>x. Z \<le> f x) F)"
hoelzl@50346
  1262
  by (metis filterlim_at_top order_less_le_trans gt_ex filterlim_at_top_ge)
hoelzl@50346
  1263
hoelzl@50322
  1264
lemma filterlim_at_bot: 
hoelzl@50346
  1265
  fixes f :: "'a \<Rightarrow> ('b::linorder)"
hoelzl@50346
  1266
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. f x \<le> Z) F)"
hoelzl@50346
  1267
  by (auto simp: filterlim_iff eventually_at_bot_linorder elim!: eventually_elim1)
hoelzl@50346
  1268
hoelzl@50346
  1269
lemma filterlim_at_bot_le:
hoelzl@50346
  1270
  fixes f :: "'a \<Rightarrow> ('b::linorder)" and c :: "'b"
hoelzl@50346
  1271
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z\<le>c. eventually (\<lambda>x. Z \<ge> f x) F)"
hoelzl@50346
  1272
  unfolding filterlim_at_bot
hoelzl@50346
  1273
proof safe
hoelzl@50346
  1274
  fix Z assume *: "\<forall>Z\<le>c. eventually (\<lambda>x. Z \<ge> f x) F"
hoelzl@50346
  1275
  with *[THEN spec, of "min Z c"] show "eventually (\<lambda>x. Z \<ge> f x) F"
hoelzl@50346
  1276
    by (auto elim!: eventually_elim1)
hoelzl@50346
  1277
qed simp
hoelzl@50247
  1278
hoelzl@50323
  1279
lemma filterlim_at_bot_lt:
hoelzl@50323
  1280
  fixes f :: "'a \<Rightarrow> ('b::dense_linorder)" and c :: "'b"
hoelzl@50346
  1281
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z<c. eventually (\<lambda>x. Z \<ge> f x) F)"
hoelzl@50346
  1282
  by (metis filterlim_at_bot filterlim_at_bot_le lt_ex order_le_less_trans)
hoelzl@50346
  1283
hoelzl@50346
  1284
lemma filterlim_at_bot_at_right:
hoelzl@50346
  1285
  fixes f :: "real \<Rightarrow> 'b::linorder"
hoelzl@50346
  1286
  assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@50346
  1287
  assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
hoelzl@50346
  1288
  assumes Q: "eventually Q (at_right a)" and bound: "\<And>b. Q b \<Longrightarrow> a < b"
hoelzl@50346
  1289
  assumes P: "eventually P at_bot"
hoelzl@50346
  1290
  shows "filterlim f at_bot (at_right a)"
hoelzl@50346
  1291
proof -
hoelzl@50346
  1292
  from P obtain x where x: "\<And>y. y \<le> x \<Longrightarrow> P y"
hoelzl@50346
  1293
    unfolding eventually_at_bot_linorder by auto
hoelzl@50346
  1294
  show ?thesis
hoelzl@50346
  1295
  proof (intro filterlim_at_bot_le[THEN iffD2] allI impI)
hoelzl@50346
  1296
    fix z assume "z \<le> x"
hoelzl@50346
  1297
    with x have "P z" by auto
hoelzl@50346
  1298
    have "eventually (\<lambda>x. x \<le> g z) (at_right a)"
hoelzl@50346
  1299
      using bound[OF bij(2)[OF `P z`]]
hoelzl@50346
  1300
      by (auto simp add: eventually_within_less dist_real_def intro!:  exI[of _ "g z - a"])
hoelzl@50346
  1301
    with Q show "eventually (\<lambda>x. f x \<le> z) (at_right a)"
hoelzl@50346
  1302
      by eventually_elim (metis bij `P z` mono)
hoelzl@50346
  1303
  qed
hoelzl@50346
  1304
qed
hoelzl@50346
  1305
hoelzl@50346
  1306
lemma filterlim_at_top_at_left:
hoelzl@50346
  1307
  fixes f :: "real \<Rightarrow> 'b::linorder"
hoelzl@50346
  1308
  assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@50346
  1309
  assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
hoelzl@50346
  1310
  assumes Q: "eventually Q (at_left a)" and bound: "\<And>b. Q b \<Longrightarrow> b < a"
hoelzl@50346
  1311
  assumes P: "eventually P at_top"
hoelzl@50346
  1312
  shows "filterlim f at_top (at_left a)"
hoelzl@50346
  1313
proof -
hoelzl@50346
  1314
  from P obtain x where x: "\<And>y. x \<le> y \<Longrightarrow> P y"
hoelzl@50346
  1315
    unfolding eventually_at_top_linorder by auto
hoelzl@50346
  1316
  show ?thesis
hoelzl@50346
  1317
  proof (intro filterlim_at_top_ge[THEN iffD2] allI impI)
hoelzl@50346
  1318
    fix z assume "x \<le> z"
hoelzl@50346
  1319
    with x have "P z" by auto
hoelzl@50346
  1320
    have "eventually (\<lambda>x. g z \<le> x) (at_left a)"
hoelzl@50346
  1321
      using bound[OF bij(2)[OF `P z`]]
hoelzl@50346
  1322
      by (auto simp add: eventually_within_less dist_real_def intro!:  exI[of _ "a - g z"])
hoelzl@50346
  1323
    with Q show "eventually (\<lambda>x. z \<le> f x) (at_left a)"
hoelzl@50346
  1324
      by eventually_elim (metis bij `P z` mono)
hoelzl@50346
  1325
  qed
hoelzl@50346
  1326
qed
hoelzl@50323
  1327
hoelzl@50325
  1328
lemma filterlim_at_infinity:
hoelzl@50325
  1329
  fixes f :: "_ \<Rightarrow> 'a\<Colon>real_normed_vector"
hoelzl@50325
  1330
  assumes "0 \<le> c"
hoelzl@50325
  1331
  shows "(LIM x F. f x :> at_infinity) \<longleftrightarrow> (\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F)"
hoelzl@50325
  1332
  unfolding filterlim_iff eventually_at_infinity
hoelzl@50325
  1333
proof safe
hoelzl@50325
  1334
  fix P :: "'a \<Rightarrow> bool" and b
hoelzl@50325
  1335
  assume *: "\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F"
hoelzl@50325
  1336
    and P: "\<forall>x. b \<le> norm x \<longrightarrow> P x"
hoelzl@50325
  1337
  have "max b (c + 1) > c" by auto
hoelzl@50325
  1338
  with * have "eventually (\<lambda>x. max b (c + 1) \<le> norm (f x)) F"
hoelzl@50325
  1339
    by auto
hoelzl@50325
  1340
  then show "eventually (\<lambda>x. P (f x)) F"
hoelzl@50325
  1341
  proof eventually_elim
hoelzl@50325
  1342
    fix x assume "max b (c + 1) \<le> norm (f x)"
hoelzl@50325
  1343
    with P show "P (f x)" by auto
hoelzl@50325
  1344
  qed
hoelzl@50325
  1345
qed force
hoelzl@50325
  1346
hoelzl@50322
  1347
lemma filterlim_real_sequentially: "LIM x sequentially. real x :> at_top"
hoelzl@50322
  1348
  unfolding filterlim_at_top
hoelzl@50247
  1349
  apply (intro allI)
hoelzl@50247
  1350
  apply (rule_tac c="natceiling (Z + 1)" in eventually_sequentiallyI)
hoelzl@50247
  1351
  apply (auto simp: natceiling_le_eq)
hoelzl@50247
  1352
  done
hoelzl@50247
  1353
hoelzl@50347
  1354
subsection {* Relate @{const at}, @{const at_left} and @{const at_right} *}
hoelzl@50347
  1355
hoelzl@50347
  1356
text {*
hoelzl@50347
  1357
hoelzl@50347
  1358
This lemmas are useful for conversion between @{term "at x"} to @{term "at_left x"} and
hoelzl@50347
  1359
@{term "at_right x"} and also @{term "at_right 0"}.
hoelzl@50347
  1360
hoelzl@50347
  1361
*}
hoelzl@50347
  1362
hoelzl@50347
  1363
lemma at_eq_sup_left_right: "at (x::real) = sup (at_left x) (at_right x)"
hoelzl@50347
  1364
  by (auto simp: eventually_within at_def filter_eq_iff eventually_sup 
hoelzl@50347
  1365
           elim: eventually_elim2 eventually_elim1)
hoelzl@50347
  1366
hoelzl@50347
  1367
lemma filterlim_split_at_real:
hoelzl@50347
  1368
  "filterlim f F (at_left x) \<Longrightarrow> filterlim f F (at_right x) \<Longrightarrow> filterlim f F (at (x::real))"
hoelzl@50347
  1369
  by (subst at_eq_sup_left_right) (rule filterlim_sup)
hoelzl@50323
  1370
hoelzl@50347
  1371
lemma filtermap_nhds_shift: "filtermap (\<lambda>x. x - d) (nhds a) = nhds (a - d::real)"
hoelzl@50347
  1372
  unfolding filter_eq_iff eventually_filtermap eventually_nhds_metric
hoelzl@50347
  1373
  by (intro allI ex_cong) (auto simp: dist_real_def field_simps)
hoelzl@50347
  1374
hoelzl@50347
  1375
lemma filtermap_nhds_minus: "filtermap (\<lambda>x. - x) (nhds a) = nhds (- a::real)"
hoelzl@50347
  1376
  unfolding filter_eq_iff eventually_filtermap eventually_nhds_metric
hoelzl@50347
  1377
  apply (intro allI ex_cong)
hoelzl@50347
  1378
  apply (auto simp: dist_real_def field_simps)
hoelzl@50347
  1379
  apply (erule_tac x="-x" in allE)
hoelzl@50347
  1380
  apply simp
hoelzl@50347
  1381
  done
hoelzl@50347
  1382
hoelzl@50347
  1383
lemma filtermap_at_shift: "filtermap (\<lambda>x. x - d) (at a) = at (a - d::real)"
hoelzl@50347
  1384
  unfolding at_def filtermap_nhds_shift[symmetric]
hoelzl@50347
  1385
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50347
  1386
hoelzl@50347
  1387
lemma filtermap_at_right_shift: "filtermap (\<lambda>x. x - d) (at_right a) = at_right (a - d::real)"
hoelzl@50347
  1388
  unfolding filtermap_at_shift[symmetric]
hoelzl@50347
  1389
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50323
  1390
hoelzl@50347
  1391
lemma at_right_to_0: "at_right (a::real) = filtermap (\<lambda>x. x + a) (at_right 0)"
hoelzl@50347
  1392
  using filtermap_at_right_shift[of "-a" 0] by simp
hoelzl@50347
  1393
hoelzl@50347
  1394
lemma filterlim_at_right_to_0:
hoelzl@50347
  1395
  "filterlim f F (at_right (a::real)) \<longleftrightarrow> filterlim (\<lambda>x. f (x + a)) F (at_right 0)"
hoelzl@50347
  1396
  unfolding filterlim_def filtermap_filtermap at_right_to_0[of a] ..
hoelzl@50347
  1397
hoelzl@50347
  1398
lemma eventually_at_right_to_0:
hoelzl@50347
  1399
  "eventually P (at_right (a::real)) \<longleftrightarrow> eventually (\<lambda>x. P (x + a)) (at_right 0)"
hoelzl@50347
  1400
  unfolding at_right_to_0[of a] by (simp add: eventually_filtermap)
hoelzl@50347
  1401
hoelzl@50347
  1402
lemma filtermap_at_minus: "filtermap (\<lambda>x. - x) (at a) = at (- a::real)"
hoelzl@50347
  1403
  unfolding at_def filtermap_nhds_minus[symmetric]
hoelzl@50347
  1404
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50347
  1405
hoelzl@50347
  1406
lemma at_left_minus: "at_left (a::real) = filtermap (\<lambda>x. - x) (at_right (- a))"
hoelzl@50347
  1407
  by (simp add: filter_eq_iff eventually_filtermap eventually_within filtermap_at_minus[symmetric])
hoelzl@50323
  1408
hoelzl@50347
  1409
lemma at_right_minus: "at_right (a::real) = filtermap (\<lambda>x. - x) (at_left (- a))"
hoelzl@50347
  1410
  by (simp add: filter_eq_iff eventually_filtermap eventually_within filtermap_at_minus[symmetric])
hoelzl@50347
  1411
hoelzl@50347
  1412
lemma filterlim_at_left_to_right:
hoelzl@50347
  1413
  "filterlim f F (at_left (a::real)) \<longleftrightarrow> filterlim (\<lambda>x. f (- x)) F (at_right (-a))"
hoelzl@50347
  1414
  unfolding filterlim_def filtermap_filtermap at_left_minus[of a] ..
hoelzl@50347
  1415
hoelzl@50347
  1416
lemma eventually_at_left_to_right:
hoelzl@50347
  1417
  "eventually P (at_left (a::real)) \<longleftrightarrow> eventually (\<lambda>x. P (- x)) (at_right (-a))"
hoelzl@50347
  1418
  unfolding at_left_minus[of a] by (simp add: eventually_filtermap)
hoelzl@50347
  1419
hoelzl@50347
  1420
lemma filterlim_at_split:
hoelzl@50347
  1421
  "filterlim f F (at (x::real)) \<longleftrightarrow> filterlim f F (at_left x) \<and> filterlim f F (at_right x)"
hoelzl@50347
  1422
  by (subst at_eq_sup_left_right) (simp add: filterlim_def filtermap_sup)
hoelzl@50347
  1423
hoelzl@50347
  1424
lemma eventually_at_split:
hoelzl@50347
  1425
  "eventually P (at (x::real)) \<longleftrightarrow> eventually P (at_left x) \<and> eventually P (at_right x)"
hoelzl@50347
  1426
  by (subst at_eq_sup_left_right) (simp add: eventually_sup)
hoelzl@50323
  1427
hoelzl@50346
  1428
lemma at_top_mirror: "at_top = filtermap uminus (at_bot :: real filter)"
hoelzl@50346
  1429
  unfolding filter_eq_iff eventually_filtermap eventually_at_top_linorder eventually_at_bot_linorder
hoelzl@50346
  1430
  by (metis le_minus_iff minus_minus)
hoelzl@50346
  1431
hoelzl@50346
  1432
lemma at_bot_mirror: "at_bot = filtermap uminus (at_top :: real filter)"
hoelzl@50346
  1433
  unfolding at_top_mirror filtermap_filtermap by (simp add: filtermap_ident)
hoelzl@50346
  1434
hoelzl@50346
  1435
lemma filterlim_at_top_mirror: "(LIM x at_top. f x :> F) \<longleftrightarrow> (LIM x at_bot. f (-x::real) :> F)"
hoelzl@50346
  1436
  unfolding filterlim_def at_top_mirror filtermap_filtermap ..
hoelzl@50346
  1437
hoelzl@50346
  1438
lemma filterlim_at_bot_mirror: "(LIM x at_bot. f x :> F) \<longleftrightarrow> (LIM x at_top. f (-x::real) :> F)"
hoelzl@50346
  1439
  unfolding filterlim_def at_bot_mirror filtermap_filtermap ..
hoelzl@50346
  1440
hoelzl@50323
  1441
lemma filterlim_uminus_at_top_at_bot: "LIM x at_bot. - x :: real :> at_top"
hoelzl@50323
  1442
  unfolding filterlim_at_top eventually_at_bot_dense
hoelzl@50346
  1443
  by (metis leI minus_less_iff order_less_asym)
hoelzl@50323
  1444
hoelzl@50323
  1445
lemma filterlim_uminus_at_bot_at_top: "LIM x at_top. - x :: real :> at_bot"
hoelzl@50323
  1446
  unfolding filterlim_at_bot eventually_at_top_dense
hoelzl@50346
  1447
  by (metis leI less_minus_iff order_less_asym)
hoelzl@50323
  1448
hoelzl@50346
  1449
lemma filterlim_uminus_at_top: "(LIM x F. f x :> at_top) \<longleftrightarrow> (LIM x F. - (f x) :: real :> at_bot)"
hoelzl@50346
  1450
  using filterlim_compose[OF filterlim_uminus_at_bot_at_top, of f F]
hoelzl@50346
  1451
  using filterlim_compose[OF filterlim_uminus_at_top_at_bot, of "\<lambda>x. - f x" F]
hoelzl@50346
  1452
  by auto
hoelzl@50346
  1453
hoelzl@50346
  1454
lemma filterlim_uminus_at_bot: "(LIM x F. f x :> at_bot) \<longleftrightarrow> (LIM x F. - (f x) :: real :> at_top)"
hoelzl@50346
  1455
  unfolding filterlim_uminus_at_top by simp
hoelzl@50323
  1456
hoelzl@50347
  1457
lemma filterlim_inverse_at_top_right: "LIM x at_right (0::real). inverse x :> at_top"
hoelzl@50347
  1458
  unfolding filterlim_at_top_gt[where c=0] eventually_within at_def
hoelzl@50347
  1459
proof safe
hoelzl@50347
  1460
  fix Z :: real assume [arith]: "0 < Z"
hoelzl@50347
  1461
  then have "eventually (\<lambda>x. x < inverse Z) (nhds 0)"
hoelzl@50347
  1462
    by (auto simp add: eventually_nhds_metric dist_real_def intro!: exI[of _ "\<bar>inverse Z\<bar>"])
hoelzl@50347
  1463
  then show "eventually (\<lambda>x. x \<in> - {0} \<longrightarrow> x \<in> {0<..} \<longrightarrow> Z \<le> inverse x) (nhds 0)"
hoelzl@50347
  1464
    by (auto elim!: eventually_elim1 simp: inverse_eq_divide field_simps)
hoelzl@50347
  1465
qed
hoelzl@50347
  1466
hoelzl@50347
  1467
lemma filterlim_inverse_at_top:
hoelzl@50347
  1468
  "(f ---> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. 0 < f x) F \<Longrightarrow> LIM x F. inverse (f x) :> at_top"
hoelzl@50347
  1469
  by (intro filterlim_compose[OF filterlim_inverse_at_top_right])
hoelzl@50347
  1470
     (simp add: filterlim_def eventually_filtermap le_within_iff at_def eventually_elim1)
hoelzl@50347
  1471
hoelzl@50347
  1472
lemma filterlim_inverse_at_bot_neg:
hoelzl@50347
  1473
  "LIM x (at_left (0::real)). inverse x :> at_bot"
hoelzl@50347
  1474
  by (simp add: filterlim_inverse_at_top_right filterlim_uminus_at_bot filterlim_at_left_to_right)
hoelzl@50347
  1475
hoelzl@50347
  1476
lemma filterlim_inverse_at_bot:
hoelzl@50347
  1477
  "(f ---> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. f x < 0) F \<Longrightarrow> LIM x F. inverse (f x) :> at_bot"
hoelzl@50347
  1478
  unfolding filterlim_uminus_at_bot inverse_minus_eq[symmetric]
hoelzl@50347
  1479
  by (rule filterlim_inverse_at_top) (simp_all add: tendsto_minus_cancel_left[symmetric])
hoelzl@50347
  1480
hoelzl@50325
  1481
lemma tendsto_inverse_0:
hoelzl@50325
  1482
  fixes x :: "_ \<Rightarrow> 'a\<Colon>real_normed_div_algebra"
hoelzl@50325
  1483
  shows "(inverse ---> (0::'a)) at_infinity"
hoelzl@50325
  1484
  unfolding tendsto_Zfun_iff diff_0_right Zfun_def eventually_at_infinity
hoelzl@50325
  1485
proof safe
hoelzl@50325
  1486
  fix r :: real assume "0 < r"
hoelzl@50325
  1487
  show "\<exists>b. \<forall>x. b \<le> norm x \<longrightarrow> norm (inverse x :: 'a) < r"
hoelzl@50325
  1488
  proof (intro exI[of _ "inverse (r / 2)"] allI impI)
hoelzl@50325
  1489
    fix x :: 'a
hoelzl@50325
  1490
    from `0 < r` have "0 < inverse (r / 2)" by simp
hoelzl@50325
  1491
    also assume *: "inverse (r / 2) \<le> norm x"
hoelzl@50325
  1492
    finally show "norm (inverse x) < r"
hoelzl@50325
  1493
      using * `0 < r` by (subst nonzero_norm_inverse) (simp_all add: inverse_eq_divide field_simps)
hoelzl@50325
  1494
  qed
hoelzl@50325
  1495
qed
hoelzl@50325
  1496
hoelzl@50347
  1497
lemma at_right_to_top: "(at_right (0::real)) = filtermap inverse at_top"
hoelzl@50347
  1498
proof (rule antisym)
hoelzl@50347
  1499
  have "(inverse ---> (0::real)) at_top"
hoelzl@50347
  1500
    by (metis tendsto_inverse_0 filterlim_mono at_top_le_at_infinity order_refl)
hoelzl@50347
  1501
  then show "filtermap inverse at_top \<le> at_right (0::real)"
hoelzl@50347
  1502
    unfolding at_within_eq
hoelzl@50347
  1503
    by (intro le_withinI) (simp_all add: eventually_filtermap eventually_gt_at_top filterlim_def)
hoelzl@50347
  1504
next
hoelzl@50347
  1505
  have "filtermap inverse (filtermap inverse (at_right (0::real))) \<le> filtermap inverse at_top"
hoelzl@50347
  1506
    using filterlim_inverse_at_top_right unfolding filterlim_def by (rule filtermap_mono)
hoelzl@50347
  1507
  then show "at_right (0::real) \<le> filtermap inverse at_top"
hoelzl@50347
  1508
    by (simp add: filtermap_ident filtermap_filtermap)
hoelzl@50347
  1509
qed
hoelzl@50347
  1510
hoelzl@50347
  1511
lemma eventually_at_right_to_top:
hoelzl@50347
  1512
  "eventually P (at_right (0::real)) \<longleftrightarrow> eventually (\<lambda>x. P (inverse x)) at_top"
hoelzl@50347
  1513
  unfolding at_right_to_top eventually_filtermap ..
hoelzl@50347
  1514
hoelzl@50347
  1515
lemma filterlim_at_right_to_top:
hoelzl@50347
  1516
  "filterlim f F (at_right (0::real)) \<longleftrightarrow> (LIM x at_top. f (inverse x) :> F)"
hoelzl@50347
  1517
  unfolding filterlim_def at_right_to_top filtermap_filtermap ..
hoelzl@50347
  1518
hoelzl@50347
  1519
lemma at_top_to_right: "at_top = filtermap inverse (at_right (0::real))"
hoelzl@50347
  1520
  unfolding at_right_to_top filtermap_filtermap inverse_inverse_eq filtermap_ident ..
hoelzl@50347
  1521
hoelzl@50347
  1522
lemma eventually_at_top_to_right:
hoelzl@50347
  1523
  "eventually P at_top \<longleftrightarrow> eventually (\<lambda>x. P (inverse x)) (at_right (0::real))"
hoelzl@50347
  1524
  unfolding at_top_to_right eventually_filtermap ..
hoelzl@50347
  1525
hoelzl@50347
  1526
lemma filterlim_at_top_to_right:
hoelzl@50347
  1527
  "filterlim f F at_top \<longleftrightarrow> (LIM x (at_right (0::real)). f (inverse x) :> F)"
hoelzl@50347
  1528
  unfolding filterlim_def at_top_to_right filtermap_filtermap ..
hoelzl@50347
  1529
hoelzl@50325
  1530
lemma filterlim_inverse_at_infinity:
hoelzl@50325
  1531
  fixes x :: "_ \<Rightarrow> 'a\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50325
  1532
  shows "filterlim inverse at_infinity (at (0::'a))"
hoelzl@50325
  1533
  unfolding filterlim_at_infinity[OF order_refl]
hoelzl@50325
  1534
proof safe
hoelzl@50325
  1535
  fix r :: real assume "0 < r"
hoelzl@50325
  1536
  then show "eventually (\<lambda>x::'a. r \<le> norm (inverse x)) (at 0)"
hoelzl@50325
  1537
    unfolding eventually_at norm_inverse
hoelzl@50325
  1538
    by (intro exI[of _ "inverse r"])
hoelzl@50325
  1539
       (auto simp: norm_conv_dist[symmetric] field_simps inverse_eq_divide)
hoelzl@50325
  1540
qed
hoelzl@50325
  1541
hoelzl@50325
  1542
lemma filterlim_inverse_at_iff:
hoelzl@50325
  1543
  fixes g :: "'a \<Rightarrow> 'b\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50325
  1544
  shows "(LIM x F. inverse (g x) :> at 0) \<longleftrightarrow> (LIM x F. g x :> at_infinity)"
hoelzl@50325
  1545
  unfolding filterlim_def filtermap_filtermap[symmetric]
hoelzl@50325
  1546
proof
hoelzl@50325
  1547
  assume "filtermap g F \<le> at_infinity"
hoelzl@50325
  1548
  then have "filtermap inverse (filtermap g F) \<le> filtermap inverse at_infinity"
hoelzl@50325
  1549
    by (rule filtermap_mono)
hoelzl@50325
  1550
  also have "\<dots> \<le> at 0"
hoelzl@50325
  1551
    using tendsto_inverse_0
hoelzl@50325
  1552
    by (auto intro!: le_withinI exI[of _ 1]
hoelzl@50325
  1553
             simp: eventually_filtermap eventually_at_infinity filterlim_def at_def)
hoelzl@50325
  1554
  finally show "filtermap inverse (filtermap g F) \<le> at 0" .
hoelzl@50325
  1555
next
hoelzl@50325
  1556
  assume "filtermap inverse (filtermap g F) \<le> at 0"
hoelzl@50325
  1557
  then have "filtermap inverse (filtermap inverse (filtermap g F)) \<le> filtermap inverse (at 0)"
hoelzl@50325
  1558
    by (rule filtermap_mono)
hoelzl@50325
  1559
  with filterlim_inverse_at_infinity show "filtermap g F \<le> at_infinity"
hoelzl@50325
  1560
    by (auto intro: order_trans simp: filterlim_def filtermap_filtermap)
hoelzl@50325
  1561
qed
hoelzl@50325
  1562
hoelzl@50324
  1563
text {*
hoelzl@50324
  1564
hoelzl@50324
  1565
We only show rules for multiplication and addition when the functions are either against a real
hoelzl@50324
  1566
value or against infinity. Further rules are easy to derive by using @{thm filterlim_uminus_at_top}.
hoelzl@50324
  1567
hoelzl@50324
  1568
*}
hoelzl@50324
  1569
hoelzl@50324
  1570
lemma filterlim_tendsto_pos_mult_at_top: 
hoelzl@50324
  1571
  assumes f: "(f ---> c) F" and c: "0 < c"
hoelzl@50324
  1572
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
  1573
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
  1574
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1575
proof safe
hoelzl@50324
  1576
  fix Z :: real assume "0 < Z"
hoelzl@50324
  1577
  from f `0 < c` have "eventually (\<lambda>x. c / 2 < f x) F"
hoelzl@50324
  1578
    by (auto dest!: tendstoD[where e="c / 2"] elim!: eventually_elim1
hoelzl@50324
  1579
             simp: dist_real_def abs_real_def split: split_if_asm)
hoelzl@50346
  1580
  moreover from g have "eventually (\<lambda>x. (Z / c * 2) \<le> g x) F"
hoelzl@50324
  1581
    unfolding filterlim_at_top by auto
hoelzl@50346
  1582
  ultimately show "eventually (\<lambda>x. Z \<le> f x * g x) F"
hoelzl@50324
  1583
  proof eventually_elim
hoelzl@50346
  1584
    fix x assume "c / 2 < f x" "Z / c * 2 \<le> g x"
hoelzl@50346
  1585
    with `0 < Z` `0 < c` have "c / 2 * (Z / c * 2) \<le> f x * g x"
hoelzl@50346
  1586
      by (intro mult_mono) (auto simp: zero_le_divide_iff)
hoelzl@50346
  1587
    with `0 < c` show "Z \<le> f x * g x"
hoelzl@50324
  1588
       by simp
hoelzl@50324
  1589
  qed
hoelzl@50324
  1590
qed
hoelzl@50324
  1591
hoelzl@50324
  1592
lemma filterlim_at_top_mult_at_top: 
hoelzl@50324
  1593
  assumes f: "LIM x F. f x :> at_top"
hoelzl@50324
  1594
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
  1595
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
  1596
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1597
proof safe
hoelzl@50324
  1598
  fix Z :: real assume "0 < Z"
hoelzl@50346
  1599
  from f have "eventually (\<lambda>x. 1 \<le> f x) F"
hoelzl@50324
  1600
    unfolding filterlim_at_top by auto
hoelzl@50346
  1601
  moreover from g have "eventually (\<lambda>x. Z \<le> g x) F"
hoelzl@50324
  1602
    unfolding filterlim_at_top by auto
hoelzl@50346
  1603
  ultimately show "eventually (\<lambda>x. Z \<le> f x * g x) F"
hoelzl@50324
  1604
  proof eventually_elim
hoelzl@50346
  1605
    fix x assume "1 \<le> f x" "Z \<le> g x"
hoelzl@50346
  1606
    with `0 < Z` have "1 * Z \<le> f x * g x"
hoelzl@50346
  1607
      by (intro mult_mono) (auto simp: zero_le_divide_iff)
hoelzl@50346
  1608
    then show "Z \<le> f x * g x"
hoelzl@50324
  1609
       by simp
hoelzl@50324
  1610
  qed
hoelzl@50324
  1611
qed
hoelzl@50324
  1612
hoelzl@50324
  1613
lemma filterlim_tendsto_add_at_top: 
hoelzl@50324
  1614
  assumes f: "(f ---> c) F"
hoelzl@50324
  1615
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
  1616
  shows "LIM x F. (f x + g x :: real) :> at_top"
hoelzl@50324
  1617
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1618
proof safe
hoelzl@50324
  1619
  fix Z :: real assume "0 < Z"
hoelzl@50324
  1620
  from f have "eventually (\<lambda>x. c - 1 < f x) F"
hoelzl@50324
  1621
    by (auto dest!: tendstoD[where e=1] elim!: eventually_elim1 simp: dist_real_def)
hoelzl@50346
  1622
  moreover from g have "eventually (\<lambda>x. Z - (c - 1) \<le> g x) F"
hoelzl@50324
  1623
    unfolding filterlim_at_top by auto
hoelzl@50346
  1624
  ultimately show "eventually (\<lambda>x. Z \<le> f x + g x) F"
hoelzl@50324
  1625
    by eventually_elim simp
hoelzl@50324
  1626
qed
hoelzl@50324
  1627
hoelzl@50347
  1628
lemma LIM_at_top_divide:
hoelzl@50347
  1629
  fixes f g :: "'a \<Rightarrow> real"
hoelzl@50347
  1630
  assumes f: "(f ---> a) F" "0 < a"
hoelzl@50347
  1631
  assumes g: "(g ---> 0) F" "eventually (\<lambda>x. 0 < g x) F"
hoelzl@50347
  1632
  shows "LIM x F. f x / g x :> at_top"
hoelzl@50347
  1633
  unfolding divide_inverse
hoelzl@50347
  1634
  by (rule filterlim_tendsto_pos_mult_at_top[OF f]) (rule filterlim_inverse_at_top[OF g])
hoelzl@50347
  1635
hoelzl@50324
  1636
lemma filterlim_at_top_add_at_top: 
hoelzl@50324
  1637
  assumes f: "LIM x F. f x :> at_top"
hoelzl@50324
  1638
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
  1639
  shows "LIM x F. (f x + g x :: real) :> at_top"
hoelzl@50324
  1640
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1641
proof safe
hoelzl@50324
  1642
  fix Z :: real assume "0 < Z"
hoelzl@50346
  1643
  from f have "eventually (\<lambda>x. 0 \<le> f x) F"
hoelzl@50324
  1644
    unfolding filterlim_at_top by auto
hoelzl@50346
  1645
  moreover from g have "eventually (\<lambda>x. Z \<le> g x) F"
hoelzl@50324
  1646
    unfolding filterlim_at_top by auto
hoelzl@50346
  1647
  ultimately show "eventually (\<lambda>x. Z \<le> f x + g x) F"
hoelzl@50324
  1648
    by eventually_elim simp
hoelzl@50324
  1649
qed
hoelzl@50324
  1650
hoelzl@50331
  1651
lemma tendsto_divide_0:
hoelzl@50331
  1652
  fixes f :: "_ \<Rightarrow> 'a\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50331
  1653
  assumes f: "(f ---> c) F"
hoelzl@50331
  1654
  assumes g: "LIM x F. g x :> at_infinity"
hoelzl@50331
  1655
  shows "((\<lambda>x. f x / g x) ---> 0) F"
hoelzl@50331
  1656
  using tendsto_mult[OF f filterlim_compose[OF tendsto_inverse_0 g]] by (simp add: divide_inverse)
hoelzl@50331
  1657
hoelzl@50331
  1658
lemma linear_plus_1_le_power:
hoelzl@50331
  1659
  fixes x :: real
hoelzl@50331
  1660
  assumes x: "0 \<le> x"
hoelzl@50331
  1661
  shows "real n * x + 1 \<le> (x + 1) ^ n"
hoelzl@50331
  1662
proof (induct n)
hoelzl@50331
  1663
  case (Suc n)
hoelzl@50331
  1664
  have "real (Suc n) * x + 1 \<le> (x + 1) * (real n * x + 1)"
hoelzl@50331
  1665
    by (simp add: field_simps real_of_nat_Suc mult_nonneg_nonneg x)
hoelzl@50331
  1666
  also have "\<dots> \<le> (x + 1)^Suc n"
hoelzl@50331
  1667
    using Suc x by (simp add: mult_left_mono)
hoelzl@50331
  1668
  finally show ?case .
hoelzl@50331
  1669
qed simp
hoelzl@50331
  1670
hoelzl@50331
  1671
lemma filterlim_realpow_sequentially_gt1:
hoelzl@50331
  1672
  fixes x :: "'a :: real_normed_div_algebra"
hoelzl@50331
  1673
  assumes x[arith]: "1 < norm x"
hoelzl@50331
  1674
  shows "LIM n sequentially. x ^ n :> at_infinity"
hoelzl@50331
  1675
proof (intro filterlim_at_infinity[THEN iffD2] allI impI)
hoelzl@50331
  1676
  fix y :: real assume "0 < y"
hoelzl@50331
  1677
  have "0 < norm x - 1" by simp
hoelzl@50331
  1678
  then obtain N::nat where "y < real N * (norm x - 1)" by (blast dest: reals_Archimedean3)
hoelzl@50331
  1679
  also have "\<dots> \<le> real N * (norm x - 1) + 1" by simp
hoelzl@50331
  1680
  also have "\<dots> \<le> (norm x - 1 + 1) ^ N" by (rule linear_plus_1_le_power) simp
hoelzl@50331
  1681
  also have "\<dots> = norm x ^ N" by simp
hoelzl@50331
  1682
  finally have "\<forall>n\<ge>N. y \<le> norm x ^ n"
hoelzl@50331
  1683
    by (metis order_less_le_trans power_increasing order_less_imp_le x)
hoelzl@50331
  1684
  then show "eventually (\<lambda>n. y \<le> norm (x ^ n)) sequentially"
hoelzl@50331
  1685
    unfolding eventually_sequentially
hoelzl@50331
  1686
    by (auto simp: norm_power)
hoelzl@50331
  1687
qed simp
hoelzl@50331
  1688
huffman@31349
  1689
end
hoelzl@50324
  1690