4 (c) due to copyright terms
6 use"../smltest/IsacKnowledge/polyminus.sml";
9 "--------------------------------------------------------";
10 "--------------------------------------------------------";
11 "table of contents --------------------------------------";
12 "--------------------------------------------------------";
13 "----------- fun eval_ist_monom -------------------------";
14 "----------- watch order_add_mult ----------------------";
15 "----------- build predicate for +- ordering ------------";
16 "----------- build fasse_zusammen -----------------------";
17 "----------- build verschoenere -------------------------";
18 "----------- met simplification for_polynomials with_minu";
19 "----------- me 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 "----------- *** prep_pbt: syntax error in '#Where' of [v";
29 "----------- check: fmz matches pbt ---------------------";
30 "--------------------------------------------------------";
31 "--------------------------------------------------------";
32 "--------------------------------------------------------";
34 val thy = @{theory "PolyMinus"};
36 "----------- fun eval_ist_monom ----------------------------------";
37 "----------- fun eval_ist_monom ----------------------------------";
38 "----------- fun eval_ist_monom ----------------------------------";
39 ist_monom (str2term "12");
40 case eval_ist_monom 0 0 (str2term "12 ist_monom") 0 of
41 SOME ("12 ist_monom = True", _) => ()
42 | _ => error "polyminus.sml: 12 ist_monom = True";
44 case eval_ist_monom 0 0 (str2term "a ist_monom") 0 of
45 SOME ("a ist_monom = True", _) => ()
46 | _ => error "polyminus.sml: a ist_monom = True";
48 case eval_ist_monom 0 0 (str2term "(3*a) ist_monom") 0 of
49 SOME ("3 * a ist_monom = True", _) => ()
50 | _ => error "polyminus.sml: 3 * a ist_monom = True";
52 case eval_ist_monom 0 0 (str2term "(a^^^2) ist_monom") 0 of
53 SOME ("a ^^^ 2 ist_monom = True", _) => ()
54 | _ => error "polyminus.sml: a^^^2 ist_monom = True";
56 case eval_ist_monom 0 0 (str2term "(3*a^^^2) ist_monom") 0 of
57 SOME ("3 * a ^^^ 2 ist_monom = True", _) => ()
58 | _ => error "polyminus.sml: 3*a^^^2 ist_monom = True";
60 case eval_ist_monom 0 0 (str2term "(a*b) ist_monom") 0 of
61 SOME ("a * b ist_monom = True", _) => ()
62 | _ => error "polyminus.sml: a*b ist_monom = True";
64 case eval_ist_monom 0 0 (str2term "(3*a*b) ist_monom") 0 of
65 SOME ("3 * a * b ist_monom = True", _) => ()
66 | _ => error "polyminus.sml: 3*a*b ist_monom = True";
69 "----------- watch order_add_mult -------------------------------";
70 "----------- watch order_add_mult -------------------------------";
71 "----------- watch order_add_mult -------------------------------";
72 "----- with these simple variables it works...";
75 val t = str2term "((a + d) + c) + b";
76 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
77 if term2str t = "a + (b + (c + d))" then ()
78 else error "polyminus.sml 1 watch order_add_mult";
81 "----- the same stepwise...";
82 val od = ord_make_polynomial true (@{theory "Poly"});
83 val t = str2term "((a + d) + c) + b";
85 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_commute} t; term2str t;
87 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_commute} t; term2str t;
89 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
91 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
93 if term2str t = "a + (b + (c + d))" then ()
94 else error "polyminus.sml 2 watch order_add_mult";
96 "----- if parentheses are right, left_commute is (almost) sufficient...";
97 val t = str2term "a + (d + (c + b))";
99 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
101 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_commute} t;term2str t;
103 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
106 "----- but we do not want the parentheses at right; thus: cond.rew.";
107 "WN0712707 complicated monomials do not yet work ...";
108 val t = str2term "((5*a + 4*d) + 3*c) + 2*b";
109 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
110 if term2str t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
111 else error "polyminus.sml: order_add_mult changed";
113 "----- here we see rew_sub going into subterm with ord.rew....";
114 val od = ord_make_polynomial false (@{theory "Poly"});
115 val t = str2term "b + a + c + d";
116 val SOME (t,_) = rewrite_ thy od e_rls false @{thm add_commute} t; term2str t;
117 val SOME (t,_) = rewrite_ thy od e_rls false @{thm add_commute} t; term2str t;
118 (*@@@ rew_sub gosub: t = d + (b + a + c)
119 @@@ rew_sub begin: t = b + a + c*)
122 "----------- build predicate for +- ordering ---------------------";
123 "----------- build predicate for +- ordering ---------------------";
124 "----------- build predicate for +- ordering ---------------------";
127 "123" < "a"; (*unused due to ---vvv*)
128 "12" < "3"; (*true !!!*)
130 " a kleiner b ==> (b + a) = (a + b)";
132 str2term "222 * aaa";
134 case eval_kleiner 0 0 (str2term "123 kleiner 32") 0 of
135 SOME ("12 kleiner 9 = False", _) => ()
136 | _ => error "polyminus.sml: 12 kleiner 9 = False";
138 (*========== inhibit exn =======================================================
139 case eval_kleiner 0 0 (str2term "a kleiner b") 0 of
140 SOME ("a kleiner b = True", _) => ()
141 | _ => error "polyminus.sml: a kleiner b = True";
143 case eval_kleiner 0 0 (str2term "(10*g) kleiner f") 0 of
144 SOME ("10 * g kleiner f = False", _) => ()
145 | _ => error "polyminus.sml: 10 * g kleiner f = False";
147 case eval_kleiner 0 0 (str2term "(a^^^2) kleiner b") 0 of
148 SOME ("a ^^^ 2 kleiner b = True", _) => ()
149 | _ => error "polyminus.sml: a ^^^ 2 kleiner b = True";
151 case eval_kleiner 0 0 (str2term "(3*a^^^2) kleiner b") 0 of
152 SOME ("3 * a ^^^ 2 kleiner b = True", _) => ()
153 | _ => error "polyminus.sml: 3 * a ^^^ 2 kleiner b = True";
155 case eval_kleiner 0 0 (str2term "(a*b) kleiner c") 0 of
156 SOME ("a * b kleiner c = True", _) => ()
157 | _ => error "polyminus.sml: a * b kleiner b = True";
159 case eval_kleiner 0 0 (str2term "(3*a*b) kleiner c") 0 of
160 SOME ("3 * a * b kleiner c = True", _) => ()
161 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
163 ============ inhibit exn =====================================================*)
166 "----- compare tausche_plus with real_num_collect";
169 val erls = erls_ordne_alphabetisch;
170 val t = str2term "b + a";
171 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
172 if term2str t = "a + b" then ()
173 else error "polyminus.sml: ordne_alphabetisch1 b + a";
175 val erls = Atools_erls;
176 val t = str2term "2*a + 3*a";
177 val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; term2str t;
179 "----- test rewrite_, rewrite_set_";
181 val erls = erls_ordne_alphabetisch;
182 val t = str2term "b + a";
183 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
184 if term2str t = "a + b" then ()
185 else error "polyminus.sml: ordne_alphabetisch a + b";
187 val t = str2term "2*b + a";
188 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
189 if term2str t = "a + 2 * b" then ()
190 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
192 val t = str2term "a + c + b";
193 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
194 if term2str t = "a + b + c" then ()
195 else error "polyminus.sml: ordne_alphabetisch a + b + c";
197 "----- rewrite goes into subterms";
198 val t = str2term "a + c + b + d";
199 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; term2str t;
200 if term2str t = "a + b + c + d" then ()
201 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
203 val t = str2term "a + c + d + b";
204 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
205 if term2str t = "a + b + c + d" then ()
206 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
208 "----- here we see rew_sub going into subterm with cond.rew....";
209 val t = str2term "b + a + c + d";
210 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
211 if term2str t = "a + b + c + d" then ()
212 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
214 "----- compile rls for the most complicated terms";
215 val t = str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
216 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
217 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t;
218 if term2str t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
219 then () else error "polyminus.sml: ordne_alphabetisch finished";
222 "----------- build fasse_zusammen --------------------------------";
223 "----------- build fasse_zusammen --------------------------------";
224 "----------- build fasse_zusammen --------------------------------";
225 val t = str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
226 val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
227 if term2str t = "3 + -2 * e + 2 * f + 2 * g" then ()
228 else error "polyminus.sml: fasse_zusammen finished";
230 "----------- build verschoenere ----------------------------------";
231 "----------- build verschoenere ----------------------------------";
232 "----------- build verschoenere ----------------------------------";
233 val t = str2term "3 + -2 * e + 2 * f + 2 * g";
234 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
235 if term2str t = "3 - 2 * e + 2 * f + 2 * g" then ()
236 else error "polyminus.sml: verschoenere 3 + -2 * e ...";
239 trace_rewrite:=false;
241 "----------- met simplification for_polynomials with_minus -------";
242 "----------- met simplification for_polynomials with_minus -------";
243 "----------- met simplification for_polynomials with_minus -------";
245 "Script SimplifyScript (t_t::real) = \
246 \ (((Try (Rewrite_Set ordne_alphabetisch False)) @@ \
247 \ (Try (Rewrite_Set fasse_zusammen False)) @@ \
248 \ (Try (Rewrite_Set verschoenere False))) t_t)"
249 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
253 "----------- me simplification.for_polynomials.with_minus";
254 "----------- me simplification.for_polynomials.with_minus";
255 "----------- me simplification.for_polynomials.with_minus";
257 val (p,_,f,nxt,_,pt) =
259 [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
261 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
262 ["simplification","for_polynomials","with_minus"]))];
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 val (p,_,f,nxt,_,pt) = me nxt p c pt;
267 val (p,_,f,nxt,_,pt) = me nxt p c pt;
268 val (p,_,f,nxt,_,pt) = me nxt p c pt;
270 val (p,_,f,nxt,_,pt) = me nxt p c pt;
271 val (p,_,f,nxt,_,pt) = me nxt p c pt;
272 val (p,_,f,nxt,_,pt) = me nxt p c pt;
273 val (p,_,f,nxt,_,pt) = me nxt p c pt;
274 val (p,_,f,nxt,_,pt) = me nxt p c pt;
275 if f2str f = "3 - 2 * e + 2 * f + 2 * g" andalso #1 nxt = "End_Proof'" then ()
276 else error "polyminus.sml: me simplification.for_polynomials.with_minus";
279 "----------- pbl polynom vereinfachen p.33 -----------------------";
280 "----------- pbl polynom vereinfachen p.33 -----------------------";
281 "----------- pbl polynom vereinfachen p.33 -----------------------";
282 "----------- 140 c ---";
284 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
286 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
287 ["simplification","for_polynomials","with_minus"]))];
289 autoCalculate 1 CompleteCalc;
290 val ((pt,p),_) = get_calc 1; show_pt pt;
291 if p = ([], Res) andalso
292 term2str (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
293 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
295 "----------- 140 d ---";
297 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
299 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
300 ["simplification","for_polynomials","with_minus"]))];
302 autoCalculate 1 CompleteCalc;
303 val ((pt,p),_) = get_calc 1; show_pt pt;
307 (get_obj g_res pt (fst p));
308 term2str (get_obj g_res pt (fst p));
309 if p = ([], Res) andalso
310 term2str (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
311 then () else error "polyminus.sml: Vereinfache 140 d)";
314 "----------- 139 c ---";
316 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
318 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
319 ["simplification","for_polynomials","with_minus"]))];
321 autoCalculate 1 CompleteCalc;
322 val ((pt,p),_) = get_calc 1; show_pt pt;
323 if p = ([], Res) andalso
324 term2str (get_obj g_res pt (fst p)) = "- (3 * f)"
325 then () else error "polyminus.sml: Vereinfache 139 c)";
327 "----------- 139 b ---";
329 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
331 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
332 ["simplification","for_polynomials","with_minus"]))];
334 autoCalculate 1 CompleteCalc;
335 val ((pt,p),_) = get_calc 1; show_pt pt;
336 if p = ([], Res) andalso
337 term2str (get_obj g_res pt (fst p)) = "-3 * u - v"
338 then () else error "polyminus.sml: Vereinfache 139 b)";
340 "----------- 138 a ---";
342 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
344 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
345 ["simplification","for_polynomials","with_minus"]))];
347 autoCalculate 1 CompleteCalc;
348 val ((pt,p),_) = get_calc 1; show_pt pt;
349 if p = ([], Res) andalso
350 term2str (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
351 then () else error "polyminus.sml: Vereinfache 138 a)";
354 "----------- met probe fuer_polynom ------------------------------";
355 "----------- met probe fuer_polynom ------------------------------";
356 "----------- met probe fuer_polynom ------------------------------";
358 "Script ProbeScript (e_e::bool) (w_s::bool list) =\
359 \ (let e_e = Take e_e; \
360 \ e_e = Substitute w_s e_e \
361 \ in (Repeat((Try (Repeat (Calculate TIMES))) @@ \
362 \ (Try (Repeat (Calculate PLUS ))) @@ \
363 \ (Try (Repeat (Calculate MINUS))))) e_e)"
364 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
368 "----------- pbl polynom probe -----------------------------------";
369 "----------- pbl polynom probe -----------------------------------";
370 "----------- pbl polynom probe -----------------------------------";
372 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
373 \3 - 2 * e + 2 * f + 2 * g)",
374 "mitWert [e = 1, f = 2, g = 3]",
376 ("PolyMinus",["polynom","probe"],
377 ["probe","fuer_polynom"]))];
379 autoCalculate 1 CompleteCalc;
380 (* autoCalculate 1 CompleteCalcHead;
381 autoCalculate 1 (Step 1);
382 autoCalculate 1 (Step 1);
383 val ((pt,p),_) = get_calc 1; term2str (get_obj g_res pt (fst p));
384 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
385 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
386 val ((pt,p),_) = get_calc 1;
387 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "11 = 11"
388 then () else error "polyminus.sml: Probe 11 = 11";
392 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
393 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
394 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
396 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
398 ("PolyMinus",["klammer","polynom","vereinfachen"],
399 ["simplification","for_polynomials","with_parentheses"]))];
401 autoCalculate 1 CompleteCalc;
402 val ((pt,p),_) = get_calc 1;
403 if p = ([], Res) andalso
404 term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
405 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
408 "----- probe p.34 -----";
410 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * u)",
413 ("PolyMinus",["polynom","probe"],
414 ["probe","fuer_polynom"]))];
416 autoCalculate 1 CompleteCalc;
417 val ((pt,p),_) = get_calc 1;
418 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "29 = 29"
419 then () else error "polyminus.sml: Probe 29 = 29";
423 "----------- try fun applyTactics --------------------------------";
424 "----------- try fun applyTactics --------------------------------";
425 "----------- try fun applyTactics --------------------------------";
427 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
429 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
430 ["simplification","for_polynomials","with_minus"]))];
432 autoCalculate 1 CompleteCalcHead;
433 autoCalculate 1 (Step 1);
434 autoCalculate 1 (Step 1);
435 val ((pt,p),_) = get_calc 1; show_pt pt;
437 fetchApplicableTactics 1 0 p;
438 val appltacs = sel_appl_atomic_tacs pt p;
439 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
440 val ((pt,p),_) = get_calc 1; show_pt pt;
442 trace_rewrite := true;
443 val erls = erls_ordne_alphabetisch;
444 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
446 rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus} t;
447 term2str t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
449 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
451 rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
453 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
455 rewrite_set_ (@{theory "Isac"}) false ordne_alphabetisch t;
456 term2str t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
457 trace_rewrite := false;
460 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (*tausche_minus*);
461 val ((pt,p),_) = get_calc 1; show_pt pt;
463 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
464 val ((pt,p),_) = get_calc 1; show_pt pt;
466 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
467 val ((pt,p),_) = get_calc 1; show_pt pt;
469 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
470 val ((pt,p),_) = get_calc 1; show_pt pt;
473 (*<CALCMESSAGE> failure </CALCMESSAGE>
474 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
475 val ((pt,p),_) = get_calc 1; show_pt pt;
479 autoCalculate 1 CompleteCalc;
480 val ((pt,p),_) = get_calc 1; show_pt pt;
481 (*independent from failure above: met_simp_poly_minus not confluent:
482 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
483 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
484 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
487 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
489 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
490 ["simplification","for_polynomials","with_minus"]))];
492 autoCalculate 1 CompleteCalc;
493 val ((pt,p),_) = get_calc 1; show_pt pt;
494 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "2 * g + h"
495 then () else error "polyminus.sml: addiere_vor_minus";
499 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
501 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
502 ["simplification","for_polynomials","with_minus"]))];
504 autoCalculate 1 CompleteCalc;
505 val ((pt,p),_) = get_calc 1; show_pt pt;
506 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "f + 2 * g"
507 then () else error "polyminus.sml: tausche_vor_plus";
510 "----------- pbl binom polynom vereinfachen p.39 -----------------";
511 "----------- pbl binom polynom vereinfachen p.39 -----------------";
512 "----------- pbl binom polynom vereinfachen p.39 -----------------";
513 val rls = klammern_ausmultiplizieren;
514 val t = str2term "(3 * a + 2) * (4 * a - 1)";
515 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
516 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
517 val rls = discard_parentheses;
518 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
519 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
520 val rls = ordne_monome;
521 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
522 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
524 val t = str2term "3 * a * 4 * a";
525 val rls = ordne_monome;
526 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
528 val rls = klammern_aufloesen;
529 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
530 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
531 val rls = ordne_alphabetisch;
532 (*TODO: make is_monom more general, a*a=a^2, ...*)
533 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
534 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
536 val rls = fasse_zusammen;
537 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
538 val rls = verschoenere;
539 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
543 trace_rewrite := true;
544 trace_rewrite := false;
548 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
550 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
551 ["simplification","for_polynomials","with_parentheses_mult"]))];
553 autoCalculate 1 CompleteCalc;
554 val ((pt,p),_) = get_calc 1; show_pt pt;
557 if p = ([], Res) andalso
558 term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
559 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
563 "----------- pbl binom polynom vereinfachen: cube ----------------";
564 "----------- pbl binom polynom vereinfachen: cube ----------------";
565 "----------- pbl binom polynom vereinfachen: cube ----------------";
567 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
568 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
569 ["simplification","for_polynomials","with_parentheses_mult"]))];
571 autoCalculate 1 CompleteCalc;
572 val ((pt,p),_) = get_calc 1; show_pt pt;
575 "----------- refine Vereinfache ----------------------------------";
576 "----------- refine Vereinfache ----------------------------------";
577 "----------- refine Vereinfache ----------------------------------";
578 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))",
581 val matches = refine fmz ["vereinfachen"];
584 "----- go into details, if it seems not to work -----";
585 "--- does the predicate evaluate correctly ?";
586 (*=== inhibit exn ==============================================================
587 !!!!! no '?a' ............
589 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + \
591 val ma = eval_matchsub "" "Tools.matchsub" t thy;
593 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
594 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
595 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
597 "--- does the respective prls rewrite ?";
598 val prls = append_rls "prls_pbl_vereinf_poly" e_rls
599 [Calc ("Poly.is'_polyexp", eval_is_polyexp ""),
600 Calc ("Tools.matchsub", eval_matchsub ""),
601 Thm ("or_true",@{thm or_true}),
602 (*"(?a | True) = True"*)
603 Thm ("or_false",@{thm or_false}),
604 (*"(?a | False) = ?a"*)
605 Thm ("not_true",num_str @{thm not_true}),
606 (*"(~ True) = False"*)
607 Thm ("not_false",num_str @{thm not_false})
608 (*"(~ False) = True"*)];
609 trace_rewrite := true;
610 val SOME (t', _) = rewrite_set_ thy false prls t;
611 trace_rewrite := false;
613 "--- does the respective prls rewrite the whole predicate ?";
615 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
616 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
617 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
618 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
619 trace_rewrite := true;
620 val SOME (t', _) = rewrite_set_ thy false prls t;
621 trace_rewrite := false;
622 if term2str t' = "HOL.False" then ()
623 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
624 ============ inhibit exn =====================================================*)
627 "----------- *** prep_pbt: syntax error in '#Where' of [v";
628 "----------- *** prep_pbt: syntax error in '#Where' of [v";
629 "----------- *** prep_pbt: syntax error in '#Where' of [v";
630 (*see test/../termC.sml for details*)
631 val t = parse_patt thy "t_t is_polyexp";
632 val t = parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
633 " matchsub (?a + (?b - ?c)) t_t | " ^
634 " matchsub (?a - (?b + ?c)) t_t | " ^
635 " matchsub (?a + (?b - ?c)) t_t )");
637 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)"
638 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
641 "----------- check: fmz matches pbt ---------------------";
642 "----------- check: fmz matches pbt ---------------------";
643 "----------- check: fmz matches pbt ---------------------";
644 "101230 error *** nxt_add: EX itm. not(dat(itm)<=dat(ori))";
645 val fmz = ["TERM (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)","normalform N"];
646 val pI = ["plus_minus","polynom","vereinfachen"];
647 prep_ori fmz thy ((#ppc o get_pbt) pI);
649 [(1, [1], "#undef", Const (...), [...]), <<<===
650 (2, [1], "#Find", Const (...), [...])]
653 val t = str2term "TERM ttt";
655 val t = str2term "term ttt";
657 val t = str2term "Term ttt";
659 val fmz = ["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)","normalform N"];
660 prep_ori fmz thy ((#ppc o get_pbt) pI);
662 [(1, [1], "#Given", Const (...), [...]),
663 (2, [1], "#Find", Const (...), [...])]