+let lapply_tac (s,n,t) =
+ exact_tac (s,n, Ast.Appl [Ast.Implicit `JustOne; t])
+;;
+
+let reduce_tac ~reduction ~where =
+ let change status t =
+ match reduction with
+ | `Normalize perform_delta ->
+ normalize status
+ ?delta:(if perform_delta then None else Some max_int) (ctx_of t) t
+ | `Whd perform_delta ->
+ whd status
+ ?delta:(if perform_delta then None else Some max_int) (ctx_of t) t
+ in
+ let where = GrafiteDisambiguate.disambiguate_npattern where in
+ select0_tac ~where ~job:(`ChangeWith change)
+;;
+
+let change_tac ~where ~with_what =
+ let change status t =
+ let status, ww = disambiguate status (ctx_of t) with_what None in
+ let status = unify status (ctx_of t) t ww in
+ status, ww
+ in
+ let where = GrafiteDisambiguate.disambiguate_npattern where in
+ select0_tac ~where ~job:(`ChangeWith change)
+;;
+
+let letin_tac ~where ~what:(_,_,w) name =
+ block_tac [
+ select_tac ~where ~job:(`Substexpand 1) true;
+ exact_tac
+ ("",0,Ast.LetIn((Ast.Ident (name,None),None),w,Ast.Implicit `JustOne));
+ ]
+;;
+
+let apply_tac (s,n,t) =
+ let t = Ast.Appl [t; Ast.Implicit `Vector] in
+ exact_tac (s,n,t)
+;;
+
+type indtyinfo = {
+ rightno: int;
+ leftno: int;
+ consno: int;
+ reference: NReference.reference;
+ }
+;;
+
+let ref_of_indtyinfo iti = iti.reference;;
+
+let analyze_indty_tac ~what indtyref =
+ distribute_tac (fun (status as orig_status) goal ->
+ let goalty = get_goalty status goal in
+ let status, what = disambiguate status (ctx_of goalty) what None in
+ let status, ty_what = typeof status (ctx_of what) what in
+ let status, (r,consno,lefts,rights) = analyse_indty status ty_what in
+ let leftno = List.length lefts in
+ let rightno = List.length rights in
+ indtyref := Some {
+ rightno = rightno; leftno = leftno; consno = consno; reference = r;
+ };
+ exec id_tac orig_status goal)
+;;
+
+let sort_of_goal_tac sortref = distribute_tac (fun status goal ->
+ let goalty = get_goalty status goal in
+ let status,sort = typeof status (ctx_of goalty) goalty in
+ let status, sort = fix_sorts status sort in
+ let status, sort = term_of_cic_term status sort (ctx_of goalty) in
+ sortref := sort;
+ status)
+;;
+
+let elim_tac ~what:(txt,len,what) ~where =
+ let what = txt, len, Ast.Appl [what; Ast.Implicit `Vector] in
+ let indtyinfo = ref None in
+ let sort = ref (NCic.Rel 1) in
+ atomic_tac (block_tac [
+ analyze_indty_tac ~what indtyinfo;
+ (fun s -> select_tac
+ ~where ~job:(`Substexpand ((HExtlib.unopt !indtyinfo).rightno+1)) true s);
+ sort_of_goal_tac sort;
+ (fun status ->
+ let ity = HExtlib.unopt !indtyinfo in
+ let NReference.Ref (uri, _) = ity.reference in
+ let name =
+ NUri.name_of_uri uri ^ "_" ^
+ snd (NCicElim.ast_of_sort
+ (match !sort with NCic.Sort x -> x | _ -> assert false))
+ in
+ let eliminator =
+ let _,_,w = what in
+ Ast.Appl [ Ast.Ident (name,None) ; Ast.Implicit `Vector ; w ]
+ in
+ exact_tac ("",0,eliminator) status) ])