352 ("No such variable in theorem: " ^ Syntax.string_of_vname xi); |
352 ("No such variable in theorem: " ^ Syntax.string_of_vname xi); |
353 val (rtypes, rsorts) = types_sorts thm; |
353 val (rtypes, rsorts) = types_sorts thm; |
354 fun readT (xi, s) = |
354 fun readT (xi, s) = |
355 let val S = case rsorts xi of SOME S => S | NONE => absent xi; |
355 let val S = case rsorts xi of SOME S => S | NONE => absent xi; |
356 val T = Sign.read_typ (sign, sorts) s; |
356 val T = Sign.read_typ (sign, sorts) s; |
357 in if Sign.typ_instance sign (T, TVar (xi, S)) then (xi, T) |
357 val U = TVar (xi, S); |
|
358 in if Sign.typ_instance sign (T, U) then (U, T) |
358 else error |
359 else error |
359 ("Instantiation of " ^ Syntax.string_of_vname xi ^ " fails") |
360 ("Instantiation of " ^ Syntax.string_of_vname xi ^ " fails") |
360 end; |
361 end; |
361 val Tinsts_env = map readT Tinsts; |
362 val Tinsts_env = map readT Tinsts; |
362 (* Preprocess rule: extract vars and their types, apply Tinsts *) |
363 (* Preprocess rule: extract vars and their types, apply Tinsts *) |
363 fun get_typ xi = |
364 fun get_typ xi = |
364 (case rtypes xi of |
365 (case rtypes xi of |
365 SOME T => typ_subst_TVars Tinsts_env T |
366 SOME T => typ_subst_atomic Tinsts_env T |
366 | NONE => absent xi); |
367 | NONE => absent xi); |
367 val (xis, ss) = Library.split_list tinsts; |
368 val (xis, ss) = Library.split_list tinsts; |
368 val Ts = map get_typ xis; |
369 val Ts = map get_typ xis; |
369 val (_, _, Bi, _) = dest_state(st,i) |
370 val (_, _, Bi, _) = dest_state(st,i) |
370 val params = Logic.strip_params Bi |
371 val params = Logic.strip_params Bi |
378 | types' xi = types xi; |
379 | types' xi = types xi; |
379 fun internal x = isSome (types' (x, ~1)); |
380 fun internal x = isSome (types' (x, ~1)); |
380 val used = Drule.add_used thm (Drule.add_used st []); |
381 val used = Drule.add_used thm (Drule.add_used st []); |
381 val (ts, envT) = |
382 val (ts, envT) = |
382 ProofContext.read_termTs_schematic ctxt internal types' sorts used (ss ~~ Ts); |
383 ProofContext.read_termTs_schematic ctxt internal types' sorts used (ss ~~ Ts); |
383 val cenvT = map (apsnd (Thm.ctyp_of sign)) (envT @ Tinsts_env); |
384 val envT' = map (fn (ixn, T) => |
|
385 (TVar (ixn, valOf (rsorts ixn)), T)) envT @ Tinsts_env; |
384 val cenv = |
386 val cenv = |
385 map |
387 map |
386 (fn (xi, t) => |
388 (fn (xi, t) => |
387 pairself (Thm.cterm_of sign) (Var (xi, fastype_of t), t)) |
389 pairself (Thm.cterm_of sign) (Var (xi, fastype_of t), t)) |
388 (gen_distinct |
390 (gen_distinct |
397 | liftvar t = raise TERM("Variable expected", [t]); |
399 | liftvar t = raise TERM("Variable expected", [t]); |
398 fun liftterm t = list_abs_free |
400 fun liftterm t = list_abs_free |
399 (params, Logic.incr_indexes(paramTs,inc) t) |
401 (params, Logic.incr_indexes(paramTs,inc) t) |
400 fun liftpair (cv,ct) = |
402 fun liftpair (cv,ct) = |
401 (cterm_fun liftvar cv, cterm_fun liftterm ct) |
403 (cterm_fun liftvar cv, cterm_fun liftterm ct) |
402 fun lifttvar((a,i),ctyp) = |
404 val lifttvar = pairself (ctyp_of sign o incr_tvar inc); |
403 let val {T,sign} = rep_ctyp ctyp |
|
404 in ((a,i+inc), ctyp_of sign (incr_tvar inc T)) end |
|
405 val rule = Drule.instantiate |
405 val rule = Drule.instantiate |
406 (map lifttvar cenvT, map liftpair cenv) |
406 (map lifttvar envT', map liftpair cenv) |
407 (lift_rule (st, i) thm) |
407 (lift_rule (st, i) thm) |
408 in |
408 in |
409 if i > nprems_of st then no_tac st |
409 if i > nprems_of st then no_tac st |
410 else st |> |
410 else st |> |
411 compose_tac (bires_flag, rule, nprems_of thm) i |
411 compose_tac (bires_flag, rule, nprems_of thm) i |