test/Tools/isac/Interpret/inform.sml
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 21 May 2012 16:56:01 +0200
changeset 42430 5b629bb1c073
parent 42428 aaca5c033fa4
child 42431 22f0435fdfe2
permissions -rw-r--r--
added fun FindFillpatterns

TODO: separate "error pattern #" from "no derivation found"
     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 "--------- embed fun find_fillpatterns ---------------------------";
    39 "-----------------------------------------------------------------";
    40 "-----------------------------------------------------------------";
    41 "-----------------------------------------------------------------";
    42 
    43 
    44 
    45 
    46 
    47 
    48 "--------- appendFormula: on Res + equ_nrls ----------------------";
    49 "--------- appendFormula: on Res + equ_nrls ----------------------";
    50 "--------- appendFormula: on Res + equ_nrls ----------------------";
    51 
    52  val Script sc = (#scr o get_met) ["Test","squ-equ-test-subpbl1"];
    53  (writeln o term2str) sc;
    54  val Script sc = (#scr o get_met) ["Test","solve_linear"];
    55  (writeln o term2str) sc;
    56 
    57  states:=[];
    58  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
    59 	    ("Test", ["sqroot-test","univariate","equation","test"],
    60 	     ["Test","squ-equ-test-subpbl1"]))];
    61  Iterator 1; moveActiveRoot 1;
    62  autoCalculate 1 CompleteCalcHead;
    63  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
    64  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
    65 
    66  appendFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
    67  val ((pt,_),_) = get_calc 1;
    68  val str = pr_ptree pr_short pt;
    69 
    70  writeln str;
    71 (*============ inhibit exn AK110726 ==============================================
    72 (* 2nd string should be the same as 1st one *)
    73 ".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n2.1.   x + 1 + -1 * 2 = 0\n2.2.   1 + x + -1 * 2 = 0\n2.3.   1 + (x + -1 * 2) = 0\n2.4.   1 + (x + -2) = 0\n2.5.   1 + (x + -2 * 1) = 0\n2.6.   1 + x + -2 * 1 = 0\n";
    74 ".    ----- 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";
    75  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 ()
    76    else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
    77 ============ inhibit exn AK110726 ==============================================*)
    78 
    79  moveDown 1 ([ ],Pbl); refFormula 1 ([1],Frm); (*x + 1 = 2*)
    80  moveDown 1 ([1],Frm); refFormula 1 ([1],Res); (*x + 1 + -1 * 2 = 0*)
    81 
    82  (*the seven steps of detailed derivation*)
    83  moveDown 1 ([1  ],Res); refFormula 1 ([2,1],Frm); 
    84  moveDown 1 ([2,1],Frm); refFormula 1 ([2,1],Res);
    85  moveDown 1 ([2,1],Res); refFormula 1 ([2,2],Res);
    86  moveDown 1 ([2,2],Res); refFormula 1 ([2,3],Res); 
    87  moveDown 1 ([2,3],Res); refFormula 1 ([2,4],Res);
    88  moveDown 1 ([2,4],Res); refFormula 1 ([2,5],Res);
    89  moveDown 1 ([2,5],Res); refFormula 1 ([2,6],Res);
    90  val ((pt,_),_) = get_calc 1;
    91  if "-2 * 1 + (1 + x) = 0" = term2str (fst (get_obj g_result pt [2,6])) then()
    92  else error "inform.sml: diff.behav.appendFormula: on Res + equ 2";
    93 
    94  fetchProposedTactic 1; (*takes Iterator 1 _1_*)
    95 
    96 (*============ inhibit exn AK110725 ==============================================
    97 (* ERROR: exception Bind raised *)
    98  val (_,(tac,_,_)::_) = get_calc 1;
    99  if tac = Rewrite_Set "Test_simplify" then ()
   100  else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
   101 ============ inhibit exn AK110725 ==============================================*)
   102 
   103  autoCalculate 1 CompleteCalc;
   104  val ((pt,_),_) = get_calc 1;
   105  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   106  else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
   107  (* autoCalculate 1 CompleteCalc;
   108    val ((pt,p),_) = get_calc 1;
   109    (writeln o istates2str) (get_obj g_loc pt [ ]);  
   110    (writeln o istates2str) (get_obj g_loc pt [1]);  
   111    (writeln o istates2str) (get_obj g_loc pt [2]);  
   112    (writeln o istates2str) (get_obj g_loc pt [3]);  
   113    (writeln o istates2str) (get_obj g_loc pt [3,1]);  
   114    (writeln o istates2str) (get_obj g_loc pt [3,2]);  
   115    (writeln o istates2str) (get_obj g_loc pt [4]);  
   116 
   117    *)
   118 "----------------------------------------------------------";
   119 
   120  val fod = make_deriv (@{theory "Isac"}) Atools_erls 
   121 		       ((#rules o rep_rls) Test_simplify)
   122 		       (sqrt_right false (@{theory "Pure"})) NONE 
   123 		       (str2term "x + 1 + -1 * 2 = 0");
   124  (writeln o trtas2str) fod;
   125 
   126  val ifod = make_deriv (@{theory "Isac"}) Atools_erls 
   127 		       ((#rules o rep_rls) Test_simplify)
   128 		       (sqrt_right false (@{theory "Pure"})) NONE 
   129 		       (str2term "-2 * 1 + (1 + x) = 0");
   130  (writeln o trtas2str) ifod;
   131  fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1 = t2;
   132  val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
   133  val der = fod' @ (map rev_deriv' rifod');
   134  (writeln o trtas2str) der;
   135  "----------------------------------------------------------";
   136 
   137 
   138 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   139 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   140 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   141  states:=[];
   142  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   143 	    ("Test", ["sqroot-test","univariate","equation","test"],
   144 	     ["Test","squ-equ-test-subpbl1"]))];
   145  Iterator 1; moveActiveRoot 1;
   146  autoCalculate 1 CompleteCalcHead;
   147  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1) (*x + 1 = 2*);
   148  appendFormula 1 "2+ -1 + x = 2"; refFormula 1 (get_pos 1 1);
   149 
   150  moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
   151 
   152  moveDown 1 ([1  ],Frm); refFormula 1 ([1,1],Frm); 
   153  moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res); 
   154  moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res); 
   155  moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res); 
   156  moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res); 
   157  moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res); 
   158  moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res); 
   159  val ((pt,_),_) = get_calc 1;
   160  if "2 + -1 + x = 2" = term2str (fst (get_obj g_result pt [1,6])) then()
   161  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
   162 
   163  fetchProposedTactic 1; (*takes Iterator 1 _1_*)
   164  val (_,(tac,_,_)::_) = get_calc 1;
   165  if tac = Rewrite_Set "norm_equation" then ()
   166  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
   167  autoCalculate 1 CompleteCalc;
   168  val ((pt,_),_) = get_calc 1;
   169  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   170  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
   171 
   172 
   173 "--------- appendFormula: on Res + NO deriv ----------------------";
   174 "--------- appendFormula: on Res + NO deriv ----------------------";
   175 "--------- appendFormula: on Res + NO deriv ----------------------";
   176  states:=[];
   177  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   178 	    ("Test", ["sqroot-test","univariate","equation","test"],
   179 	     ["Test","squ-equ-test-subpbl1"]))];
   180  Iterator 1; moveActiveRoot 1;
   181  autoCalculate 1 CompleteCalcHead;
   182  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   183  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   184 
   185  appendFormula 1 "x = 2";
   186  val ((pt,p),_) = get_calc 1;
   187  val str = pr_ptree pr_short pt;
   188  writeln str;
   189  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" andalso p = ([1], Res)
   190  then ()
   191  else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
   192 
   193  fetchProposedTactic 1;
   194  val (_,(tac,_,_)::_) = get_calc 1;
   195  if tac = Rewrite_Set "Test_simplify" then ()
   196  else error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
   197  autoCalculate 1 CompleteCalc;
   198  val ((pt,_),_) = get_calc 1;
   199  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   200  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
   201 
   202 
   203 "--------- appendFormula: on Res + late deriv --------------------";
   204 "--------- appendFormula: on Res + late deriv --------------------";
   205 "--------- appendFormula: on Res + late deriv --------------------";
   206  states:=[];
   207  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   208 	    ("Test", ["sqroot-test","univariate","equation","test"],
   209 	     ["Test","squ-equ-test-subpbl1"]))];
   210  Iterator 1; moveActiveRoot 1;
   211  autoCalculate 1 CompleteCalcHead;
   212  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   213  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   214 
   215  appendFormula 1 "x = 1";
   216  val ((pt,p),_) = get_calc 1;
   217  val str = pr_ptree pr_short pt;
   218  writeln str;
   219  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)
   220  then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
   221  else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
   222 
   223  fetchProposedTactic 1;
   224  val (_,(tac,_,_)::_) = get_calc 1;
   225  if tac = Check_Postcond ["linear", "univariate", "equation", "test"] then ()
   226  else error "inform.sml: diff.behav.appendFormula: Res + late d 2";
   227  autoCalculate 1 CompleteCalc;
   228  val ((pt,_),_) = get_calc 1;
   229  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   230  else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
   231 
   232 
   233 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   234 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   235 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   236  states:=[];
   237  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   238 	    ("Test", ["sqroot-test","univariate","equation","test"],
   239 	     ["Test","squ-equ-test-subpbl1"]))];
   240  Iterator 1; moveActiveRoot 1;
   241  autoCalculate 1 CompleteCalcHead;
   242  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   243  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   244  appendFormula 1 "[x = 3 + -2*1]";
   245  val ((pt,p),_) = get_calc 1;
   246  val str = pr_ptree pr_short pt;
   247  writeln str;
   248  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 ()
   249  else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
   250  autoCalculate 1 CompleteCalc;
   251  val ((pt,p),_) = get_calc 1;
   252  if "[x = 3 + -2 * 1]" = term2str (fst (get_obj g_result pt [])) then ()
   253  (*       ~~~~~~~~~~ simplify as last step in any script ?!*)
   254  else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
   255 
   256 
   257 
   258 "--------- replaceFormula: on Res + = ----------------------------";
   259 "--------- replaceFormula: on Res + = ----------------------------";
   260 "--------- replaceFormula: on Res + = ----------------------------";
   261  states:=[];
   262  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   263 	    ("Test", ["sqroot-test","univariate","equation","test"],
   264 	     ["Test","squ-equ-test-subpbl1"]))];
   265  Iterator 1; moveActiveRoot 1;
   266  autoCalculate 1 CompleteCalcHead;
   267  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   268  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   269  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*-1 + x*);
   270 
   271  replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
   272  val ((pt,_),_) = get_calc 1;
   273  val str = pr_ptree pr_short pt;
   274  writeln str;
   275 
   276 (*============ inhibit exn AK110725 ==============================================
   277 (* 2nd string should be the same as 1st one *)
   278 ".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 + -1 * 2 = 0\n2.1.   x + 1 + -1 * 2 = 0\n2.2.   1 + x + -1 * 2 = 0\n2.3.   1 + (x + -1 * 2) = 0\n2.4.   1 + (x + -2) = 0\n2.5.   1 + (x + -2 * 1) = 0\n2.6.   1 + x + -2 * 1 = 0\n";
   279 ".    ----- 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";
   280  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()
   281  else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
   282 ============ inhibit exn AK110725 ==============================================*)
   283 
   284  autoCalculate 1 CompleteCalc;
   285  val ((pt,pos as (p,_)),_) = get_calc 1;
   286  if pos = ([],Res) andalso "[x = 1]" = (term2str o fst) (get_obj g_result pt p) then()
   287  else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
   288  
   289 
   290 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   291 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   292 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   293  states:=[];
   294  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   295 	    ("Test", ["sqroot-test","univariate","equation","test"],
   296 	     ["Test","squ-equ-test-subpbl1"]))];
   297  Iterator 1; moveActiveRoot 1;
   298  autoCalculate 1 CompleteCalcHead;
   299  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   300  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   301 
   302  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   303  val ((pt,_),_) = get_calc 1;
   304  val str = pr_ptree pr_short pt;
   305  writeln str;
   306  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 ()
   307  else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
   308  autoCalculate 1 CompleteCalc;
   309  val ((pt,pos as (p,_)),_) = get_calc 1;
   310  if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
   311  else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
   312 
   313 
   314 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   315 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   316 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   317  states:=[];
   318  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   319 	    ("Test", ["sqroot-test","univariate","equation","test"],
   320 	     ["Test","squ-equ-test-subpbl1"]))];
   321  Iterator 1; moveActiveRoot 1;
   322  autoCalculate 1 CompleteCalcHead;
   323  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   324 
   325  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   326  val ((pt,_),_) = get_calc 1;
   327  val str = pr_ptree pr_short pt;
   328  writeln str;
   329  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 ()
   330  else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
   331  autoCalculate 1 CompleteCalc;
   332  val ((pt,pos as (p,_)),_) = get_calc 1;
   333  if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
   334  else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
   335 
   336 
   337 "--------- replaceFormula: cut calculation -----------------------";
   338 "--------- replaceFormula: cut calculation -----------------------";
   339 "--------- replaceFormula: cut calculation -----------------------";
   340  states:=[];
   341  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   342 	    ("Test", ["sqroot-test","univariate","equation","test"],
   343 	     ["Test","squ-equ-test-subpbl1"]))];
   344  Iterator 1; moveActiveRoot 1;
   345  autoCalculate 1 CompleteCalc;
   346  moveActiveRoot 1; moveActiveDown 1;
   347  if get_pos 1 1 = ([1], Frm) then ()
   348  else error "inform.sml: diff.behav. cut calculation 1";
   349 
   350  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   351  val ((pt,p),_) = get_calc 1;
   352  val str = pr_ptree pr_short pt;
   353  writeln str;
   354  if p = ([1], Res) then ()
   355  else error "inform.sml: diff.behav. cut calculation 2";
   356 
   357 
   358 (* 040307 copied from informtest.sml; ... old version 
   359  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   360  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   361  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   362 
   363  val p = ([],Pbl);
   364  val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
   365 	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   366 	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   367 	      "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
   368 	      (*^^^ these are the elements for the root-problem (in variants)*)
   369               (*vvv these are elements required for subproblems*)
   370 	      "boundVariable a","boundVariable b","boundVariable alpha",
   371 	      "interval {x::real. 0 <= x & x <= 2*r}",
   372 	      "interval {x::real. 0 <= x & x <= 2*r}",
   373 	      "interval {x::real. 0 <= x & x <= pi}",
   374 	      "errorBound (eps=(0::real))"]
   375  (*specifying is not interesting for this example*)
   376  val spec = ("DiffApp", ["maximum_of","function"], 
   377 	     ["DiffApp","max_by_calculus"]);
   378  (*the empty model with descriptions for user-guidance by Model_Problem*)
   379  val empty_model = [Given ["fixedValues []"],
   380 		    Find ["maximum", "valuesFor"],
   381 		    Relate ["relations []"]];
   382 
   383 
   384  (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
   385  val (p,_,f,nxt,_,pt) = CalcTreeTEST [(elems, spec)];
   386  (*val nxt = ("Model_Problem", ...*)
   387  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   388 
   389  val (p,_,f,nxt,_,pt) = me nxt p c pt;
   390  (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
   391  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   392 (*[
   393 (0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
   394 (0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
   395 (0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
   396 (0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
   397 
   398  (*the empty CalcHead is checked w.r.t the model and re-established as such*)
   399  val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, e_spec);
   400  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   401  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";
   402 
   403  (*there is one input to the model (could be more)*)
   404  val (b,pt,ocalhd) = 
   405      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   406 			     Find ["maximum", "valuesFor"],
   407 			     Relate ["relations"]], Pbl, e_spec);
   408  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   409  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 () 
   410  else error "informtest.sml: diff.behav. max 2";
   411 
   412  (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
   413  val (b,pt''''',ocalhd) = 
   414      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   415 			     Find ["maximum A", "valuesFor [a,b]"],
   416 			     Relate ["relations [A=a*b, a/2=r*sin alpha, \
   417 				     \b/2=r*cos alpha]"]], Pbl, e_spec);
   418  val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   419  if ocalhd2str ocalhd = ------------^^^^^^^^^^ missing !!!*)
   420 
   421  (*this input is complete in variant 1 (variant 3 does not work yet)*)
   422  val (b,pt''''',ocalhd) = 
   423      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   424 			     Find ["maximum A", "valuesFor [a,b]"],
   425 			     Relate ["relations [A=a*b, \
   426 				     \(a/2)^^^2 + (b/2)^^^2 = r^^^2]"]], 
   427 		      Pbl, e_spec);
   428  val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   429 
   430  modifycalcheadOK2xml 111 (bool2str b) ocalhd;
   431 *)
   432 
   433 "--------- syntax error ------------------------------------------";
   434 "--------- syntax error ------------------------------------------";
   435 "--------- syntax error ------------------------------------------";
   436  states:=[];
   437  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   438 	    ("Test", ["sqroot-test","univariate","equation","test"],
   439 	     ["Test","squ-equ-test-subpbl1"]))];
   440  Iterator 1; moveActiveRoot 1;
   441  autoCalculate 1 CompleteCalcHead;
   442  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   443  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   444 
   445  appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
   446  val ((pt,_),_) = get_calc 1;
   447  val str = pr_ptree pr_short pt;
   448  writeln str;
   449  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" then ()
   450  else error "inform.sml: diff.behav.appendFormula: syntax error";
   451 
   452 
   453 "--------- CAS-command on ([],Pbl) -------------------------------";
   454 "--------- CAS-command on ([],Pbl) -------------------------------";
   455 "--------- CAS-command on ([],Pbl) -------------------------------";
   456 val (p,_,f,nxt,_,pt) = 
   457     CalcTreeTEST [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   458 val ifo = "solve(x+1=2,x)";
   459 val (_,(_,c,(pt,p))) = inform ([],[],(pt,p)) "solve(x+1=2,x)";
   460 show_pt pt;
   461 val nxt = ("Apply_Method",Apply_Method ["Test","squ-equ-test-subpbl1"]);
   462 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   463 if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
   464 else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
   465 
   466 
   467 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   468 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   469 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   470 states:=[];
   471 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   472 Iterator 1;
   473 moveActiveRoot 1;
   474 replaceFormula 1 "solve(x+1=2,x)";
   475 autoCalculate 1 CompleteCalc;
   476 val ((pt,p),_) = get_calc 1;
   477 show_pt pt;
   478 if p = ([], Res) then ()
   479 else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
   480 
   481 
   482 "--------- inform [rational,simplification] ----------------------";
   483 "--------- inform [rational,simplification] ----------------------";
   484 "--------- inform [rational,simplification] ----------------------";
   485 states:=[];
   486 CalcTree [(["Term (4/x - 3/y - 1)", "normalform N"],
   487 	   ("Rational",["rational","simplification"],
   488 	    ["simplification","of_rationals"]))];
   489 Iterator 1; moveActiveRoot 1;
   490 autoCalculate 1 CompleteCalcHead;
   491 autoCalculate 1 (Step 1);
   492 autoCalculate 1 (Step 1);
   493 autoCalculate 1 (Step 1);
   494 autoCalculate 1 (Step 1);
   495 "--- input the next formula that _should_ be presented by mat-engine";
   496 appendFormula 1 "(4 * y + -3 * x) / (x * y) + -1";
   497 val ((pt,p),_) = get_calc 1;
   498 if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   499 else error ("inform.sml: [rational,simplification] 1");
   500 
   501 "--- input the next formula that would be presented by mat-engine";
   502 (*autoCalculate 1 (Step 1);*)
   503 appendFormula 1 "(4 * y + -3 * x + -1 * (x * y)) / (x * y)";
   504 val ((pt,p),_) = get_calc 1;
   505 if p = ([5], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
   506 else error ("inform.sml: [rational,simplification] 2");
   507 
   508 "--- input the exact final result";(*TODO: Exception- LIST "last_elem" raised*)
   509 appendFormula 1 "(-3 * x + 4 * y + -1 * x * y) / (x * y)";
   510 val ((pt,p),_) = get_calc 1;
   511 if p = ([6], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   512 else error ("inform.sml: [rational,simplification] 3");
   513 show_pt pt;
   514 
   515 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   516 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   517 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   518 val t = str2term "Diff (x^^^2 + x + 1, x)";
   519 case t of Const ("Diff.Diff", _) $ _ => ()
   520 	| _ => raise 
   521 	      error "diff.sml behav.changed for CAS Diff (..., x)";
   522 atomty t;
   523 "-----------------------------------------------------------------";
   524 (*1>*)states:=[];
   525 (*2>*)CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   526 (*3>*)Iterator 1;moveActiveRoot 1;
   527 "----- here the Headline has been finished";
   528 (*4>*)moveActiveFormula 1 ([],Pbl);
   529 (*5>*)replaceFormula 1 "Diff (x^2 + x + 1, x)";
   530 val ((pt,_),_) = get_calc 1;
   531 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   532 val NONE = env;
   533 val (SOME istate, NONE) = loc;
   534 print_depth 5;
   535 writeln"-----------------------------------------------------------";
   536 spec;
   537 writeln (itms2str_ ctxt probl);
   538 writeln (itms2str_ ctxt meth);
   539 
   540 (*============ inhibit exn AK110725 ==============================================
   541 (* ERROR: Argument: istate : istate * Proof.context Reason: 
   542         Can't unify istate to istate * Proof.context *)
   543 writeln (istate2str istate);
   544 ============ inhibit exn AK110725 ==============================================*)
   545 
   546 print_depth 3;
   547 
   548 refFormula 1 ([],Pbl) (*--> correct CalcHead*);
   549  (*081016 NOT necessary (but leave it in Java):*)
   550 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
   551 "----- here the CalcHead has been completed --- ONCE MORE ?????";
   552 
   553 (***difference II***)
   554 val ((pt,p),_) = get_calc 1;
   555 (*val p = ([], Pbl)*)
   556 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   557 val NONE = env;
   558 val (SOME istate, NONE) = loc;
   559 (*============ inhibit exn AK110725 ==============================================
   560 (* ERROR: Argument: istate : istate * Proof.context Reason: Can't unify istate to istate * Proof.context *)
   561 print_depth 5; writeln (istate2str istate);  print_depth 3;
   562 ============ inhibit exn AK110725 ==============================================*)
   563 (*ScrState ([],
   564  [], NONE,
   565  ??.empty, Sundef, false)*)
   566 print_depth 5; spec; print_depth 3;
   567 (*("Isac",
   568       ["derivative_of", "function"],
   569       ["diff", "differentiate_on_R"]) : spec*)
   570 writeln (itms2str_ ctxt probl);
   571 (*[
   572 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   573 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   574 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   575 writeln (itms2str_ ctxt meth);
   576 (*[
   577 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   578 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   579 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   580 writeln"-----------------------------------------------------------";
   581 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   582 (*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
   583 autoCalculate 1 CompleteCalc;
   584 val ((pt,p),_) = get_calc 1;
   585 val Form res = (#1 o pt_extract) (pt, ([],Res));
   586 show_pt pt;
   587 if p = ([], Res) andalso term2str res = "1 + 2 * x" then ()
   588 else error "diff.sml behav.changed for Diff (x^2 + x + 1, x)";
   589 
   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 (*============ inhibit exn AK110725 ==============================================
   607 (* ERROR: Argument: istate : istate * Proof.context Reason: Can't unify istate to istate * Proof.context *)
   608 print_depth 5; writeln (istate2str istate);  print_depth 3;
   609 ============ inhibit exn AK110725 ==============================================*)
   610 (*ScrState ([],
   611  [], NONE,
   612  ??.empty, Sundef, false)*)
   613 print_depth 5; spec; print_depth 3;
   614 (*("Isac",
   615       ["derivative_of", "function"],
   616       ["diff", "differentiate_on_R"]) : spec*)
   617 writeln (itms2str_ ctxt probl);
   618 (*[
   619 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   620 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   621 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   622 writeln (itms2str_ ctxt meth);
   623 (*[
   624 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   625 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   626 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   627 writeln"-----------------------------------------------------------";
   628 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   629 autoCalculate 1 (Step 1);
   630 val ((pt,p),_) = get_calc 1;
   631 val Form res = (#1 o pt_extract) (pt, p);
   632 if term2str res = "d_d x (x ^^^ 2 + x + 1)" then ()
   633 else error "diff.sml Diff (x^2 + x + 1, x) from exp";
   634 
   635 
   636 "--------- init_form, start with <NEW> (CAS input) ---------------";
   637 "--------- init_form, start with <NEW> (CAS input) ---------------";
   638 "--------- init_form, start with <NEW> (CAS input) ---------------";
   639 states:=[];
   640 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   641 (*[[from sml: > @@@@@begin@@@@@
   642 [[from sml:  1 
   643 [[from sml: <CALCTREE>
   644 [[from sml:    <CALCID> 1 </CALCID>
   645 [[from sml: </CALCTREE>
   646 [[from sml: @@@@@end@@@@@*)
   647 Iterator 1;
   648 (*[[from sml: > @@@@@begin@@@@@
   649 [[from sml:  1 
   650 [[from sml: <ADDUSER>
   651 [[from sml:   <CALCID> 1 </CALCID>
   652 [[from sml:   <USERID> 1 </USERID>
   653 [[from sml: </ADDUSER>
   654 [[from sml: @@@@@end@@@@@*)
   655 moveActiveRoot 1;
   656 (*[[from sml: > @@@@@begin@@@@@
   657 [[from sml:  1 
   658 [[from sml: <CALCITERATOR>
   659 [[from sml:   <CALCID> 1 </CALCID>
   660 [[from sml:   <POSITION>
   661 [[from sml:     <INTLIST>
   662 [[from sml:     </INTLIST>
   663 [[from sml:     <POS> Pbl </POS>
   664 [[from sml:   </POSITION>
   665 [[from sml: </CALCITERATOR>
   666 [[from sml: @@@@@end@@@@@*)
   667 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
   668 (*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
   669 [[from sml:  1 
   670 [[from sml: <GETELEMENTSFROMTO>
   671 [[from sml:   <CALCID> 1 </CALCID>
   672 [[from sml:   <FORMHEADS>
   673 [[from sml:     <CALCFORMULA>
   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:       <FORMULA>
   680 [[from sml:         <MATHML>
   681 [[from sml:           <ISA> ________________________________________________ </ISA>
   682 [[from sml:         </MATHML>
   683 [[from sml: 
   684 [[from sml:       </FORMULA>
   685 [[from sml:     </CALCFORMULA>
   686 [[from sml:   </FORMHEADS>
   687 [[from sml: </GETELEMENTSFROMTO>
   688 [[from sml: @@@@@end@@@@@*)
   689 refFormula 1 ([],Pbl);
   690 (*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
   691 [[from sml:  1 
   692 [[from sml: <REFFORMULA>
   693 [[from sml:   <CALCID> 1 </CALCID>
   694 [[from sml:   <CALCHEAD status = "incorrect">
   695 [[from sml:     <POSITION>
   696 [[from sml:       <INTLIST>
   697 [[from sml:       </INTLIST>
   698 [[from sml:       <POS> Pbl </POS>
   699 [[from sml:     </POSITION>
   700 [[from sml:     <HEAD>
   701 [[from sml:       <MATHML>
   702 [[from sml:         <ISA> Problem (e_domID, [e_pblID]) </ISA>
   703 [[from sml:       </MATHML>
   704 [[from sml:     </HEAD>
   705 [[from sml:     <MODEL>
   706 [[from sml:       <GIVEN>  </GIVEN>
   707 [[from sml:       <WHERE>  </WHERE>
   708 [[from sml:       <FIND>  </FIND>
   709 [[from sml:       <RELATE>  </RELATE>
   710 [[from sml:     </MODEL>
   711 [[from sml:     <BELONGSTO> Pbl </BELONGSTO>
   712 [[from sml:     <SPECIFICATION>
   713 [[from sml:       <THEORYID> e_domID </THEORYID>
   714 [[from sml:       <PROBLEMID>
   715 [[from sml:         <STRINGLIST>
   716 [[from sml:           <STRING> e_pblID </STRING>
   717 [[from sml:         </STRINGLIST>
   718 [[from sml:       </PROBLEMID>
   719 [[from sml:       <METHODID>
   720 [[from sml:         <STRINGLIST>
   721 [[from sml:           <STRING> e_metID </STRING>
   722 [[from sml:         </STRINGLIST>
   723 [[from sml:       </METHODID>
   724 [[from sml:     </SPECIFICATION>
   725 [[from sml:   </CALCHEAD>
   726 [[from sml: </REFFORMULA>
   727 [[from sml: @@@@@end@@@@@*)
   728 moveActiveFormula 1 ([],Pbl);
   729 (*[[from sml: > @@@@@begin@@@@@
   730 [[from sml:  1 
   731 [[from sml: <CALCITERATOR>
   732 [[from sml:   <CALCID> 1 </CALCID>
   733 [[from sml:   <POSITION>
   734 [[from sml:     <INTLIST>
   735 [[from sml:     </INTLIST>
   736 [[from sml:     <POS> Pbl </POS>
   737 [[from sml:   </POSITION>
   738 [[from sml: </CALCITERATOR>
   739 [[from sml: @@@@@end@@@@@*)
   740 replaceFormula 1 "Simplify (1+2)";
   741 (*[[from sml: > @@@@@begin@@@@@
   742 [[from sml:  1 
   743 [[from sml: <REPLACEFORMULA>
   744 [[from sml:   <CALCID> 1 </CALCID>
   745 [[from sml:   <CALCCHANGED>
   746 [[from sml:     <UNCHANGED>
   747 [[from sml:       <INTLIST>
   748 [[from sml:       </INTLIST>
   749 [[from sml:       <POS> Pbl </POS>
   750 [[from sml:     </UNCHANGED>
   751 [[from sml:     <DELETED>
   752 [[from sml:       <INTLIST>
   753 [[from sml:       </INTLIST>
   754 [[from sml:       <POS> Pbl </POS>
   755 [[from sml:     </DELETED>
   756 [[from sml:     <GENERATED>
   757 [[from sml:       <INTLIST>
   758 [[from sml:       </INTLIST>
   759 [[from sml:       <POS> Met </POS>                           DIFFERENCE: Pbl
   760 [[from sml:     </GENERATED>
   761 [[from sml:   </CALCCHANGED>
   762 [[from sml: </REPLACEFORMULA>
   763 [[from sml: @@@@@end@@@@@*)
   764 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(*              DIFFERENCE: Pbl*);
   765 (*@@@@@begin@@@@@
   766  1
   767 <GETELEMENTSFROMTO>
   768   <CALCID> 1 </CALCID>
   769   <FORMHEADS>
   770     <CALCFORMULA>
   771       <POSITION>
   772         <INTLIST>
   773         </INTLIST>
   774         <POS> Pbl </POS>
   775       </POSITION>
   776       <FORMULA>
   777         <MATHML>
   778           <ISA> Simplify (1 + 2) </ISA>                      WORKS !!!!!
   779         </MATHML>
   780       </FORMULA>
   781     </CALCFORMULA>
   782   </FORMHEADS>
   783 </GETELEMENTSFROMTO>
   784 @@@@@end@@@@@*)
   785 getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
   786 (*[[from sml: > @@@@@begin@@@@@
   787 [[from sml:  1 
   788 [[from sml: <SYSERROR>
   789 [[from sml:   <CALCID> 1 </CALCID>
   790 [[from sml:   <ERROR> error in getFormulaeFromTo </ERROR>
   791 [[from sml: </SYSERROR>
   792 [[from sml: @@@@@end@@@@@*)
   793 (*step into getFormulaeFromTo --- bug corrected...*)
   794 
   795 "--------- build fun check_err_patt ------------------------------";
   796 "--------- build fun check_err_patt ------------------------------";
   797 "--------- build fun check_err_patt ------------------------------";
   798 val subst = [(str2term "bdv", str2term "x")]: subst;
   799 val rls = norm_Rational
   800 val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
   801 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
   802 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "1 / 2");
   803 
   804 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
   805   rew_sub thy 1 [] e_rew_ord e_rls false [] (Trueprop $ pat) res;
   806 if rewritten then NONE else SOME "e_errpatID";
   807 
   808 val norm_res = case rewrite_set_ (Isac()) false rls res' of
   809   NONE => res'
   810 | SOME (norm_res, _) => norm_res
   811 
   812 val norm_inf = case rewrite_set_ (Isac()) false rls inf of
   813   NONE => inf
   814 | SOME (norm_inf, _) => norm_inf;
   815 
   816 res' = inf;
   817 norm_res = norm_inf;
   818 
   819 val pat = parse_patt @{theory} "(?a + ?b)/?a = ?b";
   820 val (res, inf) = (str2term "(2 + 3)/2", str2term "3");
   821 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   822 then () else error "error patt example1 changed";
   823 
   824 val pat = parse_patt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
   825 val (res, inf) = (str2term "(2 + 3)/(2 + 4)", str2term "3 / 4");
   826 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   827 then () else error "error patt example2 changed";
   828 
   829 val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
   830 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
   831 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   832 then () else error "error patt example3 changed";
   833 
   834 val inf =  str2term "1 / 2";
   835 if check_err_patt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   836 then () else error "error patt example3 changed";
   837 
   838 "--------- build fun check_err_patt ?bdv -------------------------";
   839 "--------- build fun check_err_patt ?bdv -------------------------";
   840 "--------- build fun check_err_patt ?bdv -------------------------";
   841 val subst = [(str2term "bdv", str2term "x")]: subst;
   842 val t = str2term "d_d x (x ^^^ 2 + sin (x ^^^ 4))";
   843 val SOME (t, _) = rewrite_set_inst_ thy false subst norm_diff t;
   844 if term2str t = "2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3" then ()
   845 else error "build fun check_err_patt ?bdv changed 1"; 
   846 
   847 val rls = norm_diff
   848 val pat = parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)"; 
   849 val (res, inf) = (str2term "2 * x + d_d x (sin (x ^^^ 4))", str2term "2 * x + cos (4 * x ^^^ 3)");
   850 
   851 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
   852   rew_sub thy 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) res;
   853 if term2str res' = "2 * x + cos (d_d x (x ^^^ 4))" andalso rewritten then ()
   854 else error "build fun check_err_patt ?bdv changed 2";
   855 
   856 val norm_res = case rewrite_set_inst_ (Isac()) false subst rls  res' of
   857   NONE => res'
   858 | SOME (norm_res, _) => norm_res;
   859 if term2str norm_res = "2 * x + cos (4 * x ^^^ 3)" then ()
   860 else error "build fun check_err_patt ?bdv changed 3";
   861 
   862 val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
   863   NONE => inf
   864 | SOME (norm_inf, _) => norm_inf;
   865 if term2str norm_inf = "2 * x + cos (4 * x ^^^ 3)" then ()
   866 else error "build fun check_err_patt ?bdv changed 4";
   867 
   868 res' = inf;
   869 if norm_res = norm_inf then ()
   870 else error "build fun check_err_patt ?bdv changed 5";
   871 
   872 if check_err_patt (res, inf) (subst: subst) ("errpatID": errpatID, pat) rls = SOME "errpatID"
   873 then () else error "error patt example1 changed";
   874 
   875 "--------- build fun check_error_patterns ------------------------";
   876 "--------- build fun check_error_patterns ------------------------";
   877 "--------- build fun check_error_patterns ------------------------";
   878 val (res, inf) =
   879   (str2term "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))",
   880    str2term "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)");
   881 val {errpats, nrls = rls, scr = Script prog, ...} = get_met ["diff", "differentiate_on_R"]
   882 
   883 val env = [(str2term "v_v", str2term "x")];
   884 val errpats =
   885   [e_errpat, (*generalised for testing*)
   886    ("chain-rule-diff-both",
   887      [parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)",
   888       parse_patt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)",
   889       parse_patt @{theory} "d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1)",
   890       parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u",
   891       parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u"],
   892      [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain}, 
   893       @{thm diff_ln_chain}, @{thm  diff_exp_chain}])]: errpat list;
   894 
   895 case check_error_patterns (res, inf) (prog, env) (errpats, rls) of SOME _ => () 
   896 | NONE => error "check_error_patterns broken";
   897 
   898 
   899 "--------- embed fun check_error_patterns ------------------------";
   900 "--------- embed fun check_error_patterns ------------------------";
   901 "--------- embed fun check_error_patterns ------------------------";
   902 states:=[];
   903 CalcTree
   904 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
   905   ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
   906 Iterator 1;
   907 moveActiveRoot 1;
   908 autoCalculate 1 CompleteCalcHead;
   909 autoCalculate 1 (Step 1);
   910 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
   911 (*autoCalculate 1 (Step 1);([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)*)
   912 
   913 "~~~~~ fun appendFormula, args:"; val (cI, (ifo:cterm')) = (1, "d_d x (x ^ 2) + cos (4 * x ^ 3)");
   914 val cs = get_calc cI
   915 val pos as (_,p_) = get_pos cI 1; (*pos = ([1], Res)*)
   916 val cs' = 
   917     case step pos cs of
   918 	    ("ok", cs') => cs';
   919 
   920 val (_, _, (pt, ([2], Res))) = cs';
   921 (*show_pt pt;
   922   [(([], Frm), Diff (x ^^^ 2 + sin (x ^^^ 4), x)),
   923    (([1], Frm), d_d x (x ^^^ 2 + sin (x ^^^ 4))),
   924    (([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))), <<=== input follos: "...+ cos(4.x^3)"
   925    (([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4))] *)
   926 
   927 "~~~~~ fun inform, args:"; val ((cs as (_, _, ptp as (pt, pos as (p, p_))): calcstate'), istr) =
   928   (cs', (encode ifo));
   929 val 	SOME f_in = parse (assoc_thy "Isac") istr
   930 val f_in = term_of f_in
   931 val pos_pred = lev_back' pos
   932 			(* f_pred ---"step pos cs"---> f_succ in appendFormula
   933    TODO.WN120517: one starting point for redesign of pos' *)
   934 val (f_pred, f_succ) = (get_pred_formula (pt, pos_pred), get_pred_formula (pt, pos));
   935 	
   936 term2str f_pred = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))";
   937 term2str f_succ = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)";
   938 
   939 			f_succ = f_in; (* = false*)
   940 cas_input f_in; (* = NONE*)
   941 val msg_calcstate' = compare_step ([], [], (pt, pos_pred)) f_in
   942 val ("no derivation found", calcstate') = msg_calcstate';
   943 			                 val pp = par_pblobj pt p
   944 			                 val {errpats, nrls, scr = Script prog, ...} = get_met (get_obj g_metID pt pp)
   945 			                 val ScrState (env, _, _, _, _, _) = get_istate pt pos;
   946                  case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
   947 			                   SOME errpatID => ("error pattern #" ^ errpatID ^ "#", calcstate')
   948 			                 | NONE => msg_calcstate';
   949 
   950 "~~~~~ from inform return val:"; val () = ();
   951 case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
   952 			  SOME errpatID => ()
   953 			| NONE => error "check_error_patterns broken";
   954 
   955 "--- final check:";
   956 case inform cs' (encode ifo) of
   957   ("error pattern #chain-rule-diff-both#", calcstate') => ()
   958 | _ => error "inform with (positive) check_error_patterns broken"
   959 
   960 "--------- embed fun find_fillpatterns ---------------------------";
   961 "--------- embed fun find_fillpatterns ---------------------------";
   962 "--------- embed fun find_fillpatterns ---------------------------";
   963 states:=[];
   964 CalcTree
   965 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
   966   ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
   967 Iterator 1;
   968 moveActiveRoot 1;
   969 autoCalculate 1 CompleteCalcHead;
   970 autoCalculate 1 (Step 1);
   971 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
   972 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)";
   973   (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
   974   (*TODO BACK TO <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
   975 
   976 "~~~~~ fun FindFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
   977   val ((pt, _), _) = get_calc cI
   978 				val pos = get_pos cI 1;
   979 			"~~~~~ fun find_fillpatterns, args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
   980 	    val f_curr = get_pred_formula (pt, pos); (* = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"*)
   981     val pp = par_pblobj pt p
   982 			    val {errpats, scr = Script prog, ...} = get_met (get_obj g_metID pt pp)
   983     val ScrState (env, _, _, _, _, _) = get_istate pt pos
   984     val subst = get_bdv_subst prog env
   985     val errpatthms = errpats
   986       |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
   987       |> map (#3: errpat -> thm list)
   988       |> flat;
   989 
   990 case map (get_fillpats subst f_curr errpatID) errpatthms |> flat of
   991  ("fill-d_d-arg",
   992   "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1")
   993     :: _ => ()
   994 | _ => error "find_fillpatterns changed"
   995 
   996 "~~~~~ fun get_fillpats, args:"; val (subst, form, errpatID, thm) =
   997   (subst, f_curr, errpatID, hd errpatthms);
   998         val thmDeriv = Thm.get_name_hint thm
   999         val (part, thyID) = thy_containing_thm thmDeriv
  1000         val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
  1001         val Hthm {fillpats, ...} = get_the theID
  1002         val some = map (get_fillform subst form errpatID) fillpats;
  1003 
  1004 case some |> filter is_some |> map the of
  1005   ("fill-d_d-arg",
  1006   "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1")
  1007     :: _ => ()
  1008 | _ => error "get_fillpats changed"
  1009