src/Pure/tctical.ML
changeset 17344 8b2f56aff711
parent 16510 606d919ad3c3
child 17969 7262f4a45190
equal deleted inserted replaced
17343:098db1bc1e59 17344:8b2f56aff711
    84 
    84 
    85 
    85 
    86 (*** LCF-style tacticals ***)
    86 (*** LCF-style tacticals ***)
    87 
    87 
    88 (*the tactical THEN performs one tactic followed by another*)
    88 (*the tactical THEN performs one tactic followed by another*)
    89 fun (tac1 THEN tac2) st = Seq.flat (Seq.map tac2 (tac1 st));
    89 fun (tac1 THEN tac2) st = Seq.maps tac2 (tac1 st);
    90 
    90 
    91 
    91 
    92 (*The tactical ORELSE uses the first tactic that returns a nonempty sequence.
    92 (*The tactical ORELSE uses the first tactic that returns a nonempty sequence.
    93   Like in LCF, ORELSE commits to either tac1 or tac2 immediately.
    93   Like in LCF, ORELSE commits to either tac1 or tac2 immediately.
    94   Does not backtrack to tac2 if tac1 was initially chosen. *)
    94   Does not backtrack to tac2 if tac1 was initially chosen. *)
   114         tac1 ORELSE tac2 = tac1 THEN_ELSE (all_tac, tac2)
   114         tac1 ORELSE tac2 = tac1 THEN_ELSE (all_tac, tac2)
   115         tac1 THEN tac2   = tac1 THEN_ELSE (tac2, no_tac)
   115         tac1 THEN tac2   = tac1 THEN_ELSE (tac2, no_tac)
   116 *)
   116 *)
   117 fun (tac THEN_ELSE (tac1, tac2)) st =
   117 fun (tac THEN_ELSE (tac1, tac2)) st =
   118     case Seq.pull(tac st) of
   118     case Seq.pull(tac st) of
   119         NONE    => tac2 st              (*failed; try tactic 2*)
   119         NONE    => tac2 st                                   (*failed; try tactic 2*)
   120       | seqcell => Seq.flat       (*succeeded; use tactic 1*)
   120       | seqcell => Seq.maps tac1 (Seq.make(fn()=> seqcell)); (*succeeded; use tactic 1*)
   121                     (Seq.map tac1 (Seq.make(fn()=> seqcell)));
       
   122 
   121 
   123 
   122 
   124 (*Versions for combining tactic-valued functions, as in
   123 (*Versions for combining tactic-valued functions, as in
   125      SOMEGOAL (resolve_tac rls THEN' assume_tac) *)
   124      SOMEGOAL (resolve_tac rls THEN' assume_tac) *)
   126 fun (tac1 THEN' tac2) x = tac1 x THEN tac2 x;
   125 fun (tac1 THEN' tac2) x = tac1 x THEN tac2 x;
   381   let
   380   let
   382     val thm = Drule.mk_triv_goal (adjust_maxidx (List.nth (cprems_of st, i-1)));
   381     val thm = Drule.mk_triv_goal (adjust_maxidx (List.nth (cprems_of st, i-1)));
   383     fun restore th = Seq.hd (bicompose false (false, th, nprems_of th) 1
   382     fun restore th = Seq.hd (bicompose false (false, th, nprems_of th) 1
   384       (Thm.incr_indexes (#maxidx (rep_thm th) + 1) Drule.rev_triv_goal));
   383       (Thm.incr_indexes (#maxidx (rep_thm th) + 1) Drule.rev_triv_goal));
   385     fun next st' = bicompose false (false, restore st', nprems_of st') i st;
   384     fun next st' = bicompose false (false, restore st', nprems_of st') i st;
   386   in  Seq.flat (Seq.map next (tac thm))
   385   in Seq.maps next (tac thm) end;
   387   end;
       
   388 
   386 
   389 fun SELECT_GOAL tac i st =
   387 fun SELECT_GOAL tac i st =
   390   let val np = nprems_of st
   388   let val np = nprems_of st
   391   in  if 1<=i andalso i<=np then
   389   in  if 1<=i andalso i<=np then
   392           (*If only one subgoal, then just apply tactic*)
   390           (*If only one subgoal, then just apply tactic*)
   490       val subprems = map (forall_elim_vars 0) hypths
   488       val subprems = map (forall_elim_vars 0) hypths
   491       and st0 = trivial (cterm concl)
   489       and st0 = trivial (cterm concl)
   492       (*function to replace the current subgoal*)
   490       (*function to replace the current subgoal*)
   493       fun next st = bicompose false (false, relift st, nprems_of st)
   491       fun next st = bicompose false (false, relift st, nprems_of st)
   494                     i state
   492                     i state
   495   in  Seq.flat (Seq.map next (tacf subprems st0))
   493   in Seq.maps next (tacf subprems st0) end;
   496   end;
       
   497 end;
   494 end;
   498 
   495 
   499 fun METAHYPS tacf = SUBGOAL (metahyps_aux_tac tacf);
   496 fun METAHYPS tacf = SUBGOAL (metahyps_aux_tac tacf);
   500 
   497 
   501 (*Makes a tactic whose effect on a state is given by thmfun: thm->thm seq.*)
   498 (*Makes a tactic whose effect on a state is given by thmfun: thm->thm seq.*)