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
26 fun () -> incr id; !id
29 module Utils (B : Terms.Blob) = struct
30 module Subst = FoSubst;; (*.Subst(B) ;;*)
31 module Order = Orderings.Orderings(B) ;;
33 let rec eq_foterm x y =
36 | Terms.Leaf t1, Terms.Leaf t2 -> B.eq t1 t2
37 | Terms.Var i, Terms.Var j -> i = j
38 | Terms.Node l1, Terms.Node l2 -> List.for_all2 eq_foterm l1 l2
43 let rec compare_foterm x y =
45 | Terms.Leaf t1, Terms.Leaf t2 -> B.compare t1 t2
46 | Terms.Var i, Terms.Var j -> i - j
47 | Terms.Node l1, Terms.Node l2 -> lexicograph compare_foterm l1 l2
48 | Terms.Leaf _, ( Terms.Node _ | Terms.Var _ ) -> ~-1
49 | Terms.Node _, Terms.Leaf _ -> 1
50 | Terms.Node _, Terms.Var _ -> ~-1
54 let eq_literal l1 l2 =
56 | Terms.Predicate p1, Terms.Predicate p2 -> eq_foterm p1 p2
57 | Terms.Equation (l1,r1,ty1,o1), Terms.Equation (l2,r2,ty2,o2) ->
58 o1 = o2 && eq_foterm l1 l2 && eq_foterm r1 r2 && eq_foterm ty1 ty2
62 let compare_literal l1 l2 =
64 | Terms.Predicate p1, Terms.Predicate p2 -> compare_foterm p1 p2
65 | Terms.Equation (l1,r1,ty1,o1), Terms.Equation (l2,r2,ty2,o2) ->
66 let c = Pervasives.compare o1 o2 in
68 let c = compare_foterm l1 l2 in
70 let c = compare_foterm r1 r2 in
72 compare_foterm ty1 ty2
73 | Terms.Predicate _, Terms.Equation _ -> ~-1
74 | Terms.Equation _, Terms.Predicate _ -> 1
77 let eq_unit_clause (id1,_,_,_) (id2,_,_,_) = id1 = id2
78 let compare_unit_clause (id1,_,_,_) (id2,_,_,_) = Pervasives.compare id1 id2
80 let relocate maxvar varlist =
82 (fun i (maxvar, varlist, s) ->
83 maxvar+1, maxvar::varlist, Subst.build_subst i (Terms.Var maxvar) s)
84 varlist (maxvar+1, [], Subst.id_subst)
87 let fresh_unit_clause maxvar (id, lit, varlist, proof) =
88 let maxvar, varlist, subst = relocate maxvar varlist in
91 | Terms.Equation (l,r,ty,o) ->
92 let l = Subst.apply_subst subst l in
93 let r = Subst.apply_subst subst r in
94 let ty = Subst.apply_subst subst ty in
95 Terms.Equation (l,r,ty,o)
96 | Terms.Predicate p ->
97 let p = Subst.apply_subst subst p in
102 | Terms.Exact t -> Terms.Exact (Subst.apply_subst subst t)
103 | Terms.Step (rule,c1,c2,dir,pos,s) ->
104 Terms.Step(rule,c1,c2,dir,pos,Subst.concat subst s)
106 (id, lit, varlist, proof), maxvar
109 (* may be moved inside the bag *)
110 let mk_unit_clause maxvar ty proofterm =
112 let rec aux acc = function
113 | Terms.Leaf _ -> acc
114 | Terms.Var i -> if List.mem i acc then acc else i::acc
115 | Terms.Node l -> List.fold_left aux acc l
117 aux (aux [] ty) proofterm
121 | Terms.Node [ Terms.Leaf eq ; ty; l; r ] when B.eq B.eqP eq ->
122 let o = Order.compare_terms l r in
123 Terms.Equation (l, r, ty, o)
124 | t -> Terms.Predicate t
126 let proof = Terms.Exact proofterm in
127 fresh_unit_clause maxvar (mk_id (), lit, varlist, proof)
130 let add_to_bag bag (_,lit,vl,proof) =
132 let clause = (id, lit, vl, proof) in
133 let bag = Terms.M.add id (clause,false) bag in
137 let empty_bag = Terms.M.empty ;;
139 let mk_passive_clause cl =
140 (Order.compute_unit_clause_weight cl, cl)
143 let compare_passive_clauses_weight (w1,(id1,_,_,_)) (w2,(id2,_,_,_)) =
144 if w1 = w2 then id1 - id2
148 let compare_passive_clauses_age (_,(id1,_,_,_)) (_,(id2,_,_,_)) =