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