Theory First_Order_Clause
theory First_Order_Clause
imports
Ground_Clause
Abstract_Substitution.Substitution_First_Order_Term
Variable_Substitution
Clausal_Calculus_Extra
Multiset_Extra
Term_Rewrite_System
Term_Ordering_Lifting
"HOL-Eisbach.Eisbach"
HOL_Extra
begin
no_notation subst_compose (infixl "∘⇩s" 75)
no_notation subst_apply_term (infixl "⋅" 67)
text ‹Prefer @{thm [source] term_subst.subst_id_subst} to @{thm [source] subst_apply_term_empty}.›
declare subst_apply_term_empty[no_atp]
section ‹\<^session>‹First_Order_Terms› And \<^session>‹Abstract_Substitution››
type_synonym 'f ground_term = "'f gterm"
type_synonym 'f ground_context = "'f gctxt"
type_synonym ('f, 'v) "context" = "('f, 'v) ctxt"
type_synonym 'f ground_atom = "'f gatom"
type_synonym ('f, 'v) atom = "('f, 'v) term uprod"
notation subst_apply_term (infixl "⋅t" 67)
notation subst_compose (infixl "⊙" 75)
notation subst_apply_ctxt (infixl "⋅t⇩c" 67)
lemmas clause_simp_term =
subst_apply_term_ctxt_apply_distrib vars_term_ctxt_apply literal.sel
named_theorems clause_simp
named_theorems clause_intro
lemma ball_set_uprod [clause_simp]: "(∀t∈set_uprod (Upair t⇩1 t⇩2). P t) ⟷ P t⇩1 ∧ P t⇩2"
by auto
lemma infinite_terms [clause_intro]: "infinite (UNIV :: ('f, 'v) term set)"
proof-
have "infinite (UNIV :: ('f, 'v) term list set)"
using infinite_UNIV_listI.
then have "⋀f :: 'f. infinite ((Fun f) ` (UNIV :: ('f, 'v) term list set))"
by (meson finite_imageD injI term.inject(2))
then show "infinite (UNIV :: ('f, 'v) term set)"
using infinite_super top_greatest by blast
qed
lemma literal_cases: "⟦𝒫 ∈ {Pos, Neg}; 𝒫 = Pos ⟹ P; 𝒫 = Neg ⟹ P⟧ ⟹ P"
by blast
method clause_simp uses simp intro =
auto simp only: simp clause_simp clause_simp_term intro: intro clause_intro
method clause_auto uses simp intro =
(clause_simp simp: simp intro: intro)?,
(auto simp: simp intro intro)?,
(auto simp: simp clause_simp intro: intro clause_intro)?
locale vars_def =
fixes vars_def :: "'expression ⇒ 'variables"
begin
abbreviation "vars ≡ vars_def"
end
locale grounding_def =
fixes
to_ground_def :: "'non_ground ⇒ 'ground" and
from_ground_def :: "'ground ⇒ 'non_ground"
begin
abbreviation "to_ground ≡ to_ground_def"
abbreviation "from_ground ≡ from_ground_def"
end
section ‹Term›
global_interpretation "term": vars_def where vars_def = vars_term.
global_interpretation "context": vars_def where
vars_def = "vars_ctxt".
global_interpretation "term": grounding_def where
to_ground_def = gterm_of_term and from_ground_def = term_of_gterm .
global_interpretation "context": grounding_def where
to_ground_def = gctxt_of_ctxt and from_ground_def = ctxt_of_gctxt.
global_interpretation
"term": base_variable_substitution where
subst = subst_apply_term and id_subst = Var and comp_subst = "(⊙)" and
vars = "term.vars :: ('f, 'v) term ⇒ 'v set" +
"term": finite_variables where vars = "term.vars :: ('f, 'v) term ⇒ 'v set" +
"term": all_subst_ident_iff_ground where
is_ground = "term.is_ground :: ('f, 'v) term ⇒ bool" and subst = "(⋅t)"
proof unfold_locales
show "⋀t σ τ. (⋀x. x ∈ term.vars t ⟹ σ x = τ x) ⟹ t ⋅t σ = t ⋅t τ"
using term_subst_eq.
next
fix t :: "('f, 'v) term"
show "finite (term.vars t)"
by simp
next
fix t :: "('f, 'v) term"
show "(term.vars t = {}) = (∀σ. t ⋅t σ = t)"
using is_ground_trm_iff_ident_forall_subst.
next
fix t :: "('f, 'v) term" and ts :: "('f, 'v) term set"
assume "finite ts" "term.vars t ≠ {}"
then show "∃σ. t ⋅t σ ≠ t ∧ t ⋅t σ ∉ ts"
proof(induction t arbitrary: ts)
case (Var x)
obtain t' where t': "t' ∉ ts" "is_Fun t'"
using Var.prems(1) finite_list by blast
define σ :: "('f, 'v) subst" where "⋀x. σ x = t'"
have "Var x ⋅t σ ≠ Var x"
using t'
unfolding σ_def
by auto
moreover have "Var x ⋅t σ ∉ ts"
using t'
unfolding σ_def
by simp
ultimately show ?case
using Var
by blast
next
case (Fun f args)
obtain a where a: "a ∈ set args" and a_vars: "term.vars a ≠ {}"
using Fun.prems by fastforce
then obtain σ where
σ: "a ⋅t σ ≠ a" and
a_σ_not_in_args: "a ⋅t σ ∉ ⋃ (set ` term.args ` ts)"
by (metis Fun.IH Fun.prems(1) List.finite_set finite_UN finite_imageI)
then have "Fun f args ⋅t σ ≠ Fun f args"
by (metis a subsetI term.set_intros(4) term_subst.comp_subst.left.action_neutral
vars_term_subset_subst_eq)
moreover have "Fun f args ⋅t σ ∉ ts"
using a a_σ_not_in_args
by auto
ultimately show ?case
using Fun
by blast
qed
next
show "⋀γ t. (term.vars (t ⋅t γ) = {}) = (∀x ∈ term.vars t. term.vars (γ x) = {})"
by (meson is_ground_iff)
next
show "∃t. term.vars t = {}"
by (meson vars_term_of_gterm)
qed
lemma term_context_ground_iff_term_is_ground [clause_simp]:
"Term_Context.ground t = term.is_ground t"
by(induction t) simp_all
global_interpretation
"term": grounding where
vars = "term.vars :: ('f, 'v) term ⇒ 'v set" and id_subst = Var and comp_subst = "(⊙)" and
subst = "(⋅t)" and to_ground = term.to_ground and from_ground = term.from_ground
proof unfold_locales
have "⋀t :: ('f, 'v) term. term.is_ground t ⟹ ∃g. term.from_ground g = t"
proof(intro exI)
fix t :: "('f, 'v) term"
assume "term.is_ground t"
then show "term.from_ground (term.to_ground t) = t"
by(induction t)(simp_all add: map_idI)
qed
then show "{t :: ('f, 'v) term. term.is_ground t} = range term.from_ground"
by fastforce
next
show "⋀g. term.to_ground (term.from_ground g) = g"
by simp
qed
global_interpretation "context": all_subst_ident_iff_ground where
is_ground = "λκ. context.vars κ = {}" and subst = "(⋅t⇩c)"
proof unfold_locales
fix κ :: "('f, 'v) context"
show "context.vars κ = {} = (∀σ. κ ⋅t⇩c σ = κ)"
proof (intro iffI)
show "context.vars κ = {} ⟹ ∀σ. κ ⋅t⇩c σ = κ"
by(induction κ) (simp_all add: list.map_ident_strong)
next
assume "∀σ. κ ⋅t⇩c σ = κ"
then have "⋀t⇩G. term.is_ground t⇩G ⟹ ∀σ. κ⟨t⇩G⟩ ⋅t σ = κ⟨t⇩G⟩"
by simp
then have "⋀t⇩G. term.is_ground t⇩G ⟹ term.is_ground κ⟨t⇩G⟩"
by (meson is_ground_trm_iff_ident_forall_subst)
then show "context.vars κ = {}"
by (metis sup.commute sup_bot_left vars_term_ctxt_apply vars_term_of_gterm)
qed
next
fix κ :: "('f, 'v) context" and κs :: "('f, 'v) context set"
assume finite: "finite κs" and non_ground: "context.vars κ ≠ {}"
then show "∃σ. κ ⋅t⇩c σ ≠ κ ∧ κ ⋅t⇩c σ ∉ κs"
proof(induction κ arbitrary: κs)
case Hole
then show ?case
by simp
next
case (More f ts κ ts')
show ?case
proof(cases "context.vars κ = {}")
case True
let ?sub_terms =
"λκ :: ('f, 'v) context. case κ of More _ ts _ ts' ⇒ set ts ∪ set ts' | _ ⇒ {}"
let ?κs' = "set ts ∪ set ts' ∪ ⋃(?sub_terms ` κs)"
from True obtain t where t: "t ∈ set ts ∪ set ts'" and non_ground: "¬term.is_ground t"
using More.prems by auto
have "⋀κ. finite (?sub_terms κ)"
proof-
fix κ
show "finite (?sub_terms κ)"
by(cases κ) simp_all
qed
then have "finite (⋃(?sub_terms ` κs))"
using More.prems(1) by blast
then have finite: "finite ?κs'"
by blast
obtain σ where σ: "t ⋅t σ ≠ t" and κs': "t ⋅t σ ∉ ?κs'"
using term.exists_non_ident_subst[OF finite non_ground]
by blast
then have "More f ts κ ts' ⋅t⇩c σ ≠ More f ts κ ts'"
using t set_map_id[of _ _ "λt. t ⋅t σ"]
by auto
moreover have " More f ts κ ts' ⋅t⇩c σ ∉ κs"
using κs' t
by auto
ultimately show ?thesis
by blast
next
case False
let ?sub_contexts = "(λκ. case κ of More _ _ κ _ ⇒ κ) ` {κ ∈ κs. κ ≠ □}"
have "finite ?sub_contexts"
using More.prems(1)
by auto
then obtain σ where σ: "κ ⋅t⇩c σ ≠ κ" and sub_contexts: "κ ⋅t⇩c σ ∉ ?sub_contexts"
using More.IH[OF _ False]
by blast
then have "More f ts κ ts' ⋅t⇩c σ ≠ More f ts κ ts'"
by simp
moreover have "More f ts κ ts' ⋅t⇩c σ ∉ κs"
using sub_contexts image_iff
by fastforce
ultimately show ?thesis
by blast
qed
qed
qed