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