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"};
35 "----------- fun identifier --------------------------------------------------------------------";
36 "----------- fun identifier --------------------------------------------------------------------";
37 "----------- fun identifier --------------------------------------------------------------------";
38 if identifier (TermC.str2term "12 ::real") = "12" then () else error "identifier 1";
39 if identifier (TermC.str2term "a ::real") = "a" then () else error "identifier 2";
40 if identifier (TermC.str2term "3 * a ::real") = "a" then () else error "identifier 3";
41 if identifier (TermC.str2term "a \<up> 2 ::real") = "a" then () else error "identifier 4";
42 if identifier (TermC.str2term "3*a \<up> 2 ::real") = "a" then () else error "identifier 5";
43 if identifier (TermC.str2term "a * b ::real") = "b" then () else error "identifier 5b";
45 (*these are strange (see "specific monomials" in comment to fun.def.)..*)
46 if identifier (TermC.str2term "a*b ::real") = "b" then () else error "identifier 6";
47 if identifier (TermC.str2term "(3*a*b) ::real") = "b" then () else error "identifier 7";
50 "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
51 "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
52 "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
55 "123" < "a"; (*unused due to ---vvv*)
56 "12" < "3"; (*true !!!*)
58 " a kleiner b ==> (b + a) = (a + b)";
60 TermC.str2term "222 * aaa";
62 case eval_kleiner 0 0 (TermC.str2term "123 kleiner 32") 0 of
63 SOME ("123 kleiner 32 = False", _) => ()
64 | _ => error "polyminus.sml: 12 kleiner 9 = False";
65 case eval_kleiner 0 0 (TermC.str2term "a kleiner b") 0 of
66 SOME ("a kleiner b = True", _) => ()
67 | _ => error "polyminus.sml: a kleiner b = True";
68 case eval_kleiner 0 0 (TermC.str2term "(10*g) kleiner f") 0 of
69 SOME ("10 * g kleiner f = False", _) => ()
70 | _ => error "polyminus.sml: 10 * g kleiner f = False";
71 case eval_kleiner 0 0 (TermC.str2term "(a \<up> 2) kleiner b") 0 of
72 SOME ("a \<up> 2 kleiner b = True", _) => ()
73 | _ => error "polyminus.sml: a \<up> 2 kleiner b = True";
74 case eval_kleiner 0 0 (TermC.str2term "(3*a \<up> 2) kleiner b") 0 of
75 SOME ("3 * a \<up> 2 kleiner b = True", _) => ()
76 | _ => error "polyminus.sml: 3 * a \<up> 2 kleiner b = True";
77 case eval_kleiner 0 0 (TermC.str2term "(a*b) kleiner c") 0 of
78 SOME ("a * b kleiner c = True", _) => ()
79 | _ => error "polyminus.sml: a * b kleiner b = True";
80 case eval_kleiner 0 0 (TermC.str2term "(3*a*b) kleiner c") 0 of
81 SOME ("3 * a * b kleiner c = True", _) => ()
82 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
85 val t = TermC.str2term "12 kleiner 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * (g::real)";
86 val SOME ("12 kleiner 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g = True", _) =
87 eval_kleiner "aaa" "bbb" t "ccc";
88 "~~~~~ fun eval_kleiner , args:"; val (_, _, (p as (Const ("PolyMinus.kleiner",_) $ a $ b)), _) =
89 ("aaa", "bbb", t, "ccc");
90 (*if*) TermC.is_num b (*else*);
92 (*if*) identifier a < identifier b (*else*);
93 "~~~~~ fun identifier , args:"; val (t) = (a);
95 Const ("Num.numeral_class.numeral", _) $ (Const ("Num.num.Bit0", _) $
96 (Const ("Num.num.Bit0", _) $ (Const ("Num.num.Bit1", _) $ Const ("Num.num.One", _)))) => ()
97 | _ => error "eval_kleiner CHANGED"; (*isa*)
100 "----------- fun ist_monom ---------------------------------------------------------------------";
101 "----------- fun ist_monom ---------------------------------------------------------------------";
102 "----------- fun ist_monom ---------------------------------------------------------------------";
103 val t = TermC.str2term "0 ::real";
104 if ist_monom t then () else error "ist_monom 1";
106 val t = TermC.str2term "a";
107 if ist_monom t then () else error "ist_monom 2";
109 val t = TermC.str2term "2 * a";
110 if ist_monom t then () else error "ist_monom 3";
112 val t = TermC.str2term "2 * a * b";
113 if ist_monom t then () else error "ist_monom 4";
115 val t = TermC.str2term "a * b";
116 if ist_monom t then () else error "ist_monom 5";
118 (*not covered before NEW numerals*)
119 val t = TermC.str2term "2 * a \<up> 2 * b";
120 if ist_monom t then () else error "ist_monom 6";
122 (*not covered before NEW numerals*)
123 val t = TermC.str2term "a \<up> 2 * b \<up> 3";
124 if ist_monom t then () else error "ist_monom 7";
126 val t = TermC.str2term "a \<up> 2 * 4 * b \<up> 3 * 5";
127 if ist_monom t then () else error "ist_monom 8";
130 "----------- fun eval_ist_monom ----------------------------------";
131 "----------- fun eval_ist_monom ----------------------------------";
132 "----------- fun eval_ist_monom ----------------------------------";
133 case eval_ist_monom 0 0 (TermC.str2term "12 ist_monom") 0 of
134 SOME ("12 ist_monom = True", _) => ()
135 | _ => error "polyminus.sml: 12 ist_monom = True";
137 case eval_ist_monom 0 0 (TermC.str2term "a ist_monom") 0 of
138 SOME ("a ist_monom = True", _) => ()
139 | _ => error "polyminus.sml: a ist_monom = True";
141 case eval_ist_monom 0 0 (TermC.str2term "(3*a) ist_monom") 0 of
142 SOME ("3 * a ist_monom = True", _) => ()
143 | _ => error "polyminus.sml: 3 * a ist_monom = True";
145 case eval_ist_monom 0 0 (TermC.str2term "(a \<up> 2) ist_monom") 0 of
146 SOME ("a \<up> 2 ist_monom = True", _) => ()
147 | _ => error "polyminus.sml: a \<up> 2 ist_monom = True";
149 case eval_ist_monom 0 0 (TermC.str2term "(3*a \<up> 2) ist_monom") 0 of
150 SOME ("3 * a \<up> 2 ist_monom = True", _) => ()
151 | _ => error "polyminus.sml: 3*a \<up> 2 ist_monom = True";
153 case eval_ist_monom 0 0 (TermC.str2term "(a*b) ist_monom") 0 of
154 SOME ("a * b ist_monom = True", _) => ()
155 | _ => error "polyminus.sml: a*b ist_monom = True";
157 case eval_ist_monom 0 0 (TermC.str2term "(3*a*b) ist_monom") 0 of
158 SOME ("3 * a * b ist_monom = True", _) => ()
159 | _ => error "polyminus.sml: 3*a*b ist_monom = True";
162 "----------- watch order_add_mult -------------------------------";
163 "----------- watch order_add_mult -------------------------------";
164 "----------- watch order_add_mult -------------------------------";
165 "----- with these simple variables it works...";
166 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
167 Rewrite.trace_on:=false; (*true false*)
168 val t = TermC.str2term "((a + d) + c) + b";
169 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
170 if UnparseC.term t = "a + (b + (c + d))" then ()
171 else error "polyminus.sml 1 watch order_add_mult";
172 Rewrite.trace_on:=false; (*true false*)
174 "----- the same stepwise...";
175 val od = ord_make_polynomial true (@{theory "Poly"});
176 val t = TermC.str2term "((a + d) + c) + b";
178 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
180 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
182 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
184 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
186 if UnparseC.term t = "a + (b + (c + d))" then ()
187 else error "polyminus.sml 2 watch order_add_mult";
189 "----- if parentheses are right, left_commute is (almost) sufficient...";
190 val t = TermC.str2term "a + (d + (c + b))";
192 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
194 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t;UnparseC.term t;
196 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
199 "----- but we do not want the parentheses at right; thus: cond.rew.";
200 "WN0712707 complicated monomials do not yet work ...";
201 val t = TermC.str2term "((5*a + 4*d) + 3*c) + 2*b";
202 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
203 if UnparseC.term t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
204 else error "polyminus.sml: order_add_mult changed";
206 "----- here we see rew_sub going into subterm with ord.rew....";
207 val od = ord_make_polynomial false (@{theory "Poly"});
208 val t = TermC.str2term "b + a + c + d";
209 val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
210 val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
211 (*@@@ rew_sub gosub: t = d + (b + a + c)
212 @@@ rew_sub begin: t = b + a + c*)
215 "----------- build predicate for +- ordering ---------------------";
216 "----------- build predicate for +- ordering ---------------------";
217 "----------- build predicate for +- ordering ---------------------";
220 "123" < "a"; (*unused due to ---vvv*)
221 "12" < "3"; (*true !!!*)
223 " a kleiner b ==> (b + a) = (a + b)";
224 TermC.str2term "aaa";
225 TermC.str2term "222 * aaa";
227 case eval_kleiner 0 0 (TermC.str2term "123 kleiner 32") 0 of
228 SOME ("123 kleiner 32 = False", _) => ()
229 | _ => error "polyminus.sml: 12 kleiner 9 = False";
231 case eval_kleiner 0 0 (TermC.str2term "a kleiner b") 0 of
232 SOME ("a kleiner b = True", _) => ()
233 | _ => error "polyminus.sml: a kleiner b = True";
235 case eval_kleiner 0 0 (TermC.str2term "(10*g) kleiner f") 0 of
236 SOME ("10 * g kleiner f = False", _) => ()
237 | _ => error "polyminus.sml: 10 * g kleiner f = False";
239 case eval_kleiner 0 0 (TermC.str2term "(a \<up> 2) kleiner b") 0 of
240 SOME ("a \<up> 2 kleiner b = True", _) => ()
241 | _ => error "polyminus.sml: a \<up> 2 kleiner b = True";
243 case eval_kleiner 0 0 (TermC.str2term "(3*a \<up> 2) kleiner b") 0 of
244 SOME ("3 * a \<up> 2 kleiner b = True", _) => ()
245 | _ => error "polyminus.sml: 3 * a \<up> 2 kleiner b = True";
247 case eval_kleiner 0 0 (TermC.str2term "(a*b) kleiner c") 0 of
248 SOME ("a * b kleiner c = True", _) => ()
249 | _ => error "polyminus.sml: a * b kleiner b = True";
251 case eval_kleiner 0 0 (TermC.str2term "(3*a*b) kleiner c") 0 of
252 SOME ("3 * a * b kleiner c = True", _) => ()
253 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
255 "======= compare tausche_plus with real_num_collect";
258 val erls = erls_ordne_alphabetisch;
259 val t = TermC.str2term "b + a";
260 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
261 if UnparseC.term t = "a + b" then ()
262 else error "polyminus.sml: ordne_alphabetisch1 b + a";
264 val erls = Atools_erls;
265 val t = TermC.str2term "2*a + 3*a";
266 val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; UnparseC.term t;
268 "======= test rewrite_, rewrite_set_";
269 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
270 val erls = erls_ordne_alphabetisch;
271 val t = TermC.str2term "b + a";
272 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
273 if UnparseC.term t = "a + b" then ()
274 else error "polyminus.sml: ordne_alphabetisch a + b";
276 val t = TermC.str2term "2*b + a";
277 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
278 if UnparseC.term t = "a + 2 * b" then ()
279 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
281 val t = TermC.str2term "a + c + b";
282 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
283 if UnparseC.term t = "a + b + c" then ()
284 else error "polyminus.sml: ordne_alphabetisch a + b + c";
286 "======= rewrite goes into subterms";
287 val t = TermC.str2term "a + c + b + d ::real";
288 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; UnparseC.term t;
289 if UnparseC.term t = "a + b + c + d" then ()
290 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
292 val t = TermC.str2term "a + c + d + b";
293 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
294 if UnparseC.term t = "a + b + c + d" then ()
295 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
297 "======= here we see rew_sub going into subterm with cond.rew....";
298 val t = TermC.str2term "b + a + c + d";
299 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
300 if UnparseC.term t = "a + b + c + d" then ()
301 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
303 "======= compile rls for the most complicated terms";
304 val t = TermC.str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
305 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
306 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t;
307 if UnparseC.term t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
308 then () else error "polyminus.sml: ordne_alphabetisch finished";
311 "----------- build fasse_zusammen --------------------------------";
312 "----------- build fasse_zusammen --------------------------------";
313 "----------- build fasse_zusammen --------------------------------";
314 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
315 val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
316 if UnparseC.term t = "3 + - 2 * e + 2 * f + 2 * g" then ()
317 else error "polyminus.sml: fasse_zusammen finished";
319 "----------- build verschoenere ----------------------------------";
320 "----------- build verschoenere ----------------------------------";
321 "----------- build verschoenere ----------------------------------";
322 val t = TermC.str2term "3 + - 2 * e + 2 * f + 2 * g";
323 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
324 if UnparseC.term t = "3 - 2 * e + 2 * f + 2 * g" then ()
325 else error "polyminus.sml: verschoenere 3 + - 2 * e ...";
327 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
328 Rewrite.trace_on:=false; (*true false*)
330 "----------- met simplification for_polynomials with_minus -------";
331 "----------- met simplification for_polynomials with_minus -------";
332 "----------- met simplification for_polynomials with_minus -------";
334 "Program SimplifyScript (t_t::real) = \
335 \ (((Try (Rewrite_Set ordne_alphabetisch False)) #> \
336 \ (Try (Rewrite_Set fasse_zusammen False)) #> \
337 \ (Try (Rewrite_Set verschoenere False))) t_t)"
338 val sc = (inst_abs o Thm.term_of o the o (TermC.parse thy)) str;
341 "----------- me simplification.for_polynomials.with_minus";
342 "----------- me simplification.for_polynomials.with_minus";
343 "----------- me simplification.for_polynomials.with_minus";
345 val (p,_,f,nxt,_,pt) =
347 [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
349 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
350 ["simplification", "for_polynomials", "with_minus"]))];
351 val (p,_,f,nxt,_,pt) = me nxt p c pt;
352 val (p,_,f,nxt,_,pt) = me nxt p c pt;
353 val (p,_,f,nxt,_,pt) = me nxt p c pt;
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;
358 val (p,_,f,nxt,_,pt) = me nxt p c pt;
359 f2str f = "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12"; (*isa == isa2*)
360 val (p''''',_,f,nxt''''',_,pt''''') = me nxt p c pt;
361 val (*^^^*) Rewrite_Set "ordne_alphabetisch" = nxt;
362 f2str f = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"; (*isa2*)
363 val (p,_,f,nxt,_,pt) = me nxt''''' p''''' c pt''''';
364 f2str f = "3 + - 2 * e + 2 * f + 2 * g"; (*isa2*)
365 val (p,_,f,nxt,_,pt) = me nxt p c pt;
366 f2str f = "3 - 2 * e + 2 * f + 2 * g"; (*isa2*)
367 val (p,_,f,nxt,_,pt) = me nxt p c pt;
368 f2str f = "3 - 2 * e + 2 * f + 2 * g"; (*isa2*)
369 if f2str f = "3 - 2 * e + 2 * f + 2 * g" (*isa2*)
370 then case nxt of End_Proof' => () | _ => error "me simplification.for_polynomials.with_minus 1"
371 else error "polyminus.sml: me simplification.for_polynomials.with_minus 2";
373 "----------- pbl polynom vereinfachen p.33 -----------------------";
374 "----------- pbl polynom vereinfachen p.33 -----------------------";
375 "----------- pbl polynom vereinfachen p.33 -----------------------";
376 "----------- 140 c ---";
378 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
380 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
381 ["simplification", "for_polynomials", "with_minus"]))];
383 autoCalculate 1 CompleteCalc;
384 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
385 if p = ([], Res) andalso
386 UnparseC.term (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
387 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
391 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
393 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
394 ["simplification", "for_polynomials", "with_minus"]))];
396 autoCalculate 1 CompleteCalc;
397 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
398 if p = ([], Res) andalso
399 UnparseC.term (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
400 then () else error "polyminus.sml: Vereinfache 140 d)";
404 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
406 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
407 ["simplification", "for_polynomials", "with_minus"]))];
409 autoCalculate 1 CompleteCalc;
410 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
411 if p = ([], Res) andalso
412 UnparseC.term (get_obj g_res pt (fst p)) = "- (3 * f)"
413 then () else error "polyminus.sml: Vereinfache 139 c)";
417 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
419 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
420 ["simplification", "for_polynomials", "with_minus"]))];
422 autoCalculate 1 CompleteCalc;
423 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
424 if p = ([], Res) andalso
425 UnparseC.term (get_obj g_res pt (fst p)) = "- 3 * u - v"
426 then () else error "polyminus.sml: Vereinfache 139 b)";
430 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
432 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
433 ["simplification", "for_polynomials", "with_minus"]))];
435 autoCalculate 1 CompleteCalc;
436 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
437 if p = ([], Res) andalso
438 UnparseC.term (get_obj g_res pt (fst p)) = "- 4 * u + 2 * v"
439 then () else error "polyminus.sml: Vereinfache 138 a)";
441 "----------- met probe fuer_polynom ------------------------------";
442 "----------- met probe fuer_polynom ------------------------------";
443 "----------- met probe fuer_polynom ------------------------------";
445 "Program ProbeScript (e_e::bool) (w_s::bool list) =\
446 \ (let e_e = Take e_e; \
447 \ e_e = Substitute w_s e_e \
448 \ in (Repeat((Try (Repeat (Calculate ''TIMES''))) #> \
449 \ (Try (Repeat (Calculate ''PLUS''))) #> \
450 \ (Try (Repeat (Calculate ''MINUS''))))) e_e)"
451 val sc = (inst_abs o Thm.term_of o the o (TermC.parse thy)) str;
454 "----------- pbl polynom probe -----------------------------------";
455 "----------- pbl polynom probe -----------------------------------";
456 "----------- pbl polynom probe -----------------------------------";
458 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
459 \3 - 2 * e + 2 * f + 2 * (g::int))",
460 "mitWert [e = (1::int), f = (2::int), g = (3::int)]",
462 ("PolyMinus",["polynom", "probe"],
463 ["probe", "fuer_polynom"]))];
465 autoCalculate 1 CompleteCalc;
466 (* autoCalculate 1 CompleteCalcHead;
467 autoCalculate 1 (Steps 1);
468 autoCalculate 1 (Steps 1);
469 val ((pt,p),_) = get_calc 1; UnparseC.term (get_obj g_res pt (fst p));
470 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
471 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
472 val ((pt,p),_) = get_calc 1;
473 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "11 = 11"
474 then () else error "polyminus.sml: Probe 11 = 11";
475 Test_Tool.show_pt pt;
477 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
478 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
479 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
481 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
483 ("PolyMinus",["klammer", "polynom", "vereinfachen"],
484 ["simplification", "for_polynomials", "with_parentheses"]))];
486 autoCalculate 1 CompleteCalc;
487 val ((pt,p),_) = get_calc 1;
488 if p = ([], Res) andalso
489 UnparseC.term (get_obj g_res pt (fst p)) = "1 + 14 * u"
490 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
491 Test_Tool.show_pt pt;
493 "======= probe p.34 -----";
495 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * (u::int))",
496 "mitWert [u = (2::int)]",
498 ("PolyMinus",["polynom", "probe"],
499 ["probe", "fuer_polynom"]))];
501 autoCalculate 1 CompleteCalc;
502 val ((pt,p),_) = get_calc 1;
503 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "29 = 29"
504 then () else error "polyminus.sml: Probe 29 = 29";
505 Test_Tool.show_pt pt;
507 "----------- try fun applyTactics --------------------------------";
508 "----------- try fun applyTactics --------------------------------";
509 "----------- try fun applyTactics --------------------------------";
511 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
513 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
514 ["simplification", "for_polynomials", "with_minus"]))];
516 autoCalculate 1 CompleteCalcHead;
517 autoCalculate 1 (Steps 1);
518 autoCalculate 1 (Steps 1);
519 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
521 fetchApplicableTactics 1 0 p;
522 val appltacs = specific_from_prog pt p;
523 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
524 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
526 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
527 val erls = erls_ordne_alphabetisch;
528 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
530 rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus} t;
531 UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
533 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
535 rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
537 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
539 rewrite_set_ (@{theory "Isac_Knowledge"}) false ordne_alphabetisch t;
540 UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
541 Rewrite.trace_on := false; (*true false*)
544 applyTactic 1 p (hd (specific_from_prog pt p)) (*tausche_minus*);
545 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
547 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
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;
557 (*<CALCMESSAGE> failure </CALCMESSAGE>
558 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
559 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
562 autoCalculate 1 CompleteCalc;
563 val ((pt,p),_) = 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 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
570 "#############################################################################";
572 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
574 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
575 ["simplification", "for_polynomials", "with_minus"]))];
577 autoCalculate 1 CompleteCalc;
578 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
579 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "2 * g + h"
580 then () else error "polyminus.sml: addiere_vor_minus";
583 "#############################################################################";
585 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
587 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
588 ["simplification", "for_polynomials", "with_minus"]))];
590 autoCalculate 1 CompleteCalc;
591 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
592 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "f + 2 * g"
593 then () else error "polyminus.sml: tausche_vor_plus";
595 "----------- pbl binom polynom vereinfachen p.39 -----------------";
596 "----------- pbl binom polynom vereinfachen p.39 -----------------";
597 "----------- pbl binom polynom vereinfachen p.39 -----------------";
598 val rls = klammern_ausmultiplizieren;
599 val t = TermC.str2term "(3 * a + 2) * (4 * a - 1)";
600 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
601 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
602 val rls = discard_parentheses;
603 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
604 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
605 val rls = ordne_monome;
606 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
607 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
609 val t = TermC.str2term "3 * a * 4 * a";
610 val rls = ordne_monome;
611 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
613 val rls = klammern_aufloesen;
614 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
615 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
616 val rls = ordne_alphabetisch;
617 (*TODO: make is_monom more general, a*a=a^2, ...*)
618 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
619 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
621 val rls = fasse_zusammen;
622 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
623 val rls = verschoenere;
624 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
629 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
631 ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
632 ["simplification", "for_polynomials", "with_parentheses_mult"]))];
634 autoCalculate 1 CompleteCalc;
635 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
637 if p = ([], Res) andalso
638 UnparseC.term (get_obj g_res pt (fst p)) =(*"- 2 + 12 * a \<up> 2 + 5 * a" with OLD numerals*)
639 "- 2 + 5 * a + 12 * a \<up> 2"
640 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
642 "----------- pbl binom polynom vereinfachen: cube ----------------";
643 "----------- pbl binom polynom vereinfachen: cube ----------------";
644 "----------- pbl binom polynom vereinfachen: cube ----------------";
646 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
647 ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
648 ["simplification", "for_polynomials", "with_parentheses_mult"]))];
650 autoCalculate 1 CompleteCalc;
651 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
652 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "12 * a - 16 * q"
653 then () else error "pbl binom polynom vereinfachen: cube";
655 "----------- Refine.refine Vereinfache ----------------------------------";
656 "----------- Refine.refine Vereinfache ----------------------------------";
657 "----------- Refine.refine Vereinfache ----------------------------------";
658 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"];
659 (*default_print_depth 11;*)
660 val matches = Refine.refine fmz ["vereinfachen"];
661 (*default_print_depth 3;*)
663 "----- go into details, if it seems not to work -----";
664 "--- does the predicate evaluate correctly ?";
665 val t = TermC.str2term
666 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))";
667 val ma = eval_matchsub "" "Prog_Expr.matchsub" t thy;
669 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
670 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
671 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
673 "--- does the respective prls rewrite ?";
674 val prls = Rule_Set.append_rules "prls_pbl_vereinf_poly" Rule_Set.empty
675 [Eval ("Poly.is_polyexp", eval_is_polyexp ""),
676 Eval ("Prog_Expr.matchsub", eval_matchsub ""),
677 Thm ("or_true",@{thm or_true}),
678 (*"(?a | True) = True"*)
679 Thm ("or_false",@{thm or_false}),
680 (*"(?a | False) = ?a"*)
681 Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
682 (*"(~ True) = False"*)
683 Thm ("not_false",ThmC.numerals_to_Free @{thm not_false})
684 (*"(~ False) = True"*)];
685 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
686 val SOME (t', _) = rewrite_set_ thy false prls t;
687 Rewrite.trace_on := false; (*true false*)
689 "--- does the respective prls rewrite the whole predicate ?";
690 val t = TermC.str2term
691 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
692 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
693 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
694 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
695 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
696 val SOME (t', _) = rewrite_set_ thy false prls t;
697 Rewrite.trace_on := false; (*true false*)
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";