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 "--------------------------------------------------------";
18 "--------------------------------------------------------";
19 "table of contents --------------------------------------";
20 "--------------------------------------------------------";
21 "~~~~~BEGIN: decomment structure RationalI : RATIONALI ~~";
22 "-------- ... missing WN060103 --------------------------";
23 "-------- fun monom2term, fun poly2term' ---------------";
24 "~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
25 "-------- external calculating functions test -----------";
26 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
27 "-------- common_nominator_p ----------------------------";
28 "-------- reverse rewrite -------------------------------";
29 "-------- 'reverse-ruleset' cancel_p --------------------";
30 "-------- norm_Rational ---------------------------------";
31 "-------- numeral rationals -----------------------------";
32 "-------- cancellation ----------------------------------";
33 "-------- common denominator ----------------------------";
34 "-------- multiply and cancel ---------------------------";
35 "-------- common denominator and multiplication ---------";
36 "-------- double fractions ------------------------------";
37 "-------- crucial examples ------------------------------";
38 "-------- examples for Stefan Karnels thesis ------------";
39 "-------- me Schalk I No.186 ----------------------------";
40 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
41 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
42 "-------- investigate rulesets for cancel_p -------------";
43 "-------- investigate format of factout_ and factout_p_ -";
44 "-------- how to stepwise construct Scripts -------------";
45 "----------- get_denominator ----------------------------";
46 "--------- several errpats in complicated term -------------------";
47 "--------------------------------------------------------";
48 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
49 "--------------------------------------------------------";
50 "--------------------------------------------------------";
53 "~~~~~BEGIN: decomment structure RationalI : RATIONALI ~~";
54 (*.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55 tests of internal functions: to make them work,
56 out-comment (*!!!*) in knowledge/Rational.ML:
58 structure RationalI : RATIONALI =
65 !!!##*)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.*)
67 "-------- ... missing WN060103 --------------------------";
68 "-------- ... missing WN060103 --------------------------";
69 "-------- ... missing WN060103 --------------------------";
70 (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
71 writeln ("********************* rational.sml - TESTS *************************");
72 writeln ("***** divide tests *****");
73 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_)));
74 (* result: [(1,[0,0,1]),(1,[0,0,0])] *)
75 if mv_pquot1=[(1,[0,0,1]),(1,[0,0,0])] then () else error ("rational.sml: example failed");
77 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_)));
78 (* result: [(1,[1,0,1]),(~1,[0,0,1])] *)
79 if mv_prest1=[(1,[1,0,1]),(~1,[0,0,1])] then () else error ("rational.sml: example failed");
81 val mv_pquot2 = (#1(mv_division([(4,[2]),(8,[1]),(16,[0])],[(1,[1]),(1,[0])],LEX_)));
82 (* result: [(4,[1]),(4,[0])] *)
83 if mv_pquot2=[(4,[1]),(4,[0])] then () else error ("rational.sml: example failed");
85 val mv_prest2 = (#2(mv_division([(4,[2]),(8,[1]),(16,[0])],[(1,[1]),(1,[0])],LEX_)));
86 (* result: [(12,[0]] *)
87 if mv_prest2=[(12,[0])] then () else error ("rational.sml: example failed");
89 val mv_pquot3 = (#1(mv_division([(4,[2]),(~4,[0])],[(2,[1]),(2,[0])],LEX_)));
90 (* [(2,[1]),(~2,[0])] *)
91 if mv_pquot3=[(2,[1]),(~2,[0])] then () else error ("rational.sml: example failed");
93 val mv_prest3 = (#2(mv_division([(1,[2]),(~1,[0])],[(2,[1]),(2,[0])],LEX_)));
94 (* [(1,[2]),(~1,[0])] *)
95 if mv_prest3=[(1,[2]),(~1,[0])] then () else error ("rational.sml: example failed");
97 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_)));
99 if mv_pquot4=[(1,[0,1,1])] then () else error ("rational.sml: example failed");
101 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_)));
102 (* [(1,[1,1,1]),(~4,[0,1,2]),(4,[1,0,1]),(3,[0,0,1])] *)
103 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");
105 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_)));
106 (* [(1,[2,2,0]),(6,[2,1,2]),(3,[1,1,0]),(4,[1,0,0]),(4,[0,4,0]),(3,[0,0,0])]*)
107 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");
109 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_)));
111 if mv_prest5=[] then () else error ("rational.sml: example failed");
113 (* (x^2 + 2(a+1)x + (a^2+2a+1)) / (x+a+1) = x+a+1 *)
114 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_)));
115 if mv_pquot6=[(1,[1,0,0]),(1,[0,1,0]),(1,[0,0,0])] then () else error ("rational.sml: example failed");
117 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_)));
118 if mv_prest6=[] then () else error ("rational.sml: example failed");
121 writeln ("***** MV_CONTENT-TESTS *****");
122 val mv_cont1=mv_content([(1,[2,1]),(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,1]),(1,[0,0])]);
123 (* [(1,[0,1]),(1,[0,0])] *)
124 if mv_cont1=[(1,[0,1]),(1,[0,0])] then () else error ("rational.sml: example failed");
126 val mv_pp1=mv_pp([(1,[1,1]),(1,[1,0]),(1,[0,1]),(1,[0,0])]);
127 (*[(1,[1,0]),(1,[0,0])]*)
128 if mv_pp1=[(1,[1,0]),(1,[0,0])] then () else error ("rational.sml: example failed");
130 val mv_cont2=mv_content([(2,[1]),(4,[0])]);
132 if mv_cont2=[(2,[0])] then () else error ("rational.sml: example failed");
134 val mv_pp2=mv_pp([(2,[1]),(4,[0])]);
135 (* [(1,[1]),(2,[0])] *)
136 if mv_pp2=[(1,[1]),(2,[0])] then () else error ("rational.sml: example failed");
138 val mv_cont3=mv_content[(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(16,[1,1,1])];
140 if mv_cont3=[(2,[0,0,0])] then () else error ("rational.sml: example failed");
142 val mv_pp3=mv_pp[(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(16,[1,1,1])];
143 (* [(5,[2,2,0]),(4,[2,1,1]),(8,[1,1,1]),(6,[1,0,2])] *)
144 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");
146 val mv_cont4=mv_content[(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])];
148 if mv_cont4=[(1,[0,0,0])] then () else error ("rational.sml: example failed");
150 val mv_pp4=mv_pp [(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])];
151 (* [(2,[2,1,0]),(2,[1,1,0]),(3,[1,0,1]),(3,[0,0,1])] *)
152 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");
154 val con1=mv_content([(9,[2,0]),(15,[1,1]),(12,[1,0]),(6,[0,2]),(12,[0,1])]);
156 if con1=[(3,[0,0])] then () else error ("rational.sml: example failed");
158 val pp1=mv_pp([(9,[2,0]),(15,[1,1]),(12,[1,0]),(6,[0,2]),(12,[0,1])]);
159 (* [(3,[2,0]),(5,[1,1]),(4,[1,0]),(2,[0,2]),(4,[0,1])] *)
160 if pp1=[(3,[2,0]),(5,[1,1]),(4,[1,0]),(2,[0,2]),(4,[0,1])] then () else error ("rational.sml: example failed");
162 val con2=mv_content([(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])]);
164 if con2=[(1,[0,0])] then () else error ("rational.sml: example failed");
166 val pp2 =mv_pp([(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])]);
167 (* [(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])] *)
168 if pp2=[(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])] then () else error ("rational.sml: example failed");
170 val cont1 = mv_content [(1,[2,1,0]),(2,[2,1,0])];
172 if cont1=[(3,[0,1,0])] then () else error ("rational.sml: example failed");
174 val pp1 = mv_pp [(1,[2,1,0]),(2,[2,1,0])];
176 if pp1=[(1,[2,0,0])] then () else error ("rational.sml: example failed");
178 val cont2 = mv_content [(4,[1,2,0]),(2,[2,1,0])];
180 if cont2=[(2,[0,1,0])] then () else error ("rational.sml: example failed");
182 val pp2 = mv_pp [(4,[1,2,0]),(2,[2,1,0])];
183 (* [(1,[2,0,0]),(2,[1,1,0])] *)
184 if pp2=[(1,[2,0,0]),(2,[1,1,0])] then () else error ("rational.sml: example failed");
186 writeln ("********************************************************");
187 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])];
188 if cont3=[(5,[0,2,1]),(4,[0,2,0]),(2,[0,1,1])] then () else error ("rational.sml: example failed");
189 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])];
192 "-------- fun monom2term, fun poly2term' ---------------";
193 "-------- fun monom2term, fun poly2term' ---------------";
194 "-------- fun monom2term, fun poly2term' ---------------";
195 val t = monom2term ((3,[2,1,0]), ["c","b","a"](*reverse ???SK-*));
196 term2str t = "3 * (c ^^^ 2 * b)" (*true*);
198 val t = monom2term ((1,[1,0]), ["b","a"]);
199 term2str t = "b" (*true*);
201 val t = poly2term ([(1,[0,0,0]),(2,[1,0,0]),(3,[2,1,0]),(4,[3,2,1])],
203 term2str t = "1 + 2 * c + 3 * (c ^^^ 2 * b) + 4 * (c ^^^ 3 * (b ^^^ 2 * a))";
205 val t = poly2term ([(1,[1,0]),(1,[0,1])], ["b","a"]);
206 term2str t = "a + b" (*true*);
208 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
209 "~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
210 "~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
211 "~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
214 fun parse_rat str = (term_of o the o (parse thy)) str;
216 writeln ("***** mv_gcd-tests *****");
217 val ggt1 = mv_gcd [(4,[2,2]),(8,[1,1]),(4,[0,0])] [(2,[1,1]),(2,[0,0])];
218 (* [(2,[1,1]),(2,[0,0])] *)
219 if ggt1=[(2,[1,1]),(2,[0,0])] then () else error ("rational.sml: example failed");
221 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])];
222 (* [(2,[1,1,0]),(3,[0,0,1])] *)
223 if ggt2=[(2,[1,1,0]),(3,[0,0,1])] then () else error ("rational.sml: example failed");
226 val ggt3 = mv_gcd [(1,[2,0]),(~2,[1,1]),(1,[0,2])] [(1,[1,0]),(~1,[0,1])];
227 (* [(1,[1,0]),(~1,[0,1])] *)
228 if ggt3=[(1,[1,0]),(~1,[0,1])] then () else error ("rational.sml: example failed");
231 val ggt4 = mv_gcd [(1,[2,1,0]),(2,[2,1,0])] [(5,[1,0,0])];
233 if ggt4=[(1,[1,0,0])] then () else error ("rational.sml: example failed");
236 val ggt5 = mv_gcd [(4,[2,0]),(~8,[1,1]),(4,[0,2])] [(1,[2,0]),(~1,[0,2])];
237 (* [(1,[1,0]),(~1,[0,1])] *)
238 if ggt5=[(1,[1,0]),(~1,[0,1])] then () else error ("rational.sml: example failed");
241 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])];
243 if ggt6=[(1,[1,0,0])] then () else error ("rational.sml: example failed");
245 writeln ("***** kgv-tests *****");
246 val kgv1=mv_lcm [(10,[])] [(15,[])];
248 if kgv1=[(30,[])] then () else error ("rational.sml: example failed");
250 val kgv2=mv_lcm [(1,[2,0]),(~2,[1,1]),(1,[0,2])] [(1,[1,0]),(~1,[0,1])];
251 (* [(1,[2,0]),(~2,[1,1]),(1,[0,2])] *)
252 if kgv2=[(1,[2,0]),(~2,[1,1]),(1,[0,2])] then () else error ("rational.sml: example failed");
254 val kgv3=mv_lcm [(4,[2,0]),(~8,[1,1]),(4,[0,2])] [(1,[2,0]),(~1,[0,2])];
255 (* [(4,[3,0]),(~4,[2,1]),(~4,[1,2]),(4,[0,3])] *)
256 if kgv3=[(4,[3,0]),(~4,[2,1]),(~4,[1,2]),(4,[0,3])] then () else error ("rational.sml: example failed");
259 writeln ("***** STEP_CANCEL_TESTS: *****");
261 val term2 = (term_of o the o (parse thy)) " (9 * a^^^2 * b) / (6 * a * c)";
262 val div2 = term2str (step_cancel term2);
263 if div2 = "3 * (a * b) * (3 * a) / (2 * c * (3 * a))" then () else error ("rational.sml: example failed");
266 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";
267 val div1 = term2str(step_cancel term1);
268 if div1 = "(3 * c + 14 * b + 20 * (b ^^^ 2 * c) + 10 * (a * (b * c))) * a / (1 * a)" then () else error ("rational.sml: example failed");
270 val term3 = (term_of o the o (parse thy)) "(10 * a^^^2 * b * c) / (1 * x * y * z) ";
271 val div3 = term2str(step_cancel term3);
272 if div3="10 * a ^^^ 2 * b * c / (1 * x * y * z)" then () else error ("rational.sml: example failed");
274 --------------------------------------------------------------------------!!!*)
276 (*-----versuche 13.3.03-----
277 val t = str2term "1 - x^^^2 - 5 * x^^^5";
278 val vs=(((map free2str) o vars) t);
279 val SOME ml = expanded2poly t vs;
281 poly2term'(rev(sort (mv_geq LEX_) (ml)),vs);
282 poly2term'([(~5,[5]),(~1,[2]),(1,[0])], vs);
283 monom2term((~5,[5]),vs);
284 monom2term((~1,[2]),vs);
285 val t' = monom2term((1,[0]),vs);(*uncaught exception LIST*)
287 val (i,is) = (~1,[2]);
288 val ttt = Const ("Groups.times_class.times", [HOLogic.realT,HOLogic.realT]---> HOLogic.realT) $
289 (Const ("uminus", HOLogic.realT --> HOLogic.realT) $
290 Free ((str_of_int o abs) i, HOLogic.realT)) $
291 powerproduct2term(is, vs);
293 -------versuche 13.3.03-----*)
295 val t = str2term "1 - x^^^2 - 5 * x^^^5";
296 val SOME t' = expanded2polynomial t; term2str t';
297 "1 + - 1 * x ^^^ 2 + - 5 * x ^^^ 5";
298 val t = str2term "1 - x";
299 val SOME t' = expanded2polynomial t; term2str t';
301 val t = str2term "1 + (-1) * x";
302 val SOME t' = expanded2polynomial t; term2str t';
304 val t = (term_of o the o (parse thy)) "1 + (-1) * x ^^^ 2 + (-5) * x ^^^5";
305 val SOME t' = polynomial2expanded t; term2str t';
306 "1 - x ^^^ 2 - 5 * x ^^^ 5";
309 "-------- external calculating functions test -----------";
310 "-------- external calculating functions test -----------";
311 "-------- external calculating functions test -----------";
312 val t1 = (term_of o the o (parse thy)) "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
313 val SOME (t1',asm)= factout_p_ thy t1;
314 term2str t1'; terms2str asm;
315 "(3 + 3 * x) * (1 + 1 * x) / (2 * (1 + 1 * x))";
317 val SOME (t1',asm)= cancel_p_ thy t1;
318 term2str t1'; terms2str asm;
320 "[\"1 + 1 * x ~= 0\"]";
322 val t = (term_of o the o (parse thy)) "((-3 * x^^^2 + 6 *x - 3) / (2*x - 2))";
323 val SOME (t',asm)= cancel_ thy t;
324 term2str t'; terms2str asm;
327 val SOME (t',asm)= factout_ thy t;
328 term2str t'; terms2str asm;
329 "(3 - 3 * x) * (-1 + x) / (2 * (-1 + x))";
332 val t = str2term "((x+ (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
333 val SOME (t',asm) = add_fraction_p_ thy t;
334 term2str t'; terms2str asm;
335 "(2 + 2 * x ^^^ 2) / (-1 + 1 * x ^^^ 2)";
337 val SOME (t',asm) = common_nominator_p_ thy t;
338 term2str t'; terms2str asm;
339 "(-1 + 1 * x) * (-1 + 1 * x) / ((1 + 1 * x) * (-1 + 1 * x)) +\n(1 + 1 * x) * (1 + 1 * x) / ((1 + 1 * x) * (-1 + 1 * x))";
342 val t = str2term "((x - 1) / (x + 1)) + ((x + 1) / (x - 1))";
343 val SOME (t',asm) = add_fraction_ thy t;
344 term2str t'; terms2str asm;
345 "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)";
347 val SOME (t',asm) = common_nominator_ thy t;
348 term2str t'; terms2str asm;
349 "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))";
352 val t = str2term "((1) / (2*x + 2)) + ((1) / (2*x + (-2))) + ((1) / ( x^^^2 + (-1)))+((1) / (x^^^2 + (-2)*x + 1))";
353 val SOME (t',asm) = common_nominator_p_ thy t;
354 term2str t'; terms2str asm;
355 "1 * (1 + -2 * x + 1 * x ^^^ 2) /\n((-1 + 1 * x) * (2 * ((-1 + 1 * x) * (1 + 1 * x)))) +\n(1 * (-1 + 1 * x ^^^ 2) /\n ((-1 + 1 * x) * (2 * ((-1 + 1 * x) * (1 + 1 * x)))) +\n (1 * (-2 + 2 * x) / ((-1 + 1 * x) * (2 * ((-1 + 1 * x) * (1 + 1 * x)))) +\n 1 * (#";
357 val SOME (t',asm) = add_fraction_p_ thy t;
358 term2str t'; terms2str asm;
359 "1 * x / (1 + -2 * x + 1 * x ^^^ 2)";
360 "[\"1 + 1 * x ~= 0\"]";
361 val SOME(t',asm) = norm_rational_ thy t;
362 term2str t'; terms2str asm;
363 "1 * x / (1 + -2 * x + 1 * x ^^^ 2)";
364 "[\"1 + 1 * x ~= 0\"]";
366 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))";
367 val SOME (t3',_) = common_nominator_ thy t3;
368 val SOME (t3'',_) = add_fraction_ thy t3;
372 val SOME(t4,t5) = norm_expanded_rat_ thy t3;
378 val t=(term_of o the o (parse thy)) "(9 - x^^^2)/(9 - 6*x + x^^^2)";
379 val SOME (t',_) = factout_ thy t;
380 val SOME (t'',_) = cancel_ thy t;
383 "(3 + x) * (3 - x) / ((3 - x) * (3 - x))";
386 val t=(term_of o the o (parse thy))
387 "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1 / (3 - x)";
388 val SOME (t',_) = common_nominator_ thy t;
389 val SOME (t'',_) = add_fraction_ thy t;
392 "(9 - x ^^^ 2) / ((3 - x) * (3 - x)) + 1 * (3 - x) / ((3 - x) * (3 - x))";
395 (*WN021016 added -----vv---*)
396 val t = str2term "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1";
397 val SOME (t',_) = common_nominator_ thy t;
398 val SOME (t'',_) = add_fraction_ thy t;
399 term2str t' = "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n1" ^
400 " * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
401 term2str t'' = "6 / (3 - x)" (*true*);
403 val t = str2term "1 + (9 - x^^^2) / (9 - 6*x + x^^^2)";
404 val SOME (t',_) = common_nominator_ thy t;
405 val SOME (t'',_) = add_fraction_ thy t;
406 term2str t' = "1 * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n" ^
407 "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
408 term2str t'' = "6 / (3 - x)" (*true*);
409 (*WN021016 added -----^^---*)
410 (*WN030602 added -----vv--- no rewrite -> NONE !*)
411 val t = str2term "1 / a";
412 val NONE = cancel_p_ thy t;
413 val NONE = rewrite_set_ thy false cancel_p t;
414 (*WN.2.6.03 added -------^^---*)
416 val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2)";
417 val SOME (t',_) = factout_ thy t;
418 val SOME (t'',_) = cancel_ thy t;
419 term2str t' = "(y + x) * (y - x) / ((y - x) * (y - x))"(*true*);
420 term2str t'' = "(y + x) / (y - x)";
422 val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2) + 1 / (y - x)";
423 val SOME (t',_) = common_nominator_ thy t;
424 val SOME (t'',_) = add_fraction_ thy t;
426 "(-1 * x ^^^ 2 + y ^^^ 2) / ((-1 * x + y) * (-1 * x + y)) +\n1" ^
427 " * (-1 * x + y) / ((-1 * x + y) * (-1 * x + y))" (*true*);
428 term2str t'' = "(-1 - x - y) / (x - y)" (*true*);
430 val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2) + 1 / (x - y)";
431 val SOME (t',_) = common_nominator_ thy t;
432 val SOME (t'',_) = add_fraction_ thy t;
433 if term2str t' = "(-1 * y ^^^ 2 + x ^^^ 2) / ((-1 * y + x) * (-1 * y + x))" ^
434 " +\n1 * (-1 * y + x) / ((-1 * y + x) * (-1 * y + x))" then ()
435 else error "rational.sml lex-ord 1";
436 if term2str t'' = "(-1 - y - x) / (y - x)" then ()
437 else error "rational.sml lex-ord 2";
438 (*WN.16.10.02 WN070905 lexicographische Ordnung erhalten ! SK.ord*)
441 val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2)";
442 val SOME (t',_) = norm_expanded_rat_ thy t;
443 if term2str t' = "(x + y) / (x - y)" then ()
444 else error "rational.sml term2poly: invalid x ^^^ 2 - y ^^^ 2 No.1";
445 (*val SOME (t'',_) = norm_rational_ thy t;
446 *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial
447 WN.16.10.02 ?! + WN060831???SK4
448 WN070905 *** term2poly: invalid = x ^^^ 2 - y ^^^ 2*)
451 val t = str2term "(9 - x^^^2)/(9 - 6*x + x^^^2) + (1)/(3 + x)";
452 val SOME (t',_) = norm_expanded_rat_ thy t;
453 if term2str t' = "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)" then ()
454 else error "rational.sml (9 - x^^^2)/(9 - 6*x + x^^^2) +...";
455 (*val SOME (t'',_) = norm_rational_ thy t;
456 *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial WN.16.10.02 ?!
457 WN070906 *** term2poly: invalid = 9 - x ^^^ 2 SK.term2poly*)
459 val t=(term_of o the o (parse thy))
460 "(9 + (-1)* x^^^2)/(9 + (-1)* 6*x + x^^^2) + (1)/(3 + x)";
461 val SOME (t',_) = norm_expanded_rat_ thy t;
462 val SOME (t'',_) = norm_rational_ thy t;
465 "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)";
466 "(12 + 5 * x + x ^^^ 2) / (9 + (-1) * x ^^^ 2)";
469 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
470 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
471 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
472 val thy = @{theory "Rational"};
473 val thy' = "Rational";
475 val mp = "make_polynomial";
477 writeln ("example 186:");
479 val e186a'="(14 * x * y) / ( x * y )";(*SRC*)
480 rewrite_set_ thy false cancel (str2term e186a');
482 val e186a = the (rewrite_set thy' false "cancel" e186a');
483 is_expanded (parse_rat "14 * x * y");
484 is_expanded (parse_rat "x * y");
485 if e186a = ("14 / 1", "[\"y * x ~= 0\"]") then ()
486 else error "rational.sml cancel Schalk e186a";
489 val e186b'="(60 * a * b) / ( 15 * a * b )";
490 val e186b = the (rewrite_set thy' false "cancel" e186b');
492 val e186c'="(144 * a^^^2 * b * c) / (12 * a * b * c )";
493 val e186c = (the (rewrite_set thy' false "cancel" e186c'))
494 handle e => print_exn_G e;
495 val t = (term_of o the o (parse thy)) e186c';
496 if e186c = ("12 * a / 1", "[\"12 * (c * (b * a)) ~= 0\"]") then ()
497 else error "rational.sml cancel Schalk e186c";
499 writeln ("example 187:");
501 val e187a'="(12 * x * y) / (8 * y^^^2 )";(*SRC*)
502 val e187a = the (rewrite_set thy' false "cancel" e187a');
504 val e187b'="(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
505 val e187b = the (rewrite_set thy' false "cancel" e187b');
507 val e187d'="(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";(*SRC*)
508 val e187d = the (rewrite_set thy' false "cancel" e187d');
509 if e187d = ("3 * z ^^^ 3 / (5 * (y * x))",
510 "[\"3 * (z * (y ^^^ 2 * x ^^^ 5)) ~= 0\"]") then ()
511 else error "rational.sml cancel Schalk e186d";
513 writeln "example 188:";
514 val e188a'="(-8 + 8 * x) / (-9 + 9 * x)";(*SRC*)
515 val e188a = the (rewrite_set thy' false "cancel" e188a');
516 is_expanded (parse_rat "8 * x + -8");
517 (* e188a = ("8 / 9",["not ((-1) + x = 0)"]) then () 13.3.03*)
518 if e188a = ("8 / 9", "[\"-1 + x ~= 0\"]") then ()
519 else error "rational.sml: e188a new behaviour";
521 val SOME (t,_) = rewrite_set thy' false mp "(8*((-1) + x))/(9*((-1) + x))";
523 val e188b'="(-15 + 5 * x) / (-18 + 6 * x)";(*SRC*)
524 val SOME (t, asm) = rewrite_set thy' false "cancel" e188b';
525 t = "5 / 6" (*true*);
528 val e188c'="( a + -1 * b ) / ( b + -1 * a )";
529 val e188c = the (rewrite_set thy' false "cancel_p" e188c');
530 (*is_expanded (parse_rat "a + -1 * b");*)
532 rewrite_set thy' false mp "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
533 if t= "(a + -1 * b) / (-1 * a + b)" then()
534 else error "rational.sml: e188c new behaviour";
536 writeln ("example 190:");
538 val e190c'="( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )";
539 val e190c = the (rewrite_set thy' false "cancel" e190c');
540 val SOME (t,_) = rewrite_set thy' false mp "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
541 if t = "(1 + 3 * a + 9 * a ^^^ 2 + 27 * a ^^^ 3) /\n(3 * a + 18 * a ^^^ 2 + 27 * a ^^^ 3)" then ()
542 else error "rational.sml: e190c new behaviour";
544 writeln ("example 191:");
546 val e191a'="( x^^^2 + -1 * y^^^2 ) / ( x + y )";
548 val e191a = the (rewrite_set thy' false "cancel" e191a');
549 is_expanded (parse_rat "x^^^2 + -1 * y^^^2");
551 is_expanded (parse_rat "x + y");
553 val SOME (t,_) = rewrite_set thy' false mp "((x + (-1) * y)*(x + y))/((1)*(x + y))";
554 (* t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then() WN.13.3.03*)
555 if t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then()
556 else error "rational.sml: e191a new behaviour";
559 val e191c'="( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )";
561 val e191c = the (rewrite_set thy' false "cancel" e191c');
562 is_expanded (parse_rat "9 * x^^^2 + -30 * x + 25");
564 is_expanded (parse_rat "25 + -30*x + 9*x^^^2");
566 is_expanded (parse_rat "-25 + 9*x^^^2");
568 val SOME (t,_) = rewrite_set thy' false mp "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
569 (* t="(25 + ((-30) * x + 9 * x ^^^ 2)) / ((-25) + 9 * x ^^^ 2)"then() 13.3.03*)
570 if t= "(25 + -30 * x + 9 * x ^^^ 2) / (-25 + 9 * x ^^^ 2)" then()
571 else error "rational.sml: 'e191c' new behaviour";
574 writeln ("example 192:");
576 val e192b'="( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 * y^^^3 )";
578 val e192b = the (rewrite_set thy' false "cancel" e192b');
579 -------------------*)
580 val SOME (t',_) = rewrite_set thy' false mp "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
581 (*========== inhibit exn 110317 ================================================
582 if t' = "(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)"
583 (*"(-1 * y * x ^^^ 2 + 7 * x ^^^ 3) / (-1 * y ^^^ 3 + 7 * x * y ^^^ 2)"WN050929*)
584 then () else error "rational.sml: 'e192b' new behaviour";
585 (*^^^ works with MG's simplifier vvv*)
586 val t =str2term"((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
587 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
588 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";
589 ============ inhibit exn 110317 ==============================================*)
591 writeln ("example 193:");
593 val e193a'="( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )";
595 val e193a = the (rewrite_set thy' false "cancel" e193a');
596 -------------------*)
598 val e193b'="( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )";
600 val e193b = the (rewrite_set thy' false "cancel" e193b');
602 val e193c'="( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )";
603 val SOME(t,_) = rewrite_set thy' false "cancel" e193c';
604 -------------------*)
606 val wn01 = "(-25 + 9*x^^^2)/(5 + 3*x)";
607 val SOME (t, asm) = rewrite_set thy' false "cancel" wn01;
608 (* t = "((-5) + 3 * x) / 1" then () WN.13.3.03*)
609 if t = "(-5 + 3 * x) / 1" andalso asm = "[\"5 + 3 * x ~= 0\"]" then ()
610 else error "rational.sml: new behav. in cancel wn01";
612 "-------- common_nominator_p ----------------------------";
613 "-------- common_nominator_p ----------------------------";
614 "-------- common_nominator_p ----------------------------";
615 val rls' = "common_nominator_p";
617 writeln ("example 204:");
619 val e204a'="((5 * x) / 9) + ((3 * x) / 9) + (x / 9)";
620 val e204a = the (rewrite_set thy' false "common_nominator_p" e204a');
622 val e204b'="5 / x + -3 / x + -1 / x";
623 val e204b = the (rewrite_set thy' false "common_nominator_p" e204b');
624 if e204b = ("1 / x", "[]") then ()
625 else error "rational.sml common_nominator_p example e204b";
627 writeln ("example 205:");
629 val e205a'="((4 * x + 7) / 8) + ((4 * x + 3) / 8)";
630 val e205a = the (rewrite_set thy' false "common_nominator_p" e205a');
632 val e205b'="((5 * x + 2) / 3) + ((-2 * x + 1) / 3)";
633 val e205b = the (rewrite_set thy' false "common_nominator_p" e205b');
634 if e205b = ("(1 + x) / 1", "[]") then ()
635 else error "rational.sml common_nominator_p example e204b";
637 writeln ("example 206:");
639 val e206a'="((5 * x + 4) / (2 * x + -1)) + ((9 * x + 5) / (2 * x + -1))";
640 val e206a = the (rewrite_set thy' false "common_nominator_p" e206a');
642 val e206b'="((17 * x + -23) / (5 * x + 4)) + ((-25 + -17 * x) / (5 * x + 4))";
643 val e206b = the (rewrite_set thy' false "common_nominator_p" e206b');
645 writeln ("example 207:");
646 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)) ";
647 val e207 = the (rewrite_set thy' false "common_nominator_p" e207');
649 writeln ("example 208:");
650 val e208'="((3 * x + 2) / (x + 2)) + ((5 * x + -1) / (x + 2)) + ((-7 * x + -3) / (x + 2)) + ((-1 * x + -3) / (x + 2)) ";
651 val e208 = the (rewrite_set thy' false "common_nominator_p" e208');
653 writeln ("example 209:");
654 val e209'="((3 * x + -7 * y + 3 * z) / (4)) + ((2 * x + 17 * y + 10 * z) / (4)) + ((-1 * x + 2 * y + z) / (4)) ";
655 val e209 = the (rewrite_set thy' false "common_nominator_p" e209');
657 writeln ("example 210:");
658 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)) ";
659 val e210 = the (rewrite_set thy' false "common_nominator_p" e210');
661 writeln ("example 211:");
663 val e211a'="((b) / (a + -1 * b)) + ((-1 * a) / (a + -1 * b))";
664 val e211a = the (rewrite_set thy' false "common_nominator_p" e211a');
666 val e211b'="((b) / (b^^^2 + -1 * a^^^2)) + ((-1 * a) / (b^^^2 + -1 * a^^^2))";
667 val e211b = the (rewrite_set thy' false "common_nominator_p" e211b');
669 writeln ("example 212:");
671 val e212a'="((4) / (x)) + ((-3) / (y)) + -1";
672 val e212a = the (rewrite_set thy' false "common_nominator_p" e212a');
674 val e212b'="((4) / (x)) + ((-5) / (y)) + ((6) / (x*y))";
675 val e212b = the (rewrite_set thy' false "common_nominator_p" e212b');
677 writeln ("example 213:");
679 val e213a'="((5 * x) / (3 * y^^^2)) + ((19 * z) / (6 * x * y)) + ((-2 * x) / (3 * y^^^2)) + ((7 * y^^^2) / (6 * x^^^2)) ";
680 val e213a = the (rewrite_set thy' false "common_nominator_p" e213a');
682 val e213b'="((2 * b) / (3 * a^^^2)) + ((3 * c) / (7 * a * b)) + ((4 * b) / (3 * a^^^2)) + ((3 * a) / (7 * b^^^2))";
683 val e213b = the (rewrite_set thy' false "common_nominator_p" e213b');
685 writeln ("example 214:");
687 val e214a'="((3 * x + 2 * y + 2 * z) / (4)) + ((-5 * x + -3 * y) / (3)) + ((x + y + -2 * z) / (2))";
688 val e214a = the (rewrite_set thy' false "common_nominator_p" e214a');
690 val e214b'="((5 * x + 2 * y + z) / (2)) + ((-7 * x + -3 * y) / (3)) + ((3 * x + 6 * y + -1 * z) / (12))";
691 val e214b = the (rewrite_set thy' false "common_nominator_p" e214b');
693 writeln ("example 216:");
695 val e216a'="((2 * b + 3 * c) / (a * c)) + ((3 * a + b) / (a * b)) + ((-2 * b^^^2 + -3 * a * c) / (a * b * c))";
696 val e216a = the (rewrite_set thy' false "common_nominator_p" e216a');
698 val e216b'="((2 * a + 3 * b) / (b * c)) + ((3 * c + a) / (a * c)) + ((-2 * a^^^2 + -3 * b * c) / (a * b * c))";
699 val e216b = the (rewrite_set thy' false "common_nominator_p" e216b');
701 writeln ("example 217:");
702 val e217'="((z + -1) / (z)) + ((3 * z ^^^2 + -6 * z + 5) / (z^^^2)) + ((-4 * z^^^3 + 7 * z^^^2 + -5 * z + 5) / (z^^^3))";
703 val e217 = the (rewrite_set thy' false "common_nominator_p" e217');
706 val rls' = "common_nominator";
707 writeln ("example 218:");
708 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))";
709 val e218 = the (rewrite_set thy' false "common_nominator" e218');
710 if e218 = ("(16 - 63 * a ^^^ 2 - 81 * a ^^^ 3) / (108 * a ^^^ 4)", "[]") then ()
711 else error "rationa.sml common_nominator example e218";
713 writeln ("example 219:");
715 val e219a'="((1) / (y + 1)) + ((1) / (y + 2)) + ((1) / (y + 3))";
716 val e219a = the (rewrite_set thy' false "common_nominator" e219a');
718 val e219b'="((1) / (x + 1)) + ((1) / (x + 2)) + ((-2) / (x + 3))";
719 val e219b = the (rewrite_set thy' false "common_nominator" e219b');
720 if e219b = ("(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)", "[]") then ()
721 else error "rationa.sml common_nominator example e219b";
723 writeln ("example 220:");
725 val e220a'="((17) / (5 * r + -2)) + ((-13) / (2 * r + 3)) + ((4) / (3 * r + -5))";
726 val e220a = the (rewrite_set thy' false "common_nominator" e220a');
728 val e220b'="((20 * a) / (a + -3)) + ((-19 * a) / (a + -4)) + ((a) / (a + -5))";
729 val e220b = the (rewrite_set thy' false "common_nominator" e220b');
731 writeln ("example 221:");
733 val e221a'="((a + b) / (a + -1 * b)) + ((a + -1 * b) / (a + b))";
734 val e221a = the (rewrite_set thy' false "common_nominator" e221a');
736 val e221b'="((x + -1 * y) / (x + y)) + ((x + y) / (x + -1 * y)) ";
737 val e221b = the (rewrite_set thy' false "common_nominator" e221b');
739 writeln ("example 222:");
741 val e222a'="((1 + -1 * x) / (1 + x)) + ((-1 + -1 * x) / (1 + -1 * x)) + ((4 * x) / (1 + -1 * x^^^2))";
742 val e222a = the (rewrite_set thy' false "common_nominator" e222a');
744 val e222b'="((1 + x ) / (1 + -1 * x)) + ((-1 + x) / (1 + x)) + ((2 * x) / (1 + -1 * x^^^2))";
745 val e222b = the (rewrite_set thy' false "common_nominator" e222b');
747 writeln ("example 225:");
749 val e225a'="((6 * a) / (a^^^2 + -64)) + ((a + 2) / (2 * a + 16)) + ((-1) / (2))";
750 val e225a = the (rewrite_set thy' false "common_nominator" e225a');
752 val e225b'="((a + 2 ) / (2 * a + 12)) + ((4 * a) / (a^^^2 + -36)) + ((-1) / (2))";
753 val e225b = the (rewrite_set thy' false "common_nominator" e225b');
755 writeln ("example 226:");
757 val e226a'="((35 * z) / (49 * z^^^2 + -4)) + -1 + ((14 * z + -1) / (14 * z + 4)) ";
758 val e226a = the (rewrite_set thy' false "common_nominator" e226a');
760 val e226b'="((45 * a * b) / (25 * a^^^2 + -9 * b^^^2)) + ((20 * a + 3 * b) / (10 * a + 6 * b)) + -2";
761 val e226b = the (rewrite_set thy' false "common_nominator" e226b');
763 writeln ("example 227:");
765 val e227a'="((6 * z + 11) / (6 * z + 14)) + ((9 * z ) / (9 * z^^^2 + -49)) + -1 ";
766 val e227a = the (rewrite_set thy' false "common_nominator" e227a');
768 val e227b'="((16 * a + 37 * b) / (4 * a + 10 * b)) + ((6 * a * b) / (4 * a^^^2 + -25 * b^^^2)) + -4 ";
769 val e227b = the (rewrite_set thy' false "common_nominator" e227b');
771 writeln ("example 228:");
773 val e228a'="((7 * a + 11) / (3 * a^^^2 + -3)) + ((-2 * a + -1) / (a^^^2 + -1 * a)) + ((-1) / (3 * a + 3))";
774 val e228a = the (rewrite_set thy' false "common_nominator" e228a');
776 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))";
777 val e228b = the (rewrite_set thy' false "common_nominator" e228b');
780 writeln ("example 229:");
782 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))";
783 val e229a = the (rewrite_set thy' false "common_nominator" e229a');
785 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))";
786 val e229b = the (rewrite_set thy' false "common_nominator" e229b');
788 writeln ("example 230:");
790 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))";
791 val e230a = the (rewrite_set thy' false "common_nominator" e230a');
793 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))";
794 val e230b = the (rewrite_set thy' false "common_nominator" e230b');
796 writeln ("example 231:");
798 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))";
799 val e231a = the (rewrite_set thy' false "common_nominator" e231a');
801 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))";
802 val e231b = the (rewrite_set thy' false "common_nominator" e231b');
804 writeln ("example 232:");
806 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))";
807 val e232a = the (rewrite_set thy' false "common_nominator" e232a');
809 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))";
810 val e232b = the (rewrite_set thy' false "common_nominator" e232b');
812 writeln ("example 233:");
814 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))";
815 val e233a = the (rewrite_set thy' false "common_nominator" e233a');
817 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))";
818 val e233b = the (rewrite_set thy' false "common_nominator" e233b');
820 writeln ("example 234:");
822 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))";
823 val e234a = the (rewrite_set thy' false "common_nominator" e234a');
825 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)) ";
826 val e234b = the (rewrite_set thy' false "common_nominator" e234b');
828 writeln ("example 235:");
830 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))";
831 val e235a = the (rewrite_set thy' false "common_nominator" e235a');
833 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)) ";
834 val e235b = the (rewrite_set thy' false "common_nominator" e235b');
836 writeln ("example 236:");
838 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))";
839 val e236a = the (rewrite_set thy' false "common_nominator" e236a');
841 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)) ";
842 val e236b = the (rewrite_set thy' false "common_nominator" e236b');
846 writeln ("example heuberger:");
847 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)";
848 val eheu = the (rewrite_set thy' false "cancel" eheu');
850 val rls' = "common_nominator_p";
851 writeln ("example stiefel:");
852 val est1'="(7) / (-14) + (-2) / (4)";
853 val est1 = the (rewrite_set thy' false "common_nominator_p" est1');
854 if est1 = ("-1 / 1", "[]") then ()
855 else error "new behaviour in rational.sml: est1'";
857 val t = (term_of o the o (parse thy))
858 "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
859 val SOME (t',_) = factout_ thy t;
860 if term2str t' = "(3 + x) * (3 - x) / ((3 - x) * (3 - x))" then ()
861 else error "rational.sml factout_ (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
864 "-------- reverse rewrite -------------------------------";
865 "-------- reverse rewrite -------------------------------";
866 "-------- reverse rewrite -------------------------------";
867 (*WN.28.8.02: tests for the 'reverse-rewrite' functions:
868 these are defined in Rationals.ML and stored in
869 the 'reverse-ruleset' cancel*)
871 (*the term for which reverse rewriting is demonstrated*)
872 val t = (term_of o the o (parse thy))
873 "(9 - x ^^^ 2) / (9 + 6 * x + x ^^^ 2)";
874 val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
875 next_rule=nex,normal_form=nor,...},...} = cancel;
877 (*normal_form produces the result in ONE step*)
878 val SOME (t',_) = nor t;
879 if term2str t' = "(3 - x) / (3 + x)" then ()
880 else error "rational.sml normal_form (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
882 (*initialize the interpreter state used by the 'me'*)
883 val (t,_,revsets,_) = ini t;
885 (*find the rule 'r' to apply to term 't'*)
886 val SOME (r as (Thm (str, thm))) = nex revsets t;
887 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))"
888 andalso string_of_thm thm =
889 (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
890 (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
891 else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
892 (* before Isa02->09-2 was not checked automatically, ?was different?:
893 val SOME r = nex revsets t;
894 val r = Thm ("sym_#mult_2_3","6 = 2 * 3") : rule*)
896 (* check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
897 if the rule is OK, the term resulting from applying the rule is returned,too;
898 there might be several rule applications inbetween,
899 which are listed after the head in reverse order *)
900 val (r, (t, asm))::_ = loc revsets t r;
901 if term2str t = "(9 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" andalso asm = []
903 else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
905 (* find the next rule to apply *)
906 val SOME (r as (Thm (str, thm))) = nex revsets t;
907 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso
908 string_of_thm thm = (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
909 (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
910 else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
912 (*check the next rule*)
913 val (r, (t, asm)) :: _ = loc revsets t r;
914 if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" then ()
915 else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) II";
917 (*find and check the next rules, rewrite*)
918 val SOME r = nex revsets t;
919 val (r,(t,asm))::_ = loc revsets t r;
920 if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
921 else error "rational.sml locate_rule II";
923 val SOME r = nex revsets t;
924 val (r,(t,asm))::_ = loc revsets t r;
925 if term2str t = "(3 - x) * (3 + x) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
926 else error "rational.sml next_rule II";
928 val SOME r = nex revsets t;
929 val (r,(t,asm))::_ = loc revsets t r;
930 if term2str t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then ()
931 else error "rational.sml next_rule III";
933 val SOME r = nex revsets t;
934 val (r, (t, asm)) :: _ = loc revsets t r;
936 if ss = "(3 - x) / (3 + x)" andalso terms2str asm = "[\"3 + x ~= 0\"]" then ()
937 else error "rational.sml: new behav. in rev-set cancel";
939 "-------- 'reverse-ruleset' cancel_p --------------------";
940 "-------- 'reverse-ruleset' cancel_p --------------------";
941 "-------- 'reverse-ruleset' cancel_p --------------------";
942 (*WN.11.9.02: the 'reverse-ruleset' cancel_p*)
944 (*the term for which reverse rewriting is demonstrated*)
945 val t = str2term "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))";
946 val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
947 next_rule=nex,normal_form=nor,...},...} = cancel_p;
949 (*normal_form produces the result in ONE step*)
950 val SOME (t',_) = nor t;
951 term2str t' = "(3 + 1 * x) / (3 + -1 * x)";
953 (*initialize the interpreter state used by the 'me'*)
954 val SOME (t', asm) = cancel_p_ thy t;
955 term2str t' = "(3 + x) / (3 + -1 * x)" (*true*);
956 terms2str asm = "[\"3 + -1 * x ~= 0\"]" (*true*);
957 val (t,_,revsets,_) = ini t;
959 (* WN.10.10.02: dieser Fall terminiert nicht
960 (make_polynomial enth"alt zu viele rules)
961 WN060823 'init_state' requires rewriting on specified location in the term
962 print_depth 99; Rfuns; print_depth 3;
963 WN060831 cycling "sym_order_mult_rls_" "sym_mult_assoc"
964 as was with make_polynomial before ?!?*)
966 val SOME r = nex revsets t;
967 eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))",
968 mk_thm thy "9 = 3 ^^^ 2"));
969 (*WN060831 *** id_of_thm
970 Exception- ERROR raised ...
971 val (r,(t,asm))::_ = loc revsets t r;
974 val SOME r = nex revsets t;
975 val (r,(t,asm))::_ = loc revsets t r;
979 writeln "****************** all tests successfull *************************";
983 (*WN.17.3.03 =========================================================vvv---*)
984 "-------- norm_Rational ---------------------------------";
985 "-------- norm_Rational ---------------------------------";
986 "-------- norm_Rational ---------------------------------";
987 val t = str2term "(3*x+5)/18 - x/2 - -(3*x - 2)/9 = 0";
988 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
989 if term2str t' = "1 / 18 = 0" then () else error "rational.sml 1";
991 val t = str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0";
992 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
993 if term2str t' = "(237 + 65 * x) / 36 = 0" then ()
994 else error "rational.sml 2";
996 val t = str2term "(1/2 + (5*x)/2)^^^2 - ((13*x)/2 - 5/2)^^^2 - (6*x)^^^2 + 29";
997 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
998 if term2str t' = "23 + 35 * x + -72 * x ^^^ 2" then ()
999 else error "rational.sml 3";
1001 (*trace_rewrite:=true;*)
1002 val t = str2term "Not (6*x is_atom)";
1003 val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
1005 val t = str2term "1 < 2";
1006 val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
1009 val t = str2term "(6*x)^^^2";
1010 val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false
1011 (num_str @{thm realpow_def_atom}) t;
1012 if term2str t' = "6 * x * (6 * x) ^^^ (2 + -1)" then ()
1013 else error "rational.sml powers_erls (6*x)^^^2";
1015 val t = str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))";
1016 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1017 if term2str t' = "65 * x / 2" then () else error "rational.sml 4";
1019 val t = str2term "1 - ((13*x)/2 - 5/2)^^^2";
1020 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1021 (*bef.040209: if term2str t' = "(-21 + (130 * x + -169 * x ^^^ 2)) / 4"then()*)
1022 if term2str t' = "(-21 + 130 * x + -169 * x ^^^ 2) / 4" then ()
1023 else error "rational.sml 5";
1025 (*SRAM Schalk I, p.92 Nr. 609a*)
1026 val t = str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
1027 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1028 if term2str t' = "(-255 + 112 * x) / 135" then ()
1029 else error "rational.sml 6";
1031 (*SRAM Schalk I, p.92 Nr. 610c*)
1032 val t = str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
1033 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1034 if term2str t' = "(-3 + -1 * x) / 2" then () else error "rational.sml 7";
1036 (*SRAM Schalk I, p.92 Nr. 476a*)
1037 val t = str2term "(x^^^2/(1 - x^^^2) + 1)/(x/(1 - x) + 1) * (1 + x)";
1038 (*. a/b : c/d translated to a/b * d/c .*)
1039 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1040 (*if term2str t' = "1 / 1" then () else error "rational.sml 8";3.6.03*)
1041 if term2str t' = "1" then () else error "rational.sml 8";
1043 (*............................vvv---TODO: sollte gehen mit poly_order *)
1044 (*Schalk I, p.92 Nr. 472a*)
1045 val t = str2term "((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
1046 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1047 if term2str t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
1049 (*Schalk I, p.70 Nr. 480b; a/b : c/d translated to a/b * d/c*)
1050 val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
1051 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
1052 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
1053 "(20*x*y/(x^^^2 - 25*y^^^2))");
1054 (*... nicht simpl, zerlegt ...*)
1055 val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
1056 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2))");
1057 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1058 "(-12 * (x * y ^^^ 3) + 108 * (x * (y * x ^^^ 2))) / (12 * (x * y))";
1059 (* ~~~~~~~~~~ poly_order notwendig!*)
1060 val t = str2term ("(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
1061 "(20*x*y/(x^^^2 - 25*y^^^2))");
1062 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1063 if term2str t' = "1 / (x ^^^ 2 + -25 * y ^^^ 2)" then ()
1064 else error "rational.sml norm_Rational 1 / (x ^^^ 2 + -25 * y ^^^ 2)";
1066 "nonterm.SK6 ----- SK060904-2a non-termination of add_fraction_p_";
1067 (*WN.2.6.03 from rlang.sml 56a
1068 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)";
1069 val NONE = rewrite_set_ thy false common_nominator_p t;
1071 WN060831 nonterm.SK7
1072 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
1073 val NONE = add_fraction_p_ thy t;
1077 (* ------------------------------------------------------------------- *)
1078 (*---------vvv------------ MG: ab 1.7.03 ----------------vvv-----------*)
1079 (* Simplifier fuer beliebige Buchterme *)
1080 (* ------------------------------------------------------------------- *)
1081 (*----------------------- norm_Rational_mg ----------------------------*)
1082 (* ------------------------------------------------------------------- *)
1084 "-------- numeral rationals -----------------------------";
1085 "-------- numeral rationals -----------------------------";
1086 "-------- numeral rationals -----------------------------";
1087 (*SRA Schalk I, p.40 Nr. 164b *)
1088 val t = str2term "(47/6 - 76/9 + 13/4)/(35/12)";
1089 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1091 if (term2str t) = "19 / 21" then ()
1092 else error "rational.sml: diff.behav. in norm_Rational_mg 1";
1094 (*SRA Schalk I, p.40 Nr. 166a *)
1095 val t = str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
1096 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1098 if (term2str t) = "45 / 2" then ()
1099 else error "rational.sml: diff.behav. in norm_Rational_mg 2";
1102 "-------- cancellation ----------------------------------";
1103 "-------- cancellation ----------------------------------";
1104 "-------- cancellation ----------------------------------";
1105 (* e190c Stefan K.*)
1107 "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
1108 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1111 "(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
1113 else error "rational.sml: diff.behav. in norm_Rational_mg 3";
1115 (* e192b Stefan K.*)
1117 "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
1118 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1123 else error "rational.sml: diff.behav. in norm_Rational_mg 4";
1125 (*SRC Schalk I, p.66 Nr. 379c *)
1128 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1133 else error "rational.sml: diff.behav. in norm_Rational_mg 5";
1135 (*SRC Schalk I, p.66 Nr. 380b *)
1137 "15*(3*x+3)*(4*x+9)/(12*(2*x+7)*(5*x+5))";
1138 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1141 "(27 + 12 * x) / (28 + 8 * x)"
1143 else error "rational.sml: diff.behav. in norm_Rational_mg 6";
1145 (*Schalk I, p.60 Nr. 215c *)
1146 (* Falsches Ergebnis: rechnet lange und cancel_p kann nicht weiter krzen!!!*)
1148 val t = str2term "(a+b)^^^4*(x - y)/((x - y)^^^3*(a+b)^^^2)";
1149 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1152 "(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)"
1154 else error "rational.sml: diff.behav. in norm_Rational_mg 7";
1157 "(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)"
1158 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1160 (* uncaught exception nonexhaustive binding failure
1161 raised at: stdIn:93.1-93.51 *)
1163 (*Schalk I, p.66 Nr. 381a *)
1164 (* ACHTUNG: rechnet ca. 2 Minuten !!! *)
1166 val t = str2term "18*(a+b)^^^3*(a - b)^^^2/(72*(a - b)^^^3*(a+b)^^^2)";
1167 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1170 "(a + b) / (4 * a + -4 * b)"
1171 then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
1174 (*SRC Schalk I, p.66 Nr. 381b *)
1176 "(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
1177 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1182 else error "rational.sml: diff.behav. in norm_Rational_mg 9";
1184 (*SRC Schalk I, p.66 Nr. 381c *)
1186 "(27*a^^^3+9*a^^^2+3*a+1)/(27*a^^^3+18*a^^^2+3*a)";
1187 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1190 "(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
1192 else error "rational.sml: diff.behav. in norm_Rational_mg 10";
1194 (*SRC Schalk I, p.66 Nr. 383a *)
1196 "(5*a^^^2 - 5*a*b)/(a - b)^^^2";
1197 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1200 "5 * a / (a + -1 * b)"
1202 else error "rational.sml: diff.behav. in norm_Rational_mg 11";
1205 "-------- common denominator ----------------------------";
1206 "-------- common denominator ----------------------------";
1207 "-------- common denominator ----------------------------";
1208 (*SRA Schalk I, p.67 Nr. 403a *)
1211 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1214 "(-3 * x + 4 * y + -1 * x * y) / (x * y)"
1216 else error "rational.sml: diff.behav. in norm_Rational_mg 12";
1218 (*SRA Schalk I, p.67 Nr. 407b *)
1220 "(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a^^^2+3*b*c)/(a*b*c)";
1221 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1226 else error "rational.sml: diff.behav. in norm_Rational_mg 13";
1228 (*SRA Schalk I, p.67 Nr. 410b *)
1230 "1/(x+1) + 1/(x+2) - 2/(x+3)";
1231 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1234 "(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)"
1236 else error "rational.sml: diff.behav. in norm_Rational_mg 14";
1238 (*SRA Schalk I, p.67 Nr. 413b *)
1240 "(1+x)/(1 - x) - (1 - x)/(1+x) + 2*x/(1 - x^^^2)";
1241 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1244 "6 * x / (1 + -1 * x ^^^ 2)"
1246 else error "rational.sml: diff.behav. in norm_Rational_mg 15";
1248 (*SRA Schalk I, p.68 Nr. 414a *)
1250 "(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))";
1251 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1254 "(-2 + -5 * x + 2 * x ^^^ 2) / (2 + -3 * x + x ^^^ 2)"
1256 else error "rational.sml: diff.behav. in norm_Rational_mg 16";
1258 (*SRA Schalk I, p.68 Nr. 423a *)
1260 "(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)";
1261 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1266 else error "rational.sml: diff.behav. in norm_Rational_mg 17";
1268 (*SRA Schalk I, p.68 Nr. 428b *)
1270 "1/(a - b)^^^2 + 1/(a+b)^^^2 - 2/(a^^^2 - b^^^2) - 4*(b^^^2 - 1)/(a^^^2 - b^^^2)^^^2";
1271 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1274 "4 / (a ^^^ 4 + -2 * a ^^^ 2 * b ^^^ 2 + b ^^^ 4)"
1276 else error "rational.sml: diff.behav. in norm_Rational_mg 18";
1278 (*SRA Schalk I, p.68 Nr. 430b *)
1280 "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";
1281 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1286 else error "rational.sml: diff.behav. in norm_Rational_mg 19";
1289 (*SRA Schalk I, p.68 Nr. 432 *)
1291 "(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)";
1292 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1297 else error "rational.sml: diff.behav. in norm_Rational_mg 20";
1302 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1305 "(3 * y + b * x) / (b * y)"
1307 else error "rational.sml: diff.behav. in norm_Rational_mg 21";
1310 "-------- multiply and cancel ---------------------------";
1311 "-------- multiply and cancel ---------------------------";
1312 "-------- multiply and cancel ---------------------------";
1313 (*SRM Schalk I, p.68 Nr. 436a *)
1315 "3*(x+y)/(15*(x - y)) * 25*(x - y)^^^2/(18*(x+y)^^^2)";
1316 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1319 "(5 * x + -5 * y) / (18 * x + 18 * y)"
1321 else error "rational.sml: diff.behav. in norm_Rational_mg 22";
1323 (*SRM.test Schalk I, p.68 Nr. 436b *)
1324 (*WN060420???MG3 crashes with method 'simplify' in
1325 IsacCore > Simplification > Rational Terms > Multiplication > No.2*)
1326 val t = str2term "5*a*(a - b)^^^2*(a + b)^^^3/(7*b*(a - b)^^^3) * 7*b/(a + b)^^^3";
1327 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1330 "5 * a / (a + -1 * b)"
1332 else error "rational.sml: diff.behav. in norm_Rational_mg 23";
1334 (*Schalk I, p.68 Nr. 437a *)
1335 val t = str2term "(3*a - 4*b)/(4*c+3*e) * (3*a+4*b)/(9*a^^^2 - 16*b^^^2)";
1336 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1337 if (term2str t) = "1 / (4 * c + 3 * e)" then ()
1338 else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1340 "----- S.K. corrected non-termination 060904";
1341 val t = str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a^^^2 - 16*b^^^2))";
1342 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
1345 "(9 * a ^^^ 2 + -16 * b ^^^ 2) /\n(36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c +\n -48 * b ^^^ 2 * e)"
1346 (*"(9 * a ^^^ 2 + -16 * b ^^^ 2) / (36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c + -48 * b ^^^ 2 * e)"*)
1347 then () else error "rational.sml: S.K.8..corrected 060904-6";
1349 "----- S.K. corrected non-termination of cancel_p_";
1350 val t'' = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
1351 "(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
1352 val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
1353 if term2str t' = "1 / (4 * c + 3 * e)" then ()
1354 else error "rational.sml: diff.behav. in cancel_p S.K.8";
1356 (*Schalk I, p.68 Nr. 437b *)
1357 (* nonterm.SK9 loops: cancel_p kann nicht weiter kuerzen!!! *)
1358 val t'' = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
1359 (* val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t'';
1362 "================delete===";
1363 (*a casual output from above*)
1365 "(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)";
1366 (* WN060831 nonterm.SK10
1367 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1371 (*SRM Schalk I, p.68 Nr. 438a *)
1373 "x*y/(x*y - y^^^2)*(x^^^2 - x*y)";
1374 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1379 else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1381 (*SRM Schalk I, p.68 Nr. 439b *)
1383 "(4*x^^^2+4*x+1)*((x^^^2 - 2*x^^^3)/(4*x^^^2+2*x))";
1384 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1387 "(x + -4 * x ^^^ 3) / 2"
1389 else error "rational.sml: diff.behav. in norm_Rational_mg 25";
1391 (*SRM Schalk I, p.68 Nr. 440a *)
1393 "(x^^^2 - 2*x)/(x^^^2 - 3*x) * (x - 3)^^^2/(x^^^2 - 4)";
1394 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1397 "(-3 + x) / (2 + x)"
1399 else error "rational.sml: diff.behav. in norm_Rational_mg 26";
1401 "----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
1403 "(a^^^3 - 9*a)/(a^^^3*b - a*b^^^3)*(a^^^2*b+a*b^^^2)/(a+3)";
1404 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1405 if term2str t = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
1406 else error "rational.sml: diff.behav. in norm_Rational 27";
1408 "----- SK12 works since 0707xx";
1409 val t = str2term "(a^^^3 - 9*a)*(a^^^2*b+a*b^^^2)/((a^^^3*b - a*b^^^3)*(a+3))";
1410 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1411 if term2str t' = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
1412 else error "rational.sml: diff.behav. in norm_Rational 28";
1415 "-------- common denominator and multiplication ---------";
1416 "-------- common denominator and multiplication ---------";
1417 "-------- common denominator and multiplication ---------";
1418 (*SRAM Schalk I, p.69 Nr. 441b *)
1419 val t = str2term "(4*a/3 + 3*b^^^2/a^^^3 + b/(4*a))*(4*b/(3*a))";
1420 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1423 "(36 * b ^^^ 3 + 3 * a ^^^ 2 * b ^^^ 2 + 16 * a ^^^ 4 * b) / (9 * a ^^^ 4)"
1424 then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
1426 (*SRAM Schalk I, p.69 Nr. 442b *)
1427 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)";
1428 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1431 "5 * x ^^^ 2 / (a * b ^^^ 3 * c)"
1432 then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
1434 (*SRAM Schalk I, p.69 Nr. 443b *)
1435 val t = str2term "(a/2 + b/3)*(b/3 - a/2)";
1436 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1439 "(-9 * a ^^^ 2 + 4 * b ^^^ 2) / 36"
1440 then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
1442 (*SRAM Schalk I, p.69 Nr. 445b *)
1443 val t = str2term "(a^^^2/9 + 2*a/(3*b) + 4/b^^^2)*(a/3 - 2/b) + 8/b^^^3";
1444 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1448 then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
1450 (*SRAM Schalk I, p.69 Nr. 446b *)
1451 val t = str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x^^^2 - 16*y^^^2)";
1452 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1455 "30 * x ^^^ 2 + -9 * x * y + -20 * y ^^^ 2"
1457 else error "rational.sml: diff.behav. in norm_Rational_mg 32";
1459 (*SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
1461 "(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)";
1462 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1464 if (term2str t) = "(-81 * x ^^^ 4 + 16 * x ^^^ 8 * y ^^^ 4) / (81 * y ^^^ 8)"
1465 then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
1468 (*SRAM Schalk I, p.69 Nr. 450a *)
1470 "(4*x/(3*y)+2*y/(3*x))^^^2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
1471 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1474 "(52 * x ^^^ 2 + 16 * y ^^^ 2) / (9 * y ^^^ 2)"
1476 else error "rational.sml: diff.behav. in norm_Rational_mg 34";
1479 "-------- double fractions ------------------------------";
1480 "-------- double fractions ------------------------------";
1481 "-------- double fractions ------------------------------";
1482 (*SRD Schalk I, p.69 Nr. 454b *)
1484 "((2 - x)/(2*a)) / (2*a/(x - 2))";
1485 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1488 "(-4 + 4 * x + -1 * x ^^^ 2) / (4 * a ^^^ 2)"
1490 else error "rational.sml: diff.behav. in norm_Rational_mg 35";
1492 (*SRD Schalk I, p.69 Nr. 455a *)
1494 "(a^^^2 + 1)/(a^^^2 - 1) / ((a+1)/(a - 1))";
1495 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1498 "(1 + a ^^^ 2) / (1 + 2 * a + a ^^^ 2)" then ()
1499 else error "rational.sml: diff.behav. in norm_Rational_mg 36";
1502 "----- Schalk I, p.69 Nr. 455b";
1503 val t = str2term "(x^^^2 - 4)/(y^^^2 - 9)/((2+x)/(3 - y))";
1504 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1505 if term2str t = "(2 + -1 * x) / (3 + y)" then ()
1506 else error "rational.sml: diff.behav. in norm_Rational_mg 37";
1508 "----- SK060904-1a non-termination of cancel_p_ ?: worked before 0707xx";
1509 val t = str2term "(x^^^2 - 4)*(3 - y)/((y^^^2 - 9)*(2+x))";
1510 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1511 if term2str t = "(2 + -1 * x) / (3 + y)" then ()
1512 else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
1514 "----- ?: worked before 0707xx";
1515 val t = str2term "(3 + -1 * y) / (-9 + y ^^^ 2)";
1516 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1517 if term2str t = "-1 / (3 + y)" then ()
1518 else error "rational.sml: -1 / (3 + y) norm_Rational";
1520 (*SRD Schalk I, p.69 Nr. 456b *)
1522 "(b^^^3 - b^^^2)/(b^^^2+b)/(b^^^2 - 1)";
1523 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1525 if (term2str t) = "b / (1 + 2 * b + b ^^^ 2)" then ()
1526 else error "rational.sml: diff.behav. in norm_Rational_mg 38";
1528 (*SRD Schalk I, p.69 Nr. 457b *)
1530 "(16*a^^^2 - 9*b^^^2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a^^^2 - 9*a^^^2*b^^^2))";
1531 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1534 "8 * a ^^^ 2 + -6 * a * b + -12 * a ^^^ 2 * b + 9 * a * b ^^^ 2"
1535 then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
1537 "----- Schalk I, p.69 Nr. 458b works since 0707";
1539 "(2*a^^^2*x - a^^^2)/(a*x - b*x) / (b^^^2*(2*x - 1)/(x*(a - b)))";
1540 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1541 if term2str t = "a ^^^ 2 / b ^^^ 2" then ()
1542 else error "rational.sml: diff.behav. in norm_Rational_mg 39b";
1544 (*SRD Schalk I, p.69 Nr. 459b *)
1545 val t = str2term "(a^^^2 - b^^^2)/(a*b) / (4*(a+b)^^^2/a)";
1546 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1547 if term2str t = "(a + -1 * b) / (4 * a * b + 4 * b ^^^ 2)" then ()
1548 else error "rational.sml: diff.behav. in norm_Rational_mg 41";
1551 (*Schalk I, p.69 Nr. 460b nonterm.SK
1553 "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
1554 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1557 else error "rational.sml: diff.behav. in norm_Rational_mg 42";
1560 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
1561 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
1562 ... non terminating.
1563 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
1564 "(-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)";
1565 val SOME (t,_) = rewrite_set_ thy false cancel_p t';
1566 ... non terminating.*)
1568 (*SRD Schalk I, p.70 Nr. 472a *)
1569 val t = str2term ("((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/" ^
1570 "((4*x - 8*y)/(x + y))");
1571 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1576 else error "rational.sml: diff.behav. in norm_Rational_mg 43";
1579 (*----------------------------------------------------------------------*)
1580 (*---------------------- Einfache Dppelbrche --------------------------*)
1581 (*----------------------------------------------------------------------*)
1583 (*SRD Schalk I, p.69 Nr. 461a *)
1585 "(2/(x+3) + 2/(x - 3)) / (8*x/(x^^^2 - 9))";
1586 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1591 else error "rational.sml: diff.behav. in norm_Rational_mg 44";
1593 (*SRD Schalk I, p.69 Nr. 464b *)
1595 "(a - a/(a - 2)) / (a + a/(a - 2))";
1596 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1599 "(3 + -1 * a) / (1 + -1 * a)"
1601 else error "rational.sml: diff.behav. in norm_Rational_mg 45";
1603 (*SRD Schalk I, p.69 Nr. 465b *)
1605 "((x+3*y)/9 + (4*y^^^2 - 9*z^^^2)/(16*x)) /(x/9+y/6+z/4)";
1606 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1609 "(4 * x + 6 * y + -9 * z) / (4 * x)"
1611 else error "rational.sml: diff.behav. in norm_Rational_mg 46";
1613 (*SRD Schalk I, p.69 Nr. 466b *)
1615 "((1 - 7*(x - 2)/(x^^^2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x^^^2 - 25))";
1616 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1619 "(25 + -10 * x + x ^^^ 2) / 18"
1621 else error "rational.sml: diff.behav. in norm_Rational_mg 47";
1623 (*SRD Schalk I, p.70 Nr. 469 *)
1625 "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))";
1626 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1629 "3 * b ^^^ 3 / (2 * a + -2 * b)"
1631 else error "rational.sml: diff.behav. in norm_Rational_mg 48";
1633 (*----------------------------------------------------------------------*)
1634 (*---------------------- Mehrfache Dppelbrueche ------------------------*)
1635 (*----------------------------------------------------------------------*)
1637 (*SRD.test Schalk I, p.70 Nr. 476b *) (* Rechenzeit: 10 sec *)
1638 (*WN060419 crashes with method 'simplify' ????SK*)
1640 "((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)";
1641 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1642 if term2str t = "1 / (a ^^^ 2 + -1 * b ^^^ 2)" then ()
1643 else error "rational.sml: diff.behav. in norm_Rational_mg 49";
1645 "----- Schalk I, p.70 Nr. 477a";
1646 (* MG Achtung: terme explodieren; Bsp zu komplex;
1647 L???ung sollte (ziemlich grosser) Faktorisierter Ausdruck sein
1648 val t = str2term "b*y/(b - 2*y)/((b^^^2 - y^^^2)/(b+2*y)) /" ^
1649 "(b^^^2*y+b*y^^^2)*(a+x)^^^2/((b^^^2 - 4*y^^^2)*(a+2*x)^^^2)";
1650 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
1653 val t = str2term "b*y*(b+2*y)*(b^^^2 - 4*y^^^2)*(a+2*x)^^^2 / " ^
1654 "((b - 2*y)*(b^^^2 - y^^^2)*(b^^^2*y+b*y^^^2)*(a+x)^^^2)";
1655 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
1659 "----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
1660 val t = str2term ("(a - (a*b+b^^^2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
1661 "((a - a^^^2/(a+b))/(a+(a*b)/(a - b)))");
1662 val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1664 "(2 * a ^^^ 3 + 2 * a ^^^ 2 * b) / (a ^^^ 2 * b + b ^^^ 3)"
1666 else error "rational.sml: diff.behav. in norm_Rational_mg 51";
1668 (* TODO.new_c:WN050820 STOP_REW_SUB introduced gave ...
1669 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 ()
1670 else error "rational.sml: works again";
1671 re-outcommented with TODO.new_c: cvs before 071227, 11:50*)
1675 (*Schalk I, p.70 Nr. 480a *)
1676 (* Achtung: rechnet ewig; cancel_p kann nicht krzen: WN060831 nonterm.SK00
1678 "(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)))";
1679 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1684 else error "rational.sml: diff.behav. in norm_Rational_mg 52";
1686 (*MG Berechne Zwischenergebnisse: WN060831 nonterm.SK00*)
1688 "(1/x+1/y+1/z)/(1/x - 1/y - 1/z)";
1689 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1691 "(x ^^^ 2 * y ^^^ 2 * z + x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2) /
1692 (-1 * x ^^^ 2 * y ^^^ 2 * z + -1 * x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2)";
1694 "2*x^^^2/(x^^^2 - z^^^2)/(x/(x+z)+x/(x - z))";
1695 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1699 (* SK 1. Ausdruck kann nicht weiter gekrzt werden; cancel_p !!!*)
1700 ### rls: cancel_p on:
1701 (x ^^^ 2 * (y ^^^ 2 * z) + x ^^^ 2 * (y * z ^^^ 2) + x * (y ^^^ 2 * z ^^^ 2)) /
1702 (-1 * (x ^^^ 2 * (y ^^^ 2 * z)) + -1 * (x ^^^ 2 * (y * z ^^^ 2)) + x * (y ^^^ 2 * z ^^^ 2))
1703 GC #3.61.81.101.197.17503: (0 ms)
1704 *** RATIONALS_DIRECT_CANCEL_EXCEPTION: Invalid fraction
1707 "(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))";
1708 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1710 (*uncaught exception nonexhaustive binding failure*)
1712 (* Das kann er aber krzen !!????: *)
1714 "(x^^^2 * (y^^^2 * z) + x * (y^^^2 * z^^^2)) / (-1 * (x^^^2 * (y * z^^^2)) + x * (y^^^2 * z^^^2))";
1715 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1717 "(-1 * (y * x) + -1 * (z * y)) / (1 * (z * x) + -1 * (z * y))";
1721 "-------- crucial examples ------------------------------";
1722 "-------- crucial examples ------------------------------";
1723 "-------- crucial examples ------------------------------";
1724 (*Schalk I, p.60 Nr. 215d *)
1725 (* Achtung: rechnet ewig ...
1726 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
1727 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1728 term2str t; noterm.SK
1731 (* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt:*)
1733 val t = str2term "(a-b)^^^3 * (x+y)^^^4";
1734 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1736 "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";
1737 val t = str2term "((x+y)^^^2 * (a-b)^^^5)";
1738 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1740 "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";
1742 (*anscheinend macht dem Rechner das Krzen diese Bruches keinen Spass mehr ...*)
1744 (*--------------------------------------------------------------------*)
1745 (*Schalk I, p.70 Nr. 480b
1746 val t = str2term "((12*x*y/(9*x^^^2 - y^^^2))/" ^
1747 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
1748 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
1749 "(20*x*y/(x^^^2 - 25*y^^^2))";
1750 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1752 Kann nicht weiter vereinfacht werden !!!!?? *)
1754 (*--------------------------------------------------------------------*)
1755 "---- MGs test set";
1756 val t = str2term " (1 + x^^^5) / (y + x) + x^^^3 / x ";
1757 val SOME (t,_) = rewrite_set_ thy false common_nominator_p t;
1758 if term2str t = "(1 + x ^^^ 3 + x ^^^ 5 + y * x ^^^ 2) / (x + y)" then()
1761 (*--------------------------------------------------------------------*)
1762 (* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3b
1763 ---> Sortierung FALSCH !! *)
1764 val t = str2term "b^^^3 * a^^^5/a ";
1765 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1767 "1 * (a^^^4 * b^^^3) / 1"; (*OK*)
1769 val t = str2term "b^^^3 * a^^^5/b ";
1770 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1772 "1 * (b^^^2 * a^^^5) / 1"; (*cancel_p sortiert hier falsch um!*)
1774 (* Problem liegt NICHT bei ord_make_polynomial! (siehe folgende Bsple) *)
1776 val x = str2term "x"; val bdv = str2term "bdv";
1777 val t1 = str2term "b^^^2 * a^^^5";
1778 val t2 = str2term "a^^^5 * b^^^2 ";
1779 ord_make_polynomial false Rational.thy [(x,bdv)] (t1,t2); (*false*)
1781 (* ==> "b^^^2 * a^^^5" > "a^^^5 * b^^^2 " ... OK!*)
1783 (*--------------------------------------------------------------------*)
1784 (* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3c
1785 ---> erzeugt berflssige "1 * ..."
1787 val t = str2term "-1 / (3 + y)";
1789 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1792 (********* Das ist das PROBLEM !!!!!!!??? *******************)
1793 (* -1 im Z???ler der Angabe verursacht das Problem !*)
1796 (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
1797 "----- MGs test set";
1798 val t = str2term "(a^^^2 + -1)/(a+1)";
1799 val SOME (t',_) = rewrite_set_ thy false cancel_p t;
1800 if term2str t' = "(-1 + a) / 1" then ()
1801 else error "rational.sml MG tests 3d";
1803 "----- NOT TERMINATING ?: worked before 0707xx";
1804 val t = str2term "(a^^^2 - 1)*(b + 1) / ((b^^^2 - 1)*(a+1))";
1805 val SOME (t'',_) = rewrite_set_ thy false norm_Rational t;
1806 if term2str t'' = "(1 + -1 * a) / (1 + -1 * b)" then ()
1807 else error "rational.sml MG tests 3e";
1809 "----- corrected SK060905";
1810 val t = str2term "(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
1811 val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1812 if term2str t' = "-1 / (5 + -2 * x)" then ()
1813 else error "rational.sml corrected SK060905";
1816 "-------- examples for Stefan Karnels thesis ------------";
1817 "-------- examples for Stefan Karnels thesis ------------";
1818 "-------- examples for Stefan Karnels thesis ------------";
1819 (*SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*)
1821 "(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))";
1822 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1825 "5 * x ^^^ 2 / (b ^^^ 3 * c)"
1827 else error "rational.sml: diff.behav. in norm_Rational_mg 53";
1830 "-------- me Schalk I No.186 ----------------------------";
1831 "-------- me Schalk I No.186 ----------------------------";
1832 "-------- me Schalk I No.186 ----------------------------";
1833 val fmz = ["Term ((14 * x * y) / ( x * y ))",
1836 ("Rational",["rational","simplification"],
1837 ["simplification","of_rationals"]);
1838 val p = e_pos'; val c = [];
1839 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
1840 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1841 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1842 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1843 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1844 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1845 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1846 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1847 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1848 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1849 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1850 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1851 case (f2str f, nxt) of
1852 ("14", ("End_Proof'", _)) => ()
1853 | _ => error "rational.sml diff.behav. in me Schalk I No.186";
1856 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
1857 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
1858 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
1861 [(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"],
1862 ("Rational",["rational","simplification"],
1863 ["simplification","of_rationals"]))];
1866 autoCalculate 1 CompleteCalc;
1867 val ((pt,p),_) = get_calc 1; show_pt pt;
1869 interSteps 1 ([1],Res);
1870 val ((pt,p),_) = get_calc 1; show_pt pt;
1873 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
1874 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
1875 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
1878 [(["Term ((a^2 + -1*b^2) / (a^2 + -2*a*b + b^2))", "normalform N"],
1879 ("Rational",["rational","simplification"],
1880 ["simplification","of_rationals"]))];
1883 autoCalculate 1 CompleteCalc;
1884 val ((pt,p),_) = get_calc 1; show_pt pt;
1885 (*========== inhibit exn 110314 ================================================
1886 (*with explicit script done already... and removed [1,..] at below...
1887 interSteps 1 ([1],Res);
1888 val ((pt,p),_) = get_calc 1; show_pt pt;
1890 interSteps 1 ([2],Res);
1891 val ((pt,p),_) = get_calc 1; show_pt pt;
1893 interSteps 1 ([2,1],Res);
1894 val ((pt,p),_) = get_calc 1; show_pt pt;
1895 val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*);
1896 (*if length newnds = 12 then () WN060905*)
1897 if length newnds = 13 then ()
1898 else error "rational.sml: interSteps cancel_p rev_rew_p";
1900 val p = ([2,1,9],Res);
1902 val (_, tac, _) = pt_extract (pt, p);
1903 (*case tac of SOME (Rewrite ("sym_real_plus_binom_times1", _)) => ()
1905 case tac of SOME (Rewrite ("sym_real_add_mult_distrib2", _)) => ()
1906 | _ => error "rational.sml: getTactic, sym_real_plus_binom_times1";
1907 ============ inhibit exn 110314 ==============================================*)
1910 "-------- investigate rulesets for cancel_p -------------";
1911 "-------- investigate rulesets for cancel_p -------------";
1912 "-------- investigate rulesets for cancel_p -------------";
1913 val thy = @{theory "Rational"};
1914 "---------------- (a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
1915 val t = str2term "(a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
1916 val tt = str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"(*numerator only*);
1917 "----- with rewrite_set_";
1918 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
1919 term2str tt'= "a ^^^ 2 + -1 * b ^^^ 2" (*true*);
1920 val tt = str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*);
1921 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
1922 term2str tt' = "a ^^^ 2 + -2 * a * b + b ^^^ 2" (*true*);
1924 "----- with make_deriv";
1925 val SOME (tt, _) = factout_p_ thy t; term2str tt =
1926 "(1 * a + 1 * b) * (1 * a + -1 * b) / ((1 * a + -1 * b) * (1 * a + -1 * b))";
1928 "--- with ruleset as before 060829";
1929 val {rules, rew_ord=(_,ro),...} =
1930 rep_rls (assoc_rls "make_polynomial");
1931 val der = make_deriv thy Atools_erls rules ro NONE tt;
1932 print_depth 99; map (term2str o #1) der; print_depth 3;
1933 print_depth 99; map (rule2str o #2) der; print_depth 3;
1934 ... did not terminate*)
1935 "--- with simpler ruleset";
1936 val {rules, rew_ord=(_,ro),...} =
1937 rep_rls (assoc_rls "rev_rew_p");
1938 val der = make_deriv thy Atools_erls rules ro NONE tt;
1939 print_depth 99; writeln (deriv2str der); print_depth 3;
1941 print_depth 99; map (term2str o #1) der; print_depth 3;
1942 "...,(-1 * b ^^^ 2 + a ^^^ 2) / (-2 * (a * b) + a ^^^ 2 + (-1 * b) ^^^ 2) ]";
1943 print_depth 99; map (rule2str o #2) der; print_depth 3;
1944 print_depth 99; map (term2str o #1 o #3) der; print_depth 3;
1946 val der = make_deriv thy Atools_erls rules ro NONE
1947 (str2term "(1 * a + 1 * b) * (1 * a + -1 * b)");
1948 print_depth 99; writeln (deriv2str der); print_depth 3;
1950 val {rules, rew_ord=(_,ro),...} =
1951 rep_rls (assoc_rls "rev_rew_p");
1952 val der = make_deriv thy Atools_erls rules ro NONE
1953 (str2term "(1 * a + -1 * b) * (1 * a + -1 * b)");
1954 print_depth 99; writeln (deriv2str der); print_depth 3;
1955 print_depth 99; map (term2str o #1) der; print_depth 3;
1956 (*WN060829 ...postponed*)
1959 "-------- investigate format of factout_ and factout_p_ -";
1960 "-------- investigate format of factout_ and factout_p_ -";
1961 "-------- investigate format of factout_ and factout_p_ -";
1962 val {rules, rew_ord = (_,ro),...} = rep_rls (assoc_rls "make_polynomial");
1963 val (thy, eval_rls) = (@{theory "Rational"}, Atools_erls)(*see 'fun init_state'*);
1964 val Rrls {scr = Rfuns {init_state,...},...} = assoc_rls "cancel_p";
1966 "----- see Rational.ML, local cancel_p, fun init_state";
1967 val t = str2term "(a^^^2 + (-1)*b^^^2) / (a^^^2 + (-2)*a*b + b^^^2)";
1968 val SOME (t',_) = factout_p_ thy t; term2str t';
1970 val rtas = reverse_deriv thy eval_rls rules ro NONE t';
1971 writeln(trtas2str rst);
1975 "----- see Rational.ML, local cancel_p, fun init_state";
1976 val t = str2term "a^^^2 / a";
1977 val SOME (t',_) = factout_p_ thy t;
1978 term2str t' = "a * a / (1 * a)" (*true*);
1979 (*... can be canceled with
1980 real_mult_div_cancel2 ?k ~= 0 ==> ?m * ?k / (?n * ?k) = ?m / ?n"*)
1981 (* sml/ME/rewtools.sml:
1982 val rtas = reverse_deriv thy Atools_erls rules ro NONE t';
1983 writeln (deri2str rtas);
1987 "-------- SK 060904 ----------------------------------------------";
1988 "----- order on polynomials -- input + output";
1989 val thy = @{theory "Isac"};
1990 val t = str2term "(a + -1 * b) / (-1 * a + b)";
1991 val SOME (t', _) = factout_p_ thy t; term2str t';
1992 val SOME (t', _) = cancel_p_ thy t; term2str t';
1994 val t = str2term "a*b*c*d / (d*e*f*g)";
1995 val SOME (t', _) = cancel_p_ thy t; term2str t';
1997 val t = str2term "a*(b*(c*d)) / (b*(e*(f*g)))";
1998 val SOME (t', _) = cancel_p_ thy t; term2str t';
2001 "----- SK060904-1a non-termination of cancel_p_ ? worked before 0707xx";
2002 val t = str2term "(x^^^2 - 4)*(3 - y) / ((y^^^2 - 9)*(2+x))";
2003 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
2004 if term2str t' = "(2 + -1 * x) / (3 + y)" then ()
2005 else error "rational.sml SK060904-1a worked since 0707xx";
2007 "----- SK060904-1b non-termination of cancel_p_ ... worked before 0707xx";
2008 val t = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
2009 "(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
2010 val SOME (t',_) = cancel_p_ thy t;
2011 if term2str t' = "1 / (4 * c + 3 * e)" then ()
2012 else error "rational.sml SK060904-1b";
2015 "----- SK060904-2a non-termination of add_fraction_p_";
2016 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^
2017 " (-1 * a + b * x) / (a + b * x) ");
2019 val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
2021 common_nominator_p_ thy t;
2022 " (a + b * x)*(a + b * x) / ((a + -1 * (b * x))*(a + -1 * (b * x))) + " ^
2023 " (-1 * a + b * x)*(a + -1 * (b * x)) / ((a + b * x)*(-1 * a + b * x)) ";
2025 add_fraction_p_ thy t;
2026 " ((a + b * x)*(a + b * x) + (-1 * a + b * x)*(a + -1 * (b * x))) /" ^
2027 " ((a + b * x)*(-1 * a + b * x)) ";
2031 "-------- how to stepwise construct Scripts -------------";
2032 "-------- how to stepwise construct Scripts -------------";
2033 "-------- how to stepwise construct Scripts -------------";
2034 val thy = @{theory "Rational"};
2036 val p1 = parse thy (
2037 "Script SimplifyScript (t_t::real) = " ^
2038 " (Rewrite_Set discard_minus False " ^
2041 (*required (): (Rewrite_Set discard_minus False)*)
2042 val p2 = parse thy (
2043 "Script SimplifyScript (t_t::real) = " ^
2044 " (Rewrite_Set discard_minus False " ^
2047 val p3 = parse thy (
2048 "Script SimplifyScript (t_t::real) = " ^
2049 " ((Rewrite_Set discard_minus False) " ^
2052 val p4 = parse thy (
2053 "Script SimplifyScript (t_t::real) = " ^
2054 " ((Rewrite_Set discard_minus False) " ^
2057 val p5 = parse thy (
2058 "Script SimplifyScript (t_t::real) = " ^
2059 " ((Try (Rewrite_Set discard_minus False) " ^
2060 " Try (Rewrite_Set discard_parentheses False)) " ^
2063 val p6 = parse thy (
2064 "Script SimplifyScript (t_t::real) = " ^
2065 " ((Try (Rewrite_Set discard_minus False) @@ " ^
2066 " Try (Rewrite_Set rat_mult_poly False) @@ " ^
2067 " Try (Rewrite_Set make_rat_poly_with_parentheses False) @@ " ^
2068 " Try (Rewrite_Set cancel_p_rls False) @@ " ^
2070 " ((Try (Rewrite_Set common_nominator_p_rls False) @@ " ^
2071 " Try (Rewrite_Set rat_mult_div_pow False) @@ " ^
2072 " Try (Rewrite_Set make_rat_poly_with_parentheses False) @@" ^
2073 " Try (Rewrite_Set cancel_p_rls False) @@ " ^
2074 " Try (Rewrite_Set rat_reduce_1 False)))) @@ " ^
2075 " Try (Rewrite_Set discard_parentheses False)) " ^
2079 "----------- get_denominator ----------------------------";
2080 "----------- get_denominator ----------------------------";
2081 "----------- get_denominator ----------------------------";
2082 val thy = @{theory Isac};
2083 val t = term_of (the (parse thy "get_denominator ((a +x)/b)"));
2084 val SOME (_, t') = eval_get_denominator "" 0 t thy;
2085 if term2str t' = "get_denominator ((a + x) / b) = b" then ()
2086 else error "get_denominator ((a + x) / b) = b"
2089 "--------- several errpats in complicated term -------------------";
2090 "--------- several errpats in complicated term -------------------";
2091 "--------- several errpats in complicated term -------------------";
2092 (*TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one*)
2095 [(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"],
2096 ("Rational",["rational","simplification"], ["simplification","of_rationals"]))];
2099 autoCalculate 1 CompleteCalc;
2100 val ((pt,p),_) = get_calc 1; show_pt pt;
2102 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
2103 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
2104 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
2105 (*------------------------------------------------------------------------------------\
2106 "--- WN121204: searched rational.sml for "nonterm", added new numbering" ^
2107 " and thoroughly tested with this numbering subsequently";
2109 WN.2.6.03 from rlang.sml 56a
2110 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)";
2111 val NONE = rewrite_set_ thy false common_nominator_p t;
2113 WN060831 nonterm.SK7
2114 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
2115 val NONE = add_fraction_p_ thy t;
2117 nonterm.SK9 loops: cancel_p kann nicht weiter kuerzen!!! *)
2118 val t'' = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
2119 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t'';
2122 "(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)";
2123 WN060831 nonterm.SK10
2124 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
2128 "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
2129 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2132 else error "rational.sml: diff.behav. in norm_Rational_mg 42";
2135 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
2136 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
2137 ... non terminating.
2139 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
2140 "(-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)";
2141 val SOME (t,_) = rewrite_set_ thy false cancel_p t';
2143 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
2144 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2146 val t = str2term "((12*x*y/(9*x^^^2 - y^^^2))/" ^
2147 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
2148 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
2149 "(20*x*y/(x^^^2 - 25*y^^^2))";
2150 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2152 SK060904-2a non-termination of add_fraction_p_";
2153 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^
2154 " (-1 * a + b * x) / (a + b * x) ");
2156 val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
2158 common_nominator_p_ thy t;
2159 " (a + b * x)*(a + b * x) / ((a + -1 * (b * x))*(a + -1 * (b * x))) + " ^
2160 " (-1 * a + b * x)*(a + -1 * (b * x)) / ((a + b * x)*(-1 * a + b * x)) ";
2162 add_fraction_p_ thy t;
2163 " ((a + b * x)*(a + b * x) + (-1 * a + b * x)*(a + -1 * (b * x))) /" ^
2164 " ((a + b * x)*(-1 * a + b * x)) ";
2165 --------------------------------------------------------------------------------------/*)
2167 (*------------------------------------------------------------------------------------\
2168 "WN121205: thoroughly tested with the above numbering.";
2169 " errors in cancel_p: --- 4,5,6,7.";
2170 " error in common_nominator_p, common_nominator_p_: --- 10; 1,2?.";
2171 " errors caused by ruleset norm_Rational: --- 8,9.";
2172 trace_rewrite := true;
2174 "--- 1 ---: non-terminating with ### add_fract: done t22 ";
2175 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)";
2176 trace_rewrite:= true;
2177 rewrite_set_ thy false common_nominator_p t;
2179 "--- 2 ---: non-terminating with ### add_fract: done t22 ";
2180 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
2181 add_fraction_p_ thy t;
2183 "--- 3 ---: norm_Rational calls Rrls cancel_p with non-normalised polys";
2184 val t = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
2185 rewrite_set_ thy false norm_Rational t;
2186 (*tracing end...#### rls: cancel_p on:
2187 (a * x ^^^ 2 + -2 * (a * (x * y)) + a * y ^^^ 2 + b * x ^^^ 2 + -2 * (b * (x * y)) + b * y ^^^ 2) /
2188 (a ^^^ 2 * x ^^^ 2 + -1 * (a ^^^ 2 * y ^^^ 2) + -1 * (b ^^^ 2 * x ^^^ 2) + b ^^^ 2 * y ^^^ 2) *)
2190 "--- 4 ---: non-terminating with Rrls cancel_p on plausible input";
2192 "(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /"^
2193 "(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)");
2194 rewrite_set_ thy false cancel_p t;
2195 (*# rls: cancel_p on:
2196 (a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /
2197 (a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2) *)
2199 "--- 5 ---: non-terminating with Rrls cancel_p on plausible input";
2200 val t = str2term "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
2201 rewrite_set_ thy false norm_Rational t;
2202 (*#### rls: cancel_p on:
2203 (2304 + -1152 * x + -2304 * y + 144 * x ^^^ 2 + 1152 * (x * y) + -144 * (x ^^^ 2 * y)) /
2204 (48 + -12 * x + -96 * y + 24 * (x * y) + 48 * y ^^^ 2 + -12 * (x * y ^^^ 2)) *)
2206 "--- 6 ---: non-terminating with Rrls cancel_p on plausible input";
2208 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
2209 rewrite_set_ thy false norm_Rational t;
2210 (*### rls: cancel_p on: (-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * (x * y) +
2211 144 * (x ^^^ 2 * y)) /
2212 (-48 + 12 * x + 96 * y + -24 * (x * y) + -48 * y ^^^ 2 + 12 * (x * y ^^^ 2)) *)
2214 "--- 7 ---: non-terminating with Rrls cancel_p on plausible input";
2216 "(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /"^
2217 "(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)");
2218 rewrite_set_ thy false cancel_p t';
2220 "--- 8 ---: bottom of output cannot be looked ad (due to looping?)";
2221 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
2222 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
2224 "--- 9 ---: probably error in norm_Rational";
2226 "((12*x*y / (9*x^^^2 - y^^^2)) / (1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
2227 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2) / (20*x*y/(x^^^2 - 25*y^^^2))");
2228 rewrite_set_ thy false norm_Rational t;
2229 (*#### rls: cancel_p on: (19440 * (x ^^^ 8 * y ^^^ 2) + -490320 * (x ^^^ 6 * y ^^^ 4) +
2230 108240 * (x ^^^ 4 * y ^^^ 6) +
2231 -6000 * (x ^^^ 2 * y ^^^ 8)) /
2232 (2160 * (x ^^^ 8 * y ^^^ 2) + -108240 * (x ^^^ 6 * y ^^^ 4) +
2233 1362000 * (x ^^^ 4 * y ^^^ 6) +
2234 -150000 * (x ^^^ 2 * y ^^^ 8)) *)
2236 "--- 10 ---: non-terminating with ### add_fract: done t22: error in common_nominator_p ";
2237 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)");
2238 rewrite_set_ thy false common_nominator_p t; (*### add_fract: done t22 *)
2239 common_nominator_p_ thy t; (*loops without output*)
2240 "--- reformulated 10:";
2241 val t = str2term "(a + -1 * (b * x)) / (a + b * x)";
2242 rewrite_set_ thy false cancel_p t = NONE;
2245 "...both are to be considered after common_nominator_p_ is improved";
2246 --------------------------------------------------------------------------------------/*)