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 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
173 Rewrite.trace_on:=false; (*true false*)
174 val t = TermC.str2term "((a + d) + c) + b";
175 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
176 if UnparseC.term t = "a + (b + (c + d))" then ()
177 else error "polyminus.sml 1 watch order_add_mult";
178 Rewrite.trace_on:=false; (*true false*)
180 "----- the same stepwise...";
181 val od = ord_make_polynomial true (@{theory "Poly"});
182 val t = TermC.str2term "((a + d) + c) + b";
184 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
186 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
188 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
190 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
192 if UnparseC.term t = "a + (b + (c + d))" then ()
193 else error "polyminus.sml 2 watch order_add_mult";
195 "----- if parentheses are right, left_commute is (almost) sufficient...";
196 val t = TermC.str2term "a + (d + (c + b))";
198 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
200 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t;UnparseC.term t;
202 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
205 "----- but we do not want the parentheses at right; thus: cond.rew.";
206 "WN0712707 complicated monomials do not yet work ...";
207 val t = TermC.str2term "((5*a + 4*d) + 3*c) + 2*b";
208 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
209 if UnparseC.term t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
210 else error "polyminus.sml: order_add_mult changed";
212 "----- here we see rew_sub going into subterm with ord.rew....";
213 val od = ord_make_polynomial false (@{theory "Poly"});
214 val t = TermC.str2term "b + a + c + d";
215 val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
216 val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
217 (*@@@ rew_sub gosub: t = d + (b + a + c)
218 @@@ rew_sub begin: t = b + a + c*)
221 "----------- build predicate for +- ordering ---------------------";
222 "----------- build predicate for +- ordering ---------------------";
223 "----------- build predicate for +- ordering ---------------------";
226 "123" < "a"; (*unused due to ---vvv*)
227 "12" < "3"; (*true !!!*)
229 " a kleiner b ==> (b + a) = (a + b)";
230 TermC.str2term "aaa";
231 TermC.str2term "222 * aaa";
233 case eval_kleiner 0 0 (TermC.str2term "123 kleiner 32") 0 of
234 SOME ("123 kleiner 32 = False", _) => ()
235 | _ => error "polyminus.sml: 12 kleiner 9 = False";
237 case eval_kleiner 0 0 (TermC.str2term "a kleiner b") 0 of
238 SOME ("a kleiner b = True", _) => ()
239 | _ => error "polyminus.sml: a kleiner b = True";
241 case eval_kleiner 0 0 (TermC.str2term "(10*g) kleiner f") 0 of
242 SOME ("10 * g kleiner f = False", _) => ()
243 | _ => error "polyminus.sml: 10 * g kleiner f = False";
245 case eval_kleiner 0 0 (TermC.str2term "(a \<up> 2) kleiner b") 0 of
246 SOME ("a \<up> 2 kleiner b = True", _) => ()
247 | _ => error "polyminus.sml: a \<up> 2 kleiner b = True";
249 case eval_kleiner 0 0 (TermC.str2term "(3*a \<up> 2) kleiner b") 0 of
250 SOME ("3 * a \<up> 2 kleiner b = True", _) => ()
251 | _ => error "polyminus.sml: 3 * a \<up> 2 kleiner b = True";
253 case eval_kleiner 0 0 (TermC.str2term "(a*b) kleiner c") 0 of
254 SOME ("a * b kleiner c = True", _) => ()
255 | _ => error "polyminus.sml: a * b kleiner b = True";
257 case eval_kleiner 0 0 (TermC.str2term "(3*a*b) kleiner c") 0 of
258 SOME ("3 * a * b kleiner c = True", _) => ()
259 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
261 "======= compare tausche_plus with real_num_collect";
264 val erls = erls_ordne_alphabetisch;
265 val t = TermC.str2term "b + a";
266 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
267 if UnparseC.term t = "a + b" then ()
268 else error "polyminus.sml: ordne_alphabetisch1 b + a";
270 val erls = Atools_erls;
271 val t = TermC.str2term "2*a + 3*a";
272 val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; UnparseC.term t;
274 "======= test rewrite_, rewrite_set_";
275 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
276 val erls = erls_ordne_alphabetisch;
277 val t = TermC.str2term "b + a";
278 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
279 if UnparseC.term t = "a + b" then ()
280 else error "polyminus.sml: ordne_alphabetisch a + b";
282 val t = TermC.str2term "2*b + a";
283 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
284 if UnparseC.term t = "a + 2 * b" then ()
285 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
287 val t = TermC.str2term "a + c + b";
288 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
289 if UnparseC.term t = "a + b + c" then ()
290 else error "polyminus.sml: ordne_alphabetisch a + b + c";
292 "======= rewrite goes into subterms";
293 val t = TermC.str2term "a + c + b + d ::real";
294 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; UnparseC.term t;
295 if UnparseC.term t = "a + b + c + d" then ()
296 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
298 val t = TermC.str2term "a + c + d + b";
299 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
300 if UnparseC.term t = "a + b + c + d" then ()
301 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
303 "======= here we see rew_sub going into subterm with cond.rew....";
304 val t = TermC.str2term "b + a + c + d";
305 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
306 if UnparseC.term t = "a + b + c + d" then ()
307 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
309 "======= compile rls for the most complicated terms";
310 val t = TermC.str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
311 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
312 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t;
313 if UnparseC.term t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
314 then () else error "polyminus.sml: ordne_alphabetisch finished";
318 "----------- build fasse_zusammen --------------------------------";
319 "----------- build fasse_zusammen --------------------------------";
320 "----------- build fasse_zusammen --------------------------------";
321 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
322 val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
323 if UnparseC.term t = "3 + - 2 * e + 2 * f + 2 * g" then ()
324 else error "polyminus.sml: fasse_zusammen finished";
326 "----------- build verschoenere ----------------------------------";
327 "----------- build verschoenere ----------------------------------";
328 "----------- build verschoenere ----------------------------------";
329 val t = TermC.str2term "3 + - 2 * e + 2 * f + 2 * g";
330 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
331 if UnparseC.term t = "3 - 2 * e + 2 * f + 2 * g" then ()
332 else error "polyminus.sml: verschoenere 3 + - 2 * e ...";
334 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
335 Rewrite.trace_on:=false; (*true false*)
337 "----------- met simplification for_polynomials with_minus -------";
338 "----------- met simplification for_polynomials with_minus -------";
339 "----------- met simplification for_polynomials with_minus -------";
341 "Program SimplifyScript (t_t::real) = \
342 \ (((Try (Rewrite_Set ordne_alphabetisch False)) #> \
343 \ (Try (Rewrite_Set fasse_zusammen False)) #> \
344 \ (Try (Rewrite_Set verschoenere False))) t_t)"
345 val sc = (inst_abs o (TermC.parseNEW' ctxt)) str;
348 "----------- me simplification.for_polynomials.with_minus";
349 "----------- me simplification.for_polynomials.with_minus";
350 "----------- me simplification.for_polynomials.with_minus";
352 val (p,_,f,nxt,_,pt) =
354 [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
356 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
357 ["simplification", "for_polynomials", "with_minus"]))];
358 val (p,_,f,nxt,_,pt) = me nxt p c pt;
359 val (p,_,f,nxt,_,pt) = me nxt p c pt;
360 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;
365 val (p,_,f,nxt,_,pt) = me nxt p c pt;
366 val (p,_,f,nxt,_,pt) = me nxt p c pt;
367 val (p,_,f,nxt,_,pt) = me nxt p c pt;
368 val (p,_,f,nxt,_,pt) = me nxt p c pt;
369 val (p,_,f,nxt,_,pt) = me nxt p c pt;
370 if f2str f = "3 - 2 * e + 2 * f + 2 * g"
371 then case nxt of End_Proof' => () | _ => error "me simplification.for_polynomials.with_minus 1"
372 else error "polyminus.sml: me simplification.for_polynomials.with_minus 2";
374 "----------- pbl polynom vereinfachen p.33 -----------------------";
375 "----------- pbl polynom vereinfachen p.33 -----------------------";
376 "----------- pbl polynom vereinfachen p.33 -----------------------";
377 "----------- 140 c ---";
379 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
381 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
382 ["simplification", "for_polynomials", "with_minus"]))];
384 autoCalculate 1 CompleteCalc;
385 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
386 if p = ([], Res) andalso
387 UnparseC.term (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
388 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
392 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
394 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
395 ["simplification", "for_polynomials", "with_minus"]))];
397 autoCalculate 1 CompleteCalc;
398 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
399 if p = ([], Res) andalso
400 UnparseC.term (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
401 then () else error "polyminus.sml: Vereinfache 140 d)";
405 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
407 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
408 ["simplification", "for_polynomials", "with_minus"]))];
410 autoCalculate 1 CompleteCalc;
411 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
412 if p = ([], Res) andalso
413 UnparseC.term (get_obj g_res pt (fst p)) = "- (3 * f)"
414 then () else error "polyminus.sml: Vereinfache 139 c)";
418 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
420 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
421 ["simplification", "for_polynomials", "with_minus"]))];
423 autoCalculate 1 CompleteCalc;
424 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
425 if p = ([], Res) andalso
426 UnparseC.term (get_obj g_res pt (fst p)) = "- 3 * u - v"
427 then () else error "polyminus.sml: Vereinfache 139 b)";
431 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
433 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
434 ["simplification", "for_polynomials", "with_minus"]))];
436 autoCalculate 1 CompleteCalc;
437 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
438 if p = ([], Res) andalso
439 UnparseC.term (get_obj g_res pt (fst p)) = "- 4 * u + 2 * v"
440 then () else error "polyminus.sml: Vereinfache 138 a)";
442 "----------- met probe fuer_polynom ------------------------------";
443 "----------- met probe fuer_polynom ------------------------------";
444 "----------- met probe fuer_polynom ------------------------------";
446 "Program ProbeScript (e_e::bool) (w_s::bool list) =\
447 \ (let e_e = Take e_e; \
448 \ e_e = Substitute w_s e_e \
449 \ in (Repeat((Try (Repeat (Calculate ''TIMES''))) #> \
450 \ (Try (Repeat (Calculate ''PLUS''))) #> \
451 \ (Try (Repeat (Calculate ''MINUS''))))) e_e)"
452 val sc = (inst_abs o (TermC.parseNEW' ctxt)) str;
455 "----------- pbl polynom probe -----------------------------------";
456 "----------- pbl polynom probe -----------------------------------";
457 "----------- pbl polynom probe -----------------------------------";
459 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
460 \3 - 2 * e + 2 * f + 2 * (g::int))",
461 "mitWert [e = (1::int), f = (2::int), g = (3::int)]",
463 ("PolyMinus",["polynom", "probe"],
464 ["probe", "fuer_polynom"]))];
466 autoCalculate 1 CompleteCalc;
467 (* autoCalculate 1 CompleteCalcHead;
468 autoCalculate 1 (Steps 1);
469 autoCalculate 1 (Steps 1);
470 val ((pt,p),_) = get_calc 1; UnparseC.term (get_obj g_res pt (fst p));
471 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
472 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
473 val ((pt,p),_) = get_calc 1;
474 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "11 = 11"
475 then () else error "polyminus.sml: Probe 11 = 11";
476 Test_Tool.show_pt pt;
479 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
480 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
481 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
483 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
485 ("PolyMinus",["klammer", "polynom", "vereinfachen"],
486 ["simplification", "for_polynomials", "with_parentheses"]))];
488 autoCalculate 1 CompleteCalc;
489 val ((pt,p),_) = get_calc 1;
490 if p = ([], Res) andalso
491 UnparseC.term (get_obj g_res pt (fst p)) = "1 + 14 * u"
492 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
493 Test_Tool.show_pt pt;
495 "======= probe p.34 -----";
497 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * (u::int))",
498 "mitWert [u = (2::int)]",
500 ("PolyMinus",["polynom", "probe"],
501 ["probe", "fuer_polynom"]))];
503 autoCalculate 1 CompleteCalc;
504 val ((pt,p),_) = get_calc 1;
505 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "29 = 29"
506 then () else error "polyminus.sml: Probe 29 = 29";
507 Test_Tool.show_pt pt;
510 "----------- try fun applyTactics --------------------------------";
511 "----------- try fun applyTactics --------------------------------";
512 "----------- try fun applyTactics --------------------------------";
514 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
516 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
517 ["simplification", "for_polynomials", "with_minus"]))];
519 autoCalculate 1 CompleteCalcHead;
520 autoCalculate 1 (Steps 1);
521 autoCalculate 1 (Steps 1);
522 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
524 fetchApplicableTactics 1 0 p;
525 val appltacs = specific_from_prog pt p;
526 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
527 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
529 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
530 val erls = erls_ordne_alphabetisch;
531 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
533 rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus} t;
534 UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
536 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
538 rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
540 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
542 rewrite_set_ (@{theory "Isac_Knowledge"}) false ordne_alphabetisch t;
543 UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
544 Rewrite.trace_on := false; (*true false*)
547 applyTactic 1 p (hd (specific_from_prog pt p)) (*tausche_minus*);
548 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
550 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
551 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
553 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
554 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
556 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
557 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
560 (*<CALCMESSAGE> failure </CALCMESSAGE>
561 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
562 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
565 autoCalculate 1 CompleteCalc;
566 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
567 (*independent from failure above: met_simp_poly_minus not confluent:
568 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
569 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
570 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
572 val "2 * g + (3 - 2 * e + 2 * f)" = get_obj g_res pt (fst p) |> UnparseC.term;
573 (* ---------^^^--- not quite perfect*)
576 "#############################################################################";
578 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
580 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
581 ["simplification", "for_polynomials", "with_minus"]))];
583 autoCalculate 1 CompleteCalc;
584 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
585 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "2 * g + h"
586 then () else error "polyminus.sml: addiere_vor_minus";
589 "#############################################################################";
591 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
593 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
594 ["simplification", "for_polynomials", "with_minus"]))];
596 autoCalculate 1 CompleteCalc;
597 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
598 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "f + 2 * g"
599 then () else error "polyminus.sml: tausche_vor_plus";
601 "----------- pbl binom polynom vereinfachen p.39 -----------------";
602 "----------- pbl binom polynom vereinfachen p.39 -----------------";
603 "----------- pbl binom polynom vereinfachen p.39 -----------------";
605 val rls = klammern_ausmultiplizieren;
606 val t = TermC.str2term "(3 * a + 2) * (4 * a - 1::real)";
607 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
608 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
609 val rls = discard_parentheses;
610 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
611 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
612 val rls = ordne_monome;
613 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
614 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
616 val t = TermC.str2term "3 * a * 4 * a";
617 val rls = ordne_monome;
618 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
620 val rls = klammern_aufloesen;
621 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
622 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
623 val rls = ordne_alphabetisch;
624 (*TODO: make is_monom more general, a*a=a^2, ...*)
625 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
626 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
628 val rls = fasse_zusammen;
629 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
630 val rls = verschoenere;
631 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
636 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
638 ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
639 ["simplification", "for_polynomials", "with_parentheses_mult"]))];
641 autoCalculate 1 CompleteCalc;
642 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
644 if p = ([], Res) andalso
645 UnparseC.term (get_obj g_res pt (fst p)) =(*"- 2 + 12 * a \<up> 2 + 5 * a" with OLD numerals*)
646 "- 2 + 5 * a + 12 * a \<up> 2"
647 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
649 "----------- pbl binom polynom vereinfachen: cube ----------------";
650 "----------- pbl binom polynom vereinfachen: cube ----------------";
651 "----------- pbl binom polynom vereinfachen: cube ----------------";
653 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
654 ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
655 ["simplification", "for_polynomials", "with_parentheses_mult"]))];
657 autoCalculate 1 CompleteCalc;
658 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
659 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "12 * a - 16 * q"
660 then () else error "pbl binom polynom vereinfachen: cube";
662 "----------- Refine.refine Vereinfache ----------------------------------";
663 "----------- Refine.refine Vereinfache ----------------------------------";
664 "----------- Refine.refine Vereinfache ----------------------------------";
665 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"];
666 (*default_print_depth 11;*)
667 val matches = Refine.refine fmz ["vereinfachen"];
668 (*default_print_depth 3;*)
670 "----- go into details, if it seems not to work -----";
671 "--- does the predicate evaluate correctly ?";
672 val t = TermC.str2term
673 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))";
674 val ma = eval_matchsub "" "Prog_Expr.matchsub" t thy;
676 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
677 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
678 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
680 "--- does the respective prls rewrite ?";
681 val prls = Rule_Set.append_rules "prls_pbl_vereinf_poly" Rule_Set.empty
682 [Eval ("Poly.is_polyexp", eval_is_polyexp ""),
683 Eval ("Prog_Expr.matchsub", eval_matchsub ""),
684 Thm ("or_true",@{thm or_true}),
685 (*"(?a | True) = True"*)
686 Thm ("or_false",@{thm or_false}),
687 (*"(?a | False) = ?a"*)
688 Thm ("not_true", @{thm not_true}),
689 (*"(~ True) = False"*)
690 Thm ("not_false", @{thm not_false})
691 (*"(~ False) = True"*)];
692 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
693 val SOME (t', _) = rewrite_set_ thy false prls t;
694 Rewrite.trace_on := false; (*true false*)
696 "--- does the respective prls rewrite the whole predicate ?";
697 val t = TermC.str2term
698 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
699 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
700 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
701 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
702 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
703 val SOME (t', _) = rewrite_set_ thy false prls t;
704 Rewrite.trace_on := false; (*true false*)
705 if UnparseC.term t' = "False" then ()
706 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
708 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
709 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
710 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
711 (*see test/../termC.sml for details*)
712 val t = TermC.parse_patt thy "t_t is_polyexp";
713 val t = TermC.parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
714 " matchsub (?a + (?b - ?c)) t_t | " ^
715 " matchsub (?a - (?b + ?c)) t_t | " ^
716 " matchsub (?a + (?b - ?c)) t_t )");
717 (*show_types := true;
718 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)"
719 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
720 show_types := false;*)
722 "\<not> (matchsub (?a + (?b + ?c)) t_t \<or>\n " ^
723 "matchsub (?a + (?b - ?c)) t_t \<or>\n " ^
724 "matchsub (?a - (?b + ?c)) t_t \<or> " ^
725 "matchsub (?a + (?b - ?c)) t_t)"
726 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";