!user_db (List.flatten hints)
;;
+let saturate ?(delta=0) metasenv subst context ty goal_arity =
+ assert (goal_arity >= 0);
+ let rec aux metasenv = function
+ | NCic.Prod (name,s,t) as ty ->
+ let metasenv1, arg,_ =
+ NCicMetaSubst.mk_meta ~name:name metasenv context (`WithType s) in
+ let t, metasenv1, args, pno =
+ aux metasenv1 (NCicSubstitution.subst arg t)
+ in
+ if pno + 1 = goal_arity then
+ ty, metasenv, [], goal_arity+1
+ else
+ t, metasenv1, arg::args, pno+1
+ | ty ->
+ match NCicReduction.whd ~subst context ty ~delta with
+ | NCic.Prod _ as ty -> aux metasenv ty
+ | _ -> ty, metasenv, [], 0 (* differs from the other impl in this line*)
+ in
+ let res, newmetasenv, arguments, _ = aux metasenv ty in
+ res, newmetasenv, arguments
+;;
let look_for_hint hdb metasenv subst context t1 t2 =
(*
let candidates2 = DB.retrieve_unifiables hdb (pair t2 t1) in
let candidates1 =
List.map (fun (prec,ty) ->
- prec,true,NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty 0)
+ prec,true,saturate ~delta:max_int metasenv subst context ty 0)
(HintSet.elements candidates1)
in
let candidates2 =
List.map (fun (prec,ty) ->
- prec,false,NCicMetaSubst.saturate ~delta:max_int metasenv subst context ty 0)
+ prec,false,saturate ~delta:max_int metasenv subst context ty 0)
(HintSet.elements candidates2)
in
+ let rc =
+ List.map
+ (fun (p,b,(t,m,_)) ->
+ let rec aux () (m,l as acc) = function
+ | NCic.Meta _ as t -> acc, t
+ | NCic.LetIn (name,ty,bo,t) ->
+ let m,i,_=NCicMetaSubst.mk_meta ~name m context (`WithType ty)in
+ let t = NCicSubstitution.subst i t in
+ aux () (m, (i,bo)::l) t
+ | t -> NCicUntrusted.map_term_fold_a (fun _ () -> ()) () aux acc t
+ in
+ let (m,l), t = aux () (m,[]) t in
+ p,b,(t,m,l))
+ (candidates1 @ candidates2)
+ in
let rc =
List.map
(function
- | (prec,true,(NCic.Appl [_; t1; t2],metasenv,_)) -> prec,metasenv, t1, t2
- | (prec,false,(NCic.Appl [_; t1; t2],metasenv,_)) -> prec,metasenv, t2, t1
+ | (prec,true,(NCic.Appl [_; t1; t2],metasenv,l))-> prec,metasenv, (t1,t2),l
+ | (prec,false,(NCic.Appl [_; t1; t2],metasenv,l))-> prec,metasenv, (t2,t1),l
| _ -> assert false)
- (candidates1 @ candidates2)
+ rc
in
let rc =
List.sort (fun (x,_,_,_) (y,_,_,_) -> Pervasives.compare x y) rc
let rc = List.map (fun (_,x,y,z) -> x,y,z) rc in
(*
List.iter
- (fun (metasenv, t1, t2) ->
+ (fun (metasenv, (t1, t2), premises) ->
prerr_endline
- ("CAND: "^NCicPp.ppterm ~metasenv ~subst ~context t1 ^
- " == "^NCicPp.ppterm ~metasenv ~subst ~context t2))
+ (String.concat "\n"
+ (List.map (fun (a,b) ->
+ NCicPp.ppterm ~metasenv ~subst ~context a ^
+ " =?= "^NCicPp.ppterm ~metasenv ~subst ~context b)
+ premises) ^
+ "\n--------------------------------------------------"^
+ "\n"^NCicPp.ppterm ~metasenv ~subst ~context t1 ^
+ " = "^NCicPp.ppterm ~metasenv ~subst ~context t2 ^ "\n\n"))
rc;
*)
rc
in
let rec cand_iter = function
| [] -> None (* raise exc *)
- | (metasenv,c1,c2)::tl ->
+ | (metasenv,(c1,c2),premises)::tl ->
(*
prerr_endline ("\n attempt: " ^
NCicPp.ppterm ~metasenv ~subst ~context t1 ^ " ==?== " ^
NCicPp.ppterm ~metasenv ~subst ~context t2);
*)
try
- let metasenv,subst = unify hdb test_eq_only metasenv subst context t1 c1 in
- let metasenv,subst = unify hdb test_eq_only metasenv subst context c2 t2 in
+ let metasenv,subst =
+ fo_unif test_eq_only metasenv subst t1 c1 in
+ let metasenv,subst =
+ fo_unif test_eq_only metasenv subst c2 t2 in
+ let metasenv,subst =
+ List.fold_left
+ (fun (metasenv, subst) (x,y) ->
+ unify hdb test_eq_only metasenv subst context x y)
+ (metasenv, subst) premises
+ in
Some (metasenv, subst)
with
UnificationFailure _ | Uncertain _ ->