+ if name = "_clearme" then clear_tac ["_clearme"] else id_tac ]
+;;
+
+let constructor_tac ?(num=1) ~args = distribute_tac (fun status goal ->
+ if num < 1 then fail (lazy "constructor numbers begin with 1");
+ let gty = get_goalty status goal in
+ let status, (r,_,_,_) = analyse_indty status gty in
+ let ref = NReference.mk_constructor num r in
+ let t =
+ if args = [] then Ast.NRef ref else
+ Ast.Appl (HExtlib.list_concat ~sep:[Ast.Implicit `Vector]
+ ([Ast.NRef ref] :: List.map (fun _,_,x -> [x]) args))
+ in
+ exec (apply_tac ("",0,t)) status goal)
+;;
+
+let assert0_tac (hyps,concl) = distribute_tac (fun status goal ->
+ let gty = get_goalty status goal in
+ let eq status ctx t1 t2 =
+ let status,t1 = disambiguate status ctx t1 None in
+ let status,t1 = apply_subst status ctx t1 in
+ let status,t1 = term_of_cic_term status t1 ctx in
+ let t2 = mk_cic_term ctx t2 in
+ let status,t2 = apply_subst status ctx t2 in
+ let status,t2 = term_of_cic_term status t2 ctx in
+ prerr_endline ("COMPARING: " ^ NCicPp.ppterm ~subst:[] ~metasenv:[] ~context:ctx t1 ^ " vs " ^ NCicPp.ppterm ~subst:[] ~metasenv:[] ~context:ctx t2);
+ assert (t1=t2);
+ status
+ in
+ let status,gty' = term_of_cic_term status gty (ctx_of gty) in
+ let status = eq status (ctx_of gty) concl gty' in
+ let status,_ =
+ List.fold_right2
+ (fun (id1,e1) ((id2,e2) as item) (status,ctx) ->
+ assert (id1=id2 || (prerr_endline (id1 ^ " vs " ^ id2); false));
+ match e1,e2 with
+ `Decl t1, NCic.Decl t2 ->
+ let status = eq status ctx t1 t2 in
+ status,item::ctx
+ | `Def (b1,t1), NCic.Def (b2,t2) ->
+ let status = eq status ctx t1 t2 in
+ let status = eq status ctx b1 b2 in
+ status,item::ctx
+ | _ -> assert false
+ ) hyps (ctx_of gty) (status,[])
+ in
+ exec id_tac status goal)
+;;
+
+let assert_tac seqs status =
+ match status#stack with
+ | [] -> assert false
+ | (g,_,_,_) :: s ->
+ assert (List.length g = List.length seqs);
+ (match seqs with
+ [] -> id_tac
+ | [seq] -> assert0_tac seq
+ | _ ->
+ block_tac
+ ((branch_tac ~force:false)::
+ HExtlib.list_concat ~sep:[shift_tac]
+ (List.map (fun seq -> [assert0_tac seq]) seqs)@
+ [merge_tac])
+ ) status
+;;
+
+let inversion_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 ^ "_inv_" ^
+ 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) ])