Theory Superposition

theory Superposition
  imports
    First_Order_Clause.Nonground_Order_With_Equality
    First_Order_Clause.Nonground_Selection_Function
    First_Order_Clause.Nonground_Typing_With_Equality
    First_Order_Clause.Typed_Tiebreakers
    First_Order_Clause.Infinite_Variables
                          
    Ground_Superposition
begin

section ‹Nonground Layer›

locale type_system =
  context_compatible_term_typing_properties where
  welltyped = welltyped and context_from_ground = context_from_ground +
  witnessed_nonground_typing where welltyped = welltyped
for
  welltyped :: "('v, 'ty) var_types ⇒ 't ⇒ 'ty ⇒ bool" and
  context_from_ground :: "'cG ⇒ 'c"

locale superposition_calculus =
  type_system where
  welltyped = welltyped and id_subst = "id_subst :: 'subst" and
  context_from_ground = "context_from_ground ::'cG ⇒ 'c" and 
  term_from_ground = "term_from_ground ::'tG ⇒ 't" +

  context_compatible_nonground_order where lesst = lesst +

  nonground_selection_function where
  select = select and atom_subst = "(⋅a)" and atom_vars = atom.vars and
  atom_to_ground = atom.to_ground and atom_from_ground = atom.from_ground and
  atom_is_ground = atom.is_ground +

  tiebreakers where tiebreakers = tiebreakers +

  ground_term_context' +

  infinite_variables where
  exists_nonground = term.exists_nonground and variables = "UNIV :: 'v set"
for
    select :: "'t atom select" and
    lesst :: "'t ⇒ 't ⇒ bool" and
    tiebreakers :: "('tG atom, 't atom) tiebreakers" and
    welltyped :: "('v, 'ty) var_types ⇒ 't ⇒ 'ty ⇒ bool"
begin

interpretation term_order_notation .

(* TODO: side condition order *)
inductive eq_resolution :: "('t, 'v, 'ty) typed_clause ⇒ ('t, 'v, 'ty) typed_clause ⇒ bool" where
  eq_resolutionI:
  "D = add_mset l D' ⟹
   l = t !≈ t' ⟹
   C = D' ⋅ μ ⟹
   eq_resolution (𝒱, D) (𝒱, C)"
if
  "type_preserving_on (clause.vars D) 𝒱 μ"
  "term.is_imgu μ {{t, t'}}"
  "select D = {#} ⟹ is_maximal (l ⋅l μ) (D ⋅ μ)"
  "select D ≠ {#} ⟹ is_maximal (l ⋅l μ) (select D ⋅ μ)"

inductive eq_factoring :: "('t, 'v, 'ty) typed_clause ⇒ ('t, 'v, 'ty) typed_clause ⇒ bool" where
  eq_factoringI:
  "D = add_mset l1 (add_mset l2 D') ⟹
   l1 = t1 ≈ t1' ⟹
   l2 = t2 ≈ t2' ⟹
   C = add_mset (t1 ≈ t2') (add_mset (t1' !≈ t2') D') ⋅ μ ⟹
   eq_factoring (𝒱, D) (𝒱, C)"
if
  "select D = {#}"
  "is_maximal (l1 ⋅l μ) (D ⋅ μ)"
  "¬ (t1 ⋅t μ ≼t t1' ⋅t μ)"
  "type_preserving_on (clause.vars D) 𝒱 μ"
  "term.is_imgu μ {{t1, t2}}"

inductive superposition ::
  "('t, 'v, 'ty) typed_clause ⇒
   ('t, 'v, 'ty) typed_clause ⇒
   ('t, 'v, 'ty) typed_clause ⇒ bool" where
  superpositionI:
  "E = add_mset l1 E' ⟹
   D = add_mset l2 D' ⟹
   l1 = 𝒫 (Upair c1⟨t1⟩ t1') ⟹
   l2 = t2 ≈ t2' ⟹
   C = add_mset (𝒫 (Upair (c1 ⋅tc ρ1)⟨t2' ⋅t ρ2⟩ (t1' ⋅t ρ1))) (E' ⋅ ρ1 + D' ⋅ ρ2) ⋅ μ ⟹
   superposition (𝒱2, D) (𝒱1, E) (𝒱3, C)"
if
  "𝒫 ∈ {Pos, Neg}"
  "term.exists_nonground ⟹ infinite_variables_per_type 𝒱1"
  "term.exists_nonground ⟹ infinite_variables_per_type 𝒱2"
  "term.is_renaming ρ1"
  "term.is_renaming ρ2"
  "clause.vars (E ⋅ ρ1) ∩ clause.vars (D ⋅ ρ2) = {}"
  "¬ term.is_Var t1"
  "type_preserving_on (clause.vars (E ⋅ ρ1) ∪ clause.vars (D ⋅ ρ2)) 𝒱3 μ"
  "term.is_imgu μ {{t1 ⋅t ρ1, t2 ⋅t ρ2}}"
  "¬ (E ⋅ ρ1 ⊙ μ ≼c D ⋅ ρ2 ⊙ μ)"
  "¬ (c1⟨t1⟩ ⋅t ρ1 ⊙ μ ≼t t1' ⋅t ρ1 ⊙ μ)"
  "¬ (t2 ⋅t ρ2 ⊙ μ ≼t t2' ⋅t ρ2 ⊙ μ)"
  "𝒫 = Pos ⟹ select E = {#}"
  "𝒫 = Pos ⟹ is_strictly_maximal (l1 ⋅l ρ1 ⊙ μ) (E ⋅ ρ1 ⊙ μ)"
  "𝒫 = Neg ⟹ select E = {#} ⟹ is_maximal (l1 ⋅l ρ1 ⊙ μ) (E ⋅ ρ1 ⊙ μ)"
  "𝒫 = Neg ⟹ select E ≠ {#} ⟹ is_maximal (l1 ⋅l ρ1 ⊙ μ) ((select E) ⋅ ρ1 ⊙ μ)"
  "select D = {#}"
  "is_strictly_maximal (l2 ⋅l ρ2 ⊙ μ) (D ⋅ ρ2 ⊙ μ)"
  "∀x ∈ clause.vars E. 𝒱1 x = 𝒱3 (term.rename ρ1 x)"
  "∀x ∈ clause.vars D. 𝒱2 x = 𝒱3 (term.rename ρ2 x)"
  "type_preserving_on (clause.vars E) 𝒱1 ρ1"
  "type_preserving_on (clause.vars D) 𝒱2 ρ2"
  "clause.weakly_welltyped 𝒱3 C ⟹ literal.weakly_welltyped 𝒱2 l2"

abbreviation eq_factoring_inferences where
  "eq_factoring_inferences ≡ { Infer [D] C | D C. eq_factoring D C }"

abbreviation eq_resolution_inferences where
  "eq_resolution_inferences ≡ { Infer [D] C | D C. eq_resolution D C }"

abbreviation superposition_inferences where
  "superposition_inferences ≡ { Infer [D, E] C | D E C. superposition D E C }"

definition inferences :: "('t, 'v, 'ty) typed_clause inference set" where
  "inferences ≡ superposition_inferences ∪ eq_resolution_inferences ∪ eq_factoring_inferences"

abbreviation bottomF :: "('t, 'v, 'ty) typed_clause set" ("⊥F") where
  "bottomF ≡ {(𝒱, {#}) | 𝒱. term.exists_nonground ⟶ infinite_variables_per_type 𝒱 }"

end

end