src/HOL/Limits.thy
author hoelzl
Mon Jan 14 17:16:59 2013 +0100 (2013-01-14)
changeset 50880 b22ecedde1c7
parent 50419 3177d0374701
child 50999 3de230ed0547
permissions -rw-r--r--
move eventually_Ball_finite to Limits
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
huffman@44195
   835
lemma tendsto_Zfun_iff: "(f ---> a) F = Zfun (\<lambda>x. f x - a) F"
huffman@44081
   836
  by (simp only: tendsto_iff Zfun_def dist_norm)
huffman@31349
   837
huffman@45031
   838
lemma tendsto_bot [simp]: "(f ---> a) bot"
huffman@45031
   839
  unfolding tendsto_def by simp
huffman@45031
   840
huffman@31565
   841
lemma tendsto_ident_at [tendsto_intros]: "((\<lambda>x. x) ---> a) (at a)"
huffman@44081
   842
  unfolding tendsto_def eventually_at_topological by auto
huffman@31565
   843
huffman@31565
   844
lemma tendsto_ident_at_within [tendsto_intros]:
huffman@36655
   845
  "((\<lambda>x. x) ---> a) (at a within S)"
huffman@44081
   846
  unfolding tendsto_def eventually_within eventually_at_topological by auto
huffman@31565
   847
huffman@44195
   848
lemma tendsto_const [tendsto_intros]: "((\<lambda>x. k) ---> k) F"
huffman@44081
   849
  by (simp add: tendsto_def)
huffman@31349
   850
huffman@44205
   851
lemma tendsto_unique:
huffman@44205
   852
  fixes f :: "'a \<Rightarrow> 'b::t2_space"
huffman@44205
   853
  assumes "\<not> trivial_limit F" and "(f ---> a) F" and "(f ---> b) F"
huffman@44205
   854
  shows "a = b"
huffman@44205
   855
proof (rule ccontr)
huffman@44205
   856
  assume "a \<noteq> b"
huffman@44205
   857
  obtain U V where "open U" "open V" "a \<in> U" "b \<in> V" "U \<inter> V = {}"
huffman@44205
   858
    using hausdorff [OF `a \<noteq> b`] by fast
huffman@44205
   859
  have "eventually (\<lambda>x. f x \<in> U) F"
huffman@44205
   860
    using `(f ---> a) F` `open U` `a \<in> U` by (rule topological_tendstoD)
huffman@44205
   861
  moreover
huffman@44205
   862
  have "eventually (\<lambda>x. f x \<in> V) F"
huffman@44205
   863
    using `(f ---> b) F` `open V` `b \<in> V` by (rule topological_tendstoD)
huffman@44205
   864
  ultimately
huffman@44205
   865
  have "eventually (\<lambda>x. False) F"
noschinl@46887
   866
  proof eventually_elim
noschinl@46887
   867
    case (elim x)
huffman@44205
   868
    hence "f x \<in> U \<inter> V" by simp
noschinl@46887
   869
    with `U \<inter> V = {}` show ?case by simp
huffman@44205
   870
  qed
huffman@44205
   871
  with `\<not> trivial_limit F` show "False"
huffman@44205
   872
    by (simp add: trivial_limit_def)
huffman@44205
   873
qed
huffman@44205
   874
huffman@36662
   875
lemma tendsto_const_iff:
huffman@44205
   876
  fixes a b :: "'a::t2_space"
huffman@44205
   877
  assumes "\<not> trivial_limit F" shows "((\<lambda>x. a) ---> b) F \<longleftrightarrow> a = b"
huffman@44205
   878
  by (safe intro!: tendsto_const tendsto_unique [OF assms tendsto_const])
huffman@44205
   879
hoelzl@50323
   880
lemma tendsto_at_iff_tendsto_nhds:
hoelzl@50323
   881
  "(g ---> g l) (at l) \<longleftrightarrow> (g ---> g l) (nhds l)"
hoelzl@50323
   882
  unfolding tendsto_def at_def eventually_within
hoelzl@50323
   883
  by (intro ext all_cong imp_cong) (auto elim!: eventually_elim1)
hoelzl@50323
   884
huffman@44218
   885
lemma tendsto_compose:
hoelzl@50323
   886
  "(g ---> g l) (at l) \<Longrightarrow> (f ---> l) F \<Longrightarrow> ((\<lambda>x. g (f x)) ---> g l) F"
hoelzl@50323
   887
  unfolding tendsto_at_iff_tendsto_nhds by (rule filterlim_compose[of g])
huffman@44218
   888
huffman@44253
   889
lemma tendsto_compose_eventually:
hoelzl@50325
   890
  "(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
   891
  by (rule filterlim_compose[of g _ "at l"]) (auto simp add: filterlim_at)
huffman@44253
   892
huffman@44251
   893
lemma metric_tendsto_imp_tendsto:
huffman@44251
   894
  assumes f: "(f ---> a) F"
huffman@44251
   895
  assumes le: "eventually (\<lambda>x. dist (g x) b \<le> dist (f x) a) F"
huffman@44251
   896
  shows "(g ---> b) F"
huffman@44251
   897
proof (rule tendstoI)
huffman@44251
   898
  fix e :: real assume "0 < e"
huffman@44251
   899
  with f have "eventually (\<lambda>x. dist (f x) a < e) F" by (rule tendstoD)
huffman@44251
   900
  with le show "eventually (\<lambda>x. dist (g x) b < e) F"
huffman@44251
   901
    using le_less_trans by (rule eventually_elim2)
huffman@44251
   902
qed
huffman@44251
   903
huffman@44205
   904
subsubsection {* Distance and norms *}
huffman@36662
   905
huffman@31565
   906
lemma tendsto_dist [tendsto_intros]:
huffman@44195
   907
  assumes f: "(f ---> l) F" and g: "(g ---> m) F"
huffman@44195
   908
  shows "((\<lambda>x. dist (f x) (g x)) ---> dist l m) F"
huffman@31565
   909
proof (rule tendstoI)
huffman@31565
   910
  fix e :: real assume "0 < e"
huffman@31565
   911
  hence e2: "0 < e/2" by simp
huffman@31565
   912
  from tendstoD [OF f e2] tendstoD [OF g e2]
huffman@44195
   913
  show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) F"
noschinl@46887
   914
  proof (eventually_elim)
noschinl@46887
   915
    case (elim x)
huffman@31565
   916
    then show "dist (dist (f x) (g x)) (dist l m) < e"
huffman@31565
   917
      unfolding dist_real_def
huffman@31565
   918
      using dist_triangle2 [of "f x" "g x" "l"]
huffman@31565
   919
      using dist_triangle2 [of "g x" "l" "m"]
huffman@31565
   920
      using dist_triangle3 [of "l" "m" "f x"]
huffman@31565
   921
      using dist_triangle [of "f x" "m" "g x"]
huffman@31565
   922
      by arith
huffman@31565
   923
  qed
huffman@31565
   924
qed
huffman@31565
   925
huffman@36662
   926
lemma norm_conv_dist: "norm x = dist x 0"
huffman@44081
   927
  unfolding dist_norm by simp
huffman@36662
   928
huffman@31565
   929
lemma tendsto_norm [tendsto_intros]:
huffman@44195
   930
  "(f ---> a) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> norm a) F"
huffman@44081
   931
  unfolding norm_conv_dist by (intro tendsto_intros)
huffman@36662
   932
huffman@36662
   933
lemma tendsto_norm_zero:
huffman@44195
   934
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> 0) F"
huffman@44081
   935
  by (drule tendsto_norm, simp)
huffman@36662
   936
huffman@36662
   937
lemma tendsto_norm_zero_cancel:
huffman@44195
   938
  "((\<lambda>x. norm (f x)) ---> 0) F \<Longrightarrow> (f ---> 0) F"
huffman@44081
   939
  unfolding tendsto_iff dist_norm by simp
huffman@36662
   940
huffman@36662
   941
lemma tendsto_norm_zero_iff:
huffman@44195
   942
  "((\<lambda>x. norm (f x)) ---> 0) F \<longleftrightarrow> (f ---> 0) F"
huffman@44081
   943
  unfolding tendsto_iff dist_norm by simp
huffman@31349
   944
huffman@44194
   945
lemma tendsto_rabs [tendsto_intros]:
huffman@44195
   946
  "(f ---> (l::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> \<bar>l\<bar>) F"
huffman@44194
   947
  by (fold real_norm_def, rule tendsto_norm)
huffman@44194
   948
huffman@44194
   949
lemma tendsto_rabs_zero:
huffman@44195
   950
  "(f ---> (0::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> 0) F"
huffman@44194
   951
  by (fold real_norm_def, rule tendsto_norm_zero)
huffman@44194
   952
huffman@44194
   953
lemma tendsto_rabs_zero_cancel:
huffman@44195
   954
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<Longrightarrow> (f ---> 0) F"
huffman@44194
   955
  by (fold real_norm_def, rule tendsto_norm_zero_cancel)
huffman@44194
   956
huffman@44194
   957
lemma tendsto_rabs_zero_iff:
huffman@44195
   958
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<longleftrightarrow> (f ---> 0) F"
huffman@44194
   959
  by (fold real_norm_def, rule tendsto_norm_zero_iff)
huffman@44194
   960
huffman@44194
   961
subsubsection {* Addition and subtraction *}
huffman@44194
   962
huffman@31565
   963
lemma tendsto_add [tendsto_intros]:
huffman@31349
   964
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   965
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> a + b) F"
huffman@44081
   966
  by (simp only: tendsto_Zfun_iff add_diff_add Zfun_add)
huffman@31349
   967
huffman@44194
   968
lemma tendsto_add_zero:
huffman@44194
   969
  fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
huffman@44195
   970
  shows "\<lbrakk>(f ---> 0) F; (g ---> 0) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> 0) F"
huffman@44194
   971
  by (drule (1) tendsto_add, simp)
huffman@44194
   972
huffman@31565
   973
lemma tendsto_minus [tendsto_intros]:
huffman@31349
   974
  fixes a :: "'a::real_normed_vector"
huffman@44195
   975
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. - f x) ---> - a) F"
huffman@44081
   976
  by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
huffman@31349
   977
huffman@31349
   978
lemma tendsto_minus_cancel:
huffman@31349
   979
  fixes a :: "'a::real_normed_vector"
huffman@44195
   980
  shows "((\<lambda>x. - f x) ---> - a) F \<Longrightarrow> (f ---> a) F"
huffman@44081
   981
  by (drule tendsto_minus, simp)
huffman@31349
   982
hoelzl@50330
   983
lemma tendsto_minus_cancel_left:
hoelzl@50330
   984
    "(f ---> - (y::_::real_normed_vector)) F \<longleftrightarrow> ((\<lambda>x. - f x) ---> y) F"
hoelzl@50330
   985
  using tendsto_minus_cancel[of f "- y" F]  tendsto_minus[of f "- y" F]
hoelzl@50330
   986
  by auto
hoelzl@50330
   987
huffman@31565
   988
lemma tendsto_diff [tendsto_intros]:
huffman@31349
   989
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   990
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x - g x) ---> a - b) F"
huffman@44081
   991
  by (simp add: diff_minus tendsto_add tendsto_minus)
huffman@31349
   992
huffman@31588
   993
lemma tendsto_setsum [tendsto_intros]:
huffman@31588
   994
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
huffman@44195
   995
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> a i) F"
huffman@44195
   996
  shows "((\<lambda>x. \<Sum>i\<in>S. f i x) ---> (\<Sum>i\<in>S. a i)) F"
huffman@31588
   997
proof (cases "finite S")
huffman@31588
   998
  assume "finite S" thus ?thesis using assms
huffman@44194
   999
    by (induct, simp add: tendsto_const, simp add: tendsto_add)
huffman@31588
  1000
next
huffman@31588
  1001
  assume "\<not> finite S" thus ?thesis
huffman@31588
  1002
    by (simp add: tendsto_const)
huffman@31588
  1003
qed
huffman@31588
  1004
noschinl@45892
  1005
lemma real_tendsto_sandwich:
noschinl@45892
  1006
  fixes f g h :: "'a \<Rightarrow> real"
noschinl@45892
  1007
  assumes ev: "eventually (\<lambda>n. f n \<le> g n) net" "eventually (\<lambda>n. g n \<le> h n) net"
noschinl@45892
  1008
  assumes lim: "(f ---> c) net" "(h ---> c) net"
noschinl@45892
  1009
  shows "(g ---> c) net"
noschinl@45892
  1010
proof -
noschinl@45892
  1011
  have "((\<lambda>n. g n - f n) ---> 0) net"
noschinl@45892
  1012
  proof (rule metric_tendsto_imp_tendsto)
noschinl@45892
  1013
    show "eventually (\<lambda>n. dist (g n - f n) 0 \<le> dist (h n - f n) 0) net"
noschinl@45892
  1014
      using ev by (rule eventually_elim2) (simp add: dist_real_def)
noschinl@45892
  1015
    show "((\<lambda>n. h n - f n) ---> 0) net"
noschinl@45892
  1016
      using tendsto_diff[OF lim(2,1)] by simp
noschinl@45892
  1017
  qed
noschinl@45892
  1018
  from tendsto_add[OF this lim(1)] show ?thesis by simp
noschinl@45892
  1019
qed
noschinl@45892
  1020
huffman@44194
  1021
subsubsection {* Linear operators and multiplication *}
huffman@44194
  1022
huffman@44282
  1023
lemma (in bounded_linear) tendsto:
huffman@44195
  1024
  "(g ---> a) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> f a) F"
huffman@44081
  1025
  by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
huffman@31349
  1026
huffman@44194
  1027
lemma (in bounded_linear) tendsto_zero:
huffman@44195
  1028
  "(g ---> 0) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> 0) F"
huffman@44194
  1029
  by (drule tendsto, simp only: zero)
huffman@44194
  1030
huffman@44282
  1031
lemma (in bounded_bilinear) tendsto:
huffman@44195
  1032
  "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ** g x) ---> a ** b) F"
huffman@44081
  1033
  by (simp only: tendsto_Zfun_iff prod_diff_prod
huffman@44081
  1034
                 Zfun_add Zfun Zfun_left Zfun_right)
huffman@31349
  1035
huffman@44194
  1036
lemma (in bounded_bilinear) tendsto_zero:
huffman@44195
  1037
  assumes f: "(f ---> 0) F"
huffman@44195
  1038
  assumes g: "(g ---> 0) F"
huffman@44195
  1039
  shows "((\<lambda>x. f x ** g x) ---> 0) F"
huffman@44194
  1040
  using tendsto [OF f g] by (simp add: zero_left)
huffman@31355
  1041
huffman@44194
  1042
lemma (in bounded_bilinear) tendsto_left_zero:
huffman@44195
  1043
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. f x ** c) ---> 0) F"
huffman@44194
  1044
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_left])
huffman@44194
  1045
huffman@44194
  1046
lemma (in bounded_bilinear) tendsto_right_zero:
huffman@44195
  1047
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. c ** f x) ---> 0) F"
huffman@44194
  1048
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_right])
huffman@44194
  1049
huffman@44282
  1050
lemmas tendsto_of_real [tendsto_intros] =
huffman@44282
  1051
  bounded_linear.tendsto [OF bounded_linear_of_real]
huffman@44282
  1052
huffman@44282
  1053
lemmas tendsto_scaleR [tendsto_intros] =
huffman@44282
  1054
  bounded_bilinear.tendsto [OF bounded_bilinear_scaleR]
huffman@44282
  1055
huffman@44282
  1056
lemmas tendsto_mult [tendsto_intros] =
huffman@44282
  1057
  bounded_bilinear.tendsto [OF bounded_bilinear_mult]
huffman@44194
  1058
huffman@44568
  1059
lemmas tendsto_mult_zero =
huffman@44568
  1060
  bounded_bilinear.tendsto_zero [OF bounded_bilinear_mult]
huffman@44568
  1061
huffman@44568
  1062
lemmas tendsto_mult_left_zero =
huffman@44568
  1063
  bounded_bilinear.tendsto_left_zero [OF bounded_bilinear_mult]
huffman@44568
  1064
huffman@44568
  1065
lemmas tendsto_mult_right_zero =
huffman@44568
  1066
  bounded_bilinear.tendsto_right_zero [OF bounded_bilinear_mult]
huffman@44568
  1067
huffman@44194
  1068
lemma tendsto_power [tendsto_intros]:
huffman@44194
  1069
  fixes f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra}"
huffman@44195
  1070
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. f x ^ n) ---> a ^ n) F"
huffman@44194
  1071
  by (induct n) (simp_all add: tendsto_const tendsto_mult)
huffman@44194
  1072
huffman@44194
  1073
lemma tendsto_setprod [tendsto_intros]:
huffman@44194
  1074
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
huffman@44195
  1075
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> L i) F"
huffman@44195
  1076
  shows "((\<lambda>x. \<Prod>i\<in>S. f i x) ---> (\<Prod>i\<in>S. L i)) F"
huffman@44194
  1077
proof (cases "finite S")
huffman@44194
  1078
  assume "finite S" thus ?thesis using assms
huffman@44194
  1079
    by (induct, simp add: tendsto_const, simp add: tendsto_mult)
huffman@44194
  1080
next
huffman@44194
  1081
  assume "\<not> finite S" thus ?thesis
huffman@44194
  1082
    by (simp add: tendsto_const)
huffman@44194
  1083
qed
huffman@44194
  1084
hoelzl@50331
  1085
lemma tendsto_le_const:
hoelzl@50331
  1086
  fixes f :: "_ \<Rightarrow> real" 
hoelzl@50331
  1087
  assumes F: "\<not> trivial_limit F"
hoelzl@50331
  1088
  assumes x: "(f ---> x) F" and a: "eventually (\<lambda>x. a \<le> f x) F"
hoelzl@50331
  1089
  shows "a \<le> x"
hoelzl@50331
  1090
proof (rule ccontr)
hoelzl@50331
  1091
  assume "\<not> a \<le> x"
hoelzl@50331
  1092
  with x have "eventually (\<lambda>x. f x < a) F"
hoelzl@50331
  1093
    by (auto simp add: tendsto_def elim!: allE[of _ "{..< a}"])
hoelzl@50331
  1094
  with a have "eventually (\<lambda>x. False) F"
hoelzl@50331
  1095
    by eventually_elim auto
hoelzl@50331
  1096
  with F show False
hoelzl@50331
  1097
    by (simp add: eventually_False)
hoelzl@50331
  1098
qed
hoelzl@50331
  1099
hoelzl@50331
  1100
lemma tendsto_le:
hoelzl@50331
  1101
  fixes f g :: "_ \<Rightarrow> real" 
hoelzl@50331
  1102
  assumes F: "\<not> trivial_limit F"
hoelzl@50331
  1103
  assumes x: "(f ---> x) F" and y: "(g ---> y) F"
hoelzl@50331
  1104
  assumes ev: "eventually (\<lambda>x. g x \<le> f x) F"
hoelzl@50331
  1105
  shows "y \<le> x"
hoelzl@50331
  1106
  using tendsto_le_const[OF F tendsto_diff[OF x y], of 0] ev
hoelzl@50331
  1107
  by (simp add: sign_simps)
hoelzl@50331
  1108
huffman@44194
  1109
subsubsection {* Inverse and division *}
huffman@31355
  1110
huffman@31355
  1111
lemma (in bounded_bilinear) Zfun_prod_Bfun:
huffman@44195
  1112
  assumes f: "Zfun f F"
huffman@44195
  1113
  assumes g: "Bfun g F"
huffman@44195
  1114
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31355
  1115
proof -
huffman@31355
  1116
  obtain K where K: "0 \<le> K"
huffman@31355
  1117
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31355
  1118
    using nonneg_bounded by fast
huffman@31355
  1119
  obtain B where B: "0 < B"
huffman@44195
  1120
    and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) F"
huffman@31487
  1121
    using g by (rule BfunE)
huffman@44195
  1122
  have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) F"
noschinl@46887
  1123
  using norm_g proof eventually_elim
noschinl@46887
  1124
    case (elim x)
huffman@31487
  1125
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31355
  1126
      by (rule norm_le)
huffman@31487
  1127
    also have "\<dots> \<le> norm (f x) * B * K"
huffman@31487
  1128
      by (intro mult_mono' order_refl norm_g norm_ge_zero
noschinl@46887
  1129
                mult_nonneg_nonneg K elim)
huffman@31487
  1130
    also have "\<dots> = norm (f x) * (B * K)"
huffman@31355
  1131
      by (rule mult_assoc)
huffman@31487
  1132
    finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
huffman@31355
  1133
  qed
huffman@31487
  1134
  with f show ?thesis
huffman@31487
  1135
    by (rule Zfun_imp_Zfun)
huffman@31355
  1136
qed
huffman@31355
  1137
huffman@31355
  1138
lemma (in bounded_bilinear) flip:
huffman@31355
  1139
  "bounded_bilinear (\<lambda>x y. y ** x)"
huffman@44081
  1140
  apply default
huffman@44081
  1141
  apply (rule add_right)
huffman@44081
  1142
  apply (rule add_left)
huffman@44081
  1143
  apply (rule scaleR_right)
huffman@44081
  1144
  apply (rule scaleR_left)
huffman@44081
  1145
  apply (subst mult_commute)
huffman@44081
  1146
  using bounded by fast
huffman@31355
  1147
huffman@31355
  1148
lemma (in bounded_bilinear) Bfun_prod_Zfun:
huffman@44195
  1149
  assumes f: "Bfun f F"
huffman@44195
  1150
  assumes g: "Zfun g F"
huffman@44195
  1151
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@44081
  1152
  using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
huffman@31355
  1153
huffman@31355
  1154
lemma Bfun_inverse_lemma:
huffman@31355
  1155
  fixes x :: "'a::real_normed_div_algebra"
huffman@31355
  1156
  shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
huffman@44081
  1157
  apply (subst nonzero_norm_inverse, clarsimp)
huffman@44081
  1158
  apply (erule (1) le_imp_inverse_le)
huffman@44081
  1159
  done
huffman@31355
  1160
huffman@31355
  1161
lemma Bfun_inverse:
huffman@31355
  1162
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
  1163
  assumes f: "(f ---> a) F"
huffman@31355
  1164
  assumes a: "a \<noteq> 0"
huffman@44195
  1165
  shows "Bfun (\<lambda>x. inverse (f x)) F"
huffman@31355
  1166
proof -
huffman@31355
  1167
  from a have "0 < norm a" by simp
huffman@31355
  1168
  hence "\<exists>r>0. r < norm a" by (rule dense)
huffman@31355
  1169
  then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
huffman@44195
  1170
  have "eventually (\<lambda>x. dist (f x) a < r) F"
huffman@31487
  1171
    using tendstoD [OF f r1] by fast
huffman@44195
  1172
  hence "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) F"
noschinl@46887
  1173
  proof eventually_elim
noschinl@46887
  1174
    case (elim x)
huffman@31487
  1175
    hence 1: "norm (f x - a) < r"
huffman@31355
  1176
      by (simp add: dist_norm)
huffman@31487
  1177
    hence 2: "f x \<noteq> 0" using r2 by auto
huffman@31487
  1178
    hence "norm (inverse (f x)) = inverse (norm (f x))"
huffman@31355
  1179
      by (rule nonzero_norm_inverse)
huffman@31355
  1180
    also have "\<dots> \<le> inverse (norm a - r)"
huffman@31355
  1181
    proof (rule le_imp_inverse_le)
huffman@31355
  1182
      show "0 < norm a - r" using r2 by simp
huffman@31355
  1183
    next
huffman@31487
  1184
      have "norm a - norm (f x) \<le> norm (a - f x)"
huffman@31355
  1185
        by (rule norm_triangle_ineq2)
huffman@31487
  1186
      also have "\<dots> = norm (f x - a)"
huffman@31355
  1187
        by (rule norm_minus_commute)
huffman@31355
  1188
      also have "\<dots> < r" using 1 .
huffman@31487
  1189
      finally show "norm a - r \<le> norm (f x)" by simp
huffman@31355
  1190
    qed
huffman@31487
  1191
    finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
huffman@31355
  1192
  qed
huffman@31355
  1193
  thus ?thesis by (rule BfunI)
huffman@31355
  1194
qed
huffman@31355
  1195
huffman@31565
  1196
lemma tendsto_inverse [tendsto_intros]:
huffman@31355
  1197
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
  1198
  assumes f: "(f ---> a) F"
huffman@31355
  1199
  assumes a: "a \<noteq> 0"
huffman@44195
  1200
  shows "((\<lambda>x. inverse (f x)) ---> inverse a) F"
huffman@31355
  1201
proof -
huffman@31355
  1202
  from a have "0 < norm a" by simp
huffman@44195
  1203
  with f have "eventually (\<lambda>x. dist (f x) a < norm a) F"
huffman@31355
  1204
    by (rule tendstoD)
huffman@44195
  1205
  then have "eventually (\<lambda>x. f x \<noteq> 0) F"
huffman@31355
  1206
    unfolding dist_norm by (auto elim!: eventually_elim1)
huffman@44627
  1207
  with a have "eventually (\<lambda>x. inverse (f x) - inverse a =
huffman@44627
  1208
    - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
  1209
    by (auto elim!: eventually_elim1 simp: inverse_diff_inverse)
huffman@44627
  1210
  moreover have "Zfun (\<lambda>x. - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
  1211
    by (intro Zfun_minus Zfun_mult_left
huffman@44627
  1212
      bounded_bilinear.Bfun_prod_Zfun [OF bounded_bilinear_mult]
huffman@44627
  1213
      Bfun_inverse [OF f a] f [unfolded tendsto_Zfun_iff])
huffman@44627
  1214
  ultimately show ?thesis
huffman@44627
  1215
    unfolding tendsto_Zfun_iff by (rule Zfun_ssubst)
huffman@31355
  1216
qed
huffman@31355
  1217
huffman@31565
  1218
lemma tendsto_divide [tendsto_intros]:
huffman@31355
  1219
  fixes a b :: "'a::real_normed_field"
huffman@44195
  1220
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F; b \<noteq> 0\<rbrakk>
huffman@44195
  1221
    \<Longrightarrow> ((\<lambda>x. f x / g x) ---> a / b) F"
huffman@44282
  1222
  by (simp add: tendsto_mult tendsto_inverse divide_inverse)
huffman@31355
  1223
huffman@44194
  1224
lemma tendsto_sgn [tendsto_intros]:
huffman@44194
  1225
  fixes l :: "'a::real_normed_vector"
huffman@44195
  1226
  shows "\<lbrakk>(f ---> l) F; l \<noteq> 0\<rbrakk> \<Longrightarrow> ((\<lambda>x. sgn (f x)) ---> sgn l) F"
huffman@44194
  1227
  unfolding sgn_div_norm by (simp add: tendsto_intros)
huffman@44194
  1228
hoelzl@50247
  1229
subsection {* Limits to @{const at_top} and @{const at_bot} *}
hoelzl@50247
  1230
hoelzl@50322
  1231
lemma filterlim_at_top:
hoelzl@50346
  1232
  fixes f :: "'a \<Rightarrow> ('b::linorder)"
hoelzl@50346
  1233
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. Z \<le> f x) F)"
hoelzl@50346
  1234
  by (auto simp: filterlim_iff eventually_at_top_linorder elim!: eventually_elim1)
hoelzl@50346
  1235
hoelzl@50346
  1236
lemma filterlim_at_top_dense:
hoelzl@50247
  1237
  fixes f :: "'a \<Rightarrow> ('b::dense_linorder)"
hoelzl@50247
  1238
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. Z < f x) F)"
hoelzl@50346
  1239
  by (metis eventually_elim1[of _ F] eventually_gt_at_top order_less_imp_le
hoelzl@50346
  1240
            filterlim_at_top[of f F] filterlim_iff[of f at_top F])
hoelzl@50247
  1241
hoelzl@50346
  1242
lemma filterlim_at_top_ge:
hoelzl@50346
  1243
  fixes f :: "'a \<Rightarrow> ('b::linorder)" and c :: "'b"
hoelzl@50346
  1244
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z\<ge>c. eventually (\<lambda>x. Z \<le> f x) F)"
hoelzl@50323
  1245
  unfolding filterlim_at_top
hoelzl@50323
  1246
proof safe
hoelzl@50346
  1247
  fix Z assume *: "\<forall>Z\<ge>c. eventually (\<lambda>x. Z \<le> f x) F"
hoelzl@50346
  1248
  with *[THEN spec, of "max Z c"] show "eventually (\<lambda>x. Z \<le> f x) F"
hoelzl@50323
  1249
    by (auto elim!: eventually_elim1)
hoelzl@50323
  1250
qed simp
hoelzl@50323
  1251
hoelzl@50346
  1252
lemma filterlim_at_top_at_top:
hoelzl@50346
  1253
  fixes f :: "'a::linorder \<Rightarrow> 'b::linorder"
hoelzl@50346
  1254
  assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@50346
  1255
  assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
hoelzl@50346
  1256
  assumes Q: "eventually Q at_top"
hoelzl@50346
  1257
  assumes P: "eventually P at_top"
hoelzl@50346
  1258
  shows "filterlim f at_top at_top"
hoelzl@50346
  1259
proof -
hoelzl@50346
  1260
  from P obtain x where x: "\<And>y. x \<le> y \<Longrightarrow> P y"
hoelzl@50346
  1261
    unfolding eventually_at_top_linorder by auto
hoelzl@50346
  1262
  show ?thesis
hoelzl@50346
  1263
  proof (intro filterlim_at_top_ge[THEN iffD2] allI impI)
hoelzl@50346
  1264
    fix z assume "x \<le> z"
hoelzl@50346
  1265
    with x have "P z" by auto
hoelzl@50346
  1266
    have "eventually (\<lambda>x. g z \<le> x) at_top"
hoelzl@50346
  1267
      by (rule eventually_ge_at_top)
hoelzl@50346
  1268
    with Q show "eventually (\<lambda>x. z \<le> f x) at_top"
hoelzl@50346
  1269
      by eventually_elim (metis mono bij `P z`)
hoelzl@50346
  1270
  qed
hoelzl@50346
  1271
qed
hoelzl@50346
  1272
hoelzl@50346
  1273
lemma filterlim_at_top_gt:
hoelzl@50346
  1274
  fixes f :: "'a \<Rightarrow> ('b::dense_linorder)" and c :: "'b"
hoelzl@50346
  1275
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z>c. eventually (\<lambda>x. Z \<le> f x) F)"
hoelzl@50346
  1276
  by (metis filterlim_at_top order_less_le_trans gt_ex filterlim_at_top_ge)
hoelzl@50346
  1277
hoelzl@50322
  1278
lemma filterlim_at_bot: 
hoelzl@50346
  1279
  fixes f :: "'a \<Rightarrow> ('b::linorder)"
hoelzl@50346
  1280
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. f x \<le> Z) F)"
hoelzl@50346
  1281
  by (auto simp: filterlim_iff eventually_at_bot_linorder elim!: eventually_elim1)
hoelzl@50346
  1282
hoelzl@50346
  1283
lemma filterlim_at_bot_le:
hoelzl@50346
  1284
  fixes f :: "'a \<Rightarrow> ('b::linorder)" and c :: "'b"
hoelzl@50346
  1285
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z\<le>c. eventually (\<lambda>x. Z \<ge> f x) F)"
hoelzl@50346
  1286
  unfolding filterlim_at_bot
hoelzl@50346
  1287
proof safe
hoelzl@50346
  1288
  fix Z assume *: "\<forall>Z\<le>c. eventually (\<lambda>x. Z \<ge> f x) F"
hoelzl@50346
  1289
  with *[THEN spec, of "min Z c"] show "eventually (\<lambda>x. Z \<ge> f x) F"
hoelzl@50346
  1290
    by (auto elim!: eventually_elim1)
hoelzl@50346
  1291
qed simp
hoelzl@50247
  1292
hoelzl@50323
  1293
lemma filterlim_at_bot_lt:
hoelzl@50323
  1294
  fixes f :: "'a \<Rightarrow> ('b::dense_linorder)" and c :: "'b"
hoelzl@50346
  1295
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z<c. eventually (\<lambda>x. Z \<ge> f x) F)"
hoelzl@50346
  1296
  by (metis filterlim_at_bot filterlim_at_bot_le lt_ex order_le_less_trans)
hoelzl@50346
  1297
hoelzl@50346
  1298
lemma filterlim_at_bot_at_right:
hoelzl@50346
  1299
  fixes f :: "real \<Rightarrow> 'b::linorder"
hoelzl@50346
  1300
  assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@50346
  1301
  assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
hoelzl@50346
  1302
  assumes Q: "eventually Q (at_right a)" and bound: "\<And>b. Q b \<Longrightarrow> a < b"
hoelzl@50346
  1303
  assumes P: "eventually P at_bot"
hoelzl@50346
  1304
  shows "filterlim f at_bot (at_right a)"
hoelzl@50346
  1305
proof -
hoelzl@50346
  1306
  from P obtain x where x: "\<And>y. y \<le> x \<Longrightarrow> P y"
hoelzl@50346
  1307
    unfolding eventually_at_bot_linorder by auto
hoelzl@50346
  1308
  show ?thesis
hoelzl@50346
  1309
  proof (intro filterlim_at_bot_le[THEN iffD2] allI impI)
hoelzl@50346
  1310
    fix z assume "z \<le> x"
hoelzl@50346
  1311
    with x have "P z" by auto
hoelzl@50346
  1312
    have "eventually (\<lambda>x. x \<le> g z) (at_right a)"
hoelzl@50346
  1313
      using bound[OF bij(2)[OF `P z`]]
hoelzl@50346
  1314
      by (auto simp add: eventually_within_less dist_real_def intro!:  exI[of _ "g z - a"])
hoelzl@50346
  1315
    with Q show "eventually (\<lambda>x. f x \<le> z) (at_right a)"
hoelzl@50346
  1316
      by eventually_elim (metis bij `P z` mono)
hoelzl@50346
  1317
  qed
hoelzl@50346
  1318
qed
hoelzl@50346
  1319
hoelzl@50346
  1320
lemma filterlim_at_top_at_left:
hoelzl@50346
  1321
  fixes f :: "real \<Rightarrow> 'b::linorder"
hoelzl@50346
  1322
  assumes mono: "\<And>x y. Q x \<Longrightarrow> Q y \<Longrightarrow> x \<le> y \<Longrightarrow> f x \<le> f y"
hoelzl@50346
  1323
  assumes bij: "\<And>x. P x \<Longrightarrow> f (g x) = x" "\<And>x. P x \<Longrightarrow> Q (g x)"
hoelzl@50346
  1324
  assumes Q: "eventually Q (at_left a)" and bound: "\<And>b. Q b \<Longrightarrow> b < a"
hoelzl@50346
  1325
  assumes P: "eventually P at_top"
hoelzl@50346
  1326
  shows "filterlim f at_top (at_left a)"
hoelzl@50346
  1327
proof -
hoelzl@50346
  1328
  from P obtain x where x: "\<And>y. x \<le> y \<Longrightarrow> P y"
hoelzl@50346
  1329
    unfolding eventually_at_top_linorder by auto
hoelzl@50346
  1330
  show ?thesis
hoelzl@50346
  1331
  proof (intro filterlim_at_top_ge[THEN iffD2] allI impI)
hoelzl@50346
  1332
    fix z assume "x \<le> z"
hoelzl@50346
  1333
    with x have "P z" by auto
hoelzl@50346
  1334
    have "eventually (\<lambda>x. g z \<le> x) (at_left a)"
hoelzl@50346
  1335
      using bound[OF bij(2)[OF `P z`]]
hoelzl@50346
  1336
      by (auto simp add: eventually_within_less dist_real_def intro!:  exI[of _ "a - g z"])
hoelzl@50346
  1337
    with Q show "eventually (\<lambda>x. z \<le> f x) (at_left a)"
hoelzl@50346
  1338
      by eventually_elim (metis bij `P z` mono)
hoelzl@50346
  1339
  qed
hoelzl@50346
  1340
qed
hoelzl@50323
  1341
hoelzl@50325
  1342
lemma filterlim_at_infinity:
hoelzl@50325
  1343
  fixes f :: "_ \<Rightarrow> 'a\<Colon>real_normed_vector"
hoelzl@50325
  1344
  assumes "0 \<le> c"
hoelzl@50325
  1345
  shows "(LIM x F. f x :> at_infinity) \<longleftrightarrow> (\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F)"
hoelzl@50325
  1346
  unfolding filterlim_iff eventually_at_infinity
hoelzl@50325
  1347
proof safe
hoelzl@50325
  1348
  fix P :: "'a \<Rightarrow> bool" and b
hoelzl@50325
  1349
  assume *: "\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F"
hoelzl@50325
  1350
    and P: "\<forall>x. b \<le> norm x \<longrightarrow> P x"
hoelzl@50325
  1351
  have "max b (c + 1) > c" by auto
hoelzl@50325
  1352
  with * have "eventually (\<lambda>x. max b (c + 1) \<le> norm (f x)) F"
hoelzl@50325
  1353
    by auto
hoelzl@50325
  1354
  then show "eventually (\<lambda>x. P (f x)) F"
hoelzl@50325
  1355
  proof eventually_elim
hoelzl@50325
  1356
    fix x assume "max b (c + 1) \<le> norm (f x)"
hoelzl@50325
  1357
    with P show "P (f x)" by auto
hoelzl@50325
  1358
  qed
hoelzl@50325
  1359
qed force
hoelzl@50325
  1360
hoelzl@50322
  1361
lemma filterlim_real_sequentially: "LIM x sequentially. real x :> at_top"
hoelzl@50322
  1362
  unfolding filterlim_at_top
hoelzl@50247
  1363
  apply (intro allI)
hoelzl@50247
  1364
  apply (rule_tac c="natceiling (Z + 1)" in eventually_sequentiallyI)
hoelzl@50247
  1365
  apply (auto simp: natceiling_le_eq)
hoelzl@50247
  1366
  done
hoelzl@50247
  1367
hoelzl@50347
  1368
subsection {* Relate @{const at}, @{const at_left} and @{const at_right} *}
hoelzl@50347
  1369
hoelzl@50347
  1370
text {*
hoelzl@50347
  1371
hoelzl@50347
  1372
This lemmas are useful for conversion between @{term "at x"} to @{term "at_left x"} and
hoelzl@50347
  1373
@{term "at_right x"} and also @{term "at_right 0"}.
hoelzl@50347
  1374
hoelzl@50347
  1375
*}
hoelzl@50347
  1376
hoelzl@50347
  1377
lemma at_eq_sup_left_right: "at (x::real) = sup (at_left x) (at_right x)"
hoelzl@50347
  1378
  by (auto simp: eventually_within at_def filter_eq_iff eventually_sup 
hoelzl@50347
  1379
           elim: eventually_elim2 eventually_elim1)
hoelzl@50347
  1380
hoelzl@50347
  1381
lemma filterlim_split_at_real:
hoelzl@50347
  1382
  "filterlim f F (at_left x) \<Longrightarrow> filterlim f F (at_right x) \<Longrightarrow> filterlim f F (at (x::real))"
hoelzl@50347
  1383
  by (subst at_eq_sup_left_right) (rule filterlim_sup)
hoelzl@50323
  1384
hoelzl@50347
  1385
lemma filtermap_nhds_shift: "filtermap (\<lambda>x. x - d) (nhds a) = nhds (a - d::real)"
hoelzl@50347
  1386
  unfolding filter_eq_iff eventually_filtermap eventually_nhds_metric
hoelzl@50347
  1387
  by (intro allI ex_cong) (auto simp: dist_real_def field_simps)
hoelzl@50347
  1388
hoelzl@50347
  1389
lemma filtermap_nhds_minus: "filtermap (\<lambda>x. - x) (nhds a) = nhds (- a::real)"
hoelzl@50347
  1390
  unfolding filter_eq_iff eventually_filtermap eventually_nhds_metric
hoelzl@50347
  1391
  apply (intro allI ex_cong)
hoelzl@50347
  1392
  apply (auto simp: dist_real_def field_simps)
hoelzl@50347
  1393
  apply (erule_tac x="-x" in allE)
hoelzl@50347
  1394
  apply simp
hoelzl@50347
  1395
  done
hoelzl@50347
  1396
hoelzl@50347
  1397
lemma filtermap_at_shift: "filtermap (\<lambda>x. x - d) (at a) = at (a - d::real)"
hoelzl@50347
  1398
  unfolding at_def filtermap_nhds_shift[symmetric]
hoelzl@50347
  1399
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50347
  1400
hoelzl@50347
  1401
lemma filtermap_at_right_shift: "filtermap (\<lambda>x. x - d) (at_right a) = at_right (a - d::real)"
hoelzl@50347
  1402
  unfolding filtermap_at_shift[symmetric]
hoelzl@50347
  1403
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50323
  1404
hoelzl@50347
  1405
lemma at_right_to_0: "at_right (a::real) = filtermap (\<lambda>x. x + a) (at_right 0)"
hoelzl@50347
  1406
  using filtermap_at_right_shift[of "-a" 0] by simp
hoelzl@50347
  1407
hoelzl@50347
  1408
lemma filterlim_at_right_to_0:
hoelzl@50347
  1409
  "filterlim f F (at_right (a::real)) \<longleftrightarrow> filterlim (\<lambda>x. f (x + a)) F (at_right 0)"
hoelzl@50347
  1410
  unfolding filterlim_def filtermap_filtermap at_right_to_0[of a] ..
hoelzl@50347
  1411
hoelzl@50347
  1412
lemma eventually_at_right_to_0:
hoelzl@50347
  1413
  "eventually P (at_right (a::real)) \<longleftrightarrow> eventually (\<lambda>x. P (x + a)) (at_right 0)"
hoelzl@50347
  1414
  unfolding at_right_to_0[of a] by (simp add: eventually_filtermap)
hoelzl@50347
  1415
hoelzl@50347
  1416
lemma filtermap_at_minus: "filtermap (\<lambda>x. - x) (at a) = at (- a::real)"
hoelzl@50347
  1417
  unfolding at_def filtermap_nhds_minus[symmetric]
hoelzl@50347
  1418
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50347
  1419
hoelzl@50347
  1420
lemma at_left_minus: "at_left (a::real) = filtermap (\<lambda>x. - x) (at_right (- a))"
hoelzl@50347
  1421
  by (simp add: filter_eq_iff eventually_filtermap eventually_within filtermap_at_minus[symmetric])
hoelzl@50323
  1422
hoelzl@50347
  1423
lemma at_right_minus: "at_right (a::real) = filtermap (\<lambda>x. - x) (at_left (- a))"
hoelzl@50347
  1424
  by (simp add: filter_eq_iff eventually_filtermap eventually_within filtermap_at_minus[symmetric])
hoelzl@50347
  1425
hoelzl@50347
  1426
lemma filterlim_at_left_to_right:
hoelzl@50347
  1427
  "filterlim f F (at_left (a::real)) \<longleftrightarrow> filterlim (\<lambda>x. f (- x)) F (at_right (-a))"
hoelzl@50347
  1428
  unfolding filterlim_def filtermap_filtermap at_left_minus[of a] ..
hoelzl@50347
  1429
hoelzl@50347
  1430
lemma eventually_at_left_to_right:
hoelzl@50347
  1431
  "eventually P (at_left (a::real)) \<longleftrightarrow> eventually (\<lambda>x. P (- x)) (at_right (-a))"
hoelzl@50347
  1432
  unfolding at_left_minus[of a] by (simp add: eventually_filtermap)
hoelzl@50347
  1433
hoelzl@50347
  1434
lemma filterlim_at_split:
hoelzl@50347
  1435
  "filterlim f F (at (x::real)) \<longleftrightarrow> filterlim f F (at_left x) \<and> filterlim f F (at_right x)"
hoelzl@50347
  1436
  by (subst at_eq_sup_left_right) (simp add: filterlim_def filtermap_sup)
hoelzl@50347
  1437
hoelzl@50347
  1438
lemma eventually_at_split:
hoelzl@50347
  1439
  "eventually P (at (x::real)) \<longleftrightarrow> eventually P (at_left x) \<and> eventually P (at_right x)"
hoelzl@50347
  1440
  by (subst at_eq_sup_left_right) (simp add: eventually_sup)
hoelzl@50323
  1441
hoelzl@50346
  1442
lemma at_top_mirror: "at_top = filtermap uminus (at_bot :: real filter)"
hoelzl@50346
  1443
  unfolding filter_eq_iff eventually_filtermap eventually_at_top_linorder eventually_at_bot_linorder
hoelzl@50346
  1444
  by (metis le_minus_iff minus_minus)
hoelzl@50346
  1445
hoelzl@50346
  1446
lemma at_bot_mirror: "at_bot = filtermap uminus (at_top :: real filter)"
hoelzl@50346
  1447
  unfolding at_top_mirror filtermap_filtermap by (simp add: filtermap_ident)
hoelzl@50346
  1448
hoelzl@50346
  1449
lemma filterlim_at_top_mirror: "(LIM x at_top. f x :> F) \<longleftrightarrow> (LIM x at_bot. f (-x::real) :> F)"
hoelzl@50346
  1450
  unfolding filterlim_def at_top_mirror filtermap_filtermap ..
hoelzl@50346
  1451
hoelzl@50346
  1452
lemma filterlim_at_bot_mirror: "(LIM x at_bot. f x :> F) \<longleftrightarrow> (LIM x at_top. f (-x::real) :> F)"
hoelzl@50346
  1453
  unfolding filterlim_def at_bot_mirror filtermap_filtermap ..
hoelzl@50346
  1454
hoelzl@50323
  1455
lemma filterlim_uminus_at_top_at_bot: "LIM x at_bot. - x :: real :> at_top"
hoelzl@50323
  1456
  unfolding filterlim_at_top eventually_at_bot_dense
hoelzl@50346
  1457
  by (metis leI minus_less_iff order_less_asym)
hoelzl@50323
  1458
hoelzl@50323
  1459
lemma filterlim_uminus_at_bot_at_top: "LIM x at_top. - x :: real :> at_bot"
hoelzl@50323
  1460
  unfolding filterlim_at_bot eventually_at_top_dense
hoelzl@50346
  1461
  by (metis leI less_minus_iff order_less_asym)
hoelzl@50323
  1462
hoelzl@50346
  1463
lemma filterlim_uminus_at_top: "(LIM x F. f x :> at_top) \<longleftrightarrow> (LIM x F. - (f x) :: real :> at_bot)"
hoelzl@50346
  1464
  using filterlim_compose[OF filterlim_uminus_at_bot_at_top, of f F]
hoelzl@50346
  1465
  using filterlim_compose[OF filterlim_uminus_at_top_at_bot, of "\<lambda>x. - f x" F]
hoelzl@50346
  1466
  by auto
hoelzl@50346
  1467
hoelzl@50346
  1468
lemma filterlim_uminus_at_bot: "(LIM x F. f x :> at_bot) \<longleftrightarrow> (LIM x F. - (f x) :: real :> at_top)"
hoelzl@50346
  1469
  unfolding filterlim_uminus_at_top by simp
hoelzl@50323
  1470
hoelzl@50347
  1471
lemma filterlim_inverse_at_top_right: "LIM x at_right (0::real). inverse x :> at_top"
hoelzl@50347
  1472
  unfolding filterlim_at_top_gt[where c=0] eventually_within at_def
hoelzl@50347
  1473
proof safe
hoelzl@50347
  1474
  fix Z :: real assume [arith]: "0 < Z"
hoelzl@50347
  1475
  then have "eventually (\<lambda>x. x < inverse Z) (nhds 0)"
hoelzl@50347
  1476
    by (auto simp add: eventually_nhds_metric dist_real_def intro!: exI[of _ "\<bar>inverse Z\<bar>"])
hoelzl@50347
  1477
  then show "eventually (\<lambda>x. x \<in> - {0} \<longrightarrow> x \<in> {0<..} \<longrightarrow> Z \<le> inverse x) (nhds 0)"
hoelzl@50347
  1478
    by (auto elim!: eventually_elim1 simp: inverse_eq_divide field_simps)
hoelzl@50347
  1479
qed
hoelzl@50347
  1480
hoelzl@50347
  1481
lemma filterlim_inverse_at_top:
hoelzl@50347
  1482
  "(f ---> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. 0 < f x) F \<Longrightarrow> LIM x F. inverse (f x) :> at_top"
hoelzl@50347
  1483
  by (intro filterlim_compose[OF filterlim_inverse_at_top_right])
hoelzl@50347
  1484
     (simp add: filterlim_def eventually_filtermap le_within_iff at_def eventually_elim1)
hoelzl@50347
  1485
hoelzl@50347
  1486
lemma filterlim_inverse_at_bot_neg:
hoelzl@50347
  1487
  "LIM x (at_left (0::real)). inverse x :> at_bot"
hoelzl@50347
  1488
  by (simp add: filterlim_inverse_at_top_right filterlim_uminus_at_bot filterlim_at_left_to_right)
hoelzl@50347
  1489
hoelzl@50347
  1490
lemma filterlim_inverse_at_bot:
hoelzl@50347
  1491
  "(f ---> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. f x < 0) F \<Longrightarrow> LIM x F. inverse (f x) :> at_bot"
hoelzl@50347
  1492
  unfolding filterlim_uminus_at_bot inverse_minus_eq[symmetric]
hoelzl@50347
  1493
  by (rule filterlim_inverse_at_top) (simp_all add: tendsto_minus_cancel_left[symmetric])
hoelzl@50347
  1494
hoelzl@50325
  1495
lemma tendsto_inverse_0:
hoelzl@50325
  1496
  fixes x :: "_ \<Rightarrow> 'a\<Colon>real_normed_div_algebra"
hoelzl@50325
  1497
  shows "(inverse ---> (0::'a)) at_infinity"
hoelzl@50325
  1498
  unfolding tendsto_Zfun_iff diff_0_right Zfun_def eventually_at_infinity
hoelzl@50325
  1499
proof safe
hoelzl@50325
  1500
  fix r :: real assume "0 < r"
hoelzl@50325
  1501
  show "\<exists>b. \<forall>x. b \<le> norm x \<longrightarrow> norm (inverse x :: 'a) < r"
hoelzl@50325
  1502
  proof (intro exI[of _ "inverse (r / 2)"] allI impI)
hoelzl@50325
  1503
    fix x :: 'a
hoelzl@50325
  1504
    from `0 < r` have "0 < inverse (r / 2)" by simp
hoelzl@50325
  1505
    also assume *: "inverse (r / 2) \<le> norm x"
hoelzl@50325
  1506
    finally show "norm (inverse x) < r"
hoelzl@50325
  1507
      using * `0 < r` by (subst nonzero_norm_inverse) (simp_all add: inverse_eq_divide field_simps)
hoelzl@50325
  1508
  qed
hoelzl@50325
  1509
qed
hoelzl@50325
  1510
hoelzl@50347
  1511
lemma at_right_to_top: "(at_right (0::real)) = filtermap inverse at_top"
hoelzl@50347
  1512
proof (rule antisym)
hoelzl@50347
  1513
  have "(inverse ---> (0::real)) at_top"
hoelzl@50347
  1514
    by (metis tendsto_inverse_0 filterlim_mono at_top_le_at_infinity order_refl)
hoelzl@50347
  1515
  then show "filtermap inverse at_top \<le> at_right (0::real)"
hoelzl@50347
  1516
    unfolding at_within_eq
hoelzl@50347
  1517
    by (intro le_withinI) (simp_all add: eventually_filtermap eventually_gt_at_top filterlim_def)
hoelzl@50347
  1518
next
hoelzl@50347
  1519
  have "filtermap inverse (filtermap inverse (at_right (0::real))) \<le> filtermap inverse at_top"
hoelzl@50347
  1520
    using filterlim_inverse_at_top_right unfolding filterlim_def by (rule filtermap_mono)
hoelzl@50347
  1521
  then show "at_right (0::real) \<le> filtermap inverse at_top"
hoelzl@50347
  1522
    by (simp add: filtermap_ident filtermap_filtermap)
hoelzl@50347
  1523
qed
hoelzl@50347
  1524
hoelzl@50347
  1525
lemma eventually_at_right_to_top:
hoelzl@50347
  1526
  "eventually P (at_right (0::real)) \<longleftrightarrow> eventually (\<lambda>x. P (inverse x)) at_top"
hoelzl@50347
  1527
  unfolding at_right_to_top eventually_filtermap ..
hoelzl@50347
  1528
hoelzl@50347
  1529
lemma filterlim_at_right_to_top:
hoelzl@50347
  1530
  "filterlim f F (at_right (0::real)) \<longleftrightarrow> (LIM x at_top. f (inverse x) :> F)"
hoelzl@50347
  1531
  unfolding filterlim_def at_right_to_top filtermap_filtermap ..
hoelzl@50347
  1532
hoelzl@50347
  1533
lemma at_top_to_right: "at_top = filtermap inverse (at_right (0::real))"
hoelzl@50347
  1534
  unfolding at_right_to_top filtermap_filtermap inverse_inverse_eq filtermap_ident ..
hoelzl@50347
  1535
hoelzl@50347
  1536
lemma eventually_at_top_to_right:
hoelzl@50347
  1537
  "eventually P at_top \<longleftrightarrow> eventually (\<lambda>x. P (inverse x)) (at_right (0::real))"
hoelzl@50347
  1538
  unfolding at_top_to_right eventually_filtermap ..
hoelzl@50347
  1539
hoelzl@50347
  1540
lemma filterlim_at_top_to_right:
hoelzl@50347
  1541
  "filterlim f F at_top \<longleftrightarrow> (LIM x (at_right (0::real)). f (inverse x) :> F)"
hoelzl@50347
  1542
  unfolding filterlim_def at_top_to_right filtermap_filtermap ..
hoelzl@50347
  1543
hoelzl@50325
  1544
lemma filterlim_inverse_at_infinity:
hoelzl@50325
  1545
  fixes x :: "_ \<Rightarrow> 'a\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50325
  1546
  shows "filterlim inverse at_infinity (at (0::'a))"
hoelzl@50325
  1547
  unfolding filterlim_at_infinity[OF order_refl]
hoelzl@50325
  1548
proof safe
hoelzl@50325
  1549
  fix r :: real assume "0 < r"
hoelzl@50325
  1550
  then show "eventually (\<lambda>x::'a. r \<le> norm (inverse x)) (at 0)"
hoelzl@50325
  1551
    unfolding eventually_at norm_inverse
hoelzl@50325
  1552
    by (intro exI[of _ "inverse r"])
hoelzl@50325
  1553
       (auto simp: norm_conv_dist[symmetric] field_simps inverse_eq_divide)
hoelzl@50325
  1554
qed
hoelzl@50325
  1555
hoelzl@50325
  1556
lemma filterlim_inverse_at_iff:
hoelzl@50325
  1557
  fixes g :: "'a \<Rightarrow> 'b\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50325
  1558
  shows "(LIM x F. inverse (g x) :> at 0) \<longleftrightarrow> (LIM x F. g x :> at_infinity)"
hoelzl@50325
  1559
  unfolding filterlim_def filtermap_filtermap[symmetric]
hoelzl@50325
  1560
proof
hoelzl@50325
  1561
  assume "filtermap g F \<le> at_infinity"
hoelzl@50325
  1562
  then have "filtermap inverse (filtermap g F) \<le> filtermap inverse at_infinity"
hoelzl@50325
  1563
    by (rule filtermap_mono)
hoelzl@50325
  1564
  also have "\<dots> \<le> at 0"
hoelzl@50325
  1565
    using tendsto_inverse_0
hoelzl@50325
  1566
    by (auto intro!: le_withinI exI[of _ 1]
hoelzl@50325
  1567
             simp: eventually_filtermap eventually_at_infinity filterlim_def at_def)
hoelzl@50325
  1568
  finally show "filtermap inverse (filtermap g F) \<le> at 0" .
hoelzl@50325
  1569
next
hoelzl@50325
  1570
  assume "filtermap inverse (filtermap g F) \<le> at 0"
hoelzl@50325
  1571
  then have "filtermap inverse (filtermap inverse (filtermap g F)) \<le> filtermap inverse (at 0)"
hoelzl@50325
  1572
    by (rule filtermap_mono)
hoelzl@50325
  1573
  with filterlim_inverse_at_infinity show "filtermap g F \<le> at_infinity"
hoelzl@50325
  1574
    by (auto intro: order_trans simp: filterlim_def filtermap_filtermap)
hoelzl@50325
  1575
qed
hoelzl@50325
  1576
hoelzl@50419
  1577
lemma tendsto_inverse_0_at_top:
hoelzl@50419
  1578
  "LIM x F. f x :> at_top \<Longrightarrow> ((\<lambda>x. inverse (f x) :: real) ---> 0) F"
hoelzl@50419
  1579
 by (metis at_top_le_at_infinity filterlim_at filterlim_inverse_at_iff filterlim_mono order_refl)
hoelzl@50419
  1580
hoelzl@50324
  1581
text {*
hoelzl@50324
  1582
hoelzl@50324
  1583
We only show rules for multiplication and addition when the functions are either against a real
hoelzl@50324
  1584
value or against infinity. Further rules are easy to derive by using @{thm filterlim_uminus_at_top}.
hoelzl@50324
  1585
hoelzl@50324
  1586
*}
hoelzl@50324
  1587
hoelzl@50324
  1588
lemma filterlim_tendsto_pos_mult_at_top: 
hoelzl@50324
  1589
  assumes f: "(f ---> c) F" and c: "0 < c"
hoelzl@50324
  1590
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
  1591
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
  1592
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1593
proof safe
hoelzl@50324
  1594
  fix Z :: real assume "0 < Z"
hoelzl@50324
  1595
  from f `0 < c` have "eventually (\<lambda>x. c / 2 < f x) F"
hoelzl@50324
  1596
    by (auto dest!: tendstoD[where e="c / 2"] elim!: eventually_elim1
hoelzl@50324
  1597
             simp: dist_real_def abs_real_def split: split_if_asm)
hoelzl@50346
  1598
  moreover from g have "eventually (\<lambda>x. (Z / c * 2) \<le> g x) F"
hoelzl@50324
  1599
    unfolding filterlim_at_top by auto
hoelzl@50346
  1600
  ultimately show "eventually (\<lambda>x. Z \<le> f x * g x) F"
hoelzl@50324
  1601
  proof eventually_elim
hoelzl@50346
  1602
    fix x assume "c / 2 < f x" "Z / c * 2 \<le> g x"
hoelzl@50346
  1603
    with `0 < Z` `0 < c` have "c / 2 * (Z / c * 2) \<le> f x * g x"
hoelzl@50346
  1604
      by (intro mult_mono) (auto simp: zero_le_divide_iff)
hoelzl@50346
  1605
    with `0 < c` show "Z \<le> f x * g x"
hoelzl@50324
  1606
       by simp
hoelzl@50324
  1607
  qed
hoelzl@50324
  1608
qed
hoelzl@50324
  1609
hoelzl@50324
  1610
lemma filterlim_at_top_mult_at_top: 
hoelzl@50324
  1611
  assumes f: "LIM x F. f x :> at_top"
hoelzl@50324
  1612
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
  1613
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
  1614
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1615
proof safe
hoelzl@50324
  1616
  fix Z :: real assume "0 < Z"
hoelzl@50346
  1617
  from f have "eventually (\<lambda>x. 1 \<le> f x) F"
hoelzl@50324
  1618
    unfolding filterlim_at_top by auto
hoelzl@50346
  1619
  moreover from g have "eventually (\<lambda>x. Z \<le> g x) F"
hoelzl@50324
  1620
    unfolding filterlim_at_top by auto
hoelzl@50346
  1621
  ultimately show "eventually (\<lambda>x. Z \<le> f x * g x) F"
hoelzl@50324
  1622
  proof eventually_elim
hoelzl@50346
  1623
    fix x assume "1 \<le> f x" "Z \<le> g x"
hoelzl@50346
  1624
    with `0 < Z` have "1 * Z \<le> f x * g x"
hoelzl@50346
  1625
      by (intro mult_mono) (auto simp: zero_le_divide_iff)
hoelzl@50346
  1626
    then show "Z \<le> f x * g x"
hoelzl@50324
  1627
       by simp
hoelzl@50324
  1628
  qed
hoelzl@50324
  1629
qed
hoelzl@50324
  1630
hoelzl@50419
  1631
lemma filterlim_tendsto_pos_mult_at_bot:
hoelzl@50419
  1632
  assumes "(f ---> c) F" "0 < (c::real)" "filterlim g at_bot F"
hoelzl@50419
  1633
  shows "LIM x F. f x * g x :> at_bot"
hoelzl@50419
  1634
  using filterlim_tendsto_pos_mult_at_top[OF assms(1,2), of "\<lambda>x. - g x"] assms(3)
hoelzl@50419
  1635
  unfolding filterlim_uminus_at_bot by simp
hoelzl@50419
  1636
hoelzl@50324
  1637
lemma filterlim_tendsto_add_at_top: 
hoelzl@50324
  1638
  assumes f: "(f ---> c) F"
hoelzl@50324
  1639
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
  1640
  shows "LIM x F. (f x + g x :: real) :> at_top"
hoelzl@50324
  1641
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1642
proof safe
hoelzl@50324
  1643
  fix Z :: real assume "0 < Z"
hoelzl@50324
  1644
  from f have "eventually (\<lambda>x. c - 1 < f x) F"
hoelzl@50324
  1645
    by (auto dest!: tendstoD[where e=1] elim!: eventually_elim1 simp: dist_real_def)
hoelzl@50346
  1646
  moreover from g have "eventually (\<lambda>x. Z - (c - 1) \<le> g x) F"
hoelzl@50324
  1647
    unfolding filterlim_at_top by auto
hoelzl@50346
  1648
  ultimately show "eventually (\<lambda>x. Z \<le> f x + g x) F"
hoelzl@50324
  1649
    by eventually_elim simp
hoelzl@50324
  1650
qed
hoelzl@50324
  1651
hoelzl@50347
  1652
lemma LIM_at_top_divide:
hoelzl@50347
  1653
  fixes f g :: "'a \<Rightarrow> real"
hoelzl@50347
  1654
  assumes f: "(f ---> a) F" "0 < a"
hoelzl@50347
  1655
  assumes g: "(g ---> 0) F" "eventually (\<lambda>x. 0 < g x) F"
hoelzl@50347
  1656
  shows "LIM x F. f x / g x :> at_top"
hoelzl@50347
  1657
  unfolding divide_inverse
hoelzl@50347
  1658
  by (rule filterlim_tendsto_pos_mult_at_top[OF f]) (rule filterlim_inverse_at_top[OF g])
hoelzl@50347
  1659
hoelzl@50324
  1660
lemma filterlim_at_top_add_at_top: 
hoelzl@50324
  1661
  assumes f: "LIM x F. f x :> at_top"
hoelzl@50324
  1662
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
  1663
  shows "LIM x F. (f x + g x :: real) :> at_top"
hoelzl@50324
  1664
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1665
proof safe
hoelzl@50324
  1666
  fix Z :: real assume "0 < Z"
hoelzl@50346
  1667
  from f have "eventually (\<lambda>x. 0 \<le> f x) F"
hoelzl@50324
  1668
    unfolding filterlim_at_top by auto
hoelzl@50346
  1669
  moreover from g have "eventually (\<lambda>x. Z \<le> g x) F"
hoelzl@50324
  1670
    unfolding filterlim_at_top by auto
hoelzl@50346
  1671
  ultimately show "eventually (\<lambda>x. Z \<le> f x + g x) F"
hoelzl@50324
  1672
    by eventually_elim simp
hoelzl@50324
  1673
qed
hoelzl@50324
  1674
hoelzl@50331
  1675
lemma tendsto_divide_0:
hoelzl@50331
  1676
  fixes f :: "_ \<Rightarrow> 'a\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50331
  1677
  assumes f: "(f ---> c) F"
hoelzl@50331
  1678
  assumes g: "LIM x F. g x :> at_infinity"
hoelzl@50331
  1679
  shows "((\<lambda>x. f x / g x) ---> 0) F"
hoelzl@50331
  1680
  using tendsto_mult[OF f filterlim_compose[OF tendsto_inverse_0 g]] by (simp add: divide_inverse)
hoelzl@50331
  1681
hoelzl@50331
  1682
lemma linear_plus_1_le_power:
hoelzl@50331
  1683
  fixes x :: real
hoelzl@50331
  1684
  assumes x: "0 \<le> x"
hoelzl@50331
  1685
  shows "real n * x + 1 \<le> (x + 1) ^ n"
hoelzl@50331
  1686
proof (induct n)
hoelzl@50331
  1687
  case (Suc n)
hoelzl@50331
  1688
  have "real (Suc n) * x + 1 \<le> (x + 1) * (real n * x + 1)"
hoelzl@50331
  1689
    by (simp add: field_simps real_of_nat_Suc mult_nonneg_nonneg x)
hoelzl@50331
  1690
  also have "\<dots> \<le> (x + 1)^Suc n"
hoelzl@50331
  1691
    using Suc x by (simp add: mult_left_mono)
hoelzl@50331
  1692
  finally show ?case .
hoelzl@50331
  1693
qed simp
hoelzl@50331
  1694
hoelzl@50331
  1695
lemma filterlim_realpow_sequentially_gt1:
hoelzl@50331
  1696
  fixes x :: "'a :: real_normed_div_algebra"
hoelzl@50331
  1697
  assumes x[arith]: "1 < norm x"
hoelzl@50331
  1698
  shows "LIM n sequentially. x ^ n :> at_infinity"
hoelzl@50331
  1699
proof (intro filterlim_at_infinity[THEN iffD2] allI impI)
hoelzl@50331
  1700
  fix y :: real assume "0 < y"
hoelzl@50331
  1701
  have "0 < norm x - 1" by simp
hoelzl@50331
  1702
  then obtain N::nat where "y < real N * (norm x - 1)" by (blast dest: reals_Archimedean3)
hoelzl@50331
  1703
  also have "\<dots> \<le> real N * (norm x - 1) + 1" by simp
hoelzl@50331
  1704
  also have "\<dots> \<le> (norm x - 1 + 1) ^ N" by (rule linear_plus_1_le_power) simp
hoelzl@50331
  1705
  also have "\<dots> = norm x ^ N" by simp
hoelzl@50331
  1706
  finally have "\<forall>n\<ge>N. y \<le> norm x ^ n"
hoelzl@50331
  1707
    by (metis order_less_le_trans power_increasing order_less_imp_le x)
hoelzl@50331
  1708
  then show "eventually (\<lambda>n. y \<le> norm (x ^ n)) sequentially"
hoelzl@50331
  1709
    unfolding eventually_sequentially
hoelzl@50331
  1710
    by (auto simp: norm_power)
hoelzl@50331
  1711
qed simp
hoelzl@50331
  1712
huffman@31349
  1713
end
hoelzl@50324
  1714