test/Tools/isac/Interpret/inform.sml
author Walther Neuper <neuper@ist.tugraz.at>
Fri, 25 May 2012 16:30:15 +0200
changeset 42437 529008b1408e
parent 42436 27b2f087587b
child 42450 429980a4c472
permissions -rw-r--r--
added "fun inputFillFormula"

a usecase with
# appendFormula (related to an error pattern)
# findFillpatterns
# requestFillformula
# inputFillFormula
# autoCalculate
in test/../interface.sml --- UC errpat, fillpat ---
     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 "--------- appendFormula: on Res + equ_nrls ----------------------";
    45 "--------- appendFormula: on Res + equ_nrls ----------------------";
    46 "--------- appendFormula: on Res + equ_nrls ----------------------";
    47 
    48  val Script sc = (#scr o get_met) ["Test","squ-equ-test-subpbl1"];
    49  (writeln o term2str) sc;
    50  val Script sc = (#scr o get_met) ["Test","solve_linear"];
    51  (writeln o term2str) sc;
    52 
    53  states:=[];
    54  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
    55 	    ("Test", ["sqroot-test","univariate","equation","test"],
    56 	     ["Test","squ-equ-test-subpbl1"]))];
    57  Iterator 1; moveActiveRoot 1;
    58  autoCalculate 1 CompleteCalcHead;
    59  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
    60  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
    61 
    62  appendFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
    63  val ((pt,_),_) = get_calc 1;
    64  val str = pr_ptree pr_short pt;
    65 
    66  writeln str;
    67 (*============ inhibit exn AK110726 ==============================================
    68 (* 2nd string should be the same as 1st one *)
    69 ".    ----- 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";
    70 ".    ----- 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";
    71  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 ()
    72    else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
    73 ============ inhibit exn AK110726 ==============================================*)
    74 
    75  moveDown 1 ([ ],Pbl); refFormula 1 ([1],Frm); (*x + 1 = 2*)
    76  moveDown 1 ([1],Frm); refFormula 1 ([1],Res); (*x + 1 + -1 * 2 = 0*)
    77 
    78  (*the seven steps of detailed derivation*)
    79  moveDown 1 ([1  ],Res); refFormula 1 ([2,1],Frm); 
    80  moveDown 1 ([2,1],Frm); refFormula 1 ([2,1],Res);
    81  moveDown 1 ([2,1],Res); refFormula 1 ([2,2],Res);
    82  moveDown 1 ([2,2],Res); refFormula 1 ([2,3],Res); 
    83  moveDown 1 ([2,3],Res); refFormula 1 ([2,4],Res);
    84  moveDown 1 ([2,4],Res); refFormula 1 ([2,5],Res);
    85  moveDown 1 ([2,5],Res); refFormula 1 ([2,6],Res);
    86  val ((pt,_),_) = get_calc 1;
    87  if "-2 * 1 + (1 + x) = 0" = term2str (fst (get_obj g_result pt [2,6])) then()
    88  else error "inform.sml: diff.behav.appendFormula: on Res + equ 2";
    89 
    90  fetchProposedTactic 1; (*takes Iterator 1 _1_*)
    91 
    92 (*============ inhibit exn AK110725 ==============================================
    93 (* ERROR: exception Bind raised *)
    94  val (_,(tac,_,_)::_) = get_calc 1;
    95  if tac = Rewrite_Set "Test_simplify" then ()
    96  else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
    97 ============ inhibit exn AK110725 ==============================================*)
    98 
    99  autoCalculate 1 CompleteCalc;
   100  val ((pt,_),_) = get_calc 1;
   101  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   102  else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
   103  (* autoCalculate 1 CompleteCalc;
   104    val ((pt,p),_) = get_calc 1;
   105    (writeln o istates2str) (get_obj g_loc pt [ ]);  
   106    (writeln o istates2str) (get_obj g_loc pt [1]);  
   107    (writeln o istates2str) (get_obj g_loc pt [2]);  
   108    (writeln o istates2str) (get_obj g_loc pt [3]);  
   109    (writeln o istates2str) (get_obj g_loc pt [3,1]);  
   110    (writeln o istates2str) (get_obj g_loc pt [3,2]);  
   111    (writeln o istates2str) (get_obj g_loc pt [4]);  
   112 
   113    *)
   114 "----------------------------------------------------------";
   115 
   116  val fod = make_deriv (@{theory "Isac"}) Atools_erls 
   117 		       ((#rules o rep_rls) Test_simplify)
   118 		       (sqrt_right false (@{theory "Pure"})) NONE 
   119 		       (str2term "x + 1 + -1 * 2 = 0");
   120  (writeln o trtas2str) fod;
   121 
   122  val ifod = make_deriv (@{theory "Isac"}) Atools_erls 
   123 		       ((#rules o rep_rls) Test_simplify)
   124 		       (sqrt_right false (@{theory "Pure"})) NONE 
   125 		       (str2term "-2 * 1 + (1 + x) = 0");
   126  (writeln o trtas2str) ifod;
   127  fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1 = t2;
   128  val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
   129  val der = fod' @ (map rev_deriv' rifod');
   130  (writeln o trtas2str) der;
   131  "----------------------------------------------------------";
   132 
   133 
   134 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   135 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   136 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   137  states:=[];
   138  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   139 	    ("Test", ["sqroot-test","univariate","equation","test"],
   140 	     ["Test","squ-equ-test-subpbl1"]))];
   141  Iterator 1; moveActiveRoot 1;
   142  autoCalculate 1 CompleteCalcHead;
   143  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1) (*x + 1 = 2*);
   144  appendFormula 1 "2+ -1 + x = 2"; refFormula 1 (get_pos 1 1);
   145 
   146  moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
   147 
   148  moveDown 1 ([1  ],Frm); refFormula 1 ([1,1],Frm); 
   149  moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res); 
   150  moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res); 
   151  moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res); 
   152  moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res); 
   153  moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res); 
   154  moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res); 
   155  val ((pt,_),_) = get_calc 1;
   156  if "2 + -1 + x = 2" = term2str (fst (get_obj g_result pt [1,6])) then()
   157  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
   158 
   159  fetchProposedTactic 1; (*takes Iterator 1 _1_*)
   160  val (_,(tac,_,_)::_) = get_calc 1;
   161  if tac = Rewrite_Set "norm_equation" then ()
   162  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
   163  autoCalculate 1 CompleteCalc;
   164  val ((pt,_),_) = get_calc 1;
   165  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   166  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
   167 
   168 
   169 "--------- appendFormula: on Res + NO deriv ----------------------";
   170 "--------- appendFormula: on Res + NO deriv ----------------------";
   171 "--------- appendFormula: on Res + NO deriv ----------------------";
   172  states:=[];
   173  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   174 	    ("Test", ["sqroot-test","univariate","equation","test"],
   175 	     ["Test","squ-equ-test-subpbl1"]))];
   176  Iterator 1; moveActiveRoot 1;
   177  autoCalculate 1 CompleteCalcHead;
   178  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   179  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   180 
   181  appendFormula 1 "x = 2";
   182  val ((pt,p),_) = get_calc 1;
   183  val str = pr_ptree pr_short pt;
   184  writeln str;
   185  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" andalso p = ([1], Res)
   186  then ()
   187  else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
   188 
   189  fetchProposedTactic 1;
   190  val (_,(tac,_,_)::_) = get_calc 1;
   191  if tac = Rewrite_Set "Test_simplify" then ()
   192  else error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
   193  autoCalculate 1 CompleteCalc;
   194  val ((pt,_),_) = get_calc 1;
   195  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   196  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
   197 
   198 
   199 "--------- appendFormula: on Res + late deriv --------------------";
   200 "--------- appendFormula: on Res + late deriv --------------------";
   201 "--------- appendFormula: on Res + late deriv --------------------";
   202  states:=[];
   203  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   204 	    ("Test", ["sqroot-test","univariate","equation","test"],
   205 	     ["Test","squ-equ-test-subpbl1"]))];
   206  Iterator 1; moveActiveRoot 1;
   207  autoCalculate 1 CompleteCalcHead;
   208  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   209  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   210 
   211  appendFormula 1 "x = 1";
   212  val ((pt,p),_) = get_calc 1;
   213  val str = pr_ptree pr_short pt;
   214  writeln str;
   215  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)
   216  then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
   217  else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
   218 
   219  fetchProposedTactic 1;
   220  val (_,(tac,_,_)::_) = get_calc 1;
   221  if tac = Check_Postcond ["linear", "univariate", "equation", "test"] then ()
   222  else error "inform.sml: diff.behav.appendFormula: Res + late d 2";
   223  autoCalculate 1 CompleteCalc;
   224  val ((pt,_),_) = get_calc 1;
   225  if "[x = 1]" = term2str (fst (get_obj g_result pt [])) then ()
   226  else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
   227 
   228 
   229 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   230 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   231 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   232  states:=[];
   233  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   234 	    ("Test", ["sqroot-test","univariate","equation","test"],
   235 	     ["Test","squ-equ-test-subpbl1"]))];
   236  Iterator 1; moveActiveRoot 1;
   237  autoCalculate 1 CompleteCalcHead;
   238  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   239  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   240  appendFormula 1 "[x = 3 + -2*1]";
   241  val ((pt,p),_) = get_calc 1;
   242  val str = pr_ptree pr_short pt;
   243  writeln str;
   244  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 ()
   245  else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
   246  autoCalculate 1 CompleteCalc;
   247  val ((pt,p),_) = get_calc 1;
   248  if "[x = 3 + -2 * 1]" = term2str (fst (get_obj g_result pt [])) then ()
   249  (*       ~~~~~~~~~~ simplify as last step in any script ?!*)
   250  else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
   251 
   252 
   253 
   254 "--------- replaceFormula: on Res + = ----------------------------";
   255 "--------- replaceFormula: on Res + = ----------------------------";
   256 "--------- replaceFormula: on Res + = ----------------------------";
   257  states:=[];
   258  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   259 	    ("Test", ["sqroot-test","univariate","equation","test"],
   260 	     ["Test","squ-equ-test-subpbl1"]))];
   261  Iterator 1; moveActiveRoot 1;
   262  autoCalculate 1 CompleteCalcHead;
   263  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   264  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   265  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*-1 + x*);
   266 
   267  replaceFormula 1 "-2 * 1 + (1 + x) = 0"; refFormula 1 (get_pos 1 1);
   268  val ((pt,_),_) = get_calc 1;
   269  val str = pr_ptree pr_short pt;
   270  writeln str;
   271 
   272 (*============ inhibit exn AK110725 ==============================================
   273 (* 2nd string should be the same as 1st one *)
   274 ".    ----- 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";
   275 ".    ----- 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";
   276  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()
   277  else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
   278 ============ inhibit exn AK110725 ==============================================*)
   279 
   280  autoCalculate 1 CompleteCalc;
   281  val ((pt,pos as (p,_)),_) = get_calc 1;
   282  if pos = ([],Res) andalso "[x = 1]" = (term2str o fst) (get_obj g_result pt p) then()
   283  else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
   284  
   285 
   286 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   287 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   288 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   289  states:=[];
   290  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   291 	    ("Test", ["sqroot-test","univariate","equation","test"],
   292 	     ["Test","squ-equ-test-subpbl1"]))];
   293  Iterator 1; moveActiveRoot 1;
   294  autoCalculate 1 CompleteCalcHead;
   295  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   296  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   297 
   298  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   299  val ((pt,_),_) = get_calc 1;
   300  val str = pr_ptree pr_short pt;
   301  writeln str;
   302  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 ()
   303  else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
   304  autoCalculate 1 CompleteCalc;
   305  val ((pt,pos as (p,_)),_) = get_calc 1;
   306  if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
   307  else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
   308 
   309 
   310 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   311 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   312 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   313  states:=[];
   314  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   315 	    ("Test", ["sqroot-test","univariate","equation","test"],
   316 	     ["Test","squ-equ-test-subpbl1"]))];
   317  Iterator 1; moveActiveRoot 1;
   318  autoCalculate 1 CompleteCalcHead;
   319  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   320 
   321  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   322  val ((pt,_),_) = get_calc 1;
   323  val str = pr_ptree pr_short pt;
   324  writeln str;
   325  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 ()
   326  else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
   327  autoCalculate 1 CompleteCalc;
   328  val ((pt,pos as (p,_)),_) = get_calc 1;
   329  if pos = ([],Res) andalso "[x = 1]" = (term2str o fst)(get_obj g_result pt p) then()
   330  else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
   331 
   332 
   333 "--------- replaceFormula: cut calculation -----------------------";
   334 "--------- replaceFormula: cut calculation -----------------------";
   335 "--------- replaceFormula: cut calculation -----------------------";
   336  states:=[];
   337  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   338 	    ("Test", ["sqroot-test","univariate","equation","test"],
   339 	     ["Test","squ-equ-test-subpbl1"]))];
   340  Iterator 1; moveActiveRoot 1;
   341  autoCalculate 1 CompleteCalc;
   342  moveActiveRoot 1; moveActiveDown 1;
   343  if get_pos 1 1 = ([1], Frm) then ()
   344  else error "inform.sml: diff.behav. cut calculation 1";
   345 
   346  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   347  val ((pt,p),_) = get_calc 1;
   348  val str = pr_ptree pr_short pt;
   349  writeln str;
   350  if p = ([1], Res) then ()
   351  else error "inform.sml: diff.behav. cut calculation 2";
   352 
   353 
   354 (* 040307 copied from informtest.sml; ... old version 
   355  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   356  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   357  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   358 
   359  val p = ([],Pbl);
   360  val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
   361 	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   362 	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   363 	      "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
   364 	      (*^^^ these are the elements for the root-problem (in variants)*)
   365               (*vvv these are elements required for subproblems*)
   366 	      "boundVariable a","boundVariable b","boundVariable alpha",
   367 	      "interval {x::real. 0 <= x & x <= 2*r}",
   368 	      "interval {x::real. 0 <= x & x <= 2*r}",
   369 	      "interval {x::real. 0 <= x & x <= pi}",
   370 	      "errorBound (eps=(0::real))"]
   371  (*specifying is not interesting for this example*)
   372  val spec = ("DiffApp", ["maximum_of","function"], 
   373 	     ["DiffApp","max_by_calculus"]);
   374  (*the empty model with descriptions for user-guidance by Model_Problem*)
   375  val empty_model = [Given ["fixedValues []"],
   376 		    Find ["maximum", "valuesFor"],
   377 		    Relate ["relations []"]];
   378 
   379 
   380  (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
   381  val (p,_,f,nxt,_,pt) = CalcTreeTEST [(elems, spec)];
   382  (*val nxt = ("Model_Problem", ...*)
   383  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   384 
   385  val (p,_,f,nxt,_,pt) = me nxt p c pt;
   386  (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
   387  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   388 (*[
   389 (0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
   390 (0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
   391 (0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
   392 (0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
   393 
   394  (*the empty CalcHead is checked w.r.t the model and re-established as such*)
   395  val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, e_spec);
   396  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   397  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";
   398 
   399  (*there is one input to the model (could be more)*)
   400  val (b,pt,ocalhd) = 
   401      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   402 			     Find ["maximum", "valuesFor"],
   403 			     Relate ["relations"]], Pbl, e_spec);
   404  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   405  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 () 
   406  else error "informtest.sml: diff.behav. max 2";
   407 
   408  (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
   409  val (b,pt''''',ocalhd) = 
   410      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   411 			     Find ["maximum A", "valuesFor [a,b]"],
   412 			     Relate ["relations [A=a*b, a/2=r*sin alpha, \
   413 				     \b/2=r*cos alpha]"]], Pbl, e_spec);
   414  val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   415  if ocalhd2str ocalhd = ------------^^^^^^^^^^ missing !!!*)
   416 
   417  (*this input is complete in variant 1 (variant 3 does not work yet)*)
   418  val (b,pt''''',ocalhd) = 
   419      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   420 			     Find ["maximum A", "valuesFor [a,b]"],
   421 			     Relate ["relations [A=a*b, \
   422 				     \(a/2)^^^2 + (b/2)^^^2 = r^^^2]"]], 
   423 		      Pbl, e_spec);
   424  val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   425 
   426  modifycalcheadOK2xml 111 (bool2str b) ocalhd;
   427 *)
   428 
   429 "--------- syntax error ------------------------------------------";
   430 "--------- syntax error ------------------------------------------";
   431 "--------- syntax error ------------------------------------------";
   432  states:=[];
   433  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   434 	    ("Test", ["sqroot-test","univariate","equation","test"],
   435 	     ["Test","squ-equ-test-subpbl1"]))];
   436  Iterator 1; moveActiveRoot 1;
   437  autoCalculate 1 CompleteCalcHead;
   438  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   439  autoCalculate 1 (Step 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   440 
   441  appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
   442  val ((pt,_),_) = get_calc 1;
   443  val str = pr_ptree pr_short pt;
   444  writeln str;
   445  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" then ()
   446  else error "inform.sml: diff.behav.appendFormula: syntax error";
   447 
   448 
   449 "--------- CAS-command on ([],Pbl) -------------------------------";
   450 "--------- CAS-command on ([],Pbl) -------------------------------";
   451 "--------- CAS-command on ([],Pbl) -------------------------------";
   452 val (p,_,f,nxt,_,pt) = 
   453     CalcTreeTEST [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   454 val ifo = "solve(x+1=2,x)";
   455 val (_,(_,c,(pt,p))) = inform ([],[],(pt,p)) "solve(x+1=2,x)";
   456 show_pt pt;
   457 val nxt = ("Apply_Method",Apply_Method ["Test","squ-equ-test-subpbl1"]);
   458 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   459 if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
   460 else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
   461 
   462 
   463 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   464 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   465 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   466 states:=[];
   467 CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   468 Iterator 1;
   469 moveActiveRoot 1;
   470 replaceFormula 1 "solve(x+1=2,x)";
   471 autoCalculate 1 CompleteCalc;
   472 val ((pt,p),_) = get_calc 1;
   473 show_pt pt;
   474 if p = ([], Res) then ()
   475 else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
   476 
   477 
   478 "--------- inform [rational,simplification] ----------------------";
   479 "--------- inform [rational,simplification] ----------------------";
   480 "--------- inform [rational,simplification] ----------------------";
   481 states:=[];
   482 CalcTree [(["Term (4/x - 3/y - 1)", "normalform N"],
   483 	   ("Rational",["rational","simplification"],
   484 	    ["simplification","of_rationals"]))];
   485 Iterator 1; moveActiveRoot 1;
   486 autoCalculate 1 CompleteCalcHead;
   487 autoCalculate 1 (Step 1);
   488 autoCalculate 1 (Step 1);
   489 autoCalculate 1 (Step 1);
   490 autoCalculate 1 (Step 1);
   491 "--- input the next formula that _should_ be presented by mat-engine";
   492 appendFormula 1 "(4 * y + -3 * x) / (x * y) + -1";
   493 val ((pt,p),_) = get_calc 1;
   494 if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   495 else error ("inform.sml: [rational,simplification] 1");
   496 
   497 "--- input the next formula that would be presented by mat-engine";
   498 (*autoCalculate 1 (Step 1);*)
   499 appendFormula 1 "(4 * y + -3 * x + -1 * (x * y)) / (x * y)";
   500 val ((pt,p),_) = get_calc 1;
   501 if p = ([5], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
   502 else error ("inform.sml: [rational,simplification] 2");
   503 
   504 "--- input the exact final result";(*TODO: Exception- LIST "last_elem" raised*)
   505 appendFormula 1 "(-3 * x + 4 * y + -1 * x * y) / (x * y)";
   506 val ((pt,p),_) = get_calc 1;
   507 if p = ([6], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   508 else error ("inform.sml: [rational,simplification] 3");
   509 show_pt pt;
   510 
   511 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   512 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   513 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   514 val t = str2term "Diff (x^^^2 + x + 1, x)";
   515 case t of Const ("Diff.Diff", _) $ _ => ()
   516 	| _ => raise 
   517 	      error "diff.sml behav.changed for CAS Diff (..., x)";
   518 atomty t;
   519 "-----------------------------------------------------------------";
   520 (*1>*)states:=[];
   521 (*2>*)CalcTree [([], ("e_domID", ["e_pblID"], ["e_metID"]))];
   522 (*3>*)Iterator 1;moveActiveRoot 1;
   523 "----- here the Headline has been finished";
   524 (*4>*)moveActiveFormula 1 ([],Pbl);
   525 (*5>*)replaceFormula 1 "Diff (x^2 + x + 1, x)";
   526 val ((pt,_),_) = get_calc 1;
   527 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   528 val NONE = env;
   529 val (SOME istate, NONE) = loc;
   530 print_depth 5;
   531 writeln"-----------------------------------------------------------";
   532 spec;
   533 writeln (itms2str_ ctxt probl);
   534 writeln (itms2str_ ctxt meth);
   535 
   536 (*============ inhibit exn AK110725 ==============================================
   537 (* ERROR: Argument: istate : istate * Proof.context Reason: 
   538         Can't unify istate to istate * Proof.context *)
   539 writeln (istate2str istate);
   540 ============ inhibit exn AK110725 ==============================================*)
   541 
   542 print_depth 3;
   543 
   544 refFormula 1 ([],Pbl) (*--> correct CalcHead*);
   545  (*081016 NOT necessary (but leave it in Java):*)
   546 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
   547 "----- here the CalcHead has been completed --- ONCE MORE ?????";
   548 
   549 (***difference II***)
   550 val ((pt,p),_) = get_calc 1;
   551 (*val p = ([], Pbl)*)
   552 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   553 val NONE = env;
   554 val (SOME istate, NONE) = loc;
   555 (*============ inhibit exn AK110725 ==============================================
   556 (* ERROR: Argument: istate : istate * Proof.context Reason: Can't unify istate to istate * Proof.context *)
   557 print_depth 5; writeln (istate2str istate);  print_depth 3;
   558 ============ inhibit exn AK110725 ==============================================*)
   559 (*ScrState ([],
   560  [], NONE,
   561  ??.empty, Sundef, false)*)
   562 print_depth 5; spec; print_depth 3;
   563 (*("Isac",
   564       ["derivative_of", "function"],
   565       ["diff", "differentiate_on_R"]) : spec*)
   566 writeln (itms2str_ ctxt probl);
   567 (*[
   568 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   569 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   570 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   571 writeln (itms2str_ ctxt meth);
   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"-----------------------------------------------------------";
   577 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   578 (*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
   579 autoCalculate 1 CompleteCalc;
   580 val ((pt,p),_) = get_calc 1;
   581 val Form res = (#1 o pt_extract) (pt, ([],Res));
   582 show_pt pt;
   583 if p = ([], Res) andalso term2str res = "1 + 2 * x" then ()
   584 else error "diff.sml behav.changed for Diff (x^2 + x + 1, x)";
   585 
   586 
   587 "--------- Take as 1st tac, start from exp -----------------------";
   588 "--------- Take as 1st tac, start from exp -----------------------";
   589 "--------- Take as 1st tac, start from exp -----------------------";
   590 (*the following input is copied from BridgeLog Java <==> SML,
   591   omitting unnecessary inputs*)
   592 (*1>*)states:=[];
   593 (*2>*)CalcTree [(["functionTerm (x^2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac",["derivative_of","function"],["diff","differentiate_on_R"]))];
   594 (*3>*)Iterator 1; moveActiveRoot 1;
   595 
   596 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
   597 (***difference II***)
   598 val ((pt,_),_) = get_calc 1;
   599 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   600 val NONE = env;
   601 val (SOME istate, NONE) = loc;
   602 (*============ inhibit exn AK110725 ==============================================
   603 (* ERROR: Argument: istate : istate * Proof.context Reason: Can't unify istate to istate * Proof.context *)
   604 print_depth 5; writeln (istate2str istate);  print_depth 3;
   605 ============ inhibit exn AK110725 ==============================================*)
   606 (*ScrState ([],
   607  [], NONE,
   608  ??.empty, Sundef, false)*)
   609 print_depth 5; spec; print_depth 3;
   610 (*("Isac",
   611       ["derivative_of", "function"],
   612       ["diff", "differentiate_on_R"]) : spec*)
   613 writeln (itms2str_ ctxt probl);
   614 (*[
   615 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   616 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   617 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   618 writeln (itms2str_ ctxt meth);
   619 (*[
   620 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   621 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   622 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   623 writeln"-----------------------------------------------------------";
   624 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   625 autoCalculate 1 (Step 1);
   626 val ((pt,p),_) = get_calc 1;
   627 val Form res = (#1 o pt_extract) (pt, p);
   628 if term2str res = "d_d x (x ^^^ 2 + x + 1)" then ()
   629 else error "diff.sml Diff (x^2 + x + 1, x) from exp";
   630 
   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 = Script 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 
   891 case check_error_patterns (res, inf) (prog, env) (errpats, rls) of SOME _ => () 
   892 | NONE => error "check_error_patterns broken";
   893 
   894 
   895 "--------- embed fun check_error_patterns ------------------------";
   896 "--------- embed fun check_error_patterns ------------------------";
   897 "--------- embed fun check_error_patterns ------------------------";
   898 states:=[];
   899 CalcTree
   900 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
   901   ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
   902 Iterator 1;
   903 moveActiveRoot 1;
   904 autoCalculate 1 CompleteCalcHead;
   905 autoCalculate 1 (Step 1);
   906 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
   907 (*autoCalculate 1 (Step 1);([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)*)
   908 
   909 "~~~~~ fun appendFormula, args:"; val (cI, (ifo:cterm')) = (1, "d_d x (x ^ 2) + cos (4 * x ^ 3)");
   910 val cs = get_calc cI
   911 val pos as (_,p_) = get_pos cI 1; (*pos = ([1], Res)*)
   912 val cs' = 
   913     case step pos cs of
   914 	    ("ok", cs') => cs';
   915 
   916 val (_, _, (pt, ([2], Res))) = cs';
   917 (*show_pt pt;
   918   [(([], Frm), Diff (x ^^^ 2 + sin (x ^^^ 4), x)),
   919    (([1], Frm), d_d x (x ^^^ 2 + sin (x ^^^ 4))),
   920    (([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))), <<=== input follos: "...+ cos(4.x^3)"
   921    (([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4))] *)
   922 
   923 "~~~~~ fun inform, args:"; val ((cs as (_, _, ptp as (pt, pos as (p, p_))): calcstate'), istr) =
   924   (cs', (encode ifo));
   925 val 	SOME f_in = parse (assoc_thy "Isac") istr
   926 val f_in = term_of f_in
   927 val pos_pred = lev_back' pos
   928 			(* f_pred ---"step pos cs"---> f_succ in appendFormula
   929    TODO.WN120517: one starting point for redesign of pos' *)
   930 val (f_pred, f_succ) = (get_curr_formula (pt, pos_pred), get_curr_formula (pt, pos));
   931 	
   932 term2str f_pred = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))";
   933 term2str f_succ = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)";
   934 
   935 			f_succ = f_in; (* = false*)
   936 cas_input f_in; (* = NONE*)
   937 val msg_calcstate' = compare_step ([], [], (pt, pos_pred)) f_in
   938 val ("no derivation found", calcstate') = msg_calcstate';
   939 			                 val pp = par_pblobj pt p
   940 			                 val {errpats, nrls, scr = Script prog, ...} = get_met (get_obj g_metID pt pp)
   941 			                 val ScrState (env, _, _, _, _, _) = get_istate pt pos;
   942                  case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
   943 			                   SOME errpatID => ("error pattern #" ^ errpatID ^ "#", calcstate')
   944 			                 | NONE => msg_calcstate';
   945 
   946 "~~~~~ from inform return val:"; val () = ();
   947 case check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
   948 			  SOME errpatID => ()
   949 			| NONE => error "check_error_patterns broken";
   950 
   951 "--- final check:";
   952 case inform cs' (encode ifo) of
   953   ("error pattern #chain-rule-diff-both#", calcstate') => ()
   954 | _ => error "inform with (positive) check_error_patterns broken"
   955 
   956 "--------- embed fun find_fillpatterns ---------------------------";
   957 "--------- embed fun find_fillpatterns ---------------------------";
   958 "--------- embed fun find_fillpatterns ---------------------------";
   959 states:=[];
   960 CalcTree
   961 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
   962   ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
   963 Iterator 1;
   964 moveActiveRoot 1;
   965 autoCalculate 1 CompleteCalcHead;
   966 autoCalculate 1 (Step 1);
   967 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
   968 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)";
   969   (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
   970   (*or
   971     <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
   972 
   973 "~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
   974   val ((pt, _), _) = get_calc cI
   975 				val pos = get_pos cI 1;
   976 "~~~~~ fun find_fillpatterns, args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
   977 	    val f_curr = get_curr_formula (pt, pos); (* = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"*)
   978     val pp = par_pblobj pt p
   979 			    val {errpats, scr = Script prog, ...} = get_met (get_obj g_metID pt pp)
   980     val ScrState (env, _, _, _, _, _) = get_istate pt pos
   981     val subst = get_bdv_subst prog env
   982     val errpatthms = errpats
   983       |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
   984       |> map (#3: errpat -> thm list)
   985       |> flat;
   986 
   987 case map (get_fillpats subst f_curr errpatID) errpatthms |> flat of
   988   ("fill-d_d-arg", tm, thm, subs_opt) :: _ => if term2str tm = 
   989     "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
   990     then () else error "find_fillpatterns changed 1a"
   991 | _ => error "find_fillpatterns changed 1b"
   992 
   993 "~~~~~ fun get_fillpats, args:"; val (subst, form, errpatID, thm) =
   994   (subst, f_curr, errpatID, hd (*simulate beginning of "map"*) errpatthms);
   995         val thmDeriv = Thm.get_name_hint thm
   996         val (part, thyID) = thy_containing_thm thmDeriv
   997         val theID = [part, thyID, "Theorems", thmID_of_derivation_name thmDeriv]
   998         val Hthm {fillpats, ...} = get_the theID
   999         val some = map (get_fillform subst (thm, form) errpatID) fillpats;
  1000 
  1001 case some |> filter is_some |> map the of
  1002   ("fill-d_d-arg", tm, thm, subsopt) :: _ => if term2str tm = 
  1003     "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
  1004     then () else error "find_fillpatterns changed 2a"
  1005 | _ => error "find_fillpatterns changed 2b"
  1006 
  1007 "~~~~~ fun get_fillform, args:";
  1008   val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
  1009   (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
  1010 val (form', _, _, rewritten) =
  1011       rew_sub (Isac()) 1 subst e_rew_ord e_rls false [] (Trueprop $ pat) form;
  1012 
  1013 if term2str form' = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" then ()
  1014 else error "find_fillpatterns changed 3";
  1015 
  1016 "~~~~~ to findFillpatterns return val:"; val (fillpats) =
  1017   (map (get_fillpats (subs_opt, subst) f_curr errpatID) errpatthms |> flat) (*only from "hd errpatthms"*);
  1018 
  1019 val msg = "fill patterns " ^
  1020   ((map ((apsnd term2str) o quad2pair) fillpats) |> map pair2str_ |> strs2str_);
  1021 if msg =
  1022   "fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1023     " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" ^
  1024   "#fill-both-args#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1025     " =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3" ^
  1026   "#fill-d_d#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1027     " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1 x (x ^^^ 4)" ^
  1028   "#fill-inner-deriv#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1029     " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1" ^
  1030   "#fill-all#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) = d_d x (x ^^^ 2) + ?_dummy_1#"
  1031 then () else error "find_fillpatterns changed 4";
  1032 
  1033 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1034 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1035 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1036 states := [];
  1037 CalcTree
  1038 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
  1039   ("Isac", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
  1040 Iterator 1;
  1041 moveActiveRoot 1;
  1042 autoCalculate 1 CompleteCalcHead;
  1043 autoCalculate 1 (Step 1);
  1044 autoCalculate 1 (Step 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
  1045 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)"; (*<<<<<<<=========================*)
  1046 (* the check for errpat is maximally liberal (whole term modulo "nrls" from "type met"),
  1047   would recognize "cos (4 * x ^ (4 - 1)) + 2 * x" as well.
  1048   results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
  1049   instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
  1050   val ((pt,pos), _) = get_calc 1;
  1051   val p = get_pos 1 1;
  1052   val (Form f, _, asms) = pt_extract (pt, p);
  1053 
  1054   if p = ([1], Res) andalso term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
  1055     get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], ("diff_sum", "Diff.diff_sum"(*?!?*)))
  1056   then () else error "embed fun get_fillform changed 1";
  1057 
  1058 findFillpatterns 1 "chain-rule-diff-both"; (*<<<<<<<=================================*)
  1059 (*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =
  1060   d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
  1061   val ((pt,pos),_) = get_calc 1;
  1062   val p = get_pos 1 1;
  1063 
  1064   val (Form f, _, asms) = pt_extract (pt, p);
  1065   if p = ([1], Res) andalso term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
  1066     get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], ("diff_sum", "Diff.diff_sum"(*?!?*)))
  1067   then ()
  1068   else error "embed fun get_fillform changed 2";
  1069 
  1070 requestFillformula 1 ("chain-rule-diff-both", "fill-both-args");(*<<<<<<<============*)
  1071   (*<AUTOCALC> ([1], Res) ([2], Res) ([2], Res) </AUTOCALC>*)
  1072   val ((pt,pos),_) = get_calc 1;
  1073   val p = get_pos 1 1;
  1074   val (Form f, _, asms) = pt_extract (pt, p);
  1075   if p = ([1], Res) andalso existpt [2] pt andalso
  1076     term2str f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
  1077     get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], ("diff_sum", "Diff.diff_sum"))
  1078   then () else error "embed fun get_fillform changed 3";
  1079 
  1080 (* input a formula which exactly fills the gaps in a "fillformula"
  1081    presented to the learner immediately before by "requestFillformula (errpatID, fillpatID)":
  1082    errpatID: lhs of the respective thm = lhs of fillformula with fillpatID.
  1083    the respective thm is in the ctree ................
  1084 *)
  1085 "~~~~~ fun inputFillFormula, args:"; val (cI, ifo) =
  1086   (1, "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)");
  1087     val ((pt, _), _) = get_calc cI
  1088     val pos = get_pos cI 1;
  1089 
  1090 "~~~~~ fun is_exactly_equal, args:"; val ((pt, pos as (p, p_)), istr) = ((pt, pos), ifo);
  1091   val SOME ifo = parseNEW (assoc_thy "Isac" |> thy2ctxt) istr
  1092   val p' = lev_on p;
  1093   val tac = get_obj g_tac pt p';
  1094   if tac = Rewrite_Inst (["(bdv, x)"], ("diff_sin_chain", "")) then ()
  1095   else error "inputFillFormula changed 10";
  1096   val Appl rew = applicable_in pos pt tac;
  1097   val Rewrite_Inst' (_, _, _, _, _, _, _, (res, _)) = rew;
  1098 
  1099 "~~~~~ to inputFillFormula return val:"; val ("ok", tac) = ("ok", tac);
  1100   val ("ok", (_, c, ptp as (_,p'))) = locatetac tac (pt, pos);
  1101     upd_calc cI (ptp, []);
  1102     upd_ipos cI 1 p';
  1103     autocalculateOK2xml cI pos (if null c then p' else last_elem c) p';
  1104 
  1105 "~~~~~ final check:";
  1106 val ((pt, _),_) = get_calc 1;
  1107 val p = get_pos 1 1;
  1108 val (Form f, _, asms) = pt_extract (pt, p);
  1109 if p = ([2], Res) andalso
  1110   term2str f = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)" andalso
  1111   get_obj g_tac pt (fst p) = Rewrite_Inst (["(bdv, x)"], ("diff_sin_chain", ""))
  1112 then () else error "inputFillFormula changed 11";
  1113