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 =
17 let compare = Pervasives.compare
20 module HintSet = Set.Make(COT)
23 Discrimination_tree.Make(NDiscriminationTree.NCicIndexable)(HintSet)
27 let dummy = NCic.Const (NReference.reference_of_string "cic:/dummy_conv.dec");;
28 let pair t1 t2 = (NCic.Appl [dummy;t1;t2]) ;;
30 let index_hint hdb context t1 t2 =
33 | NCic.Meta _ | NCic.Appl (NCic.Meta _ :: _) -> false | _ -> true)
36 | NCic.Meta _ | NCic.Appl (NCic.Meta _ :: _) -> false | _ -> true)
38 let pair' = pair t1 t2 in
43 | NCic.Decl ty -> NCic.Prod (n,ty,t)
51 NCicSubstitution.subst (NCic.Meta (-1,(0,NCic.Irl 0))) t
57 let empty_db = DB.empty ;;
60 let combine f cmp l1 l2 =
65 (fun u2 -> if cmp u1 u2 then None else Some (f u1 u2)) l2)
68 let mk_hint (u1,_,_) (u2,_,_) =
69 let l = OCic2NCic.convert_obj u1
70 (fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph u1)) in
71 let r = OCic2NCic.convert_obj u2
72 (fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph u2)) in
73 match List.hd l,List.hd r with
74 | (_,_,_,_,NCic.Constant (_,_,Some l,_,_)),
75 (_,_,_,_,NCic.Constant (_,_,Some r,_,_)) ->
76 let rec aux ctx t1 t2 =
78 | NCic.Lambda (n1,s1,b1), NCic.Lambda(_,s2,b2) ->
79 if NCicReduction.are_convertible ~subst:[] ~metasenv:[] ctx s1 s2
80 then aux ((n1, NCic.Decl s1) :: ctx) b1 b2
83 if NCicReduction.are_convertible ~subst:[] ~metasenv:[] ctx b1 b2
86 prerr_endline ("hint: " ^ NCicPp.ppterm ~metasenv:[] ~subst:[]
87 ~context:ctx b1 ^ " === " ^ NCicPp.ppterm ~metasenv:[]
88 ~subst:[] ~context:ctx b2);
100 if List.length l > 1 then
101 combine mk_hint (fun (u1,_,_) (u2,_,_) -> UriManager.eq u1 u2) l l
103 [] (CoercDb.to_list ())
108 | Some (ctx,b1,b2) -> index_hint db ctx b1 b2)
113 let look_for_hint hdb metasenv subst context t1 t2 =
115 prerr_endline ("KEY1: "^NCicPp.ppterm ~metasenv ~subst ~context (pair t1 t2));
116 prerr_endline ("KEY2: "^NCicPp.ppterm ~metasenv ~subst ~context (pair t2 t1));
119 prerr_endline ("ENTRY: " ^
120 NDiscriminationTree.NCicIndexable.string_of_path p ^ " |--> " ^
121 String.concat "|" (List.map (NCicPp.ppterm ~metasenv:[] ~subst:[]
122 ~context:[]) (HintSet.elements ds))));
124 let candidates1 = DB.retrieve_unifiables hdb (pair t1 t2) in
125 let candidates2 = DB.retrieve_unifiables hdb (pair t2 t1) in
128 true,NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty 0)
129 (HintSet.elements candidates1)
133 false,NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty 0)
134 (HintSet.elements candidates2)
138 | (true,(NCic.Appl [_; t1; t2],metasenv,_)) -> metasenv, t1, t2
139 | (false,(NCic.Appl [_; t1; t2],metasenv,_)) -> metasenv, t2, t1
141 (candidates1 @ candidates2)