src/HOL/Limits.thy
author bulwahn
Fri Oct 21 11:17:14 2011 +0200 (2011-10-21)
changeset 45231 d85a2fdc586c
parent 45031 9583f2b56f85
child 45294 3c5d3d286055
permissions -rw-r--r--
replacing code_inline by code_unfold, removing obsolete code_unfold, code_inline del now that the ancient code generator is removed
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@44342
   219
abbreviation (input) trivial_limit :: "'a filter \<Rightarrow> bool"
huffman@44342
   220
  where "trivial_limit F \<equiv> F = bot"
huffman@44342
   221
huffman@44342
   222
lemma trivial_limit_def: "trivial_limit F \<longleftrightarrow> eventually (\<lambda>x. False) F"
huffman@44342
   223
  by (rule eventually_False [symmetric])
huffman@44342
   224
huffman@44342
   225
huffman@44081
   226
subsection {* Map function for filters *}
huffman@36654
   227
huffman@44081
   228
definition filtermap :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a filter \<Rightarrow> 'b filter"
huffman@44195
   229
  where "filtermap f F = Abs_filter (\<lambda>P. eventually (\<lambda>x. P (f x)) F)"
huffman@36654
   230
huffman@44081
   231
lemma eventually_filtermap:
huffman@44195
   232
  "eventually P (filtermap f F) = eventually (\<lambda>x. P (f x)) F"
huffman@44081
   233
  unfolding filtermap_def
huffman@44081
   234
  apply (rule eventually_Abs_filter)
huffman@44081
   235
  apply (rule is_filter.intro)
huffman@44081
   236
  apply (auto elim!: eventually_rev_mp)
huffman@44081
   237
  done
huffman@36654
   238
huffman@44195
   239
lemma filtermap_ident: "filtermap (\<lambda>x. x) F = F"
huffman@44081
   240
  by (simp add: filter_eq_iff eventually_filtermap)
huffman@36654
   241
huffman@44081
   242
lemma filtermap_filtermap:
huffman@44195
   243
  "filtermap f (filtermap g F) = filtermap (\<lambda>x. f (g x)) F"
huffman@44081
   244
  by (simp add: filter_eq_iff eventually_filtermap)
huffman@36654
   245
huffman@44195
   246
lemma filtermap_mono: "F \<le> F' \<Longrightarrow> filtermap f F \<le> filtermap f F'"
huffman@44081
   247
  unfolding le_filter_def eventually_filtermap by simp
huffman@44081
   248
huffman@44081
   249
lemma filtermap_bot [simp]: "filtermap f bot = bot"
huffman@44081
   250
  by (simp add: filter_eq_iff eventually_filtermap)
huffman@36654
   251
huffman@36654
   252
huffman@36662
   253
subsection {* Sequentially *}
huffman@31392
   254
huffman@44081
   255
definition sequentially :: "nat filter"
huffman@44081
   256
  where "sequentially = Abs_filter (\<lambda>P. \<exists>k. \<forall>n\<ge>k. P n)"
huffman@31392
   257
huffman@36662
   258
lemma eventually_sequentially:
huffman@36662
   259
  "eventually P sequentially \<longleftrightarrow> (\<exists>N. \<forall>n\<ge>N. P n)"
huffman@36662
   260
unfolding sequentially_def
huffman@44081
   261
proof (rule eventually_Abs_filter, rule is_filter.intro)
huffman@36662
   262
  fix P Q :: "nat \<Rightarrow> bool"
huffman@36662
   263
  assume "\<exists>i. \<forall>n\<ge>i. P n" and "\<exists>j. \<forall>n\<ge>j. Q n"
huffman@36662
   264
  then obtain i j where "\<forall>n\<ge>i. P n" and "\<forall>n\<ge>j. Q n" by auto
huffman@36662
   265
  then have "\<forall>n\<ge>max i j. P n \<and> Q n" by simp
huffman@36662
   266
  then show "\<exists>k. \<forall>n\<ge>k. P n \<and> Q n" ..
huffman@36662
   267
qed auto
huffman@36662
   268
huffman@44342
   269
lemma sequentially_bot [simp, intro]: "sequentially \<noteq> bot"
huffman@44081
   270
  unfolding filter_eq_iff eventually_sequentially by auto
huffman@36662
   271
huffman@44342
   272
lemmas trivial_limit_sequentially = sequentially_bot
huffman@44342
   273
huffman@36662
   274
lemma eventually_False_sequentially [simp]:
huffman@36662
   275
  "\<not> eventually (\<lambda>n. False) sequentially"
huffman@44081
   276
  by (simp add: eventually_False)
huffman@36662
   277
huffman@36662
   278
lemma le_sequentially:
huffman@44195
   279
  "F \<le> sequentially \<longleftrightarrow> (\<forall>N. eventually (\<lambda>n. N \<le> n) F)"
huffman@44081
   280
  unfolding le_filter_def eventually_sequentially
huffman@44081
   281
  by (safe, fast, drule_tac x=N in spec, auto elim: eventually_rev_mp)
huffman@36662
   282
huffman@36662
   283
huffman@44081
   284
subsection {* Standard filters *}
huffman@36662
   285
huffman@44081
   286
definition within :: "'a filter \<Rightarrow> 'a set \<Rightarrow> 'a filter" (infixr "within" 70)
huffman@44195
   287
  where "F within S = Abs_filter (\<lambda>P. eventually (\<lambda>x. x \<in> S \<longrightarrow> P x) F)"
huffman@31392
   288
huffman@44206
   289
definition (in topological_space) nhds :: "'a \<Rightarrow> 'a filter"
huffman@44081
   290
  where "nhds a = Abs_filter (\<lambda>P. \<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
huffman@36654
   291
huffman@44206
   292
definition (in topological_space) at :: "'a \<Rightarrow> 'a filter"
huffman@44081
   293
  where "at a = nhds a within - {a}"
huffman@31447
   294
huffman@31392
   295
lemma eventually_within:
huffman@44195
   296
  "eventually P (F within S) = eventually (\<lambda>x. x \<in> S \<longrightarrow> P x) F"
huffman@44081
   297
  unfolding within_def
huffman@44081
   298
  by (rule eventually_Abs_filter, rule is_filter.intro)
huffman@44081
   299
     (auto elim!: eventually_rev_mp)
huffman@31392
   300
huffman@45031
   301
lemma within_UNIV [simp]: "F within UNIV = F"
huffman@45031
   302
  unfolding filter_eq_iff eventually_within by simp
huffman@45031
   303
huffman@45031
   304
lemma within_empty [simp]: "F within {} = bot"
huffman@44081
   305
  unfolding filter_eq_iff eventually_within by simp
huffman@36360
   306
huffman@36654
   307
lemma eventually_nhds:
huffman@36654
   308
  "eventually P (nhds a) \<longleftrightarrow> (\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x))"
huffman@36654
   309
unfolding nhds_def
huffman@44081
   310
proof (rule eventually_Abs_filter, rule is_filter.intro)
huffman@36654
   311
  have "open UNIV \<and> a \<in> UNIV \<and> (\<forall>x\<in>UNIV. True)" by simp
huffman@36654
   312
  thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. True)" by - rule
huffman@36358
   313
next
huffman@36358
   314
  fix P Q
huffman@36654
   315
  assume "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
huffman@36654
   316
     and "\<exists>T. open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)"
huffman@36358
   317
  then obtain S T where
huffman@36654
   318
    "open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x)"
huffman@36654
   319
    "open T \<and> a \<in> T \<and> (\<forall>x\<in>T. Q x)" by auto
huffman@36654
   320
  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
   321
    by (simp add: open_Int)
huffman@36654
   322
  thus "\<exists>S. open S \<and> a \<in> S \<and> (\<forall>x\<in>S. P x \<and> Q x)" by - rule
huffman@36358
   323
qed auto
huffman@31447
   324
huffman@36656
   325
lemma eventually_nhds_metric:
huffman@36656
   326
  "eventually P (nhds a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. dist x a < d \<longrightarrow> P x)"
huffman@36656
   327
unfolding eventually_nhds open_dist
huffman@31447
   328
apply safe
huffman@31447
   329
apply fast
huffman@31492
   330
apply (rule_tac x="{x. dist x a < d}" in exI, simp)
huffman@31447
   331
apply clarsimp
huffman@31447
   332
apply (rule_tac x="d - dist x a" in exI, clarsimp)
huffman@31447
   333
apply (simp only: less_diff_eq)
huffman@31447
   334
apply (erule le_less_trans [OF dist_triangle])
huffman@31447
   335
done
huffman@31447
   336
huffman@44571
   337
lemma nhds_neq_bot [simp]: "nhds a \<noteq> bot"
huffman@44571
   338
  unfolding trivial_limit_def eventually_nhds by simp
huffman@44571
   339
huffman@36656
   340
lemma eventually_at_topological:
huffman@36656
   341
  "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
   342
unfolding at_def eventually_within eventually_nhds by simp
huffman@36656
   343
huffman@36656
   344
lemma eventually_at:
huffman@36656
   345
  fixes a :: "'a::metric_space"
huffman@36656
   346
  shows "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> P x)"
huffman@36656
   347
unfolding at_def eventually_within eventually_nhds_metric by auto
huffman@36656
   348
huffman@44571
   349
lemma at_eq_bot_iff: "at a = bot \<longleftrightarrow> open {a}"
huffman@44571
   350
  unfolding trivial_limit_def eventually_at_topological
huffman@44571
   351
  by (safe, case_tac "S = {a}", simp, fast, fast)
huffman@44571
   352
huffman@44571
   353
lemma at_neq_bot [simp]: "at (a::'a::perfect_space) \<noteq> bot"
huffman@44571
   354
  by (simp add: at_eq_bot_iff not_open_singleton)
huffman@44571
   355
huffman@31392
   356
huffman@31355
   357
subsection {* Boundedness *}
huffman@31355
   358
huffman@44081
   359
definition Bfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
   360
  where "Bfun f F = (\<exists>K>0. eventually (\<lambda>x. norm (f x) \<le> K) F)"
huffman@31355
   361
huffman@31487
   362
lemma BfunI:
huffman@44195
   363
  assumes K: "eventually (\<lambda>x. norm (f x) \<le> K) F" shows "Bfun f F"
huffman@31355
   364
unfolding Bfun_def
huffman@31355
   365
proof (intro exI conjI allI)
huffman@31355
   366
  show "0 < max K 1" by simp
huffman@31355
   367
next
huffman@44195
   368
  show "eventually (\<lambda>x. norm (f x) \<le> max K 1) F"
huffman@31355
   369
    using K by (rule eventually_elim1, simp)
huffman@31355
   370
qed
huffman@31355
   371
huffman@31355
   372
lemma BfunE:
huffman@44195
   373
  assumes "Bfun f F"
huffman@44195
   374
  obtains B where "0 < B" and "eventually (\<lambda>x. norm (f x) \<le> B) F"
huffman@31355
   375
using assms unfolding Bfun_def by fast
huffman@31355
   376
huffman@31355
   377
huffman@31349
   378
subsection {* Convergence to Zero *}
huffman@31349
   379
huffman@44081
   380
definition Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool"
huffman@44195
   381
  where "Zfun f F = (\<forall>r>0. eventually (\<lambda>x. norm (f x) < r) F)"
huffman@31349
   382
huffman@31349
   383
lemma ZfunI:
huffman@44195
   384
  "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F) \<Longrightarrow> Zfun f F"
huffman@44081
   385
  unfolding Zfun_def by simp
huffman@31349
   386
huffman@31349
   387
lemma ZfunD:
huffman@44195
   388
  "\<lbrakk>Zfun f F; 0 < r\<rbrakk> \<Longrightarrow> eventually (\<lambda>x. norm (f x) < r) F"
huffman@44081
   389
  unfolding Zfun_def by simp
huffman@31349
   390
huffman@31355
   391
lemma Zfun_ssubst:
huffman@44195
   392
  "eventually (\<lambda>x. f x = g x) F \<Longrightarrow> Zfun g F \<Longrightarrow> Zfun f F"
huffman@44081
   393
  unfolding Zfun_def by (auto elim!: eventually_rev_mp)
huffman@31355
   394
huffman@44195
   395
lemma Zfun_zero: "Zfun (\<lambda>x. 0) F"
huffman@44081
   396
  unfolding Zfun_def by simp
huffman@31349
   397
huffman@44195
   398
lemma Zfun_norm_iff: "Zfun (\<lambda>x. norm (f x)) F = Zfun (\<lambda>x. f x) F"
huffman@44081
   399
  unfolding Zfun_def by simp
huffman@31349
   400
huffman@31349
   401
lemma Zfun_imp_Zfun:
huffman@44195
   402
  assumes f: "Zfun f F"
huffman@44195
   403
  assumes g: "eventually (\<lambda>x. norm (g x) \<le> norm (f x) * K) F"
huffman@44195
   404
  shows "Zfun (\<lambda>x. g x) F"
huffman@31349
   405
proof (cases)
huffman@31349
   406
  assume K: "0 < K"
huffman@31349
   407
  show ?thesis
huffman@31349
   408
  proof (rule ZfunI)
huffman@31349
   409
    fix r::real assume "0 < r"
huffman@31349
   410
    hence "0 < r / K"
huffman@31349
   411
      using K by (rule divide_pos_pos)
huffman@44195
   412
    then have "eventually (\<lambda>x. norm (f x) < r / K) F"
huffman@31487
   413
      using ZfunD [OF f] by fast
huffman@44195
   414
    with g show "eventually (\<lambda>x. norm (g x) < r) F"
huffman@31355
   415
    proof (rule eventually_elim2)
huffman@31487
   416
      fix x
huffman@31487
   417
      assume *: "norm (g x) \<le> norm (f x) * K"
huffman@31487
   418
      assume "norm (f x) < r / K"
huffman@31487
   419
      hence "norm (f x) * K < r"
huffman@31349
   420
        by (simp add: pos_less_divide_eq K)
huffman@31487
   421
      thus "norm (g x) < r"
huffman@31355
   422
        by (simp add: order_le_less_trans [OF *])
huffman@31349
   423
    qed
huffman@31349
   424
  qed
huffman@31349
   425
next
huffman@31349
   426
  assume "\<not> 0 < K"
huffman@31349
   427
  hence K: "K \<le> 0" by (simp only: not_less)
huffman@31355
   428
  show ?thesis
huffman@31355
   429
  proof (rule ZfunI)
huffman@31355
   430
    fix r :: real
huffman@31355
   431
    assume "0 < r"
huffman@44195
   432
    from g show "eventually (\<lambda>x. norm (g x) < r) F"
huffman@31355
   433
    proof (rule eventually_elim1)
huffman@31487
   434
      fix x
huffman@31487
   435
      assume "norm (g x) \<le> norm (f x) * K"
huffman@31487
   436
      also have "\<dots> \<le> norm (f x) * 0"
huffman@31355
   437
        using K norm_ge_zero by (rule mult_left_mono)
huffman@31487
   438
      finally show "norm (g x) < r"
huffman@31355
   439
        using `0 < r` by simp
huffman@31355
   440
    qed
huffman@31355
   441
  qed
huffman@31349
   442
qed
huffman@31349
   443
huffman@44195
   444
lemma Zfun_le: "\<lbrakk>Zfun g F; \<forall>x. norm (f x) \<le> norm (g x)\<rbrakk> \<Longrightarrow> Zfun f F"
huffman@44081
   445
  by (erule_tac K="1" in Zfun_imp_Zfun, simp)
huffman@31349
   446
huffman@31349
   447
lemma Zfun_add:
huffman@44195
   448
  assumes f: "Zfun f F" and g: "Zfun g F"
huffman@44195
   449
  shows "Zfun (\<lambda>x. f x + g x) F"
huffman@31349
   450
proof (rule ZfunI)
huffman@31349
   451
  fix r::real assume "0 < r"
huffman@31349
   452
  hence r: "0 < r / 2" by simp
huffman@44195
   453
  have "eventually (\<lambda>x. norm (f x) < r/2) F"
huffman@31487
   454
    using f r by (rule ZfunD)
huffman@31349
   455
  moreover
huffman@44195
   456
  have "eventually (\<lambda>x. norm (g x) < r/2) F"
huffman@31487
   457
    using g r by (rule ZfunD)
huffman@31349
   458
  ultimately
huffman@44195
   459
  show "eventually (\<lambda>x. norm (f x + g x) < r) F"
huffman@31349
   460
  proof (rule eventually_elim2)
huffman@31487
   461
    fix x
huffman@31487
   462
    assume *: "norm (f x) < r/2" "norm (g x) < r/2"
huffman@31487
   463
    have "norm (f x + g x) \<le> norm (f x) + norm (g x)"
huffman@31349
   464
      by (rule norm_triangle_ineq)
huffman@31349
   465
    also have "\<dots> < r/2 + r/2"
huffman@31349
   466
      using * by (rule add_strict_mono)
huffman@31487
   467
    finally show "norm (f x + g x) < r"
huffman@31349
   468
      by simp
huffman@31349
   469
  qed
huffman@31349
   470
qed
huffman@31349
   471
huffman@44195
   472
lemma Zfun_minus: "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. - f x) F"
huffman@44081
   473
  unfolding Zfun_def by simp
huffman@31349
   474
huffman@44195
   475
lemma Zfun_diff: "\<lbrakk>Zfun f F; Zfun g F\<rbrakk> \<Longrightarrow> Zfun (\<lambda>x. f x - g x) F"
huffman@44081
   476
  by (simp only: diff_minus Zfun_add Zfun_minus)
huffman@31349
   477
huffman@31349
   478
lemma (in bounded_linear) Zfun:
huffman@44195
   479
  assumes g: "Zfun g F"
huffman@44195
   480
  shows "Zfun (\<lambda>x. f (g x)) F"
huffman@31349
   481
proof -
huffman@31349
   482
  obtain K where "\<And>x. norm (f x) \<le> norm x * K"
huffman@31349
   483
    using bounded by fast
huffman@44195
   484
  then have "eventually (\<lambda>x. norm (f (g x)) \<le> norm (g x) * K) F"
huffman@31355
   485
    by simp
huffman@31487
   486
  with g show ?thesis
huffman@31349
   487
    by (rule Zfun_imp_Zfun)
huffman@31349
   488
qed
huffman@31349
   489
huffman@31349
   490
lemma (in bounded_bilinear) Zfun:
huffman@44195
   491
  assumes f: "Zfun f F"
huffman@44195
   492
  assumes g: "Zfun g F"
huffman@44195
   493
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31349
   494
proof (rule ZfunI)
huffman@31349
   495
  fix r::real assume r: "0 < r"
huffman@31349
   496
  obtain K where K: "0 < K"
huffman@31349
   497
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31349
   498
    using pos_bounded by fast
huffman@31349
   499
  from K have K': "0 < inverse K"
huffman@31349
   500
    by (rule positive_imp_inverse_positive)
huffman@44195
   501
  have "eventually (\<lambda>x. norm (f x) < r) F"
huffman@31487
   502
    using f r by (rule ZfunD)
huffman@31349
   503
  moreover
huffman@44195
   504
  have "eventually (\<lambda>x. norm (g x) < inverse K) F"
huffman@31487
   505
    using g K' by (rule ZfunD)
huffman@31349
   506
  ultimately
huffman@44195
   507
  show "eventually (\<lambda>x. norm (f x ** g x) < r) F"
huffman@31349
   508
  proof (rule eventually_elim2)
huffman@31487
   509
    fix x
huffman@31487
   510
    assume *: "norm (f x) < r" "norm (g x) < inverse K"
huffman@31487
   511
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31349
   512
      by (rule norm_le)
huffman@31487
   513
    also have "norm (f x) * norm (g x) * K < r * inverse K * K"
huffman@31349
   514
      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero * K)
huffman@31349
   515
    also from K have "r * inverse K * K = r"
huffman@31349
   516
      by simp
huffman@31487
   517
    finally show "norm (f x ** g x) < r" .
huffman@31349
   518
  qed
huffman@31349
   519
qed
huffman@31349
   520
huffman@31349
   521
lemma (in bounded_bilinear) Zfun_left:
huffman@44195
   522
  "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. f x ** a) F"
huffman@44081
   523
  by (rule bounded_linear_left [THEN bounded_linear.Zfun])
huffman@31349
   524
huffman@31349
   525
lemma (in bounded_bilinear) Zfun_right:
huffman@44195
   526
  "Zfun f F \<Longrightarrow> Zfun (\<lambda>x. a ** f x) F"
huffman@44081
   527
  by (rule bounded_linear_right [THEN bounded_linear.Zfun])
huffman@31349
   528
huffman@44282
   529
lemmas Zfun_mult = bounded_bilinear.Zfun [OF bounded_bilinear_mult]
huffman@44282
   530
lemmas Zfun_mult_right = bounded_bilinear.Zfun_right [OF bounded_bilinear_mult]
huffman@44282
   531
lemmas Zfun_mult_left = bounded_bilinear.Zfun_left [OF bounded_bilinear_mult]
huffman@31349
   532
huffman@31349
   533
wenzelm@31902
   534
subsection {* Limits *}
huffman@31349
   535
huffman@44206
   536
definition (in topological_space)
huffman@44206
   537
  tendsto :: "('b \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'b filter \<Rightarrow> bool" (infixr "--->" 55) where
huffman@44195
   538
  "(f ---> l) F \<longleftrightarrow> (\<forall>S. open S \<longrightarrow> l \<in> S \<longrightarrow> eventually (\<lambda>x. f x \<in> S) F)"
huffman@31349
   539
wenzelm@31902
   540
ML {*
wenzelm@31902
   541
structure Tendsto_Intros = Named_Thms
wenzelm@31902
   542
(
wenzelm@31902
   543
  val name = "tendsto_intros"
wenzelm@31902
   544
  val description = "introduction rules for tendsto"
wenzelm@31902
   545
)
huffman@31565
   546
*}
huffman@31565
   547
wenzelm@31902
   548
setup Tendsto_Intros.setup
huffman@31565
   549
huffman@44195
   550
lemma tendsto_mono: "F \<le> F' \<Longrightarrow> (f ---> l) F' \<Longrightarrow> (f ---> l) F"
huffman@44081
   551
  unfolding tendsto_def le_filter_def by fast
huffman@36656
   552
huffman@31488
   553
lemma topological_tendstoI:
huffman@44195
   554
  "(\<And>S. open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F)
huffman@44195
   555
    \<Longrightarrow> (f ---> l) F"
huffman@31349
   556
  unfolding tendsto_def by auto
huffman@31349
   557
huffman@31488
   558
lemma topological_tendstoD:
huffman@44195
   559
  "(f ---> l) F \<Longrightarrow> open S \<Longrightarrow> l \<in> S \<Longrightarrow> eventually (\<lambda>x. f x \<in> S) F"
huffman@31488
   560
  unfolding tendsto_def by auto
huffman@31488
   561
huffman@31488
   562
lemma tendstoI:
huffman@44195
   563
  assumes "\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
huffman@44195
   564
  shows "(f ---> l) F"
huffman@44081
   565
  apply (rule topological_tendstoI)
huffman@44081
   566
  apply (simp add: open_dist)
huffman@44081
   567
  apply (drule (1) bspec, clarify)
huffman@44081
   568
  apply (drule assms)
huffman@44081
   569
  apply (erule eventually_elim1, simp)
huffman@44081
   570
  done
huffman@31488
   571
huffman@31349
   572
lemma tendstoD:
huffman@44195
   573
  "(f ---> l) F \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) F"
huffman@44081
   574
  apply (drule_tac S="{x. dist x l < e}" in topological_tendstoD)
huffman@44081
   575
  apply (clarsimp simp add: open_dist)
huffman@44081
   576
  apply (rule_tac x="e - dist x l" in exI, clarsimp)
huffman@44081
   577
  apply (simp only: less_diff_eq)
huffman@44081
   578
  apply (erule le_less_trans [OF dist_triangle])
huffman@44081
   579
  apply simp
huffman@44081
   580
  apply simp
huffman@44081
   581
  done
huffman@31488
   582
huffman@31488
   583
lemma tendsto_iff:
huffman@44195
   584
  "(f ---> l) F \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) F)"
huffman@44081
   585
  using tendstoI tendstoD by fast
huffman@31349
   586
huffman@44195
   587
lemma tendsto_Zfun_iff: "(f ---> a) F = Zfun (\<lambda>x. f x - a) F"
huffman@44081
   588
  by (simp only: tendsto_iff Zfun_def dist_norm)
huffman@31349
   589
huffman@45031
   590
lemma tendsto_bot [simp]: "(f ---> a) bot"
huffman@45031
   591
  unfolding tendsto_def by simp
huffman@45031
   592
huffman@31565
   593
lemma tendsto_ident_at [tendsto_intros]: "((\<lambda>x. x) ---> a) (at a)"
huffman@44081
   594
  unfolding tendsto_def eventually_at_topological by auto
huffman@31565
   595
huffman@31565
   596
lemma tendsto_ident_at_within [tendsto_intros]:
huffman@36655
   597
  "((\<lambda>x. x) ---> a) (at a within S)"
huffman@44081
   598
  unfolding tendsto_def eventually_within eventually_at_topological by auto
huffman@31565
   599
huffman@44195
   600
lemma tendsto_const [tendsto_intros]: "((\<lambda>x. k) ---> k) F"
huffman@44081
   601
  by (simp add: tendsto_def)
huffman@31349
   602
huffman@44205
   603
lemma tendsto_unique:
huffman@44205
   604
  fixes f :: "'a \<Rightarrow> 'b::t2_space"
huffman@44205
   605
  assumes "\<not> trivial_limit F" and "(f ---> a) F" and "(f ---> b) F"
huffman@44205
   606
  shows "a = b"
huffman@44205
   607
proof (rule ccontr)
huffman@44205
   608
  assume "a \<noteq> b"
huffman@44205
   609
  obtain U V where "open U" "open V" "a \<in> U" "b \<in> V" "U \<inter> V = {}"
huffman@44205
   610
    using hausdorff [OF `a \<noteq> b`] by fast
huffman@44205
   611
  have "eventually (\<lambda>x. f x \<in> U) F"
huffman@44205
   612
    using `(f ---> a) F` `open U` `a \<in> U` by (rule topological_tendstoD)
huffman@44205
   613
  moreover
huffman@44205
   614
  have "eventually (\<lambda>x. f x \<in> V) F"
huffman@44205
   615
    using `(f ---> b) F` `open V` `b \<in> V` by (rule topological_tendstoD)
huffman@44205
   616
  ultimately
huffman@44205
   617
  have "eventually (\<lambda>x. False) F"
huffman@44205
   618
  proof (rule eventually_elim2)
huffman@44205
   619
    fix x
huffman@44205
   620
    assume "f x \<in> U" "f x \<in> V"
huffman@44205
   621
    hence "f x \<in> U \<inter> V" by simp
huffman@44205
   622
    with `U \<inter> V = {}` show "False" by simp
huffman@44205
   623
  qed
huffman@44205
   624
  with `\<not> trivial_limit F` show "False"
huffman@44205
   625
    by (simp add: trivial_limit_def)
huffman@44205
   626
qed
huffman@44205
   627
huffman@36662
   628
lemma tendsto_const_iff:
huffman@44205
   629
  fixes a b :: "'a::t2_space"
huffman@44205
   630
  assumes "\<not> trivial_limit F" shows "((\<lambda>x. a) ---> b) F \<longleftrightarrow> a = b"
huffman@44205
   631
  by (safe intro!: tendsto_const tendsto_unique [OF assms tendsto_const])
huffman@44205
   632
huffman@44218
   633
lemma tendsto_compose:
huffman@44218
   634
  assumes g: "(g ---> g l) (at l)"
huffman@44218
   635
  assumes f: "(f ---> l) F"
huffman@44218
   636
  shows "((\<lambda>x. g (f x)) ---> g l) F"
huffman@44218
   637
proof (rule topological_tendstoI)
huffman@44218
   638
  fix B assume B: "open B" "g l \<in> B"
huffman@44218
   639
  obtain A where A: "open A" "l \<in> A"
huffman@44218
   640
    and gB: "\<forall>y. y \<in> A \<longrightarrow> g y \<in> B"
huffman@44218
   641
    using topological_tendstoD [OF g B] B(2)
huffman@44218
   642
    unfolding eventually_at_topological by fast
huffman@44218
   643
  hence "\<forall>x. f x \<in> A \<longrightarrow> g (f x) \<in> B" by simp
huffman@44218
   644
  from this topological_tendstoD [OF f A]
huffman@44218
   645
  show "eventually (\<lambda>x. g (f x) \<in> B) F"
huffman@44218
   646
    by (rule eventually_mono)
huffman@44218
   647
qed
huffman@44218
   648
huffman@44253
   649
lemma tendsto_compose_eventually:
huffman@44253
   650
  assumes g: "(g ---> m) (at l)"
huffman@44253
   651
  assumes f: "(f ---> l) F"
huffman@44253
   652
  assumes inj: "eventually (\<lambda>x. f x \<noteq> l) F"
huffman@44253
   653
  shows "((\<lambda>x. g (f x)) ---> m) F"
huffman@44253
   654
proof (rule topological_tendstoI)
huffman@44253
   655
  fix B assume B: "open B" "m \<in> B"
huffman@44253
   656
  obtain A where A: "open A" "l \<in> A"
huffman@44253
   657
    and gB: "\<And>y. y \<in> A \<Longrightarrow> y \<noteq> l \<Longrightarrow> g y \<in> B"
huffman@44253
   658
    using topological_tendstoD [OF g B]
huffman@44253
   659
    unfolding eventually_at_topological by fast
huffman@44253
   660
  show "eventually (\<lambda>x. g (f x) \<in> B) F"
huffman@44253
   661
    using topological_tendstoD [OF f A] inj
huffman@44253
   662
    by (rule eventually_elim2) (simp add: gB)
huffman@44253
   663
qed
huffman@44253
   664
huffman@44251
   665
lemma metric_tendsto_imp_tendsto:
huffman@44251
   666
  assumes f: "(f ---> a) F"
huffman@44251
   667
  assumes le: "eventually (\<lambda>x. dist (g x) b \<le> dist (f x) a) F"
huffman@44251
   668
  shows "(g ---> b) F"
huffman@44251
   669
proof (rule tendstoI)
huffman@44251
   670
  fix e :: real assume "0 < e"
huffman@44251
   671
  with f have "eventually (\<lambda>x. dist (f x) a < e) F" by (rule tendstoD)
huffman@44251
   672
  with le show "eventually (\<lambda>x. dist (g x) b < e) F"
huffman@44251
   673
    using le_less_trans by (rule eventually_elim2)
huffman@44251
   674
qed
huffman@44251
   675
huffman@44205
   676
subsubsection {* Distance and norms *}
huffman@36662
   677
huffman@31565
   678
lemma tendsto_dist [tendsto_intros]:
huffman@44195
   679
  assumes f: "(f ---> l) F" and g: "(g ---> m) F"
huffman@44195
   680
  shows "((\<lambda>x. dist (f x) (g x)) ---> dist l m) F"
huffman@31565
   681
proof (rule tendstoI)
huffman@31565
   682
  fix e :: real assume "0 < e"
huffman@31565
   683
  hence e2: "0 < e/2" by simp
huffman@31565
   684
  from tendstoD [OF f e2] tendstoD [OF g e2]
huffman@44195
   685
  show "eventually (\<lambda>x. dist (dist (f x) (g x)) (dist l m) < e) F"
huffman@31565
   686
  proof (rule eventually_elim2)
huffman@31565
   687
    fix x assume "dist (f x) l < e/2" "dist (g x) m < e/2"
huffman@31565
   688
    then show "dist (dist (f x) (g x)) (dist l m) < e"
huffman@31565
   689
      unfolding dist_real_def
huffman@31565
   690
      using dist_triangle2 [of "f x" "g x" "l"]
huffman@31565
   691
      using dist_triangle2 [of "g x" "l" "m"]
huffman@31565
   692
      using dist_triangle3 [of "l" "m" "f x"]
huffman@31565
   693
      using dist_triangle [of "f x" "m" "g x"]
huffman@31565
   694
      by arith
huffman@31565
   695
  qed
huffman@31565
   696
qed
huffman@31565
   697
huffman@36662
   698
lemma norm_conv_dist: "norm x = dist x 0"
huffman@44081
   699
  unfolding dist_norm by simp
huffman@36662
   700
huffman@31565
   701
lemma tendsto_norm [tendsto_intros]:
huffman@44195
   702
  "(f ---> a) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> norm a) F"
huffman@44081
   703
  unfolding norm_conv_dist by (intro tendsto_intros)
huffman@36662
   704
huffman@36662
   705
lemma tendsto_norm_zero:
huffman@44195
   706
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. norm (f x)) ---> 0) F"
huffman@44081
   707
  by (drule tendsto_norm, simp)
huffman@36662
   708
huffman@36662
   709
lemma tendsto_norm_zero_cancel:
huffman@44195
   710
  "((\<lambda>x. norm (f x)) ---> 0) F \<Longrightarrow> (f ---> 0) F"
huffman@44081
   711
  unfolding tendsto_iff dist_norm by simp
huffman@36662
   712
huffman@36662
   713
lemma tendsto_norm_zero_iff:
huffman@44195
   714
  "((\<lambda>x. norm (f x)) ---> 0) F \<longleftrightarrow> (f ---> 0) F"
huffman@44081
   715
  unfolding tendsto_iff dist_norm by simp
huffman@31349
   716
huffman@44194
   717
lemma tendsto_rabs [tendsto_intros]:
huffman@44195
   718
  "(f ---> (l::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> \<bar>l\<bar>) F"
huffman@44194
   719
  by (fold real_norm_def, rule tendsto_norm)
huffman@44194
   720
huffman@44194
   721
lemma tendsto_rabs_zero:
huffman@44195
   722
  "(f ---> (0::real)) F \<Longrightarrow> ((\<lambda>x. \<bar>f x\<bar>) ---> 0) F"
huffman@44194
   723
  by (fold real_norm_def, rule tendsto_norm_zero)
huffman@44194
   724
huffman@44194
   725
lemma tendsto_rabs_zero_cancel:
huffman@44195
   726
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<Longrightarrow> (f ---> 0) F"
huffman@44194
   727
  by (fold real_norm_def, rule tendsto_norm_zero_cancel)
huffman@44194
   728
huffman@44194
   729
lemma tendsto_rabs_zero_iff:
huffman@44195
   730
  "((\<lambda>x. \<bar>f x\<bar>) ---> (0::real)) F \<longleftrightarrow> (f ---> 0) F"
huffman@44194
   731
  by (fold real_norm_def, rule tendsto_norm_zero_iff)
huffman@44194
   732
huffman@44194
   733
subsubsection {* Addition and subtraction *}
huffman@44194
   734
huffman@31565
   735
lemma tendsto_add [tendsto_intros]:
huffman@31349
   736
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   737
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> a + b) F"
huffman@44081
   738
  by (simp only: tendsto_Zfun_iff add_diff_add Zfun_add)
huffman@31349
   739
huffman@44194
   740
lemma tendsto_add_zero:
huffman@44194
   741
  fixes f g :: "'a::type \<Rightarrow> 'b::real_normed_vector"
huffman@44195
   742
  shows "\<lbrakk>(f ---> 0) F; (g ---> 0) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x + g x) ---> 0) F"
huffman@44194
   743
  by (drule (1) tendsto_add, simp)
huffman@44194
   744
huffman@31565
   745
lemma tendsto_minus [tendsto_intros]:
huffman@31349
   746
  fixes a :: "'a::real_normed_vector"
huffman@44195
   747
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. - f x) ---> - a) F"
huffman@44081
   748
  by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
huffman@31349
   749
huffman@31349
   750
lemma tendsto_minus_cancel:
huffman@31349
   751
  fixes a :: "'a::real_normed_vector"
huffman@44195
   752
  shows "((\<lambda>x. - f x) ---> - a) F \<Longrightarrow> (f ---> a) F"
huffman@44081
   753
  by (drule tendsto_minus, simp)
huffman@31349
   754
huffman@31565
   755
lemma tendsto_diff [tendsto_intros]:
huffman@31349
   756
  fixes a b :: "'a::real_normed_vector"
huffman@44195
   757
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x - g x) ---> a - b) F"
huffman@44081
   758
  by (simp add: diff_minus tendsto_add tendsto_minus)
huffman@31349
   759
huffman@31588
   760
lemma tendsto_setsum [tendsto_intros]:
huffman@31588
   761
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::real_normed_vector"
huffman@44195
   762
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> a i) F"
huffman@44195
   763
  shows "((\<lambda>x. \<Sum>i\<in>S. f i x) ---> (\<Sum>i\<in>S. a i)) F"
huffman@31588
   764
proof (cases "finite S")
huffman@31588
   765
  assume "finite S" thus ?thesis using assms
huffman@44194
   766
    by (induct, simp add: tendsto_const, simp add: tendsto_add)
huffman@31588
   767
next
huffman@31588
   768
  assume "\<not> finite S" thus ?thesis
huffman@31588
   769
    by (simp add: tendsto_const)
huffman@31588
   770
qed
huffman@31588
   771
huffman@44194
   772
subsubsection {* Linear operators and multiplication *}
huffman@44194
   773
huffman@44282
   774
lemma (in bounded_linear) tendsto:
huffman@44195
   775
  "(g ---> a) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> f a) F"
huffman@44081
   776
  by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
huffman@31349
   777
huffman@44194
   778
lemma (in bounded_linear) tendsto_zero:
huffman@44195
   779
  "(g ---> 0) F \<Longrightarrow> ((\<lambda>x. f (g x)) ---> 0) F"
huffman@44194
   780
  by (drule tendsto, simp only: zero)
huffman@44194
   781
huffman@44282
   782
lemma (in bounded_bilinear) tendsto:
huffman@44195
   783
  "\<lbrakk>(f ---> a) F; (g ---> b) F\<rbrakk> \<Longrightarrow> ((\<lambda>x. f x ** g x) ---> a ** b) F"
huffman@44081
   784
  by (simp only: tendsto_Zfun_iff prod_diff_prod
huffman@44081
   785
                 Zfun_add Zfun Zfun_left Zfun_right)
huffman@31349
   786
huffman@44194
   787
lemma (in bounded_bilinear) tendsto_zero:
huffman@44195
   788
  assumes f: "(f ---> 0) F"
huffman@44195
   789
  assumes g: "(g ---> 0) F"
huffman@44195
   790
  shows "((\<lambda>x. f x ** g x) ---> 0) F"
huffman@44194
   791
  using tendsto [OF f g] by (simp add: zero_left)
huffman@31355
   792
huffman@44194
   793
lemma (in bounded_bilinear) tendsto_left_zero:
huffman@44195
   794
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. f x ** c) ---> 0) F"
huffman@44194
   795
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_left])
huffman@44194
   796
huffman@44194
   797
lemma (in bounded_bilinear) tendsto_right_zero:
huffman@44195
   798
  "(f ---> 0) F \<Longrightarrow> ((\<lambda>x. c ** f x) ---> 0) F"
huffman@44194
   799
  by (rule bounded_linear.tendsto_zero [OF bounded_linear_right])
huffman@44194
   800
huffman@44282
   801
lemmas tendsto_of_real [tendsto_intros] =
huffman@44282
   802
  bounded_linear.tendsto [OF bounded_linear_of_real]
huffman@44282
   803
huffman@44282
   804
lemmas tendsto_scaleR [tendsto_intros] =
huffman@44282
   805
  bounded_bilinear.tendsto [OF bounded_bilinear_scaleR]
huffman@44282
   806
huffman@44282
   807
lemmas tendsto_mult [tendsto_intros] =
huffman@44282
   808
  bounded_bilinear.tendsto [OF bounded_bilinear_mult]
huffman@44194
   809
huffman@44568
   810
lemmas tendsto_mult_zero =
huffman@44568
   811
  bounded_bilinear.tendsto_zero [OF bounded_bilinear_mult]
huffman@44568
   812
huffman@44568
   813
lemmas tendsto_mult_left_zero =
huffman@44568
   814
  bounded_bilinear.tendsto_left_zero [OF bounded_bilinear_mult]
huffman@44568
   815
huffman@44568
   816
lemmas tendsto_mult_right_zero =
huffman@44568
   817
  bounded_bilinear.tendsto_right_zero [OF bounded_bilinear_mult]
huffman@44568
   818
huffman@44194
   819
lemma tendsto_power [tendsto_intros]:
huffman@44194
   820
  fixes f :: "'a \<Rightarrow> 'b::{power,real_normed_algebra}"
huffman@44195
   821
  shows "(f ---> a) F \<Longrightarrow> ((\<lambda>x. f x ^ n) ---> a ^ n) F"
huffman@44194
   822
  by (induct n) (simp_all add: tendsto_const tendsto_mult)
huffman@44194
   823
huffman@44194
   824
lemma tendsto_setprod [tendsto_intros]:
huffman@44194
   825
  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'c::{real_normed_algebra,comm_ring_1}"
huffman@44195
   826
  assumes "\<And>i. i \<in> S \<Longrightarrow> (f i ---> L i) F"
huffman@44195
   827
  shows "((\<lambda>x. \<Prod>i\<in>S. f i x) ---> (\<Prod>i\<in>S. L i)) F"
huffman@44194
   828
proof (cases "finite S")
huffman@44194
   829
  assume "finite S" thus ?thesis using assms
huffman@44194
   830
    by (induct, simp add: tendsto_const, simp add: tendsto_mult)
huffman@44194
   831
next
huffman@44194
   832
  assume "\<not> finite S" thus ?thesis
huffman@44194
   833
    by (simp add: tendsto_const)
huffman@44194
   834
qed
huffman@44194
   835
huffman@44194
   836
subsubsection {* Inverse and division *}
huffman@31355
   837
huffman@31355
   838
lemma (in bounded_bilinear) Zfun_prod_Bfun:
huffman@44195
   839
  assumes f: "Zfun f F"
huffman@44195
   840
  assumes g: "Bfun g F"
huffman@44195
   841
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@31355
   842
proof -
huffman@31355
   843
  obtain K where K: "0 \<le> K"
huffman@31355
   844
    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
huffman@31355
   845
    using nonneg_bounded by fast
huffman@31355
   846
  obtain B where B: "0 < B"
huffman@44195
   847
    and norm_g: "eventually (\<lambda>x. norm (g x) \<le> B) F"
huffman@31487
   848
    using g by (rule BfunE)
huffman@44195
   849
  have "eventually (\<lambda>x. norm (f x ** g x) \<le> norm (f x) * (B * K)) F"
huffman@31487
   850
  using norm_g proof (rule eventually_elim1)
huffman@31487
   851
    fix x
huffman@31487
   852
    assume *: "norm (g x) \<le> B"
huffman@31487
   853
    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K"
huffman@31355
   854
      by (rule norm_le)
huffman@31487
   855
    also have "\<dots> \<le> norm (f x) * B * K"
huffman@31487
   856
      by (intro mult_mono' order_refl norm_g norm_ge_zero
huffman@31355
   857
                mult_nonneg_nonneg K *)
huffman@31487
   858
    also have "\<dots> = norm (f x) * (B * K)"
huffman@31355
   859
      by (rule mult_assoc)
huffman@31487
   860
    finally show "norm (f x ** g x) \<le> norm (f x) * (B * K)" .
huffman@31355
   861
  qed
huffman@31487
   862
  with f show ?thesis
huffman@31487
   863
    by (rule Zfun_imp_Zfun)
huffman@31355
   864
qed
huffman@31355
   865
huffman@31355
   866
lemma (in bounded_bilinear) flip:
huffman@31355
   867
  "bounded_bilinear (\<lambda>x y. y ** x)"
huffman@44081
   868
  apply default
huffman@44081
   869
  apply (rule add_right)
huffman@44081
   870
  apply (rule add_left)
huffman@44081
   871
  apply (rule scaleR_right)
huffman@44081
   872
  apply (rule scaleR_left)
huffman@44081
   873
  apply (subst mult_commute)
huffman@44081
   874
  using bounded by fast
huffman@31355
   875
huffman@31355
   876
lemma (in bounded_bilinear) Bfun_prod_Zfun:
huffman@44195
   877
  assumes f: "Bfun f F"
huffman@44195
   878
  assumes g: "Zfun g F"
huffman@44195
   879
  shows "Zfun (\<lambda>x. f x ** g x) F"
huffman@44081
   880
  using flip g f by (rule bounded_bilinear.Zfun_prod_Bfun)
huffman@31355
   881
huffman@31355
   882
lemma Bfun_inverse_lemma:
huffman@31355
   883
  fixes x :: "'a::real_normed_div_algebra"
huffman@31355
   884
  shows "\<lbrakk>r \<le> norm x; 0 < r\<rbrakk> \<Longrightarrow> norm (inverse x) \<le> inverse r"
huffman@44081
   885
  apply (subst nonzero_norm_inverse, clarsimp)
huffman@44081
   886
  apply (erule (1) le_imp_inverse_le)
huffman@44081
   887
  done
huffman@31355
   888
huffman@31355
   889
lemma Bfun_inverse:
huffman@31355
   890
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
   891
  assumes f: "(f ---> a) F"
huffman@31355
   892
  assumes a: "a \<noteq> 0"
huffman@44195
   893
  shows "Bfun (\<lambda>x. inverse (f x)) F"
huffman@31355
   894
proof -
huffman@31355
   895
  from a have "0 < norm a" by simp
huffman@31355
   896
  hence "\<exists>r>0. r < norm a" by (rule dense)
huffman@31355
   897
  then obtain r where r1: "0 < r" and r2: "r < norm a" by fast
huffman@44195
   898
  have "eventually (\<lambda>x. dist (f x) a < r) F"
huffman@31487
   899
    using tendstoD [OF f r1] by fast
huffman@44195
   900
  hence "eventually (\<lambda>x. norm (inverse (f x)) \<le> inverse (norm a - r)) F"
huffman@31355
   901
  proof (rule eventually_elim1)
huffman@31487
   902
    fix x
huffman@31487
   903
    assume "dist (f x) a < r"
huffman@31487
   904
    hence 1: "norm (f x - a) < r"
huffman@31355
   905
      by (simp add: dist_norm)
huffman@31487
   906
    hence 2: "f x \<noteq> 0" using r2 by auto
huffman@31487
   907
    hence "norm (inverse (f x)) = inverse (norm (f x))"
huffman@31355
   908
      by (rule nonzero_norm_inverse)
huffman@31355
   909
    also have "\<dots> \<le> inverse (norm a - r)"
huffman@31355
   910
    proof (rule le_imp_inverse_le)
huffman@31355
   911
      show "0 < norm a - r" using r2 by simp
huffman@31355
   912
    next
huffman@31487
   913
      have "norm a - norm (f x) \<le> norm (a - f x)"
huffman@31355
   914
        by (rule norm_triangle_ineq2)
huffman@31487
   915
      also have "\<dots> = norm (f x - a)"
huffman@31355
   916
        by (rule norm_minus_commute)
huffman@31355
   917
      also have "\<dots> < r" using 1 .
huffman@31487
   918
      finally show "norm a - r \<le> norm (f x)" by simp
huffman@31355
   919
    qed
huffman@31487
   920
    finally show "norm (inverse (f x)) \<le> inverse (norm a - r)" .
huffman@31355
   921
  qed
huffman@31355
   922
  thus ?thesis by (rule BfunI)
huffman@31355
   923
qed
huffman@31355
   924
huffman@31565
   925
lemma tendsto_inverse [tendsto_intros]:
huffman@31355
   926
  fixes a :: "'a::real_normed_div_algebra"
huffman@44195
   927
  assumes f: "(f ---> a) F"
huffman@31355
   928
  assumes a: "a \<noteq> 0"
huffman@44195
   929
  shows "((\<lambda>x. inverse (f x)) ---> inverse a) F"
huffman@31355
   930
proof -
huffman@31355
   931
  from a have "0 < norm a" by simp
huffman@44195
   932
  with f have "eventually (\<lambda>x. dist (f x) a < norm a) F"
huffman@31355
   933
    by (rule tendstoD)
huffman@44195
   934
  then have "eventually (\<lambda>x. f x \<noteq> 0) F"
huffman@31355
   935
    unfolding dist_norm by (auto elim!: eventually_elim1)
huffman@44627
   936
  with a have "eventually (\<lambda>x. inverse (f x) - inverse a =
huffman@44627
   937
    - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
   938
    by (auto elim!: eventually_elim1 simp: inverse_diff_inverse)
huffman@44627
   939
  moreover have "Zfun (\<lambda>x. - (inverse (f x) * (f x - a) * inverse a)) F"
huffman@44627
   940
    by (intro Zfun_minus Zfun_mult_left
huffman@44627
   941
      bounded_bilinear.Bfun_prod_Zfun [OF bounded_bilinear_mult]
huffman@44627
   942
      Bfun_inverse [OF f a] f [unfolded tendsto_Zfun_iff])
huffman@44627
   943
  ultimately show ?thesis
huffman@44627
   944
    unfolding tendsto_Zfun_iff by (rule Zfun_ssubst)
huffman@31355
   945
qed
huffman@31355
   946
huffman@31565
   947
lemma tendsto_divide [tendsto_intros]:
huffman@31355
   948
  fixes a b :: "'a::real_normed_field"
huffman@44195
   949
  shows "\<lbrakk>(f ---> a) F; (g ---> b) F; b \<noteq> 0\<rbrakk>
huffman@44195
   950
    \<Longrightarrow> ((\<lambda>x. f x / g x) ---> a / b) F"
huffman@44282
   951
  by (simp add: tendsto_mult tendsto_inverse divide_inverse)
huffman@31355
   952
huffman@44194
   953
lemma tendsto_sgn [tendsto_intros]:
huffman@44194
   954
  fixes l :: "'a::real_normed_vector"
huffman@44195
   955
  shows "\<lbrakk>(f ---> l) F; l \<noteq> 0\<rbrakk> \<Longrightarrow> ((\<lambda>x. sgn (f x)) ---> sgn l) F"
huffman@44194
   956
  unfolding sgn_div_norm by (simp add: tendsto_intros)
huffman@44194
   957
huffman@31349
   958
end