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