Theory Examples

section ‹Examples›

theory Examples imports Resolution begin

value "Var ''x''"
value "Fun ''one'' []"
value "Fun ''mul'' [Var ''y'',Var ''y'']"
value "Fun ''add'' [Fun ''mul'' [Var ''y'',Var ''y''], Fun ''one'' []]"

value "Pos ''greater'' [Var ''x'', Var ''y'']"
value "Neg ''less'' [Var ''x'', Var ''y'']"
value "Pos ''less'' [Var ''x'', Var ''y'']"
value "Pos ''equals''
        [Fun ''add''[Fun ''mul''[Var ''y'',Var ''y''], Fun ''one''[]],Var ''x'']"

fun Fnat :: "nat fun_denot" where
  "Fnat f [n,m] = 
     (if f = ''add'' then n + m else 
      if f = ''mul'' then n * m else 0)"
| "Fnat f [] = 
     (if f = ''one''  then 1 else
      if f = ''zero'' then 0 else 0)"
| "Fnat f us = 0"

fun Gnat :: "nat pred_denot" where
  "Gnat p [x,y] =
     (if p = ''less''  x < y then True else
      if p = ''greater''  x > y then True else 
      if p = ''equals''  x = y then True else False)"
| "Gnat p us = False"

fun Enat :: "nat var_denot" where
  "Enat x =
     (if x = ''x'' then 26 else
      if x = ''y'' then 5 else 0)"

lemma "evalt Enat Fnat (Var ''x'') = 26" 
  by auto
lemma "evalt Enat Fnat (Fun ''one'' []) = 1" 
  by auto
lemma "evalt Enat Fnat (Fun ''mul'' [Var ''y'',Var ''y'']) = 25" 
  by auto
lemma 
  "evalt Enat Fnat (Fun ''add'' [Fun ''mul'' [Var ''y'',Var ''y''], Fun ''one'' []]) = 26" 
  by auto

lemma "evall Enat Fnat Gnat (Pos ''greater'' [Var ''x'', Var ''y'']) = True" 
  by auto
lemma "evall Enat Fnat Gnat (Neg ''less'' [Var ''x'', Var ''y'']) = True" 
  by auto
lemma "evall Enat Fnat Gnat (Pos ''less'' [Var ''x'', Var ''y'']) = False" 
  by auto

lemma "evall Enat Fnat Gnat 
       (Pos ''equals'' 
         [Fun ''add'' [Fun ''mul'' [Var ''y'',Var ''y''],Fun ''one'' []]
         ,Var ''x'']
       ) = True" 
  by auto

definition PP :: "fterm literal" where
  "PP = Pos ''P'' [Fun ''c'' []]"

definition PQ :: "fterm literal" where
  "PQ = Pos ''Q'' [Fun ''d'' []]"

definition NP :: "fterm literal" where
  "NP = Neg ''P'' [Fun ''c'' []]"

definition NQ :: "fterm literal" where
  "NQ = Neg ''Q'' [Fun ''d'' []]"

theorem empty_mgu: 
  assumes "unifierls ε L"
  shows "mguls ε L"
using assms unfolding unifierls_def mguls_def apply auto
apply (rule_tac x=u in exI)
using empty_comp1 empty_comp2 apply auto
done

theorem unifier_single: "unifierls σ {l}" 
unfolding unifierls_def by auto

theorem resolution_rule':
  assumes "C1  Cs"
  assumes "C2  Cs"
  assumes "applicable C1 C2 L1 L2 σ"
  assumes "C = {resolution C1 C2 L1 L2 σ}"
  shows "resolution_step Cs (Cs  C)"
  using assms resolution_rule by auto

lemma resolution_example1: 
   "resolution_deriv {{NP,PQ},{NQ},{PP,PQ}} 
                              {{NP,PQ},{NQ},{PP,PQ},{NP},{PP},{}}"
proof -
  have "resolution_step 
          {{NP,PQ},{NQ},{PP,PQ}}
         ({{NP,PQ},{NQ},{PP,PQ}}  {{NP}})"
    apply (rule resolution_rule'[of "{NP,PQ}" _ "{NQ}" "{PQ}" "{NQ}" ε])
       unfolding applicable_def varsls_def  varsl_def 
              NQ_def NP_def PQ_def PP_def resolution_def
       using unifier_single empty_mgu using empty_subls
       apply auto 
    done
  then have "resolution_step 
          {{NP,PQ},{NQ},{PP,PQ}}
         ({{NP,PQ},{NQ},{PP,PQ},{NP}})" 
    by (simp add: insert_commute) 
  moreover
  have "resolution_step
         {{NP,PQ},{NQ},{PP,PQ},{NP}}
        ({{NP,PQ},{NQ},{PP,PQ},{NP}}  {{PP}})"
    apply (rule resolution_rule'[of "{NQ}" _ "{PP,PQ}" "{NQ}" "{PQ}" ε])
       unfolding applicable_def varsls_def  varsl_def 
              NQ_def NP_def PQ_def PP_def resolution_def
       using unifier_single empty_mgu empty_subls apply auto
    done
  then have "resolution_step
         {{NP,PQ},{NQ},{PP,PQ},{NP}}
        ({{NP,PQ},{NQ},{PP,PQ},{NP},{PP}})" 
    by (simp add: insert_commute)
  moreover
  have "resolution_step
         {{NP,PQ},{NQ},{PP,PQ},{NP},{PP}}
        ({{NP,PQ},{NQ},{PP,PQ},{NP},{PP}}  {{}})"
    apply (rule resolution_rule'[of "{NP}" _ "{PP}" "{NP}" "{PP}" ε])
       unfolding applicable_def varsls_def  varsl_def 
              NQ_def NP_def PQ_def PP_def resolution_def
       using unifier_single empty_mgu apply auto
    done
  then have "resolution_step
         {{NP,PQ},{NQ},{PP,PQ},{NP},{PP}}
        ({{NP,PQ},{NQ},{PP,PQ},{NP},{PP},{}})" 
    by (simp add: insert_commute)
  ultimately
  have "resolution_deriv {{NP,PQ},{NQ},{PP,PQ}} 
                         {{NP,PQ},{NQ},{PP,PQ},{NP},{PP},{}}"
    unfolding resolution_deriv_def by auto 
  then show ?thesis by auto
qed

definition Pa :: "fterm literal" where
  "Pa = Pos ''a'' []"

definition Na :: "fterm literal" where
  "Na = Neg ''a'' []"

definition Pb :: "fterm literal" where
  "Pb = Pos ''b'' []"

definition Nb :: "fterm literal" where
  "Nb = Neg ''b'' []"

definition Paa :: "fterm literal" where
  "Paa = Pos ''a'' [Fun ''a'' []]"

definition Naa :: "fterm literal" where
  "Naa = Neg ''a'' [Fun ''a'' []]"

definition Pax :: "fterm literal" where
  "Pax = Pos ''a'' [Var ''x'']"

definition Nax :: "fterm literal" where
  "Nax = Neg ''a'' [Var ''x'']"

definition mguPaaPax :: substitution where
  "mguPaaPax = (λx. if x = ''x'' then Fun ''a'' [] else Var x)"

lemma mguPaaPax_mgu: "mguls mguPaaPax {Paa,Pax}"
proof -
  let  = "λx. if x = ''x'' then Fun ''a'' [] else Var x"
  have a: "unifierls (λx. if x = ''x'' then Fun ''a'' [] else Var x) {Paa,Pax}" unfolding Paa_def Pax_def unifierls_def by auto
  have b: "u. unifierls u {Paa,Pax}  (i. u =   i)"
    proof (rule;rule)
      fix u
      assume "unifierls u {Paa,Pax}"
      then have uuu: "u ''x'' = Fun ''a'' []" unfolding unifierls_def Paa_def Pax_def by auto
      have "  u = u"
        proof
          fix x
          {
            assume "x=''x''"
            moreover
            have "(  u) ''x'' =  Fun ''a'' []" unfolding composition_def by auto
            ultimately have "(  u) x = u x" using uuu by auto
          }
          moreover
          {
            assume "x''x''"
            then have "(  u) x = (ε x) t u" unfolding composition_def by auto
            then have "(  u) x = u x" by auto
          }
          ultimately show "(  u) x = u x" by auto
        qed
      then have "i.   i = u" by auto
      then show "i. u =   i" by auto
     qed
   from a b show ?thesis unfolding mguls_def unfolding mguPaaPax_def by auto
qed

lemma resolution_example2: 
   "resolution_deriv {{Nb,Na},{Pax},{Pa},{Na,Pb,Naa}}
                              {{Nb,Na},{Pax},{Pa},{Na,Pb,Naa},{Na,Pb},{Na},{}}"
proof -
  have "resolution_step 
          {{Nb,Na},{Pax},{Pa},{Na,Pb,Naa}}
         ({{Nb,Na},{Pax},{Pa},{Na,Pb,Naa}}  {{Na,Pb}})"
    apply (rule resolution_rule'[of "{Pax}" _ "{Na,Pb,Naa}" "{Pax}" "{Naa}" mguPaaPax ])
       using mguPaaPax_mgu unfolding applicable_def varsls_def  varsl_def 
          Nb_def Na_def Pax_def Pa_def Pb_def Naa_def Paa_def mguPaaPax_def resolution_def
       apply auto
     apply (rule_tac x=Na in image_eqI)
      unfolding Na_def apply auto
    apply (rule_tac x=Pb in image_eqI)
     unfolding Pb_def apply auto
    done
  then have "resolution_step 
          {{Nb,Na},{Pax},{Pa},{Na,Pb,Naa}}
         ({{Nb,Na},{Pax},{Pa},{Na,Pb,Naa},{Na,Pb}})" 
    by (simp add: insert_commute)
  moreover
  have "resolution_step 
          {{Nb,Na},{Pax},{Pa},{Na,Pb,Naa},{Na,Pb}}
         ({{Nb,Na},{Pax},{Pa},{Na,Pb,Naa},{Na,Pb}}  {{Na}})"
    apply (rule resolution_rule'[of "{Nb,Na}" _ "{Na,Pb}" "{Nb}" "{Pb}" ε])
       unfolding applicable_def varsls_def  varsl_def 
                 Pb_def Nb_def Na_def PP_def resolution_def
       using unifier_single empty_mgu apply auto
    done
  then have "resolution_step 
          {{Nb,Na},{Pax},{Pa},{Na,Pb,Naa},{Na,Pb}}
         ({{Nb,Na},{Pax},{Pa},{Na,Pb,Naa},{Na,Pb},{Na}})" 
    by (simp add: insert_commute)
  moreover
  have "resolution_step 
          {{Nb,Na},{Pax},{Pa},{Na,Pb,Naa},{Na,Pb},{Na}}
         ({{Nb,Na},{Pax},{Pa},{Na,Pb,Naa},{Na,Pb},{Na}}  {{}})"
    apply (rule resolution_rule'[of "{Na}" _ "{Pa}" "{Na}" "{Pa}" ε])
       unfolding applicable_def varsls_def  varsl_def 
                  Pa_def Nb_def Na_def PP_def resolution_def
       using unifier_single empty_mgu apply auto
    done
  then have "resolution_step 
          {{Nb,Na},{Pax},{Pa},{Na,Pb,Naa},{Na,Pb},{Na}}
         ({{Nb,Na},{Pax},{Pa},{Na,Pb,Naa},{Na,Pb},{Na},{}})" 
    by (simp add: insert_commute)
  ultimately
  have "resolution_deriv {{Nb,Na},{Pax},{Pa},{Na,Pb,Naa}} 
          {{Nb,Na},{Pax},{Pa},{Na,Pb,Naa},{Na,Pb},{Na},{}}"
    unfolding resolution_deriv_def by auto 
  then show ?thesis by auto
qed

lemma resolution_example1_sem: "¬evalcs F G {{NP, PQ}, {NQ}, {PP, PQ}}"
  using resolution_example1 derivation_sound_refute by auto

lemma resolution_example2_sem: "¬evalcs F G {{Nb,Na},{Pax},{Pa},{Na,Pb,Naa}}"
  using resolution_example2 derivation_sound_refute by auto

end