]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/tactics/paramodulation/equality_indexing.ml
Preparing for 0.5.9 release.
[helm.git] / helm / software / components / tactics / paramodulation / equality_indexing.ml
1 (* Copyright (C) 2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (* $Id$ *)
27
28 module type EqualityIndex =
29   sig
30     module PosEqSet : Set.S with type elt = Utils.pos * Equality.equality
31     type t = Discrimination_tree.Make(Cic_indexable.CicIndexable)(PosEqSet).t
32     val empty : t
33     val retrieve_generalizations : t -> Cic.term -> PosEqSet.t
34     val retrieve_unifiables : t -> Cic.term -> PosEqSet.t
35     val init_index : unit -> unit
36     val remove_index : t -> Equality.equality -> t
37     val index : t -> Equality.equality -> t
38     val in_index : t -> Equality.equality -> bool
39     val iter : t -> (Cic_indexable.CicIndexable.constant_name Discrimination_tree.path -> PosEqSet.t -> unit) -> unit
40   end
41
42 module DT = 
43 struct
44     module OrderedPosEquality = struct
45         type t = Utils.pos * Equality.equality
46         let compare (p1,e1) (p2,e2) = 
47           let rc = Pervasives.compare p1 p2 in
48             if rc = 0 then Equality.compare e1 e2 else rc
49       end
50
51     module PosEqSet = Set.Make(OrderedPosEquality);;
52     
53     include Discrimination_tree.Make(Cic_indexable.CicIndexable)(PosEqSet)
54     
55
56     (* DISCRIMINATION TREES *)
57     let init_index () = () ;;
58
59     let remove_index tree equality = 
60       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
61         match ordering with
62           | Utils.Gt -> remove_index tree l (Utils.Left, equality)
63           | Utils.Lt -> remove_index tree r (Utils.Right, equality)
64           | _ -> 
65               let tree = remove_index tree r (Utils.Right, equality) in
66                 remove_index tree l (Utils.Left, equality)
67
68     let index tree equality = 
69       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
70         match ordering with
71           | Utils.Gt -> index tree l (Utils.Left, equality)
72           | Utils.Lt -> index tree r (Utils.Right, equality)
73           | _ -> 
74               let tree = index tree r (Utils.Right, equality) in
75                 index tree l (Utils.Left, equality)
76   
77
78     let in_index tree equality = 
79       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
80       let meta_convertibility (pos,equality') = 
81         Equality.meta_convertibility_eq equality equality' 
82       in
83         in_index tree l meta_convertibility || in_index tree r meta_convertibility
84
85   end
86
87 module PT = 
88   struct
89     module OrderedPosEquality = struct
90         type t = Utils.pos * Equality.equality
91         let compare (p1,e1) (p2,e2) = 
92           let rc = Pervasives.compare p1 p2 in
93             if rc = 0 then Equality.compare e1 e2 else rc
94       end
95
96     module PosEqSet = Set.Make(OrderedPosEquality);;
97     
98     include Discrimination_tree.Make(Cic_indexable.CicIndexable)(PosEqSet)
99     
100
101     (* DISCRIMINATION TREES *)
102     let init_index () = () ;;
103
104     let remove_index tree equality = 
105       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
106           match ordering with
107           | Utils.Gt -> remove_index tree l (Utils.Left, equality)
108           | Utils.Lt -> remove_index tree r (Utils.Right, equality)
109           | _ -> 
110               let tree = remove_index tree r (Utils.Right, equality) in
111                 remove_index tree l (Utils.Left, equality)
112
113     let index tree equality = 
114       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
115         match ordering with
116           | Utils.Gt -> index tree l (Utils.Left, equality)
117           | Utils.Lt -> index tree r (Utils.Right, equality)
118           | _ -> 
119               let tree = index tree r (Utils.Right, equality) in
120                 index tree l (Utils.Left, equality)
121   
122
123     let in_index tree equality = 
124       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
125       let meta_convertibility (pos,equality') = 
126         Equality.meta_convertibility_eq equality equality' 
127       in
128         in_index tree l meta_convertibility || in_index tree r meta_convertibility
129 end
130