theory GTT
imports TR.Tree_Automata FOR.Lift_Root_Step
begin
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 π’)"
inductive gtt_accept :: "('q, 'f) gtt β 'f gterm β 'f gterm β bool" for π’ where
refl [intro]: "gtt_accept π’ t t"
| join [intro]: "q |β| gta_der (fst π’) s βΉ q |β| gta_der (snd π’) t βΉ gtt_accept π’ s t"
| ctxt [intro]: "length ss = length ts βΉ
βi < length ss. gtt_accept π’ (ss ! i) (ts ! i) βΉ
gtt_accept π’ (GFun f ss) (GFun f ts)"
hide_fact (open) refl
inductive gtt_accept' :: "('q, 'f) gtt β 'f gterm β 'f gterm β bool"
for π’ where
mctxt [intro]: "length ss = length ts βΉ num_gholes C = length ss βΉ
βi < length ts. βq. q |β| gta_der (fst π’) (ss ! i) β§ q |β| gta_der (snd π’) (ts ! i) βΉ
gtt_accept' π’ (fill_gholes C ss) (fill_gholes C ts)"
text βΉlanguage accepted by a GTTβΊ
abbreviation gtt_lang :: "('q, 'f) gtt β 'f gterm rel" where
"gtt_lang π’ β‘ {(s, t). gtt_accept π’ s t}"
abbreviation gtt_lang_terms :: "('q, 'f) gtt β ('f, 'q) term rel" where
"gtt_lang_terms π’ β‘ {(s, t). gtt_accept π’ (gterm_of_term s) (gterm_of_term t) β§ ground s β§ ground t}"
lemma term_of_gterm_gtt_lang_gtt_lang_terms_conv:
"map_both term_of_gterm ` gtt_lang π’ = gtt_lang_terms π’"
by auto (metis CollectI case_prodI gterm_of_term_inv map_prod_imageI)
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 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)
lemma gtt_accept'_refl [simp]:
"gtt_accept' π’ t t"
proof -
have "gtt_accept' π’ (fill_gholes (gmctxt_of_gterm t) [])
(fill_gholes (gmctxt_of_gterm t) [])" by fastforce
thus ?thesis by simp
qed
lemma gtt_accept'_join [simp]:
assumes "q |β| gta_der (fst π’) s" "q |β| gta_der (snd π’) t"
shows "gtt_accept' π’ s t"
proof -
have "gtt_accept' π’ (fill_gholes GMHole [s]) (fill_gholes GMHole [t])"
using assms by (intro gtt_accept'.intros) auto
thus ?thesis by simp
qed
lemma gtt_cont_extrct:
assumes "gtt_accept' π’ s t"
shows "βC ss ts. s =β©Gβ©f (C, ss) β§ t =β©Gβ©f (C, ts) β§
(βi < length ts. βq. q |β| gta_der (fst π’) (ss ! i) β§
q |β| gta_der (snd π’) (ts ! i))"
using assms by (auto elim!: gtt_accept'.cases) (metis eq_gfill.intros)
lemma gtt_accept'E [elim]:
assumes "gtt_accept' π’ s t"
obtains C ss ts where "s = fill_gholes C ss" "t = fill_gholes C ts"
"num_gholes C = length ss" "num_gholes C = length ts"
"β i < length ts. βq. q |β| gta_der (fst π’) (ss ! i) β§ q |β| gta_der (snd π’) (ts ! i)"
using gtt_cont_extrct[OF assms] eqgfE
by blast
lemma gtt_accept'_closed:
assumes "length ss = length ts" "β i < length ts. gtt_accept' π’ (ss ! i) (ts ! i)"
shows " gtt_accept' π’ (GFun f ss) (GFun f ts)"
proof -
let ?Prop = "Ξ» (C, ss',ts') i. ss ! i =β©Gβ©f (C, ss') β§ ts ! i =β©Gβ©f (C, ts') β§
(βj < length ts'. βq. q |β| gta_der (fst π’) (ss' ! j) β§
q |β| gta_der (snd π’) (ts' ! j)) β§
gtt_accept' π’ (fill_gholes C ss') (fill_gholes C ts')"
from assms gtt_cont_extrct[of π’ "ss ! i" "ts ! i" for i]
have "β i < length ts. β C ss' ts'. ?Prop (C, ss', ts') i" for i
by auto (metis eqgfE(1))
then obtain xs where inv: "length ts = length xs" "β i < length xs. ?Prop (xs ! i) i"
using Ex_list_of_length_P[of "length ts" ?Prop]
by fastforce
define Ds where "Ds β‘ map fst xs" define sss where "sss β‘ map (fst β snd) xs"
define tss where "tss β‘ map (snd β snd) xs" note unf = Ds_def sss_def tss_def
let ?C = "GMFun f (replicate (length Ds) GMHole)"
have len: "length ts = length Ds" "length Ds = length sss" "length sss = length tss"
using inv(1) by (auto simp: unf comp_def)
then have eq: "β i < length tss. ss ! i =β©Gβ©f (Ds ! i, sss ! i)" "β i < length tss. ts ! i =β©Gβ©f (Ds ! i, tss ! i)"
using len inv by (auto simp: unf)
then have len_inn: "β i < length tss. length (sss ! i) = length (tss ! i)"
using len by auto (metis eqgfE(2))
have mem: "β i < length (concat tss). β q. q |β| gta_der (fst π’) (concat sss ! i) β§ q |β| gta_der (snd π’) (concat tss ! i)"
using len len_inn inv by (intro concat_nth_nthI) (auto simp: unf comp_def case_prod_unfold)
have *: "fill_gholes ?C ss = GFun f ss" "fill_gholes ?C ts = GFun f ts"
using len assms(1) by (auto simp del: fill_gholes.simps)
have s: "GFun f ss =β©Gβ©f (fill_gholes_gmctxt ?C Ds, concat sss)"
using assms(1) eq len_inn len inv(1) unfolding *[symmetric]
by (intro fill_gholes_gmctxt_sound) (auto simp add: assms(1))
have t: "GFun f ts =β©Gβ©f (fill_gholes_gmctxt ?C Ds, concat tss)"
using assms(1) eq len_inn len inv(1) unfolding *[symmetric]
by (intro fill_gholes_gmctxt_sound) (auto simp add: assms(1))
show ?thesis unfolding eqgfE[OF s] eqgfE[OF t]
using mem len inv(1) len_inn eq eqgfE(2)[OF s] eqgfE(2)[OF t]
by (intro gtt_accept'.mctxt[of "concat sss" "concat tss" "fill_gholes_gmctxt ?C Ds" π’])
(auto simp del: fill_gholes_gmctxt.simps fill_gholes.simps)
qed
lemma gtt_accept_equiv:
"gtt_accept π’ s t β· gtt_accept' π’ s t"
proof (rule iffI)
assume "gtt_accept π’ s t"
then show "gtt_accept' π’ s t"
proof (induction rule: gtt_accept.induct)
case (ctxt ss ts f)
then show ?case using gtt_accept'_closed[OF ctxt(1), of π’]
by auto
qed auto
next
assume "gtt_accept' π’ s t"
then show "gtt_accept π’ s t"
proof (induction rule: gtt_accept'.induct)
case (mctxt ss ts C) thus ?case
proof (induction C arbitrary: ss ts)
case GMHole
then obtain s' t' where "ss = [s']" "ts = [t']" by (cases ss; cases ts) fastforce+
thus ?case using GMHole(3) by auto
next
case (GMFun f Cs)
moreover { fix i
assume asm: "i < length Cs"
hence lengths_eq: "length (partition_gholes ss Cs ! i) = length (partition_gholes ts Cs ! i)"
by (metis calculation(2, 3) length_map length_partition_by_nth num_gholes.simps(2))
have num_holes_length: "num_gholes (Cs ! i) = length (partition_gholes ss Cs ! i)"
using asm GMFun(3) by (simp add: length_partition_by_nth)
have join: "βj<length (partition_gholes ts Cs ! i).
βq. q |β| gta_der (fst π’) ((partition_gholes ss Cs ! i) ! j) β§
q |β| gta_der (snd π’) ((partition_gholes ts Cs ! i) ! j)"
using GMFun(2,3,4)
by (simp add: asm length_partition_by_nth partition_by_nth_nth(1) partition_by_nth_nth(2))
have "gtt_accept π’ (fill_gholes (Cs ! i) (partition_gholes ss Cs ! i))
(fill_gholes (Cs ! i) (partition_gholes ts Cs ! i))"
using asm GMFun(1)[OF _ lengths_eq num_holes_length join] by auto
}
ultimately show ?case using length_upt[of 0 "length Cs"] unfolding fill_gholes.simps
by (intro gtt_accept.intros(3)) auto
qed
qed
qed
lemma accept'_closed_ctxt:
assumes "length ss = length ts"
and "βi < length ts. gtt_accept' π’ (ss ! i) (ts ! i)"
and "num_gholes C = length ss"
shows "gtt_accept' π’ (fill_gholes C ss) (fill_gholes C ts)" using assms
proof (induction C arbitrary: ss ts)
case GMHole
then show ?case
by (cases ss; cases ts) auto
next
case (GMFun f Cs)
let ?sss = "(partition_gholes ss Cs)"
let ?tss = "(partition_gholes ts Cs)"
obtain Css Cts where Css_Cts:"fill_gholes (GMFun f Cs) ss = GFun f Css"
"fill_gholes (GMFun f Cs) ts = GFun f Cts" "length Cts = length Css"
by simp
{fix i
assume loc_asm: "i < length Cs"
hence "length (?sss ! i) = length (?tss ! i)" using assms(1) GMFun
by (simp add: length_partition_by_nth)
moreover have "num_gholes (Cs ! i) = length (?sss ! i)" using assms(2) loc_asm GMFun
by (simp add: length_partition_by_nth)
moreover have "βj < length (?tss ! i). gtt_accept' π’ ((?sss ! i) ! j) ((?tss ! i) ! j)"
using loc_asm GMFun assms(3)
by (simp add: calculation(1, 2) partition_by_nth_nth(1, 2))
ultimately have "gtt_accept' π’ (fill_gholes (Cs ! i) (?sss ! i)) (fill_gholes (Cs ! i) (?tss ! i))"
using GMFun(1) loc_asm by force
hence "gtt_accept π’ (fill_gholes (Cs!i) (?sss!i)) (fill_gholes (Cs ! i) (?tss ! i))"
using gtt_accept_equiv by blast}
hence "βi < length Cts. gtt_accept π’ (Css ! i) (Cts ! i)" using Css_Cts by fastforce
hence "gtt_accept π’ (GFun f Css) (GFun f Cts)" using Css_Cts(3) by auto
then show ?case using gtt_accept_equiv Css_Cts by metis
qed
lemma gtt_lang_from_agtt_lang:
"gtt_lang π’ = lift_root_step UNIV PAny EParallel (agtt_lang π’)"
by (auto simp: lift_root_step.simps gtt_accept_equiv agtt_lang_def elim!: gtt_accept'E gmctxtex_onpE)
text βΉInverse of GTTs.βΊ
lemma gtt_accept_swap [simp]:
"gtt_accept (prod.swap π’) s t β· gtt_accept π’ t s"
unfolding gtt_accept_equiv
by (intro iffI; elim gtt_accept'.cases; metis gtt_accept'.intros fst_swap snd_swap)
lemma gtt_lang_swap:
"(gtt_lang (A, B))Β― = gtt_lang (B, A)"
using gtt_accept_swap[of "(A, B)"] by auto
lemma gmctxtex_onp_gtt_accpet:
"gmctxtex_onp (Ξ»C. True) (agtt_lang π’)= gtt_lang π’"
using gtt_lang_from_agtt_lang[ unfolded lift_root_step.simps, of π’]
unfolding agtt_lang_def
by force
lemma gtt_lang_signature_closed:
"signature_closed UNIV (gtt_lang π’)"
unfolding gmctxtex_onp_gtt_accpet[symmetric]
by (intro gmctxtex_onp_sig_closed) simp
abbreviation mctxt_of_terms where
"mctxt_of_terms s t β‘ (mctxt_of_term s) β (mctxt_of_term t)"
abbreviation residuals where
"residuals s t β‘ inf_mctxt_args (mctxt_of_term s) (mctxt_of_term t)"
lemma term_mctxt [simp]:
"term_of_mctxt (MFun f (map mctxt_of_term ts)) = Fun f ts"
by (metis term_of_mctxt_mctxt_of_term_id mctxt_of_term.simps(2))
lemma map_zip_fun:
assumes "length xs = length ys"
shows "map (Ξ»(x,y). f x y) (zip (map g xs) (map g ys)) =
map (Ξ»(x,y). f (g x) (g y)) (zip xs ys)"
by (simp add: map_nth_eq_conv)
lemma terms_to_common_residuals:
fixes s t :: "('f, 'v) term"
shows "s = fill_holes (mctxt_of_terms s t) (map term_of_mctxt (residuals s t)) β§
t = fill_holes (mctxt_of_terms s t) (map term_of_mctxt (residuals t s))"
proof (induction s arbitrary: t)
case (Var x) thus ?case
proof (induction t)
case (Var y)
have "num_holes (MVar y β MVar x) = num_holes (MVar x β MVar y)" by simp
define n_holes where "n_holes = (Ξ» (x::'v) y. num_holes (MVar x β MVar y))"
have "(n_holes y x = n_holes x y β§ Var y = Var x) β¨
(n_holes y x = n_holes x y β§ y β x)" using n_holes_def by simp
thus ?case by fastforce
next
case (Fun f ts)
have "Fun f ts = term_of_mctxt (MFun f (map mctxt_of_term ts))"
by (metis mctxt_of_term.simps(2) term_of_mctxt_mctxt_of_term_id)
hence "Fun f ts = fill_holes (mctxt_of_terms (Var x) (Fun f ts))
(map term_of_mctxt (residuals (Fun f ts) (Var x)))"
using term_mctxt[of f ts] by fastforce
thus ?case by auto
qed
next
case (Fun g ss) thus ?case
proof (induction t arbitrary: g ss)
case (Var y)
have "Fun g ss = fill_holes (mctxt_of_terms (Var y) (Fun g ss))
(map term_of_mctxt (residuals (Fun g ss) (Var y)))"
using term_mctxt[of g ss] by fastforce
thus ?case using term_mctxt[of g ss] by fastforce
next
case (Fun f ts) thus ?case
proof (cases "f = g β§ length ts = length ss")
case True
hence "mctxt_of_terms (Fun g ss) (Fun f ts) =
MFun f (map (Ξ»(s',t'). mctxt_of_terms s' t') (zip ss ts))"
using True by (simp add: zip_nth_conv)
let ?Cs = "map (Ξ»(s',t'). mctxt_of_terms s' t') (zip ss ts)" and
?ts = "residuals (Fun g ss) (Fun f ts)" and
?ts' = "map (Ξ»(s',t'). inf_mctxt_args s' t') (zip (map mctxt_of_term ss) (map mctxt_of_term ts))" and
?ts'' = "map (Ξ»(s',t'). residuals s' t') (zip ss ts)" and
?ss = "residuals (Fun f ts) (Fun g ss)" and
?ss' = "map (Ξ»(t',s'). inf_mctxt_args t' s') (zip (map mctxt_of_term ts) (map mctxt_of_term ss))" and
?ss'' = "map (Ξ»(t',s'). residuals t' s') (zip ts ss)"
{ fix s' t' :: "('f, 'v) Term.term" and ss' ts'
assume "s' β set ss'" "t' β set ts'"
hence "length (residuals s' t') = num_holes (mctxt_of_terms s' t')"
"length (residuals s' t') = num_holes (mctxt_of_terms t' s')"
using num_holes_inf_mctxt by (metis, metis inf_mctxt_comm)
} note residuals_num_holes = this
have "i < length (map num_holes ?Cs) βΉ
length (?ts'' ! i) = (map num_holes ?Cs) ! i" for i
using residuals_num_holes(1)[of _ ss _ ts] True by force
hence "partition_by ?ts (map num_holes ?Cs) = ?ts'"
using partition_by_concat_id[of ?ts' "map num_holes ?Cs"] True by simp
hence part1: "map (Ξ»(s', t'). residuals s' t') (zip ss ts) = partition_holes ?ts ?Cs"
using True map_zip_fun by metis
have "i < length (map num_holes ?Cs) βΉ
length (?ss'' ! i) = (map num_holes ?Cs) ! i" for i
using residuals_num_holes(2)[of _ ts _ ss] True by force
hence "partition_by ?ss (map num_holes ?Cs) = ?ss'"
using partition_by_concat_id[of ?ss' "map num_holes ?Cs"] True by simp
hence part2: "map (Ξ»(t', s'). residuals t' s') (zip ts ss) = partition_holes ?ss ?Cs"
using True map_zip_fun by metis
have push_map_inside: "(map term_of_mctxt) β (Ξ»(x, y). residuals x y) =
(Ξ»(x, y). map term_of_mctxt (residuals x y))" by auto
{ fix i
assume "i < length ss"
hence ith_in_set: "ss ! i β set ss" using True by simp+
hence IH': "ss ! i = fill_holes (mctxt_of_terms (ss ! i) (ts ! i))
(map term_of_mctxt (residuals (ss ! i) (ts ! i)))"
"ts ! i = fill_holes (mctxt_of_terms (ss ! i) (ts ! i))
(map term_of_mctxt (residuals (ts ! i) (ss ! i)))"
using Fun(2)[of "ss ! i" "ts ! i"] True by (meson set_zip_leftD)+
have "ss ! i = fill_holes (map (Ξ»(x, y). mctxt_of_terms x y) (zip ss ts) ! i)
(map (Ξ»(x, y). map term_of_mctxt (residuals x y)) (zip ss ts) ! i)"
"ts ! i = fill_holes (map (Ξ»(x, y). mctxt_of_terms x y) (zip ss ts) ! i)
(map (Ξ»(x, y). map term_of_mctxt (residuals x y)) (zip ts ss) ! i)"
using IH' True nth_map[of i "zip ss ts"] βΉi < length ssβΊ by force+
} note inner = this
have "Fun g ss = fill_holes (mctxt_of_terms (Fun g ss) (Fun f ts))
(map term_of_mctxt (residuals (Fun g ss) (Fun f ts)))"
using True part1[symmetric]
by (simp add: map_map_partition_by[symmetric] map_zip_fun push_map_inside)
(smt inner(1) atLeastLessThan_iff map_eq_conv map_nth set_upt)
moreover have "Fun f ts = fill_holes (mctxt_of_terms (Fun g ss) (Fun f ts))
(map term_of_mctxt (residuals (Fun f ts) (Fun g ss)))"
using True part2[symmetric]
by (simp add: map_map_partition_by[symmetric] map_zip_fun push_map_inside)
(smt inner(2) atLeastLessThan_iff map_eq_conv map_nth set_upt)
ultimately show ?thesis using True by blast
next
case False
thus ?thesis using term_mctxt[of f ts] term_mctxt[of g ss] by fastforce
qed
qed
qed
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
proof (induction)
case (refl t)
then show ?case using ta_der'_refl by blast
next
case (join q s t)
then show ?case
by (metis gta_der_def ta_der_to_ta_der')
next
case (ctxt 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 ctxt(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_accept_mono:
assumes "rules (fst π’) |β| rules (fst π’')" "eps (fst π’) |β| eps (fst π’')"
"rules (snd π’) |β| rules (snd π’')" "eps (snd π’) |β| eps (snd π’')"
"gtt_accept π’ s t"
shows "gtt_accept π’' s t"
using ta_der_mono[OF assms(1, 2)] ta_der_mono[OF assms(3, 4)]
using assms(5) unfolding gtt_accept_equiv
by (auto simp: gta_der_def elim!: gtt_accept'.cases intro!: mctxt) (meson fin_mono)
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 ground_map_vars_mctxt_simp:
"ground_mctxt C βΉ map_vars_mctxt f C = map_vars_mctxt (Ξ»_. undefined) C"
by (induct C) 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
proof (intro set_eqI iffI, goal_cases lr rl)
case (lr x)
obtain C ss ts where x: "x = (fill_gholes C ss, fill_gholes C ts)"
"length ss = num_gholes C" "length ts = num_gholes C"
"βi. i < num_gholes C βΉ βq. q |β| gta_der (fmap_states_ta f (fst π’)) (ss ! i) β§
q |β| gta_der (fmap_states_ta f (snd π’)) (ts ! i)"
using lr by (auto 0 0 simp: gtt_accept_equiv elim!: gtt_accept'.cases)
{ fix i assume i: "i < num_gholes C"
obtain q where q: "q |β| gta_der (fmap_states_ta f (fst π’)) (ss ! i)"
"q |β| gta_der (fmap_states_ta f (snd π’)) (ts ! i)" using x(4)[OF i] by blast
then have "the_finv_into (gtt_states π’) f q |β| gta_der (fst π’) (ss ! i) β§
the_finv_into (gtt_states π’) f q |β| gta_der (snd π’) (ts ! i)"
using assms by (simp add: gta_der_def gtt_states_def ta_der_fmap_states_inv_superset)
then have "β p. p |β| gta_der (fst π’) (ss ! i) β§ p |β| gta_der (snd π’) (ts ! i)"
using assms by blast}
then have "gtt_accept' π’ (fill_gholes C ss) (fill_gholes C ts)"
using x(2,3) by (auto simp: adapt_vars_def map_vars_term_fill_holes)
then show ?case using x
by (simp add: gtt_accept_equiv)
next
case (rl x)
obtain C ss ts where x: "x = (fill_gholes C ss, fill_gholes C ts)"
"length ss = num_gholes C" "length ts = num_gholes C"
"βi. i < num_gholes C βΉ βq. q |β| gta_der (fst π’) (ss ! i) β§ q |β| gta_der (snd π’) (ts ! i)"
using rl by (auto 0 0 simp: gtt_accept_equiv image_def elim!: gtt_accept'.cases)
from x(4) obtain qs where qs: "qs i |β| gta_der (fst π’) (ss ! i) β§ qs i |β| gta_der (snd π’) (ts ! i)"
if "i < num_gholes C" for i by metis
have "gtt_accept' (fmap_states_gtt f π’) (fst x) (snd x)"
using gtt_accept'.intros[of ss ts C "fmap_states_gtt f π’"] x
using ta_der_fmap_states_ta[OF conjunct1[OF qs, unfolded gta_der_def], where h = f]
using ta_der_fmap_states_ta[OF conjunct2[OF qs, unfolded gta_der_def], where h = f]
by (metis fmap_states_gtt_def fst_map_prod gta_der_def map_vars_term_term_of_gterm prod.sel(1, 2) snd_map_prod)
then show ?case using x by (auto simp: gtt_accept_equiv fmap_states_gtt_def)
qed
definition gtt_only_reach where
"gtt_only_reach = map_both ta_only_reach"
lemma gtt_only_reach_lang:
"gtt_lang (gtt_only_reach π’) = gtt_lang π’"
proof (intro equalityI subrelI, goal_cases LR RL)
case (LR s t)
then obtain C ss ts qs where
s: "s = fill_gholes C ss" "length ss = num_gholes C" and
t: "t = fill_gholes C ts" "length ts = num_gholes C" and
q: "βi. i < num_gholes C βΉ β q. q |β| gta_der (fst (gtt_only_reach π’)) (ss ! i) β§
q |β| gta_der (snd (gtt_only_reach π’)) (ts ! i)"
by (auto 0 0 simp: gtt_accept_equiv elim!: gtt_accept'.cases)
have "β q . q |β| gta_der (fst π’) (ss ! i) β§ q |β| gta_der (snd π’) (ts ! i)" if "i < num_gholes C" for i
using q[of i] that
by (auto simp: gta_der_def gtt_only_reach_def simp flip: ta_der_gterm_only_reach)
then show ?case using s t by (auto simp: gtt_accept_equiv)
next
case (RL s t)
then obtain C ss ts qs where
s: "s = fill_gholes C ss" "length ss = num_gholes C" and
t: "t = fill_gholes C ts" "length ts = num_gholes C" and
q: "βi. i < num_gholes C βΉ βq. q |β| gta_der (fst π’) (ss ! i) β§ q |β| gta_der (snd π’) (ts ! i)"
by (auto 0 0 simp: gtt_accept_equiv elim!: gtt_accept'.cases)
have "β q. q |β| gta_der (fst (gtt_only_reach π’)) (ss ! i) β§ q |β| gta_der (snd (gtt_only_reach π’)) (ts ! i)"
if "i < num_gholes C" for i
using q[of i] that s t
by (auto simp add: gta_der_def gtt_only_reach_def simp flip: ta_der_gterm_only_reach)
then show ?case using s t by (auto simp: gtt_accept_equiv)
qed
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)
definition gtt_only_prod where
"gtt_only_prod π’ = (let iface = gtt_interface π’ in
map_both (ta_only_prod iface) π’)"
lemma gtt_only_prod_lang:
"gtt_lang (gtt_only_prod π’) = gtt_lang π’"
proof (intro equalityI subrelI, goal_cases LR RL)
case (LR s t)
then obtain C ss ts qs where
s: "s = fill_gholes C ss" "length ss = num_gholes C" and
t: "t = fill_gholes C ts" "length ts = num_gholes C" and
q: "βi. i < num_gholes C βΉ β q. q |β| gta_der (fst (gtt_only_prod π’)) (ss ! i) β§
q |β| gta_der (snd (gtt_only_prod π’)) (ts ! i)"
by (auto 0 0 simp: gtt_accept_equiv elim!: gtt_accept'.cases)
have "βq. q |β| gta_der (fst π’) (ss ! i) β§ q |β| gta_der (snd π’) (ts ! i)" if "i < num_gholes C" for i using q[OF that]
by (auto simp: gta_der_def gtt_only_prod_def Let_def intro: ta_der_ta_only_prod_ta_der)
then show ?case using s t by (auto simp: gtt_accept_equiv)
next
case (RL s t)
then obtain C ss ts qs where
s: "s = fill_gholes C ss" "length ss = num_gholes C" and
t: "t = fill_gholes C ts" "length ts = num_gholes C" and
q: "βi. i < num_gholes C βΉ βq. q |β| gta_der (fst π’) (ss ! i) β§ q |β| gta_der (snd π’) (ts ! i)"
by (auto 0 0 simp: gtt_accept_equiv elim!: gtt_accept'.cases)
{fix i assume i: "i < num_gholes C"
guess q using q[OF i] by (elim exE conjE) note q = this
have "q |β| gtt_interface π’" using q
by (simp add: gta_der_def gtt_interface_def)
then have "q |β| gta_der (fst (gtt_only_prod π’)) (ss ! i)" "q |β| gta_der (snd (gtt_only_prod π’)) (ts ! i)"
using q
by (auto simp: gta_der_def gtt_only_prod_def Let_def gtt_interface_def ta_der_only_prod ta_productive_setI)
then have "βq. q |β| gta_der (fst (gtt_only_prod π’)) (ss ! i) β§ q |β| gta_der (snd (gtt_only_prod π’)) (ts ! i)"
by auto}
then show ?case using s t by (auto simp: gtt_accept_equiv)
qed
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)
definition trim_gtt where
"trim_gtt = gtt_only_prod β gtt_only_reach"
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)+
end