test/Tools/isac/Knowledge/polyminus.sml
author Walther Neuper <neuper@ist.tugraz.at>
Tue, 13 Mar 2012 15:04:09 +0100
changeset 42390 96174a374a7a
parent 42279 e2759e250604
child 52070 77138c64f4f6
permissions -rw-r--r--
uncomment test/../ptyps.sml (Isabelle 2002 --> 2011)

jumped from incomplete test/../equsystem.sml to above
ATTENTION: in 1st go Test_Isac.thy had errors in ctree, and 2 other files?!?
     1 (* tests on PolyMinus
     2    author: Walther Neuper
     3    WN071207,
     4    (c) due to copyright terms
     5 
     6 use"../smltest/IsacKnowledge/polyminus.sml";
     7 use"polyminus.sml";
     8 *)
     9 "--------------------------------------------------------";
    10 "--------------------------------------------------------";
    11 "table of contents --------------------------------------";
    12 "--------------------------------------------------------";
    13 "----------- fun eval_ist_monom -------------------------";
    14 "----------- watch order_add_mult  ----------------------";
    15 "----------- build predicate for +- ordering ------------";
    16 "----------- build fasse_zusammen -----------------------";
    17 "----------- build verschoenere -------------------------";
    18 "----------- met simplification for_polynomials with_minu";
    19 "----------- me simplification.for_polynomials.with_minus";
    20 "----------- pbl polynom vereinfachen p.33 --------------";
    21 "----------- met probe fuer_polynom ---------------------";
    22 "----------- pbl polynom probe --------------------------";
    23 "----------- pbl klammer polynom vereinfachen p.34 ------";
    24 "----------- try fun applyTactics -----------------------";
    25 "----------- pbl binom polynom vereinfachen p.39 --------";
    26 "----------- pbl binom polynom vereinfachen: cube -------";
    27 "----------- refine Vereinfache -------------------------";
    28 "----------- *** prep_pbt: syntax error in '#Where' of [v";
    29 "--------------------------------------------------------";
    30 "--------------------------------------------------------";
    31 "--------------------------------------------------------";
    32 
    33 val thy = @{theory "PolyMinus"};
    34 
    35 "----------- fun eval_ist_monom ----------------------------------";
    36 "----------- fun eval_ist_monom ----------------------------------";
    37 "----------- fun eval_ist_monom ----------------------------------";
    38 ist_monom (str2term "12");
    39 case eval_ist_monom 0 0 (str2term "12 ist_monom") 0 of
    40     SOME ("12 ist_monom = True", _) => ()
    41   | _ => error "polyminus.sml: 12 ist_monom = True";
    42 
    43 case eval_ist_monom 0 0 (str2term "a ist_monom") 0 of
    44     SOME ("a ist_monom = True", _) => ()
    45   | _ => error "polyminus.sml: a ist_monom = True";
    46 
    47 case eval_ist_monom 0 0 (str2term "(3*a) ist_monom") 0 of
    48     SOME ("3 * a ist_monom = True", _) => ()
    49   | _ => error "polyminus.sml: 3 * a ist_monom = True";
    50 
    51 case eval_ist_monom 0 0 (str2term "(a^^^2) ist_monom") 0 of 
    52    SOME ("a ^^^ 2 ist_monom = True", _) => ()
    53   | _ => error "polyminus.sml: a^^^2 ist_monom = True";
    54 
    55 case eval_ist_monom 0 0 (str2term "(3*a^^^2) ist_monom") 0 of
    56     SOME ("3 * a ^^^ 2 ist_monom = True", _) => ()
    57   | _ => error "polyminus.sml: 3*a^^^2 ist_monom = True";
    58 
    59 case eval_ist_monom 0 0 (str2term "(a*b) ist_monom") 0 of
    60     SOME ("a * b ist_monom = True", _) => ()
    61   | _ => error "polyminus.sml: a*b ist_monom = True";
    62 
    63 case eval_ist_monom 0 0 (str2term "(3*a*b) ist_monom") 0 of
    64     SOME ("3 * a * b ist_monom = True", _) => ()
    65   | _ => error "polyminus.sml: 3*a*b ist_monom = True";
    66 
    67 
    68 "----------- watch order_add_mult  -------------------------------";
    69 "----------- watch order_add_mult  -------------------------------";
    70 "----------- watch order_add_mult  -------------------------------";
    71 "----- with these simple variables it works...";
    72 trace_rewrite:=true;
    73 trace_rewrite:=false;
    74 val t = str2term "((a + d) + c) + b";
    75 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
    76 if term2str t = "a + (b + (c + d))" then ()
    77 else error "polyminus.sml 1 watch order_add_mult";
    78 trace_rewrite:=false;
    79 
    80 "----- the same stepwise...";
    81 val od = ord_make_polynomial true (@{theory "Poly"});
    82 val t = str2term "((a + d) + c) + b";
    83 "((a + d) + c) + b"; 
    84 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_commute} t; term2str t;
    85 "b + ((a + d) + c)";
    86 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_commute} t; term2str t;
    87 "b + (c + (a + d))";
    88 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
    89 "b + (a + (c + d))";
    90 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
    91 "a + (b + (c + d))";
    92 if term2str t = "a + (b + (c + d))" then ()
    93 else error "polyminus.sml 2 watch order_add_mult";
    94 
    95 "----- if parentheses are right, left_commute is (almost) sufficient...";
    96 val t = str2term "a + (d + (c + b))";
    97 "a + (d + (c + b))";
    98 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
    99 "a + (c + (d + b))";
   100 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_commute} t;term2str t;
   101 "a + (c + (b + d))";
   102 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
   103 "a + (b + (c + d))";
   104 
   105 "----- but we do not want the parentheses at right; thus: cond.rew.";
   106 "WN0712707 complicated monomials do not yet work ...";
   107 val t = str2term "((5*a + 4*d) + 3*c) + 2*b";
   108 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
   109 if term2str t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
   110 else error "polyminus.sml: order_add_mult changed";
   111 
   112 "----- here we see rew_sub going into subterm with ord.rew....";
   113 val od = ord_make_polynomial false (@{theory "Poly"});
   114 val t = str2term "b + a + c + d";
   115 val SOME (t,_) = rewrite_ thy od e_rls false @{thm add_commute} t; term2str t;
   116 val SOME (t,_) = rewrite_ thy od e_rls false @{thm add_commute} t; term2str t;
   117 (*@@@ rew_sub gosub: t = d + (b + a + c)
   118   @@@ rew_sub begin: t = b + a + c*)
   119 
   120 
   121 "----------- build predicate for +- ordering ---------------------";
   122 "----------- build predicate for +- ordering ---------------------";
   123 "----------- build predicate for +- ordering ---------------------";
   124 "a" < "b";
   125 "ba" < "ab";
   126 "123" < "a"; (*unused due to ---vvv*)
   127 "12" < "3"; (*true !!!*)
   128 
   129 " a kleiner b ==> (b + a) = (a + b)";
   130 str2term "aaa";
   131 str2term "222 * aaa";
   132 
   133 case eval_kleiner 0 0 (str2term "123 kleiner 32") 0 of
   134     SOME ("123 kleiner 32 = False", _) => ()
   135   | _ => error "polyminus.sml: 12 kleiner 9 = False";
   136 
   137 case eval_kleiner 0 0 (str2term "a kleiner b") 0 of
   138     SOME ("a kleiner b = True", _) => ()
   139   | _ => error "polyminus.sml: a kleiner b = True";
   140 
   141 case eval_kleiner 0 0 (str2term "(10*g) kleiner f") 0 of
   142     SOME ("10 * g kleiner f = False", _) => ()
   143   | _ => error "polyminus.sml: 10 * g kleiner f = False";
   144 
   145 case eval_kleiner 0 0 (str2term "(a^^^2) kleiner b") 0 of
   146     SOME ("a ^^^ 2 kleiner b = True", _) => ()
   147   | _ => error "polyminus.sml: a ^^^ 2 kleiner b = True";
   148 
   149 case eval_kleiner 0 0 (str2term "(3*a^^^2) kleiner b") 0 of
   150     SOME ("3 * a ^^^ 2 kleiner b = True", _) => ()
   151   | _ => error "polyminus.sml: 3 * a ^^^ 2 kleiner b = True";
   152 
   153 case eval_kleiner 0 0 (str2term "(a*b) kleiner c") 0 of
   154     SOME ("a * b kleiner c = True", _) => ()
   155   | _ => error "polyminus.sml: a * b kleiner b = True";
   156 
   157 case eval_kleiner 0 0 (str2term "(3*a*b) kleiner c") 0 of
   158     SOME ("3 * a * b kleiner c = True", _) => ()
   159   | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
   160 
   161 "======= compare tausche_plus with real_num_collect";
   162 val od = dummy_ord;
   163 
   164 val erls = erls_ordne_alphabetisch;
   165 val t = str2term "b + a";
   166 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
   167 if term2str t = "a + b" then ()
   168 else error "polyminus.sml: ordne_alphabetisch1 b + a";
   169 
   170 val erls = Atools_erls;
   171 val t = str2term "2*a + 3*a";
   172 val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; term2str t;
   173 
   174 "======= test rewrite_, rewrite_set_";
   175 trace_rewrite:=true;
   176 val erls = erls_ordne_alphabetisch;
   177 val t = str2term "b + a";
   178 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
   179 if term2str t = "a + b" then ()
   180 else error "polyminus.sml: ordne_alphabetisch a + b";
   181 
   182 val t = str2term "2*b + a";
   183 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
   184 if term2str t = "a + 2 * b" then ()
   185 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
   186 
   187 val t = str2term "a + c + b";
   188 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
   189 if term2str t = "a + b + c" then ()
   190 else error "polyminus.sml: ordne_alphabetisch a + b + c";
   191 
   192 "======= rewrite goes into subterms";
   193 val t = str2term "a + c + b + d";
   194 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; term2str t;
   195 if term2str t = "a + b + c + d" then ()
   196 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
   197 
   198 val t = str2term "a + c + d + b";
   199 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
   200 if term2str t = "a + b + c + d" then ()
   201 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
   202 
   203 "======= here we see rew_sub going into subterm with cond.rew....";
   204 val t = str2term "b + a + c + d";
   205 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
   206 if term2str t = "a + b + c + d" then ()
   207 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
   208 
   209 "======= compile rls for the most complicated terms";
   210 val t = str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
   211 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
   212 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; 
   213 if term2str t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
   214 then () else error "polyminus.sml: ordne_alphabetisch finished";
   215 
   216 
   217 "----------- build fasse_zusammen --------------------------------";
   218 "----------- build fasse_zusammen --------------------------------";
   219 "----------- build fasse_zusammen --------------------------------";
   220 val t = str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
   221 val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
   222 if term2str t = "3 + -2 * e + 2 * f + 2 * g" then ()
   223 else error "polyminus.sml: fasse_zusammen finished";
   224 
   225 "----------- build verschoenere ----------------------------------";
   226 "----------- build verschoenere ----------------------------------";
   227 "----------- build verschoenere ----------------------------------";
   228 val t = str2term "3 + -2 * e + 2 * f + 2 * g";
   229 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
   230 if term2str t = "3 - 2 * e + 2 * f + 2 * g" then ()
   231 else error "polyminus.sml: verschoenere 3 + -2 * e ...";
   232 
   233 trace_rewrite:=true;
   234 trace_rewrite:=false;
   235 
   236 "----------- met simplification for_polynomials with_minus -------";
   237 "----------- met simplification for_polynomials with_minus -------";
   238 "----------- met simplification for_polynomials with_minus -------";
   239 val str = 
   240 "Script SimplifyScript (t_t::real) =                \
   241 \  (((Try (Rewrite_Set ordne_alphabetisch False)) @@     \
   242 \    (Try (Rewrite_Set fasse_zusammen False)) @@     \
   243 \    (Try (Rewrite_Set verschoenere False))) t_t)"
   244 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
   245 atomty sc;
   246 
   247 "----------- me simplification.for_polynomials.with_minus";
   248 "----------- me simplification.for_polynomials.with_minus";
   249 "----------- me simplification.for_polynomials.with_minus";
   250 val c = [];
   251 val (p,_,f,nxt,_,pt) = 
   252       CalcTreeTEST 
   253         [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
   254            "normalform N"],
   255 	          ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   256 	           ["simplification","for_polynomials","with_minus"]))];
   257 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   258 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   259 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   260 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   261 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   262 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   263 
   264 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   265 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   266 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   267 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   268 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   269 if f2str f = "3 - 2 * e + 2 * f + 2 * g" andalso #1 nxt = "End_Proof'" then ()
   270 else error "polyminus.sml: me simplification.for_polynomials.with_minus";
   271 
   272 "----------- pbl polynom vereinfachen p.33 -----------------------";
   273 "----------- pbl polynom vereinfachen p.33 -----------------------";
   274 "----------- pbl polynom vereinfachen p.33 -----------------------";
   275 "----------- 140 c ---";
   276 states:=[];
   277 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
   278 	    "normalform N"],
   279 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   280 	    ["simplification","for_polynomials","with_minus"]))];
   281 moveActiveRoot 1;
   282 autoCalculate 1 CompleteCalc;
   283 val ((pt,p),_) = get_calc 1; show_pt pt;
   284 if p = ([], Res) andalso 
   285    term2str (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
   286 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
   287 
   288 "======= 140 d ---";
   289 states:=[];
   290 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
   291 	    "normalform N"],
   292 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   293 	    ["simplification","for_polynomials","with_minus"]))];
   294 moveActiveRoot 1;
   295 autoCalculate 1 CompleteCalc;
   296 val ((pt,p),_) = get_calc 1; show_pt pt;
   297 if p = ([], Res) andalso 
   298    term2str (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
   299 then () else error "polyminus.sml: Vereinfache 140 d)";
   300 
   301 "======= 139 c ---";
   302 states:=[];
   303 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
   304 	    "normalform N"],
   305 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   306 	    ["simplification","for_polynomials","with_minus"]))];
   307 moveActiveRoot 1;
   308 autoCalculate 1 CompleteCalc;
   309 val ((pt,p),_) = get_calc 1; show_pt pt;
   310 if p = ([], Res) andalso 
   311    term2str (get_obj g_res pt (fst p)) = "- (3 * f)"
   312 then () else error "polyminus.sml: Vereinfache 139 c)";
   313 
   314 "======= 139 b ---";
   315 states:=[];
   316 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
   317 	    "normalform N"],
   318 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   319 	    ["simplification","for_polynomials","with_minus"]))];
   320 moveActiveRoot 1;
   321 autoCalculate 1 CompleteCalc;
   322 val ((pt,p),_) = get_calc 1; show_pt pt;
   323 if p = ([], Res) andalso 
   324    term2str (get_obj g_res pt (fst p)) = "-3 * u - v"
   325 then () else error "polyminus.sml: Vereinfache 139 b)";
   326 
   327 "======= 138 a ---";
   328 states:=[];
   329 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
   330 	    "normalform N"],
   331 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   332 	    ["simplification","for_polynomials","with_minus"]))];
   333 moveActiveRoot 1;
   334 autoCalculate 1 CompleteCalc;
   335 val ((pt,p),_) = get_calc 1; show_pt pt;
   336 if p = ([], Res) andalso 
   337    term2str (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
   338 then () else error "polyminus.sml: Vereinfache 138 a)";
   339 
   340 "----------- met probe fuer_polynom ------------------------------";
   341 "----------- met probe fuer_polynom ------------------------------";
   342 "----------- met probe fuer_polynom ------------------------------";
   343 val str = 
   344 "Script ProbeScript (e_e::bool) (w_s::bool list) =\
   345 \ (let e_e = Take e_e;                             \
   346 \      e_e = Substitute w_s e_e                    \
   347 \ in (Repeat((Try (Repeat (Calculate TIMES))) @@  \
   348 \            (Try (Repeat (Calculate PLUS ))) @@  \
   349 \            (Try (Repeat (Calculate MINUS))))) e_e)"
   350 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
   351 atomty sc;
   352 
   353 "----------- pbl polynom probe -----------------------------------";
   354 "----------- pbl polynom probe -----------------------------------";
   355 "----------- pbl polynom probe -----------------------------------";
   356 states:=[];
   357 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
   358 	    \3 - 2 * e + 2 * f + 2 * g)",
   359 	    "mitWert [e = 1, f = 2, g = 3]",
   360 	    "Geprueft b"],
   361 	   ("PolyMinus",["polynom","probe"],
   362 	    ["probe","fuer_polynom"]))];
   363 moveActiveRoot 1;
   364 autoCalculate 1 CompleteCalc;
   365 (* autoCalculate 1 CompleteCalcHead;
   366    autoCalculate 1 (Step 1);
   367    autoCalculate 1 (Step 1);
   368    val ((pt,p),_) = get_calc 1; term2str (get_obj g_res pt (fst p));
   369 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
   370 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
   371 val ((pt,p),_) = get_calc 1;
   372 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "11 = 11"
   373 then () else error "polyminus.sml: Probe 11 = 11";
   374 show_pt pt;
   375 
   376 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
   377 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
   378 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
   379 states:=[];
   380 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
   381 	    "normalform N"],
   382 	   ("PolyMinus",["klammer","polynom","vereinfachen"],
   383 	    ["simplification","for_polynomials","with_parentheses"]))];
   384 moveActiveRoot 1;
   385 autoCalculate 1 CompleteCalc;
   386 val ((pt,p),_) = get_calc 1;
   387 if p = ([], Res) andalso 
   388    term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
   389 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
   390 show_pt pt;
   391 
   392 "======= probe p.34 -----";
   393 states:=[];
   394 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * u)",
   395 	    "mitWert [u = 2]",
   396 	    "Geprueft b"],
   397 	   ("PolyMinus",["polynom","probe"],
   398 	    ["probe","fuer_polynom"]))];
   399 moveActiveRoot 1;
   400 autoCalculate 1 CompleteCalc;
   401 val ((pt,p),_) = get_calc 1;
   402 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "29 = 29"
   403 then () else error "polyminus.sml: Probe 29 = 29";
   404 show_pt pt;
   405 
   406 "----------- try fun applyTactics --------------------------------";
   407 "----------- try fun applyTactics --------------------------------";
   408 "----------- try fun applyTactics --------------------------------";
   409 states:=[];
   410 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
   411 	    "normalform N"],
   412 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   413 	    ["simplification","for_polynomials","with_minus"]))];
   414 moveActiveRoot 1;
   415 autoCalculate 1 CompleteCalcHead;
   416 autoCalculate 1 (Step 1);
   417 autoCalculate 1 (Step 1);
   418 val ((pt,p),_) = get_calc 1; show_pt pt;
   419 "----- 1 ^^^";
   420 fetchApplicableTactics 1 0 p;
   421 val appltacs = sel_appl_atomic_tacs pt p;
   422 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
   423 val ((pt,p),_) = get_calc 1; show_pt pt;
   424 "----- 2 ^^^";
   425 trace_rewrite := true;
   426 val erls = erls_ordne_alphabetisch;
   427 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
   428 val SOME (t',_) = 
   429     rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus} t;
   430 term2str t';     "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
   431 
   432 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
   433 val NONE = 
   434     rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
   435 
   436 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
   437 val SOME (t',_) = 
   438     rewrite_set_ (@{theory "Isac"}) false ordne_alphabetisch t;
   439 term2str t';     "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
   440 trace_rewrite := false;
   441 
   442 
   443 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (*tausche_minus*);
   444 val ((pt,p),_) = get_calc 1; show_pt pt;
   445 "----- 3 ^^^";
   446 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
   447 val ((pt,p),_) = get_calc 1; show_pt pt;
   448 "----- 4 ^^^";
   449 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
   450 val ((pt,p),_) = get_calc 1; show_pt pt;
   451 "----- 5 ^^^";
   452 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
   453 val ((pt,p),_) = get_calc 1; show_pt pt;
   454 "----- 6 ^^^";
   455 
   456 (*<CALCMESSAGE> failure </CALCMESSAGE>
   457 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
   458 val ((pt,p),_) = get_calc 1; show_pt pt;
   459 "----- 7 ^^^";
   460 *)
   461 autoCalculate 1 CompleteCalc;
   462 val ((pt,p),_) = get_calc 1; show_pt pt;
   463 (*independent from failure above: met_simp_poly_minus not confluent:
   464 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
   465 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
   466 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
   467 
   468 
   469 "#############################################################################";
   470 states:=[];
   471 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
   472 	    "normalform N"],
   473 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   474 	    ["simplification","for_polynomials","with_minus"]))];
   475 moveActiveRoot 1;
   476 autoCalculate 1 CompleteCalc;
   477 val ((pt,p),_) = get_calc 1; show_pt pt;
   478 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "2 * g + h"
   479 then () else error "polyminus.sml: addiere_vor_minus";
   480 
   481 
   482 "#############################################################################";
   483 states:=[];
   484 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
   485 	    "normalform N"],
   486 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   487 	    ["simplification","for_polynomials","with_minus"]))];
   488 moveActiveRoot 1;
   489 autoCalculate 1 CompleteCalc;
   490 val ((pt,p),_) = get_calc 1; show_pt pt;
   491 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "f + 2 * g"
   492 then () else error "polyminus.sml: tausche_vor_plus";
   493 
   494 "----------- pbl binom polynom vereinfachen p.39 -----------------";
   495 "----------- pbl binom polynom vereinfachen p.39 -----------------";
   496 "----------- pbl binom polynom vereinfachen p.39 -----------------";
   497 val rls = klammern_ausmultiplizieren;
   498 val t = str2term "(3 * a + 2) * (4 * a - 1)";
   499 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   500 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
   501 val rls = discard_parentheses;
   502 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   503 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
   504 val rls = ordne_monome;
   505 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   506 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
   507 (*
   508 val t = str2term "3 * a * 4 * a";
   509 val rls = ordne_monome;
   510 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   511 *)
   512 val rls = klammern_aufloesen;
   513 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   514 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
   515 val rls = ordne_alphabetisch;
   516 (*TODO: make is_monom more general, a*a=a^2, ...*)
   517 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   518 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
   519 (*STOPPED.WN080104
   520 val rls = fasse_zusammen;
   521 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   522 val rls = verschoenere;
   523 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   524 *)
   525 
   526 (*@@@@@@@*)
   527 states:=[];
   528 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
   529 	    "normalform N"],
   530 	   ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
   531 	    ["simplification","for_polynomials","with_parentheses_mult"]))];
   532 moveActiveRoot 1;
   533 autoCalculate 1 CompleteCalc;
   534 val ((pt,p),_) = get_calc 1; show_pt pt;
   535 if p = ([], Res) andalso 
   536    term2str (get_obj g_res pt (fst p)) = "-2 + 12 * a ^^^ 2 + 5 * a"
   537 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
   538 
   539 "----------- pbl binom polynom vereinfachen: cube ----------------";
   540 "----------- pbl binom polynom vereinfachen: cube ----------------";
   541 "----------- pbl binom polynom vereinfachen: cube ----------------";
   542 states:=[];
   543 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
   544 	   ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
   545 	    ["simplification","for_polynomials","with_parentheses_mult"]))];
   546 moveActiveRoot 1;
   547 autoCalculate 1 CompleteCalc;
   548 val ((pt,p),_) = get_calc 1; show_pt pt;
   549 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "12 * a - 16 * q" 
   550 then () else error "pbl binom polynom vereinfachen: cube";
   551 
   552 "----------- refine Vereinfache ----------------------------------";
   553 "----------- refine Vereinfache ----------------------------------";
   554 "----------- refine Vereinfache ----------------------------------";
   555 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"];
   556 print_depth 11;
   557 val matches = refine fmz ["vereinfachen"];
   558 print_depth 3;
   559 
   560 "----- go into details, if it seems not to work -----";
   561 "--- does the predicate evaluate correctly ?";
   562 val t = str2term 
   563 	    "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))";
   564 val ma = eval_matchsub "" "Tools.matchsub" t thy;
   565 case ma of
   566     SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
   567 	  \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
   568   | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
   569 
   570 "--- does the respective prls rewrite ?";
   571 val prls = append_rls "prls_pbl_vereinf_poly" e_rls 
   572 	     [Calc ("Poly.is'_polyexp", eval_is_polyexp ""),
   573 	      Calc ("Tools.matchsub", eval_matchsub ""),
   574 	      Thm ("or_true",@{thm or_true}),
   575 	      (*"(?a | True) = True"*)
   576 	      Thm ("or_false",@{thm or_false}),
   577 	      (*"(?a | False) = ?a"*)
   578 	      Thm ("not_true",num_str @{thm not_true}),
   579 	      (*"(~ True) = False"*)
   580 	      Thm ("not_false",num_str @{thm not_false})
   581 	      (*"(~ False) = True"*)];
   582 trace_rewrite := true;
   583 val SOME (t', _) = rewrite_set_ thy false prls t;
   584 trace_rewrite := false;
   585 
   586 "--- does the respective prls rewrite the whole predicate ?";
   587 val t = str2term 
   588 	    "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
   589 	    \     matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
   590 	    \     matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
   591 	    \     matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
   592 trace_rewrite := true;
   593 val SOME (t', _) = rewrite_set_ thy false prls t;
   594 trace_rewrite := false;
   595 if term2str t' = "False" then ()
   596 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
   597 
   598 "----------- *** prep_pbt: syntax error in '#Where' of [v";
   599 "----------- *** prep_pbt: syntax error in '#Where' of [v";
   600 "----------- *** prep_pbt: syntax error in '#Where' of [v";
   601 (*see test/../termC.sml for details*)
   602 val t = parse_patt thy "t_t is_polyexp";
   603 val t = parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
   604 	                "     matchsub (?a + (?b - ?c)) t_t | " ^
   605 	                "     matchsub (?a - (?b + ?c)) t_t | " ^
   606 	                "     matchsub (?a + (?b - ?c)) t_t )");
   607 (*show_types := true;
   608 if term2str t = "~ (matchsub ((?a::real) + ((?b::real) + (?c::real))) (t_t::real) |\n   matchsub (?a + (?b - ?c)) t_t |\n   matchsub (?a - (?b + ?c)) t_t | matchsub (?a + (?b - ?c)) t_t)"
   609 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
   610 show_types := false;*)
   611 if term2str t = "~ (matchsub (?a + (?b + ?c)) t_t |\n   matchsub (?a + (?b - ?c)) t_t |\n" ^
   612 "   matchsub (?a - (?b + ?c)) t_t | matchsub (?a + (?b - ?c)) t_t)"
   613 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
   614