Theory GTT
theory GTT
imports Tree_Automata Ground_Closure
begin
section βΉGround Tree Transducers (GTT)βΊ
type_synonym ('q, 'f) gtt = "('q, 'f) ta Γ ('q, 'f) ta"
abbreviation gtt_rules where
"gtt_rules π’ β‘ rules (fst π’) |βͺ| rules (snd π’)"
abbreviation gtt_eps where
"gtt_eps π’ β‘ eps (fst π’) |βͺ| eps (snd π’)"
definition gtt_states where
"gtt_states π’ = π¬ (fst π’) |βͺ| π¬ (snd π’)"
abbreviation gtt_syms where
"gtt_syms π’ β‘ ta_sig (fst π’) |βͺ| ta_sig (snd π’)"
definition gtt_interface where
"gtt_interface π’ = π¬ (fst π’) |β©| π¬ (snd π’)"
definition gtt_eps_free where
"gtt_eps_free π’ = (eps_free (fst π’), eps_free (snd π’))"
definition is_gtt_eps_free :: "('q, 'f) ta Γ ('p, 'g) ta β bool" where
"is_gtt_eps_free π’ β· eps (fst π’) = {||} β§ eps (snd π’) = {||}"
text βΉ*anchored* language accepted by a GTTβΊ
definition agtt_lang :: "('q, 'f) gtt β 'f gterm rel" where
"agtt_lang π’ = {(t, u) |t u q. q |β| gta_der (fst π’) t β§ q |β| gta_der (snd π’) u}"
lemma agtt_langI:
"q |β| gta_der (fst π’) s βΉ q |β| gta_der (snd π’) t βΉ (s, t) β agtt_lang π’"
by (auto simp: agtt_lang_def)
lemma agtt_langE:
assumes "(s, t) β agtt_lang π’"
obtains q where "q |β| gta_der (fst π’) s" "q |β| gta_der (snd π’) t"
using assms by (auto simp: agtt_lang_def)
lemma converse_agtt_lang:
"(agtt_lang π’)Β― = agtt_lang (prod.swap π’)"
by (auto simp: agtt_lang_def)
lemma agtt_lang_swap:
"agtt_lang (prod.swap π’) = prod.swap ` agtt_lang π’"
by (auto simp: agtt_lang_def)
text βΉlanguage accepted by a GTTβΊ
abbreviation gtt_lang :: "('q, 'f) gtt β 'f gterm rel" where
"gtt_lang π’ β‘ gmctxt_cl UNIV (agtt_lang π’)"
lemma gtt_lang_join:
"q |β| gta_der (fst π’) s βΉ q |β| gta_der (snd π’) t βΉ (s, t) β gmctxt_cl UNIV (agtt_lang π’)"
by (auto simp: agtt_lang_def)
definition gtt_accept where
"gtt_accept π’ s t β‘ (s, t) β gmctxt_cl UNIV (agtt_lang π’)"
lemma gtt_accept_intros:
"(s, t) β agtt_lang π’ βΉ gtt_accept π’ s t"
"length ss = length ts βΉ β i < length ts. gtt_accept π’ (ss ! i) (ts ! i) βΉ
(f, length ss) β β± βΉ gtt_accept π’ (GFun f ss) (GFun f ts)"
by (auto simp: gtt_accept_def)
abbreviation gtt_lang_terms :: "('q, 'f) gtt β ('f, 'q) term rel" where
"gtt_lang_terms π’ β‘ (Ξ» s. map_both term_of_gterm s) ` (gmctxt_cl UNIV (agtt_lang π’))"
lemma term_of_gterm_gtt_lang_gtt_lang_terms_conv:
"map_both term_of_gterm ` gtt_lang π’ = gtt_lang_terms π’"
by auto
lemma gtt_accept_swap [simp]:
"gtt_accept (prod.swap π’) s t β· gtt_accept π’ t s"
by (auto simp: gmctxt_cl_swap agtt_lang_swap gtt_accept_def)
lemma gtt_lang_swap:
"(gtt_lang (A, B))Β― = gtt_lang (B, A)"
using gtt_accept_swap[of "(A, B)"]
by (auto simp: gtt_accept_def)
lemma gtt_accept_exI:
assumes "gtt_accept π’ s t"
shows "β u. u |β| ta_der' (fst π’) (term_of_gterm s) β§ u |β| ta_der' (snd π’) (term_of_gterm t)"
using assms unfolding gtt_accept_def
proof (induction)
case (base s t)
then show ?case unfolding agtt_lang_def
by (auto simp: gta_der_def ta_der_to_ta_der')
next
case (step ss ts f)
then have inner: "β us. length us = length ss β§
(βi < length ss. (us ! i) |β| ta_der' (fst π’) (term_of_gterm (ss ! i)) β§
(us ! i) |β| ta_der' (snd π’) (term_of_gterm (ts ! i)))"
using Ex_list_of_length_P[of "length ss" "Ξ» u i. u |β| ta_der' (fst π’) (term_of_gterm (ss ! i)) β§
u |β| ta_der' (snd π’) (term_of_gterm (ts ! i))"]
by auto
then obtain us where "length us = length ss β§ (βi < length ss.
(us ! i) |β| ta_der' (fst π’) (term_of_gterm (ss ! i)) β§ (us ! i) |β| ta_der' (snd π’) (term_of_gterm (ts ! i)))"
by blast
then have "Fun f us |β| ta_der' (fst π’) (Fun f (map term_of_gterm ss)) β§
Fun f us |β| ta_der' (snd π’) (Fun f (map term_of_gterm ts))" using step(1) by fastforce
then show ?case by (metis term_of_gterm.simps)
qed
lemma agtt_lang_mono:
assumes "rules (fst π’) |β| rules (fst π’')" "eps (fst π’) |β| eps (fst π’')"
"rules (snd π’) |β| rules (snd π’')" "eps (snd π’) |β| eps (snd π’')"
shows "agtt_lang π’ β agtt_lang π’'"
using fsubsetD[OF ta_der_mono[OF assms(1, 2)]] ta_der_mono[OF assms(3, 4)]
by (auto simp: agtt_lang_def gta_der_def dest!: fsubsetD[OF ta_der_mono[OF assms(1, 2)]] fsubsetD[OF ta_der_mono[OF assms(3, 4)]])
lemma gtt_lang_mono:
assumes "rules (fst π’) |β| rules (fst π’')" "eps (fst π’) |β| eps (fst π’')"
"rules (snd π’) |β| rules (snd π’')" "eps (snd π’) |β| eps (snd π’')"
shows "gtt_lang π’ β gtt_lang π’'"
using agtt_lang_mono[OF assms]
by (intro gmctxt_cl_mono_rel) auto
definition fmap_states_gtt where
"fmap_states_gtt f β‘ map_both (fmap_states_ta f)"
lemma ground_map_vars_term_simp:
"ground t βΉ map_term f g t = map_term f (Ξ»_. undefined) t"
by (induct t) auto
lemma states_fmap_states_gtt [simp]:
"gtt_states (fmap_states_gtt f π’) = f |`| gtt_states π’"
by (simp add: fimage_funion gtt_states_def fmap_states_gtt_def)
lemma agtt_lang_fmap_states_gtt:
assumes "finj_on f (gtt_states π’)"
shows "agtt_lang (fmap_states_gtt f π’) = agtt_lang π’" (is "?Ls = ?Rs")
proof -
from assms have inj: "finj_on f (π¬ (fst π’) |βͺ| π¬ (snd π’))" "finj_on f (π¬ (fst π’))" "finj_on f (π¬ (snd π’))"
by (auto simp: gtt_states_def finj_on_fUn)
then have "?Ls β ?Rs" using ta_der_fmap_states_inv_superset[OF _ inj(1)]
by (auto simp: agtt_lang_def gta_der_def fmap_states_gtt_def)
moreover have "?Rs β ?Ls"
by (auto simp: agtt_lang_def gta_der_def fmap_states_gtt_def elim!: ta_der_to_fmap_states_der)
ultimately show ?thesis by blast
qed
lemma agtt_lang_Inl_Inr_states_agtt:
"agtt_lang (fmap_states_gtt Inl π’) = agtt_lang π’"
"agtt_lang (fmap_states_gtt Inr π’) = agtt_lang π’"
by (auto simp: finj_Inl_Inr intro!: agtt_lang_fmap_states_gtt)
lemma gtt_lang_fmap_states_gtt:
assumes "finj_on f (gtt_states π’)"
shows "gtt_lang (fmap_states_gtt f π’) = gtt_lang π’" (is "?Ls = ?Rs")
unfolding fmap_states_gtt_def
using agtt_lang_fmap_states_gtt[OF assms]
by (simp add: fmap_states_gtt_def)
definition gtt_only_reach where
"gtt_only_reach = map_both ta_only_reach"
subsection βΉ(A)GTT reachable statesβΊ
lemma agtt_only_reach_lang:
"agtt_lang (gtt_only_reach π’) = agtt_lang π’"
unfolding agtt_lang_def gtt_only_reach_def
by (auto simp: gta_der_def simp flip: ta_der_gterm_only_reach)
lemma gtt_only_reach_lang:
"gtt_lang (gtt_only_reach π’) = gtt_lang π’"
by (auto simp: agtt_only_reach_lang)
lemma gtt_only_reach_syms:
"gtt_syms (gtt_only_reach π’) |β| gtt_syms π’"
by (auto simp: gtt_only_reach_def ta_restrict_def ta_sig_def)
subsection βΉ(A)GTT productive statesβΊ
definition gtt_only_prod where
"gtt_only_prod π’ = (let iface = gtt_interface π’ in
map_both (ta_only_prod iface) π’)"
lemma agtt_only_prod_lang:
"agtt_lang (gtt_only_prod π’) = agtt_lang π’" (is "?Ls = ?Rs")
proof -
let ?A = "fst π’" let ?B = "snd π’"
have "?Ls β ?Rs" unfolding agtt_lang_def gtt_only_prod_def
by (auto simp: Let_def gta_der_def dest: ta_der_ta_only_prod_ta_der)
moreover
{fix s t assume "(s, t) β ?Rs"
then obtain q where r: "q |β| ta_der (fst π’) (term_of_gterm s)" "q |β| ta_der (snd π’) (term_of_gterm t)"
by (auto simp: agtt_lang_def gta_der_def)
then have " q |β| gtt_interface π’" by (auto simp: gtt_interface_def)
then have "(s, t) β ?Ls" using r
by (auto simp: agtt_lang_def gta_der_def gtt_only_prod_def Let_def intro!: exI[of _ q] ta_der_only_prod ta_productive_setI)}
ultimately show ?thesis by auto
qed
lemma gtt_only_prod_lang:
"gtt_lang (gtt_only_prod π’) = gtt_lang π’"
by (auto simp: agtt_only_prod_lang)
lemma gtt_only_prod_syms:
"gtt_syms (gtt_only_prod π’) |β| gtt_syms π’"
by (auto simp: gtt_only_prod_def ta_restrict_def ta_sig_def Let_def)
subsection βΉ(A)GTT trimmingβΊ
definition trim_gtt where
"trim_gtt = gtt_only_prod β gtt_only_reach"
lemma trim_agtt_lang:
"agtt_lang (trim_gtt G) = agtt_lang G"
unfolding trim_gtt_def comp_def agtt_only_prod_lang agtt_only_reach_lang ..
lemma trim_gtt_lang:
"gtt_lang (trim_gtt G) = gtt_lang G"
unfolding trim_gtt_def comp_def gtt_only_prod_lang gtt_only_reach_lang ..
lemma trim_gtt_prod_syms:
"gtt_syms (trim_gtt G) |β| gtt_syms G"
unfolding trim_gtt_def using fsubset_trans[OF gtt_only_prod_syms gtt_only_reach_syms] by simp
subsection βΉroot-cleanlinessβΊ
text βΉA GTT is root-clean if none of its interface states can occur in a non-root positions
in the accepting derivations corresponding to its anchored GTT relation.βΊ
definition ta_nr_states :: "('q, 'f) ta β 'q fset" where
"ta_nr_states A = |β| ((fset_of_list β r_lhs_states) |`| (rules A))"
definition gtt_nr_states where
"gtt_nr_states G = ta_nr_states (fst G) |βͺ| ta_nr_states (snd G)"
definition gtt_root_clean where
"gtt_root_clean G β· gtt_nr_states G |β©| gtt_interface G = {||}"
subsection βΉRelabelingβΊ
definition relabel_gtt :: "('q :: linorder, 'f) gtt β (nat, 'f) gtt" where
"relabel_gtt G = fmap_states_gtt (map_fset_to_nat (gtt_states G)) G"
lemma relabel_agtt_lang [simp]:
"agtt_lang (relabel_gtt G) = agtt_lang G"
by (simp add: agtt_lang_fmap_states_gtt map_fset_to_nat_inj relabel_gtt_def)
lemma agtt_lang_sig:
"fset (gtt_syms G) β β± βΉ agtt_lang G β π―β©G β± Γ π―β©G β±"
by (auto simp: agtt_lang_def gta_der_def π―β©G_equivalent_def)
(metis ffunas_gterm.rep_eq less_eq_fset.rep_eq subset_iff ta_der_gterm_sig)+
subsection βΉepsilon free GTTsβΊ
lemma agtt_lang_gtt_eps_free [simp]:
"agtt_lang (gtt_eps_free π’) = agtt_lang π’"
by (auto simp: agtt_lang_def gta_der_def gtt_eps_free_def ta_res_eps_free)
lemma gtt_lang_gtt_eps_free [simp]:
"gtt_lang (gtt_eps_free π’) = gtt_lang π’"
by auto
end