1 (* Title: tests for rationals
3 Copyright (c) Stefan Karnel 2002
4 Use is subject to license terms.
6 12345678901234567890123456789012345678901234567890123456789012345678901234567890
7 10 20 30 40 50 60 70 80
9 WN120317.TODO postponed test/../ratinal,ratinal2.sml to joint work with dmeind
11 nonterm.SK marks non-terminating examples
12 ord.SK PARTIALLY marks crucial ordering examples
13 *SK* of some (secondary) interest (on 070906)
14 WN060104 transfer examples marked with (*SR..*) to the exp-collection
17 (*========== inhibit exn WN130824 TODO =======================================================
18 "--------------------------------------------------------";
19 "--------------------------------------------------------";
20 "table of contents --------------------------------------";
21 "--------------------------------------------------------";
22 "~~~~~BEGIN: decomment structure RationalI : RATIONALI ~~";
23 "-------- ... missing WN060103 --------------------------";
24 "-------- fun monom2term, fun poly2term' ---------------";
25 "~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
26 "-------- fun poly_of_term ---------------------------------------------------";
27 "-------- fun is_poly --------------------------------------------------------";
28 "-------- fun term_of_poly ---------------------------------------------------";
29 "-------- and app_rev --------------------------------------------------------";
30 "-------- external calculating functions test -----------";
31 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
32 "-------- common_nominator_p ----------------------------";
33 "-------- reverse rewrite -------------------------------";
34 "-------- 'reverse-ruleset' cancel_p --------------------";
35 "-------- norm_Rational ---------------------------------";
36 "-------- numeral rationals -----------------------------";
37 "-------- cancellation ----------------------------------";
38 "-------- common denominator ----------------------------";
39 "-------- multiply and cancel ---------------------------";
40 "-------- common denominator and multiplication ---------";
41 "-------- double fractions ------------------------------";
42 "-------- crucial examples ------------------------------";
43 "-------- examples for Stefan Karnels thesis ------------";
44 "-------- me Schalk I No.186 ----------------------------";
45 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
46 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
47 "-------- investigate rulesets for cancel_p -------------";
48 "-------- investigate format of factout_ and factout_p_ -";
49 "-------- how to stepwise construct Scripts -------------";
50 "----------- get_denominator ----------------------------";
51 "--------- several errpats in complicated term -------------------";
52 "--------------------------------------------------------";
53 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
54 "--------------------------------------------------------";
55 "--------------------------------------------------------";
58 "~~~~~BEGIN: decomment structure RationalI : RATIONALI ~~";
59 (*.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60 tests of internal functions: to make them work,
61 out-comment (*!!!*) in knowledge/Rational.ML:
63 structure RationalI : RATIONALI =
70 !!!##*)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.*)
72 "-------- ... missing WN060103 --------------------------";
73 "-------- ... missing WN060103 --------------------------";
74 "-------- ... missing WN060103 --------------------------";
75 (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76 writeln ("********************* rational.sml - TESTS *************************");
77 writeln ("***** divide tests *****");
78 val mv_pquot1 = (#1(mv_division([(1,[1,1,1]),(1,[1,1,0]),(1,[1,0,1]),(1,[0,0,0])],[(1,[1,1,0]),(1,[0,0,0])],LEX_)));
79 (* result: [(1,[0,0,1]),(1,[0,0,0])] *)
80 if mv_pquot1=[(1,[0,0,1]),(1,[0,0,0])] then () else error ("rational.sml: example failed");
82 val mv_prest1 = (#2(mv_division([(1,[1,1,1]),(1,[1,1,0]),(1,[1,0,1]),(1,[0,0,0])],[(1,[1,1,0]),(1,[0,0,0])],LEX_)));
83 (* result: [(1,[1,0,1]),(~1,[0,0,1])] *)
84 if mv_prest1=[(1,[1,0,1]),(~1,[0,0,1])] then () else error ("rational.sml: example failed");
86 val mv_pquot2 = (#1(mv_division([(4,[2]),(8,[1]),(16,[0])],[(1,[1]),(1,[0])],LEX_)));
87 (* result: [(4,[1]),(4,[0])] *)
88 if mv_pquot2=[(4,[1]),(4,[0])] then () else error ("rational.sml: example failed");
90 val mv_prest2 = (#2(mv_division([(4,[2]),(8,[1]),(16,[0])],[(1,[1]),(1,[0])],LEX_)));
91 (* result: [(12,[0]] *)
92 if mv_prest2=[(12,[0])] then () else error ("rational.sml: example failed");
94 val mv_pquot3 = (#1(mv_division([(4,[2]),(~4,[0])],[(2,[1]),(2,[0])],LEX_)));
95 (* [(2,[1]),(~2,[0])] *)
96 if mv_pquot3=[(2,[1]),(~2,[0])] then () else error ("rational.sml: example failed");
98 val mv_prest3 = (#2(mv_division([(1,[2]),(~1,[0])],[(2,[1]),(2,[0])],LEX_)));
99 (* [(1,[2]),(~1,[0])] *)
100 if mv_prest3=[(1,[2]),(~1,[0])] then () else error ("rational.sml: example failed");
102 val mv_pquot4 = (#1(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1])],[(2,[1,0,0]),(4,[0,0,1])],LEX_)));
104 if mv_pquot4=[(1,[0,1,1])] then () else error ("rational.sml: example failed");
106 val mv_prest4 = (#2(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1])],[(2,[1,0,0]),(4,[0,0,1])],GGO_)));
107 (* [(1,[1,1,1]),(~4,[0,1,2]),(4,[1,0,1]),(3,[0,0,1])] *)
108 if mv_prest4 =[(1,[1,1,1]),(~4,[0,1,2]),(4,[1,0,1]),(3,[0,0,1])] then () else error ("rational.sml: example failed");
110 val mv_pquot5 = (#1(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1]),(6,[2,1,3]),(4,[0,4,1]),(1,[2,2,1])],[(1,[0,0,1])],LEX_)));
111 (* [(1,[2,2,0]),(6,[2,1,2]),(3,[1,1,0]),(4,[1,0,0]),(4,[0,4,0]),(3,[0,0,0])]*)
112 if mv_pquot5=[(1,[2,2,0]),(6,[2,1,2]),(3,[1,1,0]),(4,[1,0,0]),(4,[0,4,0]),(3,[0,0,0])] then () else error ("rational.sml: example failed");
114 val mv_prest5 = (#2(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1]),(6,[2,1,3]),(4,[0,4,1]),(1,[2,2,1])],[(1,[0,0,1])],LEX_)));
116 if mv_prest5=[] then () else error ("rational.sml: example failed");
118 (* (x^2 + 2(a+1)x + (a^2+2a+1)) / (x+a+1) = x+a+1 *)
119 val mv_pquot6 = (#1(mv_division([(1,[2,0,0]),(2,[1,1,0]),(2,[1,0,0]),(1,[0,2,0]),(2,[0,1,0]),(1,[0,0,0])],[(1,[1,0,0]),(1,[0,1,0]),(1,[0,0,0])],LEX_)));
120 if mv_pquot6=[(1,[1,0,0]),(1,[0,1,0]),(1,[0,0,0])] then () else error ("rational.sml: example failed");
122 val mv_prest6 = (#2(mv_division([(1,[2,0,0]),(2,[1,1,0]),(2,[1,0,0]),(1,[0,2,0]),(2,[0,1,0]),(1,[0,0,0])],[(1,[1,0,0]),(1,[0,1,0]),(1,[0,0,0])],LEX_)));
123 if mv_prest6=[] then () else error ("rational.sml: example failed");
126 writeln ("***** MV_CONTENT-TESTS *****");
127 val mv_cont1=mv_content([(1,[2,1]),(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,1]),(1,[0,0])]);
128 (* [(1,[0,1]),(1,[0,0])] *)
129 if mv_cont1=[(1,[0,1]),(1,[0,0])] then () else error ("rational.sml: example failed");
131 val mv_pp1=mv_pp([(1,[1,1]),(1,[1,0]),(1,[0,1]),(1,[0,0])]);
132 (*[(1,[1,0]),(1,[0,0])]*)
133 if mv_pp1=[(1,[1,0]),(1,[0,0])] then () else error ("rational.sml: example failed");
135 val mv_cont2=mv_content([(2,[1]),(4,[0])]);
137 if mv_cont2=[(2,[0])] then () else error ("rational.sml: example failed");
139 val mv_pp2=mv_pp([(2,[1]),(4,[0])]);
140 (* [(1,[1]),(2,[0])] *)
141 if mv_pp2=[(1,[1]),(2,[0])] then () else error ("rational.sml: example failed");
143 val mv_cont3=mv_content[(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(16,[1,1,1])];
145 if mv_cont3=[(2,[0,0,0])] then () else error ("rational.sml: example failed");
147 val mv_pp3=mv_pp[(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(16,[1,1,1])];
148 (* [(5,[2,2,0]),(4,[2,1,1]),(8,[1,1,1]),(6,[1,0,2])] *)
149 if mv_pp3=[(5,[2,2,0]),(4,[2,1,1]),(8,[1,1,1]),(6,[1,0,2])] then () else error ("rational.sml: example failed");
151 val mv_cont4=mv_content[(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])];
153 if mv_cont4=[(1,[0,0,0])] then () else error ("rational.sml: example failed");
155 val mv_pp4=mv_pp [(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])];
156 (* [(2,[2,1,0]),(2,[1,1,0]),(3,[1,0,1]),(3,[0,0,1])] *)
157 if mv_pp4=[(2,[2,1,0]),(2,[1,1,0]),(3,[1,0,1]),(3,[0,0,1])] then () else error ("rational.sml: example failed");
159 val con1=mv_content([(9,[2,0]),(15,[1,1]),(12,[1,0]),(6,[0,2]),(12,[0,1])]);
161 if con1=[(3,[0,0])] then () else error ("rational.sml: example failed");
163 val pp1=mv_pp([(9,[2,0]),(15,[1,1]),(12,[1,0]),(6,[0,2]),(12,[0,1])]);
164 (* [(3,[2,0]),(5,[1,1]),(4,[1,0]),(2,[0,2]),(4,[0,1])] *)
165 if pp1=[(3,[2,0]),(5,[1,1]),(4,[1,0]),(2,[0,2]),(4,[0,1])] then () else error ("rational.sml: example failed");
167 val con2=mv_content([(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])]);
169 if con2=[(1,[0,0])] then () else error ("rational.sml: example failed");
171 val pp2 =mv_pp([(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])]);
172 (* [(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])] *)
173 if pp2=[(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])] then () else error ("rational.sml: example failed");
175 val cont1 = mv_content [(1,[2,1,0]),(2,[2,1,0])];
177 if cont1=[(3,[0,1,0])] then () else error ("rational.sml: example failed");
179 val pp1 = mv_pp [(1,[2,1,0]),(2,[2,1,0])];
181 if pp1=[(1,[2,0,0])] then () else error ("rational.sml: example failed");
183 val cont2 = mv_content [(4,[1,2,0]),(2,[2,1,0])];
185 if cont2=[(2,[0,1,0])] then () else error ("rational.sml: example failed");
187 val pp2 = mv_pp [(4,[1,2,0]),(2,[2,1,0])];
188 (* [(1,[2,0,0]),(2,[1,1,0])] *)
189 if pp2=[(1,[2,0,0]),(2,[1,1,0])] then () else error ("rational.sml: example failed");
191 writeln ("********************************************************");
192 val cont3=mv_content [(65,[3,2,2]),(52,[3,2,1]),(26,[3,1,2]),(~95,[2,2,3]),(~76,[2,2,2]),(35,[2,2,1]),(28,[2,2,0]),(~38,[2,1,3]),(14,[2,1,1])];
193 if cont3=[(5,[0,2,1]),(4,[0,2,0]),(2,[0,1,1])] then () else error ("rational.sml: example failed");
194 val pp3=mv_pp [(65,[3,2,2]),(52,[3,2,1]),(26,[3,1,2]),(~95,[2,2,3]),(~76,[2,2,2]),(35,[2,2,1]),(28,[2,2,0]),(~38,[2,1,3]),(14,[2,1,1])];
197 "-------- fun monom2term, fun poly2term' ---------------";
198 "-------- fun monom2term, fun poly2term' ---------------";
199 "-------- fun monom2term, fun poly2term' ---------------";
200 val t = monom2term ((3,[2,1,0]), ["c","b","a"](*reverse ???SK-*));
201 term2str t = "3 * (c ^^^ 2 * b)" (*true*);
203 val t = monom2term ((1,[1,0]), ["b","a"]);
204 term2str t = "b" (*true*);
206 val t = poly2term ([(1,[0,0,0]),(2,[1,0,0]),(3,[2,1,0]),(4,[3,2,1])],
208 term2str t = "1 + 2 * c + 3 * (c ^^^ 2 * b) + 4 * (c ^^^ 3 * (b ^^^ 2 * a))";
210 val t = poly2term ([(1,[1,0]),(1,[0,1])], ["b","a"]);
211 term2str t = "a + b" (*true*);
213 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
214 "~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
215 "~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
216 "~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
219 fun parse_rat str = (term_of o the o (parse thy)) str;
221 writeln ("***** mv_gcd-tests *****");
222 val ggt1 = mv_gcd [(4,[2,2]),(8,[1,1]),(4,[0,0])] [(2,[1,1]),(2,[0,0])];
223 (* [(2,[1,1]),(2,[0,0])] *)
224 if ggt1=[(2,[1,1]),(2,[0,0])] then () else error ("rational.sml: example failed");
226 val ggt2 = mv_gcd [(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(15,[1,1,1])] [(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])];
227 (* [(2,[1,1,0]),(3,[0,0,1])] *)
228 if ggt2=[(2,[1,1,0]),(3,[0,0,1])] then () else error ("rational.sml: example failed");
231 val ggt3 = mv_gcd [(1,[2,0]),(~2,[1,1]),(1,[0,2])] [(1,[1,0]),(~1,[0,1])];
232 (* [(1,[1,0]),(~1,[0,1])] *)
233 if ggt3=[(1,[1,0]),(~1,[0,1])] then () else error ("rational.sml: example failed");
236 val ggt4 = mv_gcd [(1,[2,1,0]),(2,[2,1,0])] [(5,[1,0,0])];
238 if ggt4=[(1,[1,0,0])] then () else error ("rational.sml: example failed");
241 val ggt5 = mv_gcd [(4,[2,0]),(~8,[1,1]),(4,[0,2])] [(1,[2,0]),(~1,[0,2])];
242 (* [(1,[1,0]),(~1,[0,1])] *)
243 if ggt5=[(1,[1,0]),(~1,[0,1])] then () else error ("rational.sml: example failed");
246 val ggt6 = mv_gcd [(10,[2,1,1]),(14,[1,1,0]),(3,[1,0,1]),(20,[1,2,1])] [(5,[1,1,1]),(7,[2,1,1])];
248 if ggt6=[(1,[1,0,0])] then () else error ("rational.sml: example failed");
250 writeln ("***** kgv-tests *****");
251 val kgv1=mv_lcm [(10,[])] [(15,[])];
253 if kgv1=[(30,[])] then () else error ("rational.sml: example failed");
255 val kgv2=mv_lcm [(1,[2,0]),(~2,[1,1]),(1,[0,2])] [(1,[1,0]),(~1,[0,1])];
256 (* [(1,[2,0]),(~2,[1,1]),(1,[0,2])] *)
257 if kgv2=[(1,[2,0]),(~2,[1,1]),(1,[0,2])] then () else error ("rational.sml: example failed");
259 val kgv3=mv_lcm [(4,[2,0]),(~8,[1,1]),(4,[0,2])] [(1,[2,0]),(~1,[0,2])];
260 (* [(4,[3,0]),(~4,[2,1]),(~4,[1,2]),(4,[0,3])] *)
261 if kgv3=[(4,[3,0]),(~4,[2,1]),(~4,[1,2]),(4,[0,3])] then () else error ("rational.sml: example failed");
264 writeln ("***** STEP_CANCEL_TESTS: *****");
266 val term2 = (term_of o the o (parse thy)) " (9 * a^^^2 * b) / (6 * a * c)";
267 val div2 = term2str (step_cancel term2);
268 if div2 = "3 * (a * b) * (3 * a) / (2 * c * (3 * a))" then () else error ("rational.sml: example failed");
271 val term1 = (term_of o the o (parse thy)) "(10 * a^^^2 * b * c + 14 * a * b + 3 * a * c + 20 * a * b^^^2 * c) / a";
272 val div1 = term2str(step_cancel term1);
273 if div1 = "(3 * c + 14 * b + 20 * (b ^^^ 2 * c) + 10 * (a * (b * c))) * a / (1 * a)" then () else error ("rational.sml: example failed");
275 val term3 = (term_of o the o (parse thy)) "(10 * a^^^2 * b * c) / (1 * x * y * z) ";
276 val div3 = term2str(step_cancel term3);
277 if div3="10 * a ^^^ 2 * b * c / (1 * x * y * z)" then () else error ("rational.sml: example failed");
279 --------------------------------------------------------------------------!!!*)
281 (*-----versuche 13.3.03-----
282 val t = str2term "1 - x^^^2 - 5 * x^^^5";
283 val vs=(((map free2str) o vars) t);
284 val SOME ml = expanded2poly t vs;
286 poly2term'(rev(sort (mv_geq LEX_) (ml)),vs);
287 poly2term'([(~5,[5]),(~1,[2]),(1,[0])], vs);
288 monom2term((~5,[5]),vs);
289 monom2term((~1,[2]),vs);
290 val t' = monom2term((1,[0]),vs);(*uncaught exception LIST*)
292 val (i,is) = (~1,[2]);
293 val ttt = Const ("Groups.times_class.times", [HOLogic.realT,HOLogic.realT]---> HOLogic.realT) $
294 (Const ("uminus", HOLogic.realT --> HOLogic.realT) $
295 Free ((str_of_int o abs) i, HOLogic.realT)) $
296 powerproduct2term(is, vs);
298 -------versuche 13.3.03-----*)
300 val t = str2term "1 - x^^^2 - 5 * x^^^5";
301 val SOME t' = expanded2polynomial t; term2str t';
302 "1 + - 1 * x ^^^ 2 + - 5 * x ^^^ 5";
303 val t = str2term "1 - x";
304 val SOME t' = expanded2polynomial t; term2str t';
306 val t = str2term "1 + (-1) * x";
307 val SOME t' = expanded2polynomial t; term2str t';
309 val t = (term_of o the o (parse thy)) "1 + (-1) * x ^^^ 2 + (-5) * x ^^^5";
310 val SOME t' = polynomial2expanded t; term2str t';
311 "1 - x ^^^ 2 - 5 * x ^^^ 5";
312 ============ inhibit exn WN130824 TODO ======================================================*)
314 "-------- fun poly_of_term ---------------------------------------------------";
315 "-------- fun poly_of_term ---------------------------------------------------";
316 "-------- fun poly_of_term ---------------------------------------------------";
317 val vs = "12 * x^^^3 * y^^^4 * z^^^6" |> str2term |> vars |> map free2str |> sort string_ord;
319 if poly_of_term vs (str2term "12::real") = SOME [(12, [0, 0, 0])]
320 then () else error "poly_of_term 1 changed";
321 if poly_of_term vs (str2term "x::real") = SOME [(1, [1, 0, 0])]
322 then () else error "poly_of_term 2 changed";
323 if poly_of_term vs (str2term "12 * x^^^3") = SOME [(12, [3, 0, 0])]
324 then () else error "poly_of_term 3 changed";
325 if poly_of_term vs (str2term "12 * x^^^3 * y^^^4 * z^^^6") = SOME [(12, [3, 4, 6])]
326 then () else error "poly_of_term 4 changed";
327 if poly_of_term vs (str2term "1 + 2 * x^^^3 * y^^^4 * z^^^6 + y") =
328 SOME [(1, [0, 0, 0]), (1, [0, 1, 0]), (2, [3, 4, 6])]
329 then () else error "poly_of_term 5 changed";
331 (*poly_of_term is quite liberal:*)
332 (*the coefficient may be somewhere, the order of variables and the parentheses
333 within a monomial are arbitrary*)
334 if poly_of_term vs (str2term "y^^^4 * (x^^^3 * 12 * z^^^6)") = SOME [(12, [3, 4, 6])]
335 then () else error "poly_of_term 6 changed";
337 (*there may even be more than 1 coefficient:*)
338 if poly_of_term vs (str2term "2 * y^^^4 * (x^^^3 * 6 * z^^^6)") = SOME [(12, [3, 4, 6])]
339 then () else error "poly_of_term 7 changed";
341 (*the order and the parentheses within monomials are arbitrary:*)
342 if poly_of_term vs (str2term "2 * x^^^3 * y^^^4 * z^^^6 + (7 * y^^^8 + 1)")
343 = SOME [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 6])]
344 then () else error "poly_of_term 8 changed";
346 "-------- fun is_poly --------------------------------------------------------";
347 "-------- fun is_poly --------------------------------------------------------";
348 "-------- fun is_poly --------------------------------------------------------";
349 if is_poly (str2term "2 * x^^^3 * y^^^4 * z^^^6 + 7 * y^^^8 + 1")
350 then () else error "is_poly 1 changed";
351 if not (is_poly (str2term "2 * (x^^^3 * y^^^4 * z^^^6 + 7) * y^^^8 + 1"))
352 then () else error "is_poly 2 changed";
354 "-------- fun term_of_poly ---------------------------------------------------";
355 "-------- fun term_of_poly ---------------------------------------------------";
356 "-------- fun term_of_poly ---------------------------------------------------";
357 val expT = HOLogic.realT
358 val Free (_, baseT) = (hd o vars o str2term) "12 * x^^^3 * y^^^4 * z^^^6";
359 val p = [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 5])]
360 val vs = ["x","y","z"]
361 (*precondition for [(c, es),...]: legth es = length vs*)
363 if term2str (term_of_poly baseT expT vs p) = "1 + 7 * y ^^^ 8 + 2 * x ^^^ 3 * y ^^^ 4 * z ^^^ 5"
364 then () else error "term_of_poly 1 changed";
367 "-------- and app_rev --------------------------------------------------------";
368 "-------- and app_rev --------------------------------------------------------";
369 "-------- and app_rev --------------------------------------------------------";
370 (* trace down until prepats are evaluated
371 (which does not to work, because substitution is not done -- compare rew_sub!);
372 keep this sequence for the case, factout_p, cancel_p, common_nominator_p, add_fraction_p
373 (again) get prepat = [] changed to <>[]. *)
374 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)";
376 (*rewrite_set_ @{theory Isac} true cancel t = NONE; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
377 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (thy, false, cancel_p, t);
378 "~~~~~ fun rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
379 (thy, 1, bool, [], rls, term);
380 (*val (t', asm, rew) = app_rev thy (i+1) rrls t; rew = false!!!!!!!!!!!!!!!!!!!!!*)
381 "~~~~~ fun app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
382 fun chk_prepat thy erls [] t = true
383 | chk_prepat thy erls prepat t =
385 fun chk (pres, pat) =
387 val subst: Type.tyenv * Envir.tenv =
388 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
390 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
391 end) handle _ => false
392 fun scan_ f [] = false (*scan_ NEVER called by []*)
393 | scan_ f (pp::pps) =
394 if f pp then true else scan_ f pps;
395 in scan_ chk prepat end;
396 (* apply the normal_form of a rev-set *)
397 fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
398 if chk_prepat thy erls prepat t
399 then ((*tracing("### app_rev': t = "^(term2str t));*) normal_form t)
401 (* val opt = app_rev' thy rrls t ..NONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
402 "~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
404 (* chk_prepat thy erls prepat t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
405 (* app_sub thy i rrls t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
406 "~~~~~ fun chk_prepat, args:"; val (thy, erls, prepat, t) = (thy, erls, prepat, t);
407 fun chk (pres, pat) =
409 val subst: Type.tyenv * Envir.tenv =
410 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
412 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
413 end) handle _ => false
414 fun scan_ f [] = false (*scan_ NEVER called by []*)
415 | scan_ f (pp::pps) =
416 if f pp then true else scan_ f pps;
418 (*========== inhibit exn WN130823: prepat is empty ====================================
419 (* scan_ chk prepat = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
420 "~~~~~ fun , args:"; val (f, (pp::pps)) = (chk, prepat);
422 val ([t1, t2], t) = pp;
423 term2str t1 = "?r is_expanded";
424 term2str t2 = "?s is_expanded";
425 term2str t = "?r / ?s";
426 (* f pp = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
427 "~~~~~ fun chk, args:"; val (pres, pat) = (pp);
428 val subst: Type.tyenv * Envir.tenv =
429 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
431 ({}, {(("r", 0), ("real", Var (("r", 0), "real"))),
432 (("s", 0), ("real", Var (("s", 0), "real")))}*)
434 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
435 "~~~~~ fun eval__true, args:"; val (thy, i, asms, bdv, rls) =
436 (thy, (i + 1), (map (Envir.subst_term subst) pres), [], erls);
437 terms2str asms; (* = "[\"?r is_expanded\",\"?s is_expanded\"]"*)
438 asms = [@{term True}] orelse asms = []; (* = false*)
439 asms = [@{term False}] ; (* = false*)
440 "~~~~~ fun chk, args:"; val (indets, (a::asms)) = ([], asms);
441 bdv (*= []: _a list*);
442 val bdv : (term * term) list = [];
443 rewrite__set_ thy (i+1) false;
444 term2str a = "?r is_expanded"; (*hier m"usste doch der Numerator eingesetzt sein ??????????????*)
445 val SOME (Const ("HOL.False", _), []) = rewrite__set_ thy (i+1) false bdv rls a
446 ============ inhibit exn WN130823: prepat is empty ===================================*)
448 (*========== inhibit exn WN130824 TODO =======================================================
449 "-------- external calculating functions test -----------";
450 "-------- external calculating functions test -----------";
451 "-------- external calculating functions test -----------";
452 val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
453 val SOME (t', asm) = factout_p_ thy t;
454 if term2str t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso terms2str asm = "[]"
455 then () else error "factout_p_ 1 changed";
456 val SOME (t', asm) = cancel_p_ thy t;
457 if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[\"1 + x ~= 0\"]"
458 then () else error "cancel_p_ 1 changed";
460 val t = str2term "((-3 * x^^^2 + 6 *x - 3) / (2*x - 2))";
461 val SOME (t', asm) = factout_(*p_*) thy t;
462 if term2str t' = "(3 - 3 * x) * (-1 + x) / (2 * (-1 + x))" andalso terms2str asm = "[]"
463 then () else error "factout_ 2 changed";
464 val SOME (t', asm) = cancel_(*p_*) thy t;
465 if term2str t' = "(3 - 3 * x) / 2" andalso terms2str asm = "[\"-1 + x ~= 0\"]"
466 then () else error "cancel_ 2 changed";
468 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
469 val SOME (t', asm) = add_fraction_p_ thy t;
470 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
471 then () else error "add_fraction_p_ 3 changed";
472 val SOME (t', asm) = common_nominator_p_ thy t;
474 "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
475 andalso terms2str asm = "[]"
476 then () else error "common_nominator_p_ 3 changed";
478 val t = str2term "((x - 1) / (x + 1)) + ((x + 1) / (x - 1))";
479 val SOME (t', asm) = add_fraction_ thy t;
480 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
481 then () else error "factout_ 4 changed";
482 val SOME (t', asm) = common_nominator_ thy t;
484 "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
485 andalso terms2str asm = "[]"
486 then () else error "cancel_ 4 changed";
489 "((1) / (2*x + 2)) + ((1) / (2*x + (-2))) + ((1) / ( x^^^2 + (-1)))+((1) / (x^^^2 + (-2)*x + 1))";
490 val SOME (t', asm) = add_fraction_p_ thy t;
491 if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
492 then () else error "add_fraction_p_ 5 changed";
493 val SOME (t', asm) = norm_rational_ thy t;
494 if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
495 then () else error "norm_rational_ 5 changed";
499 val t3 = (term_of o the o (parse thy)) "((1) / (2*x + 2)) + ((1) / (2*x - 2)) + ((1) / ( x^^^2 - 1))+((1) / (x^^^2 - 2 * x + 1))";
500 val SOME (t3',_) = common_nominator_ thy t3;
501 val SOME (t3'',_) = add_fraction_ thy t3;
505 val SOME(t4,t5) = norm_expanded_rat_ thy t3;
511 val t=(term_of o the o (parse thy)) "(9 - x^^^2)/(9 - 6*x + x^^^2)";
512 val SOME (t',_) = factout_ thy t;
513 val SOME (t'',_) = cancel_ thy t;
516 "(3 + x) * (3 - x) / ((3 - x) * (3 - x))";
519 val t=(term_of o the o (parse thy))
520 "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1 / (3 - x)";
521 val SOME (t',_) = common_nominator_ thy t;
522 val SOME (t'',_) = add_fraction_ thy t;
525 "(9 - x ^^^ 2) / ((3 - x) * (3 - x)) + 1 * (3 - x) / ((3 - x) * (3 - x))";
528 (*WN021016 added -----vv---*)
529 val t = str2term "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1";
530 val SOME (t',_) = common_nominator_ thy t;
531 val SOME (t'',_) = add_fraction_ thy t;
532 term2str t' = "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n1" ^
533 " * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
534 term2str t'' = "6 / (3 - x)" (*true*);
536 val t = str2term "1 + (9 - x^^^2) / (9 - 6*x + x^^^2)";
537 val SOME (t',_) = common_nominator_ thy t;
538 val SOME (t'',_) = add_fraction_ thy t;
539 term2str t' = "1 * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n" ^
540 "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
541 term2str t'' = "6 / (3 - x)" (*true*);
542 (*WN021016 added -----^^---*)
543 (*WN030602 added -----vv--- no rewrite -> NONE !*)
544 val t = str2term "1 / a";
545 val NONE = cancel_p_ thy t;
546 val NONE = rewrite_set_ thy false cancel_p t;
547 (*WN.2.6.03 added -------^^---*)
549 val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2)";
550 val SOME (t',_) = factout_ thy t;
551 val SOME (t'',_) = cancel_ thy t;
552 term2str t' = "(y + x) * (y - x) / ((y - x) * (y - x))"(*true*);
553 term2str t'' = "(y + x) / (y - x)";
555 val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2) + 1 / (y - x)";
556 val SOME (t',_) = common_nominator_ thy t;
557 val SOME (t'',_) = add_fraction_ thy t;
559 "(-1 * x ^^^ 2 + y ^^^ 2) / ((-1 * x + y) * (-1 * x + y)) +\n1" ^
560 " * (-1 * x + y) / ((-1 * x + y) * (-1 * x + y))" (*true*);
561 term2str t'' = "(-1 - x - y) / (x - y)" (*true*);
563 val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2) + 1 / (x - y)";
564 val SOME (t',_) = common_nominator_ thy t;
565 val SOME (t'',_) = add_fraction_ thy t;
566 if term2str t' = "(-1 * y ^^^ 2 + x ^^^ 2) / ((-1 * y + x) * (-1 * y + x))" ^
567 " +\n1 * (-1 * y + x) / ((-1 * y + x) * (-1 * y + x))" then ()
568 else error "rational.sml lex-ord 1";
569 if term2str t'' = "(-1 - y - x) / (y - x)" then ()
570 else error "rational.sml lex-ord 2";
571 (*WN.16.10.02 WN070905 lexicographische Ordnung erhalten *)
574 val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2)";
575 val SOME (t',_) = norm_expanded_rat_ thy t;
576 if term2str t' = "(x + y) / (x - y)" then ()
577 else error "rational.sml term2poly: invalid x ^^^ 2 - y ^^^ 2 No.1";
578 (*val SOME (t'',_) = norm_rational_ thy t;
579 *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial
580 WN.16.10.02 ?! + WN060831???SK4
581 WN070905 *** term2poly: invalid = x ^^^ 2 - y ^^^ 2*)
584 val t = str2term "(9 - x^^^2)/(9 - 6*x + x^^^2) + (1)/(3 + x)";
585 val SOME (t',_) = norm_expanded_rat_ thy t;
586 if term2str t' = "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)" then ()
587 else error "rational.sml (9 - x^^^2)/(9 - 6*x + x^^^2) +...";
588 (*val SOME (t'',_) = norm_rational_ thy t;
589 *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial WN.16.10.02 ?!
590 WN070906 *** term2poly: invalid = 9 - x ^^^ 2 SK.term2poly*)
592 val t=(term_of o the o (parse thy))
593 "(9 + (-1)* x^^^2)/(9 + (-1)* 6*x + x^^^2) + (1)/(3 + x)";
594 val SOME (t',_) = norm_expanded_rat_ thy t;
595 val SOME (t'',_) = norm_rational_ thy t;
598 "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)";
599 "(12 + 5 * x + x ^^^ 2) / (9 + (-1) * x ^^^ 2)";
602 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
603 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
604 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
605 val thy = @{theory "Rational"};
606 val thy' = "Rational";
608 val mp = "make_polynomial";
610 writeln ("example 186:");
612 val e186a'="(14 * x * y) / ( x * y )";(*SRC*)
613 rewrite_set_ thy false cancel (str2term e186a');
615 val e186a = the (rewrite_set thy' false "cancel" e186a');
616 is_expanded (parse_rat "14 * x * y");
617 is_expanded (parse_rat "x * y");
618 if e186a = ("14 / 1", "[\"y * x ~= 0\"]") then ()
619 else error "rational.sml cancel Schalk e186a";
622 val e186b'="(60 * a * b) / ( 15 * a * b )";
623 val e186b = the (rewrite_set thy' false "cancel" e186b');
625 val e186c'="(144 * a^^^2 * b * c) / (12 * a * b * c )";
626 val e186c = (the (rewrite_set thy' false "cancel" e186c'))
627 handle e => print_exn_G e;
628 val t = (term_of o the o (parse thy)) e186c';
629 if e186c = ("12 * a / 1", "[\"12 * (c * (b * a)) ~= 0\"]") then ()
630 else error "rational.sml cancel Schalk e186c";
632 writeln ("example 187:");
634 val e187a'="(12 * x * y) / (8 * y^^^2 )";(*SRC*)
635 val e187a = the (rewrite_set thy' false "cancel" e187a');
637 val e187b'="(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
638 val e187b = the (rewrite_set thy' false "cancel" e187b');
640 val e187d'="(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";(*SRC*)
641 val e187d = the (rewrite_set thy' false "cancel" e187d');
642 if e187d = ("3 * z ^^^ 3 / (5 * (y * x))",
643 "[\"3 * (z * (y ^^^ 2 * x ^^^ 5)) ~= 0\"]") then ()
644 else error "rational.sml cancel Schalk e186d";
646 writeln "example 188:";
647 val e188a'="(-8 + 8 * x) / (-9 + 9 * x)";(*SRC*)
648 val e188a = the (rewrite_set thy' false "cancel" e188a');
649 is_expanded (parse_rat "8 * x + -8");
650 (* e188a = ("8 / 9",["not ((-1) + x = 0)"]) then () 13.3.03*)
651 if e188a = ("8 / 9", "[\"-1 + x ~= 0\"]") then ()
652 else error "rational.sml: e188a new behaviour";
654 val SOME (t,_) = rewrite_set thy' false mp "(8*((-1) + x))/(9*((-1) + x))";
656 val e188b'="(-15 + 5 * x) / (-18 + 6 * x)";(*SRC*)
657 val SOME (t, asm) = rewrite_set thy' false "cancel" e188b';
658 t = "5 / 6" (*true*);
661 val e188c'="( a + -1 * b ) / ( b + -1 * a )";
662 val e188c = the (rewrite_set thy' false "cancel_p" e188c');
663 (*is_expanded (parse_rat "a + -1 * b");*)
665 rewrite_set thy' false mp "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
666 if t= "(a + -1 * b) / (-1 * a + b)" then()
667 else error "rational.sml: e188c new behaviour";
669 writeln ("example 190:");
671 val e190c'="( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )";
672 val e190c = the (rewrite_set thy' false "cancel" e190c');
673 val SOME (t,_) = rewrite_set thy' false mp "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
674 if t = "(1 + 3 * a + 9 * a ^^^ 2 + 27 * a ^^^ 3) /\n(3 * a + 18 * a ^^^ 2 + 27 * a ^^^ 3)" then ()
675 else error "rational.sml: e190c new behaviour";
677 writeln ("example 191:");
679 val e191a'="( x^^^2 + -1 * y^^^2 ) / ( x + y )";
681 val e191a = the (rewrite_set thy' false "cancel" e191a');
682 is_expanded (parse_rat "x^^^2 + -1 * y^^^2");
684 is_expanded (parse_rat "x + y");
686 val SOME (t,_) = rewrite_set thy' false mp "((x + (-1) * y)*(x + y))/((1)*(x + y))";
687 (* t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then() WN.13.3.03*)
688 if t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then()
689 else error "rational.sml: e191a new behaviour";
692 val e191c'="( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )";
694 val e191c = the (rewrite_set thy' false "cancel" e191c');
695 is_expanded (parse_rat "9 * x^^^2 + -30 * x + 25");
697 is_expanded (parse_rat "25 + -30*x + 9*x^^^2");
699 is_expanded (parse_rat "-25 + 9*x^^^2");
701 val SOME (t,_) = rewrite_set thy' false mp "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
702 (* t="(25 + ((-30) * x + 9 * x ^^^ 2)) / ((-25) + 9 * x ^^^ 2)"then() 13.3.03*)
703 if t= "(25 + -30 * x + 9 * x ^^^ 2) / (-25 + 9 * x ^^^ 2)" then()
704 else error "rational.sml: 'e191c' new behaviour";
707 writeln ("example 192:");
709 val e192b'="( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 * y^^^3 )";
711 val e192b = the (rewrite_set thy' false "cancel" e192b');
712 -------------------*)
713 val SOME (t',_) = rewrite_set thy' false mp "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
714 (*========== inhibit exn 110317 ================================================
715 if t' = "(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)"
716 (*"(-1 * y * x ^^^ 2 + 7 * x ^^^ 3) / (-1 * y ^^^ 3 + 7 * x * y ^^^ 2)"WN050929*)
717 then () else error "rational.sml: 'e192b' new behaviour";
718 (*^^^ works with MG's simplifier vvv*)
719 val t =str2term"((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
720 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
721 if term2str t' = "(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)" then () else error "rational.sml: 'e192b'MG new behaviour";
722 ============ inhibit exn 110317 ==============================================*)
724 writeln ("example 193:");
726 val e193a'="( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )";
728 val e193a = the (rewrite_set thy' false "cancel" e193a');
729 -------------------*)
731 val e193b'="( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )";
733 val e193b = the (rewrite_set thy' false "cancel" e193b');
735 val e193c'="( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )";
736 val SOME(t,_) = rewrite_set thy' false "cancel" e193c';
737 -------------------*)
739 val wn01 = "(-25 + 9*x^^^2)/(5 + 3*x)";
740 val SOME (t, asm) = rewrite_set thy' false "cancel" wn01;
741 (* t = "((-5) + 3 * x) / 1" then () WN.13.3.03*)
742 if t = "(-5 + 3 * x) / 1" andalso asm = "[\"5 + 3 * x ~= 0\"]" then ()
743 else error "rational.sml: new behav. in cancel wn01";
745 "-------- common_nominator_p ----------------------------";
746 "-------- common_nominator_p ----------------------------";
747 "-------- common_nominator_p ----------------------------";
748 val rls' = "common_nominator_p";
750 writeln ("example 204:");
752 val e204a'="((5 * x) / 9) + ((3 * x) / 9) + (x / 9)";
753 val e204a = the (rewrite_set thy' false "common_nominator_p" e204a');
755 val e204b'="5 / x + -3 / x + -1 / x";
756 val e204b = the (rewrite_set thy' false "common_nominator_p" e204b');
757 if e204b = ("1 / x", "[]") then ()
758 else error "rational.sml common_nominator_p example e204b";
760 writeln ("example 205:");
762 val e205a'="((4 * x + 7) / 8) + ((4 * x + 3) / 8)";
763 val e205a = the (rewrite_set thy' false "common_nominator_p" e205a');
765 val e205b'="((5 * x + 2) / 3) + ((-2 * x + 1) / 3)";
766 val e205b = the (rewrite_set thy' false "common_nominator_p" e205b');
767 if e205b = ("(1 + x) / 1", "[]") then ()
768 else error "rational.sml common_nominator_p example e204b";
770 writeln ("example 206:");
772 val e206a'="((5 * x + 4) / (2 * x + -1)) + ((9 * x + 5) / (2 * x + -1))";
773 val e206a = the (rewrite_set thy' false "common_nominator_p" e206a');
775 val e206b'="((17 * x + -23) / (5 * x + 4)) + ((-25 + -17 * x) / (5 * x + 4))";
776 val e206b = the (rewrite_set thy' false "common_nominator_p" e206b');
778 writeln ("example 207:");
779 val e207'="((3 * x * y + 3 * y) / (x * y)) + ((5 * x * y + 7 * y) / (x * y)) + ((9 * x * y + -2 * y) / (x * y)) + ((x * y + 4 * y) / (x * y)) ";
780 val e207 = the (rewrite_set thy' false "common_nominator_p" e207');
782 writeln ("example 208:");
783 val e208'="((3 * x + 2) / (x + 2)) + ((5 * x + -1) / (x + 2)) + ((-7 * x + -3) / (x + 2)) + ((-1 * x + -3) / (x + 2)) ";
784 val e208 = the (rewrite_set thy' false "common_nominator_p" e208');
786 writeln ("example 209:");
787 val e209'="((3 * x + -7 * y + 3 * z) / (4)) + ((2 * x + 17 * y + 10 * z) / (4)) + ((-1 * x + 2 * y + z) / (4)) ";
788 val e209 = the (rewrite_set thy' false "common_nominator_p" e209');
790 writeln ("example 210:");
791 val e210'="((2 * x + 3 + -1 * x^^^2) / (5 * x)) + ((5 * x^^^2 + -2 * x + 1) / (5 * x)) + ((-3 * x^^^2 + -2 * x + 1) / (5 * x)) + ((-1 * x^^^2 + -3 * x + -5) / (5 * x)) ";
792 val e210 = the (rewrite_set thy' false "common_nominator_p" e210');
794 writeln ("example 211:");
796 val e211a'="((b) / (a + -1 * b)) + ((-1 * a) / (a + -1 * b))";
797 val e211a = the (rewrite_set thy' false "common_nominator_p" e211a');
799 val e211b'="((b) / (b^^^2 + -1 * a^^^2)) + ((-1 * a) / (b^^^2 + -1 * a^^^2))";
800 val e211b = the (rewrite_set thy' false "common_nominator_p" e211b');
802 writeln ("example 212:");
804 val e212a'="((4) / (x)) + ((-3) / (y)) + -1";
805 val e212a = the (rewrite_set thy' false "common_nominator_p" e212a');
807 val e212b'="((4) / (x)) + ((-5) / (y)) + ((6) / (x*y))";
808 val e212b = the (rewrite_set thy' false "common_nominator_p" e212b');
810 writeln ("example 213:");
812 val e213a'="((5 * x) / (3 * y^^^2)) + ((19 * z) / (6 * x * y)) + ((-2 * x) / (3 * y^^^2)) + ((7 * y^^^2) / (6 * x^^^2)) ";
813 val e213a = the (rewrite_set thy' false "common_nominator_p" e213a');
815 val e213b'="((2 * b) / (3 * a^^^2)) + ((3 * c) / (7 * a * b)) + ((4 * b) / (3 * a^^^2)) + ((3 * a) / (7 * b^^^2))";
816 val e213b = the (rewrite_set thy' false "common_nominator_p" e213b');
818 writeln ("example 214:");
820 val e214a'="((3 * x + 2 * y + 2 * z) / (4)) + ((-5 * x + -3 * y) / (3)) + ((x + y + -2 * z) / (2))";
821 val e214a = the (rewrite_set thy' false "common_nominator_p" e214a');
823 val e214b'="((5 * x + 2 * y + z) / (2)) + ((-7 * x + -3 * y) / (3)) + ((3 * x + 6 * y + -1 * z) / (12))";
824 val e214b = the (rewrite_set thy' false "common_nominator_p" e214b');
826 writeln ("example 216:");
828 val e216a'="((2 * b + 3 * c) / (a * c)) + ((3 * a + b) / (a * b)) + ((-2 * b^^^2 + -3 * a * c) / (a * b * c))";
829 val e216a = the (rewrite_set thy' false "common_nominator_p" e216a');
831 val e216b'="((2 * a + 3 * b) / (b * c)) + ((3 * c + a) / (a * c)) + ((-2 * a^^^2 + -3 * b * c) / (a * b * c))";
832 val e216b = the (rewrite_set thy' false "common_nominator_p" e216b');
834 writeln ("example 217:");
835 val e217'="((z + -1) / (z)) + ((3 * z ^^^2 + -6 * z + 5) / (z^^^2)) + ((-4 * z^^^3 + 7 * z^^^2 + -5 * z + 5) / (z^^^3))";
836 val e217 = the (rewrite_set thy' false "common_nominator_p" e217');
839 val rls' = "common_nominator";
840 writeln ("example 218:");
841 val e218'="((9 * a^^^3 - 5 * a^^^2 + 2 * a + 8) / (108 * a^^^4)) + ((-5 * a + 3 * a^^^2 + 4) / (8 * a^^^3)) + ((-261 * a^^^3 + 19 * a^^^2 + -112 * a + 16) / (216 * a^^^4))";
842 val e218 = the (rewrite_set thy' false "common_nominator" e218');
843 if e218 = ("(16 - 63 * a ^^^ 2 - 81 * a ^^^ 3) / (108 * a ^^^ 4)", "[]") then ()
844 else error "rationa.sml common_nominator example e218";
846 writeln ("example 219:");
848 val e219a'="((1) / (y + 1)) + ((1) / (y + 2)) + ((1) / (y + 3))";
849 val e219a = the (rewrite_set thy' false "common_nominator" e219a');
851 val e219b'="((1) / (x + 1)) + ((1) / (x + 2)) + ((-2) / (x + 3))";
852 val e219b = the (rewrite_set thy' false "common_nominator" e219b');
853 if e219b = ("(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)", "[]") then ()
854 else error "rationa.sml common_nominator example e219b";
856 writeln ("example 220:");
858 val e220a'="((17) / (5 * r + -2)) + ((-13) / (2 * r + 3)) + ((4) / (3 * r + -5))";
859 val e220a = the (rewrite_set thy' false "common_nominator" e220a');
861 val e220b'="((20 * a) / (a + -3)) + ((-19 * a) / (a + -4)) + ((a) / (a + -5))";
862 val e220b = the (rewrite_set thy' false "common_nominator" e220b');
864 writeln ("example 221:");
866 val e221a'="((a + b) / (a + -1 * b)) + ((a + -1 * b) / (a + b))";
867 val e221a = the (rewrite_set thy' false "common_nominator" e221a');
869 val e221b'="((x + -1 * y) / (x + y)) + ((x + y) / (x + -1 * y)) ";
870 val e221b = the (rewrite_set thy' false "common_nominator" e221b');
872 writeln ("example 222:");
874 val e222a'="((1 + -1 * x) / (1 + x)) + ((-1 + -1 * x) / (1 + -1 * x)) + ((4 * x) / (1 + -1 * x^^^2))";
875 val e222a = the (rewrite_set thy' false "common_nominator" e222a');
877 val e222b'="((1 + x ) / (1 + -1 * x)) + ((-1 + x) / (1 + x)) + ((2 * x) / (1 + -1 * x^^^2))";
878 val e222b = the (rewrite_set thy' false "common_nominator" e222b');
880 writeln ("example 225:");
882 val e225a'="((6 * a) / (a^^^2 + -64)) + ((a + 2) / (2 * a + 16)) + ((-1) / (2))";
883 val e225a = the (rewrite_set thy' false "common_nominator" e225a');
885 val e225b'="((a + 2 ) / (2 * a + 12)) + ((4 * a) / (a^^^2 + -36)) + ((-1) / (2))";
886 val e225b = the (rewrite_set thy' false "common_nominator" e225b');
888 writeln ("example 226:");
890 val e226a'="((35 * z) / (49 * z^^^2 + -4)) + -1 + ((14 * z + -1) / (14 * z + 4)) ";
891 val e226a = the (rewrite_set thy' false "common_nominator" e226a');
893 val e226b'="((45 * a * b) / (25 * a^^^2 + -9 * b^^^2)) + ((20 * a + 3 * b) / (10 * a + 6 * b)) + -2";
894 val e226b = the (rewrite_set thy' false "common_nominator" e226b');
896 writeln ("example 227:");
898 val e227a'="((6 * z + 11) / (6 * z + 14)) + ((9 * z ) / (9 * z^^^2 + -49)) + -1 ";
899 val e227a = the (rewrite_set thy' false "common_nominator" e227a');
901 val e227b'="((16 * a + 37 * b) / (4 * a + 10 * b)) + ((6 * a * b) / (4 * a^^^2 + -25 * b^^^2)) + -4 ";
902 val e227b = the (rewrite_set thy' false "common_nominator" e227b');
904 writeln ("example 228:");
906 val e228a'="((7 * a + 11) / (3 * a^^^2 + -3)) + ((-2 * a + -1) / (a^^^2 + -1 * a)) + ((-1) / (3 * a + 3))";
907 val e228a = the (rewrite_set thy' false "common_nominator" e228a');
909 val e228b'="((11 * z + 2 * b) / (4 * b * z + -8 * b^^^2)) + ((-8 * z) / (z^^^2 + -4 * b^^^2)) + ((-9 * z + -2 * b) / (4 * b * z + 8 * b^^^2))";
910 val e228b = the (rewrite_set thy' false "common_nominator" e228b');
913 writeln ("example 229:");
915 val e229a'="((5 * x^^^2 + y) / (x + 2 * y)) + ((-8 * x^^^3 + 4 * x^^^2 * y + 3 * x * y) / (x^^^2 + -4 * y^^^2)) + ((3 * x^^^2 + -4 * y) / (x + -2 * y))";
916 val e229a = the (rewrite_set thy' false "common_nominator" e229a');
918 val e229b'="((7 * x^^^2 + y) / (x + 3 * y)) + ((-24 * x^^^2 * y + 5 * x * y + 21 * y^^^2) / (x^^^2 + -9 * y^^^2)) + ((4 * x^^^2 + -6 * y) / (x + -3 * y))";
919 val e229b = the (rewrite_set thy' false "common_nominator" e229b');
921 writeln ("example 230:");
923 val e230a'="((5 * x^^^2 + y) / (2 * x + y)) + ((-16 * x^^^3 + 2 * x^^^2 * y + 6 * x * y) / (4 * x^^^2 + -1 * y^^^2)) + ((3 * x^^^2 + -4 * y) / (2 * x + -1 * y))";
924 val e230a = the (rewrite_set thy' false "common_nominator" e230a');
926 val e230b'="((7 * x^^^2 + y) / (3 * x + y)) + ((-3 * x^^^3 + 15 * x * y + -7 * x^^^2 * y + 7 * y^^^2) / (9 * x^^^2 + -1 * y^^^2)) + ((4 * x^^^2 + -6 * y) / (3 * x + -1 * y))";
927 val e230b = the (rewrite_set thy' false "common_nominator" e230b');
929 writeln ("example 231:");
931 val e231a'="((2 * x + 5 * y) / (x)) + ((2 * x^^^3 + -5 * y^^^3 + 3 * x * y^^^2) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-3 * x + -6 * y) / (x + -1 * y))";
932 val e231a = the (rewrite_set thy' false "common_nominator" e231a');
934 val e231b'="((6 * x + 2 * y) / (x)) + ((6 * x^^^2 * y + -4 * x * y^^^2 + -2 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-5 * x + -3 * y) / (x + -1 * y))";
935 val e231b = the (rewrite_set thy' false "common_nominator" e231b');
937 writeln ("example 232:");
939 val e232a'="((2 * x + 3 * y) / (x)) + ((4 * x^^^3 + -1 * x * y^^^2 + -3 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-5 * x + -6 * y) / (x + -1 * y))";
940 val e232a = the (rewrite_set thy' false "common_nominator" e232a');
942 val e232b'="((5 * x + 2 * y) / (x)) + ((2 * x^^^3 + -3 * x * y^^^2 + 3 * x^^^2 * y + -2 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-6 * x + -3 * y) / (x + -1 * y))";
943 val e232b = the (rewrite_set thy' false "common_nominator" e232b');
945 writeln ("example 233:");
947 val e233a'="((5 * x + 6 * y) / (x)) + ((5 * x * y^^^2 + -6 * y^^^3 + -2 * x^^^3 + 3 * x^^^2 * y) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-2 * x + -3 * y) / (x + -1 * y))";
948 val e233a = the (rewrite_set thy' false "common_nominator" e233a');
950 val e233b'="((6 * x + 5 * y) / (x)) + ((4 * x^^^2 * y + 3 * x * y^^^2 + -5 * y^^^3 + -2 * x^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-3 * x + -2 * y) / (x + -1 * y))";
951 val e233b = the (rewrite_set thy' false "common_nominator" e233b');
953 writeln ("example 234:");
955 val e234a'="((5 * a + b) / (2 * a * b + -2 * b^^^2)) + ((-3 * a + -1 * b) / (2 * a * b + 2 * b^^^2)) + ((-2 * a) / (a^^^2 + -1 * b^^^2))";
956 val e234a = the (rewrite_set thy' false "common_nominator" e234a');
958 val e234b'="((5 * a + 3 * b) / (6 * a * b + -18 * b^^^2)) + ((-3 * a + -3 * b) / (6 * a * b + 18 * b^^^2)) + ((-2 * a) / (a^^^2 + -9 * b^^^2)) ";
959 val e234b = the (rewrite_set thy' false "common_nominator" e234b');
961 writeln ("example 235:");
963 val e235a'="((10 * x + 3 * y) / (12 * x * y + -18 * y^^^2)) + ((-6 * x + -3 * y) / (12 * x * y + 18 * y^^^2)) + ((-4 * x) / (4 * x^^^2 + -9 * y^^^2))";
964 val e235a = the (rewrite_set thy' false "common_nominator" e235a');
966 val e235b'="((8 * a + b) / (4 * a * b + -2 * b^^^2)) + ((-4 * a + -1 * b) / (4 * a * b + 2 * b^^^2)) + ((-2 * a) / (4 * a^^^2 + -1 * b^^^2)) ";
967 val e235b = the (rewrite_set thy' false "common_nominator" e235b');
969 writeln ("example 236:");
971 val e236a'="((8 * a + 5 * b) / (20 * a * b + -50 * b^^^2)) + ((-4 * a + -5 * b) / (20 * a * b + 50 * b^^^2)) + ((-2 * a) / (4 * a^^^2 + -25 * b^^^2))";
972 val e236a = the (rewrite_set thy' false "common_nominator" e236a');
974 val e236b'="((24 * x + y) / (6 * x * y + -2 * y^^^2)) + ((-18 * x + -1 * y) / (6 * x * y + 2 * y^^^2)) + ((-15 * x) / (9 * x^^^2 + -1 * y^^^2)) ";
975 val e236b = the (rewrite_set thy' false "common_nominator" e236b');
979 writeln ("example heuberger:");
980 val eheu'="(x^^^4 + x * y + x^^^3 * y + y^^^2) / (x + 5 * x^^^2 + y + 5 * x * y + x^^^2 * y^^^3 + x * y^^^4)";
981 val eheu = the (rewrite_set thy' false "cancel" eheu');
983 val rls' = "common_nominator_p";
984 writeln ("example stiefel:");
985 val est1'="(7) / (-14) + (-2) / (4)";
986 val est1 = the (rewrite_set thy' false "common_nominator_p" est1');
987 if est1 = ("-1 / 1", "[]") then ()
988 else error "new behaviour in rational.sml: est1'";
990 val t = (term_of o the o (parse thy))
991 "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
992 val SOME (t',_) = factout_ thy t;
993 if term2str t' = "(3 + x) * (3 - x) / ((3 - x) * (3 - x))" then ()
994 else error "rational.sml factout_ (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
997 "-------- reverse rewrite -------------------------------";
998 "-------- reverse rewrite -------------------------------";
999 "-------- reverse rewrite -------------------------------";
1000 (*WN.28.8.02: tests for the 'reverse-rewrite' functions:
1001 these are defined in Rationals.ML and stored in
1002 the 'reverse-ruleset' cancel*)
1004 (*the term for which reverse rewriting is demonstrated*)
1005 val t = (term_of o the o (parse thy))
1006 "(9 - x ^^^ 2) / (9 + 6 * x + x ^^^ 2)";
1007 val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
1008 next_rule=nex,normal_form=nor,...},...} = cancel;
1010 (*normal_form produces the result in ONE step*)
1011 val SOME (t',_) = nor t;
1012 if term2str t' = "(3 - x) / (3 + x)" then ()
1013 else error "rational.sml normal_form (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1015 (*initialize the interpreter state used by the 'me'*)
1016 val (t,_,revsets,_) = ini t;
1018 (*find the rule 'r' to apply to term 't'*)
1019 val SOME (r as (Thm (str, thm))) = nex revsets t;
1020 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))"
1021 andalso string_of_thm thm =
1022 (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
1023 (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
1024 else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1025 (* before Isa02->09-2 was not checked automatically, ?was different?:
1026 val SOME r = nex revsets t;
1027 val r = Thm ("sym_#mult_2_3","6 = 2 * 3") : rule*)
1029 (* check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
1030 if the rule is OK, the term resulting from applying the rule is returned,too;
1031 there might be several rule applications inbetween,
1032 which are listed after the head in reverse order *)
1033 val (r, (t, asm))::_ = loc revsets t r;
1034 if term2str t = "(9 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" andalso asm = []
1036 else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1038 (* find the next rule to apply *)
1039 val SOME (r as (Thm (str, thm))) = nex revsets t;
1040 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso
1041 string_of_thm thm = (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
1042 (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
1043 else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1045 (*check the next rule*)
1046 val (r, (t, asm)) :: _ = loc revsets t r;
1047 if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" then ()
1048 else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) II";
1050 (*find and check the next rules, rewrite*)
1051 val SOME r = nex revsets t;
1052 val (r,(t,asm))::_ = loc revsets t r;
1053 if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
1054 else error "rational.sml locate_rule II";
1056 val SOME r = nex revsets t;
1057 val (r,(t,asm))::_ = loc revsets t r;
1058 if term2str t = "(3 - x) * (3 + x) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
1059 else error "rational.sml next_rule II";
1061 val SOME r = nex revsets t;
1062 val (r,(t,asm))::_ = loc revsets t r;
1063 if term2str t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then ()
1064 else error "rational.sml next_rule III";
1066 val SOME r = nex revsets t;
1067 val (r, (t, asm)) :: _ = loc revsets t r;
1068 val ss = term2str t;
1069 if ss = "(3 - x) / (3 + x)" andalso terms2str asm = "[\"3 + x ~= 0\"]" then ()
1070 else error "rational.sml: new behav. in rev-set cancel";
1072 "-------- 'reverse-ruleset' cancel_p --------------------";
1073 "-------- 'reverse-ruleset' cancel_p --------------------";
1074 "-------- 'reverse-ruleset' cancel_p --------------------";
1075 (*WN.11.9.02: the 'reverse-ruleset' cancel_p*)
1077 (*the term for which reverse rewriting is demonstrated*)
1078 val t = str2term "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))";
1079 val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
1080 next_rule=nex,normal_form=nor,...},...} = cancel_p;
1082 (*normal_form produces the result in ONE step*)
1083 val SOME (t',_) = nor t;
1084 term2str t' = "(3 + 1 * x) / (3 + -1 * x)";
1086 (*initialize the interpreter state used by the 'me'*)
1087 val SOME (t', asm) = cancel_p_ thy t;
1088 term2str t' = "(3 + x) / (3 + -1 * x)" (*true*);
1089 terms2str asm = "[\"3 + -1 * x ~= 0\"]" (*true*);
1090 val (t,_,revsets,_) = ini t;
1092 (* WN.10.10.02: dieser Fall terminiert nicht
1093 (make_polynomial enth"alt zu viele rules)
1094 WN060823 'init_state' requires rewriting on specified location in the term
1095 print_depth 99; Rfuns; print_depth 3;
1096 WN060831 cycling "sym_order_mult_rls_" "sym_mult_assoc"
1097 as was with make_polynomial before ?!?*)
1099 val SOME r = nex revsets t;
1100 eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))",
1101 mk_thm thy "9 = 3 ^^^ 2"));
1102 (*WN060831 *** id_of_thm
1103 Exception- ERROR raised ...
1104 val (r,(t,asm))::_ = loc revsets t r;
1107 val SOME r = nex revsets t;
1108 val (r,(t,asm))::_ = loc revsets t r;
1112 writeln "****************** all tests successfull *************************";
1116 (*WN.17.3.03 =========================================================vvv---*)
1117 "-------- norm_Rational ---------------------------------";
1118 "-------- norm_Rational ---------------------------------";
1119 "-------- norm_Rational ---------------------------------";
1120 val t = str2term "(3*x+5)/18 - x/2 - -(3*x - 2)/9 = 0";
1121 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1122 if term2str t' = "1 / 18 = 0" then () else error "rational.sml 1";
1124 val t = str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0";
1125 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1126 if term2str t' = "(237 + 65 * x) / 36 = 0" then ()
1127 else error "rational.sml 2";
1129 val t = str2term "(1/2 + (5*x)/2)^^^2 - ((13*x)/2 - 5/2)^^^2 - (6*x)^^^2 + 29";
1130 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1131 if term2str t' = "23 + 35 * x + -72 * x ^^^ 2" then ()
1132 else error "rational.sml 3";
1134 (*trace_rewrite:=true;*)
1135 val t = str2term "Not (6*x is_atom)";
1136 val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
1138 val t = str2term "1 < 2";
1139 val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
1142 val t = str2term "(6*x)^^^2";
1143 val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false
1144 (num_str @{thm realpow_def_atom}) t;
1145 if term2str t' = "6 * x * (6 * x) ^^^ (2 + -1)" then ()
1146 else error "rational.sml powers_erls (6*x)^^^2";
1148 val t = str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))";
1149 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1150 if term2str t' = "65 * x / 2" then () else error "rational.sml 4";
1152 val t = str2term "1 - ((13*x)/2 - 5/2)^^^2";
1153 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1154 (*bef.040209: if term2str t' = "(-21 + (130 * x + -169 * x ^^^ 2)) / 4"then()*)
1155 if term2str t' = "(-21 + 130 * x + -169 * x ^^^ 2) / 4" then ()
1156 else error "rational.sml 5";
1158 (*SRAM Schalk I, p.92 Nr. 609a*)
1159 val t = str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
1160 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1161 if term2str t' = "(-255 + 112 * x) / 135" then ()
1162 else error "rational.sml 6";
1164 (*SRAM Schalk I, p.92 Nr. 610c*)
1165 val t = str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
1166 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1167 if term2str t' = "(-3 + -1 * x) / 2" then () else error "rational.sml 7";
1169 (*SRAM Schalk I, p.92 Nr. 476a*)
1170 val t = str2term "(x^^^2/(1 - x^^^2) + 1)/(x/(1 - x) + 1) * (1 + x)";
1171 (*. a/b : c/d translated to a/b * d/c .*)
1172 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1173 (*if term2str t' = "1 / 1" then () else error "rational.sml 8";3.6.03*)
1174 if term2str t' = "1" then () else error "rational.sml 8";
1176 (*............................vvv---TODO: sollte gehen mit poly_order *)
1177 (*Schalk I, p.92 Nr. 472a*)
1178 val t = str2term "((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
1179 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1180 if term2str t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
1182 (*Schalk I, p.70 Nr. 480b; a/b : c/d translated to a/b * d/c*)
1183 val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
1184 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
1185 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
1186 "(20*x*y/(x^^^2 - 25*y^^^2))");
1187 (*... nicht simpl, zerlegt ...*)
1188 val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
1189 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2))");
1190 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1191 "(-12 * (x * y ^^^ 3) + 108 * (x * (y * x ^^^ 2))) / (12 * (x * y))";
1192 (* ~~~~~~~~~~ poly_order notwendig!*)
1193 val t = str2term ("(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
1194 "(20*x*y/(x^^^2 - 25*y^^^2))");
1195 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1196 if term2str t' = "1 / (x ^^^ 2 + -25 * y ^^^ 2)" then ()
1197 else error "rational.sml norm_Rational 1 / (x ^^^ 2 + -25 * y ^^^ 2)";
1199 "nonterm.SK6 ----- SK060904-2a non-termination of add_fraction_p_";
1200 (*WN.2.6.03 from rlang.sml 56a
1201 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a ^^^ 2 + -1 * b ^^^ 2)";
1202 val NONE = rewrite_set_ thy false common_nominator_p t;
1204 WN060831 nonterm.SK7
1205 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
1206 val NONE = add_fraction_p_ thy t;
1210 (* ------------------------------------------------------------------- *)
1211 (*---------vvv------------ MG: ab 1.7.03 ----------------vvv-----------*)
1212 (* Simplifier fuer beliebige Buchterme *)
1213 (* ------------------------------------------------------------------- *)
1214 (*----------------------- norm_Rational_mg ----------------------------*)
1215 (* ------------------------------------------------------------------- *)
1217 "-------- numeral rationals -----------------------------";
1218 "-------- numeral rationals -----------------------------";
1219 "-------- numeral rationals -----------------------------";
1220 (*SRA Schalk I, p.40 Nr. 164b *)
1221 val t = str2term "(47/6 - 76/9 + 13/4)/(35/12)";
1222 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1224 if (term2str t) = "19 / 21" then ()
1225 else error "rational.sml: diff.behav. in norm_Rational_mg 1";
1227 (*SRA Schalk I, p.40 Nr. 166a *)
1228 val t = str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
1229 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1231 if (term2str t) = "45 / 2" then ()
1232 else error "rational.sml: diff.behav. in norm_Rational_mg 2";
1235 "-------- cancellation ----------------------------------";
1236 "-------- cancellation ----------------------------------";
1237 "-------- cancellation ----------------------------------";
1238 (* e190c Stefan K.*)
1240 "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
1241 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1244 "(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
1246 else error "rational.sml: diff.behav. in norm_Rational_mg 3";
1248 (* e192b Stefan K.*)
1250 "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
1251 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1256 else error "rational.sml: diff.behav. in norm_Rational_mg 4";
1258 (*SRC Schalk I, p.66 Nr. 379c *)
1261 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1266 else error "rational.sml: diff.behav. in norm_Rational_mg 5";
1268 (*SRC Schalk I, p.66 Nr. 380b *)
1270 "15*(3*x+3)*(4*x+9)/(12*(2*x+7)*(5*x+5))";
1271 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1274 "(27 + 12 * x) / (28 + 8 * x)"
1276 else error "rational.sml: diff.behav. in norm_Rational_mg 6";
1278 (*Schalk I, p.60 Nr. 215c *)
1279 (* Falsches Ergebnis: rechnet lange und cancel_p kann nicht weiter krzen!!!*)
1281 val t = str2term "(a+b)^^^4*(x - y)/((x - y)^^^3*(a+b)^^^2)";
1282 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1285 "(a ^^^ 4 * x + -1 * a ^^^ 4 * y + 4 * a ^^^ 3 * b * x + -4 * a ^^^ 3 * b * y + 6 * a ^^^ 2 * b ^^^ 2 * x + -6 * a ^^^ 2 * b ^^^ 2 * y + 4 * a * b ^^^ 3 * x + -4 * a * b ^^^ 3 * y + b ^^^ 4 * x + -1 * b ^^^ 4 * y) /(a ^^^ 2 * x ^^^ 3 + -3 * a ^^^ 2 * x ^^^ 2 * y + 3 * a ^^^ 2 * x * y ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 3 + 2 * a * b * x ^^^ 3 + -6 * a * b * x ^^^ 2 * y + 6 * a * b * x * y ^^^ 2 + -2 * a * b * y ^^^ 3 + b ^^^ 2 * x ^^^ 3 + -3 * b ^^^ 2 * x ^^^ 2 * y + 3 * b ^^^ 2 * x * y ^^^ 2 + -1 * b ^^^ 2 * y ^^^ 3)"
1287 else error "rational.sml: diff.behav. in norm_Rational_mg 7";
1290 "(a ^^^ 4 * x + -1 * a ^^^ 4 * y + 4 * a ^^^ 3 * b * x + -4 * a ^^^ 3 * b * y + 6 * a ^^^ 2 * b ^^^ 2 * x + -6 * a ^^^ 2 * b ^^^ 2 * y + 4 * a * b ^^^ 3 * x + -4 * a * b ^^^ 3 * y + b ^^^ 4 * x + -1 * b ^^^ 4 * y) /(a ^^^ 2 * x ^^^ 3 + -3 * a ^^^ 2 * x ^^^ 2 * y + 3 * a ^^^ 2 * x * y ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 3 + 2 * a * b * x ^^^ 3 + -6 * a * b * x ^^^ 2 * y + 6 * a * b * x * y ^^^ 2 + -2 * a * b * y ^^^ 3 + b ^^^ 2 * x ^^^ 3 + -3 * b ^^^ 2 * x ^^^ 2 * y + 3 * b ^^^ 2 * x * y ^^^ 2 + -1 * b ^^^ 2 * y ^^^ 3)"
1291 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1293 (* uncaught exception nonexhaustive binding failure
1294 raised at: stdIn:93.1-93.51 *)
1296 (*Schalk I, p.66 Nr. 381a *)
1297 (* ACHTUNG: rechnet ca. 2 Minuten !!! *)
1299 val t = str2term "18*(a+b)^^^3*(a - b)^^^2/(72*(a - b)^^^3*(a+b)^^^2)";
1300 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1303 "(a + b) / (4 * a + -4 * b)"
1304 then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
1307 (*SRC Schalk I, p.66 Nr. 381b *)
1309 "(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
1310 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1315 else error "rational.sml: diff.behav. in norm_Rational_mg 9";
1317 (*SRC Schalk I, p.66 Nr. 381c *)
1319 "(27*a^^^3+9*a^^^2+3*a+1)/(27*a^^^3+18*a^^^2+3*a)";
1320 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1323 "(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
1325 else error "rational.sml: diff.behav. in norm_Rational_mg 10";
1327 (*SRC Schalk I, p.66 Nr. 383a *)
1329 "(5*a^^^2 - 5*a*b)/(a - b)^^^2";
1330 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1333 "5 * a / (a + -1 * b)"
1335 else error "rational.sml: diff.behav. in norm_Rational_mg 11";
1338 "-------- common denominator ----------------------------";
1339 "-------- common denominator ----------------------------";
1340 "-------- common denominator ----------------------------";
1341 (*SRA Schalk I, p.67 Nr. 403a *)
1344 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1347 "(-3 * x + 4 * y + -1 * x * y) / (x * y)"
1349 else error "rational.sml: diff.behav. in norm_Rational_mg 12";
1351 (*SRA Schalk I, p.67 Nr. 407b *)
1353 "(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a^^^2+3*b*c)/(a*b*c)";
1354 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1359 else error "rational.sml: diff.behav. in norm_Rational_mg 13";
1361 (*SRA Schalk I, p.67 Nr. 410b *)
1363 "1/(x+1) + 1/(x+2) - 2/(x+3)";
1364 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1367 "(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)"
1369 else error "rational.sml: diff.behav. in norm_Rational_mg 14";
1371 (*SRA Schalk I, p.67 Nr. 413b *)
1373 "(1+x)/(1 - x) - (1 - x)/(1+x) + 2*x/(1 - x^^^2)";
1374 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1377 "6 * x / (1 + -1 * x ^^^ 2)"
1379 else error "rational.sml: diff.behav. in norm_Rational_mg 15";
1381 (*SRA Schalk I, p.68 Nr. 414a *)
1383 "(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))";
1384 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1387 "(-2 + -5 * x + 2 * x ^^^ 2) / (2 + -3 * x + x ^^^ 2)"
1389 else error "rational.sml: diff.behav. in norm_Rational_mg 16";
1391 (*SRA Schalk I, p.68 Nr. 423a *)
1393 "(2*x+3*y)/x + (4*x^^^3 - x*y^^^2 - 3*y^^^3)/(x^^^3 - 2*x^^^2*y+x*y^^^2) - (5*x+6*y)/(x - y)";
1394 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1399 else error "rational.sml: diff.behav. in norm_Rational_mg 17";
1401 (*SRA Schalk I, p.68 Nr. 428b *)
1403 "1/(a - b)^^^2 + 1/(a+b)^^^2 - 2/(a^^^2 - b^^^2) - 4*(b^^^2 - 1)/(a^^^2 - b^^^2)^^^2";
1404 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1407 "4 / (a ^^^ 4 + -2 * a ^^^ 2 * b ^^^ 2 + b ^^^ 4)"
1409 else error "rational.sml: diff.behav. in norm_Rational_mg 18";
1411 (*SRA Schalk I, p.68 Nr. 430b *)
1413 "a^^^2/(a - 3*b) - 108*a*b^^^3/((a+3*b)*(a^^^2 - 9*b^^^2)) - 9*b^^^2*(a - 3*b)/(a+3*b)^^^2";
1414 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1419 else error "rational.sml: diff.behav. in norm_Rational_mg 19";
1422 (*SRA Schalk I, p.68 Nr. 432 *)
1424 "(a^^^2+a*b)/(a^^^2 - b^^^2) - (b^^^2 - a*b)/(b^^^2 - a^^^2) + a^^^2*(a - b)/(a^^^3 - a^^^2*b) - 2*a*(a^^^2 - b^^^2)/(a^^^3 - a*b^^^2) - 2*b^^^2/(a^^^2 - b^^^2)";
1425 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1430 else error "rational.sml: diff.behav. in norm_Rational_mg 20";
1435 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1438 "(3 * y + b * x) / (b * y)"
1440 else error "rational.sml: diff.behav. in norm_Rational_mg 21";
1443 "-------- multiply and cancel ---------------------------";
1444 "-------- multiply and cancel ---------------------------";
1445 "-------- multiply and cancel ---------------------------";
1446 (*SRM Schalk I, p.68 Nr. 436a *)
1448 "3*(x+y)/(15*(x - y)) * 25*(x - y)^^^2/(18*(x+y)^^^2)";
1449 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1452 "(5 * x + -5 * y) / (18 * x + 18 * y)"
1454 else error "rational.sml: diff.behav. in norm_Rational_mg 22";
1456 (*SRM.test Schalk I, p.68 Nr. 436b *)
1457 (*WN060420???MG3 crashes with method 'simplify' in
1458 IsacCore > Simplification > Rational Terms > Multiplication > No.2*)
1459 val t = str2term "5*a*(a - b)^^^2*(a + b)^^^3/(7*b*(a - b)^^^3) * 7*b/(a + b)^^^3";
1460 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1463 "5 * a / (a + -1 * b)"
1465 else error "rational.sml: diff.behav. in norm_Rational_mg 23";
1467 (*Schalk I, p.68 Nr. 437a *)
1468 val t = str2term "(3*a - 4*b)/(4*c+3*e) * (3*a+4*b)/(9*a^^^2 - 16*b^^^2)";
1469 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1470 if (term2str t) = "1 / (4 * c + 3 * e)" then ()
1471 else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1473 "----- S.K. corrected non-termination 060904";
1474 val t = str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a^^^2 - 16*b^^^2))";
1475 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
1478 "(9 * a ^^^ 2 + -16 * b ^^^ 2) /\n(36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c +\n -48 * b ^^^ 2 * e)"
1479 (*"(9 * a ^^^ 2 + -16 * b ^^^ 2) / (36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c + -48 * b ^^^ 2 * e)"*)
1480 then () else error "rational.sml: S.K.8..corrected 060904-6";
1482 "----- S.K. corrected non-termination of cancel_p_";
1483 val t'' = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
1484 "(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
1485 val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
1486 if term2str t' = "1 / (4 * c + 3 * e)" then ()
1487 else error "rational.sml: diff.behav. in cancel_p S.K.8";
1489 (*Schalk I, p.68 Nr. 437b *)
1490 (* nonterm.SK9 loops: cancel_p kann nicht weiter kuerzen!!! *)
1491 val t'' = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
1492 (* val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t'';
1495 "================delete===";
1496 (*a casual output from above*)
1498 "(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)";
1499 (* WN060831 nonterm.SK10
1500 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1504 (*SRM Schalk I, p.68 Nr. 438a *)
1506 "x*y/(x*y - y^^^2)*(x^^^2 - x*y)";
1507 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1512 else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1514 (*SRM Schalk I, p.68 Nr. 439b *)
1516 "(4*x^^^2+4*x+1)*((x^^^2 - 2*x^^^3)/(4*x^^^2+2*x))";
1517 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1520 "(x + -4 * x ^^^ 3) / 2"
1522 else error "rational.sml: diff.behav. in norm_Rational_mg 25";
1524 (*SRM Schalk I, p.68 Nr. 440a *)
1526 "(x^^^2 - 2*x)/(x^^^2 - 3*x) * (x - 3)^^^2/(x^^^2 - 4)";
1527 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1530 "(-3 + x) / (2 + x)"
1532 else error "rational.sml: diff.behav. in norm_Rational_mg 26";
1534 "----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
1536 "(a^^^3 - 9*a)/(a^^^3*b - a*b^^^3)*(a^^^2*b+a*b^^^2)/(a+3)";
1537 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1538 if term2str t = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
1539 else error "rational.sml: diff.behav. in norm_Rational 27";
1541 "----- SK12 works since 0707xx";
1542 val t = str2term "(a^^^3 - 9*a)*(a^^^2*b+a*b^^^2)/((a^^^3*b - a*b^^^3)*(a+3))";
1543 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1544 if term2str t' = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
1545 else error "rational.sml: diff.behav. in norm_Rational 28";
1548 "-------- common denominator and multiplication ---------";
1549 "-------- common denominator and multiplication ---------";
1550 "-------- common denominator and multiplication ---------";
1551 (*SRAM Schalk I, p.69 Nr. 441b *)
1552 val t = str2term "(4*a/3 + 3*b^^^2/a^^^3 + b/(4*a))*(4*b/(3*a))";
1553 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1556 "(36 * b ^^^ 3 + 3 * a ^^^ 2 * b ^^^ 2 + 16 * a ^^^ 4 * b) / (9 * a ^^^ 4)"
1557 then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
1559 (*SRAM Schalk I, p.69 Nr. 442b *)
1560 val t = str2term "(15*a^^^2/x^^^3 - 5*b^^^4/x^^^2 + 25*c^^^2/x)*(x^^^3/(5*a*b^^^3*c^^^3)) + 1/c^^^3 * (b*x/a - 3*a/b^^^3)";
1561 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1564 "5 * x ^^^ 2 / (a * b ^^^ 3 * c)"
1565 then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
1567 (*SRAM Schalk I, p.69 Nr. 443b *)
1568 val t = str2term "(a/2 + b/3)*(b/3 - a/2)";
1569 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1572 "(-9 * a ^^^ 2 + 4 * b ^^^ 2) / 36"
1573 then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
1575 (*SRAM Schalk I, p.69 Nr. 445b *)
1576 val t = str2term "(a^^^2/9 + 2*a/(3*b) + 4/b^^^2)*(a/3 - 2/b) + 8/b^^^3";
1577 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1581 then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
1583 (*SRAM Schalk I, p.69 Nr. 446b *)
1584 val t = str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x^^^2 - 16*y^^^2)";
1585 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1588 "30 * x ^^^ 2 + -9 * x * y + -20 * y ^^^ 2"
1590 else error "rational.sml: diff.behav. in norm_Rational_mg 32";
1592 (*SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
1594 "(2*x^^^2/(3*y)+x/y^^^2)*(4*x^^^4/(9*y^^^2)+x^^^2/y^^^4)*(2*x^^^2/(3*y) - x/y^^^2)";
1595 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1597 if (term2str t) = "(-81 * x ^^^ 4 + 16 * x ^^^ 8 * y ^^^ 4) / (81 * y ^^^ 8)"
1598 then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
1601 (*SRAM Schalk I, p.69 Nr. 450a *)
1603 "(4*x/(3*y)+2*y/(3*x))^^^2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
1604 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1607 "(52 * x ^^^ 2 + 16 * y ^^^ 2) / (9 * y ^^^ 2)"
1609 else error "rational.sml: diff.behav. in norm_Rational_mg 34";
1612 "-------- double fractions ------------------------------";
1613 "-------- double fractions ------------------------------";
1614 "-------- double fractions ------------------------------";
1615 (*SRD Schalk I, p.69 Nr. 454b *)
1617 "((2 - x)/(2*a)) / (2*a/(x - 2))";
1618 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1621 "(-4 + 4 * x + -1 * x ^^^ 2) / (4 * a ^^^ 2)"
1623 else error "rational.sml: diff.behav. in norm_Rational_mg 35";
1625 (*SRD Schalk I, p.69 Nr. 455a *)
1627 "(a^^^2 + 1)/(a^^^2 - 1) / ((a+1)/(a - 1))";
1628 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1631 "(1 + a ^^^ 2) / (1 + 2 * a + a ^^^ 2)" then ()
1632 else error "rational.sml: diff.behav. in norm_Rational_mg 36";
1635 "----- Schalk I, p.69 Nr. 455b";
1636 val t = str2term "(x^^^2 - 4)/(y^^^2 - 9)/((2+x)/(3 - y))";
1637 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1638 if term2str t = "(2 + -1 * x) / (3 + y)" then ()
1639 else error "rational.sml: diff.behav. in norm_Rational_mg 37";
1641 "----- SK060904-1a non-termination of cancel_p_ ?: worked before 0707xx";
1642 val t = str2term "(x^^^2 - 4)*(3 - y)/((y^^^2 - 9)*(2+x))";
1643 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1644 if term2str t = "(2 + -1 * x) / (3 + y)" then ()
1645 else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
1647 "----- ?: worked before 0707xx";
1648 val t = str2term "(3 + -1 * y) / (-9 + y ^^^ 2)";
1649 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1650 if term2str t = "-1 / (3 + y)" then ()
1651 else error "rational.sml: -1 / (3 + y) norm_Rational";
1653 (*SRD Schalk I, p.69 Nr. 456b *)
1655 "(b^^^3 - b^^^2)/(b^^^2+b)/(b^^^2 - 1)";
1656 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1658 if (term2str t) = "b / (1 + 2 * b + b ^^^ 2)" then ()
1659 else error "rational.sml: diff.behav. in norm_Rational_mg 38";
1661 (*SRD Schalk I, p.69 Nr. 457b *)
1663 "(16*a^^^2 - 9*b^^^2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a^^^2 - 9*a^^^2*b^^^2))";
1664 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1667 "8 * a ^^^ 2 + -6 * a * b + -12 * a ^^^ 2 * b + 9 * a * b ^^^ 2"
1668 then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
1670 "----- Schalk I, p.69 Nr. 458b works since 0707";
1672 "(2*a^^^2*x - a^^^2)/(a*x - b*x) / (b^^^2*(2*x - 1)/(x*(a - b)))";
1673 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1674 if term2str t = "a ^^^ 2 / b ^^^ 2" then ()
1675 else error "rational.sml: diff.behav. in norm_Rational_mg 39b";
1677 (*SRD Schalk I, p.69 Nr. 459b *)
1678 val t = str2term "(a^^^2 - b^^^2)/(a*b) / (4*(a+b)^^^2/a)";
1679 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1680 if term2str t = "(a + -1 * b) / (4 * a * b + 4 * b ^^^ 2)" then ()
1681 else error "rational.sml: diff.behav. in norm_Rational_mg 41";
1684 (*Schalk I, p.69 Nr. 460b nonterm.SK
1686 "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
1687 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1690 else error "rational.sml: diff.behav. in norm_Rational_mg 42";
1693 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
1694 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
1695 ... non terminating.
1696 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
1697 "(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)";
1698 val SOME (t,_) = rewrite_set_ thy false cancel_p t';
1699 ... non terminating.*)
1701 (*SRD Schalk I, p.70 Nr. 472a *)
1702 val t = str2term ("((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/" ^
1703 "((4*x - 8*y)/(x + y))");
1704 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1709 else error "rational.sml: diff.behav. in norm_Rational_mg 43";
1712 (*----------------------------------------------------------------------*)
1713 (*---------------------- Einfache Dppelbrche --------------------------*)
1714 (*----------------------------------------------------------------------*)
1716 (*SRD Schalk I, p.69 Nr. 461a *)
1718 "(2/(x+3) + 2/(x - 3)) / (8*x/(x^^^2 - 9))";
1719 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1724 else error "rational.sml: diff.behav. in norm_Rational_mg 44";
1726 (*SRD Schalk I, p.69 Nr. 464b *)
1728 "(a - a/(a - 2)) / (a + a/(a - 2))";
1729 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1732 "(3 + -1 * a) / (1 + -1 * a)"
1734 else error "rational.sml: diff.behav. in norm_Rational_mg 45";
1736 (*SRD Schalk I, p.69 Nr. 465b *)
1738 "((x+3*y)/9 + (4*y^^^2 - 9*z^^^2)/(16*x)) /(x/9+y/6+z/4)";
1739 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1742 "(4 * x + 6 * y + -9 * z) / (4 * x)"
1744 else error "rational.sml: diff.behav. in norm_Rational_mg 46";
1746 (*SRD Schalk I, p.69 Nr. 466b *)
1748 "((1 - 7*(x - 2)/(x^^^2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x^^^2 - 25))";
1749 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1752 "(25 + -10 * x + x ^^^ 2) / 18"
1754 else error "rational.sml: diff.behav. in norm_Rational_mg 47";
1756 (*SRD Schalk I, p.70 Nr. 469 *)
1758 "3*b^^^2/(4*a^^^2 - 8*a*b + 4*b^^^2)/(a/(a^^^2*b - b^^^3) + (a - b)/(4*a*b^^^2+4*b^^^3) - 1/(4*b^^^2))";
1759 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1762 "3 * b ^^^ 3 / (2 * a + -2 * b)"
1764 else error "rational.sml: diff.behav. in norm_Rational_mg 48";
1766 (*----------------------------------------------------------------------*)
1767 (*---------------------- Mehrfache Dppelbrueche ------------------------*)
1768 (*----------------------------------------------------------------------*)
1770 (*SRD.test Schalk I, p.70 Nr. 476b *) (* Rechenzeit: 10 sec *)
1771 (*WN060419 crashes with method 'simplify' ????SK*)
1773 "((a^^^2 - b^^^2)/(2*a*b)+2*a*b/(a^^^2 - b^^^2))/((a^^^2+b^^^2)/(2*a*b)+1) / ((a^^^2+b^^^2)^^^2/(a+b)^^^2)";
1774 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1775 if term2str t = "1 / (a ^^^ 2 + -1 * b ^^^ 2)" then ()
1776 else error "rational.sml: diff.behav. in norm_Rational_mg 49";
1778 "----- Schalk I, p.70 Nr. 477a";
1779 (* MG Achtung: terme explodieren; Bsp zu komplex;
1780 L???ung sollte (ziemlich grosser) Faktorisierter Ausdruck sein
1781 val t = str2term "b*y/(b - 2*y)/((b^^^2 - y^^^2)/(b+2*y)) /" ^
1782 "(b^^^2*y+b*y^^^2)*(a+x)^^^2/((b^^^2 - 4*y^^^2)*(a+2*x)^^^2)";
1783 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
1786 val t = str2term "b*y*(b+2*y)*(b^^^2 - 4*y^^^2)*(a+2*x)^^^2 / " ^
1787 "((b - 2*y)*(b^^^2 - y^^^2)*(b^^^2*y+b*y^^^2)*(a+x)^^^2)";
1788 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
1792 "----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
1793 val t = str2term ("(a - (a*b+b^^^2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
1794 "((a - a^^^2/(a+b))/(a+(a*b)/(a - b)))");
1795 val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1797 "(2 * a ^^^ 3 + 2 * a ^^^ 2 * b) / (a ^^^ 2 * b + b ^^^ 3)"
1799 else error "rational.sml: diff.behav. in norm_Rational_mg 51";
1801 (* TODO.new_c:WN050820 STOP_REW_SUB introduced gave ...
1802 if term2str t' = "(a ^^^ 4 + -1 * a ^^^ 2 * b ^^^ 2) /(a * b * (b + (a * (a + -1 * b) + -1 * b * (a + -1 * b)) / (2 * a)) * (a + -1 * b))" then ()
1803 else error "rational.sml: works again";
1804 re-outcommented with TODO.new_c: cvs before 071227, 11:50*)
1808 (*Schalk I, p.70 Nr. 480a *)
1809 (* Achtung: rechnet ewig; cancel_p kann nicht krzen: WN060831 nonterm.SK00
1811 "(1/x+1/y+1/z)/(1/x - 1/y - 1/z) / (2*x^^^2/(x^^^2 - z^^^2)/(x/(x+z)+x/(x - z)))";
1812 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1817 else error "rational.sml: diff.behav. in norm_Rational_mg 52";
1819 (*MG Berechne Zwischenergebnisse: WN060831 nonterm.SK00*)
1821 "(1/x+1/y+1/z)/(1/x - 1/y - 1/z)";
1822 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1824 "(x ^^^ 2 * y ^^^ 2 * z + x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2) /
1825 (-1 * x ^^^ 2 * y ^^^ 2 * z + -1 * x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2)";
1827 "2*x^^^2/(x^^^2 - z^^^2)/(x/(x+z)+x/(x - z))";
1828 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1832 (* SK 1. Ausdruck kann nicht weiter gekrzt werden; cancel_p !!!*)
1833 ### rls: cancel_p on:
1834 (x ^^^ 2 * (y ^^^ 2 * z) + x ^^^ 2 * (y * z ^^^ 2) + x * (y ^^^ 2 * z ^^^ 2)) /
1835 (-1 * (x ^^^ 2 * (y ^^^ 2 * z)) + -1 * (x ^^^ 2 * (y * z ^^^ 2)) + x * (y ^^^ 2 * z ^^^ 2))
1836 GC #3.61.81.101.197.17503: (0 ms)
1837 *** RATIONALS_DIRECT_CANCEL_EXCEPTION: Invalid fraction
1840 "(x^^^2 * (y^^^2 * z) + x^^^2 * (y * z^^^2) + x * (y^^^2 * z^^^2)) / (-1 * (x^^^2 * (y^^^2 * z)) + -1 * (x^^^2 * (y * z^^^2)) + x * (y^^^2 * z^^^2))";
1841 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1843 (*uncaught exception nonexhaustive binding failure*)
1845 (* Das kann er aber krzen !!????: *)
1847 "(x^^^2 * (y^^^2 * z) + x * (y^^^2 * z^^^2)) / (-1 * (x^^^2 * (y * z^^^2)) + x * (y^^^2 * z^^^2))";
1848 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1850 "(-1 * (y * x) + -1 * (z * y)) / (1 * (z * x) + -1 * (z * y))";
1854 "-------- crucial examples ------------------------------";
1855 "-------- crucial examples ------------------------------";
1856 "-------- crucial examples ------------------------------";
1857 (*Schalk I, p.60 Nr. 215d *)
1858 (* Achtung: rechnet ewig ...
1859 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
1860 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1861 term2str t; noterm.SK
1864 (* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt:*)
1866 val t = str2term "(a-b)^^^3 * (x+y)^^^4";
1867 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1869 "a^^^3 * x^^^4 + 4 * a^^^3 * x^^^3 * y +6 * a^^^3 * x^^^2 * y^^^2 +4 * a^^^3 * x * y^^^3 +a^^^3 * y^^^4 +-3 * a^^^2 * b * x^^^4 +-12 * a^^^2 * b * x^^^3 * y +-18 * a^^^2 * b * x^^^2 * y^^^2 +-12 * a^^^2 * b * x * y^^^3 +-3 * a^^^2 * b * y^^^4 +3 * a * b^^^2 * x^^^4 +12 * a * b^^^2 * x^^^3 * y +18 * a * b^^^2 * x^^^2 * y^^^2 +12 * a * b^^^2 * x * y^^^3 +3 * a * b^^^2 * y^^^4 +-1 * b^^^3 * x^^^4 +-4 * b^^^3 * x^^^3 * y +-6 * b^^^3 * x^^^2 * y^^^2 +-4 * b^^^3 * x * y^^^3 +-1 * b^^^3 * y^^^4";
1870 val t = str2term "((x+y)^^^2 * (a-b)^^^5)";
1871 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1873 "a^^^5 * x^^^2 + 2 * a^^^5 * x * y + a^^^5 * y^^^2 +-5 * a^^^4 * b * x^^^2 +-10 * a^^^4 * b * x * y +-5 * a^^^4 * b * y^^^2 +10 * a^^^3 * b^^^2 * x^^^2 +20 * a^^^3 * b^^^2 * x * y +10 * a^^^3 * b^^^2 * y^^^2 +-10 * a^^^2 * b^^^3 * x^^^2 +-20 * a^^^2 * b^^^3 * x * y +-10 * a^^^2 * b^^^3 * y^^^2 +5 * a * b^^^4 * x^^^2 +10 * a * b^^^4 * x * y +5 * a * b^^^4 * y^^^2 +-1 * b^^^5 * x^^^2 +-2 * b^^^5 * x * y +-1 * b^^^5 * y^^^2";
1875 (*anscheinend macht dem Rechner das Krzen diese Bruches keinen Spass mehr ...*)
1877 (*--------------------------------------------------------------------*)
1878 (*Schalk I, p.70 Nr. 480b
1879 val t = str2term "((12*x*y/(9*x^^^2 - y^^^2))/" ^
1880 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
1881 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
1882 "(20*x*y/(x^^^2 - 25*y^^^2))";
1883 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1885 Kann nicht weiter vereinfacht werden !!!!?? *)
1887 (*--------------------------------------------------------------------*)
1888 "---- MGs test set";
1889 val t = str2term " (1 + x^^^5) / (y + x) + x^^^3 / x ";
1890 val SOME (t,_) = rewrite_set_ thy false common_nominator_p t;
1891 if term2str t = "(1 + x ^^^ 3 + x ^^^ 5 + y * x ^^^ 2) / (x + y)" then()
1894 (*--------------------------------------------------------------------*)
1895 (* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3b
1896 ---> Sortierung FALSCH !! *)
1897 val t = str2term "b^^^3 * a^^^5/a ";
1898 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1900 "1 * (a^^^4 * b^^^3) / 1"; (*OK*)
1902 val t = str2term "b^^^3 * a^^^5/b ";
1903 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1905 "1 * (b^^^2 * a^^^5) / 1"; (*cancel_p sortiert hier falsch um!*)
1907 (* Problem liegt NICHT bei ord_make_polynomial! (siehe folgende Bsple) *)
1909 val x = str2term "x"; val bdv = str2term "bdv";
1910 val t1 = str2term "b^^^2 * a^^^5";
1911 val t2 = str2term "a^^^5 * b^^^2 ";
1912 ord_make_polynomial false Rational.thy [(x,bdv)] (t1,t2); (*false*)
1914 (* ==> "b^^^2 * a^^^5" > "a^^^5 * b^^^2 " ... OK!*)
1916 (*--------------------------------------------------------------------*)
1917 (* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3c
1918 ---> erzeugt berflssige "1 * ..."
1920 val t = str2term "-1 / (3 + y)";
1922 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1925 (********* Das ist das PROBLEM !!!!!!!??? *******************)
1926 (* -1 im Z???ler der Angabe verursacht das Problem !*)
1929 (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
1930 "----- MGs test set";
1931 val t = str2term "(a^^^2 + -1)/(a+1)";
1932 val SOME (t',_) = rewrite_set_ thy false cancel_p t;
1933 if term2str t' = "(-1 + a) / 1" then ()
1934 else error "rational.sml MG tests 3d";
1936 "----- NOT TERMINATING ?: worked before 0707xx";
1937 val t = str2term "(a^^^2 - 1)*(b + 1) / ((b^^^2 - 1)*(a+1))";
1938 val SOME (t'',_) = rewrite_set_ thy false norm_Rational t;
1939 if term2str t'' = "(1 + -1 * a) / (1 + -1 * b)" then ()
1940 else error "rational.sml MG tests 3e";
1942 "----- corrected SK060905";
1943 val t = str2term "(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
1944 val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1945 if term2str t' = "-1 / (5 + -2 * x)" then ()
1946 else error "rational.sml corrected SK060905";
1949 "-------- examples for Stefan Karnels thesis ------------";
1950 "-------- examples for Stefan Karnels thesis ------------";
1951 "-------- examples for Stefan Karnels thesis ------------";
1952 (*SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*)
1954 "(15*a^^^4/(a*x^^^3) - 5*a*((b^^^4 - 5*c^^^2*x)/x^^^2))*(x^^^3/(5*a*b^^^3*c^^^3)) + a/c^^^3 * (x*(b/a) - 3*b*(a/b^^^4))";
1955 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1958 "5 * x ^^^ 2 / (b ^^^ 3 * c)"
1960 else error "rational.sml: diff.behav. in norm_Rational_mg 53";
1963 "-------- me Schalk I No.186 ----------------------------";
1964 "-------- me Schalk I No.186 ----------------------------";
1965 "-------- me Schalk I No.186 ----------------------------";
1966 val fmz = ["Term ((14 * x * y) / ( x * y ))",
1969 ("Rational",["rational","simplification"],
1970 ["simplification","of_rationals"]);
1971 val p = e_pos'; val c = [];
1972 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
1973 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1974 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1975 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1976 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1977 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1978 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1979 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1980 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1981 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1982 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1983 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1984 case (f2str f, nxt) of
1985 ("14", ("End_Proof'", _)) => ()
1986 | _ => error "rational.sml diff.behav. in me Schalk I No.186";
1989 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
1990 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
1991 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
1994 [(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"],
1995 ("Rational",["rational","simplification"],
1996 ["simplification","of_rationals"]))];
1999 autoCalculate 1 CompleteCalc;
2000 val ((pt,p),_) = get_calc 1; show_pt pt;
2002 interSteps 1 ([1],Res);
2003 val ((pt,p),_) = get_calc 1; show_pt pt;
2006 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
2007 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
2008 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
2011 [(["Term ((a^2 + -1*b^2) / (a^2 + -2*a*b + b^2))", "normalform N"],
2012 ("Rational",["rational","simplification"],
2013 ["simplification","of_rationals"]))];
2016 autoCalculate 1 CompleteCalc;
2017 val ((pt,p),_) = get_calc 1; show_pt pt;
2018 (*========== inhibit exn 110314 ================================================
2019 (*with explicit script done already... and removed [1,..] at below...
2020 interSteps 1 ([1],Res);
2021 val ((pt,p),_) = get_calc 1; show_pt pt;
2023 interSteps 1 ([2],Res);
2024 val ((pt,p),_) = get_calc 1; show_pt pt;
2026 interSteps 1 ([2,1],Res);
2027 val ((pt,p),_) = get_calc 1; show_pt pt;
2028 val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*);
2029 (*if length newnds = 12 then () WN060905*)
2030 if length newnds = 13 then ()
2031 else error "rational.sml: interSteps cancel_p rev_rew_p";
2033 val p = ([2,1,9],Res);
2035 val (_, tac, _) = pt_extract (pt, p);
2036 (*case tac of SOME (Rewrite ("sym_real_plus_binom_times1", _)) => ()
2038 case tac of SOME (Rewrite ("sym_real_add_mult_distrib2", _)) => ()
2039 | _ => error "rational.sml: getTactic, sym_real_plus_binom_times1";
2040 ============ inhibit exn 110314 ==============================================*)
2043 "-------- investigate rulesets for cancel_p -------------";
2044 "-------- investigate rulesets for cancel_p -------------";
2045 "-------- investigate rulesets for cancel_p -------------";
2046 val thy = @{theory "Rational"};
2047 "---------------- (a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
2048 val t = str2term "(a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
2049 val tt = str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"(*numerator only*);
2050 "----- with rewrite_set_";
2051 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
2052 term2str tt'= "a ^^^ 2 + -1 * b ^^^ 2" (*true*);
2053 val tt = str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*);
2054 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
2055 term2str tt' = "a ^^^ 2 + -2 * a * b + b ^^^ 2" (*true*);
2057 "----- with make_deriv";
2058 val SOME (tt, _) = factout_p_ thy t; term2str tt =
2059 "(1 * a + 1 * b) * (1 * a + -1 * b) / ((1 * a + -1 * b) * (1 * a + -1 * b))";
2061 "--- with ruleset as before 060829";
2062 val {rules, rew_ord=(_,ro),...} =
2063 rep_rls (assoc_rls "make_polynomial");
2064 val der = make_deriv thy Atools_erls rules ro NONE tt;
2065 print_depth 99; map (term2str o #1) der; print_depth 3;
2066 print_depth 99; map (rule2str o #2) der; print_depth 3;
2067 ... did not terminate*)
2068 "--- with simpler ruleset";
2069 val {rules, rew_ord=(_,ro),...} =
2070 rep_rls (assoc_rls "rev_rew_p");
2071 val der = make_deriv thy Atools_erls rules ro NONE tt;
2072 print_depth 99; writeln (deriv2str der); print_depth 3;
2074 print_depth 99; map (term2str o #1) der; print_depth 3;
2075 "...,(-1 * b ^^^ 2 + a ^^^ 2) / (-2 * (a * b) + a ^^^ 2 + (-1 * b) ^^^ 2) ]";
2076 print_depth 99; map (rule2str o #2) der; print_depth 3;
2077 print_depth 99; map (term2str o #1 o #3) der; print_depth 3;
2079 val der = make_deriv thy Atools_erls rules ro NONE
2080 (str2term "(1 * a + 1 * b) * (1 * a + -1 * b)");
2081 print_depth 99; writeln (deriv2str der); print_depth 3;
2083 val {rules, rew_ord=(_,ro),...} =
2084 rep_rls (assoc_rls "rev_rew_p");
2085 val der = make_deriv thy Atools_erls rules ro NONE
2086 (str2term "(1 * a + -1 * b) * (1 * a + -1 * b)");
2087 print_depth 99; writeln (deriv2str der); print_depth 3;
2088 print_depth 99; map (term2str o #1) der; print_depth 3;
2089 (*WN060829 ...postponed*)
2092 "-------- investigate format of factout_ and factout_p_ -";
2093 "-------- investigate format of factout_ and factout_p_ -";
2094 "-------- investigate format of factout_ and factout_p_ -";
2095 val {rules, rew_ord = (_,ro),...} = rep_rls (assoc_rls "make_polynomial");
2096 val (thy, eval_rls) = (@{theory "Rational"}, Atools_erls)(*see 'fun init_state'*);
2097 val Rrls {scr = Rfuns {init_state,...},...} = assoc_rls "cancel_p";
2099 "----- see Rational.ML, local cancel_p, fun init_state";
2100 val t = str2term "(a^^^2 + (-1)*b^^^2) / (a^^^2 + (-2)*a*b + b^^^2)";
2101 val SOME (t',_) = factout_p_ thy t; term2str t';
2103 val rtas = reverse_deriv thy eval_rls rules ro NONE t';
2104 writeln(trtas2str rst);
2108 "----- see Rational.ML, local cancel_p, fun init_state";
2109 val t = str2term "a^^^2 / a";
2110 val SOME (t',_) = factout_p_ thy t;
2111 term2str t' = "a * a / (1 * a)" (*true*);
2112 (*... can be canceled with
2113 real_mult_div_cancel2 ?k ~= 0 ==> ?m * ?k / (?n * ?k) = ?m / ?n"*)
2114 (* sml/ME/rewtools.sml:
2115 val rtas = reverse_deriv thy Atools_erls rules ro NONE t';
2116 writeln (deri2str rtas);
2120 "-------- SK 060904 ----------------------------------------------";
2121 "----- order on polynomials -- input + output";
2122 val thy = @{theory "Isac"};
2123 val t = str2term "(a + -1 * b) / (-1 * a + b)";
2124 val SOME (t', _) = factout_p_ thy t; term2str t';
2125 val SOME (t', _) = cancel_p_ thy t; term2str t';
2127 val t = str2term "a*b*c*d / (d*e*f*g)";
2128 val SOME (t', _) = cancel_p_ thy t; term2str t';
2130 val t = str2term "a*(b*(c*d)) / (b*(e*(f*g)))";
2131 val SOME (t', _) = cancel_p_ thy t; term2str t';
2134 "----- SK060904-1a non-termination of cancel_p_ ? worked before 0707xx";
2135 val t = str2term "(x^^^2 - 4)*(3 - y) / ((y^^^2 - 9)*(2+x))";
2136 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
2137 if term2str t' = "(2 + -1 * x) / (3 + y)" then ()
2138 else error "rational.sml SK060904-1a worked since 0707xx";
2140 "----- SK060904-1b non-termination of cancel_p_ ... worked before 0707xx";
2141 val t = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
2142 "(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
2143 val SOME (t',_) = cancel_p_ thy t;
2144 if term2str t' = "1 / (4 * c + 3 * e)" then ()
2145 else error "rational.sml SK060904-1b";
2148 "----- SK060904-2a non-termination of add_fraction_p_";
2149 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^
2150 " (-1 * a + b * x) / (a + b * x) ");
2152 val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
2154 common_nominator_p_ thy t;
2155 " (a + b * x)*(a + b * x) / ((a + -1 * (b * x))*(a + -1 * (b * x))) + " ^
2156 " (-1 * a + b * x)*(a + -1 * (b * x)) / ((a + b * x)*(-1 * a + b * x)) ";
2158 add_fraction_p_ thy t;
2159 " ((a + b * x)*(a + b * x) + (-1 * a + b * x)*(a + -1 * (b * x))) /" ^
2160 " ((a + b * x)*(-1 * a + b * x)) ";
2164 "-------- how to stepwise construct Scripts -------------";
2165 "-------- how to stepwise construct Scripts -------------";
2166 "-------- how to stepwise construct Scripts -------------";
2167 val thy = @{theory "Rational"};
2169 val p1 = parse thy (
2170 "Script SimplifyScript (t_t::real) = " ^
2171 " (Rewrite_Set discard_minus False " ^
2174 (*required (): (Rewrite_Set discard_minus False)*)
2175 val p2 = parse thy (
2176 "Script SimplifyScript (t_t::real) = " ^
2177 " (Rewrite_Set discard_minus False " ^
2180 val p3 = parse thy (
2181 "Script SimplifyScript (t_t::real) = " ^
2182 " ((Rewrite_Set discard_minus False) " ^
2185 val p4 = parse thy (
2186 "Script SimplifyScript (t_t::real) = " ^
2187 " ((Rewrite_Set discard_minus False) " ^
2190 val p5 = parse thy (
2191 "Script SimplifyScript (t_t::real) = " ^
2192 " ((Try (Rewrite_Set discard_minus False) " ^
2193 " Try (Rewrite_Set discard_parentheses False)) " ^
2196 val p6 = parse thy (
2197 "Script SimplifyScript (t_t::real) = " ^
2198 " ((Try (Rewrite_Set discard_minus False) @@ " ^
2199 " Try (Rewrite_Set rat_mult_poly False) @@ " ^
2200 " Try (Rewrite_Set make_rat_poly_with_parentheses False) @@ " ^
2201 " Try (Rewrite_Set cancel_p_rls False) @@ " ^
2203 " ((Try (Rewrite_Set common_nominator_p_rls False) @@ " ^
2204 " Try (Rewrite_Set rat_mult_div_pow False) @@ " ^
2205 " Try (Rewrite_Set make_rat_poly_with_parentheses False) @@" ^
2206 " Try (Rewrite_Set cancel_p_rls False) @@ " ^
2207 " Try (Rewrite_Set rat_reduce_1 False)))) @@ " ^
2208 " Try (Rewrite_Set discard_parentheses False)) " ^
2212 "----------- get_denominator ----------------------------";
2213 "----------- get_denominator ----------------------------";
2214 "----------- get_denominator ----------------------------";
2215 val thy = @{theory Isac};
2216 val t = term_of (the (parse thy "get_denominator ((a +x)/b)"));
2217 val SOME (_, t') = eval_get_denominator "" 0 t thy;
2218 if term2str t' = "get_denominator ((a + x) / b) = b" then ()
2219 else error "get_denominator ((a + x) / b) = b"
2222 "--------- several errpats in complicated term -------------------";
2223 "--------- several errpats in complicated term -------------------";
2224 "--------- several errpats in complicated term -------------------";
2225 (*TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one*)
2228 [(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"],
2229 ("Rational",["rational","simplification"], ["simplification","of_rationals"]))];
2232 autoCalculate 1 CompleteCalc;
2233 val ((pt,p),_) = get_calc 1; show_pt pt;
2235 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
2236 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
2237 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
2238 (*------------------------------------------------------------------------------------\
2239 "--- WN121204: searched rational.sml for "nonterm", added new numbering" ^
2240 " and thoroughly tested with this numbering subsequently";
2242 WN.2.6.03 from rlang.sml 56a
2243 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a ^^^ 2 + -1 * b ^^^ 2)";
2244 val NONE = rewrite_set_ thy false common_nominator_p t;
2246 WN060831 nonterm.SK7
2247 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
2248 val NONE = add_fraction_p_ thy t;
2250 nonterm.SK9 loops: cancel_p kann nicht weiter kuerzen!!! *)
2251 val t'' = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
2252 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t'';
2255 "(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)";
2256 WN060831 nonterm.SK10
2257 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
2261 "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
2262 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2265 else error "rational.sml: diff.behav. in norm_Rational_mg 42";
2268 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
2269 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
2270 ... non terminating.
2272 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
2273 "(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)";
2274 val SOME (t,_) = rewrite_set_ thy false cancel_p t';
2276 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
2277 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2279 val t = str2term "((12*x*y/(9*x^^^2 - y^^^2))/" ^
2280 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
2281 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
2282 "(20*x*y/(x^^^2 - 25*y^^^2))";
2283 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2285 SK060904-2a non-termination of add_fraction_p_";
2286 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^
2287 " (-1 * a + b * x) / (a + b * x) ");
2289 val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
2291 common_nominator_p_ thy t;
2292 " (a + b * x)*(a + b * x) / ((a + -1 * (b * x))*(a + -1 * (b * x))) + " ^
2293 " (-1 * a + b * x)*(a + -1 * (b * x)) / ((a + b * x)*(-1 * a + b * x)) ";
2295 add_fraction_p_ thy t;
2296 " ((a + b * x)*(a + b * x) + (-1 * a + b * x)*(a + -1 * (b * x))) /" ^
2297 " ((a + b * x)*(-1 * a + b * x)) ";
2298 --------------------------------------------------------------------------------------/*)
2300 (*------------------------------------------------------------------------------------\
2301 "WN121205: thoroughly tested with the above numbering.";
2302 " errors in cancel_p: --- 4,5,6,7.";
2303 " error in common_nominator_p, common_nominator_p_: --- 10; 1,2?.";
2304 " errors caused by ruleset norm_Rational: --- 8,9.";
2305 trace_rewrite := true;
2307 "--- 1 ---: non-terminating with ### add_fract: done t22 ";
2308 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a ^^^ 2 + -1 * b ^^^ 2)";
2309 trace_rewrite:= true;
2310 rewrite_set_ thy false common_nominator_p t;
2312 "--- 2 ---: non-terminating with ### add_fract: done t22 ";
2313 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
2314 add_fraction_p_ thy t;
2316 "--- 3 ---: norm_Rational calls Rrls cancel_p with non-normalised polys";
2317 val t = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
2318 rewrite_set_ thy false norm_Rational t;
2319 (*tracing end...#### rls: cancel_p on:
2320 (a * x ^^^ 2 + -2 * (a * (x * y)) + a * y ^^^ 2 + b * x ^^^ 2 + -2 * (b * (x * y)) + b * y ^^^ 2) /
2321 (a ^^^ 2 * x ^^^ 2 + -1 * (a ^^^ 2 * y ^^^ 2) + -1 * (b ^^^ 2 * x ^^^ 2) + b ^^^ 2 * y ^^^ 2) *)
2323 "--- 4 ---: non-terminating with Rrls cancel_p on plausible input";
2325 "(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /"^
2326 "(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)");
2327 rewrite_set_ thy false cancel_p t;
2328 (*# rls: cancel_p on:
2329 (a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /
2330 (a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2) *)
2332 "--- 5 ---: non-terminating with Rrls cancel_p on plausible input";
2333 val t = str2term "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
2334 rewrite_set_ thy false norm_Rational t;
2335 (*#### rls: cancel_p on:
2336 (2304 + -1152 * x + -2304 * y + 144 * x ^^^ 2 + 1152 * (x * y) + -144 * (x ^^^ 2 * y)) /
2337 (48 + -12 * x + -96 * y + 24 * (x * y) + 48 * y ^^^ 2 + -12 * (x * y ^^^ 2)) *)
2339 "--- 6 ---: non-terminating with Rrls cancel_p on plausible input";
2341 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
2342 rewrite_set_ thy false norm_Rational t;
2343 (*### rls: cancel_p on: (-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * (x * y) +
2344 144 * (x ^^^ 2 * y)) /
2345 (-48 + 12 * x + 96 * y + -24 * (x * y) + -48 * y ^^^ 2 + 12 * (x * y ^^^ 2)) *)
2347 "--- 7 ---: non-terminating with Rrls cancel_p on plausible input";
2349 "(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /"^
2350 "(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)");
2351 rewrite_set_ thy false cancel_p t';
2353 "--- 8 ---: bottom of output cannot be looked ad (due to looping?)";
2354 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
2355 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
2357 "--- 9 ---: probably error in norm_Rational";
2359 "((12*x*y / (9*x^^^2 - y^^^2)) / (1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
2360 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2) / (20*x*y/(x^^^2 - 25*y^^^2))");
2361 rewrite_set_ thy false norm_Rational t;
2362 (*#### rls: cancel_p on: (19440 * (x ^^^ 8 * y ^^^ 2) + -490320 * (x ^^^ 6 * y ^^^ 4) +
2363 108240 * (x ^^^ 4 * y ^^^ 6) +
2364 -6000 * (x ^^^ 2 * y ^^^ 8)) /
2365 (2160 * (x ^^^ 8 * y ^^^ 2) + -108240 * (x ^^^ 6 * y ^^^ 4) +
2366 1362000 * (x ^^^ 4 * y ^^^ 6) +
2367 -150000 * (x ^^^ 2 * y ^^^ 8)) *)
2369 "--- 10 ---: non-terminating with ### add_fract: done t22: error in common_nominator_p ";
2370 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)");
2371 rewrite_set_ thy false common_nominator_p t; (*### add_fract: done t22 *)
2372 common_nominator_p_ thy t; (*loops without output*)
2373 "--- reformulated 10:";
2374 val t = str2term "(a + -1 * (b * x)) / (a + b * x)";
2375 rewrite_set_ thy false cancel_p t = NONE;
2378 "...both are to be considered after common_nominator_p_ is improved";
2379 --------------------------------------------------------------------------------------/*)
2380 ============ inhibit exn WN130824 TODO ======================================================*)