Theory Parallel_Rewrite
theory Parallel_Rewrite
imports
Parallel_Induct
Generic_Term_Context
Ground_Term_Rewrite_System
begin
locale parallel_rewrite =
term_interpretation where Fun = Fun and is_var = "λ_. False" +
smaller_subcontext where size = size⇩c +
replace_at_subterm where Fun = Fun and is_var = "λ_. False" +
ground_term_rewrite_system
for Fun :: "'f ⇒ 'e ⇒ 't list ⇒ 't" and size⇩c :: "'c ⇒ nat"
begin
lemma parallel_induct_in_positions [case_names parallel p⇩1_in_t p⇩2_in_t base step]:
assumes
parallel: "p⇩1 ⊥ p⇩2" and
p⇩1_in_t: "p⇩1 ∈ positions t" and
p⇩2_in_t: "p⇩2 ∈ positions t" and
base:
"⋀p⇩1 p⇩2 i j q⇩1 q⇩2 t f e ts.
p⇩1 = i # q⇩1 ⟹
p⇩2 = j # q⇩2 ⟹
i ≠ j ⟹
t = Fun f e ts ⟹
j < length ts ⟹
i < length ts ⟹
P p⇩1 p⇩2 t" and
step:
"⋀p⇩1 p⇩2 p k i j q⇩1 q⇩2 t f e ts.
p⇩1 = k # p @ i # q⇩1 ⟹
p⇩2 = k # p @ j # q⇩2 ⟹
i ≠ j ⟹
t = Fun f e ts ⟹
k < length ts ⟹
p⇩1 ∈ positions t ⟹
p⇩2 ∈ positions t ⟹
P (p @ i # q⇩1) (p @ j # q⇩2) (ts ! k) ⟹
P p⇩1 p⇩2 t"
shows "P p⇩1 p⇩2 t"
using p⇩1_in_t p⇩2_in_t
proof (induction arbitrary: t rule: parallel_induct[OF parallel])
case base': (1 p⇩1 p⇩2 i j q⇩1 q⇩2 t)
obtain f e ts where t: "t = Fun f e ts"
using term_destruct[of t]
by blast
moreover have "i < length ts"
using base'(4) t
unfolding base'(1)
by simp
moreover have "j < length ts"
using base'(5) t
unfolding base'(2)
by simp
ultimately show ?case
using base' base
by metis
next
case step': (2 p⇩1 p⇩2 p k i j q⇩1 q⇩2 t)
obtain f e ts where t: "t = Fun f e ts"
using term_destruct
by metis
then have k: "k < length ts"
using step'(5)
unfolding step'(1)
by simp
show ?case
proof (rule step[OF step'(1, 2, 3) t k step'(5, 6)])
let ?p⇩1 = "p @ i # q⇩1"
let ?p⇩2 = "p @ j # q⇩2"
have "?p⇩1 ∈ positions (ts ! k)" "?p⇩2 ∈ positions (ts ! k)"
using step'(5, 6)
unfolding step'(1, 2)
by (simp_all add: t)
then show "P ?p⇩1 ?p⇩2 (ts ! k)"
using step'.IH
by blast
qed
qed
lemma parallel_replace_at:
assumes "p⇩1 ⊥ p⇩2" "p⇩1 ∈ positions t" "p⇩2 ∈ positions t"
shows "t⟦p⇩1 := s⇩1⟧⟦p⇩2 := s⇩2⟧ = t⟦p⇩2 := s⇩2⟧⟦p⇩1 := s⇩1⟧"
proof (induction rule: parallel_induct_in_positions[OF assms])
case base: (1 p⇩1 p⇩2 i j q⇩1 q⇩2 t f e ts)
let ?p⇩1 = "i # q⇩1"
let ?p⇩2 = "j # q⇩2"
let ?s⇩1 = "(ts ! i)⟦q⇩1 := s⇩1⟧"
let ?s⇩2 = "(ts ! j)⟦q⇩2 := s⇩2⟧"
let ?ts⇩1 = "ts[i := ?s⇩1]"
let ?ts⇩2 = "ts[j := ?s⇩2]"
note i_neq_j = base(3)
note i = base(6)
note j = base(5)
have j': "j < length ?ts⇩1" and i': "i < length ?ts⇩2"
using i j
by simp_all
have "t⟦?p⇩1 := s⇩1⟧⟦?p⇩2 := s⇩2⟧ = (Fun f e ?ts⇩1)⟦?p⇩2 := s⇩2⟧"
unfolding base upd_conv_take_nth_drop[OF i]
by simp
also have "... = Fun f e (?ts⇩1[j := ?s⇩2])"
unfolding upd_conv_take_nth_drop[OF j']
using i_neq_j
by simp
also have "... = Fun f e (?ts⇩2[i := ?s⇩1])"
using list_update_swap[OF i_neq_j]
by metis
also have "... = (Fun f e ?ts⇩2)⟦?p⇩1 := s⇩1⟧"
unfolding upd_conv_take_nth_drop[OF i']
using i_neq_j
by simp
also have "... = t⟦?p⇩2 := s⇩2⟧⟦?p⇩1 := s⇩1⟧"
unfolding upd_conv_take_nth_drop[OF j] base
by simp
finally show ?case
unfolding base
by satx
next
case step: 2
then show ?case
by (simp add: nth_append)
qed
lemma parallel_rewrite_in_context:
assumes
parallel: "p⇩1 ⊥ p⇩2" and
p⇩1_in_t: "p⇩1 ∈ positions t" and
p⇩2_in_t: "p⇩2 ∈ positions t" and
l⇩2: "l⇩2 = t !⇩t 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⟩, ?c⟨r⇩2⟩)"
unfolding l⇩2 parallel_replace_at[OF parallel p⇩1_in_t p⇩2_in_t] context_at_subterm_at[OF p⇩2_in_t] ..
qed (rule l⇩2_r⇩2)
end
end