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 $ *)
16 include Orderings.Blob
20 module Clauses (B : Orderings.Blob) = struct
22 module Utils = FoUtils.Utils(B)
24 let eq_clause (id1,_,_,_,_) (id2,_,_,_,_) = id1 = id2
25 let compare_clause (id1,_,_,_,_) (id2,_,_,_,_) = Pervasives.compare id1 id2
27 let fresh_clause maxvar (id, nlit, plit, varlist, proof) =
28 let maxvar, varlist, subst = Utils.relocate maxvar varlist FoSubst.id_subst in
29 let apply_subst_on_lit = function
30 | Terms.Equation (l,r,ty,o) ->
31 let l = FoSubst.apply_subst subst l in
32 let r = FoSubst.apply_subst subst r in
33 let ty = FoSubst.apply_subst subst ty in
34 Terms.Equation (l,r,ty,o)
35 | Terms.Predicate p ->
36 let p = FoSubst.apply_subst subst p in
39 let nlit = List.map (fun (l,s) -> (apply_subst_on_lit l,s)) nlit in
40 let plit = List.map (fun (l,s) -> (apply_subst_on_lit l,s)) plit in
43 | Terms.Exact t -> Terms.Exact (FoSubst.apply_subst subst t)
44 | Terms.Step (rule,c1,c2,dir,pos,s) ->
45 Terms.Step(rule,c1,c2,dir,pos,FoSubst.concat subst s)
47 (id, nlit, plit, varlist, proof), maxvar
50 (* may be moved inside the bag *)
51 let mk_clause maxvar nlit plit proofterm =
52 let foterm_to_lit (acc,literals) ty =
53 let vars = Terms.vars_of_term ~start_acc:acc ty in
55 | Terms.Node [ Terms.Leaf eq ; ty; l; r ] when B.eq B.eqP eq ->
56 let o = Order.compare_terms l r in
57 (vars,(Terms.Equation (l, r, ty, o),true)::literals)
58 | _ -> (vars,(Terms.Predicate ty,true)::literals)
60 let varlist = Terms.vars_of_term proofterm in
61 let (varlist,nlit) = List.fold_left foterm_to_lit (varlist,[]) nlit in
62 let (varlist,plit) = List.fold_left foterm_to_lit (varlist,[]) plit in
63 let proof = Terms.Exact proofterm in
64 fresh_clause maxvar (0, nlit, plit, varlist, proof)
67 let mk_passive_clause cl =
68 (Order.compute_clause_weight cl, cl)
71 let mk_passive_goal g =
72 (Order.compute_clause_weight g, g)
75 let compare_passive_clauses_weight (w1,(id1,_,_,_,_)) (w2,(id2,_,_,_,_)) =
76 if w1 = w2 then id1 - id2
80 let compare_passive_clauses_age (_,(id1,_,_,_,_)) (_,(id2,_,_,_,_)) =