527 assumes fin: "finite (range x)" |
527 assumes fin: "finite (range x)" |
528 shows "\<exists>k. limit x = range (suffix k x)" |
528 shows "\<exists>k. limit x = range (suffix k x)" |
529 proof - |
529 proof - |
530 have "\<exists>k. range (suffix k x) \<subseteq> limit x" |
530 have "\<exists>k. range (suffix k x) \<subseteq> limit x" |
531 proof - |
531 proof - |
532 -- "The set of letters that are not in the limit is certainly finite." |
532 \<comment> "The set of letters that are not in the limit is certainly finite." |
533 from fin have "finite (range x - limit x)" |
533 from fin have "finite (range x - limit x)" |
534 by simp |
534 by simp |
535 -- "Moreover, any such letter occurs only finitely often" |
535 \<comment> "Moreover, any such letter occurs only finitely often" |
536 moreover |
536 moreover |
537 have "\<forall>a \<in> range x - limit x. finite (x -` {a})" |
537 have "\<forall>a \<in> range x - limit x. finite (x -` {a})" |
538 by (auto simp add: limit_vimage) |
538 by (auto simp add: limit_vimage) |
539 -- "Thus, there are only finitely many occurrences of such letters." |
539 \<comment> "Thus, there are only finitely many occurrences of such letters." |
540 ultimately have "finite (UN a : range x - limit x. x -` {a})" |
540 ultimately have "finite (UN a : range x - limit x. x -` {a})" |
541 by (blast intro: finite_UN_I) |
541 by (blast intro: finite_UN_I) |
542 -- "Therefore these occurrences are within some initial interval." |
542 \<comment> "Therefore these occurrences are within some initial interval." |
543 then obtain k where "(UN a : range x - limit x. x -` {a}) \<subseteq> {..<k}" |
543 then obtain k where "(UN a : range x - limit x. x -` {a}) \<subseteq> {..<k}" |
544 by (blast dest: finite_nat_bounded) |
544 by (blast dest: finite_nat_bounded) |
545 -- "This is just the bound we are looking for." |
545 \<comment> "This is just the bound we are looking for." |
546 hence "\<forall>m. k \<le> m \<longrightarrow> x m \<in> limit x" |
546 hence "\<forall>m. k \<le> m \<longrightarrow> x m \<in> limit x" |
547 by (auto simp add: limit_vimage) |
547 by (auto simp add: limit_vimage) |
548 hence "range (suffix k x) \<subseteq> limit x" |
548 hence "range (suffix k x) \<subseteq> limit x" |
549 by auto |
549 by auto |
550 thus ?thesis .. |
550 thus ?thesis .. |
622 next |
622 next |
623 { |
623 { |
624 fix a assume a: "a \<in> set w" |
624 fix a assume a: "a \<in> set w" |
625 then obtain k where k: "k < length w \<and> w!k = a" |
625 then obtain k where k: "k < length w \<and> w!k = a" |
626 by (auto simp add: set_conv_nth) |
626 by (auto simp add: set_conv_nth) |
627 -- "the following bound is terrible, but it simplifies the proof" |
627 \<comment> "the following bound is terrible, but it simplifies the proof" |
628 from nempty k have "\<forall>m. w\<^sup>\<omega> ((Suc m)*(length w) + k) = a" |
628 from nempty k have "\<forall>m. w\<^sup>\<omega> ((Suc m)*(length w) + k) = a" |
629 by (simp add: mod_add_left_eq) |
629 by (simp add: mod_add_left_eq) |
630 moreover |
630 moreover |
631 -- "why is the following so hard to prove??" |
631 \<comment> "why is the following so hard to prove??" |
632 have "\<forall>m. m < (Suc m)*(length w) + k" |
632 have "\<forall>m. m < (Suc m)*(length w) + k" |
633 proof |
633 proof |
634 fix m |
634 fix m |
635 from nempty have "1 \<le> length w" by arith |
635 from nempty have "1 \<le> length w" by arith |
636 hence "m*1 \<le> m*length w" by simp |
636 hence "m*1 \<le> m*length w" by simp |
659 qed |
659 qed |
660 |
660 |
661 text \<open> |
661 text \<open> |
662 The converse relation is not true in general: $f(a)$ can be in the |
662 The converse relation is not true in general: $f(a)$ can be in the |
663 limit of $f \circ w$ even though $a$ is not in the limit of $w$. |
663 limit of $f \circ w$ even though $a$ is not in the limit of $w$. |
664 However, @{text limit} commutes with renaming if the function is |
664 However, \<open>limit\<close> commutes with renaming if the function is |
665 injective. More generally, if $f(a)$ is the image of only finitely |
665 injective. More generally, if $f(a)$ is the image of only finitely |
666 many elements, some of these must be in the limit of $w$. |
666 many elements, some of these must be in the limit of $w$. |
667 \<close> |
667 \<close> |
668 |
668 |
669 lemma limit_o_inv: |
669 lemma limit_o_inv: |
670 assumes fin: "finite (f -` {x})" |
670 assumes fin: "finite (f -` {x})" |
671 and x: "x \<in> limit (f \<circ> w)" |
671 and x: "x \<in> limit (f \<circ> w)" |
672 shows "\<exists>a \<in> (f -` {x}). a \<in> limit w" |
672 shows "\<exists>a \<in> (f -` {x}). a \<in> limit w" |
673 proof (rule ccontr) |
673 proof (rule ccontr) |
674 assume contra: "\<not> ?thesis" |
674 assume contra: "\<not> ?thesis" |
675 -- "hence, every element in the pre-image occurs only finitely often" |
675 \<comment> "hence, every element in the pre-image occurs only finitely often" |
676 then have "\<forall>a \<in> (f -` {x}). finite {n. w n = a}" |
676 then have "\<forall>a \<in> (f -` {x}). finite {n. w n = a}" |
677 by (simp add: limit_def Inf_many_def) |
677 by (simp add: limit_def Inf_many_def) |
678 -- "so there are only finitely many occurrences of any such element" |
678 \<comment> "so there are only finitely many occurrences of any such element" |
679 with fin have "finite (\<Union> a \<in> (f -` {x}). {n. w n = a})" |
679 with fin have "finite (\<Union> a \<in> (f -` {x}). {n. w n = a})" |
680 by auto |
680 by auto |
681 -- \<open>these are precisely those positions where $x$ occurs in $f \circ w$\<close> |
681 \<comment> \<open>these are precisely those positions where $x$ occurs in $f \circ w$\<close> |
682 moreover |
682 moreover |
683 have "(\<Union> a \<in> (f -` {x}). {n. w n = a}) = {n. f(w n) = x}" |
683 have "(\<Union> a \<in> (f -` {x}). {n. w n = a}) = {n. f(w n) = x}" |
684 by auto |
684 by auto |
685 ultimately |
685 ultimately |
686 -- "so $x$ can occur only finitely often in the translated word" |
686 \<comment> "so $x$ can occur only finitely often in the translated word" |
687 have "finite {n. f(w n) = x}" |
687 have "finite {n. f(w n) = x}" |
688 by simp |
688 by simp |
689 -- \<open>\ldots\ which yields a contradiction\<close> |
689 \<comment> \<open>\ldots\ which yields a contradiction\<close> |
690 with x show "False" |
690 with x show "False" |
691 by (simp add: limit_def Inf_many_def) |
691 by (simp add: limit_def Inf_many_def) |
692 qed |
692 qed |
693 |
693 |
694 theorem limit_inj [simp]: |
694 theorem limit_inj [simp]: |