src/Tools/isac/MathEngBasic/tactic.sml
author Walther Neuper <walther.neuper@jku.at>
Fri, 17 Jan 2020 13:14:11 +0100
changeset 59773 d88bb023c380
parent 59749 cc3b1807f72e
child 59778 148d369e6b71
permissions -rw-r--r--
lucin: introduce Calc.T and Program.T
     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_Asm|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 Rule.cterm' * Model.itm list | Add_Given' of Rule.cterm' * Model.itm list 
    14   | Add_Relation' of Rule.cterm' * Model.itm list
    15   | Apply_Assumption' of term list * term
    16   | Apply_Method' of Celem.metID * term option * Istate_Def.T * Proof.context
    17 
    18   | Begin_Sequ' | Begin_Trans' of term
    19   | Split_And' of term | Split_Or' of term | Split_Intersect' of term
    20   | Conclude_And' of term | Conclude_Or' of term | Collect_Trues' of term
    21   | End_Sequ' | End_Trans' of Selem.result
    22   | End_Ruleset' of term | End_Subproblem' of term | End_Intersect' of term | End_Proof''
    23 
    24   | CAScmd' of term
    25   | Calculate' of Rule.theory' * string * term * (term * Celem.thm')
    26   | Check_Postcond' of Celem.pblID * Selem.result
    27   | Check_elementwise' of term * Rule.cterm' * Selem.result
    28   | Del_Find' of Rule.cterm' | Del_Given' of Rule.cterm' | Del_Relation' of Rule.cterm'
    29 
    30   | Derive' of Rule.rls
    31   | Detail_Set' of Rule.theory' * bool * Rule.rls * term * Selem.result
    32   | Detail_Set_Inst' of Rule.theory' * bool * Rule.subst * Rule.rls * term * Selem.result
    33   | End_Detail' of Selem.result
    34 
    35   | Empty_Tac_
    36   | Free_Solve'
    37 
    38   | Init_Proof' of Rule.cterm' list * Celem.spec
    39   | Model_Problem' of Celem.pblID * Model.itm list * Model.itm list
    40   | Or_to_List' of term * term
    41   | Refine_Problem' of Celem.pblID * (Model.itm list * (bool * term) list)
    42   | Refine_Tacitly' of Celem.pblID * Celem.pblID * Rule.domID * Celem.metID * Model.itm list
    43 
    44   | Rewrite' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Celem.thm'' * term * Selem.result
    45   | Rewrite_Asm' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Celem.thm'' * term * Selem.result
    46   | Rewrite_Inst' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Rule.subst * Celem.thm'' * term * Selem.result
    47   | Rewrite_Set' of Rule.theory' * bool * Rule.rls * term * Selem.result
    48   | Rewrite_Set_Inst' of Rule.theory' * bool * Rule.subst * Rule.rls * term * Selem.result
    49 
    50   | Specify_Method' of Celem.metID * Model.ori list * Model.itm list
    51   | Specify_Problem' of Celem.pblID * (bool * (Model.itm list * (bool * term) list))
    52   | Specify_Theory' of Rule.domID
    53   | Subproblem' of Celem.spec * Model.ori list * term * Selem.fmz_ * Proof.context * term
    54   | Substitute' of Rule.rew_ord_ * Rule.rls * Selem.subte * term * term
    55   | Tac_ of theory * string * string * string
    56   | Take' of term | Take_Inst' of term
    57   val string_of : T -> string
    58 
    59   datatype input =
    60     Add_Find of Rule.cterm' | Add_Given of Rule.cterm' | Add_Relation of Rule.cterm'
    61   | Apply_Assumption of Rule.cterm' list
    62   | Apply_Method of Celem.metID
    63   (*/--- TODO: re-design ? -----------------------------------------------------------------\*)
    64   | Begin_Sequ | Begin_Trans
    65   | Split_And | Split_Or | Split_Intersect
    66   | Conclude_And | Conclude_Or | Collect_Trues
    67   | End_Sequ | End_Trans
    68   | End_Ruleset | End_Subproblem | End_Intersect | End_Proof'
    69   (*\--- TODO: re-design ? -----------------------------------------------------------------/*)
    70   | CAScmd of Rule.cterm'
    71   | Calculate of string
    72   | Check_Postcond of Celem.pblID
    73   | Check_elementwise of Rule.cterm'
    74   | Del_Find of Rule.cterm' | Del_Given of Rule.cterm' | Del_Relation of Rule.cterm'
    75 
    76   | Derive of Rule.rls'
    77   | Detail_Set of Rule.rls'
    78   | Detail_Set_Inst of Selem.subs * Rule.rls'
    79   | End_Detail
    80 
    81   | Empty_Tac
    82   | Free_Solve
    83 
    84   | Init_Proof of Rule.cterm' list * Celem.spec
    85   | Model_Problem
    86   | Or_to_List
    87   | Refine_Problem of Celem.pblID
    88   | Refine_Tacitly of Celem.pblID
    89 
    90   | Rewrite of Celem.thm''
    91   | Rewrite_Asm of Celem.thm''
    92   | Rewrite_Inst of Selem.subs * Celem.thm''
    93   | Rewrite_Set of Rule.rls'
    94   | Rewrite_Set_Inst of Selem.subs * Rule.rls'
    95 
    96   | Specify_Method of Celem.metID
    97   | Specify_Problem of Celem.pblID
    98   | Specify_Theory of Rule.domID
    99   | Subproblem of Rule.domID * Celem.pblID
   100 
   101   | Substitute of Selem.sube
   102   | Tac of string
   103   | Take of Rule.cterm' | Take_Inst of Rule.cterm'
   104   val tac2str : input -> string
   105 
   106   val eq_tac : input * input -> bool
   107   val is_empty_tac : input -> bool
   108   val is_rewtac : input -> bool
   109   val is_rewset : input -> bool
   110   val rls_of : input -> Rule.rls'
   111   val tac2IDstr : input -> string
   112   val rule2tac : theory -> (term * term) list ->  Rule.rule -> input
   113   val input_from_T : T -> input
   114   val result : T -> term
   115   val creates_assms: T -> term list
   116   val insert_assumptions: T -> Proof.context -> Proof.context
   117   val for_specify: input -> bool
   118   val for_specify': T -> bool
   119 
   120 (* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
   121   (* NONE *)
   122 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
   123   (* NONE *)
   124 ( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
   125 
   126 (*----- unused code, kept as hints to design ideas ---------------------------------------------*)
   127   (* NONE *)
   128 end
   129 
   130 (**)
   131 structure Tactic(**): TACTIC(**) =
   132 struct
   133 (**)
   134 
   135 (* tactics for user at front-end.
   136    input propagates the construction of the calc-tree;
   137    there are
   138    (a) 'specsteps' for the specify-phase, and others for the solve-phase
   139    (b) those of the solve-phase are 'initac's and others;
   140        initacs start with a formula different from the preceding formula.
   141    see 'type tac_' for the internal representation of tactics
   142 *)
   143 datatype input =
   144     Add_Find of Rule.cterm' | Add_Given of Rule.cterm' | Add_Relation of Rule.cterm'
   145   | Apply_Assumption of Rule.cterm' list
   146   | Apply_Method of Celem.metID
   147     (* creates an "istate" in PblObj.env; in case of "init_form" 
   148       creates a formula at ((lev_on o lev_dn) p, Frm) and in this "ppobj.loc"
   149       a "SOME istate" at fst of "loc".
   150       As each step (in the solve-phase) has a resulting formula (at the front-end)
   151       Apply_Method also does the 1st step in the script (an "initac") if there is no "init_form" *)  
   152   (*/--- TODO: re-design ? -----------------------------------------------------------------\*)
   153   | Begin_Sequ | Begin_Trans
   154   | Split_And | Split_Or | Split_Intersect
   155   | Conclude_And | Conclude_Or | Collect_Trues
   156   | End_Sequ | End_Trans
   157   | End_Ruleset | End_Subproblem (* WN0509 drop *) | End_Intersect | End_Proof'
   158   (*\--- TODO: re-design ? -----------------------------------------------------------------/*)
   159   | CAScmd of Rule.cterm'
   160   | Calculate of string
   161   | Check_Postcond of Celem.pblID
   162   | Check_elementwise of Rule.cterm'
   163   | Del_Find of Rule.cterm' | Del_Given of Rule.cterm' | Del_Relation of Rule.cterm'
   164 
   165   | Derive of Rule.rls'                 (* WN0509 drop *)
   166   | Detail_Set of Rule.rls'             (* WN0509 drop *)
   167   | Detail_Set_Inst of Selem.subs * Rule.rls' (* WN0509 drop *)
   168   | End_Detail                     (* WN0509 drop *)
   169 
   170   | Empty_Tac
   171   | Free_Solve
   172 
   173   | Init_Proof of Rule.cterm' list * Celem.spec
   174   | Model_Problem
   175   | Or_to_List
   176   | Refine_Problem of Celem.pblID
   177   | Refine_Tacitly of Celem.pblID
   178 
   179    (* rewrite-tactics can transport a (thmID, thm) to and (!) from the java-front-end
   180      because there all the thms are present with both (thmID, thm)
   181      (where user-views can show both or only one of (thmID, thm)),
   182      and thm is created from ThmID by assoc_thm'' when entering isabisac *)
   183   | Rewrite of Celem.thm''
   184   | Rewrite_Asm of Celem.thm''
   185   | Rewrite_Inst of Selem.subs * Celem.thm''
   186   | Rewrite_Set of Rule.rls'
   187   | Rewrite_Set_Inst of Selem.subs * Rule.rls'
   188 
   189   | Specify_Method of Celem.metID
   190   | Specify_Problem of Celem.pblID
   191   | Specify_Theory of Rule.domID
   192   | Subproblem of Rule.domID * Celem.pblID (* WN0509 drop *)
   193 
   194   | Substitute of Selem.sube
   195   | Tac of string               (* WN0509 drop *)
   196   | Take of Rule.cterm' | Take_Inst of Rule.cterm'
   197 
   198 fun tac2str ma = case ma of
   199     Init_Proof (ppc, spec)  => 
   200       "Init_Proof "^(pair2str (strs2str ppc, Celem.spec2str spec))
   201   | Model_Problem           => "Model_Problem "
   202   | Refine_Tacitly pblID    => "Refine_Tacitly " ^ strs2str pblID 
   203   | Refine_Problem pblID    => "Refine_Problem " ^ strs2str pblID 
   204   | Add_Given cterm'        => "Add_Given " ^ cterm'
   205   | Del_Given cterm'        => "Del_Given " ^ cterm'
   206   | Add_Find cterm'         => "Add_Find " ^ cterm'
   207   | Del_Find cterm'         => "Del_Find " ^ cterm'
   208   | Add_Relation cterm'     => "Add_Relation " ^ cterm'
   209   | Del_Relation cterm'     => "Del_Relation " ^ cterm'
   210 
   211   | Specify_Theory domID    => "Specify_Theory " ^ quote domID
   212   | Specify_Problem pblID   => "Specify_Problem " ^ strs2str pblID
   213   | Specify_Method metID    => "Specify_Method " ^ strs2str metID
   214   | Apply_Method metID      => "Apply_Method " ^ strs2str metID
   215   | Check_Postcond pblID    => "Check_Postcond " ^ strs2str pblID
   216   | Free_Solve              => "Free_Solve"
   217 
   218   | Rewrite_Inst (subs, (id, thm)) =>
   219     "Rewrite_Inst " ^ (pair2str (subs2str subs, spair2str (id, thm |> Thm.prop_of |> Rule.term2str)))
   220   | Rewrite (id, thm) => "Rewrite " ^ spair2str (id, thm |> Thm.prop_of |> Rule.term2str)
   221   | Rewrite_Asm (id, thm) => "Rewrite_Asm " ^ spair2str (id, thm |> Thm.prop_of |> Rule.term2str)
   222   | Rewrite_Set_Inst (subs, rls) => 
   223     "Rewrite_Set_Inst " ^ pair2str (subs2str subs, quote rls)
   224   | Rewrite_Set rls         => "Rewrite_Set " ^ quote rls
   225   | Detail_Set rls          => "Detail_Set " ^ quote rls
   226   | Detail_Set_Inst (subs, rls) =>  "Detail_Set_Inst " ^ pair2str (subs2str subs, quote rls)
   227   | End_Detail              => "End_Detail"
   228   | Derive rls'             => "Derive " ^ rls' 
   229   | Calculate op_           => "Calculate " ^ op_ 
   230   | Substitute sube         => "Substitute " ^ Selem.sube2str sube	     
   231   | Apply_Assumption ct's   => "Apply_Assumption " ^ strs2str ct's
   232 
   233   | Take cterm'             => "Take " ^ quote cterm'
   234   | Take_Inst cterm'        => "Take_Inst " ^ quote cterm'
   235   | Subproblem (domID, pblID) => "Subproblem " ^ pair2str (domID, strs2str pblID)
   236   | End_Subproblem          => "End_Subproblem"
   237   | CAScmd cterm'           => "CAScmd " ^ quote cterm'
   238 
   239   | Check_elementwise cterm'=> "Check_elementwise " ^ quote cterm'
   240   | Or_to_List              => "Or_to_List "
   241   | Collect_Trues           => "Collect_Trues"
   242 
   243   | Empty_Tac               => "Empty_Tac"
   244   | Tac string              => "Tac " ^ string
   245   | End_Proof'              => "input End_Proof'"
   246   | _                       => "tac2str not impl. for ?!";
   247 
   248 fun is_empty_tac input = case input of Empty_Tac => true | _ => false
   249 
   250 fun eq_tac (Rewrite (id1, _), Rewrite (id2, _)) = id1 = id2
   251   | eq_tac (Rewrite_Inst (_, (id1, _)), Rewrite_Inst (_, (id2, _))) = id1 = id2
   252   | eq_tac (Rewrite_Set id1, Rewrite_Set id2) = id1 = id2
   253   | eq_tac (Rewrite_Set_Inst (_, id1), Rewrite_Set_Inst (_, id2)) = id1 = id2
   254   | eq_tac (Calculate id1, Calculate id2) = id1 = id2
   255   | eq_tac _ = false
   256 
   257 fun is_rewset (Rewrite_Set_Inst _) = true
   258   | is_rewset (Rewrite_Set _) = true 
   259   | is_rewset _ = false;
   260 fun is_rewtac (Rewrite _) = true
   261   | is_rewtac (Rewrite_Inst _) = true
   262   | is_rewtac (Rewrite_Asm _) = true
   263   | is_rewtac input = is_rewset input;
   264 
   265 fun tac2IDstr ma = case ma of
   266     Model_Problem => "Model_Problem"
   267   | Refine_Tacitly _ => "Refine_Tacitly"
   268   | Refine_Problem _ => "Refine_Problem"
   269   | Add_Given _ => "Add_Given"
   270   | Del_Given _ => "Del_Given"
   271   | Add_Find _ => "Add_Find"
   272   | Del_Find _ => "Del_Find"
   273   | Add_Relation _ => "Add_Relation"
   274   | Del_Relation _ => "Del_Relation"
   275 
   276   | Specify_Theory _ => "Specify_Theory"
   277   | Specify_Problem _ => "Specify_Problem"
   278   | Specify_Method _ => "Specify_Method"
   279   | Apply_Method _ => "Apply_Method"
   280   | Check_Postcond _ => "Check_Postcond"
   281   | Free_Solve => "Free_Solve"
   282 
   283   | Rewrite_Inst _ => "Rewrite_Inst"
   284   | Rewrite _ => "Rewrite"
   285   | Rewrite_Asm _ => "Rewrite_Asm"
   286   | Rewrite_Set_Inst _ => "Rewrite_Set_Inst"
   287   | Rewrite_Set _ => "Rewrite_Set"
   288   | Detail_Set _ => "Detail_Set"
   289   | Detail_Set_Inst _ => "Detail_Set_Inst"
   290   | Derive _ => "Derive "
   291   | Calculate _ => "Calculate "
   292   | Substitute _ => "Substitute" 
   293   | Apply_Assumption _ => "Apply_Assumption"
   294 
   295   | Take _ => "Take"
   296   | Take_Inst _ => "Take_Inst"
   297   | Subproblem _ => "Subproblem"
   298   | End_Subproblem => "End_Subproblem"
   299   | CAScmd _ => "CAScmd"
   300 
   301   | Check_elementwise _ => "Check_elementwise"
   302   | Or_to_List => "Or_to_List "
   303   | Collect_Trues => "Collect_Trues"
   304 
   305   | Empty_Tac => "Empty_Tac"
   306   | Tac _ => "Tac "
   307   | End_Proof' => "End_Proof'"
   308   | _ => "tac2str not impl. for ?!";
   309 
   310 fun rls_of (Rewrite_Set_Inst (_, rls)) = rls
   311   | rls_of (Rewrite_Set rls) = rls
   312   | rls_of input = error ("rls_of: called with input \"" ^ tac2IDstr input ^ "\"");
   313 
   314 fun rule2tac thy _ (Rule.Num_Calc (opID, _)) = Calculate (assoc_calc thy opID)
   315   | rule2tac _ [] (Rule.Thm thm'') = Rewrite thm''
   316   | rule2tac _ subst (Rule.Thm thm'') = 
   317     Rewrite_Inst (Selem.subst2subs subst, thm'')
   318   | rule2tac _ [] (Rule.Rls_ rls) = Rewrite_Set (Rule.id_rls rls)
   319   | rule2tac _ subst (Rule.Rls_ rls) = 
   320     Rewrite_Set_Inst (Selem.subst2subs subst, (Rule.id_rls rls))
   321   | rule2tac _ _ rule = 
   322     error ("rule2tac: called with \"" ^ Rule.rule2str rule ^ "\"");
   323 
   324 (* tactics for for internal use, compare "input" for user at the front-end.
   325   tac_ contains results from check in 'fun applicable_in'.
   326   This is useful for costly results, e.g. from rewriting;
   327   however, these results might be changed by Scripts like
   328       "      eq = (Rewrite_Set ''ansatz_rls'' False) eql;" ^
   329       "      eq = (Rewrite_Set equival_trans False) eq;" ^
   330   TODO.WN120106 ANALOGOUSLY TO Substitute':
   331   So tac_ contains the term t the result was calculated from
   332   in order to compare t with t' possibly changed by "Expr "
   333   and re-calculate result if t<>t'
   334   TODO.WN161219: replace *every* cterm' by term
   335 *)
   336   datatype T =
   337     Add_Find' of Rule.cterm' * Model.itm list | Add_Given' of Rule.cterm' * Model.itm list 
   338   | Add_Relation' of Rule.cterm' * Model.itm list
   339   | Apply_Assumption' of term list * term
   340   | Apply_Method' of Celem.metID * term option * Istate_Def.T * Proof.context
   341   (*/--- TODO: re-design ? -----------------------------------------------------------------\*)
   342   | Begin_Sequ' | Begin_Trans' of term
   343   | Split_And' of term | Split_Or' of term | Split_Intersect' of term
   344   | Conclude_And' of term | Conclude_Or' of term | Collect_Trues' of term
   345   | End_Sequ' | End_Trans' of Selem.result
   346   | End_Ruleset' of term | End_Subproblem' of term | End_Intersect' of term | End_Proof''
   347   (*\--- TODO: re-design ? -----------------------------------------------------------------/*)
   348   | CAScmd' of term
   349   | Calculate' of Rule.theory' * string * term * (term * Celem.thm')
   350   | Check_Postcond' of Celem.pblID *
   351     Selem.result (* returnvalue of script in solve *)
   352   | Check_elementwise' of (*special case:*)
   353     term *       (* (1) the current formula: [x=1,x=...]     *)
   354     string *     (* (2) the pred from Check_elementwise      *)
   355     Selem.result (* (3) composed from (1) and (2): {x. pred} *)
   356   | Del_Find' of Rule.cterm' | Del_Given' of Rule.cterm' | Del_Relation' of Rule.cterm'
   357 
   358   | Derive' of Rule.rls
   359   | Detail_Set' of Rule.theory' * bool * Rule.rls * term * Selem.result
   360   | Detail_Set_Inst' of Rule.theory' * bool * Rule.subst * Rule.rls * term * Selem.result
   361   | End_Detail' of Selem.result
   362 
   363   | Empty_Tac_
   364   | Free_Solve'
   365 
   366   | Init_Proof' of Rule.cterm' list * Celem.spec
   367   | Model_Problem' of Celem.pblID * 
   368     Model.itm list *  (* the 'untouched' pbl        *)
   369     Model.itm list    (* the casually completed met *)
   370   | Or_to_List' of term * term
   371   | Refine_Problem' of Celem.pblID * (Model.itm list * (bool * term) list)
   372   | Refine_Tacitly' of
   373     Celem.pblID *     (* input*)
   374     Celem.pblID *     (* the refined from applicable_in                                       *)
   375     Rule.domID *     (* from new pbt?! filled in specify                                     *)
   376     Celem.metID *     (* from new pbt?! filled in specify                                     *)
   377     Model.itm list    (* drop ! 9.03: remains [] for Model_Problem recognizing its activation *)
   378   | Rewrite' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Celem.thm'' * term * Selem.result
   379   | Rewrite_Asm' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Celem.thm'' * term * Selem.result
   380   | Rewrite_Inst' of Rule.theory' * Rule.rew_ord' * Rule.rls * bool * Rule.subst * Celem.thm'' * term * Selem.result
   381   | Rewrite_Set' of Rule.theory' * bool * Rule.rls * term * Selem.result
   382   | Rewrite_Set_Inst' of Rule.theory' * bool * Rule.subst * Rule.rls * term * Selem.result
   383 
   384   | Specify_Method' of Celem.metID * Model.ori list * Model.itm list
   385   | Specify_Problem' of Celem.pblID * 
   386     (bool *                  (* matches	                                  *)
   387       (Model.itm list *      (* ppc	                                      *)
   388         (bool * term) list)) (* preconditions                             *)
   389   | Specify_Theory' of Rule.domID
   390   | Subproblem' of
   391     Celem.spec * 
   392 		(Model.ori list) *       (* filled in associate Subproblem'           *)
   393 		term *                   (* filled -"-, headline of calc-head         *)
   394 		Selem.fmz_ *             
   395     Proof.context *          (* DEPRECATED shifted into loc for all ppobj *)
   396 		term                     (* Subproblem (thyID, pbl) OR cascmd         *)  
   397   | Substitute' of           
   398     Rule.rew_ord_ *          (* for re-calculation                        *)
   399     Rule.rls *               (* for re-calculation                        *)
   400     Selem.subte *            (* the 'substitution': terms of type bool    *)
   401     term *                   (* to be substituted into                    *)
   402     term                     (* resulting from the substitution           *)
   403   | Tac_ of theory * string * string * string
   404   | Take' of term | Take_Inst' of term
   405 
   406 fun string_of ma = case ma of
   407     Init_Proof' (ppc, spec)  => "Init_Proof' " ^ pair2str (strs2str ppc, Celem.spec2str spec)
   408   | Model_Problem' (pblID, _, _) => "Model_Problem' " ^ strs2str pblID
   409   | Refine_Tacitly'(p, prefin, domID, metID, _) => "Refine_Tacitly' (" ^ strs2str p ^ ", " ^
   410     strs2str prefin ^ ", " ^ domID ^ ", " ^ strs2str metID ^ ", pbl-itms)"
   411   | Refine_Problem' _ => "Refine_Problem' (" ^ (*matchs2str ms*)"..." ^ ")"
   412   | Add_Given' _ => "Add_Given' "(*^cterm'*)
   413   | Del_Given' _ => "Del_Given' "(*^cterm'*)
   414   | Add_Find' _ => "Add_Find' "(*^cterm'*)
   415   | Del_Find' _ => "Del_Find' "(*^cterm'*)
   416   | Add_Relation' _ => "Add_Relation' "(*^cterm'*)
   417   | Del_Relation' _ => "Del_Relation' "(*^cterm'*)
   418 
   419   | Specify_Theory' domID => "Specify_Theory' " ^ quote domID
   420   | Specify_Problem' (pI, (ok, _)) =>  "Specify_Problem' " ^ 
   421     spair2str (strs2str pI, spair2str (bool2str ok, spair2str ("itms2str_ itms", "items2str pre")))
   422   | Specify_Method' (pI, oris, _) => "Specify_Method' (" ^ 
   423     Celem.metID2str pI ^ ", " ^ Model.oris2str oris ^ ", )"
   424 
   425   | Apply_Method' (metID, _, _, _) => "Apply_Method' " ^ strs2str metID
   426   | Check_Postcond' (pblID, (scval, asm)) => "Check_Postcond' " ^
   427       (spair2str (strs2str pblID, spair2str (Rule.term2str scval, Rule.terms2str asm)))
   428 
   429   | Free_Solve' => "Free_Solve'"
   430 
   431   | Rewrite_Inst' (*subs,thm'*) _ => "Rewrite_Inst' "(*^(pair2str (subs2str subs, spair2str thm'))*)
   432   | Rewrite' _(*thm'*) => "Rewrite' "(*^(spair2str thm')*)
   433   | Rewrite_Asm' _(*thm'*) => "Rewrite_Asm' "(*^(spair2str thm')*)
   434   | Rewrite_Set_Inst' _(*subs,thm'*) => "Rewrite_Set_Inst' "(*^(pair2str (subs2str subs, quote rls))*)
   435   | Rewrite_Set' (thy', pasm, rls', f, (f', asm)) => "Rewrite_Set' (" ^ thy' ^ "," ^ bool2str pasm ^
   436     "," ^ Rule.id_rls rls' ^ "," ^ Rule.term2str f ^ ",(" ^ Rule.term2str f' ^ "," ^ Rule.terms2str asm ^ "))"
   437   | End_Detail' _ => "End_Detail' xxx"
   438   | Detail_Set' _ => "Detail_Set' xxx"
   439   | Detail_Set_Inst' _ => "Detail_Set_Inst' xxx"
   440 
   441   | Derive' rls => "Derive' " ^ Rule.id_rls rls
   442   | Calculate'  _ => "Calculate' "
   443   | Substitute' _ => "Substitute' "(*^(subs2str subs)*)    
   444   | Apply_Assumption' _(* ct's*) => "Apply_Assumption' "(*^(strs2str ct's)*)
   445 
   446   | Take' _(*cterm'*) => "Take' "(*^(quote cterm'	)*)
   447   | Take_Inst' _(*cterm'*) => "Take_Inst' "(*^(quote cterm' )*)
   448   | Subproblem' _(*(spec, oris, _, _, _, pbl_form)*) => 
   449     "Subproblem' "(*^(pair2str (domID, strs2str ,))*)
   450   | End_Subproblem' _ => "End_Subproblem'"
   451   | CAScmd' _(*cterm'*) => "CAScmd' "(*^(quote cterm')*)
   452 
   453   | Empty_Tac_ => "Empty_Tac_"
   454   | Tac_ (_, form, id, result) => "Tac_ (thy," ^ form ^ "," ^ id ^ "," ^ result ^ ")"
   455   | _  => "string_of not impl. for arg";
   456 
   457 fun input_from_T (Refine_Tacitly' (pI, _, _, _, _)) = Refine_Tacitly pI
   458   | input_from_T (Model_Problem' (_, _, _)) = Model_Problem
   459   | input_from_T (Add_Given' (t, _)) = Add_Given t
   460   | input_from_T (Add_Find' (t, _)) = Add_Find t
   461   | input_from_T (Add_Relation' (t, _)) = Add_Relation t
   462  
   463   | input_from_T (Specify_Theory' dI) = Specify_Theory dI
   464   | input_from_T (Specify_Problem' (dI, _)) = Specify_Problem dI
   465   | input_from_T (Specify_Method' (dI, _, _)) = Specify_Method dI
   466   
   467   | input_from_T (Rewrite' (_, _, _, _, thm, _, _)) = Rewrite thm
   468   | input_from_T (Rewrite_Inst' (_, _, _, _, sub, thm, _, _)) = Rewrite_Inst (Selem.subst2subs sub, thm)
   469 
   470   | input_from_T (Rewrite_Set' (_, _, rls, _, _)) = Rewrite_Set (Rule.id_rls rls)
   471   | input_from_T (Detail_Set' (_, _, rls, _, _)) = Detail_Set (Rule.id_rls rls)
   472 
   473   | input_from_T (Rewrite_Set_Inst' (_, _, sub, rls, _, _)) = 
   474     Rewrite_Set_Inst (Selem.subst2subs sub, Rule.id_rls rls)
   475   | input_from_T (Detail_Set_Inst' (_, _, sub, rls, _, _)) = 
   476     Detail_Set_Inst (Selem.subst2subs sub, Rule.id_rls rls)
   477 
   478   | input_from_T (Calculate' (_, op_, _, _)) = Calculate (op_)
   479   | input_from_T (Check_elementwise' (_, pred, _)) = Check_elementwise pred
   480 
   481   | input_from_T (Or_to_List' _) = Or_to_List
   482   | input_from_T (Take' term) = Take (Rule.term2str term)
   483   | input_from_T (Substitute' (_, _, subte, _, _)) = Substitute (Selem.subte2sube subte) 
   484   | input_from_T (Tac_ (_, _, id, _)) = Tac id
   485 
   486   | input_from_T (Subproblem' ((domID, pblID, _), _, _, _,_ ,_)) = Subproblem (domID, pblID)
   487   | input_from_T (Check_Postcond' (pblID, _)) = Check_Postcond pblID
   488   | input_from_T Empty_Tac_ = Empty_Tac
   489   | input_from_T m = error (": not impl. for "^(string_of m));
   490 
   491 fun res (Rewrite_Inst' (_ , _, _, _, _, _, _, res)) = res
   492   | res (Rewrite' (_, _, _, _, _, _, res)) = res
   493   | res (Rewrite_Set_Inst' (_, _, _, _, _, res)) = res
   494   | res (Rewrite_Set' (_, _, _, _, res)) = res
   495   | res (Calculate' (_, _, _, (t, _))) = (t, [])
   496   | res (Check_elementwise' (_, _, res)) = res
   497   | res (Subproblem' (_, _, _, _, _, t)) = (t, [])
   498   | res (Take' t) = (t, [])
   499   | res (Substitute' (_, _, _, _, t)) = (t, [])
   500   | res (Or_to_List' (_,  t)) = (t, [])
   501   | res m = raise ERROR ("result: not impl.for " ^ string_of m)
   502 
   503 (*fun result m = (fst o res) m; TODO*)
   504 fun result tac = (fst o res) tac;
   505 fun creates_assms tac = (snd o res) tac;
   506 
   507 fun insert_assumptions tac ctxt  = ContextC.insert_assumptions (creates_assms tac) ctxt
   508 
   509 fun for_specify (Init_Proof _) = true
   510   | for_specify Model_Problem  = true
   511   | for_specify (Refine_Tacitly _) = true
   512   | for_specify (Refine_Problem _) = true
   513   | for_specify (Add_Given _) = true
   514   | for_specify (Del_Given _) = true
   515   | for_specify (Add_Find _) = true
   516   | for_specify (Del_Find _) = true
   517   | for_specify (Add_Relation _) = true
   518   | for_specify (Del_Relation _) = true
   519   | for_specify (Specify_Theory _) = true
   520   | for_specify (Specify_Problem _) = true
   521   | for_specify (Specify_Method _) = true
   522   | for_specify _ = false
   523 fun for_specify' (Init_Proof' _) = true
   524   | for_specify' (Model_Problem' _) = true
   525   | for_specify' (Refine_Tacitly' _) = true
   526   | for_specify' (Refine_Problem' _) = true
   527   | for_specify' (Add_Given' _) = true
   528   | for_specify' (Del_Given' _) = true
   529   | for_specify' (Add_Find' _) = true
   530   | for_specify' (Del_Find' _) = true
   531   | for_specify' (Add_Relation' _) = true
   532   | for_specify' (Del_Relation' _) = true
   533   | for_specify' (Specify_Theory' _) = true
   534   | for_specify' (Specify_Problem' _) = true
   535   | for_specify' (Specify_Method' _) = true
   536   | for_specify' _ = false
   537 
   538 (**)end(**)