2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
12 (* $Id: terms.ml 9836 2009-06-05 15:33:35Z denes $ *)
14 let rec lexicograph f l1 l2 =
19 if c <> 0 then c else lexicograph f xs ys
24 module Utils (B : Orderings.Blob) = struct
25 module Subst = FoSubst;;
28 let rec eq_foterm x y =
31 | Terms.Leaf t1, Terms.Leaf t2 -> B.eq t1 t2
32 | Terms.Var i, Terms.Var j -> i = j
33 | Terms.Node l1, Terms.Node l2 -> List.for_all2 eq_foterm l1 l2
38 let rec compare_foterm x y =
40 | Terms.Leaf t1, Terms.Leaf t2 -> B.compare t1 t2
41 | Terms.Var i, Terms.Var j -> i - j
42 | Terms.Node l1, Terms.Node l2 -> lexicograph compare_foterm l1 l2
43 | Terms.Leaf _, ( Terms.Node _ | Terms.Var _ ) -> ~-1
44 | Terms.Node _, Terms.Leaf _ -> 1
45 | Terms.Node _, Terms.Var _ -> ~-1
49 let eq_literal l1 l2 =
51 | Terms.Predicate p1, Terms.Predicate p2 -> eq_foterm p1 p2
52 | Terms.Equation (l1,r1,ty1,o1), Terms.Equation (l2,r2,ty2,o2) ->
53 o1 = o2 && eq_foterm l1 l2 && eq_foterm r1 r2 && eq_foterm ty1 ty2
57 let compare_literal l1 l2 =
59 | Terms.Predicate p1, Terms.Predicate p2 -> compare_foterm p1 p2
60 | Terms.Equation (l1,r1,ty1,o1), Terms.Equation (l2,r2,ty2,o2) ->
61 let c = Pervasives.compare o1 o2 in
63 let c = compare_foterm l1 l2 in
65 let c = compare_foterm r1 r2 in
67 compare_foterm ty1 ty2
68 | Terms.Predicate _, Terms.Equation _ -> ~-1
69 | Terms.Equation _, Terms.Predicate _ -> 1
72 let eq_unit_clause (id1,_,_,_) (id2,_,_,_) = id1 = id2
73 let compare_unit_clause (id1,_,_,_) (id2,_,_,_) = Pervasives.compare id1 id2
75 let relocate maxvar varlist subst =
77 (fun i (maxvar, varlist, s) ->
78 maxvar+1, maxvar::varlist, Subst.build_subst i (Terms.Var maxvar) s)
79 varlist (maxvar+1, [], subst)
82 let fresh_unit_clause maxvar (id, lit, varlist, proof) =
84 ("varlist = " ^ (String.concat "," (List.map string_of_int varlist)));*)
85 let maxvar, varlist, subst = relocate maxvar varlist Subst.id_subst in
88 | Terms.Equation (l,r,ty,o) ->
89 let l = Subst.reloc_subst subst l in
90 let r = Subst.reloc_subst subst r in
91 let ty = Subst.reloc_subst subst ty in
92 Terms.Equation (l,r,ty,o)
93 | Terms.Predicate p ->
94 let p = Subst.reloc_subst subst p in
99 | Terms.Exact t -> Terms.Exact (Subst.reloc_subst subst t)
100 | Terms.Step (rule,c1,c2,dir,pos,s) ->
101 Terms.Step(rule,c1,c2,dir,pos,Subst.concat subst s)
103 (id, lit, varlist, proof), maxvar
106 (* may be moved inside the bag *)
107 let mk_unit_clause maxvar ty proofterm =
109 let rec aux acc = function
110 | Terms.Leaf _ -> acc
111 | Terms.Var i -> if List.mem i acc then acc else i::acc
112 | Terms.Node l -> List.fold_left aux acc l
114 aux (aux [] ty) proofterm
117 match B.is_eq ty with
119 let o = Order.compare_terms l r in
120 Terms.Equation (l, r, ty, o)
121 | None -> Terms.Predicate ty
123 let proof = Terms.Exact proofterm in
124 fresh_unit_clause maxvar (0, lit, varlist, proof)
127 let mk_passive_clause cl =
128 (Order.compute_unit_clause_weight cl, cl)
131 let mk_passive_goal g =
132 (Order.compute_unit_clause_weight g, g)
135 let compare_passive_clauses_weight (w1,(id1,_,_,_)) (w2,(id2,_,_,_)) =
136 if w1 = w2 then id1 - id2
140 let compare_passive_clauses_age (_,(id1,_,_,_)) (_,(id2,_,_,_)) =