Theory First_Order_Clause.IsaFoR_Ground_Context
theory IsaFoR_Ground_Context
imports
Generic_Context
IsaFoR_Ground_Term
begin
abbreviation hole_position where
"hole_position ≡ hole_pos"
type_synonym 'f ground_context = "('f, 'f ground_term) actxt"
abbreviation apply_ground_context (‹_⟨_⟩⇩G› [1000, 0] 1000) where
"C⟨s⟩⇩G ≡ GFun⟨C;s⟩"
interpretation ground_context: "context" where
hole = □ and
apply_context = apply_ground_context and
compose_context = actxt_compose
proof unfold_locales
fix c :: "'f ground_context" and t t'
assume "c⟨t⟩⇩G = c⟨t'⟩⇩G"
then show "t = t'"
by (induction c) auto
qed (simp_all add: intp_actxt_compose)
lemma gsubt_at_hole [simp]: "c⟨t⟩⇩G !⇩t⇩G hole_position c = t"
by (induction c) auto
lemma hole_position_in_positions⇩G [intro]: "hole_position c ∈ positions⇩G c⟨t⟩⇩G"
by (induction c) auto
fun context_at_position⇩G :: "'f ground_term ⇒ pos ⇒ 'f ground_context" (infixl ‹!⇩c› 64) where
"t !⇩c [] = □" |
"GFun f ts !⇩c i # ps = More f (take i ts) (ts!i !⇩c ps) (drop (Suc i) ts)"
text‹Behaves differently than const‹replace_gterm_at›!›
abbreviation replace_at⇩G (‹_⟦_ := _⟧› [70, 0, 50] 70) where
"replace_at⇩G t p s ≡ (t !⇩c p)⟨s⟩⇩G"
lemma replace_at⇩G_hole [simp]: "c⟨t⟩⇩G⟦hole_position c := t'⟧ = c⟨t'⟩⇩G"
by (induction c) auto
lemma gsubt_at_id:
assumes "p ∈ positions⇩G t"
shows "t⟦p := t !⇩t⇩G p⟧ = t"
using assms
by (induction t arbitrary: p) (auto simp: id_take_nth_drop[symmetric])
lemma parallel_replace_at⇩G_in_positions⇩G:
assumes "p⇩1 ⊥ p⇩2" "p⇩1 ∈ positions⇩G t"
shows "p⇩2 ∈ positions⇩G (t⟦p⇩1 := t'⟧) ⟷ p⇩2 ∈ positions⇩G t"
proof (induction rule: parallel_induct_first_in_positions⇩G[OF assms])
case base: (1 p⇩1 p⇩2 i j q⇩1 q⇩2 t f ts)
let ?p⇩1 = "i # q⇩1"
let ?t⇩i = "(ts ! i)⟦q⇩1 := t'⟧"
have "t⟦?p⇩1 := t'⟧ = GFun f (ts[i := ?t⇩i])"
unfolding base upd_conv_take_nth_drop[OF base(5)]
by simp
then show ?case
unfolding base
using base
by auto
next
case step: (2 p⇩1 p⇩2 p k i j q⇩1 q⇩2 t f ts)
then have "min (length ts) k = k"
by simp
then show ?case
using step
by (auto simp: nth_append)
qed
lemma parallel_replace_at⇩G_gsubt_at:
assumes "p⇩1 ⊥ p⇩2" "p⇩1 ∈ positions⇩G t"
shows "t⟦p⇩1 := t'⟧ !⇩t⇩G p⇩2 = t !⇩t⇩G p⇩2"
proof (induction rule: parallel_induct_first_in_positions⇩G[OF assms])
case base: (1 p⇩1 p⇩2 i j q⇩1 q⇩2 t f ts)
let ?p⇩1 = "i # q⇩1"
let ?p⇩2 = "j # q⇩2"
let ?t⇩i = "replace_at⇩G (ts ! i) q⇩1 t'"
let ?ts⇩i = "ts[i := ?t⇩i]"
have "t⟦?p⇩1 := t'⟧ !⇩t⇩G ?p⇩2 = GFun f ?ts⇩i !⇩t⇩G ?p⇩2"
unfolding base upd_conv_take_nth_drop[OF base(5)]
by simp
also have "... = ts ! j !⇩t⇩G q⇩2"
using base
by simp
finally show ?case
by (simp add: base.hyps)
next
case step: (2 p⇩1 p⇩2 p k i j q⇩1 q⇩2 t f ts)
then show ?case
by (simp add: nth_append)
qed
lemma parallel_replace_at⇩G:
assumes "p⇩1 ⊥ p⇩2" "p⇩1 ∈ positions⇩G t" "p⇩2 ∈ positions⇩G 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⇩G[OF assms])
case base: (1 p⇩1 p⇩2 i j q⇩1 q⇩2 t f 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⟧ = (GFun f ?ts⇩1)⟦?p⇩2 := s⇩2⟧"
unfolding base upd_conv_take_nth_drop[OF i]
by simp
also have "... = GFun f (?ts⇩1[j := ?s⇩2])"
unfolding upd_conv_take_nth_drop[OF j']
using i_neq_j
by simp
also have "... = GFun f (?ts⇩2[i := ?s⇩1])"
using list_update_swap[OF i_neq_j]
by simp
also have "... = (GFun f ?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
end