(* ||M|| This file is part of HELM, an Hypertextual, Electronic ||A|| Library of Mathematics, developed at the Computer Science ||T|| Department, University of Bologna, Italy. ||I|| ||T|| HELM is free software; you can redistribute it and/or ||A|| modify it under the terms of the GNU General Public License \ / version 2 or (at your option) any later version. \ / This software is distributed as is, NO WARRANTY. V_______________________________________________________________ *) (* $Id: nCicRefiner.mli 9227 2008-11-21 16:00:06Z tassi $ *) module COT : Set.OrderedType with type t = NCic.term = struct type t = NCic.term let compare = Pervasives.compare end module HintSet = Set.Make(COT) module DB = Discrimination_tree.Make(NDiscriminationTree.NCicIndexable)(HintSet) type db = DB.t let dummy = NCic.Const (NReference.reference_of_string "cic:/dummy_conv.dec");; let pair t1 t2 = (NCic.Appl [dummy;t1;t2]) ;; let index_hint hdb context t1 t2 = assert ( (match t1 with | NCic.Meta _ | NCic.Appl (NCic.Meta _ :: _) -> false | _ -> true) && (match t2 with | NCic.Meta _ | NCic.Appl (NCic.Meta _ :: _) -> false | _ -> true) ); let pair' = pair t1 t2 in let data = List.fold_left (fun t (n,e) -> match e with | NCic.Decl ty -> NCic.Prod (n,ty,t) | _ -> assert false) pair' context in let src = List.fold_left (fun t (_,e) -> match e with | NCic.Decl _ -> NCicSubstitution.subst (NCic.Meta (-1,(0,NCic.Irl 0))) t | _ -> assert false) pair' context in DB.index hdb src data ;; let empty_db = DB.empty ;; let db () = let _,_,_,x,_,_ = NCicEnvironment.get_checked_def (NReference.reference_of_string "cic:/matita/tests/pullback/xxx.def(0)") in let rec decontextualize ctx = function | NCic.Prod (n,s,t) -> decontextualize ((n,NCic.Decl s)::ctx) t | t -> ctx, t in match (decontextualize [] x) with | ctx, NCic.Appl [_;_;a;b] -> index_hint empty_db ctx a b | _ -> assert false ;; let look_for_hint hdb metasenv subst context t1 t2 = (* prerr_endline ("KEY1: "^NCicPp.ppterm ~metasenv ~subst ~context (pair t1 t2)); prerr_endline ("KEY2: "^NCicPp.ppterm ~metasenv ~subst ~context (pair t2 t1)); DB.iter hdb (fun p ds -> prerr_endline ("ENTRY: " ^ NDiscriminationTree.NCicIndexable.string_of_path p ^ " |--> " ^ String.concat "|" (List.map (NCicPp.ppterm ~metasenv:[] ~subst:[] ~context:[]) (HintSet.elements ds)))); *) let candidates1 = DB.retrieve_unifiables hdb (pair t1 t2) in let candidates2 = DB.retrieve_unifiables hdb (pair t2 t1) in let candidates1 = List.map (fun ty -> true,NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty 0) (HintSet.elements candidates1) in let candidates2 = List.map (fun ty -> false,NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty 0) (HintSet.elements candidates2) in List.map (function | (true,(NCic.Appl [_; t1; t2],metasenv,_)) -> metasenv, t1, t2 | (false,(NCic.Appl [_; t1; t2],metasenv,_)) -> metasenv, t2, t1 | _ -> assert false) (candidates1 @ candidates2) ;;