test/Tools/isac/Interpret/rewtools.sml
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 02 Sep 2013 16:16:08 +0200
changeset 52101 c3f399ce32af
parent 52062 b3f18f0d55d9
child 52156 aa0884017d48
permissions -rw-r--r--
Test_Isac works again, almost ..

4 files raise errors:
# Interpret/solve.sml: "solve.sml: interSteps on norm_Rational 2"
# Interpret/inform.sml: "inform.sml: [rational,simplification] 2"
# Knowledge/partial_fractions.sml: "autoCalculate for met_partial_fraction changed: final result"
# Knowledge/eqsystem.sml: "eqsystem.sml: exp 7.70 normalize 4x4 by rewrite changed"

The chunk of changes is due to the fact, that Isac's code still is unstable.
The changes are accumulated since e8f46493af82.
     1 (* Title: test for rewtools.sml
     2    authors: Walther Neuper 2000, 2006
     3 *)
     4 
     5 "--------------------------------------------------------";
     6 "--------------------------------------------------------";
     7 "table of contents --------------------------------------";
     8 "--------------------------------------------------------";
     9 (*============ inhibit exn WN1130621 Isabelle2012-->13 !thehier! =================
    10 "----------- fun make_isab ------------------------------";
    11 "----------- fun collect_isab_thys ----------------------";
    12 ============ inhibit exn WN1130621 Isabelle2012-->13 !thehier! ===============*)
    13 "----------- fun thy_containing_rls ---------------------";
    14 "----------- fun thy_containing_cal ---------------------";
    15 (*============ inhibit exn WN120321 ==============================================
    16 "----------- initContext Thy_ Integration-demo ----------";
    17 "----------- initContext..Thy_, fun context_thm ---------";
    18 "----------- initContext..Thy_, fun context_rls ---------";
    19 "----------- checkContext..Thy_, fun context_thy --------";
    20 "----------- checkContext..Thy_, fun context_rls --------";
    21 "----------- checkContext..Thy_ on last formula ---------"; 
    22 "----------- fun guh2theID ------------------------------";
    23 "----------- debugging on Tests/solve_linear_as_rootpbl -";
    24 "--------------------------------------------------------";
    25 "----------- fun string_of_thmI for_[.]_) ---------------";
    26 "----------- (sym_real_minus_eq_cancel, (?b1 = ?a1) ..._[";
    27 "--------------------------------------------------------";
    28 "----------- fun filter_appl_rews -----------------------";
    29 "----------- fun is_contained_in ------------------------";
    30 ============ inhibit exn WN120321 ==============================================*)
    31 "-------- build fun get_bdv_subst --------------------------------";
    32 "--------------------------------------------------------";
    33 "--------------------------------------------------------";
    34 
    35 "----------- fun make_isab ------------------------------";
    36 "----------- fun make_isab ------------------------------";
    37 (*============ inhibit exn WN120321 ==============================================
    38 "----------- fun make_isab ------------------------------";
    39 (* rlsthmsNOTisac: contains thms in rls requested from Isabelle ---" *)
    40 map #1 (rlsthmsNOTisac : (string * term) list) = (*WN101011, Isabelle2009-2*)
    41 ["refl", "o_apply", "del_base", "del_rec", "LENGTH_CONS", "LENGTH_NIL",
    42  "list_diff_def", "take_Nil", "take_Cons", "if_True", "if_False",
    43  "sym_real_mult_minus1", "distrib_right", "distrib_left",
    44  "sym_realpow_twoI", "sym_realpow_addI", "mult_1_right",
    45  "sym_real_mult_2", "mult_1_left", "mult_zero_left", "mult_zero_right",
    46  "add_0_left", "add_0_right", "divide_zero_left", "sym_mult_assoc",
    47  "order_refl", "minus_minus", "mult_commute", "mult_assoc",
    48  "add_commute", "add_left_commute", "add_assoc", "minus_mult_left",
    49  "right_minus", "sym_add_assoc", "left_diff_distrib",
    50  "right_diff_distrib", "minus_divide_left", "times_divide_eq_right",
    51  "times_divide_eq_left", "divide_divide_eq_left",
    52  "divide_divide_eq_right", "divide_1", "add_divide_distrib",
    53  "sym_rmult_assoc"]; 
    54 if length rlsthmsNOTisac > 34 then () 
    55 else error "rewtools.sml: some rlsthmsNOTisac dropped";
    56 
    57 "----- FIXME.WN11xxxx: rlsthmsNOTisac DOES contain thms from isac ---";
    58 map (thmID_of_derivation_name o #1) rlsthmsNOTisac;
    59 "----- FIXME.WN11xxxx: sym_* in rlsthmsNOTisac DOES contain thms from isac ---";
    60 val symthms = [("real_mult_minus1", @{thm real_mult_minus1}),
    61                ("realpow_twoI", @{thm realpow_twoI}),
    62                ("realpow_addI", @{thm realpow_addI}),
    63                ("real_mult_2", @{thm real_mult_2}),
    64                ("mult_assoc", @{thm mult_assoc}),
    65                ("add_assoc", @{thm add_assoc}),
    66                ("rmult_assoc", @{thm rmult_assoc})];
    67 map (Thm.derivation_name o #2) symthms;
    68 
    69 "----------- fun collect_isab_thys ----------------------";
    70 "----------- fun collect_isab_thys ----------------------";
    71 "----------- fun collect_isab_thys ----------------------";
    72 val ancestors = Theory.ancestors_of @{theory "Complex_Main"};
    73 val isabthms = (flat o (map Theory.axioms_of)) ancestors;
    74 
    75 val isacrules = (flat o (map (thms_of_rls o #2 o #2))) (! ruleset');
    76 (*thms from rulesets*)
    77 (*=== inhibit exn AK110725 =============================================================
    78 val isacrlsthms = ((map rep_thm_G') o flat o 
    79 		 (map (PureThy.all_thms_of_rls o #2 o #2))) (!ruleset');
    80 length isacrlsthms;
    81 (*takes a few seconds...
    82 val isacrlsthms = gen_distinct eq_thmI isacrlsthms;
    83 length isacrlsthms;
    84 "----- theorems used in isac's rulesets -----vvvvvvvvvvvvvvvvvvvvv";
    85 print_depth 99; map #1 isacrlsthms; print_depth 3;
    86 "----- theorems used in isac's rulesets -----^^^^^^^^^^^^^^^^^^^^^";
    87 ...*)
    88 
    89 
    90 (!theory');
    91 map #2 (!theory');
    92 map (PureThy.all_thms_of o #2) (!theory');
    93 val isacthms = (flat o (map (PureThy.all_thms_of o #2))) (!theory');
    94 (*takes a few seconds...
    95 val rlsthmsNOTisac = gen_diff eq_thmI (isacrlsthms, isacthms);
    96 length rlsthmsNOTisac;
    97 "----- theorems from rulesets NOT def. in isac -----vvvvvvvvvvvvvv";
    98 print_depth 99; map #1 rlsthmsNOTisac; print_depth 3;
    99 "----- theorems from rulesets NOT def. in isac -----^^^^^^^^^^^^^^";
   100 ...*)
   101 
   102 "----- for 'fun make_isab_thm_thy'";
   103 inter eq_thmI isacrlsthms (PureThy.all_thms_of (nth 1 ancestors));
   104 inter eq_thmI;
   105 (inter eq_thmI);
   106 (inter eq_thmI) isacrlsthms;
   107 (*takes a few seconds...
   108 curry (inter eq_thmI) isacrlsthms (PureThy.all_thms_of (nth 9 ancestors));
   109 
   110 val thy = (nth 52 ancestors);
   111 val sec = ((inter eq_thmI) isacrlsthms o PureThy.all_thms_of) (nth 52 ancestors);
   112 length (PureThy.all_thms_of (nth 9 ancestors));
   113 length sec;
   114 ...*)
   115 (*takes 1 minute...
   116 print_depth 99; 
   117 map ((inter eq_thmI) rlsthmsNOTisac o PureThy.all_thms_of) ancestors;
   118 print_depth 3;
   119 *)
   120 
   121 (*takes some seconds...
   122 val isab_thm_thy = (flat o (map (make_isab_thm_thy rlsthmsNOTisac)))
   123 		       ((#ancestors o rep_theory) first_isac_thy);
   124 print_depth 99; isab_thm_thy; print_depth 3;
   125 *)
   126 === inhibit exn AK110725 =============================================================*)
   127 ============ inhibit exn WN120321 ==============================================*)
   128 
   129 
   130 
   131 "----------- fun thy_containing_rls ---------------------";
   132 "----------- fun thy_containing_rls ---------------------";
   133 "----------- fun thy_containing_rls ---------------------";
   134 infix mem; (*from Isabelle2002*)
   135 fun x mem [] = false
   136   | x mem (y :: ys) = x = y orelse x mem ys;
   137 
   138 val thy' = "Biegelinie";
   139     val dropthys =
   140       takewhile [] (not o (curry op= thy') o (#1:theory' * theory -> theory'))
   141         (rev (!theory'));
   142 
   143 (*========== inhibit exn WN1130621 Isabelle2012-->13 !thehier! ====================
   144 if length (!theory') <> length dropthys then ()
   145 else error "thy_containing_rls changed 1";
   146 
   147 		    val dropthys' = map (get_thy o (#1 : (theory' * theory) -> theory')) dropthys;
   148 
   149 if dropthys' = ["Isac", "Inverse_Z_Transform", "DiophantEq", "AlgEin"](*, "Biegelinie",..,"Test",.*)
   150 then () else error "thy_containing_rls changed ancestors_rls";
   151 
   152 "Isac" mem dropthys';
   153 op mem ("Isac", dropthys');
   154 (op mem) o swap;
   155 ((op mem) o swap) (dropthys', "Isac");
   156 curry ((op mem) o swap);
   157 curry ((op mem) o swap) dropthys' "Isac";
   158 		val ancestors_rls = 
   159 		  filter_out ((curry ((op mem) o swap) dropthys') o ((#1 o #2): rls'*(theory' * rls)->theory'))
   160 		     (rev (!ruleset'));
   161 
   162 take (10, map #1 ancestors_rls) = 
   163   ["expand_binomtest", "make_polytest", "rearrange_assoc", "ac_plus_times", "norm_equation", 
   164    "matches", "isolate_bdv", "isolate_root", "tval_rls", "Test_simplify"]; (*..all rls in each*)
   165 
   166 (* WN120523 popped up again ?!?!?
   167 if length (!ruleset') <> length ancestors_rls then ()
   168 else error "rewtools.sml: diff.behav. in thy_containing_rls 2 ERRATICAL?";
   169 *)
   170 
   171 val rls' = "norm_Poly";
   172 case assoc (ancestors_rls, rls') of
   173     SOME (thy', _) => thyID2theory' thy'
   174   | _ => error ("thy_containing_rls : rls '" ^ rls' ^
   175 			  "' not in !rulset' und thy '" ^ thy' ^ "'");
   176 
   177 if thy_containing_rls thy' rls' = ("IsacKnowledge", "Poly") then ()
   178 else error "thy_containing_rls 3: changed with (Biegelinie, norm_Poly)";
   179 
   180 "~~~~~ fun thy_containing_rls, args:"; val (thy', rls') = ("Biegelinie" ,"norm_Poly");
   181     val rls' = strip_thy rls'
   182     val thy' = thyID2theory' thy'
   183     val dropthys =
   184       takewhile [] (not o (curry op= thy') o (#1:theory' * theory -> theory'))
   185         (rev (!theory'));
   186 
   187 map #1 dropthys = ["Isac", "Inverse_Z_Transform", "DiophantEq", "AlgEin"]; (*= true WN120410*)
   188 
   189     val dropthys' = map (get_thy o (#1 : (theory' * theory) -> theory')) dropthys: string list;
   190 		    val ancestors_rls = 
   191 		      filter_out ((curry ((op mem) o swap) dropthys') o ((#1 o #2): rls'*(theory' * rls)->theory'))
   192 		        (rev (!ruleset'));
   193 		
   194 case assoc (ancestors_rls, rls') of
   195   SOME ("Poly", Seq {id = "norm_Poly", ...}) => ()
   196 | _ => error "thy_containing_rls changed 2";
   197 ============ inhibit exn WN1130621 Isabelle2012-->13 !thehier! ==================*)
   198 
   199 
   200 "----------- fun thy_containing_cal ---------------------";
   201 "----------- fun thy_containing_cal ---------------------";
   202 "----------- fun thy_containing_cal ---------------------";
   203 val thy' = "Atools";
   204     val dropthys =
   205       takewhile [] (not o (curry op= thy') o (#1:theory' * theory -> theory'))
   206         (rev (!theory'));
   207 
   208 length dropthys <> length (!theory');
   209 
   210     val dropthys' = map (get_thy o (#1 : (theory' * theory) -> theory')) dropthys;
   211 
   212 (*========== inhibit exn WN1130621 Isabelle2012-->13 !thehier! ====================
   213 if dropthys' = ["Isac", "Inverse_Z_Transform", "DiophantEq", "AlgEin", "Biegelinie",
   214   "Vect", "PolyMinus", "Frontend", "Partial_Fractions", "DiffApp", "Test", "EqSystem", "Integrate",
   215   "Diff", "LogExp", "Trig", "Calculus", "PolyEq", "RootRatEq", "RootRat", "RatEq", "RootEq",
   216   "LinEq", "Root", "Equation", "Rational", "Poly", "Simplify"] (*, "Atools", ..*)
   217 then () else error "thy_containing_cal changed ancestors_rls for Atools";
   218 
   219 (rev (!calclist'));
   220 map #1 (rev (!calclist'));
   221 map (#1 : calc -> string) (rev (!calclist'));
   222 
   223     val ancestors_cal =
   224       filter_out ((curry ((op mem) o swap) dropthys') o (#1 : calc -> string))
   225         (rev (!calclist'));
   226 
   227 if thy_containing_cal "Biegelinie" "PLUS" = ("IsacKnowledge", "plus") 
   228                     (*WN120410: SHOULD BE = ("IsacKnowledge", "Atools")*)
   229 then () else error "(wrong) thy_containing_cal 'Biegelinie' 'PLUS' changed";
   230 ============ inhibit exn WN1130621 Isabelle2012-->13 !thehier! ==================*)
   231 
   232 "----------- initContext Thy_ Integration-demo ----------";
   233 "----------- initContext Thy_ Integration-demo ----------";
   234 "----------- initContext Thy_ Integration-demo ----------";
   235 states:=[];
   236 CalcTree
   237 [(["functionTerm (2 * x)","integrateBy x","antiDerivative FF"], 
   238   ("Integrate",["integrate","function"],
   239   ["diff","integration"]))];
   240 Iterator 1;
   241 moveActiveRoot 1;
   242 autoCalculate 1 CompleteCalc;
   243 interSteps 1 ([1],Res);
   244 interSteps 1 ([1,1],Res);
   245 val ((pt,p),_) = get_calc 1; show_pt pt;
   246 if existpt' ([1,1,1], Frm) pt then ()
   247 else error "integrate.sml: interSteps on Rewrite_Set_Inst 1";
   248 initContext  1 Thy_ ([1,1,1], Frm);
   249 
   250 "----------- initContext..Thy_, fun context_thm ---------";
   251 "----------- initContext..Thy_, fun context_thm ---------";
   252 "----------- initContext..Thy_, fun context_thm ---------";
   253 states:=[]; (*start of calculation, return No.1*)
   254 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   255   ("Test", ["sqroot-test","univariate","equation","test"],
   256    ["Test","squ-equ-test-subpbl1"]))];
   257 Iterator 1; moveActiveRoot 1;
   258 autoCalculate 1 CompleteCalc;
   259 
   260 "----- no thy-context at result -----";
   261 val p = ([], Res);
   262 initContext 1 Thy_ p;
   263 
   264 interSteps 1 ([2], Res);
   265 interSteps 1 ([3,1], Res);
   266 val ((pt,_),_) = get_calc 1; show_pt pt;
   267 
   268 val p = ([2,4], Res);
   269 val tac = Rewrite ("radd_left_commute","");
   270 (*============ inhibit exn WN120321 ==============================================
   271 initContext 1 Thy_ p;
   272 (*Res->Res, Rewrite "radd_left_commute 1 + (-2 + x) = 0 -> -2 + (1 + x) = 0
   273   --- in initContext..Thy_ ---*)
   274 val ContThm {thm,result,...} = context_thy (pt,p) tac;
   275 (*WN130621: thm = "thy_isac_WN120320: AT Isa2009-2-->11 BROKEN": guh !!!!!!!!!!!!!!!!!!!!!!!!!*)
   276 if thm = "thy_isac_Test-thm-radd_left_commute" 
   277    andalso term2str result = "-2 + (1 + x) = 0" then ()
   278 else error"rewtools.sml initContext..Th_ thy_Test-thm-radd_left_commute";
   279 
   280 
   281 val p = ([3,1,1], Frm);
   282 val tac = Rewrite_Inst (["(bdv, x)"],("risolate_bdv_add",""));
   283 initContext 1 Thy_ p;
   284 (*Frm->Res, Rewrite_Inst "risolate_bdv_add"  -1 + x = 0 -> x = 0 + -1 * -1
   285   --- in initContext..Thy_ ---*)
   286 val ContThmInst {thm,result,...} = context_thy (pt,p) tac;
   287 if thm =  "thy_isac_Test-thm-risolate_bdv_add"
   288    andalso term2str result = "x = 0 + -1 * -1" then ()
   289 else error "rewtools.sml initContext..Th_ thy_Test-thm-risolate_bdv_add";
   290 
   291 initContext 1 Thy_ ([2,5], Res);
   292 (*Res->Res, Calculate "plus"  -2 + (1 + x) = 0 -> -1 + x = 0
   293   --- in initContext..Thy_ ---*)
   294 
   295 
   296 "----------- initContext..Thy_, fun context_rls ---------";
   297 "----------- initContext..Thy_, fun context_rls ---------";
   298 "----------- initContext..Thy_, fun context_rls ---------";
   299 (*using pt from above*)
   300 val p = ([1], Res);
   301 val tac = Rewrite_Set "Test_simplify";
   302 initContext 1 Thy_ p;
   303 (*Res->Res, Rewrite_Set "Test_simplify" x + 1 + -1 * 2 = 0 -> -1 + x = 0
   304   --- in initContext..Thy_ ---*)
   305 val ContRls {rls,result,...} = context_thy (pt,p) tac;
   306 if rls = "thy_isac_Test-rls-Test_simplify" 
   307    andalso term2str result = "-1 + x = 0" then ()
   308 else error "rewtools.sml initContext..Th_ thy_Test-thm-risolate_bdv_add";
   309 
   310 val p = ([3,1], Frm);
   311 val tac = Rewrite_Set_Inst (["(bdv, x)"],"isolate_bdv");
   312 initContext 1 Thy_ p;
   313 (*Frm->Res, Rewrite_Set_Inst "isolate_bdv" -1 + x = 0 ->  x = 0 + -1 * -1
   314   --- in initContext..Thy_ ---*)
   315 val ContRlsInst {rls,result,...} = context_thy (pt,p) tac;
   316 if rls =  "thy_isac_Test-rls-isolate_bdv"
   317    andalso term2str result = "x = 0 + -1 * -1" then ()
   318 else error "rewtools.sml initContext..Th_ thy_Test-thm-risolate_bdv_add";
   319 
   320 "----------- checkContext..Thy_, fun context_thy --------";
   321 "----------- checkContext..Thy_, fun context_thy --------";
   322 "----------- checkContext..Thy_, fun context_thy --------";
   323 (*using pt from above*)
   324 
   325 val p = ([2,4], Res);
   326 val tac = Rewrite ("radd_left_commute","");
   327 checkContext 1 p "thy_Test-thm-radd_left_commute";
   328 (* radd_left_commute: 1 + (-2 + x) = 0 -> -2 + (1 + x) = 0
   329   --- in checkContext..Thy_ ---*)
   330 val ContThm {thm,result,...} = context_thy (pt,p) tac;
   331 if thm =  "thy_isac_Test-thm-radd_left_commute"
   332    andalso term2str result = "-2 + (1 + x) = 0" then ()
   333 else error "rewtools.sml checkContext.._ thy_Test-thm-radd_left_commute";
   334 
   335 val p = ([3,1,1], Frm);
   336 val tac = Rewrite_Inst (["(bdv,x)"],("risolate_bdv_add",""));
   337 checkContext 1 p "thy_Test-thm-risolate_bdv_add";
   338 (* risolate_bdv_add:  -1 + x = 0 -> x = 0 + -1 * -1
   339   --- in checkContext..Thy_ ---*)
   340 val ContThmInst {thm,result,...} = context_thy (pt,p) tac;
   341 if thm =  "thy_isac_Test-thm-risolate_bdv_add"
   342    andalso term2str result = "x = 0 + -1 * -1" then ()
   343 else error "rewtools.sml checkContext..T_ thy_Test-thm-risolate_bdv_add";
   344 
   345 val p = ([2,5], Res);
   346 val tac = Calculate "plus";
   347 (*checkContext..Thy_ 1 ([2,5], Res);*)
   348 (*FIXXXME #######################vvvvv kestoreID !!!!!!!!!!!!!!!!*)
   349 checkContext 1 p ;
   350 (* Calculate "plus"  -2 + (1 + x) = 0 -> -1 + x = 0
   351   --- in checkContext..Thy_ ---*)
   352 
   353 "----------- checkContext..Thy_, fun context_rls --------";
   354 "----------- checkContext..Thy_, fun context_rls --------";
   355 "----------- checkContext..Thy_, fun context_rls --------";
   356 (*using pt from above*)
   357 show_pt pt;
   358 
   359 val p = ([1], Res);
   360 val tac = Rewrite_Set "Test_simplify";
   361 checkContext 1 p "thy_isac_Test-rls-Test_simplify";
   362 (*Res->Res, Rewrite_Set "Test_simplify" x + 1 + -1 * 2 = 0 -> -1 + x = 0
   363   --- in checkContext..Thy_ ---*)
   364 val ContRls {rls,result,...} = context_thy (pt,p) tac;
   365 if rls = "thy_isac_Test-rls-Test_simplify" 
   366    andalso term2str result = "-1 + x = 0" then ()
   367 else error "rewtools.sml checkContext..Thy_ thy_Test-rls-Test_simplify";
   368 
   369 val p = ([3,1], Frm);
   370 val tac = Rewrite_Set_Inst (["(bdv, x)"],"isolate_bdv");
   371 checkContext 1 p "thy_Test-rls-isolate_bdv";
   372 val ContRlsInst {rls,result,...} = context_thy (pt,p) tac;
   373 if rls = "thy_isac_Test-rls-isolate_bdv" 
   374    andalso term2str result = "x = 0 + -1 * -1" then ()
   375 else error "rewtools.sml checkContext..Thy_ thy_Test-thm-isolate_bdv";
   376 
   377 "----------- checkContext..Thy_ on last formula ---------"; 
   378 "----------- checkContext..Thy_ on last formula ---------"; 
   379 "----------- checkContext..Thy_ on last formula ---------"; 
   380 states:=[]; (*start of calculation, return No.1*)
   381 CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
   382   ("Test", ["sqroot-test","univariate","equation","test"],
   383    ["Test","squ-equ-test-subpbl1"]))];
   384 Iterator 1; moveActiveRoot 1;
   385 
   386 autoCalculate 1 CompleteCalcHead;
   387 autoCalculate 1 (Step 1);
   388 val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
   389 initContext 1 Thy_ ([1], Frm);
   390 checkContext 1 ([1], Frm) "thy_isac_Test-thm-radd_left_commute";
   391 
   392 autoCalculate 1 (Step 1);
   393 val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
   394 initContext 1 Thy_ ([1], Res);
   395 checkContext 1 ([1], Res) "thy_isac_Test-rls-Test_simplify";
   396 
   397 ============ inhibit exn WN1130621 Isabelle2012-->13 !thehier! ==================*)
   398 
   399 
   400 "----------- fun guh2theID ------------------------------";
   401 "----------- fun guh2theID ------------------------------";
   402 "----------- fun guh2theID ------------------------------";
   403 
   404 val guh = "thy_scri_ListG-thm-zip_Nil";
   405 print_depth 3; (*999*)
   406 take_fromto 1 4 (Symbol.explode guh);
   407 take_fromto 5 9 (Symbol.explode guh);
   408 val rest = takerest (9,(Symbol.explode guh)); 
   409 
   410 separate "-" rest;
   411 space_implode "-" rest;
   412 commas rest;
   413 
   414 val delim = "-";
   415 val thyID = takewhile [] (not o (curry op= delim)) rest;
   416 val rest' = dropuntil (curry op= delim) rest;
   417 val setc = take_fromto 1 5 rest';
   418 val xstr = takerest (5, rest');
   419 
   420 if guh2theID guh = ["IsacScripts", "ListG", "Theorems", "zip_Nil"] then ()
   421 else error "rewtools.sml: guh2theID thy_scri_ListG-thm-zip_Nil changed";
   422 
   423 
   424 "----------- debugging on Tests/solve_linear_as_rootpbl -";
   425 "----------- debugging on Tests/solve_linear_as_rootpbl -";
   426 "----------- debugging on Tests/solve_linear_as_rootpbl -";
   427 "----- initContext -----";
   428 states:=[];
   429 CalcTree 
   430     [(["equality (1+-1*2+x=(0::real))", "solveFor x", "solutions L"],
   431       ("Test",
   432        ["linear","univariate","equation","test"],
   433        ["Test","solve_linear"]))];
   434 Iterator 1; moveActiveRoot 1;
   435 autoCalculate 1 CompleteCalcHead;
   436 
   437 autoCalculate 1 (Step 1); val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
   438 if is_curr_endof_calc pt ([1],Frm) then ()
   439 else error "rewtools.sml is_curr_endof_calc ([1],Frm)";
   440 
   441 autoCalculate 1 (Step 1); val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
   442 
   443 if not (is_curr_endof_calc pt ([1],Frm)) then ()
   444 else error "rewtools.sml is_curr_endof_calc ([1],Frm) not";
   445 if is_curr_endof_calc pt ([1],Res) then ()
   446 else error "rewtools.sml is_curr_endof_calc ([1],Res)";
   447 
   448 initContext 1 Thy_ ([1],Res);
   449 
   450 "----- checkContext -----";
   451 states:=[];
   452 CalcTree 
   453     [(["equality (1+-1*2+x=(0::real))", "solveFor x", "solutions L"],
   454       ("Test",
   455        ["linear","univariate","equation","test"],
   456        ["Test","solve_linear"]))];
   457 Iterator 1; moveActiveRoot 1;
   458 autoCalculate 1 CompleteCalc;
   459 interSteps 1 ([1],Res);
   460 
   461 val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
   462 checkContext 1 ([1],Res) "thy_isac_Test-rls-Test_simplify";
   463 
   464 interSteps 1 ([2],Res);
   465 val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
   466 
   467 checkContext 1 ([2,1],Res) "thy_isac_Test-rls-Test_simplify";
   468 checkContext 1 ([2,2],Res) "thy_isac_Test-rls-Test_simplify";
   469 
   470 
   471 "----------- fun string_of_thmI for_[.]_) ---------------";
   472 "----------- fun string_of_thmI for_[.]_) ---------------";
   473 "----------- fun string_of_thmI for_[.]_) ---------------";
   474 "----- these work ?!?";
   475 (*========== inhibit exn 110718 ================================================
   476 (* ERROR: constructor real_minus_eq_cancel has not been declared *)
   477 val th = sym_thm real_minus_eq_cancel;
   478 val Th = sym_Thm (Thm ("real_minus_eq_cancel", real_minus_eq_cancel));
   479 val th'= mk_thm ( @{theory "Isac"} ) ((de_quote o string_of_thm) real_minus_eq_cancel);
   480 val th'= mk_thm Biegelinie.thy((de_quote o string_of_thm) real_minus_eq_cancel);
   481 
   482 "----- DIFFERENCE TO ABOVE ?!?: this is still ok, when called in next_tac...";
   483 val ((pt,(p,p_)), _) = get_calc 1; show_pt pt;
   484 val Appl (Rewrite' (_,_,_,_,thm',_,_)) =
   485     applicable_in (p,p_) pt (Rewrite ("sym_real_minus_eq_cancel",""));
   486 "- compose stac as done in | appy (*leaf*) by handle_leaf";
   487 
   488 val (th, sr, E, a, v, t) = 
   489     ("Biegelinie", 
   490      (#srls o get_met) ["IntegrierenUndKonstanteBestimmen"],
   491      [(str2term "q__::bool", str2term "q x = q_0")], 
   492      SOME (str2term "q x = q_0"),
   493      str2term "q__::bool", 
   494      str2term "(Rewrite sym_real_minus_eq_cancel False) (q__::bool)");
   495 val (a', STac stac) = handle_leaf "next  " th sr E a v t;
   496 term2str stac;
   497 "--- but this \"m\" is already corrupted";
   498 val (m,_) = stac2tac_ EmptyPtree (assoc_thy th) stac;
   499 "- because in assoc_thm'...";
   500 val (thy, (thmid, ct')) = (Biegelinie.thy, ("sym_real_minus_eq_cancel",""));
   501 val "s"::"y"::"m"::"_"::id = explode thmid;
   502 ((num_str o (get_thm thy)) (implode id)) RS sym;
   503 ((get_thm thy) (implode id)) RS sym;
   504 "... this creates [.]";
   505 ((get_thm thy) (implode id));
   506 "... while this has _NO_ [.]";
   507 
   508 "----- thus we repair the [.] in string_of_thmI...";
   509 val thm = ((num_str o (get_thm thy)) (implode id)) RS sym;
   510 if string_of_thmI thm = "(?b1 = ?a1) = (- ?b1 = - ?a1)" then ()
   511 else error ("rewtools.sml: string_of_thmI " ^ string_of_thm thm ^
   512 		  " = " ^ string_of_thmI thm);
   513 ========== inhibit exn 110718 ================================================*)
   514 
   515 "----------- (sym_real_minus_eq_cancel, (?b1 = ?a1) ..._[";
   516 "----------- (sym_real_minus_eq_cancel, (?b1 = ?a1) ..._[";
   517 "----------- (sym_real_minus_eq_cancel, (?b1 = ?a1) ..._[";
   518 states:=[];
   519 CalcTree [(["Traegerlaenge L","Streckenlast q_0","Biegelinie y",
   520 	     "RandbedingungenBiegung [y 0 = 0, y L = 0]",
   521 	     "RandbedingungenMoment [M_b 0 = 0, M_b L = 0]",
   522 	     "FunktionsVariable x"],
   523 	    ("Biegelinie",
   524 	     ["MomentBestimmte","Biegelinien"],
   525 	     ["IntegrierenUndKonstanteBestimmen"]))];
   526 moveActiveRoot 1;
   527 autoCalculate 1 CompleteCalcHead;
   528 autoCalculate 1 (Step 1) (*Apply_Method*);
   529 autoCalculate 1 (Step 1) (*->GENERATED ([1], Frm)*);
   530 (*========== inhibit exn 110718 ================================================
   531 
   532 "--- this was corrupted before 'fun string_of_thmI'";
   533 val ((pt,(p,p_)), _) = get_calc 1; show_pt pt;
   534 if get_obj g_tac pt p = Rewrite ("sym_real_minus_eq_cancel", 
   535 				 "(?b1 = ?a1) = (- ?b1 = - ?a1)") then ()
   536 else error "rewtools.sml: string_of_thmI ?!?";
   537 
   538 getTactic 1 ([1],Frm);
   539 "----------- fun filter_appl_rews -----------------------";
   540 "----------- fun filter_appl_rews -----------------------";
   541 "----------- fun filter_appl_rews -----------------------";
   542 val f = str2term "a + z + 2*a + 3*z + 5 + 6";
   543 val thy = assoc_thy "Isac";
   544 val subst = [(*TODO.WN071231 test Rewrite_Inst*)];
   545 val rls = Test_simplify;
   546 (* val rls = rls_p_33;      filter_appl_rews  ---> length 2
   547    val rls = norm_Poly;     filter_appl_rews  ---> length 1
   548    *)
   549 if filter_appl_rews thy subst f rls =
   550    [Rewrite ("radd_commute", "?m + ?n = ?n + ?m"),
   551     Rewrite ("radd_assoc", "?m + ?n + ?k = ?m + (?n + ?k)"),
   552     Calculate "plus"] then () 
   553 else error "rewtools.sml filter_appl_rews a + z + 2*a + 3*z + 5 + 6";
   554 ============ inhibit exn 110718 ==============================================*)
   555 
   556 
   557 "----------- fun is_contained_in ------------------------";
   558 "----------- fun is_contained_in ------------------------";
   559 "----------- fun is_contained_in ------------------------";
   560 val r1 = Thm ("real_diff_minus",num_str @{thm real_diff_minus});
   561 if contains_rule r1 Test_simplify then ()
   562 else error "rewtools.sml contains_rule Thm";
   563 
   564 val r1 = Calc ("Groups.plus_class.plus", eval_binop "#add_");
   565 if contains_rule r1 Test_simplify then ()
   566 else error "rewtools.sml contains_rule Calc";
   567 
   568 val r1 = Calc ("Groups.minus_class.minus", eval_binop "#add_");
   569 if not (contains_rule r1 Test_simplify) then ()
   570 else error "rewtools.sml contains_rule Calc";
   571 
   572 
   573 "-------- build fun get_bdv_subst --------------------------------";
   574 "-------- build fun get_bdv_subst --------------------------------";
   575 "-------- build fun get_bdv_subst --------------------------------";
   576 val {scr = Prog prog, ...} = get_met ["diff", "differentiate_on_R"];
   577 val env = [(str2term "v_v", str2term "x")];
   578 subst2str env = "[\"\n(v_v, x)\"]";
   579 
   580 "~~~~~ fun get_bdv_subst, args:"; val (prog, env) = (prog, env);
   581     fun scan (Const _) = NONE
   582       | scan (Free _) = NONE
   583       | scan (Var _) = NONE
   584       | scan (Bound _) = NONE
   585       | scan (t as Const ("List.list.Cons", _) $
   586          (Const ("Product_Type.Pair", _) $ Free (str, _) $ _) $ _) =
   587            if is_bdv_subst t then SOME t else NONE
   588       | scan (Abs (_, _, body)) = scan body
   589       | scan (t1 $ t2) =
   590           case scan t1 of
   591             NONE => scan t2
   592           | SOME subst => SOME subst
   593 
   594 val SOME tm = scan prog;
   595 val subst = tm |> subst_atomic env |> isalist2list |> map isapair2pair: subst;
   596 if term2str tm = "[(bdv, v_v)]" then () else error "get_bdv_subst changed 1";
   597 
   598 if subst2subs subst = ["(bdv, x)"] then () else error "get_bdv_subst changed 2";
   599 
   600 case get_bdv_subst prog env of
   601   (SOME ["(bdv, x)"], [(Free ("bdv", _), Free ("x", _))]: subst) => ()
   602 | _ => error "get_bdv_subst changed 3";
   603 
   604 val (SOME subs, _) = get_bdv_subst prog env;
   605 Rewrite_Inst (subs, ("diff_sin_chain","")) (*<<<----- this is the intended usage*)
   606