2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
12 (* $Id: nCicRefiner.mli 9227 2008-11-21 16:00:06Z tassi $ *)
14 module COT : Set.OrderedType with type t = NCic.term * int * int =
16 type t = NCic.term * int * int
17 let compare = Pervasives.compare
20 module CoercionSet = Set.Make(COT)
23 Discrimination_tree.Make(NDiscriminationTree.NCicIndexable)(CoercionSet)
27 let index_coercion (db_src,db_tgt) c src tgt arity arg =
28 let data = (c,arity,arg) in
30 prerr_endline ("INDEX:" ^
31 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] src ^ " ===> " ^
32 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] tgt ^ " := " ^
33 NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[] c);
35 let db_src = DB.index db_src src data in
36 let db_tgt = DB.index db_tgt tgt data in
40 let index_old_db odb db =
42 (fun db (_,tgt,clist) ->
44 (fun db (uri,_,arg) ->
46 let c=fst (OCic2NCic.convert_term uri (CicUtil.term_of_uri uri)) in
47 let arity = match tgt with | CoercDb.Fun i -> i | _ -> 0 in
49 let cty = NCicTypeChecker.typeof ~subst:[] ~metasenv:[] [] c in
50 let scty, metasenv,_ =
51 NCicMetaSubst.saturate ~delta:max_int [] [] [] cty (arity+1)
54 | NCic.Prod (_, src, tgt) ->
56 NCicSubstitution.subst (NCic.Meta (-1,(0,NCic.Irl 0))) tgt
59 prerr_endline (Printf.sprintf "indicizzo %s (%d) : %s ===> %s"
60 (NCicPp.ppterm ~metasenv ~subst:[] ~context:[] scty) (arity+1)
61 (NCicPp.ppterm ~metasenv ~subst:[] ~context:[] src)
62 (NCicPp.ppterm ~metasenv ~subst:[] ~context:[] tgt));
67 NCicPp.ppterm ~metasenv ~subst:[] ~context:[] t);
70 index_coercion db c src tgt arity arg
72 | NCicEnvironment.BadDependency _
73 | NCicTypeChecker.TypeCheckerFailure _ -> db)
75 db (CoercDb.to_list odb)
78 let empty_db = (DB.empty,DB.empty) ;;
81 let look_for_coercion (db_src,db_tgt) metasenv subst context infty expty =
82 match infty, expty with
83 | (NCic.Meta _ | NCic.Appl (NCic.Meta _::_)),
84 (NCic.Meta _ | NCic.Appl (NCic.Meta _::_)) -> []
87 prerr_endline ("LOOK FOR COERCIONS: " ^
88 NCicPp.ppterm ~metasenv ~subst ~context infty ^ " |===> " ^
89 NCicPp.ppterm ~metasenv ~subst ~context expty);
91 let set_src = DB.retrieve_unifiables db_src infty in
92 let set_tgt = DB.retrieve_unifiables db_tgt expty in
93 let candidates = CoercionSet.inter set_src set_tgt in
95 prerr_endline ("CANDIDATES: " ^
96 String.concat "," (List.map (fun (t,_,_) ->
97 NCicPp.ppterm ~metasenv ~subst ~context t)
98 (CoercionSet.elements candidates)));
101 (fun (t,arity,arg) ->
102 let ty = NCicTypeChecker.typeof ~metasenv:[] ~subst:[] [] t in
103 let ty, metasenv, args =
104 NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty arity
107 NCicPp.ppterm ~metasenv ~subst:[] ~context:[] ty ^ " --- " ^
108 NCicPp.ppterm ~metasenv ~subst ~context
109 (NCicUntrusted.mk_appl t args) ^ " --- " ^
110 string_of_int (List.length args) ^ " == " ^ string_of_int arg); *)
111 metasenv, NCicUntrusted.mk_appl t args, ty, List.nth args arg)
112 (CoercionSet.elements candidates)