]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_notation/cicNotationRew.ml
fixed "let .. in" rendering, adding the break between the "in" and what follows
[helm.git] / helm / ocaml / cic_notation / cicNotationRew.ml
1 (* Copyright (C) 2004-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 open Printf
27
28 module Ast = CicNotationPt
29
30 type pattern_id = int
31 type interpretation_id = pattern_id
32 type pretty_printer_id = pattern_id
33
34 type term_info =
35   { sort: (Cic.id, Ast.sort_kind) Hashtbl.t;
36     uri: (Cic.id, string) Hashtbl.t;
37   }
38
39 let get_types uri =
40   let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
41     match o with
42       | Cic.InductiveDefinition (l,_,_,_) -> l 
43       | _ -> assert false
44
45 let name_of_inductive_type uri i = 
46   let types = get_types uri in
47   let (name, _, _, _) = try List.nth types i with Not_found -> assert false in
48   name
49
50   (* returns <name, type> pairs *)
51 let constructors_of_inductive_type uri i =
52   let types = get_types uri in
53   let (_, _, _, constructors) = 
54     try List.nth types i with Not_found -> assert false
55   in
56   constructors
57
58   (* returns name only *)
59 let constructor_of_inductive_type uri i j =
60   (try
61     fst (List.nth (constructors_of_inductive_type uri i) (j-1))
62   with Not_found -> assert false)
63
64 let idref id t = Ast.AttributedTerm (`IdRef id, t)
65
66 let resolve_binder = function
67   | `Lambda -> "\\lambda"
68   | `Pi -> "\\Pi"
69   | `Forall -> "\\forall"
70   | `Exists -> "\\exists"
71
72 let add_level_info prec assoc t = Ast.AttributedTerm (`Level (prec, assoc), t)
73
74 let rec remove_level_info =
75   function
76   | Ast.AttributedTerm (`Level _, t) -> remove_level_info t
77   | Ast.AttributedTerm (a, t) -> Ast.AttributedTerm (a, remove_level_info t)
78   | t -> t
79
80 let add_xml_attrs attrs t = Ast.AttributedTerm (`XmlAttrs attrs, t)
81 let add_keyword_attrs =
82   add_xml_attrs (RenderingAttrs.keyword_attributes `MathML)
83 let box kind spacing indent content =
84   Ast.Layout (Ast.Box ((kind, spacing, indent), content))
85 let hbox = box Ast.H
86 let vbox = box Ast.V
87 let hvbox = box Ast.HV
88 let hovbox = box Ast.HOV
89 let break = Ast.Layout Ast.Break
90 (* let reset_href t = Ast.AttributedTerm (`Href [], t) *)
91 let reset_href t = t
92 let builtin_symbol s = reset_href (Ast.Literal (`Symbol s))
93 let keyword k = reset_href (add_keyword_attrs (Ast.Literal (`Keyword k)))
94 let number s =
95   reset_href
96     (add_xml_attrs (RenderingAttrs.number_attributes `MathML)
97       (Ast.Literal (`Number s)))
98 let ident i =
99   add_xml_attrs (RenderingAttrs.ident_attributes `MathML) (Ast.Ident (i, None))
100 let binder_symbol s =
101   add_xml_attrs (RenderingAttrs.builtin_symbol_attributes `MathML)
102     (builtin_symbol s)
103
104 let string_of_sort_kind = function
105   | `Prop -> "Prop"
106   | `Set -> "Set"
107   | `CProp -> "CProp"
108   | `Type -> "Type"
109
110 let pp_ast0 t k =
111   let rec aux = function
112     | Ast.Appl ts ->
113         add_level_info Ast.apply_prec Ast.apply_assoc
114           (hovbox true true (CicNotationUtil.dress break (List.map k ts)))
115     | Ast.Binder (binder_kind, (id, ty), body) ->
116         add_level_info Ast.binder_prec Ast.binder_assoc
117           (hvbox false true
118             [ binder_symbol (resolve_binder binder_kind);
119               k id; builtin_symbol ":"; aux_ty ty; break;
120               builtin_symbol "."; k body ])
121     | Ast.Case (what, indty_opt, outty_opt, patterns) ->
122         let outty_box =
123           match outty_opt with
124           | None -> []
125           | Some outty ->
126               [ builtin_symbol "["; remove_level_info (k outty);
127                 builtin_symbol "]"; break ]
128         in
129         let indty_box =
130           match indty_opt with
131           | None -> []
132           | Some indty -> [ keyword "in"; ident indty ]
133         in
134         let match_box =
135           hvbox false true [
136             keyword "match"; break;
137             hvbox false false ([ k what ] @ indty_box); break;
138             keyword "with" ]
139         in
140         let mk_case_pattern (head, vars) =
141           hbox true false (ident head :: List.map aux_var vars)
142         in
143         let patterns' =
144           List.map
145             (fun (lhs, rhs) ->
146               remove_level_info
147                 (hvbox false true [
148                   hbox false true [
149                     mk_case_pattern lhs; builtin_symbol "\\Rightarrow" ];
150                   break; k rhs ]))
151             patterns
152         in
153         let patterns'' =
154           let rec aux_patterns = function
155             | [] -> assert false
156             | [ last ] ->
157                 [ break; 
158                   hbox false false [
159                     builtin_symbol "|";
160                     last; builtin_symbol "]" ] ]
161             | hd :: tl ->
162                 [ break; hbox false false [ builtin_symbol "|"; hd ] ]
163                 @ aux_patterns tl
164           in
165           match patterns' with
166           | [] ->
167               [ hbox false false [ builtin_symbol "["; builtin_symbol "]" ] ]
168           | [ one ] ->
169               [ hbox false false [
170                 builtin_symbol "["; one; builtin_symbol "]" ] ]
171           | hd :: tl ->
172               hbox false false [ builtin_symbol "["; hd ]
173               :: aux_patterns tl
174         in
175         add_level_info Ast.simple_prec Ast.simple_assoc
176           (hvbox false false [
177             hvbox false false (outty_box @ [ match_box ]); break;
178             hbox false false [ hvbox false false patterns'' ] ])
179     | Ast.Cast (bo, ty) ->
180         add_level_info Ast.simple_prec Ast.simple_assoc
181           (hvbox false true [
182             builtin_symbol "("; k bo; break; builtin_symbol ":"; k ty;
183             builtin_symbol ")"])
184     | Ast.LetIn (var, s, t) ->
185         add_level_info Ast.let_in_prec Ast.let_in_assoc
186           (hvbox false true [
187             hvbox false true [
188               keyword "let";
189               hvbox false true [
190                 aux_var var; builtin_symbol "\\def"; break; k s ];
191               break; keyword "in" ];
192             break;
193             k t ])
194     | Ast.LetRec (rec_kind, funs, where) ->
195         let rec_op =
196           match rec_kind with `Inductive -> "rec" | `CoInductive -> "corec"
197         in
198         let mk_fun (var, body, _) = aux_var var, k body in
199         let mk_funs = List.map mk_fun in
200         let fst_fun, tl_funs =
201           match mk_funs funs with hd :: tl -> hd, tl | [] -> assert false
202         in
203         let fst_row =
204           let (name, body) = fst_fun in
205           hvbox false true [
206             keyword "let"; keyword rec_op; name; builtin_symbol "\\def"; break;
207             body ]
208         in
209         let tl_rows =
210           List.map
211             (fun (name, body) ->
212               [ break;
213                 hvbox false true [
214                   keyword "and"; name; builtin_symbol "\\def"; break; body ] ])
215             tl_funs
216         in
217         add_level_info Ast.let_in_prec Ast.let_in_assoc
218           ((hvbox false false
219             (fst_row :: List.flatten tl_rows
220              @ [ break; keyword "in"; break; k where ])))
221     | Ast.Implicit -> builtin_symbol "?"
222     | Ast.Meta (n, l) ->
223         let local_context l =
224           CicNotationUtil.dress (builtin_symbol ";")
225             (List.map (function None -> builtin_symbol "_" | Some t -> k t) l)
226         in
227         hbox false false
228           ([ builtin_symbol "?"; number (string_of_int n) ]
229             @ (if l <> [] then local_context l else []))
230     | Ast.Sort sort -> aux_sort sort
231     | Ast.Num _
232     | Ast.Symbol _
233     | Ast.Ident (_, None) | Ast.Ident (_, Some [])
234     | Ast.Uri (_, None) | Ast.Uri (_, Some [])
235     | Ast.Literal _
236     | Ast.UserInput as leaf -> leaf
237     | t -> CicNotationUtil.visit_ast ~special_k k t
238   and aux_sort sort_kind =
239     add_xml_attrs (RenderingAttrs.keyword_attributes `MathML)
240       (Ast.Ident (string_of_sort_kind sort_kind, None))
241   and aux_ty = function
242     | None -> builtin_symbol "?"
243     | Some ty -> k ty
244   and aux_var = function
245     | name, Some ty ->
246         hvbox false true [
247           builtin_symbol "("; name; builtin_symbol ":"; break; k ty;
248           builtin_symbol ")" ]
249     | name, None -> name
250   and special_k = function
251     | Ast.AttributedTerm (attrs, t) -> Ast.AttributedTerm (attrs, k t)
252     | t ->
253         prerr_endline ("unexpected special: " ^ CicNotationPp.pp_term t);
254         assert false
255   in
256   aux t
257
258 let ast_of_acic0 term_info acic k =
259   let k = k term_info in
260   let register_uri id uri = Hashtbl.add term_info.uri id uri in
261   let sort_of_id id =
262     try
263       Hashtbl.find term_info.sort id
264     with Not_found ->
265       prerr_endline (sprintf "warning: sort of id %s not found, using Type" id);
266       `Type
267   in
268   let aux_substs substs =
269     Some
270       (List.map
271         (fun (uri, annterm) -> (UriManager.name_of_uri uri, k annterm))
272         substs)
273   in
274   let aux_context context =
275     List.map
276       (function
277         | None -> None
278         | Some annterm -> Some (k annterm))
279       context
280   in
281   let aux = function
282     | Cic.ARel (id,_,_,b) -> idref id (Ast.Ident (b, None))
283     | Cic.AVar (id,uri,substs) ->
284         register_uri id (UriManager.string_of_uri uri);
285         idref id (Ast.Ident (UriManager.name_of_uri uri, aux_substs substs))
286     | Cic.AMeta (id,n,l) -> idref id (Ast.Meta (n, aux_context l))
287     | Cic.ASort (id,Cic.Prop) -> idref id (Ast.Sort `Prop)
288     | Cic.ASort (id,Cic.Set) -> idref id (Ast.Sort `Set)
289     | Cic.ASort (id,Cic.Type _) -> idref id (Ast.Sort `Type)
290     | Cic.ASort (id,Cic.CProp) -> idref id (Ast.Sort `CProp)
291     | Cic.AImplicit _ -> assert false
292     | Cic.AProd (id,n,s,t) ->
293         let binder_kind =
294           match sort_of_id id with
295           | `Set | `Type -> `Pi
296           | `Prop | `CProp -> `Forall
297         in
298         idref id (Ast.Binder (binder_kind,
299           (CicNotationUtil.name_of_cic_name n, Some (k s)), k t))
300     | Cic.ACast (id,v,t) -> idref id (Ast.Cast (k v, k t))
301     | Cic.ALambda (id,n,s,t) ->
302         idref id (Ast.Binder (`Lambda,
303           (CicNotationUtil.name_of_cic_name n, Some (k s)), k t))
304     | Cic.ALetIn (id,n,s,t) ->
305         idref id (Ast.LetIn ((CicNotationUtil.name_of_cic_name n, None),
306           k s, k t))
307     | Cic.AAppl (aid,args) -> idref aid (Ast.Appl (List.map k args))
308     | Cic.AConst (id,uri,substs) ->
309         register_uri id (UriManager.string_of_uri uri);
310         idref id (Ast.Ident (UriManager.name_of_uri uri, aux_substs substs))
311     | Cic.AMutInd (id,uri,i,substs) as t ->
312         let name = name_of_inductive_type uri i in
313         let uri_str = UriManager.string_of_uri uri in
314         let puri_str =
315           uri_str ^ "#xpointer(1/" ^ (string_of_int (i + 1)) ^ ")"
316         in
317         register_uri id puri_str;
318         idref id (Ast.Ident (name, aux_substs substs))
319     | Cic.AMutConstruct (id,uri,i,j,substs) ->
320         let name = constructor_of_inductive_type uri i j in
321         let uri_str = UriManager.string_of_uri uri in
322         let puri_str = sprintf "%s#xpointer(1/%d/%d)" uri_str (i + 1) j in
323         register_uri id puri_str;
324         idref id (Ast.Ident (name, aux_substs substs))
325     | Cic.AMutCase (id,uri,typeno,ty,te,patterns) ->
326         let name = name_of_inductive_type uri typeno in
327         let constructors = constructors_of_inductive_type uri typeno in
328         let rec eat_branch ty pat =
329           match (ty, pat) with
330           | Cic.Prod (_, _, t), Cic.ALambda (_, name, s, t') ->
331               let (cv, rhs) = eat_branch t t' in
332               (CicNotationUtil.name_of_cic_name name, Some (k s)) :: cv, rhs
333           | _, _ -> [], k pat
334         in
335         let patterns =
336           List.map2
337             (fun (name, ty) pat ->
338               let (capture_variables, rhs) = eat_branch ty pat in
339               ((name, capture_variables), rhs))
340             constructors patterns
341         in
342         idref id (Ast.Case (k te, Some name, Some (k ty), patterns))
343     | Cic.AFix (id, no, funs) -> 
344         let defs = 
345           List.map
346             (fun (_, n, decr_idx, ty, bo) ->
347               ((Ast.Ident (n, None), Some (k ty)), k bo, decr_idx))
348             funs
349         in
350         let name =
351           try
352             (match List.nth defs no with
353             | (Ast.Ident (n, _), _), _, _ when n <> "_" -> n
354             | _ -> assert false)
355           with Not_found -> assert false
356         in
357         idref id (Ast.LetRec (`Inductive, defs, Ast.Ident (name, None)))
358     | Cic.ACoFix (id, no, funs) -> 
359         let defs = 
360           List.map
361             (fun (_, n, ty, bo) ->
362               ((Ast.Ident (n, None), Some (k ty)), k bo, 0))
363             funs
364         in
365         let name =
366           try
367             (match List.nth defs no with
368             | (Ast.Ident (n, _), _), _, _ when n <> "_" -> n
369             | _ -> assert false)
370           with Not_found -> assert false
371         in
372         idref id (Ast.LetRec (`CoInductive, defs, Ast.Ident (name, None)))
373   in
374   aux acic
375
376   (* persistent state *)
377
378 let level1_patterns21 = Hashtbl.create 211
379 let level2_patterns32 = Hashtbl.create 211
380 let interpretations = Hashtbl.create 211  (* symb -> id list ref *)
381
382 let compiled21 = ref None
383 let compiled32 = ref None
384
385 let pattern21_matrix = ref []
386 let pattern32_matrix = ref []
387
388 let get_compiled21 () =
389   match !compiled21 with
390   | None -> assert false
391   | Some f -> Lazy.force f
392 let get_compiled32 () =
393   match !compiled32 with
394   | None -> assert false
395   | Some f -> Lazy.force f
396
397 let set_compiled21 f = compiled21 := Some f
398 let set_compiled32 f = compiled32 := Some f
399
400 let instantiate21 env (* precedence associativity *) l1 =
401   let rec subst_singleton env t =
402     CicNotationUtil.group (subst env t)
403   and subst env = function
404     | Ast.AttributedTerm (_, t) -> subst env t
405     | Ast.Variable var ->
406         let name, expected_ty = CicNotationEnv.declaration_of_var var in
407         let ty, value =
408           try
409             List.assoc name env
410           with Not_found -> assert false
411         in
412         assert (CicNotationEnv.well_typed ty value); (* INVARIANT *)
413         (* following assertion should be a conditional that makes this
414          * instantiation fail *)
415         assert (CicNotationEnv.well_typed expected_ty value);
416         [ CicNotationEnv.term_of_value value ]
417     | Ast.Magic m -> subst_magic env m
418     | Ast.Literal (`Keyword k) as t -> [ (*reset_href*) (add_keyword_attrs t) ]
419     | Ast.Literal _ as t -> [ (*reset_href*) t ]
420     | Ast.Layout l -> [ Ast.Layout (subst_layout env l) ]
421     | t -> [ CicNotationUtil.visit_ast (subst_singleton env) t ]
422   and subst_magic env = function
423     | Ast.List0 (p, sep_opt)
424     | Ast.List1 (p, sep_opt) ->
425         let rec_decls = CicNotationEnv.declarations_of_term p in
426         let rec_values =
427           List.map (fun (n, _) -> CicNotationEnv.lookup_list env n) rec_decls
428         in
429         let values = CicNotationUtil.ncombine rec_values in
430         let sep =
431           match sep_opt with
432             | None -> []
433             | Some l -> [ Ast.Literal l ]
434         in
435         let rec instantiate_list acc = function
436           | [] -> List.rev acc
437           | value_set :: [] ->
438               let env = CicNotationEnv.combine rec_decls value_set in
439               instantiate_list (CicNotationUtil.group (subst env p) :: acc) []
440           | value_set :: tl ->
441               let env = CicNotationEnv.combine rec_decls value_set in
442               instantiate_list
443                 (CicNotationUtil.group ((subst env p) @ sep) :: acc) tl
444         in
445         instantiate_list [] values
446     | Ast.Opt p ->
447         let opt_decls = CicNotationEnv.declarations_of_term p in
448         let env =
449           let rec build_env = function
450             | [] -> []
451             | (name, ty) :: tl ->
452                   (* assumption: if one of the value is None then all are *)
453                 (match CicNotationEnv.lookup_opt env name with
454                 | None -> raise Exit
455                 | Some v -> (name, (ty, v)) :: build_env tl)
456           in
457           try build_env opt_decls with Exit -> []
458         in
459           begin
460             match env with
461               | [] -> []
462               | _ -> subst env p
463           end
464     | _ -> assert false (* impossible *)
465   and subst_layout env = function
466     | Ast.Box (kind, tl) ->
467         Ast.Box (kind, List.concat (List.map (subst env) tl))
468     | l -> CicNotationUtil.visit_layout (subst_singleton env) l
469   in
470     subst_singleton env l1
471
472 let rec pp_ast1 term = 
473   let rec pp_value = function
474     | CicNotationEnv.NumValue _ as v -> v
475     | CicNotationEnv.StringValue _ as v -> v
476 (*     | CicNotationEnv.TermValue t when t == term -> CicNotationEnv.TermValue (pp_ast0 t pp_ast1) *)
477     | CicNotationEnv.TermValue t -> CicNotationEnv.TermValue (pp_ast1 t)
478     | CicNotationEnv.OptValue None as v -> v
479     | CicNotationEnv.OptValue (Some v) -> 
480         CicNotationEnv.OptValue (Some (pp_value v))
481     | CicNotationEnv.ListValue vl ->
482         CicNotationEnv.ListValue (List.map pp_value vl)
483   in
484   let ast_env_of_env env =
485     List.map (fun (var, (ty, value)) -> (var, (ty, pp_value value))) env
486   in
487   match term with
488   | Ast.AttributedTerm (attrs, t) -> Ast.AttributedTerm (attrs, pp_ast1 t)
489   | _ ->
490       (match (get_compiled21 ()) term with
491       | None -> pp_ast0 term pp_ast1
492       | Some (env, pid) ->
493           let prec, assoc, l1 =
494             try
495               Hashtbl.find level1_patterns21 pid
496             with Not_found -> assert false
497           in
498           add_level_info prec assoc (instantiate21 (ast_env_of_env env) l1))
499
500 let instantiate32 term_info env symbol args =
501   let rec instantiate_arg = function
502     | Ast.IdentArg (n, name) ->
503         let t = (try List.assoc name env with Not_found -> assert false) in
504         let rec count_lambda = function
505           | Ast.Binder (`Lambda, _, body) -> 1 + count_lambda body
506           | _ -> 0
507         in
508         let rec add_lambda t n =
509           if n > 0 then
510             let name = CicNotationUtil.fresh_name () in
511             Ast.Binder (`Lambda, (Ast.Ident (name, None), None),
512               Ast.Appl [add_lambda t (n - 1); Ast.Ident (name, None)])
513           else
514             t
515         in
516         add_lambda t (n - count_lambda t)
517   in
518   let head = Ast.Symbol (symbol, 0) in
519   match args with
520   | [] -> head
521   | _ -> Ast.Appl (head :: List.map instantiate_arg args)
522
523 let rec ast_of_acic1 term_info annterm = 
524   match (get_compiled32 ()) annterm with
525   | None -> ast_of_acic0 term_info annterm ast_of_acic1
526   | Some (env, pid) -> 
527       let env' =
528         List.map (fun (name, term) -> (name, ast_of_acic1 term_info term)) env
529       in
530       let _, symbol, args, _, uris =
531         try
532           Hashtbl.find level2_patterns32 pid
533         with Not_found -> assert false
534       in
535       let ast = instantiate32 term_info env' symbol args in
536       Ast.AttributedTerm (`IdRef (CicUtil.id_of_annterm annterm),
537         (match uris with
538         | [] -> ast
539         | _ -> Ast.AttributedTerm (`Href uris, ast)))
540
541 let load_patterns32 t =
542   set_compiled32 (lazy (CicNotationMatcher.Matcher32.compiler t))
543
544 let load_patterns21 t =
545   set_compiled21 (lazy (CicNotationMatcher.Matcher21.compiler t))
546
547 let ast_of_acic id_to_sort annterm =
548   let term_info = { sort = id_to_sort; uri = Hashtbl.create 211 } in
549   let ast = ast_of_acic1 term_info annterm in
550   ast, term_info.uri
551
552 let pp_ast term =
553 (*   prerr_endline ("pp_ast <- : " ^ CicNotationPp.pp_term term); *)
554   pp_ast1 term
555
556 let fresh_id =
557   let counter = ref ~-1 in
558   fun () ->
559     incr counter;
560     !counter
561
562 let add_interpretation dsc (symbol, args) appl_pattern =
563   let id = fresh_id () in
564   let uris = CicNotationUtil.find_appl_pattern_uris appl_pattern in
565   Hashtbl.add level2_patterns32 id (dsc, symbol, args, appl_pattern, uris);
566   pattern32_matrix := (appl_pattern, id) :: !pattern32_matrix;
567   load_patterns32 !pattern32_matrix;
568   (try
569     let ids = Hashtbl.find interpretations symbol in
570     ids := id :: !ids
571   with Not_found -> Hashtbl.add interpretations symbol (ref [id]));
572   id
573
574 exception Interpretation_not_found
575 exception Pretty_printer_not_found
576
577 let rec list_uniq = function 
578   | [] -> []
579   | h::[] -> [h]
580   | h1::h2::tl when h1 = h2 -> list_uniq (h2 :: tl) 
581   | h1::tl (* when h1 <> h2 *) -> h1 :: list_uniq tl
582
583 let lookup_interpretations symbol =
584   try
585    list_uniq
586     (List.sort Pervasives.compare
587      (List.map
588       (fun id ->
589         let (dsc, _, args, appl_pattern, _) =
590           try
591             Hashtbl.find level2_patterns32 id
592           with Not_found -> assert false 
593         in
594         dsc, args, appl_pattern)
595       !(Hashtbl.find interpretations symbol)))
596   with Not_found -> raise Interpretation_not_found
597
598 let add_pretty_printer ~precedence ~associativity l2 l1 =
599   let id = fresh_id () in
600   let l2' = CicNotationUtil.strip_attributes l2 in
601   Hashtbl.add level1_patterns21 id (precedence, associativity, l1);
602   pattern21_matrix := (l2', id) :: !pattern21_matrix;
603   load_patterns21 !pattern21_matrix;
604   id
605
606 let remove_interpretation id =
607   (try
608     let _, symbol, _, _, _ = Hashtbl.find level2_patterns32 id in
609     let ids = Hashtbl.find interpretations symbol in
610     ids := List.filter ((<>) id) !ids;
611     Hashtbl.remove level2_patterns32 id;
612   with Not_found -> raise Interpretation_not_found);
613   pattern32_matrix := List.filter (fun (_, id') -> id <> id') !pattern32_matrix;
614   load_patterns32 !pattern32_matrix
615
616 let remove_pretty_printer id =
617   (try
618     Hashtbl.remove level1_patterns21 id;
619   with Not_found -> raise Pretty_printer_not_found);
620   pattern21_matrix := List.filter (fun (_, id') -> id <> id') !pattern21_matrix;
621   load_patterns21 !pattern21_matrix
622
623 let _ =
624   load_patterns21 [];
625   load_patterns32 []
626