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/.
26 exception Bad_pattern of string
28 let new_meta_of_proof ~proof:(_, metasenv, _, _) =
29 CicMkImplicit.new_meta metasenv []
31 let subst_meta_in_proof proof meta term newmetasenv =
32 let uri,metasenv,bo,ty = proof in
33 (* empty context is ok for term since it wont be used by apply_subst *)
34 (* hack: since we do not know the context and the type of term, we
35 create a substitution with cc =[] and type = Implicit; they will be
36 in any case dropped by apply_subst, but it would be better to rewrite
37 the code. Cannot we just use apply_subst_metasenv, etc. ?? *)
38 let subst_in = CicMetaSubst.apply_subst [meta,([], term,Cic.Implicit None)] in
40 newmetasenv @ (List.filter (function (m,_,_) -> m <> meta) metasenv)
44 (function i,canonical_context,ty ->
45 let canonical_context' =
48 Some (n,Cic.Decl s) -> Some (n,Cic.Decl (subst_in s))
49 | Some (n,Cic.Def (s,None)) -> Some (n,Cic.Def ((subst_in s),None))
51 | Some (_,Cic.Def (_,Some _)) -> assert false
54 i,canonical_context',(subst_in ty)
57 let bo' = subst_in bo in
58 (* Metavariables can appear also in the *statement* of the theorem
59 * since the parser does not reject as statements terms with
60 * metavariable therein *)
61 let ty' = subst_in ty in
62 let newproof = uri,metasenv'',bo',ty' in
63 (newproof, metasenv'')
65 (*CSC: commento vecchio *)
66 (* refine_meta_with_brand_new_metasenv meta term subst_in newmetasenv *)
67 (* This (heavy) function must be called when a tactic can instantiate old *)
68 (* metavariables (i.e. existential variables). It substitues the metasenv *)
69 (* of the proof with the result of removing [meta] from the domain of *)
70 (* [newmetasenv]. Then it replaces Cic.Meta [meta] with [term] everywhere *)
71 (* in the current proof. Finally it applies [apply_subst_replacing] to *)
73 (*CSC: A questo punto perche' passare un bo' gia' istantiato, se tanto poi *)
74 (*CSC: ci ripasso sopra apply_subst!!! *)
75 (*CSC: Attenzione! Ora questa funzione applica anche [subst_in] a *)
76 (*CSC: [newmetasenv]. *)
77 let subst_meta_and_metasenv_in_proof proof meta subst_in newmetasenv =
78 let (uri,_,bo,ty) = proof in
79 let bo' = subst_in bo in
80 (* Metavariables can appear also in the *statement* of the theorem
81 * since the parser does not reject as statements terms with
82 * metavariable therein *)
83 let ty' = subst_in ty in
86 (fun metasenv_entry i ->
87 match metasenv_entry with
88 (m,canonical_context,ty) when m <> meta ->
89 let canonical_context' =
93 | Some (i,Cic.Decl t) -> Some (i,Cic.Decl (subst_in t))
94 | Some (i,Cic.Def (t,None)) ->
95 Some (i,Cic.Def ((subst_in t),None))
96 | Some (_,Cic.Def (_,Some _)) -> assert false
99 (m,canonical_context',subst_in ty)::i
103 let newproof = uri,metasenv',bo',ty' in
104 (newproof, metasenv')
106 let compare_metasenvs ~oldmetasenv ~newmetasenv =
107 List.map (function (i,_,_) -> i)
110 not (List.exists (fun (j,_,_) -> i=j) oldmetasenv)) newmetasenv)
113 (** finds the _pointers_ to subterms that are alpha-equivalent to wanted in t *)
114 let find_subterms ~subst ~metasenv ~ugraph ~wanted ~context t =
115 let rec find subst metasenv ugraph context w t =
117 let subst,metasenv,ugraph =
118 CicUnification.fo_unif_subst subst context metasenv w t ugraph
120 subst,metasenv,ugraph,[context,t]
122 CicUnification.UnificationFailure _
123 | CicUnification.Uncertain _ ->
126 | Cic.Rel _ -> subst,metasenv,ugraph,[]
127 | Cic.Meta (_, ctx) ->
129 fun (subst,metasenv,ugraph,acc) e ->
131 | None -> subst,metasenv,ugraph,acc
133 let subst,metasenv,ugraph,res =
134 find subst metasenv ugraph context w t
136 subst,metasenv,ugraph, res @ acc
137 ) (subst,metasenv,ugraph,[]) ctx
138 | Cic.Lambda (name, t1, t2)
139 | Cic.Prod (name, t1, t2) ->
140 let subst,metasenv,ugraph,rest1 =
141 find subst metasenv ugraph context w t1 in
142 let subst,metasenv,ugraph,rest2 =
143 find subst metasenv ugraph (Some (name, Cic.Decl t1)::context)
144 (CicSubstitution.lift 1 w) t2
146 subst,metasenv,ugraph,rest1 @ rest2
147 | Cic.LetIn (name, t1, t2) ->
148 let subst,metasenv,ugraph,rest1 =
149 find subst metasenv ugraph context w t1 in
150 let subst,metasenv,ugraph,rest2 =
151 find subst metasenv ugraph (Some (name, Cic.Def (t1,None))::context)
152 (CicSubstitution.lift 1 w) t2
154 subst,metasenv,ugraph,rest1 @ rest2
157 (fun (subst,metasenv,ugraph,acc) t ->
158 let subst,metasenv,ugraph,res =
159 find subst metasenv ugraph context w t
161 subst,metasenv,ugraph,res @ acc)
162 (subst,metasenv,ugraph,[]) l
163 | Cic.Cast (t, ty) ->
164 let subst,metasenv,ugraph,rest =
165 find subst metasenv ugraph context w t in
166 let subst,metasenv,ugraph,resty =
167 find subst metasenv ugraph context w ty
169 subst,metasenv,ugraph,rest @ resty
170 | Cic.Implicit _ -> assert false
171 | Cic.Const (_, esubst)
172 | Cic.Var (_, esubst)
173 | Cic.MutInd (_, _, esubst)
174 | Cic.MutConstruct (_, _, _, esubst) ->
176 (fun (subst,metasenv,ugraph,acc) (_, t) ->
177 let subst,metasenv,ugraph,res =
178 find subst metasenv ugraph context w t
180 subst,metasenv,ugraph,res @ acc)
181 (subst,metasenv,ugraph,[]) esubst
182 | Cic.MutCase (_, _, outty, indterm, patterns) ->
183 let subst,metasenv,ugraph,resoutty =
184 find subst metasenv ugraph context w outty in
185 let subst,metasenv,ugraph,resindterm =
186 find subst metasenv ugraph context w indterm in
187 let subst,metasenv,ugraph,respatterns =
189 (fun (subst,metasenv,ugraph,acc) p ->
190 let subst,metaseng,ugraph,res =
191 find subst metasenv ugraph context w p
193 subst,metasenv,ugraph,res @ acc
194 ) (subst,metasenv,ugraph,[]) patterns
196 subst,metasenv,ugraph,resoutty @ resindterm @ respatterns
197 | Cic.Fix (_, funl) ->
199 List.map (fun (n,_,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funl
202 fun (subst,metasenv,ugraph,acc) (_, _, ty, bo) ->
203 let subst,metasenv,ugraph,resty =
204 find subst metasenv ugraph context w ty in
205 let subst,metasenv,ugraph,resbo =
206 find subst metasenv ugraph (tys @ context) w bo
208 subst,metasenv,ugraph, resty @ resbo @ acc
209 ) (subst,metasenv,ugraph,[]) funl
210 | Cic.CoFix (_, funl) ->
212 List.map (fun (n,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funl
215 fun (subst,metasenv,ugraph,acc) (_, ty, bo) ->
216 let subst,metasenv,ugraph,resty =
217 find subst metasenv ugraph context w ty in
218 let subst,metasenv,ugraph,resbo =
219 find subst metasenv ugraph (tys @ context) w bo
221 subst,metasenv,ugraph, resty @ resbo @ acc
222 ) (subst,metasenv,ugraph,[]) funl
224 find subst metasenv ugraph context wanted t
226 let select_in_term ~metasenv ~context ~ugraph ~term ~pattern:(wanted,where) =
227 let add_ctx context name entry =
228 (Some (name, entry)) :: context
230 let map2 error_msg f l1 l2 =
234 | Invalid_argument _ -> raise (Bad_pattern error_msg)
236 let rec aux context where term =
237 match (where, term) with
238 | Cic.Implicit (Some `Hole), t -> [context,t]
239 | Cic.Implicit (Some `Type), t -> []
240 | Cic.Implicit None,_ -> []
241 | Cic.Meta (_, ctxt1), Cic.Meta (_, ctxt2) ->
243 (map2 "wrong number of argument in explicit substitution"
246 Some t1, Some t2 -> aux context t1 t2
249 | Cic.Cast (te1, ty1), Cic.Cast (te2, ty2) ->
250 aux context te1 te2 @ aux context ty1 ty2
251 | Cic.Prod (Cic.Anonymous, s1, t1), Cic.Prod (name, s2, t2)
252 | Cic.Lambda (Cic.Anonymous, s1, t1), Cic.Lambda (name, s2, t2) ->
253 aux context s1 s2 @ aux (add_ctx context name (Cic.Decl s2)) t1 t2
254 | Cic.Prod (Cic.Name n1, s1, t1),
255 Cic.Prod ((Cic.Name n2) as name , s2, t2)
256 | Cic.Lambda (Cic.Name n1, s1, t1),
257 Cic.Lambda ((Cic.Name n2) as name, s2, t2) when n1 = n2->
258 aux context s1 s2 @ aux (add_ctx context name (Cic.Decl s2)) t1 t2
259 | Cic.Prod (name1, s1, t1), Cic.Prod (name2, s2, t2)
260 | Cic.Lambda (name1, s1, t1), Cic.Lambda (name2, s2, t2) -> []
261 | Cic.LetIn (Cic.Anonymous, s1, t1), Cic.LetIn (name, s2, t2) ->
262 aux context s1 s2 @ aux (add_ctx context name (Cic.Def (s2,None))) t1 t2
263 | Cic.LetIn (Cic.Name n1, s1, t1),
264 Cic.LetIn ((Cic.Name n2) as name, s2, t2) when n1 = n2->
265 aux context s1 s2 @ aux (add_ctx context name (Cic.Def (s2,None))) t1 t2
266 | Cic.LetIn (name1, s1, t1), Cic.LetIn (name2, s2, t2) -> []
267 | Cic.Appl terms1, Cic.Appl terms2 -> auxs context terms1 terms2
268 | Cic.Var (_, subst1), Cic.Var (_, subst2)
269 | Cic.Const (_, subst1), Cic.Const (_, subst2)
270 | Cic.MutInd (_, _, subst1), Cic.MutInd (_, _, subst2)
271 | Cic.MutConstruct (_, _, _, subst1), Cic.MutConstruct (_, _, _, subst2) ->
272 auxs context (List.map snd subst1) (List.map snd subst2)
273 | Cic.MutCase (_, _, out1, t1, pat1), Cic.MutCase (_ , _, out2, t2, pat2) ->
274 aux context out1 out2 @ aux context t1 t2 @ auxs context pat1 pat2
275 | Cic.Fix (_, funs1), Cic.Fix (_, funs2) ->
277 List.map (fun (n,_,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funs2
280 (map2 "wrong number of mutually recursive functions"
281 (fun (_, _, ty1, bo1) (_, _, ty2, bo2) ->
282 aux context ty1 ty2 @ aux (tys @ context) bo1 bo2)
284 | Cic.CoFix (_, funs1), Cic.CoFix (_, funs2) ->
286 List.map (fun (n,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funs2
289 (map2 "wrong number of mutually co-recursive functions"
290 (fun (_, ty1, bo1) (_, ty2, bo2) ->
291 aux context ty1 ty2 @ aux (tys @ context) bo1 bo2)
295 (Printf.sprintf "Pattern %s versus term %s"
298 and auxs context terms1 terms2 = (* as aux for list of terms *)
299 List.concat (map2 "wrong number of arguments in application"
300 (fun t1 t2 -> aux context t1 t2) terms1 terms2)
302 let context_len = List.length context in
303 let roots = aux context where term in
305 None -> [],metasenv,ugraph,roots
307 let rec find_in_roots =
309 [] -> [],metasenv,ugraph,[]
310 | (context',where)::tl ->
311 let subst,metasenv,ugraph,tl' = find_in_roots tl in
312 let subst,metasenv,ugraph,found =
313 let wanted, metasenv, ugraph = wanted context' metasenv ugraph in
314 find_subterms ~subst ~metasenv ~ugraph ~wanted ~context:context'
317 subst,metasenv,ugraph,found @ tl'
321 (** create a pattern from a term and a list of subterms.
322 * the pattern is granted to have a ? for every subterm that has no selected
324 * @param equality equality function used while walking the term. Defaults to
325 * physical equality (==) *)
326 let pattern_of ?(equality=(==)) ~term terms =
327 let (===) x y = equality x y in
328 let not_found = false, Cic.Implicit None in
331 | t when List.exists (fun t' -> t === t') terms ->
332 true,Cic.Implicit (Some `Hole)
333 | Cic.Var (uri, subst) ->
334 let b,subst = aux_subst subst in
336 true,Cic.Var (uri, subst)
339 | Cic.Meta (i, ctxt) ->
345 | Some t -> let bt,t = aux t in b||bt ,Some t::ctxt
349 true,Cic.Meta (i, ctxt)
352 | Cic.Cast (te, ty) ->
353 let b1,te = aux te in
354 let b2,ty = aux ty in
355 if b1||b2 then true,Cic.Cast (te, ty)
358 | Cic.Prod (name, s, t) ->
362 true, Cic.Prod (name, s, t)
365 | Cic.Lambda (name, s, t) ->
369 true, Cic.Lambda (name, s, t)
372 | Cic.LetIn (name, s, t) ->
376 true, Cic.LetIn (name, s, t)
391 | Cic.Const (uri, subst) ->
392 let b,subst = aux_subst subst in
394 true, Cic.Const (uri, subst)
397 | Cic.MutInd (uri, tyno, subst) ->
398 let b,subst = aux_subst subst in
400 true, Cic.MutInd (uri, tyno, subst)
403 | Cic.MutConstruct (uri, tyno, consno, subst) ->
404 let b,subst = aux_subst subst in
406 true, Cic.MutConstruct (uri, tyno, consno, subst)
409 | Cic.MutCase (uri, tyno, outty, t, pat) ->
410 let b1,outty = aux outty in
419 if b1 || b2 || b3 then
420 true, Cic.MutCase (uri, tyno, outty, t, pat)
423 | Cic.Fix (funno, funs) ->
426 (fun (name, i, ty, bo) (b,funs) ->
427 let b1,ty = aux ty in
428 let b2,bo = aux bo in
429 b||b1||b2, (name, i, ty, bo)::funs) funs (false,[])
432 true, Cic.Fix (funno, funs)
435 | Cic.CoFix (funno, funs) ->
438 (fun (name, ty, bo) (b,funs) ->
439 let b1,ty = aux ty in
440 let b2,bo = aux bo in
441 b||b1||b2, (name, ty, bo)::funs) funs (false,[])
444 true, Cic.CoFix (funno, funs)
449 | Cic.Implicit _ -> not_found
450 and aux_subst subst =
452 (fun (uri, t) (b,subst) ->
454 b||b1,(uri, t)::subst) subst (false,[])
458 exception Fail of string
460 (** select metasenv conjecture pattern
461 * select all subterms of [conjecture] matching [pattern].
462 * It returns the set of matched terms (that can be compared using physical
463 * equality to the subterms of [conjecture]) together with their contexts.
464 * The representation of the set mimics the ProofEngineTypes.pattern type:
465 * a list of hypothesis (names of) together with the list of its matched
466 * subterms (and their contexts) + the list of matched subterms of the
467 * with their context conclusion. Note: in the result the list of hypothesis
468 * has an entry for each entry in the context and in the same order.
469 * Of course the list of terms (with their context) associated to the
470 * hypothesis name may be empty.
474 let select ~metasenv ~ugraph ~conjecture:(_,context,ty)
475 ~pattern:(what,hyp_patterns,goal_pattern)
477 let find_pattern_for name =
478 try Some (snd (List.find (fun (n, pat) -> Cic.Name n = name) hyp_patterns))
479 with Not_found -> None in
480 let subst,metasenv,ugraph,ty_terms =
481 select_in_term ~metasenv ~context ~ugraph ~term:ty
482 ~pattern:(what,goal_pattern) in
483 let context_len = List.length context in
484 let subst,metasenv,ugraph,context_terms =
485 let subst,metasenv,ugraph,res,_ =
487 (fun entry (subst,metasenv,ugraph,res,context) ->
489 None -> subst,metasenv,ugraph,(None::res),(None::context)
490 | Some (name,Cic.Decl term) ->
491 (match find_pattern_for name with
493 subst,metasenv,ugraph,((Some (`Decl []))::res),(entry::context)
495 let subst,metasenv,ugraph,terms =
496 select_in_term ~metasenv ~context ~ugraph ~term
499 subst,metasenv,ugraph,((Some (`Decl terms))::res),
501 | Some (name,Cic.Def (bo, ty)) ->
502 (match find_pattern_for name with
504 let selected_ty=match ty with None -> None | Some _ -> Some [] in
505 subst,metasenv,ugraph,((Some (`Def ([],selected_ty)))::res),
508 let subst,metasenv,ugraph,terms_bo =
509 select_in_term ~metasenv ~context ~ugraph ~term:bo
510 ~pattern:(what,pat) in
511 let subst,metasenv,ugraph,terms_ty =
513 None -> subst,metasenv,ugraph,None
515 let subst,metasenv,ugraph,res =
516 select_in_term ~metasenv ~context ~ugraph ~term:ty
519 subst,metasenv,ugraph,Some res
521 subst,metasenv,ugraph,((Some (`Def (terms_bo,terms_ty)))::res),
523 ) context (subst,metasenv,ugraph,[],[]))
525 subst,metasenv,ugraph,res
527 subst,metasenv,ugraph,context_terms, ty_terms
529 (** locate_in_term equality what where context
530 * [what] must match a subterm of [where] according to [equality]
531 * It returns the matched terms together with their contexts in [where]
532 * [equality] defaults to physical equality
533 * [context] must be the context of [where]
535 let locate_in_term ?(equality=(fun _ -> (==))) what ~where context =
536 let add_ctx context name entry =
537 (Some (name, entry)) :: context in
538 let rec aux context where =
539 if equality context what where then [context,where]
549 | Cic.MutConstruct _ -> []
550 | Cic.Cast (te, ty) -> aux context te @ aux context ty
551 | Cic.Prod (name, s, t)
552 | Cic.Lambda (name, s, t) ->
553 aux context s @ aux (add_ctx context name (Cic.Decl s)) t
554 | Cic.LetIn (name, s, t) ->
555 aux context s @ aux (add_ctx context name (Cic.Def (s,None))) t
556 | Cic.Appl tl -> auxs context tl
557 | Cic.MutCase (_, _, out, t, pat) ->
558 aux context out @ aux context t @ auxs context pat
559 | Cic.Fix (_, funs) ->
561 List.map (fun (n,_,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funs
565 (fun (_, _, ty, bo) ->
566 aux context ty @ aux (tys @ context) bo)
568 | Cic.CoFix (_, funs) ->
570 List.map (fun (n,ty,_) -> Some (Cic.Name n,(Cic.Decl ty))) funs
575 aux context ty @ aux (tys @ context) bo)
577 and auxs context tl = (* as aux for list of terms *)
578 List.concat (List.map (fun t -> aux context t) tl)
582 (** locate_in_conjecture equality what where context
583 * [what] must match a subterm of [where] according to [equality]
584 * It returns the matched terms together with their contexts in [where]
585 * [equality] defaults to physical equality
586 * [context] must be the context of [where]
588 let locate_in_conjecture ?(equality=fun _ -> (==)) what (_,context,ty) =
591 (fun entry (context,res) ->
593 None -> entry::context, res
594 | Some (_, Cic.Decl ty) ->
595 let res = res @ locate_in_term what ~where:ty context in
596 let context' = entry::context in
598 | Some (_, Cic.Def (bo,ty)) ->
599 let res = res @ locate_in_term what ~where:bo context in
604 res @ locate_in_term what ~where:ty context in
605 let context' = entry::context in
609 res @ locate_in_term what ~where:ty context
611 (* saturate_term newmeta metasenv context ty goal_arity *)
612 (* Given a type [ty] (a backbone), it returns its suffix of length *)
613 (* [goal_arity] head and a new metasenv in which there is new a META for each *)
614 (* hypothesis, a list of arguments for the new applications and the index of *)
615 (* the last new META introduced. The nth argument in the list of arguments is *)
616 (* just the nth new META. *)
617 let saturate_term newmeta metasenv context ty goal_arity =
618 let module C = Cic in
619 let module S = CicSubstitution in
620 assert (goal_arity >= 0);
621 let rec aux newmeta ty =
623 C.Cast (he,_) -> aux newmeta he
624 (* CSC: patch to generate ?1 : ?2 : Type in place of ?1 : Type to simulate ?1 :< Type
625 (* If the expected type is a Type, then also Set is OK ==>
626 * we accept any term of type Type *)
627 (*CSC: BUG HERE: in this way it is possible for the term of
628 * type Type to be different from a Sort!!! *)
629 | C.Prod (name,(C.Sort (C.Type _) as s),t) ->
630 (* TASSI: ask CSC if BUG HERE refers to the C.Cast or C.Propd case *)
632 CicMkImplicit.identity_relocation_list_for_metavariable context
634 let newargument = C.Meta (newmeta+1,irl) in
635 let (res,newmetasenv,arguments,lastmeta) =
636 aux (newmeta + 2) (S.subst newargument t)
639 (newmeta,[],s)::(newmeta+1,context,C.Meta (newmeta,[]))::newmetasenv,
640 newargument::arguments,lastmeta
642 | C.Prod (name,s,t) ->
644 CicMkImplicit.identity_relocation_list_for_metavariable context
646 let newargument = C.Meta (newmeta,irl) in
647 let res,newmetasenv,arguments,lastmeta,prod_no =
648 aux (newmeta + 1) (S.subst newargument t)
650 if prod_no + 1 = goal_arity then
651 let head = CicReduction.normalize ~delta:false context ty in
652 head,[],[],lastmeta,goal_arity + 1
654 (** NORMALIZE RATIONALE
655 * we normalize the target only NOW since we may be in this case:
656 * A1 -> A2 -> T where T = (\lambda x.A3 -> P) k
657 * and we want a mesasenv with ?1:A1 and ?2:A2 and not
658 * ?1, ?2, ?3 (that is the one we whould get if we start from the
659 * beta-normalized A1 -> A2 -> A3 -> P **)
660 let s' = CicReduction.normalize ~delta:false context s in
661 res,(newmeta,context,s')::newmetasenv,newargument::arguments,
664 let head = CicReduction.normalize ~delta:false context t in
665 match CicReduction.whd context head with
666 C.Prod _ as head' -> aux newmeta head'
667 | _ -> head,[],[],newmeta,0
669 (* WARNING: here we are using the invariant that above the most *)
670 (* recente new_meta() there are no used metas. *)
671 let res,newmetasenv,arguments,lastmeta,_ = aux newmeta ty in
672 res,metasenv @ newmetasenv,arguments,lastmeta
674 let lookup_type metasenv context hyp =
675 let rec aux p = function
676 | Some (Cic.Name name, Cic.Decl t) :: _ when name = hyp -> p, t
677 | Some (Cic.Name name, Cic.Def (_, Some t)) :: _ when name = hyp -> p, t
678 | Some (Cic.Name name, Cic.Def (u, _)) :: tail when name = hyp ->
679 p, fst (CicTypeChecker.type_of_aux' metasenv tail u CicUniv.empty_ugraph)
680 | _ :: tail -> aux (succ p) tail
681 | [] -> raise (ProofEngineTypes.Fail "lookup_type: not premise in the current goal")