1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/Tools/isac/IsacKnowledge/polyminus.sml Thu Aug 12 11:02:32 2010 +0200
1.3 @@ -0,0 +1,598 @@
1.4 +(* tests on PolyMinus
1.5 + author: Walther Neuper
1.6 + WN071207,
1.7 + (c) due to copyright terms
1.8 +
1.9 +use"../smltest/IsacKnowledge/polyminus.sml";
1.10 +use"polyminus.sml";
1.11 +*)
1.12 +val thy = PolyMinus.thy;
1.13 +
1.14 +"-----------------------------------------------------------------";
1.15 +"table of contents -----------------------------------------------";
1.16 +"-----------------------------------------------------------------";
1.17 +"----------- fun eval_ist_monom ----------------------------------";
1.18 +"----------- watch order_add_mult -------------------------------";
1.19 +"----------- build predicate for +- ordering ---------------------";
1.20 +"----------- build fasse_zusammen --------------------------------";
1.21 +"----------- build verschoenere ----------------------------------";
1.22 +"----------- met simplification for_polynomials with_minus -------";
1.23 +"----------- pbl polynom vereinfachen p.33 -----------------------";
1.24 +"----------- met probe fuer_polynom ------------------------------";
1.25 +"----------- pbl polynom probe -----------------------------------";
1.26 +"----------- pbl klammer polynom vereinfachen p.34 ---------------";
1.27 +"----------- try fun applyTactics --------------------------------";
1.28 +"----------- pbl binom polynom vereinfachen p.39 -----------------";
1.29 +"----------- pbl binom polynom vereinfachen: cube ----------------";
1.30 +"----------- refine Vereinfache ----------------------------------";
1.31 +"-----------------------------------------------------------------";
1.32 +"-----------------------------------------------------------------";
1.33 +"-----------------------------------------------------------------";
1.34 +
1.35 +
1.36 +"----------- fun eval_ist_monom ----------------------------------";
1.37 +"----------- fun eval_ist_monom ----------------------------------";
1.38 +"----------- fun eval_ist_monom ----------------------------------";
1.39 +ist_monom (str2term "12");
1.40 +case eval_ist_monom 0 0 (str2term "12 ist_monom") 0 of
1.41 + Some ("12 ist_monom = True", _) => ()
1.42 + | _ => raise error "polyminus.sml: 12 ist_monom = True";
1.43 +
1.44 +case eval_ist_monom 0 0 (str2term "a ist_monom") 0 of
1.45 + Some ("a ist_monom = True", _) => ()
1.46 + | _ => raise error "polyminus.sml: a ist_monom = True";
1.47 +
1.48 +case eval_ist_monom 0 0 (str2term "(3*a) ist_monom") 0 of
1.49 + Some ("3 * a ist_monom = True", _) => ()
1.50 + | _ => raise error "polyminus.sml: 3 * a ist_monom = True";
1.51 +
1.52 +case eval_ist_monom 0 0 (str2term "(a^^^2) ist_monom") 0 of
1.53 + Some ("a ^^^ 2 ist_monom = True", _) => ()
1.54 + | _ => raise error "polyminus.sml: a^^^2 ist_monom = True";
1.55 +
1.56 +case eval_ist_monom 0 0 (str2term "(3*a^^^2) ist_monom") 0 of
1.57 + Some ("3 * a ^^^ 2 ist_monom = True", _) => ()
1.58 + | _ => raise error "polyminus.sml: 3*a^^^2 ist_monom = True";
1.59 +
1.60 +case eval_ist_monom 0 0 (str2term "(a*b) ist_monom") 0 of
1.61 + Some ("a * b ist_monom = True", _) => ()
1.62 + | _ => raise error "polyminus.sml: a*b ist_monom = True";
1.63 +
1.64 +case eval_ist_monom 0 0 (str2term "(3*a*b) ist_monom") 0 of
1.65 + Some ("3 * a * b ist_monom = True", _) => ()
1.66 + | _ => raise error "polyminus.sml: 3*a*b ist_monom = True";
1.67 +
1.68 +
1.69 +"----------- watch order_add_mult -------------------------------";
1.70 +"----------- watch order_add_mult -------------------------------";
1.71 +"----------- watch order_add_mult -------------------------------";
1.72 +"----- with these simple variables it works...";
1.73 +trace_rewrite:=true;
1.74 +trace_rewrite:=false;
1.75 +val t = str2term "((a + d) + c) + b";
1.76 +val Some (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
1.77 +if term2str t = "a + (b + (c + d))" then ()
1.78 +else raise error "polyminus.sml 1 watch order_add_mult";
1.79 +trace_rewrite:=false;
1.80 +
1.81 +"----- the same stepwise...";
1.82 +val od = ord_make_polynomial true Poly.thy;
1.83 +val t = str2term "((a + d) + c) + b";
1.84 +"((a + d) + c) + b";
1.85 +val Some (t,_) = rewrite_ thy od e_rls true real_add_commute t; term2str t;
1.86 +"b + ((a + d) + c)";
1.87 +val Some (t,_) = rewrite_ thy od e_rls true real_add_commute t; term2str t;
1.88 +"b + (c + (a + d))";
1.89 +val Some (t,_) = rewrite_ thy od e_rls true real_add_left_commute t;term2str t;
1.90 +"b + (a + (c + d))";
1.91 +val Some (t,_) = rewrite_ thy od e_rls true real_add_left_commute t;term2str t;
1.92 +"a + (b + (c + d))";
1.93 +if term2str t = "a + (b + (c + d))" then ()
1.94 +else raise error "polyminus.sml 2 watch order_add_mult";
1.95 +
1.96 +"----- if parentheses are right, left_commute is (almost) sufficient...";
1.97 +val t = str2term "a + (d + (c + b))";
1.98 +"a + (d + (c + b))";
1.99 +val Some (t,_) = rewrite_ thy od e_rls true real_add_left_commute t;term2str t;
1.100 +"a + (c + (d + b))";
1.101 +val Some (t,_) = rewrite_ thy od e_rls true real_add_commute t;term2str t;
1.102 +"a + (c + (b + d))";
1.103 +val Some (t,_) = rewrite_ thy od e_rls true real_add_left_commute t;term2str t;
1.104 +"a + (b + (c + d))";
1.105 +
1.106 +"----- but we do not want the parentheses at right; thus: cond.rew.";
1.107 +"WN0712707 complicated monomials do not yet work ...";
1.108 +val t = str2term "((5*a + 4*d) + 3*c) + 2*b";
1.109 +val Some (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
1.110 +if term2str t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
1.111 +else raise error "polyminus.sml: order_add_mult changed";
1.112 +
1.113 +"----- here we see rew_sub going into subterm with ord.rew....";
1.114 +val od = ord_make_polynomial false Poly.thy;
1.115 +val t = str2term "b + a + c + d";
1.116 +val Some (t,_) = rewrite_ thy od e_rls false real_add_commute t; term2str t;
1.117 +val Some (t,_) = rewrite_ thy od e_rls false real_add_commute t; term2str t;
1.118 +(*@@@ rew_sub gosub: t = d + (b + a + c)
1.119 + @@@ rew_sub begin: t = b + a + c*)
1.120 +
1.121 +
1.122 +"----------- build predicate for +- ordering ---------------------";
1.123 +"----------- build predicate for +- ordering ---------------------";
1.124 +"----------- build predicate for +- ordering ---------------------";
1.125 +"a" < "b";
1.126 +"ba" < "ab";
1.127 +"123" < "a"; (*unused due to ---vvv*)
1.128 +"12" < "3"; (*true !!!*)
1.129 +
1.130 +" a kleiner b ==> (b + a) = (a + b)";
1.131 +str2term "aaa";
1.132 +str2term "222 * aaa";
1.133 +(*
1.134 +case eval_kleiner 0 0 (str2term "123 kleiner 32") 0 of
1.135 + Some ("12 kleiner 9 = False", _) => ()
1.136 + | _ => raise error "polyminus.sml: 12 kleiner 9 = False";
1.137 +*)
1.138 +case eval_kleiner 0 0 (str2term "a kleiner b") 0 of
1.139 + Some ("a kleiner b = True", _) => ()
1.140 + | _ => raise error "polyminus.sml: a kleiner b = True";
1.141 +
1.142 +case eval_kleiner 0 0 (str2term "(10*g) kleiner f") 0 of
1.143 + Some ("10 * g kleiner f = False", _) => ()
1.144 + | _ => raise error "polyminus.sml: 10 * g kleiner f = False";
1.145 +
1.146 +case eval_kleiner 0 0 (str2term "(a^^^2) kleiner b") 0 of
1.147 + Some ("a ^^^ 2 kleiner b = True", _) => ()
1.148 + | _ => raise error "polyminus.sml: a ^^^ 2 kleiner b = True";
1.149 +
1.150 +case eval_kleiner 0 0 (str2term "(3*a^^^2) kleiner b") 0 of
1.151 + Some ("3 * a ^^^ 2 kleiner b = True", _) => ()
1.152 + | _ => raise error "polyminus.sml: 3 * a ^^^ 2 kleiner b = True";
1.153 +
1.154 +case eval_kleiner 0 0 (str2term "(a*b) kleiner c") 0 of
1.155 + Some ("a * b kleiner c = True", _) => ()
1.156 + | _ => raise error "polyminus.sml: a * b kleiner b = True";
1.157 +
1.158 +case eval_kleiner 0 0 (str2term "(3*a*b) kleiner c") 0 of
1.159 + Some ("3 * a * b kleiner c = True", _) => ()
1.160 + | _ => raise error "polyminus.sml: 3 * a * b kleiner b = True";
1.161 +
1.162 +
1.163 +
1.164 +"----- compare tausche_plus with real_num_collect";
1.165 +val od = dummy_ord;
1.166 +
1.167 +val erls = erls_ordne_alphabetisch;
1.168 +val t = str2term "b + a";
1.169 +val Some (t,_) = rewrite_ thy od erls false tausche_plus t; term2str t;
1.170 +if term2str t = "a + b" then ()
1.171 +else raise error "polyminus.sml: ordne_alphabetisch1 b + a";
1.172 +
1.173 +val erls = Atools_erls;
1.174 +val t = str2term "2*a + 3*a";
1.175 +val Some (t,_) = rewrite_ thy od erls false real_num_collect t; term2str t;
1.176 +
1.177 +"----- test rewrite_, rewrite_set_";
1.178 +trace_rewrite:=true;
1.179 +val erls = erls_ordne_alphabetisch;
1.180 +val t = str2term "b + a";
1.181 +val Some (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
1.182 +if term2str t = "a + b" then ()
1.183 +else raise error "polyminus.sml: ordne_alphabetisch a + b";
1.184 +
1.185 +val t = str2term "2*b + a";
1.186 +val Some (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
1.187 +if term2str t = "a + 2 * b" then ()
1.188 +else raise error "polyminus.sml: ordne_alphabetisch a + 2 * b";
1.189 +
1.190 +val t = str2term "a + c + b";
1.191 +val Some (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
1.192 +if term2str t = "a + b + c" then ()
1.193 +else raise error "polyminus.sml: ordne_alphabetisch a + b + c";
1.194 +
1.195 +"----- rewrite goes into subterms";
1.196 +val t = str2term "a + c + b + d";
1.197 +val Some (t,_) = rewrite_ thy od erls false tausche_plus_plus t; term2str t;
1.198 +if term2str t = "a + b + c + d" then ()
1.199 +else raise error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
1.200 +
1.201 +val t = str2term "a + c + d + b";
1.202 +val Some (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
1.203 +if term2str t = "a + b + c + d" then ()
1.204 +else raise error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
1.205 +
1.206 +"----- here we see rew_sub going into subterm with cond.rew....";
1.207 +val t = str2term "b + a + c + d";
1.208 +val Some (t,_) = rewrite_ thy od erls false tausche_plus t; term2str t;
1.209 +if term2str t = "a + b + c + d" then ()
1.210 +else raise error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
1.211 +
1.212 +"----- compile rls for the most complicated terms";
1.213 +val t = str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
1.214 +"5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
1.215 +val Some (t,_) = rewrite_set_ thy false ordne_alphabetisch t;
1.216 +if term2str t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
1.217 +then () else raise error "polyminus.sml: ordne_alphabetisch finished";
1.218 +
1.219 +
1.220 +"----------- build fasse_zusammen --------------------------------";
1.221 +"----------- build fasse_zusammen --------------------------------";
1.222 +"----------- build fasse_zusammen --------------------------------";
1.223 +val t = str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
1.224 +val Some (t,_) = rewrite_set_ thy false fasse_zusammen t;
1.225 +if term2str t = "3 + -2 * e + 2 * f + 2 * g" then ()
1.226 +else raise error "polyminus.sml: fasse_zusammen finished";
1.227 +
1.228 +"----------- build verschoenere ----------------------------------";
1.229 +"----------- build verschoenere ----------------------------------";
1.230 +"----------- build verschoenere ----------------------------------";
1.231 +val t = str2term "3 + -2 * e + 2 * f + 2 * g";
1.232 +val Some (t,_) = rewrite_set_ thy false verschoenere t;
1.233 +if term2str t = "3 - 2 * e + 2 * f + 2 * g" then ()
1.234 +else raise error "polyminus.sml: verschoenere 3 + -2 * e ...";
1.235 +
1.236 +trace_rewrite:=true;
1.237 +trace_rewrite:=false;
1.238 +
1.239 +"----------- met simplification for_polynomials with_minus -------";
1.240 +"----------- met simplification for_polynomials with_minus -------";
1.241 +"----------- met simplification for_polynomials with_minus -------";
1.242 +val str =
1.243 +"Script SimplifyScript (t_::real) = \
1.244 +\ (((Try (Rewrite_Set ordne_alphabetisch False)) @@ \
1.245 +\ (Try (Rewrite_Set fasse_zusammen False)) @@ \
1.246 +\ (Try (Rewrite_Set verschoenere False))) t_)"
1.247 +val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
1.248 +atomty sc;
1.249 +
1.250 +
1.251 +"----------- pbl polynom vereinfachen p.33 -----------------------";
1.252 +"----------- pbl polynom vereinfachen p.33 -----------------------";
1.253 +"----------- pbl polynom vereinfachen p.33 -----------------------";
1.254 +"----------- 140 c ---";
1.255 +states:=[];
1.256 +CalcTree [(["term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
1.257 + "normalform N"],
1.258 + ("PolyMinus.thy",["plus_minus","polynom","vereinfachen"],
1.259 + ["simplification","for_polynomials","with_minus"]))];
1.260 +moveActiveRoot 1;
1.261 +autoCalculate 1 CompleteCalc;
1.262 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.263 +if p = ([], Res) andalso
1.264 + term2str (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
1.265 +then () else raise error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
1.266 +
1.267 +"----------- 140 d ---";
1.268 +states:=[];
1.269 +CalcTree [(["term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
1.270 + "normalform N"],
1.271 + ("PolyMinus.thy",["plus_minus","polynom","vereinfachen"],
1.272 + ["simplification","for_polynomials","with_minus"]))];
1.273 +moveActiveRoot 1;
1.274 +autoCalculate 1 CompleteCalc;
1.275 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.276 +if p = ([], Res) andalso
1.277 + term2str (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
1.278 +then () else raise error "polyminus.sml: Vereinfache 140 d)";
1.279 +
1.280 +
1.281 +"----------- 139 c ---";
1.282 +states:=[];
1.283 +CalcTree [(["term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
1.284 + "normalform N"],
1.285 + ("PolyMinus.thy",["plus_minus","polynom","vereinfachen"],
1.286 + ["simplification","for_polynomials","with_minus"]))];
1.287 +moveActiveRoot 1;
1.288 +autoCalculate 1 CompleteCalc;
1.289 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.290 +if p = ([], Res) andalso
1.291 + term2str (get_obj g_res pt (fst p)) = "- (3 * f)"
1.292 +then () else raise error "polyminus.sml: Vereinfache 139 c)";
1.293 +
1.294 +"----------- 139 b ---";
1.295 +states:=[];
1.296 +CalcTree [(["term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
1.297 + "normalform N"],
1.298 + ("PolyMinus.thy",["plus_minus","polynom","vereinfachen"],
1.299 + ["simplification","for_polynomials","with_minus"]))];
1.300 +moveActiveRoot 1;
1.301 +autoCalculate 1 CompleteCalc;
1.302 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.303 +if p = ([], Res) andalso
1.304 + term2str (get_obj g_res pt (fst p)) = "-3 * u - v"
1.305 +then () else raise error "polyminus.sml: Vereinfache 139 b)";
1.306 +
1.307 +"----------- 138 a ---";
1.308 +states:=[];
1.309 +CalcTree [(["term (2*u - 3*v - 6*u + 5*v)",
1.310 + "normalform N"],
1.311 + ("PolyMinus.thy",["plus_minus","polynom","vereinfachen"],
1.312 + ["simplification","for_polynomials","with_minus"]))];
1.313 +moveActiveRoot 1;
1.314 +autoCalculate 1 CompleteCalc;
1.315 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.316 +if p = ([], Res) andalso
1.317 + term2str (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
1.318 +then () else raise error "polyminus.sml: Vereinfache 138 a)";
1.319 +
1.320 +
1.321 +"----------- met probe fuer_polynom ------------------------------";
1.322 +"----------- met probe fuer_polynom ------------------------------";
1.323 +"----------- met probe fuer_polynom ------------------------------";
1.324 +val str =
1.325 +"Script ProbeScript (e_::bool) (ws_::bool list) =\
1.326 +\ (let e_ = Take e_; \
1.327 +\ e_ = Substitute ws_ e_ \
1.328 +\ in (Repeat((Try (Repeat (Calculate times))) @@ \
1.329 +\ (Try (Repeat (Calculate plus ))) @@ \
1.330 +\ (Try (Repeat (Calculate minus))))) e_)"
1.331 +val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
1.332 +atomty sc;
1.333 +
1.334 +
1.335 +"----------- pbl polynom probe -----------------------------------";
1.336 +"----------- pbl polynom probe -----------------------------------";
1.337 +"----------- pbl polynom probe -----------------------------------";
1.338 +states:=[];
1.339 +CalcTree [(["Pruefe (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
1.340 + \3 - 2 * e + 2 * f + 2 * g)",
1.341 + "mitWert [e = 1, f = 2, g = 3]",
1.342 + "Geprueft b"],
1.343 + ("PolyMinus.thy",["polynom","probe"],
1.344 + ["probe","fuer_polynom"]))];
1.345 +moveActiveRoot 1;
1.346 +autoCalculate 1 CompleteCalc;
1.347 +(* autoCalculate 1 CompleteCalcHead;
1.348 + autoCalculate 1 (Step 1);
1.349 + autoCalculate 1 (Step 1);
1.350 + val ((pt,p),_) = get_calc 1; term2str (get_obj g_res pt (fst p));
1.351 +@@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
1.352 +although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
1.353 +val ((pt,p),_) = get_calc 1;
1.354 +if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "11 = 11"
1.355 +then () else raise error "polyminus.sml: Probe 11 = 11";
1.356 +show_pt pt;
1.357 +
1.358 +
1.359 +"----------- pbl klammer polynom vereinfachen p.34 ---------------";
1.360 +"----------- pbl klammer polynom vereinfachen p.34 ---------------";
1.361 +"----------- pbl klammer polynom vereinfachen p.34 ---------------";
1.362 +states:=[];
1.363 +CalcTree [(["term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
1.364 + "normalform N"],
1.365 + ("PolyMinus.thy",["klammer","polynom","vereinfachen"],
1.366 + ["simplification","for_polynomials","with_parentheses"]))];
1.367 +moveActiveRoot 1;
1.368 +autoCalculate 1 CompleteCalc;
1.369 +val ((pt,p),_) = get_calc 1;
1.370 +if p = ([], Res) andalso
1.371 + term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
1.372 +then () else raise error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
1.373 +show_pt pt;
1.374 +
1.375 +"----- probe p.34 -----";
1.376 +states:=[];
1.377 +CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * u)",
1.378 + "mitWert [u = 2]",
1.379 + "Geprueft b"],
1.380 + ("PolyMinus.thy",["polynom","probe"],
1.381 + ["probe","fuer_polynom"]))];
1.382 +moveActiveRoot 1;
1.383 +autoCalculate 1 CompleteCalc;
1.384 +val ((pt,p),_) = get_calc 1;
1.385 +if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "29 = 29"
1.386 +then () else raise error "polyminus.sml: Probe 29 = 29";
1.387 +show_pt pt;
1.388 +
1.389 +
1.390 +"----------- try fun applyTactics --------------------------------";
1.391 +"----------- try fun applyTactics --------------------------------";
1.392 +"----------- try fun applyTactics --------------------------------";
1.393 +states:=[];
1.394 +CalcTree [(["term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
1.395 + "normalform N"],
1.396 + ("PolyMinus.thy",["plus_minus","polynom","vereinfachen"],
1.397 + ["simplification","for_polynomials","with_minus"]))];
1.398 +moveActiveRoot 1;
1.399 +autoCalculate 1 CompleteCalcHead;
1.400 +autoCalculate 1 (Step 1);
1.401 +autoCalculate 1 (Step 1);
1.402 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.403 +"----- 1 ^^^";
1.404 +fetchApplicableTactics 1 0 p;
1.405 +val appltacs = sel_appl_atomic_tacs pt p;
1.406 +applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
1.407 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.408 +"----- 2 ^^^";
1.409 +trace_rewrite := true;
1.410 +val erls = erls_ordne_alphabetisch;
1.411 +val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
1.412 +val Some (t',_) =
1.413 + rewrite_ Isac.thy e_rew_ord erls false tausche_minus t;
1.414 +term2str t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
1.415 +
1.416 +val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
1.417 +val None =
1.418 + rewrite_ Isac.thy e_rew_ord erls false tausche_minus_plus t;
1.419 +
1.420 +val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
1.421 +val Some (t',_) =
1.422 + rewrite_set_ Isac.thy false ordne_alphabetisch t;
1.423 +term2str t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
1.424 +trace_rewrite := false;
1.425 +
1.426 +
1.427 +applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (*tausche_minus*);
1.428 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.429 +"----- 3 ^^^";
1.430 +applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
1.431 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.432 +"----- 4 ^^^";
1.433 +applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
1.434 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.435 +"----- 5 ^^^";
1.436 +applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
1.437 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.438 +"----- 6 ^^^";
1.439 +
1.440 +(*<CALCMESSAGE> failure </CALCMESSAGE>
1.441 +applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
1.442 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.443 +"----- 7 ^^^";
1.444 +*)
1.445 +
1.446 +autoCalculate 1 CompleteCalc;
1.447 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.448 +(*independent from failure above: met_simp_poly_minus not confluent:
1.449 +(([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
1.450 +(([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
1.451 +~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
1.452 +
1.453 +states:=[];
1.454 +CalcTree [(["term (- (8 * g) + 10 * g + h)",
1.455 + "normalform N"],
1.456 + ("PolyMinus.thy",["plus_minus","polynom","vereinfachen"],
1.457 + ["simplification","for_polynomials","with_minus"]))];
1.458 +moveActiveRoot 1;
1.459 +autoCalculate 1 CompleteCalc;
1.460 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.461 +if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "2 * g + h"
1.462 +then () else raise error "polyminus.sml: addiere_vor_minus";
1.463 +
1.464 +
1.465 +states:=[];
1.466 +CalcTree [(["term (- (8 * g) + 10 * g + f)",
1.467 + "normalform N"],
1.468 + ("PolyMinus.thy",["plus_minus","polynom","vereinfachen"],
1.469 + ["simplification","for_polynomials","with_minus"]))];
1.470 +moveActiveRoot 1;
1.471 +autoCalculate 1 CompleteCalc;
1.472 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.473 +if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "f + 2 * g"
1.474 +then () else raise error "polyminus.sml: tausche_vor_plus";
1.475 +
1.476 +
1.477 +"----------- pbl binom polynom vereinfachen p.39 -----------------";
1.478 +"----------- pbl binom polynom vereinfachen p.39 -----------------";
1.479 +"----------- pbl binom polynom vereinfachen p.39 -----------------";
1.480 +val rls = klammern_ausmultiplizieren;
1.481 +val t = str2term "(3 * a + 2) * (4 * a - 1)";
1.482 +val Some (t,_) = rewrite_set_ thy false rls t; term2str t;
1.483 +"3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
1.484 +val rls = discard_parentheses;
1.485 +val Some (t,_) = rewrite_set_ thy false rls t; term2str t;
1.486 +"3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
1.487 +val rls = ordne_monome;
1.488 +val Some (t,_) = rewrite_set_ thy false rls t; term2str t;
1.489 +"3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
1.490 +(*
1.491 +val t = str2term "3 * a * 4 * a";
1.492 +val rls = ordne_monome;
1.493 +val Some (t,_) = rewrite_set_ thy false rls t; term2str t;
1.494 +*)
1.495 +val rls = klammern_aufloesen;
1.496 +val Some (t,_) = rewrite_set_ thy false rls t; term2str t;
1.497 +"3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
1.498 +val rls = ordne_alphabetisch;
1.499 +(*TODO: make is_monom more general, a*a=a^2, ...*)
1.500 +val Some (t,_) = rewrite_set_ thy false rls t; term2str t;
1.501 +"3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
1.502 +(*GOON.WN080104
1.503 +val rls = fasse_zusammen;
1.504 +val Some (t,_) = rewrite_set_ thy false rls t; term2str t;
1.505 +val rls = verschoenere;
1.506 +val Some (t,_) = rewrite_set_ thy false rls t; term2str t;
1.507 +*)
1.508 +
1.509 +
1.510 +trace_rewrite := true;
1.511 +trace_rewrite := false;
1.512 +
1.513 +(*@@@@@@@*)
1.514 +states:=[];
1.515 +CalcTree [(["term ((3*a + 2) * (4*a - 1))",
1.516 + "normalform N"],
1.517 + ("PolyMinus.thy",["binom_klammer","polynom","vereinfachen"],
1.518 + ["simplification","for_polynomials","with_parentheses_mult"]))];
1.519 +moveActiveRoot 1;
1.520 +autoCalculate 1 CompleteCalc;
1.521 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.522 +
1.523 +(*
1.524 +if p = ([], Res) andalso
1.525 + term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
1.526 +then () else raise error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
1.527 +*)
1.528 +
1.529 +
1.530 +"----------- pbl binom polynom vereinfachen: cube ----------------";
1.531 +"----------- pbl binom polynom vereinfachen: cube ----------------";
1.532 +"----------- pbl binom polynom vereinfachen: cube ----------------";
1.533 +states:=[];
1.534 +CalcTree [(["term (8*(a - q) + a - 2*q + 3*(a - 2*q))",
1.535 + "normalform N"],
1.536 + ("PolyMinus.thy",["binom_klammer","polynom","vereinfachen"],
1.537 + ["simplification","for_polynomials","with_parentheses_mult"]))];
1.538 +moveActiveRoot 1;
1.539 +autoCalculate 1 CompleteCalc;
1.540 +val ((pt,p),_) = get_calc 1; show_pt pt;
1.541 +
1.542 +
1.543 +"----------- refine Vereinfache ----------------------------------";
1.544 +"----------- refine Vereinfache ----------------------------------";
1.545 +"----------- refine Vereinfache ----------------------------------";
1.546 +val fmz = ["term (8*(a - q) + a - 2*q + 3*(a - 2*q))",
1.547 + "normalform N"];
1.548 +print_depth 11;
1.549 +val matches = refine fmz ["vereinfachen"];
1.550 +print_depth 3;
1.551 +
1.552 +"----- go into details, if it seems not to work -----";
1.553 +"--- does the predicate evaluate correctly ?";
1.554 +val t = str2term
1.555 + "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + \
1.556 + \3 * (a - 2 * q))";
1.557 +val ma = eval_matchsub "" "Tools.matchsub" t thy;
1.558 +case ma of
1.559 + Some ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
1.560 + \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
1.561 + | _ => raise error "polyminus.sml matchsub (?a * (?b - ?c)...A";
1.562 +
1.563 +"--- does the respective prls rewrite ?";
1.564 +val prls = append_rls "prls_pbl_vereinf_poly" e_rls
1.565 + [Calc ("Poly.is'_polyexp", eval_is_polyexp ""),
1.566 + Calc ("Tools.matchsub", eval_matchsub ""),
1.567 + Thm ("or_true",or_true),
1.568 + (*"(?a | True) = True"*)
1.569 + Thm ("or_false",or_false),
1.570 + (*"(?a | False) = ?a"*)
1.571 + Thm ("not_true",num_str not_true),
1.572 + (*"(~ True) = False"*)
1.573 + Thm ("not_false",num_str not_false)
1.574 + (*"(~ False) = True"*)];
1.575 +trace_rewrite := true;
1.576 +val Some (t', _) = rewrite_set_ thy false prls t;
1.577 +trace_rewrite := false;
1.578 +
1.579 +"--- does the respective prls rewrite the whole predicate ?";
1.580 +val t = str2term
1.581 + "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
1.582 + \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
1.583 + \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
1.584 + \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
1.585 +trace_rewrite := true;
1.586 +val Some (t', _) = rewrite_set_ thy false prls t;
1.587 +trace_rewrite := false;
1.588 +if term2str t' = "False" then ()
1.589 +else raise error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
1.590 +
1.591 +
1.592 +
1.593 +
1.594 +
1.595 +
1.596 +
1.597 +
1.598 +(*
1.599 +use"../smltest/IsacKnowledge/polyminus.sml";
1.600 +use"polyminus.sml";
1.601 + *)