]> matita.cs.unibo.it Git - helm.git/commitdiff
Implemented check for duplicates (in goals)
authordenes <??>
Wed, 24 Jun 2009 12:30:56 +0000 (12:30 +0000)
committerdenes <??>
Wed, 24 Jun 2009 12:30:56 +0000 (12:30 +0000)
helm/software/components/ng_paramodulation/foSubst.ml
helm/software/components/ng_paramodulation/foSubst.mli
helm/software/components/ng_paramodulation/foUnif.ml
helm/software/components/ng_paramodulation/foUnif.mli
helm/software/components/ng_paramodulation/paramod.ml
helm/software/components/ng_paramodulation/superposition.ml
helm/software/components/ng_paramodulation/superposition.mli

index 6154306b5e1d9959fc5ee7ec2d0facb51d80f119..5cb84e1c938d1ff20b359bc738f7f0b713cfe87f 100644 (file)
   
   let build_subst n t tail = (n,t) :: tail ;;
   
-  let rec lookup_subst var subst =
+  let rec lookup var subst =
     match var with
       | Terms.Var i ->
           (try
-            lookup_subst (List.assoc i subst) subst
+            lookup (List.assoc i subst) subst
           with
               Not_found -> var)
       | _ -> var
   ;;
-  let lookup_subst i subst = lookup_subst (Terms.Var i) subst;;
+  let lookup i subst = lookup (Terms.Var i) subst;;
   
   let is_in_subst i subst = List.mem_assoc i subst;;
   
@@ -39,7 +39,7 @@
   let rec apply_subst subst = function
     | (Terms.Leaf _) as t -> t
     | Terms.Var i -> 
-        (match lookup_subst i subst with
+        (match lookup i subst with
         | Terms.Node _ as t -> apply_subst subst t
         | t -> t)
     | (Terms.Node l) ->
index 441e35581562a1cc95c4e1e1a04b6f72c5a44b8a..1ed311433697d180aa65d1c1bda41fe8c234b7b8 100644 (file)
@@ -19,7 +19,7 @@ module Subst (B : Terms.Blob) :
     val build_subst : 
       int -> 'a Terms.foterm -> 'a Terms.substitution -> 
        'a Terms.substitution
-    val lookup_subst : 
+    val lookup : 
           int -> 'a Terms.substitution -> 'a Terms.foterm
     val filter : 'a Terms.substitution -> Terms.varlist -> Terms.varlist
     val apply_subst : 
index 6eb014062f81451292249ac8382e8272da65cc58..83179b4045592ba149a849bbe0b513e61b8b963c 100644 (file)
@@ -18,19 +18,18 @@ module Founif (B : Terms.Blob) = struct
   module U = FoUtils.Utils(B)
 
   let unification vars locked_vars t1 t2 =
-    let lookup = Subst.lookup_subst in
     let rec occurs_check subst what where =
       match where with
       | Terms.Var i when i = what -> true
       | Terms.Var i ->
-          let t = lookup i subst in
+          let t = Subst.lookup i subst in
           if not (U.eq_foterm t where) then occurs_check subst what t else false
       | Terms.Node l -> List.exists (occurs_check subst what) l
       | _ -> false
     in
     let rec unif subst s t =
-      let s = match s with Terms.Var i -> lookup i subst | _ -> s
-      and t = match t with Terms.Var i -> lookup i subst | _ -> t
+      let s = match s with Terms.Var i -> Subst.lookup i subst | _ -> s
+      and t = match t with Terms.Var i -> Subst.lookup i subst | _ -> t
       
       in
       match s, t with
@@ -67,5 +66,32 @@ module Founif (B : Terms.Blob) = struct
     let subst = unif Subst.id_subst t1 t2 in
     let vars = Subst.filter subst vars in
     subst, vars
-  
+;;
+
+  let alpha_eq s t =
+    let rec equiv subst s t =
+      let s = match s with Terms.Var i -> Subst.lookup i subst | _ -> s
+      and t = match t with Terms.Var i -> Subst.lookup i subst | _ -> t
+       
+      in
+      match s, t with
+       | s, t when U.eq_foterm s t -> subst
+       | Terms.Var i, Terms.Var j
+           when (not (List.exists (fun (_,k) -> k=t) subst)) ->
+            let subst = Subst.build_subst i t subst in
+              subst
+       | Terms.Node l1, Terms.Node l2 -> (
+            try
+              List.fold_left2
+               (fun subst' s t -> equiv subst' s t)
+               subst l1 l2
+            with Invalid_argument _ ->
+              raise (UnificationFailure (lazy "Inference.unification.unif"))
+          )
+       | _, _ ->
+            raise (UnificationFailure (lazy "Inference.unification.unif"))
+    in
+      equiv Subst.id_subst s t
+;;
+
 end
index fc682c5fc102849d4932097f73aa9f0e0d02f52e..6d50f70ee2339087099df6da70d9540a044b59a4 100644 (file)
@@ -16,7 +16,7 @@ exception UnificationFailure of string Lazy.t;;
 module Founif (B : Terms.Blob) : 
   sig
 
-   val unification: 
+   val unification:
      (* global varlist for both terms t1 and t2 *)
      Terms.varlist -> 
      (* locked variables: if equal to FV(t2) we match t1 with t2*)
@@ -25,4 +25,10 @@ module Founif (B : Terms.Blob) :
      B.t Terms.foterm ->
         B.t Terms.substitution * Terms.varlist
 
+
+   val alpha_eq:
+     B.t Terms.foterm ->
+     B.t Terms.foterm ->
+     B.t Terms.substitution
+
   end
index e747d6693bc228227cb8c037801a4538957f9f45..e9726116e2fc44fa2029e71aeee45f3b27e304e7 100644 (file)
@@ -53,14 +53,10 @@ let nparamod rdb metasenv subst context t table =
            (true,snd g_cl,passives,PassiveSet.remove g_cl g_passives)
   in
 
-  let backward_infer_step bag maxvar actives passives g_actives g_passives g_current =
+  let backward_infer_step bag maxvar actives passives
+                          g_actives g_passives g_current =
     (* superposition left, simplifications on goals *)
       debug "infer_left step...";
-    debug ("Selected goal : " ^ Pp.pp_unit_clause g_current);
-    let bag, g_current = 
-      Sup.simplify_goal maxvar (snd actives) bag g_current
-    in
-      debug "Simplified goal";
       let bag, maxvar, new_goals = 
         Sup.infer_left bag maxvar g_current actives 
       in
@@ -96,8 +92,9 @@ let nparamod rdb metasenv subst context t table =
       let bag, g_actives = 
        List.fold_left 
           (fun (bag,acc) c -> 
-            let bag, c = Sup.simplify_goal maxvar (snd actives) bag c in
-              bag, c::acc) 
+            match Sup.simplify_goal maxvar (snd actives) bag acc c with
+              | None -> bag, acc
+              | Some (bag,c) -> bag,c::acc)
           (bag,[]) g_actives 
       in
       let ctable = IDX.index_unit_clause IDX.DT.empty current in
@@ -132,8 +129,11 @@ let nparamod rdb metasenv subst context t table =
     let rec aux_select passives g_passives =
       let backward,current,passives,g_passives = select passives g_passives in
        if backward then
-         backward_infer_step bag maxvar actives passives
-                             g_actives g_passives current
+        match Sup.simplify_goal maxvar (snd actives) bag g_actives current with
+           | None -> aux_select passives g_passives
+           | Some x -> let bag,g_current = x in
+               backward_infer_step bag maxvar actives passives
+                 g_actives g_passives g_current
        else
          (* debug ("Selected fact : " ^ Pp.pp_unit_clause current); *)
           match Sup.keep_simplified current actives bag maxvar with
index 82fe83037b0a92ebe287dcd4114aa716b2d99c0c..ffca04b96c7ff7b2c84f2cdde3953ed97b787df2 100644 (file)
@@ -332,15 +332,28 @@ module Superposition (B : Terms.Blob) =
                          bag (newa@tl)
       in
        keep_simplified_aux ~new_cl:true cl (alist,atable) bag []
-    ;;                 
-         
+    ;;
+
+    let are_alpha_eq cl1 cl2 =
+      let get_term (_,lit,_,_) =
+       match lit with
+         | Terms.Predicate _ -> assert false
+         | Terms.Equation (l,r,ty,_) ->
+             Terms.Node [Terms.Leaf B.eqP; ty; l ; r]
+      in
+       try ignore(Unif.alpha_eq (get_term cl1) (get_term cl2)) ; true
+       with FoUnif.UnificationFailure _ -> false
+;;
+
     (* this is like simplify but raises Success *)
-    let simplify_goal maxvar table bag clause = 
+    let simplify_goal maxvar table bag g_actives clause = 
       let bag, clause = demodulate bag clause table in
       if (is_identity_clause clause)
       then raise (Success (bag, maxvar, clause))
       else match is_subsumed ~unify:true bag maxvar clause table with
-       | None -> bag, clause
+       | None -> 
+           if List.exists (are_alpha_eq clause) g_actives then None
+           else Some (bag, clause)
        | Some ((bag,maxvar),c) -> 
            debug "Goal subsumed";
            raise (Success (bag,maxvar,c))
@@ -470,8 +483,9 @@ module Superposition (B : Terms.Blob) =
       let bag, new_goals = 
         List.fold_left
          (fun (bag, acc) g -> 
-            let bag, g = simplify_goal maxvar atable bag g in
-             bag,g::acc)
+           match simplify_goal maxvar atable bag [] g with
+             | None -> assert false
+             | Some (bag,g) -> bag,g::acc)
          (bag, []) new_goals
       in
        debug "Simplified new goals with active clauses";
index a89b13f5bbeb3e9f70c29e84f94dae5a0647623f..bcfb0091e619e4784657aa8f05eb5b3252b67d3c 100644 (file)
@@ -49,8 +49,9 @@ module Superposition (B : Terms.Blob) :
           int ->
           Index.Index(B).DT.t ->
           B.t Terms.bag ->
+          B.t Terms.unit_clause list ->
           B.t Terms.unit_clause ->
-            B.t Terms.bag * B.t Terms.unit_clause
+            (B.t Terms.bag * B.t Terms.unit_clause) option
 
     val one_pass_simplification:
       B.t Terms.unit_clause ->