1 (* title: Knowledge/polyminus.sml
4 (c) due to copyright terms
6 "--------------------------------------------------------";
7 "--------------------------------------------------------";
8 "table of contents --------------------------------------";
9 "--------------------------------------------------------";
10 "----------- fun identifier --------------------------------------------------------------------";
11 "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
12 "----------- fun ist_monom ---------------------------------------------------------------------";
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.refine Vereinfache -------------------------";
28 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
29 "--------------------------------------------------------";
30 "--------------------------------------------------------";
31 "--------------------------------------------------------";
33 val thy = @{theory "PolyMinus"};
34 val ctxt = Proof_Context.init_global thy;
36 "----------- fun identifier --------------------------------------------------------------------";
37 "----------- fun identifier --------------------------------------------------------------------";
38 "----------- fun identifier --------------------------------------------------------------------";
39 if identifier (TermC.str2term "12 ::real") = "12" then () else error "identifier 1";
40 if identifier (TermC.str2term
41 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g ::real") = "|||||||||||||"
42 then () else error "identifier 1a";
44 if identifier (TermC.str2term "a ::real") = "a" then () else error "identifier 2";
45 if identifier (TermC.str2term "3 * a ::real") = "a" then () else error "identifier 3";
47 if identifier (TermC.str2term "a \<up> 2 ::real") = "a" then () else error "identifier 4";
48 if identifier (TermC.str2term "3*a \<up> 2 ::real") = "a" then () else error "identifier 5";
49 if identifier (TermC.str2term "a * b ::real") = "b" then () else error "identifier 5b";
51 (*these are strange (see "specific monomials" in comment to fun.def.)..*)
52 if identifier (TermC.str2term "a*b ::real") = "b" then () else error "identifier 6";
53 if identifier (TermC.str2term "(3*a*b) ::real") = "b" then () else error "identifier 7";
56 "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
57 "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
58 "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
61 "123" < "a"; (*unused due to ---vvv*)
62 "12" < "3"; (*true !!!*)
64 " a kleiner b ==> (b + a) = (a + b)";
66 TermC.str2term "222 * aaa";
68 case eval_kleiner 0 0 (TermC.str2term "123 kleiner 32") 0 of
69 SOME ("123 kleiner 32 = False", _) => ()
70 | _ => error "polyminus.sml: 12 kleiner 9 = False";
71 case eval_kleiner 0 0 (TermC.str2term "a kleiner b") 0 of
72 SOME ("a kleiner b = True", _) => ()
73 | _ => error "polyminus.sml: a kleiner b = True";
74 case eval_kleiner 0 0 (TermC.str2term "(10*g) kleiner f") 0 of
75 SOME ("10 * g kleiner f = False", _) => ()
76 | _ => error "polyminus.sml: 10 * g kleiner f = False";
77 case eval_kleiner 0 0 (TermC.str2term "(a \<up> 2) kleiner b") 0 of
78 SOME ("a \<up> 2 kleiner b = True", _) => ()
79 | _ => error "polyminus.sml: a \<up> 2 kleiner b = True";
80 case eval_kleiner 0 0 (TermC.str2term "(3*a \<up> 2) kleiner b") 0 of
81 SOME ("3 * a \<up> 2 kleiner b = True", _) => ()
82 | _ => error "polyminus.sml: 3 * a \<up> 2 kleiner b = True";
83 case eval_kleiner 0 0 (TermC.str2term "(a*b) kleiner c") 0 of
84 SOME ("a * b kleiner c = True", _) => ()
85 | _ => error "polyminus.sml: a * b kleiner b = True";
86 case eval_kleiner 0 0 (TermC.str2term "(3*a*b) kleiner c") 0 of
87 SOME ("3 * a * b kleiner c = True", _) => ()
88 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
91 val t = TermC.str2term "12 kleiner 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * (g::real)";
92 val SOME ("12 kleiner 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g = True", _) =
93 eval_kleiner "aaa" "bbb" t "ccc";
94 "~~~~~ fun eval_kleiner , args:"; val (_, _, (p as (Const (\<^const_name>\<open>kleiner\<close>,_) $ a $ b)), _) =
95 ("aaa", "bbb", t, "ccc");
96 (*if*) TermC.is_num b (*else*);
98 (*if*) identifier a < identifier b (*else*);
99 "~~~~~ fun identifier , args:"; val (t) = (a);
101 Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $
102 (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ (Const (\<^const_name>\<open>num.Bit1\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _)))) => ()
103 | _ => error "eval_kleiner CHANGED"; (*isa*)
106 "----------- fun ist_monom ---------------------------------------------------------------------";
107 "----------- fun ist_monom ---------------------------------------------------------------------";
108 "----------- fun ist_monom ---------------------------------------------------------------------";
109 val t = TermC.str2term "0 ::real";
110 if ist_monom t then () else error "ist_monom 1";
112 val t = TermC.str2term "a";
113 if ist_monom t then () else error "ist_monom 2";
115 val t = TermC.str2term "2 * a";
116 if ist_monom t then () else error "ist_monom 3";
118 val t = TermC.str2term "2 * a * b";
119 if ist_monom t then () else error "ist_monom 4";
121 val t = TermC.str2term "a * b";
122 if ist_monom t then () else error "ist_monom 5";
124 (*not covered before NEW numerals*)
125 val t = TermC.str2term "2 * a \<up> 2 * b";
126 if ist_monom t then () else error "ist_monom 6";
128 (*not covered before NEW numerals*)
129 val t = TermC.str2term "a \<up> 2 * b \<up> 3";
130 if ist_monom t then () else error "ist_monom 7";
132 val t = TermC.str2term "a \<up> 2 * 4 * b \<up> 3 * 5";
133 if ist_monom t then () else error "ist_monom 8";
136 "----------- fun eval_ist_monom ----------------------------------";
137 "----------- fun eval_ist_monom ----------------------------------";
138 "----------- fun eval_ist_monom ----------------------------------";
139 case eval_ist_monom 0 0 (TermC.str2term "12 ist_monom") 0 of
140 SOME ("12 ist_monom = True", _) => ()
141 | _ => error "polyminus.sml: 12 ist_monom = True";
143 case eval_ist_monom 0 0 (TermC.str2term "a ist_monom") 0 of
144 SOME ("a ist_monom = True", _) => ()
145 | _ => error "polyminus.sml: a ist_monom = True";
147 case eval_ist_monom 0 0 (TermC.str2term "(3*a) ist_monom") 0 of
148 SOME ("3 * a ist_monom = True", _) => ()
149 | _ => error "polyminus.sml: 3 * a ist_monom = True";
151 case eval_ist_monom 0 0 (TermC.str2term "(a \<up> 2) ist_monom") 0 of
152 SOME ("a \<up> 2 ist_monom = True", _) => ()
153 | _ => error "polyminus.sml: a \<up> 2 ist_monom = True";
155 case eval_ist_monom 0 0 (TermC.str2term "(3*a \<up> 2) ist_monom") 0 of
156 SOME ("3 * a \<up> 2 ist_monom = True", _) => ()
157 | _ => error "polyminus.sml: 3*a \<up> 2 ist_monom = True";
159 case eval_ist_monom 0 0 (TermC.str2term "(a*b) ist_monom") 0 of
160 SOME ("a * b ist_monom = True", _) => ()
161 | _ => error "polyminus.sml: a*b ist_monom = True";
163 case eval_ist_monom 0 0 (TermC.str2term "(3*a*b) ist_monom") 0 of
164 SOME ("3 * a * b ist_monom = True", _) => ()
165 | _ => error "polyminus.sml: 3*a*b ist_monom = True";
168 "----------- watch order_add_mult -------------------------------";
169 "----------- watch order_add_mult -------------------------------";
170 "----------- watch order_add_mult -------------------------------";
171 "----- with these simple variables it works...";
172 val ctxt = @{context};
173 val t = TermC.str2term "((a + d) + c) + b";
174 val SOME (t,_) = rewrite_set_ ctxt false order_add_mult t; UnparseC.term t;
175 if UnparseC.term t = "a + (b + (c + d))" then ()
176 else error "polyminus.sml 1 watch order_add_mult";
178 "----- the same stepwise...";
179 val od = ord_make_polynomial true (@{theory "Poly"});
180 val t = TermC.str2term "((a + d) + c) + b";
182 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
184 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
186 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
188 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
190 if UnparseC.term t = "a + (b + (c + d))" then ()
191 else error "polyminus.sml 2 watch order_add_mult";
193 "----- if parentheses are right, left_commute is (almost) sufficient...";
194 val t = TermC.str2term "a + (d + (c + b))";
196 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
198 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t;UnparseC.term t;
200 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
203 "----- but we do not want the parentheses at right; thus: cond.rew.";
204 "WN0712707 complicated monomials do not yet work ...";
205 val t = TermC.str2term "((5*a + 4*d) + 3*c) + 2*b";
206 val SOME (t,_) = rewrite_set_ ctxt false order_add_mult t; UnparseC.term t;
207 if UnparseC.term t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
208 else error "polyminus.sml: order_add_mult changed";
210 "----- here we see rew_sub going into subterm with ord.rew....";
211 val od = ord_make_polynomial false (@{theory "Poly"});
212 val t = TermC.str2term "b + a + c + d";
213 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
214 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
215 (*@@@ rew_sub gosub: t = d + (b + a + c)
216 @@@ rew_sub begin: t = b + a + c*)
219 "----------- build predicate for +- ordering ---------------------";
220 "----------- build predicate for +- ordering ---------------------";
221 "----------- build predicate for +- ordering ---------------------";
224 "123" < "a"; (*unused due to ---vvv*)
225 "12" < "3"; (*true !!!*)
227 " a kleiner b ==> (b + a) = (a + b)";
228 TermC.str2term "aaa";
229 TermC.str2term "222 * aaa";
231 case eval_kleiner 0 0 (TermC.str2term "123 kleiner 32") 0 of
232 SOME ("123 kleiner 32 = False", _) => ()
233 | _ => error "polyminus.sml: 12 kleiner 9 = False";
235 case eval_kleiner 0 0 (TermC.str2term "a kleiner b") 0 of
236 SOME ("a kleiner b = True", _) => ()
237 | _ => error "polyminus.sml: a kleiner b = True";
239 case eval_kleiner 0 0 (TermC.str2term "(10*g) kleiner f") 0 of
240 SOME ("10 * g kleiner f = False", _) => ()
241 | _ => error "polyminus.sml: 10 * g kleiner f = False";
243 case eval_kleiner 0 0 (TermC.str2term "(a \<up> 2) kleiner b") 0 of
244 SOME ("a \<up> 2 kleiner b = True", _) => ()
245 | _ => error "polyminus.sml: a \<up> 2 kleiner b = True";
247 case eval_kleiner 0 0 (TermC.str2term "(3*a \<up> 2) kleiner b") 0 of
248 SOME ("3 * a \<up> 2 kleiner b = True", _) => ()
249 | _ => error "polyminus.sml: 3 * a \<up> 2 kleiner b = True";
251 case eval_kleiner 0 0 (TermC.str2term "(a*b) kleiner c") 0 of
252 SOME ("a * b kleiner c = True", _) => ()
253 | _ => error "polyminus.sml: a * b kleiner b = True";
255 case eval_kleiner 0 0 (TermC.str2term "(3*a*b) kleiner c") 0 of
256 SOME ("3 * a * b kleiner c = True", _) => ()
257 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
259 "======= compare tausche_plus with real_num_collect";
262 val erls = erls_ordne_alphabetisch;
263 val t = TermC.str2term "b + a";
264 val SOME (t,_) = rewrite_ ctxt od erls false @{thm tausche_plus} t; UnparseC.term t;
265 if UnparseC.term t = "a + b" then ()
266 else error "polyminus.sml: ordne_alphabetisch1 b + a";
268 val erls = Atools_erls;
269 val t = TermC.str2term "2*a + 3*a";
270 val SOME (t,_) = rewrite_ ctxt od erls false @{thm real_num_collect} t; UnparseC.term t;
272 "======= test rewrite_, rewrite_set_";
273 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
274 val erls = erls_ordne_alphabetisch;
275 val t = TermC.str2term "b + a";
276 val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t;
277 if UnparseC.term t = "a + b" then ()
278 else error "polyminus.sml: ordne_alphabetisch a + b";
280 val t = TermC.str2term "2*b + a";
281 val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t;
282 if UnparseC.term t = "a + 2 * b" then ()
283 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
285 val t = TermC.str2term "a + c + b";
286 val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t;
287 if UnparseC.term t = "a + b + c" then ()
288 else error "polyminus.sml: ordne_alphabetisch a + b + c";
290 "======= rewrite goes into subterms";
291 val t = TermC.str2term "a + c + b + d ::real";
292 val SOME (t,_) = rewrite_ ctxt od erls false @{thm tausche_plus_plus} t; UnparseC.term t;
293 if UnparseC.term t = "a + b + c + d" then ()
294 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
296 val t = TermC.str2term "a + c + d + b";
297 val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term t;
298 if UnparseC.term t = "a + b + c + d" then ()
299 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
301 "======= here we see rew_sub going into subterm with cond.rew....";
302 val t = TermC.str2term "b + a + c + d";
303 val SOME (t,_) = rewrite_ ctxt od erls false @{thm tausche_plus} t; UnparseC.term t;
304 if UnparseC.term t = "a + b + c + d" then ()
305 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
307 "======= compile rls for the most complicated terms";
308 val t = TermC.str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
309 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
310 val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t;
311 if UnparseC.term t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
312 then () else error "polyminus.sml: ordne_alphabetisch finished";
316 "----------- build fasse_zusammen --------------------------------";
317 "----------- build fasse_zusammen --------------------------------";
318 "----------- build fasse_zusammen --------------------------------";
319 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
320 val SOME (t,_) = rewrite_set_ ctxt false fasse_zusammen t;
321 if UnparseC.term t = "3 + - 2 * e + 2 * f + 2 * g" then ()
322 else error "polyminus.sml: fasse_zusammen finished";
324 "----------- build verschoenere ----------------------------------";
325 "----------- build verschoenere ----------------------------------";
326 "----------- build verschoenere ----------------------------------";
327 val t = TermC.str2term "3 + - 2 * e + 2 * f + 2 * g";
328 val SOME (t,_) = rewrite_set_ ctxt false verschoenere t;
329 if UnparseC.term t = "3 - 2 * e + 2 * f + 2 * g" then ()
330 else error "polyminus.sml: verschoenere 3 + - 2 * e ...";
333 "----------- met simplification for_polynomials with_minus -------";
334 "----------- met simplification for_polynomials with_minus -------";
335 "----------- met simplification for_polynomials with_minus -------";
337 "Program SimplifyScript (t_t::real) = \
338 \ (((Try (Rewrite_Set ordne_alphabetisch False)) #> \
339 \ (Try (Rewrite_Set fasse_zusammen False)) #> \
340 \ (Try (Rewrite_Set verschoenere False))) t_t)"
341 val sc = (inst_abs o (TermC.parseNEW' ctxt)) str;
344 "----------- me simplification.for_polynomials.with_minus";
345 "----------- me simplification.for_polynomials.with_minus";
346 "----------- me simplification.for_polynomials.with_minus";
348 val (p,_,f,nxt,_,pt) =
350 [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
352 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
353 ["simplification", "for_polynomials", "with_minus"]))];
354 val (p,_,f,nxt,_,pt) = me nxt p c pt;
355 val (p,_,f,nxt,_,pt) = me nxt p c pt;
356 val (p,_,f,nxt,_,pt) = me nxt p c pt;
357 val (p,_,f,nxt,_,pt) = me nxt p c pt;
358 val (p,_,f,nxt,_,pt) = me nxt p c pt;
359 val (p,_,f,nxt,_,pt) = me nxt p c pt;
361 val (p,_,f,nxt,_,pt) = me nxt p c pt;
362 val (p,_,f,nxt,_,pt) = me nxt p c pt;
363 val (p,_,f,nxt,_,pt) = me nxt p c pt;
364 val (p,_,f,nxt,_,pt) = me nxt p c pt;
365 val (p,_,f,nxt,_,pt) = me nxt p c pt;
366 if f2str f = "3 - 2 * e + 2 * f + 2 * g"
367 then case nxt of End_Proof' => () | _ => error "me simplification.for_polynomials.with_minus 1"
368 else error "polyminus.sml: me simplification.for_polynomials.with_minus 2";
370 "----------- pbl polynom vereinfachen p.33 -----------------------";
371 "----------- pbl polynom vereinfachen p.33 -----------------------";
372 "----------- pbl polynom vereinfachen p.33 -----------------------";
373 "----------- 140 c ---";
375 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
377 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
378 ["simplification", "for_polynomials", "with_minus"]))];
380 autoCalculate 1 CompleteCalc;
381 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
382 if p = ([], Res) andalso
383 UnparseC.term (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
384 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
388 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
390 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
391 ["simplification", "for_polynomials", "with_minus"]))];
393 autoCalculate 1 CompleteCalc;
394 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
395 if p = ([], Res) andalso
396 UnparseC.term (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
397 then () else error "polyminus.sml: Vereinfache 140 d)";
401 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
403 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
404 ["simplification", "for_polynomials", "with_minus"]))];
406 autoCalculate 1 CompleteCalc;
407 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
408 if p = ([], Res) andalso
409 UnparseC.term (get_obj g_res pt (fst p)) = "- (3 * f)"
410 then () else error "polyminus.sml: Vereinfache 139 c)";
414 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
416 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
417 ["simplification", "for_polynomials", "with_minus"]))];
419 autoCalculate 1 CompleteCalc;
420 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
421 if p = ([], Res) andalso
422 UnparseC.term (get_obj g_res pt (fst p)) = "- 3 * u - v"
423 then () else error "polyminus.sml: Vereinfache 139 b)";
427 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
429 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
430 ["simplification", "for_polynomials", "with_minus"]))];
432 autoCalculate 1 CompleteCalc;
433 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
434 if p = ([], Res) andalso
435 UnparseC.term (get_obj g_res pt (fst p)) = "- 4 * u + 2 * v"
436 then () else error "polyminus.sml: Vereinfache 138 a)";
438 "----------- met probe fuer_polynom ------------------------------";
439 "----------- met probe fuer_polynom ------------------------------";
440 "----------- met probe fuer_polynom ------------------------------";
442 "Program ProbeScript (e_e::bool) (w_s::bool list) =\
443 \ (let e_e = Take e_e; \
444 \ e_e = Substitute w_s e_e \
445 \ in (Repeat((Try (Repeat (Calculate ''TIMES''))) #> \
446 \ (Try (Repeat (Calculate ''PLUS''))) #> \
447 \ (Try (Repeat (Calculate ''MINUS''))))) e_e)"
448 val sc = (inst_abs o (TermC.parseNEW' ctxt)) str;
451 "----------- pbl polynom probe -----------------------------------";
452 "----------- pbl polynom probe -----------------------------------";
453 "----------- pbl polynom probe -----------------------------------";
455 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
456 \3 - 2 * e + 2 * f + 2 * (g::int))",
457 "mitWert [e = (1::int), f = (2::int), g = (3::int)]",
459 ("PolyMinus",["polynom", "probe"],
460 ["probe", "fuer_polynom"]))];
462 autoCalculate 1 CompleteCalc;
463 (* autoCalculate 1 CompleteCalcHead;
464 autoCalculate 1 (Steps 1);
465 autoCalculate 1 (Steps 1);
466 val ((pt,p),_) = get_calc 1; UnparseC.term (get_obj g_res pt (fst p));
467 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
468 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
469 val ((pt,p),_) = get_calc 1;
470 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "11 = 11"
471 then () else error "polyminus.sml: Probe 11 = 11";
472 Test_Tool.show_pt pt;
475 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
476 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
477 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
479 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
481 ("PolyMinus",["klammer", "polynom", "vereinfachen"],
482 ["simplification", "for_polynomials", "with_parentheses"]))];
484 autoCalculate 1 CompleteCalc;
485 val ((pt,p),_) = get_calc 1;
486 if p = ([], Res) andalso
487 UnparseC.term (get_obj g_res pt (fst p)) = "1 + 14 * u"
488 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
489 Test_Tool.show_pt pt;
491 "======= probe p.34 -----";
493 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * (u::int))",
494 "mitWert [u = (2::int)]",
496 ("PolyMinus",["polynom", "probe"],
497 ["probe", "fuer_polynom"]))];
499 autoCalculate 1 CompleteCalc;
500 val ((pt,p),_) = get_calc 1;
501 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "29 = 29"
502 then () else error "polyminus.sml: Probe 29 = 29";
503 Test_Tool.show_pt pt;
506 "----------- try fun applyTactics --------------------------------";
507 "----------- try fun applyTactics --------------------------------";
508 "----------- try fun applyTactics --------------------------------";
510 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
512 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
513 ["simplification", "for_polynomials", "with_minus"]))];
515 autoCalculate 1 CompleteCalcHead;
516 autoCalculate 1 (Steps 1);
517 autoCalculate 1 (Steps 1);
518 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
520 fetchApplicableTactics 1 0 p;
521 val appltacs = specific_from_prog pt p;
522 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
523 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
525 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
526 val erls = erls_ordne_alphabetisch;
527 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
529 rewrite_ ctxt e_rew_ord erls false @{thm tausche_minus} t;
530 UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
532 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
534 rewrite_ ctxt e_rew_ord erls false @{thm tausche_minus_plus} t;
536 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
538 rewrite_set_ ctxt false ordne_alphabetisch t;
539 UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
542 applyTactic 1 p (hd (specific_from_prog pt p)) (*tausche_minus*);
543 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
545 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
546 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
548 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
549 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
551 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
552 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
555 (*<CALCMESSAGE> failure </CALCMESSAGE>
556 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
557 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
560 autoCalculate 1 CompleteCalc;
561 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
562 (*independent from failure above: met_simp_poly_minus not confluent:
563 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
564 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
565 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
567 val "2 * g + (3 - 2 * e + 2 * f)" = get_obj g_res pt (fst p) |> UnparseC.term;
568 (* ---------^^^--- not quite perfect*)
571 "#############################################################################";
573 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
575 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
576 ["simplification", "for_polynomials", "with_minus"]))];
578 autoCalculate 1 CompleteCalc;
579 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
580 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "2 * g + h"
581 then () else error "polyminus.sml: addiere_vor_minus";
584 "#############################################################################";
586 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
588 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
589 ["simplification", "for_polynomials", "with_minus"]))];
591 autoCalculate 1 CompleteCalc;
592 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
593 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "f + 2 * g"
594 then () else error "polyminus.sml: tausche_vor_plus";
596 "----------- pbl binom polynom vereinfachen p.39 -----------------";
597 "----------- pbl binom polynom vereinfachen p.39 -----------------";
598 "----------- pbl binom polynom vereinfachen p.39 -----------------";
600 val rls = klammern_ausmultiplizieren;
601 val t = TermC.str2term "(3 * a + 2) * (4 * a - 1::real)";
602 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
603 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
604 val rls = discard_parentheses;
605 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
606 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
607 val rls = ordne_monome;
608 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
609 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
611 val t = TermC.str2term "3 * a * 4 * a";
612 val rls = ordne_monome;
613 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
615 val rls = klammern_aufloesen;
616 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
617 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
618 val rls = ordne_alphabetisch;
619 (*TODO: make is_monom more general, a*a=a^2, ...*)
620 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
621 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
623 val rls = fasse_zusammen;
624 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
625 val rls = verschoenere;
626 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term t;
631 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
633 ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
634 ["simplification", "for_polynomials", "with_parentheses_mult"]))];
636 autoCalculate 1 CompleteCalc;
637 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
639 if p = ([], Res) andalso
640 UnparseC.term (get_obj g_res pt (fst p)) =(*"- 2 + 12 * a \<up> 2 + 5 * a" with OLD numerals*)
641 "- 2 + 5 * a + 12 * a \<up> 2"
642 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
644 "----------- pbl binom polynom vereinfachen: cube ----------------";
645 "----------- pbl binom polynom vereinfachen: cube ----------------";
646 "----------- pbl binom polynom vereinfachen: cube ----------------";
648 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
649 ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
650 ["simplification", "for_polynomials", "with_parentheses_mult"]))];
652 autoCalculate 1 CompleteCalc;
653 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
654 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "12 * a - 16 * q"
655 then () else error "pbl binom polynom vereinfachen: cube";
657 "----------- Refine.refine Vereinfache ----------------------------------";
658 "----------- Refine.refine Vereinfache ----------------------------------";
659 "----------- Refine.refine Vereinfache ----------------------------------";
660 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"];
661 (*default_print_depth 11;*)
662 val matches = Refine.refine fmz ["vereinfachen"];
663 (*default_print_depth 3;*)
665 "----- go into details, if it seems not to work -----";
666 "--- does the predicate evaluate correctly ?";
667 val t = TermC.str2term
668 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))";
669 val ma = eval_matchsub "" "Prog_Expr.matchsub" t thy;
671 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
672 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
673 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
675 "--- does the respective prls rewrite ?";
676 val prls = Rule_Set.append_rules "prls_pbl_vereinf_poly" Rule_Set.empty
677 [Eval ("Poly.is_polyexp", eval_is_polyexp ""),
678 Eval ("Prog_Expr.matchsub", eval_matchsub ""),
679 Thm ("or_true",@{thm or_true}),
680 (*"(?a | True) = True"*)
681 Thm ("or_false",@{thm or_false}),
682 (*"(?a | False) = ?a"*)
683 Thm ("not_true", @{thm not_true}),
684 (*"(~ True) = False"*)
685 Thm ("not_false", @{thm not_false})
686 (*"(~ False) = True"*)];
687 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
688 val SOME (t', _) = rewrite_set_ ctxt false prls t;
690 "--- does the respective prls rewrite the whole predicate ?";
691 val t = TermC.str2term
692 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
693 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
694 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
695 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
696 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
697 val SOME (t', _) = rewrite_set_ ctxt false prls t;
698 if UnparseC.term t' = "False" then ()
699 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
701 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
702 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
703 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
704 (*see test/../termC.sml for details*)
705 val t = TermC.parse_patt thy "t_t is_polyexp";
706 val t = TermC.parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
707 " matchsub (?a + (?b - ?c)) t_t | " ^
708 " matchsub (?a - (?b + ?c)) t_t | " ^
709 " matchsub (?a + (?b - ?c)) t_t )");
710 (*show_types := true;
711 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)"
712 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
713 show_types := false;*)
715 "\<not> (matchsub (?a + (?b + ?c)) t_t \<or>\n " ^
716 "matchsub (?a + (?b - ?c)) t_t \<or>\n " ^
717 "matchsub (?a - (?b + ?c)) t_t \<or> " ^
718 "matchsub (?a + (?b - ?c)) t_t)"
719 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";