test/Tools/isac/Knowledge/polyminus.sml
author wneuper <walther.neuper@jku.at>
Mon, 19 Apr 2021 15:02:00 +0200
changeset 60230 0ca0f9363ad3
parent 59997 46fe5a8c3911
child 60237 e534316f9e07
permissions -rw-r--r--
long identifiers for occurences in test/../termC.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.refine Vereinfache -------------------------";
    25 "----------- *** Problem.prep_input: 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 (TermC.str2term "12");
    36 case eval_ist_monom 0 0 (TermC.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 (TermC.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 (TermC.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 (TermC.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 (TermC.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 (TermC.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 (TermC.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 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
    70 Rewrite.trace_on:=false;
    71 val t = TermC.str2term "((a + d) + c) + b";
    72 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
    73 if UnparseC.term t = "a + (b + (c + d))" then ()
    74 else error "polyminus.sml 1 watch order_add_mult";
    75 Rewrite.trace_on:=false;
    76 
    77 "----- the same stepwise...";
    78 val od = ord_make_polynomial true (@{theory "Poly"});
    79 val t = TermC.str2term "((a + d) + c) + b";
    80 "((a + d) + c) + b"; 
    81 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
    82 "b + ((a + d) + c)";
    83 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
    84 "b + (c + (a + d))";
    85 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
    86 "b + (a + (c + d))";
    87 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
    88 "a + (b + (c + d))";
    89 if UnparseC.term 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 = TermC.str2term "a + (d + (c + b))";
    94 "a + (d + (c + b))";
    95 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
    96 "a + (c + (d + b))";
    97 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t;UnparseC.term t;
    98 "a + (c + (b + d))";
    99 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term 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 = TermC.str2term "((5*a + 4*d) + 3*c) + 2*b";
   105 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
   106 if UnparseC.term 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 = TermC.str2term "b + a + c + d";
   112 val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
   113 val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term 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 TermC.str2term "aaa";
   128 TermC.str2term "222 * aaa";
   129 
   130 case eval_kleiner 0 0 (TermC.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 (TermC.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 (TermC.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 (TermC.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 (TermC.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 (TermC.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 (TermC.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 = TermC.str2term "b + a";
   163 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
   164 if UnparseC.term t = "a + b" then ()
   165 else error "polyminus.sml: ordne_alphabetisch1 b + a";
   166 
   167 val erls = Atools_erls;
   168 val t = TermC.str2term "2*a + 3*a";
   169 val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; UnparseC.term t;
   170 
   171 "======= test rewrite_, rewrite_set_";
   172 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
   173 val erls = erls_ordne_alphabetisch;
   174 val t = TermC.str2term "b + a";
   175 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
   176 if UnparseC.term t = "a + b" then ()
   177 else error "polyminus.sml: ordne_alphabetisch a + b";
   178 
   179 val t = TermC.str2term "2*b + a";
   180 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
   181 if UnparseC.term t = "a + 2 * b" then ()
   182 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
   183 
   184 val t = TermC.str2term "a + c + b";
   185 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
   186 if UnparseC.term t = "a + b + c" then ()
   187 else error "polyminus.sml: ordne_alphabetisch a + b + c";
   188 
   189 "======= rewrite goes into subterms";
   190 val t = TermC.str2term "a + c + b + d";
   191 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; UnparseC.term t;
   192 if UnparseC.term t = "a + b + c + d" then ()
   193 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
   194 
   195 val t = TermC.str2term "a + c + d + b";
   196 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
   197 if UnparseC.term 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 = TermC.str2term "b + a + c + d";
   202 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
   203 if UnparseC.term 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 = TermC.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 UnparseC.term 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 = TermC.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 UnparseC.term 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 = TermC.str2term "3 + -2 * e + 2 * f + 2 * g";
   226 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
   227 if UnparseC.term t = "3 - 2 * e + 2 * f + 2 * g" then ()
   228 else error "polyminus.sml: verschoenere 3 + -2 * e ...";
   229 
   230 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
   231 Rewrite.trace_on:=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 (TermC.parse thy)) str;
   242 TermC.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" 
   267 then case nxt of End_Proof' => () | _ =>  error "me simplification.for_polynomials.with_minus 1"
   268 else error "polyminus.sml: me simplification.for_polynomials.with_minus 2";
   269 
   270 "----------- pbl polynom vereinfachen p.33 -----------------------";
   271 "----------- pbl polynom vereinfachen p.33 -----------------------";
   272 "----------- pbl polynom vereinfachen p.33 -----------------------";
   273 "----------- 140 c ---";
   274 reset_states ();
   275 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
   276 	    "normalform N"],
   277 	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
   278 	    ["simplification", "for_polynomials", "with_minus"]))];
   279 moveActiveRoot 1;
   280 autoCalculate 1 CompleteCalc;
   281 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   282 if p = ([], Res) andalso 
   283    UnparseC.term (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
   284 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
   285 
   286 "======= 140 d ---";
   287 reset_states ();
   288 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
   289 	    "normalform N"],
   290 	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
   291 	    ["simplification", "for_polynomials", "with_minus"]))];
   292 moveActiveRoot 1;
   293 autoCalculate 1 CompleteCalc;
   294 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   295 if p = ([], Res) andalso 
   296    UnparseC.term (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
   297 then () else error "polyminus.sml: Vereinfache 140 d)";
   298 
   299 "======= 139 c ---";
   300 reset_states ();
   301 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
   302 	    "normalform N"],
   303 	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
   304 	    ["simplification", "for_polynomials", "with_minus"]))];
   305 moveActiveRoot 1;
   306 autoCalculate 1 CompleteCalc;
   307 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   308 if p = ([], Res) andalso 
   309    UnparseC.term (get_obj g_res pt (fst p)) = "- (3 * f)"
   310 then () else error "polyminus.sml: Vereinfache 139 c)";
   311 
   312 "======= 139 b ---";
   313 reset_states ();
   314 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
   315 	    "normalform N"],
   316 	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
   317 	    ["simplification", "for_polynomials", "with_minus"]))];
   318 moveActiveRoot 1;
   319 autoCalculate 1 CompleteCalc;
   320 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   321 if p = ([], Res) andalso 
   322    UnparseC.term (get_obj g_res pt (fst p)) = "-3 * u - v"
   323 then () else error "polyminus.sml: Vereinfache 139 b)";
   324 
   325 "======= 138 a ---";
   326 reset_states ();
   327 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
   328 	    "normalform N"],
   329 	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
   330 	    ["simplification", "for_polynomials", "with_minus"]))];
   331 moveActiveRoot 1;
   332 autoCalculate 1 CompleteCalc;
   333 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   334 if p = ([], Res) andalso 
   335    UnparseC.term (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
   336 then () else error "polyminus.sml: Vereinfache 138 a)";
   337 
   338 "----------- met probe fuer_polynom ------------------------------";
   339 "----------- met probe fuer_polynom ------------------------------";
   340 "----------- met probe fuer_polynom ------------------------------";
   341 val str = 
   342 "Program ProbeScript (e_e::bool) (w_s::bool list) =\
   343 \ (let e_e = Take e_e;                             \
   344 \      e_e = Substitute w_s e_e                    \
   345 \ in (Repeat((Try (Repeat (Calculate ''TIMES''))) #>  \
   346 \            (Try (Repeat (Calculate ''PLUS''))) #>  \
   347 \            (Try (Repeat (Calculate ''MINUS''))))) e_e)"
   348 val sc = (inst_abs o Thm.term_of o the o (TermC.parse thy)) str;
   349 TermC.atomty sc;
   350 
   351 "----------- pbl polynom probe -----------------------------------";
   352 "----------- pbl polynom probe -----------------------------------";
   353 "----------- pbl polynom probe -----------------------------------";
   354 reset_states ();
   355 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
   356 	    \3 - 2 * e + 2 * f + 2 * (g::int))",
   357 	    "mitWert [e = (1::int), f = (2::int), g = (3::int)]",
   358 	    "Geprueft b"],
   359 	   ("PolyMinus",["polynom", "probe"],
   360 	    ["probe", "fuer_polynom"]))];
   361 moveActiveRoot 1;
   362 autoCalculate 1 CompleteCalc;
   363 (* autoCalculate 1 CompleteCalcHead;
   364    autoCalculate 1 (Steps 1);
   365    autoCalculate 1 (Steps 1);
   366    val ((pt,p),_) = get_calc 1; UnparseC.term (get_obj g_res pt (fst p));
   367 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
   368 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
   369 val ((pt,p),_) = get_calc 1;
   370 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "11 = 11"
   371 then () else error "polyminus.sml: Probe 11 = 11";
   372 Test_Tool.show_pt pt;
   373 
   374 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
   375 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
   376 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
   377 reset_states ();
   378 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
   379 	    "normalform N"],
   380 	   ("PolyMinus",["klammer", "polynom", "vereinfachen"],
   381 	    ["simplification", "for_polynomials", "with_parentheses"]))];
   382 moveActiveRoot 1;
   383 autoCalculate 1 CompleteCalc;
   384 val ((pt,p),_) = get_calc 1;
   385 if p = ([], Res) andalso 
   386    UnparseC.term (get_obj g_res pt (fst p)) = "1 + 14 * u"
   387 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
   388 Test_Tool.show_pt pt;
   389 
   390 "======= probe p.34 -----";
   391 reset_states ();
   392 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * (u::int))",
   393 	    "mitWert [u = (2::int)]",
   394 	    "Geprueft b"],
   395 	   ("PolyMinus",["polynom", "probe"],
   396 	    ["probe", "fuer_polynom"]))];
   397 moveActiveRoot 1;
   398 autoCalculate 1 CompleteCalc;
   399 val ((pt,p),_) = get_calc 1;
   400 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "29 = 29"
   401 then () else error "polyminus.sml: Probe 29 = 29";
   402 Test_Tool.show_pt pt;
   403 
   404 "----------- try fun applyTactics --------------------------------";
   405 "----------- try fun applyTactics --------------------------------";
   406 "----------- try fun applyTactics --------------------------------";
   407 reset_states ();
   408 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
   409 	    "normalform N"],
   410 	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
   411 	    ["simplification", "for_polynomials", "with_minus"]))];
   412 moveActiveRoot 1;
   413 autoCalculate 1 CompleteCalcHead;
   414 autoCalculate 1 (Steps 1);
   415 autoCalculate 1 (Steps 1);
   416 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   417 "----- 1 ^^^";
   418 fetchApplicableTactics 1 0 p;
   419 val appltacs = specific_from_prog pt p;
   420 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
   421 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   422 "----- 2 ^^^";
   423 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
   424 val erls = erls_ordne_alphabetisch;
   425 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
   426 val SOME (t',_) = 
   427     rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus} t;
   428 UnparseC.term t';     "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
   429 
   430 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
   431 val NONE = 
   432     rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
   433 
   434 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
   435 val SOME (t',_) = 
   436     rewrite_set_ (@{theory "Isac_Knowledge"}) false ordne_alphabetisch t;
   437 UnparseC.term t';     "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
   438 Rewrite.trace_on := false;
   439 
   440 
   441 applyTactic 1 p (hd (specific_from_prog pt p)) (*tausche_minus*);
   442 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   443 "----- 3 ^^^";
   444 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
   445 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   446 "----- 4 ^^^";
   447 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
   448 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   449 "----- 5 ^^^";
   450 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
   451 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   452 "----- 6 ^^^";
   453 
   454 (*<CALCMESSAGE> failure </CALCMESSAGE>
   455 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
   456 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   457 "----- 7 ^^^";
   458 *)
   459 autoCalculate 1 CompleteCalc;
   460 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   461 (*independent from failure above: met_simp_poly_minus not confluent:
   462 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
   463 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
   464 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
   465 
   466 
   467 "#############################################################################";
   468 reset_states ();
   469 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
   470 	    "normalform N"],
   471 	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
   472 	    ["simplification", "for_polynomials", "with_minus"]))];
   473 moveActiveRoot 1;
   474 autoCalculate 1 CompleteCalc;
   475 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   476 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "2 * g + h"
   477 then () else error "polyminus.sml: addiere_vor_minus";
   478 
   479 
   480 "#############################################################################";
   481 reset_states ();
   482 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
   483 	    "normalform N"],
   484 	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
   485 	    ["simplification", "for_polynomials", "with_minus"]))];
   486 moveActiveRoot 1;
   487 autoCalculate 1 CompleteCalc;
   488 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   489 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "f + 2 * g"
   490 then () else error "polyminus.sml: tausche_vor_plus";
   491 
   492 "----------- pbl binom polynom vereinfachen p.39 -----------------";
   493 "----------- pbl binom polynom vereinfachen p.39 -----------------";
   494 "----------- pbl binom polynom vereinfachen p.39 -----------------";
   495 val rls = klammern_ausmultiplizieren;
   496 val t = TermC.str2term "(3 * a + 2) * (4 * a - 1)";
   497 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
   498 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
   499 val rls = discard_parentheses;
   500 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
   501 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
   502 val rls = ordne_monome;
   503 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
   504 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
   505 (*
   506 val t = TermC.str2term "3 * a * 4 * a";
   507 val rls = ordne_monome;
   508 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
   509 *)
   510 val rls = klammern_aufloesen;
   511 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
   512 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
   513 val rls = ordne_alphabetisch;
   514 (*TODO: make is_monom more general, a*a=a^2, ...*)
   515 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
   516 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
   517 (*STOPPED.WN080104
   518 val rls = fasse_zusammen;
   519 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
   520 val rls = verschoenere;
   521 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
   522 *)
   523 
   524 (*@@@@@@@*)
   525 reset_states ();
   526 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
   527 	    "normalform N"],
   528 	   ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
   529 	    ["simplification", "for_polynomials", "with_parentheses_mult"]))];
   530 moveActiveRoot 1;
   531 autoCalculate 1 CompleteCalc;
   532 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   533 if p = ([], Res) andalso 
   534    UnparseC.term (get_obj g_res pt (fst p)) = "-2 + 12 * a ^^^ 2 + 5 * a"
   535 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
   536 
   537 "----------- pbl binom polynom vereinfachen: cube ----------------";
   538 "----------- pbl binom polynom vereinfachen: cube ----------------";
   539 "----------- pbl binom polynom vereinfachen: cube ----------------";
   540 reset_states ();
   541 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
   542 	   ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
   543 	    ["simplification", "for_polynomials", "with_parentheses_mult"]))];
   544 moveActiveRoot 1;
   545 autoCalculate 1 CompleteCalc;
   546 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
   547 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "12 * a - 16 * q" 
   548 then () else error "pbl binom polynom vereinfachen: cube";
   549 
   550 "----------- Refine.refine Vereinfache ----------------------------------";
   551 "----------- Refine.refine Vereinfache ----------------------------------";
   552 "----------- Refine.refine Vereinfache ----------------------------------";
   553 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"];
   554 (*default_print_depth 11;*)
   555 val TermC.matches = Refine.refine fmz ["vereinfachen"];
   556 (*default_print_depth 3;*)
   557 
   558 "----- go into details, if it seems not to work -----";
   559 "--- does the predicate evaluate correctly ?";
   560 val t = TermC.str2term 
   561 	    "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))";
   562 val ma = eval_matchsub "" "Prog_Expr.matchsub" t thy;
   563 case ma of
   564     SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
   565 	  \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
   566   | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
   567 
   568 "--- does the respective prls rewrite ?";
   569 val prls = Rule_Set.append_rules "prls_pbl_vereinf_poly" Rule_Set.empty 
   570 	     [Eval ("Poly.is'_polyexp", eval_is_polyexp ""),
   571 	      Eval ("Prog_Expr.matchsub", eval_matchsub ""),
   572 	      Thm ("or_true",@{thm or_true}),
   573 	      (*"(?a | True) = True"*)
   574 	      Thm ("or_false",@{thm or_false}),
   575 	      (*"(?a | False) = ?a"*)
   576 	      Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
   577 	      (*"(~ True) = False"*)
   578 	      Thm ("not_false",ThmC.numerals_to_Free @{thm not_false})
   579 	      (*"(~ False) = True"*)];
   580 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
   581 val SOME (t', _) = rewrite_set_ thy false prls t;
   582 Rewrite.trace_on := false;
   583 
   584 "--- does the respective prls rewrite the whole predicate ?";
   585 val t = TermC.str2term 
   586 	    "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
   587 	    \     matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
   588 	    \     matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
   589 	    \     matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
   590 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
   591 val SOME (t', _) = rewrite_set_ thy false prls t;
   592 Rewrite.trace_on := false;
   593 if UnparseC.term t' = "False" then ()
   594 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
   595 
   596 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
   597 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
   598 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
   599 (*see test/../termC.sml for details*)
   600 val t = TermC.parse_patt thy "t_t is_polyexp";
   601 val t = TermC.parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
   602 	                "     matchsub (?a + (?b - ?c)) t_t | " ^
   603 	                "     matchsub (?a - (?b + ?c)) t_t | " ^
   604 	                "     matchsub (?a + (?b - ?c)) t_t )");
   605 (*show_types := true;
   606 if UnparseC.term 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)"
   607 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
   608 show_types := false;*)
   609 if UnparseC.term t =
   610   "\<not> (matchsub (?a + (?b + ?c)) t_t \<or>\n        " ^
   611   "matchsub (?a + (?b - ?c)) t_t \<or>\n        " ^
   612   "matchsub (?a - (?b + ?c)) t_t \<or> " ^
   613   "matchsub (?a + (?b - ?c)) t_t)"
   614 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
   615