new theory of filters and limits; prove LIMSEQ and LIM lemmas using filters
authorhuffman
Sun, 31 May 2009 21:59:33 -0700
changeset 31349 2261c8781f73
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
--- a/src/HOL/Lim.thy	Sun May 31 11:27:19 2009 -0700
+++ b/src/HOL/Lim.thy	Sun May 31 21:59:33 2009 -0700
@@ -13,6 +13,10 @@
 text{*Standard Definitions*}
 
 definition
+  at :: "'a::metric_space \<Rightarrow> 'a filter" where
+  "at a = Abs_filter (\<lambda>P. \<exists>r>0. \<forall>x. x \<noteq> a \<and> dist x a < r \<longrightarrow> P x)"
+
+definition
   LIM :: "['a::metric_space \<Rightarrow> 'b::metric_space, 'a, 'b] \<Rightarrow> bool"
         ("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60) where
   [code del]: "f -- a --> L =
@@ -27,6 +31,20 @@
   isUCont :: "['a::metric_space \<Rightarrow> 'b::metric_space] \<Rightarrow> bool" where
   [code del]: "isUCont f = (\<forall>r>0. \<exists>s>0. \<forall>x y. dist x y < s \<longrightarrow> dist (f x) (f y) < r)"
 
+subsection {* Neighborhood Filter *}
+
+lemma eventually_at:
+  "eventually P (at a) \<longleftrightarrow> (\<exists>d>0. \<forall>x. x \<noteq> a \<and> dist x a < d \<longrightarrow> P x)"
+unfolding at_def
+apply (rule eventually_Abs_filter)
+apply (rule_tac x=1 in exI, simp)
+apply (clarify, rule_tac x=r in exI, simp)
+apply (clarify, rename_tac r s)
+apply (rule_tac x="min r s" in exI, simp)
+done
+
+lemma LIM_conv_tendsto: "(f -- a --> L) \<longleftrightarrow> tendsto f L (at a)"
+unfolding LIM_def tendsto_def eventually_at ..
 
 subsection {* Limits of Functions *}
 
@@ -86,33 +104,7 @@
   fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   assumes f: "f -- a --> L" and g: "g -- a --> M"
   shows "(\<lambda>x. f x + g x) -- a --> (L + M)"
-proof (rule metric_LIM_I)
-  fix r :: real
-  assume r: "0 < r"
-  from metric_LIM_D [OF f half_gt_zero [OF r]]
-  obtain fs
-    where fs:    "0 < fs"
-      and fs_lt: "\<forall>x. x \<noteq> a \<and> dist x a < fs \<longrightarrow> dist (f x) L < r/2"
-  by blast
-  from metric_LIM_D [OF g half_gt_zero [OF r]]
-  obtain gs
-    where gs:    "0 < gs"
-      and gs_lt: "\<forall>x. x \<noteq> a \<and> dist x a < gs \<longrightarrow> dist (g x) M < r/2"
-  by blast
-  show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> dist (f x + g x) (L + M) < r"
-  proof (intro exI conjI strip)
-    show "0 < min fs gs"  by (simp add: fs gs)
-    fix x :: 'a
-    assume "x \<noteq> a \<and> dist x a < min fs gs"
-    hence "x \<noteq> a \<and> dist x a < fs \<and> dist x a < gs" by simp
-    with fs_lt gs_lt
-    have "dist (f x) L < r/2" and "dist (g x) M < r/2" by blast+
-    hence "dist (f x) L + dist (g x) M < r" by arith
-    thus "dist (f x + g x) (L + M) < r"
-      unfolding dist_norm
-      by (blast intro: norm_diff_triangle_ineq order_le_less_trans)
-  qed
-qed
+using assms unfolding LIM_conv_tendsto by (rule tendsto_add)
 
 lemma LIM_add_zero:
   fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
@@ -127,7 +119,7 @@
 lemma LIM_minus:
   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   shows "f -- a --> L \<Longrightarrow> (\<lambda>x. - f x) -- a --> - L"
-by (simp only: LIM_def dist_norm minus_diff_minus norm_minus_cancel)
+unfolding LIM_conv_tendsto by (rule tendsto_minus)
 
 (* TODO: delete *)
 lemma LIM_add_minus:
@@ -138,7 +130,7 @@
 lemma LIM_diff:
   fixes f g :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   shows "\<lbrakk>f -- x --> l; g -- x --> m\<rbrakk> \<Longrightarrow> (\<lambda>x. f x - g x) -- x --> l - m"
-by (simp only: diff_minus LIM_add LIM_minus)
+unfolding LIM_conv_tendsto by (rule tendsto_diff)
 
 lemma LIM_zero:
   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
@@ -178,7 +170,7 @@
 lemma LIM_norm:
   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
   shows "f -- a --> l \<Longrightarrow> (\<lambda>x. norm (f x)) -- a --> norm l"
-by (erule LIM_imp_LIM, simp add: norm_triangle_ineq3)
+unfolding LIM_conv_tendsto by (rule tendsto_norm)
 
 lemma LIM_norm_zero:
   fixes f :: "'a::metric_space \<Rightarrow> 'b::real_normed_vector"
@@ -369,26 +361,12 @@
 
 text {* Bounded Linear Operators *}
 
-lemma (in bounded_linear) cont: "f -- a --> f a"
-proof (rule LIM_I)
-  fix r::real assume r: "0 < r"
-  obtain K where K: "0 < K" and norm_le: "\<And>x. norm (f x) \<le> norm x * K"
-    using pos_bounded by fast
-  show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> norm (x - a) < s \<longrightarrow> norm (f x - f a) < r"
-  proof (rule exI, safe)
-    from r K show "0 < r / K" by (rule divide_pos_pos)
-  next
-    fix x assume x: "norm (x - a) < r / K"
-    have "norm (f x - f a) = norm (f (x - a))" by (simp only: diff)
-    also have "\<dots> \<le> norm (x - a) * K" by (rule norm_le)
-    also from K x have "\<dots> < r" by (simp only: pos_less_divide_eq)
-    finally show "norm (f x - f a) < r" .
-  qed
-qed
-
 lemma (in bounded_linear) LIM:
   "g -- a --> l \<Longrightarrow> (\<lambda>x. f (g x)) -- a --> f l"
-by (rule LIM_compose [OF cont])
+unfolding LIM_conv_tendsto by (rule tendsto)
+
+lemma (in bounded_linear) cont: "f -- a --> f a"
+by (rule LIM [OF LIM_ident])
 
 lemma (in bounded_linear) LIM_zero:
   "g -- a --> 0 \<Longrightarrow> (\<lambda>x. f (g x)) -- a --> 0"
@@ -396,40 +374,16 @@
 
 text {* Bounded Bilinear Operators *}
 
+lemma (in bounded_bilinear) LIM:
+  "\<lbrakk>f -- a --> L; g -- a --> M\<rbrakk> \<Longrightarrow> (\<lambda>x. f x ** g x) -- a --> L ** M"
+unfolding LIM_conv_tendsto by (rule tendsto)
+
 lemma (in bounded_bilinear) LIM_prod_zero:
   fixes a :: "'d::metric_space"
   assumes f: "f -- a --> 0"
   assumes g: "g -- a --> 0"
   shows "(\<lambda>x. f x ** g x) -- a --> 0"
-proof (rule metric_LIM_I, unfold dist_norm)
-  fix r::real assume r: "0 < r"
-  obtain K where K: "0 < K"
-    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
-    using pos_bounded by fast
-  from K have K': "0 < inverse K"
-    by (rule positive_imp_inverse_positive)
-  obtain s where s: "0 < s"
-    and norm_f: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < s\<rbrakk> \<Longrightarrow> norm (f x) < r"
-    using metric_LIM_D [OF f r, unfolded dist_norm] by auto
-  obtain t where t: "0 < t"
-    and norm_g: "\<And>x. \<lbrakk>x \<noteq> a; dist x a < t\<rbrakk> \<Longrightarrow> norm (g x) < inverse K"
-    using metric_LIM_D [OF g K', unfolded dist_norm] by auto
-  show "\<exists>s>0. \<forall>x. x \<noteq> a \<and> dist x a < s \<longrightarrow> norm (f x ** g x - 0) < r"
-  proof (rule exI, safe)
-    from s t show "0 < min s t" by simp
-  next
-    fix x assume x: "x \<noteq> a"
-    assume "dist x a < min s t"
-    hence xs: "dist x a < s" and xt: "dist x a < t" by simp_all
-    from x xs have 1: "norm (f x) < r" by (rule norm_f)
-    from x xt have 2: "norm (g x) < inverse K" by (rule norm_g)
-    have "norm (f x ** g x) \<le> norm (f x) * norm (g x) * K" by (rule norm_le)
-    also from 1 2 K have "\<dots> < r * inverse K * K"
-      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero)
-    also from K have "r * inverse K * K = r" by simp
-    finally show "norm (f x ** g x - 0) < r" by simp
-  qed
-qed
+using LIM [OF f g] by (simp add: zero_left)
 
 lemma (in bounded_bilinear) LIM_left_zero:
   "f -- a --> 0 \<Longrightarrow> (\<lambda>x. f x ** c) -- a --> 0"
@@ -439,19 +393,6 @@
   "f -- a --> 0 \<Longrightarrow> (\<lambda>x. c ** f x) -- a --> 0"
 by (rule bounded_linear.LIM_zero [OF bounded_linear_right])
 
-lemma (in bounded_bilinear) LIM:
-  "\<lbrakk>f -- a --> L; g -- a --> M\<rbrakk> \<Longrightarrow> (\<lambda>x. f x ** g x) -- a --> L ** M"
-apply (drule LIM_zero)
-apply (drule LIM_zero)
-apply (rule LIM_zero_cancel)
-apply (subst prod_diff_prod)
-apply (rule LIM_add_zero)
-apply (rule LIM_add_zero)
-apply (erule (1) LIM_prod_zero)
-apply (erule LIM_left_zero)
-apply (erule LIM_right_zero)
-done
-
 lemmas LIM_mult = mult.LIM
 
 lemmas LIM_mult_zero = mult.LIM_prod_zero
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/HOL/Limits.thy	Sun May 31 21:59:33 2009 -0700
@@ -0,0 +1,296 @@
+(*  Title       : Limits.thy
+    Author      : Brian Huffman
+*)
+
+header {* Filters and Limits *}
+
+theory Limits
+imports RealVector RComplete
+begin
+
+subsection {* Filters *}
+
+typedef (open) 'a filter =
+  "{f :: ('a \<Rightarrow> bool) \<Rightarrow> bool. f (\<lambda>x. True)
+    \<and> (\<forall>P Q. (\<forall>x. P x \<longrightarrow> Q x) \<longrightarrow> f P \<longrightarrow> f Q)
+    \<and> (\<forall>P Q. f P \<longrightarrow> f Q \<longrightarrow> f (\<lambda>x. P x \<and> Q x))}"
+proof
+  show "(\<lambda>P. True) \<in> ?filter" by simp
+qed
+
+definition
+  eventually :: "('a \<Rightarrow> bool) \<Rightarrow> 'a filter \<Rightarrow> bool" where
+  "eventually P F \<longleftrightarrow> Rep_filter F P"
+
+lemma eventually_True [simp]: "eventually (\<lambda>x. True) F"
+unfolding eventually_def using Rep_filter [of F] by blast
+
+lemma eventually_mono:
+  "(\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> eventually P F \<Longrightarrow> eventually Q F"
+unfolding eventually_def using Rep_filter [of F] by blast
+
+lemma eventually_conj:
+  "\<lbrakk>eventually (\<lambda>x. P x) F; eventually (\<lambda>x. Q x) F\<rbrakk>
+    \<Longrightarrow> eventually (\<lambda>x. P x \<and> Q x) F"
+unfolding eventually_def using Rep_filter [of F] by blast
+
+lemma eventually_mp:
+  assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
+  assumes "eventually (\<lambda>x. P x) F"
+  shows "eventually (\<lambda>x. Q x) F"
+proof (rule eventually_mono)
+  show "\<forall>x. (P x \<longrightarrow> Q x) \<and> P x \<longrightarrow> Q x" by simp
+  show "eventually (\<lambda>x. (P x \<longrightarrow> Q x) \<and> P x) F"
+    using assms by (rule eventually_conj)
+qed
+
+lemma eventually_rev_mp:
+  assumes "eventually (\<lambda>x. P x) F"
+  assumes "eventually (\<lambda>x. P x \<longrightarrow> Q x) F"
+  shows "eventually (\<lambda>x. Q x) F"
+using assms(2) assms(1) by (rule eventually_mp)
+
+lemma eventually_conj_iff:
+  "eventually (\<lambda>x. P x \<and> Q x) net \<longleftrightarrow> eventually P net \<and> eventually Q net"
+by (auto intro: eventually_conj elim: eventually_rev_mp)
+
+lemma eventually_Abs_filter:
+  assumes "f (\<lambda>x. True)"
+  assumes "\<And>P Q. (\<forall>x. P x \<longrightarrow> Q x) \<Longrightarrow> f P \<Longrightarrow> f Q"
+  assumes "\<And>P Q. f P \<Longrightarrow> f Q \<Longrightarrow> f (\<lambda>x. P x \<and> Q x)"
+  shows "eventually P (Abs_filter f) \<longleftrightarrow> f P"
+unfolding eventually_def using assms
+by (subst Abs_filter_inverse, auto)
+
+lemma filter_ext:
+  "(\<And>P. eventually P F \<longleftrightarrow> eventually P F') \<Longrightarrow> F = F'"
+unfolding eventually_def
+by (simp add: Rep_filter_inject [THEN iffD1] ext)
+
+lemma eventually_elim1:
+  assumes "eventually (\<lambda>i. P i) F"
+  assumes "\<And>i. P i \<Longrightarrow> Q i"
+  shows "eventually (\<lambda>i. Q i) F"
+using assms by (auto elim!: eventually_rev_mp)
+
+lemma eventually_elim2:
+  assumes "eventually (\<lambda>i. P i) F"
+  assumes "eventually (\<lambda>i. Q i) F"
+  assumes "\<And>i. P i \<Longrightarrow> Q i \<Longrightarrow> R i"
+  shows "eventually (\<lambda>i. R i) F"
+using assms by (auto elim!: eventually_rev_mp)
+
+
+subsection {* Convergence to Zero *}
+
+definition
+  Zfun :: "('a \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'a filter \<Rightarrow> bool" where
+  "Zfun S F = (\<forall>r>0. eventually (\<lambda>i. norm (S i) < r) F)"
+
+lemma ZfunI:
+  "(\<And>r. 0 < r \<Longrightarrow> eventually (\<lambda>i. norm (S i) < r) F) \<Longrightarrow> Zfun S F"
+unfolding Zfun_def by simp
+
+lemma ZfunD:
+  "\<lbrakk>Zfun S F; 0 < r\<rbrakk> \<Longrightarrow> eventually (\<lambda>i. norm (S i) < r) F"
+unfolding Zfun_def by simp
+
+lemma Zfun_zero: "Zfun (\<lambda>i. 0) F"
+unfolding Zfun_def by simp
+
+lemma Zfun_norm_iff: "Zfun (\<lambda>i. norm (S i)) F = Zfun (\<lambda>i. S i) F"
+unfolding Zfun_def by simp
+
+lemma Zfun_imp_Zfun:
+  assumes X: "Zfun X F"
+  assumes Y: "\<And>n. norm (Y n) \<le> norm (X n) * K"
+  shows "Zfun (\<lambda>n. Y n) F"
+proof (cases)
+  assume K: "0 < K"
+  show ?thesis
+  proof (rule ZfunI)
+    fix r::real assume "0 < r"
+    hence "0 < r / K"
+      using K by (rule divide_pos_pos)
+    then have "eventually (\<lambda>i. norm (X i) < r / K) F"
+      using ZfunD [OF X] by fast
+    then show "eventually (\<lambda>i. norm (Y i) < r) F"
+    proof (rule eventually_elim1)
+      fix i assume "norm (X i) < r / K"
+      hence "norm (X i) * K < r"
+        by (simp add: pos_less_divide_eq K)
+      thus "norm (Y i) < r"
+        by (simp add: order_le_less_trans [OF Y])
+    qed
+  qed
+next
+  assume "\<not> 0 < K"
+  hence K: "K \<le> 0" by (simp only: not_less)
+  {
+    fix i
+    have "norm (Y i) \<le> norm (X i) * K" by (rule Y)
+    also have "\<dots> \<le> norm (X i) * 0"
+      using K norm_ge_zero by (rule mult_left_mono)
+    finally have "norm (Y i) = 0" by simp
+  }
+  thus ?thesis by (simp add: Zfun_zero)
+qed
+
+lemma Zfun_le: "\<lbrakk>Zfun Y F; \<forall>n. norm (X n) \<le> norm (Y n)\<rbrakk> \<Longrightarrow> Zfun X F"
+by (erule_tac K="1" in Zfun_imp_Zfun, simp)
+
+lemma Zfun_add:
+  assumes X: "Zfun X F" and Y: "Zfun Y F"
+  shows "Zfun (\<lambda>n. X n + Y n) F"
+proof (rule ZfunI)
+  fix r::real assume "0 < r"
+  hence r: "0 < r / 2" by simp
+  have "eventually (\<lambda>i. norm (X i) < r/2) F"
+    using X r by (rule ZfunD)
+  moreover
+  have "eventually (\<lambda>i. norm (Y i) < r/2) F"
+    using Y r by (rule ZfunD)
+  ultimately
+  show "eventually (\<lambda>i. norm (X i + Y i) < r) F"
+  proof (rule eventually_elim2)
+    fix i
+    assume *: "norm (X i) < r/2" "norm (Y i) < r/2"
+    have "norm (X i + Y i) \<le> norm (X i) + norm (Y i)"
+      by (rule norm_triangle_ineq)
+    also have "\<dots> < r/2 + r/2"
+      using * by (rule add_strict_mono)
+    finally show "norm (X i + Y i) < r"
+      by simp
+  qed
+qed
+
+lemma Zfun_minus: "Zfun X F \<Longrightarrow> Zfun (\<lambda>i. - X i) F"
+unfolding Zfun_def by simp
+
+lemma Zfun_diff: "\<lbrakk>Zfun X F; Zfun Y F\<rbrakk> \<Longrightarrow> Zfun (\<lambda>i. X i - Y i) F"
+by (simp only: diff_minus Zfun_add Zfun_minus)
+
+lemma (in bounded_linear) Zfun:
+  assumes X: "Zfun X F"
+  shows "Zfun (\<lambda>n. f (X n)) F"
+proof -
+  obtain K where "\<And>x. norm (f x) \<le> norm x * K"
+    using bounded by fast
+  with X show ?thesis
+    by (rule Zfun_imp_Zfun)
+qed
+
+lemma (in bounded_bilinear) Zfun:
+  assumes X: "Zfun X F"
+  assumes Y: "Zfun Y F"
+  shows "Zfun (\<lambda>n. X n ** Y n) F"
+proof (rule ZfunI)
+  fix r::real assume r: "0 < r"
+  obtain K where K: "0 < K"
+    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
+    using pos_bounded by fast
+  from K have K': "0 < inverse K"
+    by (rule positive_imp_inverse_positive)
+  have "eventually (\<lambda>i. norm (X i) < r) F"
+    using X r by (rule ZfunD)
+  moreover
+  have "eventually (\<lambda>i. norm (Y i) < inverse K) F"
+    using Y K' by (rule ZfunD)
+  ultimately
+  show "eventually (\<lambda>i. norm (X i ** Y i) < r) F"
+  proof (rule eventually_elim2)
+    fix i
+    assume *: "norm (X i) < r" "norm (Y i) < inverse K"
+    have "norm (X i ** Y i) \<le> norm (X i) * norm (Y i) * K"
+      by (rule norm_le)
+    also have "norm (X i) * norm (Y i) * K < r * inverse K * K"
+      by (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero * K)
+    also from K have "r * inverse K * K = r"
+      by simp
+    finally show "norm (X i ** Y i) < r" .
+  qed
+qed
+
+lemma (in bounded_bilinear) Zfun_left:
+  "Zfun X F \<Longrightarrow> Zfun (\<lambda>n. X n ** a) F"
+by (rule bounded_linear_left [THEN bounded_linear.Zfun])
+
+lemma (in bounded_bilinear) Zfun_right:
+  "Zfun X F \<Longrightarrow> Zfun (\<lambda>n. a ** X n) F"
+by (rule bounded_linear_right [THEN bounded_linear.Zfun])
+
+lemmas Zfun_mult = mult.Zfun
+lemmas Zfun_mult_right = mult.Zfun_right
+lemmas Zfun_mult_left = mult.Zfun_left
+
+
+subsection{* Limits *}
+
+definition
+  tendsto :: "('a \<Rightarrow> 'b::metric_space) \<Rightarrow> 'b \<Rightarrow> 'a filter \<Rightarrow> bool" where
+  "tendsto f l net \<longleftrightarrow> (\<forall>e>0. eventually (\<lambda>x. dist (f x) l < e) net)"
+
+lemma tendstoI:
+  "(\<And>e. 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) net)
+    \<Longrightarrow> tendsto f l net"
+  unfolding tendsto_def by auto
+
+lemma tendstoD:
+  "tendsto f l net \<Longrightarrow> 0 < e \<Longrightarrow> eventually (\<lambda>x. dist (f x) l < e) net"
+  unfolding tendsto_def by auto
+
+lemma tendsto_Zfun_iff: "tendsto (\<lambda>n. X n) L F = Zfun (\<lambda>n. X n - L) F"
+by (simp only: tendsto_def Zfun_def dist_norm)
+
+lemma tendsto_const: "tendsto (\<lambda>n. k) k F"
+by (simp add: tendsto_def)
+
+lemma tendsto_norm:
+  fixes a :: "'a::real_normed_vector"
+  shows "tendsto X a F \<Longrightarrow> tendsto (\<lambda>n. norm (X n)) (norm a) F"
+apply (simp add: tendsto_def dist_norm, safe)
+apply (drule_tac x="e" in spec, safe)
+apply (erule eventually_elim1)
+apply (erule order_le_less_trans [OF norm_triangle_ineq3])
+done
+
+lemma add_diff_add:
+  fixes a b c d :: "'a::ab_group_add"
+  shows "(a + c) - (b + d) = (a - b) + (c - d)"
+by simp
+
+lemma minus_diff_minus:
+  fixes a b :: "'a::ab_group_add"
+  shows "(- a) - (- b) = - (a - b)"
+by simp
+
+lemma tendsto_add:
+  fixes a b :: "'a::real_normed_vector"
+  shows "\<lbrakk>tendsto X a F; tendsto Y b F\<rbrakk> \<Longrightarrow> tendsto (\<lambda>n. X n + Y n) (a + b) F"
+by (simp only: tendsto_Zfun_iff add_diff_add Zfun_add)
+
+lemma tendsto_minus:
+  fixes a :: "'a::real_normed_vector"
+  shows "tendsto X a F \<Longrightarrow> tendsto (\<lambda>n. - X n) (- a) F"
+by (simp only: tendsto_Zfun_iff minus_diff_minus Zfun_minus)
+
+lemma tendsto_minus_cancel:
+  fixes a :: "'a::real_normed_vector"
+  shows "tendsto (\<lambda>n. - X n) (- a) F \<Longrightarrow> tendsto X a F"
+by (drule tendsto_minus, simp)
+
+lemma tendsto_diff:
+  fixes a b :: "'a::real_normed_vector"
+  shows "\<lbrakk>tendsto X a F; tendsto Y b F\<rbrakk> \<Longrightarrow> tendsto (\<lambda>n. X n - Y n) (a - b) F"
+by (simp add: diff_minus tendsto_add tendsto_minus)
+
+lemma (in bounded_linear) tendsto:
+  "tendsto X a F \<Longrightarrow> tendsto (\<lambda>n. f (X n)) (f a) F"
+by (simp only: tendsto_Zfun_iff diff [symmetric] Zfun)
+
+lemma (in bounded_bilinear) tendsto:
+  "\<lbrakk>tendsto X a F; tendsto Y b F\<rbrakk> \<Longrightarrow> tendsto (\<lambda>n. X n ** Y n) (a ** b) F"
+by (simp only: tendsto_Zfun_iff prod_diff_prod
+               Zfun_add Zfun Zfun_left Zfun_right)
+
+end
--- a/src/HOL/SEQ.thy	Sun May 31 11:27:19 2009 -0700
+++ b/src/HOL/SEQ.thy	Sun May 31 21:59:33 2009 -0700
@@ -9,10 +9,14 @@
 header {* Sequences and Convergence *}
 
 theory SEQ
-imports RealVector RComplete
+imports Limits
 begin
 
 definition
+  sequentially :: "nat filter" where
+  "sequentially = Abs_filter (\<lambda>P. \<exists>N. \<forall>n\<ge>N. P n)"
+
+definition
   Zseq :: "[nat \<Rightarrow> 'a::real_normed_vector] \<Rightarrow> bool" where
     --{*Standard definition of sequence converging to zero*}
   [code del]: "Zseq X = (\<forall>r>0. \<exists>no. \<forall>n\<ge>no. norm (X n) < r)"
@@ -67,6 +71,24 @@
   [code del]: "Cauchy X = (\<forall>e>0. \<exists>M. \<forall>m \<ge> M. \<forall>n \<ge> M. dist (X m) (X n) < e)"
 
 
+subsection {* Sequentially *}
+
+lemma eventually_sequentially:
+  "eventually P sequentially \<longleftrightarrow> (\<exists>N. \<forall>n\<ge>N. P n)"
+unfolding sequentially_def
+apply (rule eventually_Abs_filter)
+apply simp
+apply (clarify, rule_tac x=N in exI, simp)
+apply (clarify, rename_tac M N)
+apply (rule_tac x="max M N" in exI, simp)
+done
+
+lemma Zseq_conv_Zfun: "Zseq X \<longleftrightarrow> Zfun X sequentially"
+unfolding Zseq_def Zfun_def eventually_sequentially ..
+
+lemma LIMSEQ_conv_tendsto: "(X ----> L) \<longleftrightarrow> tendsto X L sequentially"
+unfolding LIMSEQ_def tendsto_def eventually_sequentially ..
+
 subsection {* Bounded Sequences *}
 
 lemma BseqI': assumes K: "\<And>n. norm (X n) \<le> K" shows "Bseq X"
@@ -134,61 +156,14 @@
   assumes X: "Zseq X"
   assumes Y: "\<And>n. norm (Y n) \<le> norm (X n) * K"
   shows "Zseq (\<lambda>n. Y n)"
-proof (cases)
-  assume K: "0 < K"
-  show ?thesis
-  proof (rule ZseqI)
-    fix r::real assume "0 < r"
-    hence "0 < r / K"
-      using K by (rule divide_pos_pos)
-    then obtain N where "\<forall>n\<ge>N. norm (X n) < r / K"
-      using ZseqD [OF X] by fast
-    hence "\<forall>n\<ge>N. norm (X n) * K < r"
-      by (simp add: pos_less_divide_eq K)
-    hence "\<forall>n\<ge>N. norm (Y n) < r"
-      by (simp add: order_le_less_trans [OF Y])
-    thus "\<exists>N. \<forall>n\<ge>N. norm (Y n) < r" ..
-  qed
-next
-  assume "\<not> 0 < K"
-  hence K: "K \<le> 0" by (simp only: linorder_not_less)
-  {
-    fix n::nat
-    have "norm (Y n) \<le> norm (X n) * K" by (rule Y)
-    also have "\<dots> \<le> norm (X n) * 0"
-      using K norm_ge_zero by (rule mult_left_mono)
-    finally have "norm (Y n) = 0" by simp
-  }
-  thus ?thesis by (simp add: Zseq_zero)
-qed
+using assms unfolding Zseq_conv_Zfun by (rule Zfun_imp_Zfun)
 
 lemma Zseq_le: "\<lbrakk>Zseq Y; \<forall>n. norm (X n) \<le> norm (Y n)\<rbrakk> \<Longrightarrow> Zseq X"
 by (erule_tac K="1" in Zseq_imp_Zseq, simp)
 
 lemma Zseq_add:
-  assumes X: "Zseq X"
-  assumes Y: "Zseq Y"
-  shows "Zseq (\<lambda>n. X n + Y n)"
-proof (rule ZseqI)
-  fix r::real assume "0 < r"
-  hence r: "0 < r / 2" by simp
-  obtain M where M: "\<forall>n\<ge>M. norm (X n) < r/2"
-    using ZseqD [OF X r] by fast
-  obtain N where N: "\<forall>n\<ge>N. norm (Y n) < r/2"
-    using ZseqD [OF Y r] by fast
-  show "\<exists>N. \<forall>n\<ge>N. norm (X n + Y n) < r"
-  proof (intro exI allI impI)
-    fix n assume n: "max M N \<le> n"
-    have "norm (X n + Y n) \<le> norm (X n) + norm (Y n)"
-      by (rule norm_triangle_ineq)
-    also have "\<dots> < r/2 + r/2"
-    proof (rule add_strict_mono)
-      from M n show "norm (X n) < r/2" by simp
-      from N n show "norm (Y n) < r/2" by simp
-    qed
-    finally show "norm (X n + Y n) < r" by simp
-  qed
-qed
+  "Zseq X \<Longrightarrow> Zseq Y \<Longrightarrow> Zseq (\<lambda>n. X n + Y n)"
+unfolding Zseq_conv_Zfun by (rule Zfun_add)
 
 lemma Zseq_minus: "Zseq X \<Longrightarrow> Zseq (\<lambda>n. - X n)"
 unfolding Zseq_def by simp
@@ -197,44 +172,12 @@
 by (simp only: diff_minus Zseq_add Zseq_minus)
 
 lemma (in bounded_linear) Zseq:
-  assumes X: "Zseq X"
-  shows "Zseq (\<lambda>n. f (X n))"
-proof -
-  obtain K where "\<And>x. norm (f x) \<le> norm x * K"
-    using bounded by fast
-  with X show ?thesis
-    by (rule Zseq_imp_Zseq)
-qed
+  "Zseq X \<Longrightarrow> Zseq (\<lambda>n. f (X n))"
+unfolding Zseq_conv_Zfun by (rule Zfun)
 
 lemma (in bounded_bilinear) Zseq:
-  assumes X: "Zseq X"
-  assumes Y: "Zseq Y"
-  shows "Zseq (\<lambda>n. X n ** Y n)"
-proof (rule ZseqI)
-  fix r::real assume r: "0 < r"
-  obtain K where K: "0 < K"
-    and norm_le: "\<And>x y. norm (x ** y) \<le> norm x * norm y * K"
-    using pos_bounded by fast
-  from K have K': "0 < inverse K"
-    by (rule positive_imp_inverse_positive)
-  obtain M where M: "\<forall>n\<ge>M. norm (X n) < r"
-    using ZseqD [OF X r] by fast
-  obtain N where N: "\<forall>n\<ge>N. norm (Y n) < inverse K"
-    using ZseqD [OF Y K'] by fast
-  show "\<exists>N. \<forall>n\<ge>N. norm (X n ** Y n) < r"
-  proof (intro exI allI impI)
-    fix n assume n: "max M N \<le> n"
-    have "norm (X n ** Y n) \<le> norm (X n) * norm (Y n) * K"
-      by (rule norm_le)
-    also have "norm (X n) * norm (Y n) * K < r * inverse K * K"
-    proof (intro mult_strict_right_mono mult_strict_mono' norm_ge_zero K)
-      from M n show Xn: "norm (X n) < r" by simp
-      from N n show Yn: "norm (Y n) < inverse K" by simp
-    qed
-    also from K have "r * inverse K * K = r" by simp
-    finally show "norm (X n ** Y n) < r" .
-  qed
-qed
+  "Zseq X \<Longrightarrow> Zseq Y \<Longrightarrow> Zseq (\<lambda>n. X n ** Y n)"
+unfolding Zseq_conv_Zfun by (rule Zfun)
 
 lemma (in bounded_bilinear) Zseq_prod_Bseq:
   assumes X: "Zseq X"
@@ -341,12 +284,7 @@
 lemma LIMSEQ_norm:
   fixes a :: "'a::real_normed_vector"
   shows "X ----> a \<Longrightarrow> (\<lambda>n. norm (X n)) ----> norm a"
-apply (simp add: LIMSEQ_iff, safe)
-apply (drule_tac x="r" in spec, safe)
-apply (rule_tac x="no" in exI, safe)
-apply (drule_tac x="n" in spec, safe)
-apply (erule order_le_less_trans [OF norm_triangle_ineq3])
-done
+unfolding LIMSEQ_conv_tendsto by (rule tendsto_norm)
 
 lemma LIMSEQ_ignore_initial_segment:
   "f ----> a \<Longrightarrow> (\<lambda>n. f (n + k)) ----> a"
@@ -381,26 +319,15 @@
   unfolding LIMSEQ_def
   by (metis div_le_dividend div_mult_self1_is_m le_trans nat_mult_commute)
 
-
-lemma add_diff_add:
-  fixes a b c d :: "'a::ab_group_add"
-  shows "(a + c) - (b + d) = (a - b) + (c - d)"
-by simp
-
-lemma minus_diff_minus:
-  fixes a b :: "'a::ab_group_add"
-  shows "(- a) - (- b) = - (a - b)"
-by simp
-
 lemma LIMSEQ_add:
   fixes a b :: "'a::real_normed_vector"
   shows "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n + Y n) ----> a + b"
-by (simp only: LIMSEQ_Zseq_iff add_diff_add Zseq_add)
+unfolding LIMSEQ_conv_tendsto by (rule tendsto_add)
 
 lemma LIMSEQ_minus:
   fixes a :: "'a::real_normed_vector"
   shows "X ----> a \<Longrightarrow> (\<lambda>n. - X n) ----> - a"
-by (simp only: LIMSEQ_Zseq_iff minus_diff_minus Zseq_minus)
+unfolding LIMSEQ_conv_tendsto by (rule tendsto_minus)
 
 lemma LIMSEQ_minus_cancel:
   fixes a :: "'a::real_normed_vector"
@@ -410,7 +337,7 @@
 lemma LIMSEQ_diff:
   fixes a b :: "'a::real_normed_vector"
   shows "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n - Y n) ----> a - b"
-by (simp add: diff_minus LIMSEQ_add LIMSEQ_minus)
+unfolding LIMSEQ_conv_tendsto by (rule tendsto_diff)
 
 lemma LIMSEQ_unique: "\<lbrakk>X ----> a; X ----> b\<rbrakk> \<Longrightarrow> a = b"
 apply (rule ccontr)
@@ -425,12 +352,11 @@
 
 lemma (in bounded_linear) LIMSEQ:
   "X ----> a \<Longrightarrow> (\<lambda>n. f (X n)) ----> f a"
-by (simp only: LIMSEQ_Zseq_iff diff [symmetric] Zseq)
+unfolding LIMSEQ_conv_tendsto by (rule tendsto)
 
 lemma (in bounded_bilinear) LIMSEQ:
   "\<lbrakk>X ----> a; Y ----> b\<rbrakk> \<Longrightarrow> (\<lambda>n. X n ** Y n) ----> a ** b"
-by (simp only: LIMSEQ_Zseq_iff prod_diff_prod
-               Zseq_add Zseq Zseq_left Zseq_right)
+unfolding LIMSEQ_conv_tendsto by (rule tendsto)
 
 lemma LIMSEQ_mult:
   fixes a b :: "'a::real_normed_algebra"