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