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