test/Tools/isac/MathEngine/mathengine-stateless.sml
author Walther Neuper <walther.neuper@jku.at>
Thu, 19 Dec 2019 16:41:57 +0100
changeset 59749 cc3b1807f72e
parent 59747 8e5335c63475
child 59751 fa26464c66bf
permissions -rw-r--r--
cleanup fun solve, shift from Solve --> Step_Solve
     1 (* Title:  tests for Interpret/mathengine.sml
     2    Author: Walther Neuper 2000, 2006
     3    (c) due to copyright terms
     4 
     5 theory Test_Some imports Build_Thydata begin 
     6 ML {* KEStore_Elems.set_ref_thy @{theory};
     7   fun autoCalculate' cI auto = autoCalculate cI auto |> Future.join *}
     8 ML_file "~~/test/Tools/isac/Interpret/mathengine.sml"
     9 *)
    10 "--------------------------------------------------------";
    11 "table of contents --------------------------------------";
    12 "--------------------------------------------------------";
    13 "----------- change to parse ctxt -----------------------";
    14 "----------- debugging setContext..pbl_ -----------------";
    15 "----------- tryrefine ----------------------------------";
    16 "---------- mini-subpbl isac-java 3992e3bd1948: initial <NEXT> ---------------";
    17 "----------- fun step: Apply_Method without init_form ---";
    18 "----------- fun step -----------------------------------";
    19 "----------- fun autocalc -------------------------------";
    20 "----------- fun autoCalculate --------------------------";
    21 "----------- fun autoCalculate..CompleteCalc ------------";
    22 "----------- search for Or_to_List ----------------------";
    23 "----------- check thy in CalcTreeTEST ------------------";
    24 "----------- identified error in fun getTactic, string_of_thmI ---------------";
    25 "----------- improved fun getTactic for interSteps and numeral calculations --";
    26 "--------------------------------------------------------";
    27 "--------------------------------------------------------";
    28 "--------------------------------------------------------";
    29 
    30 "----------- change to parse ctxt -----------------------";
    31 "----------- change to parse ctxt -----------------------";
    32 "----------- change to parse ctxt -----------------------";
    33 "===== start calculation: from problem description (fmz) to origin";
    34 val fmz = ["realTestGiven (((1+2)*4/3)^^^2)","realTestFind s"];
    35 val (thyID, pblID, metID) =
    36   ("Test", ["calculate", "test"], ["Test", "test_calculate"]);
    37 (*======= Isabelle2013-2 --> Isabelle2014: unclear, why this test ever run =====================*)
    38 
    39 "----------- debugging setContext..pbl_ -----------------";
    40 "----------- debugging setContext..pbl_ -----------------";
    41 "----------- debugging setContext..pbl_ -----------------";
    42 reset_states ();
    43 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
    44   ("Test", ["sqroot-test","univariate","equation","test"],
    45    ["Test","squ-equ-test-subpbl1"]))];
    46 Iterator 1;
    47 moveActiveRoot 1; modelProblem 1;
    48 
    49 val pos as (p,_) = ([],Pbl);
    50 val guh = "pbl_equ_univ";
    51 checkContext 1 pos guh;
    52 val ((pt,_),_) = get_calc 1;
    53 val pp = par_pblobj pt p;
    54 val keID = guh2kestoreID guh;
    55 case context_pbl keID pt pp of (true,["univariate","equation"],_,_,_)=>()
    56 | _ => error "mathengine.sml: context_pbl .. pbl_equ_univ checked";
    57 
    58 case get_obj g_spec pt p of (_, ["e_pblID"], _) => ()
    59 | _ => error "mathengine.sml: context_pbl .. pbl still empty";
    60 setContext 1 pos guh;
    61 val ((pt,_),_) = get_calc 1;
    62 case get_obj g_spec pt p of (_, ["univariate","equation"], _) => ()
    63 | _ => error "mathengine.sml: context_pbl .. pbl set";
    64 
    65 
    66 setContext 1 pos "met_eq_lin";
    67 val ((pt,_),_) = get_calc 1;
    68 case get_obj g_spec pt p of (_,  _, ["LinEq", "solve_lineq_equation"]) => ()
    69 | _ => error "mathengine.sml: context_pbl .. pbl set";
    70 
    71 
    72 "----------- tryrefine ----------------------------------";
    73 "----------- tryrefine ----------------------------------";
    74 "----------- tryrefine ----------------------------------";
    75 reset_states ();
    76 CalcTree [(["equality (x/(x^2 - 6*x+9) - 1/(x^2 - 3*x) =1/x)", 
    77 	    "solveFor x", "solutions L"],
    78 	   ("RatEq",["univariate","equation"],["no_met"]))];
    79 Iterator 1;
    80 moveActiveRoot 1; autoCalculate 1 CompleteCalc;
    81 
    82 refineProblem 1 ([1],Res) "pbl_equ_univ" 
    83 (*gives "pbl_equ_univ_rat" correct*);
    84 
    85 refineProblem 1 ([1],Res) (pblID2guh ["LINEAR","univariate","equation"])
    86 (*gives "pbl_equ_univ_lin" incorrect*);
    87 
    88 "---------- mini-subpbl isac-java 3992e3bd1948: initial <NEXT> ---------------";
    89 "---------- mini-subpbl isac-java 3992e3bd1948: initial <NEXT> ---------------";
    90 "---------- mini-subpbl isac-java 3992e3bd1948: initial <NEXT> ---------------";
    91 reset_states ();
    92 (*this is the exact sequence of input provided by isac-java 3992e3bd1948;
    93   Surrounding ML { * ... * } are omitted.
    94   The multiple calls suggest to replicate the CalcTree in the Dialogue.
    95 *)
    96 CalcTree [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
    97   ("Test",["sqroot-test","univariate","equation","test"],["Test","squ-equ-test-subpbl1"]))]; 
    98 Iterator 1; 
    99 moveActiveRoot 1; 
   100 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false; 
   101 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false; 
   102 (*completeCalcHead*)autoCalculate 1 CompleteCalcHead; 
   103 (*completeCalcHead*)getActiveFormula 1 ; 
   104 (*completeCalcHead*)refFormula 1 ([],Met); 
   105 refFormula 1 ([],Pbl); 
   106 (*<REFFORMULA>  <CALCID> 1 </CALCID>  <CALCHEAD status = "correct"> *)
   107 fetchProposedTactic 1; 
   108 (*-> <STRINGLISTTACTIC name="Apply_Method">
   109        <STRINGLIST>
   110          <STRING> Test </STRING>
   111          <STRING> squ-equ-test-subpbl1 </STRING>
   112 WAS PREVIOUSLY: <SYSERROR>  <CALCID> 1 </CALCID>  <ERROR> error in kernel </ERROR></SYSERROR>*)
   113 "~~~~~ fun fetchProposedTactic, args:"; val (cI) = (1);
   114 val ("ok", (tacis, _, _)) = step (get_pos cI 1) (get_calc cI)
   115 val _= upd_tacis cI tacis
   116 	       val (tac,_,_) = last_elem tacis;
   117 (*fetchproposedtacticOK2xml cI tac (fetchErrorpatterns tac);
   118                                     fetchErrorpatterns tac
   119 WAS PREVIOUSLY ERROR: app_py: not found: ["IsacKnowledge","KEStore","Rulesets","e_rls"]*)
   120 "~~~~~ fun fetchErrorpatterns, args:"; val (tac) = (tac);
   121     val rlsID = "e_rls"
   122     val (part, thyID) = thy_containing_rls "Build_Thydata" rlsID;
   123 if part = "IsacScripts" andalso thyID = "KEStore" then ()
   124 else error "fetchErrorpatterns .. e_rls changed";
   125 val Hrls {thy_rls = (_, rls), ...} = get_the [part, thyID, "Rulesets", rlsID];
   126 (* WAS PREVIOUSLY ERROR app_py: not found: ["IsacKnowledge","KEStore","Rulesets","e_rls"]*)
   127 case rls of
   128   Rls {id = "e_rls", ...} => ()
   129 | _ => error "thy_containing_rls changed for e_rls"
   130 
   131 "----------- fun step: Apply_Method without init_form ---";
   132 "----------- fun step: Apply_Method without init_form ---";
   133 "----------- fun step: Apply_Method without init_form ---";
   134 val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
   135 val (dI',pI',mI') =
   136   ("Test", ["sqroot-test","univariate","equation","test"],
   137    ["Test","squ-equ-test-subpbl1"]);
   138 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
   139 "~~~~~ fun me, args:"; val tac = nxt;
   140 val ("ok", (_, _, (pt, p))) = locatetac tac (pt,p);
   141 "~~~~~ fun step, args:"; val (ip as (_,p_), ptp as (pt,p), tacis) = (p, (pt, e_pos'), []);
   142 val pIopt = get_pblID (pt,ip);
   143 ip = ([],Res) (*false*);
   144 val SOME pI = pIopt;
   145 member op = [Pbl,Met] p_ andalso is_none (get_obj g_env pt (fst p));
   146 			                          (*^^^^^^^^: Apply_Method without init_form*)
   147 
   148 "----------- fun step -----------------------------------";
   149 "----------- fun step -----------------------------------";
   150 "----------- fun step -----------------------------------";
   151 val p = e_pos'; val c = []; 
   152 val (p,_,f,nxt,_,pt) = 
   153     CalcTreeTEST 
   154         [(["functionTerm (x^^^2 + 1)", "integrateBy x", "antiDerivative FF"], 
   155           ("Integrate", ["integrate","function"], ["diff","integration"]))];
   156 "----- step 1: returns tac = Model_Problem ---";
   157 val (str, ([(tac, _, _)], _, (pt, p))) = step p ((pt, e_pos'), []);
   158 "----- step 2: returns tac =  ---";
   159 val (str, ([(tac, _, _)], _, (pt, p))) = step p ((pt, e_pos'), []);
   160 "----- step 3: returns tac =  ---";
   161 val (str, ([(tac, _, _)], _, (pt, p))) = step p ((pt, e_pos'), []);
   162 "----- step 4: returns tac =  ---";
   163 val (str, ([(tac, _, _)], _, (pt, p))) = step p ((pt, e_pos'), []);
   164 "----- step 5: returns tac =  ---";
   165 
   166 (*========== inhibit exn AK110718 ==============================================
   167 2002 stops here as well: TODO review actual arguments:
   168 val (str, ([(tac, _, _)], _, (pt, p))) = step p ((pt, e_pos'), []);
   169 "----- step 6: returns tac =  ---";
   170 val (str, ([(tac, _, _)], _, (pt, p))) = step p ((pt, e_pos'), []);
   171 "----- step 7: returns tac =  ---";
   172 val (str, ([(tac, _, _)], _, (pt, p))) = step p ((pt, e_pos'), []);
   173 "----- step 8: returns tac =  ---";
   174 val (str, ([(tac, _, _)], _, (pt, p))) = step p ((pt, e_pos'), []);
   175 ========== inhibit exn AK110718 ==============================================*)
   176 
   177 
   178 "----------- fun autocalc -------------------------------";
   179 "----------- fun autocalc -------------------------------";
   180 "----------- fun autocalc -------------------------------";
   181 val p = e_pos'; val c = []; 
   182 val (p,_,f,nxt,_,pt) = 
   183     CalcTreeTEST 
   184         [(["functionTerm (x^^^2 + 1)", "integrateBy x", "antiDerivative FF"], 
   185           ("Integrate",["integrate","function"], ["diff","integration"]))];
   186 (*-----since Model_Problem + complete_mod_ in case cas of SOME-----*
   187 modeling is skipped FIXME 
   188  *-----since Model_Problem + complete_mod_ in case cas of SOME-----*)
   189 tracing "----- step 1 ---";
   190 val (str, cut, (pt, p)) = autocalc [] p ((pt, e_pos'),[]) (Steps 1); show_pt pt;
   191 tracing "----- step 2 ---";
   192 val (str, cut, (pt, p)) = autocalc [] p ((pt, e_pos'),[]) (Steps 1); show_pt pt;
   193 tracing "----- step 3 ---";
   194 val (str, cut, (pt, p)) = autocalc [] p ((pt, e_pos'),[]) (Steps 1); show_pt pt;
   195 tracing "----- step 4 ---";
   196 val (str, cut, (pt, p)) = autocalc [] p ((pt, e_pos'),[]) (Steps 1); show_pt pt;
   197 tracing "----- step 5 ---";
   198 val (str, cut, (pt, p)) = autocalc [] p ((pt, e_pos'),[]) (Steps 1); show_pt pt;
   199 tracing "----- step 6 ---";
   200 val (str, cut, (pt, p)) = autocalc [] p ((pt, e_pos'),[]) (Steps 1); show_pt pt;
   201 tracing "----- step 7 ---";
   202 val (str, cut, (pt, p)) = autocalc [] p ((pt, e_pos'),[]) (Steps 1); show_pt pt;
   203 tracing "----- step 8 ---";
   204 val (str, cut, (pt, p)) = autocalc [] p ((pt, e_pos'),[]) (Steps 1); show_pt pt;
   205 (*========== inhibit exn AK110718 ==============================================
   206 WN110628: Integration does not work, see Knowledge/integrate.sml
   207 
   208 if str = "end-of-calculation" andalso 
   209    term2str (get_obj g_res pt (fst p)) = "c + x + 1 / 3 * x ^^^ 3" then ()
   210 else error "mathengine.sml -- fun autocalc -- end";
   211 ========== inhibit exn AK110718 ==============================================*)
   212 
   213 
   214 "----------- fun autoCalculate -----------------------------------";
   215 "----------- fun autoCalculate -----------------------------------";
   216 "----------- fun autoCalculate -----------------------------------";
   217 reset_states ();
   218 CalcTree (*ATTENTION: encode_fmz ... unlike CalcTreeTEST*)
   219     [(["functionTerm (x^2 + 1)", "integrateBy x", "antiDerivative FF"],
   220       ("Integrate", ["integrate", "function"], ["diff", "integration"]))];
   221 Iterator 1;
   222 moveActiveRoot 1;
   223 (*-----since Model_Problem + complete_mod_ in case cas of SOME-----*
   224 modeling is skipped FIXME 
   225 see test/../interface -- solve_linear as rootpbl FE -- for OTHER expl:
   226  setNextTactic 1 (Add_Given "equality (1 + -1 * 2 + x = 0)");
   227  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1); (*equality added*);
   228 
   229  fetchProposedTactic 1;
   230  setNextTactic 1 (Add_Given "solveFor x");
   231  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);
   232 
   233  fetchProposedTactic 1;
   234  setNextTactic 1 (Add_Find "solutions L");
   235  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);
   236 
   237  fetchProposedTactic 1;
   238  setNextTactic 1 (Specify_Theory "Test");
   239  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);
   240 *-----since Model_Problem + complete_mod_ in case cas of SOME-----*)
   241 autoCalculate 1 (Steps 1); 
   242 "----- step 1 ---";
   243 autoCalculate 1 (Steps 1);
   244 "----- step 2 ---";
   245 autoCalculate 1 (Steps 1);
   246 "----- step 3 ---";
   247 autoCalculate 1 (Steps 1);
   248 "----- step 4 ---";
   249 autoCalculate 1 (Steps 1);
   250 "----- step 5 ---";
   251 autoCalculate 1 (Steps 1);
   252 "----- step 6 ---";
   253 autoCalculate 1 (Steps 1);
   254 "----- step 7 ---";
   255 autoCalculate 1 (Steps 1);
   256 "----- step 8 ---";
   257 autoCalculate 1 (Steps 1);
   258 val (ptp as (_, p), _) = get_calc 1;
   259 val (Form t,_,_) = pt_extract ptp;
   260 
   261 if term2str t = "c + x + 1 / 3 * x ^^^ 3" andalso p = ([], Res) then ()
   262 else error "mathengine.sml -- fun autoCalculate -- end";
   263 
   264 "----------- fun autoCalculate..CompleteCalc ------------";
   265 "----------- fun autoCalculate..CompleteCalc ------------";
   266 "----------- fun autoCalculate..CompleteCalc ------------";
   267  reset_states ();
   268  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   269    ("Test", ["sqroot-test","univariate","equation","test"],
   270     ["Test","squ-equ-test-subpbl1"]))];
   271  Iterator 1;
   272  moveActiveRoot 1; 
   273 (*autoCalculate 1 CompleteCalc; (*WAS <SYSERROR>..<ERROR> error in kernel </ERROR>*)*)
   274 "~~~~~ fun autoCalculate, args:"; val (cI, auto) = (1, CompleteCalc);
   275 val pold = get_pos cI 1;
   276 (*autocalc [] pold (get_calc cI) auto;  (*WAS Type unification failed
   277   Type error in application: incompatible operand type
   278   Operator:  solveFor :: real \<Rightarrow> una
   279   Operand:   x :: 'a *)*)
   280 "~~~~~ fun autocalc, args:"; val (c, (pos as (_,p_)), ((pt,_), _), auto) 
   281                                = ([] : pos' list, pold, (get_calc cI), auto);
   282 autoord auto > 3 andalso just_created (pt, pos); (*true*)
   283 val ptp = all_modspec (pt, pos);
   284 "TODO all_modspec: preconds for rootpbl";
   285 (*all_solve auto c ptp; (*WAS Type unification failed...*)*)
   286 "~~~~~ and all_solve, args:"; val (auto, c, (ptp as (pt, pos as (p,_)))) =
   287                                                                   (auto, c, ptp);
   288     val (_,_,mI) = get_obj g_spec pt p
   289     val ctxt = get_ctxt pt pos
   290     val (ttt, c', ptp) = begin_end_prog (Apply_Method' (mI, NONE, e_istate, ctxt)) (e_istate, ctxt) ptp;
   291 (* complete_solve auto (c @ c') ptp; (*WAS Type unification failed...*) pos = ([], Met)*)
   292 "~~~~~ fun complete_solve, args:"; val (auto, c, (ptp as (_, p as (_,p_)))) =
   293                                                            (auto, (c @ c'), ptp);
   294 p = ([], Res) (*false p = ([1], Frm)*);
   295 member op = [Pbl,Met] p_ (*false*);
   296 val (ttt, c', ptp') = do_solve_step ptp; (*ttt = Rewrite_Set "norm_equation"*)
   297 (* complete_solve auto (c @ c') ptp'; (*WAS Type unification failed...*) pos = ([], Met)*)
   298 "~~~~~ fun complete_solve, args:"; val (auto, c, (ptp as (_, p as (_,p_)))) =
   299                                                            (auto, (c @ c'), ptp');
   300 p = ([], Res) (*false p = ([1], Res)*);
   301 member op = [Pbl,Met] p_ (*false*);
   302 val (ttt, c', ptp') = do_solve_step ptp; (*ttt = Rewrite_Set "Test_simplify"*)
   303 (* complete_solve auto (c @ c') ptp'; (*WAS Type unification failed...*) pos = ([], Met)*)
   304 "~~~~~ fun complete_solve, args:"; val (auto, c, (ptp as (_, p as (_,p_)))) =
   305                                                            (auto, (c @ c'), ptp');
   306 p = ([], Res) (*false p = ([2], Res)*);
   307 member op = [Pbl,Met] p_ (*false*);
   308 val ((Subproblem _, tac_, (_, is))::_, c', ptp') = do_solve_step ptp;
   309 autoord auto < 5 (*false*);
   310 (* val ptp = all_modspec ptp' (*WAS Type unification failed...*)*)
   311 "~~~~~ fun all_modspec , args:"; val (pt, pos as (p,_)) = (ptp');
   312     val (PblObj {fmz = (fmz_, _), origin = (pors, spec as (dI,pI,mI), hdl), ...}) = get_obj I pt p;
   313 	  val {ppc, ...} = get_met mI;
   314 (*  val (mors, ctxt) = prep_ori fmz_ thy ppc; WAS Type unification failed because
   315 val ctxt' = dI |> Thy_Info_get_theory |> Proof_Context.init_global;
   316 (parseNEW ctxt' "x" |> the |> type_of) = TFree ("'a",[]); 
   317                                                ^^^^^ *)
   318 (*vvv from:  | associate pt _ (Subproblem'...*)
   319     val (_, vals) = oris2fmz_vals pors;
   320 (**)
   321 	  val ctxt = ContextC.initialise dI vals
   322 (**)
   323 (*^^^ from:  | associate pt _ (Subproblem'...*)
   324 val [(1, [1], "#Given", dsc_eq, [equality]),
   325      (2, [1], "#Given", dsc_solvefor, [xxx]),
   326      (3, [1], "#Find", dsc_solutions, [x_i])] = pors;
   327 if term2str xxx = "x" andalso type_of xxx = HOLogic.realT then () 
   328 else error "autoCalculate..CompleteCalc: SubProblem broken 1";
   329     val pt = update_pblppc pt p (map (ori2Coritm ppc) pors);
   330 	  val pt = update_metppc pt p (map (ori2Coritm ppc) pors);
   331 	  val pt = update_spec pt p (dI,pI,mI);
   332     val pt = update_ctxt pt p ctxt;
   333 "~~~~~ return to complete_solve, args:"; val (ptp) = (pt, (p,Met));
   334 val (msg, c, (pt, p)) = complete_solve auto (c @ c') ptp;
   335 if msg = "end-of-calculation" andalso c = [] andalso p = ([], Res) then ()
   336 else error "autoCalculate..CompleteCalc: final result";
   337 if eq_set op = (terms2strs (get_assumptions_ pt p),
   338   ["precond_rootmet 1", "matches (?a = ?b) (-1 + x = 0)", "x = 1", "precond_rootmet x"])
   339 (* assumptions are handled by Proof.context now:
   340   ["matches (?a = ?b) (-1 + x = 0)", (*precond of submet*) 
   341    "x = 1",                          (*result of subpbl and rootpbl*)
   342    "precond_rootmet x"]              (*precond of rootmet*)          *)
   343 then () else error "autoCalculate..CompleteCalc: ctxt at final result";
   344 
   345 
   346 "--------- search for Or_to_List ------------------------";
   347 "--------- search for Or_to_List ------------------------";
   348 "--------- search for Or_to_List ------------------------";
   349 val fmz = ["equality (x^^^2 + 4*x + 5 = (2::real))", "solveFor x","solutions L"];
   350 val (dI',pI',mI') = ("Isac_Knowledge", ["univariate","equation"], ["no_met"])
   351 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
   352 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   353 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   354 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   355 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   356 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   357 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   358 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   359 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   360 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   361 val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = ("Subproblem"*)
   362 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   363 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   364 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   365 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   366 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   367 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   368 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   369 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   370 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   371 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   372 "~~~~~ fun me, args:"; val (tac, (p:pos'), (_:NEW(*remove*)), (pt:ctree)) = 
   373                             (nxt, p, [], pt);
   374 val ("ok", (_, _, ptp))  = locatetac tac (pt,p)
   375 val (pt, p) = ptp;
   376 "~~~~~ fun step, args:"; val (((ip as (_,p_)):pos'), ((ptp as (pt,p), tacis):calcstate)) =
   377                           (p, ((pt, e_pos'),[]));
   378 val pIopt = get_pblID (pt,ip);
   379 ip = ([],Res); (*false*)
   380 ip = p; (*false*)
   381 member op = [Pbl,Met] p_; (*false*)
   382 "~~~~~ fun do_solve_step, args:"; val (ptp as (pt, pos as (p,p_))) = (pt,ip);
   383 e_metID = get_obj g_metID pt (par_pblobj pt p); (*false*)
   384 val thy' = get_obj g_domID pt (par_pblobj pt p);
   385 val (srls, (ist, ctxt), sc) = from_pblobj_or_detail' thy' (p,p_) pt;
   386 val Next_Step (istate, ctxt, tac) = find_next_tactic sc (pt,pos) ist ctxt; (*WAS Empty_Tac_: tac_*)
   387 case tac of Or_to_List' _ => ()
   388 | _ => error "Or_to_List broken ?"
   389 
   390 
   391 "----------- check thy in CalcTreeTEST ------------------";
   392 "----------- check thy in CalcTreeTEST ------------------";
   393 "----------- check thy in CalcTreeTEST ------------------";
   394 "WN1109 with Inverse_Z_Transform.thy when starting tests with CalcTreeTEST \n" ^
   395 "we got the message: ME_Isa: thy 'Build_Inverse_Z_Transform' not in system \n" ^
   396 "Below there are the steps which found out the reason: \n" ^
   397 "store_pbt mistakenly stored that theory.";
   398 val ctxt = Proof_Context.init_global @{theory Isac_Knowledge};
   399 val SOME t = parseNEW ctxt "filterExpression (X  = 3 / (z - 1/4 + -1/8 * (1/(z::real))))";
   400 val SOME t = parseNEW ctxt "stepResponse (x[n::real]::bool)";
   401 
   402 val fmz = ["filterExpression (X  = 3 / (z - 1/4 + -1/8 * (1/(z::real))))", "boundVariable z",
   403   "stepResponse (x[n::real]::bool)"];
   404 val (dI,pI,mI) = ("Isac_Knowledge", ["Inverse", "Z_Transform", "SignalProcessing"], 
   405   ["SignalProcessing","Z_Transform","Inverse"]);
   406 
   407 val (p,_,fb,nxt,_,pt)  = CalcTreeTEST [(fmz, (dI,pI,mI))]; 
   408 (*WAS ME_Isa: thy 'Build_Inverse_Z_Transform' not in system*)
   409 
   410 "~~~~~ T fun CalcTreeTEST, args:"; val [(fmz, sp):fmz] = [(fmz, (dI,pI,mI))];
   411 "~~~~~ fun nxt_specify_init_calc, args:"; val (fmz, (dI, pI, mI)) = (fmz, sp);
   412 	      val thy = assoc_thy dI;
   413     mI = ["no_met"]; (*false*)
   414 		      val (pI, (pors, pctxt), mI) = (pI, get_pbt pI |> #ppc |> prep_ori fmz thy, mI)
   415 	      val {cas, ppc, thy=thy',...} = get_pbt pI; (*take dI from _refined_ pbl*)
   416 	"tracing bottom up"; Context.theory_name thy' = "Build_Inverse_Z_Transform"; (*WAS true*)
   417       val dI = theory2theory' (maxthy thy thy');
   418 "tracing bottom up"; dI = "Build_Inverse_Z_Transform"; (*WAS true*)
   419     cas = NONE; (*true*)
   420 	      val hdl = pblterm dI pI;
   421         val (pt, _) = cappend_problem e_ctree [] (e_istate, pctxt) (fmz, (dI, pI, mI))
   422 				  (pors, (dI, pI, mI), hdl)
   423         val pt = update_ctxt pt [] pctxt;
   424 
   425 "~~~~~ fun nxt_specif, args:"; val ((tac as Model_Problem), (pt, pos as (p,p_))) = (Model_Problem, (pt, ([], Pbl)));
   426       val PblObj {origin = (oris, ospec, _), probl, spec, ctxt, ...} = get_obj I pt p;
   427 "tracing bottom up"; #1(ospec) = "Build_Inverse_Z_Transform"; (*WAS true*)
   428 
   429 "~~~~~ fun some_spec, args:"; val ((odI, opI, omI), (dI, pI, mI)) = (ospec, spec);
   430 dI = e_domID; (*true*)
   431 odI = "Build_Inverse_Z_Transform"; (*true*)
   432 dI = "e_domID"; (*true*)
   433 "~~~~~ after fun some_spec:";
   434       val (dI, pI, mI) = some_spec ospec spec;
   435 "tracing bottom up"; dI = "Build_Inverse_Z_Transform"; (*WAS true*)
   436       val thy = assoc_thy dI; (*caused ME_Isa: thy 'Build_Inverse_Z_Transform' not in system*)
   437 
   438 "----------- identified error in fun getTactic, string_of_thmI ---------------";
   439 "----------- identified error in fun getTactic, string_of_thmI ---------------";
   440 "----------- identified error in fun getTactic, string_of_thmI ---------------";
   441 reset_states ();
   442 CalcTree [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
   443   ("Test",["sqroot-test","univariate","equation","test"],["Test","squ-equ-test-subpbl1"]))];
   444 moveActiveRoot 1;
   445 autoCalculate 1 CompleteCalcHead;
   446 autoCalculate 1 (Steps 1);
   447 autoCalculate 1 (Steps 1);
   448 autoCalculate 1 (Steps 1);
   449 getTactic 1 ([1],Frm); (*<RULESET> norm_equation </RULESET>*)
   450 interSteps 1 ([1],Res);
   451 "~~~~~ fun interSteps, args:"; val (cI, ip) = (1, ([1],Res));
   452 val ((pt,p), tacis) = get_calc cI;
   453 (not o is_interpos) ip = false;
   454 val ip' = lev_pred' pt ip;
   455 "~~~~~ fun detailstep, args:"; val (pt, (pos as (p,p_):pos')) = (pt, ip);
   456 (*         ^^^^^^^^^ not in test/../ *)
   457     val nd = get_nd pt p
   458     val cn = children nd;
   459 null cn = false;
   460 (is_rewset o (get_obj g_tac nd)) [(*root of nd*)] = true;
   461 "~~~~~ fun detailrls, args:"; val (pt, (pos as (p,p_):pos')) = (pt, pos);
   462 (*         ^^^^^^^^^ only once in test/../solve.sml*)
   463     val t = get_obj g_form pt p
   464 	  val tac = get_obj g_tac pt p
   465 	  val rls = (assoc_rls o rls_of) tac
   466     val ctxt = get_ctxt pt pos
   467 (*rls = Rls {calc = [], erls = ...*)
   468           val is = init_istate tac t
   469 	        (*TODO.WN060602 Pstate (["(t_, Problem (Isac,[equation,univar]))"]
   470 				    is wrong for simpl, but working ?!? *)
   471 	        val tac_ = Apply_Method' (e_metID(*WN0402: see generate1 !?!*), SOME t, is, ctxt)
   472 	        val pos' = ((lev_on o lev_dn) p, Frm)
   473 	        val thy = assoc_thy "Isac_Knowledge"
   474 	        val (_,_,_,pt') = (*implicit Take*)generate1 thy tac_ (is, ctxt) pos' pt;
   475 	        (*val (_,_,(pt'',_)) = *)complete_solve CompleteSubpbl [] (pt',pos');
   476 	        (*                   ^^^^^^^^^^^^^^ in test/../mathengine.sml*)
   477 	        (* in pt'': tac = Rewrite ("rnorm_equation_add", "Test.rnorm_equation_add")},
   478                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
   479 "~~~~~ fun complete_solve , args:"; val (auto, c, (ptp as (_, p as (_,p_)): ctree * pos')) =
   480   (CompleteSubpbl, [], (pt',pos'));
   481 p = ([], Res) = false;
   482 member op = [Pbl,Met] p_ = false;
   483 val (_, c', ptp') = do_solve_step ptp;
   484 (* in pt': tac = Rewrite ("rnorm_equation_add", "Test.rnorm_equation_add")},
   485                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
   486 "~~~~~ fun do_solve_step , args:"; val ((ptp as (pt, pos as (p,p_)))) = (ptp);
   487 e_metID = get_obj g_metID pt (par_pblobj pt p) = false;
   488           val thy' = get_obj g_domID pt (par_pblobj pt p);
   489 	        val (srls, (ist, ctxt), sc) = from_pblobj_or_detail' thy' (p,p_) pt;
   490 	        val Next_Step (is, ctxt, tac_) = find_next_tactic sc (pt,pos) ist ctxt;
   491 (*tac_ = Rewrite' (..., ("rnorm_equation_add", "Test.rnorm_equation_add"), ...) !!!!!!!!!!!!!!!!*)
   492 
   493 (*----- outcommented during cleanup of args in lucas-interpreter.sml ------------------------\\* )
   494 "~~~~~ fun find_next_tactic , args:"; val (thy, (ptp as (pt, pos as (p, _)):ctree * pos'), 
   495   (sc as Prog (h $ body)), (Pstate (ist as (E,l,rls,a,v,s,b)), ctxt)) = ((thy',srls), (pt,pos), sc, is);
   496 l = [] = false;
   497 go_scan_up2 thy ptp sc ist Skip_ (*--> Accept_Tac2 (Rewrite' (.., (.., "Test.rnorm_equation_add"), ...)
   498   BUT WE FIND IN THE CODE ABOVE IN find_next_tactic:*)
   499 ;
   500 (*----------------------------------------------------------------------------------------------*)
   501 if string_of_thmI @{thm rnorm_equation_add} =  "\<not> ?b =!= 0 \<Longrightarrow> (?a = ?b) = (?a + - 1 * ?b = 0)"
   502 then () else error "string_of_thmI changed";
   503 if string_of_thm @{thm rnorm_equation_add} =  "\<not> ?b =!= 0 \<Longrightarrow> (?a = ?b) = (?a + - 1 * ?b = 0)"
   504 then () else error "string_of_thm changed";
   505 (*----------------------------------------------------------------------------------------------*)
   506 ;
   507 (*SEARCH FOR THE ERROR WENT DOWN TO THE END OF THIS TEST, AND THEN UP TO HERE AGAIN*)
   508 "~~~~~ fun begin_end_prog, args:"; val (tac_, is, (pt, pos as (p,p_))) = (tac_, is, ptp);
   509         val pos =
   510           case pos of
   511 		        (p, Met) => ((lev_on o lev_dn) p, Frm)(*begin script*)
   512 		      | (p, Res) => (lev_on p,Res) (*somewhere in script*)
   513 		      | _ => pos;
   514 generate1 (assoc_thy "Isac_Knowledge") tac_ is pos pt;
   515 (* tac = Rewrite ("rnorm_equation_add", "Test.rnorm_equation_add")},
   516                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
   517 "~~~~~ fun generate1, args:"; val (thy, (Rewrite' (thy',ord',rls',pa,thm',f,(f',asm))), 
   518   (is, ctxt), (p,p_), pt) = ((assoc_thy "Isac_Knowledge"), tac_, is, pos, pt);
   519         val (pt,c) = cappend_atomic pt p (is, ContextC.insert_assumptions asm ctxt) f
   520           (Rewrite thm') (f',asm) Complete;
   521 (* in pt: tac = Rewrite ("rnorm_equation_add", "Test.rnorm_equation_add")},
   522                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
   523 "~~~~~ fun cappend_atomic, args:"; val (pt, p, ist_res, f, r, f', s) = 
   524   (pt, p, (is, ContextC.insert_assumptions asm ctxt), f, (Rewrite thm'), (f',asm), Complete);
   525 existpt p pt andalso is_empty_tac (get_obj g_tac pt p) = false;
   526 apfst (append_atomic p ist_res f r f' s) (cut_tree pt (p,Frm));
   527 apfst : ('a -> 'b) -> 'a * 'c -> 'b * 'c;
   528 (append_atomic p ist_res f r f' s) : ctree -> ctree;
   529 ;
   530 (* HERE THE ERROR OCCURED IN THE FIRST APPROACH
   531   getTactic 1 ([1,1],Frm); <ERROR> syserror in getTactic </ERROR>  <<<<<=========================*)
   532 "~~~~~ fun getTactic, args:"; val (cI, (p:pos')) = (1, ([1,1],Frm));
   533 val ((pt,_),_) = get_calc cI
   534 val (form, tac, asms) = pt_extract (pt, p)
   535 val SOME ta = tac;
   536 "~~~~~ fun gettacticOK2xml, args:"; val ((cI:calcID), tac) = (cI, ta);
   537 val i = 2;
   538 "~~~~~ fun tac2xml, args:"; val (j, (Rewrite thm')) = (i, tac);
   539 "~~~~~ fun thm'2xml, args:"; val (j, ((ID, form) : thm'')) = ((j+i), thm');
   540 ID = "rnorm_equation_add";
   541 @{thm rnorm_equation_add};
   542 (term2str o Thm.prop_of) form = "~ ?b =!= 0 ==> (?a = ?b) = (?a + -1 * ?b = 0)"
   543   (*?!? should be "\<not> ?b =!= 0 \<Longrightarrow> (?a = ?b) = (?a + -1 * ?b = 0)"*)
   544 (*thmstr2xml (j+i) form;
   545 ERROR Undeclared constant: "Test.rnorm_equation_add" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
   546 ;
   547 show_pt pt;
   548 (*[
   549 (([], Frm), solve (x + 1 = 2, x)),
   550 (([1], Frm), x + 1 = 2),
   551 (([1,1], Frm), x + 1 = 2),
   552 (([1,1], Res), x + 1 + -1 * 2 = 0),
   553 (([1], Res), x + 1 + -1 * 2 = 0),
   554 (([2], Res), -1 + x = 0)]
   555 
   556 pt;   --> tac = Rewrite ("rnorm_equation_add", "Test.rnorm_equation_add")*)
   557 ( *----- outcommented during cleanup of args in lucas-interpreter.sml ------------------------//*)
   558 
   559 "----------- improved fun getTactic for interSteps and numeral calculations --";
   560 "----------- improved fun getTactic for interSteps and numeral calculations --";
   561 "----------- improved fun getTactic for interSteps and numeral calculations --";
   562 reset_states (); val cI = 1;
   563 CalcTree [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
   564   ("Test",["sqroot-test","univariate","equation","test"],["Test","squ-equ-test-subpbl1"]))];
   565 moveActiveRoot 1;
   566 autoCalculate 1 CompleteCalcHead;
   567 autoCalculate 1 (Steps 1);
   568 
   569     val cs = get_calc cI             (* we improve from the calcstate here [*] *);
   570     val pos as (_,p_) = get_pos cI 1 (* we improve from the calcstate here [*] *);
   571 
   572 appendFormula 1 "x + 4 + -3 = 2" (*|> Future.join*);
   573 interSteps 1 ([1],Res); (* already done by appendFormula, now showed to frontend *)
   574 getTactic 1 ([1,1], Res); 
   575   (*<ID> sym_#add_Float ((~3,0), (0,0)) __ ((4,0), (0,0)) </ID>  <<<<<================== to improve
   576   <ISA> 1 + x = -3 + (4 + x) </ISA>*)
   577 
   578 val ((pt''',p'''), tacis''') = get_calc cI;
   579 show_pt pt'''
   580 (*[
   581 (([], Frm), solve (x + 1 = 2, x)),
   582 (([1], Frm), x + 1 = 2),
   583 (([1,1], Frm), x + 1 = 2),
   584 (([1,1], Res), 1 + x = 2),
   585 (([1,2], Res), -3 + (4 + x) = 2),
   586 (([1,3], Res), -3 + (x + 4) = 2),
   587 (([1,4], Res), x + 4 + -3 = 2),
   588 (([1], Res), x + 4 + -3 = 2)]*)
   589 ;
   590 "~~~~~ fun appendFormula', args:"; val (cI, ifo) = (1, "x + 4 + -3 = 2");
   591 (*  val cs = get_calc cI             (* we improve from the calcstate here [*] *);
   592     val pos as (_,p_) = get_pos cI 1 (* we improve from the calcstate here [*] *);*)
   593 val ("ok", cs') = step pos cs;
   594 (*val ("ok", (_, c, ptp as (_,p))) = *)inform cs' (encode ifo);
   595 "~~~~~ fun inform , args:"; val (cs as (_, _, ptp as (pt, pos as (p, p_))), istr) =
   596   (cs', (encode ifo));
   597 val SOME f_in = parse (assoc_thy "Isac_Knowledge") istr
   598 	      val f_in = Thm.term_of f_in
   599 	      val f_succ = get_curr_formula (pt, pos);
   600 f_succ = f_in  = false;
   601 val NONE = cas_input f_in 
   602 			          val pos_pred = lev_back' pos
   603 			          (* f_pred ---"step pos cs"---> f_succ in appendFormula *)
   604 			          val f_pred = get_curr_formula (pt, pos_pred);
   605 			          (*val msg_calcstate' = *)compare_step ([], [], (pt, pos_pred)) f_in (*<<=====*);
   606 "~~~~~ fun compare_step, args:"; val (((tacis, c, ptp as (pt, pos as (p,p_)))), ifo) = 
   607   (([], [], (pt, pos_pred)), f_in);
   608     val fo =
   609       case p_ of
   610         Frm => get_obj g_form pt p
   611 			| Res => (fst o (get_obj g_result pt)) p
   612 			| _ => e_term (*on PblObj is fo <> ifo*);
   613 	  val {nrls, ...} = get_met (get_obj g_metID pt (par_pblobj pt p))
   614 	  val {rew_ord, erls, rules, ...} = rep_rls nrls;
   615 	  (*val (found, der) = *)concat_deriv rew_ord erls rules fo ifo; (*<---------------*)
   616 "~~~~~ fun concat_deriv, args:"; val (rew_ord, erls, rules, fo, ifo) =
   617   (rew_ord, erls, rules, fo, ifo);
   618     fun derivat ([]:(term * rule * (term * term list)) list) = e_term
   619       | derivat dt = (#1 o #3 o last_elem) dt
   620     fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1=t2
   621     (*val  fod = *)make_deriv (Isac"") erls rules (snd rew_ord) NONE  fo;
   622     (*val ifod = *)make_deriv (Isac"") erls rules (snd rew_ord) NONE ifo;
   623