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;
304 if p = ([], Res) andalso
305 term2str (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
306 then () else error "polyminus.sml: Vereinfache 140 d)";
309 "----------- 139 c ---";
311 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
313 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
314 ["simplification","for_polynomials","with_minus"]))];
316 autoCalculate 1 CompleteCalc;
317 val ((pt,p),_) = get_calc 1; show_pt pt;
318 if p = ([], Res) andalso
319 term2str (get_obj g_res pt (fst p)) = "- (3 * f)"
320 then () else error "polyminus.sml: Vereinfache 139 c)";
322 "----------- 139 b ---";
324 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
326 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
327 ["simplification","for_polynomials","with_minus"]))];
329 autoCalculate 1 CompleteCalc;
330 val ((pt,p),_) = get_calc 1; show_pt pt;
331 if p = ([], Res) andalso
332 term2str (get_obj g_res pt (fst p)) = "-3 * u - v"
333 then () else error "polyminus.sml: Vereinfache 139 b)";
335 "----------- 138 a ---";
337 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
339 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
340 ["simplification","for_polynomials","with_minus"]))];
342 autoCalculate 1 CompleteCalc;
343 val ((pt,p),_) = get_calc 1; show_pt pt;
344 if p = ([], Res) andalso
345 term2str (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
346 then () else error "polyminus.sml: Vereinfache 138 a)";
349 "----------- met probe fuer_polynom ------------------------------";
350 "----------- met probe fuer_polynom ------------------------------";
351 "----------- met probe fuer_polynom ------------------------------";
353 "Script ProbeScript (e_e::bool) (w_s::bool list) =\
354 \ (let e_e = Take e_e; \
355 \ e_e = Substitute w_s e_e \
356 \ in (Repeat((Try (Repeat (Calculate TIMES))) @@ \
357 \ (Try (Repeat (Calculate PLUS ))) @@ \
358 \ (Try (Repeat (Calculate MINUS))))) e_e)"
359 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
363 "----------- pbl polynom probe -----------------------------------";
364 "----------- pbl polynom probe -----------------------------------";
365 "----------- pbl polynom probe -----------------------------------";
367 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
368 \3 - 2 * e + 2 * f + 2 * g)",
369 "mitWert [e = 1, f = 2, g = 3]",
371 ("PolyMinus",["polynom","probe"],
372 ["probe","fuer_polynom"]))];
374 autoCalculate 1 CompleteCalc;
375 (* autoCalculate 1 CompleteCalcHead;
376 autoCalculate 1 (Step 1);
377 autoCalculate 1 (Step 1);
378 val ((pt,p),_) = get_calc 1; term2str (get_obj g_res pt (fst p));
379 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
380 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
381 val ((pt,p),_) = get_calc 1;
382 (*========== inhibit exn 110310 ================================================
383 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "11 = 11"
384 then () else error "polyminus.sml: Probe 11 = 11";
388 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
389 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
390 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
392 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
394 ("PolyMinus",["klammer","polynom","vereinfachen"],
395 ["simplification","for_polynomials","with_parentheses"]))];
397 autoCalculate 1 CompleteCalc;
398 val ((pt,p),_) = get_calc 1;
399 if p = ([], Res) andalso
400 term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
401 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
404 "----- probe p.34 -----";
406 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * u)",
409 ("PolyMinus",["polynom","probe"],
410 ["probe","fuer_polynom"]))];
412 autoCalculate 1 CompleteCalc;
413 val ((pt,p),_) = get_calc 1;
414 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "29 = 29"
415 then () else error "polyminus.sml: Probe 29 = 29";
419 "----------- try fun applyTactics --------------------------------";
420 "----------- try fun applyTactics --------------------------------";
421 "----------- try fun applyTactics --------------------------------";
423 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
425 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
426 ["simplification","for_polynomials","with_minus"]))];
428 autoCalculate 1 CompleteCalcHead;
429 autoCalculate 1 (Step 1);
430 autoCalculate 1 (Step 1);
431 val ((pt,p),_) = get_calc 1; show_pt pt;
433 fetchApplicableTactics 1 0 p;
434 val appltacs = sel_appl_atomic_tacs pt p;
435 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
436 val ((pt,p),_) = get_calc 1; show_pt pt;
438 trace_rewrite := true;
439 val erls = erls_ordne_alphabetisch;
440 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
442 rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus} t;
443 term2str t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
445 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
447 rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
449 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
451 rewrite_set_ (@{theory "Isac"}) false ordne_alphabetisch t;
452 term2str t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
453 trace_rewrite := false;
456 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (*tausche_minus*);
457 val ((pt,p),_) = get_calc 1; show_pt pt;
459 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
460 val ((pt,p),_) = get_calc 1; show_pt pt;
462 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
463 val ((pt,p),_) = get_calc 1; show_pt pt;
465 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
466 val ((pt,p),_) = get_calc 1; show_pt pt;
469 (*<CALCMESSAGE> failure </CALCMESSAGE>
470 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
471 val ((pt,p),_) = get_calc 1; show_pt pt;
475 autoCalculate 1 CompleteCalc;
476 val ((pt,p),_) = get_calc 1; show_pt pt;
477 (*independent from failure above: met_simp_poly_minus not confluent:
478 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
479 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
480 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
483 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
485 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
486 ["simplification","for_polynomials","with_minus"]))];
488 autoCalculate 1 CompleteCalc;
489 val ((pt,p),_) = get_calc 1; show_pt pt;
490 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "2 * g + h"
491 then () else error "polyminus.sml: addiere_vor_minus";
495 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
497 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
498 ["simplification","for_polynomials","with_minus"]))];
500 autoCalculate 1 CompleteCalc;
501 val ((pt,p),_) = get_calc 1; show_pt pt;
502 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "f + 2 * g"
503 then () else error "polyminus.sml: tausche_vor_plus";
506 "----------- pbl binom polynom vereinfachen p.39 -----------------";
507 "----------- pbl binom polynom vereinfachen p.39 -----------------";
508 "----------- pbl binom polynom vereinfachen p.39 -----------------";
509 val rls = klammern_ausmultiplizieren;
510 val t = str2term "(3 * a + 2) * (4 * a - 1)";
511 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
512 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
513 val rls = discard_parentheses;
514 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
515 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
516 val rls = ordne_monome;
517 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
518 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
520 val t = str2term "3 * a * 4 * a";
521 val rls = ordne_monome;
522 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
524 val rls = klammern_aufloesen;
525 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
526 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
527 val rls = ordne_alphabetisch;
528 (*TODO: make is_monom more general, a*a=a^2, ...*)
529 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
530 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
532 val rls = fasse_zusammen;
533 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
534 val rls = verschoenere;
535 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
539 trace_rewrite := true;
540 trace_rewrite := false;
544 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
546 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
547 ["simplification","for_polynomials","with_parentheses_mult"]))];
549 autoCalculate 1 CompleteCalc;
550 val ((pt,p),_) = get_calc 1; show_pt pt;
553 if p = ([], Res) andalso
554 term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
555 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
559 "----------- pbl binom polynom vereinfachen: cube ----------------";
560 "----------- pbl binom polynom vereinfachen: cube ----------------";
561 "----------- pbl binom polynom vereinfachen: cube ----------------";
563 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
564 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
565 ["simplification","for_polynomials","with_parentheses_mult"]))];
567 autoCalculate 1 CompleteCalc;
568 val ((pt,p),_) = get_calc 1; show_pt pt;
571 "----------- refine Vereinfache ----------------------------------";
572 "----------- refine Vereinfache ----------------------------------";
573 "----------- refine Vereinfache ----------------------------------";
574 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))",
577 val matches = refine fmz ["vereinfachen"];
580 "----- go into details, if it seems not to work -----";
581 "--- does the predicate evaluate correctly ?";
582 (*=== inhibit exn ==============================================================
583 !!!!! no '?a' ............
585 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + \
587 val ma = eval_matchsub "" "Tools.matchsub" t thy;
589 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
590 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
591 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
593 "--- does the respective prls rewrite ?";
594 val prls = append_rls "prls_pbl_vereinf_poly" e_rls
595 [Calc ("Poly.is'_polyexp", eval_is_polyexp ""),
596 Calc ("Tools.matchsub", eval_matchsub ""),
597 Thm ("or_true",@{thm or_true}),
598 (*"(?a | True) = True"*)
599 Thm ("or_false",@{thm or_false}),
600 (*"(?a | False) = ?a"*)
601 Thm ("not_true",num_str @{thm not_true}),
602 (*"(~ True) = False"*)
603 Thm ("not_false",num_str @{thm not_false})
604 (*"(~ False) = True"*)];
605 trace_rewrite := true;
606 val SOME (t', _) = rewrite_set_ thy false prls t;
607 trace_rewrite := false;
609 "--- does the respective prls rewrite the whole predicate ?";
611 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
612 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
613 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
614 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
615 trace_rewrite := true;
616 val SOME (t', _) = rewrite_set_ thy false prls t;
617 trace_rewrite := false;
618 if term2str t' = "HOL.False" then ()
619 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
620 ============ inhibit exn =====================================================*)
623 "----------- *** prep_pbt: syntax error in '#Where' of [v";
624 "----------- *** prep_pbt: syntax error in '#Where' of [v";
625 "----------- *** prep_pbt: syntax error in '#Where' of [v";
626 (*see test/../termC.sml for details*)
627 val t = parse_patt thy "t_t is_polyexp";
628 val t = parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
629 " matchsub (?a + (?b - ?c)) t_t | " ^
630 " matchsub (?a - (?b + ?c)) t_t | " ^
631 " matchsub (?a + (?b - ?c)) t_t )");
633 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)"
634 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
637 "----------- check: fmz matches pbt ---------------------";
638 "----------- check: fmz matches pbt ---------------------";
639 "----------- check: fmz matches pbt ---------------------";
640 "101230 error *** nxt_add: EX itm. not(dat(itm)<=dat(ori))";
641 val fmz = ["TERM (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)","normalform N"];
642 val pI = ["plus_minus","polynom","vereinfachen"];
643 prep_ori fmz thy ((#ppc o get_pbt) pI);
645 [(1, [1], "#undef", Const (...), [...]), <<<===
646 (2, [1], "#Find", Const (...), [...])]
649 val t = str2term "TERM ttt";
651 val t = str2term "term ttt";
653 val t = str2term "Term ttt";
655 val fmz = ["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)","normalform N"];
656 prep_ori fmz thy ((#ppc o get_pbt) pI);
658 [(1, [1], "#Given", Const (...), [...]),
659 (2, [1], "#Find", Const (...), [...])]
662 ============ inhibit exn 110310 ==============================================*)