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/.
28 exception Bad_pattern of string Lazy.t
30 let new_meta_of_proof ~proof:(_, metasenv, _, _) =
31 CicMkImplicit.new_meta metasenv []
33 let subst_meta_in_proof proof meta term newmetasenv =
34 let uri,metasenv,bo,ty = proof in
35 (* empty context is ok for term since it wont be used by apply_subst *)
36 (* hack: since we do not know the context and the type of term, we
37 create a substitution with cc =[] and type = Implicit; they will be
38 in any case dropped by apply_subst, but it would be better to rewrite
39 the code. Cannot we just use apply_subst_metasenv, etc. ?? *)
40 let subst_in = CicMetaSubst.apply_subst [meta,([], term,Cic.Implicit None)] in
42 newmetasenv @ (List.filter (function (m,_,_) -> m <> meta) metasenv)
46 (function i,canonical_context,ty ->
47 let canonical_context' =
50 Some (n,Cic.Decl s) -> Some (n,Cic.Decl (subst_in s))
51 | Some (n,Cic.Def (s,None)) -> Some (n,Cic.Def (subst_in s,None))
53 | Some (n,Cic.Def (bo,Some ty)) ->
54 Some (n,Cic.Def (subst_in bo,Some (subst_in ty)))
57 i,canonical_context',(subst_in ty)
60 let bo' = subst_in bo in
61 (* Metavariables can appear also in the *statement* of the theorem
62 * since the parser does not reject as statements terms with
63 * metavariable therein *)
64 let ty' = subst_in ty in
65 let newproof = uri,metasenv'',bo',ty' in
66 (newproof, metasenv'')
68 (*CSC: commento vecchio *)
69 (* refine_meta_with_brand_new_metasenv meta term subst_in newmetasenv *)
70 (* This (heavy) function must be called when a tactic can instantiate old *)
71 (* metavariables (i.e. existential variables). It substitues the metasenv *)
72 (* of the proof with the result of removing [meta] from the domain of *)
73 (* [newmetasenv]. Then it replaces Cic.Meta [meta] with [term] everywhere *)
74 (* in the current proof. Finally it applies [apply_subst_replacing] to *)
76 (*CSC: A questo punto perche' passare un bo' gia' istantiato, se tanto poi *)
77 (*CSC: ci ripasso sopra apply_subst!!! *)
78 (*CSC: Attenzione! Ora questa funzione applica anche [subst_in] a *)
79 (*CSC: [newmetasenv]. *)
80 let subst_meta_and_metasenv_in_proof proof meta subst_in newmetasenv =
81 let (uri,_,bo,ty) = proof in
82 let bo' = subst_in bo in
83 (* Metavariables can appear also in the *statement* of the theorem
84 * since the parser does not reject as statements terms with
85 * metavariable therein *)
86 let ty' = subst_in ty in
89 (fun metasenv_entry i ->
90 match metasenv_entry with
91 (m,canonical_context,ty) when m <> meta ->
92 let canonical_context' =
96 | Some (i,Cic.Decl t) -> Some (i,Cic.Decl (subst_in t))
97 | Some (i,Cic.Def (t,None)) ->
98 Some (i,Cic.Def (subst_in t,None))
99 | Some (i,Cic.Def (bo,Some ty)) ->
100 Some (i,Cic.Def (subst_in bo,Some (subst_in ty)))
103 (m,canonical_context',subst_in ty)::i
107 let newproof = uri,metasenv',bo',ty' in
108 (newproof, metasenv')
110 let compare_metasenvs ~oldmetasenv ~newmetasenv =
111 List.map (function (i,_,_) -> i)
114 not (List.exists (fun (j,_,_) -> i=j) oldmetasenv)) newmetasenv)
117 (** finds the _pointers_ to subterms that are alpha-equivalent to wanted in t *)
118 let find_subterms ~subst ~metasenv ~ugraph ~wanted ~context t =
119 let rec find subst metasenv ugraph context w t =
121 let subst,metasenv,ugraph =
122 CicUnification.fo_unif_subst subst context metasenv w t ugraph
124 subst,metasenv,ugraph,[context,t]
126 CicUnification.UnificationFailure _
127 | CicUnification.Uncertain _ ->
130 | Cic.Rel _ -> subst,metasenv,ugraph,[]
131 | Cic.Meta (_, ctx) ->
133 fun (subst,metasenv,ugraph,acc) e ->
135 | None -> subst,metasenv,ugraph,acc
137 let subst,metasenv,ugraph,res =
138 find subst metasenv ugraph context w t
140 subst,metasenv,ugraph, res @ acc
141 ) (subst,metasenv,ugraph,[]) ctx
142 | Cic.Lambda (name, t1, t2)
143 | Cic.Prod (name, t1, t2) ->
144 let subst,metasenv,ugraph,rest1 =
145 find subst metasenv ugraph context w t1 in
146 let subst,metasenv,ugraph,rest2 =
147 find subst metasenv ugraph (Some (name, Cic.Decl t1)::context)
148 (CicSubstitution.lift 1 w) t2
150 subst,metasenv,ugraph,rest1 @ rest2
151 | Cic.LetIn (name, t1, t2) ->
152 let subst,metasenv,ugraph,rest1 =
153 find subst metasenv ugraph context w t1 in
154 let subst,metasenv,ugraph,rest2 =
155 find subst metasenv ugraph (Some (name, Cic.Def (t1,None))::context)
156 (CicSubstitution.lift 1 w) t2
158 subst,metasenv,ugraph,rest1 @ rest2
161 (fun (subst,metasenv,ugraph,acc) t ->
162 let subst,metasenv,ugraph,res =
163 find subst metasenv ugraph context w t
165 subst,metasenv,ugraph,res @ acc)
166 (subst,metasenv,ugraph,[]) l
167 | Cic.Cast (t, ty) ->
168 let subst,metasenv,ugraph,rest =
169 find subst metasenv ugraph context w t in
170 let subst,metasenv,ugraph,resty =
171 find subst metasenv ugraph context w ty
173 subst,metasenv,ugraph,rest @ resty
174 | Cic.Implicit _ -> assert false
175 | Cic.Const (_, esubst)
176 | Cic.Var (_, esubst)
177 | Cic.MutInd (_, _, esubst)
178 | Cic.MutConstruct (_, _, _, esubst) ->
180 (fun (subst,metasenv,ugraph,acc) (_, t) ->
181 let subst,metasenv,ugraph,res =
182 find subst metasenv ugraph context w t
184 subst,metasenv,ugraph,res @ acc)
185 (subst,metasenv,ugraph,[]) esubst
186 | Cic.MutCase (_, _, outty, indterm, patterns) ->
187 let subst,metasenv,ugraph,resoutty =
188 find subst metasenv ugraph context w outty in
189 let subst,metasenv,ugraph,resindterm =
190 find subst metasenv ugraph context w indterm in
191 let subst,metasenv,ugraph,respatterns =
193 (fun (subst,metasenv,ugraph,acc) p ->
194 let subst,metaseng,ugraph,res =
195 find subst metasenv ugraph context w p
197 subst,metasenv,ugraph,res @ acc
198 ) (subst,metasenv,ugraph,[]) patterns
200 subst,metasenv,ugraph,resoutty @ resindterm @ respatterns
201 | Cic.Fix (_, funl) ->
203 List.map (fun (n,_,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funl
206 fun (subst,metasenv,ugraph,acc) (_, _, ty, bo) ->
207 let subst,metasenv,ugraph,resty =
208 find subst metasenv ugraph context w ty in
209 let subst,metasenv,ugraph,resbo =
210 find subst metasenv ugraph (tys @ context) w bo
212 subst,metasenv,ugraph, resty @ resbo @ acc
213 ) (subst,metasenv,ugraph,[]) funl
214 | Cic.CoFix (_, funl) ->
216 List.map (fun (n,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funl
219 fun (subst,metasenv,ugraph,acc) (_, ty, bo) ->
220 let subst,metasenv,ugraph,resty =
221 find subst metasenv ugraph context w ty in
222 let subst,metasenv,ugraph,resbo =
223 find subst metasenv ugraph (tys @ context) w bo
225 subst,metasenv,ugraph, resty @ resbo @ acc
226 ) (subst,metasenv,ugraph,[]) funl
228 find subst metasenv ugraph context wanted t
230 let select_in_term ~metasenv ~context ~ugraph ~term ~pattern:(wanted,where) =
231 let add_ctx context name entry = (Some (name, entry)) :: context in
232 let map2 error_msg f l1 l2 =
236 | Invalid_argument _ -> raise (Bad_pattern (lazy error_msg))
238 let rec aux context where term =
239 match (where, term) with
240 | Cic.Implicit (Some `Hole), t -> [context,t]
241 | Cic.Implicit (Some `Type), t -> []
242 | Cic.Implicit None,_ -> []
243 | Cic.Meta (_, ctxt1), Cic.Meta (_, ctxt2) ->
245 (map2 "wrong number of argument in explicit substitution"
248 Some t1, Some t2 -> aux context t1 t2
251 | Cic.Cast (te1, ty1), Cic.Cast (te2, ty2) ->
252 aux context te1 te2 @ aux context ty1 ty2
253 | Cic.Prod (Cic.Anonymous, s1, t1), Cic.Prod (name, s2, t2)
254 | Cic.Lambda (Cic.Anonymous, s1, t1), Cic.Lambda (name, s2, t2) ->
255 aux context s1 s2 @ aux (add_ctx context name (Cic.Decl s2)) t1 t2
256 | Cic.Prod (Cic.Name n1, s1, t1),
257 Cic.Prod ((Cic.Name n2) as name , s2, t2)
258 | Cic.Lambda (Cic.Name n1, s1, t1),
259 Cic.Lambda ((Cic.Name n2) as name, s2, t2) when n1 = n2->
260 aux context s1 s2 @ aux (add_ctx context name (Cic.Decl s2)) t1 t2
261 | Cic.Prod (name1, s1, t1), Cic.Prod (name2, s2, t2)
262 | Cic.Lambda (name1, s1, t1), Cic.Lambda (name2, s2, t2) -> []
263 | Cic.LetIn (Cic.Anonymous, s1, t1), Cic.LetIn (name, s2, t2) ->
264 aux context s1 s2 @ aux (add_ctx context name (Cic.Def (s2,None))) t1 t2
265 | Cic.LetIn (Cic.Name n1, s1, t1),
266 Cic.LetIn ((Cic.Name n2) as name, s2, t2) when n1 = n2->
267 aux context s1 s2 @ aux (add_ctx context name (Cic.Def (s2,None))) t1 t2
268 | Cic.LetIn (name1, s1, t1), Cic.LetIn (name2, s2, t2) -> []
269 | Cic.Appl terms1, Cic.Appl terms2 -> auxs context terms1 terms2
270 | Cic.Var (_, subst1), Cic.Var (_, subst2)
271 | Cic.Const (_, subst1), Cic.Const (_, subst2)
272 | Cic.MutInd (_, _, subst1), Cic.MutInd (_, _, subst2)
273 | Cic.MutConstruct (_, _, _, subst1), Cic.MutConstruct (_, _, _, subst2) ->
274 auxs context (List.map snd subst1) (List.map snd subst2)
275 | Cic.MutCase (_, _, out1, t1, pat1), Cic.MutCase (_ , _, out2, t2, pat2) ->
276 aux context out1 out2 @ aux context t1 t2 @ auxs context pat1 pat2
277 | Cic.Fix (_, funs1), Cic.Fix (_, funs2) ->
279 List.map (fun (n,_,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funs2
282 (map2 "wrong number of mutually recursive functions"
283 (fun (_, _, ty1, bo1) (_, _, ty2, bo2) ->
284 aux context ty1 ty2 @ aux (tys @ context) bo1 bo2)
286 | Cic.CoFix (_, funs1), Cic.CoFix (_, funs2) ->
288 List.map (fun (n,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funs2
291 (map2 "wrong number of mutually co-recursive functions"
292 (fun (_, ty1, bo1) (_, ty2, bo2) ->
293 aux context ty1 ty2 @ aux (tys @ context) bo1 bo2)
297 (lazy (Printf.sprintf "Pattern %s versus term %s"
300 and auxs context terms1 terms2 = (* as aux for list of terms *)
301 List.concat (map2 "wrong number of arguments in application"
302 (fun t1 t2 -> aux context t1 t2) terms1 terms2)
307 | Some where -> aux context where term
310 None -> [],metasenv,ugraph,roots
312 let rec find_in_roots =
314 [] -> [],metasenv,ugraph,[]
315 | (context',where)::tl ->
316 let subst,metasenv,ugraph,tl' = find_in_roots tl in
317 let subst,metasenv,ugraph,found =
318 let wanted, metasenv, ugraph = wanted context' metasenv ugraph in
319 find_subterms ~subst ~metasenv ~ugraph ~wanted ~context:context'
322 subst,metasenv,ugraph,found @ tl'
326 (** create a pattern from a term and a list of subterms.
327 * the pattern is granted to have a ? for every subterm that has no selected
329 * @param equality equality function used while walking the term. Defaults to
330 * physical equality (==) *)
331 let pattern_of ?(equality=(==)) ~term terms =
332 let (===) x y = equality x y in
333 let not_found = false, Cic.Implicit None in
336 | t when List.exists (fun t' -> t === t') terms ->
337 true,Cic.Implicit (Some `Hole)
338 | Cic.Var (uri, subst) ->
339 let b,subst = aux_subst subst in
341 true,Cic.Var (uri, subst)
344 | Cic.Meta (i, ctxt) ->
350 | Some t -> let bt,t = aux t in b||bt ,Some t::ctxt
354 true,Cic.Meta (i, ctxt)
357 | Cic.Cast (te, ty) ->
358 let b1,te = aux te in
359 let b2,ty = aux ty in
360 if b1||b2 then true,Cic.Cast (te, ty)
363 | Cic.Prod (name, s, t) ->
367 true, Cic.Prod (name, s, t)
370 | Cic.Lambda (name, s, t) ->
374 true, Cic.Lambda (name, s, t)
377 | Cic.LetIn (name, s, t) ->
381 true, Cic.LetIn (name, s, t)
396 | Cic.Const (uri, subst) ->
397 let b,subst = aux_subst subst in
399 true, Cic.Const (uri, subst)
402 | Cic.MutInd (uri, tyno, subst) ->
403 let b,subst = aux_subst subst in
405 true, Cic.MutInd (uri, tyno, subst)
408 | Cic.MutConstruct (uri, tyno, consno, subst) ->
409 let b,subst = aux_subst subst in
411 true, Cic.MutConstruct (uri, tyno, consno, subst)
414 | Cic.MutCase (uri, tyno, outty, t, pat) ->
415 let b1,outty = aux outty in
424 if b1 || b2 || b3 then
425 true, Cic.MutCase (uri, tyno, outty, t, pat)
428 | Cic.Fix (funno, funs) ->
431 (fun (name, i, ty, bo) (b,funs) ->
432 let b1,ty = aux ty in
433 let b2,bo = aux bo in
434 b||b1||b2, (name, i, ty, bo)::funs) funs (false,[])
437 true, Cic.Fix (funno, funs)
440 | Cic.CoFix (funno, funs) ->
443 (fun (name, ty, bo) (b,funs) ->
444 let b1,ty = aux ty in
445 let b2,bo = aux bo in
446 b||b1||b2, (name, ty, bo)::funs) funs (false,[])
449 true, Cic.CoFix (funno, funs)
454 | Cic.Implicit _ -> not_found
455 and aux_subst subst =
457 (fun (uri, t) (b,subst) ->
459 b||b1,(uri, t)::subst) subst (false,[])
463 exception Fail of string Lazy.t
465 (** select metasenv conjecture pattern
466 * select all subterms of [conjecture] matching [pattern].
467 * It returns the set of matched terms (that can be compared using physical
468 * equality to the subterms of [conjecture]) together with their contexts.
469 * The representation of the set mimics the ProofEngineTypes.pattern type:
470 * a list of hypothesis (names of) together with the list of its matched
471 * subterms (and their contexts) + the list of matched subterms of the
472 * with their context conclusion. Note: in the result the list of hypothesis
473 * has an entry for each entry in the context and in the same order.
474 * Of course the list of terms (with their context) associated to the
475 * hypothesis name may be empty.
479 let select ~metasenv ~ugraph ~conjecture:(_,context,ty)
480 ~(pattern: (Cic.term, Cic.lazy_term) ProofEngineTypes.pattern)
482 let what, hyp_patterns, goal_pattern = pattern in
483 let find_pattern_for name =
484 try Some (snd (List.find (fun (n, pat) -> Cic.Name n = name) hyp_patterns))
485 with Not_found -> None in
486 let subst,metasenv,ugraph,ty_terms =
487 select_in_term ~metasenv ~context ~ugraph ~term:ty
488 ~pattern:(what,goal_pattern) in
489 let subst,metasenv,ugraph,context_terms =
490 let subst,metasenv,ugraph,res,_ =
492 (fun entry (subst,metasenv,ugraph,res,context) ->
494 None -> subst,metasenv,ugraph,(None::res),(None::context)
495 | Some (name,Cic.Decl term) ->
496 (match find_pattern_for name with
498 subst,metasenv,ugraph,((Some (`Decl []))::res),(entry::context)
500 let subst,metasenv,ugraph,terms =
501 select_in_term ~metasenv ~context ~ugraph ~term
502 ~pattern:(what, Some pat)
504 subst,metasenv,ugraph,((Some (`Decl terms))::res),
506 | Some (name,Cic.Def (bo, ty)) ->
507 (match find_pattern_for name with
509 let selected_ty=match ty with None -> None | Some _ -> Some [] in
510 subst,metasenv,ugraph,((Some (`Def ([],selected_ty)))::res),
513 let subst,metasenv,ugraph,terms_bo =
514 select_in_term ~metasenv ~context ~ugraph ~term:bo
515 ~pattern:(what, Some pat) in
516 let subst,metasenv,ugraph,terms_ty =
518 None -> subst,metasenv,ugraph,None
520 let subst,metasenv,ugraph,res =
521 select_in_term ~metasenv ~context ~ugraph ~term:ty
522 ~pattern:(what, Some pat)
524 subst,metasenv,ugraph,Some res
526 subst,metasenv,ugraph,((Some (`Def (terms_bo,terms_ty)))::res),
528 ) context (subst,metasenv,ugraph,[],[]))
530 subst,metasenv,ugraph,res
532 subst,metasenv,ugraph,context_terms, ty_terms
534 (** locate_in_term equality what where context
535 * [what] must match a subterm of [where] according to [equality]
536 * It returns the matched terms together with their contexts in [where]
537 * [equality] defaults to physical equality
538 * [context] must be the context of [where]
540 let locate_in_term ?(equality=(fun _ -> (==))) what ~where context =
541 let add_ctx context name entry =
542 (Some (name, entry)) :: context in
543 let rec aux context where =
544 if equality context what where then [context,where]
554 | Cic.MutConstruct _ -> []
555 | Cic.Cast (te, ty) -> aux context te @ aux context ty
556 | Cic.Prod (name, s, t)
557 | Cic.Lambda (name, s, t) ->
558 aux context s @ aux (add_ctx context name (Cic.Decl s)) t
559 | Cic.LetIn (name, s, t) ->
560 aux context s @ aux (add_ctx context name (Cic.Def (s,None))) t
561 | Cic.Appl tl -> auxs context tl
562 | Cic.MutCase (_, _, out, t, pat) ->
563 aux context out @ aux context t @ auxs context pat
564 | Cic.Fix (_, funs) ->
566 List.map (fun (n,_,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funs
570 (fun (_, _, ty, bo) ->
571 aux context ty @ aux (tys @ context) bo)
573 | Cic.CoFix (_, funs) ->
575 List.map (fun (n,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funs
580 aux context ty @ aux (tys @ context) bo)
582 and auxs context tl = (* as aux for list of terms *)
583 List.concat (List.map (fun t -> aux context t) tl)
587 (** locate_in_conjecture equality what where context
588 * [what] must match a subterm of [where] according to [equality]
589 * It returns the matched terms together with their contexts in [where]
590 * [equality] defaults to physical equality
591 * [context] must be the context of [where]
593 let locate_in_conjecture ?(equality=fun _ -> (==)) what (_,context,ty) =
596 (fun entry (context,res) ->
598 None -> entry::context, res
599 | Some (_, Cic.Decl ty) ->
600 let res = res @ locate_in_term what ~where:ty context in
601 let context' = entry::context in
603 | Some (_, Cic.Def (bo,ty)) ->
604 let res = res @ locate_in_term what ~where:bo context in
609 res @ locate_in_term what ~where:ty context in
610 let context' = entry::context in
614 res @ locate_in_term what ~where:ty context
616 (* saturate_term newmeta metasenv context ty goal_arity *)
617 (* Given a type [ty] (a backbone), it returns its suffix of length *)
618 (* [goal_arity] head and a new metasenv in which there is new a META for each *)
619 (* hypothesis, a list of arguments for the new applications and the index of *)
620 (* the last new META introduced. The nth argument in the list of arguments is *)
621 (* just the nth new META. *)
622 let saturate_term newmeta metasenv context ty goal_arity =
623 let module C = Cic in
624 let module S = CicSubstitution in
625 assert (goal_arity >= 0);
626 let rec aux newmeta ty =
628 C.Cast (he,_) -> aux newmeta he
629 (* CSC: patch to generate ?1 : ?2 : Type in place of ?1 : Type to simulate ?1 :< Type
630 (* If the expected type is a Type, then also Set is OK ==>
631 * we accept any term of type Type *)
632 (*CSC: BUG HERE: in this way it is possible for the term of
633 * type Type to be different from a Sort!!! *)
634 | C.Prod (name,(C.Sort (C.Type _) as s),t) ->
635 (* TASSI: ask CSC if BUG HERE refers to the C.Cast or C.Propd case *)
637 CicMkImplicit.identity_relocation_list_for_metavariable context
639 let newargument = C.Meta (newmeta+1,irl) in
640 let (res,newmetasenv,arguments,lastmeta) =
641 aux (newmeta + 2) (S.subst newargument t)
644 (newmeta,[],s)::(newmeta+1,context,C.Meta (newmeta,[]))::newmetasenv,
645 newargument::arguments,lastmeta
647 | C.Prod (name,s,t) ->
649 CicMkImplicit.identity_relocation_list_for_metavariable context
651 let newargument = C.Meta (newmeta,irl) in
652 let res,newmetasenv,arguments,lastmeta,prod_no =
653 aux (newmeta + 1) (S.subst newargument t)
655 if prod_no + 1 = goal_arity then
656 let head = CicReduction.normalize ~delta:false context ty in
657 head,[],[],lastmeta,goal_arity + 1
659 (** NORMALIZE RATIONALE
660 * we normalize the target only NOW since we may be in this case:
661 * A1 -> A2 -> T where T = (\lambda x.A3 -> P) k
662 * and we want a mesasenv with ?1:A1 and ?2:A2 and not
663 * ?1, ?2, ?3 (that is the one we whould get if we start from the
664 * beta-normalized A1 -> A2 -> A3 -> P **)
665 let s' = CicReduction.normalize ~delta:false context s in
666 res,(newmeta,context,s')::newmetasenv,newargument::arguments,
669 let head = CicReduction.normalize ~delta:false context t in
670 match CicReduction.whd context head with
671 C.Prod _ as head' -> aux newmeta head'
672 | _ -> head,[],[],newmeta,0
674 (* WARNING: here we are using the invariant that above the most *)
675 (* recente new_meta() there are no used metas. *)
676 let res,newmetasenv,arguments,lastmeta,_ = aux newmeta ty in
677 res,metasenv @ newmetasenv,arguments,lastmeta
679 let lookup_type metasenv context hyp =
680 let rec aux p = function
681 | Some (Cic.Name name, Cic.Decl t) :: _ when name = hyp -> p, t
682 | Some (Cic.Name name, Cic.Def (_, Some t)) :: _ when name = hyp -> p, t
683 | Some (Cic.Name name, Cic.Def (u, _)) :: tail when name = hyp ->
684 p, fst (CicTypeChecker.type_of_aux' metasenv tail u CicUniv.empty_ugraph)
685 | _ :: tail -> aux (succ p) tail
686 | [] -> raise (ProofEngineTypes.Fail (lazy "lookup_type: not premise in the current goal"))
690 (* FG: **********************************************************************)
692 let list_rev_map_filter f l =
693 let rec aux a = function
696 begin match f hd with
698 | Some b -> aux (b :: a) tl
703 let get_name context index =
704 try match List.nth context (pred index) with
705 | Some (Cic.Name name, _) -> Some name
707 with Invalid_argument "List.nth" -> None
709 let get_rel context name =
710 let rec aux i = function
712 | Some (Cic.Name s, _) :: _ when s = name -> Some (Cic.Rel i)
713 | _ :: tl -> aux (succ i) tl