Theory Superposition_Alternative_Rules

theory Superposition_Alternative_Rules
  imports Superposition
begin

context superposition_calculus
begin

subsubsection ‹Alternative Specification of the Superposition Rule›

inductive superposition' ::
  "('t, 'v, 'ty) typed_clause  
   ('t, 'v, 'ty) typed_clause  
   ('t, 'v, 'ty) typed_clause  bool" where
  superposition'I:
   "(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) = {} 
    E = add_mset l1 E' 
    D = add_mset l2 D' 
    𝒫  {Pos, Neg} 
    l1 = 𝒫 (Upair c1t1 t1') 
    l2 = t2  t2' 
    ¬ 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}} 
    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) 
    ¬ (E  ρ1  μ c D  ρ2  μ) 
    (𝒫 = Pos  select E = {#}  is_strictly_maximal (l1 ⋅l ρ1  μ) (E  ρ1  μ) 
     𝒫 = Neg  (select E = {#}  is_maximal (l1 ⋅l ρ1  μ) (E  ρ1  μ) 
                  is_maximal (l1 ⋅l ρ1  μ) ((select E)  ρ1  μ))) 
    select D = {#} 
    is_strictly_maximal (l2 ⋅l ρ2  μ) (D  ρ2  μ) 
    ¬ (c1t1 ⋅t ρ1  μ t t1' ⋅t ρ1  μ) 
    ¬ (t2 ⋅t ρ2  μ t t2' ⋅t ρ2  μ) 
    C = add_mset (𝒫 (Upair (c1 ⋅tc ρ1)t2' ⋅t ρ2 (t1' ⋅t ρ1))) (E'  ρ1 + D'  ρ2)  μ 
    superposition' (𝒱2, D) (𝒱1, E) (𝒱3, C)"

lemma superposition_eq_superposition': "superposition = superposition'"
proof (intro ext iffI)
  fix D E C
  assume "superposition D E C"
  then show "superposition' D E C"

  proof (cases D E C rule: superposition.cases)
    case (superpositionI 𝒫 𝒱1 𝒱2 ρ1 ρ2 E D t1 𝒱3 μ t2 c1 t1' t2' l1 l2 C E' D')

    show ?thesis
    proof (unfold superpositionI(1-3), rule superposition'I; (rule superpositionI)?)

      show "𝒫 = Pos  select E = {#}  is_strictly_maximal (l1 ⋅l ρ1  μ) (E  ρ1  μ) 
       𝒫 = Neg  (select E = {#}  is_maximal (l1 ⋅l ρ1  μ) (E  ρ1  μ) 
                   is_maximal (l1 ⋅l ρ1  μ) (select E  ρ1  μ))"
        using superpositionI
        by fastforce
    qed
  qed
next
  fix D E C
  assume "superposition' D E C"
  then show "superposition D E C"
  proof (cases D E C rule: superposition'.cases)
    case (superposition'I 𝒱1 𝒱2 ρ1 ρ2 E D l1 E' l2 D' 𝒫 c1 t1 t1' t2 t2' 𝒱3 μ C)

    show ?thesis
    proof (unfold superposition'I(1-3), rule superpositionI; (rule superposition'I)?)

      show
        "𝒫 = 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  μ)"
        using superposition'I(23) is_maximal_not_empty
        by auto
    qed
  qed
qed

inductive pos_superposition ::
  "('t, 'v, 'ty) typed_clause  ('t, 'v, 'ty) typed_clause  ('t, 'v, 'ty) typed_clause  bool"
where
  pos_superpositionI:
   "(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) = {} 
    E = add_mset l1 E' 
    D = add_mset l2 D' 
    l1 = c1t1  t1' 
    l2 = t2  t2' 
    ¬ 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}} 
    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) 
    ¬ (E  ρ1  μ c D  ρ2  μ) 
    select E = {#} 
    is_strictly_maximal (l1 ⋅l ρ1  μ) (E  ρ1  μ) 
    select D = {#} 
    is_strictly_maximal (l2 ⋅l ρ2  μ) (D  ρ2  μ) 
    ¬ (c1t1 ⋅t ρ1  μ t t1' ⋅t ρ1  μ) 
    ¬ (t2 ⋅t ρ2  μ t t2' ⋅t ρ2  μ) 
    C = add_mset ((c1 ⋅tc ρ1)t2' ⋅t ρ2  (t1' ⋅t ρ1)) (E'  ρ1 + D'  ρ2)  μ 
    pos_superposition (𝒱2, D) (𝒱1, E) (𝒱3, C)"

lemma superposition_if_pos_superposition:
  assumes "pos_superposition D E C"
  shows "superposition D E C"
  using assms
proof (cases rule: pos_superposition.cases)
  case (pos_superpositionI 𝒱1 𝒱2 ρ1 ρ2 E D l1 E' l2 D' c1 t1 t1' t2 t2' 𝒱3 μ C)

  then show ?thesis
    using superpositionI[of Pos 𝒱1 𝒱2 ρ1 ρ2 E D t1 𝒱3 μ t2 c1 t1' t2' l1 l2 C E' D']
    by blast
qed

inductive neg_superposition ::
  "('t, 'v, 'ty) typed_clause  ('t, 'v, 'ty) typed_clause  ('t, 'v, 'ty) typed_clause  bool"
where
  neg_superpositionI:
   "(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) = {} 
    E = add_mset l1 E' 
    D = add_mset l2 D' 
    l1 = c1t1 !≈ t1' 
    l2 = t2  t2' 
    ¬ 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}} 
    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) 
    ¬ (E  ρ1  μ c D  ρ2  μ) 
    (select E = {#}  is_maximal (l1 ⋅l ρ1  μ) (E  ρ1  μ)) 
    (select E  {#}  is_maximal (l1 ⋅l ρ1  μ) ((select E)  ρ1  μ)) 
    select D = {#} 
    is_strictly_maximal (l2 ⋅l ρ2  μ) (D  ρ2  μ) 
    ¬ (c1t1 ⋅t ρ1  μ t t1' ⋅t ρ1  μ) 
    ¬ (t2 ⋅t ρ2  μ t t2' ⋅t ρ2  μ) 
    C = add_mset ((c1 ⋅tc ρ1)t2' ⋅t ρ2 !≈ (t1' ⋅t ρ1)) (E'  ρ1 + D'  ρ2)  μ 
    neg_superposition (𝒱2, D) (𝒱1, E) (𝒱3, C)"

lemma superposition_if_neg_superposition:
  assumes "neg_superposition E D C"
  shows "superposition E D C"
  using assms
proof (cases E D C rule: neg_superposition.cases)
  case (neg_superpositionI 𝒱1 𝒱2 ρ1 ρ2 E D l1 E' l2 D' c1 t1 t1' t2 t2' 𝒱3 μ C)
 
  then show ?thesis
    using
      superpositionI[of Neg 𝒱1 𝒱2 ρ1 ρ2 E D t1 𝒱3 μ t2 c1 t1' t2' l1 l2 C E' D']
      literals_distinct(2)
    by blast
qed

lemma superposition_iff_pos_or_neg:
  "superposition D E C  pos_superposition D E C  neg_superposition D E C"
proof (rule iffI)
  assume "superposition D E C"
  thus "pos_superposition D E C  neg_superposition D E C"
  proof (cases D E C rule: superposition.cases)
    case (superpositionI 𝒫 𝒱1 𝒱2 ρ1 ρ2 E D t1 𝒱3 μ t2 c1 t1' t2' l1 l2 C E' D')

    show ?thesis
    proof(cases "𝒫 = Pos")
      case True

      then show ?thesis
        using
          superpositionI
          pos_superpositionI[of 𝒱1 𝒱2 ρ1 ρ2 E D l1 E' l2 D' c1 t1 t1' t2 t2' 𝒱3 μ C]
        unfolding superpositionI(1-3)
        by argo
    next
      case False

      then show ?thesis
        using
          superpositionI
          neg_superpositionI[of 𝒱1 𝒱2 ρ1 ρ2 E D l1 E' l2 D' c1 t1 t1' t2 t2' 𝒱3 μ C]
        using superpositionI(4)
        unfolding superpositionI(1-3)
        by blast
    qed
  qed
next
  assume "pos_superposition D E C  neg_superposition D E C"

  thus "superposition D E C"
    using superposition_if_neg_superposition superposition_if_pos_superposition
    by fast
qed

end

end