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
40 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g ::real") = "|||||||||||||"
41 then () else error "identifier 1a";
43 if identifier (TermC.str2term "a ::real") = "a" then () else error "identifier 2";
44 if identifier (TermC.str2term "3 * a ::real") = "a" then () else error "identifier 3";
46 if identifier (TermC.str2term "a \<up> 2 ::real") = "a" then () else error "identifier 4";
47 if identifier (TermC.str2term "3*a \<up> 2 ::real") = "a" then () else error "identifier 5";
48 if identifier (TermC.str2term "a * b ::real") = "b" then () else error "identifier 5b";
50 (*these are strange (see "specific monomials" in comment to fun.def.)..*)
51 if identifier (TermC.str2term "a*b ::real") = "b" then () else error "identifier 6";
52 if identifier (TermC.str2term "(3*a*b) ::real") = "b" then () else error "identifier 7";
55 "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
56 "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
57 "----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
60 "123" < "a"; (*unused due to ---vvv*)
61 "12" < "3"; (*true !!!*)
63 " a kleiner b ==> (b + a) = (a + b)";
65 TermC.str2term "222 * aaa";
67 case eval_kleiner 0 0 (TermC.str2term "123 kleiner 32") 0 of
68 SOME ("123 kleiner 32 = False", _) => ()
69 | _ => error "polyminus.sml: 12 kleiner 9 = False";
70 case eval_kleiner 0 0 (TermC.str2term "a kleiner b") 0 of
71 SOME ("a kleiner b = True", _) => ()
72 | _ => error "polyminus.sml: a kleiner b = True";
73 case eval_kleiner 0 0 (TermC.str2term "(10*g) kleiner f") 0 of
74 SOME ("10 * g kleiner f = False", _) => ()
75 | _ => error "polyminus.sml: 10 * g kleiner f = False";
76 case eval_kleiner 0 0 (TermC.str2term "(a \<up> 2) kleiner b") 0 of
77 SOME ("a \<up> 2 kleiner b = True", _) => ()
78 | _ => error "polyminus.sml: a \<up> 2 kleiner b = True";
79 case eval_kleiner 0 0 (TermC.str2term "(3*a \<up> 2) kleiner b") 0 of
80 SOME ("3 * a \<up> 2 kleiner b = True", _) => ()
81 | _ => error "polyminus.sml: 3 * a \<up> 2 kleiner b = True";
82 case eval_kleiner 0 0 (TermC.str2term "(a*b) kleiner c") 0 of
83 SOME ("a * b kleiner c = True", _) => ()
84 | _ => error "polyminus.sml: a * b kleiner b = True";
85 case eval_kleiner 0 0 (TermC.str2term "(3*a*b) kleiner c") 0 of
86 SOME ("3 * a * b kleiner c = True", _) => ()
87 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
90 val t = TermC.str2term "12 kleiner 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * (g::real)";
91 val SOME ("12 kleiner 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g = True", _) =
92 eval_kleiner "aaa" "bbb" t "ccc";
93 "~~~~~ fun eval_kleiner , args:"; val (_, _, (p as (Const (\<^const_name>\<open>kleiner\<close>,_) $ a $ b)), _) =
94 ("aaa", "bbb", t, "ccc");
95 (*if*) TermC.is_num b (*else*);
97 (*if*) identifier a < identifier b (*else*);
98 "~~~~~ fun identifier , args:"; val (t) = (a);
100 Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $
101 (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ (Const (\<^const_name>\<open>num.Bit1\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _)))) => ()
102 | _ => error "eval_kleiner CHANGED"; (*isa*)
105 "----------- fun ist_monom ---------------------------------------------------------------------";
106 "----------- fun ist_monom ---------------------------------------------------------------------";
107 "----------- fun ist_monom ---------------------------------------------------------------------";
108 val t = TermC.str2term "0 ::real";
109 if ist_monom t then () else error "ist_monom 1";
111 val t = TermC.str2term "a";
112 if ist_monom t then () else error "ist_monom 2";
114 val t = TermC.str2term "2 * a";
115 if ist_monom t then () else error "ist_monom 3";
117 val t = TermC.str2term "2 * a * b";
118 if ist_monom t then () else error "ist_monom 4";
120 val t = TermC.str2term "a * b";
121 if ist_monom t then () else error "ist_monom 5";
123 (*not covered before NEW numerals*)
124 val t = TermC.str2term "2 * a \<up> 2 * b";
125 if ist_monom t then () else error "ist_monom 6";
127 (*not covered before NEW numerals*)
128 val t = TermC.str2term "a \<up> 2 * b \<up> 3";
129 if ist_monom t then () else error "ist_monom 7";
131 val t = TermC.str2term "a \<up> 2 * 4 * b \<up> 3 * 5";
132 if ist_monom t then () else error "ist_monom 8";
135 "----------- fun eval_ist_monom ----------------------------------";
136 "----------- fun eval_ist_monom ----------------------------------";
137 "----------- fun eval_ist_monom ----------------------------------";
138 case eval_ist_monom 0 0 (TermC.str2term "12 ist_monom") 0 of
139 SOME ("12 ist_monom = True", _) => ()
140 | _ => error "polyminus.sml: 12 ist_monom = True";
142 case eval_ist_monom 0 0 (TermC.str2term "a ist_monom") 0 of
143 SOME ("a ist_monom = True", _) => ()
144 | _ => error "polyminus.sml: a ist_monom = True";
146 case eval_ist_monom 0 0 (TermC.str2term "(3*a) ist_monom") 0 of
147 SOME ("3 * a ist_monom = True", _) => ()
148 | _ => error "polyminus.sml: 3 * a ist_monom = True";
150 case eval_ist_monom 0 0 (TermC.str2term "(a \<up> 2) ist_monom") 0 of
151 SOME ("a \<up> 2 ist_monom = True", _) => ()
152 | _ => error "polyminus.sml: a \<up> 2 ist_monom = True";
154 case eval_ist_monom 0 0 (TermC.str2term "(3*a \<up> 2) ist_monom") 0 of
155 SOME ("3 * a \<up> 2 ist_monom = True", _) => ()
156 | _ => error "polyminus.sml: 3*a \<up> 2 ist_monom = True";
158 case eval_ist_monom 0 0 (TermC.str2term "(a*b) ist_monom") 0 of
159 SOME ("a * b ist_monom = True", _) => ()
160 | _ => error "polyminus.sml: a*b ist_monom = True";
162 case eval_ist_monom 0 0 (TermC.str2term "(3*a*b) ist_monom") 0 of
163 SOME ("3 * a * b ist_monom = True", _) => ()
164 | _ => error "polyminus.sml: 3*a*b ist_monom = True";
167 "----------- watch order_add_mult -------------------------------";
168 "----------- watch order_add_mult -------------------------------";
169 "----------- watch order_add_mult -------------------------------";
170 "----- with these simple variables it works...";
171 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
172 Rewrite.trace_on:=false; (*true false*)
173 val t = TermC.str2term "((a + d) + c) + b";
174 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
175 if UnparseC.term t = "a + (b + (c + d))" then ()
176 else error "polyminus.sml 1 watch order_add_mult";
177 Rewrite.trace_on:=false; (*true false*)
179 "----- the same stepwise...";
180 val od = ord_make_polynomial true (@{theory "Poly"});
181 val t = TermC.str2term "((a + d) + c) + b";
183 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
185 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
187 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
189 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
191 if UnparseC.term t = "a + (b + (c + d))" then ()
192 else error "polyminus.sml 2 watch order_add_mult";
194 "----- if parentheses are right, left_commute is (almost) sufficient...";
195 val t = TermC.str2term "a + (d + (c + b))";
197 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
199 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t;UnparseC.term t;
201 val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
204 "----- but we do not want the parentheses at right; thus: cond.rew.";
205 "WN0712707 complicated monomials do not yet work ...";
206 val t = TermC.str2term "((5*a + 4*d) + 3*c) + 2*b";
207 val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
208 if UnparseC.term t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
209 else error "polyminus.sml: order_add_mult changed";
211 "----- here we see rew_sub going into subterm with ord.rew....";
212 val od = ord_make_polynomial false (@{theory "Poly"});
213 val t = TermC.str2term "b + a + c + d";
214 val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
215 val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
216 (*@@@ rew_sub gosub: t = d + (b + a + c)
217 @@@ rew_sub begin: t = b + a + c*)
220 "----------- build predicate for +- ordering ---------------------";
221 "----------- build predicate for +- ordering ---------------------";
222 "----------- build predicate for +- ordering ---------------------";
225 "123" < "a"; (*unused due to ---vvv*)
226 "12" < "3"; (*true !!!*)
228 " a kleiner b ==> (b + a) = (a + b)";
229 TermC.str2term "aaa";
230 TermC.str2term "222 * aaa";
232 case eval_kleiner 0 0 (TermC.str2term "123 kleiner 32") 0 of
233 SOME ("123 kleiner 32 = False", _) => ()
234 | _ => error "polyminus.sml: 12 kleiner 9 = False";
236 case eval_kleiner 0 0 (TermC.str2term "a kleiner b") 0 of
237 SOME ("a kleiner b = True", _) => ()
238 | _ => error "polyminus.sml: a kleiner b = True";
240 case eval_kleiner 0 0 (TermC.str2term "(10*g) kleiner f") 0 of
241 SOME ("10 * g kleiner f = False", _) => ()
242 | _ => error "polyminus.sml: 10 * g kleiner f = False";
244 (** )//-----------TOODOO broken with merge after "eliminate ThmC.numerals_to_Free"--------\\( ** )
245 (*TOODOO eval_kleiner 0 0 (TermC.str2term "(a \<up> 2) kleiner b") 0 \<longrightarrow> False*)
246 case eval_kleiner 0 0 (TermC.str2term "(a \<up> 2) kleiner b") 0 of
247 SOME ("a \<up> 2 kleiner b = True", _) => ()
248 | _ => error "polyminus.sml: a \<up> 2 kleiner b = True";
250 case eval_kleiner 0 0 (TermC.str2term "(3*a \<up> 2) kleiner b") 0 of
251 SOME ("3 * a \<up> 2 kleiner b = True", _) => ()
252 | _ => error "polyminus.sml: 3 * a \<up> 2 kleiner b = True";
253 ( ** )\\-----------TOODOO broken with merge after "eliminate ThmC.numerals_to_Free"--------//( **)
255 case eval_kleiner 0 0 (TermC.str2term "(a*b) kleiner c") 0 of
256 SOME ("a * b kleiner c = True", _) => ()
257 | _ => error "polyminus.sml: a * b kleiner b = True";
259 case eval_kleiner 0 0 (TermC.str2term "(3*a*b) kleiner c") 0 of
260 SOME ("3 * a * b kleiner c = True", _) => ()
261 | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
263 "======= compare tausche_plus with real_num_collect";
266 val erls = erls_ordne_alphabetisch;
267 val t = TermC.str2term "b + a";
268 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
269 if UnparseC.term t = "a + b" then ()
270 else error "polyminus.sml: ordne_alphabetisch1 b + a";
272 val erls = Atools_erls;
273 val t = TermC.str2term "2*a + 3*a";
274 val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; UnparseC.term t;
276 "======= test rewrite_, rewrite_set_";
277 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
278 val erls = erls_ordne_alphabetisch;
279 val t = TermC.str2term "b + a";
280 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
281 if UnparseC.term t = "a + b" then ()
282 else error "polyminus.sml: ordne_alphabetisch a + b";
284 val t = TermC.str2term "2*b + a";
285 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
286 if UnparseC.term t = "a + 2 * b" then ()
287 else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
289 val t = TermC.str2term "a + c + b";
290 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
291 if UnparseC.term t = "a + b + c" then ()
292 else error "polyminus.sml: ordne_alphabetisch a + b + c";
294 "======= rewrite goes into subterms";
295 val t = TermC.str2term "a + c + b + d ::real";
296 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; UnparseC.term t;
297 if UnparseC.term t = "a + b + c + d" then ()
298 else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
300 val t = TermC.str2term "a + c + d + b";
301 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
302 if UnparseC.term t = "a + b + c + d" then ()
303 else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
305 "======= here we see rew_sub going into subterm with cond.rew....";
306 val t = TermC.str2term "b + a + c + d";
307 val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
308 if UnparseC.term t = "a + b + c + d" then ()
309 else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
311 (** )//-----------TOODOO broken with merge after "eliminate ThmC.numerals_to_Free"--------\\( ** )
312 "======= compile rls for the most complicated terms";
313 val t = TermC.str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
314 "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
315 val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t;
316 if UnparseC.term t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
317 then () else error "polyminus.sml: ordne_alphabetisch finished";
318 ( ** )\\-----------TOODOO broken with merge after "eliminate ThmC.numerals_to_Free"--------//( **)
321 "----------- build fasse_zusammen --------------------------------";
322 "----------- build fasse_zusammen --------------------------------";
323 "----------- build fasse_zusammen --------------------------------";
324 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
325 val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
326 if UnparseC.term t = "3 + - 2 * e + 2 * f + 2 * g" then ()
327 else error "polyminus.sml: fasse_zusammen finished";
329 "----------- build verschoenere ----------------------------------";
330 "----------- build verschoenere ----------------------------------";
331 "----------- build verschoenere ----------------------------------";
332 val t = TermC.str2term "3 + - 2 * e + 2 * f + 2 * g";
333 val SOME (t,_) = rewrite_set_ thy false verschoenere t;
334 if UnparseC.term t = "3 - 2 * e + 2 * f + 2 * g" then ()
335 else error "polyminus.sml: verschoenere 3 + - 2 * e ...";
337 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
338 Rewrite.trace_on:=false; (*true false*)
340 "----------- met simplification for_polynomials with_minus -------";
341 "----------- met simplification for_polynomials with_minus -------";
342 "----------- met simplification for_polynomials with_minus -------";
344 "Program SimplifyScript (t_t::real) = \
345 \ (((Try (Rewrite_Set ordne_alphabetisch False)) #> \
346 \ (Try (Rewrite_Set fasse_zusammen False)) #> \
347 \ (Try (Rewrite_Set verschoenere False))) t_t)"
348 val sc = (inst_abs o Thm.term_of o the o (TermC.parse thy)) str;
351 "----------- me simplification.for_polynomials.with_minus";
352 "----------- me simplification.for_polynomials.with_minus";
353 "----------- me simplification.for_polynomials.with_minus";
355 val (p,_,f,nxt,_,pt) =
357 [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
359 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
360 ["simplification", "for_polynomials", "with_minus"]))];
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 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 val (p,_,f,nxt,_,pt) = me nxt p c pt;
371 val (p,_,f,nxt,_,pt) = me nxt p c pt;
372 val (p,_,f,nxt,_,pt) = me nxt p c pt;
373 if f2str f = "3 - 2 * e + 2 * f + 2 * g"
374 then case nxt of End_Proof' => () | _ => error "me simplification.for_polynomials.with_minus 1"
375 else error "polyminus.sml: me simplification.for_polynomials.with_minus 2";
377 "----------- pbl polynom vereinfachen p.33 -----------------------";
378 "----------- pbl polynom vereinfachen p.33 -----------------------";
379 "----------- pbl polynom vereinfachen p.33 -----------------------";
380 "----------- 140 c ---";
382 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
384 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
385 ["simplification", "for_polynomials", "with_minus"]))];
387 autoCalculate 1 CompleteCalc;
388 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
389 if p = ([], Res) andalso
390 UnparseC.term (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
391 then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
395 CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
397 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
398 ["simplification", "for_polynomials", "with_minus"]))];
400 autoCalculate 1 CompleteCalc;
401 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
402 if p = ([], Res) andalso
403 UnparseC.term (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
404 then () else error "polyminus.sml: Vereinfache 140 d)";
408 CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
410 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
411 ["simplification", "for_polynomials", "with_minus"]))];
413 autoCalculate 1 CompleteCalc;
414 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
415 if p = ([], Res) andalso
416 UnparseC.term (get_obj g_res pt (fst p)) = "- (3 * f)"
417 then () else error "polyminus.sml: Vereinfache 139 c)";
421 CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
423 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
424 ["simplification", "for_polynomials", "with_minus"]))];
426 autoCalculate 1 CompleteCalc;
427 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
428 if p = ([], Res) andalso
429 UnparseC.term (get_obj g_res pt (fst p)) = "- 3 * u - v"
430 then () else error "polyminus.sml: Vereinfache 139 b)";
434 CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
436 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
437 ["simplification", "for_polynomials", "with_minus"]))];
439 autoCalculate 1 CompleteCalc;
440 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
441 if p = ([], Res) andalso
442 UnparseC.term (get_obj g_res pt (fst p)) = "- 4 * u + 2 * v"
443 then () else error "polyminus.sml: Vereinfache 138 a)";
445 "----------- met probe fuer_polynom ------------------------------";
446 "----------- met probe fuer_polynom ------------------------------";
447 "----------- met probe fuer_polynom ------------------------------";
449 "Program ProbeScript (e_e::bool) (w_s::bool list) =\
450 \ (let e_e = Take e_e; \
451 \ e_e = Substitute w_s e_e \
452 \ in (Repeat((Try (Repeat (Calculate ''TIMES''))) #> \
453 \ (Try (Repeat (Calculate ''PLUS''))) #> \
454 \ (Try (Repeat (Calculate ''MINUS''))))) e_e)"
455 val sc = (inst_abs o Thm.term_of o the o (TermC.parse thy)) str;
458 "----------- pbl polynom probe -----------------------------------";
459 "----------- pbl polynom probe -----------------------------------";
460 "----------- pbl polynom probe -----------------------------------";
462 CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
463 \3 - 2 * e + 2 * f + 2 * (g::int))",
464 "mitWert [e = (1::int), f = (2::int), g = (3::int)]",
466 ("PolyMinus",["polynom", "probe"],
467 ["probe", "fuer_polynom"]))];
469 autoCalculate 1 CompleteCalc;
470 (* autoCalculate 1 CompleteCalcHead;
471 autoCalculate 1 (Steps 1);
472 autoCalculate 1 (Steps 1);
473 val ((pt,p),_) = get_calc 1; UnparseC.term (get_obj g_res pt (fst p));
474 @@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
475 although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
476 val ((pt,p),_) = get_calc 1;
477 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "11 = 11"
478 then () else error "polyminus.sml: Probe 11 = 11";
479 Test_Tool.show_pt pt;
481 (** )//-----------TOODOO broken with merge after "eliminate ThmC.numerals_to_Free"--------\\( ** )
482 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
483 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
484 "----------- pbl klammer polynom vereinfachen p.34 ---------------";
486 CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
488 ("PolyMinus",["klammer", "polynom", "vereinfachen"],
489 ["simplification", "for_polynomials", "with_parentheses"]))];
491 autoCalculate 1 CompleteCalc;
492 val ((pt,p),_) = get_calc 1;
493 if p = ([], Res) andalso
494 UnparseC.term (get_obj g_res pt (fst p)) = "1 + 14 * u"
495 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
496 Test_Tool.show_pt pt;
497 ( ** )\\-----------TOODOO broken with merge after "eliminate ThmC.numerals_to_Free"--------//( **)
499 "======= probe p.34 -----";
501 CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * (u::int))",
502 "mitWert [u = (2::int)]",
504 ("PolyMinus",["polynom", "probe"],
505 ["probe", "fuer_polynom"]))];
507 autoCalculate 1 CompleteCalc;
508 val ((pt,p),_) = get_calc 1;
509 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "29 = 29"
510 then () else error "polyminus.sml: Probe 29 = 29";
511 Test_Tool.show_pt pt;
513 (** )//-----------TOODOO broken with merge after "eliminate ThmC.numerals_to_Free"--------\\( ** )
514 "----------- try fun applyTactics --------------------------------";
515 "----------- try fun applyTactics --------------------------------";
516 "----------- try fun applyTactics --------------------------------";
518 CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
520 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
521 ["simplification", "for_polynomials", "with_minus"]))];
523 autoCalculate 1 CompleteCalcHead;
524 autoCalculate 1 (Steps 1);
525 autoCalculate 1 (Steps 1);
526 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
528 fetchApplicableTactics 1 0 p;
529 val appltacs = specific_from_prog pt p;
530 applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
531 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
533 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
534 val erls = erls_ordne_alphabetisch;
535 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
537 rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus} t;
538 UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
540 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
542 rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
544 val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
546 rewrite_set_ (@{theory "Isac_Knowledge"}) false ordne_alphabetisch t;
547 UnparseC.term t'; "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
548 Rewrite.trace_on := false; (*true false*)
551 applyTactic 1 p (hd (specific_from_prog pt p)) (*tausche_minus*);
552 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
554 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
555 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
557 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
558 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
560 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
561 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
564 (*<CALCMESSAGE> failure </CALCMESSAGE>
565 applyTactic 1 p (hd (specific_from_prog pt p)) (**);
566 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
569 autoCalculate 1 CompleteCalc;
570 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
571 (*independent from failure above: met_simp_poly_minus not confluent:
572 (([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
573 (([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
574 ~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
575 ( ** )\\-----------TOODOO broken with merge after "eliminate ThmC.numerals_to_Free"--------//( **)
578 "#############################################################################";
580 CalcTree [(["Term (- (8 * g) + 10 * g + h)",
582 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
583 ["simplification", "for_polynomials", "with_minus"]))];
585 autoCalculate 1 CompleteCalc;
586 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
587 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "2 * g + h"
588 then () else error "polyminus.sml: addiere_vor_minus";
591 "#############################################################################";
593 CalcTree [(["Term (- (8 * g) + 10 * g + f)",
595 ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
596 ["simplification", "for_polynomials", "with_minus"]))];
598 autoCalculate 1 CompleteCalc;
599 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
600 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "f + 2 * g"
601 then () else error "polyminus.sml: tausche_vor_plus";
603 "----------- pbl binom polynom vereinfachen p.39 -----------------";
604 "----------- pbl binom polynom vereinfachen p.39 -----------------";
605 "----------- pbl binom polynom vereinfachen p.39 -----------------";
607 val rls = klammern_ausmultiplizieren;
608 val t = TermC.str2term "(3 * a + 2) * (4 * a - 1::real)";
609 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
610 "3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
611 val rls = discard_parentheses;
612 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
613 "3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
614 val rls = ordne_monome;
615 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
616 "3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
618 val t = TermC.str2term "3 * a * 4 * a";
619 val rls = ordne_monome;
620 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
622 val rls = klammern_aufloesen;
623 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
624 "3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
625 val rls = ordne_alphabetisch;
626 (*TODO: make is_monom more general, a*a=a^2, ...*)
627 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
628 "3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
630 val rls = fasse_zusammen;
631 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
632 val rls = verschoenere;
633 val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
638 CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
640 ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
641 ["simplification", "for_polynomials", "with_parentheses_mult"]))];
643 autoCalculate 1 CompleteCalc;
644 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
646 UnparseC.term (get_obj g_res pt (fst p)) = "8 * a + 3 * a * 4 * a - 3 * a * 1 - 2";
647 (** )//-----------TOODOO broken with merge after "eliminate ThmC.numerals_to_Free"--------\\( ** )
648 if p = ([], Res) andalso
649 UnparseC.term (get_obj g_res pt (fst p)) =(*"- 2 + 12 * a \<up> 2 + 5 * a" with OLD numerals*)
650 "- 2 + 5 * a + 12 * a \<up> 2"
651 then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
652 ( ** )\\-----------TOODOO broken with merge after "eliminate ThmC.numerals_to_Free"--------//( **)
654 "----------- pbl binom polynom vereinfachen: cube ----------------";
655 "----------- pbl binom polynom vereinfachen: cube ----------------";
656 "----------- pbl binom polynom vereinfachen: cube ----------------";
658 CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
659 ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
660 ["simplification", "for_polynomials", "with_parentheses_mult"]))];
662 autoCalculate 1 CompleteCalc;
663 val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
664 if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "12 * a - 16 * q"
665 then () else error "pbl binom polynom vereinfachen: cube";
667 "----------- Refine.refine Vereinfache ----------------------------------";
668 "----------- Refine.refine Vereinfache ----------------------------------";
669 "----------- Refine.refine Vereinfache ----------------------------------";
670 val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"];
671 (*default_print_depth 11;*)
672 val matches = Refine.refine fmz ["vereinfachen"];
673 (*default_print_depth 3;*)
675 "----- go into details, if it seems not to work -----";
676 "--- does the predicate evaluate correctly ?";
677 val t = TermC.str2term
678 "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))";
679 val ma = eval_matchsub "" "Prog_Expr.matchsub" t thy;
681 SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
682 \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
683 | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
685 "--- does the respective prls rewrite ?";
686 val prls = Rule_Set.append_rules "prls_pbl_vereinf_poly" Rule_Set.empty
687 [Eval ("Poly.is_polyexp", eval_is_polyexp ""),
688 Eval ("Prog_Expr.matchsub", eval_matchsub ""),
689 Thm ("or_true",@{thm or_true}),
690 (*"(?a | True) = True"*)
691 Thm ("or_false",@{thm or_false}),
692 (*"(?a | False) = ?a"*)
693 Thm ("not_true", @{thm not_true}),
694 (*"(~ True) = False"*)
695 Thm ("not_false", @{thm not_false})
696 (*"(~ False) = True"*)];
697 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
698 val SOME (t', _) = rewrite_set_ thy false prls t;
699 Rewrite.trace_on := false; (*true false*)
701 "--- does the respective prls rewrite the whole predicate ?";
702 val t = TermC.str2term
703 "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
704 \ matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
705 \ matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
706 \ matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
707 (*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
708 val SOME (t', _) = rewrite_set_ thy false prls t;
709 Rewrite.trace_on := false; (*true false*)
710 if UnparseC.term t' = "False" then ()
711 else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
713 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
714 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
715 "----------- *** Problem.prep_input: syntax error in '#Where' of [v";
716 (*see test/../termC.sml for details*)
717 val t = TermC.parse_patt thy "t_t is_polyexp";
718 val t = TermC.parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
719 " matchsub (?a + (?b - ?c)) t_t | " ^
720 " matchsub (?a - (?b + ?c)) t_t | " ^
721 " matchsub (?a + (?b - ?c)) t_t )");
722 (*show_types := true;
723 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)"
724 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
725 show_types := false;*)
727 "\<not> (matchsub (?a + (?b + ?c)) t_t \<or>\n " ^
728 "matchsub (?a + (?b - ?c)) t_t \<or>\n " ^
729 "matchsub (?a - (?b + ?c)) t_t \<or> " ^
730 "matchsub (?a + (?b - ?c)) t_t)"
731 then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";