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 "-------- fun poly_of_term ---------------------------------------------------";
22 "-------- fun is_poly --------------------------------------------------------";
23 "-------- fun term_of_poly ---------------------------------------------------";
24 "-------- fun factout_p_ -----------------------------------------------------";
25 "-------- fun cancel_p_ ------------------------------------------------------";
26 "-------- fun common_nominator_p_ --------------------------------------------";
27 "-------- fun add_fraction_p_ ------------------------------------------------";
28 "-------- TODO ---------------------------------------------------------------";
29 "-------- and app_rev --------------------------------------------------------";
30 "-------- external calculating functions test -----------";
31 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
32 "-------- common_nominator_p ----------------------------";
33 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
34 "-------- reverse rewrite -------------------------------";
35 "-------- 'reverse-ruleset' cancel_p --------------------";
36 "-------- norm_Rational ---------------------------------";
37 "-------- numeral rationals -----------------------------";
38 "-------- cancellation ----------------------------------";
39 "-------- common denominator ----------------------------";
40 "-------- multiply and cancel ---------------------------";
41 "-------- common denominator and multiplication ---------";
42 "-------- double fractions ------------------------------";
43 "-------- crucial examples ------------------------------";
44 "-------- examples for Stefan Karnels thesis ------------";
45 "-------- me Schalk I No.186 ----------------------------";
46 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
47 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
48 "-------- investigate rulesets for cancel_p -------------";
49 "-------- investigate format of factout_ and factout_p_ -";
50 "-------- how to stepwise construct Scripts -------------";
51 "----------- get_denominator ----------------------------";
52 "--------- several errpats in complicated term -------------------";
53 "--------------------------------------------------------";
54 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
55 "--------------------------------------------------------";
56 "--------------------------------------------------------";
59 "-------- fun poly_of_term ---------------------------------------------------";
60 "-------- fun poly_of_term ---------------------------------------------------";
61 "-------- fun poly_of_term ---------------------------------------------------";
62 val vs = "12 * x^^^3 * y^^^4 * z^^^6" |> str2term |> vars |> map free2str |> sort string_ord;
64 if poly_of_term vs (str2term "12::real") = SOME [(12, [0, 0, 0])]
65 then () else error "poly_of_term 1 changed";
66 if poly_of_term vs (str2term "x::real") = SOME [(1, [1, 0, 0])]
67 then () else error "poly_of_term 2 changed";
68 if poly_of_term vs (str2term "12 * x^^^3") = SOME [(12, [3, 0, 0])]
69 then () else error "poly_of_term 3 changed";
70 if poly_of_term vs (str2term "12 * x^^^3 * y^^^4 * z^^^6") = SOME [(12, [3, 4, 6])]
71 then () else error "poly_of_term 4 changed";
72 if poly_of_term vs (str2term "1 + 2 * x^^^3 * y^^^4 * z^^^6 + y") =
73 SOME [(1, [0, 0, 0]), (1, [0, 1, 0]), (2, [3, 4, 6])]
74 then () else error "poly_of_term 5 changed";
76 (*poly_of_term is quite liberal:*)
77 (*the coefficient may be somewhere, the order of variables and the parentheses
78 within a monomial are arbitrary*)
79 if poly_of_term vs (str2term "y^^^4 * (x^^^3 * 12 * z^^^6)") = SOME [(12, [3, 4, 6])]
80 then () else error "poly_of_term 6 changed";
82 (*there may even be more than 1 coefficient:*)
83 if poly_of_term vs (str2term "2 * y^^^4 * (x^^^3 * 6 * z^^^6)") = SOME [(12, [3, 4, 6])]
84 then () else error "poly_of_term 7 changed";
86 (*the order and the parentheses within monomials are arbitrary:*)
87 if poly_of_term vs (str2term "2 * x^^^3 * y^^^4 * z^^^6 + (7 * y^^^8 + 1)")
88 = SOME [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 6])]
89 then () else error "poly_of_term 8 changed";
91 "-------- fun is_poly --------------------------------------------------------";
92 "-------- fun is_poly --------------------------------------------------------";
93 "-------- fun is_poly --------------------------------------------------------";
94 if is_poly (str2term "2 * x^^^3 * y^^^4 * z^^^6 + 7 * y^^^8 + 1")
95 then () else error "is_poly 1 changed";
96 if not (is_poly (str2term "2 * (x^^^3 * y^^^4 * z^^^6 + 7) * y^^^8 + 1"))
97 then () else error "is_poly 2 changed";
99 "-------- fun term_of_poly ---------------------------------------------------";
100 "-------- fun term_of_poly ---------------------------------------------------";
101 "-------- fun term_of_poly ---------------------------------------------------";
102 val expT = HOLogic.realT
103 val Free (_, baseT) = (hd o vars o str2term) "12 * x^^^3 * y^^^4 * z^^^6";
104 val p = [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 5])]
105 val vs = ["x","y","z"]
106 (*precondition for [(c, es),...]: legth es = length vs*)
108 if term2str (term_of_poly baseT expT vs p) = "1 + 7 * y ^^^ 8 + 2 * x ^^^ 3 * y ^^^ 4 * z ^^^ 5"
109 then () else error "term_of_poly 1 changed";
111 "-------- fun factout_p_ -----------------------------------------------------";
112 "-------- fun factout_p_ -----------------------------------------------------";
113 "-------- fun factout_p_ -----------------------------------------------------";
114 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)"
115 val SOME (t', asm) = factout_p_ thy t;
116 if term2str t' = "(x + y) * (x + -1 * y) / (x * (x + -1 * y))"
117 then () else error ("factout_p_ term 1 changed: " ^ term2str t')
119 if terms2str asm = "[\"x ~= 0\",\"x + -1 * y ~= 0\"]"
120 then () else error "factout_p_ asm 1 changed"
122 val t = str2term "nothing + to_cancel ::real";
123 if NONE = factout_p_ thy t then () else error "factout_p_ doesn't report non-applicable";
125 val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
126 val SOME (t', asm) = factout_p_ thy t;
127 if term2str t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso
128 terms2str asm = "[\"1 + x ~= 0\"]"
129 then () else error "factout_p_ 1 changed";
131 "-------- fun cancel_p_ ------------------------------------------------------";
132 "-------- fun cancel_p_ ------------------------------------------------------";
133 "-------- fun cancel_p_ ------------------------------------------------------";
134 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)"
135 val SOME (t', asm) = cancel_p_ thy t;
136 if (term2str t', terms2str asm) = ("(x + y) / x", "[\"x ~= 0\"]")
137 then () else error ("cancel_p_ (t', asm) 1 changed: " ^ term2str t')
139 val t = str2term "nothing + to_cancel ::real";
140 if NONE = cancel_p_ thy t then () else error "cancel_p_ doesn't report non-applicable";
142 val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
143 val SOME (t', asm) = cancel_p_ thy t;
144 if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[]"
145 then () else error "cancel_p_ 1 changed";
147 "-------- fun common_nominator_p_ --------------------------------------------";
148 "-------- fun common_nominator_p_ --------------------------------------------";
149 "-------- fun common_nominator_p_ --------------------------------------------";
150 val t = str2term ("y / (a*x + b*x + c*x) " ^
154 val SOME (t', asm) = common_nominator_p_ thy t;
156 ("y * y / (x * ((a + b + c) * y)) " ^
157 (* n1 *d2'/ (c'* ( d1' *d2')) *)
158 "+ a * (a + b + c) / (x * ((a + b + c) * y))")
159 (* n2 * d1' / (c'* ( d1' *d2')) *)
160 then () else error "common_nominator_p_ term 1 changed";
161 if terms2str asm = "[\"a + b + c ~= 0\",\"y ~= 0\",\"x ~= 0\"]"
162 then () else error "common_nominator_p_ asm 1 changed"
164 "-------- example in mail Nipkow";
165 val t = str2term "x/(x^^^2 + -1*y^^^2) + y/(x^^^2 + -1*x*y)";
166 val SOME (t', asm) = common_nominator_p_ thy t;
167 if term2str t' = "x * x / " ^
168 "((x + -1 * y) * ((x + y) * x))" ^
171 "((x + -1 * y) * ((x + y) * x))"
172 then () else error "common_nominator_p_ term 2 changed"
174 if terms2str asm = "[\"x + y ~= 0\",\"x ~= 0\",\"x + -1 * y ~= 0\"]"
175 then () else error "common_nominator_p_ asm 2 changed"
177 "-------- example: applicable tested by SML code";
178 val t = str2term "nothing / to_add";
179 if NONE = common_nominator_p_ thy t then () else error "common_nominator_p_ term 3 changed";
181 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
182 val SOME (t', asm) = common_nominator_p_ thy t;
184 "(x + -1) * (-1 + x) / (1 * ((1 + x) * (-1 + x))) +\n(x + 1) * (1 + x) / (1 * ((1 + x) * (-1 + x)))"
185 andalso terms2str asm = "[\"1 + x ~= 0\",\"-1 + x ~= 0\"]"
186 then () else error "common_nominator_p_ 3 changed";
188 "-------- fun add_fraction_p_ ------------------------------------------------";
189 "-------- fun add_fraction_p_ ------------------------------------------------";
190 "-------- fun add_fraction_p_ ------------------------------------------------";
191 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
192 val SOME (t', asm) = add_fraction_p_ thy t;
193 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)"
194 then () else error "add_fraction_p_ 3 changed";
196 if terms2str asm = "[\"-1 + x ^^^ 2 ~= 0\"]"
197 then () else error "add_fraction_p_ 3 changed";
199 val t = str2term "nothing / to_add";
200 if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ term 3 changed";
202 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
203 val SOME (t', asm) = add_fraction_p_ thy t;
204 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso
205 terms2str asm = "[\"-1 + x ^^^ 2 ~= 0\"]"
206 then () else error "add_fraction_p_ 3 changed";
208 "-------- TODO ---------------------------------------------------------------";
209 "-------- TODO ---------------------------------------------------------------";
210 "-------- TODO ---------------------------------------------------------------";
214 "-------- and app_rev --------------------------------------------------------";
215 "-------- and app_rev --------------------------------------------------------";
216 "-------- and app_rev --------------------------------------------------------";
217 (* trace down until prepats are evaluated
218 (which does not to work, because substitution is not done -- compare rew_sub!);
219 keep this sequence for the case, factout_p, cancel_p, common_nominator_p, add_fraction_p
220 (again) get prepat = [] changed to <>[]. *)
221 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)";
223 (*rewrite_set_ @{theory Isac} true cancel t = NONE; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
224 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (thy, false, cancel_p, t);
225 "~~~~~ fun rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
226 (thy, 1, bool, [], rls, term);
227 (*val (t', asm, rew) = app_rev thy (i+1) rrls t; rew = false!!!!!!!!!!!!!!!!!!!!!*)
228 "~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
229 fun chk_prepat thy erls [] t = true
230 | chk_prepat thy erls prepat t =
232 fun chk (pres, pat) =
234 val subst: Type.tyenv * Envir.tenv =
235 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
237 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
238 end) handle _ => false
239 fun scan_ f [] = false (*scan_ NEVER called by []*)
240 | scan_ f (pp::pps) =
241 if f pp then true else scan_ f pps;
242 in scan_ chk prepat end;
243 (* apply the normal_form of a rev-set *)
244 fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
245 if chk_prepat thy erls prepat t
246 then ((*tracing("### app_rev': t = "^(term2str t));*) normal_form t)
248 (* val opt = app_rev' thy rrls t ..NONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
249 "~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
251 (* chk_prepat thy erls prepat t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
252 (* app_sub thy i rrls t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
253 "~~~~~ fun chk_prepat, args:"; val (thy, erls, prepat, t) = (thy, erls, prepat, t);
254 fun chk (pres, pat) =
256 val subst: Type.tyenv * Envir.tenv =
257 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
259 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
260 end) handle _ => false
261 fun scan_ f [] = false (*scan_ NEVER called by []*)
262 | scan_ f (pp::pps) =
263 if f pp then true else scan_ f pps;
265 (*========== inhibit exn WN130823: prepat is empty ====================================
266 (* scan_ chk prepat = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
267 "~~~~~ fun , args:"; val (f, (pp::pps)) = (chk, prepat);
269 val ([t1, t2], t) = pp;
270 term2str t1 = "?r is_expanded";
271 term2str t2 = "?s is_expanded";
272 term2str t = "?r / ?s";
273 (* f pp = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
274 "~~~~~ fun chk, args:"; val (pres, pat) = (pp);
275 val subst: Type.tyenv * Envir.tenv =
276 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
278 ({}, {(("r", 0), ("real", Var (("r", 0), "real"))),
279 (("s", 0), ("real", Var (("s", 0), "real")))}*)
281 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
282 "~~~~~ fun eval__true, args:"; val (thy, i, asms, bdv, rls) =
283 (thy, (i + 1), (map (Envir.subst_term subst) pres), [], erls);
284 terms2str asms; (* = "[\"?r is_expanded\",\"?s is_expanded\"]"*)
285 asms = [@{term True}] orelse asms = []; (* = false*)
286 asms = [@{term False}] ; (* = false*)
287 "~~~~~ fun chk, args:"; val (indets, (a::asms)) = ([], asms);
288 bdv (*= []: _a list*);
289 val bdv : (term * term) list = [];
290 rewrite__set_ thy (i+1) false;
291 term2str a = "?r is_expanded"; (*hier m"usste doch der Numerator eingesetzt sein ??????????????*)
292 val SOME (Const ("HOL.False", _), []) = rewrite__set_ thy (i+1) false bdv rls a
293 ============ inhibit exn WN130823: prepat is empty ===================================*)
295 (*========== inhibit exn WN130824 TODO =======================================================
296 "-------- external calculating functions test -----------";
297 "-------- external calculating functions test -----------";
298 "-------- external calculating functions test -----------";
299 val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
300 val SOME (t', asm) = factout_p_ thy t;
301 if term2str t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso terms2str asm = "[]"
302 then () else error "factout_p_ 1 changed";
303 val SOME (t', asm) = cancel_p_ thy t;
304 if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[\"1 + x ~= 0\"]"
305 then () else error "cancel_p_ 1 changed";
307 val t = str2term "((-3 * x^^^2 + 6 *x - 3) / (2*x - 2))";
308 val SOME (t', asm) = factout_(*p_*) thy t;
309 if term2str t' = "(3 - 3 * x) * (-1 + x) / (2 * (-1 + x))" andalso terms2str asm = "[]"
310 then () else error "factout_ 2 changed";
311 val SOME (t', asm) = cancel_(*p_*) thy t;
312 if term2str t' = "(3 - 3 * x) / 2" andalso terms2str asm = "[\"-1 + x ~= 0\"]"
313 then () else error "cancel_ 2 changed";
315 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
316 val SOME (t', asm) = add_fraction_p_ thy t;
317 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
318 then () else error "add_fraction_p_ 3 changed";
319 val SOME (t', asm) = common_nominator_p_ thy t;
321 "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
322 andalso terms2str asm = "[]"
323 then () else error "common_nominator_p_ 3 changed";
325 val t = str2term "((x - 1) / (x + 1)) + ((x + 1) / (x - 1))";
326 val SOME (t', asm) = add_fraction_ thy t;
327 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
328 then () else error "factout_ 4 changed";
329 val SOME (t', asm) = common_nominator_ thy t;
331 "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
332 andalso terms2str asm = "[]"
333 then () else error "cancel_ 4 changed";
336 "((1) / (2*x + 2)) + ((1) / (2*x + (-2))) + ((1) / ( x^^^2 + (-1)))+((1) / (x^^^2 + (-2)*x + 1))";
337 val SOME (t', asm) = add_fraction_p_ thy t;
338 if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
339 then () else error "add_fraction_p_ 5 changed";
340 val SOME (t', asm) = norm_rational_ thy t;
341 if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
342 then () else error "norm_rational_ 5 changed";
343 ============ inhibit exn WN130826 TODO ========================================================*)
346 "-------- cancel_p from: Mathematik 1 Schalk Reniets Verlag ------------------";
347 "-------- cancel_p from: Mathematik 1 Schalk Reniets Verlag ------------------";
348 "-------- cancel_p from: Mathematik 1 Schalk Reniets Verlag ------------------";
349 val thy = @{theory "Rational"};
351 val t = str2term "(2 + -3 * x) / 9";
352 if NONE = rewrite_set_ thy false cancel_p t then ()
353 else error "rewrite_set_ cancel_p must return NONE, if the term cannot be cancelled";
355 "-------- example 186a";
356 val t = str2term "(14 * x * y) / (x * y)";
357 is_expanded (str2term "14 * x * y");
358 is_expanded (str2term "x * y");
359 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
360 if (term2str t', terms2str asm) = ("14 / 1", "[]")
361 then () else error "rational.sml cancel Schalk 186a";
363 "-------- example 186b";
364 val t = str2term "(60 * a * b) / ( 15 * a * b )";
365 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
366 if (term2str t', terms2str asm) = ("4 / 1", "[]")
367 then () else error "rational.sml cancel Schalk 186b";
369 "-------- example 186c";
370 val t = str2term "(144 * a^^^2 * b * c) / (12 * a * b * c)";
371 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
372 if (term2str t', terms2str asm) = ("12 * a / 1", "[]")
373 then () else error "rational.sml cancel Schalk 186c";
375 (* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! exception Div raised !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
376 see --- fun rewrite_set_ downto fun gcd_poly ---
377 "-------- example 187a";
378 val t = str2term "(12 * x * y) / (8 * y^^^2 )";
379 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
380 if (term2str t', terms2str asm) = ("3 * x / (2 * y)", "[\"4 * y ~= 0\"]")
381 then () else error "rational.sml cancel Schalk 187a";
384 (* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
385 see --- fun rewrite_set_ downto fun gcd_poly ---
386 "-------- example 187b";
387 val t = str2term "(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
388 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
389 if (term2str t', terms2str asm) = ("4 * x / (9 * y)", "[\"2 * (z * (y * x)) ~= 0\"]")
390 then () else error "rational.sml cancel Schalk 187b";
393 (* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
394 see --- fun rewrite_set_ downto fun gcd_poly ---
395 "-------- example 187c";
396 val t = str2term "(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";
397 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
398 if (term2str t', terms2str asm) =
399 ("3 * z ^^^ 3 / (5 * (y * x))", "[\"3 * (z * (y ^^^ 2 * x ^^^ 5)) ~= 0\"]")
400 then () else error "rational.sml cancel Schalk 187c";
403 "-------- example 188a";
404 val t = str2term "(-8 + 8 * x) / (-9 + 9 * x)";
405 is_expanded (str2term "8 * x + -8");
406 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
407 if (term2str t', terms2str asm) = ("8 / 9", "[]")
408 then () else error "rational.sml cancel Schalk 188a";
410 val t = str2term "(8*((-1) + x))/(9*((-1) + x))";
411 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
412 if (term2str t', terms2str asm) = ("8 / 9", "[]")
413 then () else error "rational.sml cancel Schalk make_polynomial 1";
415 "-------- example 188b";
416 val t = str2term "(-15 + 5 * x) / (-18 + 6 * x)";
417 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
418 if (term2str t', terms2str asm) = ("5 / 6", "[]")
419 then () else error "rational.sml cancel Schalk 188b";
421 "-------- example 188c";
422 val t = str2term "(a + -1 * b) / (b + -1 * a)";
423 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
424 if (term2str t', terms2str asm) = ("-1 / 1", "[]")
425 then () else error "rational.sml cancel Schalk 188c";
427 is_expanded (str2term "a + -1 * b") = true;
428 val t = str2term "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
429 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
430 if (term2str t', terms2str asm) = ("(a + -1 * b) / (-1 * a + b)", "[]")
431 then () else error "rational.sml cancel Schalk make_polynomial 2";
433 "-------- example 190a";
434 val t = str2term "( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )";
435 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
436 if (term2str t', terms2str asm) =
437 ("(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)", "[\"3 * a + 9 * a ^^^ 2 ~= 0\"]")
438 then () else error "rational.sml cancel Schalk 190a";
440 "-------- example 190c";
441 val t = str2term "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
442 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
443 if (term2str t', terms2str asm) =
444 ("(1 + 3 * a + 9 * a ^^^ 2 + 27 * a ^^^ 3) /\n(3 * a + 18 * a ^^^ 2 + 27 * a ^^^ 3)", "[]")
445 then () else error "rational.sml make_polynomial Schalk 190c";
447 "-------- example 191a";
448 val t = str2term "( x^^^2 + -1 * y^^^2 ) / ( x + y )";
449 is_expanded (str2term "x^^^2 + -1 * y^^^2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
450 is_expanded (str2term "x + y") = true;
451 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
452 if (term2str t', terms2str asm) = ("(x + -1 * y) / 1", "[]")
453 then () else error "rational.sml make_polynomial Schalk 191a";
455 "-------- example 191b";
456 val t = str2term "((x + (-1) * y)*(x + y))/((1)*(x + y))";
457 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
458 if (term2str t', terms2str asm) = ("(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)", "[]")
459 then () else error "rational.sml make_polynomial Schalk 191b";
461 "-------- example 191c";
462 val t = str2term "( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )";
463 is_expanded (str2term "9 * x^^^2 + -30 * x + 25") = true;
464 is_expanded (str2term "25 + -30*x + 9*x^^^2") = true;
465 is_expanded (str2term "-25 + 9*x^^^2") = true;
467 val t = str2term "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
468 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
469 if (term2str t', terms2str asm) = ("(25 + -30 * x + 9 * x ^^^ 2) / (-25 + 9 * x ^^^ 2)", "[]")
470 then () else error "rational.sml make_polynomial Schalk 191c";
472 "-------- example 192b";
473 val t = str2term "( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 * y^^^3 )";
474 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
475 if (term2str t', terms2str asm) = ("x ^^^ 2 / y ^^^ 2", "[\"y ^^^ 2 ~= 0\"]")
476 then () else error "rational.sml cancel_p Schalk 192b";
478 val t = str2term "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
479 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
480 if (term2str t', terms2str asm) =
481 ("(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)", "[]")
482 then () else error "rational.sml make_polynomial Schalk 192b";
484 val t = str2term "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
485 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
486 if (term2str t', terms2str asm) =
487 ("(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)", "[]")
488 then () else error "rational.sml make_polynomial Schalk WN050929 not working";
490 "-------- example 193a";
491 val t = str2term "( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )";
492 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
493 if (term2str t', terms2str asm) = ("(-3 + x) / (3 + x)", "[\"3 + x ~= 0\"]")
494 then () else error "rational.sml cancel_p Schalk 193a";
496 "-------- example 193b";
497 val t = str2term "( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )";
498 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
499 if (term2str t', terms2str asm) = ("(-4 + x) / (8 + 2 * x)", "[\"8 + 2 * x ~= 0\"]")
500 then () else error "rational.sml cancel_p Schalk 193b";
502 "-------- example 193c";
503 val t = str2term "( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )";
504 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
505 if (term2str t', terms2str asm) =
506 ("(2 * x + 10 * x ^^^ 2) / (1 + -5 * x)", "[\"1 + -5 * x ~= 0\"]")
507 then () else error "rational.sml cancel_p Schalk 193c";
510 val t = str2term "(-25 + 9*x^^^2)/(5 + 3*x)";
511 val SOME (t, asm) = rewrite_set_ thy false cancel_p t;
512 if (term2str t', terms2str asm) = ("(2 * x + 10 * x ^^^ 2) / (1 + -5 * x)", "[]")
513 then () else error "rational.sml cancel WN 1";
515 (*========== inhibit exn WN130826 TODO =========================================================
516 "-------- some old tests REVISE ! --------------------------------------------";
517 "-------- some old tests REVISE ! --------------------------------------------";
518 "-------- some old tests REVISE ! --------------------------------------------";
519 (*WAS --- external calculating functions test ---*)
520 val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
521 val SOME (t', asm) = factout_p_ thy t;
522 if term2str t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso terms2str asm = "[]"
523 then () else error "factout_p_ 1 changed";
524 val SOME (t', asm) = cancel_p_ thy t;
525 if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[\"1 + x ~= 0\"]"
526 then () else error "cancel_p_ 1 changed";
528 val t = str2term "((-3 * x^^^2 + 6 *x - 3) / (2*x - 2))";
529 val SOME (t', asm) = factout_(*p_*) thy t;
530 if term2str t' = "(3 - 3 * x) * (-1 + x) / (2 * (-1 + x))" andalso terms2str asm = "[]"
531 then () else error "factout_ 2 changed";
532 val SOME (t', asm) = cancel_(*p_*) thy t;
533 if term2str t' = "(3 - 3 * x) / 2" andalso terms2str asm = "[\"-1 + x ~= 0\"]"
534 then () else error "cancel_ 2 changed";
536 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
537 val SOME (t', asm) = add_fraction_p_ thy t;
538 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
539 then () else error "add_fraction_p_ 3 changed";
540 val SOME (t', asm) = common_nominator_p_ thy t;
542 "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
543 andalso terms2str asm = "[]"
544 then () else error "common_nominator_p_ 3 changed";
546 val t = str2term "((x - 1) / (x + 1)) + ((x + 1) / (x - 1))";
547 val SOME (t', asm) = add_fraction_ thy t;
548 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
549 then () else error "factout_ 4 changed";
550 val SOME (t', asm) = common_nominator_ thy t;
552 "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
553 andalso terms2str asm = "[]"
554 then () else error "cancel_ 4 changed";
557 "((1) / (2*x + 2)) + ((1) / (2*x + (-2))) + ((1) / ( x^^^2 + (-1)))+((1) / (x^^^2 + (-2)*x + 1))";
558 val SOME (t', asm) = add_fraction_p_ thy t;
559 if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
560 then () else error "add_fraction_p_ 5 changed";
561 val SOME (t', asm) = norm_rational_ thy t;
562 if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
563 then () else error "norm_rational_ 5 changed";
566 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))";
567 val SOME (t3',_) = common_nominator_ thy t3;
568 val SOME (t3'',_) = add_fraction_ thy t3;
572 val SOME(t4,t5) = norm_expanded_rat_ thy t3;
578 val t=(term_of o the o (parse thy)) "(9 - x^^^2)/(9 - 6*x + x^^^2)";
579 val SOME (t',_) = factout_ thy t;
580 val SOME (t'',_) = cancel_ thy t;
583 "(3 + x) * (3 - x) / ((3 - x) * (3 - x))";
586 val t=(term_of o the o (parse thy))
587 "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1 / (3 - x)";
588 val SOME (t',_) = common_nominator_ thy t;
589 val SOME (t'',_) = add_fraction_ thy t;
592 "(9 - x ^^^ 2) / ((3 - x) * (3 - x)) + 1 * (3 - x) / ((3 - x) * (3 - x))";
595 (*WN021016 added -----vv---*)
596 val t = str2term "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1";
597 val SOME (t',_) = common_nominator_ thy t;
598 val SOME (t'',_) = add_fraction_ thy t;
599 term2str t' = "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n1" ^
600 " * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
601 term2str t'' = "6 / (3 - x)" (*true*);
603 val t = str2term "1 + (9 - x^^^2) / (9 - 6*x + x^^^2)";
604 val SOME (t',_) = common_nominator_ thy t;
605 val SOME (t'',_) = add_fraction_ thy t;
606 term2str t' = "1 * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n" ^
607 "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
608 term2str t'' = "6 / (3 - x)" (*true*);
609 (*WN021016 added -----^^---*)
610 (*WN030602 added -----vv--- no rewrite -> NONE !*)
611 val t = str2term "1 / a";
612 val NONE = cancel_p_ thy t;
613 val NONE = rewrite_set_ thy false cancel_p t;
614 (*WN.2.6.03 added -------^^---*)
616 val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2)";
617 val SOME (t',_) = factout_ thy t;
618 val SOME (t'',_) = cancel_ thy t;
619 term2str t' = "(y + x) * (y - x) / ((y - x) * (y - x))"(*true*);
620 term2str t'' = "(y + x) / (y - x)";
622 val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2) + 1 / (y - x)";
623 val SOME (t',_) = common_nominator_ thy t;
624 val SOME (t'',_) = add_fraction_ thy t;
626 "(-1 * x ^^^ 2 + y ^^^ 2) / ((-1 * x + y) * (-1 * x + y)) +\n1" ^
627 " * (-1 * x + y) / ((-1 * x + y) * (-1 * x + y))" (*true*);
628 term2str t'' = "(-1 - x - y) / (x - y)" (*true*);
630 val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2) + 1 / (x - y)";
631 val SOME (t',_) = common_nominator_ thy t;
632 val SOME (t'',_) = add_fraction_ thy t;
633 if term2str t' = "(-1 * y ^^^ 2 + x ^^^ 2) / ((-1 * y + x) * (-1 * y + x))" ^
634 " +\n1 * (-1 * y + x) / ((-1 * y + x) * (-1 * y + x))" then ()
635 else error "rational.sml lex-ord 1";
636 if term2str t'' = "(-1 - y - x) / (y - x)" then ()
637 else error "rational.sml lex-ord 2";
638 (*WN.16.10.02 WN070905 lexicographische Ordnung erhalten *)
641 val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2)";
642 val SOME (t',_) = norm_expanded_rat_ thy t;
643 if term2str t' = "(x + y) / (x - y)" then ()
644 else error "rational.sml term2poly: invalid x ^^^ 2 - y ^^^ 2 No.1";
645 (*val SOME (t'',_) = norm_rational_ thy t;
646 *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial
647 WN.16.10.02 ?! + WN060831???SK4
648 WN070905 *** term2poly: invalid = x ^^^ 2 - y ^^^ 2*)
651 val t = str2term "(9 - x^^^2)/(9 - 6*x + x^^^2) + (1)/(3 + x)";
652 val SOME (t',_) = norm_expanded_rat_ thy t;
653 if term2str t' = "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)" then ()
654 else error "rational.sml (9 - x^^^2)/(9 - 6*x + x^^^2) +...";
655 (*val SOME (t'',_) = norm_rational_ thy t;
656 *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial WN.16.10.02 ?!
657 WN070906 *** term2poly: invalid = 9 - x ^^^ 2 SK.term2poly*)
659 val t=(term_of o the o (parse thy))
660 "(9 + (-1)* x^^^2)/(9 + (-1)* 6*x + x^^^2) + (1)/(3 + x)";
661 val SOME (t',_) = norm_expanded_rat_ thy t;
662 val SOME (t'',_) = norm_rational_ thy t;
665 "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)";
666 "(12 + 5 * x + x ^^^ 2) / (9 + (-1) * x ^^^ 2)";
669 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
670 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
671 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
672 val thy = @{theory "Rational"};
673 val thy' = "Rational";
675 val mp = "make_polynomial";
677 writeln ("example 186:");
679 val e186a'="(14 * x * y) / ( x * y )";(*SRC*)
680 rewrite_set_ thy false cancel (str2term e186a');
682 val e186a = the (rewrite_set thy' false "cancel" e186a');
683 is_expanded (parse_rat "14 * x * y");
684 is_expanded (parse_rat "x * y");
685 if e186a = ("14 / 1", "[\"y * x ~= 0\"]") then ()
686 else error "rational.sml cancel Schalk e186a";
689 val e186b'="(60 * a * b) / ( 15 * a * b )";
690 val e186b = the (rewrite_set thy' false "cancel" e186b');
692 val e186c'="(144 * a^^^2 * b * c) / (12 * a * b * c )";
693 val e186c = (the (rewrite_set thy' false "cancel" e186c'))
694 handle e => print_exn_G e;
695 val t = (term_of o the o (parse thy)) e186c';
696 if e186c = ("12 * a / 1", "[\"12 * (c * (b * a)) ~= 0\"]") then ()
697 else error "rational.sml cancel Schalk e186c";
699 writeln ("example 187:");
701 val e187a'="(12 * x * y) / (8 * y^^^2 )";(*SRC*)
702 val e187a = the (rewrite_set thy' false "cancel" e187a');
704 val e187b'="(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
705 val e187b = the (rewrite_set thy' false "cancel" e187b');
707 val e187d'="(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";(*SRC*)
708 val e187d = the (rewrite_set thy' false "cancel" e187d');
709 if e187d = ("3 * z ^^^ 3 / (5 * (y * x))",
710 "[\"3 * (z * (y ^^^ 2 * x ^^^ 5)) ~= 0\"]") then ()
711 else error "rational.sml cancel Schalk e186d";
713 writeln "example 188:";
714 val e188a'="(-8 + 8 * x) / (-9 + 9 * x)";(*SRC*)
715 val e188a = the (rewrite_set thy' false "cancel" e188a');
716 is_expanded (parse_rat "8 * x + -8");
717 (* e188a = ("8 / 9",["not ((-1) + x = 0)"]) then () 13.3.03*)
718 if e188a = ("8 / 9", "[\"-1 + x ~= 0\"]") then ()
719 else error "rational.sml: e188a new behaviour";
721 val SOME (t,_) = rewrite_set thy' false mp "(8*((-1) + x))/(9*((-1) + x))";
723 val e188b'="(-15 + 5 * x) / (-18 + 6 * x)";(*SRC*)
724 val SOME (t, asm) = rewrite_set thy' false "cancel" e188b';
725 t = "5 / 6" (*true*);
728 val e188c'="( a + -1 * b ) / ( b + -1 * a )";
729 val e188c = the (rewrite_set thy' false "cancel_p" e188c');
730 (*is_expanded (parse_rat "a + -1 * b");*)
732 rewrite_set thy' false mp "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
733 if t= "(a + -1 * b) / (-1 * a + b)" then()
734 else error "rational.sml: e188c new behaviour";
736 writeln ("example 190:");
738 val e190c'="( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )";
739 val e190c = the (rewrite_set thy' false "cancel" e190c');
740 val SOME (t,_) = rewrite_set thy' false mp "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
741 if t = "(1 + 3 * a + 9 * a ^^^ 2 + 27 * a ^^^ 3) /\n(3 * a + 18 * a ^^^ 2 + 27 * a ^^^ 3)" then ()
742 else error "rational.sml: e190c new behaviour";
744 writeln ("example 191:");
746 val e191a'="( x^^^2 + -1 * y^^^2 ) / ( x + y )";
748 val e191a = the (rewrite_set thy' false "cancel" e191a');
749 is_expanded (parse_rat "x^^^2 + -1 * y^^^2");
751 is_expanded (parse_rat "x + y");
753 val SOME (t,_) = rewrite_set thy' false mp "((x + (-1) * y)*(x + y))/((1)*(x + y))";
754 (* t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then() WN.13.3.03*)
755 if t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then()
756 else error "rational.sml: e191a new behaviour";
759 val e191c'="( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )";
761 val e191c = the (rewrite_set thy' false "cancel" e191c');
762 is_expanded (parse_rat "9 * x^^^2 + -30 * x + 25");
764 is_expanded (parse_rat "25 + -30*x + 9*x^^^2");
766 is_expanded (parse_rat "-25 + 9*x^^^2");
768 val SOME (t,_) = rewrite_set thy' false mp "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
769 (* t="(25 + ((-30) * x + 9 * x ^^^ 2)) / ((-25) + 9 * x ^^^ 2)"then() 13.3.03*)
770 if t= "(25 + -30 * x + 9 * x ^^^ 2) / (-25 + 9 * x ^^^ 2)" then()
771 else error "rational.sml: 'e191c' new behaviour";
774 writeln ("example 192:");
776 val e192b'="( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 * y^^^3 )";
778 val e192b = the (rewrite_set thy' false "cancel" e192b');
779 -------------------*)
780 val SOME (t',_) = rewrite_set thy' false mp "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
781 (*========== inhibit exn 110317 ================================================
782 if t' = "(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)"
783 (*"(-1 * y * x ^^^ 2 + 7 * x ^^^ 3) / (-1 * y ^^^ 3 + 7 * x * y ^^^ 2)"WN050929*)
784 then () else error "rational.sml: 'e192b' new behaviour";
785 (*^^^ works with MG's simplifier vvv*)
786 val t =str2term"((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
787 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
788 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";
789 ============ inhibit exn 110317 ==============================================*)
791 writeln ("example 193:");
793 val e193a'="( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )";
795 val e193a = the (rewrite_set thy' false "cancel" e193a');
796 -------------------*)
798 val e193b'="( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )";
800 val e193b = the (rewrite_set thy' false "cancel" e193b');
802 val e193c'="( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )";
803 val SOME(t,_) = rewrite_set thy' false "cancel" e193c';
804 -------------------*)
806 val wn01 = "(-25 + 9*x^^^2)/(5 + 3*x)";
807 val SOME (t, asm) = rewrite_set thy' false "cancel" wn01;
808 (* t = "((-5) + 3 * x) / 1" then () WN.13.3.03*)
809 if t = "(-5 + 3 * x) / 1" andalso asm = "[\"5 + 3 * x ~= 0\"]" then ()
810 else error "rational.sml: new behav. in cancel wn01";
812 "-------- common_nominator_p ----------------------------";
813 "-------- common_nominator_p ----------------------------";
814 "-------- common_nominator_p ----------------------------";
815 val rls' = "common_nominator_p";
817 writeln ("example 204:");
819 val e204a'="((5 * x) / 9) + ((3 * x) / 9) + (x / 9)";
820 val e204a = the (rewrite_set thy' false "common_nominator_p" e204a');
822 val e204b'="5 / x + -3 / x + -1 / x";
823 val e204b = the (rewrite_set thy' false "common_nominator_p" e204b');
824 if e204b = ("1 / x", "[]") then ()
825 else error "rational.sml common_nominator_p example e204b";
827 writeln ("example 205:");
829 val e205a'="((4 * x + 7) / 8) + ((4 * x + 3) / 8)";
830 val e205a = the (rewrite_set thy' false "common_nominator_p" e205a');
832 val e205b'="((5 * x + 2) / 3) + ((-2 * x + 1) / 3)";
833 val e205b = the (rewrite_set thy' false "common_nominator_p" e205b');
834 if e205b = ("(1 + x) / 1", "[]") then ()
835 else error "rational.sml common_nominator_p example e204b";
837 writeln ("example 206:");
839 val e206a'="((5 * x + 4) / (2 * x + -1)) + ((9 * x + 5) / (2 * x + -1))";
840 val e206a = the (rewrite_set thy' false "common_nominator_p" e206a');
842 val e206b'="((17 * x + -23) / (5 * x + 4)) + ((-25 + -17 * x) / (5 * x + 4))";
843 val e206b = the (rewrite_set thy' false "common_nominator_p" e206b');
845 writeln ("example 207:");
846 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)) ";
847 val e207 = the (rewrite_set thy' false "common_nominator_p" e207');
849 writeln ("example 208:");
850 val e208'="((3 * x + 2) / (x + 2)) + ((5 * x + -1) / (x + 2)) + ((-7 * x + -3) / (x + 2)) + ((-1 * x + -3) / (x + 2)) ";
851 val e208 = the (rewrite_set thy' false "common_nominator_p" e208');
853 writeln ("example 209:");
854 val e209'="((3 * x + -7 * y + 3 * z) / (4)) + ((2 * x + 17 * y + 10 * z) / (4)) + ((-1 * x + 2 * y + z) / (4)) ";
855 val e209 = the (rewrite_set thy' false "common_nominator_p" e209');
857 writeln ("example 210:");
858 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)) ";
859 val e210 = the (rewrite_set thy' false "common_nominator_p" e210');
861 writeln ("example 211:");
863 val e211a'="((b) / (a + -1 * b)) + ((-1 * a) / (a + -1 * b))";
864 val e211a = the (rewrite_set thy' false "common_nominator_p" e211a');
866 val e211b'="((b) / (b^^^2 + -1 * a^^^2)) + ((-1 * a) / (b^^^2 + -1 * a^^^2))";
867 val e211b = the (rewrite_set thy' false "common_nominator_p" e211b');
869 writeln ("example 212:");
871 val e212a'="((4) / (x)) + ((-3) / (y)) + -1";
872 val e212a = the (rewrite_set thy' false "common_nominator_p" e212a');
874 val e212b'="((4) / (x)) + ((-5) / (y)) + ((6) / (x*y))";
875 val e212b = the (rewrite_set thy' false "common_nominator_p" e212b');
877 writeln ("example 213:");
879 val e213a'="((5 * x) / (3 * y^^^2)) + ((19 * z) / (6 * x * y)) + ((-2 * x) / (3 * y^^^2)) + ((7 * y^^^2) / (6 * x^^^2)) ";
880 val e213a = the (rewrite_set thy' false "common_nominator_p" e213a');
882 val e213b'="((2 * b) / (3 * a^^^2)) + ((3 * c) / (7 * a * b)) + ((4 * b) / (3 * a^^^2)) + ((3 * a) / (7 * b^^^2))";
883 val e213b = the (rewrite_set thy' false "common_nominator_p" e213b');
885 writeln ("example 214:");
887 val e214a'="((3 * x + 2 * y + 2 * z) / (4)) + ((-5 * x + -3 * y) / (3)) + ((x + y + -2 * z) / (2))";
888 val e214a = the (rewrite_set thy' false "common_nominator_p" e214a');
890 val e214b'="((5 * x + 2 * y + z) / (2)) + ((-7 * x + -3 * y) / (3)) + ((3 * x + 6 * y + -1 * z) / (12))";
891 val e214b = the (rewrite_set thy' false "common_nominator_p" e214b');
893 writeln ("example 216:");
895 val e216a'="((2 * b + 3 * c) / (a * c)) + ((3 * a + b) / (a * b)) + ((-2 * b^^^2 + -3 * a * c) / (a * b * c))";
896 val e216a = the (rewrite_set thy' false "common_nominator_p" e216a');
898 val e216b'="((2 * a + 3 * b) / (b * c)) + ((3 * c + a) / (a * c)) + ((-2 * a^^^2 + -3 * b * c) / (a * b * c))";
899 val e216b = the (rewrite_set thy' false "common_nominator_p" e216b');
901 writeln ("example 217:");
902 val e217'="((z + -1) / (z)) + ((3 * z ^^^2 + -6 * z + 5) / (z^^^2)) + ((-4 * z^^^3 + 7 * z^^^2 + -5 * z + 5) / (z^^^3))";
903 val e217 = the (rewrite_set thy' false "common_nominator_p" e217');
906 val rls' = "common_nominator";
907 writeln ("example 218:");
908 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))";
909 val e218 = the (rewrite_set thy' false "common_nominator" e218');
910 if e218 = ("(16 - 63 * a ^^^ 2 - 81 * a ^^^ 3) / (108 * a ^^^ 4)", "[]") then ()
911 else error "rationa.sml common_nominator example e218";
913 writeln ("example 219:");
915 val e219a'="((1) / (y + 1)) + ((1) / (y + 2)) + ((1) / (y + 3))";
916 val e219a = the (rewrite_set thy' false "common_nominator" e219a');
918 val e219b'="((1) / (x + 1)) + ((1) / (x + 2)) + ((-2) / (x + 3))";
919 val e219b = the (rewrite_set thy' false "common_nominator" e219b');
920 if e219b = ("(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)", "[]") then ()
921 else error "rationa.sml common_nominator example e219b";
923 writeln ("example 220:");
925 val e220a'="((17) / (5 * r + -2)) + ((-13) / (2 * r + 3)) + ((4) / (3 * r + -5))";
926 val e220a = the (rewrite_set thy' false "common_nominator" e220a');
928 val e220b'="((20 * a) / (a + -3)) + ((-19 * a) / (a + -4)) + ((a) / (a + -5))";
929 val e220b = the (rewrite_set thy' false "common_nominator" e220b');
931 writeln ("example 221:");
933 val e221a'="((a + b) / (a + -1 * b)) + ((a + -1 * b) / (a + b))";
934 val e221a = the (rewrite_set thy' false "common_nominator" e221a');
936 val e221b'="((x + -1 * y) / (x + y)) + ((x + y) / (x + -1 * y)) ";
937 val e221b = the (rewrite_set thy' false "common_nominator" e221b');
939 writeln ("example 222:");
941 val e222a'="((1 + -1 * x) / (1 + x)) + ((-1 + -1 * x) / (1 + -1 * x)) + ((4 * x) / (1 + -1 * x^^^2))";
942 val e222a = the (rewrite_set thy' false "common_nominator" e222a');
944 val e222b'="((1 + x ) / (1 + -1 * x)) + ((-1 + x) / (1 + x)) + ((2 * x) / (1 + -1 * x^^^2))";
945 val e222b = the (rewrite_set thy' false "common_nominator" e222b');
947 writeln ("example 225:");
949 val e225a'="((6 * a) / (a^^^2 + -64)) + ((a + 2) / (2 * a + 16)) + ((-1) / (2))";
950 val e225a = the (rewrite_set thy' false "common_nominator" e225a');
952 val e225b'="((a + 2 ) / (2 * a + 12)) + ((4 * a) / (a^^^2 + -36)) + ((-1) / (2))";
953 val e225b = the (rewrite_set thy' false "common_nominator" e225b');
955 writeln ("example 226:");
957 val e226a'="((35 * z) / (49 * z^^^2 + -4)) + -1 + ((14 * z + -1) / (14 * z + 4)) ";
958 val e226a = the (rewrite_set thy' false "common_nominator" e226a');
960 val e226b'="((45 * a * b) / (25 * a^^^2 + -9 * b^^^2)) + ((20 * a + 3 * b) / (10 * a + 6 * b)) + -2";
961 val e226b = the (rewrite_set thy' false "common_nominator" e226b');
963 writeln ("example 227:");
965 val e227a'="((6 * z + 11) / (6 * z + 14)) + ((9 * z ) / (9 * z^^^2 + -49)) + -1 ";
966 val e227a = the (rewrite_set thy' false "common_nominator" e227a');
968 val e227b'="((16 * a + 37 * b) / (4 * a + 10 * b)) + ((6 * a * b) / (4 * a^^^2 + -25 * b^^^2)) + -4 ";
969 val e227b = the (rewrite_set thy' false "common_nominator" e227b');
971 writeln ("example 228:");
973 val e228a'="((7 * a + 11) / (3 * a^^^2 + -3)) + ((-2 * a + -1) / (a^^^2 + -1 * a)) + ((-1) / (3 * a + 3))";
974 val e228a = the (rewrite_set thy' false "common_nominator" e228a');
976 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))";
977 val e228b = the (rewrite_set thy' false "common_nominator" e228b');
980 writeln ("example 229:");
982 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))";
983 val e229a = the (rewrite_set thy' false "common_nominator" e229a');
985 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))";
986 val e229b = the (rewrite_set thy' false "common_nominator" e229b');
988 writeln ("example 230:");
990 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))";
991 val e230a = the (rewrite_set thy' false "common_nominator" e230a');
993 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))";
994 val e230b = the (rewrite_set thy' false "common_nominator" e230b');
996 writeln ("example 231:");
998 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))";
999 val e231a = the (rewrite_set thy' false "common_nominator" e231a');
1001 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))";
1002 val e231b = the (rewrite_set thy' false "common_nominator" e231b');
1004 writeln ("example 232:");
1006 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))";
1007 val e232a = the (rewrite_set thy' false "common_nominator" e232a');
1009 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))";
1010 val e232b = the (rewrite_set thy' false "common_nominator" e232b');
1012 writeln ("example 233:");
1014 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))";
1015 val e233a = the (rewrite_set thy' false "common_nominator" e233a');
1017 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))";
1018 val e233b = the (rewrite_set thy' false "common_nominator" e233b');
1020 writeln ("example 234:");
1022 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))";
1023 val e234a = the (rewrite_set thy' false "common_nominator" e234a');
1025 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)) ";
1026 val e234b = the (rewrite_set thy' false "common_nominator" e234b');
1028 writeln ("example 235:");
1030 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))";
1031 val e235a = the (rewrite_set thy' false "common_nominator" e235a');
1033 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)) ";
1034 val e235b = the (rewrite_set thy' false "common_nominator" e235b');
1036 writeln ("example 236:");
1038 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))";
1039 val e236a = the (rewrite_set thy' false "common_nominator" e236a');
1041 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)) ";
1042 val e236b = the (rewrite_set thy' false "common_nominator" e236b');
1045 val rls' = "cancel";
1046 writeln ("example heuberger:");
1047 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)";
1048 val eheu = the (rewrite_set thy' false "cancel" eheu');
1050 val rls' = "common_nominator_p";
1051 writeln ("example stiefel:");
1052 val est1'="(7) / (-14) + (-2) / (4)";
1053 val est1 = the (rewrite_set thy' false "common_nominator_p" est1');
1054 if est1 = ("-1 / 1", "[]") then ()
1055 else error "new behaviour in rational.sml: est1'";
1057 val t = (term_of o the o (parse thy))
1058 "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1059 val SOME (t',_) = factout_ thy t;
1060 if term2str t' = "(3 + x) * (3 - x) / ((3 - x) * (3 - x))" then ()
1061 else error "rational.sml factout_ (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1063 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
1064 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
1065 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
1066 val t = str2term ("123 = (a*x)/(b*x) + (c*x)/(d*x) + (e*x)/(f*x::real)");
1067 "-------- gcd_poly integration level 1: works on exact term";
1068 if NONE = cancel_p_ thy t then () else error "cancel_p_ works on exact fraction";
1069 if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ works on exact fraction";
1071 "-------- gcd_poly integration level 2: picks out ONE appropriate subterm";
1072 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1073 if term2str t' = "123 = a * x / (b * x) + c * x / (d * x) + e / f"
1074 then () else error "level 2, rewrite_set_ cancel_p: changed";
1075 val SOME (t', asm) = rewrite_set_ thy false add_fractions_p t;
1076 if term2str t' = "123 = (b * c * x + a * d * x) / (b * d * x) + e * x / (f * x)"
1077 then () else error "level 2, rewrite_set_ add_fractions_p: changed";
1079 "-------- gcd_poly integration level 3: rewrites all appropriate subterms";
1080 val SOME (t', asm) = rewrite_set_ thy false cancel_p_rls t;
1081 if term2str t' = "123 = a / b + c / d + e / f"
1082 then () else error "level 3, rewrite_set_ cancel_p_rls: changed";
1083 val SOME (t', asm) = rewrite_set_ thy false common_nominator_p_rls t; (*CREATE add_fractions_p_rls*)
1084 if term2str t' = "123 = (b * d * e * x + b * c * f * x + a * d * f * x) / (b * d * f * x)"
1085 then () else error "level 3, rewrite_set_ add_fractions_p_rls: changed";
1087 "-------- gcd_poly integration level 4: iteration cancel_p -- add_fraction_p";
1088 (* simpler variant *)
1089 val testrls = append_rls "testrls" e_rls [Rls_ cancel_p, Rls_ add_fractions_p]
1090 val SOME (t', asm) = rewrite_set_ thy false testrls t;
1091 (*trace_rewrite := false;
1092 # rls: testrls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
1093 ## rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
1094 ## rls: common_nominator_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f
1095 ## rls: cancel_p on: 123 = (b * c * x + a * d * x) / (b * d * x) + e / f
1096 ## rls: common_nominator_p on: 123 = (b * c + a * d) / (b * d) + e / f
1097 ## rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
1098 ## rls: common_nominator_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
1099 if term2str t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
1100 then () else error "level 4, rewrite_set_ *_p: changed";
1102 (* complicated variant *)
1103 val testrls_rls = append_rls "testrls_rls" e_rls [Rls_ cancel_p_rls, Rls_ common_nominator_p_rls];
1104 val SOME (t', asm) = rewrite_set_ thy false testrls_rls t;
1105 (*# rls: testrls_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
1106 ## rls: cancel_p_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
1107 ### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
1108 ### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f
1109 ### rls: cancel_p on: 123 = a * x / (b * x) + c / d + e / f
1110 ### rls: cancel_p on: 123 = a / b + c / d + e / f
1111 ## rls: common_nominator_p_rls on: 123 = a / b + c / d + e / f
1112 ### rls: common_nominator_p on: 123 = a / b + c / d + e / f
1113 ### rls: common_nominator_p on: 123 = (b * c + a * d) / (b * d) + e / f
1114 ### rls: common_nominator_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
1115 ## rls: cancel_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
1116 ### rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
1117 ## rls: common_nominator_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
1118 ### rls: common_nominator_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
1119 if term2str t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
1120 then () else error "level 4, rewrite_set_ *_p_rls: changed"
1122 "-------- gcd_poly integration level 5: cancel_p & add_fraction_p within norm_Rational";
1123 val SOME (t', asm) = rewrite_set_ thy false norm_Rational t;
1124 if term2str t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)"
1125 then () else error "level 5, rewrite_set_ norm_Rational: changed"
1127 "-------- reverse rewrite -------------------------------";
1128 "-------- reverse rewrite -------------------------------";
1129 "-------- reverse rewrite -------------------------------";
1130 (*WN.28.8.02: tests for the 'reverse-rewrite' functions:
1131 these are defined in Rationals.ML and stored in
1132 the 'reverse-ruleset' cancel*)
1134 (*the term for which reverse rewriting is demonstrated*)
1135 val t = (term_of o the o (parse thy))
1136 "(9 - x ^^^ 2) / (9 + 6 * x + x ^^^ 2)";
1137 val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
1138 next_rule=nex,normal_form=nor,...},...} = cancel;
1140 (*normal_form produces the result in ONE step*)
1141 val SOME (t',_) = nor t;
1142 if term2str t' = "(3 - x) / (3 + x)" then ()
1143 else error "rational.sml normal_form (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1145 (*initialize the interpreter state used by the 'me'*)
1146 val (t,_,revsets,_) = ini t;
1148 (*find the rule 'r' to apply to term 't'*)
1149 val SOME (r as (Thm (str, thm))) = nex revsets t;
1150 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))"
1151 andalso string_of_thm thm =
1152 (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
1153 (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
1154 else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1155 (* before Isa02->09-2 was not checked automatically, ?was different?:
1156 val SOME r = nex revsets t;
1157 val r = Thm ("sym_#mult_2_3","6 = 2 * 3") : rule*)
1159 (* check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
1160 if the rule is OK, the term resulting from applying the rule is returned,too;
1161 there might be several rule applications inbetween,
1162 which are listed after the head in reverse order *)
1163 val (r, (t, asm))::_ = loc revsets t r;
1164 if term2str t = "(9 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" andalso asm = []
1166 else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1168 (* find the next rule to apply *)
1169 val SOME (r as (Thm (str, thm))) = nex revsets t;
1170 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso
1171 string_of_thm thm = (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
1172 (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
1173 else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1175 (*check the next rule*)
1176 val (r, (t, asm)) :: _ = loc revsets t r;
1177 if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" then ()
1178 else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) II";
1180 (*find and check the next rules, rewrite*)
1181 val SOME r = nex revsets t;
1182 val (r,(t,asm))::_ = loc revsets t r;
1183 if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
1184 else error "rational.sml locate_rule II";
1186 val SOME r = nex revsets t;
1187 val (r,(t,asm))::_ = loc revsets t r;
1188 if term2str t = "(3 - x) * (3 + x) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
1189 else error "rational.sml next_rule II";
1191 val SOME r = nex revsets t;
1192 val (r,(t,asm))::_ = loc revsets t r;
1193 if term2str t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then ()
1194 else error "rational.sml next_rule III";
1196 val SOME r = nex revsets t;
1197 val (r, (t, asm)) :: _ = loc revsets t r;
1198 val ss = term2str t;
1199 if ss = "(3 - x) / (3 + x)" andalso terms2str asm = "[\"3 + x ~= 0\"]" then ()
1200 else error "rational.sml: new behav. in rev-set cancel";
1202 "-------- 'reverse-ruleset' cancel_p --------------------";
1203 "-------- 'reverse-ruleset' cancel_p --------------------";
1204 "-------- 'reverse-ruleset' cancel_p --------------------";
1205 (*WN.11.9.02: the 'reverse-ruleset' cancel_p*)
1207 (*the term for which reverse rewriting is demonstrated*)
1208 val t = str2term "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))";
1209 val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
1210 next_rule=nex,normal_form=nor,...},...} = cancel_p;
1212 (*normal_form produces the result in ONE step*)
1213 val SOME (t',_) = nor t;
1214 term2str t' = "(3 + 1 * x) / (3 + -1 * x)";
1216 (*initialize the interpreter state used by the 'me'*)
1217 val SOME (t', asm) = cancel_p_ thy t;
1218 term2str t' = "(3 + x) / (3 + -1 * x)" (*true*);
1219 terms2str asm = "[\"3 + -1 * x ~= 0\"]" (*true*);
1220 val (t,_,revsets,_) = ini t;
1222 (* WN.10.10.02: dieser Fall terminiert nicht
1223 (make_polynomial enth"alt zu viele rules)
1224 WN060823 'init_state' requires rewriting on specified location in the term
1225 print_depth 99; Rfuns; print_depth 3;
1226 WN060831 cycling "sym_order_mult_rls_" "sym_mult_assoc"
1227 as was with make_polynomial before ?!?*)
1229 val SOME r = nex revsets t;
1230 eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))",
1231 mk_thm thy "9 = 3 ^^^ 2"));
1232 (*WN060831 *** id_of_thm
1233 Exception- ERROR raised ...
1234 val (r,(t,asm))::_ = loc revsets t r;
1237 val SOME r = nex revsets t;
1238 val (r,(t,asm))::_ = loc revsets t r;
1242 writeln "****************** all tests successfull *************************";
1246 (*WN.17.3.03 =========================================================vvv---*)
1247 "-------- norm_Rational ---------------------------------";
1248 "-------- norm_Rational ---------------------------------";
1249 "-------- norm_Rational ---------------------------------";
1250 val t = str2term "(3*x+5)/18 - x/2 - -(3*x - 2)/9 = 0";
1251 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1252 if term2str t' = "1 / 18 = 0" then () else error "rational.sml 1";
1254 val t = str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0";
1255 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1256 if term2str t' = "(237 + 65 * x) / 36 = 0" then ()
1257 else error "rational.sml 2";
1259 val t = str2term "(1/2 + (5*x)/2)^^^2 - ((13*x)/2 - 5/2)^^^2 - (6*x)^^^2 + 29";
1260 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1261 if term2str t' = "23 + 35 * x + -72 * x ^^^ 2" then ()
1262 else error "rational.sml 3";
1264 (*trace_rewrite:=true;*)
1265 val t = str2term "Not (6*x is_atom)";
1266 val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
1268 val t = str2term "1 < 2";
1269 val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
1272 val t = str2term "(6*x)^^^2";
1273 val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false
1274 (num_str @{thm realpow_def_atom}) t;
1275 if term2str t' = "6 * x * (6 * x) ^^^ (2 + -1)" then ()
1276 else error "rational.sml powers_erls (6*x)^^^2";
1278 val t = str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))";
1279 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1280 if term2str t' = "65 * x / 2" then () else error "rational.sml 4";
1282 val t = str2term "1 - ((13*x)/2 - 5/2)^^^2";
1283 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1284 (*bef.040209: if term2str t' = "(-21 + (130 * x + -169 * x ^^^ 2)) / 4"then()*)
1285 if term2str t' = "(-21 + 130 * x + -169 * x ^^^ 2) / 4" then ()
1286 else error "rational.sml 5";
1288 (*SRAM Schalk I, p.92 Nr. 609a*)
1289 val t = str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
1290 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1291 if term2str t' = "(-255 + 112 * x) / 135" then ()
1292 else error "rational.sml 6";
1294 (*SRAM Schalk I, p.92 Nr. 610c*)
1295 val t = str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
1296 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1297 if term2str t' = "(-3 + -1 * x) / 2" then () else error "rational.sml 7";
1299 (*SRAM Schalk I, p.92 Nr. 476a*)
1300 val t = str2term "(x^^^2/(1 - x^^^2) + 1)/(x/(1 - x) + 1) * (1 + x)";
1301 (*. a/b : c/d translated to a/b * d/c .*)
1302 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1303 (*if term2str t' = "1 / 1" then () else error "rational.sml 8";3.6.03*)
1304 if term2str t' = "1" then () else error "rational.sml 8";
1306 (*............................vvv---TODO: sollte gehen mit poly_order *)
1307 (*Schalk I, p.92 Nr. 472a*)
1308 val t = str2term "((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
1309 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1310 if term2str t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
1312 (*Schalk I, p.70 Nr. 480b; a/b : c/d translated to a/b * d/c*)
1313 val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
1314 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
1315 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
1316 "(20*x*y/(x^^^2 - 25*y^^^2))");
1317 (*... nicht simpl, zerlegt ...*)
1318 val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
1319 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2))");
1320 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1321 "(-12 * (x * y ^^^ 3) + 108 * (x * (y * x ^^^ 2))) / (12 * (x * y))";
1322 (* ~~~~~~~~~~ poly_order notwendig!*)
1323 val t = str2term ("(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
1324 "(20*x*y/(x^^^2 - 25*y^^^2))");
1325 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1326 if term2str t' = "1 / (x ^^^ 2 + -25 * y ^^^ 2)" then ()
1327 else error "rational.sml norm_Rational 1 / (x ^^^ 2 + -25 * y ^^^ 2)";
1329 "nonterm.SK6 ----- SK060904-2a non-termination of add_fraction_p_";
1330 (*WN.2.6.03 from rlang.sml 56a
1331 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)";
1332 val NONE = rewrite_set_ thy false common_nominator_p t;
1334 WN060831 nonterm.SK7
1335 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
1336 val NONE = add_fraction_p_ thy t;
1340 (* ------------------------------------------------------------------- *)
1341 (*---------vvv------------ MG: ab 1.7.03 ----------------vvv-----------*)
1342 (* Simplifier fuer beliebige Buchterme *)
1343 (* ------------------------------------------------------------------- *)
1344 (*----------------------- norm_Rational_mg ----------------------------*)
1345 (* ------------------------------------------------------------------- *)
1347 "-------- numeral rationals -----------------------------";
1348 "-------- numeral rationals -----------------------------";
1349 "-------- numeral rationals -----------------------------";
1350 (*SRA Schalk I, p.40 Nr. 164b *)
1351 val t = str2term "(47/6 - 76/9 + 13/4)/(35/12)";
1352 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1354 if (term2str t) = "19 / 21" then ()
1355 else error "rational.sml: diff.behav. in norm_Rational_mg 1";
1357 (*SRA Schalk I, p.40 Nr. 166a *)
1358 val t = str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
1359 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1361 if (term2str t) = "45 / 2" then ()
1362 else error "rational.sml: diff.behav. in norm_Rational_mg 2";
1365 "-------- cancellation ----------------------------------";
1366 "-------- cancellation ----------------------------------";
1367 "-------- cancellation ----------------------------------";
1368 (* e190c Stefan K.*)
1370 "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
1371 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1374 "(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
1376 else error "rational.sml: diff.behav. in norm_Rational_mg 3";
1378 (* e192b Stefan K.*)
1380 "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
1381 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1386 else error "rational.sml: diff.behav. in norm_Rational_mg 4";
1388 (*SRC Schalk I, p.66 Nr. 379c *)
1391 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1396 else error "rational.sml: diff.behav. in norm_Rational_mg 5";
1398 (*SRC Schalk I, p.66 Nr. 380b *)
1400 "15*(3*x+3)*(4*x+9)/(12*(2*x+7)*(5*x+5))";
1401 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1404 "(27 + 12 * x) / (28 + 8 * x)"
1406 else error "rational.sml: diff.behav. in norm_Rational_mg 6";
1408 (*Schalk I, p.60 Nr. 215c *)
1409 (* Falsches Ergebnis: rechnet lange und cancel_p kann nicht weiter krzen!!!*)
1411 val t = str2term "(a+b)^^^4*(x - y)/((x - y)^^^3*(a+b)^^^2)";
1412 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1415 "(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)"
1417 else error "rational.sml: diff.behav. in norm_Rational_mg 7";
1420 "(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)"
1421 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1423 (* uncaught exception nonexhaustive binding failure
1424 raised at: stdIn:93.1-93.51 *)
1426 (*Schalk I, p.66 Nr. 381a *)
1427 (* ACHTUNG: rechnet ca. 2 Minuten !!! *)
1429 val t = str2term "18*(a+b)^^^3*(a - b)^^^2/(72*(a - b)^^^3*(a+b)^^^2)";
1430 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1433 "(a + b) / (4 * a + -4 * b)"
1434 then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
1437 (*SRC Schalk I, p.66 Nr. 381b *)
1439 "(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
1440 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1445 else error "rational.sml: diff.behav. in norm_Rational_mg 9";
1447 (*SRC Schalk I, p.66 Nr. 381c *)
1449 "(27*a^^^3+9*a^^^2+3*a+1)/(27*a^^^3+18*a^^^2+3*a)";
1450 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1453 "(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
1455 else error "rational.sml: diff.behav. in norm_Rational_mg 10";
1457 (*SRC Schalk I, p.66 Nr. 383a *)
1459 "(5*a^^^2 - 5*a*b)/(a - b)^^^2";
1460 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1463 "5 * a / (a + -1 * b)"
1465 else error "rational.sml: diff.behav. in norm_Rational_mg 11";
1468 "-------- common denominator ----------------------------";
1469 "-------- common denominator ----------------------------";
1470 "-------- common denominator ----------------------------";
1471 (*SRA Schalk I, p.67 Nr. 403a *)
1474 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1477 "(-3 * x + 4 * y + -1 * x * y) / (x * y)"
1479 else error "rational.sml: diff.behav. in norm_Rational_mg 12";
1481 (*SRA Schalk I, p.67 Nr. 407b *)
1483 "(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a^^^2+3*b*c)/(a*b*c)";
1484 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1489 else error "rational.sml: diff.behav. in norm_Rational_mg 13";
1491 (*SRA Schalk I, p.67 Nr. 410b *)
1493 "1/(x+1) + 1/(x+2) - 2/(x+3)";
1494 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1497 "(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)"
1499 else error "rational.sml: diff.behav. in norm_Rational_mg 14";
1501 (*SRA Schalk I, p.67 Nr. 413b *)
1503 "(1+x)/(1 - x) - (1 - x)/(1+x) + 2*x/(1 - x^^^2)";
1504 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1507 "6 * x / (1 + -1 * x ^^^ 2)"
1509 else error "rational.sml: diff.behav. in norm_Rational_mg 15";
1511 (*SRA Schalk I, p.68 Nr. 414a *)
1513 "(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))";
1514 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1517 "(-2 + -5 * x + 2 * x ^^^ 2) / (2 + -3 * x + x ^^^ 2)"
1519 else error "rational.sml: diff.behav. in norm_Rational_mg 16";
1521 (*SRA Schalk I, p.68 Nr. 423a *)
1523 "(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)";
1524 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1529 else error "rational.sml: diff.behav. in norm_Rational_mg 17";
1531 (*SRA Schalk I, p.68 Nr. 428b *)
1533 "1/(a - b)^^^2 + 1/(a+b)^^^2 - 2/(a^^^2 - b^^^2) - 4*(b^^^2 - 1)/(a^^^2 - b^^^2)^^^2";
1534 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1537 "4 / (a ^^^ 4 + -2 * a ^^^ 2 * b ^^^ 2 + b ^^^ 4)"
1539 else error "rational.sml: diff.behav. in norm_Rational_mg 18";
1541 (*SRA Schalk I, p.68 Nr. 430b *)
1543 "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";
1544 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1549 else error "rational.sml: diff.behav. in norm_Rational_mg 19";
1552 (*SRA Schalk I, p.68 Nr. 432 *)
1554 "(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)";
1555 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1560 else error "rational.sml: diff.behav. in norm_Rational_mg 20";
1565 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1568 "(3 * y + b * x) / (b * y)"
1570 else error "rational.sml: diff.behav. in norm_Rational_mg 21";
1573 "-------- multiply and cancel ---------------------------";
1574 "-------- multiply and cancel ---------------------------";
1575 "-------- multiply and cancel ---------------------------";
1576 (*SRM Schalk I, p.68 Nr. 436a *)
1578 "3*(x+y)/(15*(x - y)) * 25*(x - y)^^^2/(18*(x+y)^^^2)";
1579 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1582 "(5 * x + -5 * y) / (18 * x + 18 * y)"
1584 else error "rational.sml: diff.behav. in norm_Rational_mg 22";
1586 (*SRM.test Schalk I, p.68 Nr. 436b *)
1587 (*WN060420???MG3 crashes with method 'simplify' in
1588 IsacCore > Simplification > Rational Terms > Multiplication > No.2*)
1589 val t = str2term "5*a*(a - b)^^^2*(a + b)^^^3/(7*b*(a - b)^^^3) * 7*b/(a + b)^^^3";
1590 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1593 "5 * a / (a + -1 * b)"
1595 else error "rational.sml: diff.behav. in norm_Rational_mg 23";
1597 (*Schalk I, p.68 Nr. 437a *)
1598 val t = str2term "(3*a - 4*b)/(4*c+3*e) * (3*a+4*b)/(9*a^^^2 - 16*b^^^2)";
1599 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1600 if (term2str t) = "1 / (4 * c + 3 * e)" then ()
1601 else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1603 "----- S.K. corrected non-termination 060904";
1604 val t = str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a^^^2 - 16*b^^^2))";
1605 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
1608 "(9 * a ^^^ 2 + -16 * b ^^^ 2) /\n(36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c +\n -48 * b ^^^ 2 * e)"
1609 (*"(9 * a ^^^ 2 + -16 * b ^^^ 2) / (36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c + -48 * b ^^^ 2 * e)"*)
1610 then () else error "rational.sml: S.K.8..corrected 060904-6";
1612 "----- S.K. corrected non-termination of cancel_p_";
1613 val t'' = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
1614 "(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
1615 val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
1616 if term2str t' = "1 / (4 * c + 3 * e)" then ()
1617 else error "rational.sml: diff.behav. in cancel_p S.K.8";
1619 (*Schalk I, p.68 Nr. 437b *)
1620 (* nonterm.SK9 loops: cancel_p kann nicht weiter kuerzen!!! *)
1621 val t'' = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
1622 (* val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t'';
1625 "================delete===";
1626 (*a casual output from above*)
1628 "(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)";
1629 (* WN060831 nonterm.SK10
1630 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1634 (*SRM Schalk I, p.68 Nr. 438a *)
1636 "x*y/(x*y - y^^^2)*(x^^^2 - x*y)";
1637 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1642 else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1644 (*SRM Schalk I, p.68 Nr. 439b *)
1646 "(4*x^^^2+4*x+1)*((x^^^2 - 2*x^^^3)/(4*x^^^2+2*x))";
1647 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1650 "(x + -4 * x ^^^ 3) / 2"
1652 else error "rational.sml: diff.behav. in norm_Rational_mg 25";
1654 (*SRM Schalk I, p.68 Nr. 440a *)
1656 "(x^^^2 - 2*x)/(x^^^2 - 3*x) * (x - 3)^^^2/(x^^^2 - 4)";
1657 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1660 "(-3 + x) / (2 + x)"
1662 else error "rational.sml: diff.behav. in norm_Rational_mg 26";
1664 "----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
1666 "(a^^^3 - 9*a)/(a^^^3*b - a*b^^^3)*(a^^^2*b+a*b^^^2)/(a+3)";
1667 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1668 if term2str t = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
1669 else error "rational.sml: diff.behav. in norm_Rational 27";
1671 "----- SK12 works since 0707xx";
1672 val t = str2term "(a^^^3 - 9*a)*(a^^^2*b+a*b^^^2)/((a^^^3*b - a*b^^^3)*(a+3))";
1673 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1674 if term2str t' = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
1675 else error "rational.sml: diff.behav. in norm_Rational 28";
1678 "-------- common denominator and multiplication ---------";
1679 "-------- common denominator and multiplication ---------";
1680 "-------- common denominator and multiplication ---------";
1681 (*SRAM Schalk I, p.69 Nr. 441b *)
1682 val t = str2term "(4*a/3 + 3*b^^^2/a^^^3 + b/(4*a))*(4*b/(3*a))";
1683 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1686 "(36 * b ^^^ 3 + 3 * a ^^^ 2 * b ^^^ 2 + 16 * a ^^^ 4 * b) / (9 * a ^^^ 4)"
1687 then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
1689 (*SRAM Schalk I, p.69 Nr. 442b *)
1690 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)";
1691 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1694 "5 * x ^^^ 2 / (a * b ^^^ 3 * c)"
1695 then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
1697 (*SRAM Schalk I, p.69 Nr. 443b *)
1698 val t = str2term "(a/2 + b/3)*(b/3 - a/2)";
1699 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1702 "(-9 * a ^^^ 2 + 4 * b ^^^ 2) / 36"
1703 then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
1705 (*SRAM Schalk I, p.69 Nr. 445b *)
1706 val t = str2term "(a^^^2/9 + 2*a/(3*b) + 4/b^^^2)*(a/3 - 2/b) + 8/b^^^3";
1707 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1711 then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
1713 (*SRAM Schalk I, p.69 Nr. 446b *)
1714 val t = str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x^^^2 - 16*y^^^2)";
1715 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1718 "30 * x ^^^ 2 + -9 * x * y + -20 * y ^^^ 2"
1720 else error "rational.sml: diff.behav. in norm_Rational_mg 32";
1722 (*SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
1724 "(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)";
1725 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1727 if (term2str t) = "(-81 * x ^^^ 4 + 16 * x ^^^ 8 * y ^^^ 4) / (81 * y ^^^ 8)"
1728 then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
1731 (*SRAM Schalk I, p.69 Nr. 450a *)
1733 "(4*x/(3*y)+2*y/(3*x))^^^2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
1734 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1737 "(52 * x ^^^ 2 + 16 * y ^^^ 2) / (9 * y ^^^ 2)"
1739 else error "rational.sml: diff.behav. in norm_Rational_mg 34";
1742 "-------- double fractions ------------------------------";
1743 "-------- double fractions ------------------------------";
1744 "-------- double fractions ------------------------------";
1745 (*SRD Schalk I, p.69 Nr. 454b *)
1747 "((2 - x)/(2*a)) / (2*a/(x - 2))";
1748 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1751 "(-4 + 4 * x + -1 * x ^^^ 2) / (4 * a ^^^ 2)"
1753 else error "rational.sml: diff.behav. in norm_Rational_mg 35";
1755 (*SRD Schalk I, p.69 Nr. 455a *)
1757 "(a^^^2 + 1)/(a^^^2 - 1) / ((a+1)/(a - 1))";
1758 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1761 "(1 + a ^^^ 2) / (1 + 2 * a + a ^^^ 2)" then ()
1762 else error "rational.sml: diff.behav. in norm_Rational_mg 36";
1765 "----- Schalk I, p.69 Nr. 455b";
1766 val t = str2term "(x^^^2 - 4)/(y^^^2 - 9)/((2+x)/(3 - y))";
1767 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1768 if term2str t = "(2 + -1 * x) / (3 + y)" then ()
1769 else error "rational.sml: diff.behav. in norm_Rational_mg 37";
1771 "----- SK060904-1a non-termination of cancel_p_ ?: worked before 0707xx";
1772 val t = str2term "(x^^^2 - 4)*(3 - y)/((y^^^2 - 9)*(2+x))";
1773 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1774 if term2str t = "(2 + -1 * x) / (3 + y)" then ()
1775 else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
1777 "----- ?: worked before 0707xx";
1778 val t = str2term "(3 + -1 * y) / (-9 + y ^^^ 2)";
1779 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1780 if term2str t = "-1 / (3 + y)" then ()
1781 else error "rational.sml: -1 / (3 + y) norm_Rational";
1783 (*SRD Schalk I, p.69 Nr. 456b *)
1785 "(b^^^3 - b^^^2)/(b^^^2+b)/(b^^^2 - 1)";
1786 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1788 if (term2str t) = "b / (1 + 2 * b + b ^^^ 2)" then ()
1789 else error "rational.sml: diff.behav. in norm_Rational_mg 38";
1791 (*SRD Schalk I, p.69 Nr. 457b *)
1793 "(16*a^^^2 - 9*b^^^2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a^^^2 - 9*a^^^2*b^^^2))";
1794 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1797 "8 * a ^^^ 2 + -6 * a * b + -12 * a ^^^ 2 * b + 9 * a * b ^^^ 2"
1798 then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
1800 "----- Schalk I, p.69 Nr. 458b works since 0707";
1802 "(2*a^^^2*x - a^^^2)/(a*x - b*x) / (b^^^2*(2*x - 1)/(x*(a - b)))";
1803 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1804 if term2str t = "a ^^^ 2 / b ^^^ 2" then ()
1805 else error "rational.sml: diff.behav. in norm_Rational_mg 39b";
1807 (*SRD Schalk I, p.69 Nr. 459b *)
1808 val t = str2term "(a^^^2 - b^^^2)/(a*b) / (4*(a+b)^^^2/a)";
1809 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1810 if term2str t = "(a + -1 * b) / (4 * a * b + 4 * b ^^^ 2)" then ()
1811 else error "rational.sml: diff.behav. in norm_Rational_mg 41";
1814 (*Schalk I, p.69 Nr. 460b nonterm.SK
1816 "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
1817 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1820 else error "rational.sml: diff.behav. in norm_Rational_mg 42";
1823 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
1824 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
1825 ... non terminating.
1826 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
1827 "(-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)";
1828 val SOME (t,_) = rewrite_set_ thy false cancel_p t';
1829 ... non terminating.*)
1831 (*SRD Schalk I, p.70 Nr. 472a *)
1832 val t = str2term ("((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/" ^
1833 "((4*x - 8*y)/(x + y))");
1834 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1839 else error "rational.sml: diff.behav. in norm_Rational_mg 43";
1842 (*----------------------------------------------------------------------*)
1843 (*---------------------- Einfache Dppelbrche --------------------------*)
1844 (*----------------------------------------------------------------------*)
1846 (*SRD Schalk I, p.69 Nr. 461a *)
1848 "(2/(x+3) + 2/(x - 3)) / (8*x/(x^^^2 - 9))";
1849 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1854 else error "rational.sml: diff.behav. in norm_Rational_mg 44";
1856 (*SRD Schalk I, p.69 Nr. 464b *)
1858 "(a - a/(a - 2)) / (a + a/(a - 2))";
1859 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1862 "(3 + -1 * a) / (1 + -1 * a)"
1864 else error "rational.sml: diff.behav. in norm_Rational_mg 45";
1866 (*SRD Schalk I, p.69 Nr. 465b *)
1868 "((x+3*y)/9 + (4*y^^^2 - 9*z^^^2)/(16*x)) /(x/9+y/6+z/4)";
1869 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1872 "(4 * x + 6 * y + -9 * z) / (4 * x)"
1874 else error "rational.sml: diff.behav. in norm_Rational_mg 46";
1876 (*SRD Schalk I, p.69 Nr. 466b *)
1878 "((1 - 7*(x - 2)/(x^^^2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x^^^2 - 25))";
1879 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1882 "(25 + -10 * x + x ^^^ 2) / 18"
1884 else error "rational.sml: diff.behav. in norm_Rational_mg 47";
1886 (*SRD Schalk I, p.70 Nr. 469 *)
1888 "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))";
1889 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1892 "3 * b ^^^ 3 / (2 * a + -2 * b)"
1894 else error "rational.sml: diff.behav. in norm_Rational_mg 48";
1896 (*----------------------------------------------------------------------*)
1897 (*---------------------- Mehrfache Dppelbrueche ------------------------*)
1898 (*----------------------------------------------------------------------*)
1900 (*SRD.test Schalk I, p.70 Nr. 476b *) (* Rechenzeit: 10 sec *)
1901 (*WN060419 crashes with method 'simplify' ????SK*)
1903 "((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)";
1904 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
1905 if term2str t = "1 / (a ^^^ 2 + -1 * b ^^^ 2)" then ()
1906 else error "rational.sml: diff.behav. in norm_Rational_mg 49";
1908 "----- Schalk I, p.70 Nr. 477a";
1909 (* MG Achtung: terme explodieren; Bsp zu komplex;
1910 L???ung sollte (ziemlich grosser) Faktorisierter Ausdruck sein
1911 val t = str2term "b*y/(b - 2*y)/((b^^^2 - y^^^2)/(b+2*y)) /" ^
1912 "(b^^^2*y+b*y^^^2)*(a+x)^^^2/((b^^^2 - 4*y^^^2)*(a+2*x)^^^2)";
1913 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
1916 val t = str2term "b*y*(b+2*y)*(b^^^2 - 4*y^^^2)*(a+2*x)^^^2 / " ^
1917 "((b - 2*y)*(b^^^2 - y^^^2)*(b^^^2*y+b*y^^^2)*(a+x)^^^2)";
1918 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
1922 "----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
1923 val t = str2term ("(a - (a*b+b^^^2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
1924 "((a - a^^^2/(a+b))/(a+(a*b)/(a - b)))");
1925 val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1927 "(2 * a ^^^ 3 + 2 * a ^^^ 2 * b) / (a ^^^ 2 * b + b ^^^ 3)"
1929 else error "rational.sml: diff.behav. in norm_Rational_mg 51";
1931 (* TODO.new_c:WN050820 STOP_REW_SUB introduced gave ...
1932 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 ()
1933 else error "rational.sml: works again";
1934 re-outcommented with TODO.new_c: cvs before 071227, 11:50*)
1938 (*Schalk I, p.70 Nr. 480a *)
1939 (* Achtung: rechnet ewig; cancel_p kann nicht krzen: WN060831 nonterm.SK00
1941 "(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)))";
1942 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1947 else error "rational.sml: diff.behav. in norm_Rational_mg 52";
1949 (*MG Berechne Zwischenergebnisse: WN060831 nonterm.SK00*)
1951 "(1/x+1/y+1/z)/(1/x - 1/y - 1/z)";
1952 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1954 "(x ^^^ 2 * y ^^^ 2 * z + x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2) /
1955 (-1 * x ^^^ 2 * y ^^^ 2 * z + -1 * x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2)";
1957 "2*x^^^2/(x^^^2 - z^^^2)/(x/(x+z)+x/(x - z))";
1958 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1962 (* SK 1. Ausdruck kann nicht weiter gekrzt werden; cancel_p !!!*)
1963 ### rls: cancel_p on:
1964 (x ^^^ 2 * (y ^^^ 2 * z) + x ^^^ 2 * (y * z ^^^ 2) + x * (y ^^^ 2 * z ^^^ 2)) /
1965 (-1 * (x ^^^ 2 * (y ^^^ 2 * z)) + -1 * (x ^^^ 2 * (y * z ^^^ 2)) + x * (y ^^^ 2 * z ^^^ 2))
1966 GC #3.61.81.101.197.17503: (0 ms)
1967 *** RATIONALS_DIRECT_CANCEL_EXCEPTION: Invalid fraction
1970 "(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))";
1971 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1973 (*uncaught exception nonexhaustive binding failure*)
1975 (* Das kann er aber krzen !!????: *)
1977 "(x^^^2 * (y^^^2 * z) + x * (y^^^2 * z^^^2)) / (-1 * (x^^^2 * (y * z^^^2)) + x * (y^^^2 * z^^^2))";
1978 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
1980 "(-1 * (y * x) + -1 * (z * y)) / (1 * (z * x) + -1 * (z * y))";
1984 "-------- crucial examples ------------------------------";
1985 "-------- crucial examples ------------------------------";
1986 "-------- crucial examples ------------------------------";
1987 (*Schalk I, p.60 Nr. 215d *)
1988 (* Achtung: rechnet ewig ...
1989 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
1990 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1991 term2str t; noterm.SK
1994 (* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt:*)
1996 val t = str2term "(a-b)^^^3 * (x+y)^^^4";
1997 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
1999 "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";
2000 val t = str2term "((x+y)^^^2 * (a-b)^^^5)";
2001 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2003 "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";
2005 (*anscheinend macht dem Rechner das Krzen diese Bruches keinen Spass mehr ...*)
2007 (*--------------------------------------------------------------------*)
2008 (*Schalk I, p.70 Nr. 480b
2009 val t = str2term "((12*x*y/(9*x^^^2 - y^^^2))/" ^
2010 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
2011 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
2012 "(20*x*y/(x^^^2 - 25*y^^^2))";
2013 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2015 Kann nicht weiter vereinfacht werden !!!!?? *)
2017 (*--------------------------------------------------------------------*)
2018 "---- MGs test set";
2019 val t = str2term " (1 + x^^^5) / (y + x) + x^^^3 / x ";
2020 val SOME (t,_) = rewrite_set_ thy false common_nominator_p t;
2021 if term2str t = "(1 + x ^^^ 3 + x ^^^ 5 + y * x ^^^ 2) / (x + y)" then()
2024 (*--------------------------------------------------------------------*)
2025 (* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3b
2026 ---> Sortierung FALSCH !! *)
2027 val t = str2term "b^^^3 * a^^^5/a ";
2028 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
2030 "1 * (a^^^4 * b^^^3) / 1"; (*OK*)
2032 val t = str2term "b^^^3 * a^^^5/b ";
2033 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
2035 "1 * (b^^^2 * a^^^5) / 1"; (*cancel_p sortiert hier falsch um!*)
2037 (* Problem liegt NICHT bei ord_make_polynomial! (siehe folgende Bsple) *)
2039 val x = str2term "x"; val bdv = str2term "bdv";
2040 val t1 = str2term "b^^^2 * a^^^5";
2041 val t2 = str2term "a^^^5 * b^^^2 ";
2042 ord_make_polynomial false Rational.thy [(x,bdv)] (t1,t2); (*false*)
2044 (* ==> "b^^^2 * a^^^5" > "a^^^5 * b^^^2 " ... OK!*)
2046 (*--------------------------------------------------------------------*)
2047 (* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3c
2048 ---> erzeugt berflssige "1 * ..."
2050 val t = str2term "-1 / (3 + y)";
2052 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
2055 (********* Das ist das PROBLEM !!!!!!!??? *******************)
2056 (* -1 im Z???ler der Angabe verursacht das Problem !*)
2059 (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
2060 "----- MGs test set";
2061 val t = str2term "(a^^^2 + -1)/(a+1)";
2062 val SOME (t',_) = rewrite_set_ thy false cancel_p t;
2063 if term2str t' = "(-1 + a) / 1" then ()
2064 else error "rational.sml MG tests 3d";
2066 "----- NOT TERMINATING ?: worked before 0707xx";
2067 val t = str2term "(a^^^2 - 1)*(b + 1) / ((b^^^2 - 1)*(a+1))";
2068 val SOME (t'',_) = rewrite_set_ thy false norm_Rational t;
2069 if term2str t'' = "(1 + -1 * a) / (1 + -1 * b)" then ()
2070 else error "rational.sml MG tests 3e";
2072 "----- corrected SK060905";
2073 val t = str2term "(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
2074 val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2075 if term2str t' = "-1 / (5 + -2 * x)" then ()
2076 else error "rational.sml corrected SK060905";
2079 "-------- examples for Stefan Karnels thesis ------------";
2080 "-------- examples for Stefan Karnels thesis ------------";
2081 "-------- examples for Stefan Karnels thesis ------------";
2082 (*SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*)
2084 "(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))";
2085 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2088 "5 * x ^^^ 2 / (b ^^^ 3 * c)"
2090 else error "rational.sml: diff.behav. in norm_Rational_mg 53";
2093 "-------- me Schalk I No.186 ----------------------------";
2094 "-------- me Schalk I No.186 ----------------------------";
2095 "-------- me Schalk I No.186 ----------------------------";
2096 val fmz = ["Term ((14 * x * y) / ( x * y ))",
2099 ("Rational",["rational","simplification"],
2100 ["simplification","of_rationals"]);
2101 val p = e_pos'; val c = [];
2102 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
2103 val (p,_,f,nxt,_,pt) = me nxt p c pt;
2104 val (p,_,f,nxt,_,pt) = me nxt p c pt;
2105 val (p,_,f,nxt,_,pt) = me nxt p c pt;
2106 val (p,_,f,nxt,_,pt) = me nxt p c pt;
2107 val (p,_,f,nxt,_,pt) = me nxt p c pt;
2108 val (p,_,f,nxt,_,pt) = me nxt p c pt;
2109 val (p,_,f,nxt,_,pt) = me nxt p c pt;
2110 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
2111 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
2112 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
2113 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
2114 case (f2str f, nxt) of
2115 ("14", ("End_Proof'", _)) => ()
2116 | _ => error "rational.sml diff.behav. in me Schalk I No.186";
2119 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
2120 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
2121 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
2124 [(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"],
2125 ("Rational",["rational","simplification"],
2126 ["simplification","of_rationals"]))];
2129 autoCalculate 1 CompleteCalc;
2130 val ((pt,p),_) = get_calc 1; show_pt pt;
2132 interSteps 1 ([1],Res);
2133 val ((pt,p),_) = get_calc 1; show_pt pt;
2136 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
2137 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
2138 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
2141 [(["Term ((a^2 + -1*b^2) / (a^2 + -2*a*b + b^2))", "normalform N"],
2142 ("Rational",["rational","simplification"],
2143 ["simplification","of_rationals"]))];
2146 autoCalculate 1 CompleteCalc;
2147 val ((pt,p),_) = get_calc 1; show_pt pt;
2148 (*========== inhibit exn 110314 ================================================
2149 (*with explicit script done already... and removed [1,..] at below...
2150 interSteps 1 ([1],Res);
2151 val ((pt,p),_) = get_calc 1; show_pt pt;
2153 interSteps 1 ([2],Res);
2154 val ((pt,p),_) = get_calc 1; show_pt pt;
2156 interSteps 1 ([2,1],Res);
2157 val ((pt,p),_) = get_calc 1; show_pt pt;
2158 val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*);
2159 (*if length newnds = 12 then () WN060905*)
2160 if length newnds = 13 then ()
2161 else error "rational.sml: interSteps cancel_p rev_rew_p";
2163 val p = ([2,1,9],Res);
2165 val (_, tac, _) = pt_extract (pt, p);
2166 (*case tac of SOME (Rewrite ("sym_real_plus_binom_times1", _)) => ()
2168 case tac of SOME (Rewrite ("sym_real_add_mult_distrib2", _)) => ()
2169 | _ => error "rational.sml: getTactic, sym_real_plus_binom_times1";
2170 ============ inhibit exn 110314 ==============================================*)
2173 "-------- investigate rulesets for cancel_p -------------";
2174 "-------- investigate rulesets for cancel_p -------------";
2175 "-------- investigate rulesets for cancel_p -------------";
2176 val thy = @{theory "Rational"};
2177 "---------------- (a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
2178 val t = str2term "(a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
2179 val tt = str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"(*numerator only*);
2180 "----- with rewrite_set_";
2181 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
2182 term2str tt'= "a ^^^ 2 + -1 * b ^^^ 2" (*true*);
2183 val tt = str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*);
2184 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
2185 term2str tt' = "a ^^^ 2 + -2 * a * b + b ^^^ 2" (*true*);
2187 "----- with make_deriv";
2188 val SOME (tt, _) = factout_p_ thy t; term2str tt =
2189 "(1 * a + 1 * b) * (1 * a + -1 * b) / ((1 * a + -1 * b) * (1 * a + -1 * b))";
2191 "--- with ruleset as before 060829";
2192 val {rules, rew_ord=(_,ro),...} =
2193 rep_rls (assoc_rls "make_polynomial");
2194 val der = make_deriv thy Atools_erls rules ro NONE tt;
2195 print_depth 99; map (term2str o #1) der; print_depth 3;
2196 print_depth 99; map (rule2str o #2) der; print_depth 3;
2197 ... did not terminate*)
2198 "--- with simpler ruleset";
2199 val {rules, rew_ord=(_,ro),...} =
2200 rep_rls (assoc_rls "rev_rew_p");
2201 val der = make_deriv thy Atools_erls rules ro NONE tt;
2202 print_depth 99; writeln (deriv2str der); print_depth 3;
2204 print_depth 99; map (term2str o #1) der; print_depth 3;
2205 "...,(-1 * b ^^^ 2 + a ^^^ 2) / (-2 * (a * b) + a ^^^ 2 + (-1 * b) ^^^ 2) ]";
2206 print_depth 99; map (rule2str o #2) der; print_depth 3;
2207 print_depth 99; map (term2str o #1 o #3) der; print_depth 3;
2209 val der = make_deriv thy Atools_erls rules ro NONE
2210 (str2term "(1 * a + 1 * b) * (1 * a + -1 * b)");
2211 print_depth 99; writeln (deriv2str der); print_depth 3;
2213 val {rules, rew_ord=(_,ro),...} =
2214 rep_rls (assoc_rls "rev_rew_p");
2215 val der = make_deriv thy Atools_erls rules ro NONE
2216 (str2term "(1 * a + -1 * b) * (1 * a + -1 * b)");
2217 print_depth 99; writeln (deriv2str der); print_depth 3;
2218 print_depth 99; map (term2str o #1) der; print_depth 3;
2219 (*WN060829 ...postponed*)
2222 "-------- investigate format of factout_ and factout_p_ -";
2223 "-------- investigate format of factout_ and factout_p_ -";
2224 "-------- investigate format of factout_ and factout_p_ -";
2225 val {rules, rew_ord = (_,ro),...} = rep_rls (assoc_rls "make_polynomial");
2226 val (thy, eval_rls) = (@{theory "Rational"}, Atools_erls)(*see 'fun init_state'*);
2227 val Rrls {scr = Rfuns {init_state,...},...} = assoc_rls "cancel_p";
2229 "----- see Rational.ML, local cancel_p, fun init_state";
2230 val t = str2term "(a^^^2 + (-1)*b^^^2) / (a^^^2 + (-2)*a*b + b^^^2)";
2231 val SOME (t',_) = factout_p_ thy t; term2str t';
2233 val rtas = reverse_deriv thy eval_rls rules ro NONE t';
2234 writeln(trtas2str rst);
2238 "----- see Rational.ML, local cancel_p, fun init_state";
2239 val t = str2term "a^^^2 / a";
2240 val SOME (t',_) = factout_p_ thy t;
2241 term2str t' = "a * a / (1 * a)" (*true*);
2242 (*... can be canceled with
2243 real_mult_div_cancel2 ?k ~= 0 ==> ?m * ?k / (?n * ?k) = ?m / ?n"*)
2244 (* sml/ME/rewtools.sml:
2245 val rtas = reverse_deriv thy Atools_erls rules ro NONE t';
2246 writeln (deri2str rtas);
2250 "-------- SK 060904 ----------------------------------------------";
2251 "----- order on polynomials -- input + output";
2252 val thy = @{theory "Isac"};
2253 val t = str2term "(a + -1 * b) / (-1 * a + b)";
2254 val SOME (t', _) = factout_p_ thy t; term2str t';
2255 val SOME (t', _) = cancel_p_ thy t; term2str t';
2257 val t = str2term "a*b*c*d / (d*e*f*g)";
2258 val SOME (t', _) = cancel_p_ thy t; term2str t';
2260 val t = str2term "a*(b*(c*d)) / (b*(e*(f*g)))";
2261 val SOME (t', _) = cancel_p_ thy t; term2str t';
2264 "----- SK060904-1a non-termination of cancel_p_ ? worked before 0707xx";
2265 val t = str2term "(x^^^2 - 4)*(3 - y) / ((y^^^2 - 9)*(2+x))";
2266 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
2267 if term2str t' = "(2 + -1 * x) / (3 + y)" then ()
2268 else error "rational.sml SK060904-1a worked since 0707xx";
2270 "----- SK060904-1b non-termination of cancel_p_ ... worked before 0707xx";
2271 val t = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
2272 "(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
2273 val SOME (t',_) = cancel_p_ thy t;
2274 if term2str t' = "1 / (4 * c + 3 * e)" then ()
2275 else error "rational.sml SK060904-1b";
2278 "----- SK060904-2a non-termination of add_fraction_p_";
2279 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^
2280 " (-1 * a + b * x) / (a + b * x) ");
2282 val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
2284 common_nominator_p_ thy t;
2285 " (a + b * x)*(a + b * x) / ((a + -1 * (b * x))*(a + -1 * (b * x))) + " ^
2286 " (-1 * a + b * x)*(a + -1 * (b * x)) / ((a + b * x)*(-1 * a + b * x)) ";
2288 add_fraction_p_ thy t;
2289 " ((a + b * x)*(a + b * x) + (-1 * a + b * x)*(a + -1 * (b * x))) /" ^
2290 " ((a + b * x)*(-1 * a + b * x)) ";
2294 "-------- how to stepwise construct Scripts -------------";
2295 "-------- how to stepwise construct Scripts -------------";
2296 "-------- how to stepwise construct Scripts -------------";
2297 val thy = @{theory "Rational"};
2299 val p1 = parse thy (
2300 "Script SimplifyScript (t_t::real) = " ^
2301 " (Rewrite_Set discard_minus False " ^
2304 (*required (): (Rewrite_Set discard_minus False)*)
2305 val p2 = parse thy (
2306 "Script SimplifyScript (t_t::real) = " ^
2307 " (Rewrite_Set discard_minus False " ^
2310 val p3 = parse thy (
2311 "Script SimplifyScript (t_t::real) = " ^
2312 " ((Rewrite_Set discard_minus False) " ^
2315 val p4 = parse thy (
2316 "Script SimplifyScript (t_t::real) = " ^
2317 " ((Rewrite_Set discard_minus False) " ^
2320 val p5 = parse thy (
2321 "Script SimplifyScript (t_t::real) = " ^
2322 " ((Try (Rewrite_Set discard_minus False) " ^
2323 " Try (Rewrite_Set discard_parentheses False)) " ^
2326 val p6 = parse thy (
2327 "Script SimplifyScript (t_t::real) = " ^
2328 " ((Try (Rewrite_Set discard_minus False) @@ " ^
2329 " Try (Rewrite_Set rat_mult_poly False) @@ " ^
2330 " Try (Rewrite_Set make_rat_poly_with_parentheses False) @@ " ^
2331 " Try (Rewrite_Set cancel_p_rls False) @@ " ^
2333 " ((Try (Rewrite_Set common_nominator_p_rls False) @@ " ^
2334 " Try (Rewrite_Set rat_mult_div_pow False) @@ " ^
2335 " Try (Rewrite_Set make_rat_poly_with_parentheses False) @@" ^
2336 " Try (Rewrite_Set cancel_p_rls False) @@ " ^
2337 " Try (Rewrite_Set rat_reduce_1 False)))) @@ " ^
2338 " Try (Rewrite_Set discard_parentheses False)) " ^
2342 "----------- get_denominator ----------------------------";
2343 "----------- get_denominator ----------------------------";
2344 "----------- get_denominator ----------------------------";
2345 val thy = @{theory Isac};
2346 val t = term_of (the (parse thy "get_denominator ((a +x)/b)"));
2347 val SOME (_, t') = eval_get_denominator "" 0 t thy;
2348 if term2str t' = "get_denominator ((a + x) / b) = b" then ()
2349 else error "get_denominator ((a + x) / b) = b"
2352 "--------- several errpats in complicated term -------------------";
2353 "--------- several errpats in complicated term -------------------";
2354 "--------- several errpats in complicated term -------------------";
2355 (*TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one*)
2358 [(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"],
2359 ("Rational",["rational","simplification"], ["simplification","of_rationals"]))];
2362 autoCalculate 1 CompleteCalc;
2363 val ((pt,p),_) = get_calc 1; show_pt pt;
2365 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
2366 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
2367 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
2368 (*------------------------------------------------------------------------------------\
2369 "--- WN121204: searched rational.sml for "nonterm", added new numbering" ^
2370 " and thoroughly tested with this numbering subsequently";
2372 WN.2.6.03 from rlang.sml 56a
2373 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)";
2374 val NONE = rewrite_set_ thy false common_nominator_p t;
2376 WN060831 nonterm.SK7
2377 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
2378 val NONE = add_fraction_p_ thy t;
2380 nonterm.SK9 loops: cancel_p kann nicht weiter kuerzen!!! *)
2381 val t'' = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
2382 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t'';
2385 "(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)";
2386 WN060831 nonterm.SK10
2387 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
2391 "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
2392 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2395 else error "rational.sml: diff.behav. in norm_Rational_mg 42";
2398 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
2399 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
2400 ... non terminating.
2402 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
2403 "(-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)";
2404 val SOME (t,_) = rewrite_set_ thy false cancel_p t';
2406 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
2407 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2409 val t = str2term "((12*x*y/(9*x^^^2 - y^^^2))/" ^
2410 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
2411 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
2412 "(20*x*y/(x^^^2 - 25*y^^^2))";
2413 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
2415 SK060904-2a non-termination of add_fraction_p_";
2416 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^
2417 " (-1 * a + b * x) / (a + b * x) ");
2419 val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
2421 common_nominator_p_ thy t;
2422 " (a + b * x)*(a + b * x) / ((a + -1 * (b * x))*(a + -1 * (b * x))) + " ^
2423 " (-1 * a + b * x)*(a + -1 * (b * x)) / ((a + b * x)*(-1 * a + b * x)) ";
2425 add_fraction_p_ thy t;
2426 " ((a + b * x)*(a + b * x) + (-1 * a + b * x)*(a + -1 * (b * x))) /" ^
2427 " ((a + b * x)*(-1 * a + b * x)) ";
2428 --------------------------------------------------------------------------------------/*)
2430 (*------------------------------------------------------------------------------------\
2431 "WN121205: thoroughly tested with the above numbering.";
2432 " errors in cancel_p: --- 4,5,6,7.";
2433 " error in common_nominator_p, common_nominator_p_: --- 10; 1,2?.";
2434 " errors caused by ruleset norm_Rational: --- 8,9.";
2435 trace_rewrite := true;
2437 "--- 1 ---: non-terminating with ### add_fract: done t22 ";
2438 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)";
2439 trace_rewrite:= true;
2440 rewrite_set_ thy false common_nominator_p t;
2442 "--- 2 ---: non-terminating with ### add_fract: done t22 ";
2443 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
2444 add_fraction_p_ thy t;
2446 "--- 3 ---: norm_Rational calls Rrls cancel_p with non-normalised polys";
2447 val t = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
2448 rewrite_set_ thy false norm_Rational t;
2449 (*tracing end...#### rls: cancel_p on:
2450 (a * x ^^^ 2 + -2 * (a * (x * y)) + a * y ^^^ 2 + b * x ^^^ 2 + -2 * (b * (x * y)) + b * y ^^^ 2) /
2451 (a ^^^ 2 * x ^^^ 2 + -1 * (a ^^^ 2 * y ^^^ 2) + -1 * (b ^^^ 2 * x ^^^ 2) + b ^^^ 2 * y ^^^ 2) *)
2453 "--- 4 ---: non-terminating with Rrls cancel_p on plausible input";
2455 "(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /"^
2456 "(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)");
2457 rewrite_set_ thy false cancel_p t;
2458 (*# rls: cancel_p on:
2459 (a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /
2460 (a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2) *)
2462 "--- 5 ---: non-terminating with Rrls cancel_p on plausible input";
2463 val t = str2term "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
2464 rewrite_set_ thy false norm_Rational t;
2465 (*#### rls: cancel_p on:
2466 (2304 + -1152 * x + -2304 * y + 144 * x ^^^ 2 + 1152 * (x * y) + -144 * (x ^^^ 2 * y)) /
2467 (48 + -12 * x + -96 * y + 24 * (x * y) + 48 * y ^^^ 2 + -12 * (x * y ^^^ 2)) *)
2469 "--- 6 ---: non-terminating with Rrls cancel_p on plausible input";
2471 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
2472 rewrite_set_ thy false norm_Rational t;
2473 (*### rls: cancel_p on: (-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * (x * y) +
2474 144 * (x ^^^ 2 * y)) /
2475 (-48 + 12 * x + 96 * y + -24 * (x * y) + -48 * y ^^^ 2 + 12 * (x * y ^^^ 2)) *)
2477 "--- 7 ---: non-terminating with Rrls cancel_p on plausible input";
2479 "(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /"^
2480 "(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)");
2481 rewrite_set_ thy false cancel_p t';
2483 "--- 8 ---: bottom of output cannot be looked ad (due to looping?)";
2484 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
2485 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
2487 "--- 9 ---: probably error in norm_Rational";
2489 "((12*x*y / (9*x^^^2 - y^^^2)) / (1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
2490 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2) / (20*x*y/(x^^^2 - 25*y^^^2))");
2491 rewrite_set_ thy false norm_Rational t;
2492 (*#### rls: cancel_p on: (19440 * (x ^^^ 8 * y ^^^ 2) + -490320 * (x ^^^ 6 * y ^^^ 4) +
2493 108240 * (x ^^^ 4 * y ^^^ 6) +
2494 -6000 * (x ^^^ 2 * y ^^^ 8)) /
2495 (2160 * (x ^^^ 8 * y ^^^ 2) + -108240 * (x ^^^ 6 * y ^^^ 4) +
2496 1362000 * (x ^^^ 4 * y ^^^ 6) +
2497 -150000 * (x ^^^ 2 * y ^^^ 8)) *)
2499 "--- 10 ---: non-terminating with ### add_fract: done t22: error in common_nominator_p ";
2500 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)");
2501 rewrite_set_ thy false common_nominator_p t; (*### add_fract: done t22 *)
2502 common_nominator_p_ thy t; (*loops without output*)
2503 "--- reformulated 10:";
2504 val t = str2term "(a + -1 * (b * x)) / (a + b * x)";
2505 rewrite_set_ thy false cancel_p t = NONE;
2508 "...both are to be considered after common_nominator_p_ is improved";
2509 --------------------------------------------------------------------------------------/*)
2510 ============ inhibit exn WN130824 TODO ======================================================*)