X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Fng_tactics%2FnTactics.ml;h=49daed849e0fab1f9cbfaf7413b04b6d3f7f8ac8;hb=9f1f0cb1ae2665a495db930f1561e381e64f5137;hp=0c5f5360c5ef579fa75851dbbbcea576298047a6;hpb=e898ca2563cc4dfbd328efc7aa3a4ff86feaec92;p=helm.git diff --git a/helm/software/components/ng_tactics/nTactics.ml b/helm/software/components/ng_tactics/nTactics.ml index 0c5f5360c..49daed849 100644 --- a/helm/software/components/ng_tactics/nTactics.ml +++ b/helm/software/components/ng_tactics/nTactics.ml @@ -198,7 +198,7 @@ let compare_statuses ~past ~present = (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 @@ -288,6 +288,14 @@ let typeof status where t = 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 @@ -427,6 +435,20 @@ let select_term low_status (name,context,term) (wanted,path) = 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 @@ -434,6 +456,7 @@ let exact t status goal = instantiate status goal t ;; +let exact_tac t = distribute_tac (exact t) ;; let reopen status = let n,h,metasenv,subst,o = status.pstatus in @@ -477,21 +500,64 @@ let change ~where ~with_what status goal = 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 ] +;;