test/Tools/isac/Interpret/error-pattern.sml
author wneuper <Walther.Neuper@jku.at>
Mon, 01 Jan 2024 11:31:16 +0100
changeset 60789 8fa678b678e8
parent 60782 e797d1bdfe37
permissions -rw-r--r--
Doc/Specify_Phase 4: start use antiquotations from isar-ref
     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 @{context}) sc;
    53  val Prog sc = (#program o MethodC.from_store ctxt) ["Test", "solve_linear"];
    54  (writeln o UnparseC.term @{context}) 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 @{context} (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 @{context} (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 		       (ParseC.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 		       (ParseC.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 @{context} (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 @{context} (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 @{context} (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 @{context} (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 @{context} (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 @{context} 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 @{context} 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 @{context} 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 Inner syntax error: unexpected end of input
   463                                    Failed to parse term *)
   464  val ((pt,_),_) = States.get_calc 1;
   465  val str = pr_ctree ctxt pr_short pt;
   466  writeln str;
   467  if str = ".    ----- pblobj -----\n1.   x + 1 = 2\n" then ()
   468  else error "inform.sml: diff.behav.appendFormula: syntax error";
   469 DEconstrCalcTree 1;
   470 
   471 (*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
   472 "--------- CAS-command on ([],Pbl) -------------------------------";
   473 "--------- CAS-command on ([],Pbl) -------------------------------";
   474 "--------- CAS-command on ([],Pbl) -------------------------------";
   475 val (p,_,f,nxt,_,pt) = 
   476     Test_Code.init_calc @{context} [([], References.empty)];
   477 val ifo = "solve(x+1=2,x)";
   478 val (_,(_,c,(pt,p))) = Step_Solve.by_term (pt,p) "solve(x+1=2,x)";
   479 ( *
   480   This trick           \<up> \<up> \<up> micked input of \<up> \<up> \<up> \<up>  \<up> ^^ in the front-end.
   481   The trick worked in changeset fbaff8cf0179, it does not work in 59c5dd27d589 anymore
   482   (TODO hg bisect ?) and raises the ERROR Undefined fact: "xfoldr_Nil".
   483 
   484   Compare tests "CAS-command" in test/../inssort.sml etc.
   485   ---------------------------------------------------------------------------------------------
   486 Test_Tool.show_pt pt;
   487 val nxt = (Apply_Method ["Test", "squ-equ-test-subpbl1"]);
   488 val (p,_,f,nxt,_,pt) = me nxt p [] pt;
   489 if p = ([1], Frm) andalso f2str f = "x + 1 = 2" then ()
   490 else error "inform.sml: diff.behav. CAScmd ([],Pbl)";
   491 DEconstrCalcTree 1;
   492 -----------------------------------------------------------------------------------------------*)
   493 
   494 (*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
   495 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   496 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   497 "--------- CAS-command on ([],Pbl) FE-interface ------------------";
   498 States.reset ();
   499 CalcTree @{context} [([], References.empty)];
   500 Iterator 1;
   501 moveActiveRoot 1;
   502 replaceFormula 1 "solve(x+1=2,x)";
   503 autoCalculate 1 CompleteCalc;
   504 val ((pt,p),_) = States.get_calc 1;
   505 Test_Tool.show_pt pt;
   506 if p = ([], Res) then ()
   507 else error "inform.sml: diff.behav. CAScmd ([],Pbl) FE-interface";
   508 DEconstrCalcTree 1;
   509 -----------------------------------------------------------------------------------------------*)
   510 
   511 "--------- inform [rational,simplification] ----------------------";
   512 "--------- inform [rational,simplification] ----------------------";
   513 "--------- inform [rational,simplification] ----------------------";
   514 States.reset ();
   515 CalcTree @{context} [(["Term (a * x / (b * x) + c * x / (d * x) + e / f)", "normalform N"],
   516 	("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
   517 Iterator 1; moveActiveRoot 1;
   518 autoCalculate 1 CompleteCalcHead;
   519 
   520 "--- (- 1) give a preview on the calculation without any input";
   521 (*
   522 autoCalculate 1 CompleteCalc;
   523 val ((pt, p), _) = States.get_calc 1;
   524 Test_Tool.show_pt pt;
   525 [
   526 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   527 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   528 (([1], Res), a / b + c / d + e / f),                             <--- (1) input arbitrary
   529 (([2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   530 (([3], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
   531 (([4], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)), <--- (2) input next
   532 (([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))]  <--- (3) is also final result
   533                                                                           EXAMPLE NOT OPTIMAL
   534 *)
   535 "--- (0) user input as the *first* step does not work, thus impdo at least 1 step";
   536 autoCalculate 1 (Steps 1);
   537 autoCalculate 1 (Steps 1);
   538 val ((pt, p), _) = States.get_calc 1;
   539 (*Test_Tool.show_pt pt;
   540 [
   541 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   542 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   543 (([1], Res), a / b + c / d + e / f)] 
   544 *)
   545 "--- (1) input an arbitrary next formula";
   546 appendFormula 1 "((a * d) + (c * b)) / (b * d) + e / f" (*|> Future.join*);
   547 val ((pt, p), _) = States.get_calc 1;
   548 (*Test_Tool.show_pt pt;
   549 [
   550 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   551 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   552 (([1], Res), a / b + c / d + e / f),
   553 (([2,1], Frm), a / b + c / d + e / f),
   554 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   555 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
   556 (([2], Res), (a * d + c * b) / (b * d) + e / f)] 
   557 *)
   558 val ((pt,p),_) = States.get_calc 1;
   559 if p = ([2], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   560 else error ("inform.sml: [rational,simplification] 1");
   561 
   562 "--- (2) input the next formula that would be presented by mat-engine";
   563 (* generate a preview:
   564 autoCalculate 1 (Steps 1);
   565 val ((pt, p), _) = States.get_calc 1;
   566 Test_Tool.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))]   <--- input this
   576 *)
   577 appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
   578 val ((pt, p), _) = States.get_calc 1;
   579 (*Test_Tool.show_pt pt;
   580 [
   581 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   582 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   583 (([1], Res), a / b + c / d + e / f),
   584 (([2,1], Frm), a / b + c / d + e / f),
   585 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   586 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
   587 (([2], Res), (a * d + c * b) / (b * d) + e / f),
   588 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] 
   589 *)
   590 if p = ([3], Res) andalso (length o children o (get_nd pt)) (fst p) = 0 then ()
   591 else error ("inform.sml: [rational,simplification] 2");
   592 
   593 "--- (3) input the exact final result";
   594 appendFormula 1 "(b * d * e + b * c * f + a * d * f) / (b * d * f)" (*|> Future.join*);
   595 val ((pt, p), _) = States.get_calc 1;
   596 (*Test_Tool.show_pt pt;
   597 [
   598 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   599 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   600 (([1], Res), a / b + c / d + e / f),
   601 (([2,1], Frm), a / b + c / d + e / f),
   602 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   603 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
   604 (([2], Res), (a * d + c * b) / (b * d) + e / f),
   605 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   606 (([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   607 (([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
   608 (([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   609 (([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f))] 
   610 *)
   611 if p = ([4], Res) andalso (length o children o (get_nd pt)) (fst p) = 2 then ()
   612 else error ("inform.sml: [rational,simplification] 3");
   613 
   614 "--- (4) finish the calculation + check the postcondition (in the future)";
   615 autoCalculate 1 CompleteCalc;
   616 val ((pt, p), _) = States.get_calc 1;
   617 val (t, asm) = get_obj g_result pt [];
   618 if UnparseC.term @{context} t = "(a * d * f + b * c * f + b * d * e) / (b * d * f)" andalso
   619 UnparseC.terms @{context} asm =(*"[\"b * d * f \<noteq> 0\",\"d \<noteq> 0\",\"b \<noteq> 0\",\"a * x / (b * x) + c * x / (d * x) + e / f is_ratpolyexp\"]"*)
   620                     "[]" (*..found broken in child of 33913fe24685, error covered by  CAS-command *)
   621 then () else error "inform [rational,simplification] changed at end";
   622 (*Test_Tool.show_pt pt;
   623 [
   624 (([], Frm), Simplify (a * x / (b * x) + c * x / (d * x) + e / f)),
   625 (([1], Frm), a * x / (b * x) + c * x / (d * x) + e / f),
   626 (([1], Res), a / b + c / d + e / f),
   627 (([2,1], Frm), a / b + c / d + e / f),
   628 (([2,1], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   629 (([2,2], Res), (a * d + c * b) / (b * d) + e / f),
   630 (([2], Res), (a * d + c * b) / (b * d) + e / f),
   631 (([3], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   632 (([4,1], Frm), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   633 (([4,1], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
   634 (([4,2], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   635 (([4], Res), (b * d * e + b * c * f + a * d * f) / (b * d * f)),
   636 (([5], Res), (a * (d * f) + b * (c * f) + b * (d * e)) / (b * (d * f))),
   637 (([6], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f)),
   638 (([], Res), (a * d * f + b * c * f + b * d * e) / (b * d * f))] 
   639 *)
   640 DEconstrCalcTree 1;
   641 
   642 (*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
   643 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   644 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   645 "--------- Take as 1st tac, start with <NEW> (CAS input) ---------";
   646 val t = ParseC.parse_test @{context} "Diff (x \<up> 2 + x + 1, x)";
   647 case t of Const (\<^const_name>\<open>Diff\<close>, _) $ _ => ()
   648 	| _ => raise 
   649 	      error "diff.sml behav.changed for CAS Diff (..., x)";
   650 TermC.atom_trace_detail @{context} t;
   651 "-----------------------------------------------------------------";
   652 (*1>*)States.reset ();
   653 (*2>*)CalcTree @{context} [([], References.empty)];
   654 (*3>*)Iterator 1;moveActiveRoot 1;
   655 "----- here the Headline has been finished";
   656 (*4>*)moveActiveFormula 1 ([],Pbl);
   657 (*5>*)replaceFormula 1 "Diff (x \<up> 2 + x + 1, x)";
   658 val ((pt,_),_) = States.get_calc 1;
   659 val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
   660 val (SOME istate, NONE) = loc;
   661 (*default_print_depth 5;*)
   662 writeln"-----------------------------------------------------------";
   663 spec;
   664 writeln (I_Model.to_string ctxt probl);
   665 writeln (I_Model.to_string ctxt meth);
   666 writeln (Istate.string_of ctxt (fst istate));
   667 
   668 refFormula 1 ([],Pbl) (*--> correct CalcHead*);
   669  (*081016 NOT necessary (but leave it in Java):*)
   670 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
   671 "----- here the CalcHead has been completed --- ONCE MORE ?????";
   672 
   673 (**difference II**)
   674 val ((pt,p),_) = States.get_calc 1;
   675 (*val p = ([], Pbl)*)
   676 val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
   677 val (SOME istate, NONE) = loc;
   678 (*default_print_depth 5;*) writeln (Istate.string_of ctxt (fst istate));  (*default_print_depth 3;*)
   679 (*Pstate ([],
   680  [], NONE,
   681  ??.empty, Sundef, false)*)
   682 (*default_print_depth 5;*) spec; (*default_print_depth 3;*)
   683 (*("Isac_Knowledge",
   684       ["derivative_of", "function"],
   685       ["diff", "differentiate_on_R"]) : spec*)
   686 writeln (I_Model.to_string ctxt probl);
   687 (*[
   688 (1 ,[1] ,true ,#Given ,Cor functionTerm (x \<up> 2 + x + 1) ,(f_, [x \<up> 2 + x + 1])),
   689 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   690 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   691 writeln (I_Model.to_string ctxt meth);
   692 (*[
   693 (1 ,[1] ,true ,#Given ,Cor functionTerm (x \<up> 2 + x + 1) ,(f_, [x \<up> 2 + x + 1])),
   694 (2 ,[1] ,true ,#Given ,Cor differentiateFor x ,(v_, [x])),
   695 (3 ,[1] ,true ,#Find ,Cor derivative f_'_f ,(f_'_f, [f_'_f]))]*)
   696 writeln"-----------------------------------------------------------";
   697 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   698 (*WN081028 fixed <ERROR> helpless </ERROR> by inform returning ...(.,Met)*)
   699 autoCalculate 1 CompleteCalc;
   700 val ((pt,p),_) = States.get_calc 1;
   701 val Form res = (#1 o ME_Misc.pt_extract) (pt, ([],Res));
   702 Test_Tool.show_pt pt;
   703 
   704 if p = ([], Res) andalso UnparseC.term @{context} res = "1 + 2 * x" then ()
   705 else error "diff.sml behav.changed for Diff (x \<up> 2 + x + 1, x)";
   706 DEconstrCalcTree 1;
   707 -----------------------------------------------------------------------------------------------*)
   708 
   709 "--------- Take as 1st tac, start from exp -----------------------";
   710 "--------- Take as 1st tac, start from exp -----------------------";
   711 "--------- Take as 1st tac, start from exp -----------------------";
   712 (*the following input is copied from BridgeLog Java <==> SML,
   713   omitting unnecessary inputs*)
   714 (*1>*)States.reset ();
   715 (*2>*)CalcTree @{context} [(["functionTerm (x \<up> 2 + x + 1)", "differentiateFor x", "derivative f_'_f"],("Isac_Knowledge",["derivative_of", "function"],["diff", "differentiate_on_R"]))];
   716 (*3>*)Iterator 1; moveActiveRoot 1;
   717 
   718 (*6>*)(*completeCalcHead*)autoCalculate 1 CompleteCalcHead;
   719 (**difference II**)
   720 val ((pt,_),_) = States.get_calc 1;
   721 val PblObj {probl, meth, spec, fmz, loc, ...} = get_obj I pt [];
   722 val (SOME istate, NONE) = loc;
   723 
   724 val "Pstate ([], [], empty, NONE, \n??.empty, ORundef, false, false)"
   725  = fst istate |> Istate.string_of ctxt
   726 val ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]) = spec;
   727 val "[\n(1, [1], true ,#Given, (Cor functionTerm (x \<up> 2 + x + 1) , pen2str, Position.T)), \n(2, [1], true ,#Given, (Cor differentiateFor x , pen2str, Position.T)), \n(3, [1], true ,#Find, (Cor derivative f_'_f , pen2str, Position.T))]"
   728  = probl |> I_Model.to_string ctxt
   729 val "[\n(1, [1], true ,#Given, (Cor functionTerm (x \<up> 2 + x + 1) , pen2str, Position.T)), \n(2, [1], true ,#Given, (Cor differentiateFor x , pen2str, Position.T)), \n(3, [1], true ,#Find, (Cor derivative f_'_f , pen2str, Position.T))]"
   730  = meth |> I_Model.to_string ctxt;
   731 
   732 (*7>*)fetchProposedTactic 1 (*--> Apply_Method*);
   733 autoCalculate 1 (Steps 1);
   734 val ((pt,p),_) = States.get_calc 1;
   735 val Form res = (#1 o (ME_Misc.pt_extract ctxt)) (pt, p);
   736 if UnparseC.term @{context} res = "d_d x (x \<up> 2 + x + 1)" then ()
   737 else error "diff.sml Diff (x \<up> 2 + x + 1, x) from exp";
   738 DEconstrCalcTree 1;
   739 
   740 (*POSTPONE CORRECTION AT END OF TRANSITION TO Isabelle/PIDE/Isac (~ Cas_Cmd)
   741 "--------- implicit_take, start with <NEW> (CAS input) ---------------";
   742 "--------- implicit_take, start with <NEW> (CAS input) ---------------";
   743 "--------- implicit_take, start with <NEW> (CAS input) ---------------";
   744 States.reset ();
   745 CalcTree @{context} [([], References.empty)];
   746 (*[[from sml: > @@@@@begin@@@@@
   747 [[from sml:  1 
   748 [[from sml: <CALCTREE>
   749 [[from sml:    <CALCID> 1 </CALCID>
   750 [[from sml: </CALCTREE>
   751 [[from sml: @@@@@end@@@@@*)
   752 Iterator 1;
   753 (*[[from sml: > @@@@@begin@@@@@
   754 [[from sml:  1 
   755 [[from sml: <ADDUSER>
   756 [[from sml:   <CALCID> 1 </CALCID>
   757 [[from sml:   <USERID> 1 </USERID>
   758 [[from sml: </ADDUSER>
   759 [[from sml: @@@@@end@@@@@*)
   760 moveActiveRoot 1;
   761 (*[[from sml: > @@@@@begin@@@@@
   762 [[from sml:  1 
   763 [[from sml: <CALCITERATOR>
   764 [[from sml:   <CALCID> 1 </CALCID>
   765 [[from sml:   <POSITION>
   766 [[from sml:     <INTLIST>
   767 [[from sml:     </INTLIST>
   768 [[from sml:     <POS> Pbl </POS>
   769 [[from sml:   </POSITION>
   770 [[from sml: </CALCITERATOR>
   771 [[from sml: @@@@@end@@@@@*)
   772 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false;
   773 (*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
   774 [[from sml:  1 
   775 [[from sml: <GETELEMENTSFROMTO>
   776 [[from sml:   <CALCID> 1 </CALCID>
   777 [[from sml:   <FORMHEADS>
   778 [[from sml:     <CALCFORMULA>
   779 [[from sml:       <POSITION>
   780 [[from sml:         <INTLIST>
   781 [[from sml:         </INTLIST>
   782 [[from sml:         <POS> Pbl </POS>
   783 [[from sml:       </POSITION>
   784 [[from sml:       <FORMULA>
   785 [[from sml:         <MATHML>
   786 [[from sml:           <ISA> ________________________________________________ </ISA>
   787 [[from sml:         </MATHML>
   788 [[from sml: 
   789 [[from sml:       </FORMULA>
   790 [[from sml:     </CALCFORMULA>
   791 [[from sml:   </FORMHEADS>
   792 [[from sml: </GETELEMENTSFROMTO>
   793 [[from sml: @@@@@end@@@@@*)
   794 refFormula 1 ([],Pbl);
   795 (*[[from sml: > @@@@@begin@@@@@                STILL CORRECT
   796 [[from sml:  1 
   797 [[from sml: <REFFORMULA>
   798 [[from sml:   <CALCID> 1 </CALCID>
   799 [[from sml:   <CALCHEAD status = "incorrect">
   800 [[from sml:     <POSITION>
   801 [[from sml:       <INTLIST>
   802 [[from sml:       </INTLIST>
   803 [[from sml:       <POS> Pbl </POS>
   804 [[from sml:     </POSITION>
   805 [[from sml:     <HEAD>
   806 [[from sml:       <MATHML>
   807 [[from sml:         <ISA> Problem (ThyC.id_empty, [e_pblID]) </ISA>
   808 [[from sml:       </MATHML>
   809 [[from sml:     </HEAD>
   810 [[from sml:     <MODEL>
   811 [[from sml:       <GIVEN>  </GIVEN>
   812 [[from sml:       <WHERE>  </WHERE>
   813 [[from sml:       <FIND>  </FIND>
   814 [[from sml:       <RELATE>  </RELATE>
   815 [[from sml:     </MODEL>
   816 [[from sml:     <BELONGSTO> Pbl </BELONGSTO>
   817 [[from sml:     <SPECIFICATION>
   818 [[from sml:       <THEORYID> ThyC.id_empty </THEORYID>
   819 [[from sml:       <PROBLEMID>
   820 [[from sml:         <STRINGLIST>
   821 [[from sml:           <STRING> Problem.id_empty </STRING>
   822 [[from sml:         </STRINGLIST>
   823 [[from sml:       </PROBLEMID>
   824 [[from sml:       <METHODID>
   825 [[from sml:         <STRINGLIST>
   826 [[from sml:           <STRING> e_metID </STRING>
   827 [[from sml:         </STRINGLIST>
   828 [[from sml:       </METHODID>
   829 [[from sml:     </SPECIFICATION>
   830 [[from sml:   </CALCHEAD>
   831 [[from sml: </REFFORMULA>
   832 [[from sml: @@@@@end@@@@@*)
   833 moveActiveFormula 1 ([],Pbl);
   834 (*[[from sml: > @@@@@begin@@@@@
   835 [[from sml:  1 
   836 [[from sml: <CALCITERATOR>
   837 [[from sml:   <CALCID> 1 </CALCID>
   838 [[from sml:   <POSITION>
   839 [[from sml:     <INTLIST>
   840 [[from sml:     </INTLIST>
   841 [[from sml:     <POS> Pbl </POS>
   842 [[from sml:   </POSITION>
   843 [[from sml: </CALCITERATOR>
   844 [[from sml: @@@@@end@@@@@*)
   845 replaceFormula 1 "Simplify (1+2)";
   846 (*[[from sml: > @@@@@begin@@@@@
   847 [[from sml:  1 
   848 [[from sml: <REPLACEFORMULA>
   849 [[from sml:   <CALCID> 1 </CALCID>
   850 [[from sml:   <CALCCHANGED>
   851 [[from sml:     <UNCHANGED>
   852 [[from sml:       <INTLIST>
   853 [[from sml:       </INTLIST>
   854 [[from sml:       <POS> Pbl </POS>
   855 [[from sml:     </UNCHANGED>
   856 [[from sml:     <DELETED>
   857 [[from sml:       <INTLIST>
   858 [[from sml:       </INTLIST>
   859 [[from sml:       <POS> Pbl </POS>
   860 [[from sml:     </DELETED>
   861 [[from sml:     <GENERATED>
   862 [[from sml:       <INTLIST>
   863 [[from sml:       </INTLIST>
   864 [[from sml:       <POS> Met </POS>                           DIFFERENCE: Pbl
   865 [[from sml:     </GENERATED>
   866 [[from sml:   </CALCCHANGED>
   867 [[from sml: </REPLACEFORMULA>
   868 [[from sml: @@@@@end@@@@@*)
   869 getFormulaeFromTo 1 ([],Pbl) ([],Pbl) 0 false(*              DIFFERENCE: Pbl*);
   870 (*@@@@@begin@@@@@
   871  1
   872 <GETELEMENTSFROMTO>
   873   <CALCID> 1 </CALCID>
   874   <FORMHEADS>
   875     <CALCFORMULA>
   876       <POSITION>
   877         <INTLIST>
   878         </INTLIST>
   879         <POS> Pbl </POS>
   880       </POSITION>
   881       <FORMULA>
   882         <MATHML>
   883           <ISA> Simplify (1 + 2) </ISA>                      WORKS !!!!!
   884         </MATHML>
   885       </FORMULA>
   886     </CALCFORMULA>
   887   </FORMHEADS>
   888 </GETELEMENTSFROMTO>
   889 @@@@@end@@@@@*)
   890 getFormulaeFromTo 1 ([],Pbl) ([],Met) 0 false;
   891 (*[[from sml: > @@@@@begin@@@@@
   892 [[from sml:  1 
   893 [[from sml: <SYSERROR>
   894 [[from sml:   <CALCID> 1 </CALCID>
   895 [[from sml:   <ERROR> error in getFormulaeFromTo </ERROR>
   896 [[from sml: </SYSERROR>
   897 [[from sml: @@@@@end@@@@@*)
   898 (*step into getFormulaeFromTo --- bug corrected...*)
   899 -----------------------------------------------------------------------------------------------*)
   900 
   901 "--------- build fun check_for' ------------------------------";
   902 "--------- build fun check_for' ------------------------------";
   903 "--------- build fun check_for' ------------------------------";
   904 val subst = [(ParseC.parse_test @{context} "bdv", ParseC.parse_test @{context} "x")]: subst;
   905 val rls = norm_Rational
   906 val SOME pat = ParseC.patt_opt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
   907 val (res, inf) = (ParseC.parse_test @{context} "(2 + 3)/(3 + 4)", ParseC.parse_test @{context} "2 / 4");
   908 val (res, inf) = (ParseC.parse_test @{context} "(2 + 3)/(3 + 4)", ParseC.parse_test @{context} "1 / 2");
   909 
   910 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern TermC.matches in res*)
   911   rew_sub ctxt 1 [] Rewrite_Ord.function_empty Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
   912 if rewritten then NONE else SOME "e_errpatID";
   913 
   914 val norm_res = case rewrite_set_ ctxt false rls res' of
   915   NONE => res'
   916 | SOME (norm_res, _) => norm_res
   917 
   918 val norm_inf = case rewrite_set_ ctxt false rls inf of
   919   NONE => inf
   920 | SOME (norm_inf, _) => norm_inf;
   921 
   922 res' = inf;
   923 norm_res = norm_inf;
   924 
   925 val SOME pat = ParseC.patt_opt @{theory} "(?a + ?b)/?a = ?b";
   926 val (res, inf) = (ParseC.parse_test @{context} "(2 + 3)/2", ParseC.parse_test @{context} "3");
   927 if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   928 then () else error "error patt example1 changed";
   929 
   930 val SOME pat = ParseC.patt_opt @{theory} "(?a + ?b)/(?a + ?c) = ?b / ?c";
   931 val (res, inf) = (ParseC.parse_test @{context} "(2 + 3)/(2 + 4)", ParseC.parse_test @{context} "3 / 4");
   932 if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   933 then () else error "error patt example2 changed";
   934 
   935 val SOME pat = ParseC.patt_opt @{theory} "(?a + ?b)/(?b + ?c) = ?a / ?c";
   936 val (res, inf) = (ParseC.parse_test @{context} "(2 + 3)/(3 + 4)", ParseC.parse_test @{context} "2 / 4");
   937 if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   938 then () else error "error patt example3 changed";
   939 
   940 val inf =  ParseC.parse_test @{context} "1 / 2";
   941 if check_for' ctxt (res, inf) subst ("errpatID", pat) rls = SOME "errpatID"
   942 then () else error "error patt example3 changed";
   943 
   944 "--------- build fun check_for' ?bdv -------------------------";
   945 "--------- build fun check_for' ?bdv -------------------------";
   946 "--------- build fun check_for' ?bdv -------------------------";
   947 val ctxt = Proof_Context.init_global @{theory}
   948 val subst = [(ParseC.parse_test @{context} "bdv", ParseC.parse_test @{context} "x")]: subst;
   949 val t = ParseC.parse_test @{context} "d_d x (x \<up> 2 + sin (x \<up> 4))";
   950 val SOME (t, _) = rewrite_set_inst_ ctxt false subst norm_diff t;
   951 if UnparseC.term @{context} t = "2 * x + cos (x \<up> 4) * 4 * x \<up> 3" then ()
   952 else error "build fun check_for' ?bdv changed 1"; 
   953 
   954 val rls = norm_diff
   955 val SOME pat = ParseC.patt_opt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)"; 
   956 val (res, inf) = (ParseC.parse_test @{context} "2 * x + d_d x (sin (x \<up> 4))", ParseC.parse_test @{context} "2 * x + cos (4 * x \<up> 3)");
   957 
   958 val (res', _, _, rewritten) = (*rewritten: the lhs of the pattern TermC.matches in res*)
   959   rew_sub ctxt 1 subst Rewrite_Ord.function_empty Rule_Set.empty false [] (HOLogic.Trueprop $ pat) res;
   960 if UnparseC.term @{context} res' = "2 * x + cos (d_d x (x \<up> 4))" andalso rewritten then ()
   961 else error "build fun check_for' ?bdv changed 2";
   962 
   963 val norm_res = case rewrite_set_inst_ ctxt false subst rls  res' of
   964   NONE => res'
   965 | SOME (norm_res, _) => norm_res;
   966 if UnparseC.term @{context} norm_res = "2 * x + cos (4 * x \<up> 3)" then ()
   967 else error "build fun check_for' ?bdv changed 3";
   968 
   969 val norm_inf = case rewrite_set_inst_ ctxt false subst rls inf of
   970   NONE => inf
   971 | SOME (norm_inf, _) => norm_inf;
   972 if UnparseC.term @{context} norm_inf = "2 * x + cos (4 * x \<up> 3)" then ()
   973 else error "build fun check_for' ?bdv changed 4";
   974 
   975 res' = inf;
   976 if norm_res = norm_inf then ()
   977 else error "build fun check_for' ?bdv changed 5";
   978 
   979 if Error_Pattern.check_for' ctxt (res, inf) (subst: subst) ("errpatID": Error_Pattern.id, pat) rls = SOME "errpatID"
   980 then () else error "error patt example1 changed";
   981 
   982 "--------- build fun check_for ------------------------";
   983 "--------- build fun check_for ------------------------";
   984 "--------- build fun check_for ------------------------";
   985 val (res, inf) =
   986   (ParseC.parse_test @{context} "d_d x (x \<up> 2) + d_d x (sin (x \<up>  4))",
   987    ParseC.parse_test @{context} "d_d x (x \<up> 2) + cos (4 * x \<up> 3)");
   988 val {errpats, rew_rls = rls, program = Prog prog, ...} = MethodC.from_store ctxt ["diff", "differentiate_on_R"]
   989 
   990 val env = [(ParseC.parse_test @{context} "v_v", ParseC.parse_test @{context} "x")];
   991 val errpats =
   992   [Error_Pattern.empty, (*generalised for testing*)
   993    ("chain-rule-diff-both",
   994      [ParseC.patt_opt @{theory} "d_d ?bdv (sin ?u) = cos (d_d ?bdv ?u)" |> the,
   995       ParseC.patt_opt @{theory} "d_d ?bdv (cos ?u) = - sin (d_d ?bdv ?u)" |> the,
   996       ParseC.patt_opt @{theory} "d_d ?bdv (?u \<up> ?n) = ?n * ?u \<up> (?n - 1)" |> the,
   997       ParseC.patt_opt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / ?u" |> the,
   998       ParseC.patt_opt @{theory} "d_d ?bdv (LogExp.ln ?u) = 1 / d_d ?bdv ?u" |> the],
   999      [@{thm diff_sin_chain}, @{thm diff_cos_chain}, @{thm diff_pow_chain}, 
  1000       @{thm diff_ln_chain}, @{thm  diff_exp_chain}])];
  1001 case Error_Pattern.check_for ctxt (res, inf) (prog, env) (errpats, rls) of SOME _ => () 
  1002 | NONE => error "Error_Pattern.check_for broken";
  1003 DEconstrCalcTree 1;
  1004 
  1005 "--------- embed fun check_for ------------------------";
  1006 "--------- embed fun check_for ------------------------";
  1007 "--------- embed fun check_for ------------------------";
  1008 States.reset ();     
  1009 CalcTree @{context}
  1010 [(["functionTerm (x \<up> 2 + sin (x \<up> 4))", "differentiateFor x", "derivative f_f'"], 
  1011   ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]))];
  1012 Iterator 1;
  1013 moveActiveRoot 1;
  1014 autoCalculate 1 CompleteCalcHead;
  1015 autoCalculate 1 (Steps 1);
  1016 autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))*)
  1017 (*autoCalculate 1 (Steps 1);([2], Res), d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x (x \<up> \<up>  4)*)
  1018 
  1019 "~~~~~ fun appendFormula , args:"; val (cI, (ifo:TermC.as_string)) = (1, "d_d x (x \<up> 2) + cos (4 * x \<up> 3)");
  1020 "~~~~~ fun appendFormula' , args:"; val (cI, (ifo: TermC.as_string)) = (cI, ifo);
  1021     val cs = States.get_calc cI
  1022     val pos = States.get_pos cI 1;
  1023 (*+*)if pos = ([1], Res) then () else error "inform with (positive) Error_Pattern.check_for broken 1";
  1024     val ("ok", cs' as (_, _, ptp)) = (*case*) Step.do_next pos cs (*of*);
  1025       (*case*) Step_Solve.by_term ptp (encode ifo) (*of*); (*ERROR WAS: "no derivation found"*)
  1026 "~~~~~ fun Step_Solve.by_term , args:"; val (((*next_*)cs as (_, _, (pt, pos as (p, _))): Calc.state_post), istr)
  1027   = (cs', (encode ifo));
  1028     val ctxt = get_ctxt pt pos (*see TODO.thy*)
  1029     val SOME f_in = (*case*) ParseC.term_opt ctxt istr (*of*);
  1030         val pos_pred = lev_back' pos
  1031     	  val f_pred = Ctree.get_curr_formula (pt, pos_pred);
  1032         (*if*) f_pred = f_in; (*else*)
  1033           val NONE = (*case*) CAS_Cmd.input f_in (*of*);
  1034        (*old* )val (_, _, metID) = get_obj g_spec pt (par_pblobj pt p)
  1035        (*old*)val {program = prog, ...} = MethodC.from_store ctxt metID
  1036        (*old*)val istate = get_istate_LI pt pos
  1037        (*old*)val ctxt = get_ctxt pt pos
  1038        ( *old*)
  1039        val LI.Not_Derivable =
  1040              (*case*) LI.locate_input_term (pt, pos) f_in (*of*);
  1041                 val met_id = Ctree.get_obj Ctree.g_metID pt (Ctree.par_pblobj pt p)
  1042             		  val (errpats, rew_rls, prog) = case MethodC.from_store' (Know_Store.get_via_last_thy "Build_Thydata") met_id of
  1043               		    {errpats, rew_rls, program = Rule.Prog prog, ...} => (errpats, rew_rls, prog)
  1044               		  | _ => error "inform: uncovered case of MethodC.from_store ctxt"
  1045 ;
  1046 (*+*)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\"]]"
  1047 (*+*)then () else error "inform with (positive) Error_Pattern.check_for broken 3";
  1048 
  1049             		  val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
  1050 ;
  1051 (*+*)if UnparseC.term @{context} f_pred = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" andalso
  1052 (*+*)   UnparseC.term @{context} f_in = "d_d x (x \<up> 2) + cos (4 * x \<up> 3)"
  1053 (*+*)then () else error "inform with (positive) Error_Pattern.check_for broken 2";
  1054 
  1055              val SOME "chain-rule-diff-both" = (*case*) Error_Pattern.check_for ctxt (f_pred, f_in) (prog, env) (errpats, rew_rls) (*of*);
  1056 
  1057 "--- final check:";
  1058 (*+*)val (_, _, ptp') = cs';
  1059 case Step_Solve.by_term ptp' (encode ifo) of
  1060   ("error pattern #chain-rule-diff-both#", calcstate') => ()
  1061 | _ => error "inform with (positive) Error_Pattern.check_for broken"
  1062 
  1063 
  1064 "----------- re-build: fill_from_store without thy-hierarchy -----------------------------------";
  1065 "----------- re-build: fill_from_store without thy-hierarchy -----------------------------------";
  1066 "----------- re-build: fill_from_store without thy-hierarchy -----------------------------------";
  1067 open Error_Pattern
  1068 val c = []: int list
  1069 val (p,_,f,nxt,_,pt) = Test_Code.init_calc @{context}
  1070 [(["functionTerm (x \<up> 2 + sin (x \<up> 4))", "differentiateFor x", "derivative f_f'"], 
  1071   ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]))];
  1072 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  1073 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  1074 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  1075 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  1076 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  1077 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  1078 val (p,_,f,nxt,_,pt) = me nxt p c pt; (*nxt = Apply_Method ["diff", "differentiate_on_R"]*)
  1079 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"))*)
  1080   val ([1], Frm) = p;
  1081   val "d_d x (x \<up> 2 + sin (x \<up> 4))" = f2str f;
  1082 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"))*)
  1083   val ([1], Res) = p;
  1084   val "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" = f2str f
  1085 
  1086 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)"))*)
  1087   val ([1], Res) = p
  1088   val "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" = f2str f;
  1089   (*  "d_d x (x \<up> 2) +        cos (x \<up> 4)" .. wrong user input within next step *)
  1090 (*//------------------ step into find_fill_patterns ----------------------------------------\\*)
  1091 (* INSTEAD OF STEPPING INTO me WE DO SO FOR Kernel.findFillpatterns cI errpatID =
  1092   let
  1093     val ((pt, _), _) = States.get_calc cI
  1094 		val pos = States.get_pos cI 1;
  1095 		val fillpats = Error_Pattern.find_fill_patterns (pt, pos) errpatID
  1096 *)
  1097 "~~~~~ fun findFillpatterns , args:"; val (pt, p, errpatID) = (pt, p, "chain-rule-diff-both");
  1098 "~~~~~ fun find_fill_patterns , args:"; val ((pt, pos as (p, _)), id) = ((pt, p), errpatID);
  1099 (*old-------\* )
  1100     val f_curr = Ctree.get_curr_formula (pt, pos);
  1101     val pp = Ctree.par_pblobj pt p
  1102     val (errpats, prog) = case MethodC.from_store ctxt (Ctree.get_obj Ctree.g_metID pt pp) of
  1103       {errpats, program = Rule.Prog prog, ...} => (errpats, prog)
  1104     | _ => error "find_fill_patterns: uncovered case of MethodC.from_store ctxt"
  1105 ( *new-------\*)
  1106     val ctxt = Ctree.get_ctxt pt pos
  1107     val f_curr = Ctree.get_curr_formula (pt, pos)
  1108     val met_id = Ctree.get_obj Ctree.g_metID pt (Ctree.par_pblobj pt p)
  1109     val (errpats, prog) = case MethodC.from_store' (Know_Store.get_via_last_thy "Build_Thydata") met_id of
  1110       {errpats, program = Rule.Prog prog, ...} => (errpats, prog)
  1111     | _ => error "find_fill_patterns: uncovered case of MethodC.from_store ctxt"
  1112 (*new-------/*)
  1113 
  1114 (*+*)val 1 = length errpats(*ONLY WITH from_store' @{theory (*!!!*)Build_Thydata}*)
  1115     val {env, ...} = Ctree.get_istate_LI pt pos |> Istate.the_pstate
  1116     val subst = Subst.for_bdv ctxt prog env
  1117     val errpatthms = errpats
  1118       |> filter ((curry op = errpatID) o (#1: Error_Pattern.T -> Error_Pattern.id))
  1119       |> map (#3: Error_Pattern.T -> thm list)
  1120       |> flat;
  1121 
  1122 (*+*)val 3 = length errpatthms;
  1123 (*+*)val 5 = length (get_fill_ins @{theory} "diff_sin_chain");
  1124 
  1125 (*case*) map (
  1126            fill_from_store ctxt subst f_curr errpatID) errpatthms |> flat (*of*);
  1127 "~~~~~ fun fill_from_store , args:"; val (ctxt, subst, form, (*id*)errpat_id, thm) =
  1128   (ctxt, subst, f_curr, errpatID, hd errpatthms);
  1129     val thm_id_long = Thm.get_name_hint thm
  1130 
  1131 (*+*)val "Diff.diff_sin_chain" = thm_id_long;
  1132 (*+*)val "diff_sin_chain" = ThmC.cut_longid thm_id_long;
  1133 
  1134     val thm_id = ThmC.cut_longid thm_id_long
  1135     val fill_ins =
  1136 
  1137 Error_Pattern.get_fill_ins (Proof_Context.theory_of ctxt) thm_id;
  1138 "~~~~~ fun get_fill_ins , args:"; val (thy, thm_id) =
  1139   ((Proof_Context.theory_of ctxt), thm_id);
  1140   (*case*) AList.lookup (op =) (get_fill_inss thy) thm_id (*of*);
  1141 val ERROR "fill_ins for thm \"diff_sin_chain\" missing in theory \"Isac_Knowledge\" (and ancestors)\nTODO exception hierarchy needs to be established." =
  1142   ERROR ("fill_ins for thm \"" ^ thm_id ^ "\" missing in theory \"" ^ 
  1143     (thy |> ThyC.id_of) ^ "\" (and ancestors)" ^
  1144     "\nTODO exception hierarchy needs to be established.");
  1145 
  1146 (*return to fill_from_store..*)
  1147     val some = map (fill_form ctxt subst (thm, form) errpat_id) fill_ins;
  1148 val return_fill_from_store = some |> filter is_some |> map the;
  1149 
  1150 (* final test ... ----------------------------------------------------------------------------*)
  1151 (*+*)if length return_fill_from_store = 5 then
  1152 (*+*)  case return_fill_from_store of
  1153 (*+*)    ("fill-d_d-arg", tm, thm, subsopt) :: _ => if UnparseC.term @{context} tm = 
  1154 (*+*)      "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"
  1155 (*+*)      then () else error "find_fill_patterns changed 2a"
  1156 (*+*)  | _ => error "find_fill_patterns changed 2b"
  1157 (*+*)else error "find_fill_patterns changed 2c";
  1158 (*-------------------- stop step into find_fill_patterns -------------------------------------*)
  1159 (*\\------------------ step into find_fill_patterns ----------------------------------------//*)
  1160 
  1161 val (p,_,f,nxt,_,pt) = return_of_me
  1162 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)"))*)
  1163   val ([3], Res) = p
  1164   val "d_d x (x \<up> 2) + cos (x \<up> 4) * (4 * x \<up> (4 - 1))" = f2str f;
  1165 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  1166 val (p,_,f,nxt,_,pt) = me nxt p c pt; (*nxt = Check_Postcond ["derivative_of", "function"]*)
  1167 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  1168   val ([], Res) = p;
  1169   val "2 * x + cos (x \<up> 4) * 4 * x \<up> 3" = f2str f
  1170   val End_Proof' = nxt;
  1171 
  1172 
  1173 "--------- embed fun find_fill_patterns ---------------------------";
  1174 "--------- embed fun find_fill_patterns ---------------------------";
  1175 "--------- embed fun find_fill_patterns ---------------------------";
  1176 States.reset ();
  1177 CalcTree @{context}
  1178 [(["functionTerm (x \<up> 2 + sin (x \<up> 4))", "differentiateFor x", "derivative f_f'"], 
  1179   ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]))];
  1180 Iterator 1;
  1181 moveActiveRoot 1;
  1182 autoCalculate 1 CompleteCalcHead;
  1183 autoCalculate 1 (Steps 1);
  1184 autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))*)
  1185 appendFormula 1 "d_d x (x \<up> 2) + cos (4 * x \<up> 3)";
  1186   (*<CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>*)
  1187   (*or
  1188     <CALCMESSAGE> no derivation found </CALCMESSAGE>*)
  1189 "~~~~~ fun findFillpatterns, args:"; val (cI, errpatID) = (1, "chain-rule-diff-both");
  1190   val ((pt, _), _) = States.get_calc cI
  1191 				val pos = States.get_pos cI 1;
  1192 
  1193 val return_from_find_fill_patterns = find_fill_patterns (pt, pos) errpatID;
  1194 DEconstrCalcTree 1;
  1195 
  1196 (* final test ... ----------------------------------------------------------------------------*)
  1197 val 6 = length return_from_find_fill_patterns
  1198 val (fill_in_id, term, thm, subst) :: _ = return_from_find_fill_patterns
  1199 
  1200 val "fill-d_d-arg" = fill_in_id
  1201 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" =
  1202   UnparseC.term @{context} term
  1203 val "Diff.diff_sin_chain" = Thm.get_name_hint thm
  1204 val "[(''bdv'', x)]" = subst |> the |> Subst.string_of_input;
  1205 
  1206 
  1207 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1208 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1209 "--------- build fun is_exactly_equal, inputFillFormula ----------";
  1210 States.reset ();
  1211 CalcTree @{context}
  1212 [(["functionTerm (x \<up> 2 + sin (x \<up> 4))", "differentiateFor x", "derivative f_f'"], 
  1213   ("Isac_Knowledge", ["derivative_of", "function"], ["diff", "differentiate_on_R"]))];
  1214 Iterator 1;
  1215 moveActiveRoot 1;
  1216 autoCalculate 1 CompleteCalcHead;
  1217 autoCalculate 1 (Steps 1);
  1218 autoCalculate 1 (Steps 1);(*([1], Res), d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))*)
  1219 appendFormula 1 "d_d x (x \<up> 2) + cos (4 * x \<up> 3)" (*|> Future.join*); (*<<<<<<<=========================*)
  1220 (* the check for errpat is maximally liberal (whole term modulo "rew_rls" from "type met"),
  1221   would recognize "cos (4 * x \<up> (4 - 1)) + 2 * x" as well.
  1222   results in <CALCMESSAGE> error pattern #chain-rule-diff-both# </CALCMESSAGE>
  1223   instead of <CALCMESSAGE> no derivation found </CALCMESSAGE> *)
  1224   val ((pt,pos), _) = States.get_calc 1;
  1225   val p = States.get_pos 1 1;
  1226   val (Form f, _, asms) = ME_Misc.pt_extract ctxt (pt, p);
  1227 
  1228   if p = ([1], Res) andalso UnparseC.term @{context} f = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" then
  1229     case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
  1230       ("diff_sum", thm)) =>
  1231       if (UnparseC.term @{context} o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
  1232       else error "embed fun fill_form changed 11"
  1233     | _ => error "embed fun fill_form changed 12"
  1234   else error "embed fun fill_form changed 13";
  1235 
  1236 findFillpatterns 1 "chain-rule-diff-both"; (*<<<<<<<=================================*)
  1237 (*<CALCMESSAGE> fill patterns #fill-d_d-arg#d_d x (x \<up> 2) + d_d x (sin (x \<up>  4)) =
  1238   d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x ?_dummy_1#fill-both-args#...#...#... *)
  1239   val ((pt,pos),_) = States.get_calc 1;
  1240   val p = States.get_pos 1 1;
  1241 
  1242   val (Form f, _, asms) = ME_Misc.pt_extract ctxt (pt, p);
  1243   if p = ([1], Res) andalso UnparseC.term @{context} f = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))" then
  1244     case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
  1245       ("diff_sum", thm)) =>
  1246       if (UnparseC.term @{context} o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
  1247       else error "embed fun fill_form changed 21"
  1248     | _ => error "embed fun fill_form changed 22"
  1249   else error "embed fun fill_form changed 23";
  1250 
  1251 requestFillformula 1 ("chain-rule-diff-both", "fill-both-args");(*<<<<<<<============*)
  1252   (*<AUTOCALC> ([1], Res) ([2], Res) ([2], Res) </AUTOCALC>*)
  1253   val ((pt,pos),_) = States.get_calc 1;
  1254   val p = States.get_pos 1 1;
  1255   val (Form f, _, asms) = ME_Misc.pt_extract ctxt (pt, p);
  1256   if p = ([1], Res) andalso existpt [2] pt
  1257     andalso UnparseC.term @{context} f = "d_d x (x \<up> 2) + d_d x (sin (x \<up> 4))"
  1258   then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
  1259       ("diff_sum", thm)) =>
  1260       if (UnparseC.term @{context} o Thm.prop_of) thm = "d_d ?bdv (?u + ?v) = d_d ?bdv ?u + d_d ?bdv ?v" then ()
  1261       else error "embed fun fill_form changed 31"
  1262     | _ => error "embed fun fill_form changed 32"
  1263   else error "embed fun fill_form changed 33";
  1264 
  1265 (* input a formula which exactly fills the gaps in a "fillformula"
  1266    presented to the learner immediately before by "requestFillformula (errpatID, fillpatID)":
  1267    errpatID: lhs of the respective thm = lhs of fillformula with fillpatID.
  1268    the respective thm is in the ctree ................
  1269 *)
  1270 "~~~~~ fun inputFillFormula, args:"; val (cI, ifo) =
  1271   (1, "d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x (x \<up> 4)");
  1272     val ((pt, _), _) = States.get_calc cI
  1273     val pos = States.get_pos cI 1;
  1274 
  1275 "~~~~~ fun is_exactly_equal, args:"; val ((pt, pos as (p, p_)), istr) = ((pt, pos), ifo);
  1276   val SOME ifo = ParseC.term_opt (ThyC.get_theory @{context} "Isac_Knowledge" |> Proof_Context.init_global) istr
  1277   val p' = lev_on p;
  1278   val tac = get_obj g_tac pt p';
  1279 val Rewrite_Inst ([bbb as "(''bdv'', x)"], ("diff_sin_chain", ttt)) = tac;
  1280 if (UnparseC.term @{context} o Thm.prop_of) ttt = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
  1281 else error "inputFillFormula changed 10";
  1282   val Applicable.Yes rew = Step.check tac (pt, pos);
  1283   val Rewrite_Inst' (_, _, _, _, _, _, _, (res, _)) = rew;
  1284 
  1285 "~~~~~ to inputFillFormula return val:"; val ("ok", tac) = ("ok", tac);
  1286   val ("ok", (_, c, ptp as (_,p'))) = Step.by_tactic tac (pt, pos);
  1287     States.upd_calc cI (ptp, []);
  1288     States.upd_ipos cI 1 p';
  1289     autocalculateOK2xml cI pos (if null c then p' else last_elem c) p';
  1290 
  1291 "~~~~~ final check:";
  1292 val ((pt, _),_) = States.get_calc 1;
  1293 val p = States.get_pos 1 1;
  1294 val (Form f, _, asms) = ME_Misc.pt_extract ctxt (pt, p);
  1295   if p = ([2], Res) andalso UnparseC.term @{context} f = "d_d x (x \<up> 2) + cos (x \<up> 4) * d_d x (x \<up> 4)"
  1296   then case get_obj g_tac pt (fst p) of Rewrite_Inst (["(''bdv'', x)"], 
  1297       ("diff_sin_chain", thm)) =>
  1298       if (UnparseC.term @{context} o Thm.prop_of) thm = "d_d ?bdv (sin ?u) = cos ?u * d_d ?bdv ?u" then ()
  1299       else error "inputFillFormula changed 111"
  1300     | _ => error "inputFillFormula changed 112"
  1301   else error "inputFillFormula changed 113";
  1302 
  1303 "--------- fun appl_adds -----------------------------------------";
  1304 "--------- fun appl_adds -----------------------------------------";
  1305 "--------- fun appl_adds -----------------------------------------";
  1306 (* val (dI, oris, model, pbt, selct::ss) = 
  1307        (dI, pors, probl, model, map itms2fstr probl);
  1308    ...vvv
  1309    *)
  1310 (* val (dI, oris, model, pbt, (selct::ss))=
  1311        (#1 (References.select_input ospec spec), oris, []:I_Model.T,
  1312 	((#model o Problem.from_store) (#2 (References.select_input ospec spec))),(imodel2fstr imodel));
  1313    val iii = appl_adds dI oris model pbt (selct::ss); 
  1314    tracing(I_Model.to_string thy iii);
  1315 
  1316  val itm = add_single' dI oris model pbt selct;
  1317  val model = I_Model.add itm model;
  1318 
  1319  val _::selct::ss = (selct::ss);
  1320  val itm = add_single' dI oris model pbt selct;
  1321  val model = I_Model.add itm model;
  1322 
  1323  val _::selct::ss = (selct::ss);
  1324  val itm = add_single' dI oris model pbt selct;
  1325  val model = I_Model.add itm model;
  1326  tracing(I_Model.to_string thy 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 "--------- fun concat_deriv --------------------------------------";
  1333 "--------- fun concat_deriv --------------------------------------";
  1334 "--------- fun concat_deriv --------------------------------------";
  1335 (*
  1336  val ({rew_ord, asm_rls, rules,...}, fo, ifo) = 
  1337      (Rule_Set.rep Test_simplify, ParseC.parse_test @{context} "x+1+ - 1*2=0", ParseC.parse_test @{context} "-2*1+(x+1)=0");
  1338  (tracing o Derive.trtas2str) fod';
  1339 > ["
  1340 (x + 1 + - 1 * 2 = 0, Thm ("radd_commute", "?m + ?n = ?n + ?m"), (- 1 * 2 + (x + 1) = 0, []))", "
  1341 (- 1 * 2 + (x + 1) = 0, Thm ("radd_commute", "?m + ?n = ?n + ?m"), (- 1 * 2 + (1 + x) = 0, []))", "
  1342 (- 1 * 2 + (1 + x) = 0, Thm ("radd_left_commute", "?x + (?y + ?z) = ?y + (?x + ?z)"), (1 + (- 1 * 2 + x) = 0, []))", "
  1343 (1 + (- 1 * 2 + x) = 0, Thm ("#mult_Float ((~1,0), (0,0)) __ ((2,0), (0,0))", "- 1 * 2 = -2"), (1 + (-2 + x) = 0, []))"]
  1344 val it = () : unit
  1345  (tracing o Derive.trtas2str) (map Derive.rev_deriv' rifod');
  1346 > ["
  1347 (1 + (-2 + x) = 0, Thm ("sym_#mult_Float ((~2,0), (0,0)) __ ((1,0), (0,0))", "-2 = -2 * 1"), (1 + (-2 * 1 + x) = 0, []))", "
  1348 (1 + (-2 * 1 + x) = 0, Thm ("sym_radd_left_commute", "?y + (?x + ?z) = ?x + (?y + ?z)"), (-2 * 1 + (1 + x) = 0, []))", "
  1349 (-2 * 1 + (1 + x) = 0, Thm ("sym_radd_commute", "?n + ?m = ?m + ?n"), (-2 * 1 + (x + 1) = 0, []))"]
  1350 val it = () : unit
  1351 *)
  1352 "--------- handle an input formula -------------------------------";
  1353 "--------- handle an input formula -------------------------------";
  1354 "--------- handle an input formula -------------------------------";
  1355 (*
  1356 Untersuchung zur Formeleingabe (appendFormula, replaceFormla) zu einer Anregung von Alan Krempler:
  1357 Welche RICHTIGEN Formeln koennen NICHT abgeleitet werden, 
  1358 wenn Abteilungen nur auf gleichem Level gesucht werden ?
  1359 WN.040216 
  1360 
  1361 Beispiele zum Equationsolver von Richard Lang aus /src/sml/kbtest/rlang.sml
  1362 
  1363 ------------------------------------------------------------------------------
  1364 "Schalk I s.87 Bsp 52a ((5*x)/(x - 2) - x/(x+2)=4)";
  1365 ------------------------------------------------------------------------------
  1366 1. "5 * x / (x - 2) - x / (x + 2) = 4"
  1367 ...
  1368 4. "12 * x + 4 * x \<up> 2 = 4 * (-4 + x \<up> 2)",Subproblem["normalise", "poly"..
  1369 ...
  1370 4.3. "16 + 12 * x = 0", Subproblem["degree_1", "polynomial", "univariate"..
  1371 ...
  1372 4.3.3. "[x = -4 / 3]")), Check_elementwise "Assumptions"
  1373 ...
  1374 "[x = -4 / 3]"
  1375 ------------------------------------------------------------------------------
  1376 (1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
  1377 
  1378 (4.1)..(4.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 4.3.n]
  1379 ------------------------------------------------------------------------------
  1380 
  1381 
  1382 ------------------------------------------------------------------------------
  1383 "Schalk I s.87 Bsp 55b (x/(x \<up> 2 - 6*x+9) - 1/(x \<up> 2 - 3*x) =1/x)";
  1384 ------------------------------------------------------------------------------
  1385 1. "x / (x \<up> 2 - 6 * x + 9) - 1 / (x \<up> 2 - 3 * x) = 1 / x"
  1386 ...
  1387 4. "(3 + (- 1 * x + x \<up> 2)) * x = 1 * (9 * x + (x \<up> 3 + -6 * x \<up> 2))"
  1388                          Subproblem["normalise", "polynomial", "univariate"..
  1389 ...
  1390 4.4. "-6 * x + 5 * x \<up> 2 = 0", Subproblem["bdv_only", "degree_2", "poly"..
  1391 ...
  1392 4.4.4. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
  1393 4.4.5. "[x = 0, x = 6 / 5]"
  1394 ...
  1395 5. "[x = 0, x = 6 / 5]", Check_elementwise "Assumptions"
  1396    "[x = 6 / 5]"
  1397 ------------------------------------------------------------------------------
  1398 (1)..(4): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite schiebt [Ableitung waere in 4.4.x]
  1399 
  1400 (4.1)..(4.4.5): keine 'richtige' Eingabe kann abgeleitet werden, die dem Ergebnis "[x = 6 / 5]" aequivalent ist [Ableitung waere in 5.]
  1401 ------------------------------------------------------------------------------
  1402 
  1403 
  1404 ------------------------------------------------------------------------------
  1405 "Schalk II s.56 Bsp 73b (sqrt(x+1)+sqrt(4*x+4)=sqrt(9*x+9))";
  1406 ------------------------------------------------------------------------------
  1407 1. "sqrt (x + 1) + sqrt (4 * x + 4) = sqrt (9 * x + 9)"
  1408 ...
  1409 6. "13 + 13 * x + -2 * sqrt ((4 + 4 * x) * (9 + 9 * x)) = 1 + x"
  1410                              Subproblem["sq", "rootX", "univariate", "equation"]
  1411 ...
  1412 6.6. "144 + 288 * x + 144 * x \<up> 2 = 144 + x \<up> 2 + 288 * x + 143 * x \<up> 2"
  1413                 Subproblem["normalise", "polynomial", "univariate", "equation"]
  1414 ...6.6.3 "0 = 0"    Subproblem["degree_0", "polynomial", "univariate", "equation"]
  1415 ...                                       Or_to_List
  1416 6.6.3.2 "UniversalList"
  1417 ------------------------------------------------------------------------------
  1418 (1)..(6): keine 'richtige' Eingabe kann abgeleitet werden, die eine der Wurzeln auf die andere Seite verschieb [Ableitung ware in 6.6.n]
  1419 
  1420 (6.1)..(6.3): keine 'richtige' Eingabe kann abgeleitet werden, die einen Summanden auf die andere Seite verschiebt [Ableitung ware in 6.6.n]
  1421 ------------------------------------------------------------------------------
  1422 *)
  1423 (*sh. comments auf 498*)
  1424 "--------- fun dropwhile' ----------------------------------------";
  1425 "--------- fun dropwhile' ----------------------------------------";
  1426 "--------- fun dropwhile' ----------------------------------------";
  1427 (*
  1428  fun equal a b = a=b;
  1429  val foder = [0,1,2,3,4,5]; val ifoder = [11,12,3,4,5];
  1430  val r_foder = rev foder;  val r_ifoder = rev ifoder;
  1431  dropwhile' equal r_foder r_ifoder;
  1432 > vval it = ([0, 1, 2, 3], [3, 12, 11]) : int list * int list
  1433 
  1434  val foder = [3,4,5]; val ifoder = [11,12,3,4,5];
  1435  val r_foder = rev foder;  val r_ifoder = rev ifoder;
  1436  dropwhile' equal r_foder r_ifoder;
  1437 > val it = ([3], [3, 12, 11]) : int list * int list
  1438 
  1439  val foder = [5]; val ifoder = [11,12,3,4,5];
  1440  val r_foder = rev foder;  val r_ifoder = rev ifoder;
  1441  dropwhile' equal r_foder r_ifoder;
  1442 > val it = ([5], [5, 4, 3, 12, 11]) : int list * int list
  1443 
  1444  val foder = [10,11,12,13,14,15]; val ifoder = [11,12,3,4,5];
  1445  val r_foder = rev foder;  val r_ifoder = rev ifoder;
  1446  dropwhile' equal r_foder r_ifoder;
  1447 > *** dropwhile': did not start with equal elements*)