test/Tools/isac/Knowledge/polyminus.sml
author Walther Neuper <walther.neuper@jku.at>
Tue, 03 Sep 2019 12:40:27 +0200
changeset 59603 30cd47104ad7
parent 59592 99c8d2ff63eb
child 59637 8881c5d28f82
permissions -rw-r--r--
lucin: reorganise theories in ProgLang

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