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 ("123 kleiner 32 = False", _) => ()
135 | _ => error "polyminus.sml: 12 kleiner 9 = False";
137 case eval_kleiner 0 0 (str2term "a kleiner b") 0 of
138 SOME ("a kleiner b = True", _) => ()
139 | _ => error "polyminus.sml: a kleiner b = True";
141 case eval_kleiner 0 0 (str2term "(10*g) kleiner f") 0 of
142 SOME ("10 * g kleiner f = False", _) => ()
143 | _ => error "polyminus.sml: 10 * g kleiner f = False";
145 case eval_kleiner 0 0 (str2term "(a^^^2) kleiner b") 0 of
146 SOME ("a ^^^ 2 kleiner b = True", _) => ()
147 | _ => error "polyminus.sml: a ^^^ 2 kleiner b = True";
149 case eval_kleiner 0 0 (str2term "(3*a^^^2) kleiner b") 0 of
150 SOME ("3 * a ^^^ 2 kleiner b = True", _) => ()
151 | _ => error "polyminus.sml: 3 * a ^^^ 2 kleiner b = True";
153 case eval_kleiner 0 0 (str2term "(a*b) kleiner c") 0 of
154 SOME ("a * b kleiner c = True", _) => ()
155 | _ => error "polyminus.sml: a * b kleiner b = True";
157 case eval_kleiner 0 0 (str2term "(3*a*b) kleiner c") 0 of
158 SOME ("3 * a * b kleiner c = True", _) => ()
159 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
161 "======= compare tausche_plus with real_num_collect";
164 val erls = erls_ordne_alphabetisch;
165 val t = str2term "b + a";
166 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
167 if term2str t = "a + b" then ()
168 else error "polyminus.sml: ordne_alphabetisch1 b + a";
170 val erls = Atools_erls;
171 val t = str2term "2*a + 3*a";
172 val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; term2str t;
174 "======= test rewrite_, rewrite_set_";
176 val erls = erls_ordne_alphabetisch;
177 val t = str2term "b + a";
178 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
179 if term2str t = "a + b" then ()
180 else error "polyminus.sml: ordne_alphabetisch a + b";
182 val t = str2term "2*b + a";
183 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
184 if term2str t = "a + 2 * b" then ()
185 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
187 val t = str2term "a + c + b";
188 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
189 if term2str t = "a + b + c" then ()
190 else error "polyminus.sml: ordne_alphabetisch a + b + c";
192 "======= rewrite goes into subterms";
193 val t = str2term "a + c + b + d";
194 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; term2str t;
195 if term2str t = "a + b + c + d" then ()
196 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
198 val t = str2term "a + c + d + b";
199 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
200 if term2str t = "a + b + c + d" then ()
201 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
203 "======= here we see rew_sub going into subterm with cond.rew....";
204 val t = str2term "b + a + c + d";
205 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; term2str t;
206 if term2str t = "a + b + c + d" then ()
207 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
209 "======= compile rls for the most complicated terms";
210 val t = str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
211 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
212 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t;
213 if term2str t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
214 then () else error "polyminus.sml: ordne_alphabetisch finished";
217 "----------- build fasse_zusammen --------------------------------";
218 "----------- build fasse_zusammen --------------------------------";
219 "----------- build fasse_zusammen --------------------------------";
220 val t = str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
221 val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
222 if term2str t = "3 + -2 * e + 2 * f + 2 * g" then ()
223 else error "polyminus.sml: fasse_zusammen finished";
225 "----------- build verschoenere ----------------------------------";
226 "----------- build verschoenere ----------------------------------";
227 "----------- build verschoenere ----------------------------------";
228 val t = str2term "3 + -2 * e + 2 * f + 2 * g";
229 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
230 if term2str t = "3 - 2 * e + 2 * f + 2 * g" then ()
231 else error "polyminus.sml: verschoenere 3 + -2 * e ...";
234 trace_rewrite:=false;
236 "----------- met simplification for_polynomials with_minus -------";
237 "----------- met simplification for_polynomials with_minus -------";
238 "----------- met simplification for_polynomials with_minus -------";
240 "Script SimplifyScript (t_t::real) = \
241 \ (((Try (Rewrite_Set ordne_alphabetisch False)) @@ \
242 \ (Try (Rewrite_Set fasse_zusammen False)) @@ \
243 \ (Try (Rewrite_Set verschoenere False))) t_t)"
244 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
247 "----------- me simplification.for_polynomials.with_minus";
248 "----------- me simplification.for_polynomials.with_minus";
249 "----------- me simplification.for_polynomials.with_minus";
251 val (p,_,f,nxt,_,pt) =
253 [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
255 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
256 ["simplification","for_polynomials","with_minus"]))];
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;
260 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;
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;
269 if f2str f = "3 - 2 * e + 2 * f + 2 * g" andalso #1 nxt = "End_Proof'" then ()
270 else error "polyminus.sml: me simplification.for_polynomials.with_minus";
272 "----------- pbl polynom vereinfachen p.33 -----------------------";
273 "----------- pbl polynom vereinfachen p.33 -----------------------";
274 "----------- pbl polynom vereinfachen p.33 -----------------------";
275 "----------- 140 c ---";
277 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
279 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
280 ["simplification","for_polynomials","with_minus"]))];
282 autoCalculate 1 CompleteCalc;
283 val ((pt,p),_) = get_calc 1; show_pt pt;
284 if p = ([], Res) andalso
285 term2str (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
286 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
290 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
292 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
293 ["simplification","for_polynomials","with_minus"]))];
295 autoCalculate 1 CompleteCalc;
296 val ((pt,p),_) = get_calc 1; show_pt pt;
297 if p = ([], Res) andalso
298 term2str (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
299 then () else error "polyminus.sml: Vereinfache 140 d)";
303 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
305 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
306 ["simplification","for_polynomials","with_minus"]))];
308 autoCalculate 1 CompleteCalc;
309 val ((pt,p),_) = get_calc 1; show_pt pt;
310 if p = ([], Res) andalso
311 term2str (get_obj g_res pt (fst p)) = "- (3 * f)"
312 then () else error "polyminus.sml: Vereinfache 139 c)";
316 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
318 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
319 ["simplification","for_polynomials","with_minus"]))];
321 autoCalculate 1 CompleteCalc;
322 val ((pt,p),_) = get_calc 1; show_pt pt;
323 if p = ([], Res) andalso
324 term2str (get_obj g_res pt (fst p)) = "-3 * u - v"
325 then () else error "polyminus.sml: Vereinfache 139 b)";
329 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
331 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
332 ["simplification","for_polynomials","with_minus"]))];
334 autoCalculate 1 CompleteCalc;
335 val ((pt,p),_) = get_calc 1; show_pt pt;
336 if p = ([], Res) andalso
337 term2str (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
338 then () else error "polyminus.sml: Vereinfache 138 a)";
340 "----------- met probe fuer_polynom ------------------------------";
341 "----------- met probe fuer_polynom ------------------------------";
342 "----------- met probe fuer_polynom ------------------------------";
344 "Script ProbeScript (e_e::bool) (w_s::bool list) =\
345 \ (let e_e = Take e_e; \
346 \ e_e = Substitute w_s e_e \
347 \ in (Repeat((Try (Repeat (Calculate TIMES))) @@ \
348 \ (Try (Repeat (Calculate PLUS ))) @@ \
349 \ (Try (Repeat (Calculate MINUS))))) e_e)"
350 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
353 "----------- pbl polynom probe -----------------------------------";
354 "----------- pbl polynom probe -----------------------------------";
355 "----------- pbl polynom probe -----------------------------------";
357 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
358 \3 - 2 * e + 2 * f + 2 * g)",
359 "mitWert [e = 1, f = 2, g = 3]",
361 ("PolyMinus",["polynom","probe"],
362 ["probe","fuer_polynom"]))];
364 autoCalculate 1 CompleteCalc;
365 (* autoCalculate 1 CompleteCalcHead;
366 autoCalculate 1 (Step 1);
367 autoCalculate 1 (Step 1);
368 val ((pt,p),_) = get_calc 1; term2str (get_obj g_res pt (fst p));
369 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
370 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
371 val ((pt,p),_) = get_calc 1;
372 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "11 = 11"
373 then () else error "polyminus.sml: Probe 11 = 11";
376 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
377 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
378 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
380 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
382 ("PolyMinus",["klammer","polynom","vereinfachen"],
383 ["simplification","for_polynomials","with_parentheses"]))];
385 autoCalculate 1 CompleteCalc;
386 val ((pt,p),_) = get_calc 1;
387 if p = ([], Res) andalso
388 term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
389 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
392 "======= probe p.34 -----";
394 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * u)",
397 ("PolyMinus",["polynom","probe"],
398 ["probe","fuer_polynom"]))];
400 autoCalculate 1 CompleteCalc;
401 val ((pt,p),_) = get_calc 1;
402 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "29 = 29"
403 then () else error "polyminus.sml: Probe 29 = 29";
406 "----------- try fun applyTactics --------------------------------";
407 "----------- try fun applyTactics --------------------------------";
408 "----------- try fun applyTactics --------------------------------";
410 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
412 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
413 ["simplification","for_polynomials","with_minus"]))];
415 autoCalculate 1 CompleteCalcHead;
416 autoCalculate 1 (Step 1);
417 autoCalculate 1 (Step 1);
418 val ((pt,p),_) = get_calc 1; show_pt pt;
420 fetchApplicableTactics 1 0 p;
421 val appltacs = sel_appl_atomic_tacs pt p;
422 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
423 val ((pt,p),_) = get_calc 1; show_pt pt;
425 trace_rewrite := true;
426 val erls = erls_ordne_alphabetisch;
427 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
429 rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus} t;
430 term2str t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
432 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
434 rewrite_ (@{theory "Isac"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
436 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
438 rewrite_set_ (@{theory "Isac"}) false ordne_alphabetisch t;
439 term2str t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
440 trace_rewrite := false;
443 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (*tausche_minus*);
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;
452 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
453 val ((pt,p),_) = get_calc 1; show_pt pt;
456 (*<CALCMESSAGE> failure </CALCMESSAGE>
457 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
458 val ((pt,p),_) = get_calc 1; show_pt pt;
461 autoCalculate 1 CompleteCalc;
462 val ((pt,p),_) = get_calc 1; show_pt pt;
463 (*independent from failure above: met_simp_poly_minus not confluent:
464 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
465 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
466 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
469 "#############################################################################";
471 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
473 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
474 ["simplification","for_polynomials","with_minus"]))];
476 autoCalculate 1 CompleteCalc;
477 val ((pt,p),_) = get_calc 1; show_pt pt;
478 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "2 * g + h"
479 then () else error "polyminus.sml: addiere_vor_minus";
482 "#############################################################################";
484 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
486 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
487 ["simplification","for_polynomials","with_minus"]))];
489 autoCalculate 1 CompleteCalc;
490 val ((pt,p),_) = get_calc 1; show_pt pt;
491 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "f + 2 * g"
492 then () else error "polyminus.sml: tausche_vor_plus";
494 "----------- pbl binom polynom vereinfachen p.39 -----------------";
495 "----------- pbl binom polynom vereinfachen p.39 -----------------";
496 "----------- pbl binom polynom vereinfachen p.39 -----------------";
497 val rls = klammern_ausmultiplizieren;
498 val t = str2term "(3 * a + 2) * (4 * a - 1)";
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 = discard_parentheses;
502 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
503 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
504 val rls = ordne_monome;
505 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
506 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
508 val t = str2term "3 * a * 4 * a";
509 val rls = ordne_monome;
510 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
512 val rls = klammern_aufloesen;
513 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
514 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
515 val rls = ordne_alphabetisch;
516 (*TODO: make is_monom more general, a*a=a^2, ...*)
517 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
518 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
520 val rls = fasse_zusammen;
521 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
522 val rls = verschoenere;
523 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
528 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
530 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
531 ["simplification","for_polynomials","with_parentheses_mult"]))];
533 autoCalculate 1 CompleteCalc;
534 val ((pt,p),_) = get_calc 1; show_pt pt;
535 if p = ([], Res) andalso
536 term2str (get_obj g_res pt (fst p)) = "-2 + 12 * a ^^^ 2 + 5 * a"
537 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
539 "----------- pbl binom polynom vereinfachen: cube ----------------";
540 "----------- pbl binom polynom vereinfachen: cube ----------------";
541 "----------- pbl binom polynom vereinfachen: cube ----------------";
543 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
544 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
545 ["simplification","for_polynomials","with_parentheses_mult"]))];
547 autoCalculate 1 CompleteCalc;
548 val ((pt,p),_) = get_calc 1; show_pt pt;
549 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "12 * a - 16 * q"
550 then () else error "pbl binom polynom vereinfachen: cube";
552 "----------- refine Vereinfache ----------------------------------";
553 "----------- refine Vereinfache ----------------------------------";
554 "----------- refine Vereinfache ----------------------------------";
555 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"];
557 val matches = refine fmz ["vereinfachen"];
560 "----- go into details, if it seems not to work -----";
561 "--- does the predicate evaluate correctly ?";
563 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))";
564 val ma = eval_matchsub "" "Tools.matchsub" t thy;
566 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
567 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
568 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
570 "--- does the respective prls rewrite ?";
571 val prls = append_rls "prls_pbl_vereinf_poly" e_rls
572 [Calc ("Poly.is'_polyexp", eval_is_polyexp ""),
573 Calc ("Tools.matchsub", eval_matchsub ""),
574 Thm ("or_true",@{thm or_true}),
575 (*"(?a | True) = True"*)
576 Thm ("or_false",@{thm or_false}),
577 (*"(?a | False) = ?a"*)
578 Thm ("not_true",num_str @{thm not_true}),
579 (*"(~ True) = False"*)
580 Thm ("not_false",num_str @{thm not_false})
581 (*"(~ False) = True"*)];
582 trace_rewrite := true;
583 val SOME (t', _) = rewrite_set_ thy false prls t;
584 trace_rewrite := false;
586 "--- does the respective prls rewrite the whole predicate ?";
588 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
589 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
590 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
591 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
592 trace_rewrite := true;
593 val SOME (t', _) = rewrite_set_ thy false prls t;
594 trace_rewrite := false;
595 if term2str t' = "False" then ()
596 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
598 "----------- *** prep_pbt: syntax error in '#Where' of [v";
599 "----------- *** prep_pbt: syntax error in '#Where' of [v";
600 "----------- *** prep_pbt: syntax error in '#Where' of [v";
601 (*see test/../termC.sml for details*)
602 val t = parse_patt thy "t_t is_polyexp";
603 val t = parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
604 " matchsub (?a + (?b - ?c)) t_t | " ^
605 " matchsub (?a - (?b + ?c)) t_t | " ^
606 " matchsub (?a + (?b - ?c)) t_t )");
607 (*show_types := true;
608 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)"
609 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
610 show_types := false;*)
611 if term2str t = "~ (matchsub (?a + (?b + ?c)) t_t |\n matchsub (?a + (?b - ?c)) t_t |\n" ^
612 " matchsub (?a - (?b + ?c)) t_t | matchsub (?a + (?b - ?c)) t_t)"
613 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";