intermed. ctxt ..: generate1..Check_Postcond..restored
works with str2term..parse_patt
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 (*========== inhibit exn =======================================================
41 case eval_ist_monom 0 0 (str2term "12 ist_monom") 0 of
42 SOME ("12 ist_monom = True", _) => ()
43 | _ => error "polyminus.sml: 12 ist_monom = True";
45 case eval_ist_monom 0 0 (str2term "a ist_monom") 0 of
46 SOME ("a ist_monom = True", _) => ()
47 | _ => error "polyminus.sml: a ist_monom = True";
49 case eval_ist_monom 0 0 (str2term "(3*a) ist_monom") 0 of
50 SOME ("3 * a ist_monom = True", _) => ()
51 | _ => error "polyminus.sml: 3 * a ist_monom = True";
53 case eval_ist_monom 0 0 (str2term "(a^^^2) ist_monom") 0 of
54 SOME ("a ^^^ 2 ist_monom = True", _) => ()
55 | _ => error "polyminus.sml: a^^^2 ist_monom = True";
57 case eval_ist_monom 0 0 (str2term "(3*a^^^2) ist_monom") 0 of
58 SOME ("3 * a ^^^ 2 ist_monom = True", _) => ()
59 | _ => error "polyminus.sml: 3*a^^^2 ist_monom = True";
61 case eval_ist_monom 0 0 (str2term "(a*b) ist_monom") 0 of
62 SOME ("a * b ist_monom = True", _) => ()
63 | _ => error "polyminus.sml: a*b ist_monom = True";
65 case eval_ist_monom 0 0 (str2term "(3*a*b) ist_monom") 0 of
66 SOME ("3 * a * b ist_monom = True", _) => ()
67 | _ => error "polyminus.sml: 3*a*b ist_monom = True";
69 ============ inhibit exn =====================================================*)
71 "----------- watch order_add_mult -------------------------------";
72 "----------- watch order_add_mult -------------------------------";
73 "----------- watch order_add_mult -------------------------------";
74 "----- with these simple variables it works...";
77 val t = str2term "((a + d) + c) + b";
78 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
79 if term2str t = "a + (b + (c + d))" then ()
80 else error "polyminus.sml 1 watch order_add_mult";
83 "----- the same stepwise...";
84 val od = ord_make_polynomial true (@{theory "Poly"});
85 val t = str2term "((a + d) + c) + b";
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_commute} t; term2str t;
91 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
93 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
95 if term2str t = "a + (b + (c + d))" then ()
96 else error "polyminus.sml 2 watch order_add_mult";
98 "----- if parentheses are right, left_commute is (almost) sufficient...";
99 val t = str2term "a + (d + (c + b))";
101 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
103 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_commute} t;term2str t;
105 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add_left_commute} t;term2str t;
108 "----- but we do not want the parentheses at right; thus: cond.rew.";
109 "WN0712707 complicated monomials do not yet work ...";
110 val t = str2term "((5*a + 4*d) + 3*c) + 2*b";
111 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
112 if term2str t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
113 else error "polyminus.sml: order_add_mult changed";
115 "----- here we see rew_sub going into subterm with ord.rew....";
116 val od = ord_make_polynomial false (@{theory "Poly"});
117 val t = str2term "b + a + c + d";
118 val SOME (t,_) = rewrite_ thy od e_rls false @{thm add_commute} t; term2str t;
119 val SOME (t,_) = rewrite_ thy od e_rls false @{thm add_commute} t; term2str t;
120 (*@@@ rew_sub gosub: t = d + (b + a + c)
121 @@@ rew_sub begin: t = b + a + c*)
124 "----------- build predicate for +- ordering ---------------------";
125 "----------- build predicate for +- ordering ---------------------";
126 "----------- build predicate for +- ordering ---------------------";
129 "123" < "a"; (*unused due to ---vvv*)
130 "12" < "3"; (*true !!!*)
132 " a kleiner b ==> (b + a) = (a + b)";
134 str2term "222 * aaa";
136 case eval_kleiner 0 0 (str2term "123 kleiner 32") 0 of
137 SOME ("12 kleiner 9 = False", _) => ()
138 | _ => error "polyminus.sml: 12 kleiner 9 = False";
140 (*========== inhibit exn =======================================================
141 case eval_kleiner 0 0 (str2term "a kleiner b") 0 of
142 SOME ("a kleiner b = True", _) => ()
143 | _ => error "polyminus.sml: a kleiner b = True";
145 case eval_kleiner 0 0 (str2term "(10*g) kleiner f") 0 of
146 SOME ("10 * g kleiner f = False", _) => ()
147 | _ => error "polyminus.sml: 10 * g kleiner f = False";
149 case eval_kleiner 0 0 (str2term "(a^^^2) kleiner b") 0 of
150 SOME ("a ^^^ 2 kleiner b = True", _) => ()
151 | _ => error "polyminus.sml: a ^^^ 2 kleiner b = True";
153 case eval_kleiner 0 0 (str2term "(3*a^^^2) kleiner b") 0 of
154 SOME ("3 * a ^^^ 2 kleiner b = True", _) => ()
155 | _ => error "polyminus.sml: 3 * a ^^^ 2 kleiner b = True";
157 case eval_kleiner 0 0 (str2term "(a*b) kleiner c") 0 of
158 SOME ("a * b kleiner c = True", _) => ()
159 | _ => error "polyminus.sml: a * b kleiner b = True";
161 case eval_kleiner 0 0 (str2term "(3*a*b) kleiner c") 0 of
162 SOME ("3 * a * b kleiner c = True", _) => ()
163 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
165 ============ inhibit exn =====================================================*)
168 "----- compare tausche_plus with real_num_collect";
171 val erls = erls_ordne_alphabetisch;
172 val t = str2term "b + a";
173 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
174 if term2str t = "a + b" then ()
175 else error "polyminus.sml: ordne_alphabetisch1 b + a";
177 val erls = Atools_erls;
178 val t = str2term "2*a + 3*a";
179 val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; term2str t;
181 "----- test rewrite_, rewrite_set_";
183 val erls = erls_ordne_alphabetisch;
184 val t = str2term "b + a";
185 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
186 if term2str t = "a + b" then ()
187 else error "polyminus.sml: ordne_alphabetisch a + b";
189 val t = str2term "2*b + a";
190 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
191 if term2str t = "a + 2 * b" then ()
192 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
194 val t = str2term "a + c + b";
195 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
196 if term2str t = "a + b + c" then ()
197 else error "polyminus.sml: ordne_alphabetisch a + b + c";
199 "----- rewrite goes into subterms";
200 val t = str2term "a + c + b + d";
201 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; term2str t;
202 if term2str t = "a + b + c + d" then ()
203 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
205 val t = str2term "a + c + d + b";
206 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
207 if term2str t = "a + b + c + d" then ()
208 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
210 "----- here we see rew_sub going into subterm with cond.rew....";
211 val t = str2term "b + a + c + d";
212 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
213 if term2str t = "a + b + c + d" then ()
214 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
216 "----- compile rls for the most complicated terms";
217 val t = str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
218 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
219 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t;
220 if term2str t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
221 then () else error "polyminus.sml: ordne_alphabetisch finished";
224 "----------- build fasse_zusammen --------------------------------";
225 "----------- build fasse_zusammen --------------------------------";
226 "----------- build fasse_zusammen --------------------------------";
227 val t = str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
228 val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
229 if term2str t = "3 + -2 * e + 2 * f + 2 * g" then ()
230 else error "polyminus.sml: fasse_zusammen finished";
232 "----------- build verschoenere ----------------------------------";
233 "----------- build verschoenere ----------------------------------";
234 "----------- build verschoenere ----------------------------------";
235 val t = str2term "3 + -2 * e + 2 * f + 2 * g";
236 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
237 if term2str t = "3 - 2 * e + 2 * f + 2 * g" then ()
238 else error "polyminus.sml: verschoenere 3 + -2 * e ...";
241 trace_rewrite:=false;
243 "----------- met simplification for_polynomials with_minus -------";
244 "----------- met simplification for_polynomials with_minus -------";
245 "----------- met simplification for_polynomials with_minus -------";
247 "Script SimplifyScript (t_t::real) = \
248 \ (((Try (Rewrite_Set ordne_alphabetisch False)) @@ \
249 \ (Try (Rewrite_Set fasse_zusammen False)) @@ \
250 \ (Try (Rewrite_Set verschoenere False))) t_t)"
251 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
255 "----------- me simplification.for_polynomials.with_minus";
256 "----------- me simplification.for_polynomials.with_minus";
257 "----------- me simplification.for_polynomials.with_minus";
259 val (p,_,f,nxt,_,pt) =
261 [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
263 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
264 ["simplification","for_polynomials","with_minus"]))];
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;
269 val (p,_,f,nxt,_,pt) = me nxt p c pt;
270 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 val (p,_,f,nxt,_,pt) = me nxt p c pt;
276 val (p,_,f,nxt,_,pt) = me nxt p c pt;
277 if f2str f = "3 - 2 * e + 2 * f + 2 * g" andalso #1 nxt = "End_Proof'" then ()
278 else error "polyminus.sml: me simplification.for_polynomials.with_minus";
281 "----------- pbl polynom vereinfachen p.33 -----------------------";
282 "----------- pbl polynom vereinfachen p.33 -----------------------";
283 "----------- pbl polynom vereinfachen p.33 -----------------------";
284 "----------- 140 c ---";
286 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
288 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
289 ["simplification","for_polynomials","with_minus"]))];
291 autoCalculate 1 CompleteCalc;
292 val ((pt,p),_) = get_calc 1; show_pt pt;
293 if p = ([], Res) andalso
294 term2str (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
295 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
297 "----------- 140 d ---";
299 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
301 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
302 ["simplification","for_polynomials","with_minus"]))];
304 autoCalculate 1 CompleteCalc;
305 val ((pt,p),_) = get_calc 1; show_pt pt;
306 (*========== inhibit exn 110520 ================================================
307 "??.empty" came with getting preconditions into ctxt:
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)";
312 ============ inhibit exn 110520 ==============================================*)
315 "----------- 139 c ---";
317 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
319 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
320 ["simplification","for_polynomials","with_minus"]))];
322 autoCalculate 1 CompleteCalc;
323 val ((pt,p),_) = get_calc 1; show_pt pt;
324 if p = ([], Res) andalso
325 term2str (get_obj g_res pt (fst p)) = "- (3 * f)"
326 then () else error "polyminus.sml: Vereinfache 139 c)";
328 "----------- 139 b ---";
330 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
332 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
333 ["simplification","for_polynomials","with_minus"]))];
335 autoCalculate 1 CompleteCalc;
336 val ((pt,p),_) = get_calc 1; show_pt pt;
337 if p = ([], Res) andalso
338 term2str (get_obj g_res pt (fst p)) = "-3 * u - v"
339 then () else error "polyminus.sml: Vereinfache 139 b)";
341 "----------- 138 a ---";
343 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
345 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
346 ["simplification","for_polynomials","with_minus"]))];
348 autoCalculate 1 CompleteCalc;
349 val ((pt,p),_) = get_calc 1; show_pt pt;
350 if p = ([], Res) andalso
351 term2str (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
352 then () else error "polyminus.sml: Vereinfache 138 a)";
355 "----------- met probe fuer_polynom ------------------------------";
356 "----------- met probe fuer_polynom ------------------------------";
357 "----------- met probe fuer_polynom ------------------------------";
359 "Script ProbeScript (e_e::bool) (w_s::bool list) =\
360 \ (let e_e = Take e_e; \
361 \ e_e = Substitute w_s e_e \
362 \ in (Repeat((Try (Repeat (Calculate TIMES))) @@ \
363 \ (Try (Repeat (Calculate PLUS ))) @@ \
364 \ (Try (Repeat (Calculate MINUS))))) e_e)"
365 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
369 "----------- pbl polynom probe -----------------------------------";
370 "----------- pbl polynom probe -----------------------------------";
371 "----------- pbl polynom probe -----------------------------------";
373 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
374 \3 - 2 * e + 2 * f + 2 * g)",
375 "mitWert [e = 1, f = 2, g = 3]",
377 ("PolyMinus",["polynom","probe"],
378 ["probe","fuer_polynom"]))];
380 autoCalculate 1 CompleteCalc;
381 (* autoCalculate 1 CompleteCalcHead;
382 autoCalculate 1 (Step 1);
383 autoCalculate 1 (Step 1);
384 val ((pt,p),_) = get_calc 1; term2str (get_obj g_res pt (fst p));
385 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
386 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
387 val ((pt,p),_) = get_calc 1;
388 (*========== inhibit exn 110310 ================================================
389 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "11 = 11"
390 then () else error "polyminus.sml: Probe 11 = 11";
394 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
395 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
396 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
398 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
400 ("PolyMinus",["klammer","polynom","vereinfachen"],
401 ["simplification","for_polynomials","with_parentheses"]))];
403 autoCalculate 1 CompleteCalc;
404 val ((pt,p),_) = get_calc 1;
405 if p = ([], Res) andalso
406 term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
407 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
410 "----- probe p.34 -----";
412 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * u)",
415 ("PolyMinus",["polynom","probe"],
416 ["probe","fuer_polynom"]))];
418 autoCalculate 1 CompleteCalc;
419 val ((pt,p),_) = get_calc 1;
420 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "29 = 29"
421 then () else error "polyminus.sml: Probe 29 = 29";
425 "----------- try fun applyTactics --------------------------------";
426 "----------- try fun applyTactics --------------------------------";
427 "----------- try fun applyTactics --------------------------------";
429 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
431 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
432 ["simplification","for_polynomials","with_minus"]))];
434 autoCalculate 1 CompleteCalcHead;
435 autoCalculate 1 (Step 1);
436 autoCalculate 1 (Step 1);
437 val ((pt,p),_) = get_calc 1; show_pt pt;
439 fetchApplicableTactics 1 0 p;
440 val appltacs = sel_appl_atomic_tacs pt p;
441 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
442 val ((pt,p),_) = get_calc 1; show_pt pt;
444 trace_rewrite := true;
445 val erls = erls_ordne_alphabetisch;
446 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
448 rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus} t;
449 term2str t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
451 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
453 rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
455 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
457 rewrite_set_ (@{theory "Isac"}) false ordne_alphabetisch t;
458 term2str t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
459 trace_rewrite := false;
462 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (*tausche_minus*);
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;
468 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
469 val ((pt,p),_) = get_calc 1; show_pt pt;
471 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
472 val ((pt,p),_) = get_calc 1; show_pt pt;
475 (*<CALCMESSAGE> failure </CALCMESSAGE>
476 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
477 val ((pt,p),_) = get_calc 1; show_pt pt;
481 autoCalculate 1 CompleteCalc;
482 val ((pt,p),_) = get_calc 1; show_pt pt;
483 (*independent from failure above: met_simp_poly_minus not confluent:
484 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
485 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
486 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
489 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
491 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
492 ["simplification","for_polynomials","with_minus"]))];
494 autoCalculate 1 CompleteCalc;
495 val ((pt,p),_) = get_calc 1; show_pt pt;
496 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "2 * g + h"
497 then () else error "polyminus.sml: addiere_vor_minus";
501 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
503 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
504 ["simplification","for_polynomials","with_minus"]))];
506 autoCalculate 1 CompleteCalc;
507 val ((pt,p),_) = get_calc 1; show_pt pt;
508 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "f + 2 * g"
509 then () else error "polyminus.sml: tausche_vor_plus";
512 "----------- pbl binom polynom vereinfachen p.39 -----------------";
513 "----------- pbl binom polynom vereinfachen p.39 -----------------";
514 "----------- pbl binom polynom vereinfachen p.39 -----------------";
515 val rls = klammern_ausmultiplizieren;
516 val t = str2term "(3 * a + 2) * (4 * a - 1)";
517 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
518 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
519 val rls = discard_parentheses;
520 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
521 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
522 val rls = ordne_monome;
523 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
524 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
526 val t = str2term "3 * a * 4 * a";
527 val rls = ordne_monome;
528 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
530 val rls = klammern_aufloesen;
531 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
532 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
533 val rls = ordne_alphabetisch;
534 (*TODO: make is_monom more general, a*a=a^2, ...*)
535 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
536 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
538 val rls = fasse_zusammen;
539 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
540 val rls = verschoenere;
541 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
545 trace_rewrite := true;
546 trace_rewrite := false;
550 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
552 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
553 ["simplification","for_polynomials","with_parentheses_mult"]))];
555 autoCalculate 1 CompleteCalc;
556 val ((pt,p),_) = get_calc 1; show_pt pt;
559 if p = ([], Res) andalso
560 term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
561 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
565 "----------- pbl binom polynom vereinfachen: cube ----------------";
566 "----------- pbl binom polynom vereinfachen: cube ----------------";
567 "----------- pbl binom polynom vereinfachen: cube ----------------";
569 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
570 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
571 ["simplification","for_polynomials","with_parentheses_mult"]))];
573 autoCalculate 1 CompleteCalc;
574 val ((pt,p),_) = get_calc 1; show_pt pt;
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";
643 "----------- check: fmz matches pbt ---------------------";
644 "----------- check: fmz matches pbt ---------------------";
645 "----------- check: fmz matches pbt ---------------------";
646 "101230 error *** nxt_add: EX itm. not(dat(itm)<=dat(ori))";
647 val fmz = ["TERM (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)","normalform N"];
648 val pI = ["plus_minus","polynom","vereinfachen"];
649 prep_ori fmz thy ((#ppc o get_pbt) pI);
651 [(1, [1], "#undef", Const (...), [...]), <<<===
652 (2, [1], "#Find", Const (...), [...])]
655 val t = str2term "TERM ttt";
657 val t = str2term "term ttt";
659 val t = str2term "Term ttt";
661 val fmz = ["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)","normalform N"];
662 prep_ori fmz thy ((#ppc o get_pbt) pI);
664 [(1, [1], "#Given", Const (...), [...]),
665 (2, [1], "#Find", Const (...), [...])]
668 ============ inhibit exn 110310 ==============================================*)