Theory Myhill_Nerode
theory Myhill_Nerode
imports Tree_Automata Ground_Ctxt
begin
subsection βΉMyhill Nerode characterization for regular tree languagesβΊ
lemma ground_ctxt_apply_pres_der:
assumes "ta_der π (term_of_gterm s) = ta_der π (term_of_gterm t)"
shows "ta_der π (term_of_gterm Cβ¨sβ©β©G) = ta_der π (term_of_gterm Cβ¨tβ©β©G)" using assms
by (induct C) (auto, (metis append_Cons_nth_not_middle nth_append_length)+)
locale myhill_nerode =
fixes β± β assumes term_subset: "β β π―β©G β±"
begin
definition myhill (βΉ_ β‘β©β _βΊ) where
"myhill s t β‘ s β π―β©G β± β§ t β π―β©G β± β§ (β C. Cβ¨sβ©β©G β β β§ Cβ¨tβ©β©G β β β¨ Cβ¨sβ©β©G β β β§ Cβ¨tβ©β©G β β)"
lemma myhill_sound: "s β‘β©β t βΉ s β π―β©G β±" "s β‘β©β t βΉ t β π―β©G β±"
unfolding myhill_def by auto
lemma myhill_refl [simp]: "s β π―β©G β± βΉ s β‘β©β s"
unfolding myhill_def by auto
lemma myhill_symmetric: "s β‘β©β t βΉ t β‘β©β s"
unfolding myhill_def by auto
lemma myhill_trans [trans]:
"s β‘β©β t βΉ t β‘β©β u βΉ s β‘β©β u"
unfolding myhill_def by auto
abbreviation myhill_r (βΉMNβ©ββΊ) where
"myhill_r β‘ {(s, t) | s t. s β‘β©β t}"
lemma myhill_equiv:
"equiv (π―β©G β±) MNβ©β"
apply (intro equivI) apply (auto simp: myhill_sound myhill_symmetric sym_def trans_def refl_on_def)
using myhill_trans by blast
lemma rtl_der_image_on_myhill_inj:
assumes "gta_lang Qβ©f π = β"
shows "inj_on (Ξ» X. gta_der π ` X) (π―β©G β± // MNβ©β)" (is "inj_on ?D ?R")
proof -
{fix S T assume eq_rel: "S β ?R" "T β ?R" "?D S = ?D T"
have "β s t. s β S βΉ t β T βΉ s β‘β©β t"
proof -
fix s t assume mem: "s β S" "t β T"
then obtain t' where res: "t' β T" "gta_der π s = gta_der π t'" using eq_rel(3)
by (metis image_iff)
from res(1) mem have "s β π―β©G β±" "t β π―β©G β±" "t' β π―β©G β±" using eq_rel(1, 2)
using in_quotient_imp_subset myhill_equiv by blast+
then have "s β‘β©β t'" using assms res ground_ctxt_apply_pres_der[of π s]
by (auto simp: myhill_def gta_der_def simp flip: ctxt_of_gctxt_apply
elim!: gta_langE intro: gta_langI)
moreover have "t' β‘β©β t" using quotient_eq_iff[OF myhill_equiv eq_rel(2) eq_rel(2) res(1) mem(2)]
by simp
ultimately show "s β‘β©β t" using myhill_trans by blast
qed
then have "β s t. s β S βΉ t β T βΉ (s, t) β MNβ©β" by blast
then have "S = T" using quotient_eq_iff[OF myhill_equiv eq_rel(1, 2)]
using eq_rel(3) by fastforce}
then show inj: "inj_on ?D ?R" by (meson inj_onI)
qed
lemma rtl_implies_finite_indexed_myhill_relation:
assumes "gta_lang Qβ©f π = β"
shows "finite (π―β©G β± // MNβ©β)" (is "finite ?R")
proof -
let ?D = "Ξ» X. gta_der π ` X"
have image: "?D ` ?R β Pow (fset (fPow (π¬ π)))" unfolding gta_der_def
by (meson PowI fPowI ground_ta_der_states ground_term_of_gterm image_subsetI)
then have "finite (Pow (fset (fPow (π¬ π))))" by simp
then have "finite (?D ` ?R)" using finite_subset[OF image] by fastforce
then show ?thesis using finite_image_iff[OF rtl_der_image_on_myhill_inj[OF assms]]
by blast
qed
end
end