]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_paramodulation/index.ml
New functorialization: paramod is abstracted over a Orderings.Blob, that is like...
[helm.git] / helm / software / components / ng_paramodulation / index.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$ *)
13
14 module Index(B : Orderings.Blob) = struct
15   module U = FoUtils.Utils(B)
16
17   module ClauseOT =
18     struct 
19       type t = Terms.direction * B.t Terms.unit_clause
20  
21       let compare (d1,uc1) (d2,uc2) = 
22         let c = Pervasives.compare d1 d2 in
23         if c <> 0 then c else U.compare_unit_clause uc1 uc2
24       ;;
25     end
26
27   module ClauseSet : 
28     Set.S with type elt = Terms.direction * B.t Terms.unit_clause
29     = Set.Make(ClauseOT)
30
31   open Discrimination_tree
32
33   module FotermIndexable : Indexable with
34     type constant_name = B.t and
35     type input = B.t Terms.foterm 
36   =
37     struct
38
39       type input = B.t Terms.foterm
40       type constant_name = B.t
41
42       let path_string_of =
43         let rec aux arity = function
44           | Terms.Leaf a -> [Constant (a, arity)]
45           | Terms.Var i -> assert (arity = 0); [Variable]
46           | Terms.Node (Terms.Var _::_) ->
47               (* FIXME : should this be allowed or not ? *)
48               assert false
49           | Terms.Node ([] | [ _ ] ) -> assert false
50           | Terms.Node (Terms.Node _::_) -> assert false              
51           | Terms.Node (hd::tl) ->
52               aux (List.length tl) hd @ List.flatten (List.map (aux 0) tl) 
53         in 
54           aux 0
55       ;;
56
57       let compare e1 e2 = 
58         match e1,e2 with 
59         | Constant (a1,ar1), Constant (a2,ar2) ->
60             let c = B.compare a1 a2 in
61             if c <> 0 then c else Pervasives.compare ar1 ar2
62         | Variable, Variable -> 0
63         | Constant _, Variable -> ~-1
64         | Variable, Constant _ -> 1
65         | Proposition, _ | _, Proposition
66         | Datatype, _ | _, Datatype
67         | Dead, _ | _, Dead
68         | Bound _, _ | _, Bound _ -> assert false
69       ;;
70
71       let string_of_path l = String.concat "." (List.map (fun _ -> "*") l) ;;
72
73     end
74
75     module DT : DiscriminationTree with
76       type constant_name = B.t and 
77       type input = B.t Terms.foterm and 
78       type data = ClauseSet.elt and 
79       type dataset = ClauseSet.t
80     = Make(FotermIndexable)(ClauseSet)
81
82   let index_unit_clause t = function
83     | (_,Terms.Equation (l,_,_,Terms.Gt),_,_) as c -> 
84           DT.index t l (Terms.Left2Right, c)
85     | (_,Terms.Equation (_,r,_,Terms.Lt),_,_) as c -> 
86           DT.index t r (Terms.Right2Left, c)
87     | (_,Terms.Equation (l,r,_,Terms.Incomparable),_,_) as c ->  
88           DT.index  
89            (DT.index t l (Terms.Left2Right, c))
90            r (Terms.Right2Left, c)
91     | (_,Terms.Equation (_,r,_,Terms.Eq),_,_)  -> assert false
92     | (_,Terms.Predicate p,_,_) as c ->
93           DT.index t p (Terms.Nodir, c)
94   ;;
95
96   type active_set = B.t Terms.unit_clause list * DT.t
97
98 end