test/Tools/isac/Interpret/inform.sml
author Walther Neuper <neuper@ist.tugraz.at>
Fri, 12 Jul 2013 06:39:55 +0200
changeset 48897 d2d8179de1b0
parent 48895 35751d90365e
child 52105 2786cc9704c8
permissions -rw-r--r--
tuned
     1 (* Title: tests on inform.sml
     2    Author: Walther Neuper 060225,
     3    (c) due to copyright terms 
     4 
     5 use"../smltest/ME/inform.sml";
     6 use"inform.sml";
     7 *)
     8 
     9 "-----------------------------------------------------------------";
    10 "table of contents -----------------------------------------------";
    11 "-----------------------------------------------------------------";
    12 "appendForm with miniscript with mini-subpbl:";
    13 "--------- appendFormula: on Res + equ_nrls ----------------------";
    14 "--------- appendFormula: on Frm + equ_nrls ----------------------";
    15 "--------- appendFormula: on Res + NO deriv ----------------------";
    16 "--------- appendFormula: on Res + late deriv --------------------";
    17 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
    18 "replaceForm with miniscript with mini-subpbl:";
    19 "--------- replaceFormula: on Res + = ----------------------------";
    20 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
    21 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
    22 "--------- replaceFormula: cut calculation -----------------------";
    23 "--------- replaceFormula: cut calculation -----------------------";
    24 (* 040307 copied from informtest.sml ... old versions
    25 "--------- maximum-example, UC: Modeling / modifyCalcHead --------";*)
    26 "--------- syntax error ------------------------------------------";
    27 "CAS-command:";
    28 "--------- CAS-command on ([],Pbl) -------------------------------";
    29 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
    30 "--------- inform [rational,simplification] ----------------------";
    31 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
    32 "--------- Take as 1st tac, start from exp -----------------------";
    33 "--------- init_form, start with <NEW> (CAS input) ---------------";
    34 "--------- build fun check_err_patt ------------------------------";
    35 "--------- build fun check_err_patt ?bdv -------------------------";
    36 "--------- build fun check_error_patterns ------------------------";
    37 "--------- embed fun check_error_patterns ------------------------";
    38 "--------- build fun get_fillpats --------------------------------";
    39 "--------- embed fun find_fillpatterns ---------------------------";
    40 "--------- build fun is_exactly_equal, inputFillFormula ----------";
    41 "-----------------------------------------------------------------";
    42 "-----------------------------------------------------------------";
    43 "-----------------------------------------------------------------";
    44 
    45 
    46 "--------- appendFormula: on Res + equ_nrls ----------------------";
    47 "--------- appendFormula: on Res + equ_nrls ----------------------";
    48 "--------- appendFormula: on Res + equ_nrls ----------------------";
    49  val Prog sc = (#scr o get_met) ["Test","squ-equ-test-subpbl1"];
    50  (writeln o term2str) sc;
    51  val Prog sc = (#scr o get_met) ["Test","solve_linear"];
    52  (writeln o term2str) sc;
    53 
    54  states:=[];
    55  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
    56 	    ("Test", ["sqroot-test","univariate","equation","test"],
    57 	     ["Test","squ-equ-test-subpbl1"]))];
    58  Iterator 1; moveActiveRoot 1;
    59  autoCalculate 1 CompleteCalcHead;
    60  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
    61  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
    62 
    63  appendFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
    64  val ((pt,_),_) = get_calc 1;
    65  val str = pr_ptree pr_short pt;
    66 if str =
    67 (".    ----- pblobj -----\n" ^
    68 "1.   x + 1 = 2\n" ^
    69 "2.   x + 1 + -1 * 2 = 0\n" ^
    70 "2.1.   x + 1 + -1 * 2 = 0\n" ^
    71 "2.2.   1 + x + -1 * 2 = 0\n" ^
    72 "2.3.   1 + (x + -1 * 2) = 0\n" ^
    73 "2.4.   1 + (x + -2) = 0\n" ^
    74 "2.5.   1 + (x + -2 * 1) = 0\n" ^
    75 "2.6.   1 + x + -2 * 1 = 0\n" ) then ()
    76 else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
    77 
    78  moveDown 1 ([ ],Pbl); refFormula 1 ([1],Frm); (*x + 1 = 2*)
    79  moveDown 1 ([1],Frm); refFormula 1 ([1],Res); (*x + 1 + -1 * 2 = 0*)
    80 
    81  (*the seven steps of detailed derivation*)
    82  moveDown 1 ([1  ],Res); refFormula 1 ([2,1],Frm); 
    83  moveDown 1 ([2,1],Frm); refFormula 1 ([2,1],Res);
    84  moveDown 1 ([2,1],Res); refFormula 1 ([2,2],Res);
    85  moveDown 1 ([2,2],Res); refFormula 1 ([2,3],Res); 
    86  moveDown 1 ([2,3],Res); refFormula 1 ([2,4],Res);
    87  moveDown 1 ([2,4],Res); refFormula 1 ([2,5],Res);
    88  moveDown 1 ([2,5],Res); refFormula 1 ([2,6],Res);
    89  val ((pt,_),_) = get_calc 1;
    90  if "-2 * 1 + (1 + x) = 0" = term2str (fst (get_obj g_result pt [2,6])) then()
    91  else error "inform.sml: diff.behav.appendFormula: on Res + equ 2";
    92 
    93  fetchProposedTactic 1; (*takes Iterator 1 _1_*)
    94 (* <ERROR> error in kernel </ERROR> ALREADY IN 2009-2*)
    95 (*========== inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 =============
    96  val (_,(tac,_,_)::_) = get_calc 1;
    97  if tac = Rewrite_Set "Test_simplify" then ()
    98  else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
    99 ============ inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 ============*)
   100 
   101  autoCalculate 1 CompleteCalc;
   102  val ((pt,_),_) = get_calc 1;
   103  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   104  else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
   105  (* autoCalculate 1 CompleteCalc;
   106    val ((pt,p),_) = get_calc 1;
   107    (writeln o istates2str) (get_obj g_loc pt [ ]);  
   108    (writeln o istates2str) (get_obj g_loc pt [1]);  
   109    (writeln o istates2str) (get_obj g_loc pt [2]);  
   110    (writeln o istates2str) (get_obj g_loc pt [3]);  
   111    (writeln o istates2str) (get_obj g_loc pt [3,1]);  
   112    (writeln o istates2str) (get_obj g_loc pt [3,2]);  
   113    (writeln o istates2str) (get_obj g_loc pt [4]);  
   114 
   115    *)
   116 "----------------------------------------------------------";
   117 
   118  val fod = make_deriv (@{theory "Isac"}) Atools_erls 
   119 		       ((#rules o rep_rls) Test_simplify)
   120 		       (sqrt_right false (@{theory "Pure"})) NONE 
   121 		       (str2term "x + 1 + -1 * 2 = 0");
   122  (writeln o trtas2str) fod;
   123 
   124  val ifod = make_deriv (@{theory "Isac"}) Atools_erls 
   125 		       ((#rules o rep_rls) Test_simplify)
   126 		       (sqrt_right false (@{theory "Pure"})) NONE 
   127 		       (str2term "-2 * 1 + (1 + x) = 0");
   128  (writeln o trtas2str) ifod;
   129  fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1 = t2;
   130  val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
   131  val der = fod' @ (map rev_deriv' rifod');
   132  (writeln o trtas2str) der;
   133  "----------------------------------------------------------";
   134 
   135 
   136 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   137 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   138 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   139  states:=[];
   140  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   141 	    ("Test", ["sqroot-test","univariate","equation","test"],
   142 	     ["Test","squ-equ-test-subpbl1"]))];
   143  Iterator 1; moveActiveRoot 1;
   144  autoCalculate 1 CompleteCalcHead;
   145  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1) (*x + 1 = 2*);
   146  appendFormula 1 "2+ -1 + x = 2"; refFormula 1 (get_pos 1 1);
   147 
   148  moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
   149 
   150  moveDown 1 ([1  ],Frm); refFormula 1 ([1,1],Frm); 
   151  moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res); 
   152  moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res); 
   153  moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res); 
   154  moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res); 
   155  moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res); 
   156  moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res); 
   157  val ((pt,_),_) = get_calc 1;
   158  if "2 + -1 + x = 2" = term2str (fst (get_obj g_result pt [1,6])) then()
   159  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
   160 
   161  fetchProposedTactic 1; (*takes Iterator 1 _1_*)
   162  val (_,(tac,_,_)::_) = get_calc 1;
   163  if tac = Rewrite_Set "norm_equation" then ()
   164  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
   165  autoCalculate 1 CompleteCalc;
   166  val ((pt,_),_) = get_calc 1;
   167  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   168  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
   169 
   170 
   171 "--------- appendFormula: on Res + NO deriv ----------------------";
   172 "--------- appendFormula: on Res + NO deriv ----------------------";
   173 "--------- appendFormula: on Res + NO deriv ----------------------";
   174  states:=[];
   175  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   176 	    ("Test", ["sqroot-test","univariate","equation","test"],
   177 	     ["Test","squ-equ-test-subpbl1"]))];
   178  Iterator 1; moveActiveRoot 1;
   179  autoCalculate 1 CompleteCalcHead;
   180  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   181  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   182 
   183  appendFormula 1 "x = 2";
   184  val ((pt,p),_) = get_calc 1;
   185  val str = pr_ptree pr_short pt;
   186  writeln str;
   187  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" andalso p = ([1], Res)
   188  then ()
   189  else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
   190 
   191  fetchProposedTactic 1;
   192  val (_,(tac,_,_)::_) = get_calc 1;
   193  if tac = Rewrite_Set "Test_simplify" then ()
   194  else error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
   195  autoCalculate 1 CompleteCalc;
   196  val ((pt,_),_) = get_calc 1;
   197  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   198  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
   199 
   200 
   201 "--------- appendFormula: on Res + late deriv --------------------";
   202 "--------- appendFormula: on Res + late deriv --------------------";
   203 "--------- appendFormula: on Res + late deriv --------------------";
   204  states:=[];
   205  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   206 	    ("Test", ["sqroot-test","univariate","equation","test"],
   207 	     ["Test","squ-equ-test-subpbl1"]))];
   208  Iterator 1; moveActiveRoot 1;
   209  autoCalculate 1 CompleteCalcHead;
   210  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   211  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   212 
   213  appendFormula 1 "x = 1";
   214  val ((pt,p),_) = get_calc 1;
   215  val str = pr_ptree pr_short pt;
   216  writeln str;
   217  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)
   218  then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
   219  else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
   220 
   221  fetchProposedTactic 1;
   222  val (_,(tac,_,_)::_) = get_calc 1;
   223  if tac = Check_Postcond ["linear", "univariate", "equation", "test"] then ()
   224  else error "inform.sml: diff.behav.appendFormula: Res + late d 2";
   225  autoCalculate 1 CompleteCalc;
   226  val ((pt,_),_) = get_calc 1;
   227  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   228  else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
   229 
   230 
   231 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   232 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   233 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   234  states:=[];
   235  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   236 	    ("Test", ["sqroot-test","univariate","equation","test"],
   237 	     ["Test","squ-equ-test-subpbl1"]))];
   238  Iterator 1; moveActiveRoot 1;
   239  autoCalculate 1 CompleteCalcHead;
   240  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   241  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   242  appendFormula 1 "[x = 3 + -2*1]";
   243  val ((pt,p),_) = get_calc 1;
   244  val str = pr_ptree pr_short pt;
   245  writeln str;
   246  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 ()
   247  else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
   248  autoCalculate 1 CompleteCalc;
   249  val ((pt,p),_) = get_calc 1;
   250  if "[x = 3 + -2 * 1]" = term2str (fst (get_obj g_result pt [])) then ()
   251  (*       ~~~~~~~~~~ simplify as last step in any script ?!*)
   252  else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
   253 
   254 
   255 
   256 "--------- replaceFormula: on Res + = ----------------------------";
   257 "--------- replaceFormula: on Res + = ----------------------------";
   258 "--------- replaceFormula: on Res + = ----------------------------";
   259  states:=[];
   260  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   261 	    ("Test", ["sqroot-test","univariate","equation","test"],
   262 	     ["Test","squ-equ-test-subpbl1"]))];
   263  Iterator 1; moveActiveRoot 1;
   264  autoCalculate 1 CompleteCalcHead;
   265  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   266  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   267  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*-1 + x*);
   268 
   269  replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
   270  val ((pt,_),_) = get_calc 1;
   271  val str = pr_ptree pr_short pt;
   272 
   273 (* before AK110725 this was
   274 ".    ----- pblobj -----\n
   275 1.   x + 1 = 2\n
   276 2.   x + 1 + -1 * 2 = 0\n
   277 2.1.   x + 1 + -1 * 2 = 0\n
   278 2.2.   1 + x + -1 * 2 = 0\n
   279 2.3.   1 + (x + -1 * 2) = 0\n
   280 2.4.   1 + (x + -2) = 0\n
   281 2.5.   1 + (x + -2 * 1) = 0\n
   282 2.6.   1 + x + -2 * 1 = 0\n";
   283 *)
   284 if str = 
   285 ".    ----- pblobj -----\n"^
   286 "1.   x + 1 = 2\n"^
   287 "2.   x + 1 + -1 * 2 = 0\n"^
   288 "2.1.   x + 1 + -1 * 2 = 0\n"^
   289 "2.2.   1 + x + -1 * 2 = 0\n"^
   290 "2.3.   1 + (x + -1 * 2) = 0\n"^
   291 "2.4.   1 + (x + -2) = 0\n"^
   292 "2.5.   1 + (x + -2 * 1) = 0\n"^
   293 "2.6.   1 + x + -2 * 1 = 0\n" then()
   294 else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
   295 
   296  autoCalculate 1 CompleteCalc;
   297  val ((pt,pos as (p,_)),_) = get_calc 1;
   298  if pos = ([],Res) andalso "[x = 1]" = (term2str o fst) (get_obj g_result pt p) then()
   299  else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
   300 
   301 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   302 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   303 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   304  states:=[];
   305  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   306 	    ("Test", ["sqroot-test","univariate","equation","test"],
   307 	     ["Test","squ-equ-test-subpbl1"]))];
   308  Iterator 1; moveActiveRoot 1;
   309  autoCalculate 1 CompleteCalcHead;
   310  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   311  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   312 
   313  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   314  val ((pt,_),_) = get_calc 1;
   315  val str = pr_ptree pr_short pt;
   316  writeln str;
   317  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 ()
   318  else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
   319  autoCalculate 1 CompleteCalc;
   320  val ((pt,pos as (p,_)),_) = get_calc 1;
   321  if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
   322  else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
   323 
   324 
   325 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   326 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   327 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   328  states:=[];
   329  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   330 	    ("Test", ["sqroot-test","univariate","equation","test"],
   331 	     ["Test","squ-equ-test-subpbl1"]))];
   332  Iterator 1; moveActiveRoot 1;
   333  autoCalculate 1 CompleteCalcHead;
   334  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   335 
   336  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   337  val ((pt,_),_) = get_calc 1;
   338  val str = pr_ptree pr_short pt;
   339  writeln str;
   340  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 ()
   341  else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
   342  autoCalculate 1 CompleteCalc;
   343  val ((pt,pos as (p,_)),_) = get_calc 1;
   344  if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
   345  else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
   346 
   347 
   348 "--------- replaceFormula: cut calculation -----------------------";
   349 "--------- replaceFormula: cut calculation -----------------------";
   350 "--------- replaceFormula: cut calculation -----------------------";
   351  states:=[];
   352  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   353 	    ("Test", ["sqroot-test","univariate","equation","test"],
   354 	     ["Test","squ-equ-test-subpbl1"]))];
   355  Iterator 1; moveActiveRoot 1;
   356  autoCalculate 1 CompleteCalc;
   357  moveActiveRoot 1; moveActiveDown 1;
   358  if get_pos 1 1 = ([1], Frm) then ()
   359  else error "inform.sml: diff.behav. cut calculation 1";
   360 
   361  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   362  val ((pt,p),_) = get_calc 1;
   363  val str = pr_ptree pr_short pt;
   364  writeln str;
   365  if p = ([1], Res) then ()
   366  else error "inform.sml: diff.behav. cut calculation 2";
   367 
   368 
   369 (* 040307 copied from informtest.sml; ... old version 
   370  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   371  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   372  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   373 
   374  val p = ([],Pbl);
   375  val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
   376 	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   377 	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   378 	      "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
   379 	      (*^^^ these are the elements for the root-problem (in variants)*)
   380               (*vvv these are elements required for subproblems*)
   381 	      "boundVariable a","boundVariable b","boundVariable alpha",
   382 	      "interval {x::real. 0 <= x & x <= 2*r}",
   383 	      "interval {x::real. 0 <= x & x <= 2*r}",
   384 	      "interval {x::real. 0 <= x & x <= pi}",
   385 	      "errorBound (eps=(0::real))"]
   386  (*specifying is not interesting for this example*)
   387  val spec = ("DiffApp", ["maximum_of","function"], 
   388 	     ["DiffApp","max_by_calculus"]);
   389  (*the empty model with descriptions for user-guidance by Model_Problem*)
   390  val empty_model = [Given ["fixedValues []"],
   391 		    Find ["maximum", "valuesFor"],
   392 		    Relate ["relations []"]];
   393 
   394 
   395  (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
   396  val (p,_,f,nxt,_,pt) = CalcTreeTEST [(elems, spec)];
   397  (*val nxt = ("Model_Problem", ...*)
   398  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   399 
   400  val (p,_,f,nxt,_,pt) = me nxt p c pt;
   401  (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
   402  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   403 (*[
   404 (0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
   405 (0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
   406 (0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
   407 (0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
   408 
   409  (*the empty CalcHead is checked w.r.t the model and re-established as such*)
   410  val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, e_spec);
   411  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   412  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";
   413 
   414  (*there is one input to the model (could be more)*)
   415  val (b,pt,ocalhd) = 
   416      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   417 			     Find ["maximum", "valuesFor"],
   418 			     Relate ["relations"]], Pbl, e_spec);
   419  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   420  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 () 
   421  else error "informtest.sml: diff.behav. max 2";
   422 
   423  (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
   424  val (b,pt''''',ocalhd) = 
   425      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   426 			     Find ["maximum A", "valuesFor [a,b]"],
   427 			     Relate ["relations [A=a*b, a/2=r*sin alpha, \
   428 				     \b/2=r*cos alpha]"]], Pbl, e_spec);
   429  val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   430  if ocalhd2str ocalhd = ------------^^^^^^^^^^ missing !!!*)
   431 
   432  (*this input is complete in variant 1 (variant 3 does not work yet)*)
   433  val (b,pt''''',ocalhd) = 
   434      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   435 			     Find ["maximum A", "valuesFor [a,b]"],
   436 			     Relate ["relations [A=a*b, \
   437 				     \(a/2)^^^2 + (b/2)^^^2 = r^^^2]"]], 
   438 		      Pbl, e_spec);
   439  val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   440 
   441  modifycalcheadOK2xml 111 (bool2str b) ocalhd;
   442 *)
   443 
   444 "--------- syntax error ------------------------------------------";
   445 "--------- syntax error ------------------------------------------";
   446 "--------- syntax error ------------------------------------------";
   447  states:=[];
   448  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   449 	    ("Test", ["sqroot-test","univariate","equation","test"],
   450 	     ["Test","squ-equ-test-subpbl1"]))];
   451  Iterator 1; moveActiveRoot 1;
   452  autoCalculate 1 CompleteCalcHead;
   453  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   454  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   455 
   456  appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
   457  val ((pt,_),_) = get_calc 1;
   458  val str = pr_ptree pr_short pt;
   459  writeln str;
   460  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" then ()
   461  else error "inform.sml: diff.behav.appendFormula: syntax error";
   462 
   463 
   464 "--------- CAS-command on ([],Pbl) -------------------------------";
   465 "--------- CAS-command on ([],Pbl) -------------------------------";
   466 "--------- CAS-command on ([],Pbl) -------------------------------";
   467 val (p,_,f,nxt,_,pt) = 
   468     CalcTreeTEST [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   469 val ifo = "solve(x+1=2,x)";
   470 val (_,(_,c,(pt,p))) = inform ([],[],(pt,p)) "solve(x+1=2,x)";
   471 show_pt pt;
   472 val nxt = ("Apply_Method",Apply_Method ["Test","squ-equ-test-subpbl1"]);
   473 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   474 if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
   475 else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
   476 
   477 
   478 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   479 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   480 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   481 states:=[];
   482 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   483 Iterator 1;
   484 moveActiveRoot 1;
   485 replaceFormula 1 "solve(x+1=2,x)";
   486 autoCalculate 1 CompleteCalc;
   487 val ((pt,p),_) = get_calc 1;
   488 show_pt pt;
   489 if p = ([], Res) then ()
   490 else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
   491 
   492 
   493 "--------- inform [rational,simplification] ----------------------";
   494 "--------- inform [rational,simplification] ----------------------";
   495 "--------- inform [rational,simplification] ----------------------";
   496 states:=[];
   497 CalcTree [(["Term (4/x - 3/y - 1)", "normalform N"],
   498 	   ("Rational",["rational","simplification"],
   499 	    ["simplification","of_rationals"]))];
   500 Iterator 1; moveActiveRoot 1;
   501 autoCalculate 1 CompleteCalcHead;
   502 autoCalculate 1 (Step 1);
   503 autoCalculate 1 (Step 1);
   504 autoCalculate 1 (Step 1);
   505 autoCalculate 1 (Step 1);
   506 "--- input the next formula that _should_ be presented by mat-engine";
   507 appendFormula 1 "(4 * y + -3 * x) / (x * y) + -1";
   508 val ((pt,p),_) = get_calc 1;
   509 if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   510 else error ("inform.sml: [rational,simplification] 1");
   511 
   512 "--- input the next formula that would be presented by mat-engine";
   513 (*autoCalculate 1 (Step 1);*)
   514 appendFormula 1 "(4 * y + -3 * x + -1 * (x * y)) / (x * y)";
   515 val ((pt,p),_) = get_calc 1;
   516 if p = ([5], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
   517 else error ("inform.sml: [rational,simplification] 2");
   518 
   519 "--- input the exact final result";(*TODO: Exception- LIST "last_elem" raised*)
   520 appendFormula 1 "(-3 * x + 4 * y + -1 * x * y) / (x * y)";
   521 val ((pt,p),_) = get_calc 1;
   522 if p = ([6], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   523 else error ("inform.sml: [rational,simplification] 3");
   524 show_pt pt;
   525 
   526 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   527 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   528 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   529 val t = str2term "Diff (x^^^2 + x + 1, x)";
   530 case t of Const ("Diff.Diff", _) $ _ => ()
   531 	| _ => raise 
   532 	      error "diff.sml behav.changed for CAS Diff (..., x)";
   533 atomty t;
   534 "-----------------------------------------------------------------";
   535 (*1>*)states:=[];
   536 (*2>*)CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   537 (*3>*)Iterator 1;moveActiveRoot 1;
   538 "----- here the Headline has been finished";
   539 (*4>*)moveActiveFormula 1 ([],Pbl);
   540 (*5>*)replaceFormula 1 "Diff (x^2 + x + 1, x)";
   541 val ((pt,_),_) = get_calc 1;
   542 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   543 val NONE = env;
   544 val (SOME istate, NONE) = loc;
   545 print_depth 5;
   546 writeln"-----------------------------------------------------------";
   547 spec;
   548 writeln (itms2str_ ctxt probl);
   549 writeln (itms2str_ ctxt meth);
   550 writeln (istate2str (fst istate));
   551 
   552 refFormula 1 ([],Pbl) (*--> correct CalcHead*);
   553  (*081016 NOT necessary (but leave it in Java):*)
   554 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
   555 "----- here the CalcHead has been completed --- ONCE MORE ?????";
   556 
   557 (***difference II***)
   558 val ((pt,p),_) = get_calc 1;
   559 (*val p = ([], Pbl)*)
   560 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   561 val NONE = env;
   562 val (SOME istate, NONE) = loc;
   563 print_depth 5; writeln (istate2str (fst istate));  print_depth 3;
   564 (*ScrState ([],
   565  [], NONE,
   566  ??.empty, Sundef, false)*)
   567 print_depth 5; spec; print_depth 3;
   568 (*("Isac",
   569       ["derivative_of", "function"],
   570       ["diff", "differentiate_on_R"]) : spec*)
   571 writeln (itms2str_ ctxt probl);
   572 (*[
   573 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   574 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   575 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   576 writeln (itms2str_ ctxt meth);
   577 (*[
   578 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   579 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   580 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   581 writeln"-----------------------------------------------------------";
   582 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   583 (*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
   584 autoCalculate 1 CompleteCalc;
   585 val ((pt,p),_) = get_calc 1;
   586 val Form res = (#1 o pt_extract) (pt, ([],Res));
   587 show_pt pt;
   588 if p = ([], Res) andalso term2str res = "1 + 2 * x" then ()
   589 else error "diff.sml behav.changed for Diff (x^2 + x + 1, x)";
   590 
   591 "--------- Take as 1st tac, start from exp -----------------------";
   592 "--------- Take as 1st tac, start from exp -----------------------";
   593 "--------- Take as 1st tac, start from exp -----------------------";
   594 (*the following input is copied from BridgeLog Java <==> SML,
   595   omitting unnecessary inputs*)
   596 (*1>*)states:=[];
   597 (*2>*)CalcTree [(["functionTerm (x^2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac",["derivative_of","function"],["diff","differentiate_on_R"]))];
   598 (*3>*)Iterator 1; moveActiveRoot 1;
   599 
   600 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
   601 (***difference II***)
   602 val ((pt,_),_) = get_calc 1;
   603 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   604 val NONE = env;
   605 val (SOME istate, NONE) = loc;
   606 print_depth 5; writeln (istate2str (fst istate));  print_depth 3;
   607 (*ScrState ([],
   608  [], NONE,
   609  ??.empty, Sundef, false)*)
   610 print_depth 5; spec; print_depth 3;
   611 (*("Isac",
   612       ["derivative_of", "function"],
   613       ["diff", "differentiate_on_R"]) : spec*)
   614 writeln (itms2str_ ctxt probl);
   615 (*[
   616 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   617 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   618 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   619 writeln (itms2str_ ctxt meth);
   620 (*[
   621 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   622 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   623 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   624 writeln"-----------------------------------------------------------";
   625 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   626 autoCalculate 1 (Step 1);
   627 val ((pt,p),_) = get_calc 1;
   628 val Form res = (#1 o pt_extract) (pt, p);
   629 if term2str res = "d_d x (x ^^^ 2 + x + 1)" then ()
   630 else error "diff.sml Diff (x^2 + x + 1, x) from exp";
   631 
   632 "--------- init_form, start with <NEW> (CAS input) ---------------";
   633 "--------- init_form, start with <NEW> (CAS input) ---------------";
   634 "--------- init_form, start with <NEW> (CAS input) ---------------";
   635 states:=[];
   636 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   637 (*[[from sml: > @@@@@begin@@@@@
   638 [[from sml:  1 
   639 [[from sml: <CALCTREE>
   640 [[from sml:    <CALCID> 1 </CALCID>
   641 [[from sml: </CALCTREE>
   642 [[from sml: @@@@@end@@@@@*)
   643 Iterator 1;
   644 (*[[from sml: > @@@@@begin@@@@@
   645 [[from sml:  1 
   646 [[from sml: <ADDUSER>
   647 [[from sml:   <CALCID> 1 </CALCID>
   648 [[from sml:   <USERID> 1 </USERID>
   649 [[from sml: </ADDUSER>
   650 [[from sml: @@@@@end@@@@@*)
   651 moveActiveRoot 1;
   652 (*[[from sml: > @@@@@begin@@@@@
   653 [[from sml:  1 
   654 [[from sml: <CALCITERATOR>
   655 [[from sml:   <CALCID> 1 </CALCID>
   656 [[from sml:   <POSITION>
   657 [[from sml:     <INTLIST>
   658 [[from sml:     </INTLIST>
   659 [[from sml:     <POS> Pbl </POS>
   660 [[from sml:   </POSITION>
   661 [[from sml: </CALCITERATOR>
   662 [[from sml: @@@@@end@@@@@*)
   663 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
   664 (*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
   665 [[from sml:  1 
   666 [[from sml: <GETELEMENTSFROMTO>
   667 [[from sml:   <CALCID> 1 </CALCID>
   668 [[from sml:   <FORMHEADS>
   669 [[from sml:     <CALCFORMULA>
   670 [[from sml:       <POSITION>
   671 [[from sml:         <INTLIST>
   672 [[from sml:         </INTLIST>
   673 [[from sml:         <POS> Pbl </POS>
   674 [[from sml:       </POSITION>
   675 [[from sml:       <FORMULA>
   676 [[from sml:         <MATHML>
   677 [[from sml:           <ISA> ________________________________________________ </ISA>
   678 [[from sml:         </MATHML>
   679 [[from sml: 
   680 [[from sml:       </FORMULA>
   681 [[from sml:     </CALCFORMULA>
   682 [[from sml:   </FORMHEADS>
   683 [[from sml: </GETELEMENTSFROMTO>
   684 [[from sml: @@@@@end@@@@@*)
   685 refFormula 1 ([],Pbl);
   686 (*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
   687 [[from sml:  1 
   688 [[from sml: <REFFORMULA>
   689 [[from sml:   <CALCID> 1 </CALCID>
   690 [[from sml:   <CALCHEAD status = "incorrect">
   691 [[from sml:     <POSITION>
   692 [[from sml:       <INTLIST>
   693 [[from sml:       </INTLIST>
   694 [[from sml:       <POS> Pbl </POS>
   695 [[from sml:     </POSITION>
   696 [[from sml:     <HEAD>
   697 [[from sml:       <MATHML>
   698 [[from sml:         <ISA> Problem (e_domID, [e_pblID]) </ISA>
   699 [[from sml:       </MATHML>
   700 [[from sml:     </HEAD>
   701 [[from sml:     <MODEL>
   702 [[from sml:       <GIVEN>  </GIVEN>
   703 [[from sml:       <WHERE>  </WHERE>
   704 [[from sml:       <FIND>  </FIND>
   705 [[from sml:       <RELATE>  </RELATE>
   706 [[from sml:     </MODEL>
   707 [[from sml:     <BELONGSTO> Pbl </BELONGSTO>
   708 [[from sml:     <SPECIFICATION>
   709 [[from sml:       <THEORYID> e_domID </THEORYID>
   710 [[from sml:       <PROBLEMID>
   711 [[from sml:         <STRINGLIST>
   712 [[from sml:           <STRING> e_pblID </STRING>
   713 [[from sml:         </STRINGLIST>
   714 [[from sml:       </PROBLEMID>
   715 [[from sml:       <METHODID>
   716 [[from sml:         <STRINGLIST>
   717 [[from sml:           <STRING> e_metID </STRING>
   718 [[from sml:         </STRINGLIST>
   719 [[from sml:       </METHODID>
   720 [[from sml:     </SPECIFICATION>
   721 [[from sml:   </CALCHEAD>
   722 [[from sml: </REFFORMULA>
   723 [[from sml: @@@@@end@@@@@*)
   724 moveActiveFormula 1 ([],Pbl);
   725 (*[[from sml: > @@@@@begin@@@@@
   726 [[from sml:  1 
   727 [[from sml: <CALCITERATOR>
   728 [[from sml:   <CALCID> 1 </CALCID>
   729 [[from sml:   <POSITION>
   730 [[from sml:     <INTLIST>
   731 [[from sml:     </INTLIST>
   732 [[from sml:     <POS> Pbl </POS>
   733 [[from sml:   </POSITION>
   734 [[from sml: </CALCITERATOR>
   735 [[from sml: @@@@@end@@@@@*)
   736 replaceFormula 1 "Simplify (1+2)";
   737 (*[[from sml: > @@@@@begin@@@@@
   738 [[from sml:  1 
   739 [[from sml: <REPLACEFORMULA>
   740 [[from sml:   <CALCID> 1 </CALCID>
   741 [[from sml:   <CALCCHANGED>
   742 [[from sml:     <UNCHANGED>
   743 [[from sml:       <INTLIST>
   744 [[from sml:       </INTLIST>
   745 [[from sml:       <POS> Pbl </POS>
   746 [[from sml:     </UNCHANGED>
   747 [[from sml:     <DELETED>
   748 [[from sml:       <INTLIST>
   749 [[from sml:       </INTLIST>
   750 [[from sml:       <POS> Pbl </POS>
   751 [[from sml:     </DELETED>
   752 [[from sml:     <GENERATED>
   753 [[from sml:       <INTLIST>
   754 [[from sml:       </INTLIST>
   755 [[from sml:       <POS> Met </POS>                           DIFFERENCE: Pbl
   756 [[from sml:     </GENERATED>
   757 [[from sml:   </CALCCHANGED>
   758 [[from sml: </REPLACEFORMULA>
   759 [[from sml: @@@@@end@@@@@*)
   760 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(*              DIFFERENCE: Pbl*);
   761 (*@@@@@begin@@@@@
   762  1
   763 <GETELEMENTSFROMTO>
   764   <CALCID> 1 </CALCID>
   765   <FORMHEADS>
   766     <CALCFORMULA>
   767       <POSITION>
   768         <INTLIST>
   769         </INTLIST>
   770         <POS> Pbl </POS>
   771       </POSITION>
   772       <FORMULA>
   773         <MATHML>
   774           <ISA> Simplify (1 + 2) </ISA>                      WORKS !!!!!
   775         </MATHML>
   776       </FORMULA>
   777     </CALCFORMULA>
   778   </FORMHEADS>
   779 </GETELEMENTSFROMTO>
   780 @@@@@end@@@@@*)
   781 getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
   782 (*[[from sml: > @@@@@begin@@@@@
   783 [[from sml:  1 
   784 [[from sml: <SYSERROR>
   785 [[from sml:   <CALCID> 1 </CALCID>
   786 [[from sml:   <ERROR> error in getFormulaeFromTo </ERROR>
   787 [[from sml: </SYSERROR>
   788 [[from sml: @@@@@end@@@@@*)
   789 (*step into getFormulaeFromTo --- bug corrected...*)
   790 
   791 "--------- build fun check_err_patt ------------------------------";
   792 "--------- build fun check_err_patt ------------------------------";
   793 "--------- build fun check_err_patt ------------------------------";
   794 val subst = [(str2term "bdv", str2term "x")]: subst;
   795 val rls = norm_Rational
   796 val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
   797 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
   798 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "1 / 2");
   799 
   800 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
   801   rew_sub thy 1 [] e_rew_ord e_rls false [] (Trueprop $ pat) res;
   802 if rewritten then NONE else SOME "e_errpatID";
   803 
   804 val norm_res = case rewrite_set_ (Isac()) false rls res' of
   805   NONE => res'
   806 | SOME (norm_res, _) => norm_res
   807 
   808 val norm_inf = case rewrite_set_ (Isac()) false rls inf of
   809   NONE => inf
   810 | SOME (norm_inf, _) => norm_inf;
   811 
   812 res' = inf;
   813 norm_res = norm_inf;
   814 
   815 val pat = parse_patt @{theory} "(?a + ?b)/?a = ?b";
   816 val (res, inf) = (str2term "(2 + 3)/2", str2term "3");
   817 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   818 then () else error "error patt example1 changed";
   819 
   820 val pat = parse_patt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
   821 val (res, inf) = (str2term "(2 + 3)/(2 + 4)", str2term "3 / 4");
   822 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   823 then () else error "error patt example2 changed";
   824 
   825 val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
   826 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
   827 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   828 then () else error "error patt example3 changed";
   829 
   830 val inf =  str2term "1 / 2";
   831 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   832 then () else error "error patt example3 changed";
   833 
   834 "--------- build fun check_err_patt ?bdv -------------------------";
   835 "--------- build fun check_err_patt ?bdv -------------------------";
   836 "--------- build fun check_err_patt ?bdv -------------------------";
   837 val subst = [(str2term "bdv", str2term "x")]: subst;
   838 val t = str2term "d_d x (x ^^^ 2 + sin (x ^^^ 4))";
   839 val SOME (t, _) = rewrite_set_inst_ thy false subst norm_diff t;
   840 if term2str t = "2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3" then ()
   841 else error "build fun check_err_patt ?bdv changed 1"; 
   842 
   843 val rls = norm_diff
   844 val pat = parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)"; 
   845 val (res, inf) = (str2term "2 * x + d_d x (sin (x ^^^ 4))", str2term "2 * x + cos (4 * x ^^^ 3)");
   846 
   847 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
   848   rew_sub thy 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) res;
   849 if term2str res' = "2 * x + cos (d_d x (x ^^^ 4))" andalso rewritten then ()
   850 else error "build fun check_err_patt ?bdv changed 2";
   851 
   852 val norm_res = case rewrite_set_inst_ (Isac()) false subst rls  res' of
   853   NONE => res'
   854 | SOME (norm_res, _) => norm_res;
   855 if term2str norm_res = "2 * x + cos (4 * x ^^^ 3)" then ()
   856 else error "build fun check_err_patt ?bdv changed 3";
   857 
   858 val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
   859   NONE => inf
   860 | SOME (norm_inf, _) => norm_inf;
   861 if term2str norm_inf = "2 * x + cos (4 * x ^^^ 3)" then ()
   862 else error "build fun check_err_patt ?bdv changed 4";
   863 
   864 res' = inf;
   865 if norm_res = norm_inf then ()
   866 else error "build fun check_err_patt ?bdv changed 5";
   867 
   868 if check_err_patt (res, inf) (subst: subst) ("errpatID": errpatID, pat) rls = SOME "errpatID"
   869 then () else error "error patt example1 changed";
   870 
   871 "--------- build fun check_error_patterns ------------------------";
   872 "--------- build fun check_error_patterns ------------------------";
   873 "--------- build fun check_error_patterns ------------------------";
   874 val (res, inf) =
   875   (str2term "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))",
   876    str2term "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)");
   877 val {errpats, nrls = rls, scr = Prog prog, ...} = get_met ["diff", "differentiate_on_R"]
   878 
   879 val env = [(str2term "v_v", str2term "x")];
   880 val errpats =
   881   [e_errpat, (*generalised for testing*)
   882    ("chain-rule-diff-both",
   883      [parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)",
   884       parse_patt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)",
   885       parse_patt @{theory} "d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1)",
   886       parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u",
   887       parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u"],
   888      [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain}, 
   889       @{thm diff_ln_chain}, @{thm  diff_exp_chain}])]: errpat list;
   890 case check_error_patterns (res, inf) (prog, env) (errpats, rls) of SOME _ => () 
   891 | NONE => error "check_error_patterns broken";
   892 
   893 "--------- embed fun check_error_patterns ------------------------";
   894 "--------- embed fun check_error_patterns ------------------------";
   895 "--------- embed fun check_error_patterns ------------------------";
   896 states:=[];
   897 CalcTree
   898 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
   899   ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
   900 Iterator 1;
   901 moveActiveRoot 1;
   902 autoCalculate 1 CompleteCalcHead;
   903 autoCalculate 1 (Step 1);
   904 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
   905 (*autoCalculate 1 (Step 1);([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)*)
   906 
   907 "~~~~~ fun appendFormula, args:"; val (cI, (ifo:cterm')) = (1, "d_d x (x ^ 2) + cos (4 * x ^ 3)");
   908 val cs = get_calc cI
   909 val pos as (_,p_) = get_pos cI 1; (*pos = ([1], Res)*)
   910 val cs' = 
   911     case step pos cs of
   912 	    ("ok", cs') => cs';
   913 
   914 val (_, _, (pt, ([2], Res))) = cs';
   915 (*show_pt pt;
   916   [(([], Frm), Diff (x ^^^ 2 + sin (x ^^^ 4), x)),
   917    (([1], Frm), d_d x (x ^^^ 2 + sin (x ^^^ 4))),
   918    (([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))), <<=== input follos: "...+ cos(4.x^3)"
   919    (([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4))] *)
   920 
   921 "~~~~~ fun inform, args:"; val ((cs as (_, _, ptp as (pt, pos as (p, p_))): calcstate'), istr) =
   922   (cs', (encode ifo));
   923 val 	SOME f_in = parse (assoc_thy "Isac") istr
   924 val f_in = term_of f_in
   925 val pos_pred = lev_back' pos
   926 			(* f_pred ---"step pos cs"---> f_succ in appendFormula
   927    TODO.WN120517: one starting point for redesign of pos' *)
   928 val (f_pred, f_succ) = (get_curr_formula (pt, pos_pred), get_curr_formula (pt, pos));
   929 	
   930 term2str f_pred = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))";
   931 term2str f_succ = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)";
   932 
   933 			f_succ = f_in; (* = false*)
   934 cas_input f_in; (* = NONE*)
   935 val msg_calcstate' = compare_step ([], [], (pt, pos_pred)) f_in
   936 val ("no derivation found", calcstate') = msg_calcstate';
   937 			                 val pp = par_pblobj pt p
   938 			                 val {errpats, nrls, scr = Prog prog, ...} = get_met (get_obj g_metID pt pp)
   939 			                 val ScrState (env, _, _, _, _, _) = get_istate pt pos;
   940                  case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
   941 			                   SOME errpatID => ("error pattern #" ^ errpatID ^ "#", calcstate')
   942 			                 | NONE => msg_calcstate';
   943 
   944 "~~~~~ from inform return val:"; val () = ();
   945 case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
   946 			  SOME errpatID => ()
   947 			| NONE => error "check_error_patterns broken";
   948 
   949 "--- final check:";
   950 case inform cs' (encode ifo) of
   951   ("error pattern #chain-rule-diff-both#", calcstate') => ()
   952 | _ => error "inform with (positive) check_error_patterns broken"
   953 
   954 "--------- build fun get_fillpats --------------------------------";
   955 "--------- build fun get_fillpats --------------------------------";
   956 "--------- build fun get_fillpats --------------------------------";
   957 (*cause for this test was: wrong thy in Build_Thydata.thy in 
   958   insert_fillpats ["IsacKnowledge", "Diff", "Theorems", "diff_sin_chain"]*)
   959 val f_curr = str2term "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"
   960 val errpatID = "chain-rule-diff-both"
   961   val {errpats, scr = Prog prog, ...} = get_met ["diff", "differentiate_on_R"]
   962 val env = 
   963   [(str2term "f_f", str2term "x ^^^ 2 + sin (x ^^^ 4)"),
   964    (str2term "v_v", str2term "x"),
   965    (str2term "f_f'", str2term "d_d x (x ^^^ 2 + sin (x ^^^ 4))")]
   966   val subst = get_bdv_subst prog env
   967   val errpatthms = errpats
   968     |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
   969     |> map (#3: errpat -> thm list)
   970     |> flat;
   971 "~~~~~ fun get_fillpats, args:"; val (subst, form, errpatID, thm) =
   972   (subst, f_curr, errpatID, hd (*simulate beginning of "map"*) errpatthms);
   973         val thmDeriv = Thm.get_name_hint thm
   974         val (part, thyID) = thy_containing_thm thmDeriv
   975         val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
   976         val Hthm {fillpats, ...} = get_the theID
   977         val some = map (get_fillform subst (thm, form) errpatID) fillpats;
   978 "~~~~~ fun get_fillform, args:";
   979   val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
   980   (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
   981   val (form', _, _, rewritten) =
   982         rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) form;
   983 "~~~~~ fun rew_sub, args:"; val (thy, i, bdv, tless, rls, put_asm, lrd:lrd list, r, t) = 
   984   ((Isac()), 1, subst, e_rew_ord, e_rls, false, [], (Trueprop $ pat), form);
   985      val (lhs, rhs) = (HOLogic.dest_eq o HOLogic.dest_Trueprop
   986                        o Logic.strip_imp_concl) r;
   987 (*/-------------catch the planned exception*)
   988 (let
   989      val r' = Envir.subst_term (Pattern.match thy (lhs, t) 
   990 					      (Vartab.empty, Vartab.empty)) r;
   991 in 111 end
   992 ) handle PATTERN (*because only a subterm matches*) => 111;
   993 case t of t1 $ t2 => 
   994 	  let val (t2', asm2, lrd, rew2) = rew_sub thy i bdv tless rls put_asm (lrd@[R]) r t2
   995 	  in 
   996 	    if rew2 then (t1 $ t2', asm2, lrd, true) else
   997 	      let val (t1', asm1, lrd, rew1) = rew_sub thy i bdv tless rls put_asm (lrd@[L]) r t1
   998 	      in if rew1 then (t1' $ t2, asm1, lrd, true) else (t1 $ t2,[], lrd, false) end
   999 	  end;
  1000 (*catch the planned exception-------------/*)
  1001 
  1002 val t1 $ t2 = t;
  1003 val (t2', asm2, lrd, rew2) = rew_sub thy i bdv tless rls put_asm (lrd@[R]) r t2;
  1004 "~~~~~ fun rew_sub, args:"; val (thy, i, bdv, tless, rls, put_asm, lrd:lrd list, r, t) = 
  1005   (thy, i, bdv, tless, rls, put_asm, (lrd@[R]), r, t2);
  1006      val (lhs, rhs) = (HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r;
  1007      val r' = Envir.subst_term (Pattern.match thy (lhs, t) (Vartab.empty, Vartab.empty)) r;
  1008      val p' = map HOLogic.dest_Trueprop ((fst o Logic.strip_prems) (Logic.count_prems r', [], r'));
  1009      val t' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r';
  1010 if term2str t' = "cos (x ^^^ 4) * d_d x ?_dummy_1" then ()
  1011   else error "get_fillpats changed 1"
  1012 
  1013 "--------- embed fun find_fillpatterns ---------------------------";
  1014 "--------- embed fun find_fillpatterns ---------------------------";
  1015 "--------- embed fun find_fillpatterns ---------------------------";
  1016 states:=[];
  1017 CalcTree
  1018 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
  1019   ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
  1020 Iterator 1;
  1021 moveActiveRoot 1;
  1022 autoCalculate 1 CompleteCalcHead;
  1023 autoCalculate 1 (Step 1);
  1024 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
  1025 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)";
  1026   (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
  1027   (*or
  1028     <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
  1029 
  1030 "~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
  1031   val ((pt, _), _) = get_calc cI
  1032 				val pos = get_pos cI 1;
  1033 "~~~~~ fun find_fillpatterns, args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
  1034 	    val f_curr = get_curr_formula (pt, pos); (* = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"*)
  1035     val pp = par_pblobj pt p
  1036     val {errpats, scr = Prog prog, ...} = get_met (get_obj g_metID pt pp)
  1037     val ScrState (env, _, _, _, _, _) = get_istate pt pos
  1038     val subst = get_bdv_subst prog env
  1039     val errpatthms = errpats
  1040       |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
  1041       |> map (#3: errpat -> thm list)
  1042       |> flat;
  1043 
  1044 case map (get_fillpats subst f_curr errpatID) errpatthms |> flat of
  1045   ("fill-d_d-arg", tm, thm, subs_opt) :: _ => if term2str tm = 
  1046     "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
  1047     then () else error "find_fillpatterns changed 1a"
  1048 | _ => error "find_fillpatterns changed 1b"
  1049 
  1050 "~~~~~ fun get_fillpats, args:"; val (subst, form, errpatID, thm) =
  1051   (subst, f_curr, errpatID, hd (*simulate beginning of "map"*) errpatthms);
  1052         val thmDeriv = Thm.get_name_hint thm
  1053         val (part, thyID) = thy_containing_thm thmDeriv
  1054         val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
  1055         val Hthm {fillpats, ...} = get_the theID
  1056         val some = map (get_fillform subst (thm, form) errpatID) fillpats;
  1057 
  1058 case some |> filter is_some |> map the of
  1059   ("fill-d_d-arg", tm, thm, subsopt) :: _ => if term2str tm = 
  1060     "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
  1061     then () else error "find_fillpatterns changed 2a"
  1062 | _ => error "find_fillpatterns changed 2b"
  1063 
  1064 "~~~~~ fun get_fillform, args:";
  1065   val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
  1066   (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
  1067 val (form', _, _, rewritten) =
  1068       rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) form;
  1069 
  1070 if term2str form' = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" then ()
  1071 else error "find_fillpatterns changed 3";
  1072 
  1073 "~~~~~ to findFillpatterns return val:"; val (fillpats) =
  1074   (map (get_fillpats (subs_opt, subst) f_curr errpatID) errpatthms |> flat) (*only from "hd errpatthms"*);
  1075 
  1076 "vvv--- dropped this code WN120730";
  1077 val msg = "fill patterns " ^
  1078   ((map ((apsnd term2str) o quad2pair) fillpats) |> map pair2str_ |> strs2str_);
  1079 msg =
  1080   "fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1081     " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" ^
  1082   "#fill-both-args#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1083     " =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3" ^
  1084   "#fill-d_d#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1085     " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1 x (x ^^^ 4)" ^
  1086   "#fill-inner-deriv#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1087     " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1" ^
  1088   "#fill-all#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) = d_d x (x ^^^ 2) + ?_dummy_1#";
  1089 "^^^--- dropped this code WN120730";
  1090 
  1091 if (map #1 fillpats) =
  1092   ["fill-d_d-arg", "fill-both-args", "fill-d_d", "fill-inner-deriv", "fill-all"]
  1093 then () else error "find_fillpatterns changed 4b";
  1094 
  1095 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1096 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1097 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1098 states := [];
  1099 CalcTree
  1100 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
  1101   ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
  1102 Iterator 1;
  1103 moveActiveRoot 1;
  1104 autoCalculate 1 CompleteCalcHead;
  1105 autoCalculate 1 (Step 1);
  1106 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
  1107 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)"; (*<<<<<<<=========================*)
  1108 (* the check for errpat is maximally liberal (whole term modulo "nrls" from "type met"),
  1109   would recognize "cos (4 * x ^ (4 - 1)) + 2 * x" as well.
  1110   results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
  1111   instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
  1112   val ((pt,pos), _) = get_calc 1;
  1113   val p = get_pos 1 1;
  1114   val (Form f, _, asms) = pt_extract (pt, p);
  1115 
  1116   if p = ([1], Res) andalso term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
  1117     get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], ("diff_sum", "Diff.diff_sum"(*?!?*)))
  1118   then () else error "embed fun get_fillform changed 1";
  1119 
  1120 findFillpatterns 1 "chain-rule-diff-both"; (*<<<<<<<=================================*)
  1121 (*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =
  1122   d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
  1123   val ((pt,pos),_) = get_calc 1;
  1124   val p = get_pos 1 1;
  1125 
  1126   val (Form f, _, asms) = pt_extract (pt, p);
  1127   if p = ([1], Res) andalso term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
  1128     get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], ("diff_sum", "Diff.diff_sum"(*?!?*)))
  1129   then ()
  1130   else error "embed fun get_fillform changed 2";
  1131 
  1132 requestFillformula 1 ("chain-rule-diff-both", "fill-both-args");(*<<<<<<<============*)
  1133   (*<AUTOCALC> ([1], Res) ([2], Res) ([2], Res) </AUTOCALC>*)
  1134   val ((pt,pos),_) = get_calc 1;
  1135   val p = get_pos 1 1;
  1136   val (Form f, _, asms) = pt_extract (pt, p);
  1137   if p = ([1], Res) andalso existpt [2] pt andalso
  1138     term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
  1139     get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], ("diff_sum", "Diff.diff_sum"))
  1140   then () else error "embed fun get_fillform changed 3";
  1141 
  1142 (* input a formula which exactly fills the gaps in a "fillformula"
  1143    presented to the learner immediately before by "requestFillformula (errpatID, fillpatID)":
  1144    errpatID: lhs of the respective thm = lhs of fillformula with fillpatID.
  1145    the respective thm is in the ctree ................
  1146 *)
  1147 "~~~~~ fun inputFillFormula, args:"; val (cI, ifo) =
  1148   (1, "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)");
  1149     val ((pt, _), _) = get_calc cI
  1150     val pos = get_pos cI 1;
  1151 
  1152 "~~~~~ fun is_exactly_equal, args:"; val ((pt, pos as (p, p_)), istr) = ((pt, pos), ifo);
  1153   val SOME ifo = parseNEW (assoc_thy "Isac" |> thy2ctxt) istr
  1154   val p' = lev_on p;
  1155   val tac = get_obj g_tac pt p';
  1156   if tac = Rewrite_Inst (["(bdv, x)"], ("diff_sin_chain", "")) then ()
  1157   else error "inputFillFormula changed 10";
  1158   val Appl rew = applicable_in pos pt tac;
  1159   val Rewrite_Inst' (_, _, _, _, _, _, _, (res, _)) = rew;
  1160 
  1161 "~~~~~ to inputFillFormula return val:"; val ("ok", tac) = ("ok", tac);
  1162   val ("ok", (_, c, ptp as (_,p'))) = locatetac tac (pt, pos);
  1163     upd_calc cI (ptp, []);
  1164     upd_ipos cI 1 p';
  1165     autocalculateOK2xml cI pos (if null c then p' else last_elem c) p';
  1166 
  1167 "~~~~~ final check:";
  1168 val ((pt, _),_) = get_calc 1;
  1169 val p = get_pos 1 1;
  1170 val (Form f, _, asms) = pt_extract (pt, p);
  1171 if p = ([2], Res) andalso
  1172   term2str f = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)" andalso
  1173   get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], ("diff_sin_chain", ""))
  1174 then () else error "inputFillFormula changed 11";
  1175