Theory Substitution_HOL_ex_Unification
theory Substitution_HOL_ex_Unification
imports
Based_Substitution
"HOL-ex.Unification"
Fresh_Identifiers.Fresh
begin
section ‹Substitutions for first order terms as binary tree›
no_notation Comb (infix ‹⋅› 60)
quotient_type 'v subst = "('v × 'v trm) list" / "(≐)"
proof (rule equivpI)
show "reflp (≐)"
using reflpI subst_refl by metis
next
show "symp (≐)"
using sympI subst_sym by metis
next
show "transp (≐)"
using transpI subst_trans by metis
qed
subsection ‹Substitution monoid›
lift_definition subst_comp :: "'v subst ⇒ 'v subst ⇒ 'v subst" (infixl ‹⊙› 67)
is Unification.comp
using Unification.subst_cong .
lift_definition subst_id :: "'v subst"
is "[]" .
global_interpretation subst_comp: monoid subst_comp subst_id
proof unfold_locales
fix σ σ' σ'' :: "'v subst"
show "σ ⊙ σ' ⊙ σ'' = σ ⊙ (σ' ⊙ σ'')"
by transfer auto
next
fix σ :: "'v subst"
show "subst_id ⊙ σ = σ"
by transfer simp
show "σ ⊙ subst_id = σ"
by transfer simp
qed
subsection ‹Transfer definitions and lemmas from HOL-ex.Unification›
lift_definition subst_apply :: "'v trm ⇒ 'v subst ⇒ 'v trm" (infixl ‹⋅› 61)
is Unification.subst
using Unification.subst_eq_dest .
lift_definition subst_domain :: "'v subst ⇒ 'v set"
is Unification.subst_domain
by (metis (no_types, lifting) ext subst_domain_def subst_eq_def)
lift_definition range_vars :: "'v subst ⇒ 'v set"
is Unification.range_vars
by (metis (no_types, lifting) ext range_vars_def subst_eq_def)
lift_definition Unifier :: "'v subst ⇒ 'v trm ⇒ 'v trm ⇒ bool"
is Unification.Unifier
unfolding subst_eq_def Unifier_def
by auto
lift_definition IMGU :: "'v subst ⇒ 'v trm ⇒ 'v trm ⇒ bool"
is Unification.IMGU
unfolding subst_eq_def IMGU_def
by (simp add: Unification.Unifier_def)
lift_definition unify :: "'v trm ⇒ 'v trm ⇒ 'v subst option"
is Unification.unify.
lemma unify_eq_Some_if_Unifier:
assumes "Unifier σ t t'"
shows "∃τ. unify t t' = Some τ"
proof -
obtain rep_σ where σ_def: "σ = abs_subst rep_σ"
by transfer simp
from assms have "Unification.Unifier rep_σ t t'"
unfolding σ_def
by transfer
then obtain rep_τ where "Unification.unify t t' = Some rep_τ"
using Unification.unify_eq_Some_if_Unifier
by blast
then have "unify t t' = Some (abs_subst rep_τ)"
by (simp add: unify.abs_eq)
thus ?thesis
by blast
qed
lemma unify_computes_IMGU:
assumes "unify t t' = Some σ"
shows "IMGU σ t t'"
proof -
obtain rep_σ where σ_def: "σ = abs_subst rep_σ"
by transfer simp
have "map_option abs_subst (Unification.unify t t') = Some (abs_subst rep_σ)"
using assms σ_def
by (simp add: unify.abs_eq)
then obtain rep_σ' where
"Unification.unify t t' = Some rep_σ'" and
rep_σ': "abs_subst rep_σ' = abs_subst rep_σ"
by (cases "Unification.unify t t'") auto
then have "Unification.IMGU rep_σ' t t'"
using Unification.unify_computes_IMGU
by blast
hence "IMGU (abs_subst rep_σ') t t'"
by transfer
thus "IMGU σ t t'"
using rep_σ' σ_def
by simp
qed
lift_definition subst_update :: "'v × 'v trm ⇒ 'v subst ⇒ 'v subst"
is "(#)"
proof -
fix update and σ σ' :: "('v × 'v trm) list"
assume subst_eq: "σ ≐ σ'"
{
fix t
have "t ⊲ update # σ = t ⊲ update # σ'"
proof (induction t)
case Var
then show ?case
using subst_eq
unfolding subst_eq_def
by (metis assoc.simps(2) prod.exhaust subst.simps(1))
qed simp_all
}
then show "update # σ ≐ update # σ' "
unfolding subst_eq_def
by satx
qed
subsection ‹Base Substitution›