]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_paramodulation/foUtils.ml
Reorganized foUtils, added Clauses module to avoid duplicate code around are_invertib...
[helm.git] / helm / software / components / ng_paramodulation / foUtils.ml
1 (*
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.                     
5     ||I||                                                                
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_______________________________________________________________ *)
11
12 (* $Id: terms.ml 9836 2009-06-05 15:33:35Z denes $ *)
13
14 let rec lexicograph f l1 l2 =
15   match l1, l2 with
16   | [], [] -> 0
17   | x::xs, y::ys ->
18      let c = f x y in
19      if c <> 0 then c else lexicograph f xs ys
20   | [],_ -> ~-1
21   | _,[] -> 1
22 ;;
23   
24 module Utils (B : Terms.Blob) = struct
25   module Subst = FoSubst;; 
26
27   let rec eq_foterm x y =
28     x == y ||
29     match x, y with
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
33     | _ -> false
34   ;;
35
36
37   let rec compare_foterm x y =
38     match x, y with
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
45     | Terms.Var _, _ ->  1
46   ;;
47
48   let eq_literal l1 l2 =
49     match l1, l2 with
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
53     | _ -> false
54   ;;
55
56   let compare_literal l1 l2 =
57     match l1, l2 with
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
61         if c <> 0 then c else
62           let c = compare_foterm l1 l2 in
63           if c <> 0 then c else
64             let c = compare_foterm r1 r2 in
65             if c <> 0 then c else
66               compare_foterm ty1 ty2
67     | Terms.Predicate _, Terms.Equation _ -> ~-1
68     | Terms.Equation _, Terms.Predicate _ -> 1
69   ;;
70
71   let relocate maxvar varlist subst =
72     List.fold_right
73       (fun i (maxvar, varlist, s) -> 
74          maxvar+1, maxvar::varlist, Subst.build_subst i (Terms.Var maxvar) s)
75       varlist (maxvar+1, [], subst)
76   ;;
77
78 end