Test_Isac_Short now ok.
1 (* title: Knowledge/polyminus.sml
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.trace_rewrite := true; ..stopped Test_Isac.thy*)
70 Trace.trace_rewrite:=false;
71 val t = str2term "((a + d) + c) + b";
72 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
73 if UnparseC.term t = "a + (b + (c + d))" then ()
74 else error "polyminus.sml 1 watch order_add_mult";
75 Trace.trace_rewrite:=false;
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 Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
83 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
85 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
87 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
89 if UnparseC.term 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 Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
97 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t;UnparseC.term t;
99 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term 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; UnparseC.term t;
106 if UnparseC.term 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 Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
113 val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term 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; UnparseC.term t;
164 if UnparseC.term 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; UnparseC.term t;
171 "======= test rewrite_, rewrite_set_";
172 (*Trace.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; UnparseC.term t;
176 if UnparseC.term 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; UnparseC.term t;
181 if UnparseC.term 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; UnparseC.term t;
186 if UnparseC.term 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; UnparseC.term t;
192 if UnparseC.term 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; UnparseC.term t;
197 if UnparseC.term 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; UnparseC.term t;
203 if UnparseC.term 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 UnparseC.term 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 UnparseC.term 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 UnparseC.term t = "3 - 2 * e + 2 * f + 2 * g" then ()
228 else error "polyminus.sml: verschoenere 3 + -2 * e ...";
230 (*Trace.trace_rewrite := true; ..stopped Test_Isac.thy*)
231 Trace.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 "Program 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 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"
267 then case nxt of End_Proof' => () | _ => error "me simplification.for_polynomials.with_minus 1"
268 else error "polyminus.sml: me simplification.for_polynomials.with_minus 2";
270 "----------- pbl polynom vereinfachen p.33 -----------------------";
271 "----------- pbl polynom vereinfachen p.33 -----------------------";
272 "----------- pbl polynom vereinfachen p.33 -----------------------";
273 "----------- 140 c ---";
275 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
277 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
278 ["simplification","for_polynomials","with_minus"]))];
280 autoCalculate 1 CompleteCalc;
281 val ((pt,p),_) = get_calc 1; show_pt pt;
282 if p = ([], Res) andalso
283 UnparseC.term (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
284 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
288 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
290 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
291 ["simplification","for_polynomials","with_minus"]))];
293 autoCalculate 1 CompleteCalc;
294 val ((pt,p),_) = get_calc 1; show_pt pt;
295 if p = ([], Res) andalso
296 UnparseC.term (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
297 then () else error "polyminus.sml: Vereinfache 140 d)";
301 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
303 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
304 ["simplification","for_polynomials","with_minus"]))];
306 autoCalculate 1 CompleteCalc;
307 val ((pt,p),_) = get_calc 1; show_pt pt;
308 if p = ([], Res) andalso
309 UnparseC.term (get_obj g_res pt (fst p)) = "- (3 * f)"
310 then () else error "polyminus.sml: Vereinfache 139 c)";
314 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
316 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
317 ["simplification","for_polynomials","with_minus"]))];
319 autoCalculate 1 CompleteCalc;
320 val ((pt,p),_) = get_calc 1; show_pt pt;
321 if p = ([], Res) andalso
322 UnparseC.term (get_obj g_res pt (fst p)) = "-3 * u - v"
323 then () else error "polyminus.sml: Vereinfache 139 b)";
327 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
329 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
330 ["simplification","for_polynomials","with_minus"]))];
332 autoCalculate 1 CompleteCalc;
333 val ((pt,p),_) = get_calc 1; show_pt pt;
334 if p = ([], Res) andalso
335 UnparseC.term (get_obj g_res pt (fst p)) = "-4 * u + 2 * v"
336 then () else error "polyminus.sml: Vereinfache 138 a)";
338 "----------- met probe fuer_polynom ------------------------------";
339 "----------- met probe fuer_polynom ------------------------------";
340 "----------- met probe fuer_polynom ------------------------------";
342 "Program ProbeScript (e_e::bool) (w_s::bool list) =\
343 \ (let e_e = Take e_e; \
344 \ e_e = Substitute w_s e_e \
345 \ in (Repeat((Try (Repeat (Calculate ''TIMES''))) #> \
346 \ (Try (Repeat (Calculate ''PLUS''))) #> \
347 \ (Try (Repeat (Calculate ''MINUS''))))) e_e)"
348 val sc = (inst_abs o Thm.term_of o the o (parse thy)) str;
351 "----------- pbl polynom probe -----------------------------------";
352 "----------- pbl polynom probe -----------------------------------";
353 "----------- pbl polynom probe -----------------------------------";
355 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
356 \3 - 2 * e + 2 * f + 2 * (g::int))",
357 "mitWert [e = (1::int), f = (2::int), g = (3::int)]",
359 ("PolyMinus",["polynom","probe"],
360 ["probe","fuer_polynom"]))];
362 autoCalculate 1 CompleteCalc;
363 (* autoCalculate 1 CompleteCalcHead;
364 autoCalculate 1 (Steps 1);
365 autoCalculate 1 (Steps 1);
366 val ((pt,p),_) = get_calc 1; UnparseC.term (get_obj g_res pt (fst p));
367 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
368 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
369 val ((pt,p),_) = get_calc 1;
370 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "11 = 11"
371 then () else error "polyminus.sml: Probe 11 = 11";
374 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
375 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
376 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
378 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
380 ("PolyMinus",["klammer","polynom","vereinfachen"],
381 ["simplification","for_polynomials","with_parentheses"]))];
383 autoCalculate 1 CompleteCalc;
384 val ((pt,p),_) = get_calc 1;
385 if p = ([], Res) andalso
386 UnparseC.term (get_obj g_res pt (fst p)) = "1 + 14 * u"
387 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
390 "======= probe p.34 -----";
392 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * (u::int))",
393 "mitWert [u = (2::int)]",
395 ("PolyMinus",["polynom","probe"],
396 ["probe","fuer_polynom"]))];
398 autoCalculate 1 CompleteCalc;
399 val ((pt,p),_) = get_calc 1;
400 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "29 = 29"
401 then () else error "polyminus.sml: Probe 29 = 29";
404 "----------- try fun applyTactics --------------------------------";
405 "----------- try fun applyTactics --------------------------------";
406 "----------- try fun applyTactics --------------------------------";
408 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
410 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
411 ["simplification","for_polynomials","with_minus"]))];
413 autoCalculate 1 CompleteCalcHead;
414 autoCalculate 1 (Steps 1);
415 autoCalculate 1 (Steps 1);
416 val ((pt,p),_) = get_calc 1; show_pt pt;
418 fetchApplicableTactics 1 0 p;
419 val appltacs = specific_from_prog pt p;
420 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
421 val ((pt,p),_) = get_calc 1; show_pt pt;
423 (*Trace.trace_rewrite := true; ..stopped Test_Isac.thy*)
424 val erls = erls_ordne_alphabetisch;
425 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
427 rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus} t;
428 UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
430 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
432 rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
434 val t = str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
436 rewrite_set_ (@{theory "Isac_Knowledge"}) false ordne_alphabetisch t;
437 UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
438 Trace.trace_rewrite := false;
441 applyTactic 1 p (hd (specific_from_prog pt p)) (*tausche_minus*);
442 val ((pt,p),_) = get_calc 1; show_pt pt;
444 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
445 val ((pt,p),_) = get_calc 1; show_pt pt;
447 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
448 val ((pt,p),_) = get_calc 1; show_pt pt;
450 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
451 val ((pt,p),_) = get_calc 1; show_pt pt;
454 (*<CALCMESSAGE> failure </CALCMESSAGE>
455 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
456 val ((pt,p),_) = get_calc 1; show_pt pt;
459 autoCalculate 1 CompleteCalc;
460 val ((pt,p),_) = get_calc 1; show_pt pt;
461 (*independent from failure above: met_simp_poly_minus not confluent:
462 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
463 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
464 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
467 "#############################################################################";
469 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
471 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
472 ["simplification","for_polynomials","with_minus"]))];
474 autoCalculate 1 CompleteCalc;
475 val ((pt,p),_) = get_calc 1; show_pt pt;
476 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "2 * g + h"
477 then () else error "polyminus.sml: addiere_vor_minus";
480 "#############################################################################";
482 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
484 ("PolyMinus",["plus_minus","polynom","vereinfachen"],
485 ["simplification","for_polynomials","with_minus"]))];
487 autoCalculate 1 CompleteCalc;
488 val ((pt,p),_) = get_calc 1; show_pt pt;
489 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "f + 2 * g"
490 then () else error "polyminus.sml: tausche_vor_plus";
492 "----------- pbl binom polynom vereinfachen p.39 -----------------";
493 "----------- pbl binom polynom vereinfachen p.39 -----------------";
494 "----------- pbl binom polynom vereinfachen p.39 -----------------";
495 val rls = klammern_ausmultiplizieren;
496 val t = str2term "(3 * a + 2) * (4 * a - 1)";
497 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
498 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
499 val rls = discard_parentheses;
500 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
501 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
502 val rls = ordne_monome;
503 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
504 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
506 val t = str2term "3 * a * 4 * a";
507 val rls = ordne_monome;
508 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
510 val rls = klammern_aufloesen;
511 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
512 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
513 val rls = ordne_alphabetisch;
514 (*TODO: make is_monom more general, a*a=a^2, ...*)
515 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
516 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
518 val rls = fasse_zusammen;
519 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
520 val rls = verschoenere;
521 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
526 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
528 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
529 ["simplification","for_polynomials","with_parentheses_mult"]))];
531 autoCalculate 1 CompleteCalc;
532 val ((pt,p),_) = get_calc 1; show_pt pt;
533 if p = ([], Res) andalso
534 UnparseC.term (get_obj g_res pt (fst p)) = "-2 + 12 * a ^^^ 2 + 5 * a"
535 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
537 "----------- pbl binom polynom vereinfachen: cube ----------------";
538 "----------- pbl binom polynom vereinfachen: cube ----------------";
539 "----------- pbl binom polynom vereinfachen: cube ----------------";
541 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
542 ("PolyMinus",["binom_klammer","polynom","vereinfachen"],
543 ["simplification","for_polynomials","with_parentheses_mult"]))];
545 autoCalculate 1 CompleteCalc;
546 val ((pt,p),_) = get_calc 1; show_pt pt;
547 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "12 * a - 16 * q"
548 then () else error "pbl binom polynom vereinfachen: cube";
550 "----------- refine Vereinfache ----------------------------------";
551 "----------- refine Vereinfache ----------------------------------";
552 "----------- refine Vereinfache ----------------------------------";
553 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"];
554 (*default_print_depth 11;*)
555 val matches = refine fmz ["vereinfachen"];
556 (*default_print_depth 3;*)
558 "----- go into details, if it seems not to work -----";
559 "--- does the predicate evaluate correctly ?";
561 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))";
562 val ma = eval_matchsub "" "Prog_Expr.matchsub" t thy;
564 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
565 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
566 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
568 "--- does the respective prls rewrite ?";
569 val prls = Rule_Set.append_rules "prls_pbl_vereinf_poly" Rule_Set.empty
570 [Eval ("Poly.is'_polyexp", eval_is_polyexp ""),
571 Eval ("Prog_Expr.matchsub", eval_matchsub ""),
572 Thm ("or_true",@{thm or_true}),
573 (*"(?a | True) = True"*)
574 Thm ("or_false",@{thm or_false}),
575 (*"(?a | False) = ?a"*)
576 Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
577 (*"(~ True) = False"*)
578 Thm ("not_false",ThmC.numerals_to_Free @{thm not_false})
579 (*"(~ False) = True"*)];
580 (*Trace.trace_rewrite := true; ..stopped Test_Isac.thy*)
581 val SOME (t', _) = rewrite_set_ thy false prls t;
582 Trace.trace_rewrite := false;
584 "--- does the respective prls rewrite the whole predicate ?";
586 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
587 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
588 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
589 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
590 (*Trace.trace_rewrite := true; ..stopped Test_Isac.thy*)
591 val SOME (t', _) = rewrite_set_ thy false prls t;
592 Trace.trace_rewrite := false;
593 if UnparseC.term t' = "False" then ()
594 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
596 "----------- *** prep_pbt: syntax error in '#Where' of [v";
597 "----------- *** prep_pbt: syntax error in '#Where' of [v";
598 "----------- *** prep_pbt: syntax error in '#Where' of [v";
599 (*see test/../termC.sml for details*)
600 val t = parse_patt thy "t_t is_polyexp";
601 val t = parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
602 " matchsub (?a + (?b - ?c)) t_t | " ^
603 " matchsub (?a - (?b + ?c)) t_t | " ^
604 " matchsub (?a + (?b - ?c)) t_t )");
605 (*show_types := true;
606 if UnparseC.term 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)"
607 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
608 show_types := false;*)
610 "\<not> (matchsub (?a + (?b + ?c)) t_t \<or>\n " ^
611 "matchsub (?a + (?b - ?c)) t_t \<or>\n " ^
612 "matchsub (?a - (?b + ?c)) t_t \<or> " ^
613 "matchsub (?a + (?b - ?c)) t_t)"
614 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";