Theory Nonground_Selection_Function

theory Nonground_Selection_Function
  imports
    Nonground_Clause
    Selection_Function
begin

type_synonym 'f ground_select = "'f ground_atom clause  'f ground_atom clause"
type_synonym ('f, 'v) select = "('f, 'v) atom clause  ('f, 'v) atom clause"

context nonground_clause
begin

definition is_select_grounding :: "('f, 'v) select  'f ground_select  bool" where
  "is_select_grounding select selectG  CG. C γ.
    clause.is_ground (C  γ) 
    CG = clause.to_ground (C  γ) 
    selectG CG = clause.to_ground ((select C)  γ)"

end

locale nonground_selection_function =
  nonground_clause +
  selection_function select
  for select :: "('f, 'v) atom clause  ('f, 'v) atom clause"
begin

abbreviation is_grounding :: "'f ground_select  bool" where
  "is_grounding selectG  is_select_grounding select selectG"

definition selectGs where
  "selectGs = { selectG. is_grounding selectG }"

definition selectG_simple where
  "selectG_simple C = clause.to_ground (select (clause.from_ground C))"

lemma selectG_simple: "is_grounding selectG_simple"
  unfolding is_select_grounding_def selectG_simple_def
  by (metis clause.from_ground_inverse clause.ground_is_ground clause.subst_id_subst)

lemma select_is_ground:
  assumes "clause.is_ground C"
  shows "clause.is_ground (select C)"
  using select_subset sub_ground_clause assms
  by metis

lemma is_ground_in_selection:
  assumes "l ∈# select (clause.from_ground C)"
  shows "literal.is_ground l"
  using assms clause.sub_in_ground_is_ground select_subset
  by blast

lemma ground_literal_in_selection:
  assumes "clause.is_ground C" "lG ∈# clause.to_ground C"
  shows "literal.from_ground lG ∈# C"
  using assms
  by (metis clause.to_ground_inverse clause.ground_sub_in_ground)

lemma select_ground_subst:
  assumes "clause.is_ground (C  γ)"
  shows "clause.is_ground (select C  γ)"
  using assms
  by (metis image_mset_subseteq_mono select_subset sub_ground_clause clause.subst_def)

lemma select_neg_subst:
  assumes "l ∈# select C  γ"
  shows "is_neg l"
  using assms subst_neg_stable select_negative_literals
  unfolding clause.subst_def
  by blast

lemma select_vars_subset: "C. clause.vars (select C)  clause.vars C"
  by (simp add: clause_submset_vars_clause_subset select_subset)

end

end