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