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