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