src/Tools/isac/MathEngBasic/tactic.sml
author Walther Neuper <walther.neuper@jku.at>
Sat, 02 May 2020 10:57:04 +0200
changeset 59925 caf3839e53c5
parent 59924 eb40bce6d6f1
child 59926 3b056e367183
permissions -rw-r--r--
remove unused tactics, part 1
     1 (* Title:  Tactics; tac_ for interaction with frontend, input for internal use.
     2    Author: Walther Neuper 170121
     3    (c) due to copyright terms
     4 
     5 regular expression for search:
     6 
     7 Add_Find|Add_Given|Add_Relation|Apply_Assumption|Apply_Method|Begin_Sequ|Begin_Trans|Split_And|Split_Or|Split_Intersect|Conclude_And|Conclude_Or|Collect_Trues|End_Sequ|End_Trans|End_Ruleset|End_Subproblem|End_Intersect|End_Proof|CAScmd|Calculate|Check_Postcond|Check_elementwise|Del_Find|Del_Given|Del_Relation|Derive|Detail_Set|Detail_Set_Inst|End_Detail|Empty_Tac|Free_Solve|Init_Proof|Model_Problem Or_to_List|Refine_Problem|Refine_Tacitly| Rewrite|Rewrite_Inst|Rewrite_Set|Rewrite_Set_Inst|Specify_Method|Specify_Problem|Specify_Theory|Subproblem|Substitute|Tac|Take|Take_Inst
     8 
     9 *)
    10 signature TACTIC =
    11 sig
    12   datatype T =
    13     Add_Find' of TermC.as_string * Model.itm list | Add_Given' of TermC.as_string * Model.itm list 
    14   | Add_Relation' of TermC.as_string * Model.itm list
    15   | Apply_Method' of Method.id * term option * Istate_Def.T * Proof.context
    16 (*RM*)| Del_Find' of TermC.as_string | Del_Given' of TermC.as_string | Del_Relation' of TermC.as_string
    17 (*RM*)| Init_Proof' of TermC.as_string list * Spec.T
    18   | Model_Problem' of Problem.id * Model.itm list * Model.itm list
    19   | Refine_Problem' of Problem.id * (Model.itm list * (bool * term) list)
    20   | Refine_Tacitly' of Problem.id * Problem.id * ThyC.id * Method.id * Model.itm list
    21   | Specify_Method' of Method.id * Model.ori list * Model.itm list
    22   | Specify_Problem' of Problem.id * (bool * (Model.itm list * (bool * term) list))
    23   | Specify_Theory' of ThyC.id
    24   (* ^^^^^--------------------- for specify-phase, for solve-phase ---------------------vvvvv*)
    25   | CAScmd' of term
    26   | Calculate' of ThyC.id * string * term * (term * ThmC.T)
    27   | Check_Postcond' of Problem.id * term
    28   | Check_elementwise' of term * TermC.as_string * Selem.result
    29 (*RM*)| Derive' of Rule_Set.T      
    30   | Empty_Tac_
    31   | Free_Solve'
    32 (*RM* )| Apply_Assumption of TermC.as_string list( *RM*)
    33   | Or_to_List' of term * term
    34   | Rewrite' of ThyC.id * Rewrite_Ord.rew_ord' * Rule_Set.T * bool * ThmC.T * term * Selem.result
    35   | Rewrite_Inst' of ThyC.id * Rewrite_Ord.rew_ord' * Rule_Set.T * bool * subst * ThmC.T * term * Selem.result
    36   | Rewrite_Set' of ThyC.id * bool * Rule_Set.T * term * Selem.result
    37   | Rewrite_Set_Inst' of ThyC.id * bool * subst * Rule_Set.T * term * Selem.result
    38   | Subproblem' of Spec.T * Model.ori list * term * Selem.fmz_ * Proof.context * term
    39   | Substitute' of Rule_Def.rew_ord_ * Rule_Set.T * Subst.as_eqs * term * term
    40 (*RM*)| Tac_ of theory * string * string * string
    41   | Take' of term
    42   | End_Detail' of Selem.result
    43   | Begin_Trans' of term | End_Trans' of Selem.result
    44   | End_Proof''
    45 
    46   val string_of: T -> string
    47 
    48   datatype input =
    49     Add_Find of TermC.as_string | Add_Given of TermC.as_string
    50   | Add_Relation of TermC.as_string
    51   | Apply_Method of Method.id
    52   | Del_Find of TermC.as_string | Del_Given of TermC.as_string | Del_Relation of TermC.as_string
    53   | Init_Proof of TermC.as_string list * Spec.T
    54   | Model_Problem
    55   | Refine_Problem of Problem.id
    56   | Refine_Tacitly of Problem.id
    57   | Specify_Method of Method.id
    58   | Specify_Problem of Problem.id
    59   | Specify_Theory of ThyC.id
    60   (* ^^^^^--------------------- for specify-phase, for solve-phase ---------------------vvvvv*)
    61   | CAScmd of TermC.as_string
    62   | Calculate of string
    63   | Check_Postcond of Problem.id
    64   | Check_elementwise of TermC.as_string
    65 (*RM*)| Derive of Rule_Set.id(*RM*)
    66   | Empty_Tac
    67 (*RM*)| Free_Solve
    68 (*RM*)| Apply_Assumption of TermC.as_string list
    69   | Or_to_List
    70   | Rewrite of ThmC.T
    71   | Rewrite_Inst of Subst.input * ThmC.T
    72   | Rewrite_Set of Rule_Set.id
    73   | Rewrite_Set_Inst of Subst.input * Rule_Set.id
    74   | Subproblem of ThyC.id * Problem.id
    75   | Substitute of Subst.input
    76 (*RM*)| Tac of string
    77   | Take of TermC.as_string
    78   | End_Detail
    79   | Begin_Trans | End_Trans
    80   | End_Proof';
    81 
    82   val input_to_string : input -> string
    83   val tac2IDstr : input -> string
    84   val is_empty : input -> bool
    85 
    86   val eq_tac : input * input -> bool
    87   val is_rewtac : input -> bool
    88   val is_rewset : input -> bool
    89   val rls_of : input -> Rule_Set.id
    90   val rule2tac : theory -> (term * term) list ->  Rule.rule -> input
    91   val applicable : theory -> string -> Rule_Set.T -> term -> input ->input list
    92   val for_specify: input -> bool
    93 
    94   val input_from_T : T -> input
    95   val result : T -> term
    96   val creates_assms: T -> term list
    97   val insert_assumptions: T -> Proof.context -> Proof.context
    98   val for_specify': T -> bool
    99 
   100 (* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
   101   (* NONE *)
   102 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
   103   (* NONE *)
   104 ( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
   105 
   106 (*----- unused code, kept as hints to design ideas ---------------------------------------------*)
   107   (* NONE *)
   108 end
   109 
   110 (**)
   111 structure Tactic(**): TACTIC(**) =
   112 struct
   113 (**)
   114 
   115 (** tactics for user at front-end **)
   116 
   117 datatype input =
   118     Add_Find of TermC.as_string | Add_Given of TermC.as_string | Add_Relation of TermC.as_string
   119   | Apply_Method of Method.id
   120   | Del_Find of TermC.as_string | Del_Given of TermC.as_string | Del_Relation of TermC.as_string
   121   | Init_Proof of TermC.as_string list * Spec.T
   122   | Model_Problem
   123   | Refine_Problem of Problem.id
   124   | Refine_Tacitly of Problem.id
   125   | Specify_Method of Method.id
   126   | Specify_Problem of Problem.id
   127   | Specify_Theory of ThyC.id
   128   (* ^^^^^--------------------- for specify-phase, for solve-phase ---------------------vvvvv*)
   129   | CAScmd of TermC.as_string
   130   | Calculate of string
   131   | Check_Postcond of Problem.id
   132   | Check_elementwise of TermC.as_string
   133 (*RM*)| Derive of Rule_Set.id
   134   | Empty_Tac
   135 (*RM*)| Free_Solve
   136 (*RM*)| Apply_Assumption of TermC.as_string list
   137   | Or_to_List
   138   | Rewrite of ThmC.T
   139   | Rewrite_Inst of Subst.input * ThmC.T
   140   | Rewrite_Set of Rule_Set.id
   141   | Rewrite_Set_Inst of Subst.input * Rule_Set.id
   142   | Subproblem of ThyC.id * Problem.id
   143   | Substitute of Subst.input
   144 (*RM*)| Tac of string
   145   | Take of TermC.as_string
   146   | End_Detail
   147   | Begin_Trans | End_Trans
   148   | End_Proof';
   149 
   150 fun input_to_string ma = case ma of
   151     Init_Proof (ppc, spec)  => 
   152       "Init_Proof "^(pair2str (strs2str ppc, Spec.to_string spec))
   153   | Model_Problem           => "Model_Problem "
   154   | Refine_Tacitly pblID    => "Refine_Tacitly " ^ strs2str pblID 
   155   | Refine_Problem pblID    => "Refine_Problem " ^ strs2str pblID 
   156   | Add_Given cterm'        => "Add_Given " ^ cterm'
   157   | Del_Given cterm'        => "Del_Given " ^ cterm'
   158   | Add_Find cterm'         => "Add_Find " ^ cterm'
   159   | Del_Find cterm'         => "Del_Find " ^ cterm'
   160   | Add_Relation cterm'     => "Add_Relation " ^ cterm'
   161   | Del_Relation cterm'     => "Del_Relation " ^ cterm'
   162 
   163   | Specify_Theory domID    => "Specify_Theory " ^ quote domID
   164   | Specify_Problem pblID   => "Specify_Problem " ^ strs2str pblID
   165   | Specify_Method metID    => "Specify_Method " ^ strs2str metID
   166   | Apply_Method metID      => "Apply_Method " ^ strs2str metID
   167   | Check_Postcond pblID    => "Check_Postcond " ^ strs2str pblID
   168   | Free_Solve              => "Free_Solve"
   169 
   170   | Rewrite_Inst (subs, (id, thm)) =>
   171     "Rewrite_Inst " ^ (pair2str (subs2str subs, spair2str (id, thm |> Thm.prop_of |> UnparseC.term)))
   172   | Rewrite (id, thm) => "Rewrite " ^ spair2str (id, thm |> Thm.prop_of |> UnparseC.term)
   173   | Rewrite_Set_Inst (subs, rls) => 
   174     "Rewrite_Set_Inst " ^ pair2str (subs2str subs, quote rls)
   175   | Rewrite_Set rls         => "Rewrite_Set " ^ quote rls
   176   | End_Detail              => "End_Detail"
   177   | Derive rls'             => "Derive " ^ rls' 
   178   | Calculate op_           => "Calculate " ^ op_
   179   | Substitute sube         => "Substitute " ^ Subst.string_eqs_to_string sube	     
   180   | Apply_Assumption ct's   => "Apply_Assumption " ^ strs2str ct's
   181 
   182   | Take cterm'             => "Take " ^ quote cterm'
   183   | Subproblem (domID, pblID) => "Subproblem " ^ pair2str (domID, strs2str pblID)
   184   | End_Subproblem          => "End_Subproblem"
   185   | CAScmd cterm'           => "CAScmd " ^ quote cterm'
   186 
   187   | Check_elementwise cterm'=> "Check_elementwise " ^ quote cterm'
   188   | Or_to_List              => "Or_to_List "
   189   | Collect_Trues           => "Collect_Trues"
   190 
   191   | Empty_Tac               => "Empty_Tac"
   192   | Tac string              => "Tac " ^ string
   193   | End_Proof'              => "input End_Proof'"
   194   | _                       => "input_to_string not impl. for ?!";
   195 
   196 fun tac2IDstr ma = case ma of
   197     Model_Problem => "Model_Problem"
   198   | Refine_Tacitly _ => "Refine_Tacitly"
   199   | Refine_Problem _ => "Refine_Problem"
   200   | Add_Given _ => "Add_Given"
   201   | Del_Given _ => "Del_Given"
   202   | Add_Find _ => "Add_Find"
   203   | Del_Find _ => "Del_Find"
   204   | Add_Relation _ => "Add_Relation"
   205   | Del_Relation _ => "Del_Relation"
   206 
   207   | Specify_Theory _ => "Specify_Theory"
   208   | Specify_Problem _ => "Specify_Problem"
   209   | Specify_Method _ => "Specify_Method"
   210   | Apply_Method _ => "Apply_Method"
   211   | Check_Postcond _ => "Check_Postcond"
   212   | Free_Solve => "Free_Solve"
   213 
   214   | Rewrite_Inst _ => "Rewrite_Inst"
   215   | Rewrite _ => "Rewrite"
   216   | Rewrite_Set_Inst _ => "Rewrite_Set_Inst"
   217   | Rewrite_Set _ => "Rewrite_Set"
   218   | Derive _ => "Derive "
   219   | Calculate _ => "Calculate "
   220   | Substitute _ => "Substitute" 
   221   | Apply_Assumption _ => "Apply_Assumption"
   222 
   223   | Take _ => "Take"
   224   | Subproblem _ => "Subproblem"
   225   | End_Subproblem => "End_Subproblem"
   226   | CAScmd _ => "CAScmd"
   227 
   228   | Check_elementwise _ => "Check_elementwise"
   229   | Or_to_List => "Or_to_List "
   230   | Collect_Trues => "Collect_Trues"
   231 
   232   | Empty_Tac => "Empty_Tac"
   233   | Tac _ => "Tac "
   234   | End_Proof' => "End_Proof'"
   235   | _ => "input_to_string not impl. for ?!";
   236 
   237 fun is_empty input = case input of Empty_Tac => true | _ => false
   238 
   239 fun eq_tac (Rewrite (id1, _), Rewrite (id2, _)) = id1 = id2
   240   | eq_tac (Rewrite_Inst (_, (id1, _)), Rewrite_Inst (_, (id2, _))) = id1 = id2
   241   | eq_tac (Rewrite_Set id1, Rewrite_Set id2) = id1 = id2
   242   | eq_tac (Rewrite_Set_Inst (_, id1), Rewrite_Set_Inst (_, id2)) = id1 = id2
   243   | eq_tac (Calculate id1, Calculate id2) = id1 = id2
   244   | eq_tac _ = false
   245 
   246 fun is_rewset (Rewrite_Set_Inst _) = true
   247   | is_rewset (Rewrite_Set _) = true 
   248   | is_rewset _ = false;
   249 fun is_rewtac (Rewrite _) = true
   250   | is_rewtac (Rewrite_Inst _) = true
   251   | is_rewtac input = is_rewset input;
   252 
   253 
   254 fun rls_of (Rewrite_Set_Inst (_, rls)) = rls
   255   | rls_of (Rewrite_Set rls) = rls
   256   | rls_of input = error ("rls_of: called with input \"" ^ tac2IDstr input ^ "\"");
   257 
   258 fun rule2tac thy _ (Rule.Eval (opID, _)) = Calculate (assoc_calc thy opID)
   259   | rule2tac _ [] (Rule.Thm thm'') = Rewrite thm''
   260   | rule2tac _ subst (Rule.Thm thm'') = 
   261     Rewrite_Inst (Subst.T_to_input subst, thm'')
   262   | rule2tac _ [] (Rule.Rls_ rls) = Rewrite_Set (Rule_Set.id rls)
   263   | rule2tac _ subst (Rule.Rls_ rls) = 
   264     Rewrite_Set_Inst (Subst.T_to_input subst, (Rule_Set.id rls))
   265   | rule2tac _ _ rule = 
   266     error ("rule2tac: called with \"" ^ Rule.to_string rule ^ "\"");
   267 
   268 (* try if a rewrite-rule is applicable to a given formula; 
   269    in case of rule-sets (recursivley) collect all _atomic_ rewrites *) 
   270 fun try_rew thy ((_, ro) : Rewrite_Ord.rew_ord) erls (subst : subst) f (thm' as Rule.Thm (_, thm)) =
   271     if Auto_Prog.contains_bdv thm
   272     then case Rewrite.rewrite_inst_ thy ro erls false subst thm f of
   273 	    SOME _ => [rule2tac thy subst thm']
   274 	  | NONE => []
   275     else (case Rewrite.rewrite_ thy ro erls false thm f of
   276 	    SOME _ => [rule2tac thy [] thm']
   277 	  | NONE => [])
   278   | try_rew thy _ _ _ f (cal as Rule.Eval c) = 
   279     (case Eval.adhoc_thm thy c f of
   280 	    SOME _ => [rule2tac thy [] cal]
   281     | NONE => [])
   282   | try_rew thy _ _ _ f (cal as Rule.Cal1 c) = 
   283     (case Eval.adhoc_thm thy c f of
   284 	      SOME _ => [rule2tac thy [] cal]
   285       | NONE => [])
   286   | try_rew thy _ _ subst f (Rule.Rls_ rls) = filter_appl_rews thy subst f rls
   287   | try_rew _ _ _ _ _ _ = error "try_rew: uncovered case"
   288 and filter_appl_rews thy subst f (Rule_Def.Repeat {rew_ord = ro, erls, rules, ...}) = 
   289     gen_distinct eq_tac (flat (map (try_rew thy ro erls subst f) rules))
   290   | filter_appl_rews thy subst f (Rule_Set.Sequence {rew_ord = ro, erls, rules,...}) = 
   291     gen_distinct eq_tac (flat (map (try_rew thy ro erls subst f) rules))
   292   | filter_appl_rews _ _ _ (Rule_Set.Rrls _) = []
   293   | filter_appl_rews _ _ _ _ = error "filter_appl_rews: uncovered case"
   294 
   295 (* decide if a tactic is applicable to a given formula; 
   296    in case of Rewrite_Set* go down to _atomic_ rewrite-tactics *)
   297 fun applicable thy _ _ f (Calculate scrID) =
   298     try_rew thy Rewrite_Ord.e_rew_ordX Rule_Set.empty [] f (Rule.Eval (assoc_calc' thy scrID |> snd))
   299   | applicable thy ro erls f (Rewrite thm'') =
   300     try_rew thy (ro, Rewrite_Ord.assoc_rew_ord ro) erls [] f (Rule.Thm thm'')
   301   | applicable thy ro erls f (Rewrite_Inst (subs, thm'')) =
   302     try_rew thy (ro, Rewrite_Ord.assoc_rew_ord ro) erls (Subst.T_from_input thy subs) f (Rule.Thm thm'')
   303 
   304   | applicable thy _ _ f (Rewrite_Set rls') =
   305     filter_appl_rews thy [] f (assoc_rls rls')
   306   | applicable thy _ _ f (Rewrite_Set_Inst (subs, rls')) =
   307     filter_appl_rews thy (Subst.T_from_input thy subs) f (assoc_rls rls')
   308   | applicable _ _ _ _ tac = 
   309     (tracing ("### applicable: not impl. for tac = '" ^ input_to_string tac ^ "'"); []);
   310 
   311 
   312 (** tactics for internal use **)
   313 
   314   datatype T =
   315     Add_Find' of TermC.as_string * Model.itm list | Add_Given' of TermC.as_string * Model.itm list 
   316   | Add_Relation' of TermC.as_string * Model.itm list (* for Step.do_next    *)
   317   | Apply_Method' of   (* last step in specifu-phse, switch to solve-phase   *)
   318       Method.id *      (* id in the Know_Store                               *)
   319       term option *    (* first formula in the (sub-)Problem TODO: rm option *)           
   320       Istate_Def.T *   (* for starting the Program                           *)
   321       Proof.context    (* for starting the Program                           *)
   322 (*RM*)| Del_Find' of TermC.as_string | Del_Given' of TermC.as_string | Del_Relation' of TermC.as_string
   323 (*RM*)| Init_Proof' of TermC.as_string list * Spec.T
   324   | Model_Problem' of  (* first step in specify-phase                        *)
   325       Problem.id *     (* id in the Know_Store                               *)
   326       Model.itm list * (* the model for the Problem                          *)
   327       Model.itm list   (* the model for the method                           *)
   328   | Refine_Problem' of Problem.id * (Model.itm list * (bool * term) list)
   329   | Refine_Tacitly' of                                                      
   330       Problem.id *       (* the original id in the Know_Store                *)
   331       Problem.id *       (* the id of the refined Problem                    *)
   332       ThyC.id *          (* the id of the refined theory                     *)
   333       Method.id *        (* the id of the refined Method                     *)
   334       Model.itm list     (* RM 9.03: remains [] for Model_Problem recognizing its activation *)
   335   | Specify_Method' of Method.id * Model.ori list * Model.itm list
   336   | Specify_Problem' of Problem.id * 
   337       (bool *                  (* all preconditions evaluate to True         *)
   338         (Model.itm list *      (* the model checked for the input id         *)
   339           (bool * term) list)) (* individual preconditions marked true/false *)
   340   | Specify_Theory' of ThyC.id
   341   (* ^^^^^--------------------- for specify-phase, for solve-phase ---------------------vvvvv*)
   342   | CAScmd' of term
   343   | Calculate' of ThyC.id * string * term * (term * ThmC.T)
   344   | Check_Postcond' of   (* last step in solving a (sub-)Problem             *)
   345       Problem.id *       (* id of the Problem to be checked                  *)
   346       term               (* return value of the program                      *)
   347   | Check_elementwise' of(* DEPRECATED, made idle for Calc.T in df00a2b5c4cc *)
   348       term *             (* the current formula: [x=1,x=...]                 *)
   349       string *           (* the pred from Check_elementwise                  *)
   350       Selem.result       (* composed from (1) and (2): {x. pred}             *)
   351 (*RM*)| Derive' of Rule_Set.T
   352   | Empty_Tac_
   353   | Free_Solve'
   354   | Or_to_List' of term * term
   355   | Rewrite' of ThyC.id * Rewrite_Ord.rew_ord' * Rule_Set.T * bool * ThmC.T * term * Selem.result
   356   | Rewrite_Inst' of ThyC.id * Rewrite_Ord.rew_ord' * Rule_Set.T * bool * subst * ThmC.T * term * Selem.result
   357   | Rewrite_Set' of ThyC.id * bool * Rule_Set.T * term * Selem.result
   358   | Rewrite_Set_Inst' of ThyC.id * bool * subst * Rule_Set.T * term * Selem.result
   359   | Subproblem' of       (* switch from solve-phase to specify-phase         *)
   360       Spec.T *           (* specification of the SubProblem                  *)
   361   		(Model.ori list) * (* original model, filled in associate Subproblem'  *)
   362   		term *             (* headline of calc-head, filled -"-                *)
   363   		Selem.fmz_ *       (* string list from arguments of the calling Program*)
   364       Proof.context *    (* for the specify-phase                            *)
   365   		term               (* Subproblem (thyID, pbl) OR CAS_Cmd               *)  
   366   | Substitute' of       (* substitute variables (TODO: from the context)    *)    
   367       Rule_Def.rew_ord_ *(* for re-calculation                               *)
   368       Rule_Set.T *       (* for re-calculation                               *)
   369       Subst.as_eqs *     (* the substitution: terms of type bool             *)
   370       term *             (* to be substituted into                           *)
   371       term               (* resulting from the substitution                  *)
   372 (*RM*)| Tac_ of theory * string * string * string
   373   | Take' of term
   374   | End_Detail' of Selem.result
   375   | Begin_Trans' of term | End_Trans' of Selem.result
   376   | End_Proof''
   377 
   378 fun string_of ma = case ma of
   379     Init_Proof' (ppc, spec)  => "Init_Proof' " ^ pair2str (strs2str ppc, Spec.to_string spec)
   380   | Model_Problem' (pblID, _, _) => "Model_Problem' " ^ strs2str pblID
   381   | Refine_Tacitly'(p, prefin, domID, metID, _) => "Refine_Tacitly' (" ^ strs2str p ^ ", " ^
   382     strs2str prefin ^ ", " ^ domID ^ ", " ^ strs2str metID ^ ", pbl-itms)"
   383   | Refine_Problem' _ => "Refine_Problem' (" ^ (*matchs2str ms*)"..." ^ ")"
   384   | Add_Given' _ => "Add_Given' "(*^cterm'*)
   385   | Del_Given' _ => "Del_Given' "(*^cterm'*)
   386   | Add_Find' _ => "Add_Find' "(*^cterm'*)
   387   | Del_Find' _ => "Del_Find' "(*^cterm'*)
   388   | Add_Relation' _ => "Add_Relation' "(*^cterm'*)
   389   | Del_Relation' _ => "Del_Relation' "(*^cterm'*)
   390 
   391   | Specify_Theory' domID => "Specify_Theory' " ^ quote domID
   392   | Specify_Problem' (pI, (ok, _)) =>  "Specify_Problem' " ^ 
   393     spair2str (strs2str pI, spair2str (bool2str ok, spair2str ("itms2str_ itms", "items2str pre")))
   394   | Specify_Method' (pI, oris, _) => "Specify_Method' (" ^ 
   395     Method.id_to_string pI ^ ", " ^ Model.oris2str oris ^ ", )"
   396 
   397   | Apply_Method' (metID, _, _, _) => "Apply_Method' " ^ strs2str metID
   398   | Check_Postcond' (pblID, scval) => "Check_Postcond' " ^
   399       (spair2str (strs2str pblID, UnparseC.term scval))
   400 
   401   | Free_Solve' => "Free_Solve'"
   402 
   403   | Rewrite_Inst' (*subs,thm'*) _ => "Rewrite_Inst' "(*^(pair2str (subs2str subs, spair2str thm'))*)
   404   | Rewrite' _(*thm'*) => "Rewrite' "(*^(spair2str thm')*)
   405   | Rewrite_Set_Inst' _(*subs,thm'*) => "Rewrite_Set_Inst' "(*^(pair2str (subs2str subs, quote rls))*)
   406   | Rewrite_Set' (thy', pasm, rls', f, (f', asm)) => "Rewrite_Set' (" ^ thy' ^ "," ^ bool2str pasm ^
   407     "," ^ Rule_Set.id rls' ^ "," ^ UnparseC.term f ^ ",(" ^ UnparseC.term f' ^ "," ^ UnparseC.terms asm ^ "))"
   408   | End_Detail' _ => "End_Detail' xxx"
   409 
   410   | Derive' rls => "Derive' " ^ Rule_Set.id rls
   411   | Calculate'  _ => "Calculate' "
   412   | Substitute' _ => "Substitute' "(*^(subs2str subs)*)    
   413 
   414   | Take' _(*cterm'*) => "Take' "(*^(quote cterm'	)*)
   415   | Subproblem' _(*(spec, oris, _, _, _, pbl_form)*) => 
   416     "Subproblem' "(*^(pair2str (domID, strs2str ,))*)
   417   | CAScmd' _(*cterm'*) => "CAScmd' "(*^(quote cterm')*)
   418 
   419   | Empty_Tac_ => "Empty_Tac_"
   420   | Tac_ (_, form, id, result) => "Tac_ (thy," ^ form ^ "," ^ id ^ "," ^ result ^ ")"
   421 
   422   | Begin_Trans' _ => "Begin_Trans' xxx"
   423   | End_Trans' _ => "End_Trans' xxx"
   424   | End_Proof'' => "End_Trans' xxx"
   425   | _  => "string_of not impl. for arg";
   426 
   427 fun input_from_T (Refine_Tacitly' (pI, _, _, _, _)) = Refine_Tacitly pI
   428   | input_from_T (Model_Problem' (_, _, _)) = Model_Problem
   429   | input_from_T (Add_Given' (t, _)) = Add_Given t
   430   | input_from_T (Add_Find' (t, _)) = Add_Find t
   431   | input_from_T (Add_Relation' (t, _)) = Add_Relation t
   432  
   433   | input_from_T (Specify_Theory' dI) = Specify_Theory dI
   434   | input_from_T (Specify_Problem' (dI, _)) = Specify_Problem dI
   435   | input_from_T (Specify_Method' (dI, _, _)) = Specify_Method dI
   436   
   437   | input_from_T (Rewrite' (_, _, _, _, thm, _, _)) = Rewrite thm
   438   | input_from_T (Rewrite_Inst' (_, _, _, _, sub, thm, _, _)) = Rewrite_Inst (Subst.T_to_input sub, thm)
   439 
   440   | input_from_T (Rewrite_Set' (_, _, rls, _, _)) = Rewrite_Set (Rule_Set.id rls)
   441   | input_from_T (Rewrite_Set_Inst' (_, _, sub, rls, _, _)) = 
   442     Rewrite_Set_Inst (Subst.T_to_input sub, Rule_Set.id rls)
   443 
   444   | input_from_T (Calculate' (_, op_, _, _)) = Calculate (op_)
   445   | input_from_T (Check_elementwise' (_, pred, _)) = Check_elementwise pred
   446 
   447   | input_from_T (Or_to_List' _) = Or_to_List
   448   | input_from_T (Take' term) = Take (UnparseC.term term)
   449   | input_from_T (Substitute' (_, _, subte, _, _)) = Substitute (Subst.eqs_to_input subte) 
   450   | input_from_T (Tac_ (_, _, id, _)) = Tac id
   451 
   452   | input_from_T (Subproblem' ((domID, pblID, _), _, _, _,_ ,_)) = Subproblem (domID, pblID)
   453   | input_from_T (Check_Postcond' (pblID, _)) = Check_Postcond pblID
   454   | input_from_T Empty_Tac_ = Empty_Tac
   455   | input_from_T m = raise ERROR (": not impl. for "^(string_of m));
   456 
   457 fun res (Rewrite_Inst' (_ , _, _, _, _, _, _, res)) = res
   458   | res (Rewrite' (_, _, _, _, _, _, res)) = res
   459   | res (Rewrite_Set_Inst' (_, _, _, _, _, res)) = res
   460   | res (Rewrite_Set' (_, _, _, _, res)) = res
   461   | res (Calculate' (_, _, _, (t, _))) = (t, [])
   462   | res (Check_elementwise' (_, _, res)) = res
   463   | res (Subproblem' (_, _, _, _, _, t)) = (t, [])
   464   | res (Take' t) = (t, [])
   465   | res (Substitute' (_, _, _, _, t)) = (t, [])
   466   | res (Or_to_List' (_,  t)) = (t, [])
   467   | res m = raise ERROR ("result: not impl.for " ^ string_of m)
   468 
   469 (*fun result m = (fst o res) m; TODO*)
   470 fun result tac = (fst o res) tac;
   471 fun creates_assms tac = (snd o res) tac;
   472 
   473 fun insert_assumptions tac ctxt  = ContextC.insert_assumptions (creates_assms tac) ctxt
   474 
   475 fun for_specify (Init_Proof _) = true
   476   | for_specify Model_Problem  = true
   477   | for_specify (Refine_Tacitly _) = true
   478   | for_specify (Refine_Problem _) = true
   479   | for_specify (Add_Given _) = true
   480   | for_specify (Del_Given _) = true
   481   | for_specify (Add_Find _) = true
   482   | for_specify (Del_Find _) = true
   483   | for_specify (Add_Relation _) = true
   484   | for_specify (Del_Relation _) = true
   485   | for_specify (Specify_Theory _) = true
   486   | for_specify (Specify_Problem _) = true
   487   | for_specify (Specify_Method _) = true
   488   | for_specify _ = false
   489 fun for_specify' (Init_Proof' _) = true
   490   | for_specify' (Model_Problem' _) = true
   491   | for_specify' (Refine_Tacitly' _) = true
   492   | for_specify' (Refine_Problem' _) = true
   493   | for_specify' (Add_Given' _) = true
   494   | for_specify' (Del_Given' _) = true
   495   | for_specify' (Add_Find' _) = true
   496   | for_specify' (Del_Find' _) = true
   497   | for_specify' (Add_Relation' _) = true
   498   | for_specify' (Del_Relation' _) = true
   499   | for_specify' (Specify_Theory' _) = true
   500   | for_specify' (Specify_Problem' _) = true
   501   | for_specify' (Specify_Method' _) = true
   502   | for_specify' _ = false
   503 
   504 (**)end(**)