]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/ng_refiner/nCicUnifHint.ml
removed debug code
[helm.git] / helm / software / components / ng_refiner / nCicUnifHint.ml
1 (*
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.                     
5     ||I||                                                                
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_______________________________________________________________ *)
11
12 (* $Id: nCicRefiner.mli 9227 2008-11-21 16:00:06Z tassi $ *)
13
14 module COT : Set.OrderedType with type t = NCic.term = 
15   struct
16         type t = NCic.term
17         let compare = Pervasives.compare
18   end
19
20 module HintSet = Set.Make(COT)
21
22 module DB = 
23   Discrimination_tree.Make(NDiscriminationTree.NCicIndexable)(HintSet)
24
25 type db = DB.t
26
27 let dummy = NCic.Const (NReference.reference_of_string "cic:/dummy_conv.dec");;
28 let pair t1 t2 = (NCic.Appl [dummy;t1;t2]) ;;
29
30 let index_hint hdb context t1 t2 =
31   assert (
32     (match t1 with
33     | NCic.Meta _ | NCic.Appl (NCic.Meta _ :: _) -> false | _ -> true)
34     &&
35     (match t2 with
36     | NCic.Meta _ | NCic.Appl (NCic.Meta _ :: _) -> false | _ -> true)
37   );
38   let pair' = pair t1 t2 in
39   let data = 
40     List.fold_left 
41      (fun t (n,e) -> 
42         match e with
43         | NCic.Decl ty -> NCic.Prod (n,ty,t)
44         | _ -> assert false) 
45       pair' context in
46   let src = 
47     List.fold_left 
48      (fun t (_,e) -> 
49         match e with
50         | NCic.Decl _ -> 
51             NCicSubstitution.subst (NCic.Meta (-1,(0,NCic.Irl 0))) t
52         | _ -> assert false) 
53      pair' context in
54   DB.index hdb src data
55 ;;
56
57 let empty_db = DB.empty ;;
58
59 let db () = 
60   let _,_,_,x,_,_ = NCicEnvironment.get_checked_def
61     (NReference.reference_of_string "cic:/matita/tests/pullback/xxx.def(0)")
62   in
63   let rec decontextualize ctx = function
64     | NCic.Prod (n,s,t) -> decontextualize ((n,NCic.Decl s)::ctx) t
65     | t -> ctx, t
66   in
67     match (decontextualize [] x) with
68     | ctx, NCic.Appl [_;_;a;b] -> index_hint empty_db ctx a b
69     | _ -> assert false
70 ;;
71
72
73 let look_for_hint hdb metasenv subst context t1 t2 =
74 (*
75   prerr_endline ("KEY1: "^NCicPp.ppterm ~metasenv ~subst ~context (pair t1 t2));
76   prerr_endline ("KEY2: "^NCicPp.ppterm ~metasenv ~subst ~context (pair t2 t1));
77   DB.iter hdb
78    (fun p ds ->
79       prerr_endline ("ENTRY: " ^
80       NDiscriminationTree.NCicIndexable.string_of_path p ^ " |--> " ^
81       String.concat "|" (List.map (NCicPp.ppterm ~metasenv:[] ~subst:[]
82       ~context:[]) (HintSet.elements ds))));
83 *)
84   let candidates1 = DB.retrieve_unifiables hdb (pair t1 t2) in
85   let candidates2 = DB.retrieve_unifiables hdb (pair t2 t1) in
86   let candidates1 = 
87     List.map (fun ty -> 
88        true,NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty 0) 
89     (HintSet.elements candidates1) 
90   in
91   let candidates2 = 
92     List.map (fun ty -> 
93        false,NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty 0) 
94     (HintSet.elements candidates2) 
95   in
96   List.map
97    (function 
98     | (true,(NCic.Appl [_; t1; t2],metasenv,_)) -> metasenv, t1, t2
99     | (false,(NCic.Appl [_; t1; t2],metasenv,_)) -> metasenv, t2, t1
100     | _ -> assert false)
101    (candidates1 @ candidates2)
102 ;;