src/HOL/Limits.thy
author hoelzl
Mon Dec 03 18:19:11 2012 +0100 (2012-12-03)
changeset 50330 d0b12171118e
parent 50327 bbea2e82871c
child 50331 4b6dc5077e98
permissions -rw-r--r--
conversion rules for at, at_left and at_right; applied to l'Hopital's rules.
huffman@31349
     1
(*  Title       : Limits.thy
huffman@31349
     2
    Author      : Brian Huffman
huffman@31349
     3
*)
huffman@31349
     4
huffman@31349
     5
header {* Filters and Limits *}
huffman@31349
     6
huffman@31349
     7
theory Limits
huffman@36822
     8
imports RealVector
huffman@31349
     9
begin
huffman@31349
    10
huffman@44081
    11
subsection {* Filters *}
huffman@31392
    12
huffman@31392
    13
text {*
huffman@44081
    14
  This definition also allows non-proper filters.
huffman@31392
    15
*}
huffman@31392
    16
huffman@36358
    17
locale is_filter =
huffman@44081
    18
  fixes F :: "('a \<Rightarrow> bool) \<Rightarrow> bool"
huffman@44081
    19
  assumes True: "F (\<lambda>x. True)"
huffman@44081
    20
  assumes conj: "F (\<lambda>x. P x) \<Longrightarrow> F (\<lambda>x. Q x) \<Longrightarrow> F (\<lambda>x. P x \<and> Q x)"
huffman@44081
    21
  assumes mono: "\<forall>x. P x \<longrightarrow> Q x \<Longrightarrow> F (\<lambda>x. P x) \<Longrightarrow> F (\<lambda>x. Q x)"
huffman@36358
    22
wenzelm@49834
    23
typedef 'a filter = "{F :: ('a \<Rightarrow> bool) \<Rightarrow> bool. is_filter F}"
huffman@31392
    24
proof
huffman@44081
    25
  show "(\<lambda>x. True) \<in> ?filter" by (auto intro: is_filter.intro)
huffman@31392
    26
qed
huffman@31349
    27
huffman@44195
    28
lemma is_filter_Rep_filter: "is_filter (Rep_filter F)"
huffman@44195
    29
  using Rep_filter [of F] by simp
huffman@31392
    30
huffman@44081
    31
lemma Abs_filter_inverse':
huffman@44081
    32
  assumes "is_filter F" shows "Rep_filter (Abs_filter F) = F"
huffman@44081
    33
  using assms by (simp add: Abs_filter_inverse)
huffman@31392
    34
huffman@31392
    35
huffman@31392
    36
subsection {* Eventually *}
huffman@31349
    37
huffman@44081
    38
definition eventually :: "('a \<Rightarrow> bool) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
    39
  where "eventually P F \<longleftrightarrow> Rep_filter F P"
huffman@36358
    40
huffman@44081
    41
lemma eventually_Abs_filter:
huffman@44081
    42
  assumes "is_filter F" shows "eventually P (Abs_filter F) = F P"
huffman@44081
    43
  unfolding eventually_def using assms by (simp add: Abs_filter_inverse)
huffman@31349
    44
huffman@44081
    45
lemma filter_eq_iff:
huffman@44195
    46
  shows "F = F' \<longleftrightarrow> (\<forall>P. eventually P F = eventually P F')"
huffman@44081
    47
  unfolding Rep_filter_inject [symmetric] fun_eq_iff eventually_def ..
huffman@36360
    48
huffman@44195
    49
lemma eventually_True [simp]: "eventually (\<lambda>x. True) F"
huffman@44081
    50
  unfolding eventually_def
huffman@44081
    51
  by (rule is_filter.True [OF is_filter_Rep_filter])
huffman@31349
    52
huffman@44195
    53
lemma always_eventually: "\<forall>x. P x \<Longrightarrow> eventually P F"
huffman@36630
    54
proof -
huffman@36630
    55
  assume "\<forall>x. P x" hence "P = (\<lambda>x. True)" by (simp add: ext)
huffman@44195
    56
  thus "eventually P F" by simp
huffman@36630
    57
qed
huffman@36630
    58
huffman@31349
    59
lemma eventually_mono:
huffman@44195
    60
  "(\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually P F \<Longrightarrow> eventually Q F"
huffman@44081
    61
  unfolding eventually_def
huffman@44081
    62
  by (rule is_filter.mono [OF is_filter_Rep_filter])
huffman@31349
    63
huffman@31349
    64
lemma eventually_conj:
huffman@44195
    65
  assumes P: "eventually (\<lambda>x. P x) F"
huffman@44195
    66
  assumes Q: "eventually (\<lambda>x. Q x) F"
huffman@44195
    67
  shows "eventually (\<lambda>x. P x \<and> Q x) F"
huffman@44081
    68
  using assms unfolding eventually_def
huffman@44081
    69
  by (rule is_filter.conj [OF is_filter_Rep_filter])
huffman@31349
    70
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@50324
   466
lemma eventually_at_infinity:
hoelzl@50325
   467
  "eventually P at_infinity \<longleftrightarrow> (\<exists>b. \<forall>x. b \<le> norm x \<longrightarrow> P x)"
hoelzl@50324
   468
unfolding at_infinity_def
hoelzl@50324
   469
proof (rule eventually_Abs_filter, rule is_filter.intro)
hoelzl@50324
   470
  fix P Q :: "'a \<Rightarrow> bool"
hoelzl@50324
   471
  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
   472
  then obtain r s where
hoelzl@50324
   473
    "\<forall>x. r \<le> norm x \<longrightarrow> P x" and "\<forall>x. s \<le> norm x \<longrightarrow> Q x" by auto
hoelzl@50324
   474
  then have "\<forall>x. max r s \<le> norm x \<longrightarrow> P x \<and> Q x" by simp
hoelzl@50324
   475
  then show "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x \<and> Q x" ..
hoelzl@50324
   476
qed auto
huffman@31392
   477
hoelzl@50325
   478
lemma at_infinity_eq_at_top_bot:
hoelzl@50325
   479
  "(at_infinity \<Colon> real filter) = sup at_top at_bot"
hoelzl@50325
   480
  unfolding sup_filter_def at_infinity_def eventually_at_top_linorder eventually_at_bot_linorder
hoelzl@50325
   481
proof (intro arg_cong[where f=Abs_filter] ext iffI)
hoelzl@50325
   482
  fix P :: "real \<Rightarrow> bool" assume "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x"
hoelzl@50325
   483
  then guess r ..
hoelzl@50325
   484
  then have "(\<forall>x\<ge>r. P x) \<and> (\<forall>x\<le>-r. P x)" by auto
hoelzl@50325
   485
  then show "(\<exists>r. \<forall>x\<ge>r. P x) \<and> (\<exists>r. \<forall>x\<le>r. P x)" by auto
hoelzl@50325
   486
next
hoelzl@50325
   487
  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
   488
  then obtain p q where "\<forall>x\<ge>p. P x" "\<forall>x\<le>q. P x" by auto
hoelzl@50325
   489
  then show "\<exists>r. \<forall>x. r \<le> norm x \<longrightarrow> P x"
hoelzl@50325
   490
    by (intro exI[of _ "max p (-q)"])
hoelzl@50325
   491
       (auto simp: abs_real_def)
hoelzl@50325
   492
qed
hoelzl@50325
   493
hoelzl@50325
   494
lemma at_top_le_at_infinity:
hoelzl@50325
   495
  "at_top \<le> (at_infinity :: real filter)"
hoelzl@50325
   496
  unfolding at_infinity_eq_at_top_bot by simp
hoelzl@50325
   497
hoelzl@50325
   498
lemma at_bot_le_at_infinity:
hoelzl@50325
   499
  "at_bot \<le> (at_infinity :: real filter)"
hoelzl@50325
   500
  unfolding at_infinity_eq_at_top_bot by simp
hoelzl@50325
   501
huffman@31355
   502
subsection {* Boundedness *}
huffman@31355
   503
huffman@44081
   504
definition Bfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
   505
  where "Bfun f F = (\<exists>K>0. eventually (\<lambda>x. norm (f x) \<le> K) F)"
huffman@31355
   506
huffman@31487
   507
lemma BfunI:
huffman@44195
   508
  assumes K: "eventually (\<lambda>x. norm (f x) \<le> K) F" shows "Bfun f F"
huffman@31355
   509
unfolding Bfun_def
huffman@31355
   510
proof (intro exI conjI allI)
huffman@31355
   511
  show "0 < max K 1" by simp
huffman@31355
   512
next
huffman@44195
   513
  show "eventually (\<lambda>x. norm (f x) \<le> max K 1) F"
huffman@31355
   514
    using K by (rule eventually_elim1, simp)
huffman@31355
   515
qed
huffman@31355
   516
huffman@31355
   517
lemma BfunE:
huffman@44195
   518
  assumes "Bfun f F"
huffman@44195
   519
  obtains B where "0 < B" and "eventually (\<lambda>x. norm (f x) \<le> B) F"
huffman@31355
   520
using assms unfolding Bfun_def by fast
huffman@31355
   521
huffman@31355
   522
huffman@31349
   523
subsection {* Convergence to Zero *}
huffman@31349
   524
huffman@44081
   525
definition Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
   526
  where "Zfun f F = (\<forall>r>0. eventually (\<lambda>x. norm (f x) < r) F)"
huffman@31349
   527
huffman@31349
   528
lemma ZfunI:
huffman@44195
   529
  "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F) \<Longrightarrow> Zfun f F"
huffman@44081
   530
  unfolding Zfun_def by simp
huffman@31349
   531
huffman@31349
   532
lemma ZfunD:
huffman@44195
   533
  "\<lbrakk>Zfun f F; 0 < r\<rbrakk> \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F"
huffman@44081
   534
  unfolding Zfun_def by simp
huffman@31349
   535
huffman@31355
   536
lemma Zfun_ssubst:
huffman@44195
   537
  "eventually (\<lambda>x. f x = g x) F \<Longrightarrow> Zfun g F \<Longrightarrow> Zfun f F"
huffman@44081
   538
  unfolding Zfun_def by (auto elim!: eventually_rev_mp)
huffman@31355
   539
huffman@44195
   540
lemma Zfun_zero: "Zfun (\<lambda>x. 0) F"
huffman@44081
   541
  unfolding Zfun_def by simp
huffman@31349
   542
huffman@44195
   543
lemma Zfun_norm_iff: "Zfun (\<lambda>x. norm (f x)) F = Zfun (\<lambda>x. f x) F"
huffman@44081
   544
  unfolding Zfun_def by simp
huffman@31349
   545
huffman@31349
   546
lemma Zfun_imp_Zfun:
huffman@44195
   547
  assumes f: "Zfun f F"
huffman@44195
   548
  assumes g: "eventually (\<lambda>x. norm (g x) \<le> norm (f x) * K) F"
huffman@44195
   549
  shows "Zfun (\<lambda>x. g x) F"
huffman@31349
   550
proof (cases)
huffman@31349
   551
  assume K: "0 < K"
huffman@31349
   552
  show ?thesis
huffman@31349
   553
  proof (rule ZfunI)
huffman@31349
   554
    fix r::real assume "0 < r"
huffman@31349
   555
    hence "0 < r / K"
huffman@31349
   556
      using K by (rule divide_pos_pos)
huffman@44195
   557
    then have "eventually (\<lambda>x. norm (f x) < r / K) F"
huffman@31487
   558
      using ZfunD [OF f] by fast
huffman@44195
   559
    with g show "eventually (\<lambda>x. norm (g x) < r) F"
noschinl@46887
   560
    proof eventually_elim
noschinl@46887
   561
      case (elim x)
huffman@31487
   562
      hence "norm (f x) * K < r"
huffman@31349
   563
        by (simp add: pos_less_divide_eq K)
noschinl@46887
   564
      thus ?case
noschinl@46887
   565
        by (simp add: order_le_less_trans [OF elim(1)])
huffman@31349
   566
    qed
huffman@31349
   567
  qed
huffman@31349
   568
next
huffman@31349
   569
  assume "\<not> 0 < K"
huffman@31349
   570
  hence K: "K \<le> 0" by (simp only: not_less)
huffman@31355
   571
  show ?thesis
huffman@31355
   572
  proof (rule ZfunI)
huffman@31355
   573
    fix r :: real
huffman@31355
   574
    assume "0 < r"
huffman@44195
   575
    from g show "eventually (\<lambda>x. norm (g x) < r) F"
noschinl@46887
   576
    proof eventually_elim
noschinl@46887
   577
      case (elim x)
noschinl@46887
   578
      also have "norm (f x) * K \<le> norm (f x) * 0"
huffman@31355
   579
        using K norm_ge_zero by (rule mult_left_mono)
noschinl@46887
   580
      finally show ?case
huffman@31355
   581
        using `0 < r` by simp
huffman@31355
   582
    qed
huffman@31355
   583
  qed
huffman@31349
   584
qed
huffman@31349
   585
huffman@44195
   586
lemma Zfun_le: "\<lbrakk>Zfun g F; \<forall>x. norm (f x) \<le> norm (g x)\<rbrakk> \<Longrightarrow> Zfun f F"
huffman@44081
   587
  by (erule_tac K="1" in Zfun_imp_Zfun, simp)
huffman@31349
   588
huffman@31349
   589
lemma Zfun_add:
huffman@44195
   590
  assumes f: "Zfun f F" and g: "Zfun g F"
huffman@44195
   591
  shows "Zfun (\<lambda>x. f x + g x) F"
huffman@31349
   592
proof (rule ZfunI)
huffman@31349
   593
  fix r::real assume "0 < r"
huffman@31349
   594
  hence r: "0 < r / 2" by simp
huffman@44195
   595
  have "eventually (\<lambda>x. norm (f x) < r/2) F"
huffman@31487
   596
    using f r by (rule ZfunD)
huffman@31349
   597
  moreover
huffman@44195
   598
  have "eventually (\<lambda>x. norm (g x) < r/2) F"
huffman@31487
   599
    using g r by (rule ZfunD)
huffman@31349
   600
  ultimately
huffman@44195
   601
  show "eventually (\<lambda>x. norm (f x + g x) < r) F"
noschinl@46887
   602
  proof eventually_elim
noschinl@46887
   603
    case (elim x)
huffman@31487
   604
    have "norm (f x + g x) \<le> norm (f x) + norm (g x)"
huffman@31349
   605
      by (rule norm_triangle_ineq)
huffman@31349
   606
    also have "\<dots> < r/2 + r/2"
noschinl@46887
   607
      using elim by (rule add_strict_mono)
noschinl@46887
   608
    finally show ?case
huffman@31349
   609
      by simp
huffman@31349
   610
  qed
huffman@31349
   611
qed
huffman@31349
   612
huffman@44195
   613
lemma Zfun_minus: "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. - f x) F"
huffman@44081
   614
  unfolding Zfun_def by simp
huffman@31349
   615
huffman@44195
   616
lemma Zfun_diff: "\<lbrakk>Zfun f F; Zfun g F\<rbrakk> \<Longrightarrow> Zfun (\<lambda>x. f x - g x) F"
huffman@44081
   617
  by (simp only: diff_minus Zfun_add Zfun_minus)
huffman@31349
   618
huffman@31349
   619
lemma (in bounded_linear) Zfun:
huffman@44195
   620
  assumes g: "Zfun g F"
huffman@44195
   621
  shows "Zfun (\<lambda>x. f (g x)) F"
huffman@31349
   622
proof -
huffman@31349
   623
  obtain K where "\<And>x. norm (f x) \<le> norm x * K"
huffman@31349
   624
    using bounded by fast
huffman@44195
   625
  then have "eventually (\<lambda>x. norm (f (g x)) \<le> norm (g x) * K) F"
huffman@31355
   626
    by simp
huffman@31487
   627
  with g show ?thesis
huffman@31349
   628
    by (rule Zfun_imp_Zfun)
huffman@31349
   629
qed
huffman@31349
   630
huffman@31349
   631
lemma (in bounded_bilinear) Zfun:
huffman@44195
   632
  assumes f: "Zfun f F"
huffman@44195
   633
  assumes g: "Zfun g F"
huffman@44195
   634
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31349
   635
proof (rule ZfunI)
huffman@31349
   636
  fix r::real assume r: "0 < r"
huffman@31349
   637
  obtain K where K: "0 < K"
huffman@31349
   638
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31349
   639
    using pos_bounded by fast
huffman@31349
   640
  from K have K': "0 < inverse K"
huffman@31349
   641
    by (rule positive_imp_inverse_positive)
huffman@44195
   642
  have "eventually (\<lambda>x. norm (f x) < r) F"
huffman@31487
   643
    using f r by (rule ZfunD)
huffman@31349
   644
  moreover
huffman@44195
   645
  have "eventually (\<lambda>x. norm (g x) < inverse K) F"
huffman@31487
   646
    using g K' by (rule ZfunD)
huffman@31349
   647
  ultimately
huffman@44195
   648
  show "eventually (\<lambda>x. norm (f x ** g x) < r) F"
noschinl@46887
   649
  proof eventually_elim
noschinl@46887
   650
    case (elim x)
huffman@31487
   651
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31349
   652
      by (rule norm_le)
huffman@31487
   653
    also have "norm (f x) * norm (g x) * K < r * inverse K * K"
noschinl@46887
   654
      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero elim K)
huffman@31349
   655
    also from K have "r * inverse K * K = r"
huffman@31349
   656
      by simp
noschinl@46887
   657
    finally show ?case .
huffman@31349
   658
  qed
huffman@31349
   659
qed
huffman@31349
   660
huffman@31349
   661
lemma (in bounded_bilinear) Zfun_left:
huffman@44195
   662
  "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. f x ** a) F"
huffman@44081
   663
  by (rule bounded_linear_left [THEN bounded_linear.Zfun])
huffman@31349
   664
huffman@31349
   665
lemma (in bounded_bilinear) Zfun_right:
huffman@44195
   666
  "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. a ** f x) F"
huffman@44081
   667
  by (rule bounded_linear_right [THEN bounded_linear.Zfun])
huffman@31349
   668
huffman@44282
   669
lemmas Zfun_mult = bounded_bilinear.Zfun [OF bounded_bilinear_mult]
huffman@44282
   670
lemmas Zfun_mult_right = bounded_bilinear.Zfun_right [OF bounded_bilinear_mult]
huffman@44282
   671
lemmas Zfun_mult_left = bounded_bilinear.Zfun_left [OF bounded_bilinear_mult]
huffman@31349
   672
huffman@31349
   673
wenzelm@31902
   674
subsection {* Limits *}
huffman@31349
   675
hoelzl@50322
   676
definition filterlim :: "('a \<Rightarrow> 'b) \<Rightarrow> 'b filter \<Rightarrow> 'a filter \<Rightarrow> bool" where
hoelzl@50322
   677
  "filterlim f F2 F1 \<longleftrightarrow> filtermap f F1 \<le> F2"
hoelzl@50247
   678
hoelzl@50247
   679
syntax
hoelzl@50247
   680
  "_LIM" :: "pttrns \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> bool" ("(3LIM (_)/ (_)./ (_) :> (_))" [1000, 10, 0, 10] 10)
hoelzl@50247
   681
hoelzl@50247
   682
translations
hoelzl@50322
   683
  "LIM x F1. f :> F2"   == "CONST filterlim (%x. f) F2 F1"
hoelzl@50247
   684
hoelzl@50325
   685
lemma filterlim_iff:
hoelzl@50325
   686
  "(LIM x F1. f x :> F2) \<longleftrightarrow> (\<forall>P. eventually P F2 \<longrightarrow> eventually (\<lambda>x. P (f x)) F1)"
hoelzl@50325
   687
  unfolding filterlim_def le_filter_def eventually_filtermap ..
hoelzl@50247
   688
hoelzl@50327
   689
lemma filterlim_compose:
hoelzl@50323
   690
  "filterlim g F3 F2 \<Longrightarrow> filterlim f F2 F1 \<Longrightarrow> filterlim (\<lambda>x. g (f x)) F3 F1"
hoelzl@50323
   691
  unfolding filterlim_def filtermap_filtermap[symmetric] by (metis filtermap_mono order_trans)
hoelzl@50323
   692
hoelzl@50327
   693
lemma filterlim_mono:
hoelzl@50323
   694
  "filterlim f F2 F1 \<Longrightarrow> F2 \<le> F2' \<Longrightarrow> F1' \<le> F1 \<Longrightarrow> filterlim f F2' F1'"
hoelzl@50323
   695
  unfolding filterlim_def by (metis filtermap_mono order_trans)
hoelzl@50323
   696
hoelzl@50327
   697
lemma filterlim_cong:
hoelzl@50327
   698
  "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
   699
  by (auto simp: filterlim_def le_filter_def eventually_filtermap elim: eventually_elim2)
hoelzl@50327
   700
hoelzl@50325
   701
lemma filterlim_within:
hoelzl@50325
   702
  "(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
   703
  unfolding filterlim_def
hoelzl@50325
   704
proof safe
hoelzl@50325
   705
  assume "filtermap f F1 \<le> F2 within S" then show "eventually (\<lambda>x. f x \<in> S) F1"
hoelzl@50325
   706
    by (auto simp: le_filter_def eventually_filtermap eventually_within elim!: allE[of _ "\<lambda>x. x \<in> S"])
hoelzl@50325
   707
qed (auto intro: within_le order_trans simp: le_within_iff eventually_filtermap)
hoelzl@50325
   708
hoelzl@50330
   709
lemma filterlim_filtermap: "filterlim f F1 (filtermap g F2) = filterlim (\<lambda>x. f (g x)) F1 F2"
hoelzl@50330
   710
  unfolding filterlim_def filtermap_filtermap ..
hoelzl@50330
   711
hoelzl@50330
   712
lemma filterlim_sup:
hoelzl@50330
   713
  "filterlim f F F1 \<Longrightarrow> filterlim f F F2 \<Longrightarrow> filterlim f F (sup F1 F2)"
hoelzl@50330
   714
  unfolding filterlim_def filtermap_sup by auto
hoelzl@50330
   715
hoelzl@50247
   716
abbreviation (in topological_space)
huffman@44206
   717
  tendsto :: "('b \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'b filter \<Rightarrow> bool" (infixr "--->" 55) where
hoelzl@50322
   718
  "(f ---> l) F \<equiv> filterlim f (nhds l) F"
noschinl@45892
   719
wenzelm@31902
   720
ML {*
wenzelm@31902
   721
structure Tendsto_Intros = Named_Thms
wenzelm@31902
   722
(
wenzelm@45294
   723
  val name = @{binding tendsto_intros}
wenzelm@31902
   724
  val description = "introduction rules for tendsto"
wenzelm@31902
   725
)
huffman@31565
   726
*}
huffman@31565
   727
wenzelm@31902
   728
setup Tendsto_Intros.setup
huffman@31565
   729
hoelzl@50247
   730
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
   731
  unfolding filterlim_def
hoelzl@50247
   732
proof safe
hoelzl@50247
   733
  fix S assume "open S" "l \<in> S" "filtermap f F \<le> nhds l"
hoelzl@50247
   734
  then show "eventually (\<lambda>x. f x \<in> S) F"
hoelzl@50247
   735
    unfolding eventually_nhds eventually_filtermap le_filter_def
hoelzl@50247
   736
    by (auto elim!: allE[of _ "\<lambda>x. x \<in> S"] eventually_rev_mp)
hoelzl@50247
   737
qed (auto elim!: eventually_rev_mp simp: eventually_nhds eventually_filtermap le_filter_def)
hoelzl@50247
   738
hoelzl@50325
   739
lemma filterlim_at:
hoelzl@50325
   740
  "(LIM x F. f x :> at b) \<longleftrightarrow> (eventually (\<lambda>x. f x \<noteq> b) F \<and> (f ---> b) F)"
hoelzl@50325
   741
  by (simp add: at_def filterlim_within)
hoelzl@50325
   742
huffman@44195
   743
lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f ---> l) F' \<Longrightarrow> (f ---> l) F"
huffman@44081
   744
  unfolding tendsto_def le_filter_def by fast
huffman@36656
   745
huffman@31488
   746
lemma topological_tendstoI:
huffman@44195
   747
  "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F)
huffman@44195
   748
    \<Longrightarrow> (f ---> l) F"
huffman@31349
   749
  unfolding tendsto_def by auto
huffman@31349
   750
huffman@31488
   751
lemma topological_tendstoD:
huffman@44195
   752
  "(f ---> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
huffman@31488
   753
  unfolding tendsto_def by auto
huffman@31488
   754
huffman@31488
   755
lemma tendstoI:
huffman@44195
   756
  assumes "\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
huffman@44195
   757
  shows "(f ---> l) F"
huffman@44081
   758
  apply (rule topological_tendstoI)
huffman@44081
   759
  apply (simp add: open_dist)
huffman@44081
   760
  apply (drule (1) bspec, clarify)
huffman@44081
   761
  apply (drule assms)
huffman@44081
   762
  apply (erule eventually_elim1, simp)
huffman@44081
   763
  done
huffman@31488
   764
huffman@31349
   765
lemma tendstoD:
huffman@44195
   766
  "(f ---> l) F \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
huffman@44081
   767
  apply (drule_tac S="{x. dist x l < e}" in topological_tendstoD)
huffman@44081
   768
  apply (clarsimp simp add: open_dist)
huffman@44081
   769
  apply (rule_tac x="e - dist x l" in exI, clarsimp)
huffman@44081
   770
  apply (simp only: less_diff_eq)
huffman@44081
   771
  apply (erule le_less_trans [OF dist_triangle])
huffman@44081
   772
  apply simp
huffman@44081
   773
  apply simp
huffman@44081
   774
  done
huffman@31488
   775
huffman@31488
   776
lemma tendsto_iff:
huffman@44195
   777
  "(f ---> l) F \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) F)"
huffman@44081
   778
  using tendstoI tendstoD by fast
huffman@31349
   779
huffman@44195
   780
lemma tendsto_Zfun_iff: "(f ---> a) F = Zfun (\<lambda>x. f x - a) F"
huffman@44081
   781
  by (simp only: tendsto_iff Zfun_def dist_norm)
huffman@31349
   782
huffman@45031
   783
lemma tendsto_bot [simp]: "(f ---> a) bot"
huffman@45031
   784
  unfolding tendsto_def by simp
huffman@45031
   785
huffman@31565
   786
lemma tendsto_ident_at [tendsto_intros]: "((\<lambda>x. x) ---> a) (at a)"
huffman@44081
   787
  unfolding tendsto_def eventually_at_topological by auto
huffman@31565
   788
huffman@31565
   789
lemma tendsto_ident_at_within [tendsto_intros]:
huffman@36655
   790
  "((\<lambda>x. x) ---> a) (at a within S)"
huffman@44081
   791
  unfolding tendsto_def eventually_within eventually_at_topological by auto
huffman@31565
   792
huffman@44195
   793
lemma tendsto_const [tendsto_intros]: "((\<lambda>x. k) ---> k) F"
huffman@44081
   794
  by (simp add: tendsto_def)
huffman@31349
   795
huffman@44205
   796
lemma tendsto_unique:
huffman@44205
   797
  fixes f :: "'a \<Rightarrow> 'b::t2_space"
huffman@44205
   798
  assumes "\<not> trivial_limit F" and "(f ---> a) F" and "(f ---> b) F"
huffman@44205
   799
  shows "a = b"
huffman@44205
   800
proof (rule ccontr)
huffman@44205
   801
  assume "a \<noteq> b"
huffman@44205
   802
  obtain U V where "open U" "open V" "a \<in> U" "b \<in> V" "U \<inter> V = {}"
huffman@44205
   803
    using hausdorff [OF `a \<noteq> b`] by fast
huffman@44205
   804
  have "eventually (\<lambda>x. f x \<in> U) F"
huffman@44205
   805
    using `(f ---> a) F` `open U` `a \<in> U` by (rule topological_tendstoD)
huffman@44205
   806
  moreover
huffman@44205
   807
  have "eventually (\<lambda>x. f x \<in> V) F"
huffman@44205
   808
    using `(f ---> b) F` `open V` `b \<in> V` by (rule topological_tendstoD)
huffman@44205
   809
  ultimately
huffman@44205
   810
  have "eventually (\<lambda>x. False) F"
noschinl@46887
   811
  proof eventually_elim
noschinl@46887
   812
    case (elim x)
huffman@44205
   813
    hence "f x \<in> U \<inter> V" by simp
noschinl@46887
   814
    with `U \<inter> V = {}` show ?case by simp
huffman@44205
   815
  qed
huffman@44205
   816
  with `\<not> trivial_limit F` show "False"
huffman@44205
   817
    by (simp add: trivial_limit_def)
huffman@44205
   818
qed
huffman@44205
   819
huffman@36662
   820
lemma tendsto_const_iff:
huffman@44205
   821
  fixes a b :: "'a::t2_space"
huffman@44205
   822
  assumes "\<not> trivial_limit F" shows "((\<lambda>x. a) ---> b) F \<longleftrightarrow> a = b"
huffman@44205
   823
  by (safe intro!: tendsto_const tendsto_unique [OF assms tendsto_const])
huffman@44205
   824
hoelzl@50323
   825
lemma tendsto_at_iff_tendsto_nhds:
hoelzl@50323
   826
  "(g ---> g l) (at l) \<longleftrightarrow> (g ---> g l) (nhds l)"
hoelzl@50323
   827
  unfolding tendsto_def at_def eventually_within
hoelzl@50323
   828
  by (intro ext all_cong imp_cong) (auto elim!: eventually_elim1)
hoelzl@50323
   829
huffman@44218
   830
lemma tendsto_compose:
hoelzl@50323
   831
  "(g ---> g l) (at l) \<Longrightarrow> (f ---> l) F \<Longrightarrow> ((\<lambda>x. g (f x)) ---> g l) F"
hoelzl@50323
   832
  unfolding tendsto_at_iff_tendsto_nhds by (rule filterlim_compose[of g])
huffman@44218
   833
huffman@44253
   834
lemma tendsto_compose_eventually:
hoelzl@50325
   835
  "(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
   836
  by (rule filterlim_compose[of g _ "at l"]) (auto simp add: filterlim_at)
huffman@44253
   837
huffman@44251
   838
lemma metric_tendsto_imp_tendsto:
huffman@44251
   839
  assumes f: "(f ---> a) F"
huffman@44251
   840
  assumes le: "eventually (\<lambda>x. dist (g x) b \<le> dist (f x) a) F"
huffman@44251
   841
  shows "(g ---> b) F"
huffman@44251
   842
proof (rule tendstoI)
huffman@44251
   843
  fix e :: real assume "0 < e"
huffman@44251
   844
  with f have "eventually (\<lambda>x. dist (f x) a < e) F" by (rule tendstoD)
huffman@44251
   845
  with le show "eventually (\<lambda>x. dist (g x) b < e) F"
huffman@44251
   846
    using le_less_trans by (rule eventually_elim2)
huffman@44251
   847
qed
huffman@44251
   848
huffman@44205
   849
subsubsection {* Distance and norms *}
huffman@36662
   850
huffman@31565
   851
lemma tendsto_dist [tendsto_intros]:
huffman@44195
   852
  assumes f: "(f ---> l) F" and g: "(g ---> m) F"
huffman@44195
   853
  shows "((\<lambda>x. dist (f x) (g x)) ---> dist l m) F"
huffman@31565
   854
proof (rule tendstoI)
huffman@31565
   855
  fix e :: real assume "0 < e"
huffman@31565
   856
  hence e2: "0 < e/2" by simp
huffman@31565
   857
  from tendstoD [OF f e2] tendstoD [OF g e2]
huffman@44195
   858
  show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) F"
noschinl@46887
   859
  proof (eventually_elim)
noschinl@46887
   860
    case (elim x)
huffman@31565
   861
    then show "dist (dist (f x) (g x)) (dist l m) < e"
huffman@31565
   862
      unfolding dist_real_def
huffman@31565
   863
      using dist_triangle2 [of "f x" "g x" "l"]
huffman@31565
   864
      using dist_triangle2 [of "g x" "l" "m"]
huffman@31565
   865
      using dist_triangle3 [of "l" "m" "f x"]
huffman@31565
   866
      using dist_triangle [of "f x" "m" "g x"]
huffman@31565
   867
      by arith
huffman@31565
   868
  qed
huffman@31565
   869
qed
huffman@31565
   870
huffman@36662
   871
lemma norm_conv_dist: "norm x = dist x 0"
huffman@44081
   872
  unfolding dist_norm by simp
huffman@36662
   873
huffman@31565
   874
lemma tendsto_norm [tendsto_intros]:
huffman@44195
   875
  "(f ---> a) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> norm a) F"
huffman@44081
   876
  unfolding norm_conv_dist by (intro tendsto_intros)
huffman@36662
   877
huffman@36662
   878
lemma tendsto_norm_zero:
huffman@44195
   879
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> 0) F"
huffman@44081
   880
  by (drule tendsto_norm, simp)
huffman@36662
   881
huffman@36662
   882
lemma tendsto_norm_zero_cancel:
huffman@44195
   883
  "((\<lambda>x. norm (f x)) ---> 0) F \<Longrightarrow> (f ---> 0) F"
huffman@44081
   884
  unfolding tendsto_iff dist_norm by simp
huffman@36662
   885
huffman@36662
   886
lemma tendsto_norm_zero_iff:
huffman@44195
   887
  "((\<lambda>x. norm (f x)) ---> 0) F \<longleftrightarrow> (f ---> 0) F"
huffman@44081
   888
  unfolding tendsto_iff dist_norm by simp
huffman@31349
   889
huffman@44194
   890
lemma tendsto_rabs [tendsto_intros]:
huffman@44195
   891
  "(f ---> (l::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> \<bar>l\<bar>) F"
huffman@44194
   892
  by (fold real_norm_def, rule tendsto_norm)
huffman@44194
   893
huffman@44194
   894
lemma tendsto_rabs_zero:
huffman@44195
   895
  "(f ---> (0::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> 0) F"
huffman@44194
   896
  by (fold real_norm_def, rule tendsto_norm_zero)
huffman@44194
   897
huffman@44194
   898
lemma tendsto_rabs_zero_cancel:
huffman@44195
   899
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<Longrightarrow> (f ---> 0) F"
huffman@44194
   900
  by (fold real_norm_def, rule tendsto_norm_zero_cancel)
huffman@44194
   901
huffman@44194
   902
lemma tendsto_rabs_zero_iff:
huffman@44195
   903
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<longleftrightarrow> (f ---> 0) F"
huffman@44194
   904
  by (fold real_norm_def, rule tendsto_norm_zero_iff)
huffman@44194
   905
huffman@44194
   906
subsubsection {* Addition and subtraction *}
huffman@44194
   907
huffman@31565
   908
lemma tendsto_add [tendsto_intros]:
huffman@31349
   909
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   910
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> a + b) F"
huffman@44081
   911
  by (simp only: tendsto_Zfun_iff add_diff_add Zfun_add)
huffman@31349
   912
huffman@44194
   913
lemma tendsto_add_zero:
huffman@44194
   914
  fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
huffman@44195
   915
  shows "\<lbrakk>(f ---> 0) F; (g ---> 0) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> 0) F"
huffman@44194
   916
  by (drule (1) tendsto_add, simp)
huffman@44194
   917
huffman@31565
   918
lemma tendsto_minus [tendsto_intros]:
huffman@31349
   919
  fixes a :: "'a::real_normed_vector"
huffman@44195
   920
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. - f x) ---> - a) F"
huffman@44081
   921
  by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
huffman@31349
   922
huffman@31349
   923
lemma tendsto_minus_cancel:
huffman@31349
   924
  fixes a :: "'a::real_normed_vector"
huffman@44195
   925
  shows "((\<lambda>x. - f x) ---> - a) F \<Longrightarrow> (f ---> a) F"
huffman@44081
   926
  by (drule tendsto_minus, simp)
huffman@31349
   927
hoelzl@50330
   928
lemma tendsto_minus_cancel_left:
hoelzl@50330
   929
    "(f ---> - (y::_::real_normed_vector)) F \<longleftrightarrow> ((\<lambda>x. - f x) ---> y) F"
hoelzl@50330
   930
  using tendsto_minus_cancel[of f "- y" F]  tendsto_minus[of f "- y" F]
hoelzl@50330
   931
  by auto
hoelzl@50330
   932
huffman@31565
   933
lemma tendsto_diff [tendsto_intros]:
huffman@31349
   934
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   935
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x - g x) ---> a - b) F"
huffman@44081
   936
  by (simp add: diff_minus tendsto_add tendsto_minus)
huffman@31349
   937
huffman@31588
   938
lemma tendsto_setsum [tendsto_intros]:
huffman@31588
   939
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
huffman@44195
   940
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> a i) F"
huffman@44195
   941
  shows "((\<lambda>x. \<Sum>i\<in>S. f i x) ---> (\<Sum>i\<in>S. a i)) F"
huffman@31588
   942
proof (cases "finite S")
huffman@31588
   943
  assume "finite S" thus ?thesis using assms
huffman@44194
   944
    by (induct, simp add: tendsto_const, simp add: tendsto_add)
huffman@31588
   945
next
huffman@31588
   946
  assume "\<not> finite S" thus ?thesis
huffman@31588
   947
    by (simp add: tendsto_const)
huffman@31588
   948
qed
huffman@31588
   949
noschinl@45892
   950
lemma real_tendsto_sandwich:
noschinl@45892
   951
  fixes f g h :: "'a \<Rightarrow> real"
noschinl@45892
   952
  assumes ev: "eventually (\<lambda>n. f n \<le> g n) net" "eventually (\<lambda>n. g n \<le> h n) net"
noschinl@45892
   953
  assumes lim: "(f ---> c) net" "(h ---> c) net"
noschinl@45892
   954
  shows "(g ---> c) net"
noschinl@45892
   955
proof -
noschinl@45892
   956
  have "((\<lambda>n. g n - f n) ---> 0) net"
noschinl@45892
   957
  proof (rule metric_tendsto_imp_tendsto)
noschinl@45892
   958
    show "eventually (\<lambda>n. dist (g n - f n) 0 \<le> dist (h n - f n) 0) net"
noschinl@45892
   959
      using ev by (rule eventually_elim2) (simp add: dist_real_def)
noschinl@45892
   960
    show "((\<lambda>n. h n - f n) ---> 0) net"
noschinl@45892
   961
      using tendsto_diff[OF lim(2,1)] by simp
noschinl@45892
   962
  qed
noschinl@45892
   963
  from tendsto_add[OF this lim(1)] show ?thesis by simp
noschinl@45892
   964
qed
noschinl@45892
   965
huffman@44194
   966
subsubsection {* Linear operators and multiplication *}
huffman@44194
   967
huffman@44282
   968
lemma (in bounded_linear) tendsto:
huffman@44195
   969
  "(g ---> a) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> f a) F"
huffman@44081
   970
  by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
huffman@31349
   971
huffman@44194
   972
lemma (in bounded_linear) tendsto_zero:
huffman@44195
   973
  "(g ---> 0) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> 0) F"
huffman@44194
   974
  by (drule tendsto, simp only: zero)
huffman@44194
   975
huffman@44282
   976
lemma (in bounded_bilinear) tendsto:
huffman@44195
   977
  "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ** g x) ---> a ** b) F"
huffman@44081
   978
  by (simp only: tendsto_Zfun_iff prod_diff_prod
huffman@44081
   979
                 Zfun_add Zfun Zfun_left Zfun_right)
huffman@31349
   980
huffman@44194
   981
lemma (in bounded_bilinear) tendsto_zero:
huffman@44195
   982
  assumes f: "(f ---> 0) F"
huffman@44195
   983
  assumes g: "(g ---> 0) F"
huffman@44195
   984
  shows "((\<lambda>x. f x ** g x) ---> 0) F"
huffman@44194
   985
  using tendsto [OF f g] by (simp add: zero_left)
huffman@31355
   986
huffman@44194
   987
lemma (in bounded_bilinear) tendsto_left_zero:
huffman@44195
   988
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. f x ** c) ---> 0) F"
huffman@44194
   989
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_left])
huffman@44194
   990
huffman@44194
   991
lemma (in bounded_bilinear) tendsto_right_zero:
huffman@44195
   992
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. c ** f x) ---> 0) F"
huffman@44194
   993
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_right])
huffman@44194
   994
huffman@44282
   995
lemmas tendsto_of_real [tendsto_intros] =
huffman@44282
   996
  bounded_linear.tendsto [OF bounded_linear_of_real]
huffman@44282
   997
huffman@44282
   998
lemmas tendsto_scaleR [tendsto_intros] =
huffman@44282
   999
  bounded_bilinear.tendsto [OF bounded_bilinear_scaleR]
huffman@44282
  1000
huffman@44282
  1001
lemmas tendsto_mult [tendsto_intros] =
huffman@44282
  1002
  bounded_bilinear.tendsto [OF bounded_bilinear_mult]
huffman@44194
  1003
huffman@44568
  1004
lemmas tendsto_mult_zero =
huffman@44568
  1005
  bounded_bilinear.tendsto_zero [OF bounded_bilinear_mult]
huffman@44568
  1006
huffman@44568
  1007
lemmas tendsto_mult_left_zero =
huffman@44568
  1008
  bounded_bilinear.tendsto_left_zero [OF bounded_bilinear_mult]
huffman@44568
  1009
huffman@44568
  1010
lemmas tendsto_mult_right_zero =
huffman@44568
  1011
  bounded_bilinear.tendsto_right_zero [OF bounded_bilinear_mult]
huffman@44568
  1012
huffman@44194
  1013
lemma tendsto_power [tendsto_intros]:
huffman@44194
  1014
  fixes f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra}"
huffman@44195
  1015
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. f x ^ n) ---> a ^ n) F"
huffman@44194
  1016
  by (induct n) (simp_all add: tendsto_const tendsto_mult)
huffman@44194
  1017
huffman@44194
  1018
lemma tendsto_setprod [tendsto_intros]:
huffman@44194
  1019
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
huffman@44195
  1020
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> L i) F"
huffman@44195
  1021
  shows "((\<lambda>x. \<Prod>i\<in>S. f i x) ---> (\<Prod>i\<in>S. L i)) F"
huffman@44194
  1022
proof (cases "finite S")
huffman@44194
  1023
  assume "finite S" thus ?thesis using assms
huffman@44194
  1024
    by (induct, simp add: tendsto_const, simp add: tendsto_mult)
huffman@44194
  1025
next
huffman@44194
  1026
  assume "\<not> finite S" thus ?thesis
huffman@44194
  1027
    by (simp add: tendsto_const)
huffman@44194
  1028
qed
huffman@44194
  1029
huffman@44194
  1030
subsubsection {* Inverse and division *}
huffman@31355
  1031
huffman@31355
  1032
lemma (in bounded_bilinear) Zfun_prod_Bfun:
huffman@44195
  1033
  assumes f: "Zfun f F"
huffman@44195
  1034
  assumes g: "Bfun g F"
huffman@44195
  1035
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31355
  1036
proof -
huffman@31355
  1037
  obtain K where K: "0 \<le> K"
huffman@31355
  1038
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31355
  1039
    using nonneg_bounded by fast
huffman@31355
  1040
  obtain B where B: "0 < B"
huffman@44195
  1041
    and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) F"
huffman@31487
  1042
    using g by (rule BfunE)
huffman@44195
  1043
  have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) F"
noschinl@46887
  1044
  using norm_g proof eventually_elim
noschinl@46887
  1045
    case (elim x)
huffman@31487
  1046
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31355
  1047
      by (rule norm_le)
huffman@31487
  1048
    also have "\<dots> \<le> norm (f x) * B * K"
huffman@31487
  1049
      by (intro mult_mono' order_refl norm_g norm_ge_zero
noschinl@46887
  1050
                mult_nonneg_nonneg K elim)
huffman@31487
  1051
    also have "\<dots> = norm (f x) * (B * K)"
huffman@31355
  1052
      by (rule mult_assoc)
huffman@31487
  1053
    finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
huffman@31355
  1054
  qed
huffman@31487
  1055
  with f show ?thesis
huffman@31487
  1056
    by (rule Zfun_imp_Zfun)
huffman@31355
  1057
qed
huffman@31355
  1058
huffman@31355
  1059
lemma (in bounded_bilinear) flip:
huffman@31355
  1060
  "bounded_bilinear (\<lambda>x y. y ** x)"
huffman@44081
  1061
  apply default
huffman@44081
  1062
  apply (rule add_right)
huffman@44081
  1063
  apply (rule add_left)
huffman@44081
  1064
  apply (rule scaleR_right)
huffman@44081
  1065
  apply (rule scaleR_left)
huffman@44081
  1066
  apply (subst mult_commute)
huffman@44081
  1067
  using bounded by fast
huffman@31355
  1068
huffman@31355
  1069
lemma (in bounded_bilinear) Bfun_prod_Zfun:
huffman@44195
  1070
  assumes f: "Bfun f F"
huffman@44195
  1071
  assumes g: "Zfun g F"
huffman@44195
  1072
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@44081
  1073
  using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
huffman@31355
  1074
huffman@31355
  1075
lemma Bfun_inverse_lemma:
huffman@31355
  1076
  fixes x :: "'a::real_normed_div_algebra"
huffman@31355
  1077
  shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
huffman@44081
  1078
  apply (subst nonzero_norm_inverse, clarsimp)
huffman@44081
  1079
  apply (erule (1) le_imp_inverse_le)
huffman@44081
  1080
  done
huffman@31355
  1081
huffman@31355
  1082
lemma Bfun_inverse:
huffman@31355
  1083
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
  1084
  assumes f: "(f ---> a) F"
huffman@31355
  1085
  assumes a: "a \<noteq> 0"
huffman@44195
  1086
  shows "Bfun (\<lambda>x. inverse (f x)) F"
huffman@31355
  1087
proof -
huffman@31355
  1088
  from a have "0 < norm a" by simp
huffman@31355
  1089
  hence "\<exists>r>0. r < norm a" by (rule dense)
huffman@31355
  1090
  then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
huffman@44195
  1091
  have "eventually (\<lambda>x. dist (f x) a < r) F"
huffman@31487
  1092
    using tendstoD [OF f r1] by fast
huffman@44195
  1093
  hence "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) F"
noschinl@46887
  1094
  proof eventually_elim
noschinl@46887
  1095
    case (elim x)
huffman@31487
  1096
    hence 1: "norm (f x - a) < r"
huffman@31355
  1097
      by (simp add: dist_norm)
huffman@31487
  1098
    hence 2: "f x \<noteq> 0" using r2 by auto
huffman@31487
  1099
    hence "norm (inverse (f x)) = inverse (norm (f x))"
huffman@31355
  1100
      by (rule nonzero_norm_inverse)
huffman@31355
  1101
    also have "\<dots> \<le> inverse (norm a - r)"
huffman@31355
  1102
    proof (rule le_imp_inverse_le)
huffman@31355
  1103
      show "0 < norm a - r" using r2 by simp
huffman@31355
  1104
    next
huffman@31487
  1105
      have "norm a - norm (f x) \<le> norm (a - f x)"
huffman@31355
  1106
        by (rule norm_triangle_ineq2)
huffman@31487
  1107
      also have "\<dots> = norm (f x - a)"
huffman@31355
  1108
        by (rule norm_minus_commute)
huffman@31355
  1109
      also have "\<dots> < r" using 1 .
huffman@31487
  1110
      finally show "norm a - r \<le> norm (f x)" by simp
huffman@31355
  1111
    qed
huffman@31487
  1112
    finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
huffman@31355
  1113
  qed
huffman@31355
  1114
  thus ?thesis by (rule BfunI)
huffman@31355
  1115
qed
huffman@31355
  1116
huffman@31565
  1117
lemma tendsto_inverse [tendsto_intros]:
huffman@31355
  1118
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
  1119
  assumes f: "(f ---> a) F"
huffman@31355
  1120
  assumes a: "a \<noteq> 0"
huffman@44195
  1121
  shows "((\<lambda>x. inverse (f x)) ---> inverse a) F"
huffman@31355
  1122
proof -
huffman@31355
  1123
  from a have "0 < norm a" by simp
huffman@44195
  1124
  with f have "eventually (\<lambda>x. dist (f x) a < norm a) F"
huffman@31355
  1125
    by (rule tendstoD)
huffman@44195
  1126
  then have "eventually (\<lambda>x. f x \<noteq> 0) F"
huffman@31355
  1127
    unfolding dist_norm by (auto elim!: eventually_elim1)
huffman@44627
  1128
  with a have "eventually (\<lambda>x. inverse (f x) - inverse a =
huffman@44627
  1129
    - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
  1130
    by (auto elim!: eventually_elim1 simp: inverse_diff_inverse)
huffman@44627
  1131
  moreover have "Zfun (\<lambda>x. - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
  1132
    by (intro Zfun_minus Zfun_mult_left
huffman@44627
  1133
      bounded_bilinear.Bfun_prod_Zfun [OF bounded_bilinear_mult]
huffman@44627
  1134
      Bfun_inverse [OF f a] f [unfolded tendsto_Zfun_iff])
huffman@44627
  1135
  ultimately show ?thesis
huffman@44627
  1136
    unfolding tendsto_Zfun_iff by (rule Zfun_ssubst)
huffman@31355
  1137
qed
huffman@31355
  1138
huffman@31565
  1139
lemma tendsto_divide [tendsto_intros]:
huffman@31355
  1140
  fixes a b :: "'a::real_normed_field"
huffman@44195
  1141
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F; b \<noteq> 0\<rbrakk>
huffman@44195
  1142
    \<Longrightarrow> ((\<lambda>x. f x / g x) ---> a / b) F"
huffman@44282
  1143
  by (simp add: tendsto_mult tendsto_inverse divide_inverse)
huffman@31355
  1144
huffman@44194
  1145
lemma tendsto_sgn [tendsto_intros]:
huffman@44194
  1146
  fixes l :: "'a::real_normed_vector"
huffman@44195
  1147
  shows "\<lbrakk>(f ---> l) F; l \<noteq> 0\<rbrakk> \<Longrightarrow> ((\<lambda>x. sgn (f x)) ---> sgn l) F"
huffman@44194
  1148
  unfolding sgn_div_norm by (simp add: tendsto_intros)
huffman@44194
  1149
hoelzl@50247
  1150
subsection {* Limits to @{const at_top} and @{const at_bot} *}
hoelzl@50247
  1151
hoelzl@50322
  1152
lemma filterlim_at_top:
hoelzl@50247
  1153
  fixes f :: "'a \<Rightarrow> ('b::dense_linorder)"
hoelzl@50247
  1154
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. Z < f x) F)"
hoelzl@50325
  1155
  by (auto simp: filterlim_iff eventually_at_top_dense elim!: eventually_elim1)
hoelzl@50247
  1156
hoelzl@50323
  1157
lemma filterlim_at_top_gt:
hoelzl@50323
  1158
  fixes f :: "'a \<Rightarrow> ('b::dense_linorder)" and c :: "'b"
hoelzl@50323
  1159
  shows "(LIM x F. f x :> at_top) \<longleftrightarrow> (\<forall>Z>c. eventually (\<lambda>x. Z < f x) F)"
hoelzl@50323
  1160
  unfolding filterlim_at_top
hoelzl@50323
  1161
proof safe
hoelzl@50323
  1162
  fix Z assume *: "\<forall>Z>c. eventually (\<lambda>x. Z < f x) F"
hoelzl@50323
  1163
  from gt_ex[of "max Z c"] guess x ..
hoelzl@50323
  1164
  with *[THEN spec, of x] show "eventually (\<lambda>x. Z < f x) F"
hoelzl@50323
  1165
    by (auto elim!: eventually_elim1)
hoelzl@50323
  1166
qed simp
hoelzl@50323
  1167
hoelzl@50322
  1168
lemma filterlim_at_bot: 
hoelzl@50247
  1169
  fixes f :: "'a \<Rightarrow> ('b::dense_linorder)"
hoelzl@50247
  1170
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z. eventually (\<lambda>x. f x < Z) F)"
hoelzl@50325
  1171
  by (auto simp: filterlim_iff eventually_at_bot_dense elim!: eventually_elim1)
hoelzl@50247
  1172
hoelzl@50323
  1173
lemma filterlim_at_bot_lt:
hoelzl@50323
  1174
  fixes f :: "'a \<Rightarrow> ('b::dense_linorder)" and c :: "'b"
hoelzl@50323
  1175
  shows "(LIM x F. f x :> at_bot) \<longleftrightarrow> (\<forall>Z<c. eventually (\<lambda>x. Z > f x) F)"
hoelzl@50323
  1176
  unfolding filterlim_at_bot
hoelzl@50323
  1177
proof safe
hoelzl@50323
  1178
  fix Z assume *: "\<forall>Z<c. eventually (\<lambda>x. Z > f x) F"
hoelzl@50323
  1179
  from lt_ex[of "min Z c"] guess x ..
hoelzl@50323
  1180
  with *[THEN spec, of x] show "eventually (\<lambda>x. Z > f x) F"
hoelzl@50323
  1181
    by (auto elim!: eventually_elim1)
hoelzl@50323
  1182
qed simp
hoelzl@50323
  1183
hoelzl@50325
  1184
lemma filterlim_at_infinity:
hoelzl@50325
  1185
  fixes f :: "_ \<Rightarrow> 'a\<Colon>real_normed_vector"
hoelzl@50325
  1186
  assumes "0 \<le> c"
hoelzl@50325
  1187
  shows "(LIM x F. f x :> at_infinity) \<longleftrightarrow> (\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F)"
hoelzl@50325
  1188
  unfolding filterlim_iff eventually_at_infinity
hoelzl@50325
  1189
proof safe
hoelzl@50325
  1190
  fix P :: "'a \<Rightarrow> bool" and b
hoelzl@50325
  1191
  assume *: "\<forall>r>c. eventually (\<lambda>x. r \<le> norm (f x)) F"
hoelzl@50325
  1192
    and P: "\<forall>x. b \<le> norm x \<longrightarrow> P x"
hoelzl@50325
  1193
  have "max b (c + 1) > c" by auto
hoelzl@50325
  1194
  with * have "eventually (\<lambda>x. max b (c + 1) \<le> norm (f x)) F"
hoelzl@50325
  1195
    by auto
hoelzl@50325
  1196
  then show "eventually (\<lambda>x. P (f x)) F"
hoelzl@50325
  1197
  proof eventually_elim
hoelzl@50325
  1198
    fix x assume "max b (c + 1) \<le> norm (f x)"
hoelzl@50325
  1199
    with P show "P (f x)" by auto
hoelzl@50325
  1200
  qed
hoelzl@50325
  1201
qed force
hoelzl@50325
  1202
hoelzl@50322
  1203
lemma filterlim_real_sequentially: "LIM x sequentially. real x :> at_top"
hoelzl@50322
  1204
  unfolding filterlim_at_top
hoelzl@50247
  1205
  apply (intro allI)
hoelzl@50247
  1206
  apply (rule_tac c="natceiling (Z + 1)" in eventually_sequentiallyI)
hoelzl@50247
  1207
  apply (auto simp: natceiling_le_eq)
hoelzl@50247
  1208
  done
hoelzl@50247
  1209
hoelzl@50323
  1210
lemma filterlim_inverse_at_top_pos:
hoelzl@50323
  1211
  "LIM x (nhds 0 within {0::real <..}). inverse x :> at_top"
hoelzl@50323
  1212
  unfolding filterlim_at_top_gt[where c=0] eventually_within
hoelzl@50323
  1213
proof safe
hoelzl@50323
  1214
  fix Z :: real assume [arith]: "0 < Z"
hoelzl@50323
  1215
  then have "eventually (\<lambda>x. x < inverse Z) (nhds 0)"
hoelzl@50323
  1216
    by (auto simp add: eventually_nhds_metric dist_real_def intro!: exI[of _ "\<bar>inverse Z\<bar>"])
hoelzl@50323
  1217
  then show "eventually (\<lambda>x. x \<in> {0<..} \<longrightarrow> Z < inverse x) (nhds 0)"
hoelzl@50323
  1218
    by (auto elim!: eventually_elim1 simp: inverse_eq_divide field_simps)
hoelzl@50323
  1219
qed
hoelzl@50323
  1220
hoelzl@50323
  1221
lemma filterlim_inverse_at_top:
hoelzl@50323
  1222
  "(f ---> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. 0 < f x) F \<Longrightarrow> LIM x F. inverse (f x) :> at_top"
hoelzl@50323
  1223
  by (intro filterlim_compose[OF filterlim_inverse_at_top_pos])
hoelzl@50323
  1224
     (simp add: filterlim_def eventually_filtermap le_within_iff)
hoelzl@50323
  1225
hoelzl@50323
  1226
lemma filterlim_inverse_at_bot_neg:
hoelzl@50323
  1227
  "LIM x (nhds 0 within {..< 0::real}). inverse x :> at_bot"
hoelzl@50323
  1228
  unfolding filterlim_at_bot_lt[where c=0] eventually_within
hoelzl@50323
  1229
proof safe
hoelzl@50323
  1230
  fix Z :: real assume [arith]: "Z < 0"
hoelzl@50323
  1231
  have "eventually (\<lambda>x. inverse Z < x) (nhds 0)"
hoelzl@50323
  1232
    by (auto simp add: eventually_nhds_metric dist_real_def intro!: exI[of _ "\<bar>inverse Z\<bar>"])
hoelzl@50323
  1233
  then show "eventually (\<lambda>x. x \<in> {..< 0} \<longrightarrow> inverse x < Z) (nhds 0)"
hoelzl@50323
  1234
    by (auto elim!: eventually_elim1 simp: inverse_eq_divide field_simps)
hoelzl@50323
  1235
qed
hoelzl@50323
  1236
hoelzl@50323
  1237
lemma filterlim_inverse_at_bot:
hoelzl@50323
  1238
  "(f ---> (0 :: real)) F \<Longrightarrow> eventually (\<lambda>x. f x < 0) F \<Longrightarrow> LIM x F. inverse (f x) :> at_bot"
hoelzl@50323
  1239
  by (intro filterlim_compose[OF filterlim_inverse_at_bot_neg])
hoelzl@50323
  1240
     (simp add: filterlim_def eventually_filtermap le_within_iff)
hoelzl@50323
  1241
hoelzl@50323
  1242
lemma filterlim_uminus_at_top_at_bot: "LIM x at_bot. - x :: real :> at_top"
hoelzl@50323
  1243
  unfolding filterlim_at_top eventually_at_bot_dense
hoelzl@50323
  1244
  by (blast intro: less_minus_iff[THEN iffD1])
hoelzl@50323
  1245
hoelzl@50323
  1246
lemma filterlim_uminus_at_top: "LIM x F. f x :> at_bot \<Longrightarrow> LIM x F. - (f x) :: real :> at_top"
hoelzl@50323
  1247
  by (rule filterlim_compose[OF filterlim_uminus_at_top_at_bot])
hoelzl@50323
  1248
hoelzl@50323
  1249
lemma filterlim_uminus_at_bot_at_top: "LIM x at_top. - x :: real :> at_bot"
hoelzl@50323
  1250
  unfolding filterlim_at_bot eventually_at_top_dense
hoelzl@50323
  1251
  by (blast intro: minus_less_iff[THEN iffD1])
hoelzl@50323
  1252
hoelzl@50323
  1253
lemma filterlim_uminus_at_bot: "LIM x F. f x :> at_top \<Longrightarrow> LIM x F. - (f x) :: real :> at_bot"
hoelzl@50323
  1254
  by (rule filterlim_compose[OF filterlim_uminus_at_bot_at_top])
hoelzl@50323
  1255
hoelzl@50325
  1256
lemma tendsto_inverse_0:
hoelzl@50325
  1257
  fixes x :: "_ \<Rightarrow> 'a\<Colon>real_normed_div_algebra"
hoelzl@50325
  1258
  shows "(inverse ---> (0::'a)) at_infinity"
hoelzl@50325
  1259
  unfolding tendsto_Zfun_iff diff_0_right Zfun_def eventually_at_infinity
hoelzl@50325
  1260
proof safe
hoelzl@50325
  1261
  fix r :: real assume "0 < r"
hoelzl@50325
  1262
  show "\<exists>b. \<forall>x. b \<le> norm x \<longrightarrow> norm (inverse x :: 'a) < r"
hoelzl@50325
  1263
  proof (intro exI[of _ "inverse (r / 2)"] allI impI)
hoelzl@50325
  1264
    fix x :: 'a
hoelzl@50325
  1265
    from `0 < r` have "0 < inverse (r / 2)" by simp
hoelzl@50325
  1266
    also assume *: "inverse (r / 2) \<le> norm x"
hoelzl@50325
  1267
    finally show "norm (inverse x) < r"
hoelzl@50325
  1268
      using * `0 < r` by (subst nonzero_norm_inverse) (simp_all add: inverse_eq_divide field_simps)
hoelzl@50325
  1269
  qed
hoelzl@50325
  1270
qed
hoelzl@50325
  1271
hoelzl@50325
  1272
lemma filterlim_inverse_at_infinity:
hoelzl@50325
  1273
  fixes x :: "_ \<Rightarrow> 'a\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50325
  1274
  shows "filterlim inverse at_infinity (at (0::'a))"
hoelzl@50325
  1275
  unfolding filterlim_at_infinity[OF order_refl]
hoelzl@50325
  1276
proof safe
hoelzl@50325
  1277
  fix r :: real assume "0 < r"
hoelzl@50325
  1278
  then show "eventually (\<lambda>x::'a. r \<le> norm (inverse x)) (at 0)"
hoelzl@50325
  1279
    unfolding eventually_at norm_inverse
hoelzl@50325
  1280
    by (intro exI[of _ "inverse r"])
hoelzl@50325
  1281
       (auto simp: norm_conv_dist[symmetric] field_simps inverse_eq_divide)
hoelzl@50325
  1282
qed
hoelzl@50325
  1283
hoelzl@50325
  1284
lemma filterlim_inverse_at_iff:
hoelzl@50325
  1285
  fixes g :: "'a \<Rightarrow> 'b\<Colon>{real_normed_div_algebra, division_ring_inverse_zero}"
hoelzl@50325
  1286
  shows "(LIM x F. inverse (g x) :> at 0) \<longleftrightarrow> (LIM x F. g x :> at_infinity)"
hoelzl@50325
  1287
  unfolding filterlim_def filtermap_filtermap[symmetric]
hoelzl@50325
  1288
proof
hoelzl@50325
  1289
  assume "filtermap g F \<le> at_infinity"
hoelzl@50325
  1290
  then have "filtermap inverse (filtermap g F) \<le> filtermap inverse at_infinity"
hoelzl@50325
  1291
    by (rule filtermap_mono)
hoelzl@50325
  1292
  also have "\<dots> \<le> at 0"
hoelzl@50325
  1293
    using tendsto_inverse_0
hoelzl@50325
  1294
    by (auto intro!: le_withinI exI[of _ 1]
hoelzl@50325
  1295
             simp: eventually_filtermap eventually_at_infinity filterlim_def at_def)
hoelzl@50325
  1296
  finally show "filtermap inverse (filtermap g F) \<le> at 0" .
hoelzl@50325
  1297
next
hoelzl@50325
  1298
  assume "filtermap inverse (filtermap g F) \<le> at 0"
hoelzl@50325
  1299
  then have "filtermap inverse (filtermap inverse (filtermap g F)) \<le> filtermap inverse (at 0)"
hoelzl@50325
  1300
    by (rule filtermap_mono)
hoelzl@50325
  1301
  with filterlim_inverse_at_infinity show "filtermap g F \<le> at_infinity"
hoelzl@50325
  1302
    by (auto intro: order_trans simp: filterlim_def filtermap_filtermap)
hoelzl@50325
  1303
qed
hoelzl@50325
  1304
hoelzl@50324
  1305
text {*
hoelzl@50324
  1306
hoelzl@50324
  1307
We only show rules for multiplication and addition when the functions are either against a real
hoelzl@50324
  1308
value or against infinity. Further rules are easy to derive by using @{thm filterlim_uminus_at_top}.
hoelzl@50324
  1309
hoelzl@50324
  1310
*}
hoelzl@50324
  1311
hoelzl@50324
  1312
lemma filterlim_tendsto_pos_mult_at_top: 
hoelzl@50324
  1313
  assumes f: "(f ---> c) F" and c: "0 < c"
hoelzl@50324
  1314
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
  1315
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
  1316
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1317
proof safe
hoelzl@50324
  1318
  fix Z :: real assume "0 < Z"
hoelzl@50324
  1319
  from f `0 < c` have "eventually (\<lambda>x. c / 2 < f x) F"
hoelzl@50324
  1320
    by (auto dest!: tendstoD[where e="c / 2"] elim!: eventually_elim1
hoelzl@50324
  1321
             simp: dist_real_def abs_real_def split: split_if_asm)
hoelzl@50324
  1322
  moreover from g have "eventually (\<lambda>x. (Z / c * 2) < g x) F"
hoelzl@50324
  1323
    unfolding filterlim_at_top by auto
hoelzl@50324
  1324
  ultimately show "eventually (\<lambda>x. Z < f x * g x) F"
hoelzl@50324
  1325
  proof eventually_elim
hoelzl@50324
  1326
    fix x assume "c / 2 < f x" "Z / c * 2 < g x"
hoelzl@50324
  1327
    with `0 < Z` `0 < c` have "c / 2 * (Z / c * 2) < f x * g x"
hoelzl@50324
  1328
      by (intro mult_strict_mono) (auto simp: zero_le_divide_iff)
hoelzl@50324
  1329
    with `0 < c` show "Z < f x * g x"
hoelzl@50324
  1330
       by simp
hoelzl@50324
  1331
  qed
hoelzl@50324
  1332
qed
hoelzl@50324
  1333
hoelzl@50324
  1334
lemma filterlim_at_top_mult_at_top: 
hoelzl@50324
  1335
  assumes f: "LIM x F. f x :> at_top"
hoelzl@50324
  1336
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
  1337
  shows "LIM x F. (f x * g x :: real) :> at_top"
hoelzl@50324
  1338
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1339
proof safe
hoelzl@50324
  1340
  fix Z :: real assume "0 < Z"
hoelzl@50324
  1341
  from f have "eventually (\<lambda>x. 1 < f x) F"
hoelzl@50324
  1342
    unfolding filterlim_at_top by auto
hoelzl@50324
  1343
  moreover from g have "eventually (\<lambda>x. Z < g x) F"
hoelzl@50324
  1344
    unfolding filterlim_at_top by auto
hoelzl@50324
  1345
  ultimately show "eventually (\<lambda>x. Z < f x * g x) F"
hoelzl@50324
  1346
  proof eventually_elim
hoelzl@50324
  1347
    fix x assume "1 < f x" "Z < g x"
hoelzl@50324
  1348
    with `0 < Z` have "1 * Z < f x * g x"
hoelzl@50324
  1349
      by (intro mult_strict_mono) (auto simp: zero_le_divide_iff)
hoelzl@50324
  1350
    then show "Z < f x * g x"
hoelzl@50324
  1351
       by simp
hoelzl@50324
  1352
  qed
hoelzl@50324
  1353
qed
hoelzl@50324
  1354
hoelzl@50324
  1355
lemma filterlim_tendsto_add_at_top: 
hoelzl@50324
  1356
  assumes f: "(f ---> c) F"
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 have "eventually (\<lambda>x. c - 1 < f x) F"
hoelzl@50324
  1363
    by (auto dest!: tendstoD[where e=1] elim!: eventually_elim1 simp: dist_real_def)
hoelzl@50324
  1364
  moreover from g have "eventually (\<lambda>x. Z - (c - 1) < g x) F"
hoelzl@50324
  1365
    unfolding filterlim_at_top by auto
hoelzl@50324
  1366
  ultimately show "eventually (\<lambda>x. Z < f x + g x) F"
hoelzl@50324
  1367
    by eventually_elim simp
hoelzl@50324
  1368
qed
hoelzl@50324
  1369
hoelzl@50324
  1370
lemma filterlim_at_top_add_at_top: 
hoelzl@50324
  1371
  assumes f: "LIM x F. f x :> at_top"
hoelzl@50324
  1372
  assumes g: "LIM x F. g x :> at_top"
hoelzl@50324
  1373
  shows "LIM x F. (f x + g x :: real) :> at_top"
hoelzl@50324
  1374
  unfolding filterlim_at_top_gt[where c=0]
hoelzl@50324
  1375
proof safe
hoelzl@50324
  1376
  fix Z :: real assume "0 < Z"
hoelzl@50324
  1377
  from f have "eventually (\<lambda>x. 0 < f x) F"
hoelzl@50324
  1378
    unfolding filterlim_at_top by auto
hoelzl@50324
  1379
  moreover from g have "eventually (\<lambda>x. Z < g x) F"
hoelzl@50324
  1380
    unfolding filterlim_at_top by auto
hoelzl@50324
  1381
  ultimately show "eventually (\<lambda>x. Z < f x + g x) F"
hoelzl@50324
  1382
    by eventually_elim simp
hoelzl@50324
  1383
qed
hoelzl@50324
  1384
hoelzl@50330
  1385
subsection {* Relate @{const at}, @{const at_left} and @{const at_right} *}
hoelzl@50330
  1386
hoelzl@50330
  1387
text {*
hoelzl@50330
  1388
hoelzl@50330
  1389
This lemmas are useful for conversion between @{term "at x"} to @{term "at_left x"} and
hoelzl@50330
  1390
@{term "at_right x"} and also @{term "at_right 0"}.
hoelzl@50330
  1391
hoelzl@50330
  1392
*}
hoelzl@50330
  1393
hoelzl@50330
  1394
lemma at_eq_sup_left_right: "at (x::real) = sup (at_left x) (at_right x)"
hoelzl@50330
  1395
  by (auto simp: eventually_within at_def filter_eq_iff eventually_sup 
hoelzl@50330
  1396
           elim: eventually_elim2 eventually_elim1)
hoelzl@50330
  1397
hoelzl@50330
  1398
lemma filterlim_split_at_real:
hoelzl@50330
  1399
  "filterlim f F (at_left x) \<Longrightarrow> filterlim f F (at_right x) \<Longrightarrow> filterlim f F (at (x::real))"
hoelzl@50330
  1400
  by (subst at_eq_sup_left_right) (rule filterlim_sup)
hoelzl@50330
  1401
hoelzl@50330
  1402
lemma filtermap_nhds_shift: "filtermap (\<lambda>x. x - d) (nhds a) = nhds (a - d::real)"
hoelzl@50330
  1403
  unfolding filter_eq_iff eventually_filtermap eventually_nhds_metric
hoelzl@50330
  1404
  by (intro allI ex_cong) (auto simp: dist_real_def field_simps)
hoelzl@50330
  1405
hoelzl@50330
  1406
lemma filtermap_nhds_minus: "filtermap (\<lambda>x. - x) (nhds a) = nhds (- a::real)"
hoelzl@50330
  1407
  unfolding filter_eq_iff eventually_filtermap eventually_nhds_metric
hoelzl@50330
  1408
  apply (intro allI ex_cong)
hoelzl@50330
  1409
  apply (auto simp: dist_real_def field_simps)
hoelzl@50330
  1410
  apply (erule_tac x="-x" in allE)
hoelzl@50330
  1411
  apply simp
hoelzl@50330
  1412
  done
hoelzl@50330
  1413
hoelzl@50330
  1414
lemma filtermap_at_shift: "filtermap (\<lambda>x. x - d) (at a) = at (a - d::real)"
hoelzl@50330
  1415
  unfolding at_def filtermap_nhds_shift[symmetric]
hoelzl@50330
  1416
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50330
  1417
hoelzl@50330
  1418
lemma filtermap_at_right_shift: "filtermap (\<lambda>x. x - d) (at_right a) = at_right (a - d::real)"
hoelzl@50330
  1419
  unfolding filtermap_at_shift[symmetric]
hoelzl@50330
  1420
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50330
  1421
hoelzl@50330
  1422
lemma at_right_to_0: "at_right (a::real) = filtermap (\<lambda>x. x + a) (at_right 0)"
hoelzl@50330
  1423
  using filtermap_at_right_shift[of "-a" 0] by simp
hoelzl@50330
  1424
hoelzl@50330
  1425
lemma filterlim_at_right_to_0:
hoelzl@50330
  1426
  "filterlim f F (at_right (a::real)) \<longleftrightarrow> filterlim (\<lambda>x. f (x + a)) F (at_right 0)"
hoelzl@50330
  1427
  unfolding filterlim_def filtermap_filtermap at_right_to_0[of a] ..
hoelzl@50330
  1428
hoelzl@50330
  1429
lemma eventually_at_right_to_0:
hoelzl@50330
  1430
  "eventually P (at_right (a::real)) \<longleftrightarrow> eventually (\<lambda>x. P (x + a)) (at_right 0)"
hoelzl@50330
  1431
  unfolding at_right_to_0[of a] by (simp add: eventually_filtermap)
hoelzl@50330
  1432
hoelzl@50330
  1433
lemma filtermap_at_minus: "filtermap (\<lambda>x. - x) (at a) = at (- a::real)"
hoelzl@50330
  1434
  unfolding at_def filtermap_nhds_minus[symmetric]
hoelzl@50330
  1435
  by (simp add: filter_eq_iff eventually_filtermap eventually_within)
hoelzl@50330
  1436
hoelzl@50330
  1437
lemma at_left_minus: "at_left (a::real) = filtermap (\<lambda>x. - x) (at_right (- a))"
hoelzl@50330
  1438
  by (simp add: filter_eq_iff eventually_filtermap eventually_within filtermap_at_minus[symmetric])
hoelzl@50330
  1439
hoelzl@50330
  1440
lemma at_right_minus: "at_right (a::real) = filtermap (\<lambda>x. - x) (at_left (- a))"
hoelzl@50330
  1441
  by (simp add: filter_eq_iff eventually_filtermap eventually_within filtermap_at_minus[symmetric])
hoelzl@50330
  1442
hoelzl@50330
  1443
lemma filterlim_at_left_to_right:
hoelzl@50330
  1444
  "filterlim f F (at_left (a::real)) \<longleftrightarrow> filterlim (\<lambda>x. f (- x)) F (at_right (-a))"
hoelzl@50330
  1445
  unfolding filterlim_def filtermap_filtermap at_left_minus[of a] ..
hoelzl@50330
  1446
hoelzl@50330
  1447
lemma eventually_at_left_to_right:
hoelzl@50330
  1448
  "eventually P (at_left (a::real)) \<longleftrightarrow> eventually (\<lambda>x. P (- x)) (at_right (-a))"
hoelzl@50330
  1449
  unfolding at_left_minus[of a] by (simp add: eventually_filtermap)
hoelzl@50330
  1450
hoelzl@50330
  1451
lemma filterlim_at_split:
hoelzl@50330
  1452
  "filterlim f F (at (x::real)) \<longleftrightarrow> filterlim f F (at_left x) \<and> filterlim f F (at_right x)"
hoelzl@50330
  1453
  by (subst at_eq_sup_left_right) (simp add: filterlim_def filtermap_sup)
hoelzl@50330
  1454
hoelzl@50330
  1455
lemma eventually_at_split:
hoelzl@50330
  1456
  "eventually P (at (x::real)) \<longleftrightarrow> eventually P (at_left x) \<and> eventually P (at_right x)"
hoelzl@50330
  1457
  by (subst at_eq_sup_left_right) (simp add: eventually_sup)
hoelzl@50330
  1458
huffman@31349
  1459
end
hoelzl@50324
  1460