Debian Codegraph @

tactics/inv.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 open Pp
12 open CErrors
13 open Util
14 open Names
15 open Termops
16 open Constr
17 open Context
18 open EConstr
19 open Vars
20 open Namegen
21 open Inductiveops
22 open Printer
23 open Retyping
24 open Tacticals
25 open Tactics
26 open Elim
27 open Equality
28 open Tactypes
29 open Proofview.Notations
30
31 module NamedDecl = Context.Named.Declaration
32
33 let var_occurs_in_pf gl id =
34 let env = Proofview.Goal.env gl in
35 let sigma = Proofview.Goal.sigma gl in
36 occur_var env sigma id (Proofview.Goal.concl gl) ||
37 List.exists (occur_var_in_decl env sigma id) (Proofview.Goal.hyps gl)
38
39 (* [make_inv_predicate (ity,args) C]
40
41 is given the inductive type, its arguments, both the global
42 parameters and its local arguments, and is expected to produce a
43 predicate P such that if largs is the "local" part of the
44 arguments, then (P largs) will be convertible with a conclusion of
45 the form:
46
47 <A1>a1=a1-><A2>a2=a2 ... -> C
48
49 Algorithm: suppose length(largs)=n
50
51 (1) Push the entire arity, [xbar:Abar], carrying along largs and
52 the conclusion
53
54 (2) Pair up each ai with its respective Rel version: a1==(Rel n),
55 a2==(Rel n-1), etc.
56
57 (3) For each pair, ai,Rel j, if the Ai is dependent - that is, the
58 type of [Rel j] is an open term, then we construct the iterated
59 tuple, [make_iterated_tuple] does it, and use that for our equation
60
61 Otherwise, we just use <Ai>ai=Rel j
62
63 *)
64
65 type inversion_status = Dep of constr option | NoDep
66
67 type inversion_kind =
68 | SimpleInversion
69 | FullInversion
70 | FullInversionClear
71
72 let evd_comb1 f evdref x =
73 let (evd',y) = f !evdref x in
74 evdref := evd';
75 y
76
77 let compute_eqn env sigma n i ai =
78 (mkRel (n-i),get_type_of env sigma (mkRel (n-i)))
79
80 let make_inv_predicate env evd indf realargs id status concl =
81 let nrealargs = List.length realargs in
82 let (hyps,concl) =
83 match status with
84 | NoDep ->
85 (* We push the arity and leave concl unchanged *)
86 let hyps_arity = get_arity env indf in
87 (hyps_arity,concl)
88 | Dep dflt_concl ->
89 if not (occur_var env !evd id concl) then
90 user_err
91 (str "Current goal does not depend on " ++ Id.print id ++ str".");
92 (* We abstract the conclusion of goal with respect to
93 realargs and c to * be concl in order to rewrite and have
94 c also rewritten when the case * will be done *)
95 let pred =
96 match dflt_concl with
97 | Some concl -> concl (*assumed it's some [x1..xn,H:I(x1..xn)]C*)
98 | None ->
99 let sort = get_sort_quality_of env !evd concl in
100 let sort = evd_comb1 Evd.fresh_sort_in_quality evd sort in
101 let p = make_arity env !evd true indf sort in
102 let evd',(p,ptyp) = Unification.abstract_list_all env
103 !evd p concl (realargs@[mkVar id])
104 in evd := evd'; p in
105 (* abstract_list_all returns only lambda *)
106 let hyps,bodypred = decompose_lambda_n_assum !evd (nrealargs+1) pred in
107 (* We lift to make room for the equations *)
108 (hyps,lift nrealargs bodypred)
109 in
110 let nhyps = Context.Rel.length hyps in
111 let env' = push_rel_context hyps env in
112 (* Now the arity is pushed, and we need to construct the pairs
113 * ai,mkRel(n-i+1) *)
114 (* Now, we can recurse down this list, for each ai,(mkRel k) whether to
115 push <Ai>(mkRel k)=ai (when Ai is closed).
116 In any case, we carry along the rest of pairs *)
117 let eq_term, refl_term =
118 try Rocqlib.lib_ref "core.eq.type", Rocqlib.lib_ref "core.eq.refl"
119 with Rocqlib.NotFoundRef _ ->
120 try Rocqlib.lib_ref "core.identity.type", Rocqlib.lib_ref "core.identity.refl"
121 with Rocqlib.NotFoundRef _ ->
122 user_err (str "No registered equality" ++ spc() ++
123 hov 1
124 (str "(needs \"core.eq.type\" and \"core.eq.refl\"" ++ spc() ++
125 str "or \"core.identity.type\" and \"core.identy.refl\")."))
126 in
127 let rec build_concl eqns args n = function
128 | [] -> it_mkProd concl eqns, Array.rev_of_list args
129 | ai :: restlist ->
130 let ai = lift nhyps ai in
131 let (xi, ti) = compute_eqn env' !evd nhyps n ai in
132 let (lhs,eqnty,rhs) =
133 if closed0 !evd ti then
134 (* shortcut *)
135 (xi,ti,ai)
136 else
137 let open Combinators in
138 let sigma, {telescope_value; telescope_type}, default_value = make_iterated_tuple env' !evd ~default:ai xi ti in
139 evd := sigma; telescope_value, telescope_type, default_value
140 in
141 let eq = evd_comb1 (Evd.fresh_global env) evd eq_term in
142 let eqn = applist (eq,[eqnty;lhs;rhs]) in
143 let refl_term =
144 let _, u = destRef !evd eq in
145 mkRef (refl_term, u)
146 in
147 let refl = mkApp (refl_term, [|eqnty; rhs|]) in
148 let r = Retyping.relevance_of_term env !evd refl in
149 let eqns = (make_annot Anonymous r, lift n eqn) :: eqns in
150 let _ = evd_comb1 (Typing.type_of env) evd refl in
151 let args = refl :: args in
152 build_concl eqns args (succ n) restlist
153 in
154 let (newconcl, args) = build_concl [] [] 0 realargs in
155 let predicate = it_mkLambda_or_LetIn newconcl (name_context env !evd hyps) in
156 let _ = evd_comb1 (Typing.type_of env) evd predicate in
157 (* OK - this predicate should now be usable by res_elimination_then to
158 do elimination on the conclusion. *)
159 predicate, args
160
161 (* The result of the elimination is a bunch of goals like:
162
163 |- (cibar:Cibar)Equands->C
164
165 where the cibar are either dependent or not. We are fed a
166 signature, with "true" for every recursive argument, and false for
167 every non-recursive one. So we need to do the
168 sign_branch_len(sign) intros, thinning out all recursive
169 assumptions. This leaves us with exactly length(sign) assumptions.
170
171 We save their names, and then do introductions for all the equands
172 (there are some number of them, which is the other argument of the
173 tactic)
174
175 This gives us the #neqns equations, whose names we get also, and
176 the #length(sign) arguments.
177
178 Suppose that #nodep of these arguments are non-dependent.
179 Generalize and thin them.
180
181 This gives us #dep = #length(sign)-#nodep arguments which are
182 dependent.
183
184 Now, we want to take each of the equations, and do all possible
185 injections to get the left-hand-side to be a variable. At the same
186 time, if we find a lhs/rhs pair which are different, we can
187 discriminate them to prove false and finish the branch.
188
189 Then, we thin away the equations, and do the introductions for the
190 #nodep arguments which we generalized before.
191 *)
192
193 (* Called after the case-assumptions have been killed off, and all the
194 intros have been done. Given that the clause in question is an
195 equality (if it isn't we fail), we are responsible for projecting
196 the equality, using Injection and Discriminate, and applying it to
197 the concusion *)
198
199 (* Computes the subset of hypothesis in the local context whose
200 type depends on t (should be of the form (mkVar id)), then
201 it generalizes them, applies tac to rewrite all occurrencies of t,
202 and introduces generalized hypotheis.
203 Precondition: t=(mkVar id) *)
204
205 let dependent_hyps env0 env sigma id idlist =
206 let rec dep_rec = function
207 | [] -> []
208 | d::l ->
209 (* Update the type of id1: it may have been subject to rewriting *)
210 let d =
211 let id = NamedDecl.get_id d in
212 try EConstr.lookup_named id env
213 with Not_found -> raise (Logic.RefinerError (env, sigma, NoSuchHyp id))
214 in
215 if occur_var_in_decl env0 sigma id d
216 then d :: dep_rec l
217 else dep_rec l
218 in
219 dep_rec idlist
220
221 let split_dep_and_nodep hyps gl =
222 List.fold_right
223 (fun d (l1,l2) ->
224 if var_occurs_in_pf gl (NamedDecl.get_id d) then (d::l1,l2) else (l1,d::l2))
225 hyps ([],[])
226
227 (* Computation of dids is late; must have been done in rewrite_equations*)
228 (* Will keep generalizing and introducing back and forth... *)
229 (* Moreover, others hyps depending of dids should have been *)
230 (* generalized; in such a way that [dids] can endly be cleared *)
231 (* Consider for instance this case extracted from Well_Ordering.v
232
233 A : Set
234 B : A ->Set
235 a0 : A
236 f : (B a0) ->WO
237 y : WO
238 H0 : (le_WO y (sup a0 f))
239 ============================
240 (Acc WO le_WO y)
241
242 Inversion H0 gives
243
244 A : Set
245 B : A ->Set
246 a0 : A
247 f : (B a0) ->WO
248 y : WO
249 H0 : (le_WO y (sup a0 f))
250 a1 : A
251 f0 : (B a1) ->WO
252 v : (B a1)
253 H1 : (f0 v)=y
254 H3 : a1=a0
255 f1 : (B a0) ->WO
256 v0 : (B a0)
257 H4 : (existS A [a:A](B a) ->WO a0 f1)=(existS A [a:A](B a) ->WO a0 f)
258 ============================
259 (Acc WO le_WO (f1 v0))
260
261 while, ideally, we would have expected
262
263 A : Set
264 B : A ->Set
265 a0 : A
266 f0 : (B a0)->WO
267 v : (B a0)
268 ============================
269 (Acc WO le_WO (f0 v))
270
271 obtained from destruction with equalities
272
273 A : Set
274 B : A ->Set
275 a0 : A
276 f : (B a0) ->WO
277 y : WO
278 H0 : (le_WO y (sup a0 f))
279 a1 : A
280 f0 : (B a1)->WO
281 v : (B a1)
282 H1 : (f0 v)=y
283 H2 : (sup a1 f0)=(sup a0 f)
284 ============================
285 (Acc WO le_WO (f0 v))
286
287 by clearing initial hypothesis H0 and its dependency y, clearing H1
288 (in fact H1 can be avoided using the same trick as for newdestruct),
289 decomposing H2 to get a1=a0 and (a1,f0)=(a0,f), replacing a1 by a0
290 everywhere and removing a1 and a1=a0 (in fact it would have been more
291 regular to replace a0 by a1, avoiding f1 and v0 cannot replace f0 and v),
292 finally removing H4 (here because f is not used, more generally after using
293 eq_dep and replacing f by f0) [and finally rename a0, f0 into a,f].
294 Summary: nine useless hypotheses!
295 Nota: with Inversion_clear, only four useless hypotheses
296 *)
297
298 let generalizeRewriteIntros as_mode tac depids id =
299 Proofview.tclENV >>= fun env0 ->
300 Proofview.Goal.enter begin fun gl ->
301 let env = Proofview.Goal.env gl in
302 let sigma = Proofview.Goal.sigma gl in
303 let dids = dependent_hyps env0 env sigma id depids in
304 let reintros = if as_mode then intros_replacing else intros_possibly_replacing in
305 (tclTHENLIST
306 [Generalize.bring_hyps dids; tac;
307 (* may actually fail to replace if dependent in a previous eq *)
308 reintros (ids_of_named_context dids)])
309 end
310
311 let error_too_many_names pats =
312 let loc = Loc.merge_opt (List.hd pats).CAst.loc (List.last pats).CAst.loc in
313 Proofview.tclENV >>= fun env ->
314 Proofview.tclEVARMAP >>= fun sigma ->
315 tclZEROMSG ?loc (
316 str "Unexpected " ++
317 str (String.plural (List.length pats) "introduction pattern") ++
318 str ": " ++ pr_enum (Miscprint.pr_intro_pattern
319 (fun c -> Printer.pr_econstr_env env sigma (snd (c env (Evd.from_env env))))) pats ++
320 str ".")
321
322 let get_names (allow_conj,issimple) ({CAst.loc;v=pat} as x) = match pat with
323 | IntroNaming IntroAnonymous | IntroForthcoming _ ->
324 user_err Pp.(str "Anonymous pattern not allowed for inversion equations.")
325 | IntroNaming (IntroFresh _) ->
326 user_err Pp.(str "Fresh pattern not allowed for inversion equations.")
327 | IntroAction IntroWildcard ->
328 user_err Pp.(str "Discarding pattern not allowed for inversion equations.")
329 | IntroAction (IntroRewrite _) ->
330 user_err Pp.(str "Rewriting pattern not allowed for inversion equations.")
331 | IntroAction (IntroOrAndPattern (IntroAndPattern [])) when allow_conj -> (None, [])
332 | IntroAction (IntroOrAndPattern (IntroAndPattern ({CAst.v=IntroNaming (IntroIdentifier id)} :: _ as l)
333 | IntroOrPattern [{CAst.v=IntroNaming (IntroIdentifier id)} :: _ as l]))
334 when allow_conj -> (Some id,l)
335 | IntroAction (IntroOrAndPattern (IntroAndPattern _)) ->
336 if issimple then
337 user_err Pp.(str"Conjunctive patterns not allowed for simple inversion equations.")
338 else
339 user_err Pp.(str"Nested conjunctive patterns not allowed for inversion equations.")
340 | IntroAction (IntroInjection l) ->
341 user_err Pp.(str "Injection patterns not allowed for inversion equations.")
342 | IntroAction (IntroOrAndPattern (IntroOrPattern _)) ->
343 user_err Pp.(str "Disjunctive patterns not allowed for inversion equations.")
344 | IntroAction (IntroApplyOn (c,pat)) ->
345 user_err Pp.(str "Apply patterns not allowed for inversion equations.")
346 | IntroNaming (IntroIdentifier id) ->
347 (Some id,[x])
348
349 let rec tclMAP_i allow_conj n tacfun = function
350 | [] -> tclDO n (tacfun (None,[]))
351 | a::l as l' ->
352 if Int.equal n 0 then error_too_many_names l'
353 else
354 tclTHEN
355 (tacfun (get_names allow_conj a))
356 (tclMAP_i allow_conj (n-1) tacfun l)
357
358 let remember_first_eq id x = if !x == Logic.MoveLast then x := Logic.MoveAfter id
359
360 (* invariant: ProjectAndApply is responsible for erasing the clause
361 which it is given as input
362 It simplifies the clause (an equality) to use it as a rewrite rule and then
363 erases the result of the simplification. *)
364 (* invariant: ProjectAndApplyNoThining simplifies the clause (an equality) .
365 If it can discriminate then the goal is proved, if not tries to use it as
366 a rewrite rule. It erases the clause which is given as input *)
367
368 let dest_nf_eq env sigma t = match EConstr.kind sigma t with
369 | App (r, [| t; x; y |]) ->
370 let open Reductionops in
371 let is_global_exists gr c = match Rocqlib.lib_ref_opt gr with
372 | Some gr -> isRefX env sigma gr c
373 | None -> false
374 in
375 let is_eq = is_global_exists "core.eq.type" r in
376 let is_identity = is_global_exists "core.identity.type" r in
377 if is_eq || is_identity then
378 (t, whd_all env sigma x, whd_all env sigma y)
379 else user_err Pp.(str "Not an equality.")
380 | _ ->
381 user_err Pp.(str "Not an equality.")
382
383 let projectAndApply as_mode thin avoid id eqname names depids =
384 let subst_hyp l2r id =
385 tclTHEN (tclTRY(rewriteInConcl l2r (EConstr.mkVar id)))
386 (if thin then clear [id] else (remember_first_eq id eqname; tclIDTAC))
387 in
388 let substHypIfVariable tac id =
389 Proofview.Goal.enter begin fun gl ->
390 let env = Proofview.Goal.env gl in
391 let sigma = Proofview.Goal.sigma gl in
392 (* We only look at the type of hypothesis "id" *)
393 let hyp = Reductionops.nf_evar sigma (Tacmach.pf_get_hyp_typ id gl) in
394 let (t,t1,t2) = dest_nf_eq env sigma hyp in
395 match (EConstr.kind sigma t1, EConstr.kind sigma t2) with
396 | Var id1, _ -> generalizeRewriteIntros as_mode (subst_hyp true id) depids id1
397 | _, Var id2 -> generalizeRewriteIntros as_mode (subst_hyp false id) depids id2
398 | _ -> tac id
399 end
400 in
401 let deq_trailer id neqns =
402 tclTHENLIST
403 [if as_mode then clear [id] else tclIDTAC;
404 (tclMAP_i (false,false) neqns (function (idopt,_) ->
405 tclTRY (tclTHEN
406 (intro_move_avoid idopt avoid Logic.MoveLast)
407 (* try again to substitute and if still not a variable after *)
408 (* decomposition, arbitrarily try to rewrite RL !? *)
409 (tclTRY (onLastHypId (substHypIfVariable (fun id -> subst_hyp false id))))))
410 names);
411 (if as_mode then tclIDTAC else clear [id])]
412 (* Doing the above late breaks the computation of dids in
413 generalizeRewriteIntros, and hence breaks proper intros_replacing
414 but it is needed for compatibility *)
415 in
416 substHypIfVariable
417 (* If no immediate variable in the equation, try to decompose it *)
418 (* and apply a trailer which again try to substitute *)
419 (fun id ->
420 dEqThen ~keep_proofs:None false (deq_trailer id)
421 (Some (None,ElimOnConstr (EConstr.mkVar id,NoBindings))))
422 id
423
424 let nLastDecls i tac =
425 Proofview.Goal.enter begin fun gl -> tac (nLastDecls gl i) end
426
427 (* Introduction of the equations on arguments
428 othin: discriminates Simple Inversion, Inversion and Inversion_clear
429 None: the equations are introduced, but not rewritten
430 Some thin: the equations are rewritten, and cleared if thin is true *)
431
432 let rewrite_equations as_mode othin neqns names ba =
433 Proofview.Goal.enter begin fun gl ->
434 let (depids,nodepids) = split_dep_and_nodep ba gl in
435 let first_eq = ref Logic.MoveLast in
436 let avoid = if as_mode then Id.Set.of_list (List.map NamedDecl.get_id nodepids) else Id.Set.empty in
437 match othin with
438 | Some thin ->
439 tclTHENLIST
440 [tclDO neqns intro;
441 Generalize.bring_hyps nodepids;
442 clear (ids_of_named_context nodepids);
443 (nLastDecls neqns (fun ctx -> Generalize.bring_hyps (List.rev ctx)));
444 (nLastDecls neqns (fun ctx -> clear (ids_of_named_context ctx)));
445 tclMAP_i (true,false) neqns (fun (idopt,names) ->
446 (tclTHEN
447 (intro_move_avoid idopt avoid Logic.MoveLast)
448 (onLastHypId (fun id ->
449 tclTRY (projectAndApply as_mode thin avoid id first_eq names depids)))))
450 names;
451 tclMAP (fun d -> tclIDTAC >>= fun () -> (* delay for [first_eq]. *)
452 let idopt = if as_mode then Some (NamedDecl.get_id d) else None in
453 intro_move idopt (if thin then Logic.MoveLast else !first_eq))
454 nodepids;
455 (tclMAP (fun d -> tclTRY (clear [NamedDecl.get_id d])) depids)]
456 | None ->
457 (* simple inversion *)
458 if as_mode then
459 tclMAP_i (false,true) neqns (fun (idopt,_) ->
460 intro_move idopt Logic.MoveLast) names
461 else
462 (tclTHENLIST
463 [tclDO neqns intro;
464 Generalize.bring_hyps nodepids;
465 clear (ids_of_named_context nodepids)])
466 end
467
468 let interp_inversion_kind = function
469 | SimpleInversion -> None
470 | FullInversion -> Some false
471 | FullInversionClear -> Some true
472
473 let rewrite_equations_tac as_mode othin id neqns names ba =
474 let othin = interp_inversion_kind othin in
475 let tac = rewrite_equations as_mode othin neqns names ba in
476 match othin with
477 | Some true (* if Inversion_clear, clear the hypothesis *) ->
478 tclTHEN tac (tclTRY (clear [id]))
479 | _ ->
480 tac
481
482 let raw_inversion inv_kind id status names =
483 Proofview.Goal.enter begin fun gl ->
484 let sigma = Proofview.Goal.sigma gl in
485 let env = Proofview.Goal.env gl in
486 let concl = Proofview.Goal.concl gl in
487 let c = mkVar id in
488 let ((ind, u), t) =
489 try Tacred.reduce_to_atomic_ind env sigma (Retyping.get_type_of env sigma c)
490 with UserError _ ->
491 let msg = str "The type of " ++ Id.print id ++ str " is not inductive." in
492 CErrors.user_err msg
493 in
494 let IndType (indf,realargs) = find_rectype env sigma t in
495 let evdref = ref sigma in
496 let (elim_predicate, args) =
497 make_inv_predicate env evdref indf realargs id status concl in
498 let sigma = !evdref in
499 let dep = status != NoDep && (local_occur_var sigma id concl) in
500 let cut_concl =
501 if dep then
502 applist (elim_predicate, realargs@[c])
503 else
504 applist (elim_predicate, realargs)
505 in
506 let refined id =
507 let prf = mkApp (mkVar id, args) in
508 Refine.refine ~typecheck:false (fun h -> (h, prf))
509 in
510 let neqns = List.length realargs in
511 let as_mode = names != None in
512 let (_, args) = decompose_app sigma t in
513 let solve_tac =
514 (* We have to change again because assert_before performs βι-reduction *)
515 change_concl cut_concl <*>
516 case_tac dep names (rewrite_equations_tac as_mode inv_kind id neqns) (ind, u, args) id
517 in
518 tclTHEN (Proofview.Unsafe.tclEVARS sigma)
519 (tclTHENS
520 (assert_before Anonymous cut_concl)
521 [solve_tac; onLastHypId (fun id -> tclTHEN (refined id) reflexivity)])
522 end
523
524 (* Error messages of the inversion tactics *)
525 let wrap_inv_error id = function (e, info) -> match e with
526 | Pretype_errors.PretypeError (_, sigma, Pretype_errors.NotAllowedElimination (_, s, i)) -> begin
527 match ESorts.kind sigma s with
528 | Type _ | Set as k ->
529 Proofview.tclENV >>= fun env ->
530 Proofview.tclEVARMAP >>= fun sigma ->
531 tclZEROMSG (
532 (strbrk "Inversion would require case analysis on sort " ++
533 pr_sort sigma k ++
534 strbrk " which is not allowed for inductive definition " ++
535 pr_inductive env (fst i) ++ str "."))
536 | _ -> Proofview.tclZERO ~info e
537 end
538 | e -> Proofview.tclZERO ~info e
539
540 (* The most general inversion tactic *)
541 let inversion inv_kind status names id =
542 Proofview.tclORELSE
543 (raw_inversion inv_kind id status names)
544 (wrap_inv_error id)
545
546 (* Specializing it... *)
547
548 let inv_gen thin status names =
549 try_intros_until (inversion thin status names)
550
551 let inv k = inv_gen k NoDep
552
553 let inv_tac id = inv FullInversion None (NamedHyp (CAst.make id))
554 let inv_clear_tac id = inv FullInversionClear None (NamedHyp (CAst.make id))
555
556 let dinv k c = inv_gen k (Dep c)
557
558 let dinv_tac id = dinv FullInversion None None (NamedHyp (CAst.make id))
559 let dinv_clear_tac id = dinv FullInversionClear None None (NamedHyp (CAst.make id))
560
561 (* InvIn will bring the specified clauses into the conclusion, and then
562 * perform inversion on the named hypothesis. After, it will intro them
563 * back to their places in the hyp-list. *)
564
565 let invIn k names ids id =
566 Proofview.Goal.enter begin fun gl ->
567 let hyps = List.map (fun id -> Tacmach.pf_get_hyp id gl) ids in
568 let concl = Proofview.Goal.concl gl in
569 let sigma = Proofview.Goal.sigma gl in
570 let nb_prod_init = nb_prod sigma concl in
571 let intros_replace_ids =
572 Proofview.Goal.enter begin fun gl ->
573 let sigma = Proofview.Goal.sigma gl in
574 let concl = Proofview.Goal.concl gl in
575 let nb_of_new_hyp =
576 nb_prod sigma concl - (List.length hyps + nb_prod_init)
577 in
578 if nb_of_new_hyp < 1 then
579 intros_replacing ids
580 else
581 tclTHEN (tclDO nb_of_new_hyp intro) (intros_replacing ids)
582 end
583 in
584 Proofview.tclORELSE
585 (tclTHENLIST
586 [Generalize.bring_hyps hyps;
587 inversion k NoDep names id;
588 intros_replace_ids])
589 (wrap_inv_error id)
590 end
591
592 let invIn_gen k names idl = try_intros_until (invIn k names idl)
593
594 let inv_clause k names = function
595 | [] -> inv k names
596 | idl -> invIn_gen k names idl