src/Pure/tactic.ML
changeset 2688 889a1cbd1aca
parent 2672 85d7e800d754
child 2814 a318f7f3a65c
equal deleted inserted replaced
2687:b7c86d3c9d0a 2688:889a1cbd1aca
   104     fun string_of (a,0) = a
   104     fun string_of (a,0) = a
   105       | string_of (a,i) = a ^ "_" ^ string_of_int i;
   105       | string_of (a,i) = a ^ "_" ^ string_of_int i;
   106 in
   106 in
   107   fun freeze_thaw th =
   107   fun freeze_thaw th =
   108     let val fth = freezeT th
   108     let val fth = freezeT th
       
   109 	val vary = variant (add_term_names (#prop(rep_thm fth), []))
   109 	val {prop,sign,...} = rep_thm fth
   110 	val {prop,sign,...} = rep_thm fth
   110 	fun mk_inst (Var(v,T)) = 
   111 	fun mk_inst (Var(v,T)) = 
   111 	    (cterm_of sign (Var(v,T)),
   112 	    (cterm_of sign (Var(v,T)),
   112 	     cterm_of sign (Free(string_of v, T)))
   113 	     cterm_of sign (Free(vary (string_of v), T)))
   113 	val insts = map mk_inst (term_vars prop)
   114 	val insts = map mk_inst (term_vars prop)
   114 	fun thaw th' = 
   115 	fun thaw th' = 
   115 	    th' |> forall_intr_list (map #2 insts)
   116 	    th' |> forall_intr_list (map #2 insts)
   116 		|> forall_elim_list (map #1 insts)
   117 		|> forall_elim_list (map #1 insts)
   117     in  (instantiate ([],insts) fth, thaw)  end;
   118     in  (instantiate ([],insts) fth, thaw)  end;
   133     handle _ => Sequence.null;
   134     handle _ => Sequence.null;
   134 
   135 
   135 
   136 
   136 (*Makes a rule by applying a tactic to an existing rule*)
   137 (*Makes a rule by applying a tactic to an existing rule*)
   137 fun rule_by_tactic tac rl =
   138 fun rule_by_tactic tac rl =
   138     case rl |> standard |> freeze_thaw |> #1 |> tac |> Sequence.pull of
   139   let val (st, thaw) = freeze_thaw (zero_var_indexes rl)
       
   140   in case Sequence.pull (tac st)  of
   139 	None        => raise THM("rule_by_tactic", 0, [rl])
   141 	None        => raise THM("rule_by_tactic", 0, [rl])
   140       | Some(rl',_) => standard rl';
   142       | Some(st',_) => Thm.varifyT (thaw st')
       
   143   end;
   141  
   144  
   142 (*** Basic tactics ***)
   145 (*** Basic tactics ***)
   143 
   146 
   144 (*Makes a tactic whose effect on a state is given by thmfun: thm->thm seq.*)
   147 (*Makes a tactic whose effect on a state is given by thmfun: thm->thm seq.*)
   145 fun PRIMSEQ thmfun st =  thmfun st handle THM _ => Sequence.null;
   148 fun PRIMSEQ thmfun st =  thmfun st handle THM _ => Sequence.null;