1 (* Copyright (C) 2002, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
30 exception TheTypeOfTheCurrentGoalIsAMetaICannotChooseTheRightElimiantionPrinciple
31 exception NotAnInductiveTypeToEliminate
32 exception WrongUriToVariable of string
34 (* lambda_abstract newmeta ty *)
35 (* returns a triple [bo],[context],[ty'] where *)
36 (* [ty] = Pi/LetIn [context].[ty'] ([context] is a vector!) *)
37 (* and [bo] = Lambda/LetIn [context].(Meta [newmeta]) *)
38 (* So, lambda_abstract is the core of the implementation of *)
39 (* the Intros tactic. *)
40 (* howmany = -1 means Intros, howmany > 0 means Intros n *)
41 let lambda_abstract ?(howmany=(-1)) metasenv context newmeta ty mk_fresh_name =
43 let rec collect_context context howmany do_whd ty =
47 CicMkImplicit.identity_relocation_list_for_metavariable context
49 context, ty, (C.Meta (newmeta,irl))
52 C.Cast (te,_) -> collect_context context howmany do_whd te
54 let n' = mk_fresh_name metasenv context n ~typ:s in
55 let (context',ty,bo) =
56 collect_context ((Some (n',(C.Decl s)))::context) (howmany - 1) do_whd t
58 (context',ty,C.Lambda(n',s,bo))
60 let (context',ty,bo) =
61 collect_context ((Some (n,(C.Def (s,None))))::context) (howmany - 1) do_whd t
63 (context',ty,C.LetIn(n,s,bo))
67 CicMkImplicit.identity_relocation_list_for_metavariable context
69 context, t, (C.Meta (newmeta,irl))
71 let t = CicReduction.whd ~delta:true context t in
72 collect_context context howmany false t
74 raise (Fail (lazy "intro(s): not enough products or let-ins"))
76 collect_context context howmany true ty
78 let eta_expand metasenv context t arg =
79 let module T = CicTypeChecker in
80 let module S = CicSubstitution in
84 t' when t' = S.lift n arg -> C.Rel (1 + n)
85 | C.Rel m -> if m <= n then C.Rel m else C.Rel (m+1)
86 | C.Var (uri,exp_named_subst) ->
87 let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
88 C.Var (uri,exp_named_subst')
91 List.map (function None -> None | Some t -> Some (aux n t)) l
95 | C.Implicit _ as t -> t
96 | C.Cast (te,ty) -> C.Cast (aux n te, aux n ty)
97 | C.Prod (nn,s,t) -> C.Prod (nn, aux n s, aux (n+1) t)
98 | C.Lambda (nn,s,t) -> C.Lambda (nn, aux n s, aux (n+1) t)
99 | C.LetIn (nn,s,t) -> C.LetIn (nn, aux n s, aux (n+1) t)
100 | C.Appl l -> C.Appl (List.map (aux n) l)
101 | C.Const (uri,exp_named_subst) ->
102 let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
103 C.Const (uri,exp_named_subst')
104 | C.MutInd (uri,i,exp_named_subst) ->
105 let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
106 C.MutInd (uri,i,exp_named_subst')
107 | C.MutConstruct (uri,i,j,exp_named_subst) ->
108 let exp_named_subst' = aux_exp_named_subst n exp_named_subst in
109 C.MutConstruct (uri,i,j,exp_named_subst')
110 | C.MutCase (sp,i,outt,t,pl) ->
111 C.MutCase (sp,i,aux n outt, aux n t,
114 let tylen = List.length fl in
117 (fun (name,i,ty,bo) -> (name, i, aux n ty, aux (n+tylen) bo))
120 C.Fix (i, substitutedfl)
122 let tylen = List.length fl in
125 (fun (name,ty,bo) -> (name, aux n ty, aux (n+tylen) bo))
128 C.CoFix (i, substitutedfl)
129 and aux_exp_named_subst n =
130 List.map (function uri,t -> uri,aux n t)
133 T.type_of_aux' metasenv context arg CicUniv.empty_ugraph (* TASSI: FIXME *)
136 FreshNamesGenerator.mk_fresh_name ~subst:[]
137 metasenv context (Cic.Name "Heta") ~typ:argty
139 (C.Appl [C.Lambda (fresh_name,argty,aux 0 t) ; arg])
141 (*CSC: ma serve solamente la prima delle new_uninst e l'unione delle due!!! *)
142 let classify_metas newmeta in_subst_domain subst_in metasenv =
144 (fun (i,canonical_context,ty) (old_uninst,new_uninst) ->
145 if in_subst_domain i then
146 old_uninst,new_uninst
148 let ty' = subst_in canonical_context ty in
149 let canonical_context' =
151 (fun entry canonical_context' ->
154 Some (n,Cic.Decl s) ->
155 Some (n,Cic.Decl (subst_in canonical_context' s))
156 | Some (n,Cic.Def (s,None)) ->
157 Some (n,Cic.Def ((subst_in canonical_context' s),None))
159 | Some (n,Cic.Def (bo,Some ty)) ->
163 (subst_in canonical_context' bo,
164 Some (subst_in canonical_context' ty)))
166 entry'::canonical_context'
167 ) canonical_context []
170 ((i,canonical_context',ty')::old_uninst),new_uninst
172 old_uninst,((i,canonical_context',ty')::new_uninst)
175 (* Useful only inside apply_tac *)
177 generalize_exp_named_subst_with_fresh_metas context newmeta uri exp_named_subst
179 let module C = Cic in
181 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
182 CicUtil.params_of_obj o
184 let exp_named_subst_diff,new_fresh_meta,newmetasenvfragment,exp_named_subst'=
185 let next_fresh_meta = ref newmeta in
186 let newmetasenvfragment = ref [] in
187 let exp_named_subst_diff = ref [] in
193 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
195 C.Variable (_,_,ty,_,_) ->
196 CicSubstitution.subst_vars !exp_named_subst_diff ty
197 | _ -> raise (WrongUriToVariable (UriManager.string_of_uri uri))
199 (* CSC: patch to generate ?1 : ?2 : Type in place of ?1 : Type to simulate ?1 :< Type
201 C.Sort (C.Type _) as s -> (* TASSI: ?? *)
202 let fresh_meta = !next_fresh_meta in
203 let fresh_meta' = fresh_meta + 1 in
204 next_fresh_meta := !next_fresh_meta + 2 ;
205 let subst_item = uri,C.Meta (fresh_meta',[]) in
206 newmetasenvfragment :=
207 (fresh_meta,[],C.Sort (C.Type (CicUniv.fresh()))) ::
209 (fresh_meta',[],C.Meta (fresh_meta,[])) :: !newmetasenvfragment ;
210 exp_named_subst_diff := !exp_named_subst_diff @ [subst_item] ;
211 subst_item::(aux (tl,[]))
215 CicMkImplicit.identity_relocation_list_for_metavariable context
217 let subst_item = uri,C.Meta (!next_fresh_meta,irl) in
218 newmetasenvfragment :=
219 (!next_fresh_meta,context,ty)::!newmetasenvfragment ;
220 exp_named_subst_diff := !exp_named_subst_diff @ [subst_item] ;
221 incr next_fresh_meta ;
222 subst_item::(aux (tl,[]))(*)*)
223 | uri::tl1,((uri',_) as s)::tl2 ->
224 assert (UriManager.eq uri uri') ;
226 | [],_ -> assert false
228 let exp_named_subst' = aux (params,exp_named_subst) in
229 !exp_named_subst_diff,!next_fresh_meta,
230 List.rev !newmetasenvfragment, exp_named_subst'
232 new_fresh_meta,newmetasenvfragment,exp_named_subst',exp_named_subst_diff
235 let new_metasenv_and_unify_and_t newmeta' metasenv' context term' ty termty goal_arity =
236 let (consthead,newmetasenv,arguments,_) =
237 TermUtil.saturate_term newmeta' metasenv' context termty
239 let subst,newmetasenv',_ =
240 CicUnification.fo_unif newmetasenv context consthead ty CicUniv.empty_ugraph
243 if List.length arguments = 0 then term' else Cic.Appl (term'::arguments)
247 let rec count_prods context ty =
248 match CicReduction.whd context ty with
249 Cic.Prod (n,s,t) -> 1 + count_prods (Some (n,Cic.Decl s)::context) t
252 let apply_with_subst ~term ~subst ~maxmeta (proof, goal) =
253 (* Assumption: The term "term" must be closed in the current context *)
254 let module T = CicTypeChecker in
255 let module R = CicReduction in
256 let module C = Cic in
257 let (_,metasenv,_,_, _) = proof in
258 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
259 let newmeta = max (CicMkImplicit.new_meta metasenv subst) maxmeta in
260 let exp_named_subst_diff,newmeta',newmetasenvfragment,term' =
262 C.Var (uri,exp_named_subst) ->
263 let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
264 generalize_exp_named_subst_with_fresh_metas context newmeta uri
267 exp_named_subst_diff,newmeta',newmetasenvfragment,
268 C.Var (uri,exp_named_subst')
269 | C.Const (uri,exp_named_subst) ->
270 let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
271 generalize_exp_named_subst_with_fresh_metas context newmeta uri
274 exp_named_subst_diff,newmeta',newmetasenvfragment,
275 C.Const (uri,exp_named_subst')
276 | C.MutInd (uri,tyno,exp_named_subst) ->
277 let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
278 generalize_exp_named_subst_with_fresh_metas context newmeta uri
281 exp_named_subst_diff,newmeta',newmetasenvfragment,
282 C.MutInd (uri,tyno,exp_named_subst')
283 | C.MutConstruct (uri,tyno,consno,exp_named_subst) ->
284 let newmeta',newmetasenvfragment,exp_named_subst',exp_named_subst_diff =
285 generalize_exp_named_subst_with_fresh_metas context newmeta uri
288 exp_named_subst_diff,newmeta',newmetasenvfragment,
289 C.MutConstruct (uri,tyno,consno,exp_named_subst')
290 | _ -> [],newmeta,[],term
292 let metasenv' = metasenv@newmetasenvfragment in
294 CicTypeChecker.type_of_aux' metasenv' context term' CicUniv.empty_ugraph
297 CicSubstitution.subst_vars exp_named_subst_diff termty in
298 let goal_arity = count_prods context ty in
299 let subst,newmetasenv',t =
300 let rec add_one_argument n =
302 new_metasenv_and_unify_and_t newmeta' metasenv' context term' ty
304 with CicUnification.UnificationFailure _ when n > 0 ->
305 add_one_argument (n - 1)
307 add_one_argument goal_arity
309 let in_subst_domain i = List.exists (function (j,_) -> i=j) subst in
310 let apply_subst = CicMetaSubst.apply_subst subst in
311 let old_uninstantiatedmetas,new_uninstantiatedmetas =
312 (* subst_in doesn't need the context. Hence the underscore. *)
313 let subst_in _ = CicMetaSubst.apply_subst subst in
314 classify_metas newmeta in_subst_domain subst_in newmetasenv'
316 let bo' = apply_subst t in
317 let newmetasenv'' = new_uninstantiatedmetas@old_uninstantiatedmetas in
319 (* if we just apply the subtitution, the type is irrelevant:
320 we may use Implicit, since it will be dropped *)
321 CicMetaSubst.apply_subst ((metano,(context,bo',Cic.Implicit None))::subst)
323 let (newproof, newmetasenv''') =
324 ProofEngineHelpers.subst_meta_and_metasenv_in_proof proof metano subst_in
327 let subst = ((metano,(context,bo',Cic.Implicit None))::subst) in
329 (newproof, List.map (function (i,_,_) -> i) new_uninstantiatedmetas),
330 max maxmeta (CicMkImplicit.new_meta newmetasenv''' subst)
334 let apply_with_subst ~term ?(subst=[]) ?(maxmeta=0) status =
336 (* apply_tac_verbose ~term status *)
337 apply_with_subst ~term ~subst ~maxmeta status
338 (* TODO cacciare anche altre eccezioni? *)
340 | CicUnification.UnificationFailure msg
341 | CicTypeChecker.TypeCheckerFailure msg -> raise (Fail msg)
344 let apply_tac_verbose ~term status =
345 let subst, status, _ = apply_with_subst ~term status in
346 (CicMetaSubst.apply_subst subst), status
348 let apply_tac ~term status = snd (apply_tac_verbose ~term status)
350 (* TODO per implementare i tatticali e' necessario che tutte le tattiche
351 sollevino _solamente_ Fail *)
352 let apply_tac ~term =
353 let apply_tac ~term status =
355 apply_tac ~term status
356 (* TODO cacciare anche altre eccezioni? *)
358 | CicUnification.UnificationFailure msg
359 | CicTypeChecker.TypeCheckerFailure msg ->
362 mk_tactic (apply_tac ~term)
364 let intros_tac ?howmany ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[]) ()=
366 ?(mk_fresh_name_callback = (FreshNamesGenerator.mk_fresh_name ~subst:[])) ()
369 let module C = Cic in
370 let module R = CicReduction in
371 let (_,metasenv,_,_, _) = proof in
372 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
373 let newmeta = ProofEngineHelpers.new_meta_of_proof ~proof in
374 let (context',ty',bo') =
375 lambda_abstract ?howmany metasenv context newmeta ty mk_fresh_name_callback
378 ProofEngineHelpers.subst_meta_in_proof proof metano bo'
379 [newmeta,context',ty']
381 (newproof, [newmeta])
383 mk_tactic (intros_tac ~mk_fresh_name_callback ())
385 let cut_tac ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[]) term =
387 ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[])
390 let module C = Cic in
391 let curi,metasenv,pbo,pty, attrs = proof in
392 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
393 let newmeta1 = ProofEngineHelpers.new_meta_of_proof ~proof in
394 let newmeta2 = newmeta1 + 1 in
396 mk_fresh_name_callback metasenv context (Cic.Name "Hcut") ~typ:term in
397 let context_for_newmeta1 =
398 (Some (fresh_name,C.Decl term))::context in
400 CicMkImplicit.identity_relocation_list_for_metavariable
404 CicMkImplicit.identity_relocation_list_for_metavariable context
406 let newmeta1ty = CicSubstitution.lift 1 ty in
409 [C.Lambda (fresh_name,term,C.Meta (newmeta1,irl1)) ;
410 C.Meta (newmeta2,irl2)]
413 ProofEngineHelpers.subst_meta_in_proof proof metano bo'
414 [newmeta2,context,term; newmeta1,context_for_newmeta1,newmeta1ty];
416 (newproof, [newmeta1 ; newmeta2])
418 mk_tactic (cut_tac ~mk_fresh_name_callback term)
420 let letin_tac ?(mk_fresh_name_callback=FreshNamesGenerator.mk_fresh_name ~subst:[]) term =
422 ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[])
425 let module C = Cic in
426 let curi,metasenv,pbo,pty, attrs = proof in
429 let m = CicUtil.metas_of_term t in
430 List.exists (fun (j,_) -> i=j) m
432 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
433 if occur metano term then
435 (ProofEngineTypes.Fail (lazy
436 "You can't letin a term containing the current goal"));
438 CicTypeChecker.type_of_aux' metasenv context term CicUniv.empty_ugraph in
439 let newmeta = ProofEngineHelpers.new_meta_of_proof ~proof in
441 mk_fresh_name_callback metasenv context (Cic.Name "Hletin") ~typ:term in
442 let context_for_newmeta =
443 (Some (fresh_name,C.Def (term,None)))::context in
445 CicMkImplicit.identity_relocation_list_for_metavariable
448 let newmetaty = CicSubstitution.lift 1 ty in
449 let bo' = C.LetIn (fresh_name,term,C.Meta (newmeta,irl)) in
451 ProofEngineHelpers.subst_meta_in_proof
452 proof metano bo'[newmeta,context_for_newmeta,newmetaty]
454 (newproof, [newmeta])
456 mk_tactic (letin_tac ~mk_fresh_name_callback term)
458 (** functional part of the "exact" tactic *)
459 let exact_tac ~term =
460 let exact_tac ~term (proof, goal) =
461 (* Assumption: the term bo must be closed in the current context *)
462 let (_,metasenv,_,_, _) = proof in
463 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
464 let module T = CicTypeChecker in
465 let module R = CicReduction in
466 let ty_term,u = T.type_of_aux' metasenv context term CicUniv.empty_ugraph in
467 let b,_ = R.are_convertible context ty_term ty u in (* TASSI: FIXME *)
470 let (newproof, metasenv') =
471 ProofEngineHelpers.subst_meta_in_proof proof metano term [] in
475 raise (Fail (lazy "The type of the provided term is not the one expected."))
477 mk_tactic (exact_tac ~term)
479 (* not really "primitive" tactics .... *)
480 let elim_tac ?using pattern =
481 let elim_tac (proof, goal) =
482 let module T = CicTypeChecker in
483 let module U = UriManager in
484 let module R = CicReduction in
485 let module C = Cic in
486 let (curi,metasenv,proofbo,proofty, attrs) = proof in
487 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
488 let term, metasenv, _ = match pattern with
489 | Some f, [], Some _ -> f context metasenv CicUniv.empty_ugraph
492 let termty,_ = T.type_of_aux' metasenv context term CicUniv.empty_ugraph in
493 let termty = CicReduction.whd context termty in
494 let (termty,metasenv',arguments,fresh_meta) =
495 TermUtil.saturate_term
496 (ProofEngineHelpers.new_meta_of_proof proof) metasenv context termty 0 in
497 let term = if arguments = [] then term else Cic.Appl (term::arguments) in
498 let uri,exp_named_subst,typeno,args =
500 C.MutInd (uri,typeno,exp_named_subst) -> (uri,exp_named_subst,typeno,[])
501 | C.Appl ((C.MutInd (uri,typeno,exp_named_subst))::args) ->
502 (uri,exp_named_subst,typeno,args)
503 | _ -> raise NotAnInductiveTypeToEliminate
506 let buri = U.buri_of_uri uri in
508 let o,_ = CicEnvironment.get_obj CicUniv.empty_ugraph uri in
510 C.InductiveDefinition (tys,_,_,_) ->
511 let (name,_,_,_) = List.nth tys typeno in
515 let ty_ty,_ = T.type_of_aux' metasenv' context ty CicUniv.empty_ugraph in
518 C.Sort C.Prop -> "_ind"
519 | C.Sort C.Set -> "_rec"
520 | C.Sort C.CProp -> "_rec"
521 | C.Sort (C.Type _)-> "_rect"
522 | C.Meta (_,_) -> raise TheTypeOfTheCurrentGoalIsAMetaICannotChooseTheRightElimiantionPrinciple
525 U.uri_of_string (buri ^ "/" ^ name ^ ext ^ ".con")
527 let eliminator_ref = match using with
528 | None -> C.Const (eliminator_uri,exp_named_subst)
532 T.type_of_aux' metasenv' context eliminator_ref CicUniv.empty_ugraph in
533 let rec find_args_no =
535 C.Prod (_,_,t) -> 1 + find_args_no t
536 | C.Cast (s,_) -> find_args_no s
537 | C.LetIn (_,_,t) -> 0 + find_args_no t
540 let args_no = find_args_no ety in
541 (* we find the predicate for the eliminator as in the rewrite tactic ********)
544 FreshNamesGenerator.mk_fresh_name
545 ~subst:[] metasenv' context C.Anonymous ~typ:termty in
546 let lifted_gty = S.lift 1 ty in
547 let lifted_conjecture =
548 metano, (Some (fresh_name, Cic.Decl ty)) :: context, lifted_gty in
549 let lifted_t1 = S.lift 1 t1x in
551 let lifted_concl_pat =
554 | Some term -> Some (S.lift 1 term) in
556 let distance = pred (List.length c - List.length context) in
557 S.lift distance lifted_t1, m, u),[],lifted_concl_pat
560 (****************************************************************************)
562 let rec make_tl base_case =
565 | n -> (C.Implicit None)::(make_tl base_case (n - 1))
567 C.Appl (eliminator_ref :: make_tl term (args_no - 1))
569 let refined_term,_,metasenv'',_ =
570 CicRefine.type_of_aux' metasenv' context term_to_refine
574 ProofEngineHelpers.compare_metasenvs
575 ~oldmetasenv:metasenv ~newmetasenv:metasenv''
577 let proof' = curi,metasenv'',proofbo,proofty, attrs in
578 let proof'', new_goals' =
579 apply_tactic (apply_tac ~term:refined_term) (proof',goal)
581 (* The apply_tactic can have closed some of the new_goals *)
582 let patched_new_goals =
583 let (_,metasenv''',_,_, _) = proof'' in
585 (function i -> List.exists (function (j,_,_) -> j=i) metasenv'''
586 ) new_goals @ new_goals'
588 proof'', patched_new_goals
593 let cases_intros_tac ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[]) term =
594 let cases_tac ~term (proof, goal) =
595 let module T = CicTypeChecker in
596 let module U = UriManager in
597 let module R = CicReduction in
598 let module C = Cic in
599 let (curi,metasenv,proofbo,proofty, attrs) = proof in
600 let metano,context,ty = CicUtil.lookup_meta goal metasenv in
601 let termty,_ = T.type_of_aux' metasenv context term CicUniv.empty_ugraph in
602 let termty = CicReduction.whd context termty in
603 let (termty,metasenv',arguments,fresh_meta) =
604 TermUtil.saturate_term
605 (ProofEngineHelpers.new_meta_of_proof proof) metasenv context termty 0 in
606 let term = if arguments = [] then term else Cic.Appl (term::arguments) in
607 let uri,exp_named_subst,typeno,args =
609 C.MutInd (uri,typeno,exp_named_subst) -> (uri,exp_named_subst,typeno,[])
610 | C.Appl ((C.MutInd (uri,typeno,exp_named_subst))::args) ->
611 (uri,exp_named_subst,typeno,args)
612 | _ -> raise NotAnInductiveTypeToEliminate
614 let paramsno,itty,patterns =
615 match CicEnvironment.get_obj CicUniv.empty_ugraph uri with
616 C.InductiveDefinition (tys,_,paramsno,_),_ ->
617 let _,_,itty,cl = List.nth tys typeno in
618 let rec aux n context t =
619 match n,CicReduction.whd context t with
620 0,C.Prod (name,source,target) ->
622 mk_fresh_name_callback metasenv' context name
623 (*CSC: WRONG TYPE HERE: I can get a "bad" name*)
626 C.Lambda (fresh_name,C.Implicit None,
627 aux 0 (Some (fresh_name,C.Decl source)::context) target)
628 | n,C.Prod (name,source,target) ->
630 mk_fresh_name_callback metasenv' context name
631 (*CSC: WRONG TYPE HERE: I can get a "bad" name*)
634 aux (n-1) (Some (fresh_name,C.Decl source)::context) target
635 | 0,_ -> C.Implicit None
636 | _,_ -> assert false
639 List.map (function (_,cty) -> aux paramsno context cty) cl
644 C.Lambda (C.Name "fixme",C.Implicit None,
645 ProofEngineReduction.replace_lifting
646 ~equality:(ProofEngineReduction.alpha_equivalence)
647 ~what:[CicSubstitution.lift (paramsno+1) term]
648 ~with_what:[C.Rel (paramsno+1)]
649 ~where:(CicSubstitution.lift (paramsno+1) ty))
651 let rec add_lambdas =
654 | n -> C.Lambda (C.Name "fixme",C.Implicit None,add_lambdas (n-1))
656 add_lambdas (count_prods context itty - paramsno)
659 C.MutCase (uri,typeno,outtype,term,patterns)
661 let refined_term,_,metasenv'',_ =
662 CicRefine.type_of_aux' metasenv' context term_to_refine
666 ProofEngineHelpers.compare_metasenvs
667 ~oldmetasenv:metasenv ~newmetasenv:metasenv''
669 let proof' = curi,metasenv'',proofbo,proofty, attrs in
670 let proof'', new_goals' =
671 apply_tactic (apply_tac ~term:refined_term) (proof',goal)
673 (* The apply_tactic can have closed some of the new_goals *)
674 let patched_new_goals =
675 let (_,metasenv''',_,_,_) = proof'' in
677 (function i -> List.exists (function (j,_,_) -> j=i) metasenv'''
678 ) new_goals @ new_goals'
680 proof'', patched_new_goals
682 mk_tactic (cases_tac ~term)
686 let elim_intros_tac ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[])
687 ?depth ?using pattern =
688 Tacticals.then_ ~start:(elim_tac ?using pattern)
689 ~continuation:(intros_tac ~mk_fresh_name_callback ?howmany:depth ())
692 (* The simplification is performed only on the conclusion *)
693 let elim_intros_simpl_tac ?(mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[])
694 ?depth ?using pattern =
695 Tacticals.then_ ~start:(elim_tac ?using pattern)
698 ~start:(intros_tac ~mk_fresh_name_callback ?howmany:depth ())
700 [ReductionTactics.simpl_tac
701 ~pattern:(ProofEngineTypes.conclusion_pattern None)])
704 (* FG: insetrts a "hole" in the context (derived from letin_tac) *)
709 let mk_fresh_name_callback = FreshNamesGenerator.mk_fresh_name ~subst:[] in
710 let term = C.Sort C.Set in
711 let letout_tac (proof, goal) =
712 let curi, metasenv, pbo, pty, attrs = proof in
713 let metano, context, ty = CicUtil.lookup_meta goal metasenv in
714 let newmeta = ProofEngineHelpers.new_meta_of_proof ~proof in
715 let fresh_name = mk_fresh_name_callback metasenv context (Cic.Name "hole") ~typ:term in
716 let context_for_newmeta = None :: context in
717 let irl = CicMkImplicit.identity_relocation_list_for_metavariable context_for_newmeta in
718 let newmetaty = CicSubstitution.lift 1 ty in
719 let bo' = C.LetIn (fresh_name, term, C.Meta (newmeta,irl)) in
720 let newproof, _ = ProofEngineHelpers.subst_meta_in_proof proof metano bo'[newmeta,context_for_newmeta,newmetaty] in