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