4 (c) due to copyright terms
6 "--------------------------------------------------------";
7 "--------------------------------------------------------";
8 "table of contents --------------------------------------";
9 "--------------------------------------------------------";
10 "----------- fun eval_ist_monom -------------------------";
11 "----------- watch order_add_mult ----------------------";
12 "----------- build predicate for +- ordering ------------";
13 "----------- build fasse_zusammen -----------------------";
14 "----------- build verschoenere -------------------------";
15 "----------- met simplification for_polynomials with_minu";
16 "----------- me simplification.for_polynomials.with_minus";
17 "----------- pbl polynom vereinfachen p.33 --------------";
18 "----------- met probe fuer_polynom ---------------------";
19 "----------- pbl polynom probe --------------------------";
20 "----------- pbl klammer polynom vereinfachen p.34 ------";
21 "----------- try fun applyTactics -----------------------";
22 "----------- pbl binom polynom vereinfachen p.39 --------";
23 "----------- pbl binom polynom vereinfachen: cube -------";
24 "----------- refine Vereinfache -------------------------";
25 "----------- *** prep_pbt: syntax error in '#Where' of [v";
26 "--------------------------------------------------------";
27 "--------------------------------------------------------";
28 "--------------------------------------------------------";
30 val thy = @{theory "PolyMinus"};
32 "----------- fun eval_ist_monom ----------------------------------";
33 "----------- fun eval_ist_monom ----------------------------------";
34 "----------- fun eval_ist_monom ----------------------------------";
35 ist_monom (str2term "12");
36 case eval_ist_monom 0 0 (str2term "12 ist_monom") 0 of
37 SOME ("12 ist_monom = True", _) => ()
38 | _ => error "polyminus.sml: 12 ist_monom = True";
40 case eval_ist_monom 0 0 (str2term "a ist_monom") 0 of
41 SOME ("a ist_monom = True", _) => ()
42 | _ => error "polyminus.sml: a ist_monom = True";
44 case eval_ist_monom 0 0 (str2term "(3*a) ist_monom") 0 of
45 SOME ("3 * a ist_monom = True", _) => ()
46 | _ => error "polyminus.sml: 3 * a ist_monom = True";
48 case eval_ist_monom 0 0 (str2term "(a^^^2) ist_monom") 0 of
49 SOME ("a ^^^ 2 ist_monom = True", _) => ()
50 | _ => error "polyminus.sml: a^^^2 ist_monom = True";
52 case eval_ist_monom 0 0 (str2term "(3*a^^^2) ist_monom") 0 of
53 SOME ("3 * a ^^^ 2 ist_monom = True", _) => ()
54 | _ => error "polyminus.sml: 3*a^^^2 ist_monom = True";
56 case eval_ist_monom 0 0 (str2term "(a*b) ist_monom") 0 of
57 SOME ("a * b ist_monom = True", _) => ()
58 | _ => error "polyminus.sml: a*b ist_monom = True";
60 case eval_ist_monom 0 0 (str2term "(3*a*b) ist_monom") 0 of
61 SOME ("3 * a * b ist_monom = True", _) => ()
62 | _ => error "polyminus.sml: 3*a*b ist_monom = True";
65 "----------- watch order_add_mult -------------------------------";
66 "----------- watch order_add_mult -------------------------------";
67 "----------- watch order_add_mult -------------------------------";
68 "----- with these simple variables it works...";
69 (*trace_rewrite := true; ..stopped Test_Isac.thy*)
71 val t = str2term "((a + d) + c) + b";
72 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
73 if term2str t = "a + (b + (c + d))" then ()
74 else error "polyminus.sml 1 watch order_add_mult";
77 "----- the same stepwise...";
78 val od = ord_make_polynomial true (@{theory "Poly"});
79 val t = str2term "((a + d) + c) + b";
81 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add.commute} t; term2str t;
83 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add.commute} t; term2str t;
85 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add.left_commute} t;term2str t;
87 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add.left_commute} t;term2str t;
89 if term2str t = "a + (b + (c + d))" then ()
90 else error "polyminus.sml 2 watch order_add_mult";
92 "----- if parentheses are right, left_commute is (almost) sufficient...";
93 val t = str2term "a + (d + (c + b))";
95 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add.left_commute} t;term2str t;
97 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add.commute} t;term2str t;
99 val SOME (t,_) = rewrite_ thy od e_rls true @{thm add.left_commute} t;term2str t;
102 "----- but we do not want the parentheses at right; thus: cond.rew.";
103 "WN0712707 complicated monomials do not yet work ...";
104 val t = str2term "((5*a + 4*d) + 3*c) + 2*b";
105 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
106 if term2str t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
107 else error "polyminus.sml: order_add_mult changed";
109 "----- here we see rew_sub going into subterm with ord.rew....";
110 val od = ord_make_polynomial false (@{theory "Poly"});
111 val t = str2term "b + a + c + d";
112 val SOME (t,_) = rewrite_ thy od e_rls false @{thm add.commute} t; term2str t;
113 val SOME (t,_) = rewrite_ thy od e_rls false @{thm add.commute} t; term2str t;
114 (*@@@ rew_sub gosub: t = d + (b + a + c)
115 @@@ rew_sub begin: t = b + a + c*)
118 "----------- build predicate for +- ordering ---------------------";
119 "----------- build predicate for +- ordering ---------------------";
120 "----------- build predicate for +- ordering ---------------------";
123 "123" < "a"; (*unused due to ---vvv*)
124 "12" < "3"; (*true !!!*)
126 " a kleiner b ==> (b + a) = (a + b)";
128 str2term "222 * aaa";
130 case eval_kleiner 0 0 (str2term "123 kleiner 32") 0 of
131 SOME ("123 kleiner 32 = False", _) => ()
132 | _ => error "polyminus.sml: 12 kleiner 9 = False";
134 case eval_kleiner 0 0 (str2term "a kleiner b") 0 of
135 SOME ("a kleiner b = True", _) => ()
136 | _ => error "polyminus.sml: a kleiner b = True";
138 case eval_kleiner 0 0 (str2term "(10*g) kleiner f") 0 of
139 SOME ("10 * g kleiner f = False", _) => ()
140 | _ => error "polyminus.sml: 10 * g kleiner f = False";
142 case eval_kleiner 0 0 (str2term "(a^^^2) kleiner b") 0 of
143 SOME ("a ^^^ 2 kleiner b = True", _) => ()
144 | _ => error "polyminus.sml: a ^^^ 2 kleiner b = True";
146 case eval_kleiner 0 0 (str2term "(3*a^^^2) kleiner b") 0 of
147 SOME ("3 * a ^^^ 2 kleiner b = True", _) => ()
148 | _ => error "polyminus.sml: 3 * a ^^^ 2 kleiner b = True";
150 case eval_kleiner 0 0 (str2term "(a*b) kleiner c") 0 of
151 SOME ("a * b kleiner c = True", _) => ()
152 | _ => error "polyminus.sml: a * b kleiner b = True";
154 case eval_kleiner 0 0 (str2term "(3*a*b) kleiner c") 0 of
155 SOME ("3 * a * b kleiner c = True", _) => ()
156 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
158 "======= compare tausche_plus with real_num_collect";
161 val erls = erls_ordne_alphabetisch;
162 val t = str2term "b + a";
163 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
164 if term2str t = "a + b" then ()
165 else error "polyminus.sml: ordne_alphabetisch1 b + a";
167 val erls = Atools_erls;
168 val t = str2term "2*a + 3*a";
169 val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; term2str t;
171 "======= test rewrite_, rewrite_set_";
172 (*trace_rewrite := true; ..stopped Test_Isac.thy*)
173 val erls = erls_ordne_alphabetisch;
174 val t = str2term "b + a";
175 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
176 if term2str t = "a + b" then ()
177 else error "polyminus.sml: ordne_alphabetisch a + b";
179 val t = str2term "2*b + a";
180 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
181 if term2str t = "a + 2 * b" then ()
182 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
184 val t = str2term "a + c + b";
185 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
186 if term2str t = "a + b + c" then ()
187 else error "polyminus.sml: ordne_alphabetisch a + b + c";
189 "======= rewrite goes into subterms";
190 val t = str2term "a + c + b + d";
191 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; term2str t;
192 if term2str t = "a + b + c + d" then ()
193 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
195 val t = str2term "a + c + d + b";
196 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
197 if term2str t = "a + b + c + d" then ()
198 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
200 "======= here we see rew_sub going into subterm with cond.rew....";
201 val t = str2term "b + a + c + d";
202 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
203 if term2str t = "a + b + c + d" then ()
204 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
206 "======= compile rls for the most complicated terms";
207 val t = str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
208 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
209 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t;
210 if term2str t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
211 then () else error "polyminus.sml: ordne_alphabetisch finished";
214 "----------- build fasse_zusammen --------------------------------";
215 "----------- build fasse_zusammen --------------------------------";
216 "----------- build fasse_zusammen --------------------------------";
217 val t = str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
218 val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
219 if term2str t = "3 + -2 * e + 2 * f + 2 * g" then ()
220 else error "polyminus.sml: fasse_zusammen finished";
222 "----------- build verschoenere ----------------------------------";
223 "----------- build verschoenere ----------------------------------";
224 "----------- build verschoenere ----------------------------------";
225 val t = str2term "3 + -2 * e + 2 * f + 2 * g";
226 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
227 if term2str t = "3 - 2 * e + 2 * f + 2 * g" then ()
228 else error "polyminus.sml: verschoenere 3 + -2 * e ...";
230 (*trace_rewrite := true; ..stopped Test_Isac.thy*)
231 trace_rewrite:=false;
233 "----------- met simplification for_polynomials with_minus -------";
234 "----------- met simplification for_polynomials with_minus -------";
235 "----------- met simplification for_polynomials with_minus -------";
237 "Script SimplifyScript (t_t::real) = \
238 \ (((Try (Rewrite_Set ordne_alphabetisch False)) @@ \
239 \ (Try (Rewrite_Set fasse_zusammen False)) @@ \
240 \ (Try (Rewrite_Set verschoenere False))) t_t)"
241 val sc = ((inst_abs thy) o Thm.term_of o the o (parse thy)) str;
244 "----------- me simplification.for_polynomials.with_minus";
245 "----------- me simplification.for_polynomials.with_minus";
246 "----------- me simplification.for_polynomials.with_minus";
248 val (p,_,f,nxt,_,pt) =
250 [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
252 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
253 ["simplification","for_polynomials","with_minus"]))];
254 val (p,_,f,nxt,_,pt) = me nxt p c pt;
255 val (p,_,f,nxt,_,pt) = me nxt p c pt;
256 val (p,_,f,nxt,_,pt) = me nxt p c pt;
257 val (p,_,f,nxt,_,pt) = me nxt p c pt;
258 val (p,_,f,nxt,_,pt) = me nxt p c pt;
259 val (p,_,f,nxt,_,pt) = me nxt p c pt;
261 val (p,_,f,nxt,_,pt) = me nxt p c pt;
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 if f2str f = "3 - 2 * e + 2 * f + 2 * g" andalso #1 nxt = "End_Proof'" then ()
267 else error "polyminus.sml: me simplification.for_polynomials.with_minus";
269 "----------- pbl polynom vereinfachen p.33 -----------------------";
270 "----------- pbl polynom vereinfachen p.33 -----------------------";
271 "----------- pbl polynom vereinfachen p.33 -----------------------";
272 "----------- 140 c ---";
274 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
276 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
277 ["simplification","for_polynomials","with_minus"]))];
279 autoCalculate 1 CompleteCalc;
280 val ((pt,p),_) = get_calc 1; show_pt pt;
281 if p = ([], Res) andalso
282 term2str (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
283 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
287 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
289 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
290 ["simplification","for_polynomials","with_minus"]))];
292 autoCalculate 1 CompleteCalc;
293 val ((pt,p),_) = get_calc 1; show_pt pt;
294 if p = ([], Res) andalso
295 term2str (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
296 then () else error "polyminus.sml: Vereinfache 140 d)";
300 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
302 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
303 ["simplification","for_polynomials","with_minus"]))];
305 autoCalculate 1 CompleteCalc;
306 val ((pt,p),_) = get_calc 1; show_pt pt;
307 if p = ([], Res) andalso
308 term2str (get_obj g_res pt (fst p)) = "- (3 * f)"
309 then () else error "polyminus.sml: Vereinfache 139 c)";
313 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
315 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
316 ["simplification","for_polynomials","with_minus"]))];
318 autoCalculate 1 CompleteCalc;
319 val ((pt,p),_) = get_calc 1; show_pt pt;
320 if p = ([], Res) andalso
321 term2str (get_obj g_res pt (fst p)) = "-3 * u - v"
322 then () else error "polyminus.sml: Vereinfache 139 b)";
326 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
328 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
329 ["simplification","for_polynomials","with_minus"]))];
331 autoCalculate 1 CompleteCalc;
332 val ((pt,p),_) = get_calc 1; show_pt pt;
333 if p = ([], Res) andalso
334 term2str (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
335 then () else error "polyminus.sml: Vereinfache 138 a)";
337 "----------- met probe fuer_polynom ------------------------------";
338 "----------- met probe fuer_polynom ------------------------------";
339 "----------- met probe fuer_polynom ------------------------------";
341 "Script ProbeScript (e_e::bool) (w_s::bool list) =\
342 \ (let e_e = Take e_e; \
343 \ e_e = Substitute w_s e_e \
344 \ in (Repeat((Try (Repeat (Calculate TIMES))) @@ \
345 \ (Try (Repeat (Calculate PLUS ))) @@ \
346 \ (Try (Repeat (Calculate MINUS))))) e_e)"
347 val sc = ((inst_abs thy) o Thm.term_of o the o (parse thy)) str;
350 "----------- pbl polynom probe -----------------------------------";
351 "----------- pbl polynom probe -----------------------------------";
352 "----------- pbl polynom probe -----------------------------------";
354 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
355 \3 - 2 * e + 2 * f + 2 * g)",
356 "mitWert [e = 1, f = 2, g = 3]",
358 ("PolyMinus",["polynom","probe"],
359 ["probe","fuer_polynom"]))];
361 autoCalculate 1 CompleteCalc;
362 (* autoCalculate 1 CompleteCalcHead;
363 autoCalculate 1 (Step 1);
364 autoCalculate 1 (Step 1);
365 val ((pt,p),_) = get_calc 1; term2str (get_obj g_res pt (fst p));
366 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
367 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
368 val ((pt,p),_) = get_calc 1;
369 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "11 = 11"
370 then () else error "polyminus.sml: Probe 11 = 11";
373 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
374 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
375 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
377 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
379 ("PolyMinus",["klammer","polynom","vereinfachen"],
380 ["simplification","for_polynomials","with_parentheses"]))];
382 autoCalculate 1 CompleteCalc;
383 val ((pt,p),_) = get_calc 1;
384 if p = ([], Res) andalso
385 term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
386 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
389 "======= probe p.34 -----";
391 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * u)",
394 ("PolyMinus",["polynom","probe"],
395 ["probe","fuer_polynom"]))];
397 autoCalculate 1 CompleteCalc;
398 val ((pt,p),_) = get_calc 1;
399 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "29 = 29"
400 then () else error "polyminus.sml: Probe 29 = 29";
403 "----------- try fun applyTactics --------------------------------";
404 "----------- try fun applyTactics --------------------------------";
405 "----------- try fun applyTactics --------------------------------";
407 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
409 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
410 ["simplification","for_polynomials","with_minus"]))];
412 autoCalculate 1 CompleteCalcHead;
413 autoCalculate 1 (Step 1);
414 autoCalculate 1 (Step 1);
415 val ((pt,p),_) = get_calc 1; show_pt pt;
417 fetchApplicableTactics 1 0 p;
418 val appltacs = sel_appl_atomic_tacs pt p;
419 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
420 val ((pt,p),_) = get_calc 1; show_pt pt;
422 (*trace_rewrite := true; ..stopped Test_Isac.thy*)
423 val erls = erls_ordne_alphabetisch;
424 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
426 rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus} t;
427 term2str t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
429 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
431 rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
433 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
435 rewrite_set_ (@{theory "Isac"}) false ordne_alphabetisch t;
436 term2str t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
437 trace_rewrite := false;
440 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (*tausche_minus*);
441 val ((pt,p),_) = get_calc 1; show_pt pt;
443 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
444 val ((pt,p),_) = get_calc 1; show_pt pt;
446 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
447 val ((pt,p),_) = get_calc 1; show_pt pt;
449 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
450 val ((pt,p),_) = get_calc 1; show_pt pt;
453 (*<CALCMESSAGE> failure </CALCMESSAGE>
454 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
455 val ((pt,p),_) = get_calc 1; show_pt pt;
458 autoCalculate 1 CompleteCalc;
459 val ((pt,p),_) = get_calc 1; show_pt pt;
460 (*independent from failure above: met_simp_poly_minus not confluent:
461 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
462 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
463 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
466 "#############################################################################";
468 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
470 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
471 ["simplification","for_polynomials","with_minus"]))];
473 autoCalculate 1 CompleteCalc;
474 val ((pt,p),_) = get_calc 1; show_pt pt;
475 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "2 * g + h"
476 then () else error "polyminus.sml: addiere_vor_minus";
479 "#############################################################################";
481 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
483 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
484 ["simplification","for_polynomials","with_minus"]))];
486 autoCalculate 1 CompleteCalc;
487 val ((pt,p),_) = get_calc 1; show_pt pt;
488 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "f + 2 * g"
489 then () else error "polyminus.sml: tausche_vor_plus";
491 "----------- pbl binom polynom vereinfachen p.39 -----------------";
492 "----------- pbl binom polynom vereinfachen p.39 -----------------";
493 "----------- pbl binom polynom vereinfachen p.39 -----------------";
494 val rls = klammern_ausmultiplizieren;
495 val t = str2term "(3 * a + 2) * (4 * a - 1)";
496 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
497 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
498 val rls = discard_parentheses;
499 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
500 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
501 val rls = ordne_monome;
502 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
503 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
505 val t = str2term "3 * a * 4 * a";
506 val rls = ordne_monome;
507 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
509 val rls = klammern_aufloesen;
510 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
511 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
512 val rls = ordne_alphabetisch;
513 (*TODO: make is_monom more general, a*a=a^2, ...*)
514 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
515 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
517 val rls = fasse_zusammen;
518 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
519 val rls = verschoenere;
520 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
525 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
527 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
528 ["simplification","for_polynomials","with_parentheses_mult"]))];
530 autoCalculate 1 CompleteCalc;
531 val ((pt,p),_) = get_calc 1; show_pt pt;
532 if p = ([], Res) andalso
533 term2str (get_obj g_res pt (fst p)) = "-2 + 12 * a ^^^ 2 + 5 * a"
534 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
536 "----------- pbl binom polynom vereinfachen: cube ----------------";
537 "----------- pbl binom polynom vereinfachen: cube ----------------";
538 "----------- pbl binom polynom vereinfachen: cube ----------------";
540 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
541 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
542 ["simplification","for_polynomials","with_parentheses_mult"]))];
544 autoCalculate 1 CompleteCalc;
545 val ((pt,p),_) = get_calc 1; show_pt pt;
546 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "12 * a - 16 * q"
547 then () else error "pbl binom polynom vereinfachen: cube";
549 "----------- refine Vereinfache ----------------------------------";
550 "----------- refine Vereinfache ----------------------------------";
551 "----------- refine Vereinfache ----------------------------------";
552 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"];
553 (*default_print_depth 11;*)
554 val matches = refine fmz ["vereinfachen"];
555 (*default_print_depth 3;*)
557 "----- go into details, if it seems not to work -----";
558 "--- does the predicate evaluate correctly ?";
560 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))";
561 val ma = eval_matchsub "" "Tools.matchsub" t thy;
563 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
564 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
565 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
567 "--- does the respective prls rewrite ?";
568 val prls = append_rls "prls_pbl_vereinf_poly" e_rls
569 [Calc ("Poly.is'_polyexp", eval_is_polyexp ""),
570 Calc ("Tools.matchsub", eval_matchsub ""),
571 Thm ("or_true",@{thm or_true}),
572 (*"(?a | True) = True"*)
573 Thm ("or_false",@{thm or_false}),
574 (*"(?a | False) = ?a"*)
575 Thm ("not_true",num_str @{thm not_true}),
576 (*"(~ True) = False"*)
577 Thm ("not_false",num_str @{thm not_false})
578 (*"(~ False) = True"*)];
579 (*trace_rewrite := true; ..stopped Test_Isac.thy*)
580 val SOME (t', _) = rewrite_set_ thy false prls t;
581 trace_rewrite := false;
583 "--- does the respective prls rewrite the whole predicate ?";
585 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
586 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
587 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
588 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
589 (*trace_rewrite := true; ..stopped Test_Isac.thy*)
590 val SOME (t', _) = rewrite_set_ thy false prls t;
591 trace_rewrite := false;
592 if term2str t' = "False" then ()
593 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
595 "----------- *** prep_pbt: syntax error in '#Where' of [v";
596 "----------- *** prep_pbt: syntax error in '#Where' of [v";
597 "----------- *** prep_pbt: syntax error in '#Where' of [v";
598 (*see test/../termC.sml for details*)
599 val t = parse_patt thy "t_t is_polyexp";
600 val t = parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
601 " matchsub (?a + (?b - ?c)) t_t | " ^
602 " matchsub (?a - (?b + ?c)) t_t | " ^
603 " matchsub (?a + (?b - ?c)) t_t )");
604 (*show_types := true;
605 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)"
606 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
607 show_types := false;*)
608 if term2str t = "~ (matchsub (?a + (?b + ?c)) t_t |\n matchsub (?a + (?b - ?c)) t_t |\n" ^
609 " matchsub (?a - (?b + ?c)) t_t | matchsub (?a + (?b - ?c)) t_t)"
610 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";