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