+ let where' =
+ ProofEngineReduction.replace ~equality:(==) ~what:terms ~with_what:terms'
+ ~where:where
+ in
+ CicMetaSubst.apply_subst subst where' in
+ let (subst,metasenv,ugraph,selected_context,selected_ty) =
+ ProofEngineHelpers.select ~metasenv ~ugraph:CicUniv.empty_ugraph ~conjecture
+ ~pattern in
+ let ty' = change subst context_len ty selected_ty in
+ let context' =
+ List.fold_right2
+ (fun entry selected_entry context' ->
+ let context'_len = List.length context' in
+ match entry,selected_entry with
+ None,None -> None::context'
+ | Some (name,Cic.Decl ty),Some (`Decl selected_ty) ->
+ let ty' = change subst context'_len ty selected_ty in
+ Some (name,Cic.Decl ty')::context'
+ | Some (name,Cic.Def (bo,ty)),Some (`Def (selected_bo,selected_ty)) ->
+ let bo' = change subst context'_len bo selected_bo in
+ let ty' =
+ match ty,selected_ty with
+ None,None -> None
+ | Some ty,Some selected_ty ->
+ Some (change subst context'_len ty selected_ty)
+ | _,_ -> assert false
+ in
+ Some (name,Cic.Def (bo',ty'))::context'
+ | _,_ -> assert false
+ ) context selected_context [] in
+ let metasenv' =
+ List.map (function
+ | (n,_,_) when n = metano -> (metano,context',ty')
+ | _ as t -> t
+ ) metasenv
+ in
+ (curi,metasenv',pbo,pty), [metano]
+ in
+ mk_tactic (change_tac ~pattern ~with_what)
+
+let fold_tac ~reduction ~term ~pattern =
+ let fold_tac ~reduction ~term ~pattern:(wanted,hyps_pat,concl_pat) status =
+ assert (wanted = None); (* this should be checked syntactically *)
+ let proof,goal = status in
+ let _,metasenv,_,_ = proof in
+ let _,context,_ = CicUtil.lookup_meta goal metasenv in
+ let reduced_term = reduction context term in
+ apply_tactic
+ (change_tac ~pattern:(Some reduced_term,hyps_pat,concl_pat) term) status
+ in
+ mk_tactic (fold_tac ~reduction ~term ~pattern)