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