Test_Isac works again, perfectly ..
# the same tests works as in 8df4b6196660 (the *child* of "Test_Isac works...")
# ..EXCEPT those marked with "exception Div raised"
# for general state of tests see Test_Isac section {* history of tests *}.
1 (* Title: tests for rationals
3 Use is subject to license terms.
6 "-----------------------------------------------------------------------------";
7 "-----------------------------------------------------------------------------";
8 "table of contents -----------------------------------------------------------";
9 "-----------------------------------------------------------------------------";
10 "-------- fun poly_of_term ---------------------------------------------------";
11 "-------- fun is_poly --------------------------------------------------------";
12 "-------- fun term_of_poly ---------------------------------------------------";
13 "-------- integration lev.1 fun factout_p_ -----------------------------------";
14 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
15 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
16 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
17 "-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
18 "-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
19 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
20 "-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
21 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
22 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
23 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
24 "-------- reverse rewrite ----------------------------------------------------";
25 "-------- 'reverse-ruleset' cancel_p -----------------------------------------";
26 "-------- investigate rls norm_Rational --------------------------------------";
27 "-------- examples: rls norm_Rational ----------------------------------------";
28 "-------- rational numerals --------------------------------------------------";
29 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
30 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
31 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
32 "-------- examples common denominator and multiplication from: Schalk --------";
33 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
34 "-------- me Schalk I No.186 -------------------------------------------------";
35 "-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
36 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
37 "-------- investigate rulesets for cancel_p ----------------------------------";
38 "-------- fun eval_get_denominator -------------------------------------------";
39 "-------- several errpats in complicated term --------------------------------";
40 "-----------------------------------------------------------------------------";
41 "-----------------------------------------------------------------------------";
44 "-------- fun poly_of_term ---------------------------------------------------";
45 "-------- fun poly_of_term ---------------------------------------------------";
46 "-------- fun poly_of_term ---------------------------------------------------";
47 val vs = "12 * x^^^3 * y^^^4 * z^^^6" |> str2term |> vars |> map free2str |> sort string_ord;
49 if poly_of_term vs (str2term "12::real") = SOME [(12, [0, 0, 0])]
50 then () else error "poly_of_term 1 changed";
51 if poly_of_term vs (str2term "x::real") = SOME [(1, [1, 0, 0])]
52 then () else error "poly_of_term 2 changed";
53 if poly_of_term vs (str2term "12 * x^^^3") = SOME [(12, [3, 0, 0])]
54 then () else error "poly_of_term 3 changed";
55 if poly_of_term vs (str2term "12 * x^^^3 * y^^^4 * z^^^6") = SOME [(12, [3, 4, 6])]
56 then () else error "poly_of_term 4 changed";
57 if poly_of_term vs (str2term "1 + 2 * x^^^3 * y^^^4 * z^^^6 + y") =
58 SOME [(1, [0, 0, 0]), (1, [0, 1, 0]), (2, [3, 4, 6])]
59 then () else error "poly_of_term 5 changed";
61 (*poly_of_term is quite liberal:*)
62 (*the coefficient may be somewhere, the order of variables and the parentheses
63 within a monomial are arbitrary*)
64 if poly_of_term vs (str2term "y^^^4 * (x^^^3 * 12 * z^^^6)") = SOME [(12, [3, 4, 6])]
65 then () else error "poly_of_term 6 changed";
67 (*there may even be more than 1 coefficient:*)
68 if poly_of_term vs (str2term "2 * y^^^4 * (x^^^3 * 6 * z^^^6)") = SOME [(12, [3, 4, 6])]
69 then () else error "poly_of_term 7 changed";
71 (*the order and the parentheses within monomials are arbitrary:*)
72 if poly_of_term vs (str2term "2 * x^^^3 * y^^^4 * z^^^6 + (7 * y^^^8 + 1)")
73 = SOME [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 6])]
74 then () else error "poly_of_term 8 changed";
76 "-------- fun is_poly --------------------------------------------------------";
77 "-------- fun is_poly --------------------------------------------------------";
78 "-------- fun is_poly --------------------------------------------------------";
79 if is_poly (str2term "2 * x^^^3 * y^^^4 * z^^^6 + 7 * y^^^8 + 1")
80 then () else error "is_poly 1 changed";
81 if not (is_poly (str2term "2 * (x^^^3 * y^^^4 * z^^^6 + 7) * y^^^8 + 1"))
82 then () else error "is_poly 2 changed";
84 "-------- fun term_of_poly ---------------------------------------------------";
85 "-------- fun term_of_poly ---------------------------------------------------";
86 "-------- fun term_of_poly ---------------------------------------------------";
87 val expT = HOLogic.realT
88 val Free (_, baseT) = (hd o vars o str2term) "12 * x^^^3 * y^^^4 * z^^^6";
89 val p = [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 5])]
90 val vs = ["x","y","z"]
91 (*precondition for [(c, es),...]: legth es = length vs*)
93 if term2str (term_of_poly baseT expT vs p) = "1 + 7 * y ^^^ 8 + 2 * x ^^^ 3 * y ^^^ 4 * z ^^^ 5"
94 then () else error "term_of_poly 1 changed";
96 "-------- integration lev.1 fun factout_p_ -----------------------------------";
97 "-------- integration lev.1 fun factout_p_ -----------------------------------";
98 "-------- integration lev.1 fun factout_p_ -----------------------------------";
99 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)"
100 val SOME (t', asm) = factout_p_ thy t;
101 if term2str t' = "(x + y) * (x + -1 * y) / (x * (x + -1 * y))"
102 then () else error ("factout_p_ term 1 changed: " ^ term2str t')
104 if terms2str asm = "[\"x ~= 0\",\"x + -1 * y ~= 0\"]"
105 then () else error "factout_p_ asm 1 changed"
107 val t = str2term "nothing + to_cancel ::real";
108 if NONE = factout_p_ thy t then () else error "factout_p_ doesn't report non-applicable";
110 val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
111 val SOME (t', asm) = factout_p_ thy t;
112 if term2str t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso
113 terms2str asm = "[\"1 + x ~= 0\"]"
114 then () else error "factout_p_ 1 changed";
116 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
117 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
118 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
119 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)"
120 val SOME (t', asm) = cancel_p_ thy t;
121 if (term2str t', terms2str asm) = ("(x + y) / x", "[\"x ~= 0\"]")
122 then () else error ("cancel_p_ (t', asm) 1 changed: " ^ term2str t')
124 val t = str2term "nothing + to_cancel ::real";
125 if NONE = cancel_p_ thy t then () else error "cancel_p_ doesn't report non-applicable";
127 val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
128 val SOME (t', asm) = cancel_p_ thy t;
129 if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[]"
130 then () else error "cancel_p_ 1 changed";
132 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
133 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
134 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
135 val t = str2term ("y / (a*x + b*x + c*x) " ^
139 val SOME (t', asm) = common_nominator_p_ thy t;
141 ("y * y / (x * ((a + b + c) * y)) " ^
142 (* n1 *d2'/ (c'* ( d1' *d2')) *)
143 "+ a * (a + b + c) / (x * ((a + b + c) * y))")
144 (* n2 * d1' / (c'* ( d1' *d2')) *)
145 then () else error "common_nominator_p_ term 1 changed";
146 if terms2str asm = "[\"a + b + c ~= 0\",\"y ~= 0\",\"x ~= 0\"]"
147 then () else error "common_nominator_p_ asm 1 changed"
149 "-------- example in mail Nipkow";
150 val t = str2term "x/(x^^^2 + -1*y^^^2) + y/(x^^^2 + -1*x*y)";
151 val SOME (t', asm) = common_nominator_p_ thy t;
152 if term2str t' = "x * x / " ^
153 "((x + -1 * y) * ((x + y) * x))" ^
156 "((x + -1 * y) * ((x + y) * x))"
157 then () else error "common_nominator_p_ term 2 changed"
159 if terms2str asm = "[\"x + y ~= 0\",\"x ~= 0\",\"x + -1 * y ~= 0\"]"
160 then () else error "common_nominator_p_ asm 2 changed"
162 "-------- example: applicable tested by SML code";
163 val t = str2term "nothing / to_add";
164 if NONE = common_nominator_p_ thy t then () else error "common_nominator_p_ term 3 changed";
166 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
167 val SOME (t', asm) = common_nominator_p_ thy t;
169 "(x + -1) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(x + 1) * (1 + x) / ((1 + x) * (-1 + x))"
170 andalso terms2str asm = "[\"1 + x ~= 0\",\"-1 + x ~= 0\"]"
171 then () else error "common_nominator_p_ 3 changed";
173 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
174 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
175 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
176 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
177 val SOME (t', asm) = add_fraction_p_ thy t;
178 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)"
179 then () else error "add_fraction_p_ 3 changed";
181 if terms2str asm = "[\"-1 + x ^^^ 2 ~= 0\"]"
182 then () else error "add_fraction_p_ 3 changed";
184 val t = str2term "nothing / to_add";
185 if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ term 3 changed";
187 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
188 val SOME (t', asm) = add_fraction_p_ thy t;
189 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso
190 terms2str asm = "[\"-1 + x ^^^ 2 ~= 0\"]"
191 then () else error "add_fraction_p_ 3 changed";
193 "-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
194 "-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
195 "-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
196 (* trace down until prepats are evaluated
197 (which does not to work, because substitution is not done -- compare rew_sub!);
198 keep this sequence for the case, factout_p, cancel_p, common_nominator_p, add_fraction_p
199 (again) get prepat = [] changed to <>[]. *)
200 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)";
202 (*rewrite_set_ @{theory Isac} true cancel t = NONE; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
203 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (thy, false, cancel_p, t);
204 "~~~~~ fun rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
205 (thy, 1, bool, [], rls, term);
206 (*val (t', asm, rew) = app_rev thy (i+1) rrls t; rew = false!!!!!!!!!!!!!!!!!!!!!*)
207 "~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
208 fun chk_prepat thy erls [] t = true
209 | chk_prepat thy erls prepat t =
211 fun chk (pres, pat) =
213 val subst: Type.tyenv * Envir.tenv =
214 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
216 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
217 end) handle _ => false
218 fun scan_ f [] = false (*scan_ NEVER called by []*)
219 | scan_ f (pp::pps) =
220 if f pp then true else scan_ f pps;
221 in scan_ chk prepat end;
222 (* apply the normal_form of a rev-set *)
223 fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
224 if chk_prepat thy erls prepat t
225 then ((*tracing("### app_rev': t = "^term2str t);*) normal_form t)
227 (* val opt = app_rev' thy rrls t ..NONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
228 "~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
230 (* chk_prepat thy erls prepat t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
231 (* app_sub thy i rrls t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
232 "~~~~~ fun chk_prepat, args:"; val (thy, erls, prepat, t) = (thy, erls, prepat, t);
233 fun chk (pres, pat) =
235 val subst: Type.tyenv * Envir.tenv =
236 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
238 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
239 end) handle _ => false
240 fun scan_ f [] = false (*scan_ NEVER called by []*)
241 | scan_ f (pp::pps) =
242 if f pp then true else scan_ f pps;
244 (*========== inhibit exn WN130823: prepat is empty ====================================
245 (* scan_ chk prepat = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
246 "~~~~~ fun , args:"; val (f, (pp::pps)) = (chk, prepat);
248 val ([t1, t2], t) = pp;
249 term2str t1 = "?r is_expanded";
250 term2str t2 = "?s is_expanded";
251 term2str t = "?r / ?s";
252 (* f pp = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
253 "~~~~~ fun chk, args:"; val (pres, pat) = (pp);
254 val subst: Type.tyenv * Envir.tenv =
255 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
257 ({}, {(("r", 0), ("real", Var (("r", 0), "real"))),
258 (("s", 0), ("real", Var (("s", 0), "real")))}*)
260 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
261 "~~~~~ fun eval__true, args:"; val (thy, i, asms, bdv, rls) =
262 (thy, (i + 1), (map (Envir.subst_term subst) pres), [], erls);
263 terms2str asms; (* = "[\"?r is_expanded\",\"?s is_expanded\"]"*)
264 asms = [@{term True}] orelse asms = []; (* = false*)
265 asms = [@{term False}] ; (* = false*)
266 "~~~~~ fun chk, args:"; val (indets, (a::asms)) = ([], asms);
267 bdv (*= []: _a list*);
268 val bdv : (term * term) list = [];
269 rewrite__set_ thy (i+1) false;
270 term2str a = "?r is_expanded"; (*hier m"usste doch der Numerator eingesetzt sein ??????????????*)
271 val SOME (Const ("HOL.False", _), []) = rewrite__set_ thy (i+1) false bdv rls a
272 ============ inhibit exn WN130823: prepat is empty ===================================*)
274 "-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
275 "-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
276 "-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
277 val t = str2term "(12 * x * y) / (8 * y^^^2 )";
278 (* "-------- example 187a": exception Div raised...
279 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
280 val t = str2term "(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
281 (* "-------- example 187b": doesn't terminate...
282 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
283 val t = str2term "(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";
284 (* "-------- example 187c": doesn't terminate...
285 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
286 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (@{theory Isac}, false, cancel_p, t);
287 (* WN130827: exception Div raised...
288 rewrite__set_ thy 1 bool [] rls term
290 "~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
291 (thy, 1, bool, [], rls, term);
292 (* WN130827: exception Div raised...
293 val (t', asm, rew) = app_rev thy (i+1) rrls t
295 "~~~~~ fun app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
296 (* WN130827: exception Div raised...
297 val opt = app_rev' thy rrls t
299 "~~~~~ fun app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
301 chk_prepat thy erls prepat t = true;
302 (* WN130827: exception Div raised...
305 (* lookup Rational.thy, cancel_p: normal_form = cancel_p_ thy*)
306 "~~~~~ fun cancel_p_, args:"; val (t) = (t);
307 val opt = check_fraction t;
308 val SOME (numerator, denominator) = opt
309 val vs = t |> vars |> map free2str |> sort string_ord
310 val baseT = type_of numerator
311 val expT = HOLogic.realT
312 val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator);
313 (*"-------- example 187a": exception Div raised...
314 val a = [(12, [1, 1])]: poly
315 val b = [(8, [0, 2])]: poly
316 val ((a', b'), c) = gcd_poly a b
318 (* "-------- example 187b": doesn't terminate...
319 val a = [(8, [2, 1, 1])]: poly
320 val b = [(18, [1, 2, 1])]: poly
321 val ((a', b'), c) = gcd_poly a b
323 (* "-------- example 187c": doesn't terminate...
324 val a = [(9, [5, 2, 4])]: poly
325 val b = [(15, [6, 3, 1])]: poly
326 val ((a', b'), c) = gcd_poly a b
329 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
330 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
331 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
332 val t = str2term "(x^^^2 - 4)*(3 - y) / ((y^^^2 - 9)*(2+x))";
333 trace_rewrite := false (*true false*);
334 (* trace stops with ...: (and then jEdit hangs)..
335 rewrite_set_ thy false norm_Rational t;
337 ### rls: cancel_p on: (-12 + 4 * y + 3 * x ^^^ 2 + -1 * (x ^^^ 2 * y)) /
338 (-18 + -9 * x + 2 * y ^^^ 2 + x * y ^^^ 2)
340 val t = str2term (*copy from above: "::real" is not required due to "^^^"*)
341 ("(-12 + 4 * y + 3 * x ^^^ 2 + -1 * (x ^^^ 2 * y)) /" ^
342 "(-18 + -9 * x + 2 * y ^^^ 2 + x * y ^^^ 2)");
344 exception Div raised*)
346 "~~~~~ fun cancel_p_, args:"; val (t) = (t);
347 val opt = check_fraction t;
348 val SOME (numerator, denominator) = opt
349 val vs = t |> vars |> map free2str |> sort string_ord
350 val baseT = type_of numerator
351 val expT = HOLogic.realT;
352 print_depth 3; (*999*)
353 val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator);
354 print_depth 3; (*999*)
355 (* does not terminate instead of returning ?:
356 val ((a', b'), c) = gcd_poly a b
357 val a = [(~12, [0, 0]), (3, [2, 0]), (4, [0, 1]), (~1, [2, 1])]: poly
358 val b = [(~18, [0, 0]), (~9, [1, 0]), (2, [0, 2]), (1, [1, 2])]: poly
361 "-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
362 "-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
363 "-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
364 val thy = @{theory Isac};
365 "----- SK060904-2a non-termination of add_fraction_p_";
366 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^
367 " (-1 * a + b * x) / (a + b * x) ");
368 (* rewrite_set_ thy false norm_Rational t
369 exception Div raised*)
370 (* rewrite_set_ thy false add_fractions_p t;
371 exception Div raised*)
372 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) =
373 (@{theory Isac}, false, add_fractions_p, t);
374 "~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
375 (thy, 1, bool, [], rls, term);
376 (* app_rev thy (i+1) rrls t;
377 exception Div raised*)
378 "~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
379 fun chk_prepat thy erls [] t = true
380 | chk_prepat thy erls prepat t =
382 fun chk (pres, pat) =
384 val subst: Type.tyenv * Envir.tenv =
385 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
387 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
388 end) handle _ => false
389 fun scan_ f [] = false (*scan_ NEVER called by []*)
390 | scan_ f (pp::pps) =
391 if f pp then true else scan_ f pps;
392 in scan_ chk prepat end;
393 (* apply the normal_form of a rev-set *)
394 fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
395 if chk_prepat thy erls prepat t
396 then ((*tracing("### app_rev': t = "^term2str t);*) normal_form t)
398 (* val opt = app_rev' thy rrls t;
399 exception Div raised*)
400 (* val opt = app_rev' thy rrls t;
401 exception Div raised*)
402 "~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
404 chk_prepat thy erls prepat t = true = true;
406 exception Div raised*)
407 (* lookup Rational.thy, val add_fractions_p: normal_form = add_fraction_p_ thy*)
408 (*add_fraction_p_ thy t
409 exception Div raised*)
410 "~~~~~ fun add_fraction_p_, args:"; val ((_: theory), t) = (thy, t);
411 val SOME ((n1, d1), (n2, d2)) = check_frac_sum t;
412 term2str n1; term2str d1; term2str n2; term2str d2;
413 val vs = t |> vars |> map str_of_free_opt (* tolerate Var in simplification *)
414 |> filter is_some |> map the |> sort string_ord;
415 print_depth 3; (*999*)
416 val (SOME _, SOME a, SOME _, SOME b) =
417 (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2);
418 print_depth 3; (*999*)
420 val a = [(1, [1, 0, 0]), (~1, [0, 1, 1])]: poly
421 val b = [(1, [1, 0, 0]), (1, [0, 1, 1])]: poly
422 val ((a', b'), c) = gcd_poly a b
425 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
426 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
427 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
428 val thy = @{theory "Rational"};
430 val t = str2term "(2 + -3 * x) / 9";
431 if NONE = rewrite_set_ thy false cancel_p t then ()
432 else error "rewrite_set_ cancel_p must return NONE, if the term cannot be cancelled";
434 "-------- example 186a";
435 val t = str2term "(14 * x * y) / (x * y)";
436 is_expanded (str2term "14 * x * y");
437 is_expanded (str2term "x * y");
438 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
439 if (term2str t', terms2str asm) = ("14 / 1", "[]")
440 then () else error "rational.sml cancel Schalk 186a";
442 "-------- example 186b";
443 val t = str2term "(60 * a * b) / ( 15 * a * b )";
444 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
445 if (term2str t', terms2str asm) = ("4 / 1", "[]")
446 then () else error "rational.sml cancel Schalk 186b";
448 "-------- example 186c";
449 val t = str2term "(144 * a^^^2 * b * c) / (12 * a * b * c)";
450 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
451 if (term2str t', terms2str asm) = ("12 * a / 1", "[]")
452 then () else error "rational.sml cancel Schalk 186c";
454 (* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! exception Div raised !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
455 see --- fun rewrite_set_ downto fun gcd_poly ---
456 "-------- example 187a";
457 val t = str2term "(12 * x * y) / (8 * y^^^2 )";
458 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
459 if (term2str t', terms2str asm) = ("3 * x / (2 * y)", "[\"4 * y ~= 0\"]")
460 then () else error "rational.sml cancel Schalk 187a";
463 (* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
464 see --- fun rewrite_set_ downto fun gcd_poly ---
465 "-------- example 187b";
466 val t = str2term "(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
467 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
468 if (term2str t', terms2str asm) = ("4 * x / (9 * y)", "[\"2 * (z * (y * x)) ~= 0\"]")
469 then () else error "rational.sml cancel Schalk 187b";
472 (* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
473 see --- fun rewrite_set_ downto fun gcd_poly ---
474 "-------- example 187c";
475 val t = str2term "(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";
476 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
477 if (term2str t', terms2str asm) =
478 ("3 * z ^^^ 3 / (5 * (y * x))", "[\"3 * (z * (y ^^^ 2 * x ^^^ 5)) ~= 0\"]")
479 then () else error "rational.sml cancel Schalk 187c";
482 "-------- example 188a";
483 val t = str2term "(-8 + 8 * x) / (-9 + 9 * x)";
484 is_expanded (str2term "8 * x + -8");
485 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
486 if (term2str t', terms2str asm) = ("8 / 9", "[]")
487 then () else error "rational.sml cancel Schalk 188a";
489 val t = str2term "(8*((-1) + x))/(9*((-1) + x))";
490 val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
491 if (term2str t', terms2str asm) = ("8 / 9", "[]")
492 then () else error "rational.sml cancel Schalk make_polynomial 1";
494 "-------- example 188b";
495 val t = str2term "(-15 + 5 * x) / (-18 + 6 * x)";
496 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
497 if (term2str t', terms2str asm) = ("5 / 6", "[]")
498 then () else error "rational.sml cancel Schalk 188b";
500 "-------- example 188c";
501 val t = str2term "(a + -1 * b) / (b + -1 * a)";
502 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
503 if (term2str t', terms2str asm) = ("-1 / 1", "[]")
504 then () else error "rational.sml cancel Schalk 188c";
506 is_expanded (str2term "a + -1 * b") = true;
507 val t = str2term "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
508 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
509 if (term2str t', terms2str asm) = ("(a + -1 * b) / (-1 * a + b)", "[]")
510 then () else error "rational.sml cancel Schalk make_polynomial 2";
512 "-------- example 190a";
513 val t = str2term "( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )";
514 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
515 if (term2str t', terms2str asm) =
516 ("(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)", "[\"3 * a + 9 * a ^^^ 2 ~= 0\"]")
517 then () else error "rational.sml cancel Schalk 190a";
519 "-------- example 190c";
520 val t = str2term "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
521 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
522 if (term2str t', terms2str asm) =
523 ("(1 + 3 * a + 9 * a ^^^ 2 + 27 * a ^^^ 3) /\n(3 * a + 18 * a ^^^ 2 + 27 * a ^^^ 3)", "[]")
524 then () else error "rational.sml make_polynomial Schalk 190c";
526 "-------- example 191a";
527 val t = str2term "( x^^^2 + -1 * y^^^2 ) / ( x + y )";
528 is_expanded (str2term "x^^^2 + -1 * y^^^2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
529 is_expanded (str2term "x + y") = true;
530 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
531 if (term2str t', terms2str asm) = ("(x + -1 * y) / 1", "[]")
532 then () else error "rational.sml make_polynomial Schalk 191a";
534 "-------- example 191b";
535 val t = str2term "((x + (-1) * y)*(x + y))/((1)*(x + y))";
536 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
537 if (term2str t', terms2str asm) = ("(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)", "[]")
538 then () else error "rational.sml make_polynomial Schalk 191b";
540 "-------- example 191c";
541 val t = str2term "( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )";
542 is_expanded (str2term "9 * x^^^2 + -30 * x + 25") = true;
543 is_expanded (str2term "25 + -30*x + 9*x^^^2") = true;
544 is_expanded (str2term "-25 + 9*x^^^2") = true;
546 val t = str2term "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
547 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
548 if (term2str t', terms2str asm) = ("(25 + -30 * x + 9 * x ^^^ 2) / (-25 + 9 * x ^^^ 2)", "[]")
549 then () else error "rational.sml make_polynomial Schalk 191c";
551 "-------- example 192b";
552 val t = str2term "( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 * y^^^3 )";
553 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
554 if (term2str t', terms2str asm) = ("x ^^^ 2 / y ^^^ 2", "[\"y ^^^ 2 ~= 0\"]")
555 then () else error "rational.sml cancel_p Schalk 192b";
557 val t = str2term "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
558 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
559 if (term2str t', terms2str asm) =
560 ("(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)", "[]")
561 then () else error "rational.sml make_polynomial Schalk 192b";
563 val t = str2term "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
564 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
565 if (term2str t', terms2str asm) =
566 ("(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)", "[]")
567 then () else error "rational.sml make_polynomial Schalk WN050929 not working";
569 "-------- example 193a";
570 val t = str2term "( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )";
571 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
572 if (term2str t', terms2str asm) = ("(-3 + x) / (3 + x)", "[\"3 + x ~= 0\"]")
573 then () else error "rational.sml cancel_p Schalk 193a";
575 "-------- example 193b";
576 val t = str2term "( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )";
577 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
578 if (term2str t', terms2str asm) = ("(-4 + x) / (8 + 2 * x)", "[\"8 + 2 * x ~= 0\"]")
579 then () else error "rational.sml cancel_p Schalk 193b";
581 "-------- example 193c";
582 val t = str2term "( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )";
583 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
584 if (term2str t', terms2str asm) =
585 ("(2 * x + 10 * x ^^^ 2) / (1 + -5 * x)", "[\"1 + -5 * x ~= 0\"]")
586 then () else error "rational.sml cancel_p Schalk 193c";
589 val t = str2term "(-25 + 9*x^^^2)/(5 + 3*x)";
590 val SOME (t, asm) = rewrite_set_ thy false cancel_p t;
591 if (term2str t', terms2str asm) = ("(2 * x + 10 * x ^^^ 2) / (1 + -5 * x)", "[]")
592 then () else error "rational.sml cancel WN 1";
594 "-------- example heuberger";
595 val t = str2term ("(x^^^4 + x * y + x^^^3 * y + y^^^2) / " ^
596 "(x + 5 * x^^^2 + y + 5 * x * y + x^^^2 * y^^^3 + x * y^^^4)");
597 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
598 if (term2str t', terms2str asm) =
599 ("(x ^^^ 3 + y) / (1 + 5 * x + x * y ^^^ 3)", "[\"1 + 5 * x + x * y ^^^ 3 ~= 0\"]")
600 then () else error "rational.sml cancel_p heuberger";
602 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
603 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
604 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
605 (*deleted example 204 ... 236b at update Isabelle2012-->2013*)
607 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
608 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
609 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
610 val t = str2term ("123 = (a*x)/(b*x) + (c*x)/(d*x) + (e*x)/(f*x::real)");
611 "-------- gcd_poly integration level 1: works on exact term";
612 if NONE = cancel_p_ thy t then () else error "cancel_p_ works on exact fraction";
613 if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ works on exact fraction";
615 "-------- gcd_poly integration level 2: picks out ONE appropriate subterm";
616 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
617 if term2str t' = "123 = a * x / (b * x) + c * x / (d * x) + e / f"
618 then () else error "level 2, rewrite_set_ cancel_p: changed";
619 val SOME (t', asm) = rewrite_set_ thy false add_fractions_p t;
620 if term2str t' = "123 = (b * c * x + a * d * x) / (b * d * x) + e * x / (f * x)"
621 then () else error "level 2, rewrite_set_ add_fractions_p: changed";
623 "-------- gcd_poly integration level 3: rewrites all appropriate subterms";
624 val SOME (t', asm) = rewrite_set_ thy false cancel_p_rls t;
625 if term2str t' = "123 = a / b + c / d + e / f"
626 then () else error "level 3, rewrite_set_ cancel_p_rls: changed";
627 val SOME (t', asm) = rewrite_set_ thy false add_fractions_p_rls t; (*CREATE add_fractions_p_rls*)
628 if term2str t' = "123 = (b * d * e * x + b * c * f * x + a * d * f * x) / (b * d * f * x)"
629 then () else error "level 3, rewrite_set_ add_fractions_p_rls: changed";
631 "-------- gcd_poly integration level 4: iteration cancel_p -- add_fraction_p";
632 (* simpler variant *)
633 val testrls = append_rls "testrls" e_rls [Rls_ cancel_p, Rls_ add_fractions_p]
634 val SOME (t', asm) = rewrite_set_ thy false testrls t;
635 (*trace_rewrite := false;
636 # rls: testrls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
637 ## rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
638 ## rls: add_fractions_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f
639 ## rls: cancel_p on: 123 = (b * c * x + a * d * x) / (b * d * x) + e / f
640 ## rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f
641 ## rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
642 ## rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
643 if term2str t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
644 then () else error "level 4, rewrite_set_ *_p: changed";
646 (* complicated variant *)
647 val testrls_rls = append_rls "testrls_rls" e_rls [Rls_ cancel_p_rls, Rls_ add_fractions_p_rls];
648 val SOME (t', asm) = rewrite_set_ thy false testrls_rls t;
649 (*# rls: testrls_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
650 ## rls: cancel_p_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
651 ### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
652 ### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f
653 ### rls: cancel_p on: 123 = a * x / (b * x) + c / d + e / f
654 ### rls: cancel_p on: 123 = a / b + c / d + e / f
655 ## rls: add_fractions_p_rls on: 123 = a / b + c / d + e / f
656 ### rls: add_fractions_p on: 123 = a / b + c / d + e / f
657 ### rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f
658 ### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
659 ## rls: cancel_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
660 ### rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
661 ## rls: add_fractions_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
662 ### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
663 if term2str t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
664 then () else error "level 4, rewrite_set_ *_p_rls: changed"
666 "-------- gcd_poly integration level 5: cancel_p & add_fraction_p within norm_Rational";
667 val SOME (t', asm) = rewrite_set_ thy false norm_Rational t;
668 if term2str t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)"
669 then () else error "level 5, rewrite_set_ norm_Rational: changed"
671 "-------- reverse rewrite ----------------------------------------------------";
672 "-------- reverse rewrite ----------------------------------------------------";
673 "-------- reverse rewrite ----------------------------------------------------";
674 (** the term for which reverse rewriting is demonstrated **)
675 val t = str2term "(9 + -1 * x ^^^ 2) / (9 + 6 * x + x ^^^ 2)";
676 val Rrls {scr = Rfuns {init_state = ini, locate_rule = loc,
677 next_rule = nex, normal_form = nor, ...},...} = cancel_p;
679 (** normal_form produces the result in ONE step **)
680 val SOME (t',_) = nor t;
681 if term2str t' = "(3 + -1 * x) / (3 + x)" then ()
682 else error "rational.sml normal_form (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
684 (** initialize the interpreter state used by the 'me' **)
685 val (t, _, revsets, _) = ini t;
687 if length (hd revsets) = 11 then () else error "length of revset changed";
688 if (revsets |> nth 1 |> nth 1 |> id_of_thm) =
689 (@{thm realpow_twoI} |> string_of_thm |> thmID_of_derivation_name)
690 then () else error "first element of revset changed";
692 (revsets |> nth 1 |> nth 1 |> rule2str) = "Thm (\"realpow_twoI\",??.unknown)" andalso
693 (revsets |> nth 1 |> nth 2 |> rule2str) =
694 "Thm (\"sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))\",??.unknown)" andalso
695 (revsets |> nth 1 |> nth 3 |> rule2str) =
696 "Thm (\"sym_#mult_Float ((2,0), (0,0)) __ ((3,0), (0,0))\",??.unknown)" andalso
697 (revsets |> nth 1 |> nth 4 |> rule2str) =
698 "Thm (\"sym_#mult_Float ((~1,0), (0,0)) __ ((3,0), (0,0))\",??.unknown)" andalso
699 (revsets |> nth 1 |> nth 5 |> rule2str) =
700 "Thm (\"sym_#mult_Float ((3,0), (0,0)) __ ((3,0), (0,0))\",??.unknown)" andalso
701 (revsets |> nth 1 |> nth 6 |> rule2str) = "Rls_ (\"sym_order_mult_rls_\")" andalso
702 (revsets |> nth 1 |> nth 7 |> rule2str) =
703 "Thm (\"sym_mult_assoc\",Groups.semigroup_mult_class.mult_assoc)"
704 then () else error "first 7 elements in revset changed"
706 (** find the rule 'r' to apply to term 't' **)
707 (*/------- WN1309: since cancel_ (accepted "-" between monomials) has been replaced by cancel_p_
708 for Isabelle2013, we don't get a working revset, but non-termination:
710 val SOME (r as (Thm (str, thm))) = nex revsets t;
712 ((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x),
713 Rls_ ("sym_order_mult_rls_"), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x), []))","
714 ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x),
715 Thm ("sym_mult_assoc",""), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x), []))","
716 ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x),
717 Thm ("sym_mult_assoc",""), ((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), []))","
718 ((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), Rls_ ("sym_order_mult_rls_"), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x), []))","
721 Thm ("sym_#mult_2_3", "6 = 2 * 3")
722 ### Isabelle2009-2 for cancel_ (not cancel_p_):
723 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))"
724 andalso string_of_thm thm =
725 (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
726 (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
727 else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
728 \---------------------------------------------------------------------------------------/*)
730 (** check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
731 if the rule is OK, the term resulting from applying the rule is returned,too;
732 there might be several rule applications inbetween,
733 which are listed after the head in reverse order **)
734 (*/-------------------------------------------- Isabelle2013: this gives "error id_of_thm";
735 we don't repair this, because interaction within "reverse rewriting" never worked properly:
737 val (r, (t, asm))::_ = loc revsets t r;
738 if term2str t = "(9 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" andalso asm = []
739 then () else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
741 (* find the next rule to apply *)
742 val SOME (r as (Thm (str, thm))) = nex revsets t;
743 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso
744 string_of_thm thm = (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
745 (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
746 else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
748 (*check the next rule*)
749 val (r, (t, asm)) :: _ = loc revsets t r;
750 if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" then ()
751 else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) II";
753 (*find and check the next rules, rewrite*)
754 val SOME r = nex revsets t;
755 val (r,(t,asm))::_ = loc revsets t r;
756 if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
757 else error "rational.sml locate_rule II";
759 val SOME r = nex revsets t;
760 val (r,(t,asm))::_ = loc revsets t r;
761 if term2str t = "(3 - x) * (3 + x) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
762 else error "rational.sml next_rule II";
764 val SOME r = nex revsets t;
765 val (r,(t,asm))::_ = loc revsets t r;
766 if term2str t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then ()
767 else error "rational.sml next_rule III";
769 val SOME r = nex revsets t;
770 val (r, (t, asm)) :: _ = loc revsets t r;
772 if ss = "(3 - x) / (3 + x)" andalso terms2str asm = "[\"3 + x ~= 0\"]" then ()
773 else error "rational.sml: new behav. in rev-set cancel";
774 \--------------------------------------------------------------------------------------/*)
776 "-------- 'reverse-ruleset' cancel_p -----------------------------------------";
777 "-------- 'reverse-ruleset' cancel_p -----------------------------------------";
778 "-------- 'reverse-ruleset' cancel_p -----------------------------------------";
779 (*WN130909: the example below shows, why "reverse rewriting" only worked for
782 (*the term for which reverse rewriting is demonstrated*)
783 val t = str2term "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))";
784 val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
785 next_rule=nex,normal_form=nor,...},...} = cancel_p;
787 (*normal_form produces the result in ONE step*)
788 val SOME (t',_) = nor t;
789 term2str t' = "(3 + 1 * x) / (3 + -1 * x)";
791 (*initialize the interpreter state used by the 'me'*)
792 val SOME (t', asm) = cancel_p_ thy t;
793 term2str t' = "(3 + x) / (3 + -1 * x)" (*true*);
794 terms2str asm = "[\"3 + -1 * x ~= 0\"]" (*true*);
795 val (t,_,revsets,_) = ini t;
797 (* WN.10.10.02: dieser Fall terminiert nicht
798 (make_polynomial enth"alt zu viele rules)
799 WN060823 'init_state' requires rewriting on specified location in the term
800 print_depth 99; Rfuns; print_depth 3;
801 WN060831 cycling "sym_order_mult_rls_" "sym_mult_assoc"
802 as was with make_polynomial before ?!?*)
804 val SOME r = nex revsets t;
805 eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))",
806 mk_thm thy "9 = 3 ^^^ 2"));
807 (*WN060831 *** id_of_thm
808 Exception- ERROR raised ...
809 val (r,(t,asm))::_ = loc revsets t r;
812 val SOME r = nex revsets t;
813 val (r,(t,asm))::_ = loc revsets t r;
817 "-------- examples: rls norm_Rational ----------------------------------------";
818 "-------- examples: rls norm_Rational ----------------------------------------";
819 "-------- examples: rls norm_Rational ----------------------------------------";
820 val t = str2term "(3*x+5)/18 - x/2 - -(3*x - 2)/9 = 0";
821 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
822 if term2str t' = "1 / 18 = 0" then () else error "rational.sml 1";
824 val t = str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0";
825 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
826 if term2str t' = "(237 + 65 * x) / 36 = 0" then ()
827 else error "rational.sml 2";
829 val t = str2term "(1/2 + (5*x)/2)^^^2 - ((13*x)/2 - 5/2)^^^2 - (6*x)^^^2 + 29";
830 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
831 if term2str t' = "23 + 35 * x + -72 * x ^^^ 2" then ()
832 else error "rational.sml 3";
834 (*trace_rewrite:=true;*)
835 val t = str2term "Not (6*x is_atom)";
836 val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
838 val t = str2term "1 < 2";
839 val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
842 val t = str2term "(6*x)^^^2";
843 val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false
844 (num_str @{thm realpow_def_atom}) t;
845 if term2str t' = "6 * x * (6 * x) ^^^ (2 + -1)" then ()
846 else error "rational.sml powers_erls (6*x)^^^2";
848 val t = str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))";
849 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
850 if term2str t' = "65 * x / 2" then () else error "rational.sml 4";
852 val t = str2term "1 - ((13*x)/2 - 5/2)^^^2";
853 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
854 if term2str t' = "(-21 + 130 * x + -169 * x ^^^ 2) / 4" then ()
855 else error "rational.sml 5";
857 (*SRAM Schalk I, p.92 Nr. 609a*)
858 val t = str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
859 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
860 if term2str t' = "(-255 + 112 * x) / 135" then ()
861 else error "rational.sml 6";
863 (*SRAM Schalk I, p.92 Nr. 610c*)
864 val t = str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
865 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
866 if term2str t' = "(-3 + -1 * x) / 2" then () else error "rational.sml 7";
868 (*SRAM Schalk I, p.92 Nr. 476a*)
869 val t = str2term "(x^^^2/(1 - x^^^2) + 1)/(x/(1 - x) + 1) * (1 + x)";
870 (*. a/b : c/d translated to a/b * d/c .*)
871 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
872 if term2str t' = "1" then () else error "rational.sml 8";
874 (*Schalk I, p.92 Nr. 472a*)
875 val t = str2term "((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
876 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
877 if term2str t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
879 (*Schalk I, p.70 Nr. 480b: SEE rational.sml --- nonterminating rls norm_Rational ---*)
881 (*WN130910 add_fractions_p exception Div raised + history:
882 ### WN.2.6.03 from rlang.sml 56a
883 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)";
884 val NONE = rewrite_set_ thy false add_fractions_p t;
886 THE ERROR ALREADY OCCURS IN THIS PART:
887 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
888 val NONE = add_fraction_p_ thy t;
890 SEE Test_Some.thy: section {* add_fractions_p downto exception Div raised ===
893 "-------- rational numerals --------------------------------------------------";
894 "-------- rational numerals --------------------------------------------------";
895 "-------- rational numerals --------------------------------------------------";
896 (*SRA Schalk I, p.40 Nr. 164b *)
897 val t = str2term "(47/6 - 76/9 + 13/4)/(35/12)";
898 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
900 if term2str t = "19 / 21" then ()
901 else error "rational.sml: diff.behav. in norm_Rational_mg 1";
903 (*SRA Schalk I, p.40 Nr. 166a *)
904 val t = str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
905 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
907 if term2str t = "45 / 2" then ()
908 else error "rational.sml: diff.behav. in norm_Rational_mg 2";
910 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
911 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
912 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
914 val t = str2term "((1 + 9*a^^^2) * (1 + 3*a)) / ((3*a + 9*a^^^2) * (1 + 3*a))";
915 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
916 if term2str t = "(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
917 then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
920 val t = str2term "(x^^^2 * (7*x + (-1)*y)) / (y^^^2 * (7*x + (-1)*y))";
921 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
922 if term2str t = "x ^^^ 2 / y ^^^ 2"
923 then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
925 (*SRC Schalk I, p.66 Nr. 379c *)
926 val t = str2term "(a - b)/(b - a)";
927 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
930 then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
932 (*SRC Schalk I, p.66 Nr. 380b *)
933 val t = str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))";
934 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
935 if term2str t = "(27 + 12 * x) / (28 + 8 * x)"
936 then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
938 (*Schalk I, p.60 Nr. 215c: was not cancelled with Isabelle2002 *)
939 val t = str2term "(a + b)^^^4 * (x - y) / ((x - y)^^^3 * (a + b)^^^2)";
940 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
941 if term2str t = "(a ^^^ 2 + 2 * a * b + b ^^^ 2) / (x ^^^ 2 + -2 * x * y + y ^^^ 2)"
942 then () else error "rational.sml: diff.behav. in norm_Rational_mg 7";
944 (*SRC Schalk I, p.66 Nr. 381b *)
946 "(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
947 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
948 if term2str t = "1 / (-5 + 2 * x)"
949 then () else error "rational.sml: diff.behav. in norm_Rational_mg 9";
952 val t = str2term "((1 + 9*a^^^2) * (1 + 3*a)) / ((3*a + 9*a^^^2) * (1 + 3 * a))";
953 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
954 if term2str t = "(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
955 then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
958 val t = str2term "(x^^^2 * (7*x + (-1)*y)) / (y^^^2 * (7*x + (-1)*y))";
959 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
960 if term2str t = "x ^^^ 2 / y ^^^ 2"
961 then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
963 (*SRC Schalk I, p.66 Nr. 379c *)
964 val t = str2term "(a - b) / (b - a)";
965 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
967 then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
969 (*SRC Schalk I, p.66 Nr. 380b *)
970 val t = str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))";
971 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
972 if term2str t = "(27 + 12 * x) / (28 + 8 * x)"
973 then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
975 (*Schalk I, p.60 Nr. 215c *)
976 val t = str2term "(a + b)^^^4 * (x - y) / ((x - y)^^^3 * (a + b)^^^2)";
977 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
978 if term2str t = "(a ^^^ 2 + 2 * a * b + b ^^^ 2) / (x ^^^ 2 + -2 * x * y + y ^^^ 2)"
979 then () else error "Schalk I, p.60 Nr. 215c: with Isabelle2002 cancellation incomplete, changed";
981 (* extreme example from somewhere *)
983 ("(a^^^4 * x + -1*a^^^4 * y + 4*a^^^3 * b * x + -4*a^^^3 * b * y + " ^
984 "6*a^^^2 * b^^^2 * x + -6*a^^^2 * b^^^2 * y + 4*a * b^^^3 * x + -4*a * b^^^3 * y + " ^
985 "b^^^4 * x + -1*b^^^4 * y) " ^
986 " / (a^^^2 * x^^^3 + -3*a^^^2 * x^^^2 * y + 3*a^^^2 * x * y^^^2 + -1*a^^^2 * y^^^3 + " ^
987 "2*a * b * x^^^3 + -6*a * b * x^^^2 * y + 6*a * b * x * y^^^2 + -2*a * b * y^^^3 + " ^
988 "b^^^2 * x^^^3 + -3*b^^^2 * x^^^2 * y + 3*b^^^2 * x * y^^^2 + -1*b ^^^ 2 * y ^^^ 3)")
989 val SOME (t, _) = rewrite_set_ thy false cancel_p t;
990 if term2str t = "(a ^^^ 2 + 2 * a * b + b ^^^ 2) / (x ^^^ 2 + -2 * x * y + y ^^^ 2)"
991 then () else error "with Isabelle2002: NONE -- now SOME changed";
993 (*Schalk I, p.66 Nr. 381a *)
994 (* ATTENTION: here the rls is very slow. In Isabelle2002 this required 2 min *)
995 val t = str2term "18*(a + b)^^^3 * (a - b)^^^2 / (72*(a - b)^^^3 * (a + b)^^^2)";
996 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
997 if term2str t = "(a + b) / (4 * a + -4 * b)"
998 then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
1000 (*SRC Schalk I, p.66 Nr. 381b *)
1001 val t = str2term "(4*x^^^2 - 20*x + 25) / (2*x - 5)^^^3";
1002 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1003 if term2str t = "1 / (-5 + 2 * x)"
1004 then () else error "rational.sml: diff.behav. in norm_Rational_mg 9";
1006 (*SRC Schalk I, p.66 Nr. 381c *)
1007 val t = str2term "(27*a^^^3 + 9*a^^^2+3*a+1) / (27*a^^^3 + 18*a^^^2+3*a)";
1008 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1009 if term2str t = "(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
1010 then () else error "rational.sml: diff.behav. in norm_Rational_mg 10";
1012 (*SRC Schalk I, p.66 Nr. 383a *)
1013 val t = str2term "(5*a^^^2 - 5*a*b) / (a - b)^^^2";
1014 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1015 if term2str t = "-5 * a / (-1 * a + b)"
1016 then () else error "rational.sml: diff.behav. in norm_Rational_mg 11";
1018 "----- NOT TERMINATING ?: worked before 0707xx";
1019 val t = str2term "(a^^^2 - 1)*(b + 1) / ((b^^^2 - 1)*(a+1))";
1020 (* WN130911 "exception Div raised" by
1021 cancel_p_ thy (str2term ("(-1 + -1 * b + a ^^^ 2 + a ^^^ 2 * b) /" ^
1022 "(-1 + -1 * a + b ^^^ 2 + a * b ^^^ 2)"))
1024 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1025 if term2str t = "(1 + -1 * a) / (1 + -1 * b)" then ()
1026 else error "rational.sml MG tests 3e";
1029 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
1030 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
1031 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
1032 (*SRA Schalk I, p.67 Nr. 403a *)
1033 val t = str2term "4/x - 3/y - 1";
1034 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1035 if term2str t = "(-3 * x + 4 * y + -1 * x * y) / (x * y)"
1036 then () else error "rational.sml: diff.behav. in norm_Rational_mg 12";
1038 val t = str2term "(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a^^^2+3*b*c)/(a*b*c)";
1039 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1040 if term2str t = "4 / c"
1041 then () else error "rational.sml: diff.behav. in norm_Rational_mg 13";
1043 (*SRA Schalk I, p.67 Nr. 410b *)
1044 val t = str2term "1/(x+1) + 1/(x+2) - 2/(x+3)";
1045 (* WN130911 non-termination due to non-termination of
1046 cancel_p_ thy (str2term "(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)")
1048 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1049 if term2str t = "(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)"
1050 then () else error "rational.sml: diff.behav. in norm_Rational_mg 14";
1053 (*SRA Schalk I, p.67 Nr. 413b *)
1054 val t = str2term "(1 + x)/(1 - x) - (1 - x)/(1 + x) + 2*x/(1 - x^^^2)";
1055 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1056 if term2str t = "6 * x / (1 + -1 * x ^^^ 2)"
1057 then () else error "rational.sml: diff.behav. in norm_Rational_mg 15";
1059 (*SRA Schalk I, p.68 Nr. 414a *)
1060 val t = str2term "(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))";
1061 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1062 if term2str t ="(-2 + -5 * x + 2 * x ^^^ 2) / (2 + -3 * x + x ^^^ 2)"
1063 then () else error "rational.sml: diff.behav. in norm_Rational_mg 16";
1065 (*SRA Schalk I, p.68 Nr. 428b *)
1067 "1/(a - b)^^^2 + 1/(a + b)^^^2 - 2/(a^^^2 - b^^^2) - 4*(b^^^2 - 1)/(a^^^2 - b^^^2)^^^2";
1068 (* WN130911 non-termination due to non-termination of
1069 cancel_p_ thy (str2term "(4 + -4 * b ^^^ 2) / (a ^^^ 4 + -2 * (a ^^^ 2 * b ^^^ 2) + b ^^^ 4)")
1071 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1072 if term2str t = "4 / (a ^^^ 4 + -2 * a ^^^ 2 * b ^^^ 2 + b ^^^ 4)"
1073 then () else error "rational.sml: diff.behav. in norm_Rational_mg 18";
1076 (*SRA Schalk I, p.68 Nr. 430b *)
1078 "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";
1079 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1080 if term2str t = "a + 3 * b"
1081 then () else error "rational.sml: diff.behav. in norm_Rational_mg 19";
1083 (*SRA Schalk I, p.68 Nr. 432 *)
1085 ("(a^^^2 + a*b) / (a^^^2 - b^^^2) - (b^^^2 - a*b) / (b^^^2 - a^^^2) + " ^
1086 "a^^^2*(a - b) / (a^^^3 - a^^^2*b) - 2*a*(a^^^2 - b^^^2) / (a^^^3 - a*b^^^2) - " ^
1087 "2*b^^^2 / (a^^^2 - b^^^2)");
1088 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1091 then () else error "rational.sml: diff.behav. in norm_Rational_mg 20";
1094 val t = str2term "3*a / (a*b) + x/y";
1095 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1096 if term2str t = "(3 * y + b * x) / (b * y)"
1097 then () else error "rational.sml: diff.behav. in norm_Rational_mg 21";
1099 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1100 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1101 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1102 (*------- SRM Schalk I, p.68 Nr. 436a *)
1103 val t = str2term "3*(x+y) / (15*(x - y)) * 25*(x - y)^^^2 / (18*(x + y)^^^2)";
1104 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1105 if term2str t = "(-5 * x + 5 * y) / (-18 * x + -18 * y)"
1106 then () else error "rational.sml: diff.behav. in norm_Rational_mg 22";
1108 (*------- SRM.test Schalk I, p.68 Nr. 436b *)
1109 val t = str2term "5*a*(a - b)^^^2*(a + b)^^^3/(7*b*(a - b)^^^3) * 7*b/(a + b)^^^3";
1110 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1111 if term2str t = "5 * a / (a + -1 * b)"
1112 then () else error "rational.sml: diff.behav. in norm_Rational_mg 23";
1114 (*------- Schalk I, p.68 Nr. 437a *)
1115 val t = str2term "(3*a - 4*b) / (4*c+3*e) * (3*a+4*b)/(9*a^^^2 - 16*b^^^2)";
1116 (* raises an exception for unclear reasons:
1117 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1119 ### rls: cancel_p on: (9 * a ^^^ 2 + -16 * b ^^^ 2) / (4 * c + 3 * e) /
1120 (9 * a ^^^ 2 + -16 * b ^^^ 2)
1121 exception Div raised
1125 ("(9 * a ^^^ 2 + -16 * b ^^^ 2) / (4 * c + 3 * e) /" ^
1126 "(9 * a ^^^ 2 + -16 * b ^^^ 2)");
1127 NONE = cancel_p_ thy t;
1129 if term2str t = "1 / (4 * c + 3 * e)" then ()
1130 else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1133 "----- S.K. corrected non-termination 060904";
1134 val t = str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a^^^2 - 16*b^^^2))";
1135 val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
1137 "(9 * a ^^^ 2 + -16 * b ^^^ 2) /\n(36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c +\n -48 * b ^^^ 2 * e)"
1138 (*"(9 * a ^^^ 2 + -16 * b ^^^ 2) / (36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c + -48 * b ^^^ 2 * e)"*)
1139 then () else error "rational.sml: S.K.8..corrected 060904-6";
1141 "----- S.K. corrected non-termination of cancel_p_";
1142 val t'' = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
1143 "(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
1144 val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
1145 if term2str t' = "1 / (4 * c + 3 * e)"
1146 then () else error "rational.sml: diff.behav. in cancel_p S.K.8";
1148 (*------- Schalk I, p.68 Nr. 437b*)
1149 val t = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
1150 (*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1152 #### rls: cancel_p on: (a * x ^^^ 2 + -2 * (a * (x * y)) + a * y ^^^ 2 + b * x ^^^ 2 +
1153 -2 * (b * (x * y)) +
1155 (a ^^^ 2 * x ^^^ 2 + -1 * (a ^^^ 2 * y ^^^ 2) + -1 * (b ^^^ 2 * x ^^^ 2) +
1157 exception Div raised
1160 (*------- SRM Schalk I, p.68 Nr. 438a *)
1161 val t = str2term "x*y / (x*y - y^^^2) * (x^^^2 - x*y)";
1162 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1163 if term2str t = "x ^^^ 2"
1164 then () else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1166 (*------- SRM Schalk I, p.68 Nr. 439b *)
1167 val t = str2term "(4*x^^^2 + 4*x + 1) * ((x^^^2 - 2*x^^^3) / (4*x^^^2 + 2*x))";
1168 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1169 if term2str t = "(x + -4 * x ^^^ 3) / 2"
1170 then () else error "rational.sml: diff.behav. in norm_Rational_mg 25";
1172 (*------- SRM Schalk I, p.68 Nr. 440a *)
1173 val t = str2term "(x^^^2 - 2*x) / (x^^^2 - 3*x) * (x - 3)^^^2 / (x^^^2 - 4)";
1174 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1175 if term2str t = "(-3 + x) / (2 + x)"
1176 then () else error "rational.sml: diff.behav. in norm_Rational_mg 26";
1178 "----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
1179 val t = str2term "(a^^^3 - 9*a) / (a^^^3*b - a*b^^^3) * (a^^^2*b + a*b^^^2) / (a+3)";
1180 (* WN130911 non-termination for unclear reasons:
1181 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1183 ... ENDS WITH THIS TRACE:
1185 ### rls: cancel_p on: (-9 * (a ^^^ 3 * b) + -9 * (a ^^^ 2 * b ^^^ 2) + a ^^^ 5 * b +
1186 a ^^^ 4 * b ^^^ 2) /
1187 (a ^^^ 3 * b + -1 * (a * b ^^^ 3)) /
1189 BUT THIS IS CORRECTLY RECOGNISED
1191 ("(-9 * (a^^^3 * b) + -9 * (a^^^2 * b^^^2) + a^^^5 * b + a^^^4 * b^^^2) /" ^
1192 "(a^^^3 * b + -1 * (a * b^^^3)) / (3 + (a::real))");
1194 NONE = cancel_p_ thy t;
1196 if term2str t = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
1197 else error "rational.sml: diff.behav. in norm_Rational 27";
1200 "----- SK12 works since 0707xx";
1201 val t = str2term "(a^^^3 - 9*a) * (a^^^2*b+a*b^^^2) / ((a^^^3*b - a*b^^^3) * (a+3))";
1202 (* WN130911 non-termination due to non-termination of
1203 cancel_p_ thy (str2term "(4 + -4 * b ^^^ 2) / (a ^^^ 4 + -2 * (a ^^^ 2 * b ^^^ 2) + b ^^^ 4)")
1205 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1206 if term2str t' = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
1207 else error "rational.sml: diff.behav. in norm_Rational 28";
1210 "-------- examples common denominator and multiplication from: Schalk --------";
1211 "-------- examples common denominator and multiplication from: Schalk --------";
1212 "-------- examples common denominator and multiplication from: Schalk --------";
1213 (*------- SRAM Schalk I, p.69 Nr. 441b *)
1214 val t = str2term "(4*a/3 + 3*b^^^2/a^^^3 + b/(4*a))*(4*b/(3*a))";
1215 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1216 if term2str t = "(36 * b ^^^ 3 + 3 * a ^^^ 2 * b ^^^ 2 + 16 * a ^^^ 4 * b) / (9 * a ^^^ 4)"
1217 then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
1219 (*------- SRAM Schalk I, p.69 Nr. 442b *)
1220 val t = str2term ("(15*a^^^2/x^^^3 - 5*b^^^4/x^^^2 + 25*c^^^2/x) * " ^
1221 "(x^^^3/(5*a*b^^^3*c^^^3)) + 1/c^^^3 * (b*x/a - 3*a/b^^^3)");
1222 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1223 if term2str t = "5 * x ^^^ 2 / (a * b ^^^ 3 * c)"
1224 then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
1226 (*------- SRAM Schalk I, p.69 Nr. 443b *)
1227 val t = str2term "(a/2 + b/3) * (b/3 - a/2)";
1228 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1229 if term2str t = "(-9 * a ^^^ 2 + 4 * b ^^^ 2) / 36"
1230 then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
1232 (*------- SRAM Schalk I, p.69 Nr. 445b *)
1233 val t = str2term "(a^^^2/9 + 2*a/(3*b) + 4/b^^^2)*(a/3 - 2/b) + 8/b^^^3";
1234 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1235 if term2str t = "a ^^^ 3 / 27"
1236 then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
1238 (*------- SRAM Schalk I, p.69 Nr. 446b *)
1239 val t = str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x^^^2 - 16*y^^^2)";
1240 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1241 if term2str t = "30 * x ^^^ 2 + -9 * x * y + -20 * y ^^^ 2"
1242 then () else error "rational.sml: diff.behav. in norm_Rational_mg 32";
1244 (*------- SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
1246 "(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)";
1247 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1248 if term2str t = "(-81 * x ^^^ 4 + 16 * x ^^^ 8 * y ^^^ 4) / (81 * y ^^^ 8)"
1249 then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
1251 (*------- SRAM Schalk I, p.69 Nr. 450a *)
1253 "(4*x/(3*y)+2*y/(3*x))^^^2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
1254 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1255 if term2str t = "(52 * x ^^^ 2 + 16 * y ^^^ 2) / (9 * y ^^^ 2)"
1256 then () else error "rational.sml: diff.behav. in norm_Rational_mg 34";
1258 (*------- SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*)
1260 ("(15*a^^^4/(a*x^^^3) - 5*a*((b^^^4 - 5*c^^^2*x) / x^^^2)) * " ^
1261 "(x^^^3/(5*a*b^^^3*c^^^3)) + a/c^^^3 * (x*(b/a) - 3*b*(a/b^^^4))");
1262 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1263 if term2str t = "5 * x ^^^ 2 / (b ^^^ 3 * c)"
1264 then () else error "rational.sml: diff.behav. in norm_Rational_mg 53";
1267 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1268 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1269 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1270 "----- SRD Schalk I, p.69 Nr. 454b";
1271 val t = str2term "((2 - x)/(2*a)) / (2*a/(x - 2))";
1272 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1273 if term2str t = "(-4 + 4 * x + -1 * x ^^^ 2) / (4 * a ^^^ 2)"
1274 then () else error "rational.sml: diff.behav. in norm_Rational_mg 35";
1276 "----- SRD Schalk I, p.69 Nr. 455a";
1277 val t = str2term "(a^^^2 + 1)/(a^^^2 - 1) / ((a+1)/(a - 1))";
1278 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1279 if term2str t = "(1 + a ^^^ 2) / (1 + 2 * a + a ^^^ 2)" then ()
1280 else error "rational.sml: diff.behav. in norm_Rational_mg 36";
1282 "----- Schalk I, p.69 Nr. 455b";
1283 val t = str2term "(x^^^2 - 4)/(y^^^2 - 9)/((2+x)/(3 - y))";
1284 (* WN130911 non-termination due to non-termination of
1285 cancel_p_ thy (str2term ("(-12 + 4 * y + 3 * x ^^^ 2 + -1 * (x ^^^ 2 * y)) /" ^
1286 "(-18 + -9 * x + 2 * y ^^^ 2 + x * y ^^^ 2)"))
1288 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1289 if term2str t = "(2 + -1 * x) / (3 + y)" then ()
1290 else error "rational.sml: diff.behav. in norm_Rational_mg 37";
1293 "----- SK060904-1a non-termination of cancel_p_ ?: worked before 0707xx";
1294 val t = str2term "(x^^^2 - 4)*(3 - y) / ((y^^^2 - 9)*(2+x))";
1295 (* WN130911 non-termination due to non-termination of
1296 cancel_p_ thy (str2term ("(-12 + 4 * y + 3 * x ^^^ 2 + -1 * (x ^^^ 2 * y)) /" ^
1297 "(-18 + -9 * x + 2 * y ^^^ 2 + x * y ^^^ 2)"))
1299 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1300 if term2str t = "(2 + -1 * x) / (3 + y)" then ()
1301 else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
1304 "----- ?: worked before 0707xx";
1305 val t = str2term "(3 + -1 * y) / (-9 + y ^^^ 2)";
1306 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1307 if term2str t = "-1 / (3 + y)"
1308 then () else error "rational.sml: -1 / (3 + y) norm_Rational";
1310 "----- SRD Schalk I, p.69 Nr. 456b";
1311 val t = str2term "(b^^^3 - b^^^2) / (b^^^2+b) / (b^^^2 - 1)";
1312 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1313 if term2str t = "b / (1 + 2 * b + b ^^^ 2)"
1314 then () else error "rational.sml: diff.behav. in norm_Rational_mg 38";
1316 "----- SRD Schalk I, p.69 Nr. 457b";
1317 val t = str2term "(16*a^^^2 - 9*b^^^2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a^^^2 - 9*a^^^2*b^^^2))";
1318 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1319 if term2str t = "8 * a ^^^ 2 + -6 * a * b + -12 * a ^^^ 2 * b + 9 * a * b ^^^ 2"
1320 then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
1322 "----- Schalk I, p.69 Nr. 458b works since 0707";
1323 val t = str2term "(2*a^^^2*x - a^^^2) / (a*x - b*x) / (b^^^2*(2*x - 1) / (x*(a - b)))";
1324 (*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1326 ### rls: cancel_p on: (-1 * a ^^^ 2 + 2 * (a ^^^ 2 * x)) / (a * x + -1 * (b * x)) /
1327 ((-1 * b ^^^ 2 + 2 * (b ^^^ 2 * x)) / (a * x + -1 * (b * x)))
1328 exception Div raised
1332 ("(-1 * a ^^^ 2 + 2 * (a ^^^ 2 * x)) / (a * x + -1 * (b * x)) /" ^
1333 "((-1 * b ^^^ 2 + 2 * (b ^^^ 2 * x)) / (a * x + -1 * (b * x)))");
1334 NONE = cancel_p_ thy t;
1336 if term2str t = "a ^^^ 2 / b ^^^ 2" then ()
1337 else error "rational.sml: diff.behav. in norm_Rational_mg 39b";
1340 "----- SRD Schalk I, p.69 Nr. 459b";
1341 val t = str2term "(a^^^2 - b^^^2)/(a*b) / (4*(a+b)^^^2/a)";
1342 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1343 if term2str t = "(a + -1 * b) / (4 * a * b + 4 * b ^^^ 2)" then ()
1344 else error "rational.sml: diff.behav. in norm_Rational_mg 41";
1346 "----- Schalk I, p.69 Nr. 460b nonterm.SK";
1347 val t = str2term "(9*(x^^^2 - 8*x + 16) / (4*(y^^^2 - 2*y + 1))) / ((3*x - 12) / (16*y - 16))";
1348 (*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1349 exception Div raised
1353 ("(144 + -72 * x + 9 * x ^^^ 2) / (4 + -8 * y + 4 * y ^^^ 2) /" ^
1354 "((-12 + 3 * x) / (-16 + 16 * y))");
1355 NONE = cancel_p_ thy t;
1357 if term2str t = !!!!!!!!!!!!!!!!!!!!!!!!!
1358 then () else error "rational.sml: diff.behav. in norm_Rational_mg 42";
1361 "----- some variant of the above; was non-terminating before";
1362 val t = str2term "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
1363 val SOME (t , _) = rewrite_set_ thy false norm_Rational t;
1364 if term2str t = "(48 + -12 * x) / (1 + -1 * y)"
1365 then () else error "some variant of the above; was non-terminating before";
1367 "----- SRD Schalk I, p.70 Nr. 472a";
1368 val t = str2term ("((8*x^^^2 - 32*y^^^2) / (2*x + 4*y)) / ((4*x - 8*y) / (x + y))");
1369 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1370 if term2str t = "x + y"
1371 then () else error "rational.sml: diff.behav. in norm_Rational_mg 43";
1373 "----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
1374 val t = str2term ("(a - (a*b + b^^^2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
1375 "((a - a^^^2/(a+b))/(a+(a*b)/(a - b)))");
1376 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1377 if term2str t = "(2 * a ^^^ 3 + 2 * a ^^^ 2 * b) / (a ^^^ 2 * b + b ^^^ 3)"
1378 then () else error "rational.sml: diff.behav. in norm_Rational_mg 51";
1380 (*SRD Schalk I, p.69 Nr. 461a *)
1381 val t = str2term "(2/(x+3) + 2/(x - 3)) / (8*x/(x^^^2 - 9))";
1382 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1383 if term2str t = "1 / 2"
1384 then () else error "rational.sml: diff.behav. in norm_Rational_mg 44";
1386 (*SRD Schalk I, p.69 Nr. 464b *)
1387 val t = str2term "(a - a/(a - 2)) / (a + a/(a - 2))";
1388 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1389 if term2str t = "(-3 + a) / (-1 + a)"
1390 then () else error "rational.sml: diff.behav. in norm_Rational_mg 45";
1392 (*SRD Schalk I, p.69 Nr. 465b *)
1393 val t = str2term "((x+3*y)/9 + (4*y^^^2 - 9*z^^^2)/(16*x)) / (x/9 + y/6 + z/4)";
1394 (* WN130911 non-termination due to non-termination of
1395 cancel_p_ thy (str2term
1396 ("("(576 * x ^^^ 2 + 1728 * (x * y) + 1296 * y ^^^ 2 + -2916 * z ^^^ 2) /" ^
1397 "(576 * x ^^^ 2 + 864 * (x * y) + 1296 * (x * z))"))
1399 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1400 if term2str t = "(4 * x + 6 * y + -9 * z) / (4 * x)"
1401 then () else error "rational.sml: diff.behav. in norm_Rational_mg 46";
1404 (*SRD Schalk I, p.69 Nr. 466b *)
1405 val t = str2term "((1 - 7*(x - 2)/(x^^^2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x^^^2 - 25))";
1406 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1407 if term2str t = "(25 + -10 * x + x ^^^ 2) / 18"
1408 then () else error "rational.sml: diff.behav. in norm_Rational_mg 47";
1410 (*SRD Schalk I, p.70 Nr. 469 *)
1411 val t = str2term ("3*b^^^2 / (4*a^^^2 - 8*a*b + 4*b^^^2) / " ^
1412 "(a / (a^^^2*b - b^^^3) + (a - b) / (4*a*b^^^2 + 4*b^^^3) - 1 / (4*b^^^2))");
1413 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1414 if term2str t = "-3 * b ^^^ 3 / (-2 * a + 2 * b)"
1415 then () else error "rational.sml: diff.behav. in norm_Rational_mg 48";
1417 "-------- me Schalk I No.186 -------------------------------------------------";
1418 "-------- me Schalk I No.186 -------------------------------------------------";
1419 "-------- me Schalk I No.186 -------------------------------------------------";
1420 val fmz = ["Term ((14 * x * y) / ( x * y ))", "normalform N"];
1422 ("Rational",["rational","simplification"],
1423 ["simplification","of_rationals"]);
1424 val p = e_pos'; val c = [];
1425 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
1426 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1427 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1428 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1429 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1430 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1431 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1432 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1433 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1434 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1435 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1436 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1437 case (f2str f, nxt) of
1438 ("14", ("End_Proof'", _)) => ()
1439 | _ => error "rational.sml diff.behav. in me Schalk I No.186";
1441 "-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
1442 "-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
1443 "-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
1445 CalcTree [(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"],
1446 ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1449 autoCalculate 1 CompleteCalc;
1450 val ((pt, p), _) = get_calc 1;
1454 (([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))),
1455 (([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1456 (([1], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))),
1457 (([2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (-2 + x))),
1458 (([3], Res), (2 + -1 * x) * (-2 + x) / (2 * a * (2 * a))),
1459 (([4], Res), (-4 + 4 * x + -1 * x ^^^ 2) / (4 * a ^^^ 2)),
1460 (([], Res), (-4 + 4 * x + -1 * x ^^^ 2) / (4 * a ^^^ 2))]
1462 interSteps 1 ([1], Res);
1463 val ((pt, p), _) = get_calc 1;
1466 (([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))),
1467 (([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1468 (([1,1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1469 (([1,1], Res), (2 - x) / (2 * a) / (2 * a / (x + -1 * 2))),
1470 (([1,2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))),
1471 (([1], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))),
1472 (([2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (-2 + x))),
1473 (([3], Res), (2 + -1 * x) * (-2 + x) / (2 * a * (2 * a))),
1474 (([4], Res), (-4 + 4 * x + -1 * x ^^^ 2) / (4 * a ^^^ 2)),
1475 (([], Res), (-4 + 4 * x + -1 * x ^^^ 2) / (4 * a ^^^ 2))]
1477 val (t, asm) = get_obj g_result pt [1, 1];
1478 if term2str t = "(2 - x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso terms2str asm = "[]"
1479 then () else error "2nd interSteps ..Simp_Rat_Double_No-1 changed on [1, 1]";
1480 val (t, asm) = get_obj g_result pt [1, 2];
1481 if term2str t = "(2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso terms2str asm = "[]"
1482 then () else error "3rd interSteps ..Simp_Rat_Double_No-1 changed on [1, 2]";
1485 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
1486 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
1487 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
1489 CalcTree [(["Term ((a^2 + -1*b^2) / (a^2 + -2*a*b + b^2))", "normalform N"],
1490 ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1493 autoCalculate 1 CompleteCalc;
1494 val ((pt, p), _) = get_calc 1;
1497 (([], Frm), Simplify ((a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * a * b + b ^^^ 2))),
1498 (([1], Frm), (a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * a * b + b ^^^ 2)),
1499 (([1], Res), (a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * (a * b) + b ^^^ 2)),
1500 (([2], Res), (a + b) / (a + -1 * b)),
1501 (([], Res), (a + b) / (a + -1 * b))]
1503 interSteps 1 ([2], Res);
1504 val ((pt, p), _) = get_calc 1;
1507 (([], Frm), Simplify ((a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * a * b + b ^^^ 2))),
1508 (([1], Frm), (a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * a * b + b ^^^ 2)),
1509 (([1], Res), (a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * (a * b) + b ^^^ 2)),
1510 (([2,1], Frm), (a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * (a * b) + b ^^^ 2)),
1511 (([2,1], Res), (a + b) / (a + -1 * b)),
1512 (([2], Res), (a + b) / (a + -1 * b)),
1513 (([], Res), (a + b) / (a + -1 * b))]
1515 interSteps 1 ([2,1],Res);
1516 val ((pt, p), _) = get_calc 1;
1519 (([], Frm), Simplify ((a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * a * b + b ^^^ 2))),
1520 (([1], Frm), (a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * a * b + b ^^^ 2)),
1521 (([1], Res), (a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * (a * b) + b ^^^ 2)),
1522 (([2,1], Frm), (a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * (a * b) + b ^^^ 2)),
1523 (([2,1,1], Frm), (a ^^^ 2 + -1 * b ^^^ 2) / (a ^^^ 2 + -2 * (a * b) + b ^^^ 2)),
1524 (([2,1,1], Res), (a ^^^ 2 + -1 * (a * b) + a * b + -1 * b ^^^ 2) /
1525 (a ^^^ 2 + -2 * (a * b) + 1 * b ^^^ 2)),
1526 (([2,1,2], Res), (a ^^^ 2 + -1 * (a * b) + a * b + -1 * b ^^^ 2) /
1527 (a ^^^ 2 + -2 * (a * b) + -1 ^^^ 2 * b ^^^ 2)),
1528 (([2,1,3], Res), (a ^^^ 2 + -1 * (a * b) + a * b + -1 * b ^^^ 2) /
1529 (a ^^^ 2 + -2 * (a * b) + (-1 * b) ^^^ 2)),
1530 (([2,1,4], Res), (a * a + -1 * (a * b) + a * b + -1 * b ^^^ 2) /
1531 (a ^^^ 2 + -2 * (a * b) + (-1 * b) ^^^ 2)),
1532 (([2,1,5], Res), (a * a + -1 * (a * b) + a * b + -1 * (b * b)) /
1533 (a ^^^ 2 + -2 * (a * b) + (-1 * b) ^^^ 2)),
1534 (([2,1,6], Res), (a * a + -1 * (a * b) + a * b + -1 * (b * b)) /
1535 (a ^^^ 2 + -1 * (2 * (a * b)) + (-1 * b) ^^^ 2)),
1536 (([2,1,7], Res), (a * a + a * (-1 * b) + (b * a + b * (-1 * b))) /
1537 (a ^^^ 2 + 2 * (a * (-1 * b)) + (-1 * b) ^^^ 2)),
1538 (([2,1,8], Res), (a * a + a * (-1 * b) + (b * a + b * (-1 * b))) /
1539 (a ^^^ 2 + 2 * a * (-1 * b) + (-1 * b) ^^^ 2)),
1540 (([2,1,9], Res), (a * (a + -1 * b) + (b * a + b * (-1 * b))) /
1541 (a ^^^ 2 + 2 * a * (-1 * b) + (-1 * b) ^^^ 2)),
1542 (([2,1,10], Res), (a * (a + -1 * b) + b * (a + -1 * b)) /
1543 (a ^^^ 2 + 2 * a * (-1 * b) + (-1 * b) ^^^ 2)),
1544 (([2,1,11], Res), (a + b) * (a + -1 * b) / (a ^^^ 2 + 2 * a * (-1 * b) + (-1 * b) ^^^ 2)),
1545 (([2,1,12], Res), (a + b) * (a + -1 * b) / ((a + -1 * b) * (a + -1 * b))),
1546 (([2,1,13], Res), (a + b) / (a + -1 * b)),
1547 (([2,1], Res), (a + b) / (a + -1 * b)),
1548 (([2], Res), (a + b) / (a + -1 * b)),
1549 (([], Res), (a + b) / (a + -1 * b))]
1551 val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*);
1552 if length newnds = 13 then () else error "rational.sml: interSteps cancel_p rev_rew_p";
1554 val p = ([2,1,9],Res);
1556 val (_, tac, _) = pt_extract (pt, p);
1557 case tac of SOME (Rewrite ("sym_distrib_left", _)) => ()
1558 | _ => error "rational.sml: getTactic, sym_real_plus_binom_times1";
1561 "-------- investigate rulesets for cancel_p ----------------------------------";
1562 "-------- investigate rulesets for cancel_p ----------------------------------";
1563 "-------- investigate rulesets for cancel_p ----------------------------------";
1564 val thy = @{theory "Rational"};
1565 val t = str2term "(a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
1566 val tt = str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"(*numerator only*);
1568 "----- with rewrite_set_";
1569 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
1570 if term2str tt'= "a ^^^ 2 + -1 * b ^^^ 2" then () else error "rls chancel_p 1";
1571 val tt = str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*);
1572 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
1573 if term2str tt' = "a ^^^ 2 + -2 * a * b + b ^^^ 2" then () else error "rls chancel_p 2";
1575 "----- with make_deriv; WN1130912 not investigated further, will be discontinued";
1576 val SOME (tt, _) = factout_p_ thy t;
1577 if term2str tt = "(a + b) * (a + -1 * b) / ((a + -1 * b) * (a + -1 * b))"
1578 then () else error "rls chancel_p 3";
1579 term2str tt = "(1 * a + 1 * b) * (1 * a + -1 * b) / ((1 * a + -1 * b) * (1 * a + -1 * b))";
1581 "--- with simpler ruleset";
1582 val {rules, rew_ord= (_, ro), ...} = rep_rls (assoc_rls "rev_rew_p");
1583 val der = make_deriv thy Atools_erls rules ro NONE tt;
1584 if length der = 12 then () else error "WN1130912 rls chancel_p 4";
1585 print_depth 99; writeln (deriv2str der); print_depth 3;
1587 print_depth 99; map (term2str o #1) der; print_depth 3;
1588 "...,(-1 * b ^^^ 2 + a ^^^ 2) / (-2 * (a * b) + a ^^^ 2 + (-1 * b) ^^^ 2) ]";
1589 print_depth 99; map (rule2str o #2) der; print_depth 3;
1590 print_depth 99; map (term2str o #1 o #3) der; print_depth 3;
1592 val der = make_deriv thy Atools_erls rules ro NONE
1593 (str2term "(1 * a + 1 * b) * (1 * a + -1 * b)");
1594 print_depth 99; writeln (deriv2str der); print_depth 3;
1596 val {rules, rew_ord=(_,ro),...} = rep_rls (assoc_rls "rev_rew_p");
1597 val der = make_deriv thy Atools_erls rules ro NONE
1598 (str2term "(1 * a + -1 * b) * (1 * a + -1 * b)");
1599 print_depth 99; writeln (deriv2str der); print_depth 3;
1600 print_depth 99; map (term2str o #1) der; print_depth 3;
1601 (*WN060829 ...postponed*)
1604 "-------- fun eval_get_denominator -------------------------------------------";
1605 "-------- fun eval_get_denominator -------------------------------------------";
1606 "-------- fun eval_get_denominator -------------------------------------------";
1607 val thy = @{theory Isac};
1608 val t = term_of (the (parse thy "get_denominator ((a +x)/b)"));
1609 val SOME (_, t') = eval_get_denominator "" 0 t thy;
1610 if term2str t' = "get_denominator ((a + x) / b) = b"
1611 then () else error "get_denominator ((a + x) / b) = b"
1614 "-------- several errpats in complicated term --------------------------------";
1615 "-------- several errpats in complicated term --------------------------------";
1616 "-------- several errpats in complicated term --------------------------------";
1617 (*WN12xxxx TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one
1618 WN130912: kept this test, although not clear what for*)
1620 CalcTree [(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"],
1621 ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1624 autoCalculate 1 CompleteCalc;
1625 val ((pt, p), _) = get_calc 1;
1628 (([], Frm), Simplify ((5 * b + 25) / (a ^^^ 2 - b ^^^ 2) * (a - b) / (5 * b))),
1629 (([1], Frm), (5 * b + 25) / (a ^^^ 2 - b ^^^ 2) * (a - b) / (5 * b)),
1630 (([1], Res), (5 * b + 25) / (a ^^^ 2 + -1 * b ^^^ 2) * (a + -1 * b) / (5 * b)),
1631 (([2], Res), (5 * b + 25) * (a + -1 * b) / (a ^^^ 2 + -1 * b ^^^ 2) / (5 * b)),
1632 (([3], Res), (25 * a + -25 * b + 5 * (a * b) + -5 * b ^^^ 2) / (a ^^^ 2 + -1 * b ^^^ 2) /
1634 (([4], Res), (25 + 5 * b) / (a + b) / (5 * b)),
1635 (([5], Res), (25 + 5 * b) / ((a + b) * (5 * b))),
1636 (([6], Res), (25 + 5 * b) / (5 * (a * b) + 5 * b ^^^ 2)),
1637 (([7], Res), (5 + b) / (a * b + b ^^^ 2)),
1638 (([], Res), (5 + b) / (a * b + b ^^^ 2))] *)