-
-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 context metasenv t1 t2 =
- match (t1, t2) with
- (C.Meta (n,ln), C.Meta (m,lm)) when n=m ->
- let ok =
- List.fold_left2
- (fun b t1 t2 ->
- b &&
- match t1,t2 with
- None,_
- | _,None -> true
- | Some t1', Some t2' ->
- (* First possibility: restriction *)
- (* Second possibility: unification *)
- (* Third possibility: convertibility *)
- R.are_convertible context t1' t2'
- ) true ln lm
- in
- if ok then subst,metasenv else
- raise UnificationFailed
- | (C.Meta (n,l), C.Meta (m,_)) when n>m ->
- fo_unif_aux subst context metasenv t2 t1
- | (C.Meta (n,l), t)
- | (t, C.Meta (n,l)) ->
- let subst',metasenv' =
- try
- let oldt = (List.assoc n subst) in
- let lifted_oldt = S.lift_meta l oldt in
- fo_unif_aux subst context metasenv lifted_oldt t
- with Not_found ->
-prerr_endline ("DELIFT2(" ^ CicPp.ppterm t ^ ")") ; flush stderr ;
-List.iter (function (Some t) -> prerr_endline ("l: " ^ CicPp.ppterm t) | None -> prerr_endline " _ ") l ; flush stderr ;
-prerr_endline "<DELIFT2" ; flush stderr ;
- let t',metasenv' = delift context metasenv l t in
- (n, t')::subst, metasenv'
- in
- let (_,_,meta_type) =
- List.find (function (m,_,_) -> m=n) metasenv' in
- let tyt = CicTypeChecker.type_of_aux' metasenv' context t in
- fo_unif_aux subst' context metasenv' (S.lift_meta l meta_type) tyt
- | (C.Rel _, _)
- | (_, C.Rel _)
- | (C.Var _, _)
- | (_, C.Var _)
- | (C.Sort _ ,_)
- | (_, C.Sort _)
- | (C.Implicit, _)
- | (_, C.Implicit) ->
- if R.are_convertible context t1 t2 then subst, metasenv
- else raise UnificationFailed
- | (C.Cast (te,ty), t2) -> fo_unif_aux subst context metasenv te t2
- | (t1, C.Cast (te,ty)) -> fo_unif_aux subst context metasenv t1 te
- | (C.Prod (n1,s1,t1), C.Prod (_,s2,t2)) ->
- let subst',metasenv' = fo_unif_aux subst context metasenv s1 s2 in
- fo_unif_aux subst' ((Some (n1,(C.Decl s1)))::context) metasenv' t1 t2
- | (C.Lambda (n1,s1,t1), C.Lambda (_,s2,t2)) ->
- let subst',metasenv' = fo_unif_aux subst context metasenv s1 s2 in
- fo_unif_aux subst' ((Some (n1,(C.Decl s1)))::context) metasenv' t1 t2
- | (C.LetIn (_,s1,t1), t2)
- | (t2, C.LetIn (_,s1,t1)) ->
- fo_unif_aux subst context metasenv t2 (S.subst s1 t1)
- | (C.Appl l1, C.Appl l2) ->
- let lr1 = List.rev l1 in
- let lr2 = List.rev l2 in
- let rec fo_unif_l subst metasenv = function
- [],_
- | _,[] -> assert false
- | ([h1],[h2]) ->
- fo_unif_aux subst context metasenv h1 h2
- | ([h],l)
- | (l,[h]) ->
- fo_unif_aux subst context metasenv h (C.Appl (List.rev l))
- | ((h1::l1),(h2::l2)) ->
- let subst', metasenv' =
- fo_unif_aux subst context metasenv h1 h2
- in
- fo_unif_l subst' metasenv' (l1,l2)
- in
- fo_unif_l subst metasenv (lr1, lr2)
- | (C.Const _, _)
- | (_, C.Const _)
- | (C.MutInd _, _)
- | (_, C.MutInd _)
- | (C.MutConstruct _, _)
- | (_, C.MutConstruct _) ->
- if R.are_convertible context t1 t2 then subst, metasenv
- else raise UnificationFailed
- | (C.MutCase (_,_,_,outt1,t1,pl1), C.MutCase (_,_,_,outt2,t2,pl2))->
- let subst', metasenv' =
- fo_unif_aux subst context metasenv outt1 outt2 in
- let subst'',metasenv'' =
- fo_unif_aux subst' context metasenv' t1 t2 in
- List.fold_left2
- (function (subst,metasenv) ->
- fo_unif_aux subst context metasenv
- ) (subst'',metasenv'') pl1 pl2
- | (C.Fix _, _)
- | (_, C.Fix _)
- | (C.CoFix _, _)
- | (_, C.CoFix _) ->
- if R.are_convertible context t1 t2 then subst, metasenv
- else raise UnificationFailed
- | (_,_) -> raise UnificationFailed
- in fo_unif_aux [] context metasenv t1 t2;;
-
-(*CSC: ???????????????
-(* m is the index of a metavariable to restrict, k is nesting depth
-of the occurrence m, and l is its relocation list. canonical_context
-is the context of the metavariable we are instantiating - containing
-m - Only rel in the domain of canonical_context are accessible.
-This function takes in input a metasenv and gives back a metasenv.
-A rel(j) in the canonical context of m, is rel(List.nth l j) for the
-instance of m under consideration, that is rel (List.nth l j) - k
-in canonical_context. *)
-
-let restrict canonical_context m k l =
- let rec erase i =
- function
- [] -> []
- | None::tl -> None::(erase (i+1) tl)
- | he::tl ->
- let i' = (List.nth l (i-1)) in
- if i' <= k
- then he::(erase (i+1) tl) (* local variable *)
- else
- let acc =
- (try List.nth canonical_context (i'-k-1)
- with Failure _ -> None) in
- if acc = None
- then None::(erase (i+1) tl)
- else he::(erase (i+1) tl) in
- let rec aux =
- function
- [] -> []
- | (n,context,t)::tl when n=m -> (n,erase 1 context,t)::tl
- | hd::tl -> hd::(aux tl)
- in
- aux
-;;
-
-
-let check_accessibility metasenv i =
- let module C = Cic in
- let module S = CicSubstitution in
- let (_,canonical_context,_) =
- List.find (function (m,_,_) -> m=i) metasenv in
- List.map
- (function t ->
- let =
- delift canonical_context metasenv ? t
- ) canonical_context
-CSCSCS
-
-
-
- let rec aux metasenv k =
- function
- C.Rel i ->
- if i <= k then
- metasenv
- else
- (try
- match List.nth canonical_context (i-k-1) with
- Some (_,C.Decl t)
- | Some (_,C.Def t) -> aux metasenv k (S.lift i t)
- | None -> raise RelToHiddenHypothesis
- with
- Failure _ -> raise OpenTerm
- )
- | C.Var _ -> metasenv
- | C.Meta (i,l) -> restrict canonical_context i k l metasenv
- | C.Sort _ -> metasenv
- | C.Implicit -> metasenv
- | C.Cast (te,ty) ->
- let metasenv' = aux metasenv k te in
- aux metasenv' k ty
- | C.Prod (_,s,t)
- | C.Lambda (_,s,t)
- | C.LetIn (_,s,t) ->
- let metasenv' = aux metasenv k s in
- aux metasenv' (k+1) t
- | C.Appl l ->
- List.fold_left
- (function metasenv -> aux metasenv k) metasenv l
- | C.Const _
- | C.MutInd _
- | C.MutConstruct _ -> metasenv
- | C.MutCase (_,_,_,outty,t,pl) ->
- let metasenv' = aux metasenv k outty in
- let metasenv'' = aux metasenv' k t in
- List.fold_left
- (function metasenv -> aux metasenv k) metasenv'' pl
- | C.Fix (i, fl) ->
- let len = List.length fl in
- List.fold_left
- (fun metasenv f ->
- let (_,_,ty,bo) = f in
- let metasenv' = aux metasenv k ty in
- aux metasenv' (k+len) bo
- ) metasenv fl
- | C.CoFix (i, fl) ->
- let len = List.length fl in
- List.fold_left
- (fun metasenv f ->
- let (_,ty,bo) = f in
- let metasenv' = aux metasenv k ty in
- aux metasenv' (k+len) bo
- ) metasenv fl
- in aux metasenv 0
-;;
-*)
-