]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/tactics/paramodulation/equality_indexing.ml
better abstraction to allow 1 discrimination tree implementation for both the
[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 =
32             Discrimination_tree.DiscriminationTreeIndexing(Discrimination_tree.CicIndexable)(PosEqSet).t
33     val empty : t
34     val retrieve_generalizations : t -> Cic.term -> PosEqSet.t
35     val retrieve_unifiables : t -> Cic.term -> PosEqSet.t
36     val init_index : unit -> unit
37     val remove_index : t -> Equality.equality -> t
38     val index : t -> Equality.equality -> t
39     val in_index : t -> Equality.equality -> bool
40     val iter : t -> (Discrimination_tree.CicIndexable.constant_name Discrimination_tree.path -> PosEqSet.t -> unit) -> unit
41   end
42
43 module DT = 
44 struct
45     module OrderedPosEquality = struct
46         type t = Utils.pos * Equality.equality
47         let compare (p1,e1) (p2,e2) = 
48           let rc = Pervasives.compare p1 p2 in
49             if rc = 0 then Equality.compare e1 e2 else rc
50       end
51
52     module PosEqSet = Set.Make(OrderedPosEquality);;
53     
54     include
55     Discrimination_tree.DiscriminationTreeIndexing(Discrimination_tree.CicIndexable)(PosEqSet)
56     
57
58     (* DISCRIMINATION TREES *)
59     let init_index () = () ;;
60
61     let remove_index tree equality = 
62       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
63         match ordering with
64           | Utils.Gt -> remove_index tree l (Utils.Left, equality)
65           | Utils.Lt -> remove_index tree r (Utils.Right, equality)
66           | _ -> 
67               let tree = remove_index tree r (Utils.Right, equality) in
68                 remove_index tree l (Utils.Left, equality)
69
70     let index tree equality = 
71       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
72         match ordering with
73           | Utils.Gt -> index tree l (Utils.Left, equality)
74           | Utils.Lt -> index tree r (Utils.Right, equality)
75           | _ -> 
76               let tree = index tree r (Utils.Right, equality) in
77                 index tree l (Utils.Left, equality)
78   
79
80     let in_index tree equality = 
81       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
82       let meta_convertibility (pos,equality') = 
83         Equality.meta_convertibility_eq equality equality' 
84       in
85         in_index tree l meta_convertibility || in_index tree r meta_convertibility
86
87   end
88
89 module PT = 
90   struct
91     module OrderedPosEquality = struct
92         type t = Utils.pos * Equality.equality
93         let compare (p1,e1) (p2,e2) = 
94           let rc = Pervasives.compare p1 p2 in
95             if rc = 0 then Equality.compare e1 e2 else rc
96       end
97
98     module PosEqSet = Set.Make(OrderedPosEquality);;
99     
100     include
101     Discrimination_tree.DiscriminationTreeIndexing(Discrimination_tree.CicIndexable)(PosEqSet)
102     
103
104     (* DISCRIMINATION TREES *)
105     let init_index () = () ;;
106
107     let remove_index tree equality = 
108       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
109           match ordering with
110           | Utils.Gt -> remove_index tree l (Utils.Left, equality)
111           | Utils.Lt -> remove_index tree r (Utils.Right, equality)
112           | _ -> 
113               let tree = remove_index tree r (Utils.Right, equality) in
114                 remove_index tree l (Utils.Left, equality)
115
116     let index tree equality = 
117       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
118         match ordering with
119           | Utils.Gt -> index tree l (Utils.Left, equality)
120           | Utils.Lt -> index tree r (Utils.Right, equality)
121           | _ -> 
122               let tree = index tree r (Utils.Right, equality) in
123                 index tree l (Utils.Left, equality)
124   
125
126     let in_index tree equality = 
127       let _, _, (_, l, r, ordering), _,_ = Equality.open_equality equality in
128       let meta_convertibility (pos,equality') = 
129         Equality.meta_convertibility_eq equality equality' 
130       in
131         in_index tree l meta_convertibility || in_index tree r meta_convertibility
132 end
133