Theory IsaFoR_Ground_Critical_Pairs
theory IsaFoR_Ground_Critical_Pairs
imports
Parallel_Induct
IsaFoR_Ground_Context
Ground_Critical_Peaks
begin
text‹Adapted from First\_Order\_Rewriting.Critical\_Pairs›
type_synonym 'f ground_rewrite_system = "'f gterm rel"
interpretation ground_term_rewrite_system where
hole = □ and apply_context = apply_ground_context and compose_context = "(∘⇩c)"
by unfold_locales
lemma parallel_rewrite_in_context:
assumes
parallel: "p⇩1 ⊥ p⇩2" and
p⇩1_in_t: "p⇩1 ∈ positions⇩G t" and
p⇩2_in_t: "p⇩2 ∈ positions⇩G t" and
l⇩2: "l⇩2 = t !⇩t⇩G p⇩2" and
l⇩2_r⇩2: "(l⇩2, r⇩2) ∈ R"
shows "(t⟦p⇩1 := v⟧, t⟦p⇩1 := v⟧⟦p⇩2 := r⇩2⟧) ∈ rewrite_in_context R" (is "(?t⇩1,?t⇩2) ∈ _")
proof (unfold rewrite_in_context_def mem_Collect_eq, intro exI conjI)
let ?c = "t⟦p⇩1 := v⟧ !⇩c p⇩2"
show "(?t⇩1, ?t⇩2) = (?c⟨l⇩2⟩⇩G, ?c⟨r⇩2⟩⇩G)"
unfolding l⇩2 parallel_replace_at⇩G[OF parallel p⇩1_in_t p⇩2_in_t] gsubt_at_id[OF p⇩2_in_t] ..
qed (rule l⇩2_r⇩2)
interpretation ground_critical_peaks where
hole = □ and
apply_context = apply_ground_context and
compose_context = actxt_compose
proof unfold_locales
fix R :: "'f ground_rewrite_system" and t u s
assume
t_u: "(t, u) ∈ rewrite_in_context R" and
t_s: "(t, s) ∈ rewrite_in_context R"
show "(s, u) ∈ join (rewrite_in_context R) ∨
(∃c l m r. s = c⟨l⟩⇩G ∧ t = c⟨m⟩⇩G ∧ u = c⟨r⟩⇩G ∧
((l, m, r) ∈ ground_critical_peaks R ∨ (r, m, l) ∈ ground_critical_peaks R))"
proof -
let ?R = "rewrite_in_context R"
let ?CP = "ground_critical_peaks R"
from t_u obtain c⇩1 l⇩1 r⇩1 where
l⇩1_r⇩1: "(l⇩1, r⇩1) ∈ R" and
t1: "t = c⇩1⟨l⇩1⟩⇩G" and
u: "u = c⇩1⟨r⇩1⟩⇩G"
unfolding rewrite_in_context_def
by auto
from t_s obtain c⇩2 l⇩2 r⇩2 where
l⇩2_r⇩2: "(l⇩2, r⇩2) ∈ R" and
t2: "t = c⇩2⟨l⇩2⟩⇩G" and
s: "s = c⇩2⟨r⇩2⟩⇩G"
unfolding rewrite_in_context_def
by auto
define n where "n = size c⇩1 + size c⇩2"
from t1 t2 u s n_def show ?thesis
proof (induct n arbitrary: c⇩1 c⇩2 s t u rule: less_induct)
case (less n c⇩1 c⇩2 s t u)
show ?case
proof (cases c⇩1)
case Hole
show ?thesis
using l⇩1_r⇩1 l⇩2_r⇩2 less.prems
unfolding ground_critical_peaks_def mem_Collect_eq
by (metis Hole intp_actxt.simps(1))
next
case c⇩1: (More f⇩1 ss⇩1 c⇩1' ts⇩1)
show ?thesis
proof (cases c⇩2)
case Hole
show ?thesis
using l⇩1_r⇩1 l⇩2_r⇩2 less.prems
unfolding ground_critical_peaks_def mem_Collect_eq
by (metis Hole intp_actxt.simps(1))
next
case c⇩2: (More f⇩2 ss⇩2 c⇩2' ts⇩2)
from less(2-3) c⇩1 c⇩2
have id: "(More f⇩1 ss⇩1 c⇩1' ts⇩1)⟨l⇩1⟩⇩G = (More f⇩2 ss⇩2 c⇩2' ts⇩2)⟨l⇩2⟩⇩G"
by auto
let ?n⇩1 = "length ss⇩1"
let ?n⇩2 = "length ss⇩2"
from id have f: "f⇩1 = f⇩2"
by simp
show ?thesis
proof (cases "?n⇩1 = ?n⇩2")
case True
with id have
ss: "ss⇩1 = ss⇩2" and
ts: "ts⇩1 = ts⇩2" and
c': "c⇩1'⟨l⇩1⟩⇩G = c⇩2'⟨l⇩2⟩⇩G"
by auto
let ?c = "More f⇩2 ss⇩2 □ ts⇩2"
have c⇩1_eq: "c⇩1 = ?c ∘⇩c c⇩1'"
unfolding c⇩1 f ss ts
by simp
have c⇩2_eq: "c⇩2 = ?c ∘⇩c c⇩2'"
unfolding c⇩2 f ss ts
by simp
define m where
"m = size c⇩1' + size c⇩2'"
have m_less_n: "m < n"
unfolding less m_def c⇩1 c⇩2
by auto
note IH = less(1)[OF m_less_n refl c' refl refl m_def]
then show ?thesis
proof (elim disjE)
assume "(c⇩2'⟨r⇩2⟩⇩G, c⇩1'⟨r⇩1⟩⇩G) ∈ ?R⇧↓"
then obtain s' where
c⇩1'_s': "(c⇩1'⟨r⇩1⟩⇩G, s') ∈ ?R⇧*" and
c⇩2'_s': "(c⇩2'⟨r⇩2⟩⇩G, s') ∈ ?R⇧*"
by auto
have "(c⇩1⟨r⇩1⟩⇩G, ?c⟨s'⟩⇩G) ∈ ?R⇧*"
using c⇩1'_s'
unfolding c⇩1_eq intp_actxt_compose
by blast
moreover have "(c⇩2⟨r⇩2⟩⇩G, ?c⟨s'⟩⇩G) ∈ ?R⇧*"
using c⇩2'_s'
unfolding c⇩2_eq intp_actxt_compose
by blast
ultimately show ?thesis
using less
by auto
next
assume
"∃c l m r.
c⇩2'⟨r⇩2⟩⇩G = c⟨l⟩⇩G ∧
c⇩1'⟨l⇩1⟩⇩G = c⟨m⟩⇩G ∧
c⇩1'⟨r⇩1⟩⇩G = c⟨r⟩⇩G ∧
((l, m, r) ∈ ?CP ∨ (r, m, l) ∈ ?CP)"
then show ?thesis
by (metis c⇩1_eq c⇩2_eq intp_actxt_compose less.prems(1,3,4))
qed
next
case False
let ?p⇩1 = "?n⇩1 # hole_pos c⇩1'"
let ?p⇩2 = "?n⇩2 # hole_pos c⇩2'"
let ?one = "c⇩1⟨l⇩1⟩⇩G⟦?p⇩1 := r⇩1⟧"
let ?two = "c⇩2⟨l⇩2⟩⇩G⟦?p⇩2 := r⇩2⟧"
have parallel_p⇩1_p⇩2: "?p⇩1 ⊥ ?p⇩2"
using False
by simp
have p⇩1: "?p⇩1 ∈ positions⇩G c⇩1⟨l⇩1⟩⇩G"
unfolding c⇩1
by auto
have p⇩2: "?p⇩2 ∈ positions⇩G c⇩1⟨l⇩1⟩⇩G"
unfolding c⇩1 id
by auto
have "(?one, ?one⟦?p⇩2 := r⇩2⟧) ∈ rewrite_in_context R"
proof(rule parallel_rewrite_in_context[OF parallel_p⇩1_p⇩2 p⇩1 p⇩2 _ l⇩2_r⇩2])
show "l⇩2 = c⇩1⟨l⇩1⟩⇩G !⇩t⇩G ?p⇩2"
unfolding c⇩1 id
by simp
qed
then have "(c⇩1⟨r⇩1⟩⇩G, ?one⟦?p⇩2 := r⇩2⟧) ∈ (rewrite_in_context R)⇧*"
unfolding c⇩1
by simp
moreover have "(?two, ?two⟦?p⇩1 := r⇩1⟧) ∈ rewrite_in_context R"
proof (rule parallel_rewrite_in_context[OF parallel_pos_sym[OF parallel_p⇩1_p⇩2]])
show "?p⇩1 ∈ positions⇩G c⇩2⟨l⇩2⟩⇩G"
unfolding c⇩2 id[symmetric]
by auto
next
show "?p⇩2 ∈ positions⇩G c⇩2⟨l⇩2⟩⇩G"
unfolding c⇩2
by auto
next
show "l⇩1 = c⇩2⟨l⇩2⟩⇩G !⇩t⇩G ?p⇩1"
unfolding c⇩2 id[symmetric]
by simp
next
show "(l⇩1, r⇩1) ∈ R"
using l⇩1_r⇩1 .
qed
then have "(c⇩2⟨r⇩2⟩⇩G, ?two⟦?p⇩1 := r⇩1⟧) ∈ (rewrite_in_context R)⇧*"
unfolding c⇩2
by simp
moreover have "?one⟦?p⇩2 := r⇩2⟧ = (c⇩1⟨l⇩1⟩⇩G⟦?p⇩2 := r⇩2⟧⟦?p⇩1 := r⇩1⟧)"
by (rule parallel_replace_at⇩G[OF parallel_p⇩1_p⇩2 p⇩1 p⇩2])
then have "?one⟦?p⇩2 := r⇩2⟧ = ?two⟦?p⇩1 := r⇩1⟧"
unfolding c⇩1 c⇩2 id .
ultimately show ?thesis
unfolding less
by (intro disjI1) auto
qed
qed
qed
qed
qed
qed
end