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 (ParseC.parse_test @{context} "12 ::real") = "12" then () else error "identifier 1";
40 if identifier (ParseC.parse_test @{context}
41 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g ::real") = "|||||||||||||"
42 then () else error "identifier 1a";
44 if identifier (ParseC.parse_test @{context} "a ::real") = "a" then () else error "identifier 2";
45 if identifier (ParseC.parse_test @{context} "3 * a ::real") = "a" then () else error "identifier 3";
47 if identifier (ParseC.parse_test @{context} "a \<up> 2 ::real") = "a" then () else error "identifier 4";
48 if identifier (ParseC.parse_test @{context} "3*a \<up> 2 ::real") = "a" then () else error "identifier 5";
49 if identifier (ParseC.parse_test @{context} "a * b ::real") = "b" then () else error "identifier 5b";
51 (*these are strange (see "specific monomials" in comment to fun.def.)..*)
52 if identifier (ParseC.parse_test @{context} "a*b ::real") = "b" then () else error "identifier 6";
53 if identifier (ParseC.parse_test @{context} "(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)";
65 ParseC.parse_test @{context} "aaa";
66 ParseC.parse_test @{context} "222 * aaa";
68 case eval_kleiner 0 0 (ParseC.parse_test @{context} "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 (ParseC.parse_test @{context} "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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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 = ParseC.parse_test @{context} "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 = ParseC.parse_test @{context} "0 ::real";
110 if ist_monom t then () else error "ist_monom 1";
112 val t = ParseC.parse_test @{context} "a";
113 if ist_monom t then () else error "ist_monom 2";
115 val t = ParseC.parse_test @{context} "2 * a";
116 if ist_monom t then () else error "ist_monom 3";
118 val t = ParseC.parse_test @{context} "2 * a * b";
119 if ist_monom t then () else error "ist_monom 4";
121 val t = ParseC.parse_test @{context} "a * b";
122 if ist_monom t then () else error "ist_monom 5";
124 (*not covered before NEW numerals*)
125 val t = ParseC.parse_test @{context} "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 = ParseC.parse_test @{context} "a \<up> 2 * b \<up> 3";
130 if ist_monom t then () else error "ist_monom 7";
132 val t = ParseC.parse_test @{context} "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 (ParseC.parse_test @{context} "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 (ParseC.parse_test @{context} "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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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 = ParseC.parse_test ctxt "((a + d) + c) + b";
174 val SOME (t,_) = rewrite_set_ ctxt false order_add_mult t; UnparseC.term @{context} t;
175 if UnparseC.term @{context} 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
180 val t = ParseC.parse_test @{context} "((a + d) + c) + b";
182 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t; UnparseC.term @{context} t;
184 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t; UnparseC.term @{context} t;
186 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term @{context} t;
188 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term @{context} t;
190 if UnparseC.term @{context} 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 = ParseC.parse_test @{context} "a + (d + (c + b))";
196 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term @{context} t;
198 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.commute} t;UnparseC.term @{context} t;
200 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term @{context} 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 = ParseC.parse_test @{context} "((5*a + 4*d) + 3*c) + 2*b";
206 val SOME (t,_) = rewrite_set_ ctxt false order_add_mult t; UnparseC.term @{context} t;
207 if UnparseC.term @{context} 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;
212 val t = ParseC.parse_test @{context} "b + a + c + d";
213 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty false @{thm add.commute} t; UnparseC.term @{context} t;
214 val SOME (t,_) = rewrite_ ctxt od Rule_Set.empty false @{thm add.commute} t; UnparseC.term @{context} 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 ParseC.parse_test @{context} "aaa";
229 ParseC.parse_test @{context} "222 * aaa";
231 case eval_kleiner 0 0 (ParseC.parse_test @{context} "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 (ParseC.parse_test @{context} "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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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 (ParseC.parse_test @{context} "(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";
260 val od = Rewrite_Ord.function_empty;
262 val asm_rls = erls_ordne_alphabetisch;
263 val t = ParseC.parse_test @{context} "b + a";
264 val SOME (t,_) = rewrite_ ctxt od asm_rls false @{thm tausche_plus} t; UnparseC.term @{context} t;
265 if UnparseC.term @{context} t = "a + b" then ()
266 else error "polyminus.sml: ordne_alphabetisch1 b + a";
268 val asm_rls = Atools_erls;
269 val t = ParseC.parse_test @{context} "2*a + 3*a";
270 val SOME (t,_) = rewrite_ ctxt od asm_rls false @{thm real_num_collect} t; UnparseC.term @{context} t;
272 "======= test rewrite_, rewrite_set_";
273 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
274 val asm_rls = erls_ordne_alphabetisch;
275 val t = ParseC.parse_test @{context} "b + a";
276 val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term @{context} t;
277 if UnparseC.term @{context} t = "a + b" then ()
278 else error "polyminus.sml: ordne_alphabetisch a + b";
280 val t = ParseC.parse_test @{context} "2*b + a";
281 val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term @{context} t;
282 if UnparseC.term @{context} t = "a + 2 * b" then ()
283 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
285 val t = ParseC.parse_test @{context} "a + c + b";
286 val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term @{context} t;
287 if UnparseC.term @{context} t = "a + b + c" then ()
288 else error "polyminus.sml: ordne_alphabetisch a + b + c";
290 "======= rewrite goes into subterms";
291 val t = ParseC.parse_test @{context} "a + c + b + d ::real";
292 val SOME (t,_) = rewrite_ ctxt od asm_rls false @{thm tausche_plus_plus} t; UnparseC.term @{context} t;
293 if UnparseC.term @{context} t = "a + b + c + d" then ()
294 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
296 val t = ParseC.parse_test @{context} "a + c + d + b";
297 val SOME (t,_) = rewrite_set_ ctxt false ordne_alphabetisch t; UnparseC.term @{context} t;
298 if UnparseC.term @{context} 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 = ParseC.parse_test @{context} "b + a + c + d";
303 val SOME (t,_) = rewrite_ ctxt od asm_rls false @{thm tausche_plus} t; UnparseC.term @{context} t;
304 if UnparseC.term @{context} 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 = ParseC.parse_test @{context} "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 @{context} 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 = ParseC.parse_test @{context} "- 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 @{context} 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 = ParseC.parse_test @{context} "3 + - 2 * e + 2 * f + 2 * g";
328 val SOME (t,_) = rewrite_set_ ctxt false verschoenere t;
329 if UnparseC.term @{context} 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 (ParseC.parse_test ctxt)) str;
342 TermC.atom_trace_detail @{context} sc;
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) =
349 Test_Code.init_calc @{context}
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 @{context} [(["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),_) = States.get_calc 1; Test_Tool.show_pt pt;
382 if p = ([], Res) andalso
383 UnparseC.term @{context} (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 @{context} [(["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),_) = States.get_calc 1; Test_Tool.show_pt pt;
395 if p = ([], Res) andalso
396 UnparseC.term @{context} (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 @{context} [(["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),_) = States.get_calc 1; Test_Tool.show_pt pt;
408 if p = ([], Res) andalso
409 UnparseC.term @{context} (get_obj g_res pt (fst p)) = "- (3 * f)"
410 then () else error "polyminus.sml: Vereinfache 139 c)";
414 CalcTree @{context} [(["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),_) = States.get_calc 1; Test_Tool.show_pt pt;
421 if p = ([], Res) andalso
422 UnparseC.term @{context} (get_obj g_res pt (fst p)) = "- 3 * u - v"
423 then () else error "polyminus.sml: Vereinfache 139 b)";
427 CalcTree @{context} [(["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),_) = States.get_calc 1; Test_Tool.show_pt pt;
434 if p = ([], Res) andalso
435 UnparseC.term @{context} (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 (ParseC.parse_test ctxt)) str;
449 TermC.atom_trace_detail @{context} sc;
451 "----------- pbl polynom probe -----------------------------------";
452 "----------- pbl polynom probe -----------------------------------";
453 "----------- pbl polynom probe -----------------------------------";
455 CalcTree @{context} [(["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),_) = States.get_calc 1; UnparseC.term @{context} (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),_) = States.get_calc 1;
470 if p = ([], Res) andalso UnparseC.term @{context} (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 ---------------";
478 (*/------------------- WN230815 test broke since ???, undetected ERROR in autoCalculate ----\\* )
480 CalcTree @{context} [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
482 ("PolyMinus",["klammer", "polynom", "vereinfachen"],
483 ["simplification", "for_polynomials", "with_parentheses"]))];
485 autoCalculate 1 CompleteCalc;
486 val ((pt,p),_) = States.get_calc 1;
487 if p = ([], Res) andalso
488 UnparseC.term @{context} (get_obj g_res pt (fst p)) = "1 + 14 * u"
489 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
490 Test_Tool.show_pt pt;
492 "======= probe p.34 -----";
494 CalcTree @{context} [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * (u::int))",
495 "mitWert [u = (2::int)]",
497 ("PolyMinus",["polynom", "probe"],
498 ["probe", "fuer_polynom"]))];
500 autoCalculate 1 CompleteCalc;
501 val ((pt,p),_) = States.get_calc 1;
502 if p = ([], Res) andalso UnparseC.term @{context} (get_obj g_res pt (fst p)) = "29 = 29"
503 then () else error "polyminus.sml: Probe 29 = 29";
504 Test_Tool.show_pt pt;
505 ( *\------------------- WN230815 test broke since ???, undetected ERROR in autoCalculate ----//*)
508 "----------- try fun applyTactics --------------------------------";
509 "----------- try fun applyTactics --------------------------------";
510 "----------- try fun applyTactics --------------------------------";
512 CalcTree @{context} [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
514 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
515 ["simplification", "for_polynomials", "with_minus"]))];
517 autoCalculate 1 CompleteCalcHead;
518 autoCalculate 1 (Steps 1);
519 autoCalculate 1 (Steps 1);
520 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
522 fetchApplicableTactics 1 0 p;
523 val appltacs = specific_from_prog pt p;
524 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
525 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
527 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
528 val asm_rls = erls_ordne_alphabetisch;
529 val t = ParseC.parse_test @{context} "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
531 rewrite_ ctxt Rewrite_Ord.function_empty asm_rls false @{thm tausche_minus} t;
532 UnparseC.term @{context} t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
534 val t = ParseC.parse_test @{context} "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
536 rewrite_ ctxt Rewrite_Ord.function_empty asm_rls false @{thm tausche_minus_plus} t;
538 val t = ParseC.parse_test @{context} "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
540 rewrite_set_ ctxt false ordne_alphabetisch t;
541 UnparseC.term @{context} t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
544 applyTactic 1 p (hd (specific_from_prog pt p)) (*tausche_minus*);
545 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
547 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
548 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
550 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
551 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
553 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
554 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
557 (*<CALCMESSAGE> failure </CALCMESSAGE>
558 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
559 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
562 autoCalculate 1 CompleteCalc;
563 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
564 (*independent from failure above: met_simp_poly_minus not confluent:
565 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
566 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
567 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
569 val "2 * g + (3 - 2 * e + 2 * f)" = get_obj g_res pt (fst p) |> UnparseC.term @{context};
570 (* ---------^^^--- not quite perfect*)
573 "#############################################################################";
575 CalcTree @{context} [(["Term (- (8 * g) + 10 * g + h)",
577 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
578 ["simplification", "for_polynomials", "with_minus"]))];
580 autoCalculate 1 CompleteCalc;
581 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
582 if p = ([], Res) andalso UnparseC.term @{context} (get_obj g_res pt (fst p)) = "2 * g + h"
583 then () else error "polyminus.sml: addiere_vor_minus";
586 "#############################################################################";
588 CalcTree @{context} [(["Term (- (8 * g) + 10 * g + f)",
590 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
591 ["simplification", "for_polynomials", "with_minus"]))];
593 autoCalculate 1 CompleteCalc;
594 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
595 if p = ([], Res) andalso UnparseC.term @{context} (get_obj g_res pt (fst p)) = "f + 2 * g"
596 then () else error "polyminus.sml: tausche_vor_plus";
598 "----------- pbl binom polynom vereinfachen p.39 -----------------";
599 "----------- pbl binom polynom vereinfachen p.39 -----------------";
600 "----------- pbl binom polynom vereinfachen p.39 -----------------";
602 val rls = klammern_ausmultiplizieren;
603 val t = ParseC.parse_test @{context} "(3 * a + 2) * (4 * a - 1::real)";
604 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term @{context} t;
605 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
606 val rls = discard_parentheses;
607 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term @{context} t;
608 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
609 val rls = ordne_monome;
610 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term @{context} t;
611 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
613 val t = ParseC.parse_test @{context} "3 * a * 4 * a";
614 val rls = ordne_monome;
615 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term @{context} t;
617 val rls = klammern_aufloesen;
618 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term @{context} t;
619 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
620 val rls = ordne_alphabetisch;
621 (*TODO: make is_monom more general, a*a=a^2, ...*)
622 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term @{context} t;
623 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
625 val rls = fasse_zusammen;
626 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term @{context} t;
627 val rls = verschoenere;
628 val SOME (t,_) = rewrite_set_ ctxt false rls t; UnparseC.term @{context} t;
633 CalcTree @{context} [(["Term ((3*a + 2) * (4*a - 1))",
635 ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
636 ["simplification", "for_polynomials", "with_parentheses_mult"]))];
638 autoCalculate 1 CompleteCalc;
639 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
641 if p = ([], Res) andalso
642 UnparseC.term @{context} (get_obj g_res pt (fst p)) =(*"- 2 + 12 * a \<up> 2 + 5 * a" with OLD numerals*)
643 "- 2 + 5 * a + 12 * a \<up> 2"
644 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
646 "----------- pbl binom polynom vereinfachen: cube ----------------";
647 "----------- pbl binom polynom vereinfachen: cube ----------------";
648 "----------- pbl binom polynom vereinfachen: cube ----------------";
650 CalcTree @{context} [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
651 ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
652 ["simplification", "for_polynomials", "with_parentheses_mult"]))];
654 autoCalculate 1 CompleteCalc;
655 val ((pt,p),_) = States.get_calc 1; Test_Tool.show_pt pt;
656 if p = ([], Res) andalso UnparseC.term @{context} (get_obj g_res pt (fst p)) = "12 * a - 16 * q"
657 then () else error "pbl binom polynom vereinfachen: cube";
659 "----------- Refine.refine Vereinfache ----------------------------------";
660 "----------- Refine.refine Vereinfache ----------------------------------";
661 "----------- Refine.refine Vereinfache ----------------------------------";
662 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"];
663 (*default_print_depth 11;*)
664 val matches = Refine.by_formalise @{context} fmz ["vereinfachen"];
665 (*default_print_depth 3;*)
667 "----- go into details, if it seems not to work -----";
668 "--- does the predicate evaluate correctly ?";
669 val t = ParseC.parse_patt_test @{theory}
670 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))";
671 val ma = eval_matchsub "" "Prog_Expr.matchsub" t ctxt;
673 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
674 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
675 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
677 "--- does the respective where_rls rewrite ?";
678 val where_rls = Rule_Set.append_rules "prls_pbl_vereinf_poly" Rule_Set.empty
679 [Eval ("Poly.is_polyexp", eval_is_polyexp ""),
680 Eval ("Prog_Expr.matchsub", eval_matchsub ""),
681 Thm ("or_true",@{thm or_true}),
682 (*"(?a | True) = True"*)
683 Thm ("or_false",@{thm or_false}),
684 (*"(?a | False) = ?a"*)
685 Thm ("not_true", @{thm not_true}),
686 (*"(~ True) = False"*)
687 Thm ("not_false", @{thm not_false})
688 (*"(~ False) = True"*)];
689 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
690 val SOME (t', _) = rewrite_set_ ctxt false where_rls t;
692 "--- does the respective where_rls rewrite the whole predicate ?";
693 val t = ParseC.parse_patt_test @{theory}
694 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
695 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
696 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
697 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
698 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
699 val SOME (t', _) = rewrite_set_ ctxt false where_rls t;
700 if UnparseC.term @{context} t' = "False" then ()
701 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
703 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
704 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
705 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
706 (*see test/../termC.sml for details*)
707 val SOME t = ParseC.patt_opt thy "t_t is_polyexp";
708 val SOME t = ParseC.patt_opt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
709 " matchsub (?a + (?b - ?c)) t_t | " ^
710 " matchsub (?a - (?b + ?c)) t_t | " ^
711 " matchsub (?a + (?b - ?c)) t_t )");
712 (*show_types := true;
713 if UnparseC.term @{context} 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)"
714 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
715 show_types := false;*)
716 if UnparseC.term @{context} t =
717 "\<not> (matchsub (?a + (?b + ?c)) t_t \<or>\n " ^
718 "matchsub (?a + (?b - ?c)) t_t \<or>\n " ^
719 "matchsub (?a - (?b + ?c)) t_t \<or> " ^
720 "matchsub (?a + (?b - ?c)) t_t)"
721 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";