test/Tools/isac/Frontend/use-cases.sml
author Walther Neuper <wneuper@ist.tugraz.at>
Thu, 28 May 2015 14:23:18 +0200
changeset 59127 34f296390b60
parent 59123 5127be395ea1
child 59173 6777b7140b9c
permissions -rw-r--r--
PIDE: more interactions in frontend interface:

CalcTree, getActiveFormula, moveActiveCalcHead, moveActiveDown,
moveActiveFormula, ...
... all concerning iteratorOK2xml.

We leave the old code until libisabelle is integrated.
     1 (* Title:  tests the interface of isac's SML-kernel in accordance to 
     2            java-tests/isac.bridge.
     3    Author: Walther Neuper
     4    (c) copyright due to lincense terms.
     5 
     6 WN050707 ... if true, the test ist marked with a \label referring
     7 to the same UC in isac-docu.tex as the JUnit testcase.
     8 WN120210?not ME: added some labels, which are not among the above,
     9 repaired lost \label (s).
    10 
    11 theory Test_Some imports Build_Thydata begin 
    12 ML {* KEStore_Elems.set_ref_thy @{theory};
    13   fun autoCalculate' cI auto = autoCalculate cI auto (*|> Future.join*) *}
    14 ML_file "Frontend/use-cases.sml"
    15 *)
    16 
    17 "--------------------------------------------------------";
    18 "table of contents --------------------------------------";
    19 "--------------------------------------------------------";
    20 "within struct ------------------------------------------";
    21 "--------------------------------------------------------";
    22 "--------- encode ^ -> ^^^ ------------------------------";
    23 "--------------------------------------------------------";
    24 "exported from struct -----------------------------------";
    25 "--------------------------------------------------------";
    26 "--------- empty rootpbl --------------------------------";
    27 "--------- solve_linear as rootpbl FE -------------------";
    28 "--------- inspect the CalcTree No.1 with Iterator No.2 -";
    29 "--------- miniscript with mini-subpbl ------------------";
    30 "--------- mini-subpbl AUTOCALCULATE Step 1 -------------";
    31 "--------- solve_linear as rootpbl AUTO CompleteCalc ----";
    32 "--------- solve_linear as rootpbl AUTO CompleteHead/Calc ";
    33 "--------- mini-subpbl AUTOCALCULATE CompleteCalc -------";
    34 "--------- mini-subpbl AUTO CompleteCalcHead ------------";
    35 "--------- solve_linear as rootpbl AUTO CompleteModel ---";
    36 "--------- setContext..Thy ------------------------------";
    37 "--------- mini-subpbl AUTOCALC CompleteToSubpbl --------";
    38 "--------- rat-eq + subpbl: no_met, NO solution dropped -";
    39 "--------- tryMatchProblem, tryRefineProblem ------------";
    40 "--------- modifyCalcHead, resetCalcHead, modelProblem --";
    41 "--------- maximum-example, UC: Modeling an example -----";
    42 "--------- solve_linear from pbl-hierarchy --------------";
    43 "--------- solve_linear as in an algebra system (CAS)----";
    44 "--------- interSteps: on 'miniscript with mini-subpbl' -";
    45 "--------- getTactic, fetchApplicableTactics ------------";
    46 "--------- getAssumptions, getAccumulatedAsms -----------";
    47 "--------- arbitrary combinations of steps --------------";
    48 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}right";
    49 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}other";
    50 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}oth 2";
    51 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}NOTok";
    52 "--------- replaceFormula {SOL:MAN:FOR:replace} right----";
    53 "--------- replaceFormula {SOL:MAN:FOR:replace} other----";
    54 "--------- replaceFormula {SOL:MAN:FOR:replace} other 2--";
    55 "--------- replaceFormula {SOL:MAN:FOR:replace} NOTok----";
    56 "--------- UC errpat chain-rule-diff-both, fillpat by input ------";
    57 "--------- UC errpat add-fraction, fillpat by input --------------";
    58 "--------- UC errpat, fillpat step to Rewrite --------------------";
    59 "--------- UC errpat, fillpat step to Rewrite_Set ----------------";
    60 "--------------------------------------------------------";
    61 
    62 "within struct ---------------------------------------------------";
    63 "within struct ---------------------------------------------------";
    64 "within struct ---------------------------------------------------";
    65 (*==================================================================
    66 
    67 
    68 "--------- encode ^ -> ^^^ ------------------------------";
    69 "--------- encode ^ -> ^^^ ------------------------------";
    70 "--------- encode ^ -> ^^^ ------------------------------";
    71 if encode "a^2+b^2=c^2" = "a^^^2+b^^^2=c^^^2" then ()
    72 else error "interface.sml: diff.behav. in encode ^ -> ^^^ ";
    73 
    74 if (decode o encode) "a^2+b^2=c^2" = "a^2+b^2=c^2" then ()
    75 else error "interface.sml: diff.behav. in de/encode ^ <-> ^^^ ";
    76 
    77 ==================================================================*)
    78 "exported from struct --------------------------------------------";
    79 "exported from struct --------------------------------------------";
    80 "exported from struct --------------------------------------------";
    81 
    82 
    83 (*------------ set at startup of the Kernel ----------------------*)
    84 reset_states ();  (*resets all state information in Kernel           *)
    85 (*----------------------------------------------------------------*)
    86 
    87 "--------- empty rootpbl --------------------------------";
    88 "--------- empty rootpbl --------------------------------";
    89 "--------- empty rootpbl --------------------------------";
    90  CalcTree [([], ("", [], []))];
    91  Iterator 1;
    92  moveActiveRoot 1;
    93  refFormula 1 (get_pos 1 1);
    94 (*WN.040222: stoert das sehr, dass e_domID etc. statt leer kommt ???*)
    95 DEconstrCalcTree 1;
    96 
    97 "--------- solve_linear as rootpbl FE -------------------";
    98 "--------- solve_linear as rootpbl FE -------------------";
    99 "--------- solve_linear as rootpbl FE -------------------";
   100  CalcTree      (*start of calculation, return No.1*)
   101      [(["equality (1+-1*2+x=(0::real))", "solveFor x","solutions L"],
   102        ("Test", 
   103 	["LINEAR","univariate","equation","test"],
   104 	["Test","solve_linear"]))];
   105  Iterator 1;     (*create an active Iterator on CalcTree No.1*)
   106  
   107  moveActiveRoot 1;(*sets the CalcIterator No.1 at the root of CalcTree No.1*);
   108  refFormula 1 (get_pos 1 1)  (*gets CalcHead; model is still empty*);
   109  
   110 
   111  fetchProposedTactic 1 (*by using Iterator No.1*);
   112  setNextTactic 1 (Model_Problem); (*by using Iterator No.1*)
   113  autoCalculate' 1 (Step 1);
   114  refFormula 1 (get_pos 1 1)  (*model contains descriptions for all items*);
   115  autoCalculate' 1 (Step 1);
   116 (*-----since Model_Problem + complete_mod_ in case cas of SOME-----*
   117  fetchProposedTactic 1;
   118  setNextTactic 1 (Add_Given "equality (1 + -1 * 2 + x = 0)");
   119  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1); (*equality added*);
   120 
   121  fetchProposedTactic 1;
   122  setNextTactic 1 (Add_Given "solveFor x");
   123  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   124 
   125  fetchProposedTactic 1;
   126  setNextTactic 1 (Add_Find "solutions L");
   127  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   128 
   129  fetchProposedTactic 1;
   130  setNextTactic 1 (Specify_Theory "Test");
   131  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   132 *-----since Model_Problem + complete_mod_ in case cas of SOME-----*)
   133 
   134  fetchProposedTactic 1;
   135  setNextTactic 1 (Specify_Problem ["LINEAR","univariate","equation","test"]);
   136  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   137 (*-------------------------------------------------------------------------*)
   138  fetchProposedTactic 1;
   139  val (ptp as (pt,p), tacis) = get_calc 1; get_pos 1 1;
   140 
   141  setNextTactic 1 (Specify_Method ["Test","solve_linear"]);
   142  val (ptp as (pt,p), tacis) = get_calc 1; get_pos 1 1;
   143 
   144  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   145  val (ptp as (pt,p), tacis) = get_calc 1; get_pos 1 1;
   146 
   147 (*-------------------------------------------------------------------------*)
   148  fetchProposedTactic 1;
   149  val (ptp as (pt,p), tacis) = get_calc 1; get_pos 1 1;
   150 
   151  setNextTactic 1 (Apply_Method ["Test","solve_linear"]);
   152    (*ERROR.110620 <SETNEXTTACTIC>..<MESSAGE> end-of-calculation*)
   153  val (ptp as (pt,p), tacis) = get_calc 1; get_pos 1 1;
   154  is_complete_mod ptp;
   155  is_complete_spec ptp;
   156 
   157  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   158  val (ptp as (pt,p), tacis) = get_calc 1; get_pos 1 1;
   159  (*term2str (get_obj g_form pt [1]);*)
   160 (*-------------------------------------------------------------------------*)
   161 
   162  fetchProposedTactic 1;
   163  setNextTactic 1 (Rewrite_Set_Inst (["(bdv,x)"], "isolate_bdv"));
   164  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   165 
   166  fetchProposedTactic 1;
   167  setNextTactic 1 (Rewrite_Set "Test_simplify");
   168  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   169 
   170  fetchProposedTactic 1;
   171  setNextTactic 1 (Check_Postcond ["LINEAR","univariate","equation","test"]);
   172  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   173 
   174  val ((pt,_),_) = get_calc 1;
   175  val ip = get_pos 1 1;
   176  val (Form f, tac, asms) = pt_extract (pt, ip);
   177      (*exception just above means: 'ModSpec' has been returned: error anyway*)
   178  if term2str f = "[x = 1]" then () else 
   179  error "FE-Kernel-interface.sml: diff.behav. in solve_linear as rootpbl";
   180 
   181 "--------- inspect the CalcTree No.1 with Iterator No.2 -";
   182 "--------- inspect the CalcTree No.1 with Iterator No.2 -";
   183 "--------- inspect the CalcTree No.1 with Iterator No.2 -";
   184 (*WN041118: inspection shifted to Iterator No.1, because others need pos'*)
   185  moveActiveRoot 1; 
   186  refFormula 1 ([],Pbl); getTactic 1 ([],Pbl);(*Error*)
   187  moveActiveDown 1; 
   188  refFormula 1 ([1],Frm); getTactic 1 ([1],Frm);(*Error*)
   189  moveActiveDown 1 ; 
   190  refFormula 1 ([1],Res); getTactic 1 ([1],Res);(*OK*) 
   191  (*getAssumption 1 ([1],Res); TODO.WN041217*)
   192  moveActiveDown 1 ; refFormula 1 ([2],Res);
   193  moveActiveCalcHead 1; refFormula 1 ([],Pbl);
   194  moveActiveDown 1;
   195  moveActiveDown 1;
   196  moveActiveDown 1;
   197  if get_pos 1 1 = ([2], Res) then () else 
   198  error "FE-interface.sml: diff.behav. in a inspect 1 with Iterator 2";
   199  moveActiveDown 1; refFormula 1 ([], Res);
   200  if get_pos 1 1 = ([], Res) then () else 
   201  error "FE-interface.sml: diff.behav. in b inspect 1 with Iterator 2";
   202  moveActiveCalcHead 1; refFormula 1 ([],Pbl);
   203 DEconstrCalcTree 1;
   204 
   205 "--------- miniscript with mini-subpbl ------------------";
   206 "--------- miniscript with mini-subpbl ------------------";
   207 "--------- miniscript with mini-subpbl ------------------";
   208 (*WN120210?not ME:\label{SOLVE:MANUAL:TACTIC:enter} UC 30.3.2.1 p.175 !!!!!NOT IMPL IN FE*)
   209 "=== this sequence of fun-calls resembles fun me ===";
   210  reset_states (); (*start of calculation, return No.1*)
   211  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   212    ("Test", ["sqroot-test","univariate","equation","test"],
   213     ["Test","squ-equ-test-subpbl1"]))];
   214  Iterator 1;
   215 
   216  moveActiveRoot 1; 
   217  refFormula 1 (get_pos 1 1);
   218  fetchProposedTactic 1;
   219  setNextTactic 1 (Model_Problem);
   220  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);(*gets ModSpec;model is still empty*)
   221 
   222  fetchProposedTactic 1;
   223  setNextTactic 1 (Add_Given "equality (x + 1 = 2)");
   224  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   225 
   226  fetchProposedTactic 1;
   227  setNextTactic 1 (Add_Given "solveFor x");
   228  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   229 
   230  fetchProposedTactic 1;
   231  setNextTactic 1 (Add_Find "solutions L");
   232  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   233 
   234  fetchProposedTactic 1;
   235  setNextTactic 1 (Specify_Theory "Test");
   236  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   237 
   238  fetchProposedTactic 1;
   239  setNextTactic 1 (Specify_Problem 
   240 		      ["sqroot-test","univariate","equation","test"]);
   241  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   242 "1-----------------------------------------------------------------";
   243 
   244  fetchProposedTactic 1;
   245  setNextTactic 1 (Specify_Method ["Test","squ-equ-test-subpbl1"]);
   246  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   247 
   248  fetchProposedTactic 1;
   249  setNextTactic 1 (Apply_Method ["Test","squ-equ-test-subpbl1"]);
   250  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   251 
   252  fetchProposedTactic 1;
   253  setNextTactic 1 (Rewrite_Set "norm_equation");
   254  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   255 
   256  fetchProposedTactic 1;
   257  setNextTactic 1 (Rewrite_Set "Test_simplify");
   258  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   259 
   260  fetchProposedTactic 1;(*----------------Subproblem--------------------*);
   261  setNextTactic 1 (Subproblem ("Test",
   262 			      ["LINEAR","univariate","equation","test"]));
   263  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   264 
   265  fetchProposedTactic 1;
   266  setNextTactic 1 (Model_Problem );
   267  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   268 
   269  fetchProposedTactic 1;
   270  setNextTactic 1 (Add_Given "equality (-1 + x = 0)");
   271  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   272 
   273  fetchProposedTactic 1;
   274  setNextTactic 1 (Add_Given "solveFor x");
   275  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   276 
   277  fetchProposedTactic 1;
   278  setNextTactic 1 (Add_Find "solutions x_i");
   279  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   280 
   281  fetchProposedTactic 1;
   282  setNextTactic 1 (Specify_Theory "Test");
   283  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   284 
   285  fetchProposedTactic 1;
   286  setNextTactic 1 (Specify_Problem ["LINEAR","univariate","equation","test"]);
   287  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   288 "2-----------------------------------------------------------------";
   289 
   290  fetchProposedTactic 1;
   291  setNextTactic 1 (Specify_Method ["Test","solve_linear"]);
   292  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   293 
   294  fetchProposedTactic 1;
   295  setNextTactic 1 (Apply_Method ["Test","solve_linear"]);
   296  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   297 
   298  fetchProposedTactic 1;
   299  setNextTactic 1 (Rewrite_Set_Inst (["(bdv,x)"], "isolate_bdv"));
   300  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   301 
   302  fetchProposedTactic 1;
   303  setNextTactic 1 (Rewrite_Set "Test_simplify");
   304  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   305 
   306  fetchProposedTactic 1;
   307  setNextTactic 1 (Check_Postcond ["LINEAR","univariate","equation","test"]);
   308  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   309 
   310  fetchProposedTactic 1;
   311  setNextTactic 1 (Check_elementwise "Assumptions");
   312  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   313 
   314  val xml = fetchProposedTactic 1;
   315  setNextTactic 1 (Check_Postcond 
   316 		      ["sqroot-test","univariate","equation","test"]);
   317  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   318 
   319  val ((pt,_),_) = get_calc 1;
   320  val str = pr_ptree pr_short pt;
   321  writeln str;
   322  val ip = get_pos 1 1;
   323  val (Form f, tac, asms) = pt_extract (pt, ip);
   324      (*exception just above means: 'ModSpec' has been returned: error anyway*)
   325  if term2str f = "[x = 1]" then () else 
   326  error "FE-interface.sml: diff.behav. in miniscript with mini-subpb";
   327  DEconstrCalcTree 1;
   328 
   329 "--------- mini-subpbl AUTOCALCULATE Step 1 -------------";
   330 "--------- mini-subpbl AUTOCALCULATE Step 1 -------------";
   331 "--------- mini-subpbl AUTOCALCULATE Step 1 -------------";
   332 (*WN120210?not ME:\label{SOLVE:AUTO:one} UC 30.3.3.2 p.176*)
   333  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   334    ("Test", ["sqroot-test","univariate","equation","test"],
   335     ["Test","squ-equ-test-subpbl1"]))];
   336  Iterator 1;
   337  moveActiveRoot 1;
   338  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   339  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   340  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   341  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   342  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   343  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   344  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   345  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   346  (*here the solve-phase starts*)
   347  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   348  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   349  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   350  (*------------------------------------*)
   351 (* default_print_depth 13; get_calc 1;
   352    *)
   353  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   354  (*calc-head of subproblem*)
   355  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   356  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   357  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   358  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   359  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   360  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   361  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   362  (*solve-phase of the subproblem*)
   363  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   364  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   365  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   366  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   367  (*finish subproblem*)
   368  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   369  (*finish problem*)
   370  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1); 
   371 
   372  (*this checks the test for correctness..*)
   373  val ((pt,_),_) = get_calc 1;
   374  val p = get_pos 1 1;
   375  val (Form f, tac, asms) = pt_extract (pt, p);
   376  if term2str f = "[x = 1]" andalso p = ([], Res) then () else 
   377  error "FE-interface.sml: diff.behav. in miniscript with mini-subpb";
   378  DEconstrCalcTree 1;
   379 
   380 
   381 "--------- solve_linear as rootpbl AUTO CompleteCalc ----";
   382 "--------- solve_linear as rootpbl AUTO CompleteCalc ----";
   383 "--------- solve_linear as rootpbl AUTO CompleteCalc ----";
   384 (*WN120210?not ME:\label{SPECIFY:START:auto} UC 30.2.4.2 p.174*)
   385  CalcTree
   386      [(["equality (1+-1*2+x=(0::real))", "solveFor x","solutions L"],
   387        ("Test", 
   388 	["LINEAR","univariate","equation","test"],
   389 	["Test","solve_linear"]))];
   390  Iterator 1;
   391  moveActiveRoot 1;
   392 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 999 false;
   393 
   394  autoCalculate' 1 CompleteCalc; 
   395  val (unc, del, gen) = (([],Pbl), ([],Pbl), ([],Res));
   396  getFormulaeFromTo 1 unc gen 1 (*only level 1*) false;
   397 
   398  val ((pt,_),_) = get_calc 1;
   399  val p = get_pos 1 1;
   400  val (Form f, tac, asms) = pt_extract (pt, p);
   401  if term2str f = "[x = 1]" andalso p = ([], Res) then () else 
   402  error "FE-interface.sml: diff.behav. in solve_linear/rt AUTOCALCULATE ";
   403 DEconstrCalcTree 1;
   404 
   405 "--------- solve_linear as rootpbl AUTO CompleteHead/Calc ";
   406 "--------- solve_linear as rootpbl AUTO CompleteHead/Calc ";
   407 "--------- solve_linear as rootpbl AUTO CompleteHead/Calc ";
   408 (* ERROR: error in kernel ?? *)
   409  CalcTree
   410      [(["equality (1+-1*2+x=(0::real))", "solveFor x","solutions L"],
   411        ("Test", 
   412 	["LINEAR","univariate","equation","test"],
   413 	["Test","solve_linear"]))];
   414  Iterator 1;
   415  moveActiveRoot 1;
   416 
   417  autoCalculate' 1 CompleteCalcHead;
   418  refFormula 1 (get_pos 1 1);
   419  val ((pt,p),_) = get_calc 1;
   420 
   421  autoCalculate' 1 CompleteCalc; 
   422  val ((pt,p),_) = get_calc 1;
   423  if p=([], Res) then () else 
   424  error "FE-interface.sml: diff.behav. in solve_linear AUTOC Head/Calc ";
   425 DEconstrCalcTree 1;
   426 
   427 "--------- mini-subpbl AUTOCALCULATE CompleteCalc -------";
   428 "--------- mini-subpbl AUTOCALCULATE CompleteCalc -------";
   429 "--------- mini-subpbl AUTOCALCULATE CompleteCalc -------";
   430 (*WN120210?not ME:\label{SPECIFY:START:auto} UC 30.2.4.2 p.174*)
   431  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   432    ("Test", ["sqroot-test","univariate","equation","test"],
   433     ["Test","squ-equ-test-subpbl1"]))];
   434  Iterator 1;
   435  moveActiveRoot 1;
   436  autoCalculate' 1 CompleteCalc;
   437  val ((pt,p),_) = get_calc 1; show_pt pt;
   438 (*
   439 getTactic 1 ([1],Frm);
   440 getTactic 1 ([1],Res);
   441 initContext 1 Thy_ ([1],Res);
   442 *)
   443  (*... returns calcChangedEvent with*)
   444  val (unc, del, gen) = (([],Pbl), ([],Pbl), ([],Res));
   445  getFormulaeFromTo 1 unc gen 0 (*only result*) false;
   446  getFormulaeFromTo 1 unc gen 1 (*only level 1*) false;
   447  getFormulaeFromTo 1 unc gen 99999 (*all levels*) false;
   448 
   449  val ((pt,_),_) = get_calc 1;
   450  val p = get_pos 1 1;
   451  val (Form f, tac, asms) = pt_extract (pt, p);
   452  if term2str f = "[x = 1]" andalso p = ([], Res) then () else 
   453  error "FE-interface.sml: diff.behav. in mini-subpbl AUTOCALCULATE 6";
   454 DEconstrCalcTree 1;
   455 
   456 "--------- mini-subpbl AUTO CompleteCalcHead ------------";
   457 "--------- mini-subpbl AUTO CompleteCalcHead ------------";
   458 "--------- mini-subpbl AUTO CompleteCalcHead ------------";
   459  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   460    ("Test", ["sqroot-test","univariate","equation","test"],
   461     ["Test","squ-equ-test-subpbl1"]))];
   462  Iterator 1;
   463  moveActiveRoot 1;
   464  autoCalculate' 1 CompleteCalcHead;
   465 
   466 val ((Nd (PblObj {env = NONE, fmz = (fm, ("Test", pblID, metID)), loc = (SOME (env, ctxt1), NONE), 
   467       cell = NONE, ctxt = ctxt2, meth,
   468       spec = ("Test", ["sqroot-test", "univariate", "equation", "test"], 
   469         ["Test", "squ-equ-test-subpbl1"]), 
   470       probl, branch = TransitiveB, origin, ostate = Incomplete, result}, []),
   471    ([], Met)), []) = get_calc 1;
   472 if length meth = 3 andalso length probl = 3 (*just some items tested*) then () 
   473 else error "--- mini-subpbl AUTO CompleteCalcHead ---";
   474 DEconstrCalcTree 1;
   475 
   476 "--------- solve_linear as rootpbl AUTO CompleteModel ---";
   477 "--------- solve_linear as rootpbl AUTO CompleteModel ---";
   478 "--------- solve_linear as rootpbl AUTO CompleteModel ---";
   479  CalcTree
   480      [(["equality (1+-1*2+x=(0::real))", "solveFor x","solutions L"],
   481        ("Test", 
   482 	["LINEAR","univariate","equation","test"],
   483 	["Test","solve_linear"]))];
   484  Iterator 1;
   485  moveActiveRoot 1;
   486  autoCalculate' 1 CompleteModel;  
   487  refFormula 1 (get_pos 1 1);
   488 
   489 setProblem 1 ["LINEAR","univariate","equation","test"];
   490 val pos = get_pos 1 1;
   491 setContext 1 pos (kestoreID2guh Pbl_["LINEAR","univariate","equation","test"]);
   492  refFormula 1 (get_pos 1 1);
   493 
   494 setMethod 1 ["Test","solve_linear"];
   495 setContext 1 pos (kestoreID2guh Met_ ["Test","solve_linear"]);
   496  refFormula 1 (get_pos 1 1);
   497  val ((pt,_),_) = get_calc 1;
   498  if get_obj g_spec pt [] = ("e_domID", 
   499 			    ["LINEAR", "univariate","equation","test"],
   500 			    ["Test","solve_linear"]) then ()
   501  else error "FE-interface.sml: diff.behav. in setProblem, setMethod";
   502 
   503  autoCalculate' 1 CompleteCalcHead;
   504  refFormula 1 (get_pos 1 1); 
   505  autoCalculate' 1 CompleteCalc; 
   506  moveActiveDown 1;
   507  moveActiveDown 1;
   508  moveActiveDown 1;
   509  refFormula 1 (get_pos 1 1); 
   510  val ((pt,_),_) = get_calc 1;
   511  val p = get_pos 1 1;
   512  val (Form f, tac, asms) = pt_extract (pt, p);
   513  if term2str f = "[x = 1]" andalso p = ([], Res) then () else 
   514  error "FE-interface.sml: diff.behav. in mini-subpbl AUTOCALCULATE 6";
   515 DEconstrCalcTree 1;
   516 
   517 "--------- setContext..Thy ------------------------------";
   518 "--------- setContext..Thy ------------------------------";
   519 "--------- setContext..Thy ------------------------------";
   520  reset_states ();
   521  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   522   ("Test", ["sqroot-test","univariate","equation","test"],
   523    ["Test","squ-equ-test-subpbl1"]))];
   524  Iterator 1; moveActiveRoot 1;
   525  autoCalculate' 1 CompleteCalcHead;
   526  autoCalculate' 1 (Step 1);
   527  val ((pt,p),_) = get_calc 1;  show_pt pt; (*2 lines, OK*)
   528  (*
   529  setNextTactic 1 (Rewrite_Set "Test_simplify"); (*--> "thy_isac_Test-rls-Test_simplify"*)
   530  autoCalculate' 1 (Step 1);
   531  val ((pt,p),_) = get_calc 1;  show_pt pt;
   532  *)
   533 "-----^^^^^ and vvvvv do the same -----";
   534  setContext 1 p "thy_isac_Test-rls-Test_simplify";
   535  val ((pt,p),_) = get_calc 1;  show_pt pt; (*2 lines, OK*)
   536 
   537  autoCalculate' 1 (Step 1);
   538  setContext 1 p "thy_isac_Test-rls-Test_simplify";
   539  val (((pt,_),_), p) = (get_calc 1, get_pos 1 1);
   540  val (Form f, tac, asms) = pt_extract (pt, p);
   541  if p = ([1], Res) andalso term2str (get_obj g_res pt (fst p)) = "x + 1 + -1 * 2 = 0"
   542  then () else error "--- setContext..Thy --- autoCalculate' 1 (Step 1) #1";
   543 
   544  autoCalculate' 1 CompleteCalc;
   545  val (((pt,_),_), p) = (get_calc 1, get_pos 1 1);
   546  val (Form f, tac, asms) = pt_extract (pt, p);
   547 
   548  if term2str f = "[x = 1]" andalso p = ([], Res) then () 
   549   else error "--- setContext..Thy --- autoCalculate' CompleteCalc";
   550  DEconstrCalcTree 1;
   551 
   552 "--------- mini-subpbl AUTOCALC CompleteToSubpbl --------";
   553 "--------- mini-subpbl AUTOCALC CompleteToSubpbl --------";
   554 "--------- mini-subpbl AUTOCALC CompleteToSubpbl --------";
   555  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   556    ("Test", ["sqroot-test","univariate","equation","test"],
   557     ["Test","squ-equ-test-subpbl1"]))];
   558  Iterator 1; moveActiveRoot 1;
   559  autoCalculate' 1 CompleteToSubpbl;
   560  refFormula 1 (get_pos 1 1); (*<ISA> -1 + x = 0 </ISA>*);
   561  val ((pt,_),_) = get_calc 1;
   562  val str = pr_ptree pr_short pt;
   563  writeln str;
   564  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n"
   565  then () else 
   566  error "FE-interface.sml: diff.behav. in mini-subpbl CompleteToSubpbl-1";
   567 
   568  autoCalculate' 1 (Step 1); (*proceeds only, of NOT 1 step before subplb*)
   569  autoCalculate' 1 CompleteToSubpbl;
   570  val ((pt,_),_) = get_calc 1;
   571  val str = pr_ptree pr_short pt;
   572  writeln str;
   573  autoCalculate' 1 CompleteCalc; (*das geht ohnehin !*);
   574  val ((pt,_),_) = get_calc 1;
   575  val p = get_pos 1 1;
   576 
   577  val (Form f, tac, asms) = pt_extract (pt, p);
   578  if term2str f = "[x = 1]" andalso p = ([], Res) then () else 
   579  error "FE-interface.sml: diff.behav. in mini-subpbl CompleteToSubpbl 1";
   580 DEconstrCalcTree 1;
   581 
   582 "--------- rat-eq + subpbl: no_met, NO solution dropped -";
   583 "--------- rat-eq + subpbl: no_met, NO solution dropped -";
   584 "--------- rat-eq + subpbl: no_met, NO solution dropped -";
   585  CalcTree
   586  [(["equality ((5*x)/(x - 2) - x/(x+2)=(4::real))", "solveFor x","solutions L"],
   587    ("RatEq", ["univariate","equation"], ["no_met"]))];
   588  Iterator 1;
   589  moveActiveRoot 1; 
   590  fetchProposedTactic 1;
   591 
   592  setNextTactic 1 (Model_Problem);
   593  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   594 
   595  setNextTactic 1 (Specify_Theory "RatEq");
   596  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   597  setNextTactic 1 (Specify_Problem ["rational","univariate","equation"]);
   598  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   599  setNextTactic 1 (Specify_Method ["RatEq","solve_rat_equation"]);
   600  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   601  setNextTactic 1 (Apply_Method ["RatEq","solve_rat_equation"]);
   602  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   603  setNextTactic 1 (Rewrite_Set "RatEq_simplify");
   604  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   605  setNextTactic 1 (Rewrite_Set "norm_Rational");
   606  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   607  setNextTactic 1 (Rewrite_Set "RatEq_eliminate");
   608  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   609  (*               __________ for "12 * x + 4 * x ^^^ 2 = 4 * (-4 + x ^^^ 2)"*)
   610  setNextTactic 1 (Subproblem ("PolyEq", ["normalize","polynomial",
   611 					    "univariate","equation"]));
   612  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   613  setNextTactic 1 (Model_Problem );
   614  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   615  setNextTactic 1 (Specify_Theory "PolyEq");
   616  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   617  setNextTactic 1 (Specify_Problem ["normalize","polynomial",
   618 				   "univariate","equation"]);
   619  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   620  setNextTactic 1 (Specify_Method ["PolyEq","normalize_poly"]);
   621  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   622  setNextTactic 1 (Apply_Method ["PolyEq","normalize_poly"]);
   623  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   624  setNextTactic 1 (Rewrite ("all_left",""));
   625  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   626  setNextTactic 1 (Rewrite_Set_Inst (["(bdv,x)"], "make_ratpoly_in"));
   627  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   628  (*               __________ for "16 + 12 * x = 0"*)
   629  setNextTactic 1 (Subproblem ("PolyEq",
   630 			 ["degree_1","polynomial","univariate","equation"]));
   631  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   632  setNextTactic 1 (Model_Problem );
   633  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   634  setNextTactic 1 (Specify_Theory "PolyEq");
   635  (*------------- some trials in the problem-hierarchy ---------------*)
   636  setNextTactic 1 (Specify_Problem ["LINEAR","univariate","equation"]);
   637  autoCalculate' 1 (Step 1); fetchProposedTactic 1; (*<ERROR> helpless </ERROR> !!!*)
   638  setNextTactic 1 (Refine_Problem ["univariate","equation"]);
   639  (*------------------------------------------------------------------*)
   640  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   641  setNextTactic 1 (Specify_Method ["PolyEq","solve_d1_polyeq_equation"]);
   642  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   643  setNextTactic 1 (Apply_Method ["PolyEq","solve_d1_polyeq_equation"]);
   644  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   645  setNextTactic 1 (Rewrite_Set_Inst (["(bdv,x)"], "d1_polyeq_simplify"));
   646  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   647  setNextTactic 1 (Rewrite_Set "polyeq_simplify");
   648  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   649  setNextTactic 1 Or_to_List;
   650  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   651  setNextTactic 1 (Check_elementwise "Assumptions"); 
   652  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   653  setNextTactic 1 (Check_Postcond ["degree_1","polynomial",
   654 				  "univariate","equation"]);
   655  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   656  setNextTactic 1 (Check_Postcond ["normalize","polynomial",
   657 				  "univariate","equation"]);
   658  autoCalculate' 1 (Step 1); fetchProposedTactic 1;
   659  setNextTactic 1 (Check_Postcond ["rational","univariate","equation"]);
   660  val (ptp,_) = get_calc 1;
   661  val (Form t,_,_) = pt_extract ptp;
   662  if get_pos 1 1 = ([], Res) andalso term2str t = "[x = -4 / 3]" then ()
   663  else writeln "FE-inteface.sml: diff.behav. in rat-eq + subpbl: no_met, NO ..";
   664 DEconstrCalcTree 1;
   665 
   666 "--------- tryMatchProblem, tryRefineProblem ------------";
   667 "--------- tryMatchProblem, tryRefineProblem ------------";
   668 "--------- tryMatchProblem, tryRefineProblem ------------";
   669 (*{\bf\UC{Having \isac{} Refine the Problem
   670  * Automatically}\label{SPECIFY:refine-auto}\\} test match and refine with
   671  * x^^^2 + 4*x + 5 = 2
   672 see isac.bridge.TestSpecify#testMatchRefine*)
   673  CalcTree
   674  [(["equality (x^2 + 4*x + 5 = (2::real))", "solveFor x","solutions L"],
   675    ("Isac", 
   676     ["univariate","equation"],
   677     ["no_met"]))];
   678  Iterator 1;
   679  moveActiveRoot 1; 
   680 
   681  fetchProposedTactic 1;
   682  setNextTactic 1 (Model_Problem );
   683  (*..this tactic should be done 'tacitly', too !*)
   684 
   685 (*
   686 autoCalculate' 1 CompleteCalcHead; 
   687 checkContext 1 ([],Pbl) "pbl_equ_univ";
   688 checkContext 1 ([],Pbl) (kestoreID2guh Pbl_ ["univariate","equation"]);
   689 *)
   690 
   691  autoCalculate' 1 (Step 1); 
   692 
   693  fetchProposedTactic 1;
   694  setNextTactic 1 (Add_Given "equality (x ^^^ 2 + 4 * x + 5 = (2::real))");
   695  autoCalculate' 1 (Step 1); 
   696 
   697  "--------- we go into the ProblemBrowser (_NO_ pblID selected) -";
   698 initContext 1 Pbl_ ([],Pbl);
   699 initContext 1 Met_ ([],Pbl);
   700 
   701  "--------- this match will show some incomplete items: ---------";
   702 
   703 checkContext 1 ([],Pbl) (kestoreID2guh Pbl_ ["univariate","equation"]);
   704 checkContext 1 ([],Pbl) (kestoreID2guh Met_ ["LinEq", "solve_lineq_equation"]);
   705 
   706 
   707  fetchProposedTactic 1;
   708  setNextTactic 1 (Add_Given "solveFor x"); autoCalculate' 1 (Step 1);
   709 
   710  fetchProposedTactic 1;
   711  setNextTactic 1 (Add_Find "solutions L"); autoCalculate' 1 (Step 1);
   712 
   713  "--------- this is a matching model (all items correct): -------";
   714 checkContext 1  ([],Pbl) (kestoreID2guh Pbl_ ["univariate","equation"]);
   715  "--------- this is a NOT matching model (some 'false': ---------";
   716 checkContext 1  ([],Pbl)(kestoreID2guh Pbl_ ["LINEAR","univariate","equation"]);
   717 
   718  "--------- find out a matching problem: ------------------------";
   719  "--------- find out a matching problem (FAILING: no new pbl) ---";
   720  refineProblem 1([],Pbl)(pblID2guh ["LINEAR","univariate","equation"]);
   721 
   722  "--------- find out a matching problem (SUCCESSFUL) ------------";
   723  refineProblem 1 ([],Pbl) (pblID2guh ["univariate","equation"]);
   724 
   725  "--------- tryMatch, tryRefine did not change the calculation -";
   726  "--------- this is done by <TRANSFER> on the pbl-browser: ------";
   727  setNextTactic 1 (Specify_Problem ["normalize","polynomial",
   728 				 "univariate","equation"]);
   729  autoCalculate' 1 (Step 1);
   730 (*WN050904 fetchProposedTactic again --> Specify_Problem ["normalize",...
   731   and Specify_Theory skipped in comparison to below ---^^^-inserted      *)
   732 (*------------vvv-inserted-----------------------------------------------*)
   733  fetchProposedTactic 1;
   734  setNextTactic 1 (Specify_Problem ["normalize","polynomial",
   735 				 "univariate","equation"]);
   736  autoCalculate' 1 (Step 1);
   737 
   738 (*and Specify_Theory skipped by fetchProposedTactic ?!?*)
   739 
   740  fetchProposedTactic 1;
   741  setNextTactic 1 (Specify_Method ["PolyEq","normalize_poly"]);
   742  autoCalculate' 1 (Step 1);
   743 
   744  fetchProposedTactic 1;
   745  setNextTactic 1 (Apply_Method ["PolyEq","normalize_poly"]);
   746 
   747  autoCalculate' 1 CompleteCalc;
   748 
   749  val ((pt,_),_) = get_calc 1;
   750  show_pt pt;
   751  val p = get_pos 1 1;
   752  val (Form f, tac, asms) = pt_extract (pt, p);
   753  if term2str f = "[x = -1, x = -3]" andalso p = ([], Res) then () else 
   754  error "FE-interface.sml: diff.behav. in tryMatchProblem, tryRefine";
   755 
   756 (*------------^^^-inserted-----------------------------------------------*)
   757 (*WN050904 the fetchProposedTactic's below may not have worked like that
   758   before, too, because there was no check*)
   759  fetchProposedTactic 1;
   760  setNextTactic 1 (Specify_Theory "PolyEq");
   761  autoCalculate' 1 (Step 1);
   762 
   763  fetchProposedTactic 1;
   764  setNextTactic 1 (Specify_Method ["PolyEq","normalize_poly"]);
   765  autoCalculate' 1 (Step 1);
   766 
   767  fetchProposedTactic 1;
   768  "--------- now the calc-header is ready for enter 'solving' ----";
   769  autoCalculate' 1 CompleteCalc;
   770 
   771  val ((pt,_),_) = get_calc 1;
   772  rootthy pt;
   773  show_pt pt;
   774  val p = get_pos 1 1;
   775  val (Form f, tac, asms) = pt_extract (pt, p);
   776  if term2str f = "[x = -1, x = -3]" andalso p = ([], Res) then () else 
   777  error "FE-interface.sml: diff.behav. in tryMatchProblem, tryRefine";
   778 
   779 DEconstrCalcTree 1;
   780 
   781 "--------- modifyCalcHead, resetCalcHead, modelProblem --";
   782 "--------- modifyCalcHead, resetCalcHead, modelProblem --";
   783 "--------- modifyCalcHead, resetCalcHead, modelProblem --";
   784  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   785    ("Test", ["sqroot-test","univariate","equation","test"],
   786     ["Test","squ-equ-test-subpbl1"]))];
   787  Iterator 1;
   788  moveActiveRoot 1; 
   789 
   790  modifyCalcHead 1 (([],Pbl),(*the position from refFormula*)
   791 		  "solve (x+1=2, x)",(*the headline*)
   792 		  [Given ["equality (x+1=(2::real))", "solveFor x"],
   793 		   Find ["solutions L"](*,Relate []*)],
   794 		  Pbl, 
   795 		  ("Test", 
   796 		   ["sqroot-test","univariate","equation","test"],
   797 		   ["Test","squ-equ-test-subpbl1"]));
   798  
   799 val ((Nd (PblObj {env = NONE,
   800                   fmz = (fm, tpm),
   801                   loc = (SOME scrst_ctxt, NONE),
   802                   ctxt,
   803                   cell = NONE,
   804                   meth,
   805                   spec = (thy,
   806                           ["sqroot-test", "univariate", "equation", "test"],
   807                           ["Test", "squ-equ-test-subpbl1"]),
   808                   probl,
   809                   branch = TransitiveB,
   810                   origin,
   811                   ostate = Incomplete,
   812                   result},
   813                []),
   814          ([], Pbl)),
   815       []) = get_calc 1;
   816 (*WN110622: is the same as in 2002, but shouldn't be probl = [3 items?]*)
   817 if length meth = 0 andalso length probl = 0 (*just some items tested*) then () 
   818 else error "--- modifyCalcHead, resetCalcHead, modelProblem 1 --";
   819 
   820 resetCalcHead 1;
   821 modelProblem 1;
   822 
   823 get_calc 1;
   824 val ((Nd (PblObj {env = NONE,
   825                   fmz = (fm, tpm),
   826                   loc = (SOME scrst_ctxt, NONE),
   827                   ctxt,
   828                   cell = NONE,
   829                   meth,
   830                   spec = ("e_domID", ["e_pblID"], ["e_metID"]),
   831                   probl,
   832                   branch = TransitiveB,
   833                   origin,
   834                   ostate = Incomplete,
   835                   result},
   836                []),
   837          ([], Pbl)),
   838       []) = get_calc 1;
   839 if length meth = 3 andalso length probl = 3 (*just some items tested*) then () 
   840 else error "--- modifyCalcHead, resetCalcHead, modelProblem 2 --";
   841 
   842 "--------- maximum-example, UC: Modeling an example -----";
   843 "--------- maximum-example, UC: Modeling an example -----";
   844 "--------- maximum-example, UC: Modeling an example -----";
   845 (* {\bf\UC{Editing the Model}\label{SPECIFY:enter}\label{SPECIFY:check}\\}
   846 see isac.bridge.TestModel#testEditItems
   847 *)
   848  val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
   849 	      "relations [A=a*b, (a/2)^2 + (b/2)^2 = r^2]",
   850 	      "relations [A=a*b, (a/2)^2 + (b/2)^2 = r^2]",
   851 	      "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
   852 	      (*^^^ these are the elements for the root-problem (in variants)*)
   853               (*vvv these are elements required for subproblems*)
   854 	      "boundVariable a","boundVariable b","boundVariable alpha",
   855 	      "interval {x::real. 0 <= x & x <= 2*r}",
   856 	      "interval {x::real. 0 <= x & x <= 2*r}",
   857 	      "interval {x::real. 0 <= x & x <= pi}",
   858 	      "errorBound (eps=(0::real))"]
   859  (*specifying is not interesting for this example*)
   860  val spec = ("DiffApp", ["maximum_of","function"], 
   861 	     ["DiffApp","max_by_calculus"]);
   862  (*the empty model with descriptions for user-guidance by Model_Problem*)
   863  val empty_model = [Given ["fixedValues []"],
   864 		    Find ["maximum", "valuesFor"],
   865 		    Relate ["relations []"]]; 
   866  DEconstrCalcTree 1;
   867 
   868 "#################################################################";
   869 
   870  CalcTree [(elems, spec)];
   871  Iterator 1;
   872  moveActiveRoot 1; 
   873  refFormula 1 (get_pos 1 1);
   874  (*this gives a completely empty model*) 
   875 
   876  fetchProposedTactic 1;
   877 (*fill the CalcHead with Descriptions...*)
   878  setNextTactic 1 (Model_Problem );
   879  autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   880 
   881  (*user input is !!!!!EITHER!!!!! _some_ (at least one) items of the model 
   882  !!!!!OR!!!!! _one_ part of the specification !!!!!!!!!!!!!*)
   883  (*input of two items, 'fixedValues [r=Arbfix]' and 'maximum b'...*)
   884  modifyCalcHead 1 (([],Pbl) (*position, from previous refFormula*),
   885 		  "Problem (DiffApp.thy, [maximum_of, function])",
   886 		  (*the head-form ^^^ is not used for input here*)
   887 		  [Given ["fixedValues [r=Arbfix]"(*new input*)],
   888 		   Find ["maximum b"(*new input*), "valuesFor"], 
   889 		   Relate ["relations"]],
   890 		  (*input (Arbfix will dissappear soon)*)
   891 		  Pbl (*belongsto*),
   892 		  e_spec (*no input to the specification*));
   893 
   894  (*the user does not know, what 'superfluous' for 'maximum b' may mean
   895   and asks what to do next*)
   896  fetchProposedTactic 1;
   897  (*the student follows the advice*)
   898  setNextTactic 1 (Add_Find "maximum A"); (*FIXME.17.11.03: does not yet work*)
   899   autoCalculate' 1 (Step 1); refFormula 1 (get_pos 1 1);
   900  
   901  (*this input completes the model*)
   902  modifyCalcHead 1 (([],Pbl), "not used here",
   903 		  [Given ["fixedValues [r=Arbfix]"],
   904 		   Find ["maximum A", "valuesFor [a,b]"(*new input*)], 
   905 		   Relate ["relations [A=a*b, \
   906 			   \(a/2)^2 + (b/2)^2 = r^2]"]], Pbl, e_spec);
   907 
   908  (*specification is not interesting and should be skipped by the dialogguide;
   909    !!!!!!!!!!!!!!!!!!!! input of ONE part at a time !!!!!!!!!!!!!!!!!!!!!!*)
   910  modifyCalcHead 1 (([],Pbl), "not used here",
   911 		  [Given ["fixedValues [r=Arbfix]"],
   912 		   Find ["maximum A", "valuesFor [a,b]"(*new input*)], 
   913 		   Relate ["relations [A=a*b, \
   914 			   \(a/2)^2 + (b/2)^2 = r^2]"]], Pbl, 
   915 		  ("DiffApp", ["e_pblID"], ["e_metID"]));
   916  modifyCalcHead 1 (([],Pbl), "not used here",
   917 		  [Given ["fixedValues [r=Arbfix]"],
   918 		   Find ["maximum A", "valuesFor [a,b]"(*new input*)], 
   919 		   Relate ["relations [A=a*b, \
   920 			   \(a/2)^2 + (b/2)^2 = r^2]"]], Pbl, 
   921 		  ("DiffApp", ["maximum_of","function"], 
   922 		   ["e_metID"]));
   923  modifyCalcHead 1 (([],Pbl), "not used here",
   924 		  [Given ["fixedValues [r=Arbfix]"],
   925 		   Find ["maximum A", "valuesFor [a,b]"(*new input*)], 
   926 		   Relate ["relations [A=a*b, \
   927 			   \(a/2)^2 + (b/2)^2 = r^2]"]], Pbl, 
   928 		  ("DiffApp", ["maximum_of","function"], 
   929 		   ["DiffApp","max_by_calculus"]));
   930  (*this final calcHead now has STATUS 'complete' !*)
   931  DEconstrCalcTree 1;
   932 
   933 "--------- solve_linear from pbl-hierarchy --------------";
   934 "--------- solve_linear from pbl-hierarchy --------------";
   935 "--------- solve_linear from pbl-hierarchy --------------";
   936  val (fmz, sp) = ([], ("", ["LINEAR","univariate","equation","test"], []));
   937  CalcTree [(fmz, sp)];
   938  Iterator 1; moveActiveRoot 1;
   939  refFormula 1 (get_pos 1 1);
   940  modifyCalcHead 1 (([],Pbl),"solve (1+-1*2+x=(0::real))",
   941 		  [Given ["equality (1+-1*2+x=(0::real))", "solveFor x"],
   942 		   Find ["solutions L"]],
   943 		  Pbl, 
   944 		  ("Test", ["LINEAR","univariate","equation","test"],
   945 		   ["Test","solve_linear"]));
   946  autoCalculate' 1 CompleteCalc;
   947  refFormula 1 (get_pos 1 1);
   948  val ((pt,_),_) = get_calc 1;
   949  val p = get_pos 1 1;
   950  val (Form f, tac, asms) = pt_extract (pt, p);
   951  if term2str f = "[x = 1]" andalso p = ([], Res) 
   952    andalso terms2str asms = "[\"matches (?a = ?b) (1 + -1 * 2 + x = 0)\"]" then () 
   953  else error "FE-interface.sml: diff.behav. in from pbl -hierarchy";
   954  DEconstrCalcTree 1;
   955 
   956 "--------- solve_linear as in an algebra system (CAS)----";
   957 "--------- solve_linear as in an algebra system (CAS)----";
   958 "--------- solve_linear as in an algebra system (CAS)----";
   959 (*WN120210?not ME:\label{UC:cas-input} UC 30.1.2.5 p.168*)
   960  val (fmz, sp) = ([], ("", [], []));
   961  CalcTree [(fmz, sp)];
   962  Iterator 1; moveActiveRoot 1;
   963  modifyCalcHead 1 (([],Pbl),"solveTest (1+-1*2+x=0,x)", [], Pbl, ("", [], []));
   964  autoCalculate' 1 CompleteCalc;
   965  refFormula 1 (get_pos 1 1);
   966  val ((pt,_),_) = get_calc 1;
   967  val p = get_pos 1 1;
   968  val (Form f, tac, asms) = pt_extract (pt, p);
   969  if term2str f = "[x = 1]" andalso p = ([], Res) 
   970    andalso terms2str asms = "[\"matches (?a = ?b) (1 + -1 * 2 + x = 0)\"]" then () 
   971  else error "FE-interface.sml: diff.behav. in from pbl -hierarchy";
   972 DEconstrCalcTree 1;
   973 
   974 "--------- interSteps: on 'miniscript with mini-subpbl' -";
   975 "--------- interSteps: on 'miniscript with mini-subpbl' -";
   976 "--------- interSteps: on 'miniscript with mini-subpbl' -";
   977  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   978    ("Test", ["sqroot-test","univariate","equation","test"],
   979     ["Test","squ-equ-test-subpbl1"]))];
   980  Iterator 1;
   981  moveActiveRoot 1;
   982  autoCalculate' 1 CompleteCalc; 
   983  val ((pt,_),_) = get_calc 1;
   984  show_pt pt;
   985 
   986  (*UC\label{UC:inter-steps} UC 30.3.5.5 p.178*)
   987  interSteps 1 ([2],Res);
   988  val ((pt,_),_) = get_calc 1; show_pt pt (*new ([2,1],Frm)..([2,6],Res)*);
   989  val (unc, del, gen) = (([1],Res),([1],Res),([2,6],Res));
   990  getFormulaeFromTo 1 unc gen 1 false; 
   991 
   992  (*UC\label{UC:inter-steps} UC 30.3.5.5 p.178*)
   993  interSteps 1 ([3,2],Res);
   994  val ((pt,_),_) = get_calc 1; show_pt pt (*new ([3,2,1],Frm)..([3,2,2],Res)*);
   995  val (unc, del, gen) = (([3,1],Res),([3,1],Res),([3,2,2],Res));
   996  getFormulaeFromTo 1 unc gen 1 false; 
   997 
   998  (*UC\label{UC:inter-steps} UC 30.3.5.5 p.178*)
   999  interSteps 1 ([3],Res)  (*no new steps in subproblems*);
  1000  val (unc, del, gen) = (([3],Pbl),([3],Pbl),([3,2],Res));
  1001  getFormulaeFromTo 1 unc gen 1 false; 
  1002 
  1003  (*UC\label{UC:inter-steps} UC 30.3.5.5 p.178*)
  1004  interSteps 1 ([],Res)  (*no new steps in subproblems*);
  1005  val (unc, del, gen) = (([],Pbl),([],Pbl),([4],Res));
  1006  getFormulaeFromTo 1 unc gen 1 false; 
  1007 DEconstrCalcTree 1;
  1008 
  1009 "--------- getTactic, fetchApplicableTactics ------------";
  1010 "--------- getTactic, fetchApplicableTactics ------------";
  1011 "--------- getTactic, fetchApplicableTactics ------------";
  1012 (* compare test/../script.sml
  1013 "----------- fun sel_rules ---------------------------------------";
  1014 *)
  1015  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
  1016    ("Test", ["sqroot-test","univariate","equation","test"],
  1017     ["Test","squ-equ-test-subpbl1"]))];
  1018  Iterator 1; moveActiveRoot 1;
  1019  autoCalculate' 1 CompleteCalc;
  1020  val ((pt,_),_) = get_calc 1;
  1021  show_pt pt;
  1022 
  1023  (*UC\label{SOLVE:HIDE:getTactic} \label{SOLVE:AUTO:tactic} UC 30.3.3.1 p.176
  1024 WN120210 not impl. in FE*)
  1025  getTactic 1 ([],Pbl);
  1026  getTactic 1 ([1],Res);
  1027  getTactic 1 ([3],Pbl);
  1028  getTactic 1 ([3,1],Frm);
  1029  getTactic 1 ([3],Res);
  1030  getTactic 1 ([],Res);
  1031 
  1032 (*UC\label{SOLVE:MANUAL:TACTIC:listall} UC 30.3.2.2 p.175*)
  1033  fetchApplicableTactics 1 99999 ([],Pbl);
  1034  fetchApplicableTactics 1 99999 ([1],Res);
  1035  fetchApplicableTactics 1 99999 ([3],Pbl);
  1036  fetchApplicableTactics 1 99999 ([3,1],Res);
  1037  fetchApplicableTactics 1 99999 ([3],Res);
  1038  fetchApplicableTactics 1 99999 ([],Res);
  1039 DEconstrCalcTree 1;
  1040 
  1041 "--------- getAssumptions, getAccumulatedAsms -----------";
  1042 "--------- getAssumptions, getAccumulatedAsms -----------";
  1043 "--------- getAssumptions, getAccumulatedAsms -----------";
  1044 CalcTree
  1045 [(["equality (x/(x^2 - 6*x+9) - 1/(x^2 - 3*x) =1/x)",
  1046 	   "solveFor x","solutions L"], 
  1047   ("RatEq",["univariate","equation"],["no_met"]))];
  1048 Iterator 1; moveActiveRoot 1;
  1049 autoCalculate' 1 CompleteCalc; 
  1050 val ((pt,_),_) = get_calc 1;
  1051 val p = get_pos 1 1;
  1052 val (Form f, tac, asms) = pt_extract (pt, p);
  1053 (*============ inhibit exn WN120316 compare 2002--2011 ===========================
  1054 if map term2str asms = 
  1055  ["True |\n~ lhs ((3 + -1 * x + x ^^^ 2) * x =\n" ^
  1056   "       1 * (9 * x + -6 * x ^^^ 2 + x ^^^ 3)) is_poly_in x", "-6 * x + 5 * x ^^^ 2 = 0", 
  1057   "lhs (-6 * x + 5 * x ^^^ 2 = 0) is_poly_in x",
  1058   "lhs (-6 * x + 5 * x ^^^ 2 = 0) has_degree_in x = 2", 
  1059   "9 * x + -6 * x ^^^ 2 + x ^^^ 3 ~= 0"] 
  1060 andalso term2str f = "[-6 * x + 5 * x ^^^ 2 = 0]" andalso p = ([], Res) then ()
  1061 else error "TODO compare 2002--2011"; (*...data during test --- x / (x ^ 2 - 6 * x + 9) - 1...*)
  1062 ============ inhibit exn WN120316 compare 2002--2011 ===========================*)
  1063 if p = ([], Res) andalso term2str f = "[]" (*see WN120317.TODO dropped rateq*)
  1064 andalso asms = [] (*STRANGE!, compare test --- x / (x ^ 2 - 6 * x + 9) - 1 / (x ^ 2 ...*)
  1065 then () else error "rlang.sml: diff.behav. in  Schalk I s.87 Bsp 55b [x = 6 / 5]";
  1066 
  1067 (*UC\label{SOLVE:HELP:assumptions} UC 30.3.5.1 p.178*)
  1068 getAssumptions 1 ([3], Res);
  1069 getAssumptions 1 ([5], Res);
  1070 (*UC\label{SOLVE:HELP:assumptions-origin} UC 30.3.5.2 p.178
  1071   WN0502 still without positions*)
  1072 getAccumulatedAsms 1 ([3], Res);
  1073 getAccumulatedAsms 1 ([5], Res);
  1074 DEconstrCalcTree 1;
  1075 
  1076 "--------- arbitrary combinations of steps --------------";
  1077 "--------- arbitrary combinations of steps --------------";
  1078 "--------- arbitrary combinations of steps --------------";
  1079  CalcTree      (*start of calculation, return No.1*)
  1080      [(["equality (1+-1*2+x=(0::real))", "solveFor x","solutions L"],
  1081        ("Test", 
  1082 	["LINEAR","univariate","equation","test"],
  1083 	["Test","solve_linear"]))];
  1084  Iterator 1; moveActiveRoot 1;
  1085 
  1086  fetchProposedTactic 1;
  1087              (*ERROR get_calc 1 not existent*)
  1088  setNextTactic 1 (Model_Problem );
  1089  autoCalculate' 1 (Step 1); 
  1090  fetchProposedTactic 1;
  1091  fetchProposedTactic 1;
  1092 
  1093  setNextTactic 1 (Add_Find "solutions L");
  1094  setNextTactic 1 (Add_Find "solutions L");
  1095 
  1096  autoCalculate' 1 (Step 1); 
  1097  autoCalculate' 1 (Step 1); 
  1098 
  1099  setNextTactic 1 (Specify_Theory "Test");
  1100  fetchProposedTactic 1;
  1101  autoCalculate' 1 (Step 1); 
  1102 
  1103  autoCalculate' 1 (Step 1); 
  1104  autoCalculate' 1 (Step 1); 
  1105  autoCalculate' 1 (Step 1); 
  1106  autoCalculate' 1 (Step 1); 
  1107 (*------------------------- end calc-head*)
  1108 
  1109  fetchProposedTactic 1;
  1110  setNextTactic 1 (Rewrite_Set_Inst (["(bdv,x)"], "isolate_bdv"));
  1111  autoCalculate' 1 (Step 1); 
  1112 
  1113  setNextTactic 1 (Rewrite_Set "Test_simplify");
  1114  fetchProposedTactic 1;
  1115  autoCalculate' 1 (Step 1); 
  1116 
  1117  autoCalculate' 1 CompleteCalc; 
  1118  val ((pt,_),_) = get_calc 1;
  1119  val p = get_pos 1 1;
  1120  val (Form f, tac, asms) = pt_extract (pt, p);
  1121  if term2str f = "[x = 1]" andalso p = ([], Res) then () else 
  1122  error "FE-interface.sml: diff.behav. in combinations of steps";
  1123 DEconstrCalcTree 1;
  1124 
  1125 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}right"; (*UC 30.3.2.4 p.175*)
  1126 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}right";
  1127 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}right";
  1128  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
  1129    ("Test", ["sqroot-test","univariate","equation","test"],
  1130     ["Test","squ-equ-test-subpbl1"]))];
  1131  Iterator 1;
  1132  moveActiveRoot 1;
  1133  autoCalculate' 1 CompleteCalcHead;
  1134  autoCalculate' 1 (Step 1);
  1135  autoCalculate' 1 (Step 1);
  1136  appendFormula 1 "-1 + x = 0" (*|> Future.join*);
  1137  (*... returns calcChangedEvent with*)
  1138  val (unc, del, gen) = (([1],Res), ([1],Res), ([2],Res));
  1139  getFormulaeFromTo 1 unc gen 99999 (*all levels*) false;
  1140 
  1141  val ((pt,_),_) = get_calc 1;
  1142  val p = get_pos 1 1;
  1143  val (Form f, tac, asms) = pt_extract (pt, p);
  1144  if term2str f = "-1 + x = 0" andalso p = ([2], Res) then () else 
  1145  error "FE-interface.sml: diff.behav. in FORMULA:enter} right";
  1146 DEconstrCalcTree 1;
  1147 
  1148 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}other"; (*UC 30.3.2.4 p.175*)
  1149 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}other";
  1150 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}other";
  1151  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
  1152    ("Test", ["sqroot-test","univariate","equation","test"],
  1153     ["Test","squ-equ-test-subpbl1"]))];
  1154  Iterator 1;
  1155  moveActiveRoot 1;
  1156  autoCalculate' 1 CompleteCalcHead;
  1157  autoCalculate' 1 (Step 1);
  1158  autoCalculate' 1 (Step 1);
  1159  appendFormula 1 "x - 1 = 0" (*|> Future.join*);
  1160  val (unc, del, gen) = (([1],Res), ([1],Res), ([2],Res));
  1161  getFormulaeFromTo 1 unc gen 99999 (*all levels*) false;
  1162  (*11 elements !!!*)
  1163 
  1164  val ((pt,_),_) = get_calc 1;
  1165  val p = get_pos 1 1;
  1166  val (Form f, tac, asms) = pt_extract (pt, p);
  1167  if term2str f = "x - 1 = 0" andalso p = ([2], Res) then () else 
  1168  error "FE-interface.sml: diff.behav. in FORMULA:enter} other";
  1169 DEconstrCalcTree 1;
  1170 
  1171 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}oth 2"; (*UC 30.3.2.4 p.175*)
  1172 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}oth 2";
  1173 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}oth 2";
  1174  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
  1175    ("Test", ["sqroot-test","univariate","equation","test"],
  1176     ["Test","squ-equ-test-subpbl1"]))];
  1177  Iterator 1;
  1178  moveActiveRoot 1;
  1179  autoCalculate' 1 CompleteCalcHead;
  1180  autoCalculate' 1 (Step 1);
  1181  autoCalculate' 1 (Step 1);
  1182  appendFormula 1 "x = 1" (*|> Future.join*);
  1183  (*... returns calcChangedEvent with*)
  1184  val (unc, del, gen) = (([1],Res), ([1],Res), ([3,2],Res));
  1185  getFormulaeFromTo 1 unc gen 99999 (*all levels*) false;
  1186  (*6 elements !!!*)
  1187 
  1188  val ((pt,_),_) = get_calc 1;
  1189  val p = get_pos 1 1;
  1190  val (Form f, tac, asms) = pt_extract (pt, p);
  1191  if term2str f = "x = 1" andalso p = ([3,2], Res) then () else 
  1192  error "FE-interface.sml: diff.behav. in FORMULA:enter} oth 2";
  1193 DEconstrCalcTree 1;
  1194 
  1195 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}NOTok"; (*UC 30.3.2.4 p.175*)
  1196 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}NOTok";
  1197 "--------- appendF label{SOLVE:MANUAL:FORMULA:enter}NOTok";
  1198  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
  1199    ("Test", ["sqroot-test","univariate","equation","test"],
  1200     ["Test","squ-equ-test-subpbl1"]))];
  1201  Iterator 1;
  1202  moveActiveRoot 1;
  1203  autoCalculate' 1 CompleteCalcHead;
  1204  autoCalculate' 1 (Step 1);
  1205  autoCalculate' 1 (Step 1);
  1206  appendFormula 1 "x - 4711 = 0" (*|> Future.join*);
  1207  (*... returns <ERROR> no derivation found </ERROR>*)
  1208 
  1209  val ((pt,_),_) = get_calc 1;
  1210  val p = get_pos 1 1;
  1211  val (Form f, tac, asms) = pt_extract (pt, p);
  1212  if term2str f = "x + 1 + -1 * 2 = 0" andalso p = ([1], Res) then () else 
  1213  error "FE-interface.sml: diff.behav. in FORMULA:enter} NOTok";
  1214 DEconstrCalcTree 1;
  1215 
  1216 "--------- replaceFormula {SOL:MAN:FOR:replace} right----"; (*UC 30.3.2.5 p.176*)
  1217 "--------- replaceFormula {SOL:MAN:FOR:replace} right----";
  1218 "--------- replaceFormula {SOL:MAN:FOR:replace} right----";
  1219 (*\label{SOLVE:MANUAL:FORMULA:replace}*)
  1220  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
  1221    ("Test", ["sqroot-test","univariate","equation","test"],
  1222     ["Test","squ-equ-test-subpbl1"]))];
  1223  Iterator 1;
  1224  moveActiveRoot 1;
  1225  autoCalculate' 1 CompleteCalc;
  1226  moveActiveFormula 1 ([2],Res);
  1227  replaceFormula 1 "-1 + x = 0" (*i.e. repeats input*);
  1228  (*... returns <ERROR> formula not changed </ERROR>*)
  1229 
  1230  val ((pt,_),_) = get_calc 1;
  1231  val p = get_pos 1 1;
  1232  val (Form f, tac, asms) = pt_extract (pt, p);
  1233  if term2str f = "-1 + x = 0" andalso p = ([2], Res) then () else 
  1234  error "FE-interface.sml: diff.behav. in FORMULA:replace} right 1";
  1235  if map fst (get_interval ([2],Res) ([],Res) 9999 pt) = 
  1236     [([2], Res), ([3], Pbl), ([3, 1], Frm), ([3, 1], Res), ([3, 2], Res),
  1237      ([3], Res), ([4], Res), ([], Res)] then () (*nothing deleted!*) else
  1238  error "FE-interface.sml: diff.behav. in FORMULA:replace} right 2";
  1239 
  1240 (*WN050211 replaceFormula didn't work on second ctree: thus now tested...*)
  1241  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
  1242    ("Test", ["sqroot-test","univariate","equation","test"],
  1243     ["Test","squ-equ-test-subpbl1"]))];
  1244  Iterator 2;
  1245  moveActiveRoot 2;
  1246  autoCalculate' 2 CompleteCalc;
  1247  moveActiveFormula 2 ([2],Res);
  1248  replaceFormula 2 "-1 + x = 0" (*i.e. repeats input*);
  1249  (*... returns <ERROR> formula not changed </ERROR>*)
  1250 
  1251  val ((pt,_),_) = get_calc 2;
  1252  val p = get_pos 2 1;
  1253  val (Form f, tac, asms) = pt_extract (pt, p);
  1254  if term2str f = "-1 + x = 0" andalso p = ([2], Res) then () else 
  1255  error "FE-interface.sml: diff.behav. in FORMULA:replace} right 1";
  1256  if map fst (get_interval ([2],Res) ([],Res) 9999 pt) = 
  1257     [([2], Res), ([3], Pbl), ([3, 1], Frm), ([3, 1], Res), ([3, 2], Res),
  1258      ([3], Res), ([4], Res), ([], Res)] then () (*nothing deleted!*) else
  1259  error "FE-interface.sml: diff.behav. in FORMULA:replace} right 2b";
  1260 DEconstrCalcTree 1;
  1261 
  1262 "--------- replaceFormula {SOL:MAN:FOR:replace} other----"; (*UC 30.3.2.5 p.176*)
  1263 "--------- replaceFormula {SOL:MAN:FOR:replace} other----";
  1264 "--------- replaceFormula {SOL:MAN:FOR:replace} other----";
  1265 (*\label{SOLVE:MANUAL:FORMULA:replace}*)
  1266  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
  1267    ("Test", ["sqroot-test","univariate","equation","test"],
  1268     ["Test","squ-equ-test-subpbl1"]))];
  1269  Iterator 1;
  1270  moveActiveRoot 1;
  1271  autoCalculate' 1 CompleteCalc;
  1272  moveActiveFormula 1 ([2],Res); (*there is "-1 + x = 0"*)
  1273  replaceFormula 1 "x - 1 = 0"; (*<-------------------------------------*)
  1274  (*... returns calcChangedEvent with*)
  1275  val (unc, del, gen) = (([1],Res), ([4],Res), ([2],Res));
  1276  getFormulaeFromTo 1 unc gen 99999 (*all levels*) false;
  1277 
  1278  val ((pt,_),_) = get_calc 1;
  1279  show_pt pt;
  1280  val p = get_pos 1 1;
  1281  val (Form f, tac, asms) = pt_extract (pt, p);
  1282  if term2str f = "x - 1 = 0" andalso p = ([2], Res) then () else 
  1283  error "FE-interface.sml: diff.behav. in FORMULA:replace} other 1";
  1284 (* for getting the list in whole length ...
  1285 default_print_depth 99;map fst (get_interval ([1],Res) ([],Res) 9999 pt);default_print_depth 3;
  1286    *)
  1287  if map fst (get_interval ([1],Res) ([],Res) 9999 pt) = 
  1288     [([1], Res), ([2, 1], Frm), ([2, 1], Res), ([2, 2], Res), ([2, 3], Res),
  1289       ([2, 4], Res), ([2, 5], Res), ([2, 6], Res), ([2, 7], Res),
  1290       ([2, 8], Res), ([2, 9], Res), ([2], Res)
  1291 (*WN060727 {cutlevup->test_trans} removed: , 
  1292       ([], Res)(*dropped, if test_trans doesnt stop at PblNd*)*)] then () else
  1293  error "FE-interface.sml: diff.behav. in FORMULA:replace} other 2";
  1294 DEconstrCalcTree 1;
  1295 
  1296 "--------- replaceFormula {SOL:MAN:FOR:replace} other 2--"; (*UC 30.3.2.5 p.176*)
  1297 "--------- replaceFormula {SOL:MAN:FOR:replace} other 2--";
  1298 "--------- replaceFormula {SOL:MAN:FOR:replace} other 2--";
  1299 (*\label{SOLVE:MANUAL:FORMULA:replace}*)
  1300  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
  1301    ("Test", ["sqroot-test","univariate","equation","test"],
  1302     ["Test","squ-equ-test-subpbl1"]))];
  1303  Iterator 1;
  1304  moveActiveRoot 1;
  1305  autoCalculate' 1 CompleteCalc;
  1306  moveActiveFormula 1 ([2],Res); (*there is "-1 + x = 0"*)
  1307  replaceFormula 1 "x = 1"; (*<-------------------------------------*)
  1308  (*... returns calcChangedEvent with ...*)
  1309  val (unc, del, gen) = (([1],Res), ([4],Res), ([3,2],Res));
  1310  getFormulaeFromTo 1 unc gen 99999 (*all levels*) false;
  1311  (*9 elements !!!*)
  1312 
  1313  val ((pt,_),_) = get_calc 1;
  1314  show_pt pt; (*error: ...get_interval drops ([3,2],Res) ...*)
  1315  val (t,_) = get_obj g_result pt [3,2]; term2str t;
  1316   if map fst (get_interval ([1],Res) ([],Res) 9999 pt) = 
  1317     [([1], Res), ([2], Res), ([3], Pbl), ([3, 1], Frm), ([3, 1], Res),
  1318       ([3, 2, 1], Frm), ([3, 2, 1], Res), ([3, 2, 2], Res), 
  1319       ([3,2],Res)] then () else
  1320  error "FE-interface.sml: diff.behav. in FORMULA:replace} oth2 1";
  1321 
  1322  val p = get_pos 1 1;
  1323  val (Form f, tac, asms) = pt_extract (pt, p);
  1324  if term2str f = "x = 1" andalso p = ([3,2], Res) then () else 
  1325  error "FE-interface.sml: diff.behav. in FORMULA:replace} oth2 2";
  1326 DEconstrCalcTree 1;
  1327 
  1328 "--------- replaceFormula {SOL:MAN:FOR:replace} NOTok----"; (*UC 30.3.2.5 p.176*)
  1329 "--------- replaceFormula {SOL:MAN:FOR:replace} NOTok----";
  1330 "--------- replaceFormula {SOL:MAN:FOR:replace} NOTok----";
  1331 (*\label{SOLVE:MANUAL:FORMULA:replace}*)
  1332  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
  1333    ("Test", ["sqroot-test","univariate","equation","test"],
  1334     ["Test","squ-equ-test-subpbl1"]))];
  1335  Iterator 1;
  1336  moveActiveRoot 1;
  1337  autoCalculate' 1 CompleteCalc;
  1338  moveActiveFormula 1 ([2],Res); (*there is "-1 + x = 0"*)
  1339  replaceFormula 1 "x - 4711 = 0"; 
  1340  (*... returns <ERROR> no derivation found </ERROR>*)
  1341 
  1342  val ((pt,_),_) = get_calc 1;
  1343  show_pt pt;
  1344  val p = get_pos 1 1;
  1345  val (Form f, tac, asms) = pt_extract (pt, p);
  1346  if term2str f = "-1 + x = 0" andalso p = ([2], Res) then () else 
  1347  error "FE-interface.sml: diff.behav. in FORMULA:replace} NOTok";
  1348 DEconstrCalcTree 1;
  1349 
  1350 "--------- UC errpat chain-rule-diff-both, fillpat by input ------";
  1351 "--------- UC errpat chain-rule-diff-both, fillpat by input ------";
  1352 "--------- UC errpat chain-rule-diff-both, fillpat by input ------";
  1353 reset_states ();
  1354 CalcTree
  1355 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
  1356   ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
  1357 Iterator 1;
  1358 moveActiveRoot 1;
  1359 autoCalculate' 1 CompleteCalcHead;
  1360 autoCalculate' 1 (Step 1);
  1361 autoCalculate' 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
  1362 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)" (*|> Future.join*); (*<<<<<<<=========================*)
  1363 (* the check for errpat is maximally liberal (whole term modulo "nrls" from "type met"),
  1364   would recognize "cos (4 * x ^ (4 - 1)) + 2 * x" as well.
  1365   results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
  1366   instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
  1367   val ((pt,pos), _) = get_calc 1;
  1368   val p = get_pos 1 1;
  1369   val (Form f, _, asms) = pt_extract (pt, p);
  1370 
  1371   if p = ([1], Res) andalso term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
  1372     get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], 
  1373       ("diff_sum", "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v"))
  1374   then () else error "embed fun get_fillform changed 1";
  1375 
  1376 (*========== inhibit exn WN1130621 Isabelle2012-->13 !thehier! ====================
  1377 findFillpatterns 1 "chain-rule-diff-both"; (*<<<<<<<=================================*)
  1378 (*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =
  1379   d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
  1380   val ((pt,pos),_) = get_calc 1;
  1381   val p = get_pos 1 1;
  1382 
  1383   val (Form f, _, asms) = pt_extract (pt, p);
  1384   if p = ([1], Res) andalso term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
  1385     get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], ("diff_sum", "Diff.diff_sum"(*?!?*)))
  1386   then ()
  1387   else error "embed fun get_fillform changed 2";
  1388 
  1389 (* if we assume, that the fill-patterns are ordered such that the 1st has large gaps
  1390    and the last has no gaps, then the number of fill-patterns would suffice
  1391    for the DialogGuide to select appropriately. *)
  1392 requestFillformula 1 ("chain-rule-diff-both", "fill-both-args");(*<<<<<<<============*)
  1393   (*<AUTOCALC> ([1], Res) ([2], Res) ([2], Res) </AUTOCALC>*)
  1394   val ((pt,pos),_) = get_calc 1;
  1395   val p = get_pos 1 1;
  1396   val (Form f, _, asms) = pt_extract (pt, p);
  1397   if p = ([1], Res) andalso existpt [2] pt andalso
  1398     term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
  1399     get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], ("diff_sum", "Diff.diff_sum"))
  1400   then () else error "embed fun get_fillform changed 3";
  1401 
  1402 inputFillFormula 1 "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)";(*<<<<<<<=====*)
  1403   val ((pt, _),_) = get_calc 1;
  1404   val p = get_pos 1 1;
  1405   val (Form f, _, asms) = pt_extract (pt, p);
  1406   if p = ([2], Res) andalso
  1407     term2str f = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)" andalso
  1408     get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], ("diff_sin_chain", ""))
  1409   then () else error "inputFillFormula changed 11";
  1410 
  1411 autoCalculate' 1 CompleteCalc;
  1412 
  1413 "~~~~~ final check: the input formula is inserted as it would have been correct from beginning";
  1414 val ((pt, _),_) = get_calc 1;
  1415 val p = get_pos 1 1;
  1416 val (Form f, _, asms) = pt_extract (pt, p);
  1417 if p = ([], Res) andalso term2str f = "2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3"
  1418 then () else error "inputFillFormula changed 12";
  1419 show_pt pt;
  1420 (*[
  1421 (([], Frm), Diff (x ^^^ 2 + sin (x ^^^ 4), x)),
  1422 (([1], Frm), d_d x (x ^^^ 2 + sin (x ^^^ 4))),
  1423 (([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))),
  1424 (([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)),       (*<<<<<<<=====*)
  1425 (([3], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * (4 * x ^^^ (4 - 1))),
  1426 (([4], Res), 2 * x ^^^ (2 - 1) + cos (x ^^^ 4) * (4 * x ^^^ (4 - 1))),
  1427 (([5], Res), 2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3),
  1428 (([], Res), 2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3)] *)
  1429 ============ inhibit exn WN1130621 Isabelle2012-->13 !thehier! ==================*)
  1430 
  1431 "--------- UC errpat add-fraction, fillpat by input --------------";
  1432 "--------- UC errpat add-fraction, fillpat by input --------------";
  1433 "--------- UC errpat add-fraction, fillpat by input --------------";
  1434 (*cp from BridgeLog Java <=> SML*)
  1435 reset_states ();
  1436 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
  1437 Iterator 1;
  1438 moveActiveRoot 1;
  1439 moveActiveFormula 1 ([],Pbl);
  1440 replaceFormula 1 "Simplify (5 * x / (4 * y) + 3 * x / (4 * y))";
  1441 autoCalculate' 1 CompleteCalcHead;
  1442 autoCalculate' 1 (Step 1);
  1443 appendFormula 1 "8 * x / (8 * y)" (*|> Future.join*);
  1444 (*<CALCMESSAGE> no derivation found </CALCMESSAGE> 
  1445 --- but in BridgeLog Java <=> SML:
  1446 <CALCMESSAGE> error pattern #addition-of-fractions# </CALCMESSAGE>*)
  1447 
  1448 "--------- UC errpat, fillpat step to Rewrite --------------------";
  1449 "--------- UC errpat, fillpat step to Rewrite --------------------";
  1450 "--------- UC errpat, fillpat step to Rewrite --------------------";
  1451 (*TODO*)
  1452 reset_states ();
  1453 CalcTree
  1454 [(["functionTerm ((x ^ 2) ^ 3 + sin (x ^ 4))",
  1455    "differentiateFor x", "derivative f_f'"], 
  1456   ("Isac", ["derivative_of","function"],
  1457   ["diff","differentiate_on_R"]))]; (*<<<======= EP is directly in script*)
  1458 Iterator 1;
  1459 moveActiveRoot 1;
  1460 autoCalculate' 1 CompleteCalc;
  1461 val ((pt,p),_) = get_calc 1; show_pt pt;
  1462 
  1463 "--------- UC errpat, fillpat step to Rewrite_Set ----------------";
  1464 "--------- UC errpat, fillpat step to Rewrite_Set ----------------";
  1465 "--------- UC errpat, fillpat step to Rewrite_Set ----------------";
  1466 reset_states ();
  1467 CalcTree
  1468 [(["functionTerm ((x ^ 2) ^ 3 + sin (x ^ 4))",
  1469    "differentiateFor x", "derivative f_f'"], 
  1470   ("Isac", ["derivative_of","function"],
  1471   ["diff","after_simplification"]))]; (*<<<======= EP is in a ruleset*)
  1472 Iterator 1;
  1473 moveActiveRoot 1;
  1474 autoCalculate' 1 CompleteCalcHead;
  1475 autoCalculate' 1 (Step 1); fetchProposedTactic 1;
  1476 autoCalculate' 1 (Step 1); fetchProposedTactic 1;
  1477 (*
  1478 <NEXTTAC>
  1479   <CALCID> 1 </CALCID>
  1480   <TACTICERRORPATTERNS>
  1481     <STRINGLIST>
  1482       <STRING> chain-rule-diff-both </STRING>
  1483       <STRING> cancel </STRING>
  1484     </STRINGLIST>
  1485     <REWRITESETINSTTACTIC name="Rewrite_Set_Inst">
  1486       <RULESET> norm_diff </RULESET>
  1487       <SUBSTITUTION>
  1488         <PAIR>
  1489           <VARIABLE>
  1490             <MATHML>
  1491               <ISA> bdv </ISA>
  1492             </MATHML>
  1493           </VARIABLE>
  1494           <VALUE>
  1495             <MATHML>
  1496               <ISA> x </ISA>
  1497             </MATHML>
  1498           </VALUE>
  1499         </PAIR>
  1500       </SUBSTITUTION>
  1501     </REWRITESETINSTTACTIC>
  1502   </TACTICERRORPATTERNS>
  1503 </NEXTTAC>
  1504 
  1505 
  1506 (*WN1208 postponed due to efforts required for stepToErrorPatterns (NEW rewrite_set_)*)
  1507 stepToErrorPatterns 1; (*--> calcChanged, rule immediately calls... *)
  1508 stepOnErrorPatterns 1; (*--> calcChanged, rule calls getTactic and displays it *)
  1509 (* then --- UC errpat, fillpat by input ---*)
  1510 *)
  1511 autoCalculate' 1 CompleteCalc;
  1512 val ((pt,p),_) = get_calc 1; show_pt pt;
  1513 (*WN1208 postponed due to efforts required for stepToErrorPatterns (NEW rewrite_set_)*)
  1514