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