]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_refiner/nCicUnifHint.ml
hints work better now
[helm.git] / helm / software / components / ng_refiner / nCicUnifHint.ml
index c797b2eee6d752ca6a5e868384d0c26ba3465663..7961be96a80a234afed831403bdfb11cb7586de1 100644 (file)
@@ -57,16 +57,56 @@ let index_hint hdb context t1 t2 =
 let empty_db = DB.empty ;;
 
 let db () = 
-  let _,_,_,x,_,_ = NCicEnvironment.get_checked_def
-    (NReference.reference_of_string "cic:/matita/tests/pullback/xxx.def(0)")
+  let combine f cmp l1 l2 =
+   List.flatten
+     (List.map
+       (fun u1 -> 
+          HExtlib.filter_map 
+            (fun u2 -> if cmp u1 u2 then None else Some (f u1 u2)) l2)
+       l1)
   in
-  let rec decontextualize ctx = function
-    | NCic.Prod (n,s,t) -> decontextualize ((n,NCic.Decl s)::ctx) t
-    | t -> ctx, t
+  let mk_hint (u1,_,_) (u2,_,_) = 
+    let l = OCic2NCic.convert_obj u1 
+      (fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph u1)) in
+    let r = OCic2NCic.convert_obj u2 
+      (fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph u2)) in
+    match List.hd l,List.hd r with
+    | (_,_,_,_,NCic.Constant (_,_,Some l,_,_)), 
+      (_,_,_,_,NCic.Constant (_,_,Some r,_,_)) ->
+        let rec aux ctx t1 t2 =
+          match t1, t2 with
+          | NCic.Lambda (n1,s1,b1), NCic.Lambda(_,s2,b2) ->
+              if NCicReduction.are_convertible ~subst:[] ~metasenv:[] ctx s1 s2
+              then aux ((n1, NCic.Decl s1) :: ctx) b1 b2
+              else None
+          | b1,b2 -> 
+              if NCicReduction.are_convertible ~subst:[] ~metasenv:[] ctx b1 b2 
+              then begin
+(*
+                prerr_endline ("hint: " ^ NCicPp.ppterm ~metasenv:[] ~subst:[]
+                  ~context:ctx b1 ^ " === " ^ NCicPp.ppterm ~metasenv:[]
+                  ~subst:[] ~context:ctx b2);
+*)
+                Some (ctx,b1,b2)
+              end else None
+        in
+          aux [] l r
+    | _ -> None
+  in
+  let hints = 
+    List.fold_left 
+      (fun acc (_,_,l) -> 
+          acc @ 
+          if List.length l > 1 then 
+           combine mk_hint (fun (u1,_,_) (u2,_,_) -> UriManager.eq u1 u2) l l
+          else [])
+      [] (CoercDb.to_list ())
   in
-    match (decontextualize [] x) with
-    | ctx, NCic.Appl [_;_;a;b] -> index_hint empty_db ctx a b
-    | _ -> assert false
+  List.fold_left 
+    (fun db -> function 
+     |None -> db 
+     | Some (ctx,b1,b2) -> index_hint db ctx b1 b2)
+    empty_db hints
 ;;