src/Pure/tctical.ML
author berghofe
Wed Oct 31 19:37:04 2001 +0100 (2001-10-31)
changeset 11998 b14e7686ce84
parent 11916 82139d3dcdd7
child 12082 94409d15b00b
permissions -rw-r--r--
- enter_thmx -> enter_thms
- improved naming of theorems: enter_thms now takes functions pre_name and post_name
as arguments
     1 (*  Title:      tctical
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1993  University of Cambridge
     5 
     6 Tacticals
     7 *)
     8 
     9 infix 1 THEN THEN' THEN_ALL_NEW;
    10 infix 0 ORELSE APPEND INTLEAVE ORELSE' APPEND' INTLEAVE';
    11 infix 0 THEN_ELSE;
    12 
    13 
    14 signature TACTICAL =
    15 sig
    16   type tactic  (* = thm -> thm Seq.seq*)
    17   val all_tac           : tactic
    18   val ALLGOALS          : (int -> tactic) -> tactic   
    19   val APPEND            : tactic * tactic -> tactic
    20   val APPEND'           : ('a -> tactic) * ('a -> tactic) -> 'a -> tactic
    21   val CHANGED           : tactic -> tactic
    22   val CHANGED_PROP      : tactic -> tactic
    23   val CHANGED_GOAL	: (int -> tactic) -> int -> tactic
    24   val COND              : (thm -> bool) -> tactic -> tactic -> tactic   
    25   val DETERM            : tactic -> tactic
    26   val EVERY             : tactic list -> tactic   
    27   val EVERY'            : ('a -> tactic) list -> 'a -> tactic
    28   val EVERY1            : (int -> tactic) list -> tactic
    29   val FILTER            : (thm -> bool) -> tactic -> tactic
    30   val FIRST             : tactic list -> tactic   
    31   val FIRST'            : ('a -> tactic) list -> 'a -> tactic
    32   val FIRST1            : (int -> tactic) list -> tactic
    33   val FIRSTGOAL         : (int -> tactic) -> tactic
    34   val goals_limit       : int ref
    35   val INTLEAVE          : tactic * tactic -> tactic
    36   val INTLEAVE'         : ('a -> tactic) * ('a -> tactic) -> 'a -> tactic
    37   val METAHYPS          : (thm list -> tactic) -> int -> tactic
    38   val no_tac            : tactic
    39   val ORELSE            : tactic * tactic -> tactic
    40   val ORELSE'           : ('a -> tactic) * ('a -> tactic) -> 'a -> tactic
    41   val pause_tac         : tactic
    42   val print_tac         : string -> tactic
    43   val RANGE             : (int -> tactic) list -> int -> tactic
    44   val REPEAT            : tactic -> tactic
    45   val REPEAT1           : tactic -> tactic
    46   val REPEAT_FIRST      : (int -> tactic) -> tactic
    47   val REPEAT_SOME       : (int -> tactic) -> tactic
    48   val REPEAT_DETERM_N   : int -> tactic -> tactic
    49   val REPEAT_DETERM     : tactic -> tactic
    50   val REPEAT_DETERM1    : tactic -> tactic
    51   val REPEAT_DETERM_FIRST: (int -> tactic) -> tactic
    52   val REPEAT_DETERM_SOME: (int -> tactic) -> tactic
    53   val DETERM_UNTIL      : (thm -> bool) -> tactic -> tactic
    54   val SELECT_GOAL       : tactic -> int -> tactic
    55   val SOMEGOAL          : (int -> tactic) -> tactic   
    56   val strip_context     : term -> (string * typ) list * term list * term
    57   val SUBGOAL           : ((term*int) -> tactic) -> int -> tactic
    58   val suppress_tracing  : bool ref
    59   val THEN              : tactic * tactic -> tactic
    60   val THEN'             : ('a -> tactic) * ('a -> tactic) -> 'a -> tactic
    61   val THEN_ALL_NEW	: (int -> tactic) * (int -> tactic) -> int -> tactic
    62   val REPEAT_ALL_NEW	: (int -> tactic) -> int -> tactic
    63   val THEN_ELSE         : tactic * (tactic*tactic) -> tactic
    64   val traced_tac        : (thm -> (thm * thm Seq.seq) option) -> tactic
    65   val tracify           : bool ref -> tactic -> tactic
    66   val trace_REPEAT      : bool ref
    67   val TRY               : tactic -> tactic
    68   val TRYALL            : (int -> tactic) -> tactic   
    69 end;
    70 
    71 
    72 structure Tactical : TACTICAL = 
    73 struct
    74 
    75 (**** Tactics ****)
    76 
    77 (*A tactic maps a proof tree to a sequence of proof trees:
    78     if length of sequence = 0 then the tactic does not apply;
    79     if length > 1 then backtracking on the alternatives can occur.*)
    80 
    81 type tactic = thm -> thm Seq.seq;
    82 
    83 
    84 (*** LCF-style tacticals ***)
    85 
    86 (*the tactical THEN performs one tactic followed by another*)
    87 fun (tac1 THEN tac2) st = Seq.flat (Seq.map tac2 (tac1 st));
    88 
    89 
    90 (*The tactical ORELSE uses the first tactic that returns a nonempty sequence.
    91   Like in LCF, ORELSE commits to either tac1 or tac2 immediately.
    92   Does not backtrack to tac2 if tac1 was initially chosen. *)
    93 fun (tac1 ORELSE tac2) st =
    94     case Seq.pull(tac1 st) of
    95         None       => tac2 st
    96       | sequencecell => Seq.make(fn()=> sequencecell);
    97 
    98 
    99 (*The tactical APPEND combines the results of two tactics.
   100   Like ORELSE, but allows backtracking on both tac1 and tac2.
   101   The tactic tac2 is not applied until needed.*)
   102 fun (tac1 APPEND tac2) st = 
   103   Seq.append(tac1 st,
   104                   Seq.make(fn()=> Seq.pull (tac2 st)));
   105 
   106 (*Like APPEND, but interleaves results of tac1 and tac2.*)
   107 fun (tac1 INTLEAVE tac2) st = 
   108     Seq.interleave(tac1 st,
   109                         Seq.make(fn()=> Seq.pull (tac2 st)));
   110 
   111 (*Conditional tactic.
   112         tac1 ORELSE tac2 = tac1 THEN_ELSE (all_tac, tac2)
   113         tac1 THEN tac2   = tac1 THEN_ELSE (tac2, no_tac)
   114 *)
   115 fun (tac THEN_ELSE (tac1, tac2)) st = 
   116     case Seq.pull(tac st) of
   117         None    => tac2 st              (*failed; try tactic 2*)
   118       | seqcell => Seq.flat       (*succeeded; use tactic 1*)
   119                     (Seq.map tac1 (Seq.make(fn()=> seqcell)));
   120 
   121 
   122 (*Versions for combining tactic-valued functions, as in
   123      SOMEGOAL (resolve_tac rls THEN' assume_tac) *)
   124 fun (tac1 THEN' tac2) x = tac1 x THEN tac2 x;
   125 fun (tac1 ORELSE' tac2) x = tac1 x ORELSE tac2 x;
   126 fun (tac1 APPEND' tac2) x = tac1 x APPEND tac2 x;
   127 fun (tac1 INTLEAVE' tac2) x = tac1 x INTLEAVE tac2 x;
   128 
   129 (*passes all proofs through unchanged;  identity of THEN*)
   130 fun all_tac st = Seq.single st;
   131 
   132 (*passes no proofs through;  identity of ORELSE and APPEND*)
   133 fun no_tac st  = Seq.empty;
   134 
   135 
   136 (*Make a tactic deterministic by chopping the tail of the proof sequence*)
   137 fun DETERM tac st =  
   138       case Seq.pull (tac st) of
   139               None => Seq.empty
   140             | Some(x,_) => Seq.cons(x, Seq.empty);
   141 
   142 
   143 (*Conditional tactical: testfun controls which tactic to use next.
   144   Beware: due to eager evaluation, both thentac and elsetac are evaluated.*)
   145 fun COND testfun thenf elsef = (fn prf =>
   146     if testfun prf then  thenf prf   else  elsef prf);
   147 
   148 (*Do the tactic or else do nothing*)
   149 fun TRY tac = tac ORELSE all_tac;
   150 
   151 (*** List-oriented tactics ***)
   152 
   153 local
   154   (*This version of EVERY avoids backtracking over repeated states*)
   155 
   156   fun EVY (trail, []) st = 
   157 	Seq.make (fn()=> Some(st, 
   158 			Seq.make (fn()=> Seq.pull (evyBack trail))))
   159     | EVY (trail, tac::tacs) st = 
   160 	  case Seq.pull(tac st) of
   161 	      None    => evyBack trail              (*failed: backtrack*)
   162 	    | Some(st',q) => EVY ((st',q,tacs)::trail, tacs) st'
   163   and evyBack [] = Seq.empty (*no alternatives*)
   164     | evyBack ((st',q,tacs)::trail) =
   165 	  case Seq.pull q of
   166 	      None        => evyBack trail
   167 	    | Some(st,q') => if eq_thm (st',st) 
   168 			     then evyBack ((st',q',tacs)::trail)
   169 			     else EVY ((st,q',tacs)::trail, tacs) st
   170 in
   171 
   172 (* EVERY [tac1,...,tacn]   equals    tac1 THEN ... THEN tacn   *)
   173 fun EVERY tacs = EVY ([], tacs);
   174 end;
   175 
   176 
   177 (* EVERY' [tac1,...,tacn] i  equals    tac1 i THEN ... THEN tacn i   *)
   178 fun EVERY' tacs i = EVERY (map (fn f => f i) tacs);
   179 
   180 (*Apply every tactic to 1*)
   181 fun EVERY1 tacs = EVERY' tacs 1;
   182 
   183 (* FIRST [tac1,...,tacn]   equals    tac1 ORELSE ... ORELSE tacn   *)
   184 fun FIRST tacs = foldr (op ORELSE) (tacs, no_tac);
   185 
   186 (* FIRST' [tac1,...,tacn] i  equals    tac1 i ORELSE ... ORELSE tacn i   *)
   187 fun FIRST' tacs = foldr (op ORELSE') (tacs, K no_tac);
   188 
   189 (*Apply first tactic to 1*)
   190 fun FIRST1 tacs = FIRST' tacs 1;
   191 
   192 (*Apply tactics on consecutive subgoals*)
   193 fun RANGE [] _ = all_tac
   194   | RANGE (tac :: tacs) i = RANGE tacs (i + 1) THEN tac i;
   195 
   196 
   197 (*** Tracing tactics ***)
   198 
   199 (*Max number of goals to print -- set by user*)
   200 val goals_limit = ref 10;
   201 
   202 (*Print the current proof state and pass it on.*)
   203 fun print_tac msg = 
   204     (fn st => 
   205      (writeln msg;
   206       Display.print_goals (!goals_limit) st; Seq.single st));
   207 
   208 (*Pause until a line is typed -- if non-empty then fail. *)
   209 fun pause_tac st =  
   210   (writeln "** Press RETURN to continue:";
   211    if TextIO.inputLine TextIO.stdIn = "\n" then Seq.single st
   212    else (writeln "Goodbye";  Seq.empty));
   213 
   214 exception TRACE_EXIT of thm
   215 and TRACE_QUIT;
   216 
   217 (*Tracing flags*)
   218 val trace_REPEAT= ref false
   219 and suppress_tracing = ref false;
   220 
   221 (*Handle all tracing commands for current state and tactic *)
   222 fun exec_trace_command flag (tac, st) = 
   223    case TextIO.inputLine(TextIO.stdIn) of
   224        "\n" => tac st
   225      | "f\n" => Seq.empty
   226      | "o\n" => (flag:=false;  tac st)
   227      | "s\n" => (suppress_tracing:=true;  tac st)
   228      | "x\n" => (writeln "Exiting now";  raise (TRACE_EXIT st))
   229      | "quit\n" => raise TRACE_QUIT
   230      | _     => (writeln
   231 "Type RETURN to continue or...\n\
   232 \     f    - to fail here\n\
   233 \     o    - to switch tracing off\n\
   234 \     s    - to suppress tracing until next entry to a tactical\n\
   235 \     x    - to exit at this point\n\
   236 \     quit - to abort this tracing run\n\
   237 \** Well? "     ;  exec_trace_command flag (tac, st));
   238 
   239 
   240 (*Extract from a tactic, a thm->thm seq function that handles tracing*)
   241 fun tracify flag tac st =
   242   if !flag andalso not (!suppress_tracing)
   243            then (Display.print_goals (!goals_limit) st;
   244                  writeln "** Press RETURN to continue:";
   245                  exec_trace_command flag (tac,st))
   246   else tac st;
   247 
   248 (*Create a tactic whose outcome is given by seqf, handling TRACE_EXIT*)
   249 fun traced_tac seqf st = 
   250     (suppress_tracing := false;
   251      Seq.make (fn()=> seqf st
   252                          handle TRACE_EXIT st' => Some(st', Seq.empty)));
   253 
   254 
   255 (*Deterministic DO..UNTIL: only retains the first outcome; tail recursive.
   256   Forces repitition until predicate on state is fulfilled.*)
   257 fun DETERM_UNTIL p tac = 
   258 let val tac = tracify trace_REPEAT tac
   259     fun drep st = if p st then Some (st, Seq.empty)
   260                           else (case Seq.pull(tac st) of
   261                                   None        => None
   262                                 | Some(st',_) => drep st')
   263 in  traced_tac drep  end;
   264 
   265 (*Deterministic REPEAT: only retains the first outcome; 
   266   uses less space than REPEAT; tail recursive.
   267   If non-negative, n bounds the number of repetitions.*)
   268 fun REPEAT_DETERM_N n tac = 
   269   let val tac = tracify trace_REPEAT tac
   270       fun drep 0 st = Some(st, Seq.empty)
   271         | drep n st =
   272            (case Seq.pull(tac st) of
   273                 None       => Some(st, Seq.empty)
   274               | Some(st',_) => drep (n-1) st')
   275   in  traced_tac (drep n)  end;
   276 
   277 (*Allows any number of repetitions*)
   278 val REPEAT_DETERM = REPEAT_DETERM_N ~1;
   279 
   280 (*General REPEAT: maintains a stack of alternatives; tail recursive*)
   281 fun REPEAT tac = 
   282   let val tac = tracify trace_REPEAT tac
   283       fun rep qs st = 
   284         case Seq.pull(tac st) of
   285             None       => Some(st, Seq.make(fn()=> repq qs))
   286           | Some(st',q) => rep (q::qs) st'
   287       and repq [] = None
   288         | repq(q::qs) = case Seq.pull q of
   289             None       => repq qs
   290           | Some(st,q) => rep (q::qs) st
   291   in  traced_tac (rep [])  end;
   292 
   293 (*Repeat 1 or more times*)
   294 fun REPEAT_DETERM1 tac = DETERM tac THEN REPEAT_DETERM tac;
   295 fun REPEAT1 tac = tac THEN REPEAT tac;
   296 
   297 
   298 (** Filtering tacticals **)
   299 
   300 (*Returns all states satisfying the predicate*)
   301 fun FILTER pred tac st = Seq.filter pred (tac st);
   302 
   303 (*Returns all changed states*)
   304 fun CHANGED tac st = 
   305     let fun diff st' = not (eq_thm(st,st'))
   306     in  Seq.filter diff (tac st)  end;
   307 
   308 fun CHANGED_PROP tac st = 
   309     let
   310       val prop = #prop (Thm.rep_thm st);
   311       fun diff st' = not (prop aconv #prop (Thm.rep_thm st'));
   312     in  Seq.filter diff (tac st)  end;
   313 
   314 
   315 (*** Tacticals based on subgoal numbering ***)
   316 
   317 (*For n subgoals, performs tac(n) THEN ... THEN tac(1) 
   318   Essential to work backwards since tac(i) may add/delete subgoals at i. *)
   319 fun ALLGOALS tac st = 
   320   let fun doall 0 = all_tac
   321         | doall n = tac(n) THEN doall(n-1)
   322   in  doall(nprems_of st)st  end;
   323 
   324 (*For n subgoals, performs tac(n) ORELSE ... ORELSE tac(1)  *)
   325 fun SOMEGOAL tac st = 
   326   let fun find 0 = no_tac
   327         | find n = tac(n) ORELSE find(n-1)
   328   in  find(nprems_of st)st  end;
   329 
   330 (*For n subgoals, performs tac(1) ORELSE ... ORELSE tac(n).
   331   More appropriate than SOMEGOAL in some cases.*)
   332 fun FIRSTGOAL tac st = 
   333   let fun find (i,n) = if i>n then no_tac else  tac(i) ORELSE find (i+1,n)
   334   in  find(1, nprems_of st)st  end;
   335 
   336 (*Repeatedly solve some using tac. *)
   337 fun REPEAT_SOME tac = REPEAT1 (SOMEGOAL (REPEAT1 o tac));
   338 fun REPEAT_DETERM_SOME tac = REPEAT_DETERM1 (SOMEGOAL (REPEAT_DETERM1 o tac));
   339 
   340 (*Repeatedly solve the first possible subgoal using tac. *)
   341 fun REPEAT_FIRST tac = REPEAT1 (FIRSTGOAL (REPEAT1 o tac));
   342 fun REPEAT_DETERM_FIRST tac = REPEAT_DETERM1 (FIRSTGOAL (REPEAT_DETERM1 o tac));
   343 
   344 (*For n subgoals, tries to apply tac to n,...1  *)
   345 fun TRYALL tac = ALLGOALS (TRY o tac);
   346 
   347 
   348 (*Make a tactic for subgoal i, if there is one.  *)
   349 fun SUBGOAL goalfun i st = goalfun (List.nth(prems_of st, i-1),  i) st
   350                              handle Subscript => Seq.empty;
   351 
   352 (*Returns all states that have changed in subgoal i, counted from the LAST
   353   subgoal.  For stac, for example.*)
   354 fun CHANGED_GOAL tac i st = 
   355     let val np = nprems_of st
   356         val d = np-i                 (*distance from END*)
   357         val t = List.nth(prems_of st, i-1)
   358         fun diff st' = 
   359 	    nprems_of st' - d <= 0   (*the subgoal no longer exists*)
   360 	    orelse 
   361              not (Pattern.aeconv (t,
   362 				  List.nth(prems_of st', 
   363 					   nprems_of st' - d - 1)))
   364     in  Seq.filter diff (tac i st)  end
   365     handle Subscript => Seq.empty  (*no subgoal i*);
   366 
   367 fun (tac1 THEN_ALL_NEW tac2) i st =
   368   st |> (tac1 i THEN (fn st' => Seq.INTERVAL tac2 i (i + nprems_of st' - nprems_of st) st'));
   369 
   370 (*repeatedly dig into any emerging subgoals*)
   371 fun REPEAT_ALL_NEW tac =
   372   tac THEN_ALL_NEW (TRY o (fn i => REPEAT_ALL_NEW tac i));
   373 
   374 
   375 (*** SELECT_GOAL ***)
   376 
   377 (*Tactical for restricting the effect of a tactic to subgoal i.
   378   Works by making a new state from subgoal i, applying tac to it, and
   379   composing the resulting metathm with the original state.*)
   380 
   381 (*Does the work of SELECT_GOAL. *)
   382 fun select tac st i =
   383   let
   384     val thm = Drule.mk_triv_goal (adjust_maxidx (List.nth (cprems_of st, i-1)));
   385     fun restore th = Seq.hd (bicompose false (false, th, nprems_of th) 1
   386       (Thm.incr_indexes (#maxidx (rep_thm th) + 1) Drule.rev_triv_goal));
   387     fun next st' = bicompose false (false, restore st', nprems_of st') i st;
   388   in  Seq.flat (Seq.map next (tac thm))
   389   end;
   390 
   391 fun SELECT_GOAL tac i st = 
   392   let val np = nprems_of st
   393   in  if 1<=i andalso i<=np then 
   394           (*If only one subgoal, then just apply tactic*)
   395 	  if np=1 then tac st else select tac st i
   396       else Seq.empty
   397   end;
   398 
   399 
   400 (*Strips assumptions in goal yielding  ( [x1,...,xm], [H1,...,Hn], B )
   401     H1,...,Hn are the hypotheses;  x1...xm are variants of the parameters. 
   402   Main difference from strip_assums concerns parameters: 
   403     it replaces the bound variables by free variables.  *)
   404 fun strip_context_aux (params, Hs, Const("==>", _) $ H $ B) = 
   405         strip_context_aux (params, H::Hs, B)
   406   | strip_context_aux (params, Hs, Const("all",_)$Abs(a,T,t)) =
   407         let val (b,u) = variant_abs(a,T,t)
   408         in  strip_context_aux ((b,T)::params, Hs, u)  end
   409   | strip_context_aux (params, Hs, B) = (rev params, rev Hs, B);
   410 
   411 fun strip_context A = strip_context_aux ([],[],A);
   412 
   413 
   414 (**** METAHYPS -- tactical for using hypotheses as meta-level assumptions
   415        METAHYPS (fn prems => tac prems) i
   416 
   417 converts subgoal i, of the form !!x1...xm. [| A1;...;An] ==> A into a new
   418 proof state A==>A, supplying A1,...,An as meta-level assumptions (in
   419 "prems").  The parameters x1,...,xm become free variables.  If the
   420 resulting proof state is [| B1;...;Bk] ==> C (possibly assuming A1,...,An)
   421 then it is lifted back into the original context, yielding k subgoals.
   422 
   423 Replaces unknowns in the context by Frees having the prefix METAHYP_
   424 New unknowns in [| B1;...;Bk] ==> C are lifted over x1,...,xm.
   425 DOES NOT HANDLE TYPE UNKNOWNS.
   426 ****)
   427 
   428 local 
   429 
   430   (*Left-to-right replacements: ctpairs = [...,(vi,ti),...].
   431     Instantiates distinct free variables by terms of same type.*)
   432   fun free_instantiate ctpairs = 
   433       forall_elim_list (map snd ctpairs) o forall_intr_list (map fst ctpairs);
   434 
   435   fun free_of s ((a,i), T) =
   436         Free(s ^ (case i of 0 => a | _ => a ^ "_" ^ string_of_int i),
   437              T)
   438 
   439   fun mk_inst (var as Var(v,T))  = (var,  free_of "METAHYP1_" (v,T))
   440 in
   441 
   442 fun metahyps_aux_tac tacf (prem,i) state = 
   443   let val {sign,maxidx,...} = rep_thm state
   444       val cterm = cterm_of sign
   445       (*find all vars in the hyps -- should find tvars also!*)
   446       val hyps_vars = foldr add_term_vars (Logic.strip_assums_hyp prem, [])
   447       val insts = map mk_inst hyps_vars
   448       (*replace the hyps_vars by Frees*)
   449       val prem' = subst_atomic insts prem
   450       val (params,hyps,concl) = strip_context prem'
   451       val fparams = map Free params
   452       val cparams = map cterm fparams
   453       and chyps = map cterm hyps
   454       val hypths = map assume chyps
   455       fun swap_ctpair (t,u) = (cterm u, cterm t)
   456       (*Subgoal variables: make Free; lift type over params*)
   457       fun mk_subgoal_inst concl_vars (var as Var(v,T)) = 
   458           if var mem concl_vars 
   459           then (var, true, free_of "METAHYP2_" (v,T))
   460           else (var, false,
   461                 free_of "METAHYP2_" (v, map #2 params --->T))
   462       (*Instantiate subgoal vars by Free applied to params*)
   463       fun mk_ctpair (t,in_concl,u) = 
   464           if in_concl then (cterm t,  cterm u)
   465           else (cterm t,  cterm (list_comb (u,fparams)))
   466       (*Restore Vars with higher type and index*)
   467       fun mk_subgoal_swap_ctpair 
   468                 (t as Var((a,i),_), in_concl, u as Free(_,U)) = 
   469           if in_concl then (cterm u, cterm t)
   470           else (cterm u, cterm(Var((a, i+maxidx), U)))
   471       (*Embed B in the original context of params and hyps*)
   472       fun embed B = list_all_free (params, Logic.list_implies (hyps, B))
   473       (*Strip the context using elimination rules*)
   474       fun elim Bhyp = implies_elim_list (forall_elim_list cparams Bhyp) hypths
   475       (*Embed an ff pair in the original params*)
   476       fun embed_ff(t,u) = Logic.mk_flexpair (list_abs_free (params, t), 
   477                                              list_abs_free (params, u))
   478       (*Remove parameter abstractions from the ff pairs*)
   479       fun elim_ff ff = flexpair_abs_elim_list cparams ff
   480       (*A form of lifting that discharges assumptions.*)
   481       fun relift st = 
   482         let val prop = #prop(rep_thm st)
   483             val subgoal_vars = (*Vars introduced in the subgoals*)
   484                   foldr add_term_vars (Logic.strip_imp_prems prop, [])
   485             and concl_vars = add_term_vars (Logic.strip_imp_concl prop, [])
   486             val subgoal_insts = map (mk_subgoal_inst concl_vars) subgoal_vars
   487             val st' = instantiate ([], map mk_ctpair subgoal_insts) st
   488             val emBs = map (cterm o embed) (prems_of st')
   489             and ffs = map (cterm o embed_ff) (tpairs_of st')
   490             val Cth  = implies_elim_list st' 
   491                             (map (elim_ff o assume) ffs @
   492                              map (elim o assume) emBs)
   493         in  (*restore the unknowns to the hypotheses*)
   494             free_instantiate (map swap_ctpair insts @
   495                               map mk_subgoal_swap_ctpair subgoal_insts)
   496                 (*discharge assumptions from state in same order*)
   497                 (implies_intr_list (ffs@emBs)
   498                   (forall_intr_list cparams (implies_intr_list chyps Cth)))
   499         end
   500       val subprems = map (forall_elim_vars 0) hypths
   501       and st0 = trivial (cterm concl)
   502       (*function to replace the current subgoal*)
   503       fun next st = bicompose false (false, relift st, nprems_of st)
   504                     i state
   505   in  Seq.flat (Seq.map next (tacf subprems st0))
   506   end;
   507 end;
   508 
   509 fun METAHYPS tacf = SUBGOAL (metahyps_aux_tac tacf);
   510 
   511 end;
   512 
   513 open Tactical;