]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/cic/libraryObjects.ml
Preparing for 0.5.9 release.
[helm.git] / helm / software / components / cic / libraryObjects.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://helm.cs.unibo.it/
24  *)
25
26 (* $Id$ *)
27
28 (**** TABLES ****)
29
30 let default_eq_URIs = []
31 let default_true_URIs = []
32 let default_false_URIs = []
33 let default_absurd_URIs = []
34 let default_nat_URIs = []
35
36 (* eq, sym_eq, trans_eq, eq_ind, eq_ind_R *)
37 let eq_URIs_ref = ref default_eq_URIs;;
38
39 let true_URIs_ref = ref default_true_URIs
40 let false_URIs_ref = ref default_false_URIs
41 let absurd_URIs_ref = ref default_absurd_URIs
42 let nat_URIs_ref = ref default_nat_URIs
43
44
45 (**** SET_DEFAULT ****)
46
47 exception NotRecognized of string;;
48
49 (* insert an element in front of the list, removing from the list all the
50    previous elements with the same key associated *)
51 let insert_unique e extract l =
52  let uri = extract e in
53  let l' =
54   List.filter (fun x -> let uri' = extract x in not (UriManager.eq uri uri')) l
55  in
56   e :: l'
57
58 let set_default what l =
59   match what,l with
60   "equality",[eq_URI;sym_eq_URI;trans_eq_URI;eq_ind_URI;
61               eq_ind_r_URI;eq_rec_URI;eq_rec_r_URI;eq_rect_URI;
62               eq_rect_r_URI;eq_f_URI;eq_f_sym_URI] ->
63       eq_URIs_ref :=
64        insert_unique
65          (eq_URI,sym_eq_URI,trans_eq_URI,eq_ind_URI,
66           eq_ind_r_URI,eq_rec_URI,eq_rec_r_URI,eq_rect_URI,
67           eq_rect_r_URI,eq_f_URI,eq_f_sym_URI)
68         (fun x,_,_,_,_,_,_,_,_,_,_ -> x) !eq_URIs_ref
69   | "true",[true_URI] ->
70       true_URIs_ref := insert_unique true_URI (fun x -> x) !true_URIs_ref
71   | "false",[false_URI] ->
72       false_URIs_ref := insert_unique false_URI (fun x -> x) !false_URIs_ref
73   | "absurd",[absurd_URI] ->
74       absurd_URIs_ref := insert_unique absurd_URI (fun x -> x) !absurd_URIs_ref
75   | "natural numbers",[nat_URI] ->
76       nat_URIs_ref := insert_unique nat_URI (fun x -> x) !nat_URIs_ref
77   | _,l -> 
78       raise 
79         (NotRecognized (what^" with "^string_of_int(List.length l)^" params"))
80 ;;
81
82 let reset_defaults () =
83   eq_URIs_ref := default_eq_URIs;
84   true_URIs_ref := default_true_URIs;
85   false_URIs_ref := default_false_URIs;
86   absurd_URIs_ref := default_absurd_URIs;
87   nat_URIs_ref := default_nat_URIs
88 ;;
89
90 let stack = ref [];;
91
92 let push () =
93   stack := (!eq_URIs_ref, !true_URIs_ref, !false_URIs_ref, !absurd_URIs_ref,
94             !nat_URIs_ref
95            )::!stack;
96   reset_defaults ()
97 ;;
98
99 let pop () =
100   match !stack with
101   | [] -> raise (Failure "Unable to POP in libraryObjects.ml")
102   | (eq,t,f,a,n)::tl ->
103       stack := tl;
104       eq_URIs_ref := eq;
105       true_URIs_ref := t;
106       false_URIs_ref := f;
107       absurd_URIs_ref := a;
108       nat_URIs_ref := n
109 ;;
110
111 (**** LOOKUP FUNCTIONS ****)
112 let eq_URI () =
113  try let eq,_,_,_,_,_,_,_,_,_,_ = List.hd !eq_URIs_ref in Some eq
114  with Failure "hd" -> None
115
116 let is_eq_URI uri =
117  List.exists (fun (eq,_,_,_,_,_,_,_,_,_,_) -> UriManager.eq eq uri) !eq_URIs_ref
118
119 let is_eq_refl_URI uri =
120   let urieq = UriManager.strip_xpointer uri in
121   is_eq_URI urieq &&
122   not (UriManager.eq urieq uri)
123 ;;
124
125 let is_eq_ind_URI uri =
126  List.exists (fun (_,_,_,eq_ind,_,_,_,_,_,_,_) -> UriManager.eq eq_ind uri) !eq_URIs_ref
127 let is_eq_ind_r_URI uri =
128  List.exists (fun (_,_,_,_,eq_ind_r,_,_,_,_,_,_) -> UriManager.eq eq_ind_r uri) !eq_URIs_ref
129 let is_eq_rec_URI uri =
130  List.exists (fun (_,_,_,_,_,eq_rec,_,_,_,_,_) -> UriManager.eq eq_rec uri) !eq_URIs_ref
131 let is_eq_rec_r_URI uri =
132  List.exists (fun (_,_,_,_,_,_,eq_rec_r,_,_,_,_) -> UriManager.eq eq_rec_r uri) !eq_URIs_ref
133 let is_eq_rect_URI uri =
134  List.exists (fun (_,_,_,_,_,_,_,eq_rect,_,_,_) -> UriManager.eq eq_rect uri) !eq_URIs_ref
135 let is_eq_rect_r_URI uri =
136  List.exists (fun (_,_,_,_,_,_,_,_,eq_rect_r,_,_) -> UriManager.eq eq_rect_r uri) !eq_URIs_ref
137 let is_trans_eq_URI uri = 
138  List.exists (fun (_,_,trans_eq,_,_,_,_,_,_,_,_) -> UriManager.eq trans_eq uri) !eq_URIs_ref
139 let is_sym_eq_URI uri =
140  List.exists (fun (_,sym_eq,_,_,_,_,_,_,_,_,_) -> UriManager.eq sym_eq uri) !eq_URIs_ref
141 let is_eq_f_URI uri =
142  List.exists (fun (_,_,_,_,_,_,_,_,_,eq_f,_) -> UriManager.eq eq_f uri) !eq_URIs_ref
143 let is_eq_f_sym_URI uri =
144  List.exists (fun (_,_,_,_,_,_,_,_,_,_,eq_f1) -> UriManager.eq eq_f1 uri) !eq_URIs_ref
145
146 let in_eq_URIs uri =  
147   is_eq_URI uri || is_eq_refl_URI uri || is_eq_ind_URI uri || 
148   is_eq_ind_r_URI uri || is_eq_rec_URI uri || is_eq_rec_r_URI uri ||
149   is_eq_rect_URI uri || is_eq_rect_r_URI uri ||
150   is_trans_eq_URI uri || is_sym_eq_URI uri || is_eq_f_URI uri ||
151   is_eq_f_sym_URI uri
152
153
154  
155 let eq_refl_URI ~eq:uri =
156   let uri = UriManager.strip_xpointer uri in
157   UriManager.uri_of_string (UriManager.string_of_uri uri ^ "#xpointer(1/1/1)")
158  
159 let sym_eq_URI ~eq:uri =
160  try
161   let _,x,_,_,_,_,_,_,_,_,_ = List.find (fun eq,_,_,_,_,_,_,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
162  with Not_found -> raise (NotRecognized (UriManager.string_of_uri uri))
163
164 let trans_eq_URI ~eq:uri =
165  try
166   let _,_,x,_,_,_,_,_,_,_,_ = List.find (fun eq,_,_,_,_,_,_,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
167  with Not_found -> raise (NotRecognized (UriManager.string_of_uri uri))
168
169 let eq_ind_URI ~eq:uri =
170  try
171   let _,_,_,x,_,_,_,_,_,_,_ = List.find (fun eq,_,_,_,_,_,_,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
172  with Not_found -> raise (NotRecognized (UriManager.string_of_uri uri))
173
174 let eq_ind_r_URI ~eq:uri =
175  try
176   let _,_,_,_,x,_,_,_,_,_,_ = List.find (fun eq,_,_,_,_,_,_,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
177  with Not_found -> raise (NotRecognized (UriManager.string_of_uri uri))
178
179 let eq_rec_URI ~eq:uri =
180  try
181   let _,_,_,_,_,x,_,_,_,_,_ = List.find (fun eq,_,_,_,_,_,_,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
182  with Not_found -> raise (NotRecognized (UriManager.string_of_uri uri))
183
184 let eq_rec_r_URI ~eq:uri =
185  try
186   let _,_,_,_,_,_,x,_,_,_,_ = List.find (fun eq,_,_,_,_,_,_,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
187  with Not_found -> raise (NotRecognized (UriManager.string_of_uri uri))
188
189 let eq_rect_URI ~eq:uri =
190  try
191   let _,_,_,_,_,_,_,x,_,_,_ = List.find (fun eq,_,_,_,_,_,_,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
192  with Not_found -> raise (NotRecognized (UriManager.string_of_uri uri))
193
194 let eq_rect_r_URI ~eq:uri =
195  try
196   let _,_,_,_,_,_,_,_,x,_,_ = List.find (fun eq,_,_,_,_,_,_,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
197  with Not_found -> raise (NotRecognized (UriManager.string_of_uri uri))
198
199 let eq_f_URI ~eq:uri =
200  try
201   let _,_,_,_,_,_,_,_,_,x,_ = List.find (fun eq,_,_,_,_,_,_,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
202  with Not_found -> raise (NotRecognized (UriManager.string_of_uri uri))
203
204 let eq_f_sym_URI ~eq:uri =
205  try
206   let _,_,_,_,_,_,_,_,_,_,x = List.find (fun eq,_,_,_,_,_,_,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
207  with Not_found -> raise (NotRecognized (UriManager.string_of_uri uri))
208
209
210 let eq_URI_of_eq_f_URI eq_f_URI = 
211   try
212   let x,_,_,_,_,_,_,_,_,_,_ = 
213     List.find (fun _,_,_,_,_,_,_,_,_,u,_ -> UriManager.eq eq_f_URI u) !eq_URIs_ref 
214   in x
215  with Not_found -> raise (NotRecognized (UriManager.string_of_uri eq_f_URI))
216  
217 let true_URI () =
218  try Some (List.hd !true_URIs_ref) with Failure "hd" -> None
219 let false_URI () =
220  try Some (List.hd !false_URIs_ref) with Failure "hd" -> None
221 let absurd_URI () =
222  try Some (List.hd !absurd_URIs_ref) with Failure "hd" -> None
223
224 let nat_URI () =
225  try Some (List.hd !nat_URIs_ref) with Failure "hd" -> None
226 let is_nat_URI uri =
227  List.exists (fun nat -> UriManager.eq nat uri) !nat_URIs_ref