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 "--------------------------------------------------------";
30 "--------------------------------------------------------";
31 "--------------------------------------------------------";
33 val thy = @{theory "PolyMinus"};
35 "----------- fun eval_ist_monom ----------------------------------";
36 "----------- fun eval_ist_monom ----------------------------------";
37 "----------- fun eval_ist_monom ----------------------------------";
38 ist_monom (str2term "12");
39 case eval_ist_monom 0 0 (str2term "12 ist_monom") 0 of
40 SOME ("12 ist_monom = True", _) => ()
41 | _ => error "polyminus.sml: 12 ist_monom = True";
43 case eval_ist_monom 0 0 (str2term "a ist_monom") 0 of
44 SOME ("a ist_monom = True", _) => ()
45 | _ => error "polyminus.sml: a ist_monom = True";
47 case eval_ist_monom 0 0 (str2term "(3*a) ist_monom") 0 of
48 SOME ("3 * a ist_monom = True", _) => ()
49 | _ => error "polyminus.sml: 3 * a ist_monom = True";
51 case eval_ist_monom 0 0 (str2term "(a^^^2) ist_monom") 0 of
52 SOME ("a ^^^ 2 ist_monom = True", _) => ()
53 | _ => error "polyminus.sml: a^^^2 ist_monom = True";
55 case eval_ist_monom 0 0 (str2term "(3*a^^^2) ist_monom") 0 of
56 SOME ("3 * a ^^^ 2 ist_monom = True", _) => ()
57 | _ => error "polyminus.sml: 3*a^^^2 ist_monom = True";
59 case eval_ist_monom 0 0 (str2term "(a*b) ist_monom") 0 of
60 SOME ("a * b ist_monom = True", _) => ()
61 | _ => error "polyminus.sml: a*b ist_monom = True";
63 case eval_ist_monom 0 0 (str2term "(3*a*b) ist_monom") 0 of
64 SOME ("3 * a * b ist_monom = True", _) => ()
65 | _ => error "polyminus.sml: 3*a*b ist_monom = True";
68 "----------- watch order_add_mult -------------------------------";
69 "----------- watch order_add_mult -------------------------------";
70 "----------- watch order_add_mult -------------------------------";
71 "----- with these simple variables it works...";
74 val t = str2term "((a + d) + c) + b";
75 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
76 if term2str t = "a + (b + (c + d))" then ()
77 else error "polyminus.sml 1 watch order_add_mult";
80 "----- the same stepwise...";
81 val od = ord_make_polynomial true (@{theory "Poly"});
82 val t = str2term "((a + d) + c) + b";
84 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_commute} t; term2str t;
86 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_commute} t; term2str t;
88 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
90 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
92 if term2str t = "a + (b + (c + d))" then ()
93 else error "polyminus.sml 2 watch order_add_mult";
95 "----- if parentheses are right, left_commute is (almost) sufficient...";
96 val t = str2term "a + (d + (c + b))";
98 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
100 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_commute} t;term2str t;
102 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
105 "----- but we do not want the parentheses at right; thus: cond.rew.";
106 "WN0712707 complicated monomials do not yet work ...";
107 val t = str2term "((5*a + 4*d) + 3*c) + 2*b";
108 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
109 if term2str t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
110 else error "polyminus.sml: order_add_mult changed";
112 "----- here we see rew_sub going into subterm with ord.rew....";
113 val od = ord_make_polynomial false (@{theory "Poly"});
114 val t = str2term "b + a + c + d";
115 val SOME (t,_) = rewrite_ thy od e_rls false @{thm add_commute} t; term2str t;
116 val SOME (t,_) = rewrite_ thy od e_rls false @{thm add_commute} t; term2str t;
117 (*@@@ rew_sub gosub: t = d + (b + a + c)
118 @@@ rew_sub begin: t = b + a + c*)
121 "----------- build predicate for +- ordering ---------------------";
122 "----------- build predicate for +- ordering ---------------------";
123 "----------- build predicate for +- ordering ---------------------";
126 "123" < "a"; (*unused due to ---vvv*)
127 "12" < "3"; (*true !!!*)
129 " a kleiner b ==> (b + a) = (a + b)";
131 str2term "222 * aaa";
133 case eval_kleiner 0 0 (str2term "123 kleiner 32") 0 of
134 SOME ("12 kleiner 9 = False", _) => ()
135 | _ => error "polyminus.sml: 12 kleiner 9 = False";
137 (*========== inhibit exn =======================================================
138 case eval_kleiner 0 0 (str2term "a kleiner b") 0 of
139 SOME ("a kleiner b = True", _) => ()
140 | _ => error "polyminus.sml: a kleiner b = True";
142 case eval_kleiner 0 0 (str2term "(10*g) kleiner f") 0 of
143 SOME ("10 * g kleiner f = False", _) => ()
144 | _ => error "polyminus.sml: 10 * g kleiner f = False";
146 case eval_kleiner 0 0 (str2term "(a^^^2) kleiner b") 0 of
147 SOME ("a ^^^ 2 kleiner b = True", _) => ()
148 | _ => error "polyminus.sml: a ^^^ 2 kleiner b = True";
150 case eval_kleiner 0 0 (str2term "(3*a^^^2) kleiner b") 0 of
151 SOME ("3 * a ^^^ 2 kleiner b = True", _) => ()
152 | _ => error "polyminus.sml: 3 * a ^^^ 2 kleiner b = True";
154 case eval_kleiner 0 0 (str2term "(a*b) kleiner c") 0 of
155 SOME ("a * b kleiner c = True", _) => ()
156 | _ => error "polyminus.sml: a * b kleiner b = True";
158 case eval_kleiner 0 0 (str2term "(3*a*b) kleiner c") 0 of
159 SOME ("3 * a * b kleiner c = True", _) => ()
160 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
162 ============ inhibit exn =====================================================*)
165 "----- compare tausche_plus with real_num_collect";
168 val erls = erls_ordne_alphabetisch;
169 val t = str2term "b + a";
170 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
171 if term2str t = "a + b" then ()
172 else error "polyminus.sml: ordne_alphabetisch1 b + a";
174 val erls = Atools_erls;
175 val t = str2term "2*a + 3*a";
176 val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; term2str t;
178 "----- test rewrite_, rewrite_set_";
180 val erls = erls_ordne_alphabetisch;
181 val t = str2term "b + a";
182 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
183 if term2str t = "a + b" then ()
184 else error "polyminus.sml: ordne_alphabetisch a + b";
186 val t = str2term "2*b + a";
187 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
188 if term2str t = "a + 2 * b" then ()
189 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
191 val t = str2term "a + c + b";
192 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
193 if term2str t = "a + b + c" then ()
194 else error "polyminus.sml: ordne_alphabetisch a + b + c";
196 "----- rewrite goes into subterms";
197 val t = str2term "a + c + b + d";
198 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; term2str t;
199 if term2str t = "a + b + c + d" then ()
200 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
202 val t = str2term "a + c + d + b";
203 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
204 if term2str t = "a + b + c + d" then ()
205 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
207 "----- here we see rew_sub going into subterm with cond.rew....";
208 val t = str2term "b + a + c + d";
209 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
210 if term2str t = "a + b + c + d" then ()
211 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
213 "----- compile rls for the most complicated terms";
214 val t = str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
215 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
216 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t;
217 if term2str t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
218 then () else error "polyminus.sml: ordne_alphabetisch finished";
221 "----------- build fasse_zusammen --------------------------------";
222 "----------- build fasse_zusammen --------------------------------";
223 "----------- build fasse_zusammen --------------------------------";
224 val t = str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
225 val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
226 if term2str t = "3 + -2 * e + 2 * f + 2 * g" then ()
227 else error "polyminus.sml: fasse_zusammen finished";
229 "----------- build verschoenere ----------------------------------";
230 "----------- build verschoenere ----------------------------------";
231 "----------- build verschoenere ----------------------------------";
232 val t = str2term "3 + -2 * e + 2 * f + 2 * g";
233 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
234 if term2str t = "3 - 2 * e + 2 * f + 2 * g" then ()
235 else error "polyminus.sml: verschoenere 3 + -2 * e ...";
238 trace_rewrite:=false;
240 "----------- met simplification for_polynomials with_minus -------";
241 "----------- met simplification for_polynomials with_minus -------";
242 "----------- met simplification for_polynomials with_minus -------";
244 "Script SimplifyScript (t_t::real) = \
245 \ (((Try (Rewrite_Set ordne_alphabetisch False)) @@ \
246 \ (Try (Rewrite_Set fasse_zusammen False)) @@ \
247 \ (Try (Rewrite_Set verschoenere False))) t_t)"
248 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
252 "----------- me simplification.for_polynomials.with_minus";
253 "----------- me simplification.for_polynomials.with_minus";
254 "----------- me simplification.for_polynomials.with_minus";
256 val (p,_,f,nxt,_,pt) =
258 [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
260 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
261 ["simplification","for_polynomials","with_minus"]))];
262 val (p,_,f,nxt,_,pt) = me nxt p c pt;
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;
269 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 if f2str f = "3 - 2 * e + 2 * f + 2 * g" andalso #1 nxt = "End_Proof'" then ()
275 else error "polyminus.sml: me simplification.for_polynomials.with_minus";
278 "----------- pbl polynom vereinfachen p.33 -----------------------";
279 "----------- pbl polynom vereinfachen p.33 -----------------------";
280 "----------- pbl polynom vereinfachen p.33 -----------------------";
281 "----------- 140 c ---";
283 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
285 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
286 ["simplification","for_polynomials","with_minus"]))];
288 autoCalculate 1 CompleteCalc;
289 val ((pt,p),_) = get_calc 1; show_pt pt;
290 if p = ([], Res) andalso
291 term2str (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
292 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
294 "----------- 140 d ---";
296 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
298 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
299 ["simplification","for_polynomials","with_minus"]))];
301 autoCalculate 1 CompleteCalc;
302 val ((pt,p),_) = get_calc 1; show_pt pt;
303 if p = ([], Res) andalso
304 term2str (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
305 then () else error "polyminus.sml: Vereinfache 140 d)";
308 "----------- 139 c ---";
310 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
312 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
313 ["simplification","for_polynomials","with_minus"]))];
315 autoCalculate 1 CompleteCalc;
316 val ((pt,p),_) = get_calc 1; show_pt pt;
317 if p = ([], Res) andalso
318 term2str (get_obj g_res pt (fst p)) = "- (3 * f)"
319 then () else error "polyminus.sml: Vereinfache 139 c)";
321 "----------- 139 b ---";
323 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
325 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
326 ["simplification","for_polynomials","with_minus"]))];
328 autoCalculate 1 CompleteCalc;
329 val ((pt,p),_) = get_calc 1; show_pt pt;
330 if p = ([], Res) andalso
331 term2str (get_obj g_res pt (fst p)) = "-3 * u - v"
332 then () else error "polyminus.sml: Vereinfache 139 b)";
334 "----------- 138 a ---";
336 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
338 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
339 ["simplification","for_polynomials","with_minus"]))];
341 autoCalculate 1 CompleteCalc;
342 val ((pt,p),_) = get_calc 1; show_pt pt;
343 if p = ([], Res) andalso
344 term2str (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
345 then () else error "polyminus.sml: Vereinfache 138 a)";
348 "----------- met probe fuer_polynom ------------------------------";
349 "----------- met probe fuer_polynom ------------------------------";
350 "----------- met probe fuer_polynom ------------------------------";
352 "Script ProbeScript (e_e::bool) (w_s::bool list) =\
353 \ (let e_e = Take e_e; \
354 \ e_e = Substitute w_s e_e \
355 \ in (Repeat((Try (Repeat (Calculate TIMES))) @@ \
356 \ (Try (Repeat (Calculate PLUS ))) @@ \
357 \ (Try (Repeat (Calculate MINUS))))) e_e)"
358 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
362 "----------- pbl polynom probe -----------------------------------";
363 "----------- pbl polynom probe -----------------------------------";
364 "----------- pbl polynom probe -----------------------------------";
366 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
367 \3 - 2 * e + 2 * f + 2 * g)",
368 "mitWert [e = 1, f = 2, g = 3]",
370 ("PolyMinus",["polynom","probe"],
371 ["probe","fuer_polynom"]))];
373 autoCalculate 1 CompleteCalc;
374 (* autoCalculate 1 CompleteCalcHead;
375 autoCalculate 1 (Step 1);
376 autoCalculate 1 (Step 1);
377 val ((pt,p),_) = get_calc 1; term2str (get_obj g_res pt (fst p));
378 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
379 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
380 val ((pt,p),_) = get_calc 1;
381 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "11 = 11"
382 then () else error "polyminus.sml: Probe 11 = 11";
387 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
388 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
389 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
391 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
393 ("PolyMinus",["klammer","polynom","vereinfachen"],
394 ["simplification","for_polynomials","with_parentheses"]))];
396 autoCalculate 1 CompleteCalc;
397 val ((pt,p),_) = get_calc 1;
398 if p = ([], Res) andalso
399 term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
400 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
403 "----- probe p.34 -----";
405 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * u)",
408 ("PolyMinus",["polynom","probe"],
409 ["probe","fuer_polynom"]))];
411 autoCalculate 1 CompleteCalc;
412 val ((pt,p),_) = get_calc 1;
413 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "29 = 29"
414 then () else error "polyminus.sml: Probe 29 = 29";
416 (*========== inhibit exn 110719 ================================================
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;
474 ============ inhibit exn 110719 ==============================================*)
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 "#############################################################################";
485 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
487 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
488 ["simplification","for_polynomials","with_minus"]))];
490 autoCalculate 1 CompleteCalc;
491 val ((pt,p),_) = get_calc 1; show_pt pt;
492 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "2 * g + h"
493 then () else error "polyminus.sml: addiere_vor_minus";
496 "#############################################################################";
498 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
500 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
501 ["simplification","for_polynomials","with_minus"]))];
503 autoCalculate 1 CompleteCalc;
504 val ((pt,p),_) = get_calc 1; show_pt pt;
505 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "f + 2 * g"
506 then () else error "polyminus.sml: tausche_vor_plus";
508 (*========== inhibit exn 110719 ================================================
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;
547 ============ inhibit exn 110719 ==============================================*)
549 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
551 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
552 ["simplification","for_polynomials","with_parentheses_mult"]))];
554 autoCalculate 1 CompleteCalc;
555 val ((pt,p),_) = get_calc 1; show_pt pt;
556 if p = ([], Res) andalso
557 term2str (get_obj g_res pt (fst p)) = "-2 + 12 * a ^^^ 2 + 5 * a"
558 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
562 "----------- pbl binom polynom vereinfachen: cube ----------------";
563 "----------- pbl binom polynom vereinfachen: cube ----------------";
564 "----------- pbl binom polynom vereinfachen: cube ----------------";
566 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
567 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
568 ["simplification","for_polynomials","with_parentheses_mult"]))];
570 autoCalculate 1 CompleteCalc;
571 val ((pt,p),_) = get_calc 1; show_pt pt;
572 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "12 * a - 16 * q"
573 then () else error "pbl binom polynom vereinfachen: cube";
575 (*========== inhibit exn 110719 ================================================
577 "----------- refine Vereinfache ----------------------------------";
578 "----------- refine Vereinfache ----------------------------------";
579 "----------- refine Vereinfache ----------------------------------";
580 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))",
583 val matches = refine fmz ["vereinfachen"];
586 "----- go into details, if it seems not to work -----";
587 "--- does the predicate evaluate correctly ?";
588 (*=== inhibit exn ==============================================================
589 !!!!! no '?a' ............
591 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + \
593 val ma = eval_matchsub "" "Tools.matchsub" t thy;
595 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
596 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
597 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
599 "--- does the respective prls rewrite ?";
600 val prls = append_rls "prls_pbl_vereinf_poly" e_rls
601 [Calc ("Poly.is'_polyexp", eval_is_polyexp ""),
602 Calc ("Tools.matchsub", eval_matchsub ""),
603 Thm ("or_true",@{thm or_true}),
604 (*"(?a | True) = True"*)
605 Thm ("or_false",@{thm or_false}),
606 (*"(?a | False) = ?a"*)
607 Thm ("not_true",num_str @{thm not_true}),
608 (*"(~ True) = False"*)
609 Thm ("not_false",num_str @{thm not_false})
610 (*"(~ False) = True"*)];
611 trace_rewrite := true;
612 val SOME (t', _) = rewrite_set_ thy false prls t;
613 trace_rewrite := false;
615 "--- does the respective prls rewrite the whole predicate ?";
617 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
618 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
619 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
620 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
621 trace_rewrite := true;
622 val SOME (t', _) = rewrite_set_ thy false prls t;
623 trace_rewrite := false;
624 if term2str t' = "HOL.False" then ()
625 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
626 ============ inhibit exn =====================================================*)
629 "----------- *** prep_pbt: syntax error in '#Where' of [v";
630 "----------- *** prep_pbt: syntax error in '#Where' of [v";
631 "----------- *** prep_pbt: syntax error in '#Where' of [v";
632 (*see test/../termC.sml for details*)
633 val t = parse_patt thy "t_t is_polyexp";
634 val t = parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
635 " matchsub (?a + (?b - ?c)) t_t | " ^
636 " matchsub (?a - (?b + ?c)) t_t | " ^
637 " matchsub (?a + (?b - ?c)) t_t )");
639 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)"
640 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
644 ============ inhibit exn 110719 ==============================================*)