test/Tools/isac/Knowledge/polyminus.sml
author Walther Neuper <neuper@ist.tugraz.at>
Fri, 01 Oct 2010 16:23:03 +0200
branchisac-update-Isa09-2
changeset 38037 a51a70334191
parent 38031 460c24a6a6ba
child 38038 d164e328db74
permissions -rw-r--r--
intermed. 'fun parse_patt' fixes types to real (like 'parse')

this was on the way to repair rewrite (prepat in Rrls)
     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 (*========== inhibit exn ?======================================================
    10 "--------------------------------------------------------";
    11 "--------------------------------------------------------";
    12 "table of contents --------------------------------------";
    13 "--------------------------------------------------------";
    14 "----------- fun eval_ist_monom -------------------------";
    15 "----------- watch order_add_mult  ----------------------";
    16 "----------- build predicate for +- ordering ------------";
    17 "----------- build fasse_zusammen -----------------------";
    18 "----------- build verschoenere -------------------------";
    19 "----------- met simplification for_polynomials with_minu";
    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 = PolyMinus.thy;
    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 Poly.thy;
    82 val t = str2term "((a + d) + c) + b";
    83 "((a + d) + c) + b"; 
    84 val SOME (t,_) = rewrite_ thy od e_rls true add_commute t; term2str t;
    85 "b + ((a + d) + c)";
    86 val SOME (t,_) = rewrite_ thy od e_rls true add_commute t; term2str t;
    87 "b + (c + (a + d))";
    88 val SOME (t,_) = rewrite_ thy od e_rls true add_left_commute t;term2str t;
    89 "b + (a + (c + d))";
    90 val SOME (t,_) = rewrite_ thy od e_rls true 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 add_left_commute t;term2str t;
    99 "a + (c + (d + b))";
   100 val SOME (t,_) = rewrite_ thy od e_rls true add_commute t;term2str t;
   101 "a + (c + (b + d))";
   102 val SOME (t,_) = rewrite_ thy od e_rls true 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 Poly.thy;
   114 val t = str2term "b + a + c + d";
   115 val SOME (t,_) = rewrite_ thy od e_rls false add_commute t; term2str t;
   116 val SOME (t,_) = rewrite_ thy od e_rls false 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 ("12 kleiner 9 = 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 
   162 
   163 "----- compare tausche_plus with real_num_collect";
   164 val od = dummy_ord;
   165 
   166 val erls = erls_ordne_alphabetisch;
   167 val t = str2term "b + a";
   168 val SOME (t,_) = rewrite_ thy od erls false tausche_plus t; term2str t;
   169 if term2str t = "a + b" then ()
   170 else error "polyminus.sml: ordne_alphabetisch1 b + a";
   171 
   172 val erls = Atools_erls;
   173 val t = str2term "2*a + 3*a";
   174 val SOME (t,_) = rewrite_ thy od erls false real_num_collect t; term2str t;
   175 
   176 "----- test rewrite_, rewrite_set_";
   177 trace_rewrite:=true;
   178 val erls = erls_ordne_alphabetisch;
   179 val t = str2term "b + a";
   180 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
   181 if term2str t = "a + b" then ()
   182 else error "polyminus.sml: ordne_alphabetisch a + b";
   183 
   184 val t = str2term "2*b + a";
   185 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
   186 if term2str t = "a + 2 * b" then ()
   187 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
   188 
   189 val t = str2term "a + c + b";
   190 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
   191 if term2str t = "a + b + c" then ()
   192 else error "polyminus.sml: ordne_alphabetisch a + b + c";
   193 
   194 "----- rewrite goes into subterms";
   195 val t = str2term "a + c + b + d";
   196 val SOME (t,_) = rewrite_ thy od erls false tausche_plus_plus t; term2str t;
   197 if term2str t = "a + b + c + d" then ()
   198 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
   199 
   200 val t = str2term "a + c + d + b";
   201 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
   202 if term2str t = "a + b + c + d" then ()
   203 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
   204 
   205 "----- here we see rew_sub going into subterm with cond.rew....";
   206 val t = str2term "b + a + c + d";
   207 val SOME (t,_) = rewrite_ thy od erls false tausche_plus t; term2str t;
   208 if term2str t = "a + b + c + d" then ()
   209 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
   210 
   211 "----- compile rls for the most complicated terms";
   212 val t = str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
   213 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
   214 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; 
   215 if term2str t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
   216 then () else error "polyminus.sml: ordne_alphabetisch finished";
   217 
   218 
   219 "----------- build fasse_zusammen --------------------------------";
   220 "----------- build fasse_zusammen --------------------------------";
   221 "----------- build fasse_zusammen --------------------------------";
   222 val t = str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
   223 val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
   224 if term2str t = "3 + -2 * e + 2 * f + 2 * g" then ()
   225 else error "polyminus.sml: fasse_zusammen finished";
   226 
   227 "----------- build verschoenere ----------------------------------";
   228 "----------- build verschoenere ----------------------------------";
   229 "----------- build verschoenere ----------------------------------";
   230 val t = str2term "3 + -2 * e + 2 * f + 2 * g";
   231 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
   232 if term2str t = "3 - 2 * e + 2 * f + 2 * g" then ()
   233 else error "polyminus.sml: verschoenere 3 + -2 * e ...";
   234 
   235 trace_rewrite:=true;
   236 trace_rewrite:=false;
   237 
   238 "----------- met simplification for_polynomials with_minus -------";
   239 "----------- met simplification for_polynomials with_minus -------";
   240 "----------- met simplification for_polynomials with_minus -------";
   241 val str = 
   242 "Script SimplifyScript (t_::real) =                \
   243 \  (((Try (Rewrite_Set ordne_alphabetisch False)) @@     \
   244 \    (Try (Rewrite_Set fasse_zusammen False)) @@     \
   245 \    (Try (Rewrite_Set verschoenere False))) t_)"
   246 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
   247 atomty sc;
   248 
   249 
   250 "----------- pbl polynom vereinfachen p.33 -----------------------";
   251 "----------- pbl polynom vereinfachen p.33 -----------------------";
   252 "----------- pbl polynom vereinfachen p.33 -----------------------";
   253 "----------- 140 c ---";
   254 states:=[];
   255 CalcTree [(["TERM (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
   256 	    "normalform N"],
   257 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   258 	    ["simplification","for_polynomials","with_minus"]))];
   259 moveActiveRoot 1;
   260 autoCalculate 1 CompleteCalc;
   261 val ((pt,p),_) = get_calc 1; show_pt pt;
   262 if p = ([], Res) andalso 
   263    term2str (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
   264 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
   265 
   266 "----------- 140 d ---";
   267 states:=[];
   268 CalcTree [(["TERM (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
   269 	    "normalform N"],
   270 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   271 	    ["simplification","for_polynomials","with_minus"]))];
   272 moveActiveRoot 1;
   273 autoCalculate 1 CompleteCalc;
   274 val ((pt,p),_) = get_calc 1; show_pt pt;
   275 if p = ([], Res) andalso 
   276    term2str (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
   277 then () else error "polyminus.sml: Vereinfache 140 d)";
   278 
   279 
   280 "----------- 139 c ---";
   281 states:=[];
   282 CalcTree [(["TERM (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
   283 	    "normalform N"],
   284 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   285 	    ["simplification","for_polynomials","with_minus"]))];
   286 moveActiveRoot 1;
   287 autoCalculate 1 CompleteCalc;
   288 val ((pt,p),_) = get_calc 1; show_pt pt;
   289 if p = ([], Res) andalso 
   290    term2str (get_obj g_res pt (fst p)) = "- (3 * f)"
   291 then () else error "polyminus.sml: Vereinfache 139 c)";
   292 
   293 "----------- 139 b ---";
   294 states:=[];
   295 CalcTree [(["TERM (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
   296 	    "normalform N"],
   297 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   298 	    ["simplification","for_polynomials","with_minus"]))];
   299 moveActiveRoot 1;
   300 autoCalculate 1 CompleteCalc;
   301 val ((pt,p),_) = get_calc 1; show_pt pt;
   302 if p = ([], Res) andalso 
   303    term2str (get_obj g_res pt (fst p)) = "-3 * u - v"
   304 then () else error "polyminus.sml: Vereinfache 139 b)";
   305 
   306 "----------- 138 a ---";
   307 states:=[];
   308 CalcTree [(["TERM (2*u - 3*v - 6*u + 5*v)",
   309 	    "normalform N"],
   310 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   311 	    ["simplification","for_polynomials","with_minus"]))];
   312 moveActiveRoot 1;
   313 autoCalculate 1 CompleteCalc;
   314 val ((pt,p),_) = get_calc 1; show_pt pt;
   315 if p = ([], Res) andalso 
   316    term2str (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
   317 then () else error "polyminus.sml: Vereinfache 138 a)";
   318 
   319 
   320 "----------- met probe fuer_polynom ------------------------------";
   321 "----------- met probe fuer_polynom ------------------------------";
   322 "----------- met probe fuer_polynom ------------------------------";
   323 val str = 
   324 "Script ProbeScript (e_e::bool) (ws_::bool list) =\
   325 \ (let e_e = Take e_e;                             \
   326 \      e_e = Substitute ws_ e_e                    \
   327 \ in (Repeat((Try (Repeat (Calculate TIMES))) @@  \
   328 \            (Try (Repeat (Calculate PLUS ))) @@  \
   329 \            (Try (Repeat (Calculate MINUS))))) e_e)"
   330 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
   331 atomty sc;
   332 
   333 
   334 "----------- pbl polynom probe -----------------------------------";
   335 "----------- pbl polynom probe -----------------------------------";
   336 "----------- pbl polynom probe -----------------------------------";
   337 states:=[];
   338 CalcTree [(["Pruefe (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
   339 	    \3 - 2 * e + 2 * f + 2 * g)",
   340 	    "mitWert [e = 1, f = 2, g = 3]",
   341 	    "Geprueft b"],
   342 	   ("PolyMinus",["polynom","probe"],
   343 	    ["probe","fuer_polynom"]))];
   344 moveActiveRoot 1;
   345 autoCalculate 1 CompleteCalc;
   346 (* autoCalculate 1 CompleteCalcHead;
   347    autoCalculate 1 (Step 1);
   348    autoCalculate 1 (Step 1);
   349    val ((pt,p),_) = get_calc 1; term2str (get_obj g_res pt (fst p));
   350 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
   351 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
   352 val ((pt,p),_) = get_calc 1;
   353 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "11 = 11"
   354 then () else error "polyminus.sml: Probe 11 = 11";
   355 show_pt pt;
   356 
   357 
   358 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
   359 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
   360 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
   361 states:=[];
   362 CalcTree [(["TERM (2*u - 5 - (3 - 4*u) + (8*u + 9))",
   363 	    "normalform N"],
   364 	   ("PolyMinus",["klammer","polynom","vereinfachen"],
   365 	    ["simplification","for_polynomials","with_parentheses"]))];
   366 moveActiveRoot 1;
   367 autoCalculate 1 CompleteCalc;
   368 val ((pt,p),_) = get_calc 1;
   369 if p = ([], Res) andalso 
   370    term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
   371 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
   372 show_pt pt;
   373 
   374 "----- probe p.34 -----";
   375 states:=[];
   376 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * u)",
   377 	    "mitWert [u = 2]",
   378 	    "Geprueft b"],
   379 	   ("PolyMinus",["polynom","probe"],
   380 	    ["probe","fuer_polynom"]))];
   381 moveActiveRoot 1;
   382 autoCalculate 1 CompleteCalc;
   383 val ((pt,p),_) = get_calc 1;
   384 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "29 = 29"
   385 then () else error "polyminus.sml: Probe 29 = 29";
   386 show_pt pt;
   387 
   388 
   389 "----------- try fun applyTactics --------------------------------";
   390 "----------- try fun applyTactics --------------------------------";
   391 "----------- try fun applyTactics --------------------------------";
   392 states:=[];
   393 CalcTree [(["TERM (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
   394 	    "normalform N"],
   395 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   396 	    ["simplification","for_polynomials","with_minus"]))];
   397 moveActiveRoot 1;
   398 autoCalculate 1 CompleteCalcHead;
   399 autoCalculate 1 (Step 1);
   400 autoCalculate 1 (Step 1);
   401 val ((pt,p),_) = get_calc 1; show_pt pt;
   402 "----- 1 ^^^";
   403 fetchApplicableTactics 1 0 p;
   404 val appltacs = sel_appl_atomic_tacs pt p;
   405 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
   406 val ((pt,p),_) = get_calc 1; show_pt pt;
   407 "----- 2 ^^^";
   408 trace_rewrite := true;
   409 val erls = erls_ordne_alphabetisch;
   410 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
   411 val SOME (t',_) = 
   412     rewrite_ Isac.thy e_rew_ord erls false tausche_minus t;
   413 term2str t';     "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
   414 
   415 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
   416 val NONE = 
   417     rewrite_ Isac.thy e_rew_ord erls false tausche_minus_plus t;
   418 
   419 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
   420 val SOME (t',_) = 
   421     rewrite_set_ Isac.thy false ordne_alphabetisch t;
   422 term2str t';     "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
   423 trace_rewrite := false;
   424 
   425 
   426 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (*tausche_minus*);
   427 val ((pt,p),_) = get_calc 1; show_pt pt;
   428 "----- 3 ^^^";
   429 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
   430 val ((pt,p),_) = get_calc 1; show_pt pt;
   431 "----- 4 ^^^";
   432 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
   433 val ((pt,p),_) = get_calc 1; show_pt pt;
   434 "----- 5 ^^^";
   435 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
   436 val ((pt,p),_) = get_calc 1; show_pt pt;
   437 "----- 6 ^^^";
   438 
   439 (*<CALCMESSAGE> failure </CALCMESSAGE>
   440 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
   441 val ((pt,p),_) = get_calc 1; show_pt pt;
   442 "----- 7 ^^^";
   443 *)
   444 
   445 autoCalculate 1 CompleteCalc;
   446 val ((pt,p),_) = get_calc 1; show_pt pt;
   447 (*independent from failure above: met_simp_poly_minus not confluent:
   448 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
   449 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
   450 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
   451 
   452 states:=[];
   453 CalcTree [(["TERM (- (8 * g) + 10 * g + h)",
   454 	    "normalform N"],
   455 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   456 	    ["simplification","for_polynomials","with_minus"]))];
   457 moveActiveRoot 1;
   458 autoCalculate 1 CompleteCalc;
   459 val ((pt,p),_) = get_calc 1; show_pt pt;
   460 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "2 * g + h"
   461 then () else error "polyminus.sml: addiere_vor_minus";
   462 
   463 
   464 states:=[];
   465 CalcTree [(["TERM (- (8 * g) + 10 * g + f)",
   466 	    "normalform N"],
   467 	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   468 	    ["simplification","for_polynomials","with_minus"]))];
   469 moveActiveRoot 1;
   470 autoCalculate 1 CompleteCalc;
   471 val ((pt,p),_) = get_calc 1; show_pt pt;
   472 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "f + 2 * g"
   473 then () else error "polyminus.sml: tausche_vor_plus";
   474 
   475 
   476 "----------- pbl binom polynom vereinfachen p.39 -----------------";
   477 "----------- pbl binom polynom vereinfachen p.39 -----------------";
   478 "----------- pbl binom polynom vereinfachen p.39 -----------------";
   479 val rls = klammern_ausmultiplizieren;
   480 val t = str2term "(3 * a + 2) * (4 * a - 1)";
   481 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   482 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
   483 val rls = discard_parentheses;
   484 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   485 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
   486 val rls = ordne_monome;
   487 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   488 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
   489 (*
   490 val t = str2term "3 * a * 4 * a";
   491 val rls = ordne_monome;
   492 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   493 *)
   494 val rls = klammern_aufloesen;
   495 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   496 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
   497 val rls = ordne_alphabetisch;
   498 (*TODO: make is_monom more general, a*a=a^2, ...*)
   499 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   500 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
   501 (*GOON.WN080104
   502 val rls = fasse_zusammen;
   503 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   504 val rls = verschoenere;
   505 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
   506 *)
   507 
   508 
   509 trace_rewrite := true;
   510 trace_rewrite := false;
   511 
   512 (*@@@@@@@*)
   513 states:=[];
   514 CalcTree [(["TERM ((3*a + 2) * (4*a - 1))",
   515 	    "normalform N"],
   516 	   ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
   517 	    ["simplification","for_polynomials","with_parentheses_mult"]))];
   518 moveActiveRoot 1;
   519 autoCalculate 1 CompleteCalc;
   520 val ((pt,p),_) = get_calc 1; show_pt pt;
   521 
   522 (*
   523 if p = ([], Res) andalso 
   524    term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
   525 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
   526 *)
   527 
   528 
   529 "----------- pbl binom polynom vereinfachen: cube ----------------";
   530 "----------- pbl binom polynom vereinfachen: cube ----------------";
   531 "----------- pbl binom polynom vereinfachen: cube ----------------";
   532 states:=[];
   533 CalcTree [(["TERM (8*(a - q) + a - 2*q + 3*(a - 2*q))",
   534 	    "normalform N"],
   535 	   ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
   536 	    ["simplification","for_polynomials","with_parentheses_mult"]))];
   537 moveActiveRoot 1;
   538 autoCalculate 1 CompleteCalc;
   539 val ((pt,p),_) = get_calc 1; show_pt pt;
   540 
   541 
   542 "----------- refine Vereinfache ----------------------------------";
   543 "----------- refine Vereinfache ----------------------------------";
   544 "----------- refine Vereinfache ----------------------------------";
   545 val fmz = ["TERM (8*(a - q) + a - 2*q + 3*(a - 2*q))",
   546 	    "normalform N"];
   547 print_depth 11;
   548 val matches = refine fmz ["vereinfachen"];
   549 print_depth 3;
   550 
   551 "----- go into details, if it seems not to work -----";
   552 "--- does the predicate evaluate correctly ?";
   553 val t = str2term 
   554 	    "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + \
   555 	    \3 * (a - 2 * q))";
   556 val ma = eval_matchsub "" "Tools.matchsub" t thy;
   557 case ma of
   558     SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
   559 	  \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
   560   | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
   561 
   562 "--- does the respective prls rewrite ?";
   563 val prls = append_rls "prls_pbl_vereinf_poly" e_rls 
   564 	     [Calc ("Poly.is'_polyexp", eval_is_polyexp ""),
   565 	      Calc ("Tools.matchsub", eval_matchsub ""),
   566 	      Thm ("or_true",or_true),
   567 	      (*"(?a | True) = True"*)
   568 	      Thm ("or_false",or_false),
   569 	      (*"(?a | False) = ?a"*)
   570 	      Thm ("not_true",num_str @{thm not_true}),
   571 	      (*"(~ True) = False"*)
   572 	      Thm ("not_false",num_str @{thm not_false})
   573 	      (*"(~ False) = True"*)];
   574 trace_rewrite := true;
   575 val SOME (t', _) = rewrite_set_ thy false prls t;
   576 trace_rewrite := false;
   577 
   578 "--- does the respective prls rewrite the whole predicate ?";
   579 val t = str2term 
   580 	    "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
   581 	    \     matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
   582 	    \     matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
   583 	    \     matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
   584 trace_rewrite := true;
   585 val SOME (t', _) = rewrite_set_ thy false prls t;
   586 trace_rewrite := false;
   587 if term2str t' = "False" then ()
   588 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
   589 
   590 ============ inhibit exn ?====================================================*)
   591 
   592 
   593 "----------- *** prep_pbt: syntax error in '#Where' of [v";
   594 "----------- *** prep_pbt: syntax error in '#Where' of [v";
   595 "----------- *** prep_pbt: syntax error in '#Where' of [v";
   596 (*see test/../termC.sml for details*)
   597 val t = parse_patt thy "t_t is_polyexp";
   598 val t = parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
   599 	                "     matchsub (?a + (?b - ?c)) t_t | " ^
   600 	                "     matchsub (?a - (?b + ?c)) t_t | " ^
   601 	                "     matchsub (?a + (?b - ?c)) t_t )");
   602 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)"
   603 then () else error "polyminus.sml type-structure of \"?a :: real\" changed";
   604 show_types := false;
   605 
   606 "===== deconstruct datatype typ ===";
   607 val str = "?a";
   608 val t = (thy, str) |>> thy2ctxt 
   609                    |-> ProofContext.read_term_pattern
   610                    |> numbers_to_string;
   611 val Var (("a", 0), ty) = t;
   612 val TVar ((str, i), srt) = ty;
   613 if str = "'a" andalso i = 1 andalso srt = [] then ()
   614 else error "termC.sml type-structure of \"?a\" changed";
   615 
   616 "----- real type in pattern ---";
   617 val str = "?a :: real";
   618 val t = (thy, str) |>> thy2ctxt 
   619                    |-> ProofContext.read_term_pattern
   620                    |> numbers_to_string;
   621 val Var (("a", 0), ty) = t;
   622 val Type (str, tys) = ty;
   623 if str = "RealDef.real" andalso tys = [] andalso ty = HOLogic.realT then ()
   624 else error "termC.sml type-structure of \"?a :: real\" changed";
   625 
   626 "===== Not (matchsub (?a + (?b + ?c)) t_t |... ===";
   627 val (thy, str) = (thy, "Not (matchsub (?a + (?b + ?c)) t_t | " ^
   628 	               "     matchsub (?a + (?b - ?c)) t_t | " ^
   629 	               "     matchsub (?a - (?b + ?c)) t_t | " ^
   630 	               "     matchsub (?a + (?b - ?c)) t_t )");
   631 "----- read_term_pattern ---";
   632 val t = (thy, str) |>> thy2ctxt 
   633                    |-> ProofContext.read_term_pattern
   634                    |> numbers_to_string;
   635 show_types := true;
   636 val t1 = typ_a2real t;
   637 if term2str t1 = "~ (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)"
   638 then () else error "termC.sml type-structure of \"?a :: real\" changed expl";
   639 show_types := false;
   640 
   641 (*========== inhibit exn =======================================================
   642 ============ inhibit exn =====================================================*)
   643 
   644 (*-.-.-.-.-.-isolate response.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
   645 -.-.-.-.-.-.-isolate response.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*)