new theory of filters and limits; prove LIMSEQ and LIM lemmas using filters
authorhuffman
Sun May 31 21:59:33 2009 -0700 (2009-05-31)
changeset 313492261c8781f73
parent 31348 738eb25e1dd8
child 31350 f20a61cec3d4
new theory of filters and limits; prove LIMSEQ and LIM lemmas using filters
src/HOL/Lim.thy
src/HOL/Limits.thy
src/HOL/SEQ.thy
     1.1 --- a/src/HOL/Lim.thy	Sun May 31 11:27:19 2009 -0700
     1.2 +++ b/src/HOL/Lim.thy	Sun May 31 21:59:33 2009 -0700
     1.3 @@ -13,6 +13,10 @@
     1.4  text{*Standard Definitions*}
     1.5  
     1.6  definition
     1.7 +  at :: "'a::metric_space \<Rightarrow> 'a filter" where
     1.8 +  "at a = Abs_filter (\<lambda>P. \<exists>r>0. \<forall>x. x \<noteq> a \<and> dist x a < r \<longrightarrow> P x)"
     1.9 +
    1.10 +definition
    1.11    LIM :: "['a::metric_space \<Rightarrow> 'b::metric_space, 'a, 'b] \<Rightarrow> bool"
    1.12          ("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60) where
    1.13    [code del]: "f -- a --> L =
    1.14 @@ -27,6 +31,20 @@
    1.15    isUCont :: "['a::metric_space \<Rightarrow> 'b::metric_space] \<Rightarrow> bool" where
    1.16    [code del]: "isUCont f = (\<forall>r>0. \<exists>s>0. \<forall>x y. dist x y < s \<longrightarrow> dist (f x) (f y) < r)"
    1.17  
    1.18 +subsection {* Neighborhood Filter *}
    1.19 +
    1.20 +lemma eventually_at:
    1.21 +  "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> P x)"
    1.22 +unfolding at_def
    1.23 +apply (rule eventually_Abs_filter)
    1.24 +apply (rule_tac x=1 in exI, simp)
    1.25 +apply (clarify, rule_tac x=r in exI, simp)
    1.26 +apply (clarify, rename_tac r s)
    1.27 +apply (rule_tac x="min r s" in exI, simp)
    1.28 +done
    1.29 +
    1.30 +lemma LIM_conv_tendsto: "(f -- a --> L) \<longleftrightarrow> tendsto f L (at a)"
    1.31 +unfolding LIM_def tendsto_def eventually_at ..
    1.32  
    1.33  subsection {* Limits of Functions *}
    1.34  
    1.35 @@ -86,33 +104,7 @@
    1.36    fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
    1.37    assumes f: "f -- a --> L" and g: "g -- a --> M"
    1.38    shows "(\<lambda>x. f x + g x) -- a --> (L + M)"
    1.39 -proof (rule metric_LIM_I)
    1.40 -  fix r :: real
    1.41 -  assume r: "0 < r"
    1.42 -  from metric_LIM_D [OF f half_gt_zero [OF r]]
    1.43 -  obtain fs
    1.44 -    where fs:    "0 < fs"
    1.45 -      and fs_lt: "\<forall>x. x \<noteq> a \<and> dist x a < fs \<longrightarrow> dist (f x) L < r/2"
    1.46 -  by blast
    1.47 -  from metric_LIM_D [OF g half_gt_zero [OF r]]
    1.48 -  obtain gs
    1.49 -    where gs:    "0 < gs"
    1.50 -      and gs_lt: "\<forall>x. x \<noteq> a \<and> dist x a < gs \<longrightarrow> dist (g x) M < r/2"
    1.51 -  by blast
    1.52 -  show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x + g x) (L + M) < r"
    1.53 -  proof (intro exI conjI strip)
    1.54 -    show "0 < min fs gs"  by (simp add: fs gs)
    1.55 -    fix x :: 'a
    1.56 -    assume "x \<noteq> a \<and> dist x a < min fs gs"
    1.57 -    hence "x \<noteq> a \<and> dist x a < fs \<and> dist x a < gs" by simp
    1.58 -    with fs_lt gs_lt
    1.59 -    have "dist (f x) L < r/2" and "dist (g x) M < r/2" by blast+
    1.60 -    hence "dist (f x) L + dist (g x) M < r" by arith
    1.61 -    thus "dist (f x + g x) (L + M) < r"
    1.62 -      unfolding dist_norm
    1.63 -      by (blast intro: norm_diff_triangle_ineq order_le_less_trans)
    1.64 -  qed
    1.65 -qed
    1.66 +using assms unfolding LIM_conv_tendsto by (rule tendsto_add)
    1.67  
    1.68  lemma LIM_add_zero:
    1.69    fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
    1.70 @@ -127,7 +119,7 @@
    1.71  lemma LIM_minus:
    1.72    fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
    1.73    shows "f -- a --> L \<Longrightarrow> (\<lambda>x. - f x) -- a --> - L"
    1.74 -by (simp only: LIM_def dist_norm minus_diff_minus norm_minus_cancel)
    1.75 +unfolding LIM_conv_tendsto by (rule tendsto_minus)
    1.76  
    1.77  (* TODO: delete *)
    1.78  lemma LIM_add_minus:
    1.79 @@ -138,7 +130,7 @@
    1.80  lemma LIM_diff:
    1.81    fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
    1.82    shows "\<lbrakk>f -- x --> l; g -- x --> m\<rbrakk> \<Longrightarrow> (\<lambda>x. f x - g x) -- x --> l - m"
    1.83 -by (simp only: diff_minus LIM_add LIM_minus)
    1.84 +unfolding LIM_conv_tendsto by (rule tendsto_diff)
    1.85  
    1.86  lemma LIM_zero:
    1.87    fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
    1.88 @@ -178,7 +170,7 @@
    1.89  lemma LIM_norm:
    1.90    fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
    1.91    shows "f -- a --> l \<Longrightarrow> (\<lambda>x. norm (f x)) -- a --> norm l"
    1.92 -by (erule LIM_imp_LIM, simp add: norm_triangle_ineq3)
    1.93 +unfolding LIM_conv_tendsto by (rule tendsto_norm)
    1.94  
    1.95  lemma LIM_norm_zero:
    1.96    fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
    1.97 @@ -369,26 +361,12 @@
    1.98  
    1.99  text {* Bounded Linear Operators *}
   1.100  
   1.101 -lemma (in bounded_linear) cont: "f -- a --> f a"
   1.102 -proof (rule LIM_I)
   1.103 -  fix r::real assume r: "0 < r"
   1.104 -  obtain K where K: "0 < K" and norm_le: "\<And>x. norm (f x) \<le> norm x * K"
   1.105 -    using pos_bounded by fast
   1.106 -  show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (f x - f a) < r"
   1.107 -  proof (rule exI, safe)
   1.108 -    from r K show "0 < r / K" by (rule divide_pos_pos)
   1.109 -  next
   1.110 -    fix x assume x: "norm (x - a) < r / K"
   1.111 -    have "norm (f x - f a) = norm (f (x - a))" by (simp only: diff)
   1.112 -    also have "\<dots> \<le> norm (x - a) * K" by (rule norm_le)
   1.113 -    also from K x have "\<dots> < r" by (simp only: pos_less_divide_eq)
   1.114 -    finally show "norm (f x - f a) < r" .
   1.115 -  qed
   1.116 -qed
   1.117 -
   1.118  lemma (in bounded_linear) LIM:
   1.119    "g -- a --> l \<Longrightarrow> (\<lambda>x. f (g x)) -- a --> f l"
   1.120 -by (rule LIM_compose [OF cont])
   1.121 +unfolding LIM_conv_tendsto by (rule tendsto)
   1.122 +
   1.123 +lemma (in bounded_linear) cont: "f -- a --> f a"
   1.124 +by (rule LIM [OF LIM_ident])
   1.125  
   1.126  lemma (in bounded_linear) LIM_zero:
   1.127    "g -- a --> 0 \<Longrightarrow> (\<lambda>x. f (g x)) -- a --> 0"
   1.128 @@ -396,40 +374,16 @@
   1.129  
   1.130  text {* Bounded Bilinear Operators *}
   1.131  
   1.132 +lemma (in bounded_bilinear) LIM:
   1.133 +  "\<lbrakk>f -- a --> L; g -- a --> M\<rbrakk> \<Longrightarrow> (\<lambda>x. f x ** g x) -- a --> L ** M"
   1.134 +unfolding LIM_conv_tendsto by (rule tendsto)
   1.135 +
   1.136  lemma (in bounded_bilinear) LIM_prod_zero:
   1.137    fixes a :: "'d::metric_space"
   1.138    assumes f: "f -- a --> 0"
   1.139    assumes g: "g -- a --> 0"
   1.140    shows "(\<lambda>x. f x ** g x) -- a --> 0"
   1.141 -proof (rule metric_LIM_I, unfold dist_norm)
   1.142 -  fix r::real assume r: "0 < r"
   1.143 -  obtain K where K: "0 < K"
   1.144 -    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
   1.145 -    using pos_bounded by fast
   1.146 -  from K have K': "0 < inverse K"
   1.147 -    by (rule positive_imp_inverse_positive)
   1.148 -  obtain s where s: "0 < s"
   1.149 -    and norm_f: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < s\<rbrakk> \<Longrightarrow> norm (f x) < r"
   1.150 -    using metric_LIM_D [OF f r, unfolded dist_norm] by auto
   1.151 -  obtain t where t: "0 < t"
   1.152 -    and norm_g: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < t\<rbrakk> \<Longrightarrow> norm (g x) < inverse K"
   1.153 -    using metric_LIM_D [OF g K', unfolded dist_norm] by auto
   1.154 -  show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> norm (f x ** g x - 0) < r"
   1.155 -  proof (rule exI, safe)
   1.156 -    from s t show "0 < min s t" by simp
   1.157 -  next
   1.158 -    fix x assume x: "x \<noteq> a"
   1.159 -    assume "dist x a < min s t"
   1.160 -    hence xs: "dist x a < s" and xt: "dist x a < t" by simp_all
   1.161 -    from x xs have 1: "norm (f x) < r" by (rule norm_f)
   1.162 -    from x xt have 2: "norm (g x) < inverse K" by (rule norm_g)
   1.163 -    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K" by (rule norm_le)
   1.164 -    also from 1 2 K have "\<dots> < r * inverse K * K"
   1.165 -      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero)
   1.166 -    also from K have "r * inverse K * K = r" by simp
   1.167 -    finally show "norm (f x ** g x - 0) < r" by simp
   1.168 -  qed
   1.169 -qed
   1.170 +using LIM [OF f g] by (simp add: zero_left)
   1.171  
   1.172  lemma (in bounded_bilinear) LIM_left_zero:
   1.173    "f -- a --> 0 \<Longrightarrow> (\<lambda>x. f x ** c) -- a --> 0"
   1.174 @@ -439,19 +393,6 @@
   1.175    "f -- a --> 0 \<Longrightarrow> (\<lambda>x. c ** f x) -- a --> 0"
   1.176  by (rule bounded_linear.LIM_zero [OF bounded_linear_right])
   1.177  
   1.178 -lemma (in bounded_bilinear) LIM:
   1.179 -  "\<lbrakk>f -- a --> L; g -- a --> M\<rbrakk> \<Longrightarrow> (\<lambda>x. f x ** g x) -- a --> L ** M"
   1.180 -apply (drule LIM_zero)
   1.181 -apply (drule LIM_zero)
   1.182 -apply (rule LIM_zero_cancel)
   1.183 -apply (subst prod_diff_prod)
   1.184 -apply (rule LIM_add_zero)
   1.185 -apply (rule LIM_add_zero)
   1.186 -apply (erule (1) LIM_prod_zero)
   1.187 -apply (erule LIM_left_zero)
   1.188 -apply (erule LIM_right_zero)
   1.189 -done
   1.190 -
   1.191  lemmas LIM_mult = mult.LIM
   1.192  
   1.193  lemmas LIM_mult_zero = mult.LIM_prod_zero
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/HOL/Limits.thy	Sun May 31 21:59:33 2009 -0700
     2.3 @@ -0,0 +1,296 @@
     2.4 +(*  Title       : Limits.thy
     2.5 +    Author      : Brian Huffman
     2.6 +*)
     2.7 +
     2.8 +header {* Filters and Limits *}
     2.9 +
    2.10 +theory Limits
    2.11 +imports RealVector RComplete
    2.12 +begin
    2.13 +
    2.14 +subsection {* Filters *}
    2.15 +
    2.16 +typedef (open) 'a filter =
    2.17 +  "{f :: ('a \<Rightarrow> bool) \<Rightarrow> bool. f (\<lambda>x. True)
    2.18 +    \<and> (\<forall>P Q. (\<forall>x. P x \<longrightarrow> Q x) \<longrightarrow> f P \<longrightarrow> f Q)
    2.19 +    \<and> (\<forall>P Q. f P \<longrightarrow> f Q \<longrightarrow> f (\<lambda>x. P x \<and> Q x))}"
    2.20 +proof
    2.21 +  show "(\<lambda>P. True) \<in> ?filter" by simp
    2.22 +qed
    2.23 +
    2.24 +definition
    2.25 +  eventually :: "('a \<Rightarrow> bool) \<Rightarrow> 'a filter \<Rightarrow> bool" where
    2.26 +  "eventually P F \<longleftrightarrow> Rep_filter F P"
    2.27 +
    2.28 +lemma eventually_True [simp]: "eventually (\<lambda>x. True) F"
    2.29 +unfolding eventually_def using Rep_filter [of F] by blast
    2.30 +
    2.31 +lemma eventually_mono:
    2.32 +  "(\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually P F \<Longrightarrow> eventually Q F"
    2.33 +unfolding eventually_def using Rep_filter [of F] by blast
    2.34 +
    2.35 +lemma eventually_conj:
    2.36 +  "\<lbrakk>eventually (\<lambda>x. P x) F; eventually (\<lambda>x. Q x) F\<rbrakk>
    2.37 +    \<Longrightarrow> eventually (\<lambda>x. P x \<and> Q x) F"
    2.38 +unfolding eventually_def using Rep_filter [of F] by blast
    2.39 +
    2.40 +lemma eventually_mp:
    2.41 +  assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
    2.42 +  assumes "eventually (\<lambda>x. P x) F"
    2.43 +  shows "eventually (\<lambda>x. Q x) F"
    2.44 +proof (rule eventually_mono)
    2.45 +  show "\<forall>x. (P x \<longrightarrow> Q x) \<and> P x \<longrightarrow> Q x" by simp
    2.46 +  show "eventually (\<lambda>x. (P x \<longrightarrow> Q x) \<and> P x) F"
    2.47 +    using assms by (rule eventually_conj)
    2.48 +qed
    2.49 +
    2.50 +lemma eventually_rev_mp:
    2.51 +  assumes "eventually (\<lambda>x. P x) F"
    2.52 +  assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
    2.53 +  shows "eventually (\<lambda>x. Q x) F"
    2.54 +using assms(2) assms(1) by (rule eventually_mp)
    2.55 +
    2.56 +lemma eventually_conj_iff:
    2.57 +  "eventually (\<lambda>x. P x \<and> Q x) net \<longleftrightarrow> eventually P net \<and> eventually Q net"
    2.58 +by (auto intro: eventually_conj elim: eventually_rev_mp)
    2.59 +
    2.60 +lemma eventually_Abs_filter:
    2.61 +  assumes "f (\<lambda>x. True)"
    2.62 +  assumes "\<And>P Q. (\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> f P \<Longrightarrow> f Q"
    2.63 +  assumes "\<And>P Q. f P \<Longrightarrow> f Q \<Longrightarrow> f (\<lambda>x. P x \<and> Q x)"
    2.64 +  shows "eventually P (Abs_filter f) \<longleftrightarrow> f P"
    2.65 +unfolding eventually_def using assms
    2.66 +by (subst Abs_filter_inverse, auto)
    2.67 +
    2.68 +lemma filter_ext:
    2.69 +  "(\<And>P. eventually P F \<longleftrightarrow> eventually P F') \<Longrightarrow> F = F'"
    2.70 +unfolding eventually_def
    2.71 +by (simp add: Rep_filter_inject [THEN iffD1] ext)
    2.72 +
    2.73 +lemma eventually_elim1:
    2.74 +  assumes "eventually (\<lambda>i. P i) F"
    2.75 +  assumes "\<And>i. P i \<Longrightarrow> Q i"
    2.76 +  shows "eventually (\<lambda>i. Q i) F"
    2.77 +using assms by (auto elim!: eventually_rev_mp)
    2.78 +
    2.79 +lemma eventually_elim2:
    2.80 +  assumes "eventually (\<lambda>i. P i) F"
    2.81 +  assumes "eventually (\<lambda>i. Q i) F"
    2.82 +  assumes "\<And>i. P i \<Longrightarrow> Q i \<Longrightarrow> R i"
    2.83 +  shows "eventually (\<lambda>i. R i) F"
    2.84 +using assms by (auto elim!: eventually_rev_mp)
    2.85 +
    2.86 +
    2.87 +subsection {* Convergence to Zero *}
    2.88 +
    2.89 +definition
    2.90 +  Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool" where
    2.91 +  "Zfun S F = (\<forall>r>0. eventually (\<lambda>i. norm (S i) < r) F)"
    2.92 +
    2.93 +lemma ZfunI:
    2.94 +  "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>i. norm (S i) < r) F) \<Longrightarrow> Zfun S F"
    2.95 +unfolding Zfun_def by simp
    2.96 +
    2.97 +lemma ZfunD:
    2.98 +  "\<lbrakk>Zfun S F; 0 < r\<rbrakk> \<Longrightarrow> eventually (\<lambda>i. norm (S i) < r) F"
    2.99 +unfolding Zfun_def by simp
   2.100 +
   2.101 +lemma Zfun_zero: "Zfun (\<lambda>i. 0) F"
   2.102 +unfolding Zfun_def by simp
   2.103 +
   2.104 +lemma Zfun_norm_iff: "Zfun (\<lambda>i. norm (S i)) F = Zfun (\<lambda>i. S i) F"
   2.105 +unfolding Zfun_def by simp
   2.106 +
   2.107 +lemma Zfun_imp_Zfun:
   2.108 +  assumes X: "Zfun X F"
   2.109 +  assumes Y: "\<And>n. norm (Y n) \<le> norm (X n) * K"
   2.110 +  shows "Zfun (\<lambda>n. Y n) F"
   2.111 +proof (cases)
   2.112 +  assume K: "0 < K"
   2.113 +  show ?thesis
   2.114 +  proof (rule ZfunI)
   2.115 +    fix r::real assume "0 < r"
   2.116 +    hence "0 < r / K"
   2.117 +      using K by (rule divide_pos_pos)
   2.118 +    then have "eventually (\<lambda>i. norm (X i) < r / K) F"
   2.119 +      using ZfunD [OF X] by fast
   2.120 +    then show "eventually (\<lambda>i. norm (Y i) < r) F"
   2.121 +    proof (rule eventually_elim1)
   2.122 +      fix i assume "norm (X i) < r / K"
   2.123 +      hence "norm (X i) * K < r"
   2.124 +        by (simp add: pos_less_divide_eq K)
   2.125 +      thus "norm (Y i) < r"
   2.126 +        by (simp add: order_le_less_trans [OF Y])
   2.127 +    qed
   2.128 +  qed
   2.129 +next
   2.130 +  assume "\<not> 0 < K"
   2.131 +  hence K: "K \<le> 0" by (simp only: not_less)
   2.132 +  {
   2.133 +    fix i
   2.134 +    have "norm (Y i) \<le> norm (X i) * K" by (rule Y)
   2.135 +    also have "\<dots> \<le> norm (X i) * 0"
   2.136 +      using K norm_ge_zero by (rule mult_left_mono)
   2.137 +    finally have "norm (Y i) = 0" by simp
   2.138 +  }
   2.139 +  thus ?thesis by (simp add: Zfun_zero)
   2.140 +qed
   2.141 +
   2.142 +lemma Zfun_le: "\<lbrakk>Zfun Y F; \<forall>n. norm (X n) \<le> norm (Y n)\<rbrakk> \<Longrightarrow> Zfun X F"
   2.143 +by (erule_tac K="1" in Zfun_imp_Zfun, simp)
   2.144 +
   2.145 +lemma Zfun_add:
   2.146 +  assumes X: "Zfun X F" and Y: "Zfun Y F"
   2.147 +  shows "Zfun (\<lambda>n. X n + Y n) F"
   2.148 +proof (rule ZfunI)
   2.149 +  fix r::real assume "0 < r"
   2.150 +  hence r: "0 < r / 2" by simp
   2.151 +  have "eventually (\<lambda>i. norm (X i) < r/2) F"
   2.152 +    using X r by (rule ZfunD)
   2.153 +  moreover
   2.154 +  have "eventually (\<lambda>i. norm (Y i) < r/2) F"
   2.155 +    using Y r by (rule ZfunD)
   2.156 +  ultimately
   2.157 +  show "eventually (\<lambda>i. norm (X i + Y i) < r) F"
   2.158 +  proof (rule eventually_elim2)
   2.159 +    fix i
   2.160 +    assume *: "norm (X i) < r/2" "norm (Y i) < r/2"
   2.161 +    have "norm (X i + Y i) \<le> norm (X i) + norm (Y i)"
   2.162 +      by (rule norm_triangle_ineq)
   2.163 +    also have "\<dots> < r/2 + r/2"
   2.164 +      using * by (rule add_strict_mono)
   2.165 +    finally show "norm (X i + Y i) < r"
   2.166 +      by simp
   2.167 +  qed
   2.168 +qed
   2.169 +
   2.170 +lemma Zfun_minus: "Zfun X F \<Longrightarrow> Zfun (\<lambda>i. - X i) F"
   2.171 +unfolding Zfun_def by simp
   2.172 +
   2.173 +lemma Zfun_diff: "\<lbrakk>Zfun X F; Zfun Y F\<rbrakk> \<Longrightarrow> Zfun (\<lambda>i. X i - Y i) F"
   2.174 +by (simp only: diff_minus Zfun_add Zfun_minus)
   2.175 +
   2.176 +lemma (in bounded_linear) Zfun:
   2.177 +  assumes X: "Zfun X F"
   2.178 +  shows "Zfun (\<lambda>n. f (X n)) F"
   2.179 +proof -
   2.180 +  obtain K where "\<And>x. norm (f x) \<le> norm x * K"
   2.181 +    using bounded by fast
   2.182 +  with X show ?thesis
   2.183 +    by (rule Zfun_imp_Zfun)
   2.184 +qed
   2.185 +
   2.186 +lemma (in bounded_bilinear) Zfun:
   2.187 +  assumes X: "Zfun X F"
   2.188 +  assumes Y: "Zfun Y F"
   2.189 +  shows "Zfun (\<lambda>n. X n ** Y n) F"
   2.190 +proof (rule ZfunI)
   2.191 +  fix r::real assume r: "0 < r"
   2.192 +  obtain K where K: "0 < K"
   2.193 +    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
   2.194 +    using pos_bounded by fast
   2.195 +  from K have K': "0 < inverse K"
   2.196 +    by (rule positive_imp_inverse_positive)
   2.197 +  have "eventually (\<lambda>i. norm (X i) < r) F"
   2.198 +    using X r by (rule ZfunD)
   2.199 +  moreover
   2.200 +  have "eventually (\<lambda>i. norm (Y i) < inverse K) F"
   2.201 +    using Y K' by (rule ZfunD)
   2.202 +  ultimately
   2.203 +  show "eventually (\<lambda>i. norm (X i ** Y i) < r) F"
   2.204 +  proof (rule eventually_elim2)
   2.205 +    fix i
   2.206 +    assume *: "norm (X i) < r" "norm (Y i) < inverse K"
   2.207 +    have "norm (X i ** Y i) \<le> norm (X i) * norm (Y i) * K"
   2.208 +      by (rule norm_le)
   2.209 +    also have "norm (X i) * norm (Y i) * K < r * inverse K * K"
   2.210 +      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero * K)
   2.211 +    also from K have "r * inverse K * K = r"
   2.212 +      by simp
   2.213 +    finally show "norm (X i ** Y i) < r" .
   2.214 +  qed
   2.215 +qed
   2.216 +
   2.217 +lemma (in bounded_bilinear) Zfun_left:
   2.218 +  "Zfun X F \<Longrightarrow> Zfun (\<lambda>n. X n ** a) F"
   2.219 +by (rule bounded_linear_left [THEN bounded_linear.Zfun])
   2.220 +
   2.221 +lemma (in bounded_bilinear) Zfun_right:
   2.222 +  "Zfun X F \<Longrightarrow> Zfun (\<lambda>n. a ** X n) F"
   2.223 +by (rule bounded_linear_right [THEN bounded_linear.Zfun])
   2.224 +
   2.225 +lemmas Zfun_mult = mult.Zfun
   2.226 +lemmas Zfun_mult_right = mult.Zfun_right
   2.227 +lemmas Zfun_mult_left = mult.Zfun_left
   2.228 +
   2.229 +
   2.230 +subsection{* Limits *}
   2.231 +
   2.232 +definition
   2.233 +  tendsto :: "('a \<Rightarrow> 'b::metric_space) \<Rightarrow> 'b \<Rightarrow> 'a filter \<Rightarrow> bool" where
   2.234 +  "tendsto f l net \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) net)"
   2.235 +
   2.236 +lemma tendstoI:
   2.237 +  "(\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) net)
   2.238 +    \<Longrightarrow> tendsto f l net"
   2.239 +  unfolding tendsto_def by auto
   2.240 +
   2.241 +lemma tendstoD:
   2.242 +  "tendsto f l net \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) net"
   2.243 +  unfolding tendsto_def by auto
   2.244 +
   2.245 +lemma tendsto_Zfun_iff: "tendsto (\<lambda>n. X n) L F = Zfun (\<lambda>n. X n - L) F"
   2.246 +by (simp only: tendsto_def Zfun_def dist_norm)
   2.247 +
   2.248 +lemma tendsto_const: "tendsto (\<lambda>n. k) k F"
   2.249 +by (simp add: tendsto_def)
   2.250 +
   2.251 +lemma tendsto_norm:
   2.252 +  fixes a :: "'a::real_normed_vector"
   2.253 +  shows "tendsto X a F \<Longrightarrow> tendsto (\<lambda>n. norm (X n)) (norm a) F"
   2.254 +apply (simp add: tendsto_def dist_norm, safe)
   2.255 +apply (drule_tac x="e" in spec, safe)
   2.256 +apply (erule eventually_elim1)
   2.257 +apply (erule order_le_less_trans [OF norm_triangle_ineq3])
   2.258 +done
   2.259 +
   2.260 +lemma add_diff_add:
   2.261 +  fixes a b c d :: "'a::ab_group_add"
   2.262 +  shows "(a + c) - (b + d) = (a - b) + (c - d)"
   2.263 +by simp
   2.264 +
   2.265 +lemma minus_diff_minus:
   2.266 +  fixes a b :: "'a::ab_group_add"
   2.267 +  shows "(- a) - (- b) = - (a - b)"
   2.268 +by simp
   2.269 +
   2.270 +lemma tendsto_add:
   2.271 +  fixes a b :: "'a::real_normed_vector"
   2.272 +  shows "\<lbrakk>tendsto X a F; tendsto Y b F\<rbrakk> \<Longrightarrow> tendsto (\<lambda>n. X n + Y n) (a + b) F"
   2.273 +by (simp only: tendsto_Zfun_iff add_diff_add Zfun_add)
   2.274 +
   2.275 +lemma tendsto_minus:
   2.276 +  fixes a :: "'a::real_normed_vector"
   2.277 +  shows "tendsto X a F \<Longrightarrow> tendsto (\<lambda>n. - X n) (- a) F"
   2.278 +by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
   2.279 +
   2.280 +lemma tendsto_minus_cancel:
   2.281 +  fixes a :: "'a::real_normed_vector"
   2.282 +  shows "tendsto (\<lambda>n. - X n) (- a) F \<Longrightarrow> tendsto X a F"
   2.283 +by (drule tendsto_minus, simp)
   2.284 +
   2.285 +lemma tendsto_diff:
   2.286 +  fixes a b :: "'a::real_normed_vector"
   2.287 +  shows "\<lbrakk>tendsto X a F; tendsto Y b F\<rbrakk> \<Longrightarrow> tendsto (\<lambda>n. X n - Y n) (a - b) F"
   2.288 +by (simp add: diff_minus tendsto_add tendsto_minus)
   2.289 +
   2.290 +lemma (in bounded_linear) tendsto:
   2.291 +  "tendsto X a F \<Longrightarrow> tendsto (\<lambda>n. f (X n)) (f a) F"
   2.292 +by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
   2.293 +
   2.294 +lemma (in bounded_bilinear) tendsto:
   2.295 +  "\<lbrakk>tendsto X a F; tendsto Y b F\<rbrakk> \<Longrightarrow> tendsto (\<lambda>n. X n ** Y n) (a ** b) F"
   2.296 +by (simp only: tendsto_Zfun_iff prod_diff_prod
   2.297 +               Zfun_add Zfun Zfun_left Zfun_right)
   2.298 +
   2.299 +end
     3.1 --- a/src/HOL/SEQ.thy	Sun May 31 11:27:19 2009 -0700
     3.2 +++ b/src/HOL/SEQ.thy	Sun May 31 21:59:33 2009 -0700
     3.3 @@ -9,10 +9,14 @@
     3.4  header {* Sequences and Convergence *}
     3.5  
     3.6  theory SEQ
     3.7 -imports RealVector RComplete
     3.8 +imports Limits
     3.9  begin
    3.10  
    3.11  definition
    3.12 +  sequentially :: "nat filter" where
    3.13 +  "sequentially = Abs_filter (\<lambda>P. \<exists>N. \<forall>n\<ge>N. P n)"
    3.14 +
    3.15 +definition
    3.16    Zseq :: "[nat \<Rightarrow> 'a::real_normed_vector] \<Rightarrow> bool" where
    3.17      --{*Standard definition of sequence converging to zero*}
    3.18    [code del]: "Zseq X = (\<forall>r>0. \<exists>no. \<forall>n\<ge>no. norm (X n) < r)"
    3.19 @@ -67,6 +71,24 @@
    3.20    [code del]: "Cauchy X = (\<forall>e>0. \<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. dist (X m) (X n) < e)"
    3.21  
    3.22  
    3.23 +subsection {* Sequentially *}
    3.24 +
    3.25 +lemma eventually_sequentially:
    3.26 +  "eventually P sequentially \<longleftrightarrow> (\<exists>N. \<forall>n\<ge>N. P n)"
    3.27 +unfolding sequentially_def
    3.28 +apply (rule eventually_Abs_filter)
    3.29 +apply simp
    3.30 +apply (clarify, rule_tac x=N in exI, simp)
    3.31 +apply (clarify, rename_tac M N)
    3.32 +apply (rule_tac x="max M N" in exI, simp)
    3.33 +done
    3.34 +
    3.35 +lemma Zseq_conv_Zfun: "Zseq X \<longleftrightarrow> Zfun X sequentially"
    3.36 +unfolding Zseq_def Zfun_def eventually_sequentially ..
    3.37 +
    3.38 +lemma LIMSEQ_conv_tendsto: "(X ----> L) \<longleftrightarrow> tendsto X L sequentially"
    3.39 +unfolding LIMSEQ_def tendsto_def eventually_sequentially ..
    3.40 +
    3.41  subsection {* Bounded Sequences *}
    3.42  
    3.43  lemma BseqI': assumes K: "\<And>n. norm (X n) \<le> K" shows "Bseq X"
    3.44 @@ -134,61 +156,14 @@
    3.45    assumes X: "Zseq X"
    3.46    assumes Y: "\<And>n. norm (Y n) \<le> norm (X n) * K"
    3.47    shows "Zseq (\<lambda>n. Y n)"
    3.48 -proof (cases)
    3.49 -  assume K: "0 < K"
    3.50 -  show ?thesis
    3.51 -  proof (rule ZseqI)
    3.52 -    fix r::real assume "0 < r"
    3.53 -    hence "0 < r / K"
    3.54 -      using K by (rule divide_pos_pos)
    3.55 -    then obtain N where "\<forall>n\<ge>N. norm (X n) < r / K"
    3.56 -      using ZseqD [OF X] by fast
    3.57 -    hence "\<forall>n\<ge>N. norm (X n) * K < r"
    3.58 -      by (simp add: pos_less_divide_eq K)
    3.59 -    hence "\<forall>n\<ge>N. norm (Y n) < r"
    3.60 -      by (simp add: order_le_less_trans [OF Y])
    3.61 -    thus "\<exists>N. \<forall>n\<ge>N. norm (Y n) < r" ..
    3.62 -  qed
    3.63 -next
    3.64 -  assume "\<not> 0 < K"
    3.65 -  hence K: "K \<le> 0" by (simp only: linorder_not_less)
    3.66 -  {
    3.67 -    fix n::nat
    3.68 -    have "norm (Y n) \<le> norm (X n) * K" by (rule Y)
    3.69 -    also have "\<dots> \<le> norm (X n) * 0"
    3.70 -      using K norm_ge_zero by (rule mult_left_mono)
    3.71 -    finally have "norm (Y n) = 0" by simp
    3.72 -  }
    3.73 -  thus ?thesis by (simp add: Zseq_zero)
    3.74 -qed
    3.75 +using assms unfolding Zseq_conv_Zfun by (rule Zfun_imp_Zfun)
    3.76  
    3.77  lemma Zseq_le: "\<lbrakk>Zseq Y; \<forall>n. norm (X n) \<le> norm (Y n)\<rbrakk> \<Longrightarrow> Zseq X"
    3.78  by (erule_tac K="1" in Zseq_imp_Zseq, simp)
    3.79  
    3.80  lemma Zseq_add:
    3.81 -  assumes X: "Zseq X"
    3.82 -  assumes Y: "Zseq Y"
    3.83 -  shows "Zseq (\<lambda>n. X n + Y n)"
    3.84 -proof (rule ZseqI)
    3.85 -  fix r::real assume "0 < r"
    3.86 -  hence r: "0 < r / 2" by simp
    3.87 -  obtain M where M: "\<forall>n\<ge>M. norm (X n) < r/2"
    3.88 -    using ZseqD [OF X r] by fast
    3.89 -  obtain N where N: "\<forall>n\<ge>N. norm (Y n) < r/2"
    3.90 -    using ZseqD [OF Y r] by fast
    3.91 -  show "\<exists>N. \<forall>n\<ge>N. norm (X n + Y n) < r"
    3.92 -  proof (intro exI allI impI)
    3.93 -    fix n assume n: "max M N \<le> n"
    3.94 -    have "norm (X n + Y n) \<le> norm (X n) + norm (Y n)"
    3.95 -      by (rule norm_triangle_ineq)
    3.96 -    also have "\<dots> < r/2 + r/2"
    3.97 -    proof (rule add_strict_mono)
    3.98 -      from M n show "norm (X n) < r/2" by simp
    3.99 -      from N n show "norm (Y n) < r/2" by simp
   3.100 -    qed
   3.101 -    finally show "norm (X n + Y n) < r" by simp
   3.102 -  qed
   3.103 -qed
   3.104 +  "Zseq X \<Longrightarrow> Zseq Y \<Longrightarrow> Zseq (\<lambda>n. X n + Y n)"
   3.105 +unfolding Zseq_conv_Zfun by (rule Zfun_add)
   3.106  
   3.107  lemma Zseq_minus: "Zseq X \<Longrightarrow> Zseq (\<lambda>n. - X n)"
   3.108  unfolding Zseq_def by simp
   3.109 @@ -197,44 +172,12 @@
   3.110  by (simp only: diff_minus Zseq_add Zseq_minus)
   3.111  
   3.112  lemma (in bounded_linear) Zseq:
   3.113 -  assumes X: "Zseq X"
   3.114 -  shows "Zseq (\<lambda>n. f (X n))"
   3.115 -proof -
   3.116 -  obtain K where "\<And>x. norm (f x) \<le> norm x * K"
   3.117 -    using bounded by fast
   3.118 -  with X show ?thesis
   3.119 -    by (rule Zseq_imp_Zseq)
   3.120 -qed
   3.121 +  "Zseq X \<Longrightarrow> Zseq (\<lambda>n. f (X n))"
   3.122 +unfolding Zseq_conv_Zfun by (rule Zfun)
   3.123  
   3.124  lemma (in bounded_bilinear) Zseq:
   3.125 -  assumes X: "Zseq X"
   3.126 -  assumes Y: "Zseq Y"
   3.127 -  shows "Zseq (\<lambda>n. X n ** Y n)"
   3.128 -proof (rule ZseqI)
   3.129 -  fix r::real assume r: "0 < r"
   3.130 -  obtain K where K: "0 < K"
   3.131 -    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
   3.132 -    using pos_bounded by fast
   3.133 -  from K have K': "0 < inverse K"
   3.134 -    by (rule positive_imp_inverse_positive)
   3.135 -  obtain M where M: "\<forall>n\<ge>M. norm (X n) < r"
   3.136 -    using ZseqD [OF X r] by fast
   3.137 -  obtain N where N: "\<forall>n\<ge>N. norm (Y n) < inverse K"
   3.138 -    using ZseqD [OF Y K'] by fast
   3.139 -  show "\<exists>N. \<forall>n\<ge>N. norm (X n ** Y n) < r"
   3.140 -  proof (intro exI allI impI)
   3.141 -    fix n assume n: "max M N \<le> n"
   3.142 -    have "norm (X n ** Y n) \<le> norm (X n) * norm (Y n) * K"
   3.143 -      by (rule norm_le)
   3.144 -    also have "norm (X n) * norm (Y n) * K < r * inverse K * K"
   3.145 -    proof (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero K)
   3.146 -      from M n show Xn: "norm (X n) < r" by simp
   3.147 -      from N n show Yn: "norm (Y n) < inverse K" by simp
   3.148 -    qed
   3.149 -    also from K have "r * inverse K * K = r" by simp
   3.150 -    finally show "norm (X n ** Y n) < r" .
   3.151 -  qed
   3.152 -qed
   3.153 +  "Zseq X \<Longrightarrow> Zseq Y \<Longrightarrow> Zseq (\<lambda>n. X n ** Y n)"
   3.154 +unfolding Zseq_conv_Zfun by (rule Zfun)
   3.155  
   3.156  lemma (in bounded_bilinear) Zseq_prod_Bseq:
   3.157    assumes X: "Zseq X"
   3.158 @@ -341,12 +284,7 @@
   3.159  lemma LIMSEQ_norm:
   3.160    fixes a :: "'a::real_normed_vector"
   3.161    shows "X ----> a \<Longrightarrow> (\<lambda>n. norm (X n)) ----> norm a"
   3.162 -apply (simp add: LIMSEQ_iff, safe)
   3.163 -apply (drule_tac x="r" in spec, safe)
   3.164 -apply (rule_tac x="no" in exI, safe)
   3.165 -apply (drule_tac x="n" in spec, safe)
   3.166 -apply (erule order_le_less_trans [OF norm_triangle_ineq3])
   3.167 -done
   3.168 +unfolding LIMSEQ_conv_tendsto by (rule tendsto_norm)
   3.169  
   3.170  lemma LIMSEQ_ignore_initial_segment:
   3.171    "f ----> a \<Longrightarrow> (\<lambda>n. f (n + k)) ----> a"
   3.172 @@ -381,26 +319,15 @@
   3.173    unfolding LIMSEQ_def
   3.174    by (metis div_le_dividend div_mult_self1_is_m le_trans nat_mult_commute)
   3.175  
   3.176 -
   3.177 -lemma add_diff_add:
   3.178 -  fixes a b c d :: "'a::ab_group_add"
   3.179 -  shows "(a + c) - (b + d) = (a - b) + (c - d)"
   3.180 -by simp
   3.181 -
   3.182 -lemma minus_diff_minus:
   3.183 -  fixes a b :: "'a::ab_group_add"
   3.184 -  shows "(- a) - (- b) = - (a - b)"
   3.185 -by simp
   3.186 -
   3.187  lemma LIMSEQ_add:
   3.188    fixes a b :: "'a::real_normed_vector"
   3.189    shows "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n + Y n) ----> a + b"
   3.190 -by (simp only: LIMSEQ_Zseq_iff add_diff_add Zseq_add)
   3.191 +unfolding LIMSEQ_conv_tendsto by (rule tendsto_add)
   3.192  
   3.193  lemma LIMSEQ_minus:
   3.194    fixes a :: "'a::real_normed_vector"
   3.195    shows "X ----> a \<Longrightarrow> (\<lambda>n. - X n) ----> - a"
   3.196 -by (simp only: LIMSEQ_Zseq_iff minus_diff_minus Zseq_minus)
   3.197 +unfolding LIMSEQ_conv_tendsto by (rule tendsto_minus)
   3.198  
   3.199  lemma LIMSEQ_minus_cancel:
   3.200    fixes a :: "'a::real_normed_vector"
   3.201 @@ -410,7 +337,7 @@
   3.202  lemma LIMSEQ_diff:
   3.203    fixes a b :: "'a::real_normed_vector"
   3.204    shows "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n - Y n) ----> a - b"
   3.205 -by (simp add: diff_minus LIMSEQ_add LIMSEQ_minus)
   3.206 +unfolding LIMSEQ_conv_tendsto by (rule tendsto_diff)
   3.207  
   3.208  lemma LIMSEQ_unique: "\<lbrakk>X ----> a; X ----> b\<rbrakk> \<Longrightarrow> a = b"
   3.209  apply (rule ccontr)
   3.210 @@ -425,12 +352,11 @@
   3.211  
   3.212  lemma (in bounded_linear) LIMSEQ:
   3.213    "X ----> a \<Longrightarrow> (\<lambda>n. f (X n)) ----> f a"
   3.214 -by (simp only: LIMSEQ_Zseq_iff diff [symmetric] Zseq)
   3.215 +unfolding LIMSEQ_conv_tendsto by (rule tendsto)
   3.216  
   3.217  lemma (in bounded_bilinear) LIMSEQ:
   3.218    "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n ** Y n) ----> a ** b"
   3.219 -by (simp only: LIMSEQ_Zseq_iff prod_diff_prod
   3.220 -               Zseq_add Zseq Zseq_left Zseq_right)
   3.221 +unfolding LIMSEQ_conv_tendsto by (rule tendsto)
   3.222  
   3.223  lemma LIMSEQ_mult:
   3.224    fixes a b :: "'a::real_normed_algebra"