intermed. 'fun parse_patt' fixes types to real (like 'parse')
this was on the way to repair rewrite (prepat in Rrls)
4 (c) due to copyright terms
6 use"../smltest/IsacKnowledge/polyminus.sml";
9 (*========== inhibit exn ?======================================================
10 "--------------------------------------------------------";
11 "--------------------------------------------------------";
12 "table of contents --------------------------------------";
13 "--------------------------------------------------------";
14 "----------- fun eval_ist_monom -------------------------";
15 "----------- watch order_add_mult ----------------------";
16 "----------- build predicate for +- ordering ------------";
17 "----------- build fasse_zusammen -----------------------";
18 "----------- build verschoenere -------------------------";
19 "----------- met simplification for_polynomials with_minu";
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 = PolyMinus.thy;
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 Poly.thy;
82 val t = str2term "((a + d) + c) + b";
84 val SOME (t,_) = rewrite_ thy od e_rls true add_commute t; term2str t;
86 val SOME (t,_) = rewrite_ thy od e_rls true add_commute t; term2str t;
88 val SOME (t,_) = rewrite_ thy od e_rls true add_left_commute t;term2str t;
90 val SOME (t,_) = rewrite_ thy od e_rls true 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 add_left_commute t;term2str t;
100 val SOME (t,_) = rewrite_ thy od e_rls true add_commute t;term2str t;
102 val SOME (t,_) = rewrite_ thy od e_rls true 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 Poly.thy;
114 val t = str2term "b + a + c + d";
115 val SOME (t,_) = rewrite_ thy od e_rls false add_commute t; term2str t;
116 val SOME (t,_) = rewrite_ thy od e_rls false 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 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";
163 "----- compare tausche_plus with real_num_collect";
166 val erls = erls_ordne_alphabetisch;
167 val t = str2term "b + a";
168 val SOME (t,_) = rewrite_ thy od erls false tausche_plus t; term2str t;
169 if term2str t = "a + b" then ()
170 else error "polyminus.sml: ordne_alphabetisch1 b + a";
172 val erls = Atools_erls;
173 val t = str2term "2*a + 3*a";
174 val SOME (t,_) = rewrite_ thy od erls false real_num_collect t; term2str t;
176 "----- test rewrite_, rewrite_set_";
178 val erls = erls_ordne_alphabetisch;
179 val t = str2term "b + a";
180 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
181 if term2str t = "a + b" then ()
182 else error "polyminus.sml: ordne_alphabetisch a + b";
184 val t = str2term "2*b + a";
185 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
186 if term2str t = "a + 2 * b" then ()
187 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
189 val t = str2term "a + c + b";
190 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
191 if term2str t = "a + b + c" then ()
192 else error "polyminus.sml: ordne_alphabetisch a + b + c";
194 "----- rewrite goes into subterms";
195 val t = str2term "a + c + b + d";
196 val SOME (t,_) = rewrite_ thy od erls false tausche_plus_plus t; term2str t;
197 if term2str t = "a + b + c + d" then ()
198 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
200 val t = str2term "a + c + d + b";
201 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
202 if term2str t = "a + b + c + d" then ()
203 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
205 "----- here we see rew_sub going into subterm with cond.rew....";
206 val t = str2term "b + a + c + d";
207 val SOME (t,_) = rewrite_ thy od erls false tausche_plus t; term2str t;
208 if term2str t = "a + b + c + d" then ()
209 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
211 "----- compile rls for the most complicated terms";
212 val t = str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
213 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
214 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t;
215 if term2str t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
216 then () else error "polyminus.sml: ordne_alphabetisch finished";
219 "----------- build fasse_zusammen --------------------------------";
220 "----------- build fasse_zusammen --------------------------------";
221 "----------- build fasse_zusammen --------------------------------";
222 val t = str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
223 val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
224 if term2str t = "3 + -2 * e + 2 * f + 2 * g" then ()
225 else error "polyminus.sml: fasse_zusammen finished";
227 "----------- build verschoenere ----------------------------------";
228 "----------- build verschoenere ----------------------------------";
229 "----------- build verschoenere ----------------------------------";
230 val t = str2term "3 + -2 * e + 2 * f + 2 * g";
231 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
232 if term2str t = "3 - 2 * e + 2 * f + 2 * g" then ()
233 else error "polyminus.sml: verschoenere 3 + -2 * e ...";
236 trace_rewrite:=false;
238 "----------- met simplification for_polynomials with_minus -------";
239 "----------- met simplification for_polynomials with_minus -------";
240 "----------- met simplification for_polynomials with_minus -------";
242 "Script SimplifyScript (t_::real) = \
243 \ (((Try (Rewrite_Set ordne_alphabetisch False)) @@ \
244 \ (Try (Rewrite_Set fasse_zusammen False)) @@ \
245 \ (Try (Rewrite_Set verschoenere False))) t_)"
246 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
250 "----------- pbl polynom vereinfachen p.33 -----------------------";
251 "----------- pbl polynom vereinfachen p.33 -----------------------";
252 "----------- pbl polynom vereinfachen p.33 -----------------------";
253 "----------- 140 c ---";
255 CalcTree [(["TERM (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
257 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
258 ["simplification","for_polynomials","with_minus"]))];
260 autoCalculate 1 CompleteCalc;
261 val ((pt,p),_) = get_calc 1; show_pt pt;
262 if p = ([], Res) andalso
263 term2str (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
264 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
266 "----------- 140 d ---";
268 CalcTree [(["TERM (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
270 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
271 ["simplification","for_polynomials","with_minus"]))];
273 autoCalculate 1 CompleteCalc;
274 val ((pt,p),_) = get_calc 1; show_pt pt;
275 if p = ([], Res) andalso
276 term2str (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
277 then () else error "polyminus.sml: Vereinfache 140 d)";
280 "----------- 139 c ---";
282 CalcTree [(["TERM (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
284 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
285 ["simplification","for_polynomials","with_minus"]))];
287 autoCalculate 1 CompleteCalc;
288 val ((pt,p),_) = get_calc 1; show_pt pt;
289 if p = ([], Res) andalso
290 term2str (get_obj g_res pt (fst p)) = "- (3 * f)"
291 then () else error "polyminus.sml: Vereinfache 139 c)";
293 "----------- 139 b ---";
295 CalcTree [(["TERM (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
297 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
298 ["simplification","for_polynomials","with_minus"]))];
300 autoCalculate 1 CompleteCalc;
301 val ((pt,p),_) = get_calc 1; show_pt pt;
302 if p = ([], Res) andalso
303 term2str (get_obj g_res pt (fst p)) = "-3 * u - v"
304 then () else error "polyminus.sml: Vereinfache 139 b)";
306 "----------- 138 a ---";
308 CalcTree [(["TERM (2*u - 3*v - 6*u + 5*v)",
310 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
311 ["simplification","for_polynomials","with_minus"]))];
313 autoCalculate 1 CompleteCalc;
314 val ((pt,p),_) = get_calc 1; show_pt pt;
315 if p = ([], Res) andalso
316 term2str (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
317 then () else error "polyminus.sml: Vereinfache 138 a)";
320 "----------- met probe fuer_polynom ------------------------------";
321 "----------- met probe fuer_polynom ------------------------------";
322 "----------- met probe fuer_polynom ------------------------------";
324 "Script ProbeScript (e_e::bool) (ws_::bool list) =\
325 \ (let e_e = Take e_e; \
326 \ e_e = Substitute ws_ e_e \
327 \ in (Repeat((Try (Repeat (Calculate TIMES))) @@ \
328 \ (Try (Repeat (Calculate PLUS ))) @@ \
329 \ (Try (Repeat (Calculate MINUS))))) e_e)"
330 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
334 "----------- pbl polynom probe -----------------------------------";
335 "----------- pbl polynom probe -----------------------------------";
336 "----------- pbl polynom probe -----------------------------------";
338 CalcTree [(["Pruefe (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
339 \3 - 2 * e + 2 * f + 2 * g)",
340 "mitWert [e = 1, f = 2, g = 3]",
342 ("PolyMinus",["polynom","probe"],
343 ["probe","fuer_polynom"]))];
345 autoCalculate 1 CompleteCalc;
346 (* autoCalculate 1 CompleteCalcHead;
347 autoCalculate 1 (Step 1);
348 autoCalculate 1 (Step 1);
349 val ((pt,p),_) = get_calc 1; term2str (get_obj g_res pt (fst p));
350 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
351 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
352 val ((pt,p),_) = get_calc 1;
353 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "11 = 11"
354 then () else error "polyminus.sml: Probe 11 = 11";
358 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
359 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
360 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
362 CalcTree [(["TERM (2*u - 5 - (3 - 4*u) + (8*u + 9))",
364 ("PolyMinus",["klammer","polynom","vereinfachen"],
365 ["simplification","for_polynomials","with_parentheses"]))];
367 autoCalculate 1 CompleteCalc;
368 val ((pt,p),_) = get_calc 1;
369 if p = ([], Res) andalso
370 term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
371 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
374 "----- probe p.34 -----";
376 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * u)",
379 ("PolyMinus",["polynom","probe"],
380 ["probe","fuer_polynom"]))];
382 autoCalculate 1 CompleteCalc;
383 val ((pt,p),_) = get_calc 1;
384 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "29 = 29"
385 then () else error "polyminus.sml: Probe 29 = 29";
389 "----------- try fun applyTactics --------------------------------";
390 "----------- try fun applyTactics --------------------------------";
391 "----------- try fun applyTactics --------------------------------";
393 CalcTree [(["TERM (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
395 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
396 ["simplification","for_polynomials","with_minus"]))];
398 autoCalculate 1 CompleteCalcHead;
399 autoCalculate 1 (Step 1);
400 autoCalculate 1 (Step 1);
401 val ((pt,p),_) = get_calc 1; show_pt pt;
403 fetchApplicableTactics 1 0 p;
404 val appltacs = sel_appl_atomic_tacs pt p;
405 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
406 val ((pt,p),_) = get_calc 1; show_pt pt;
408 trace_rewrite := true;
409 val erls = erls_ordne_alphabetisch;
410 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
412 rewrite_ Isac.thy e_rew_ord erls false tausche_minus t;
413 term2str t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
415 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
417 rewrite_ Isac.thy e_rew_ord erls false tausche_minus_plus t;
419 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
421 rewrite_set_ Isac.thy false ordne_alphabetisch t;
422 term2str t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
423 trace_rewrite := false;
426 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (*tausche_minus*);
427 val ((pt,p),_) = get_calc 1; show_pt pt;
429 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
430 val ((pt,p),_) = get_calc 1; show_pt pt;
432 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
433 val ((pt,p),_) = get_calc 1; show_pt pt;
435 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
436 val ((pt,p),_) = get_calc 1; show_pt pt;
439 (*<CALCMESSAGE> failure </CALCMESSAGE>
440 applyTactic 1 p (hd (sel_appl_atomic_tacs pt p)) (**);
441 val ((pt,p),_) = get_calc 1; show_pt pt;
445 autoCalculate 1 CompleteCalc;
446 val ((pt,p),_) = get_calc 1; show_pt pt;
447 (*independent from failure above: met_simp_poly_minus not confluent:
448 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
449 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
450 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
453 CalcTree [(["TERM (- (8 * g) + 10 * g + h)",
455 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
456 ["simplification","for_polynomials","with_minus"]))];
458 autoCalculate 1 CompleteCalc;
459 val ((pt,p),_) = get_calc 1; show_pt pt;
460 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "2 * g + h"
461 then () else error "polyminus.sml: addiere_vor_minus";
465 CalcTree [(["TERM (- (8 * g) + 10 * g + f)",
467 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
468 ["simplification","for_polynomials","with_minus"]))];
470 autoCalculate 1 CompleteCalc;
471 val ((pt,p),_) = get_calc 1; show_pt pt;
472 if p = ([], Res) andalso term2str (get_obj g_res pt (fst p)) = "f + 2 * g"
473 then () else error "polyminus.sml: tausche_vor_plus";
476 "----------- pbl binom polynom vereinfachen p.39 -----------------";
477 "----------- pbl binom polynom vereinfachen p.39 -----------------";
478 "----------- pbl binom polynom vereinfachen p.39 -----------------";
479 val rls = klammern_ausmultiplizieren;
480 val t = str2term "(3 * a + 2) * (4 * a - 1)";
481 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
482 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
483 val rls = discard_parentheses;
484 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
485 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
486 val rls = ordne_monome;
487 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
488 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
490 val t = str2term "3 * a * 4 * a";
491 val rls = ordne_monome;
492 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
494 val rls = klammern_aufloesen;
495 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
496 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
497 val rls = ordne_alphabetisch;
498 (*TODO: make is_monom more general, a*a=a^2, ...*)
499 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
500 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
502 val rls = fasse_zusammen;
503 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
504 val rls = verschoenere;
505 val SOME (t,_) = rewrite_set_ thy false rls t; term2str t;
509 trace_rewrite := true;
510 trace_rewrite := false;
514 CalcTree [(["TERM ((3*a + 2) * (4*a - 1))",
516 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
517 ["simplification","for_polynomials","with_parentheses_mult"]))];
519 autoCalculate 1 CompleteCalc;
520 val ((pt,p),_) = get_calc 1; show_pt pt;
523 if p = ([], Res) andalso
524 term2str (get_obj g_res pt (fst p)) = "1 + 14 * u"
525 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
529 "----------- pbl binom polynom vereinfachen: cube ----------------";
530 "----------- pbl binom polynom vereinfachen: cube ----------------";
531 "----------- pbl binom polynom vereinfachen: cube ----------------";
533 CalcTree [(["TERM (8*(a - q) + a - 2*q + 3*(a - 2*q))",
535 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
536 ["simplification","for_polynomials","with_parentheses_mult"]))];
538 autoCalculate 1 CompleteCalc;
539 val ((pt,p),_) = get_calc 1; show_pt pt;
542 "----------- refine Vereinfache ----------------------------------";
543 "----------- refine Vereinfache ----------------------------------";
544 "----------- refine Vereinfache ----------------------------------";
545 val fmz = ["TERM (8*(a - q) + a - 2*q + 3*(a - 2*q))",
548 val matches = refine fmz ["vereinfachen"];
551 "----- go into details, if it seems not to work -----";
552 "--- does the predicate evaluate correctly ?";
554 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + \
556 val ma = eval_matchsub "" "Tools.matchsub" t thy;
558 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
559 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
560 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
562 "--- does the respective prls rewrite ?";
563 val prls = append_rls "prls_pbl_vereinf_poly" e_rls
564 [Calc ("Poly.is'_polyexp", eval_is_polyexp ""),
565 Calc ("Tools.matchsub", eval_matchsub ""),
566 Thm ("or_true",or_true),
567 (*"(?a | True) = True"*)
568 Thm ("or_false",or_false),
569 (*"(?a | False) = ?a"*)
570 Thm ("not_true",num_str @{thm not_true}),
571 (*"(~ True) = False"*)
572 Thm ("not_false",num_str @{thm not_false})
573 (*"(~ False) = True"*)];
574 trace_rewrite := true;
575 val SOME (t', _) = rewrite_set_ thy false prls t;
576 trace_rewrite := false;
578 "--- does the respective prls rewrite the whole predicate ?";
580 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
581 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
582 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
583 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
584 trace_rewrite := true;
585 val SOME (t', _) = rewrite_set_ thy false prls t;
586 trace_rewrite := false;
587 if term2str t' = "False" then ()
588 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
590 ============ inhibit exn ?====================================================*)
593 "----------- *** prep_pbt: syntax error in '#Where' of [v";
594 "----------- *** prep_pbt: syntax error in '#Where' of [v";
595 "----------- *** prep_pbt: syntax error in '#Where' of [v";
596 (*see test/../termC.sml for details*)
597 val t = parse_patt thy "t_t is_polyexp";
598 val t = parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
599 " matchsub (?a + (?b - ?c)) t_t | " ^
600 " matchsub (?a - (?b + ?c)) t_t | " ^
601 " matchsub (?a + (?b - ?c)) t_t )");
602 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)"
603 then () else error "polyminus.sml type-structure of \"?a :: real\" changed";
606 "===== deconstruct datatype typ ===";
608 val t = (thy, str) |>> thy2ctxt
609 |-> ProofContext.read_term_pattern
610 |> numbers_to_string;
611 val Var (("a", 0), ty) = t;
612 val TVar ((str, i), srt) = ty;
613 if str = "'a" andalso i = 1 andalso srt = [] then ()
614 else error "termC.sml type-structure of \"?a\" changed";
616 "----- real type in pattern ---";
617 val str = "?a :: real";
618 val t = (thy, str) |>> thy2ctxt
619 |-> ProofContext.read_term_pattern
620 |> numbers_to_string;
621 val Var (("a", 0), ty) = t;
622 val Type (str, tys) = ty;
623 if str = "RealDef.real" andalso tys = [] andalso ty = HOLogic.realT then ()
624 else error "termC.sml type-structure of \"?a :: real\" changed";
626 "===== Not (matchsub (?a + (?b + ?c)) t_t |... ===";
627 val (thy, str) = (thy, "Not (matchsub (?a + (?b + ?c)) t_t | " ^
628 " matchsub (?a + (?b - ?c)) t_t | " ^
629 " matchsub (?a - (?b + ?c)) t_t | " ^
630 " matchsub (?a + (?b - ?c)) t_t )");
631 "----- read_term_pattern ---";
632 val t = (thy, str) |>> thy2ctxt
633 |-> ProofContext.read_term_pattern
634 |> numbers_to_string;
636 val t1 = typ_a2real t;
637 if term2str t1 = "~ (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)"
638 then () else error "termC.sml type-structure of \"?a :: real\" changed expl";
641 (*========== inhibit exn =======================================================
642 ============ inhibit exn =====================================================*)
644 (*-.-.-.-.-.-isolate response.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
645 -.-.-.-.-.-.-isolate response.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*)