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