src/HOL/Library/Omega_Words_Fun.thy
changeset 67443 3abf6a722518
parent 64593 50c715579715
child 68977 c73ca43087c0
equal deleted inserted replaced
67442:f075640b8868 67443:3abf6a722518
   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     \<comment> "The set of letters that are not in the limit is certainly finite."
   532     \<comment> \<open>The set of letters that are not in the limit is certainly finite.\<close>
   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     \<comment> "Moreover, any such letter occurs only finitely often"
   535     \<comment> \<open>Moreover, any such letter occurs only finitely often\<close>
   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     \<comment> "Thus, there are only finitely many occurrences of such letters."
   539     \<comment> \<open>Thus, there are only finitely many occurrences of such letters.\<close>
   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     \<comment> "Therefore these occurrences are within some initial interval."
   542     \<comment> \<open>Therefore these occurrences are within some initial interval.\<close>
   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     \<comment> "This is just the bound we are looking for."
   545     \<comment> \<open>This is just the bound we are looking for.\<close>
   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     \<comment> "the following bound is terrible, but it simplifies the proof"
   627     \<comment> \<open>the following bound is terrible, but it simplifies the proof\<close>
   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 [symmetric])
   629       by (simp add: mod_add_left_eq [symmetric])
   630     moreover
   630     moreover
   631     \<comment> "why is the following so hard to prove??"
   631     \<comment> \<open>why is the following so hard to prove??\<close>
   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
   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   \<comment> "hence, every element in the pre-image occurs only finitely often"
   675   \<comment> \<open>hence, every element in the pre-image occurs only finitely often\<close>
   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   \<comment> "so there are only finitely many occurrences of any such element"
   678   \<comment> \<open>so there are only finitely many occurrences of any such element\<close>
   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   \<comment> \<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   \<comment> "so $x$ can occur only finitely often in the translated word"
   686   \<comment> \<open>so $x$ can occur only finitely often in the translated word\<close>
   687   have "finite {n. f(w n) = x}"
   687   have "finite {n. f(w n) = x}"
   688     by simp
   688     by simp
   689   \<comment> \<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)