]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_paramodulation/terms.ml
Branched paramodulation for CNF (Horn clauses)
[helm.git] / helm / software / components / ng_paramodulation / terms.ml
index 8fad7187b958c089a1051dbae59f34027777e775..db4c8cad6bce2680f9b98f538373cb8a9c274d5d 100644 (file)
@@ -18,14 +18,14 @@ type 'a foterm =
 
 type 'a substitution = (int * 'a foterm) list
 
-type comparison = Lt | Le | Eq | Ge | Gt | Incomparable
+type comparison = Lt | Eq | Gt | Incomparable
 
-type rule = SuperpositionRight | SuperpositionLeft | Demodulation
+type rule = Superposition | Demodulation
 type direction = Left2Right | Right2Left | Nodir
 type position = int list
 
 type 'a proof =
-  | Exact of 'a
+  | Exact of 'a foterm
   | Step of rule * int * int * direction * position * 'a substitution
          (* rule, eq1, eq2, direction of eq2, position, substitution *)
 
@@ -44,8 +44,23 @@ type 'a unit_clause =
  * varlist       (* variable list *)
  * 'a proof      (* proof *)
 
-type 'a passive_clause = int * 'a unit_clause (* weight * equation *)
+type 'a clause =
+    int
+    * 'a literal list (* left hand side of the arrow *)
+    * 'a literal list (* right hand side of the arrow *)
+    * varlist
+    * 'a proof
 
+type 'a passive_clause = int * 'a clause (* weight * equation *)
+
+
+let vars_of_term ?(start_acc=[]) t =
+  let rec aux acc = function
+    | Leaf _ -> acc
+    | Var i -> if (List.mem i acc) then acc else i::acc
+    | Node l -> List.fold_left aux acc l
+  in aux start_acc t
+;;
 
 module OT =
  struct
@@ -56,71 +71,36 @@ module OT =
 module M : Map.S with type key = int 
   = Map.Make(OT) 
 
-type 'a bag = 'a unit_clause M.t
+type 'a bag = int
+              * (('a unit_clause * bool * int) M.t)
+
+  let add_to_bag (_,lit,vl,proof) (id,bag) =
+    let id = id+1 in
+    let clause = (id, lit, vl, proof) in
+    let bag = M.add id (clause,false,0) bag in
+    (id,bag), clause 
+   ;;
+
+  let replace_in_bag ((id,_,_,_),_,_ as cl) (max_id,bag) =
+    let bag = M.add id cl bag in
+      (max_id,bag)
+  ;;
+
+  let get_from_bag id (_,bag) =
+    M.find id bag
+  ;;
+    
+  let empty_bag = (0,M.empty);;
 
 module type Blob =
   sig
     type t
     val eq : t -> t -> bool
     val compare : t -> t -> int
+    val eqP : t
     val pp : t -> string
+    type input
+    val embed : input -> t foterm
+    val saturate : input -> input -> t foterm * t foterm
   end
 
-module Utils (B : Blob) = struct
-  let rec eq_foterm x y =
-    x == y ||
-    match x, y with
-    | Leaf t1, Leaf t2 -> B.eq t1 t2
-    | Var i, Var j -> i = j
-    | Node l1, Node l2 -> List.for_all2 eq_foterm l1 l2
-    | _ -> false
-  ;;
-
-  let rec lexicograph f l1 l2 =
-    match l1, l2 with
-    | [], [] -> 0
-    | x::xs, y::ys ->
-       let c = f x y in
-       if c <> 0 then c else lexicograph f xs ys
-    | [],_ -> ~-1
-    | _,[] -> 1
-  ;;
-
-  let rec compare_foterm x y =
-    match x, y with
-    | Leaf t1, Leaf t2 -> B.compare t1 t2
-    | Var i, Var j -> i - j
-    | Node l1, Node l2 -> lexicograph compare_foterm l1 l2
-    | Leaf _, ( Node _ | Var _ ) -> ~-1
-    | Node _, Leaf _ -> 1
-    | Node _, Var _ -> ~-1
-    | Var _, _ ->  1
-  ;;
-
-  let eq_literal l1 l2 =
-    match l1, l2 with
-    | Predicate p1, Predicate p2 -> eq_foterm p1 p2
-    | Equation (l1,r1,ty1,o1), Equation (l2,r2,ty2,o2) ->
-        o1 = o2 && eq_foterm l1 l2 && eq_foterm r1 r2 && eq_foterm ty1 ty2
-    | _ -> false
-  ;;
-
-  let compare_literal l1 l2 =
-    match l1, l2 with
-    | Predicate p1, Predicate p2 -> compare_foterm p1 p2
-    | Equation (l1,r1,ty1,o1), Equation (l2,r2,ty2,o2) ->
-        let c = Pervasives.compare o1 o2 in
-        if c <> 0 then c else
-          let c = compare_foterm l1 l2 in
-          if c <> 0 then c else
-            let c = compare_foterm r1 r2 in
-            if c <> 0 then c else
-              compare_foterm ty1 ty2
-    | Predicate _, Equation _ -> ~-1
-    | Equation _, Predicate _ -> 1
-  ;;
-
-  let eq_unit_clause (id1,_,_,_) (id2,_,_,_) = id1 = id2
-  let compare_unit_clause (id1,_,_,_) (id2,_,_,_) = Pervasives.compare id1 id2
-
-end