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 : Terms.Blob) = struct
25 module Subst = FoSubst;;
27 let rec eq_foterm x y =
30 | Terms.Leaf t1, Terms.Leaf t2 -> B.eq t1 t2
31 | Terms.Var i, Terms.Var j -> i = j
32 | Terms.Node l1, Terms.Node l2 -> List.for_all2 eq_foterm l1 l2
37 let rec compare_foterm x y =
39 | Terms.Leaf t1, Terms.Leaf t2 -> B.compare t1 t2
40 | Terms.Var i, Terms.Var j -> i - j
41 | Terms.Node l1, Terms.Node l2 -> lexicograph compare_foterm l1 l2
42 | Terms.Leaf _, ( Terms.Node _ | Terms.Var _ ) -> ~-1
43 | Terms.Node _, Terms.Leaf _ -> 1
44 | Terms.Node _, Terms.Var _ -> ~-1
48 let eq_literal l1 l2 =
50 | Terms.Predicate p1, Terms.Predicate p2 -> eq_foterm p1 p2
51 | Terms.Equation (l1,r1,ty1,o1), Terms.Equation (l2,r2,ty2,o2) ->
52 o1 = o2 && eq_foterm l1 l2 && eq_foterm r1 r2 && eq_foterm ty1 ty2
56 let compare_literal l1 l2 =
58 | Terms.Predicate p1, Terms.Predicate p2 -> compare_foterm p1 p2
59 | Terms.Equation (l1,r1,ty1,o1), Terms.Equation (l2,r2,ty2,o2) ->
60 let c = Pervasives.compare o1 o2 in
62 let c = compare_foterm l1 l2 in
64 let c = compare_foterm r1 r2 in
66 compare_foterm ty1 ty2
67 | Terms.Predicate _, Terms.Equation _ -> ~-1
68 | Terms.Equation _, Terms.Predicate _ -> 1
71 let relocate maxvar varlist subst =
73 (fun i (maxvar, varlist, s) ->
74 maxvar+1, maxvar::varlist, Subst.build_subst i (Terms.Var maxvar) s)
75 varlist (maxvar+1, [], subst)