test/Tools/isac/Knowledge/polyminus.sml
author Walther Neuper <neuper@ist.tugraz.at>
Wed, 08 Sep 2010 16:47:22 +0200
branchisac-update-Isa09-2
changeset 37991 028442673981
parent 37982 66f3570ba808
child 38031 460c24a6a6ba
permissions -rw-r--r--
tuned src + test

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