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