(e.g. the tactic could perform a global analysis of the set of goals)
*)
-let exec tac (low_status,g) =
+let exec tac low_status g =
let stack = [ [0,Open g], [], [], `NoTag ] in
let status = tac { gstatus = stack ; istatus = low_status } in
status.istatus
None, ctx, ty
;;
+let whd status ?delta where t =
+ let _,_,metasenv,subst,_ = status.pstatus in
+ let ctx = match where with `Ctx c -> c | `Term (_,c,_) -> c in
+ let _,_,t = relocate ctx t in
+ let t = NCicReduction.whd ~subst ?delta ctx t in
+ None, ctx, t
+;;
+
let unify status where a b =
let n,h,metasenv,subst,o = status.pstatus in
let ctx = match where with `Ctx c -> c | `Term (_,c,_) -> c in
mk_meta status ~name:out_scope_tag (`Ctx context) (`Def term)
;;
+let select ~where status goal =
+ let name, _, _ as goalty = get_goal status goal in
+ let (wanted,_,where) = GrafiteDisambiguate.disambiguate_npattern where in
+ let path =
+ match where with None -> NCic.Implicit `Term | Some where -> where
+ in
+ let status, newgoalty = select_term status goalty (wanted,path) in
+ let status, instance =
+ mk_meta status ?name (`Term newgoalty) (`Decl newgoalty)
+ in
+ instantiate status goal instance
+;;
+
+let select_tac ~where = distribute_tac (select ~where) ;;
let exact t status goal =
let goalty = get_goal status goal in
instantiate status goal t
;;
+let exact_tac t = distribute_tac (exact t) ;;
let reopen status =
let n,h,metasenv,subst,o = status.pstatus in
instantiate status goal instance
;;
-let apply t status goal =
- let uri,height,metasenv, subst,obj = status.pstatus in
- let name,context,gty = List.assoc goal metasenv in
- let metasenv, subst, lexicon_status, t =
- GrafiteDisambiguate.disambiguate_nterm (Some gty)
- status.lstatus context metasenv subst t
- in
- let subst, metasenv =
- (goal, (name, context, t, gty)):: subst,
- List.filter(fun (x,_) -> x <> goal) metasenv
- in
- let new_pstatus = uri,height,metasenv,subst,obj in
- { lstatus = lexicon_status; pstatus = new_pstatus }
-;;
+let apply t status goal = exact t status goal;;
let apply_tac t = distribute_tac (apply t) ;;
let change_tac ~where ~with_what = distribute_tac (change ~where ~with_what) ;;
+let elim_tac ~what ~where status =
+ block_tac
+ [ select_tac ~where;
+ distribute_tac (fun status goal ->
+ let goalty = get_goal status goal in
+ let status, (_,_,w as what) =
+ disambiguate status what None (`Term goalty) in
+ let _ty_what = typeof status (`Term what) what in
+ (* check inductive... find eliminator *)
+ let w = (*astify what *) CicNotationPt.Ident ("m",None) in
+ let holes = [
+ CicNotationPt.Implicit;CicNotationPt.Implicit;CicNotationPt.Implicit]
+ in
+ let eliminator =
+ CicNotationPt.Appl(CicNotationPt.Ident("nat_ind",None)::holes @ [ w ])
+ in
+ exec (apply_tac ("",0,eliminator)) status goal) ]
+ status
+;;
+
+let intro_tac name =
+ exact_tac
+ ("",0,(CicNotationPt.Binder (`Lambda,
+ (CicNotationPt.Ident (name,None),None),CicNotationPt.Implicit)))
+;;
+
+let analyse_indty status ty =
+ let ref, args =
+ match whd status (`Term ty) ty with
+ | _,_,NCic.Const ref -> ref, []
+ | _,_,NCic.Appl (NCic.Const ref :: args) -> ref, args
+ | _,_,_ -> fail (lazy ("not an inductive type")) in
+ let _,lno,tl,_,i = NCicEnvironment.get_checked_indtys ref in
+ let _,_,_,cl = List.nth tl i in
+ let consno = List.length cl in
+ let left, right = HExtlib.split_nth lno args in
+ ref, consno, left, right
+;;
+
+let case status goal =
+ let _,ctx,_ = get_goal status goal in
+ let ty = typeof status (`Ctx ctx) ("",ctx,NCic.Rel 1) in
+ let ref, consno, left, right = analyse_indty status ty in
+ let t =
+ NCic.Match (ref,NCic.Implicit `Term,NCic.Rel 1,
+ HExtlib.mk_list (NCic.Implicit `Term) consno)
+ in
+ let status,t,ty = refine status (`Ctx ctx) ("",ctx,t) None in
+ instantiate status goal t
+;;
+
+let case_tac = distribute_tac case;;
+
+let case1_tac name =
+ block_tac [ intro_tac name; case_tac ]
+;;