| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 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 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 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 |
|
| 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 |
|
| 93 |
|
| 94 |
|
| 95 |
let pred = |
| 96 |
match dflt_concl with |
| 97 |
| Some concl -> concl |
| 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 |
|
| 106 |
let hyps,bodypred = decompose_lambda_n_assum !evd (nrealargs+1) pred in |
| 107 |
|
| 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 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 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 |
|
| 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 |
|
| 158 |
|
| 159 |
predicate, args |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
let dependent_hyps env0 env sigma id idlist = |
| 206 |
let rec dep_rec = function |
| 207 |
| [] -> [] |
| 208 |
| d::l -> |
| 209 |
|
| 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 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 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 |
|
| 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 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 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 |
|
| 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 |
|
| 408 |
|
| 409 |
(tclTRY (onLastHypId (substHypIfVariable (fun id -> subst_hyp false id)))))) |
| 410 |
names); |
| 411 |
(if as_mode then tclIDTAC else clear [id])] |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
in |
| 416 |
substHypIfVariable |
| 417 |
|
| 418 |
|
| 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 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 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 () -> |
| 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 |
|
| 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 -> |
| 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 |
*) |
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 562 |
|
| 563 |
|
| 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 |