test/Tools/isac/Interpret/inform.sml
author Walther Neuper <neuper@ist.tugraz.at>
Tue, 22 May 2012 13:40:06 +0200
changeset 42432 7dc25d1526a5
parent 42431 22f0435fdfe2
child 42433 ed0ff27b6165
permissions -rw-r--r--
added "fun requestFillformula"

given a fillpatID propose a fillform to the learner on the worksheet;
the "ctree" is extended with fillpat and "ostate Inconsistent", the "istate" is NOT updated;
returns CalcChanged.
arg errpatID: required because there is no dialog-related state in the math-kernel.

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