test/Tools/isac/Interpret/error-pattern.sml
author Walther Neuper <walther.neuper@jku.at>
Wed, 29 Apr 2020 12:30:51 +0200
changeset 59920 33913fe24685
parent 59911 ff30cec13f4f
child 59921 0766dade4a78
permissions -rw-r--r--
prep. separation of check Applicable between specify-phase and solve-phase
     1 (* Title: "Interpret/error-pattern.sml"
     2    Author: Walther Neuper 060225,
     3    (c) due to copyright terms 
     4 
     5 Strange ERROR "Undefined fact: "all_left""
     6 *)
     7 
     8 "-----------------------------------------------------------------";
     9 "table of contents -----------------------------------------------";
    10 "-----------------------------------------------------------------";
    11 "appendForm with miniscript with mini-subpbl:";
    12 "--------- appendFormula: on Res + equ_nrls ----------------------";
    13 "--------- appendFormula: on Frm + equ_nrls ----------------------";
    14 "--------- appendFormula: on Res + NO deriv ----------------------";
    15 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
    16 "replaceForm with miniscript with mini-subpbl:";
    17 "--------- replaceFormula: on Res + = ----------------------------";
    18 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
    19 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
    20 "--------- replaceFormula: cut calculation -----------------------";
    21 "--------- replaceFormula: cut calculation -----------------------";
    22 (* 040307 copied from informtest.sml ... old versions
    23 "--------- maximum-example, UC: Modeling / modifyCalcHead --------";*)
    24 "--------- syntax error ------------------------------------------";
    25 "CAS-command:";
    26 "--------- CAS-command on ([],Pbl) -------------------------------";
    27 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
    28 "--------- locate_input_term [rational,simplification] ----------------------";
    29 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
    30 "--------- Take as 1st tac, start from exp -----------------------";
    31 "--------- implicit_take, start with <NEW> (CAS input) ---------------";
    32 "--------- build fun check_for' ------------------------------";
    33 "--------- build fun check_for' ?bdv -------------------------";
    34 "--------- build fun check_for ------------------------";
    35 "--------- embed fun check_for ------------------------";
    36 "--------- embed fun find_fill_patterns ---------------------------";
    37 "--------- build fun is_exactly_equal, inputFillFormula ----------";
    38 "--------- fun appl_adds -----------------------------------------";
    39 "--------- fun concat_deriv --------------------------------------";
    40 "--------- handle an input formula -------------------------------";
    41 "--------- fun dropwhile' ----------------------------------------";
    42 "-----------------------------------------------------------------";
    43 "-----------------------------------------------------------------";
    44 "-----------------------------------------------------------------";
    45 
    46 
    47 "--------- appendFormula: on Res + equ_nrls ----------------------";
    48 "--------- appendFormula: on Res + equ_nrls ----------------------";
    49 "--------- appendFormula: on Res + equ_nrls ----------------------";
    50  val Prog sc = (#scr o get_met) ["Test","squ-equ-test-subpbl1"];
    51  (writeln o UnparseC.term) sc;
    52  val Prog sc = (#scr o get_met) ["Test","solve_linear"];
    53  (writeln o UnparseC.term) sc;
    54 
    55  reset_states ();
    56  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
    57 	    ("Test", ["sqroot-test","univariate","equation","test"],
    58 	     ["Test","squ-equ-test-subpbl1"]))];
    59  Iterator 1; moveActiveRoot 1;
    60  autoCalculate 1 CompleteCalcHead;
    61  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
    62  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
    63 
    64  appendFormula 1 "-2 * 1 + (1 + x) = 0" (*|> Future.join*); refFormula 1 (get_pos 1 1);
    65  val ((pt,_),_) = get_calc 1;
    66  val str = pr_ctree pr_short pt;
    67 if str =
    68 (".    ----- pblobj -----\n" ^
    69 "1.   x + 1 = 2\n" ^
    70 "2.   x + 1 + -1 * 2 = 0\n" ^
    71 "2.1.   x + 1 + -1 * 2 = 0\n" ^
    72 "2.2.   1 + x + -1 * 2 = 0\n" ^
    73 "2.3.   1 + (x + -1 * 2) = 0\n" ^
    74 "2.4.   1 + (x + -2) = 0\n" ^
    75 "2.5.   1 + (x + -2 * 1) = 0\n" ^
    76 "2.6.   1 + x + -2 * 1 = 0\n" ) then ()
    77 else error "inform.sml: diff.behav.appendFormula: on Res + equ 1";
    78 
    79  moveDown 1 ([ ],Pbl); refFormula 1 ([1],Frm); (*x + 1 = 2*)
    80  moveDown 1 ([1],Frm); refFormula 1 ([1],Res); (*x + 1 + -1 * 2 = 0*)
    81 
    82  (*the seven steps of detailed derivation*)
    83  moveDown 1 ([1  ],Res); refFormula 1 ([2,1],Frm); 
    84  moveDown 1 ([2,1],Frm); refFormula 1 ([2,1],Res);
    85  moveDown 1 ([2,1],Res); refFormula 1 ([2,2],Res);
    86  moveDown 1 ([2,2],Res); refFormula 1 ([2,3],Res); 
    87  moveDown 1 ([2,3],Res); refFormula 1 ([2,4],Res);
    88  moveDown 1 ([2,4],Res); refFormula 1 ([2,5],Res);
    89  moveDown 1 ([2,5],Res); refFormula 1 ([2,6],Res);
    90  val ((pt,_),_) = get_calc 1;
    91  if "-2 * 1 + (1 + x) = 0" = UnparseC.term (fst (get_obj g_result pt [2,6])) then()
    92  else error "inform.sml: diff.behav.appendFormula: on Res + equ 2";
    93 
    94  fetchProposedTactic 1; (*takes Iterator 1 _1_*)
    95 (* <ERROR> error in kernel </ERROR> ALREADY IN 2009-2*)
    96 (*========== inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 =============
    97  val (_,(tac,_,_)::_) = get_calc 1;
    98  if tac = Rewrite_Set "Test_simplify" then ()
    99  else error "inform.sml: diff.behav.appendFormula: on Res + equ 3";
   100 ============ inhibit exn WN1130701 broken at Isabelle2002 --> 2009-2 ============*)
   101 
   102  autoCalculate 1 CompleteCalc;
   103  val ((pt,_),_) = get_calc 1;
   104  if "[x = 1]" = UnparseC.term (fst (get_obj g_result pt [])) then ()
   105  else error "inform.sml: diff.behav.appendFormula: on Res + equ 4";
   106  (* autoCalculate 1 CompleteCalc;
   107    val ((pt,p),_) = get_calc 1;
   108    (writeln o istates2str) (get_obj g_loc pt [ ]);  
   109    (writeln o istates2str) (get_obj g_loc pt [1]);  
   110    (writeln o istates2str) (get_obj g_loc pt [2]);  
   111    (writeln o istates2str) (get_obj g_loc pt [3]);  
   112    (writeln o istates2str) (get_obj g_loc pt [3,1]);  
   113    (writeln o istates2str) (get_obj g_loc pt [3,2]);  
   114    (writeln o istates2str) (get_obj g_loc pt [4]);  
   115 
   116    *)
   117 "----------------------------------------------------------";
   118 
   119  val fod = Derive.do_one (@{theory "Isac_Knowledge"}) Atools_erls 
   120 		       ((#rules o Rule_Set.rep) Test_simplify)
   121 		       (sqrt_right false (@{theory "Pure"})) NONE 
   122 		       (str2term "x + 1 + -1 * 2 = 0");
   123  (writeln o Derive.trtas2str) fod;
   124 
   125  val ifod = Derive.do_one (@{theory "Isac_Knowledge"}) Atools_erls 
   126 		       ((#rules o Rule_Set.rep) Test_simplify)
   127 		       (sqrt_right false (@{theory "Pure"})) NONE 
   128 		       (str2term "-2 * 1 + (1 + x) = 0");
   129  (writeln o Derive.trtas2str) ifod;
   130  fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1 = t2;
   131  val (fod', rifod') = dropwhile' equal (rev fod) (rev ifod);
   132  val der = fod' @ (map Derive.rev_deriv' rifod');
   133  (writeln o Derive.trtas2str) der;
   134  "----------------------------------------------------------";
   135 DEconstrCalcTree 1;
   136 
   137 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   138 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   139 "--------- appendFormula: on Frm + equ_nrls ----------------------";
   140  reset_states ();
   141  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   142 	    ("Test", ["sqroot-test","univariate","equation","test"],
   143 	     ["Test","squ-equ-test-subpbl1"]))];
   144  Iterator 1; moveActiveRoot 1;
   145  autoCalculate 1 CompleteCalcHead;
   146  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1) (*x + 1 = 2*);
   147  appendFormula 1 "2+ -1 + x = 2" (*|> Future.join*); refFormula 1 (get_pos 1 1);
   148 
   149  moveDown 1 ([],Pbl); refFormula 1 ([1],Frm) (*x + 1 = 2*);
   150 
   151  moveDown 1 ([1  ],Frm); refFormula 1 ([1,1],Frm); 
   152  moveDown 1 ([1,1],Frm); refFormula 1 ([1,1],Res); 
   153  moveDown 1 ([1,1],Res); refFormula 1 ([1,2],Res); 
   154  moveDown 1 ([1,2],Res); refFormula 1 ([1,3],Res); 
   155  moveDown 1 ([1,3],Res); refFormula 1 ([1,4],Res); 
   156  moveDown 1 ([1,4],Res); refFormula 1 ([1,5],Res); 
   157  moveDown 1 ([1,5],Res); refFormula 1 ([1,6],Res); 
   158  val ((pt,_),_) = get_calc 1;
   159  if "2 + -1 + x = 2" = UnparseC.term (fst (get_obj g_result pt [1,6])) then()
   160  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 1";
   161 
   162  fetchProposedTactic 1; (*takes Iterator 1 _1_*)
   163  val (_,(tac,_,_)::_) = get_calc 1;
   164  case tac of Rewrite_Set "norm_equation" => ()
   165  | _ => error "inform.sml: diff.behav.appendFormula: on Frm + equ 2";
   166  autoCalculate 1 CompleteCalc;
   167  val ((pt,_),_) = get_calc 1;
   168  if "[x = 1]" = UnparseC.term (fst (get_obj g_result pt [])) then ()
   169  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
   170 DEconstrCalcTree 1;
   171 
   172 "--------- appendFormula: on Res + NO deriv ----------------------";
   173 "--------- appendFormula: on Res + NO deriv ----------------------";
   174 "--------- appendFormula: on Res + NO deriv ----------------------";
   175  reset_states ();
   176  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   177 	    ("Test", ["sqroot-test","univariate","equation","test"],
   178 	     ["Test","squ-equ-test-subpbl1"]))];
   179  Iterator 1; moveActiveRoot 1;
   180  autoCalculate 1 CompleteCalcHead;
   181  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   182  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   183 
   184  appendFormula 1 "x = 2" (*|> Future.join*);
   185  val ((pt,p),_) = get_calc 1;
   186  val str = pr_ctree pr_short pt;
   187  writeln str;
   188  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" andalso p = ([1], Res)
   189  then ()
   190  else error "inform.sml: diff.behav.appendFormula: Res + NOder 1";
   191 
   192  fetchProposedTactic 1;
   193  val (_,(tac,_,_)::_) = get_calc 1;
   194  case tac of Rewrite_Set "Test_simplify" => ()
   195  | _ => error "inform.sml: diff.behav.appendFormula: Res + NOder 2";
   196  autoCalculate 1 CompleteCalc;
   197  val ((pt,_),_) = get_calc 1;
   198  if "[x = 1]" = UnparseC.term (fst (get_obj g_result pt [])) then ()
   199  else error "inform.sml: diff.behav.appendFormula: on Frm + equ 3";
   200 DEconstrCalcTree 1;
   201 
   202 "--------- appendFormula: on Res + late deriv --------------------";
   203 "--------- appendFormula: on Res + late deriv --------------------";
   204 "--------- appendFormula: on Res + late deriv --------------------";
   205 (*cp with "fun me" to test/../lucas-interpreter.sml:
   206  re-build: fun locate_input_term ---------------------------------------------------"; 
   207 *)
   208  reset_states ();
   209  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   210 	    ("Test", ["sqroot-test","univariate","equation","test"],
   211 	     ["Test","squ-equ-test-subpbl1"]))];
   212  Iterator 1; moveActiveRoot 1;
   213  autoCalculate 1 CompleteCalcHead;
   214  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   215  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   216 
   217  appendFormula 1 "x = 1" (*|> Future.join*);
   218  val ((pt,p),_) = get_calc 1;
   219  val str = pr_ctree pr_short pt;
   220  writeln str;
   221  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)
   222  then () (*finds 1 step too early: ([3,2], Res) "x = 1" also by script !!!*)
   223  else error "inform.sml: diff.behav.appendFormula: Res + late d 1";
   224 
   225  fetchProposedTactic 1;
   226  val (_,(tac,_,_)::_) = get_calc 1;
   227  case tac of Check_Postcond ["LINEAR", "univariate", "equation", "test"] => ()
   228  | _ => error "inform.sml: diff.behav.appendFormula: Res + late d 2";
   229  autoCalculate 1 CompleteCalc;
   230  val ((pt,_),_) = get_calc 1;
   231  if "[x = 1]" = UnparseC.term (fst (get_obj g_result pt [])) then ()
   232  else error "inform.sml: diff.behav.appendFormula: Res + late d 3";
   233 DEconstrCalcTree 1;
   234 
   235 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   236 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   237 "--------- appendFormula: on Res + late deriv [x = 3 + -2]---///--";
   238  reset_states ();
   239  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   240 	    ("Test", ["sqroot-test","univariate","equation","test"],
   241 	     ["Test","squ-equ-test-subpbl1"]))];
   242  Iterator 1; moveActiveRoot 1;
   243  autoCalculate 1 CompleteCalcHead;
   244  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   245  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   246  appendFormula 1 "[x = 3 + -2*1]" (*|> Future.join*);
   247  val ((pt,p),_) = get_calc 1;
   248  val str = pr_ctree pr_short pt;
   249  writeln str;
   250  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 ()
   251  else error "inform.sml: diff.behav.appendFormula: Res + latEE 1";
   252  autoCalculate 1 CompleteCalc;
   253  val ((pt,p),_) = get_calc 1;
   254  if "[x = 3 + -2 * 1]" = UnparseC.term (fst (get_obj g_result pt [])) then ()
   255  (*       ~~~~~~~~~~ simplify as last step in any script ?!*)
   256  else error "inform.sml: diff.behav.appendFormula: Res + latEE 2";
   257 DEconstrCalcTree 1;
   258 
   259 "--------- replaceFormula: on Res + = ----------------------------";
   260 "--------- replaceFormula: on Res + = ----------------------------";
   261 "--------- replaceFormula: on Res + = ----------------------------";
   262  reset_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 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   269  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   270  autoCalculate 1 (Steps 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_ctree pr_short pt;
   275 
   276 (* before AK110725 this was
   277 ".    ----- pblobj -----\n
   278 1.   x + 1 = 2\n
   279 2.   x + 1 + -1 * 2 = 0\n
   280 2.1.   x + 1 + -1 * 2 = 0\n
   281 2.2.   1 + x + -1 * 2 = 0\n
   282 2.3.   1 + (x + -1 * 2) = 0\n
   283 2.4.   1 + (x + -2) = 0\n
   284 2.5.   1 + (x + -2 * 1) = 0\n
   285 2.6.   1 + x + -2 * 1 = 0\n";
   286 *)
   287 if str = 
   288 ".    ----- pblobj -----\n"^
   289 "1.   x + 1 = 2\n"^
   290 "2.   x + 1 + -1 * 2 = 0\n"^
   291 "2.1.   x + 1 + -1 * 2 = 0\n"^
   292 "2.2.   1 + x + -1 * 2 = 0\n"^
   293 "2.3.   1 + (x + -1 * 2) = 0\n"^
   294 "2.4.   1 + (x + -2) = 0\n"^
   295 "2.5.   1 + (x + -2 * 1) = 0\n"^
   296 "2.6.   1 + x + -2 * 1 = 0\n" then()
   297 else error "inform.sml: diff.behav.replaceFormula: on Res += 1";
   298 
   299  autoCalculate 1 CompleteCalc;
   300  val ((pt,pos as (p,_)),_) = get_calc 1;
   301  if pos = ([],Res) andalso "[x = 1]" = (UnparseC.term o fst) (get_obj g_result pt p) then()
   302  else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
   303 DEconstrCalcTree 1;
   304 
   305 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   306 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   307 "--------- replaceFormula: on Res + = 1st Nd ---------------------";
   308  reset_states ();
   309  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   310 	    ("Test", ["sqroot-test","univariate","equation","test"],
   311 	     ["Test","squ-equ-test-subpbl1"]))];
   312  Iterator 1; moveActiveRoot 1;
   313  autoCalculate 1 CompleteCalcHead;
   314  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   315  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   316 
   317  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   318  val ((pt,_),_) = get_calc 1;
   319  val str = pr_ctree pr_short pt;
   320  writeln str;
   321  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 ()
   322  else error "inform.sml: diff.behav.replaceFormula: on Res 1 + = 1";
   323  autoCalculate 1 CompleteCalc;
   324  val ((pt,pos as (p,_)),_) = get_calc 1;
   325  if pos = ([],Res) andalso "[x = 1]" = (UnparseC.term o fst)(get_obj g_result pt p) then()
   326  else error "inform.sml: diff.behav.replaceFormula: on Res + = 2";
   327 DEconstrCalcTree 1;
   328 
   329 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   330 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   331 "--------- replaceFormula: on Frm + = 1st Nd ---------------------";
   332  reset_states ();
   333  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   334 	    ("Test", ["sqroot-test","univariate","equation","test"],
   335 	     ["Test","squ-equ-test-subpbl1"]))];
   336  Iterator 1; moveActiveRoot 1;
   337  autoCalculate 1 CompleteCalcHead;
   338  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   339 
   340  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   341  val ((pt,_),_) = get_calc 1;
   342  val str = pr_ctree pr_short pt;
   343  writeln str;
   344  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 ()
   345  else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 1";
   346  autoCalculate 1 CompleteCalc;
   347  val ((pt,pos as (p,_)),_) = get_calc 1;
   348  if pos = ([],Res) andalso "[x = 1]" = (UnparseC.term o fst)(get_obj g_result pt p) then()
   349  else error "inform.sml: diff.behav.replaceFormula: on Frm 1 + = 2";
   350 DEconstrCalcTree 1;
   351 
   352 "--------- replaceFormula: cut calculation -----------------------";
   353 "--------- replaceFormula: cut calculation -----------------------";
   354 "--------- replaceFormula: cut calculation -----------------------";
   355  reset_states ();
   356  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   357 	    ("Test", ["sqroot-test","univariate","equation","test"],
   358 	     ["Test","squ-equ-test-subpbl1"]))];
   359  Iterator 1; moveActiveRoot 1;
   360  autoCalculate 1 CompleteCalc;
   361  moveActiveRoot 1; moveActiveDown 1;
   362  if get_pos 1 1 = ([1], Frm) then ()
   363  else error "inform.sml: diff.behav. cut calculation 1";
   364 
   365  replaceFormula 1 "x + 1 = 4 + -2"; refFormula 1 (get_pos 1 1);
   366  val ((pt,p),_) = get_calc 1;
   367  val str = pr_ctree pr_short pt;
   368  writeln str;
   369  if p = ([1], Res) then ()
   370  else error "inform.sml: diff.behav. cut calculation 2";
   371 
   372 
   373 (* 040307 copied from informtest.sml; ... old version 
   374  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   375  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   376  "---------------- maximum-example, UC: Modeling / modifyCalcHead -";
   377 
   378  val p = ([],Pbl);
   379  val elems = ["fixedValues [r=Arbfix]","maximum A","valuesFor [a,b]",
   380 	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   381 	      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   382         "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos (alpha::real)]",
   383 	      (*^^^ these are the elements for the root-problem (in variants)*)
   384               (*vvv these are elements required for subproblems*)
   385 	      "boundVariable a","boundVariable b","boundVariable alpha",
   386 	      "interval {x::real. 0 <= x & x <= 2*r}",
   387 	      "interval {x::real. 0 <= x & x <= 2*r}",
   388 	      "interval {x::real. 0 <= x & x <= pi}",
   389 	      "errorBound (eps=(0::real))"]
   390  (*specifying is not interesting for this example*)
   391  val spec = ("DiffApp", ["maximum_of","function"], 
   392 	     ["DiffApp","max_by_calculus"]);
   393  (*the empty model with descriptions for user-guidance by Model_Problem*)
   394  val empty_model = [Given ["fixedValues []"],
   395 		    Find ["maximum", "valuesFor"],
   396 		    Relate ["relations []"]];
   397 
   398 
   399  (*!!!!!!!!!!!!!!!!! DON'T USE me FOR FINDING nxt !!!!!!!!!!!!!!!!!!*)
   400  val (p,_,f,nxt,_,pt) = CalcTreeTEST [(elems, spec)];
   401  (*val nxt = ("Model_Problem", ...*)
   402  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   403 
   404  val (p,_,f,nxt,_,pt) = me nxt p c pt;
   405  (*nxt = Add_Given "fixedValues [r = Arbfix]"*)
   406  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   407 (*[
   408 (0 ,[] ,false ,#Given ,Inc fixedValues [] ,(??.empty, [])),
   409 (0 ,[] ,false ,#Find ,Inc maximum ,(??.empty, [])),
   410 (0 ,[] ,false ,#Find ,Inc valuesFor ,(??.empty, [])),
   411 (0 ,[] ,false ,#Relate ,Inc relations [] ,(??.empty, []))]*)
   412 
   413  (*the empty CalcHead is checked w.r.t the model and re-established as such*)
   414  val (b,pt,ocalhd) = input_icalhd pt (p,"", empty_model, Pbl, Spec.empty);
   415  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   416  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(\"ThyC.id_empty\", [\"e_pblID\"], [\"e_metID\"]) )" then () else error "informtest.sml: diff.behav. max 1";
   417 
   418  (*there is one input to the model (could be more)*)
   419  val (b,pt,ocalhd) = 
   420      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   421 			     Find ["maximum", "valuesFor"],
   422 			     Relate ["relations"]], Pbl, Spec.empty);
   423  val pbl = get_obj g_pbl pt (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   424  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(\"ThyC.id_empty\", [\"e_pblID\"], [\"e_metID\"]) )" then () 
   425  else error "informtest.sml: diff.behav. max 2";
   426 
   427  (*this input is complete in variant 3, but the ME doesn't recognize FIXXXXME
   428  val (b,pt''''',ocalhd) = 
   429      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   430 			     Find ["maximum A", "valuesFor [a,b]"],
   431 			     Relate ["relations [A=a*b, a/2=r*sin alpha, \
   432 				     \b/2=r*cos alpha]"]], Pbl, Spec.empty);
   433  val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   434  if ocalhd2str ocalhd = ------------^^^^^^^^^^ missing !!!*)
   435 
   436  (*this input is complete in variant 1 (variant 3 does not work yet)*)
   437  val (b,pt''''',ocalhd) = 
   438      input_icalhd pt (p,"", [Given ["fixedValues [r=Arbfix]"],
   439 			     Find ["maximum A", "valuesFor [a,b]"],
   440 			     Relate ["relations [A=a*b, \
   441 				     \(a/2)^^^2 + (b/2)^^^2 = r^^^2]"]], 
   442 		      Pbl, Spec.empty);
   443  val pbl = get_obj g_pbl pt''''' (fst p); (writeln o (itms2str_ ctxt)) pbl; 
   444 
   445  modifycalcheadOK2xml 111 (bool2str b) ocalhd;
   446 *)
   447 DEconstrCalcTree 1;
   448 
   449 "--------- syntax error ------------------------------------------";
   450 "--------- syntax error ------------------------------------------";
   451 "--------- syntax error ------------------------------------------";
   452  reset_states ();
   453  CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   454 	    ("Test", ["sqroot-test","univariate","equation","test"],
   455 	     ["Test","squ-equ-test-subpbl1"]))];
   456  Iterator 1; moveActiveRoot 1;
   457  autoCalculate 1 CompleteCalcHead;
   458  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 = 2*)
   459  autoCalculate 1 (Steps 1); refFormula 1 (get_pos 1 1);(*x + 1 + -1 * 2 = 0*);
   460 
   461  appendFormula 1 " x - "; (*<ERROR> syntax error in ' x - ' </ERROR>*)
   462  val ((pt,_),_) = get_calc 1;
   463  val str = pr_ctree pr_short pt;
   464  writeln str;
   465  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" then ()
   466  else error "inform.sml: diff.behav.appendFormula: syntax error";
   467 DEconstrCalcTree 1;
   468 
   469 "--------- CAS-command on ([],Pbl) -------------------------------";
   470 "--------- CAS-command on ([],Pbl) -------------------------------";
   471 "--------- CAS-command on ([],Pbl) -------------------------------";
   472 val (p,_,f,nxt,_,pt) = 
   473     CalcTreeTEST [([], ("empty_thy_id", ["empty_probl_id"], ["empty_meth_id"]))];
   474 val ifo = "solve(x+1=2,x)";
   475 val (_,(_,c,(pt,p))) = Step_Solve.by_term (pt,p) "solve(x+1=2,x)";
   476 show_pt pt;
   477 val nxt = (Apply_Method ["Test","squ-equ-test-subpbl1"]);
   478 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   479 if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
   480 else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
   481 DEconstrCalcTree 1;
   482 
   483 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   484 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   485 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   486 reset_states ();
   487 CalcTree [([], ("empty_thy_id", ["empty_probl_id"], ["empty_meth_id"]))];
   488 Iterator 1;
   489 moveActiveRoot 1;
   490 replaceFormula 1 "solve(x+1=2,x)";
   491 autoCalculate 1 CompleteCalc;
   492 val ((pt,p),_) = get_calc 1;
   493 show_pt pt;
   494 if p = ([], Res) then ()
   495 else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
   496 DEconstrCalcTree 1;
   497 
   498 "--------- inform [rational,simplification] ----------------------";
   499 "--------- inform [rational,simplification] ----------------------";
   500 "--------- inform [rational,simplification] ----------------------";
   501 reset_states ();
   502 CalcTree [(["Term (a * x / (b * x) + c * x / (d * x) + e / f)", "normalform N"],
   503 	("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
   504 Iterator 1; moveActiveRoot 1;
   505 autoCalculate 1 CompleteCalcHead;
   506 
   507 "--- (-1) give a preview on the calculation without any input";
   508 (*
   509 autoCalculate 1 CompleteCalc;
   510 val ((pt, p), _) = get_calc 1;
   511 show_pt pt;
   512 [
   513 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   514 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   515 (([1], Res), a / b + c / d + e / f),                             <--- (1) input arbitrary
   516 (([2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   517 (([3], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
   518 (([4], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)), <--- (2) input next
   519 (([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))]  <--- (3) is also final result
   520                                                                           EXAMPLE NOT OPTIMAL
   521 *)
   522 "--- (0) user input as the *first* step does not work, thus impdo at least 1 step";
   523 autoCalculate 1 (Steps 1);
   524 autoCalculate 1 (Steps 1);
   525 val ((pt, p), _) = get_calc 1;
   526 (*show_pt pt;
   527 [
   528 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   529 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   530 (([1], Res), a / b + c / d + e / f)] 
   531 *)
   532 "--- (1) input an arbitrary next formula";
   533 appendFormula 1 "((a * d) + (c * b)) / (b * d) + e / f" (*|> Future.join*);
   534 val ((pt, p), _) = get_calc 1;
   535 (*show_pt pt;
   536 [
   537 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   538 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   539 (([1], Res), a / b + c / d + e / f),
   540 (([2,1], Frm), a / b + c / d + e / f),
   541 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   542 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
   543 (([2], Res), (a * d + c * b) / (b * d) + e / f)] 
   544 *)
   545 val ((pt,p),_) = get_calc 1;
   546 if p = ([2], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   547 else error ("inform.sml: [rational,simplification] 1");
   548 
   549 "--- (2) input the next formula that would be presented by mat-engine";
   550 (* generate a preview:
   551 autoCalculate 1 (Steps 1);
   552 val ((pt, p), _) = get_calc 1;
   553 show_pt pt;
   554 [
   555 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   556 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   557 (([1], Res), a / b + c / d + e / f),
   558 (([2,1], Frm), a / b + c / d + e / f),
   559 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   560 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
   561 (([2], Res), (a * d + c * b) / (b * d) + e / f),
   562 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))]   <--- input this
   563 *)
   564 appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
   565 val ((pt, p), _) = get_calc 1;
   566 (*show_pt pt;
   567 [
   568 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   569 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   570 (([1], Res), a / b + c / d + e / f),
   571 (([2,1], Frm), a / b + c / d + e / f),
   572 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   573 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
   574 (([2], Res), (a * d + c * b) / (b * d) + e / f),
   575 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] 
   576 *)
   577 if p = ([3], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
   578 else error ("inform.sml: [rational,simplification] 2");
   579 
   580 "--- (3) input the exact final result";
   581 appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
   582 val ((pt, p), _) = get_calc 1;
   583 (*show_pt pt;
   584 [
   585 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   586 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   587 (([1], Res), a / b + c / d + e / f),
   588 (([2,1], Frm), a / b + c / d + e / f),
   589 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   590 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
   591 (([2], Res), (a * d + c * b) / (b * d) + e / f),
   592 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   593 (([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   594 (([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
   595 (([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   596 (([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] 
   597 *)
   598 if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   599 else error ("inform.sml: [rational,simplification] 3");
   600 
   601 "--- (4) finish the calculation + check the postcondition (in the future)";
   602 autoCalculate 1 CompleteCalc;
   603 val ((pt, p), _) = get_calc 1;
   604 val (t, asm) = get_obj g_result pt [];
   605 if UnparseC.term t = "(a * d * f + b * c * f + b * d * e) / (b * d * f)" andalso
   606 UnparseC.terms asm = "[\"b * d * f \<noteq> 0\",\"d \<noteq> 0\",\"b \<noteq> 0\",\"a * x / (b * x) + c * x / (d * x) + e / f is_ratpolyexp\"]"
   607 then () else error "inform [rational,simplification] changed at end";
   608 (*show_pt pt;
   609 [
   610 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   611 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   612 (([1], Res), a / b + c / d + e / f),
   613 (([2,1], Frm), a / b + c / d + e / f),
   614 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   615 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
   616 (([2], Res), (a * d + c * b) / (b * d) + e / f),
   617 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   618 (([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   619 (([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
   620 (([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   621 (([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   622 (([5], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
   623 (([6], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)),
   624 (([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))] 
   625 *)
   626 DEconstrCalcTree 1;
   627 
   628 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   629 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   630 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   631 val t = str2term "Diff (x^^^2 + x + 1, x)";
   632 case t of Const ("Diff.Diff", _) $ _ => ()
   633 	| _ => raise 
   634 	      error "diff.sml behav.changed for CAS Diff (..., x)";
   635 atomty t;
   636 "-----------------------------------------------------------------";
   637 (*1>*)reset_states ();
   638 (*2>*)CalcTree [([], ("empty_thy_id", ["empty_probl_id"], ["empty_meth_id"]))];
   639 (*3>*)Iterator 1;moveActiveRoot 1;
   640 "----- here the Headline has been finished";
   641 (*4>*)moveActiveFormula 1 ([],Pbl);
   642 (*5>*)replaceFormula 1 "Diff (x^2 + x + 1, x)";
   643 val ((pt,_),_) = get_calc 1;
   644 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   645 val NONE = env;
   646 val (SOME istate, NONE) = loc;
   647 (*default_print_depth 5;*)
   648 writeln"-----------------------------------------------------------";
   649 spec;
   650 writeln (itms2str_ ctxt probl);
   651 writeln (itms2str_ ctxt meth);
   652 writeln (Istate.string_of (fst istate));
   653 
   654 refFormula 1 ([],Pbl) (*--> correct CalcHead*);
   655  (*081016 NOT necessary (but leave it in Java):*)
   656 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
   657 "----- here the CalcHead has been completed --- ONCE MORE ?????";
   658 
   659 (***difference II***)
   660 val ((pt,p),_) = get_calc 1;
   661 (*val p = ([], Pbl)*)
   662 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   663 val NONE = env;
   664 val (SOME istate, NONE) = loc;
   665 (*default_print_depth 5;*) writeln (Istate.string_of (fst istate));  (*default_print_depth 3;*)
   666 (*Pstate ([],
   667  [], NONE,
   668  ??.empty, Sundef, false)*)
   669 (*default_print_depth 5;*) spec; (*default_print_depth 3;*)
   670 (*("Isac_Knowledge",
   671       ["derivative_of", "function"],
   672       ["diff", "differentiate_on_R"]) : spec*)
   673 writeln (itms2str_ ctxt probl);
   674 (*[
   675 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   676 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   677 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   678 writeln (itms2str_ ctxt meth);
   679 (*[
   680 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   681 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   682 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   683 writeln"-----------------------------------------------------------";
   684 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   685 (*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
   686 autoCalculate 1 CompleteCalc;
   687 val ((pt,p),_) = get_calc 1;
   688 val Form res = (#1 o pt_extract) (pt, ([],Res));
   689 show_pt pt;
   690 if p = ([], Res) andalso UnparseC.term res = "1 + 2 * x" then ()
   691 else error "diff.sml behav.changed for Diff (x^2 + x + 1, x)";
   692 DEconstrCalcTree 1;
   693 
   694 "--------- Take as 1st tac, start from exp -----------------------";
   695 "--------- Take as 1st tac, start from exp -----------------------";
   696 "--------- Take as 1st tac, start from exp -----------------------";
   697 (*the following input is copied from BridgeLog Java <==> SML,
   698   omitting unnecessary inputs*)
   699 (*1>*)reset_states ();
   700 (*2>*)CalcTree [(["functionTerm (x^2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac_Knowledge",["derivative_of","function"],["diff","differentiate_on_R"]))];
   701 (*3>*)Iterator 1; moveActiveRoot 1;
   702 
   703 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
   704 (***difference II***)
   705 val ((pt,_),_) = get_calc 1;
   706 val PblObj {probl, meth, spec, fmz, env, loc, ...} = get_obj I pt [];
   707 val NONE = env;
   708 val (SOME istate, NONE) = loc;
   709 (*default_print_depth 5;*) writeln (Istate.string_of (fst istate));  (*default_print_depth 3;*)
   710 (*Pstate ([],
   711  [], NONE,
   712  ??.empty, Sundef, false)*)
   713 (*default_print_depth 5;*) spec; (*default_print_depth 3;*)
   714 (*("Isac_Knowledge",
   715       ["derivative_of", "function"],
   716       ["diff", "differentiate_on_R"]) : spec*)
   717 writeln (itms2str_ ctxt probl);
   718 (*[
   719 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   720 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   721 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   722 writeln (itms2str_ ctxt meth);
   723 (*[
   724 (1 ,[1] ,true ,#Given ,Cor functionTerm (x ^^^ 2 + x + 1) ,(f_, [x ^^^ 2 + x + 1])),
   725 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   726 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   727 writeln"-----------------------------------------------------------";
   728 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   729 autoCalculate 1 (Steps 1);
   730 val ((pt,p),_) = get_calc 1;
   731 val Form res = (#1 o pt_extract) (pt, p);
   732 if UnparseC.term res = "d_d x (x ^^^ 2 + x + 1)" then ()
   733 else error "diff.sml Diff (x^2 + x + 1, x) from exp";
   734 DEconstrCalcTree 1;
   735 
   736 "--------- implicit_take, start with <NEW> (CAS input) ---------------";
   737 "--------- implicit_take, start with <NEW> (CAS input) ---------------";
   738 "--------- implicit_take, start with <NEW> (CAS input) ---------------";
   739 reset_states ();
   740 CalcTree [([], ("empty_thy_id", ["empty_probl_id"], ["empty_meth_id"]))];
   741 (*[[from sml: > @@@@@begin@@@@@
   742 [[from sml:  1 
   743 [[from sml: <CALCTREE>
   744 [[from sml:    <CALCID> 1 </CALCID>
   745 [[from sml: </CALCTREE>
   746 [[from sml: @@@@@end@@@@@*)
   747 Iterator 1;
   748 (*[[from sml: > @@@@@begin@@@@@
   749 [[from sml:  1 
   750 [[from sml: <ADDUSER>
   751 [[from sml:   <CALCID> 1 </CALCID>
   752 [[from sml:   <USERID> 1 </USERID>
   753 [[from sml: </ADDUSER>
   754 [[from sml: @@@@@end@@@@@*)
   755 moveActiveRoot 1;
   756 (*[[from sml: > @@@@@begin@@@@@
   757 [[from sml:  1 
   758 [[from sml: <CALCITERATOR>
   759 [[from sml:   <CALCID> 1 </CALCID>
   760 [[from sml:   <POSITION>
   761 [[from sml:     <INTLIST>
   762 [[from sml:     </INTLIST>
   763 [[from sml:     <POS> Pbl </POS>
   764 [[from sml:   </POSITION>
   765 [[from sml: </CALCITERATOR>
   766 [[from sml: @@@@@end@@@@@*)
   767 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
   768 (*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
   769 [[from sml:  1 
   770 [[from sml: <GETELEMENTSFROMTO>
   771 [[from sml:   <CALCID> 1 </CALCID>
   772 [[from sml:   <FORMHEADS>
   773 [[from sml:     <CALCFORMULA>
   774 [[from sml:       <POSITION>
   775 [[from sml:         <INTLIST>
   776 [[from sml:         </INTLIST>
   777 [[from sml:         <POS> Pbl </POS>
   778 [[from sml:       </POSITION>
   779 [[from sml:       <FORMULA>
   780 [[from sml:         <MATHML>
   781 [[from sml:           <ISA> ________________________________________________ </ISA>
   782 [[from sml:         </MATHML>
   783 [[from sml: 
   784 [[from sml:       </FORMULA>
   785 [[from sml:     </CALCFORMULA>
   786 [[from sml:   </FORMHEADS>
   787 [[from sml: </GETELEMENTSFROMTO>
   788 [[from sml: @@@@@end@@@@@*)
   789 refFormula 1 ([],Pbl);
   790 (*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
   791 [[from sml:  1 
   792 [[from sml: <REFFORMULA>
   793 [[from sml:   <CALCID> 1 </CALCID>
   794 [[from sml:   <CALCHEAD status = "incorrect">
   795 [[from sml:     <POSITION>
   796 [[from sml:       <INTLIST>
   797 [[from sml:       </INTLIST>
   798 [[from sml:       <POS> Pbl </POS>
   799 [[from sml:     </POSITION>
   800 [[from sml:     <HEAD>
   801 [[from sml:       <MATHML>
   802 [[from sml:         <ISA> Problem (ThyC.id_empty, [e_pblID]) </ISA>
   803 [[from sml:       </MATHML>
   804 [[from sml:     </HEAD>
   805 [[from sml:     <MODEL>
   806 [[from sml:       <GIVEN>  </GIVEN>
   807 [[from sml:       <WHERE>  </WHERE>
   808 [[from sml:       <FIND>  </FIND>
   809 [[from sml:       <RELATE>  </RELATE>
   810 [[from sml:     </MODEL>
   811 [[from sml:     <BELONGSTO> Pbl </BELONGSTO>
   812 [[from sml:     <SPECIFICATION>
   813 [[from sml:       <THEORYID> ThyC.id_empty </THEORYID>
   814 [[from sml:       <PROBLEMID>
   815 [[from sml:         <STRINGLIST>
   816 [[from sml:           <STRING> Problem.id_empty </STRING>
   817 [[from sml:         </STRINGLIST>
   818 [[from sml:       </PROBLEMID>
   819 [[from sml:       <METHODID>
   820 [[from sml:         <STRINGLIST>
   821 [[from sml:           <STRING> e_metID </STRING>
   822 [[from sml:         </STRINGLIST>
   823 [[from sml:       </METHODID>
   824 [[from sml:     </SPECIFICATION>
   825 [[from sml:   </CALCHEAD>
   826 [[from sml: </REFFORMULA>
   827 [[from sml: @@@@@end@@@@@*)
   828 moveActiveFormula 1 ([],Pbl);
   829 (*[[from sml: > @@@@@begin@@@@@
   830 [[from sml:  1 
   831 [[from sml: <CALCITERATOR>
   832 [[from sml:   <CALCID> 1 </CALCID>
   833 [[from sml:   <POSITION>
   834 [[from sml:     <INTLIST>
   835 [[from sml:     </INTLIST>
   836 [[from sml:     <POS> Pbl </POS>
   837 [[from sml:   </POSITION>
   838 [[from sml: </CALCITERATOR>
   839 [[from sml: @@@@@end@@@@@*)
   840 replaceFormula 1 "Simplify (1+2)";
   841 (*[[from sml: > @@@@@begin@@@@@
   842 [[from sml:  1 
   843 [[from sml: <REPLACEFORMULA>
   844 [[from sml:   <CALCID> 1 </CALCID>
   845 [[from sml:   <CALCCHANGED>
   846 [[from sml:     <UNCHANGED>
   847 [[from sml:       <INTLIST>
   848 [[from sml:       </INTLIST>
   849 [[from sml:       <POS> Pbl </POS>
   850 [[from sml:     </UNCHANGED>
   851 [[from sml:     <DELETED>
   852 [[from sml:       <INTLIST>
   853 [[from sml:       </INTLIST>
   854 [[from sml:       <POS> Pbl </POS>
   855 [[from sml:     </DELETED>
   856 [[from sml:     <GENERATED>
   857 [[from sml:       <INTLIST>
   858 [[from sml:       </INTLIST>
   859 [[from sml:       <POS> Met </POS>                           DIFFERENCE: Pbl
   860 [[from sml:     </GENERATED>
   861 [[from sml:   </CALCCHANGED>
   862 [[from sml: </REPLACEFORMULA>
   863 [[from sml: @@@@@end@@@@@*)
   864 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(*              DIFFERENCE: Pbl*);
   865 (*@@@@@begin@@@@@
   866  1
   867 <GETELEMENTSFROMTO>
   868   <CALCID> 1 </CALCID>
   869   <FORMHEADS>
   870     <CALCFORMULA>
   871       <POSITION>
   872         <INTLIST>
   873         </INTLIST>
   874         <POS> Pbl </POS>
   875       </POSITION>
   876       <FORMULA>
   877         <MATHML>
   878           <ISA> Simplify (1 + 2) </ISA>                      WORKS !!!!!
   879         </MATHML>
   880       </FORMULA>
   881     </CALCFORMULA>
   882   </FORMHEADS>
   883 </GETELEMENTSFROMTO>
   884 @@@@@end@@@@@*)
   885 getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
   886 (*[[from sml: > @@@@@begin@@@@@
   887 [[from sml:  1 
   888 [[from sml: <SYSERROR>
   889 [[from sml:   <CALCID> 1 </CALCID>
   890 [[from sml:   <ERROR> error in getFormulaeFromTo </ERROR>
   891 [[from sml: </SYSERROR>
   892 [[from sml: @@@@@end@@@@@*)
   893 (*step into getFormulaeFromTo --- bug corrected...*)
   894 
   895 "--------- build fun check_for' ------------------------------";
   896 "--------- build fun check_for' ------------------------------";
   897 "--------- build fun check_for' ------------------------------";
   898 val subst = [(str2term "bdv", str2term "x")]: subst;
   899 val rls = norm_Rational
   900 val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
   901 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
   902 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "1 / 2");
   903 
   904 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
   905   rew_sub thy 1 [] e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
   906 if rewritten then NONE else SOME "e_errpatID";
   907 
   908 val norm_res = case rewrite_set_ (Isac()) false rls res' of
   909   NONE => res'
   910 | SOME (norm_res, _) => norm_res
   911 
   912 val norm_inf = case rewrite_set_ (Isac()) false rls inf of
   913   NONE => inf
   914 | SOME (norm_inf, _) => norm_inf;
   915 
   916 res' = inf;
   917 norm_res = norm_inf;
   918 
   919 val pat = parse_patt @{theory} "(?a + ?b)/?a = ?b";
   920 val (res, inf) = (str2term "(2 + 3)/2", str2term "3");
   921 if check_for' (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   922 then () else error "error patt example1 changed";
   923 
   924 val pat = parse_patt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
   925 val (res, inf) = (str2term "(2 + 3)/(2 + 4)", str2term "3 / 4");
   926 if check_for' (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   927 then () else error "error patt example2 changed";
   928 
   929 val pat = parse_patt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
   930 val (res, inf) = (str2term "(2 + 3)/(3 + 4)", str2term "2 / 4");
   931 if check_for' (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   932 then () else error "error patt example3 changed";
   933 
   934 val inf =  str2term "1 / 2";
   935 if check_for' (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   936 then () else error "error patt example3 changed";
   937 
   938 "--------- build fun check_for' ?bdv -------------------------";
   939 "--------- build fun check_for' ?bdv -------------------------";
   940 "--------- build fun check_for' ?bdv -------------------------";
   941 val subst = [(str2term "bdv", str2term "x")]: subst;
   942 val t = str2term "d_d x (x ^^^ 2 + sin (x ^^^ 4))";
   943 val SOME (t, _) = rewrite_set_inst_ thy false subst norm_diff t;
   944 if UnparseC.term t = "2 * x + cos (x ^^^ 4) * 4 * x ^^^ 3" then ()
   945 else error "build fun check_for' ?bdv changed 1"; 
   946 
   947 val rls = norm_diff
   948 val pat = parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)"; 
   949 val (res, inf) = (str2term "2 * x + d_d x (sin (x ^^^ 4))", str2term "2 * x + cos (4 * x ^^^ 3)");
   950 
   951 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern matches in res*)
   952   rew_sub thy 1 subst e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
   953 if UnparseC.term res' = "2 * x + cos (d_d x (x ^^^ 4))" andalso rewritten then ()
   954 else error "build fun check_for' ?bdv changed 2";
   955 
   956 val norm_res = case rewrite_set_inst_ (Isac()) false subst rls  res' of
   957   NONE => res'
   958 | SOME (norm_res, _) => norm_res;
   959 if UnparseC.term norm_res = "2 * x + cos (4 * x ^^^ 3)" then ()
   960 else error "build fun check_for' ?bdv changed 3";
   961 
   962 val norm_inf = case rewrite_set_inst_ (Isac()) false subst rls inf of
   963   NONE => inf
   964 | SOME (norm_inf, _) => norm_inf;
   965 if UnparseC.term norm_inf = "2 * x + cos (4 * x ^^^ 3)" then ()
   966 else error "build fun check_for' ?bdv changed 4";
   967 
   968 res' = inf;
   969 if norm_res = norm_inf then ()
   970 else error "build fun check_for' ?bdv changed 5";
   971 
   972 if Error_Pattern.check_for' (res, inf) (subst: subst) ("errpatID": errpatID, pat) rls = SOME "errpatID"
   973 then () else error "error patt example1 changed";
   974 
   975 "--------- build fun check_for ------------------------";
   976 "--------- build fun check_for ------------------------";
   977 "--------- build fun check_for ------------------------";
   978 val (res, inf) =
   979   (str2term "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))",
   980    str2term "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)");
   981 val {errpats, nrls = rls, scr = Prog prog, ...} = get_met ["diff", "differentiate_on_R"]
   982 
   983 val env = [(str2term "v_v", str2term "x")];
   984 val errpats =
   985   [e_errpat, (*generalised for testing*)
   986    ("chain-rule-diff-both",
   987      [parse_patt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)",
   988       parse_patt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)",
   989       parse_patt @{theory} "d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1)",
   990       parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u",
   991       parse_patt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u"],
   992      [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain}, 
   993       @{thm diff_ln_chain}, @{thm  diff_exp_chain}])]: errpat list;
   994 case Error_Pattern.check_for (res, inf) (prog, env) (errpats, rls) of SOME _ => () 
   995 | NONE => error "Error_Pattern.check_for broken";
   996 DEconstrCalcTree 1;
   997 
   998 "--------- embed fun check_for ------------------------";
   999 "--------- embed fun check_for ------------------------";
  1000 "--------- embed fun check_for ------------------------";
  1001 reset_states ();     
  1002 CalcTree
  1003 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
  1004   ("Isac_Knowledge", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
  1005 Iterator 1;
  1006 moveActiveRoot 1;
  1007 autoCalculate 1 CompleteCalcHead;
  1008 autoCalculate 1 (Steps 1);
  1009 autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
  1010 (*autoCalculate 1 (Steps 1);([2], Res), d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)*)
  1011 
  1012 "~~~~~ fun appendFormula , args:"; val (cI, (ifo:TermC.as_string)) = (1, "d_d x (x ^ 2) + cos (4 * x ^ 3)");
  1013 "~~~~~ fun appendFormula' , args:"; val (cI, (ifo: TermC.as_string)) = (cI, ifo);
  1014     val cs = get_calc cI
  1015     val pos = get_pos cI 1;
  1016 (*+*)if pos = ([1], Res) then () else error "inform with (positive) Error_Pattern.check_for broken 1";
  1017     val ("ok", cs' as (_, _, ptp)) = (*case*) Step.do_next pos cs (*of*);
  1018       (*case*) Step_Solve.by_term ptp (encode ifo) (*of*); (*ERROR WAS: "no derivation found"*)
  1019 "~~~~~ fun Step_Solve.by_term , args:"; val (((*next_*)cs as (_, _, (pt, pos as (p, _))): Chead.calcstate'), istr)
  1020   = (cs', (encode ifo));
  1021     val ctxt = get_ctxt pt pos (*see TODO.thy*)
  1022     val SOME f_in = (*case*) TermC.parse (ThyC.get_theory "Isac_Knowledge") istr (*of*);
  1023     	  val f_in = Thm.term_of f_in
  1024         val pos_pred = lev_back' pos
  1025     	  val f_pred = Ctree.get_curr_formula (pt, pos_pred);
  1026         (*if*) f_pred = f_in; (*else*)
  1027           val NONE = (*case*) In_Chead.cas_input f_in (*of*);
  1028        (*old* )val (_, _, metID) = get_obj g_spec pt (par_pblobj pt p)
  1029        (*old*)val {scr = prog, ...} = Specify.get_met metID
  1030        (*old*)val istate = get_istate_LI pt pos
  1031        (*old*)val ctxt = get_ctxt pt pos
  1032        ( *old*)
  1033        val LI.Not_Derivable =
  1034              (*case*) LI.locate_input_term (pt, pos) f_in (*of*);
  1035             		  val pp = Ctree.par_pblobj pt p
  1036             		  val (errpats, nrls, prog) = case Specify.get_met (Ctree.get_obj Ctree.g_metID pt pp) of
  1037               		    {errpats, nrls, scr = Rule.Prog prog, ...} => (errpats, nrls, prog)
  1038               		  | _ => error "inform: uncovered case of get_met"
  1039 ;
  1040 (*+*)if errpats2str errpats = "[(\"chain-rule-diff-both\",\n[\"d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)\",\"d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)\",\"d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1)\",\"d_d ?bdv (LogExp.ln ?u) = 1 / ?u\",\"d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u\"],\n[\"d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u\",\"d_d ?bdv (cos ?u) = - sin ?u * d_d ?bdv ?u\",\"d_d ?bdv (?u ^^^ ?n) = ?n * ?u ^^^ (?n - 1) * d_d ?bdv ?u\",\"d_d ?bdv (LogExp.ln ?u) = d_d ?bdv ?u / ?u\",\"d_d ?bdv (E_ ^^^ ?u) = E_ ^^^ ?u * d_d ?x ?u\"]]"
  1041 (*+*)then () else error "inform with (positive) Error_Pattern.check_for broken 3";
  1042 
  1043             		  val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
  1044 ;
  1045 (*+*)if UnparseC.term f_pred = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" andalso
  1046 (*+*)   UnparseC.term f_in = "d_d x (x ^^^ 2) + cos (4 * x ^^^ 3)"
  1047 (*+*)then () else error "inform with (positive) Error_Pattern.check_for broken 2";
  1048 
  1049              val SOME "chain-rule-diff-both" = (*case*) Error_Pattern.check_for (f_pred, f_in) (prog, env) (errpats, nrls) (*of*);
  1050 
  1051 "--- final check:";
  1052 (*+*)val (_, _, ptp') = cs';
  1053 case Step_Solve.by_term ptp' (encode ifo) of
  1054   ("error pattern #chain-rule-diff-both#", calcstate') => ()
  1055 | _ => error "inform with (positive) Error_Pattern.check_for broken"
  1056 
  1057 
  1058 "--------- embed fun find_fill_patterns ---------------------------";
  1059 "--------- embed fun find_fill_patterns ---------------------------";
  1060 "--------- embed fun find_fill_patterns ---------------------------";
  1061 reset_states ();
  1062 CalcTree
  1063 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
  1064   ("Isac_Knowledge", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
  1065 Iterator 1;
  1066 moveActiveRoot 1;
  1067 autoCalculate 1 CompleteCalcHead;
  1068 autoCalculate 1 (Steps 1);
  1069 autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
  1070 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)" (*|> Future.join*);
  1071   (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
  1072   (*or
  1073     <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
  1074 
  1075 "~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
  1076   val ((pt, _), _) = get_calc cI
  1077 				val pos = get_pos cI 1;
  1078 "~~~~~ fun find_fill_patterns , args:"; val ((pt, pos as (p, _)), errpatID) = ((pt, pos), errpatID);
  1079     val f_curr = Ctree.get_curr_formula (pt, pos);
  1080     val pp = Ctree.par_pblobj pt p
  1081     val (errpats, prog) = case Specify.get_met (Ctree.get_obj Ctree.g_metID pt pp) of
  1082       {errpats, scr = Rule.Prog prog, ...} => (errpats, prog)
  1083     | _ => error "find_fill_patterns: uncovered case of get_met"
  1084     val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
  1085     val subst = Subst.for_bdv prog env
  1086     val errpatthms = errpats
  1087       |> filter ((curry op = errpatID) o (#1: errpat -> errpatID))
  1088       |> map (#3: errpat -> thm list)
  1089       |> flat;
  1090 
  1091 case map (Error_Pattern.fill_from_store subst f_curr errpatID) errpatthms |> flat of
  1092   ("fill-d_d-arg", tm, thm, subs_opt) :: _ => if UnparseC.term tm = 
  1093     "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
  1094     then () else error "find_fill_patterns changed 1a"
  1095 | _ => error "find_fill_patterns changed 1b"
  1096 
  1097 "~~~~~ fun fill_from_store, args:"; val (subst, form, errpatID, thm) =
  1098   (subst, f_curr, errpatID, hd (*simulate beginning of "map"*) errpatthms);
  1099         val thmDeriv = Thm.get_name_hint thm
  1100         val (part, thyID) = thy_containing_thm thmDeriv
  1101         val theID = [part, thyID, "Theorems", ThmC.cut_id thmDeriv]
  1102         val Hthm {fillpats, ...} = get_the theID
  1103         val some = map (Error_Pattern.fill_form subst (thm, form) errpatID) fillpats;
  1104 
  1105 case some |> filter is_some |> map the of
  1106   ("fill-d_d-arg", tm, thm, subsopt) :: _ => if UnparseC.term tm = 
  1107     "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1"
  1108     then () else error "find_fill_patterns changed 2a"
  1109 | _ => error "find_fill_patterns changed 2b"
  1110 
  1111 "~~~~~ fun fill_form, args:";
  1112   val ((subs_opt, subst), (thm, form), errpatID, (fillpatID, pat, erpaID)) =
  1113   (subst, (thm, form), errpatID, hd (*simulate beginning of "map"*) fillpats);
  1114 val (form', _, _, rewritten) =
  1115       rew_sub (Isac()) 1 subst e_rew_ord Rule_Set.empty false [] (HOLogic.Trueprop $ pat) form;
  1116 
  1117 if UnparseC.term form' = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" then ()
  1118 else error "find_fill_patterns changed 3";
  1119 
  1120 "~~~~~ to findFillpatterns return val:"; val (fillpats) =
  1121   (map (Error_Pattern.fill_from_store (subs_opt, subst) f_curr errpatID) errpatthms |> flat) (*only from "hd errpatthms"*);
  1122 
  1123 "vvv--- dropped this code WN120730";
  1124 val msg = "fill patterns " ^
  1125   ((map ((apsnd UnparseC.term) o quad2pair) fillpats) |> map pair2str_ |> strs2str_);
  1126 msg =
  1127   "fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1128     " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1" ^
  1129   "#fill-both-args#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1130     " =\nd_d x (x ^^^ 2) + cos ?_dummy_2 * d_d x ?_dummy_3" ^
  1131   "#fill-d_d#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1132     " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1 x (x ^^^ 4)" ^
  1133   "#fill-inner-deriv#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" ^
  1134     " =\nd_d x (x ^^^ 2) + cos (x ^^^ 4) * ?_dummy_1" ^
  1135   "#fill-all#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) = d_d x (x ^^^ 2) + ?_dummy_1#";
  1136 "^^^--- dropped this code WN120730";
  1137 
  1138 if (map #1 fillpats) =
  1139   ["fill-d_d-arg", "fill-both-args", "fill-d_d", "fill-inner-deriv", "fill-all"]
  1140 then () else error "find_fill_patterns changed 4b";
  1141 DEconstrCalcTree 1;
  1142 
  1143 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1144 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1145 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1146 reset_states ();
  1147 CalcTree
  1148 [(["functionTerm (x ^ 2 + sin (x ^ 4))", "differentiateFor x", "derivative f_f'"], 
  1149   ("Isac_Knowledge", ["derivative_of","function"], ["diff","differentiate_on_R"]))];
  1150 Iterator 1;
  1151 moveActiveRoot 1;
  1152 autoCalculate 1 CompleteCalcHead;
  1153 autoCalculate 1 (Steps 1);
  1154 autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))*)
  1155 appendFormula 1 "d_d x (x ^ 2) + cos (4 * x ^ 3)" (*|> Future.join*); (*<<<<<<<=========================*)
  1156 (* the check for errpat is maximally liberal (whole term modulo "nrls" from "type met"),
  1157   would recognize "cos (4 * x ^ (4 - 1)) + 2 * x" as well.
  1158   results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
  1159   instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
  1160   val ((pt,pos), _) = get_calc 1;
  1161   val p = get_pos 1 1;
  1162   val (Form f, _, asms) = pt_extract (pt, p);
  1163 
  1164   if p = ([1], Res) andalso UnparseC.term f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" then
  1165     case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
  1166       ("diff_sum", thm)) =>
  1167       if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
  1168       else error "embed fun fill_form changed 11"
  1169     | _ => error "embed fun fill_form changed 12"
  1170   else error "embed fun fill_form changed 13";
  1171 
  1172 findFillpatterns 1 "chain-rule-diff-both"; (*<<<<<<<=================================*)
  1173 (*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4)) =
  1174   d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
  1175   val ((pt,pos),_) = get_calc 1;
  1176   val p = get_pos 1 1;
  1177 
  1178   val (Form f, _, asms) = pt_extract (pt, p);
  1179   if p = ([1], Res) andalso UnparseC.term f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))" then
  1180     case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
  1181       ("diff_sum", thm)) =>
  1182       if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
  1183       else error "embed fun fill_form changed 21"
  1184     | _ => error "embed fun fill_form changed 22"
  1185   else error "embed fun fill_form changed 23";
  1186 
  1187 requestFillformula 1 ("chain-rule-diff-both", "fill-both-args");(*<<<<<<<============*)
  1188   (*<AUTOCALC> ([1], Res) ([2], Res) ([2], Res) </AUTOCALC>*)
  1189   val ((pt,pos),_) = get_calc 1;
  1190   val p = get_pos 1 1;
  1191   val (Form f, _, asms) = pt_extract (pt, p);
  1192   if p = ([1], Res) andalso existpt [2] pt
  1193     andalso UnparseC.term f = "d_d x (x ^^^ 2) + d_d x (sin (x ^^^ 4))"
  1194   then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
  1195       ("diff_sum", thm)) =>
  1196       if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
  1197       else error "embed fun fill_form changed 31"
  1198     | _ => error "embed fun fill_form changed 32"
  1199   else error "embed fun fill_form changed 33";
  1200 
  1201 (* input a formula which exactly fills the gaps in a "fillformula"
  1202    presented to the learner immediately before by "requestFillformula (errpatID, fillpatID)":
  1203    errpatID: lhs of the respective thm = lhs of fillformula with fillpatID.
  1204    the respective thm is in the ctree ................
  1205 *)
  1206 "~~~~~ fun inputFillFormula, args:"; val (cI, ifo) =
  1207   (1, "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)");
  1208     val ((pt, _), _) = get_calc cI
  1209     val pos = get_pos cI 1;
  1210 
  1211 "~~~~~ fun is_exactly_equal, args:"; val ((pt, pos as (p, p_)), istr) = ((pt, pos), ifo);
  1212   val SOME ifo = parseNEW (ThyC.get_theory "Isac_Knowledge" |> ThyC.to_ctxt) istr
  1213   val p' = lev_on p;
  1214   val tac = get_obj g_tac pt p';
  1215 val Rewrite_Inst ([bbb as "(''bdv'', x)"], ("diff_sin_chain", ttt)) = tac;
  1216 if (UnparseC.term o Thm.prop_of) ttt = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
  1217 else error "inputFillFormula changed 10";
  1218   val Applicable.Yes rew = applicable_in pos pt tac;
  1219   val Rewrite_Inst' (_, _, _, _, _, _, _, (res, _)) = rew;
  1220 
  1221 "~~~~~ to inputFillFormula return val:"; val ("ok", tac) = ("ok", tac);
  1222   val ("ok", (_, c, ptp as (_,p'))) = Step.by_tactic tac (pt, pos);
  1223     upd_calc cI (ptp, []);
  1224     upd_ipos cI 1 p';
  1225     autocalculateOK2xml cI pos (if null c then p' else last_elem c) p';
  1226 
  1227 "~~~~~ final check:";
  1228 val ((pt, _),_) = get_calc 1;
  1229 val p = get_pos 1 1;
  1230 val (Form f, _, asms) = pt_extract (pt, p);
  1231   if p = ([2], Res) andalso UnparseC.term f = "d_d x (x ^^^ 2) + cos (x ^^^ 4) * d_d x (x ^^^ 4)"
  1232   then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
  1233       ("diff_sin_chain", thm)) =>
  1234       if (UnparseC.term o Thm.prop_of) thm = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
  1235       else error "inputFillFormula changed 111"
  1236     | _ => error "inputFillFormula changed 112"
  1237   else error "inputFillFormula changed 113";
  1238 
  1239 "--------- fun appl_adds -----------------------------------------";
  1240 "--------- fun appl_adds -----------------------------------------";
  1241 "--------- fun appl_adds -----------------------------------------";
  1242 (* val (dI, oris, ppc, pbt, selct::ss) = 
  1243        (dI, pors, probl, ppc, map itms2fstr probl);
  1244    ...vvv
  1245    *)
  1246 (* val (dI, oris, ppc, pbt, (selct::ss))=
  1247        (#1 (some_spec ospec spec), oris, []:itm list,
  1248 	((#ppc o get_pbt) (#2 (some_spec ospec spec))),(imodel2fstr imodel));
  1249    val iii = appl_adds dI oris ppc pbt (selct::ss); 
  1250    tracing(itms2str_ thy iii);
  1251 
  1252  val itm = appl_add' dI oris ppc pbt selct;
  1253  val ppc = insert_ppc' itm ppc;
  1254 
  1255  val _::selct::ss = (selct::ss);
  1256  val itm = appl_add' dI oris ppc pbt selct;
  1257  val ppc = insert_ppc' itm ppc;
  1258 
  1259  val _::selct::ss = (selct::ss);
  1260  val itm = appl_add' dI oris ppc pbt selct;
  1261  val ppc = insert_ppc' itm ppc;
  1262  tracing(itms2str_ thy ppc);
  1263 
  1264  val _::selct::ss = (selct::ss);
  1265  val itm = appl_add' dI oris ppc pbt selct;
  1266  val ppc = insert_ppc' itm ppc;
  1267    *)
  1268 "--------- fun concat_deriv --------------------------------------";
  1269 "--------- fun concat_deriv --------------------------------------";
  1270 "--------- fun concat_deriv --------------------------------------";
  1271 (*
  1272  val ({rew_ord, erls, rules,...}, fo, ifo) = 
  1273      (Rule_Set.rep Test_simplify, str2term "x+1+ -1*2=0", str2term "-2*1+(x+1)=0");
  1274  (tracing o Derive.trtas2str) fod';
  1275 > ["
  1276 (x + 1 + -1 * 2 = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (x + 1) = 0, []))","
  1277 (-1 * 2 + (x + 1) = 0, Thm ("radd_commute","?m + ?n = ?n + ?m"), (-1 * 2 + (1 + x) = 0, []))","
  1278 (-1 * 2 + (1 + x) = 0, Thm ("radd_left_commute","?x + (?y + ?z) = ?y + (?x + ?z)"), (1 + (-1 * 2 + x) = 0, []))","
  1279 (1 + (-1 * 2 + x) = 0, Thm ("#mult_Float ((~1,0), (0,0)) __ ((2,0), (0,0))","-1 * 2 = -2"), (1 + (-2 + x) = 0, []))"]
  1280 val it = () : unit
  1281  (tracing o Derive.trtas2str) (map Derive.rev_deriv' rifod');
  1282 > ["
  1283 (1 + (-2 + x) = 0, Thm ("sym_#mult_Float ((~2,0), (0,0)) __ ((1,0), (0,0))","-2 = -2 * 1"), (1 + (-2 * 1 + x) = 0, []))","
  1284 (1 + (-2 * 1 + x) = 0, Thm ("sym_radd_left_commute","?y + (?x + ?z) = ?x + (?y + ?z)"), (-2 * 1 + (1 + x) = 0, []))","
  1285 (-2 * 1 + (1 + x) = 0, Thm ("sym_radd_commute","?n + ?m = ?m + ?n"), (-2 * 1 + (x + 1) = 0, []))"]
  1286 val it = () : unit
  1287 *)
  1288 "--------- handle an input formula -------------------------------";
  1289 "--------- handle an input formula -------------------------------";
  1290 "--------- handle an input formula -------------------------------";
  1291 (*
  1292 Untersuchung zur Formeleingabe (appendFormula, replaceFormla) zu einer Anregung von Alan Krempler:
  1293 Welche RICHTIGEN Formeln koennen NICHT abgeleitet werden, 
  1294 wenn Abteilungen nur auf gleichem Level gesucht werden ?
  1295 WN.040216 
  1296 
  1297 Beispiele zum Equationsolver von Richard Lang aus /src/sml/kbtest/rlang.sml
  1298 
  1299 ------------------------------------------------------------------------------
  1300 "Schalk I s.87 Bsp 52a ((5*x)/(x - 2) - x/(x+2)=4)";
  1301 ------------------------------------------------------------------------------
  1302 1. "5 * x / (x - 2) - x / (x + 2) = 4"
  1303 ...
  1304 4. "12 * x + 4 * x ^^^ 2 = 4 * (-4 + x ^^^ 2)",Subproblem["normalise", "poly"..
  1305 ...
  1306 4.3. "16 + 12 * x = 0", Subproblem["degree_1", "polynomial", "univariate"..
  1307 ...
  1308 4.3.3. "[x = -4 / 3]")), Check_elementwise "Assumptions"
  1309 ...
  1310 "[x = -4 / 3]"
  1311 ------------------------------------------------------------------------------
  1312 (1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
  1313 
  1314 (4.1)..(4.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
  1315 ------------------------------------------------------------------------------
  1316 
  1317 
  1318 ------------------------------------------------------------------------------
  1319 "Schalk I s.87 Bsp 55b (x/(x^^^2 - 6*x+9) - 1/(x^^^2 - 3*x) =1/x)";
  1320 ------------------------------------------------------------------------------
  1321 1. "x / (x ^^^ 2 - 6 * x + 9) - 1 / (x ^^^ 2 - 3 * x) = 1 / x"
  1322 ...
  1323 4. "(3 + (-1 * x + x ^^^ 2)) * x = 1 * (9 * x + (x ^^^ 3 + -6 * x ^^^ 2))"
  1324                          Subproblem["normalise", "polynomial", "univariate"..
  1325 ...
  1326 4.4. "-6 * x + 5 * x ^^^ 2 = 0", Subproblem["bdv_only", "degree_2", "poly"..
  1327 ...
  1328 4.4.4. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
  1329 4.4.5. "[x = 0, x = 6 / 5]"
  1330 ...
  1331 5. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
  1332    "[x = 6 / 5]"
  1333 ------------------------------------------------------------------------------
  1334 (1)..(4): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite schiebt [Ableitung waere in 4.4.x]
  1335 
  1336 (4.1)..(4.4.5): keine 'richtige' Eingabe kann abgeleitet werden, die dem Ergebnis "[x = 6 / 5]" aequivalent ist [Ableitung waere in 5.]
  1337 ------------------------------------------------------------------------------
  1338 
  1339 
  1340 ------------------------------------------------------------------------------
  1341 "Schalk II s.56 Bsp 73b (sqrt(x+1)+sqrt(4*x+4)=sqrt(9*x+9))";
  1342 ------------------------------------------------------------------------------
  1343 1. "sqrt (x + 1) + sqrt (4 * x + 4) = sqrt (9 * x + 9)"
  1344 ...
  1345 6. "13 + 13 * x + -2 * sqrt ((4 + 4 * x) * (9 + 9 * x)) = 1 + x"
  1346                              Subproblem["sq", "rootX", "univariate", "equation"]
  1347 ...
  1348 6.6. "144 + 288 * x + 144 * x ^^^ 2 = 144 + x ^^^ 2 + 288 * x + 143 * x ^^^ 2"
  1349                 Subproblem["normalise", "polynomial", "univariate", "equation"]
  1350 ...
  1351 6.6.3 "0 = 0"    Subproblem["degree_0", "polynomial", "univariate", "equation"]
  1352 ...                                       Or_to_List
  1353 6.6.3.2 "UniversalList"
  1354 ------------------------------------------------------------------------------
  1355 (1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die eine der Wurzeln auf die andere Seite verschieb [Ableitung ware in 6.6.n]
  1356 
  1357 (6.1)..(6.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 6.6.n]
  1358 ------------------------------------------------------------------------------
  1359 *)
  1360 (*sh. comments auf 498*)
  1361 "--------- fun dropwhile' ----------------------------------------";
  1362 "--------- fun dropwhile' ----------------------------------------";
  1363 "--------- fun dropwhile' ----------------------------------------";
  1364 (*
  1365  fun equal a b = a=b;
  1366  val foder = [0,1,2,3,4,5]; val ifoder = [11,12,3,4,5];
  1367  val r_foder = rev foder;  val r_ifoder = rev ifoder;
  1368  dropwhile' equal r_foder r_ifoder;
  1369 > vval it = ([0, 1, 2, 3], [3, 12, 11]) : int list * int list
  1370 
  1371  val foder = [3,4,5]; val ifoder = [11,12,3,4,5];
  1372  val r_foder = rev foder;  val r_ifoder = rev ifoder;
  1373  dropwhile' equal r_foder r_ifoder;
  1374 > val it = ([3], [3, 12, 11]) : int list * int list
  1375 
  1376  val foder = [5]; val ifoder = [11,12,3,4,5];
  1377  val r_foder = rev foder;  val r_ifoder = rev ifoder;
  1378  dropwhile' equal r_foder r_ifoder;
  1379 > val it = ([5], [5, 4, 3, 12, 11]) : int list * int list
  1380 
  1381  val foder = [10,11,12,13,14,15]; val ifoder = [11,12,3,4,5];
  1382  val r_foder = rev foder;  val r_ifoder = rev ifoder;
  1383  dropwhile' equal r_foder r_ifoder;
  1384 > *** dropwhile': did not start with equal elements*)