author | paulson <lp15@cam.ac.uk> |
Tue, 10 Nov 2015 14:43:29 +0000 | |
changeset 61610 | 4f54d2759a0b |
parent 61609 | 77b453bd616f |
parent 61560 | 7c985fd653c5 |
child 61711 | 21d7910d6816 |
permissions | -rw-r--r-- |
61560 | 1 |
section \<open>Bernstein-Weierstrass and Stone-Weierstrass Theorems\<close> |
60987 | 2 |
|
3 |
theory Weierstrass |
|
4 |
imports Uniform_Limit Path_Connected |
|
5 |
begin |
|
6 |
||
7 |
(*Power.thy:*) |
|
8 |
declare power_divide [where b = "numeral w" for w, simp del] |
|
9 |
||
61222 | 10 |
subsection \<open>Bernstein polynomials\<close> |
60987 | 11 |
|
12 |
definition Bernstein :: "[nat,nat,real] \<Rightarrow> real" where |
|
13 |
"Bernstein n k x \<equiv> of_nat (n choose k) * x ^ k * (1 - x) ^ (n - k)" |
|
14 |
||
15 |
lemma Bernstein_nonneg: "\<lbrakk>0 \<le> x; x \<le> 1\<rbrakk> \<Longrightarrow> 0 \<le> Bernstein n k x" |
|
16 |
by (simp add: Bernstein_def) |
|
17 |
||
18 |
lemma Bernstein_pos: "\<lbrakk>0 < x; x < 1; k \<le> n\<rbrakk> \<Longrightarrow> 0 < Bernstein n k x" |
|
19 |
by (simp add: Bernstein_def) |
|
20 |
||
21 |
lemma sum_Bernstein [simp]: "(\<Sum> k = 0..n. Bernstein n k x) = 1" |
|
22 |
using binomial_ring [of x "1-x" n] |
|
23 |
by (simp add: Bernstein_def) |
|
24 |
||
25 |
lemma binomial_deriv1: |
|
26 |
"(\<Sum>k=0..n. (of_nat k * of_nat (n choose k)) * a^(k-1) * b^(n-k)) = |
|
27 |
of_nat n * (a+b::real) ^ (n-1)" |
|
28 |
apply (rule DERIV_unique [where f = "\<lambda>a. (a+b)^n" and x=a]) |
|
29 |
apply (subst binomial_ring) |
|
30 |
apply (rule derivative_eq_intros setsum.cong | simp)+ |
|
31 |
done |
|
32 |
||
33 |
lemma binomial_deriv2: |
|
34 |
"(\<Sum>k=0..n. (of_nat k * of_nat (k-1) * of_nat (n choose k)) * a^(k-2) * b^(n-k)) = |
|
35 |
of_nat n * of_nat (n-1) * (a+b::real) ^ (n-2)" |
|
36 |
apply (rule DERIV_unique [where f = "\<lambda>a. of_nat n * (a+b::real) ^ (n-1)" and x=a]) |
|
37 |
apply (subst binomial_deriv1 [symmetric]) |
|
38 |
apply (rule derivative_eq_intros setsum.cong | simp add: Num.numeral_2_eq_2)+ |
|
39 |
done |
|
40 |
||
41 |
lemma sum_k_Bernstein [simp]: "(\<Sum>k = 0..n. real k * Bernstein n k x) = of_nat n * x" |
|
42 |
apply (subst binomial_deriv1 [of n x "1-x", simplified, symmetric]) |
|
43 |
apply (simp add: setsum_left_distrib) |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
44 |
apply (auto simp: Bernstein_def algebra_simps realpow_num_eq_if intro!: setsum.cong) |
60987 | 45 |
done |
46 |
||
47 |
lemma sum_kk_Bernstein [simp]: "(\<Sum> k = 0..n. real k * (real k - 1) * Bernstein n k x) = real n * (real n - 1) * x\<^sup>2" |
|
48 |
proof - |
|
49 |
have "(\<Sum> k = 0..n. real k * (real k - 1) * Bernstein n k x) = real_of_nat n * real_of_nat (n - Suc 0) * x\<^sup>2" |
|
50 |
apply (subst binomial_deriv2 [of n x "1-x", simplified, symmetric]) |
|
51 |
apply (simp add: setsum_left_distrib) |
|
52 |
apply (rule setsum.cong [OF refl]) |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
53 |
apply (simp add: Bernstein_def power2_eq_square algebra_simps) |
60987 | 54 |
apply (rename_tac k) |
55 |
apply (subgoal_tac "k = 0 \<or> k = 1 \<or> (\<exists>k'. k = Suc (Suc k'))") |
|
56 |
apply (force simp add: field_simps of_nat_Suc power2_eq_square) |
|
57 |
by presburger |
|
58 |
also have "... = n * (n - 1) * x\<^sup>2" |
|
59 |
by auto |
|
60 |
finally show ?thesis |
|
61 |
by auto |
|
62 |
qed |
|
63 |
||
61222 | 64 |
subsection \<open>Explicit Bernstein version of the 1D Weierstrass approximation theorem\<close> |
60987 | 65 |
|
66 |
lemma Bernstein_Weierstrass: |
|
67 |
fixes f :: "real \<Rightarrow> real" |
|
68 |
assumes contf: "continuous_on {0..1} f" and e: "0 < e" |
|
69 |
shows "\<exists>N. \<forall>n x. N \<le> n \<and> x \<in> {0..1} |
|
70 |
\<longrightarrow> abs(f x - (\<Sum>k = 0..n. f(k/n) * Bernstein n k x)) < e" |
|
71 |
proof - |
|
72 |
have "bounded (f ` {0..1})" |
|
73 |
using compact_continuous_image compact_imp_bounded contf by blast |
|
74 |
then obtain M where M: "\<And>x. 0 \<le> x \<Longrightarrow> x \<le> 1 \<Longrightarrow> \<bar>f x\<bar> \<le> M" |
|
75 |
by (force simp add: bounded_iff) |
|
76 |
then have Mge0: "0 \<le> M" by force |
|
77 |
have ucontf: "uniformly_continuous_on {0..1} f" |
|
78 |
using compact_uniformly_continuous contf by blast |
|
79 |
then obtain d where d: "d>0" "\<And>x x'. \<lbrakk> x \<in> {0..1}; x' \<in> {0..1}; \<bar>x' - x\<bar> < d\<rbrakk> \<Longrightarrow> \<bar>f x' - f x\<bar> < e/2" |
|
80 |
apply (rule uniformly_continuous_onE [where e = "e/2"]) |
|
81 |
using e by (auto simp: dist_norm) |
|
82 |
{ fix n::nat and x::real |
|
83 |
assume n: "Suc (nat\<lceil>4*M/(e*d\<^sup>2)\<rceil>) \<le> n" and x: "0 \<le> x" "x \<le> 1" |
|
84 |
have "0 < n" using n by simp |
|
85 |
have ed0: "- (e * d\<^sup>2) < 0" |
|
61222 | 86 |
using e \<open>0<d\<close> by simp |
60987 | 87 |
also have "... \<le> M * 4" |
61222 | 88 |
using \<open>0\<le>M\<close> by simp |
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
89 |
finally have [simp]: "real_of_int (nat \<lceil>4 * M / (e * d\<^sup>2)\<rceil>) = real_of_int \<lceil>4 * M / (e * d\<^sup>2)\<rceil>" |
61222 | 90 |
using \<open>0\<le>M\<close> e \<open>0<d\<close> |
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
91 |
by (simp add: of_nat_Suc field_simps) |
60987 | 92 |
have "4*M/(e*d\<^sup>2) + 1 \<le> real (Suc (nat\<lceil>4*M/(e*d\<^sup>2)\<rceil>))" |
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
93 |
by (simp add: of_nat_Suc real_nat_ceiling_ge) |
60987 | 94 |
also have "... \<le> real n" |
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
95 |
using n by (simp add: of_nat_Suc field_simps) |
60987 | 96 |
finally have nbig: "4*M/(e*d\<^sup>2) + 1 \<le> real n" . |
97 |
have sum_bern: "(\<Sum>k = 0..n. (x - k/n)\<^sup>2 * Bernstein n k x) = x * (1 - x) / n" |
|
98 |
proof - |
|
99 |
have *: "\<And>a b x::real. (a - b)\<^sup>2 * x = a * (a - 1) * x + (1 - 2 * b) * a * x + b * b * x" |
|
100 |
by (simp add: algebra_simps power2_eq_square) |
|
101 |
have "(\<Sum> k = 0..n. (k - n * x)\<^sup>2 * Bernstein n k x) = n * x * (1 - x)" |
|
102 |
apply (simp add: * setsum.distrib) |
|
103 |
apply (simp add: setsum_right_distrib [symmetric] mult.assoc) |
|
104 |
apply (simp add: algebra_simps power2_eq_square) |
|
105 |
done |
|
106 |
then have "(\<Sum> k = 0..n. (k - n * x)\<^sup>2 * Bernstein n k x)/n^2 = x * (1 - x) / n" |
|
107 |
by (simp add: power2_eq_square) |
|
108 |
then show ?thesis |
|
109 |
using n by (simp add: setsum_divide_distrib divide_simps mult.commute power2_commute) |
|
110 |
qed |
|
111 |
{ fix k |
|
112 |
assume k: "k \<le> n" |
|
113 |
then have kn: "0 \<le> k / n" "k / n \<le> 1" |
|
114 |
by (auto simp: divide_simps) |
|
115 |
consider (lessd) "abs(x - k / n) < d" | (ged) "d \<le> abs(x - k / n)" |
|
116 |
by linarith |
|
117 |
then have "\<bar>(f x - f (k/n))\<bar> \<le> e/2 + 2 * M / d\<^sup>2 * (x - k/n)\<^sup>2" |
|
118 |
proof cases |
|
119 |
case lessd |
|
120 |
then have "\<bar>(f x - f (k/n))\<bar> < e/2" |
|
121 |
using d x kn by (simp add: abs_minus_commute) |
|
122 |
also have "... \<le> (e/2 + 2 * M / d\<^sup>2 * (x - k/n)\<^sup>2)" |
|
123 |
using Mge0 d by simp |
|
124 |
finally show ?thesis by simp |
|
125 |
next |
|
126 |
case ged |
|
127 |
then have dle: "d\<^sup>2 \<le> (x - k/n)\<^sup>2" |
|
128 |
by (metis d(1) less_eq_real_def power2_abs power_mono) |
|
129 |
have "\<bar>(f x - f (k/n))\<bar> \<le> \<bar>f x\<bar> + \<bar>f (k/n)\<bar>" |
|
130 |
by (rule abs_triangle_ineq4) |
|
131 |
also have "... \<le> M+M" |
|
132 |
by (meson M add_mono_thms_linordered_semiring(1) kn x) |
|
133 |
also have "... \<le> 2 * M * ((x - k/n)\<^sup>2 / d\<^sup>2)" |
|
134 |
apply simp |
|
135 |
apply (rule Rings.ordered_semiring_class.mult_left_mono [of 1 "((x - k/n)\<^sup>2 / d\<^sup>2)", simplified]) |
|
61222 | 136 |
using dle \<open>d>0\<close> \<open>M\<ge>0\<close> by auto |
60987 | 137 |
also have "... \<le> e/2 + 2 * M / d\<^sup>2 * (x - k/n)\<^sup>2" |
138 |
using e by simp |
|
139 |
finally show ?thesis . |
|
140 |
qed |
|
141 |
} note * = this |
|
142 |
have "\<bar>f x - (\<Sum> k = 0..n. f(k / n) * Bernstein n k x)\<bar> \<le> \<bar>\<Sum> k = 0..n. (f x - f(k / n)) * Bernstein n k x\<bar>" |
|
143 |
by (simp add: setsum_subtractf setsum_right_distrib [symmetric] algebra_simps) |
|
144 |
also have "... \<le> (\<Sum> k = 0..n. (e/2 + (2 * M / d\<^sup>2) * (x - k / n)\<^sup>2) * Bernstein n k x)" |
|
145 |
apply (rule order_trans [OF setsum_abs setsum_mono]) |
|
146 |
using * |
|
147 |
apply (simp add: abs_mult Bernstein_nonneg x mult_right_mono) |
|
148 |
done |
|
149 |
also have "... \<le> e/2 + (2 * M) / (d\<^sup>2 * n)" |
|
150 |
apply (simp only: setsum.distrib Rings.semiring_class.distrib_right setsum_right_distrib [symmetric] mult.assoc sum_bern) |
|
61222 | 151 |
using \<open>d>0\<close> x |
60987 | 152 |
apply (simp add: divide_simps Mge0 mult_le_one mult_left_le) |
153 |
done |
|
154 |
also have "... < e" |
|
155 |
apply (simp add: field_simps) |
|
61222 | 156 |
using \<open>d>0\<close> nbig e \<open>n>0\<close> |
60987 | 157 |
apply (simp add: divide_simps algebra_simps) |
158 |
using ed0 by linarith |
|
159 |
finally have "\<bar>f x - (\<Sum>k = 0..n. f (real k / real n) * Bernstein n k x)\<bar> < e" . |
|
160 |
} |
|
161 |
then show ?thesis |
|
162 |
by auto |
|
163 |
qed |
|
164 |
||
165 |
||
61222 | 166 |
subsection \<open>General Stone-Weierstrass theorem\<close> |
60987 | 167 |
|
168 |
text\<open>Source: |
|
169 |
Bruno Brosowski and Frank Deutsch. |
|
170 |
An Elementary Proof of the Stone-Weierstrass Theorem. |
|
171 |
Proceedings of the American Mathematical Society |
|
172 |
Volume 81, Number 1, January 1981.\<close> |
|
173 |
||
174 |
locale function_ring_on = |
|
175 |
fixes R :: "('a::t2_space \<Rightarrow> real) set" and s :: "'a set" |
|
176 |
assumes compact: "compact s" |
|
177 |
assumes continuous: "f \<in> R \<Longrightarrow> continuous_on s f" |
|
178 |
assumes add: "f \<in> R \<Longrightarrow> g \<in> R \<Longrightarrow> (\<lambda>x. f x + g x) \<in> R" |
|
179 |
assumes mult: "f \<in> R \<Longrightarrow> g \<in> R \<Longrightarrow> (\<lambda>x. f x * g x) \<in> R" |
|
180 |
assumes const: "(\<lambda>_. c) \<in> R" |
|
181 |
assumes separable: "x \<in> s \<Longrightarrow> y \<in> s \<Longrightarrow> x \<noteq> y \<Longrightarrow> \<exists>f\<in>R. f x \<noteq> f y" |
|
182 |
||
183 |
begin |
|
184 |
lemma minus: "f \<in> R \<Longrightarrow> (\<lambda>x. - f x) \<in> R" |
|
185 |
by (frule mult [OF const [of "-1"]]) simp |
|
186 |
||
187 |
lemma diff: "f \<in> R \<Longrightarrow> g \<in> R \<Longrightarrow> (\<lambda>x. f x - g x) \<in> R" |
|
188 |
unfolding diff_conv_add_uminus by (metis add minus) |
|
189 |
||
190 |
lemma power: "f \<in> R \<Longrightarrow> (\<lambda>x. f x ^ n) \<in> R" |
|
191 |
by (induct n) (auto simp: const mult) |
|
192 |
||
193 |
lemma setsum: "\<lbrakk>finite I; \<And>i. i \<in> I \<Longrightarrow> f i \<in> R\<rbrakk> \<Longrightarrow> (\<lambda>x. \<Sum>i \<in> I. f i x) \<in> R" |
|
194 |
by (induct I rule: finite_induct; simp add: const add) |
|
195 |
||
196 |
lemma setprod: "\<lbrakk>finite I; \<And>i. i \<in> I \<Longrightarrow> f i \<in> R\<rbrakk> \<Longrightarrow> (\<lambda>x. \<Prod>i \<in> I. f i x) \<in> R" |
|
197 |
by (induct I rule: finite_induct; simp add: const mult) |
|
198 |
||
199 |
definition normf :: "('a::t2_space \<Rightarrow> real) \<Rightarrow> real" |
|
200 |
where "normf f \<equiv> SUP x:s. \<bar>f x\<bar>" |
|
201 |
||
202 |
lemma normf_upper: "\<lbrakk>continuous_on s f; x \<in> s\<rbrakk> \<Longrightarrow> \<bar>f x\<bar> \<le> normf f" |
|
203 |
apply (simp add: normf_def) |
|
204 |
apply (rule cSUP_upper, assumption) |
|
205 |
by (simp add: bounded_imp_bdd_above compact compact_continuous_image compact_imp_bounded continuous_on_rabs) |
|
206 |
||
207 |
lemma normf_least: "s \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> s \<Longrightarrow> \<bar>f x\<bar> \<le> M) \<Longrightarrow> normf f \<le> M" |
|
208 |
by (simp add: normf_def cSUP_least) |
|
209 |
||
210 |
end |
|
211 |
||
212 |
lemma (in function_ring_on) one: |
|
213 |
assumes U: "open U" and t0: "t0 \<in> s" "t0 \<in> U" and t1: "t1 \<in> s-U" |
|
214 |
shows "\<exists>V. open V \<and> t0 \<in> V \<and> s \<inter> V \<subseteq> U \<and> |
|
215 |
(\<forall>e>0. \<exists>f \<in> R. f ` s \<subseteq> {0..1} \<and> (\<forall>t \<in> s \<inter> V. f t < e) \<and> (\<forall>t \<in> s - U. f t > 1 - e))" |
|
216 |
proof - |
|
217 |
have "\<exists>pt \<in> R. pt t0 = 0 \<and> pt t > 0 \<and> pt ` s \<subseteq> {0..1}" if t: "t \<in> s - U" for t |
|
218 |
proof - |
|
219 |
have "t \<noteq> t0" using t t0 by auto |
|
220 |
then obtain g where g: "g \<in> R" "g t \<noteq> g t0" |
|
221 |
using separable t0 by (metis Diff_subset subset_eq t) |
|
222 |
def h \<equiv> "\<lambda>x. g x - g t0" |
|
223 |
have "h \<in> R" |
|
224 |
unfolding h_def by (fast intro: g const diff) |
|
225 |
then have hsq: "(\<lambda>w. (h w)\<^sup>2) \<in> R" |
|
226 |
by (simp add: power2_eq_square mult) |
|
227 |
have "h t \<noteq> h t0" |
|
228 |
by (simp add: h_def g) |
|
229 |
then have "h t \<noteq> 0" |
|
230 |
by (simp add: h_def) |
|
231 |
then have ht2: "0 < (h t)^2" |
|
232 |
by simp |
|
233 |
also have "... \<le> normf (\<lambda>w. (h w)\<^sup>2)" |
|
234 |
using t normf_upper [where x=t] continuous [OF hsq] by force |
|
235 |
finally have nfp: "0 < normf (\<lambda>w. (h w)\<^sup>2)" . |
|
236 |
def p \<equiv> "\<lambda>x. (1 / normf (\<lambda>w. (h w)\<^sup>2)) * (h x)^2" |
|
237 |
have "p \<in> R" |
|
238 |
unfolding p_def by (fast intro: hsq const mult) |
|
239 |
moreover have "p t0 = 0" |
|
240 |
by (simp add: p_def h_def) |
|
241 |
moreover have "p t > 0" |
|
242 |
using nfp ht2 by (simp add: p_def) |
|
243 |
moreover have "\<And>x. x \<in> s \<Longrightarrow> p x \<in> {0..1}" |
|
244 |
using nfp normf_upper [OF continuous [OF hsq] ] by (auto simp: p_def) |
|
245 |
ultimately show "\<exists>pt \<in> R. pt t0 = 0 \<and> pt t > 0 \<and> pt ` s \<subseteq> {0..1}" |
|
246 |
by auto |
|
247 |
qed |
|
248 |
then obtain pf where pf: "\<And>t. t \<in> s-U \<Longrightarrow> pf t \<in> R \<and> pf t t0 = 0 \<and> pf t t > 0" |
|
249 |
and pf01: "\<And>t. t \<in> s-U \<Longrightarrow> pf t ` s \<subseteq> {0..1}" |
|
250 |
by metis |
|
251 |
have com_sU: "compact (s-U)" |
|
252 |
using compact closed_inter_compact U by (simp add: Diff_eq compact_inter_closed open_closed) |
|
253 |
have "\<And>t. t \<in> s-U \<Longrightarrow> \<exists>A. open A \<and> A \<inter> s = {x\<in>s. 0 < pf t x}" |
|
254 |
apply (rule open_Collect_positive) |
|
255 |
by (metis pf continuous) |
|
256 |
then obtain Uf where Uf: "\<And>t. t \<in> s-U \<Longrightarrow> open (Uf t) \<and> (Uf t) \<inter> s = {x\<in>s. 0 < pf t x}" |
|
257 |
by metis |
|
258 |
then have open_Uf: "\<And>t. t \<in> s-U \<Longrightarrow> open (Uf t)" |
|
259 |
by blast |
|
260 |
have tUft: "\<And>t. t \<in> s-U \<Longrightarrow> t \<in> Uf t" |
|
261 |
using pf Uf by blast |
|
262 |
then have *: "s-U \<subseteq> (\<Union>x \<in> s-U. Uf x)" |
|
263 |
by blast |
|
264 |
obtain subU where subU: "subU \<subseteq> s - U" "finite subU" "s - U \<subseteq> (\<Union>x \<in> subU. Uf x)" |
|
265 |
by (blast intro: that open_Uf compactE_image [OF com_sU _ *]) |
|
266 |
then have [simp]: "subU \<noteq> {}" |
|
267 |
using t1 by auto |
|
268 |
then have cardp: "card subU > 0" using subU |
|
269 |
by (simp add: card_gt_0_iff) |
|
270 |
def p \<equiv> "\<lambda>x. (1 / card subU) * (\<Sum>t \<in> subU. pf t x)" |
|
271 |
have pR: "p \<in> R" |
|
272 |
unfolding p_def using subU pf by (fast intro: pf const mult setsum) |
|
273 |
have pt0 [simp]: "p t0 = 0" |
|
274 |
using subU pf by (auto simp: p_def intro: setsum.neutral) |
|
275 |
have pt_pos: "p t > 0" if t: "t \<in> s-U" for t |
|
276 |
proof - |
|
277 |
obtain i where i: "i \<in> subU" "t \<in> Uf i" using subU t by blast |
|
278 |
show ?thesis |
|
279 |
using subU i t |
|
280 |
apply (clarsimp simp: p_def divide_simps) |
|
61222 | 281 |
apply (rule setsum_pos2 [OF \<open>finite subU\<close>]) |
60987 | 282 |
using Uf t pf01 apply auto |
283 |
apply (force elim!: subsetCE) |
|
284 |
done |
|
285 |
qed |
|
286 |
have p01: "p x \<in> {0..1}" if t: "x \<in> s" for x |
|
287 |
proof - |
|
288 |
have "0 \<le> p x" |
|
289 |
using subU cardp t |
|
290 |
apply (simp add: p_def divide_simps setsum_nonneg) |
|
291 |
apply (rule setsum_nonneg) |
|
292 |
using pf01 by force |
|
293 |
moreover have "p x \<le> 1" |
|
294 |
using subU cardp t |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
295 |
apply (simp add: p_def divide_simps setsum_nonneg) |
60987 | 296 |
apply (rule setsum_bounded_above [where 'a=real and K=1, simplified]) |
297 |
using pf01 by force |
|
298 |
ultimately show ?thesis |
|
299 |
by auto |
|
300 |
qed |
|
301 |
have "compact (p ` (s-U))" |
|
302 |
by (meson Diff_subset com_sU compact_continuous_image continuous continuous_on_subset pR) |
|
303 |
then have "open (- (p ` (s-U)))" |
|
304 |
by (simp add: compact_imp_closed open_Compl) |
|
305 |
moreover have "0 \<in> - (p ` (s-U))" |
|
306 |
by (metis (no_types) ComplI image_iff not_less_iff_gr_or_eq pt_pos) |
|
307 |
ultimately obtain delta0 where delta0: "delta0 > 0" "ball 0 delta0 \<subseteq> - (p ` (s-U))" |
|
308 |
by (auto simp: elim!: openE) |
|
309 |
then have pt_delta: "\<And>x. x \<in> s-U \<Longrightarrow> p x \<ge> delta0" |
|
310 |
by (force simp: ball_def dist_norm dest: p01) |
|
311 |
def \<delta> \<equiv> "delta0/2" |
|
312 |
have "delta0 \<le> 1" using delta0 p01 [of t1] t1 |
|
313 |
by (force simp: ball_def dist_norm dest: p01) |
|
314 |
with delta0 have \<delta>01: "0 < \<delta>" "\<delta> < 1" |
|
315 |
by (auto simp: \<delta>_def) |
|
316 |
have pt_\<delta>: "\<And>x. x \<in> s-U \<Longrightarrow> p x \<ge> \<delta>" |
|
317 |
using pt_delta delta0 by (force simp: \<delta>_def) |
|
318 |
have "\<exists>A. open A \<and> A \<inter> s = {x\<in>s. p x < \<delta>/2}" |
|
319 |
by (rule open_Collect_less_Int [OF continuous [OF pR] continuous_on_const]) |
|
320 |
then obtain V where V: "open V" "V \<inter> s = {x\<in>s. p x < \<delta>/2}" |
|
321 |
by blast |
|
322 |
def k \<equiv> "nat\<lfloor>1/\<delta>\<rfloor> + 1" |
|
323 |
have "k>0" by (simp add: k_def) |
|
324 |
have "k-1 \<le> 1/\<delta>" |
|
325 |
using \<delta>01 by (simp add: k_def) |
|
326 |
with \<delta>01 have "k \<le> (1+\<delta>)/\<delta>" |
|
327 |
by (auto simp: algebra_simps add_divide_distrib) |
|
328 |
also have "... < 2/\<delta>" |
|
329 |
using \<delta>01 by (auto simp: divide_simps) |
|
330 |
finally have k2\<delta>: "k < 2/\<delta>" . |
|
331 |
have "1/\<delta> < k" |
|
332 |
using \<delta>01 unfolding k_def by linarith |
|
333 |
with \<delta>01 k2\<delta> have k\<delta>: "1 < k*\<delta>" "k*\<delta> < 2" |
|
334 |
by (auto simp: divide_simps) |
|
335 |
def q \<equiv> "\<lambda>n t. (1 - p t ^ n) ^ (k^n)" |
|
336 |
have qR: "q n \<in> R" for n |
|
337 |
by (simp add: q_def const diff power pR) |
|
338 |
have q01: "\<And>n t. t \<in> s \<Longrightarrow> q n t \<in> {0..1}" |
|
339 |
using p01 by (simp add: q_def power_le_one algebra_simps) |
|
340 |
have qt0 [simp]: "\<And>n. n>0 \<Longrightarrow> q n t0 = 1" |
|
341 |
using t0 pf by (simp add: q_def power_0_left) |
|
342 |
{ fix t and n::nat |
|
343 |
assume t: "t \<in> s \<inter> V" |
|
61222 | 344 |
with \<open>k>0\<close> V have "k * p t < k * \<delta> / 2" |
60987 | 345 |
by force |
346 |
then have "1 - (k * \<delta> / 2)^n \<le> 1 - (k * p t)^n" |
|
61222 | 347 |
using \<open>k>0\<close> p01 t by (simp add: power_mono) |
60987 | 348 |
also have "... \<le> q n t" |
349 |
using Bernoulli_inequality [of "- ((p t)^n)" "k^n"] |
|
350 |
apply (simp add: q_def) |
|
351 |
by (metis IntE atLeastAtMost_iff p01 power_le_one power_mult_distrib t) |
|
352 |
finally have "1 - (k * \<delta> / 2) ^ n \<le> q n t" . |
|
353 |
} note limitV = this |
|
354 |
{ fix t and n::nat |
|
355 |
assume t: "t \<in> s - U" |
|
61222 | 356 |
with \<open>k>0\<close> U have "k * \<delta> \<le> k * p t" |
60987 | 357 |
by (simp add: pt_\<delta>) |
358 |
with k\<delta> have kpt: "1 < k * p t" |
|
359 |
by (blast intro: less_le_trans) |
|
360 |
have ptn_pos: "0 < p t ^ n" |
|
361 |
using pt_pos [OF t] by simp |
|
362 |
have ptn_le: "p t ^ n \<le> 1" |
|
363 |
by (meson DiffE atLeastAtMost_iff p01 power_le_one t) |
|
364 |
have "q n t = (1/(k^n * (p t)^n)) * (1 - p t ^ n) ^ (k^n) * k^n * (p t)^n" |
|
61222 | 365 |
using pt_pos [OF t] \<open>k>0\<close> by (simp add: q_def) |
60987 | 366 |
also have "... \<le> (1/(k * (p t))^n) * (1 - p t ^ n) ^ (k^n) * (1 + k^n * (p t)^n)" |
61222 | 367 |
using pt_pos [OF t] \<open>k>0\<close> |
60987 | 368 |
apply simp |
369 |
apply (simp only: times_divide_eq_right [symmetric]) |
|
370 |
apply (rule mult_left_mono [of "1::real", simplified]) |
|
371 |
apply (simp_all add: power_mult_distrib) |
|
372 |
apply (rule zero_le_power) |
|
373 |
using ptn_le by linarith |
|
374 |
also have "... \<le> (1/(k * (p t))^n) * (1 - p t ^ n) ^ (k^n) * (1 + (p t)^n) ^ (k^n)" |
|
375 |
apply (rule mult_left_mono [OF Bernoulli_inequality [of "p t ^ n" "k^n"]]) |
|
61222 | 376 |
using \<open>k>0\<close> ptn_pos ptn_le |
60987 | 377 |
apply (auto simp: power_mult_distrib) |
378 |
done |
|
379 |
also have "... = (1/(k * (p t))^n) * (1 - p t ^ (2*n)) ^ (k^n)" |
|
61222 | 380 |
using pt_pos [OF t] \<open>k>0\<close> |
60987 | 381 |
by (simp add: algebra_simps power_mult power2_eq_square power_mult_distrib [symmetric]) |
382 |
also have "... \<le> (1/(k * (p t))^n) * 1" |
|
383 |
apply (rule mult_left_mono [OF power_le_one]) |
|
384 |
apply (metis diff_le_iff(1) less_eq_real_def mult.commute power_le_one power_mult ptn_pos ptn_le) |
|
61222 | 385 |
using pt_pos [OF t] \<open>k>0\<close> |
60987 | 386 |
apply auto |
387 |
done |
|
388 |
also have "... \<le> (1 / (k*\<delta>))^n" |
|
61222 | 389 |
using \<open>k>0\<close> \<delta>01 power_mono pt_\<delta> t |
60987 | 390 |
by (fastforce simp: field_simps) |
391 |
finally have "q n t \<le> (1 / (real k * \<delta>)) ^ n " . |
|
392 |
} note limitNonU = this |
|
393 |
def NN \<equiv> "\<lambda>e. 1 + nat \<lceil>max (ln e / ln (real k * \<delta> / 2)) (- ln e / ln (real k * \<delta>))\<rceil>" |
|
394 |
have NN: "of_nat (NN e) > ln e / ln (real k * \<delta> / 2)" "of_nat (NN e) > - ln e / ln (real k * \<delta>)" |
|
395 |
if "0<e" for e |
|
396 |
unfolding NN_def by linarith+ |
|
397 |
have NN1: "\<And>e. e>0 \<Longrightarrow> (k * \<delta> / 2)^NN e < e" |
|
398 |
apply (subst Transcendental.ln_less_cancel_iff [symmetric]) |
|
399 |
prefer 3 apply (subst ln_realpow) |
|
61222 | 400 |
using \<open>k>0\<close> \<open>\<delta>>0\<close> NN k\<delta> |
60987 | 401 |
apply (force simp add: field_simps)+ |
402 |
done |
|
403 |
have NN0: "\<And>e. e>0 \<Longrightarrow> (1/(k*\<delta>))^NN e < e" |
|
404 |
apply (subst Transcendental.ln_less_cancel_iff [symmetric]) |
|
405 |
prefer 3 apply (subst ln_realpow) |
|
61222 | 406 |
using \<open>k>0\<close> \<open>\<delta>>0\<close> NN k\<delta> |
60987 | 407 |
apply (force simp add: field_simps ln_div)+ |
408 |
done |
|
409 |
{ fix t and e::real |
|
410 |
assume "e>0" |
|
411 |
have "t \<in> s \<inter> V \<Longrightarrow> 1 - q (NN e) t < e" "t \<in> s - U \<Longrightarrow> q (NN e) t < e" |
|
412 |
proof - |
|
413 |
assume t: "t \<in> s \<inter> V" |
|
414 |
show "1 - q (NN e) t < e" |
|
61222 | 415 |
by (metis add.commute diff_le_eq not_le limitV [OF t] less_le_trans [OF NN1 [OF \<open>e>0\<close>]]) |
60987 | 416 |
next |
417 |
assume t: "t \<in> s - U" |
|
418 |
show "q (NN e) t < e" |
|
61222 | 419 |
using limitNonU [OF t] less_le_trans [OF NN0 [OF \<open>e>0\<close>]] not_le by blast |
60987 | 420 |
qed |
421 |
} then have "\<And>e. e > 0 \<Longrightarrow> \<exists>f\<in>R. f ` s \<subseteq> {0..1} \<and> (\<forall>t \<in> s \<inter> V. f t < e) \<and> (\<forall>t \<in> s - U. 1 - e < f t)" |
|
422 |
using q01 |
|
423 |
by (rule_tac x="\<lambda>x. 1 - q (NN e) x" in bexI) (auto simp: algebra_simps intro: diff const qR) |
|
424 |
moreover have t0V: "t0 \<in> V" "s \<inter> V \<subseteq> U" |
|
425 |
using pt_\<delta> t0 U V \<delta>01 by fastforce+ |
|
426 |
ultimately show ?thesis using V t0V |
|
427 |
by blast |
|
428 |
qed |
|
429 |
||
430 |
text\<open>Non-trivial case, with @{term A} and @{term B} both non-empty\<close> |
|
431 |
lemma (in function_ring_on) two_special: |
|
432 |
assumes A: "closed A" "A \<subseteq> s" "a \<in> A" |
|
433 |
and B: "closed B" "B \<subseteq> s" "b \<in> B" |
|
434 |
and disj: "A \<inter> B = {}" |
|
435 |
and e: "0 < e" "e < 1" |
|
436 |
shows "\<exists>f \<in> R. f ` s \<subseteq> {0..1} \<and> (\<forall>x \<in> A. f x < e) \<and> (\<forall>x \<in> B. f x > 1 - e)" |
|
437 |
proof - |
|
438 |
{ fix w |
|
439 |
assume "w \<in> A" |
|
440 |
then have "open ( - B)" "b \<in> s" "w \<notin> B" "w \<in> s" |
|
441 |
using assms by auto |
|
442 |
then have "\<exists>V. open V \<and> w \<in> V \<and> s \<inter> V \<subseteq> -B \<and> |
|
443 |
(\<forall>e>0. \<exists>f \<in> R. f ` s \<subseteq> {0..1} \<and> (\<forall>x \<in> s \<inter> V. f x < e) \<and> (\<forall>x \<in> s \<inter> B. f x > 1 - e))" |
|
61222 | 444 |
using one [of "-B" w b] assms \<open>w \<in> A\<close> by simp |
60987 | 445 |
} |
446 |
then obtain Vf where Vf: |
|
447 |
"\<And>w. w \<in> A \<Longrightarrow> open (Vf w) \<and> w \<in> Vf w \<and> s \<inter> Vf w \<subseteq> -B \<and> |
|
448 |
(\<forall>e>0. \<exists>f \<in> R. f ` s \<subseteq> {0..1} \<and> (\<forall>x \<in> s \<inter> Vf w. f x < e) \<and> (\<forall>x \<in> s \<inter> B. f x > 1 - e))" |
|
449 |
by metis |
|
450 |
then have open_Vf: "\<And>w. w \<in> A \<Longrightarrow> open (Vf w)" |
|
451 |
by blast |
|
452 |
have tVft: "\<And>w. w \<in> A \<Longrightarrow> w \<in> Vf w" |
|
453 |
using Vf by blast |
|
454 |
then have setsum_max_0: "A \<subseteq> (\<Union>x \<in> A. Vf x)" |
|
455 |
by blast |
|
456 |
have com_A: "compact A" using A |
|
457 |
by (metis compact compact_inter_closed inf.absorb_iff2) |
|
458 |
obtain subA where subA: "subA \<subseteq> A" "finite subA" "A \<subseteq> (\<Union>x \<in> subA. Vf x)" |
|
459 |
by (blast intro: that open_Vf compactE_image [OF com_A _ setsum_max_0]) |
|
460 |
then have [simp]: "subA \<noteq> {}" |
|
61222 | 461 |
using \<open>a \<in> A\<close> by auto |
60987 | 462 |
then have cardp: "card subA > 0" using subA |
463 |
by (simp add: card_gt_0_iff) |
|
464 |
have "\<And>w. w \<in> A \<Longrightarrow> \<exists>f \<in> R. f ` s \<subseteq> {0..1} \<and> (\<forall>x \<in> s \<inter> Vf w. f x < e / card subA) \<and> (\<forall>x \<in> s \<inter> B. f x > 1 - e / card subA)" |
|
465 |
using Vf e cardp by simp |
|
466 |
then obtain ff where ff: |
|
467 |
"\<And>w. w \<in> A \<Longrightarrow> ff w \<in> R \<and> ff w ` s \<subseteq> {0..1} \<and> |
|
468 |
(\<forall>x \<in> s \<inter> Vf w. ff w x < e / card subA) \<and> (\<forall>x \<in> s \<inter> B. ff w x > 1 - e / card subA)" |
|
469 |
by metis |
|
470 |
def pff \<equiv> "\<lambda>x. (\<Prod>w \<in> subA. ff w x)" |
|
471 |
have pffR: "pff \<in> R" |
|
472 |
unfolding pff_def using subA ff by (auto simp: intro: setprod) |
|
473 |
moreover |
|
474 |
have pff01: "pff x \<in> {0..1}" if t: "x \<in> s" for x |
|
475 |
proof - |
|
476 |
have "0 \<le> pff x" |
|
477 |
using subA cardp t |
|
478 |
apply (simp add: pff_def divide_simps setsum_nonneg) |
|
479 |
apply (rule Groups_Big.linordered_semidom_class.setprod_nonneg) |
|
480 |
using ff by fastforce |
|
481 |
moreover have "pff x \<le> 1" |
|
482 |
using subA cardp t |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
483 |
apply (simp add: pff_def divide_simps setsum_nonneg) |
60987 | 484 |
apply (rule setprod_mono [where g = "\<lambda>x. 1", simplified]) |
485 |
using ff by fastforce |
|
486 |
ultimately show ?thesis |
|
487 |
by auto |
|
488 |
qed |
|
489 |
moreover |
|
490 |
{ fix v x |
|
491 |
assume v: "v \<in> subA" and x: "x \<in> Vf v" "x \<in> s" |
|
492 |
from subA v have "pff x = ff v x * (\<Prod>w \<in> subA - {v}. ff w x)" |
|
493 |
unfolding pff_def by (metis setprod.remove) |
|
494 |
also have "... \<le> ff v x * 1" |
|
495 |
apply (rule Rings.ordered_semiring_class.mult_left_mono) |
|
496 |
apply (rule setprod_mono [where g = "\<lambda>x. 1", simplified]) |
|
497 |
using ff [THEN conjunct2, THEN conjunct1] v subA x |
|
498 |
apply auto |
|
499 |
apply (meson atLeastAtMost_iff contra_subsetD imageI) |
|
500 |
apply (meson atLeastAtMost_iff contra_subsetD image_eqI) |
|
501 |
using atLeastAtMost_iff by blast |
|
502 |
also have "... < e / card subA" |
|
503 |
using ff [THEN conjunct2, THEN conjunct2, THEN conjunct1] v subA x |
|
504 |
by auto |
|
505 |
also have "... \<le> e" |
|
506 |
using cardp e by (simp add: divide_simps) |
|
507 |
finally have "pff x < e" . |
|
508 |
} |
|
509 |
then have "\<And>x. x \<in> A \<Longrightarrow> pff x < e" |
|
510 |
using A Vf subA by (metis UN_E contra_subsetD) |
|
511 |
moreover |
|
512 |
{ fix x |
|
513 |
assume x: "x \<in> B" |
|
514 |
then have "x \<in> s" |
|
515 |
using B by auto |
|
516 |
have "1 - e \<le> (1 - e / card subA) ^ card subA" |
|
517 |
using Bernoulli_inequality [of "-e / card subA" "card subA"] e cardp |
|
518 |
by (auto simp: field_simps) |
|
519 |
also have "... = (\<Prod>w \<in> subA. 1 - e / card subA)" |
|
520 |
by (simp add: setprod_constant subA(2)) |
|
521 |
also have "... < pff x" |
|
522 |
apply (simp add: pff_def) |
|
523 |
apply (rule setprod_mono_strict [where f = "\<lambda>x. 1 - e / card subA", simplified]) |
|
524 |
apply (simp_all add: subA(2)) |
|
525 |
apply (intro ballI conjI) |
|
526 |
using e apply (force simp: divide_simps) |
|
527 |
using ff [THEN conjunct2, THEN conjunct2, THEN conjunct2] subA B x |
|
528 |
apply blast |
|
529 |
done |
|
530 |
finally have "1 - e < pff x" . |
|
531 |
} |
|
532 |
ultimately |
|
533 |
show ?thesis by blast |
|
534 |
qed |
|
535 |
||
536 |
lemma (in function_ring_on) two: |
|
537 |
assumes A: "closed A" "A \<subseteq> s" |
|
538 |
and B: "closed B" "B \<subseteq> s" |
|
539 |
and disj: "A \<inter> B = {}" |
|
540 |
and e: "0 < e" "e < 1" |
|
541 |
shows "\<exists>f \<in> R. f ` s \<subseteq> {0..1} \<and> (\<forall>x \<in> A. f x < e) \<and> (\<forall>x \<in> B. f x > 1 - e)" |
|
542 |
proof (cases "A \<noteq> {} \<and> B \<noteq> {}") |
|
543 |
case True then show ?thesis |
|
544 |
apply (simp add: ex_in_conv [symmetric]) |
|
545 |
using assms |
|
546 |
apply safe |
|
547 |
apply (force simp add: intro!: two_special) |
|
548 |
done |
|
549 |
next |
|
550 |
case False with e show ?thesis |
|
551 |
apply simp |
|
552 |
apply (erule disjE) |
|
553 |
apply (rule_tac [2] x="\<lambda>x. 0" in bexI) |
|
554 |
apply (rule_tac x="\<lambda>x. 1" in bexI) |
|
555 |
apply (auto simp: const) |
|
556 |
done |
|
557 |
qed |
|
558 |
||
559 |
text\<open>The special case where @{term f} is non-negative and @{term"e<1/3"}\<close> |
|
560 |
lemma (in function_ring_on) Stone_Weierstrass_special: |
|
561 |
assumes f: "continuous_on s f" and fpos: "\<And>x. x \<in> s \<Longrightarrow> f x \<ge> 0" |
|
562 |
and e: "0 < e" "e < 1/3" |
|
563 |
shows "\<exists>g \<in> R. \<forall>x\<in>s. \<bar>f x - g x\<bar> < 2*e" |
|
564 |
proof - |
|
565 |
def n \<equiv> "1 + nat \<lceil>normf f / e\<rceil>" |
|
566 |
def A \<equiv> "\<lambda>j::nat. {x \<in> s. f x \<le> (j - 1/3)*e}" |
|
567 |
def B \<equiv> "\<lambda>j::nat. {x \<in> s. f x \<ge> (j + 1/3)*e}" |
|
568 |
have ngt: "(n-1) * e \<ge> normf f" "n\<ge>1" |
|
569 |
using e |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
570 |
apply (simp_all add: n_def field_simps of_nat_Suc) |
60987 | 571 |
by (metis real_nat_ceiling_ge mult.commute not_less pos_less_divide_eq) |
572 |
then have ge_fx: "(n-1) * e \<ge> f x" if "x \<in> s" for x |
|
573 |
using f normf_upper that by fastforce |
|
574 |
{ fix j |
|
575 |
have A: "closed (A j)" "A j \<subseteq> s" |
|
576 |
apply (simp_all add: A_def Collect_restrict) |
|
577 |
apply (rule continuous_on_closed_Collect_le [OF f continuous_on_const]) |
|
578 |
apply (simp add: compact compact_imp_closed) |
|
579 |
done |
|
580 |
have B: "closed (B j)" "B j \<subseteq> s" |
|
581 |
apply (simp_all add: B_def Collect_restrict) |
|
582 |
apply (rule continuous_on_closed_Collect_le [OF continuous_on_const f]) |
|
583 |
apply (simp add: compact compact_imp_closed) |
|
584 |
done |
|
585 |
have disj: "(A j) \<inter> (B j) = {}" |
|
586 |
using e by (auto simp: A_def B_def field_simps) |
|
587 |
have "\<exists>f \<in> R. f ` s \<subseteq> {0..1} \<and> (\<forall>x \<in> A j. f x < e/n) \<and> (\<forall>x \<in> B j. f x > 1 - e/n)" |
|
588 |
apply (rule two) |
|
589 |
using e A B disj ngt |
|
590 |
apply simp_all |
|
591 |
done |
|
592 |
} |
|
593 |
then obtain xf where xfR: "\<And>j. xf j \<in> R" and xf01: "\<And>j. xf j ` s \<subseteq> {0..1}" |
|
594 |
and xfA: "\<And>x j. x \<in> A j \<Longrightarrow> xf j x < e/n" |
|
595 |
and xfB: "\<And>x j. x \<in> B j \<Longrightarrow> xf j x > 1 - e/n" |
|
596 |
by metis |
|
597 |
def g \<equiv> "\<lambda>x. e * (\<Sum>i\<le>n. xf i x)" |
|
598 |
have gR: "g \<in> R" |
|
599 |
unfolding g_def by (fast intro: mult const setsum xfR) |
|
600 |
have gge0: "\<And>x. x \<in> s \<Longrightarrow> g x \<ge> 0" |
|
601 |
using e xf01 by (simp add: g_def zero_le_mult_iff image_subset_iff setsum_nonneg) |
|
602 |
have A0: "A 0 = {}" |
|
603 |
using fpos e by (fastforce simp: A_def) |
|
604 |
have An: "A n = s" |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
605 |
using e ngt f normf_upper by (fastforce simp: A_def field_simps of_nat_diff) |
60987 | 606 |
have Asub: "A j \<subseteq> A i" if "i\<ge>j" for i j |
607 |
using e that apply (clarsimp simp: A_def) |
|
608 |
apply (erule order_trans, simp) |
|
609 |
done |
|
610 |
{ fix t |
|
611 |
assume t: "t \<in> s" |
|
612 |
def j \<equiv> "LEAST j. t \<in> A j" |
|
613 |
have jn: "j \<le> n" |
|
614 |
using t An by (simp add: Least_le j_def) |
|
615 |
have Aj: "t \<in> A j" |
|
616 |
using t An by (fastforce simp add: j_def intro: LeastI) |
|
617 |
then have Ai: "t \<in> A i" if "i\<ge>j" for i |
|
618 |
using Asub [OF that] by blast |
|
619 |
then have fj1: "f t \<le> (j - 1/3)*e" |
|
620 |
by (simp add: A_def) |
|
621 |
then have Anj: "t \<notin> A i" if "i<j" for i |
|
61222 | 622 |
using Aj \<open>i<j\<close> |
60987 | 623 |
apply (simp add: j_def) |
624 |
using not_less_Least by blast |
|
625 |
have j1: "1 \<le> j" |
|
626 |
using A0 Aj j_def not_less_eq_eq by (fastforce simp add: j_def) |
|
627 |
then have Anj: "t \<notin> A (j-1)" |
|
628 |
using Least_le by (fastforce simp add: j_def) |
|
629 |
then have fj2: "(j - 4/3)*e < f t" |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
630 |
using j1 t by (simp add: A_def of_nat_diff) |
60987 | 631 |
have ***: "xf i t \<le> e/n" if "i\<ge>j" for i |
632 |
using xfA [OF Ai] that by (simp add: less_eq_real_def) |
|
633 |
{ fix i |
|
634 |
assume "i+2 \<le> j" |
|
635 |
then obtain d where "i+2+d = j" |
|
636 |
using le_Suc_ex that by blast |
|
637 |
then have "t \<in> B i" |
|
61222 | 638 |
using Anj e ge_fx [OF t] \<open>1 \<le> n\<close> fpos [OF t] t |
60987 | 639 |
apply (simp add: A_def B_def) |
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
640 |
apply (clarsimp simp add: field_simps of_nat_diff not_le of_nat_Suc) |
60987 | 641 |
apply (rule order_trans [of _ "e * 2 + (e * (real d * 3) + e * (real i * 3))"]) |
642 |
apply auto |
|
643 |
done |
|
644 |
then have "xf i t > 1 - e/n" |
|
645 |
by (rule xfB) |
|
646 |
} note **** = this |
|
647 |
have xf_le1: "\<And>i. xf i t \<le> 1" |
|
648 |
using xf01 t by force |
|
649 |
have "g t = e * (\<Sum>i<j. xf i t) + e * (\<Sum>i=j..n. xf i t)" |
|
650 |
using j1 jn e |
|
651 |
apply (simp add: g_def distrib_left [symmetric]) |
|
652 |
apply (subst setsum.union_disjoint [symmetric]) |
|
653 |
apply (auto simp: ivl_disj_un) |
|
654 |
done |
|
655 |
also have "... \<le> e*j + e * ((Suc n - j)*e/n)" |
|
656 |
apply (rule add_mono) |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
657 |
apply (simp_all only: mult_le_cancel_left_pos e) |
60987 | 658 |
apply (rule setsum_bounded_above [OF xf_le1, where A = "lessThan j", simplified]) |
659 |
using setsum_bounded_above [of "{j..n}" "\<lambda>i. xf i t", OF ***] |
|
660 |
apply simp |
|
661 |
done |
|
662 |
also have "... \<le> j*e + e*(n - j + 1)*e/n " |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
663 |
using \<open>1 \<le> n\<close> e by (simp add: field_simps del: of_nat_Suc) |
60987 | 664 |
also have "... \<le> j*e + e*e" |
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
665 |
using \<open>1 \<le> n\<close> e j1 by (simp add: field_simps del: of_nat_Suc) |
60987 | 666 |
also have "... < (j + 1/3)*e" |
667 |
using e by (auto simp: field_simps) |
|
668 |
finally have gj1: "g t < (j + 1 / 3) * e" . |
|
669 |
have gj2: "(j - 4/3)*e < g t" |
|
670 |
proof (cases "2 \<le> j") |
|
671 |
case False |
|
672 |
then have "j=1" using j1 by simp |
|
673 |
with t gge0 e show ?thesis by force |
|
674 |
next |
|
675 |
case True |
|
676 |
then have "(j - 4/3)*e < (j-1)*e - e^2" |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
677 |
using e by (auto simp: of_nat_diff algebra_simps power2_eq_square) |
60987 | 678 |
also have "... < (j-1)*e - ((j - 1)/n) * e^2" |
679 |
using e True jn by (simp add: power2_eq_square field_simps) |
|
680 |
also have "... = e * (j-1) * (1 - e/n)" |
|
681 |
by (simp add: power2_eq_square field_simps) |
|
682 |
also have "... \<le> e * (\<Sum>i\<le>j-2. xf i t)" |
|
683 |
using e |
|
684 |
apply simp |
|
685 |
apply (rule order_trans [OF _ setsum_bounded_below [OF less_imp_le [OF ****]]]) |
|
686 |
using True |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
687 |
apply (simp_all add: of_nat_Suc of_nat_diff) |
60987 | 688 |
done |
689 |
also have "... \<le> g t" |
|
690 |
using jn e |
|
691 |
using e xf01 t |
|
692 |
apply (simp add: g_def zero_le_mult_iff image_subset_iff setsum_nonneg) |
|
693 |
apply (rule Groups_Big.setsum_mono2, auto) |
|
694 |
done |
|
695 |
finally show ?thesis . |
|
696 |
qed |
|
697 |
have "\<bar>f t - g t\<bar> < 2 * e" |
|
698 |
using fj1 fj2 gj1 gj2 by (simp add: abs_less_iff field_simps) |
|
699 |
} |
|
700 |
then show ?thesis |
|
701 |
by (rule_tac x=g in bexI) (auto intro: gR) |
|
702 |
qed |
|
703 |
||
704 |
text\<open>The ``unpretentious'' formulation\<close> |
|
705 |
lemma (in function_ring_on) Stone_Weierstrass_basic: |
|
706 |
assumes f: "continuous_on s f" and e: "e > 0" |
|
707 |
shows "\<exists>g \<in> R. \<forall>x\<in>s. \<bar>f x - g x\<bar> < e" |
|
708 |
proof - |
|
709 |
have "\<exists>g \<in> R. \<forall>x\<in>s. \<bar>(f x + normf f) - g x\<bar> < 2 * min (e/2) (1/4)" |
|
710 |
apply (rule Stone_Weierstrass_special) |
|
711 |
apply (rule Limits.continuous_on_add [OF f Topological_Spaces.continuous_on_const]) |
|
712 |
using normf_upper [OF f] apply force |
|
713 |
apply (simp add: e, linarith) |
|
714 |
done |
|
715 |
then obtain g where "g \<in> R" "\<forall>x\<in>s. \<bar>g x - (f x + normf f)\<bar> < e" |
|
716 |
by force |
|
717 |
then show ?thesis |
|
718 |
apply (rule_tac x="\<lambda>x. g x - normf f" in bexI) |
|
719 |
apply (auto simp: algebra_simps intro: diff const) |
|
720 |
done |
|
721 |
qed |
|
722 |
||
723 |
||
724 |
theorem (in function_ring_on) Stone_Weierstrass: |
|
725 |
assumes f: "continuous_on s f" |
|
726 |
shows "\<exists>F\<in>UNIV \<rightarrow> R. LIM n sequentially. F n :> uniformly_on s f" |
|
727 |
proof - |
|
728 |
{ fix e::real |
|
729 |
assume e: "0 < e" |
|
730 |
then obtain N::nat where N: "0 < N" "0 < inverse N" "inverse N < e" |
|
731 |
by (auto simp: real_arch_inv [of e]) |
|
732 |
{ fix n :: nat and x :: 'a and g :: "'a \<Rightarrow> real" |
|
733 |
assume n: "N \<le> n" "\<forall>x\<in>s. \<bar>f x - g x\<bar> < 1 / (1 + real n)" |
|
734 |
assume x: "x \<in> s" |
|
735 |
have "\<not> real (Suc n) < inverse e" |
|
61222 | 736 |
using \<open>N \<le> n\<close> N using less_imp_inverse_less by force |
60987 | 737 |
then have "1 / (1 + real n) \<le> e" |
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
738 |
using e by (simp add: field_simps of_nat_Suc) |
60987 | 739 |
then have "\<bar>f x - g x\<bar> < e" |
740 |
using n(2) x by auto |
|
741 |
} note * = this |
|
742 |
have "\<forall>\<^sub>F n in sequentially. \<forall>x\<in>s. \<bar>f x - (SOME g. g \<in> R \<and> (\<forall>x\<in>s. \<bar>f x - g x\<bar> < 1 / (1 + real n))) x\<bar> < e" |
|
743 |
apply (rule eventually_sequentiallyI [of N]) |
|
744 |
apply (auto intro: someI2_bex [OF Stone_Weierstrass_basic [OF f]] *) |
|
745 |
done |
|
746 |
} then |
|
747 |
show ?thesis |
|
748 |
apply (rule_tac x="\<lambda>n::nat. SOME g. g \<in> R \<and> (\<forall>x\<in>s. \<bar>f x - g x\<bar> < 1 / (1 + n))" in bexI) |
|
749 |
prefer 2 apply (force intro: someI2_bex [OF Stone_Weierstrass_basic [OF f]]) |
|
750 |
unfolding uniform_limit_iff |
|
751 |
apply (auto simp: dist_norm abs_minus_commute) |
|
752 |
done |
|
753 |
qed |
|
754 |
||
61222 | 755 |
text\<open>A HOL Light formulation\<close> |
60987 | 756 |
corollary Stone_Weierstrass_HOL: |
757 |
fixes R :: "('a::t2_space \<Rightarrow> real) set" and s :: "'a set" |
|
758 |
assumes "compact s" "\<And>c. P(\<lambda>x. c::real)" |
|
759 |
"\<And>f. P f \<Longrightarrow> continuous_on s f" |
|
760 |
"\<And>f g. P(f) \<and> P(g) \<Longrightarrow> P(\<lambda>x. f x + g x)" "\<And>f g. P(f) \<and> P(g) \<Longrightarrow> P(\<lambda>x. f x * g x)" |
|
761 |
"\<And>x y. x \<in> s \<and> y \<in> s \<and> ~(x = y) \<Longrightarrow> \<exists>f. P(f) \<and> ~(f x = f y)" |
|
762 |
"continuous_on s f" |
|
763 |
"0 < e" |
|
764 |
shows "\<exists>g. P(g) \<and> (\<forall>x \<in> s. abs(f x - g x) < e)" |
|
765 |
proof - |
|
766 |
interpret PR: function_ring_on "Collect P" |
|
767 |
apply unfold_locales |
|
768 |
using assms |
|
769 |
by auto |
|
770 |
show ?thesis |
|
61222 | 771 |
using PR.Stone_Weierstrass_basic [OF \<open>continuous_on s f\<close> \<open>0 < e\<close>] |
60987 | 772 |
by blast |
773 |
qed |
|
774 |
||
775 |
||
61222 | 776 |
subsection \<open>Polynomial functions\<close> |
60987 | 777 |
|
778 |
inductive real_polynomial_function :: "('a::real_normed_vector \<Rightarrow> real) \<Rightarrow> bool" where |
|
779 |
linear: "bounded_linear f \<Longrightarrow> real_polynomial_function f" |
|
780 |
| const: "real_polynomial_function (\<lambda>x. c)" |
|
781 |
| add: "\<lbrakk>real_polynomial_function f; real_polynomial_function g\<rbrakk> \<Longrightarrow> real_polynomial_function (\<lambda>x. f x + g x)" |
|
782 |
| mult: "\<lbrakk>real_polynomial_function f; real_polynomial_function g\<rbrakk> \<Longrightarrow> real_polynomial_function (\<lambda>x. f x * g x)" |
|
783 |
||
784 |
declare real_polynomial_function.intros [intro] |
|
785 |
||
786 |
definition polynomial_function :: "('a::real_normed_vector \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> bool" |
|
787 |
where |
|
788 |
"polynomial_function p \<equiv> (\<forall>f. bounded_linear f \<longrightarrow> real_polynomial_function (f o p))" |
|
789 |
||
790 |
lemma real_polynomial_function_eq: "real_polynomial_function p = polynomial_function p" |
|
791 |
unfolding polynomial_function_def |
|
792 |
proof |
|
793 |
assume "real_polynomial_function p" |
|
794 |
then show " \<forall>f. bounded_linear f \<longrightarrow> real_polynomial_function (f \<circ> p)" |
|
795 |
proof (induction p rule: real_polynomial_function.induct) |
|
796 |
case (linear h) then show ?case |
|
797 |
by (auto simp: bounded_linear_compose real_polynomial_function.linear) |
|
798 |
next |
|
799 |
case (const h) then show ?case |
|
800 |
by (simp add: real_polynomial_function.const) |
|
801 |
next |
|
802 |
case (add h) then show ?case |
|
803 |
by (force simp add: bounded_linear_def linear_add real_polynomial_function.add) |
|
804 |
next |
|
805 |
case (mult h) then show ?case |
|
806 |
by (force simp add: real_bounded_linear const real_polynomial_function.mult) |
|
807 |
qed |
|
808 |
next |
|
809 |
assume [rule_format, OF bounded_linear_ident]: "\<forall>f. bounded_linear f \<longrightarrow> real_polynomial_function (f \<circ> p)" |
|
810 |
then show "real_polynomial_function p" |
|
811 |
by (simp add: o_def) |
|
812 |
qed |
|
813 |
||
814 |
lemma polynomial_function_const [iff]: "polynomial_function (\<lambda>x. c)" |
|
815 |
by (simp add: polynomial_function_def o_def const) |
|
816 |
||
817 |
lemma polynomial_function_bounded_linear: |
|
818 |
"bounded_linear f \<Longrightarrow> polynomial_function f" |
|
819 |
by (simp add: polynomial_function_def o_def bounded_linear_compose real_polynomial_function.linear) |
|
820 |
||
821 |
lemma polynomial_function_id [iff]: "polynomial_function(\<lambda>x. x)" |
|
822 |
by (simp add: polynomial_function_bounded_linear) |
|
823 |
||
824 |
lemma polynomial_function_add [intro]: |
|
825 |
"\<lbrakk>polynomial_function f; polynomial_function g\<rbrakk> \<Longrightarrow> polynomial_function (\<lambda>x. f x + g x)" |
|
826 |
by (auto simp: polynomial_function_def bounded_linear_def linear_add real_polynomial_function.add o_def) |
|
827 |
||
828 |
lemma polynomial_function_mult [intro]: |
|
829 |
assumes f: "polynomial_function f" and g: "polynomial_function g" |
|
830 |
shows "polynomial_function (\<lambda>x. f x *\<^sub>R g x)" |
|
831 |
using g |
|
832 |
apply (auto simp: polynomial_function_def bounded_linear_def Real_Vector_Spaces.linear.scaleR const real_polynomial_function.mult o_def) |
|
833 |
apply (rule mult) |
|
834 |
using f |
|
835 |
apply (auto simp: real_polynomial_function_eq) |
|
836 |
done |
|
837 |
||
838 |
lemma polynomial_function_cmul [intro]: |
|
839 |
assumes f: "polynomial_function f" |
|
840 |
shows "polynomial_function (\<lambda>x. c *\<^sub>R f x)" |
|
841 |
by (rule polynomial_function_mult [OF polynomial_function_const f]) |
|
842 |
||
843 |
lemma polynomial_function_minus [intro]: |
|
844 |
assumes f: "polynomial_function f" |
|
845 |
shows "polynomial_function (\<lambda>x. - f x)" |
|
846 |
using polynomial_function_cmul [OF f, of "-1"] by simp |
|
847 |
||
848 |
lemma polynomial_function_diff [intro]: |
|
849 |
"\<lbrakk>polynomial_function f; polynomial_function g\<rbrakk> \<Longrightarrow> polynomial_function (\<lambda>x. f x - g x)" |
|
850 |
unfolding add_uminus_conv_diff [symmetric] |
|
851 |
by (metis polynomial_function_add polynomial_function_minus) |
|
852 |
||
853 |
lemma polynomial_function_setsum [intro]: |
|
854 |
"\<lbrakk>finite I; \<And>i. i \<in> I \<Longrightarrow> polynomial_function (\<lambda>x. f x i)\<rbrakk> \<Longrightarrow> polynomial_function (\<lambda>x. setsum (f x) I)" |
|
855 |
by (induct I rule: finite_induct) auto |
|
856 |
||
857 |
lemma real_polynomial_function_minus [intro]: |
|
858 |
"real_polynomial_function f \<Longrightarrow> real_polynomial_function (\<lambda>x. - f x)" |
|
859 |
using polynomial_function_minus [of f] |
|
860 |
by (simp add: real_polynomial_function_eq) |
|
861 |
||
862 |
lemma real_polynomial_function_diff [intro]: |
|
863 |
"\<lbrakk>real_polynomial_function f; real_polynomial_function g\<rbrakk> \<Longrightarrow> real_polynomial_function (\<lambda>x. f x - g x)" |
|
864 |
using polynomial_function_diff [of f] |
|
865 |
by (simp add: real_polynomial_function_eq) |
|
866 |
||
867 |
lemma real_polynomial_function_setsum [intro]: |
|
868 |
"\<lbrakk>finite I; \<And>i. i \<in> I \<Longrightarrow> real_polynomial_function (\<lambda>x. f x i)\<rbrakk> \<Longrightarrow> real_polynomial_function (\<lambda>x. setsum (f x) I)" |
|
869 |
using polynomial_function_setsum [of I f] |
|
870 |
by (simp add: real_polynomial_function_eq) |
|
871 |
||
872 |
lemma real_polynomial_function_power [intro]: |
|
873 |
"real_polynomial_function f \<Longrightarrow> real_polynomial_function (\<lambda>x. f x ^ n)" |
|
874 |
by (induct n) (simp_all add: const mult) |
|
875 |
||
876 |
lemma real_polynomial_function_compose [intro]: |
|
877 |
assumes f: "polynomial_function f" and g: "real_polynomial_function g" |
|
878 |
shows "real_polynomial_function (g o f)" |
|
879 |
using g |
|
880 |
apply (induction g rule: real_polynomial_function.induct) |
|
881 |
using f |
|
882 |
apply (simp_all add: polynomial_function_def o_def const add mult) |
|
883 |
done |
|
884 |
||
885 |
lemma polynomial_function_compose [intro]: |
|
886 |
assumes f: "polynomial_function f" and g: "polynomial_function g" |
|
887 |
shows "polynomial_function (g o f)" |
|
888 |
using g real_polynomial_function_compose [OF f] |
|
889 |
by (auto simp: polynomial_function_def o_def) |
|
890 |
||
891 |
lemma setsum_max_0: |
|
892 |
fixes x::real (*in fact "'a::comm_ring_1"*) |
|
893 |
shows "(\<Sum>i = 0..max m n. x^i * (if i \<le> m then a i else 0)) = (\<Sum>i = 0..m. x^i * a i)" |
|
894 |
proof - |
|
895 |
have "(\<Sum>i = 0..max m n. x^i * (if i \<le> m then a i else 0)) = (\<Sum>i = 0..max m n. (if i \<le> m then x^i * a i else 0))" |
|
896 |
by (auto simp: algebra_simps intro: setsum.cong) |
|
897 |
also have "... = (\<Sum>i = 0..m. (if i \<le> m then x^i * a i else 0))" |
|
898 |
by (rule setsum.mono_neutral_right) auto |
|
899 |
also have "... = (\<Sum>i = 0..m. x^i * a i)" |
|
900 |
by (auto simp: algebra_simps intro: setsum.cong) |
|
901 |
finally show ?thesis . |
|
902 |
qed |
|
903 |
||
904 |
lemma real_polynomial_function_imp_setsum: |
|
905 |
assumes "real_polynomial_function f" |
|
906 |
shows "\<exists>a n::nat. f = (\<lambda>x. \<Sum>i=0..n. a i * x ^ i)" |
|
907 |
using assms |
|
908 |
proof (induct f) |
|
909 |
case (linear f) |
|
910 |
then show ?case |
|
911 |
apply (clarsimp simp add: real_bounded_linear) |
|
912 |
apply (rule_tac x="\<lambda>i. if i=0 then 0 else c" in exI) |
|
913 |
apply (rule_tac x=1 in exI) |
|
914 |
apply (simp add: mult_ac) |
|
915 |
done |
|
916 |
next |
|
917 |
case (const c) |
|
918 |
show ?case |
|
919 |
apply (rule_tac x="\<lambda>i. c" in exI) |
|
920 |
apply (rule_tac x=0 in exI) |
|
61609
77b453bd616f
Coercion "real" now has type nat => real only and is no longer overloaded. Type class "real_of" is gone. Many duplicate theorems removed.
paulson <lp15@cam.ac.uk>
parents:
61284
diff
changeset
|
921 |
apply (auto simp: mult_ac of_nat_Suc) |
60987 | 922 |
done |
923 |
case (add f1 f2) |
|
924 |
then obtain a1 n1 a2 n2 where |
|
925 |
"f1 = (\<lambda>x. \<Sum>i = 0..n1. a1 i * x ^ i)" "f2 = (\<lambda>x. \<Sum>i = 0..n2. a2 i * x ^ i)" |
|
926 |
by auto |
|
927 |
then show ?case |
|
928 |
apply (rule_tac x="\<lambda>i. (if i \<le> n1 then a1 i else 0) + (if i \<le> n2 then a2 i else 0)" in exI) |
|
929 |
apply (rule_tac x="max n1 n2" in exI) |
|
930 |
using setsum_max_0 [where m=n1 and n=n2] setsum_max_0 [where m=n2 and n=n1] |
|
931 |
apply (simp add: setsum.distrib algebra_simps max.commute) |
|
932 |
done |
|
933 |
case (mult f1 f2) |
|
934 |
then obtain a1 n1 a2 n2 where |
|
935 |
"f1 = (\<lambda>x. \<Sum>i = 0..n1. a1 i * x ^ i)" "f2 = (\<lambda>x. \<Sum>i = 0..n2. a2 i * x ^ i)" |
|
936 |
by auto |
|
937 |
then obtain b1 b2 where |
|
938 |
"f1 = (\<lambda>x. \<Sum>i = 0..n1. b1 i * x ^ i)" "f2 = (\<lambda>x. \<Sum>i = 0..n2. b2 i * x ^ i)" |
|
939 |
"b1 = (\<lambda>i. if i\<le>n1 then a1 i else 0)" "b2 = (\<lambda>i. if i\<le>n2 then a2 i else 0)" |
|
940 |
by auto |
|
941 |
then show ?case |
|
942 |
apply (rule_tac x="\<lambda>i. \<Sum>k\<le>i. b1 k * b2 (i - k)" in exI) |
|
943 |
apply (rule_tac x="n1+n2" in exI) |
|
944 |
using polynomial_product [of n1 b1 n2 b2] |
|
945 |
apply (simp add: Set_Interval.atLeast0AtMost) |
|
946 |
done |
|
947 |
qed |
|
948 |
||
949 |
lemma real_polynomial_function_iff_setsum: |
|
950 |
"real_polynomial_function f \<longleftrightarrow> (\<exists>a n::nat. f = (\<lambda>x. \<Sum>i=0..n. a i * x ^ i))" |
|
951 |
apply (rule iffI) |
|
952 |
apply (erule real_polynomial_function_imp_setsum) |
|
953 |
apply (auto simp: linear mult const real_polynomial_function_power real_polynomial_function_setsum) |
|
954 |
done |
|
955 |
||
956 |
lemma polynomial_function_iff_Basis_inner: |
|
957 |
fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::euclidean_space" |
|
958 |
shows "polynomial_function f \<longleftrightarrow> (\<forall>b\<in>Basis. real_polynomial_function (\<lambda>x. inner (f x) b))" |
|
959 |
(is "?lhs = ?rhs") |
|
960 |
unfolding polynomial_function_def |
|
961 |
proof (intro iffI allI impI) |
|
962 |
assume "\<forall>h. bounded_linear h \<longrightarrow> real_polynomial_function (h \<circ> f)" |
|
963 |
then show ?rhs |
|
964 |
by (force simp add: bounded_linear_inner_left o_def) |
|
965 |
next |
|
966 |
fix h :: "'b \<Rightarrow> real" |
|
967 |
assume rp: "\<forall>b\<in>Basis. real_polynomial_function (\<lambda>x. f x \<bullet> b)" and h: "bounded_linear h" |
|
968 |
have "real_polynomial_function (h \<circ> (\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b))" |
|
969 |
apply (rule real_polynomial_function_compose [OF _ linear [OF h]]) |
|
970 |
using rp |
|
971 |
apply (auto simp: real_polynomial_function_eq polynomial_function_mult) |
|
972 |
done |
|
973 |
then show "real_polynomial_function (h \<circ> f)" |
|
974 |
by (simp add: euclidean_representation_setsum_fun) |
|
975 |
qed |
|
976 |
||
61222 | 977 |
subsection \<open>Stone-Weierstrass theorem for polynomial functions\<close> |
60987 | 978 |
|
979 |
text\<open>First, we need to show that they are continous, differentiable and separable.\<close> |
|
980 |
||
981 |
lemma continuous_real_polymonial_function: |
|
982 |
assumes "real_polynomial_function f" |
|
983 |
shows "continuous (at x) f" |
|
984 |
using assms |
|
985 |
by (induct f) (auto simp: linear_continuous_at) |
|
986 |
||
987 |
lemma continuous_polymonial_function: |
|
988 |
fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::euclidean_space" |
|
989 |
assumes "polynomial_function f" |
|
990 |
shows "continuous (at x) f" |
|
991 |
apply (rule euclidean_isCont) |
|
992 |
using assms apply (simp add: polynomial_function_iff_Basis_inner) |
|
993 |
apply (force dest: continuous_real_polymonial_function intro: isCont_scaleR) |
|
994 |
done |
|
995 |
||
996 |
lemma continuous_on_polymonial_function: |
|
997 |
fixes f :: "'a::real_normed_vector \<Rightarrow> 'b::euclidean_space" |
|
998 |
assumes "polynomial_function f" |
|
999 |
shows "continuous_on s f" |
|
1000 |
using continuous_polymonial_function [OF assms] continuous_at_imp_continuous_on |
|
1001 |
by blast |
|
1002 |
||
1003 |
lemma has_real_derivative_polynomial_function: |
|
1004 |
assumes "real_polynomial_function p" |
|
1005 |
shows "\<exists>p'. real_polynomial_function p' \<and> |
|
1006 |
(\<forall>x. (p has_real_derivative (p' x)) (at x))" |
|
1007 |
using assms |
|
1008 |
proof (induct p) |
|
1009 |
case (linear p) |
|
1010 |
then show ?case |
|
1011 |
by (force simp: real_bounded_linear const intro!: derivative_eq_intros) |
|
1012 |
next |
|
1013 |
case (const c) |
|
1014 |
show ?case |
|
1015 |
by (rule_tac x="\<lambda>x. 0" in exI) auto |
|
1016 |
case (add f1 f2) |
|
1017 |
then obtain p1 p2 where |
|
1018 |
"real_polynomial_function p1" "\<And>x. (f1 has_real_derivative p1 x) (at x)" |
|
1019 |
"real_polynomial_function p2" "\<And>x. (f2 has_real_derivative p2 x) (at x)" |
|
1020 |
by auto |
|
1021 |
then show ?case |
|
1022 |
apply (rule_tac x="\<lambda>x. p1 x + p2 x" in exI) |
|
1023 |
apply (auto intro!: derivative_eq_intros) |
|
1024 |
done |
|
1025 |
case (mult f1 f2) |
|
1026 |
then obtain p1 p2 where |
|
1027 |
"real_polynomial_function p1" "\<And>x. (f1 has_real_derivative p1 x) (at x)" |
|
1028 |
"real_polynomial_function p2" "\<And>x. (f2 has_real_derivative p2 x) (at x)" |
|
1029 |
by auto |
|
1030 |
then show ?case |
|
1031 |
using mult |
|
1032 |
apply (rule_tac x="\<lambda>x. f1 x * p2 x + f2 x * p1 x" in exI) |
|
1033 |
apply (auto intro!: derivative_eq_intros) |
|
1034 |
done |
|
1035 |
qed |
|
1036 |
||
1037 |
lemma has_vector_derivative_polynomial_function: |
|
1038 |
fixes p :: "real \<Rightarrow> 'a::euclidean_space" |
|
1039 |
assumes "polynomial_function p" |
|
1040 |
shows "\<exists>p'. polynomial_function p' \<and> |
|
1041 |
(\<forall>x. (p has_vector_derivative (p' x)) (at x))" |
|
1042 |
proof - |
|
1043 |
{ fix b :: 'a |
|
1044 |
assume "b \<in> Basis" |
|
1045 |
then |
|
1046 |
obtain p' where p': "real_polynomial_function p'" and pd: "\<And>x. ((\<lambda>x. p x \<bullet> b) has_real_derivative p' x) (at x)" |
|
61222 | 1047 |
using assms [unfolded polynomial_function_iff_Basis_inner, rule_format] \<open>b \<in> Basis\<close> |
60987 | 1048 |
has_real_derivative_polynomial_function |
1049 |
by blast |
|
1050 |
have "\<exists>q. polynomial_function q \<and> (\<forall>x. ((\<lambda>u. (p u \<bullet> b) *\<^sub>R b) has_vector_derivative q x) (at x))" |
|
1051 |
apply (rule_tac x="\<lambda>x. p' x *\<^sub>R b" in exI) |
|
61222 | 1052 |
using \<open>b \<in> Basis\<close> p' |
60987 | 1053 |
apply (simp add: polynomial_function_iff_Basis_inner inner_Basis) |
1054 |
apply (auto intro: derivative_eq_intros pd) |
|
1055 |
done |
|
1056 |
} |
|
1057 |
then obtain qf where qf: |
|
1058 |
"\<And>b. b \<in> Basis \<Longrightarrow> polynomial_function (qf b)" |
|
1059 |
"\<And>b x. b \<in> Basis \<Longrightarrow> ((\<lambda>u. (p u \<bullet> b) *\<^sub>R b) has_vector_derivative qf b x) (at x)" |
|
1060 |
by metis |
|
1061 |
show ?thesis |
|
1062 |
apply (subst euclidean_representation_setsum_fun [of p, symmetric]) |
|
1063 |
apply (rule_tac x="\<lambda>x. \<Sum>b\<in>Basis. qf b x" in exI) |
|
1064 |
apply (auto intro: has_vector_derivative_setsum qf) |
|
1065 |
done |
|
1066 |
qed |
|
1067 |
||
1068 |
lemma real_polynomial_function_separable: |
|
1069 |
fixes x :: "'a::euclidean_space" |
|
1070 |
assumes "x \<noteq> y" shows "\<exists>f. real_polynomial_function f \<and> f x \<noteq> f y" |
|
1071 |
proof - |
|
1072 |
have "real_polynomial_function (\<lambda>u. \<Sum>b\<in>Basis. (inner (x-u) b)^2)" |
|
1073 |
apply (rule real_polynomial_function_setsum) |
|
1074 |
apply (auto simp: algebra_simps real_polynomial_function_power real_polynomial_function_diff |
|
1075 |
const linear bounded_linear_inner_left) |
|
1076 |
done |
|
1077 |
then show ?thesis |
|
1078 |
apply (intro exI conjI, assumption) |
|
1079 |
using assms |
|
1080 |
apply (force simp add: euclidean_eq_iff [of x y] setsum_nonneg_eq_0_iff algebra_simps) |
|
1081 |
done |
|
1082 |
qed |
|
1083 |
||
1084 |
lemma Stone_Weierstrass_real_polynomial_function: |
|
1085 |
fixes f :: "'a::euclidean_space \<Rightarrow> real" |
|
1086 |
assumes "compact s" "continuous_on s f" "0 < e" |
|
1087 |
shows "\<exists>g. real_polynomial_function g \<and> (\<forall>x \<in> s. abs(f x - g x) < e)" |
|
1088 |
proof - |
|
1089 |
interpret PR: function_ring_on "Collect real_polynomial_function" |
|
1090 |
apply unfold_locales |
|
1091 |
using assms continuous_on_polymonial_function real_polynomial_function_eq |
|
1092 |
apply (auto intro: real_polynomial_function_separable) |
|
1093 |
done |
|
1094 |
show ?thesis |
|
61222 | 1095 |
using PR.Stone_Weierstrass_basic [OF \<open>continuous_on s f\<close> \<open>0 < e\<close>] |
60987 | 1096 |
by blast |
1097 |
qed |
|
1098 |
||
1099 |
lemma Stone_Weierstrass_polynomial_function: |
|
1100 |
fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space" |
|
1101 |
assumes s: "compact s" |
|
1102 |
and f: "continuous_on s f" |
|
1103 |
and e: "0 < e" |
|
1104 |
shows "\<exists>g. polynomial_function g \<and> (\<forall>x \<in> s. norm(f x - g x) < e)" |
|
1105 |
proof - |
|
1106 |
{ fix b :: 'b |
|
1107 |
assume "b \<in> Basis" |
|
1108 |
have "\<exists>p. real_polynomial_function p \<and> (\<forall>x \<in> s. abs(f x \<bullet> b - p x) < e / DIM('b))" |
|
1109 |
apply (rule exE [OF Stone_Weierstrass_real_polynomial_function [OF s _, of "\<lambda>x. f x \<bullet> b" "e / card Basis"]]) |
|
1110 |
using e f |
|
1111 |
apply (auto simp: Euclidean_Space.DIM_positive intro: continuous_intros) |
|
1112 |
done |
|
1113 |
} |
|
1114 |
then obtain pf where pf: |
|
1115 |
"\<And>b. b \<in> Basis \<Longrightarrow> real_polynomial_function (pf b) \<and> (\<forall>x \<in> s. abs(f x \<bullet> b - pf b x) < e / DIM('b))" |
|
1116 |
apply (rule bchoice [rule_format, THEN exE]) |
|
1117 |
apply assumption |
|
1118 |
apply (force simp add: intro: that) |
|
1119 |
done |
|
1120 |
have "polynomial_function (\<lambda>x. \<Sum>b\<in>Basis. pf b x *\<^sub>R b)" |
|
1121 |
using pf |
|
1122 |
by (simp add: polynomial_function_setsum polynomial_function_mult real_polynomial_function_eq) |
|
1123 |
moreover |
|
1124 |
{ fix x |
|
1125 |
assume "x \<in> s" |
|
1126 |
have "norm (\<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b - pf b x *\<^sub>R b) \<le> (\<Sum>b\<in>Basis. norm ((f x \<bullet> b) *\<^sub>R b - pf b x *\<^sub>R b))" |
|
1127 |
by (rule norm_setsum) |
|
1128 |
also have "... < of_nat DIM('b) * (e / DIM('b))" |
|
1129 |
apply (rule setsum_bounded_above_strict) |
|
61222 | 1130 |
apply (simp add: Real_Vector_Spaces.scaleR_diff_left [symmetric] pf \<open>x \<in> s\<close>) |
60987 | 1131 |
apply (rule DIM_positive) |
1132 |
done |
|
1133 |
also have "... = e" |
|
1134 |
using DIM_positive by (simp add: field_simps) |
|
1135 |
finally have "norm (\<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b - pf b x *\<^sub>R b) < e" . |
|
1136 |
} |
|
1137 |
ultimately |
|
1138 |
show ?thesis |
|
1139 |
apply (subst euclidean_representation_setsum_fun [of f, symmetric]) |
|
1140 |
apply (rule_tac x="\<lambda>x. \<Sum>b\<in>Basis. pf b x *\<^sub>R b" in exI) |
|
1141 |
apply (auto simp: setsum_subtractf [symmetric]) |
|
1142 |
done |
|
1143 |
qed |
|
1144 |
||
1145 |
||
1146 |
subsection\<open>Polynomial functions as paths\<close> |
|
1147 |
||
61222 | 1148 |
text\<open>One application is to pick a smooth approximation to a path, |
1149 |
or just pick a smooth path anyway in an open connected set\<close> |
|
60987 | 1150 |
|
1151 |
lemma path_polynomial_function: |
|
1152 |
fixes g :: "real \<Rightarrow> 'b::euclidean_space" |
|
1153 |
shows "polynomial_function g \<Longrightarrow> path g" |
|
1154 |
by (simp add: path_def continuous_on_polymonial_function) |
|
1155 |
||
1156 |
lemma path_approx_polynomial_function: |
|
1157 |
fixes g :: "real \<Rightarrow> 'b::euclidean_space" |
|
1158 |
assumes "path g" "0 < e" |
|
1159 |
shows "\<exists>p. polynomial_function p \<and> |
|
1160 |
pathstart p = pathstart g \<and> |
|
1161 |
pathfinish p = pathfinish g \<and> |
|
1162 |
(\<forall>t \<in> {0..1}. norm(p t - g t) < e)" |
|
1163 |
proof - |
|
1164 |
obtain q where poq: "polynomial_function q" and noq: "\<And>x. x \<in> {0..1} \<Longrightarrow> norm (g x - q x) < e/4" |
|
1165 |
using Stone_Weierstrass_polynomial_function [of "{0..1}" g "e/4"] assms |
|
1166 |
by (auto simp: path_def) |
|
1167 |
have pf: "polynomial_function (\<lambda>t. q t + (g 0 - q 0) + t *\<^sub>R (g 1 - q 1 - (g 0 - q 0)))" |
|
1168 |
by (force simp add: poq) |
|
1169 |
have *: "\<And>t. t \<in> {0..1} \<Longrightarrow> norm (((q t - g t) + (g 0 - q 0)) + (t *\<^sub>R (g 1 - q 1) + t *\<^sub>R (q 0 - g 0))) < (e/4 + e/4) + (e/4+e/4)" |
|
1170 |
apply (intro Real_Vector_Spaces.norm_add_less) |
|
1171 |
using noq |
|
1172 |
apply (auto simp: norm_minus_commute intro: le_less_trans [OF mult_left_le_one_le noq] simp del: less_divide_eq_numeral1) |
|
1173 |
done |
|
1174 |
show ?thesis |
|
1175 |
apply (intro exI conjI) |
|
1176 |
apply (rule pf) |
|
1177 |
using * |
|
1178 |
apply (auto simp add: pathstart_def pathfinish_def algebra_simps) |
|
1179 |
done |
|
1180 |
qed |
|
1181 |
||
1182 |
lemma connected_open_polynomial_connected: |
|
1183 |
fixes s :: "'a::euclidean_space set" |
|
1184 |
assumes s: "open s" "connected s" |
|
1185 |
and "x \<in> s" "y \<in> s" |
|
1186 |
shows "\<exists>g. polynomial_function g \<and> path_image g \<subseteq> s \<and> |
|
1187 |
pathstart g = x \<and> pathfinish g = y" |
|
1188 |
proof - |
|
1189 |
have "path_connected s" using assms |
|
1190 |
by (simp add: connected_open_path_connected) |
|
61222 | 1191 |
with \<open>x \<in> s\<close> \<open>y \<in> s\<close> obtain p where p: "path p" "path_image p \<subseteq> s" "pathstart p = x" "pathfinish p = y" |
60987 | 1192 |
by (force simp: path_connected_def) |
1193 |
have "\<exists>e. 0 < e \<and> (\<forall>x \<in> path_image p. ball x e \<subseteq> s)" |
|
1194 |
proof (cases "s = UNIV") |
|
1195 |
case True then show ?thesis |
|
1196 |
by (simp add: gt_ex) |
|
1197 |
next |
|
1198 |
case False |
|
1199 |
then have "- s \<noteq> {}" by blast |
|
1200 |
then show ?thesis |
|
1201 |
apply (rule_tac x="setdist (path_image p) (-s)" in exI) |
|
1202 |
using s p |
|
1203 |
apply (simp add: setdist_gt_0_compact_closed compact_path_image open_closed) |
|
1204 |
using setdist_le_dist [of _ "path_image p" _ "-s"] |
|
1205 |
by fastforce |
|
1206 |
qed |
|
1207 |
then obtain e where "0 < e"and eb: "\<And>x. x \<in> path_image p \<Longrightarrow> ball x e \<subseteq> s" |
|
1208 |
by auto |
|
1209 |
show ?thesis |
|
61222 | 1210 |
using path_approx_polynomial_function [OF \<open>path p\<close> \<open>0 < e\<close>] |
60987 | 1211 |
apply clarify |
1212 |
apply (intro exI conjI, assumption) |
|
1213 |
using p |
|
1214 |
apply (fastforce simp add: dist_norm path_image_def norm_minus_commute intro: eb [THEN subsetD])+ |
|
1215 |
done |
|
1216 |
qed |
|
1217 |
||
1218 |
hide_fact linear add mult const |
|
1219 |
||
1220 |
end |