File ‹hypsubst.ML›
signature HYPSUBST_DATA =
sig
val dest_eq : term -> term*term
val imp_intr : thm
val rev_mp : thm
val subst : thm
val sym : thm
end;
signature HYPSUBST =
sig
val bound_hyp_subst_tac : Proof.context -> int -> tactic
val hyp_subst_tac : Proof.context -> int -> tactic
val eq_var : bool -> term -> int * thm
val inspect_pair : bool -> term * term -> thm
end;
functor Hypsubst(Data: HYPSUBST_DATA): HYPSUBST =
struct
local open Data in
exception EQ_VAR;
fun inspect_pair bnd (t, u) =
(case (Envir.eta_contract t, Envir.eta_contract u) of
(Bound i, _) =>
if loose_bvar1 (u, i) then raise Match
else sym
| (_, Bound i) =>
if loose_bvar (t, i) then raise Match
else asm_rl
| (Free _, _) =>
if bnd orelse Logic.occs (t, u) then raise Match
else sym
| (_, Free _) =>
if bnd orelse Logic.occs(u,t) then raise Match
else asm_rl
| _ => raise Match);
fun eq_var bnd =
let fun eq_var_aux k \<^Const_>‹Pure.all _ for ‹Abs(_,_,t)›› = eq_var_aux k t
| eq_var_aux k \<^Const_>‹Pure.imp for A B› =
((k, inspect_pair bnd (dest_eq A))
handle Match => eq_var_aux (k+1) B)
| eq_var_aux k _ = raise EQ_VAR
in eq_var_aux 0 end;
fun gen_hyp_subst_tac bnd ctxt = SUBGOAL(fn (Bi,i) =>
let val n = length(Logic.strip_assums_hyp Bi) - 1
val (k,symopt) = eq_var bnd Bi
in
DETERM
(EVERY [REPEAT_DETERM_N k (eresolve_tac ctxt [rev_mp] i),
eresolve_tac ctxt [revcut_rl] i,
REPEAT_DETERM_N (n-k) (eresolve_tac ctxt [rev_mp] i),
eresolve_tac ctxt [symopt RS subst] i,
REPEAT_DETERM_N n (resolve_tac ctxt [imp_intr] i)])
end
handle THM _ => no_tac | EQ_VAR => no_tac);
val hyp_subst_tac = gen_hyp_subst_tac false;
val bound_hyp_subst_tac = gen_hyp_subst_tac true;
end
end;