3366 |
3366 |
3367 shows "foldr (%c r. f c o r) cs (%c. g c a) c0 $ n = |
3367 shows "foldr (%c r. f c o r) cs (%c. g c a) c0 $ n = |
3368 foldr (%c r. (k c + of_nat n) * r) cs (g c0 a $ n)" |
3368 foldr (%c r. (k c + of_nat n) * r) cs (g c0 a $ n)" |
3369 by (induct cs arbitrary: c0) (auto simp add: algebra_simps f) |
3369 by (induct cs arbitrary: c0) (auto simp add: algebra_simps f) |
3370 |
3370 |
|
3371 lemma dist_less_imp_nth_equal: |
|
3372 assumes "dist f g < inverse (2 ^ i)" |
|
3373 assumes "j \<le> i" |
|
3374 shows "f $ j = g $ j" |
|
3375 proof cases |
|
3376 assume "f \<noteq> g" |
|
3377 hence "\<exists>n. f $ n \<noteq> g $ n" by (simp add: fps_eq_iff) |
|
3378 with assms have "i < The (leastP (\<lambda>n. f $ n \<noteq> g $ n))" |
|
3379 by (simp add: split_if_asm dist_fps_def) |
|
3380 moreover |
|
3381 from fps_eq_least_unique[OF `f \<noteq> g`] |
|
3382 obtain n where "leastP (\<lambda>n. f$n \<noteq> g$n) n" "The (leastP (\<lambda>n. f $ n \<noteq> g $ n)) = n" by blast |
|
3383 moreover hence "\<And>m. m < n \<Longrightarrow> f$m = g$m" "f$n \<noteq> g$n" |
|
3384 by (auto simp add: leastP_def setge_def) |
|
3385 ultimately show ?thesis using `j \<le> i` by simp |
|
3386 qed simp |
|
3387 |
|
3388 lemma nth_equal_imp_dist_less: |
|
3389 assumes "\<And>j. j \<le> i \<Longrightarrow> f $ j = g $ j" |
|
3390 shows "dist f g < inverse (2 ^ i)" |
|
3391 proof cases |
|
3392 assume "f \<noteq> g" |
|
3393 hence "\<exists>n. f $ n \<noteq> g $ n" by (simp add: fps_eq_iff) |
|
3394 with assms have "dist f g = inverse (2 ^ (The (leastP (\<lambda>n. f $ n \<noteq> g $ n))))" |
|
3395 by (simp add: split_if_asm dist_fps_def) |
|
3396 moreover |
|
3397 from fps_eq_least_unique[OF `f \<noteq> g`] |
|
3398 obtain n where "leastP (\<lambda>n. f$n \<noteq> g$n) n" "The (leastP (\<lambda>n. f $ n \<noteq> g $ n)) = n" by blast |
|
3399 with assms have "i < The (leastP (\<lambda>n. f $ n \<noteq> g $ n))" |
|
3400 by (metis (full_types) leastPD1 not_le) |
|
3401 ultimately show ?thesis by simp |
|
3402 qed simp |
|
3403 |
|
3404 lemma dist_less_eq_nth_equal: |
|
3405 shows "dist f g < inverse (2 ^ i) \<longleftrightarrow> (\<forall>j \<le> i. f $ j = g $ j)" |
|
3406 using dist_less_imp_nth_equal nth_equal_imp_dist_less by blast |
|
3407 |
|
3408 instance fps :: (comm_ring_1) complete_space |
|
3409 proof |
|
3410 fix X::"nat \<Rightarrow> 'a fps" |
|
3411 assume "Cauchy X" |
|
3412 { |
|
3413 fix i |
|
3414 have "0 < inverse ((2::real)^i)" by simp |
|
3415 from metric_CauchyD[OF `Cauchy X` this] dist_less_imp_nth_equal |
|
3416 have "\<exists>M. \<forall>m \<ge> M. \<forall>j\<le>i. X M $ j = X m $ j" by blast |
|
3417 } |
|
3418 then obtain M where M: "\<forall>i. \<forall>m \<ge> M i. \<forall>j \<le> i. X (M i) $ j = X m $ j" by metis |
|
3419 hence "\<forall>i. \<forall>m \<ge> M i. \<forall>j \<le> i. X (M i) $ j = X m $ j" by metis |
|
3420 show "convergent X" |
|
3421 proof (rule convergentI) |
|
3422 show "X ----> Abs_fps (\<lambda>i. X (M i) $ i)" |
|
3423 unfolding tendsto_iff |
|
3424 proof safe |
|
3425 fix e::real assume "0 < e" |
|
3426 with LIMSEQ_inverse_realpow_zero[of 2, simplified, simplified filterlim_iff, |
|
3427 THEN spec, of "\<lambda>x. x < e"] |
|
3428 have "eventually (\<lambda>i. inverse (2 ^ i) < e) sequentially" |
|
3429 by safe (auto simp: eventually_nhds) |
|
3430 then obtain i where "inverse (2 ^ i) < e" by (auto simp: eventually_sequentially) |
|
3431 have "eventually (\<lambda>x. M i \<le> x) sequentially" by (auto simp: eventually_sequentially) |
|
3432 thus "eventually (\<lambda>x. dist (X x) (Abs_fps (\<lambda>i. X (M i) $ i)) < e) sequentially" |
|
3433 proof eventually_elim |
|
3434 fix x assume "M i \<le> x" |
|
3435 moreover |
|
3436 have "\<And>j. j \<le> i \<Longrightarrow> X (M i) $ j = X (M j) $ j" |
|
3437 using M by (metis nat_le_linear) |
|
3438 ultimately have "dist (X x) (Abs_fps (\<lambda>j. X (M j) $ j)) < inverse (2 ^ i)" |
|
3439 using M by (force simp: dist_less_eq_nth_equal) |
|
3440 also note `inverse (2 ^ i) < e` |
|
3441 finally show "dist (X x) (Abs_fps (\<lambda>j. X (M j) $ j)) < e" . |
|
3442 qed |
|
3443 qed |
|
3444 qed |
|
3445 qed |
|
3446 |
3371 end |
3447 end |