src/HOL/Limits.thy
author huffman
Sun Aug 14 10:47:47 2011 -0700 (2011-08-14)
changeset 44206 5e4a1664106e
parent 44205 18da2a87421c
child 44218 f0e442e24816
permissions -rw-r--r--
locale-ize some constant definitions, so complete_space can inherit from metric_space
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
huffman@44081
    23
typedef (open) '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
huffman@36360
   104
subsection {* Finer-than relation *}
huffman@36360
   105
huffman@44195
   106
text {* @{term "F \<le> F'"} means that filter @{term F} is finer than
huffman@44195
   107
filter @{term F'}. *}
huffman@36360
   108
huffman@44081
   109
instantiation filter :: (type) complete_lattice
huffman@36360
   110
begin
huffman@36360
   111
huffman@44081
   112
definition le_filter_def:
huffman@44195
   113
  "F \<le> F' \<longleftrightarrow> (\<forall>P. eventually P F' \<longrightarrow> eventually P F)"
huffman@36360
   114
huffman@36360
   115
definition
huffman@44195
   116
  "(F :: 'a filter) < F' \<longleftrightarrow> F \<le> F' \<and> \<not> F' \<le> F"
huffman@36360
   117
huffman@36360
   118
definition
huffman@44081
   119
  "top = Abs_filter (\<lambda>P. \<forall>x. P x)"
huffman@36630
   120
huffman@36630
   121
definition
huffman@44081
   122
  "bot = Abs_filter (\<lambda>P. True)"
huffman@36360
   123
huffman@36630
   124
definition
huffman@44195
   125
  "sup F F' = Abs_filter (\<lambda>P. eventually P F \<and> eventually P F')"
huffman@36630
   126
huffman@36630
   127
definition
huffman@44195
   128
  "inf F F' = Abs_filter
huffman@44195
   129
      (\<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
   130
huffman@36630
   131
definition
huffman@44195
   132
  "Sup S = Abs_filter (\<lambda>P. \<forall>F\<in>S. eventually P F)"
huffman@36630
   133
huffman@36630
   134
definition
huffman@44195
   135
  "Inf S = Sup {F::'a filter. \<forall>F'\<in>S. F \<le> F'}"
huffman@36630
   136
huffman@36630
   137
lemma eventually_top [simp]: "eventually P top \<longleftrightarrow> (\<forall>x. P x)"
huffman@44081
   138
  unfolding top_filter_def
huffman@44081
   139
  by (rule eventually_Abs_filter, rule is_filter.intro, auto)
huffman@36630
   140
huffman@36629
   141
lemma eventually_bot [simp]: "eventually P bot"
huffman@44081
   142
  unfolding bot_filter_def
huffman@44081
   143
  by (subst eventually_Abs_filter, rule is_filter.intro, auto)
huffman@36360
   144
huffman@36630
   145
lemma eventually_sup:
huffman@44195
   146
  "eventually P (sup F F') \<longleftrightarrow> eventually P F \<and> eventually P F'"
huffman@44081
   147
  unfolding sup_filter_def
huffman@44081
   148
  by (rule eventually_Abs_filter, rule is_filter.intro)
huffman@44081
   149
     (auto elim!: eventually_rev_mp)
huffman@36630
   150
huffman@36630
   151
lemma eventually_inf:
huffman@44195
   152
  "eventually P (inf F F') \<longleftrightarrow>
huffman@44195
   153
   (\<exists>Q R. eventually Q F \<and> eventually R F' \<and> (\<forall>x. Q x \<and> R x \<longrightarrow> P x))"
huffman@44081
   154
  unfolding inf_filter_def
huffman@44081
   155
  apply (rule eventually_Abs_filter, rule is_filter.intro)
huffman@44081
   156
  apply (fast intro: eventually_True)
huffman@44081
   157
  apply clarify
huffman@44081
   158
  apply (intro exI conjI)
huffman@44081
   159
  apply (erule (1) eventually_conj)
huffman@44081
   160
  apply (erule (1) eventually_conj)
huffman@44081
   161
  apply simp
huffman@44081
   162
  apply auto
huffman@44081
   163
  done
huffman@36630
   164
huffman@36630
   165
lemma eventually_Sup:
huffman@44195
   166
  "eventually P (Sup S) \<longleftrightarrow> (\<forall>F\<in>S. eventually P F)"
huffman@44081
   167
  unfolding Sup_filter_def
huffman@44081
   168
  apply (rule eventually_Abs_filter, rule is_filter.intro)
huffman@44081
   169
  apply (auto intro: eventually_conj elim!: eventually_rev_mp)
huffman@44081
   170
  done
huffman@36630
   171
huffman@36360
   172
instance proof
huffman@44195
   173
  fix F F' F'' :: "'a filter" and S :: "'a filter set"
huffman@44195
   174
  { show "F < F' \<longleftrightarrow> F \<le> F' \<and> \<not> F' \<le> F"
huffman@44195
   175
    by (rule less_filter_def) }
huffman@44195
   176
  { show "F \<le> F"
huffman@44195
   177
    unfolding le_filter_def by simp }
huffman@44195
   178
  { assume "F \<le> F'" and "F' \<le> F''" thus "F \<le> F''"
huffman@44195
   179
    unfolding le_filter_def by simp }
huffman@44195
   180
  { assume "F \<le> F'" and "F' \<le> F" thus "F = F'"
huffman@44195
   181
    unfolding le_filter_def filter_eq_iff by fast }
huffman@44195
   182
  { show "F \<le> top"
huffman@44195
   183
    unfolding le_filter_def eventually_top by (simp add: always_eventually) }
huffman@44195
   184
  { show "bot \<le> F"
huffman@44195
   185
    unfolding le_filter_def by simp }
huffman@44195
   186
  { show "F \<le> sup F F'" and "F' \<le> sup F F'"
huffman@44195
   187
    unfolding le_filter_def eventually_sup by simp_all }
huffman@44195
   188
  { assume "F \<le> F''" and "F' \<le> F''" thus "sup F F' \<le> F''"
huffman@44195
   189
    unfolding le_filter_def eventually_sup by simp }
huffman@44195
   190
  { show "inf F F' \<le> F" and "inf F F' \<le> F'"
huffman@44195
   191
    unfolding le_filter_def eventually_inf by (auto intro: eventually_True) }
huffman@44195
   192
  { assume "F \<le> F'" and "F \<le> F''" thus "F \<le> inf F' F''"
huffman@44081
   193
    unfolding le_filter_def eventually_inf
huffman@44195
   194
    by (auto elim!: eventually_mono intro: eventually_conj) }
huffman@44195
   195
  { assume "F \<in> S" thus "F \<le> Sup S"
huffman@44195
   196
    unfolding le_filter_def eventually_Sup by simp }
huffman@44195
   197
  { assume "\<And>F. F \<in> S \<Longrightarrow> F \<le> F'" thus "Sup S \<le> F'"
huffman@44195
   198
    unfolding le_filter_def eventually_Sup by simp }
huffman@44195
   199
  { assume "F'' \<in> S" thus "Inf S \<le> F''"
huffman@44195
   200
    unfolding le_filter_def Inf_filter_def eventually_Sup Ball_def by simp }
huffman@44195
   201
  { assume "\<And>F'. F' \<in> S \<Longrightarrow> F \<le> F'" thus "F \<le> Inf S"
huffman@44195
   202
    unfolding le_filter_def Inf_filter_def eventually_Sup Ball_def by simp }
huffman@36360
   203
qed
huffman@36360
   204
huffman@36360
   205
end
huffman@36360
   206
huffman@44081
   207
lemma filter_leD:
huffman@44195
   208
  "F \<le> F' \<Longrightarrow> eventually P F' \<Longrightarrow> eventually P F"
huffman@44081
   209
  unfolding le_filter_def by simp
huffman@36360
   210
huffman@44081
   211
lemma filter_leI:
huffman@44195
   212
  "(\<And>P. eventually P F' \<Longrightarrow> eventually P F) \<Longrightarrow> F \<le> F'"
huffman@44081
   213
  unfolding le_filter_def by simp
huffman@36360
   214
huffman@36360
   215
lemma eventually_False:
huffman@44195
   216
  "eventually (\<lambda>x. False) F \<longleftrightarrow> F = bot"
huffman@44081
   217
  unfolding filter_eq_iff by (auto elim: eventually_rev_mp)
huffman@36360
   218
huffman@44081
   219
subsection {* Map function for filters *}
huffman@36654
   220
huffman@44081
   221
definition filtermap :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a filter \<Rightarrow> 'b filter"
huffman@44195
   222
  where "filtermap f F = Abs_filter (\<lambda>P. eventually (\<lambda>x. P (f x)) F)"
huffman@36654
   223
huffman@44081
   224
lemma eventually_filtermap:
huffman@44195
   225
  "eventually P (filtermap f F) = eventually (\<lambda>x. P (f x)) F"
huffman@44081
   226
  unfolding filtermap_def
huffman@44081
   227
  apply (rule eventually_Abs_filter)
huffman@44081
   228
  apply (rule is_filter.intro)
huffman@44081
   229
  apply (auto elim!: eventually_rev_mp)
huffman@44081
   230
  done
huffman@36654
   231
huffman@44195
   232
lemma filtermap_ident: "filtermap (\<lambda>x. x) F = F"
huffman@44081
   233
  by (simp add: filter_eq_iff eventually_filtermap)
huffman@36654
   234
huffman@44081
   235
lemma filtermap_filtermap:
huffman@44195
   236
  "filtermap f (filtermap g F) = filtermap (\<lambda>x. f (g x)) F"
huffman@44081
   237
  by (simp add: filter_eq_iff eventually_filtermap)
huffman@36654
   238
huffman@44195
   239
lemma filtermap_mono: "F \<le> F' \<Longrightarrow> filtermap f F \<le> filtermap f F'"
huffman@44081
   240
  unfolding le_filter_def eventually_filtermap by simp
huffman@44081
   241
huffman@44081
   242
lemma filtermap_bot [simp]: "filtermap f bot = bot"
huffman@44081
   243
  by (simp add: filter_eq_iff eventually_filtermap)
huffman@36654
   244
huffman@36654
   245
huffman@36662
   246
subsection {* Sequentially *}
huffman@31392
   247
huffman@44081
   248
definition sequentially :: "nat filter"
huffman@44081
   249
  where "sequentially = Abs_filter (\<lambda>P. \<exists>k. \<forall>n\<ge>k. P n)"
huffman@31392
   250
huffman@36662
   251
lemma eventually_sequentially:
huffman@36662
   252
  "eventually P sequentially \<longleftrightarrow> (\<exists>N. \<forall>n\<ge>N. P n)"
huffman@36662
   253
unfolding sequentially_def
huffman@44081
   254
proof (rule eventually_Abs_filter, rule is_filter.intro)
huffman@36662
   255
  fix P Q :: "nat \<Rightarrow> bool"
huffman@36662
   256
  assume "\<exists>i. \<forall>n\<ge>i. P n" and "\<exists>j. \<forall>n\<ge>j. Q n"
huffman@36662
   257
  then obtain i j where "\<forall>n\<ge>i. P n" and "\<forall>n\<ge>j. Q n" by auto
huffman@36662
   258
  then have "\<forall>n\<ge>max i j. P n \<and> Q n" by simp
huffman@36662
   259
  then show "\<exists>k. \<forall>n\<ge>k. P n \<and> Q n" ..
huffman@36662
   260
qed auto
huffman@36662
   261
huffman@36662
   262
lemma sequentially_bot [simp]: "sequentially \<noteq> bot"
huffman@44081
   263
  unfolding filter_eq_iff eventually_sequentially by auto
huffman@36662
   264
huffman@36662
   265
lemma eventually_False_sequentially [simp]:
huffman@36662
   266
  "\<not> eventually (\<lambda>n. False) sequentially"
huffman@44081
   267
  by (simp add: eventually_False)
huffman@36662
   268
huffman@36662
   269
lemma le_sequentially:
huffman@44195
   270
  "F \<le> sequentially \<longleftrightarrow> (\<forall>N. eventually (\<lambda>n. N \<le> n) F)"
huffman@44081
   271
  unfolding le_filter_def eventually_sequentially
huffman@44081
   272
  by (safe, fast, drule_tac x=N in spec, auto elim: eventually_rev_mp)
huffman@36662
   273
huffman@36662
   274
huffman@44081
   275
definition trivial_limit :: "'a filter \<Rightarrow> bool"
huffman@44195
   276
  where "trivial_limit F \<longleftrightarrow> eventually (\<lambda>x. False) F"
hoelzl@41970
   277
huffman@44081
   278
lemma trivial_limit_sequentially [intro]: "\<not> trivial_limit sequentially"
hoelzl@41970
   279
  by (auto simp add: trivial_limit_def eventually_sequentially)
hoelzl@41970
   280
huffman@44081
   281
subsection {* Standard filters *}
huffman@36662
   282
huffman@44081
   283
definition within :: "'a filter \<Rightarrow> 'a set \<Rightarrow> 'a filter" (infixr "within" 70)
huffman@44195
   284
  where "F within S = Abs_filter (\<lambda>P. eventually (\<lambda>x. x \<in> S \<longrightarrow> P x) F)"
huffman@31392
   285
huffman@44206
   286
definition (in topological_space) nhds :: "'a \<Rightarrow> 'a filter"
huffman@44081
   287
  where "nhds a = Abs_filter (\<lambda>P. \<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
huffman@36654
   288
huffman@44206
   289
definition (in topological_space) at :: "'a \<Rightarrow> 'a filter"
huffman@44081
   290
  where "at a = nhds a within - {a}"
huffman@31447
   291
huffman@31392
   292
lemma eventually_within:
huffman@44195
   293
  "eventually P (F within S) = eventually (\<lambda>x. x \<in> S \<longrightarrow> P x) F"
huffman@44081
   294
  unfolding within_def
huffman@44081
   295
  by (rule eventually_Abs_filter, rule is_filter.intro)
huffman@44081
   296
     (auto elim!: eventually_rev_mp)
huffman@31392
   297
huffman@44195
   298
lemma within_UNIV: "F within UNIV = F"
huffman@44081
   299
  unfolding filter_eq_iff eventually_within by simp
huffman@36360
   300
huffman@36654
   301
lemma eventually_nhds:
huffman@36654
   302
  "eventually P (nhds a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
huffman@36654
   303
unfolding nhds_def
huffman@44081
   304
proof (rule eventually_Abs_filter, rule is_filter.intro)
huffman@36654
   305
  have "open UNIV \<and> a \<in> UNIV \<and> (\<forall>x\<in>UNIV. True)" by simp
huffman@36654
   306
  thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. True)" by - rule
huffman@36358
   307
next
huffman@36358
   308
  fix P Q
huffman@36654
   309
  assume "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
huffman@36654
   310
     and "\<exists>T. open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)"
huffman@36358
   311
  then obtain S T where
huffman@36654
   312
    "open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
huffman@36654
   313
    "open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)" by auto
huffman@36654
   314
  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
   315
    by (simp add: open_Int)
huffman@36654
   316
  thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x \<and> Q x)" by - rule
huffman@36358
   317
qed auto
huffman@31447
   318
huffman@36656
   319
lemma eventually_nhds_metric:
huffman@36656
   320
  "eventually P (nhds a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. dist x a < d \<longrightarrow> P x)"
huffman@36656
   321
unfolding eventually_nhds open_dist
huffman@31447
   322
apply safe
huffman@31447
   323
apply fast
huffman@31492
   324
apply (rule_tac x="{x. dist x a < d}" in exI, simp)
huffman@31447
   325
apply clarsimp
huffman@31447
   326
apply (rule_tac x="d - dist x a" in exI, clarsimp)
huffman@31447
   327
apply (simp only: less_diff_eq)
huffman@31447
   328
apply (erule le_less_trans [OF dist_triangle])
huffman@31447
   329
done
huffman@31447
   330
huffman@36656
   331
lemma eventually_at_topological:
huffman@36656
   332
  "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
   333
unfolding at_def eventually_within eventually_nhds by simp
huffman@36656
   334
huffman@36656
   335
lemma eventually_at:
huffman@36656
   336
  fixes a :: "'a::metric_space"
huffman@36656
   337
  shows "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> P x)"
huffman@36656
   338
unfolding at_def eventually_within eventually_nhds_metric by auto
huffman@36656
   339
huffman@31392
   340
huffman@31355
   341
subsection {* Boundedness *}
huffman@31355
   342
huffman@44081
   343
definition Bfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
   344
  where "Bfun f F = (\<exists>K>0. eventually (\<lambda>x. norm (f x) \<le> K) F)"
huffman@31355
   345
huffman@31487
   346
lemma BfunI:
huffman@44195
   347
  assumes K: "eventually (\<lambda>x. norm (f x) \<le> K) F" shows "Bfun f F"
huffman@31355
   348
unfolding Bfun_def
huffman@31355
   349
proof (intro exI conjI allI)
huffman@31355
   350
  show "0 < max K 1" by simp
huffman@31355
   351
next
huffman@44195
   352
  show "eventually (\<lambda>x. norm (f x) \<le> max K 1) F"
huffman@31355
   353
    using K by (rule eventually_elim1, simp)
huffman@31355
   354
qed
huffman@31355
   355
huffman@31355
   356
lemma BfunE:
huffman@44195
   357
  assumes "Bfun f F"
huffman@44195
   358
  obtains B where "0 < B" and "eventually (\<lambda>x. norm (f x) \<le> B) F"
huffman@31355
   359
using assms unfolding Bfun_def by fast
huffman@31355
   360
huffman@31355
   361
huffman@31349
   362
subsection {* Convergence to Zero *}
huffman@31349
   363
huffman@44081
   364
definition Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
   365
  where "Zfun f F = (\<forall>r>0. eventually (\<lambda>x. norm (f x) < r) F)"
huffman@31349
   366
huffman@31349
   367
lemma ZfunI:
huffman@44195
   368
  "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F) \<Longrightarrow> Zfun f F"
huffman@44081
   369
  unfolding Zfun_def by simp
huffman@31349
   370
huffman@31349
   371
lemma ZfunD:
huffman@44195
   372
  "\<lbrakk>Zfun f F; 0 < r\<rbrakk> \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F"
huffman@44081
   373
  unfolding Zfun_def by simp
huffman@31349
   374
huffman@31355
   375
lemma Zfun_ssubst:
huffman@44195
   376
  "eventually (\<lambda>x. f x = g x) F \<Longrightarrow> Zfun g F \<Longrightarrow> Zfun f F"
huffman@44081
   377
  unfolding Zfun_def by (auto elim!: eventually_rev_mp)
huffman@31355
   378
huffman@44195
   379
lemma Zfun_zero: "Zfun (\<lambda>x. 0) F"
huffman@44081
   380
  unfolding Zfun_def by simp
huffman@31349
   381
huffman@44195
   382
lemma Zfun_norm_iff: "Zfun (\<lambda>x. norm (f x)) F = Zfun (\<lambda>x. f x) F"
huffman@44081
   383
  unfolding Zfun_def by simp
huffman@31349
   384
huffman@31349
   385
lemma Zfun_imp_Zfun:
huffman@44195
   386
  assumes f: "Zfun f F"
huffman@44195
   387
  assumes g: "eventually (\<lambda>x. norm (g x) \<le> norm (f x) * K) F"
huffman@44195
   388
  shows "Zfun (\<lambda>x. g x) F"
huffman@31349
   389
proof (cases)
huffman@31349
   390
  assume K: "0 < K"
huffman@31349
   391
  show ?thesis
huffman@31349
   392
  proof (rule ZfunI)
huffman@31349
   393
    fix r::real assume "0 < r"
huffman@31349
   394
    hence "0 < r / K"
huffman@31349
   395
      using K by (rule divide_pos_pos)
huffman@44195
   396
    then have "eventually (\<lambda>x. norm (f x) < r / K) F"
huffman@31487
   397
      using ZfunD [OF f] by fast
huffman@44195
   398
    with g show "eventually (\<lambda>x. norm (g x) < r) F"
huffman@31355
   399
    proof (rule eventually_elim2)
huffman@31487
   400
      fix x
huffman@31487
   401
      assume *: "norm (g x) \<le> norm (f x) * K"
huffman@31487
   402
      assume "norm (f x) < r / K"
huffman@31487
   403
      hence "norm (f x) * K < r"
huffman@31349
   404
        by (simp add: pos_less_divide_eq K)
huffman@31487
   405
      thus "norm (g x) < r"
huffman@31355
   406
        by (simp add: order_le_less_trans [OF *])
huffman@31349
   407
    qed
huffman@31349
   408
  qed
huffman@31349
   409
next
huffman@31349
   410
  assume "\<not> 0 < K"
huffman@31349
   411
  hence K: "K \<le> 0" by (simp only: not_less)
huffman@31355
   412
  show ?thesis
huffman@31355
   413
  proof (rule ZfunI)
huffman@31355
   414
    fix r :: real
huffman@31355
   415
    assume "0 < r"
huffman@44195
   416
    from g show "eventually (\<lambda>x. norm (g x) < r) F"
huffman@31355
   417
    proof (rule eventually_elim1)
huffman@31487
   418
      fix x
huffman@31487
   419
      assume "norm (g x) \<le> norm (f x) * K"
huffman@31487
   420
      also have "\<dots> \<le> norm (f x) * 0"
huffman@31355
   421
        using K norm_ge_zero by (rule mult_left_mono)
huffman@31487
   422
      finally show "norm (g x) < r"
huffman@31355
   423
        using `0 < r` by simp
huffman@31355
   424
    qed
huffman@31355
   425
  qed
huffman@31349
   426
qed
huffman@31349
   427
huffman@44195
   428
lemma Zfun_le: "\<lbrakk>Zfun g F; \<forall>x. norm (f x) \<le> norm (g x)\<rbrakk> \<Longrightarrow> Zfun f F"
huffman@44081
   429
  by (erule_tac K="1" in Zfun_imp_Zfun, simp)
huffman@31349
   430
huffman@31349
   431
lemma Zfun_add:
huffman@44195
   432
  assumes f: "Zfun f F" and g: "Zfun g F"
huffman@44195
   433
  shows "Zfun (\<lambda>x. f x + g x) F"
huffman@31349
   434
proof (rule ZfunI)
huffman@31349
   435
  fix r::real assume "0 < r"
huffman@31349
   436
  hence r: "0 < r / 2" by simp
huffman@44195
   437
  have "eventually (\<lambda>x. norm (f x) < r/2) F"
huffman@31487
   438
    using f r by (rule ZfunD)
huffman@31349
   439
  moreover
huffman@44195
   440
  have "eventually (\<lambda>x. norm (g x) < r/2) F"
huffman@31487
   441
    using g r by (rule ZfunD)
huffman@31349
   442
  ultimately
huffman@44195
   443
  show "eventually (\<lambda>x. norm (f x + g x) < r) F"
huffman@31349
   444
  proof (rule eventually_elim2)
huffman@31487
   445
    fix x
huffman@31487
   446
    assume *: "norm (f x) < r/2" "norm (g x) < r/2"
huffman@31487
   447
    have "norm (f x + g x) \<le> norm (f x) + norm (g x)"
huffman@31349
   448
      by (rule norm_triangle_ineq)
huffman@31349
   449
    also have "\<dots> < r/2 + r/2"
huffman@31349
   450
      using * by (rule add_strict_mono)
huffman@31487
   451
    finally show "norm (f x + g x) < r"
huffman@31349
   452
      by simp
huffman@31349
   453
  qed
huffman@31349
   454
qed
huffman@31349
   455
huffman@44195
   456
lemma Zfun_minus: "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. - f x) F"
huffman@44081
   457
  unfolding Zfun_def by simp
huffman@31349
   458
huffman@44195
   459
lemma Zfun_diff: "\<lbrakk>Zfun f F; Zfun g F\<rbrakk> \<Longrightarrow> Zfun (\<lambda>x. f x - g x) F"
huffman@44081
   460
  by (simp only: diff_minus Zfun_add Zfun_minus)
huffman@31349
   461
huffman@31349
   462
lemma (in bounded_linear) Zfun:
huffman@44195
   463
  assumes g: "Zfun g F"
huffman@44195
   464
  shows "Zfun (\<lambda>x. f (g x)) F"
huffman@31349
   465
proof -
huffman@31349
   466
  obtain K where "\<And>x. norm (f x) \<le> norm x * K"
huffman@31349
   467
    using bounded by fast
huffman@44195
   468
  then have "eventually (\<lambda>x. norm (f (g x)) \<le> norm (g x) * K) F"
huffman@31355
   469
    by simp
huffman@31487
   470
  with g show ?thesis
huffman@31349
   471
    by (rule Zfun_imp_Zfun)
huffman@31349
   472
qed
huffman@31349
   473
huffman@31349
   474
lemma (in bounded_bilinear) Zfun:
huffman@44195
   475
  assumes f: "Zfun f F"
huffman@44195
   476
  assumes g: "Zfun g F"
huffman@44195
   477
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31349
   478
proof (rule ZfunI)
huffman@31349
   479
  fix r::real assume r: "0 < r"
huffman@31349
   480
  obtain K where K: "0 < K"
huffman@31349
   481
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31349
   482
    using pos_bounded by fast
huffman@31349
   483
  from K have K': "0 < inverse K"
huffman@31349
   484
    by (rule positive_imp_inverse_positive)
huffman@44195
   485
  have "eventually (\<lambda>x. norm (f x) < r) F"
huffman@31487
   486
    using f r by (rule ZfunD)
huffman@31349
   487
  moreover
huffman@44195
   488
  have "eventually (\<lambda>x. norm (g x) < inverse K) F"
huffman@31487
   489
    using g K' by (rule ZfunD)
huffman@31349
   490
  ultimately
huffman@44195
   491
  show "eventually (\<lambda>x. norm (f x ** g x) < r) F"
huffman@31349
   492
  proof (rule eventually_elim2)
huffman@31487
   493
    fix x
huffman@31487
   494
    assume *: "norm (f x) < r" "norm (g x) < inverse K"
huffman@31487
   495
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31349
   496
      by (rule norm_le)
huffman@31487
   497
    also have "norm (f x) * norm (g x) * K < r * inverse K * K"
huffman@31349
   498
      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero * K)
huffman@31349
   499
    also from K have "r * inverse K * K = r"
huffman@31349
   500
      by simp
huffman@31487
   501
    finally show "norm (f x ** g x) < r" .
huffman@31349
   502
  qed
huffman@31349
   503
qed
huffman@31349
   504
huffman@31349
   505
lemma (in bounded_bilinear) Zfun_left:
huffman@44195
   506
  "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. f x ** a) F"
huffman@44081
   507
  by (rule bounded_linear_left [THEN bounded_linear.Zfun])
huffman@31349
   508
huffman@31349
   509
lemma (in bounded_bilinear) Zfun_right:
huffman@44195
   510
  "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. a ** f x) F"
huffman@44081
   511
  by (rule bounded_linear_right [THEN bounded_linear.Zfun])
huffman@31349
   512
huffman@31349
   513
lemmas Zfun_mult = mult.Zfun
huffman@31349
   514
lemmas Zfun_mult_right = mult.Zfun_right
huffman@31349
   515
lemmas Zfun_mult_left = mult.Zfun_left
huffman@31349
   516
huffman@31349
   517
wenzelm@31902
   518
subsection {* Limits *}
huffman@31349
   519
huffman@44206
   520
definition (in topological_space)
huffman@44206
   521
  tendsto :: "('b \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'b filter \<Rightarrow> bool" (infixr "--->" 55) where
huffman@44195
   522
  "(f ---> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
huffman@31349
   523
wenzelm@31902
   524
ML {*
wenzelm@31902
   525
structure Tendsto_Intros = Named_Thms
wenzelm@31902
   526
(
wenzelm@31902
   527
  val name = "tendsto_intros"
wenzelm@31902
   528
  val description = "introduction rules for tendsto"
wenzelm@31902
   529
)
huffman@31565
   530
*}
huffman@31565
   531
wenzelm@31902
   532
setup Tendsto_Intros.setup
huffman@31565
   533
huffman@44195
   534
lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f ---> l) F' \<Longrightarrow> (f ---> l) F"
huffman@44081
   535
  unfolding tendsto_def le_filter_def by fast
huffman@36656
   536
huffman@31488
   537
lemma topological_tendstoI:
huffman@44195
   538
  "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F)
huffman@44195
   539
    \<Longrightarrow> (f ---> l) F"
huffman@31349
   540
  unfolding tendsto_def by auto
huffman@31349
   541
huffman@31488
   542
lemma topological_tendstoD:
huffman@44195
   543
  "(f ---> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
huffman@31488
   544
  unfolding tendsto_def by auto
huffman@31488
   545
huffman@31488
   546
lemma tendstoI:
huffman@44195
   547
  assumes "\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
huffman@44195
   548
  shows "(f ---> l) F"
huffman@44081
   549
  apply (rule topological_tendstoI)
huffman@44081
   550
  apply (simp add: open_dist)
huffman@44081
   551
  apply (drule (1) bspec, clarify)
huffman@44081
   552
  apply (drule assms)
huffman@44081
   553
  apply (erule eventually_elim1, simp)
huffman@44081
   554
  done
huffman@31488
   555
huffman@31349
   556
lemma tendstoD:
huffman@44195
   557
  "(f ---> l) F \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
huffman@44081
   558
  apply (drule_tac S="{x. dist x l < e}" in topological_tendstoD)
huffman@44081
   559
  apply (clarsimp simp add: open_dist)
huffman@44081
   560
  apply (rule_tac x="e - dist x l" in exI, clarsimp)
huffman@44081
   561
  apply (simp only: less_diff_eq)
huffman@44081
   562
  apply (erule le_less_trans [OF dist_triangle])
huffman@44081
   563
  apply simp
huffman@44081
   564
  apply simp
huffman@44081
   565
  done
huffman@31488
   566
huffman@31488
   567
lemma tendsto_iff:
huffman@44195
   568
  "(f ---> l) F \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) F)"
huffman@44081
   569
  using tendstoI tendstoD by fast
huffman@31349
   570
huffman@44195
   571
lemma tendsto_Zfun_iff: "(f ---> a) F = Zfun (\<lambda>x. f x - a) F"
huffman@44081
   572
  by (simp only: tendsto_iff Zfun_def dist_norm)
huffman@31349
   573
huffman@31565
   574
lemma tendsto_ident_at [tendsto_intros]: "((\<lambda>x. x) ---> a) (at a)"
huffman@44081
   575
  unfolding tendsto_def eventually_at_topological by auto
huffman@31565
   576
huffman@31565
   577
lemma tendsto_ident_at_within [tendsto_intros]:
huffman@36655
   578
  "((\<lambda>x. x) ---> a) (at a within S)"
huffman@44081
   579
  unfolding tendsto_def eventually_within eventually_at_topological by auto
huffman@31565
   580
huffman@44195
   581
lemma tendsto_const [tendsto_intros]: "((\<lambda>x. k) ---> k) F"
huffman@44081
   582
  by (simp add: tendsto_def)
huffman@31349
   583
huffman@44205
   584
lemma tendsto_unique:
huffman@44205
   585
  fixes f :: "'a \<Rightarrow> 'b::t2_space"
huffman@44205
   586
  assumes "\<not> trivial_limit F" and "(f ---> a) F" and "(f ---> b) F"
huffman@44205
   587
  shows "a = b"
huffman@44205
   588
proof (rule ccontr)
huffman@44205
   589
  assume "a \<noteq> b"
huffman@44205
   590
  obtain U V where "open U" "open V" "a \<in> U" "b \<in> V" "U \<inter> V = {}"
huffman@44205
   591
    using hausdorff [OF `a \<noteq> b`] by fast
huffman@44205
   592
  have "eventually (\<lambda>x. f x \<in> U) F"
huffman@44205
   593
    using `(f ---> a) F` `open U` `a \<in> U` by (rule topological_tendstoD)
huffman@44205
   594
  moreover
huffman@44205
   595
  have "eventually (\<lambda>x. f x \<in> V) F"
huffman@44205
   596
    using `(f ---> b) F` `open V` `b \<in> V` by (rule topological_tendstoD)
huffman@44205
   597
  ultimately
huffman@44205
   598
  have "eventually (\<lambda>x. False) F"
huffman@44205
   599
  proof (rule eventually_elim2)
huffman@44205
   600
    fix x
huffman@44205
   601
    assume "f x \<in> U" "f x \<in> V"
huffman@44205
   602
    hence "f x \<in> U \<inter> V" by simp
huffman@44205
   603
    with `U \<inter> V = {}` show "False" by simp
huffman@44205
   604
  qed
huffman@44205
   605
  with `\<not> trivial_limit F` show "False"
huffman@44205
   606
    by (simp add: trivial_limit_def)
huffman@44205
   607
qed
huffman@44205
   608
huffman@36662
   609
lemma tendsto_const_iff:
huffman@44205
   610
  fixes a b :: "'a::t2_space"
huffman@44205
   611
  assumes "\<not> trivial_limit F" shows "((\<lambda>x. a) ---> b) F \<longleftrightarrow> a = b"
huffman@44205
   612
  by (safe intro!: tendsto_const tendsto_unique [OF assms tendsto_const])
huffman@44205
   613
huffman@44205
   614
subsubsection {* Distance and norms *}
huffman@36662
   615
huffman@31565
   616
lemma tendsto_dist [tendsto_intros]:
huffman@44195
   617
  assumes f: "(f ---> l) F" and g: "(g ---> m) F"
huffman@44195
   618
  shows "((\<lambda>x. dist (f x) (g x)) ---> dist l m) F"
huffman@31565
   619
proof (rule tendstoI)
huffman@31565
   620
  fix e :: real assume "0 < e"
huffman@31565
   621
  hence e2: "0 < e/2" by simp
huffman@31565
   622
  from tendstoD [OF f e2] tendstoD [OF g e2]
huffman@44195
   623
  show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) F"
huffman@31565
   624
  proof (rule eventually_elim2)
huffman@31565
   625
    fix x assume "dist (f x) l < e/2" "dist (g x) m < e/2"
huffman@31565
   626
    then show "dist (dist (f x) (g x)) (dist l m) < e"
huffman@31565
   627
      unfolding dist_real_def
huffman@31565
   628
      using dist_triangle2 [of "f x" "g x" "l"]
huffman@31565
   629
      using dist_triangle2 [of "g x" "l" "m"]
huffman@31565
   630
      using dist_triangle3 [of "l" "m" "f x"]
huffman@31565
   631
      using dist_triangle [of "f x" "m" "g x"]
huffman@31565
   632
      by arith
huffman@31565
   633
  qed
huffman@31565
   634
qed
huffman@31565
   635
huffman@36662
   636
lemma norm_conv_dist: "norm x = dist x 0"
huffman@44081
   637
  unfolding dist_norm by simp
huffman@36662
   638
huffman@31565
   639
lemma tendsto_norm [tendsto_intros]:
huffman@44195
   640
  "(f ---> a) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> norm a) F"
huffman@44081
   641
  unfolding norm_conv_dist by (intro tendsto_intros)
huffman@36662
   642
huffman@36662
   643
lemma tendsto_norm_zero:
huffman@44195
   644
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> 0) F"
huffman@44081
   645
  by (drule tendsto_norm, simp)
huffman@36662
   646
huffman@36662
   647
lemma tendsto_norm_zero_cancel:
huffman@44195
   648
  "((\<lambda>x. norm (f x)) ---> 0) F \<Longrightarrow> (f ---> 0) F"
huffman@44081
   649
  unfolding tendsto_iff dist_norm by simp
huffman@36662
   650
huffman@36662
   651
lemma tendsto_norm_zero_iff:
huffman@44195
   652
  "((\<lambda>x. norm (f x)) ---> 0) F \<longleftrightarrow> (f ---> 0) F"
huffman@44081
   653
  unfolding tendsto_iff dist_norm by simp
huffman@31349
   654
huffman@44194
   655
lemma tendsto_rabs [tendsto_intros]:
huffman@44195
   656
  "(f ---> (l::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> \<bar>l\<bar>) F"
huffman@44194
   657
  by (fold real_norm_def, rule tendsto_norm)
huffman@44194
   658
huffman@44194
   659
lemma tendsto_rabs_zero:
huffman@44195
   660
  "(f ---> (0::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> 0) F"
huffman@44194
   661
  by (fold real_norm_def, rule tendsto_norm_zero)
huffman@44194
   662
huffman@44194
   663
lemma tendsto_rabs_zero_cancel:
huffman@44195
   664
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<Longrightarrow> (f ---> 0) F"
huffman@44194
   665
  by (fold real_norm_def, rule tendsto_norm_zero_cancel)
huffman@44194
   666
huffman@44194
   667
lemma tendsto_rabs_zero_iff:
huffman@44195
   668
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<longleftrightarrow> (f ---> 0) F"
huffman@44194
   669
  by (fold real_norm_def, rule tendsto_norm_zero_iff)
huffman@44194
   670
huffman@44194
   671
subsubsection {* Addition and subtraction *}
huffman@44194
   672
huffman@31565
   673
lemma tendsto_add [tendsto_intros]:
huffman@31349
   674
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   675
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> a + b) F"
huffman@44081
   676
  by (simp only: tendsto_Zfun_iff add_diff_add Zfun_add)
huffman@31349
   677
huffman@44194
   678
lemma tendsto_add_zero:
huffman@44194
   679
  fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
huffman@44195
   680
  shows "\<lbrakk>(f ---> 0) F; (g ---> 0) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> 0) F"
huffman@44194
   681
  by (drule (1) tendsto_add, simp)
huffman@44194
   682
huffman@31565
   683
lemma tendsto_minus [tendsto_intros]:
huffman@31349
   684
  fixes a :: "'a::real_normed_vector"
huffman@44195
   685
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. - f x) ---> - a) F"
huffman@44081
   686
  by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
huffman@31349
   687
huffman@31349
   688
lemma tendsto_minus_cancel:
huffman@31349
   689
  fixes a :: "'a::real_normed_vector"
huffman@44195
   690
  shows "((\<lambda>x. - f x) ---> - a) F \<Longrightarrow> (f ---> a) F"
huffman@44081
   691
  by (drule tendsto_minus, simp)
huffman@31349
   692
huffman@31565
   693
lemma tendsto_diff [tendsto_intros]:
huffman@31349
   694
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   695
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x - g x) ---> a - b) F"
huffman@44081
   696
  by (simp add: diff_minus tendsto_add tendsto_minus)
huffman@31349
   697
huffman@31588
   698
lemma tendsto_setsum [tendsto_intros]:
huffman@31588
   699
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
huffman@44195
   700
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> a i) F"
huffman@44195
   701
  shows "((\<lambda>x. \<Sum>i\<in>S. f i x) ---> (\<Sum>i\<in>S. a i)) F"
huffman@31588
   702
proof (cases "finite S")
huffman@31588
   703
  assume "finite S" thus ?thesis using assms
huffman@44194
   704
    by (induct, simp add: tendsto_const, simp add: tendsto_add)
huffman@31588
   705
next
huffman@31588
   706
  assume "\<not> finite S" thus ?thesis
huffman@31588
   707
    by (simp add: tendsto_const)
huffman@31588
   708
qed
huffman@31588
   709
huffman@44194
   710
subsubsection {* Linear operators and multiplication *}
huffman@44194
   711
huffman@31565
   712
lemma (in bounded_linear) tendsto [tendsto_intros]:
huffman@44195
   713
  "(g ---> a) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> f a) F"
huffman@44081
   714
  by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
huffman@31349
   715
huffman@44194
   716
lemma (in bounded_linear) tendsto_zero:
huffman@44195
   717
  "(g ---> 0) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> 0) F"
huffman@44194
   718
  by (drule tendsto, simp only: zero)
huffman@44194
   719
huffman@31565
   720
lemma (in bounded_bilinear) tendsto [tendsto_intros]:
huffman@44195
   721
  "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ** g x) ---> a ** b) F"
huffman@44081
   722
  by (simp only: tendsto_Zfun_iff prod_diff_prod
huffman@44081
   723
                 Zfun_add Zfun Zfun_left Zfun_right)
huffman@31349
   724
huffman@44194
   725
lemma (in bounded_bilinear) tendsto_zero:
huffman@44195
   726
  assumes f: "(f ---> 0) F"
huffman@44195
   727
  assumes g: "(g ---> 0) F"
huffman@44195
   728
  shows "((\<lambda>x. f x ** g x) ---> 0) F"
huffman@44194
   729
  using tendsto [OF f g] by (simp add: zero_left)
huffman@31355
   730
huffman@44194
   731
lemma (in bounded_bilinear) tendsto_left_zero:
huffman@44195
   732
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. f x ** c) ---> 0) F"
huffman@44194
   733
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_left])
huffman@44194
   734
huffman@44194
   735
lemma (in bounded_bilinear) tendsto_right_zero:
huffman@44195
   736
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. c ** f x) ---> 0) F"
huffman@44194
   737
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_right])
huffman@44194
   738
huffman@44194
   739
lemmas tendsto_mult = mult.tendsto
huffman@44194
   740
huffman@44194
   741
lemma tendsto_power [tendsto_intros]:
huffman@44194
   742
  fixes f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra}"
huffman@44195
   743
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. f x ^ n) ---> a ^ n) F"
huffman@44194
   744
  by (induct n) (simp_all add: tendsto_const tendsto_mult)
huffman@44194
   745
huffman@44194
   746
lemma tendsto_setprod [tendsto_intros]:
huffman@44194
   747
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
huffman@44195
   748
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> L i) F"
huffman@44195
   749
  shows "((\<lambda>x. \<Prod>i\<in>S. f i x) ---> (\<Prod>i\<in>S. L i)) F"
huffman@44194
   750
proof (cases "finite S")
huffman@44194
   751
  assume "finite S" thus ?thesis using assms
huffman@44194
   752
    by (induct, simp add: tendsto_const, simp add: tendsto_mult)
huffman@44194
   753
next
huffman@44194
   754
  assume "\<not> finite S" thus ?thesis
huffman@44194
   755
    by (simp add: tendsto_const)
huffman@44194
   756
qed
huffman@44194
   757
huffman@44194
   758
subsubsection {* Inverse and division *}
huffman@31355
   759
huffman@31355
   760
lemma (in bounded_bilinear) Zfun_prod_Bfun:
huffman@44195
   761
  assumes f: "Zfun f F"
huffman@44195
   762
  assumes g: "Bfun g F"
huffman@44195
   763
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31355
   764
proof -
huffman@31355
   765
  obtain K where K: "0 \<le> K"
huffman@31355
   766
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31355
   767
    using nonneg_bounded by fast
huffman@31355
   768
  obtain B where B: "0 < B"
huffman@44195
   769
    and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) F"
huffman@31487
   770
    using g by (rule BfunE)
huffman@44195
   771
  have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) F"
huffman@31487
   772
  using norm_g proof (rule eventually_elim1)
huffman@31487
   773
    fix x
huffman@31487
   774
    assume *: "norm (g x) \<le> B"
huffman@31487
   775
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31355
   776
      by (rule norm_le)
huffman@31487
   777
    also have "\<dots> \<le> norm (f x) * B * K"
huffman@31487
   778
      by (intro mult_mono' order_refl norm_g norm_ge_zero
huffman@31355
   779
                mult_nonneg_nonneg K *)
huffman@31487
   780
    also have "\<dots> = norm (f x) * (B * K)"
huffman@31355
   781
      by (rule mult_assoc)
huffman@31487
   782
    finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
huffman@31355
   783
  qed
huffman@31487
   784
  with f show ?thesis
huffman@31487
   785
    by (rule Zfun_imp_Zfun)
huffman@31355
   786
qed
huffman@31355
   787
huffman@31355
   788
lemma (in bounded_bilinear) flip:
huffman@31355
   789
  "bounded_bilinear (\<lambda>x y. y ** x)"
huffman@44081
   790
  apply default
huffman@44081
   791
  apply (rule add_right)
huffman@44081
   792
  apply (rule add_left)
huffman@44081
   793
  apply (rule scaleR_right)
huffman@44081
   794
  apply (rule scaleR_left)
huffman@44081
   795
  apply (subst mult_commute)
huffman@44081
   796
  using bounded by fast
huffman@31355
   797
huffman@31355
   798
lemma (in bounded_bilinear) Bfun_prod_Zfun:
huffman@44195
   799
  assumes f: "Bfun f F"
huffman@44195
   800
  assumes g: "Zfun g F"
huffman@44195
   801
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@44081
   802
  using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
huffman@31355
   803
huffman@31355
   804
lemma Bfun_inverse_lemma:
huffman@31355
   805
  fixes x :: "'a::real_normed_div_algebra"
huffman@31355
   806
  shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
huffman@44081
   807
  apply (subst nonzero_norm_inverse, clarsimp)
huffman@44081
   808
  apply (erule (1) le_imp_inverse_le)
huffman@44081
   809
  done
huffman@31355
   810
huffman@31355
   811
lemma Bfun_inverse:
huffman@31355
   812
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
   813
  assumes f: "(f ---> a) F"
huffman@31355
   814
  assumes a: "a \<noteq> 0"
huffman@44195
   815
  shows "Bfun (\<lambda>x. inverse (f x)) F"
huffman@31355
   816
proof -
huffman@31355
   817
  from a have "0 < norm a" by simp
huffman@31355
   818
  hence "\<exists>r>0. r < norm a" by (rule dense)
huffman@31355
   819
  then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
huffman@44195
   820
  have "eventually (\<lambda>x. dist (f x) a < r) F"
huffman@31487
   821
    using tendstoD [OF f r1] by fast
huffman@44195
   822
  hence "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) F"
huffman@31355
   823
  proof (rule eventually_elim1)
huffman@31487
   824
    fix x
huffman@31487
   825
    assume "dist (f x) a < r"
huffman@31487
   826
    hence 1: "norm (f x - a) < r"
huffman@31355
   827
      by (simp add: dist_norm)
huffman@31487
   828
    hence 2: "f x \<noteq> 0" using r2 by auto
huffman@31487
   829
    hence "norm (inverse (f x)) = inverse (norm (f x))"
huffman@31355
   830
      by (rule nonzero_norm_inverse)
huffman@31355
   831
    also have "\<dots> \<le> inverse (norm a - r)"
huffman@31355
   832
    proof (rule le_imp_inverse_le)
huffman@31355
   833
      show "0 < norm a - r" using r2 by simp
huffman@31355
   834
    next
huffman@31487
   835
      have "norm a - norm (f x) \<le> norm (a - f x)"
huffman@31355
   836
        by (rule norm_triangle_ineq2)
huffman@31487
   837
      also have "\<dots> = norm (f x - a)"
huffman@31355
   838
        by (rule norm_minus_commute)
huffman@31355
   839
      also have "\<dots> < r" using 1 .
huffman@31487
   840
      finally show "norm a - r \<le> norm (f x)" by simp
huffman@31355
   841
    qed
huffman@31487
   842
    finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
huffman@31355
   843
  qed
huffman@31355
   844
  thus ?thesis by (rule BfunI)
huffman@31355
   845
qed
huffman@31355
   846
huffman@31355
   847
lemma tendsto_inverse_lemma:
huffman@31355
   848
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
   849
  shows "\<lbrakk>(f ---> a) F; a \<noteq> 0; eventually (\<lambda>x. f x \<noteq> 0) F\<rbrakk>
huffman@44195
   850
         \<Longrightarrow> ((\<lambda>x. inverse (f x)) ---> inverse a) F"
huffman@44081
   851
  apply (subst tendsto_Zfun_iff)
huffman@44081
   852
  apply (rule Zfun_ssubst)
huffman@44081
   853
  apply (erule eventually_elim1)
huffman@44081
   854
  apply (erule (1) inverse_diff_inverse)
huffman@44081
   855
  apply (rule Zfun_minus)
huffman@44081
   856
  apply (rule Zfun_mult_left)
huffman@44081
   857
  apply (rule mult.Bfun_prod_Zfun)
huffman@44081
   858
  apply (erule (1) Bfun_inverse)
huffman@44081
   859
  apply (simp add: tendsto_Zfun_iff)
huffman@44081
   860
  done
huffman@31355
   861
huffman@31565
   862
lemma tendsto_inverse [tendsto_intros]:
huffman@31355
   863
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
   864
  assumes f: "(f ---> a) F"
huffman@31355
   865
  assumes a: "a \<noteq> 0"
huffman@44195
   866
  shows "((\<lambda>x. inverse (f x)) ---> inverse a) F"
huffman@31355
   867
proof -
huffman@31355
   868
  from a have "0 < norm a" by simp
huffman@44195
   869
  with f have "eventually (\<lambda>x. dist (f x) a < norm a) F"
huffman@31355
   870
    by (rule tendstoD)
huffman@44195
   871
  then have "eventually (\<lambda>x. f x \<noteq> 0) F"
huffman@31355
   872
    unfolding dist_norm by (auto elim!: eventually_elim1)
huffman@31487
   873
  with f a show ?thesis
huffman@31355
   874
    by (rule tendsto_inverse_lemma)
huffman@31355
   875
qed
huffman@31355
   876
huffman@31565
   877
lemma tendsto_divide [tendsto_intros]:
huffman@31355
   878
  fixes a b :: "'a::real_normed_field"
huffman@44195
   879
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F; b \<noteq> 0\<rbrakk>
huffman@44195
   880
    \<Longrightarrow> ((\<lambda>x. f x / g x) ---> a / b) F"
huffman@44081
   881
  by (simp add: mult.tendsto tendsto_inverse divide_inverse)
huffman@31355
   882
huffman@44194
   883
lemma tendsto_sgn [tendsto_intros]:
huffman@44194
   884
  fixes l :: "'a::real_normed_vector"
huffman@44195
   885
  shows "\<lbrakk>(f ---> l) F; l \<noteq> 0\<rbrakk> \<Longrightarrow> ((\<lambda>x. sgn (f x)) ---> sgn l) F"
huffman@44194
   886
  unfolding sgn_div_norm by (simp add: tendsto_intros)
huffman@44194
   887
huffman@31349
   888
end