test/Tools/isac/Interpret/inform.sml
author Walther Neuper <neuper@ist.tugraz.at>
Tue, 28 Sep 2010 09:06:56 +0200
branchisac-update-Isa09-2
changeset 38031 460c24a6a6ba
parent 37967 bd4f7a35e892
child 38050 4c52ad406c20
permissions -rw-r--r--
tuned error and writeln

# raise error --> error
# writeln in atomtyp, atomty, atomt and xmlsrc
     1 (* tests on inform.sml
     2    author: Walther Neuper
     3    060225,
     4    (c) due to copyright terms 
     5 
     6 use"../smltest/ME/inform.sml";
     7 use"inform.sml";
     8 *)
     9 
    10 "-----------------------------------------------------------------";
    11 "table of contents -----------------------------------------------";
    12 "-----------------------------------------------------------------";
    13 "appendForm with miniscript with mini-subpbl:";
    14 "--------- appendFormula: on Res + equ_nrls ----------------------";
    15 "--------- appendFormula: on Frm + equ_nrls ----------------------";
    16 "--------- appendFormula: on Res + NO deriv ----------------------";
    17 "--------- appendFormula: on Res + late deriv --------------------";
    18 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
    19 "replaceForm with miniscript with mini-subpbl:";
    20 "--------- replaceFormula: on Res + = ----------------------------";
    21 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
    22 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
    23 "--------- replaceFormula: cut calculation -----------------------";
    24 "--------- replaceFormula: cut calculation -----------------------";
    25 (* 040307 copied from informtest.sml ... old versions
    26 "--------- maximum-example, UC: Modeling / modifyCalcHead --------";*)
    27 "--------- syntax error ------------------------------------------";
    28 "CAS-command:";
    29 "--------- CAS-command on ([],Pbl) -------------------------------";
    30 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
    31 "--------- inform [rational,simplification] ----------------------";
    32 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
    33 "--------- Take as 1st tac, start from exp -----------------------";
    34 "--------- init_form, start with <NEW> (CAS input) ---------------";
    35 "-----------------------------------------------------------------";
    36 "-----------------------------------------------------------------";
    37 "-----------------------------------------------------------------";
    38 
    39 
    40 
    41 
    42 
    43 
    44 "--------- appendFormula: on Res + equ_nrls ----------------------";
    45 "--------- appendFormula: on Res + equ_nrls ----------------------";
    46 "--------- appendFormula: on Res + equ_nrls ----------------------";
    47  val Script sc = (#scr o get_met) ["Test","squ-equ-test-subpbl1"];
    48  (writeln o term2str) sc;
    49  val Script sc = (#scr o get_met) ["Test","solve_linear"];
    50  (writeln o term2str) sc;
    51 
    52  states:=[];
    53  CalcTree [(["equality (x+1=2)", "solveFor x","solutions L"], 
    54 	    ("Test.thy", 
    55 	     ["sqroot-test","univariate","equation","test"],
    56 	     ["Test","squ-equ-test-subpbl1"]))];
    57  Iterator 1; moveActiveRoot 1;
    58  autoCalculate 1 CompleteCalcHead;
    59  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
    60  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
    61 
    62  appendFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
    63  val ((pt,_),_) = get_calc 1;
    64  val str = pr_ptree pr_short pt;
    65  writeln str;
    66  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n2.1.   x + 1 + -1 * 2 = 0\n2.2.   -1 * 2 + (x + 1) = 0\n2.3.   -1 * 2 + (1 + x) = 0\n2.4.   1 + (-1 * 2 + x) = 0\n2.5.   1 + (-2 + x) = 0\n2.6.   1 + (-2 * 1 + x) = 0\n" then ()
    67  else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
    68 
    69  moveDown 1 ([ ],Pbl); refFormula 1 ([1],Frm); (*x + 1 = 2*)
    70  moveDown 1 ([1],Frm); refFormula 1 ([1],Res); (*x + 1 + -1 * 2 = 0*)
    71 
    72  (*the seven steps of detailed derivation*)
    73  moveDown 1 ([1  ],Res); refFormula 1 ([2,1],Frm); 
    74  moveDown 1 ([2,1],Frm); refFormula 1 ([2,1],Res);
    75  moveDown 1 ([2,1],Res); refFormula 1 ([2,2],Res);
    76  moveDown 1 ([2,2],Res); refFormula 1 ([2,3],Res); 
    77  moveDown 1 ([2,3],Res); refFormula 1 ([2,4],Res);
    78  moveDown 1 ([2,4],Res); refFormula 1 ([2,5],Res);
    79  moveDown 1 ([2,5],Res); refFormula 1 ([2,6],Res);
    80  val ((pt,_),_) = get_calc 1;
    81  if "-2 * 1 + (1 + x) = 0" = term2str (fst (get_obj g_result pt [2,6])) then()
    82  else error "inform.sml: diff.behav.appendFormula: on Res + equ 2";
    83 
    84  fetchProposedTactic 1; (*takes Iterator 1 _1_*)
    85  val (_,(tac,_,_)::_) = get_calc 1;
    86  if tac = Rewrite_Set "Test_simplify" then ()
    87  else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
    88  autoCalculate 1 CompleteCalc;
    89  val ((pt,_),_) = get_calc 1;
    90  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
    91  else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
    92  (* autoCalculate 1 CompleteCalc;
    93    val ((pt,p),_) = get_calc 1;
    94    (writeln o istates2str) (get_obj g_loc pt [ ]);  
    95    (writeln o istates2str) (get_obj g_loc pt [1]);  
    96    (writeln o istates2str) (get_obj g_loc pt [2]);  
    97    (writeln o istates2str) (get_obj g_loc pt [3]);  
    98    (writeln o istates2str) (get_obj g_loc pt [3,1]);  
    99    (writeln o istates2str) (get_obj g_loc pt [3,2]);  
   100    (writeln o istates2str) (get_obj g_loc pt [4]);  
   101 
   102    *)
   103 "----------------------------------------------------------";
   104  val fod = make_deriv Isac.thy Atools_erls 
   105 		       ((#rules o rep_rls) Test_simplify)
   106 		       (sqrt_right false (theory "Pure")) NONE 
   107 		       (str2term "x + 1 + -1 * 2 = 0");
   108  (writeln o trtas2str) fod;
   109 
   110  val ifod = make_deriv Isac.thy Atools_erls 
   111 		       ((#rules o rep_rls) Test_simplify)
   112 		       (sqrt_right false (theory "Pure")) NONE 
   113 		       (str2term "-2 * 1 + (1 + x) = 0");
   114  (writeln o trtas2str) ifod;
   115  fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1=t2;
   116  val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
   117  val der = fod' @ (map rev_deriv' rifod');
   118  (writeln o trtas2str) der;
   119  "----------------------------------------------------------";
   120 
   121 
   122 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   123 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   124 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   125  states:=[];
   126  CalcTree [(["equality (x+1=2)", "solveFor x","solutions L"], 
   127 	    ("Test.thy", 
   128 	     ["sqroot-test","univariate","equation","test"],
   129 	     ["Test","squ-equ-test-subpbl1"]))];
   130  Iterator 1; moveActiveRoot 1;
   131  autoCalculate 1 CompleteCalcHead;
   132  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1) (*x + 1 = 2*);
   133 
   134  appendFormula 1 "2+ -1 + x = 2"; refFormula 1 (get_pos 1 1);
   135 
   136  moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
   137 
   138  moveDown 1 ([1  ],Frm); refFormula 1 ([1,1],Frm); 
   139  moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res); 
   140  moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res); 
   141  moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res); 
   142  moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res); 
   143  moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res); 
   144  moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res); 
   145  val ((pt,_),_) = get_calc 1;
   146  if "2 + -1 + x = 2" = term2str (fst (get_obj g_result pt [1,6])) then()
   147  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
   148 
   149  fetchProposedTactic 1; (*takes Iterator 1 _1_*)
   150  val (_,(tac,_,_)::_) = get_calc 1;
   151  if tac = Rewrite_Set "norm_equation" then ()
   152  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
   153  autoCalculate 1 CompleteCalc;
   154  val ((pt,_),_) = get_calc 1;
   155  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   156  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
   157 
   158 
   159 "--------- appendFormula: on Res + NO deriv ----------------------";
   160 "--------- appendFormula: on Res + NO deriv ----------------------";
   161 "--------- appendFormula: on Res + NO deriv ----------------------";
   162  states:=[];
   163  CalcTree [(["equality (x+1=2)", "solveFor x","solutions L"], 
   164 	    ("Test.thy", 
   165 	     ["sqroot-test","univariate","equation","test"],
   166 	     ["Test","squ-equ-test-subpbl1"]))];
   167  Iterator 1; moveActiveRoot 1;
   168  autoCalculate 1 CompleteCalcHead;
   169  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   170  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   171 
   172  appendFormula 1 "x = 2";
   173  val ((pt,p),_) = get_calc 1;
   174  val str = pr_ptree pr_short pt;
   175  writeln str;
   176  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" andalso p = ([1], Res)
   177  then ()
   178  else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
   179 
   180  fetchProposedTactic 1;
   181  val (_,(tac,_,_)::_) = get_calc 1;
   182  if tac = Rewrite_Set "Test_simplify" then ()
   183  else error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
   184  autoCalculate 1 CompleteCalc;
   185  val ((pt,_),_) = get_calc 1;
   186  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   187  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
   188 
   189 
   190 "--------- appendFormula: on Res + late deriv --------------------";
   191 "--------- appendFormula: on Res + late deriv --------------------";
   192 "--------- appendFormula: on Res + late deriv --------------------";
   193  states:=[];
   194  CalcTree [(["equality (x+1=2)", "solveFor x","solutions L"], 
   195 	    ("Test.thy", 
   196 	     ["sqroot-test","univariate","equation","test"],
   197 	     ["Test","squ-equ-test-subpbl1"]))];
   198  Iterator 1; moveActiveRoot 1;
   199  autoCalculate 1 CompleteCalcHead;
   200  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   201  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   202 
   203  appendFormula 1 "x = 1";
   204  val ((pt,p),_) = get_calc 1;
   205  val str = pr_ptree pr_short pt;
   206  writeln str;
   207  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n3.    ----- pblobj -----\n3.1.   -1 + x = 0\n3.2.   x = 0 + -1 * -1\n3.2.1.   x = 0 + -1 * -1\n3.2.2.   x = 0 + 1\n" andalso p = ([3,2], Res)
   208  then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
   209  else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
   210  
   211  fetchProposedTactic 1;
   212  val (_,(tac,_,_)::_) = get_calc 1;
   213  if tac = Check_Postcond ["linear", "univariate", "equation", "test"] then ()
   214  else error "inform.sml: diff.behav.appendFormula: Res + late d 2";
   215  autoCalculate 1 CompleteCalc;
   216  val ((pt,_),_) = get_calc 1;
   217  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   218  else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
   219 
   220 
   221 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   222 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   223 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   224  states:=[];
   225  CalcTree [(["equality (x+1=2)", "solveFor x","solutions L"], 
   226 	    ("Test.thy", 
   227 	     ["sqroot-test","univariate","equation","test"],
   228 	     ["Test","squ-equ-test-subpbl1"]))];
   229  Iterator 1; moveActiveRoot 1;
   230  autoCalculate 1 CompleteCalcHead;
   231  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   232  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   233  appendFormula 1 "[x = 3 + -2*1]";
   234  val ((pt,p),_) = get_calc 1;
   235  val str = pr_ptree pr_short pt;
   236  writeln str;
   237  if str=".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n3.    ----- pblobj -----\n3.1.   -1 + x = 0\n3.2.   x = 0 + -1 * -1\n4.   [x = 1]\n4.1.   [x = 1]\n4.2.   [x = -2 + 3]\n4.3.   [x = 3 + -2]\n" then ()
   238  else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
   239  autoCalculate 1 CompleteCalc;
   240  val ((pt,p),_) = get_calc 1;
   241  if "[x = 3 + -2 * 1]" = term2str (fst (get_obj g_result pt [])) then ()
   242  (*       ~~~~~~~~~~ simplify as last step in any script ?!*)
   243  else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
   244 
   245 
   246 
   247 "--------- replaceFormula: on Res + = ----------------------------";
   248 "--------- replaceFormula: on Res + = ----------------------------";
   249 "--------- replaceFormula: on Res + = ----------------------------";
   250  states:=[];
   251  CalcTree [(["equality (x+1=2)", "solveFor x","solutions L"], 
   252 	    ("Test.thy", 
   253 	     ["sqroot-test","univariate","equation","test"],
   254 	     ["Test","squ-equ-test-subpbl1"]))];
   255  Iterator 1; moveActiveRoot 1;
   256  autoCalculate 1 CompleteCalcHead;
   257  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   258  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   259  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*-1 + x*);
   260 
   261  replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
   262  val ((pt,_),_) = get_calc 1;
   263  val str = pr_ptree pr_short pt;
   264  writeln str;
   265  if str=".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n2.1.   x + 1 + -1 * 2 = 0\n2.2.   -1 * 2 + (x + 1) = 0\n2.3.   -1 * 2 + (1 + x) = 0\n2.4.   1 + (-1 * 2 + x) = 0\n2.5.   1 + (-2 + x) = 0\n2.6.   1 + (-2 * 1 + x) = 0\n" then()
   266  else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
   267  autoCalculate 1 CompleteCalc;
   268  val ((pt,pos as(p,_)),_) = get_calc 1;
   269  if pos=([],Res)andalso"[x = 1]"=(term2str o fst)(get_obj g_result pt p)then()
   270  else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
   271  
   272 
   273 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   274 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   275 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   276  states:=[];
   277  CalcTree [(["equality (x+1=2)", "solveFor x","solutions L"], 
   278 	    ("Test.thy", 
   279 	     ["sqroot-test","univariate","equation","test"],
   280 	     ["Test","squ-equ-test-subpbl1"]))];
   281  Iterator 1; moveActiveRoot 1;
   282  autoCalculate 1 CompleteCalcHead;
   283  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   284  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   285 
   286  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   287  val ((pt,_),_) = get_calc 1;
   288  val str = pr_ptree pr_short pt;
   289  writeln str;
   290  if str=".    ----- pblobj -----\n1.   x + 1 = 2\n1.1.   x + 1 = 2\n1.2.   1 + x = 2\n1.3.   1 + x = -2 + 4\n1.4.   x + 1 = -2 + 4\n" then ()
   291  else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
   292  autoCalculate 1 CompleteCalc;
   293  val ((pt,pos as(p,_)),_) = get_calc 1;
   294  if pos=([],Res)andalso"[x = 1]"=(term2str o fst)(get_obj g_result pt p)then()
   295  else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
   296 
   297 
   298 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   299 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   300 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   301  states:=[];
   302  CalcTree [(["equality (x+1=2)", "solveFor x","solutions L"], 
   303 	    ("Test.thy", 
   304 	     ["sqroot-test","univariate","equation","test"],
   305 	     ["Test","squ-equ-test-subpbl1"]))];
   306  Iterator 1; moveActiveRoot 1;
   307  autoCalculate 1 CompleteCalcHead;
   308  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   309 
   310  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   311  val ((pt,_),_) = get_calc 1;
   312  val str = pr_ptree pr_short pt;
   313  writeln str;
   314  if str=".    ----- pblobj -----\n1.   x + 1 = 2\n1.1.   x + 1 = 2\n1.2.   1 + x = 2\n1.3.   1 + x = -2 + 4\n1.4.   x + 1 = -2 + 4\n" then ()
   315  else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
   316  autoCalculate 1 CompleteCalc;
   317  val ((pt,pos as(p,_)),_) = get_calc 1;
   318  if pos=([],Res)andalso"[x = 1]"=(term2str o fst)(get_obj g_result pt p)then()
   319  else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
   320 
   321 
   322 "--------- replaceFormula: cut calculation -----------------------";
   323 "--------- replaceFormula: cut calculation -----------------------";
   324 "--------- replaceFormula: cut calculation -----------------------";
   325  states:=[];
   326  CalcTree [(["equality (x+1=2)", "solveFor x","solutions L"], 
   327 	    ("Test.thy", 
   328 	     ["sqroot-test","univariate","equation","test"],
   329 	     ["Test","squ-equ-test-subpbl1"]))];
   330  Iterator 1; moveActiveRoot 1;
   331  autoCalculate 1 CompleteCalc;
   332  moveActiveRoot 1; moveActiveDown 1;
   333  if get_pos 1 1 = ([1], Frm) then ()
   334  else error "inform.sml: diff.behav. cut calculation 1";
   335 
   336  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   337  val ((pt,p),_) = get_calc 1;
   338  val str = pr_ptree pr_short pt;
   339  writeln str;
   340  if p = ([1], Res) then ()
   341  else error "inform.sml: diff.behav. cut calculation 2";
   342 
   343 
   344 
   345 (* 040307 copied from informtest.sml; ... old version 
   346  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   347  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   348  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   349 
   350  val p = ([],Pbl);
   351  val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
   352 	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   353 	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   354 	      "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
   355 	      (*^^^ these are the elements for the root-problem (in variants)*)
   356               (*vvv these are elements required for subproblems*)
   357 	      "boundVariable a","boundVariable b","boundVariable alpha",
   358 	      "interval {x::real. 0 <= x & x <= 2*r}",
   359 	      "interval {x::real. 0 <= x & x <= 2*r}",
   360 	      "interval {x::real. 0 <= x & x <= pi}",
   361 	      "errorBound (eps=(0::real))"]
   362  (*specifying is not interesting for this example*)
   363  val spec = ("DiffApp.thy", ["maximum_of","function"], 
   364 	     ["DiffApp","max_by_calculus"]);
   365  (*the empty model with descriptions for user-guidance by Model_Problem*)
   366  val empty_model = [Given ["fixedValues []"],
   367 		    Find ["maximum", "valuesFor"],
   368 		    Relate ["relations []"]];
   369 
   370 
   371  (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
   372  val (p,_,f,nxt,_,pt) = CalcTreeTEST [(elems, spec)];
   373  (*val nxt = ("Model_Problem", ...*)
   374  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   375 
   376  val (p,_,f,nxt,_,pt) = me nxt p c pt;
   377  (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
   378  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   379 (*[
   380 (0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
   381 (0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
   382 (0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
   383 (0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
   384 
   385  (*the empty CalcHead is checked w.r.t the model and re-established as such*)
   386  val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, e_spec);
   387  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   388  if ocalhd2str ocalhd = "(Pbl, ??.empty, [\n(0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),\n(0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),\n(0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),\n(0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))], [], \n(\"e_domID\", [\"e_pblID\"], [\"e_metID\"]) )" then () else error "informtest.sml: diff.behav. max 1";
   389 
   390  (*there is one input to the model (could be more)*)
   391  val (b,pt,ocalhd) = 
   392      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   393 			     Find ["maximum", "valuesFor"],
   394 			     Relate ["relations"]], Pbl, e_spec);
   395  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   396  if ocalhd2str ocalhd = "(Pbl, ??.empty, [\n(1 ,[1,2,3] ,true ,#Given ,Cor fixedValues [r = Arbfix] ,(fix_, [[r = Arbfix]])),\n(0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),\n(0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),\n(0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))], [], \n(\"e_domID\", [\"e_pblID\"], [\"e_metID\"]) )" then () 
   397  else error "informtest.sml: diff.behav. max 2";
   398 
   399  (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
   400  val (b,pt''''',ocalhd) = 
   401      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   402 			     Find ["maximum A", "valuesFor [a,b]"],
   403 			     Relate ["relations [A=a*b, a/2=r*sin alpha, \
   404 				     \b/2=r*cos alpha]"]], Pbl, e_spec);
   405  val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   406  if ocalhd2str ocalhd = ------------^^^^^^^^^^ missing !!!*)
   407 
   408  (*this input is complete in variant 1 (variant 3 does not work yet)*)
   409  val (b,pt''''',ocalhd) = 
   410      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   411 			     Find ["maximum A", "valuesFor [a,b]"],
   412 			     Relate ["relations [A=a*b, \
   413 				     \(a/2)^^^2 + (b/2)^^^2 = r^^^2]"]], 
   414 		      Pbl, e_spec);
   415  val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   416 
   417  modifycalcheadOK2xml 111 (bool2str b) ocalhd;
   418 *)
   419 
   420 "--------- syntax error ------------------------------------------";
   421 "--------- syntax error ------------------------------------------";
   422 "--------- syntax error ------------------------------------------";
   423  states:=[];
   424  CalcTree [(["equality (x+1=2)", "solveFor x","solutions L"], 
   425 	    ("Test.thy", 
   426 	     ["sqroot-test","univariate","equation","test"],
   427 	     ["Test","squ-equ-test-subpbl1"]))];
   428  Iterator 1; moveActiveRoot 1;
   429  autoCalculate 1 CompleteCalcHead;
   430  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   431  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   432 
   433  appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
   434  val ((pt,_),_) = get_calc 1;
   435  val str = pr_ptree pr_short pt;
   436  writeln str;
   437  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" then ()
   438  else error "inform.sml: diff.behav.appendFormula: syntax error";
   439 
   440 
   441 "--------- CAS-command on ([],Pbl) -------------------------------";
   442 "--------- CAS-command on ([],Pbl) -------------------------------";
   443 "--------- CAS-command on ([],Pbl) -------------------------------";
   444 val (p,_,f,nxt,_,pt) = 
   445     CalcTreeTEST [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   446 val ifo = "solve(x+1=2,x)";
   447 val (_,(_,c,(pt,p))) = inform ([],[],(pt,p)) "solve(x+1=2,x)";
   448 show_pt pt;
   449 val nxt = ("Apply_Method",Apply_Method ["Test","squ-equ-test-subpbl1"]);
   450 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   451 if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
   452 else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
   453 
   454 
   455 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   456 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   457 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   458 states:=[];
   459 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   460 Iterator 1;
   461 moveActiveRoot 1;
   462 replaceFormula 1 "solve(x+1=2,x)";
   463 autoCalculate 1 CompleteCalc;
   464 val ((pt,p),_) = get_calc 1;
   465 show_pt pt;
   466 if p = ([], Res) then ()
   467 else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
   468 
   469 
   470 "--------- inform [rational,simplification] ----------------------";
   471 "--------- inform [rational,simplification] ----------------------";
   472 "--------- inform [rational,simplification] ----------------------";
   473 states:=[];
   474 CalcTree [(["TERM (4/x - 3/y - 1)", "normalform N"],
   475 	   ("Rational.thy",["rational","simplification"],
   476 	    ["simplification","of_rationals"]))];
   477 Iterator 1; moveActiveRoot 1;
   478 autoCalculate 1 CompleteCalcHead;
   479 autoCalculate 1 (Step 1);
   480 autoCalculate 1 (Step 1);
   481 autoCalculate 1 (Step 1);
   482 autoCalculate 1 (Step 1);
   483 "--- input the next formula that _should_ be presented by mat-engine";
   484 appendFormula 1 "(4 * y + -3 * x) / (x * y) + -1";
   485 val ((pt,p),_) = get_calc 1;
   486 if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   487 else error ("inform.sml: [rational,simplification] 1");
   488 
   489 "--- input the next formula that would be presented by mat-engine";
   490 (*autoCalculate 1 (Step 1);*)
   491 appendFormula 1 "(4 * y + -3 * x + -1 * (x * y)) / (x * y)";
   492 val ((pt,p),_) = get_calc 1;
   493 if p = ([5], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
   494 else error ("inform.sml: [rational,simplification] 2");
   495 
   496 "--- input the exact final result";(*TODO: Exception- LIST "last_elem" raised*)
   497 appendFormula 1 "(-3 * x + 4 * y + -1 * x * y) / (x * y)";
   498 val ((pt,p),_) = get_calc 1;
   499 if p = ([6], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   500 else error ("inform.sml: [rational,simplification] 3");
   501 show_pt pt;
   502 
   503 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   504 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   505 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   506 val t = str2term "Diff (x^^^2 + x + 1, x)";
   507 case t of Const ("Diff.Diff", _) $ _ => ()
   508 	| _ => raise 
   509 	      error "diff.sml behav.changed for CAS Diff (..., x)";
   510 atomty t;
   511 "-----------------------------------------------------------------";
   512 (*1>*)states:=[];
   513 (*2>*)CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   514 (*3>*)Iterator 1;moveActiveRoot 1;
   515 "----- here the Headline has been finished";
   516 (*4>*)moveActiveFormula 1 ([],Pbl);
   517 (*5>*)replaceFormula 1 "Diff (x^2 + x + 1, x)";
   518 val ((pt,_),_) = get_calc 1;
   519 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   520 val NONE = env;
   521 val (SOME istate, NONE) = loc;
   522 print_depth 5;
   523 writeln"-----------------------------------------------------------";
   524 spec;
   525 writeln (itms2str_ ctxt probl);
   526 writeln (itms2str_ ctxt meth);
   527 writeln (istate2str istate);
   528 
   529 print_depth 3;
   530 
   531 refFormula 1 ([],Pbl) (*--> correct CalcHead*);
   532  (*081016 NOT necessary (but leave it in Java):*)
   533 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
   534 "----- here the CalcHead has been completed --- ONCE MORE ?????";
   535 
   536 (***difference II***)
   537 val ((pt,p),_) = get_calc 1;
   538 (*val p = ([], Pbl)*)
   539 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   540 val NONE = env;
   541 val (SOME istate, NONE) = loc;
   542 print_depth 5; writeln (istate2str istate);  print_depth 3;
   543 (*ScrState ([],
   544  [], NONE,
   545  ??.empty, Sundef, false)*)
   546 print_depth 5; spec; print_depth 3;
   547 (*("Isac.thy",
   548       ["derivative_of", "function"],
   549       ["diff", "differentiate_on_R"]) : spec*)
   550 writeln (itms2str_ ctxt probl);
   551 (*[
   552 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   553 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   554 (3 ,[1] ,true ,#Find ,Cor derivative f_'_ ,(f_'_, [f_'_]))]*)
   555 writeln (itms2str_ ctxt meth);
   556 (*[
   557 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   558 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   559 (3 ,[1] ,true ,#Find ,Cor derivative f_'_ ,(f_'_, [f_'_]))]*)
   560 writeln"-----------------------------------------------------------";
   561 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   562 (*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
   563 autoCalculate 1 CompleteCalc;
   564 val ((pt,p),_) = get_calc 1;
   565 val Form res = (#1 o pt_extract) (pt, ([],Res));
   566 show_pt pt;
   567 if p = ([], Res) andalso term2str res = "1 + 2 * x" then ()
   568 else error "diff.sml behav.changed for Diff (x^2 + x + 1, x)";
   569 
   570 
   571 "--------- Take as 1st tac, start from exp -----------------------";
   572 "--------- Take as 1st tac, start from exp -----------------------";
   573 "--------- Take as 1st tac, start from exp -----------------------";
   574 (*the following input is copied from BridgeLog Java <==> SML,
   575   omitting unnecessary inputs*)
   576 (*1>*)states:=[];
   577 (*2>*)CalcTree [(["functionTerm (x^2 + x + 1)", "differentiateFor x", "derivative f_'_"],("Isac.thy",["derivative_of","function"],["diff","differentiate_on_R"]))];
   578 (*3>*)Iterator 1; moveActiveRoot 1;
   579 
   580 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
   581 
   582 (***difference II***)
   583 val ((pt,_),_) = get_calc 1;
   584 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   585 val NONE = env;
   586 val (SOME istate, NONE) = loc;
   587 print_depth 5; writeln (istate2str istate);  print_depth 3;
   588 (*ScrState ([],
   589  [], NONE,
   590  ??.empty, Sundef, false)*)
   591 print_depth 5; spec; print_depth 3;
   592 (*("Isac.thy",
   593       ["derivative_of", "function"],
   594       ["diff", "differentiate_on_R"]) : spec*)
   595 writeln (itms2str_ ctxt probl);
   596 (*[
   597 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   598 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   599 (3 ,[1] ,true ,#Find ,Cor derivative f_'_ ,(f_'_, [f_'_]))]*)
   600 writeln (itms2str_ ctxt meth);
   601 (*[
   602 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   603 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   604 (3 ,[1] ,true ,#Find ,Cor derivative f_'_ ,(f_'_, [f_'_]))]*)
   605 writeln"-----------------------------------------------------------";
   606 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   607 
   608 autoCalculate 1 (Step 1);
   609 val ((pt,p),_) = get_calc 1;
   610 val Form res = (#1 o pt_extract) (pt, p);
   611 if term2str res = "d_d x (x ^^^ 2 + x + 1)" then ()
   612 else error "diff.sml Diff (x^2 + x + 1, x) from exp";
   613 
   614 
   615 "--------- init_form, start with <NEW> (CAS input) ---------------";
   616 "--------- init_form, start with <NEW> (CAS input) ---------------";
   617 "--------- init_form, start with <NEW> (CAS input) ---------------";
   618 states:=[];
   619 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   620 (*[[from sml: > @@@@@begin@@@@@
   621 [[from sml:  1 
   622 [[from sml: <CALCTREE>
   623 [[from sml:    <CALCID> 1 </CALCID>
   624 [[from sml: </CALCTREE>
   625 [[from sml: @@@@@end@@@@@*)
   626 Iterator 1;
   627 (*[[from sml: > @@@@@begin@@@@@
   628 [[from sml:  1 
   629 [[from sml: <ADDUSER>
   630 [[from sml:   <CALCID> 1 </CALCID>
   631 [[from sml:   <USERID> 1 </USERID>
   632 [[from sml: </ADDUSER>
   633 [[from sml: @@@@@end@@@@@*)
   634 moveActiveRoot 1;
   635 (*[[from sml: > @@@@@begin@@@@@
   636 [[from sml:  1 
   637 [[from sml: <CALCITERATOR>
   638 [[from sml:   <CALCID> 1 </CALCID>
   639 [[from sml:   <POSITION>
   640 [[from sml:     <INTLIST>
   641 [[from sml:     </INTLIST>
   642 [[from sml:     <POS> Pbl </POS>
   643 [[from sml:   </POSITION>
   644 [[from sml: </CALCITERATOR>
   645 [[from sml: @@@@@end@@@@@*)
   646 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
   647 (*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
   648 [[from sml:  1 
   649 [[from sml: <GETELEMENTSFROMTO>
   650 [[from sml:   <CALCID> 1 </CALCID>
   651 [[from sml:   <FORMHEADS>
   652 [[from sml:     <CALCFORMULA>
   653 [[from sml:       <POSITION>
   654 [[from sml:         <INTLIST>
   655 [[from sml:         </INTLIST>
   656 [[from sml:         <POS> Pbl </POS>
   657 [[from sml:       </POSITION>
   658 [[from sml:       <FORMULA>
   659 [[from sml:         <MATHML>
   660 [[from sml:           <ISA> ________________________________________________ </ISA>
   661 [[from sml:         </MATHML>
   662 [[from sml: 
   663 [[from sml:       </FORMULA>
   664 [[from sml:     </CALCFORMULA>
   665 [[from sml:   </FORMHEADS>
   666 [[from sml: </GETELEMENTSFROMTO>
   667 [[from sml: @@@@@end@@@@@*)
   668 refFormula 1 ([],Pbl);
   669 (*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
   670 [[from sml:  1 
   671 [[from sml: <REFFORMULA>
   672 [[from sml:   <CALCID> 1 </CALCID>
   673 [[from sml:   <CALCHEAD status = "incorrect">
   674 [[from sml:     <POSITION>
   675 [[from sml:       <INTLIST>
   676 [[from sml:       </INTLIST>
   677 [[from sml:       <POS> Pbl </POS>
   678 [[from sml:     </POSITION>
   679 [[from sml:     <HEAD>
   680 [[from sml:       <MATHML>
   681 [[from sml:         <ISA> Problem (e_domID, [e_pblID]) </ISA>
   682 [[from sml:       </MATHML>
   683 [[from sml:     </HEAD>
   684 [[from sml:     <MODEL>
   685 [[from sml:       <GIVEN>  </GIVEN>
   686 [[from sml:       <WHERE>  </WHERE>
   687 [[from sml:       <FIND>  </FIND>
   688 [[from sml:       <RELATE>  </RELATE>
   689 [[from sml:     </MODEL>
   690 [[from sml:     <BELONGSTO> Pbl </BELONGSTO>
   691 [[from sml:     <SPECIFICATION>
   692 [[from sml:       <THEORYID> e_domID </THEORYID>
   693 [[from sml:       <PROBLEMID>
   694 [[from sml:         <STRINGLIST>
   695 [[from sml:           <STRING> e_pblID </STRING>
   696 [[from sml:         </STRINGLIST>
   697 [[from sml:       </PROBLEMID>
   698 [[from sml:       <METHODID>
   699 [[from sml:         <STRINGLIST>
   700 [[from sml:           <STRING> e_metID </STRING>
   701 [[from sml:         </STRINGLIST>
   702 [[from sml:       </METHODID>
   703 [[from sml:     </SPECIFICATION>
   704 [[from sml:   </CALCHEAD>
   705 [[from sml: </REFFORMULA>
   706 [[from sml: @@@@@end@@@@@*)
   707 moveActiveFormula 1 ([],Pbl);
   708 (*[[from sml: > @@@@@begin@@@@@
   709 [[from sml:  1 
   710 [[from sml: <CALCITERATOR>
   711 [[from sml:   <CALCID> 1 </CALCID>
   712 [[from sml:   <POSITION>
   713 [[from sml:     <INTLIST>
   714 [[from sml:     </INTLIST>
   715 [[from sml:     <POS> Pbl </POS>
   716 [[from sml:   </POSITION>
   717 [[from sml: </CALCITERATOR>
   718 [[from sml: @@@@@end@@@@@*)
   719 replaceFormula 1 "Simplify (1+2)";
   720 (*[[from sml: > @@@@@begin@@@@@
   721 [[from sml:  1 
   722 [[from sml: <REPLACEFORMULA>
   723 [[from sml:   <CALCID> 1 </CALCID>
   724 [[from sml:   <CALCCHANGED>
   725 [[from sml:     <UNCHANGED>
   726 [[from sml:       <INTLIST>
   727 [[from sml:       </INTLIST>
   728 [[from sml:       <POS> Pbl </POS>
   729 [[from sml:     </UNCHANGED>
   730 [[from sml:     <DELETED>
   731 [[from sml:       <INTLIST>
   732 [[from sml:       </INTLIST>
   733 [[from sml:       <POS> Pbl </POS>
   734 [[from sml:     </DELETED>
   735 [[from sml:     <GENERATED>
   736 [[from sml:       <INTLIST>
   737 [[from sml:       </INTLIST>
   738 [[from sml:       <POS> Met </POS>                           DIFFERENCE: Pbl
   739 [[from sml:     </GENERATED>
   740 [[from sml:   </CALCCHANGED>
   741 [[from sml: </REPLACEFORMULA>
   742 [[from sml: @@@@@end@@@@@*)
   743 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(*              DIFFERENCE: Pbl*);
   744 (*@@@@@begin@@@@@
   745  1
   746 <GETELEMENTSFROMTO>
   747   <CALCID> 1 </CALCID>
   748   <FORMHEADS>
   749     <CALCFORMULA>
   750       <POSITION>
   751         <INTLIST>
   752         </INTLIST>
   753         <POS> Pbl </POS>
   754       </POSITION>
   755       <FORMULA>
   756         <MATHML>
   757           <ISA> Simplify (1 + 2) </ISA>                      WORKS !!!!!
   758         </MATHML>
   759       </FORMULA>
   760     </CALCFORMULA>
   761   </FORMHEADS>
   762 </GETELEMENTSFROMTO>
   763 @@@@@end@@@@@*)
   764 getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
   765 (*[[from sml: > @@@@@begin@@@@@
   766 [[from sml:  1 
   767 [[from sml: <SYSERROR>
   768 [[from sml:   <CALCID> 1 </CALCID>
   769 [[from sml:   <ERROR> error in getFormulaeFromTo </ERROR>
   770 [[from sml: </SYSERROR>
   771 [[from sml: @@@@@end@@@@@*)
   772 (*step into getFormulaeFromTo --- bug corrected...*)