-
-let fo_unif_new metasenv context t1 t2 =
- let module C = Cic in
- let module R = CicReduction in
- let module S = CicSubstitution in
- let rec fo_unif_aux subst k t1 t2 =
- match (t1, t2) with
- (C.Meta n, C.Meta m) -> if n == m then subst
- else let subst'=
- let tn = try List.assoc n subst
- with Not_found -> C.Meta n in
- let tm = try List.assoc m subst
- with Not_found -> C.Meta m in
- (match (tn, tm) with
- (C.Meta n, C.Meta m) -> if n==m then subst
- else if n<m
- then (m, C.Meta n)::subst
- else (n, C.Meta m)::subst
- | (C.Meta n, tm) -> (n, tm)::subst
- | (tn, C.Meta m) -> (m, tn)::subst
- | (tn,tm) -> fo_unif_aux subst 0 tn tm) in
- (* unify types first *)
- let tyn = List.assoc n metasenv in
- let tym = List.assoc m metasenv in
- fo_unif_aux subst' 0 tyn tym
- | (C.Meta n, t)
- | (t, C.Meta n) -> (* unify types first *)
- let t' = delift k t in
- let subst' =
- (try fo_unif_aux subst 0 (List.assoc n subst) t'
- with Not_found -> (n, t')::subst) in
- let tyn = List.assoc n metasenv in
- let tyt = CicTypeChecker.type_of_aux' metasenv context t' in
- fo_unif_aux subst' 0 tyn tyt
- | (C.Rel _, _)
- | (_, C.Rel _)
- | (C.Var _, _)
- | (_, C.Var _)
- | (C.Sort _ ,_)
- | (_, C.Sort _)
- | (C.Implicit, _)
- | (_, C.Implicit) -> if R.are_convertible t1 t2 then subst
- else raise UnificationFailed
- | (C.Cast (te,ty), t2) -> fo_unif_aux subst k te t2
- | (t1, C.Cast (te,ty)) -> fo_unif_aux subst k t1 te
- | (C.Prod (_,s1,t1), C.Prod (_,s2,t2)) ->
- let subst' = fo_unif_aux subst k s1 s2 in
- fo_unif_aux subst' (k+1) t1 t2
- | (C.Lambda (_,s1,t1), C.Lambda (_,s2,t2)) ->
- let subst' = fo_unif_aux subst k s1 s2 in
- fo_unif_aux subst' (k+1) t1 t2
- | (C.LetIn (_,s1,t1), t2) -> fo_unif_aux subst k (S.subst s1 t1) t2
- | (t1, C.LetIn (_,s2,t2)) -> fo_unif_aux subst k t1 (S.subst s2 t2)
- | (C.Appl l1, C.Appl l2) ->
- let lr1 = List.rev l1 in
- let lr2 = List.rev l2 in
- let rec fo_unif_l subst = function
- [],_
- | _,[] -> assert false
- | ([h1],[h2]) -> fo_unif_aux subst k h1 h2
- | ([h],l)
- | (l,[h]) -> fo_unif_aux subst k h (C.Appl l)
- | ((h1::l1),(h2::l2)) ->
- let subst' = fo_unif_aux subst k h1 h2 in
- fo_unif_l subst' (l1,l2)
- in
- fo_unif_l subst (lr1, lr2)
- | (C.Const _, _)
- | (_, C.Const _)
- | (C.Abst _, _)
- | (_, C.Abst _)
- | (C.MutInd _, _)
- | (_, C.MutInd _)
- | (C.MutConstruct _, _)
- | (_, C.MutConstruct _) -> if R.are_convertible t1 t2 then subst
- else raise UnificationFailed
- | (C.MutCase (_,_,_,outt1,t1,pl1), C.MutCase (_,_,_,outt2,t2,pl2))->
- let subst' = fo_unif_aux subst k outt1 outt2 in
- let subst'' = fo_unif_aux subst' k t1 t2 in
- List.fold_left2 (function subst -> fo_unif_aux subst k) subst'' pl1 pl2
- | (C.Fix _, _)
- | (_, C.Fix _)
- | (C.CoFix _, _)
- | (_, C.CoFix _) -> if R.are_convertible t1 t2 then subst
- else raise UnificationFailed
- | (_,_) -> raise UnificationFailed
- in fo_unif_aux [] 0 t1 t2;;