1 (* Title: tests for rationals
3 Use is subject to license terms.
6 "-----------------------------------------------------------------------------";
7 "-----------------------------------------------------------------------------";
8 "table of contents -----------------------------------------------------------";
9 "-----------------------------------------------------------------------------";
10 "-------- integration lev.1 fun factout_p_ -----------------------------------";
11 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
12 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
13 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
14 "Rfuns-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
15 "Rfuns-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
16 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
17 "Rfuns-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
18 "----------- rewrite_set_ Partial_Fractions norm_Rational --------------------------------------";
19 "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
20 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
21 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
22 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
23 "Rfuns-------- reverse rewrite ----------------------------------------------------";
24 "Rfuns-------- 'reverse-ruleset' cancel_p -----------------------------------------";
25 "-------- investigate rls norm_Rational --------------------------------------";
26 "-------- examples: rls norm_Rational ----------------------------------------";
27 "-------- rational numerals --------------------------------------------------";
28 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
29 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
30 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
31 "-------- examples common denominator and multiplication from: Schalk --------";
32 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
33 "-------- me Schalk I No.186 -------------------------------------------------";
34 "-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
35 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
36 "-------- investigate rulesets for cancel_p ----------------------------------";
37 "-------- fun eval_get_denominator -------------------------------------------";
38 "-------- several errpats in complicated term --------------------------------";
39 "-------- WN1309xx non-terminating rls norm_Rational -------------------------";
40 "-----------------------------------------------------------------------------";
41 "-----------------------------------------------------------------------------";
44 "-------- integration lev.1 fun factout_p_ -----------------------------------";
45 "-------- integration lev.1 fun factout_p_ -----------------------------------";
46 "-------- integration lev.1 fun factout_p_ -----------------------------------";
47 val t = TermC.str2term "(x \<up> 2 + - 1*y \<up> 2) / (x \<up> 2 + - 1*x*y)"
48 val SOME (t', asm) = factout_p_ thy t;
49 if UnparseC.term t' = "(x + y) * (x + - 1 * y) / (x * (x + - 1 * y))"
50 then () else error ("factout_p_ term 1 changed: " ^ UnparseC.term t')
52 if UnparseC.terms asm = "[\"x \<noteq> 0\", \"x + - 1 * y \<noteq> 0\"]"
53 then () else error "factout_p_ asm 1 changed"
55 val t = TermC.str2term "nothing + to_cancel ::real";
56 if NONE = factout_p_ thy t then () else error "factout_p_ doesn't report non-applicable";
58 val t = TermC.str2term "((3 * x \<up> 2 + 6 *x + 3) / (2*x + 2))";
59 val SOME (t', asm) = factout_p_ thy t;
60 if UnparseC.term t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso
61 UnparseC.terms asm = "[\"1 + x \<noteq> 0\"]"
62 then () else error "factout_p_ 1 changed";
64 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
65 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
66 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
67 val t = TermC.str2term "(x \<up> 2 + - 1*y \<up> 2) / (x \<up> 2 + - 1*x*y)"
68 val SOME (t', asm) = cancel_p_ thy t;
69 if (UnparseC.term t', UnparseC.terms asm) = ("(x + y) / x", "[\"x \<noteq> 0\"]")
70 then () else error ("cancel_p_ (t', asm) 1 changed: " ^ UnparseC.term t')
72 val t = TermC.str2term "nothing + to_cancel ::real";
73 if NONE = cancel_p_ thy t then () else error "cancel_p_ doesn't report non-applicable";
75 val t = TermC.str2term "((3 * x \<up> 2 + 6 *x + 3) / (2*x + 2))";
76 val SOME (t', asm) = cancel_p_ thy t;
77 if UnparseC.term t' = "(3 + 3 * x) / 2" andalso UnparseC.terms asm = "[]"
78 then () else error "cancel_p_ 1 changed";
80 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
81 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
82 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
83 val t = TermC.str2term ("y / (a*x + b*x + c*x) " ^
87 val SOME (t', asm) = common_nominator_p_ thy t;
89 ("y * y / (x * ((a + b + c) * y)) " ^
90 (* n1 *d2'/ (c'* ( d1' *d2')) *)
91 "+ a * (a + b + c) / (x * ((a + b + c) * y))")
92 (* n2 * d1' / (c'* ( d1' *d2')) *)
93 then () else error "common_nominator_p_ term 1 changed";
94 if UnparseC.terms asm = "[\"a + b + c \<noteq> 0\", \"y \<noteq> 0\", \"x \<noteq> 0\"]"
95 then () else error "common_nominator_p_ asm 1 changed"
97 "-------- example in mail Nipkow";
98 val t = TermC.str2term "x/(x \<up> 2 + - 1*y \<up> 2) + y/(x \<up> 2 + - 1*x*y)";
99 val SOME (t', asm) = common_nominator_p_ thy t;
100 if UnparseC.term t' =
101 "x * x / ((x + - 1 * y) * ((x + y) * x)) +\ny * (x + y) / ((x + - 1 * y) * ((x + y) * x))"
102 then () else error "common_nominator_p_ term 2 changed"
104 if UnparseC.terms asm = "[\"x + y \<noteq> 0\", \"x \<noteq> 0\", \"x + - 1 * y \<noteq> 0\"]"
105 then () else error "common_nominator_p_ asm 2 changed"
107 "-------- example: applicable tested by SML code";
108 val t = TermC.str2term "nothing / to_add";
109 if NONE = common_nominator_p_ thy t then () else error "common_nominator_p_ term 3 changed";
111 val t = TermC.str2term "((x + (- 1)) / (x + 1)) + ((x + 1) / (x + (- 1)))";
112 val SOME (t', asm) = common_nominator_p_ thy t;
113 if UnparseC.term t' =
114 "(x + - 1) * (- 1 + x) / ((1 + x) * (- 1 + x)) +\n(x + 1) * (1 + x) / ((1 + x) * (- 1 + x))"
115 andalso UnparseC.terms asm = "[\"1 + x \<noteq> 0\", \"- 1 + x \<noteq> 0\"]"
116 then () else error "common_nominator_p_ 3 changed";
118 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
119 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
120 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
121 val t = TermC.str2term "((x + (- 1)) / (x + 1)) + ((x + 1) / (x + (- 1)))";
122 val SOME (t', asm) = add_fraction_p_ thy t;
123 if UnparseC.term t' = "(2 + 2 * x \<up> 2) / (- 1 + x \<up> 2)"
124 then () else error "add_fraction_p_ 3 changed";
126 if UnparseC.terms asm = "[\"- 1 + x \<up> 2 \<noteq> 0\"]"
127 then () else error "add_fraction_p_ 3 changed";
129 val t = TermC.str2term "nothing / to_add";
130 if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ term 3 changed";
132 val t = TermC.str2term "((x + (- 1)) / (x + 1)) + ((x + 1) / (x + (- 1)))";
133 val SOME (t', asm) = add_fraction_p_ thy t;
134 if UnparseC.term t' = "(2 + 2 * x \<up> 2) / (- 1 + x \<up> 2)" andalso
135 UnparseC.terms asm = "[\"- 1 + x \<up> 2 \<noteq> 0\"]"
136 then () else error "add_fraction_p_ 3 changed";
138 "-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
139 "-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
140 "-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
141 (* trace down until prepats are evaluated
142 (which does not to work, because substitution is not done -- compare rew_sub!);
143 keep this sequence for the case, factout_p, cancel_p, common_nominator_p, add_fraction_p
144 (again) get prepat = [] changed to <>[]. *)
145 val t = TermC.str2term "(x \<up> 2 + - 1*y \<up> 2) / (x \<up> 2 + - 1*x*y)";
147 (*rewrite_set_ @{theory Isac_Knowledge} true cancel t = NONE; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
148 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (thy, false, cancel_p, t);
149 "~~~~~ fun rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
150 (thy, 1, bool, [], rls, term);
151 (*val (t', asm, rew) = app_rev thy (i+1) rrls t; rew = false!!!!!!!!!!!!!!!!!!!!!*)
152 "~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
153 fun chk_prepat thy erls [] t = true
154 | chk_prepat thy erls prepat t =
156 fun chk (pres, pat) =
158 val subst: Type.tyenv * Envir.tenv =
159 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
161 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
162 end) handle Pattern.MATCH => false
163 fun scan_ f [] = false (*scan_ NEVER called by []*)
164 | scan_ f (pp::pps) =
165 if f pp then true else scan_ f pps;
166 in scan_ chk prepat end;
167 (* apply the normal_form of a rev-set *)
168 fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
169 if chk_prepat thy erls prepat t
170 then ((*tracing("### app_rev': t = "^UnparseC.term t);*) normal_form t)
172 (* val opt = app_rev' thy rrls t ..NONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
173 "~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
175 (* chk_prepat thy erls prepat t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
176 (* app_sub thy i rrls t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
177 "~~~~~ fun chk_prepat, args:"; val (thy, erls, prepat, t) = (thy, erls, prepat, t);
178 fun chk (pres, pat) =
180 val subst: Type.tyenv * Envir.tenv =
181 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
183 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
184 end) handle Pattern.MATCH => false
185 fun scan_ f [] = false (*scan_ NEVER called by []*)
186 | scan_ f (pp::pps) =
187 if f pp then true else scan_ f pps;
189 (*========== inhibit exn WN130823: prepat is empty ====================================
190 (* scan_ chk prepat = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
191 "~~~~~ fun , args:"; val (f, (pp::pps)) = (chk, prepat);
193 val ([t1, t2], t) = pp;
194 UnparseC.term t1 = "?r is_expanded";
195 UnparseC.term t2 = "?s is_expanded";
196 UnparseC.term t = "?r / ?s";
197 (* f pp = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
198 "~~~~~ fun chk, args:"; val (pres, pat) = (pp);
199 val subst: Type.tyenv * Envir.tenv =
200 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
202 ({}, {(("r", 0), ("real", Var (("r", 0), "real"))),
203 (("s", 0), ("real", Var (("s", 0), "real")))}*)
205 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
206 "~~~~~ fun eval__true, args:"; val (thy, i, asms, bdv, rls) =
207 (thy, (i + 1), (map (Envir.subst_term subst) pres), [], erls);
208 UnparseC.terms asms; (* = "[\"?r is_expanded\",\"?s is_expanded\"]"*)
209 asms = [@{term True}] orelse asms = []; (* = false*)
210 asms = [@{term False}] ; (* = false*)
211 "~~~~~ fun chk, args:"; val (indets, (a::asms)) = ([], asms);
212 bdv (*= []: _a list*);
213 val bdv : (term * term) list = [];
214 rewrite__set_ thy (i+1) false;
215 UnparseC.term a = "?r is_expanded"; (*hier m"usste doch der Numerator eingesetzt sein ??????????????*)
216 val SOME (Const (\<^const_name>\<open>False\<close>, _), []) = rewrite__set_ thy (i+1) false bdv rls a
217 ============ inhibit exn WN130823: prepat is empty ===================================*)
219 "-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
220 "-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
221 "-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
222 val t = TermC.str2term "(12 * x * y) / (8 * y \<up> 2 )";
223 (* "-------- example 187a": exception Div raised...
224 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
225 val t = TermC.str2term "(8 * x \<up> 2 * y * z ) / (18 * x * y \<up> 2 * z )";
226 (* "-------- example 187b": doesn't terminate...
227 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
228 val t = TermC.str2term "(9 * x \<up> 5 * y \<up> 2 * z \<up> 4) / (15 * x \<up> 6 * y \<up> 3 * z )";
229 (* "-------- example 187c": doesn't terminate...
230 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
231 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (@{theory Isac_Knowledge}, false, cancel_p, t);
232 (* WN130827: exception Div raised...
233 rewrite__set_ thy 1 bool [] rls term
235 "~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
236 (thy, 1, bool, [], rls, term);
237 (* WN130827: exception Div raised...
238 val (t', asm, rew) = app_rev thy (i+1) rrls t
240 "~~~~~ fun app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
241 (* WN130827: exception Div raised...
242 val opt = app_rev' thy rrls t
244 "~~~~~ fun app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
246 chk_prepat thy erls prepat t = true;
247 (* WN130827: exception Div raised...
250 (* lookup Rational.thy, cancel_p: normal_form = cancel_p_ thy*)
251 "~~~~~ fun cancel_p_, args:"; val (t) = (t);
252 val opt = check_fraction t;
253 val SOME (numerator, denominator) = opt
254 val vs = TermC.vars_of t
255 val baseT = type_of numerator
256 val expT = HOLogic.realT
257 val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator);
258 (*"-------- example 187a": exception Div raised...
259 val a = [(12, [1, 1])]: poly
260 val b = [(8, [0, 2])]: poly
261 val ((a', b'), c) = gcd_poly a b
263 (* "-------- example 187b": doesn't terminate...
264 val a = [(8, [2, 1, 1])]: poly
265 val b = [(18, [1, 2, 1])]: poly
266 val ((a', b'), c) = gcd_poly a b
268 (* "-------- example 187c": doesn't terminate...
269 val a = [(9, [5, 2, 4])]: poly
270 val b = [(15, [6, 3, 1])]: poly
271 val ((a', b'), c) = gcd_poly a b
274 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
275 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
276 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
277 val t = TermC.str2term "(x \<up> 2 - 4)*(3 - y) / ((y \<up> 2 - 9)*(2+x))";
278 Rewrite.trace_on := false (*true false*);
279 (* trace stops with ...: (and then jEdit hangs)..
280 rewrite_set_ thy false norm_Rational t;
282 ### rls: cancel_p on: (- 12 + 4 * y + 3 * x \<up> 2 + - 1 * (x \<up> 2 * y)) /
283 (- 18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)
285 val t = TermC.str2term (*copy from above: "::real" is not required due to " \<up> "*)
286 ("(- 12 + 4 * y + 3 * x \<up> 2 + - 1 * (x \<up> 2 * y)) /" ^
287 "(- 18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)");
289 exception Div raised*)
291 "~~~~~ fun cancel_p_, args:"; val (t) = (t);
292 val opt = check_fraction t;
293 val SOME (numerator, denominator) = opt
294 val vs = TermC.vars_of t
295 val baseT = type_of numerator
296 val expT = HOLogic.realT;
297 (*default_print_depth 3; 999*)
298 val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator);
299 (*default_print_depth 3; 999*)
300 (* does not terminate instead of returning ?:
301 val ((a', b'), c) = gcd_poly a b
302 val a = [(~12, [0, 0]), (3, [2, 0]), (4, [0, 1]), (~1, [2, 1])]: poly
303 val b = [(~18, [0, 0]), (~9, [1, 0]), (2, [0, 2]), (1, [1, 2])]: poly
306 "-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
307 "-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
308 "-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
309 val thy = @{theory Isac_Knowledge};
310 "----- SK060904- 2a non-termination of add_fraction_p_";
311 val t = TermC.str2term (" (a + b * x) / (a + - 1 * (b * x)) + " ^
312 " (- 1 * a + b * x) / (a + b * x) ");
313 (* rewrite_set_ thy false norm_Rational t
314 exception Div raised*)
315 (* rewrite_set_ thy false add_fractions_p t;
316 exception Div raised*)
317 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) =
318 (@{theory Isac_Knowledge}, false, add_fractions_p, t);
319 "~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
320 (thy, 1, bool, [], rls, term);
321 (* app_rev thy (i+1) rrls t;
322 exception Div raised*)
323 "~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
324 fun chk_prepat thy erls [] t = true
325 | chk_prepat thy erls prepat t =
327 fun chk (pres, pat) =
329 val subst: Type.tyenv * Envir.tenv =
330 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
332 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
333 end) handle Pattern.MATCH => false
334 fun scan_ f [] = false (*scan_ NEVER called by []*)
335 | scan_ f (pp::pps) =
336 if f pp then true else scan_ f pps;
337 in scan_ chk prepat end;
338 (* apply the normal_form of a rev-set *)
339 fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
340 if chk_prepat thy erls prepat t
341 then ((*tracing("### app_rev': t = "^UnparseC.term t);*) normal_form t)
343 (* val opt = app_rev' thy rrls t;
344 exception Div raised*)
345 (* val opt = app_rev' thy rrls t;
346 exception Div raised*)
347 "~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
349 chk_prepat thy erls prepat t = true = true;
351 exception Div raised*)
352 (* lookup Rational.thy, val add_fractions_p: normal_form = add_fraction_p_ thy*)
353 (*add_fraction_p_ thy t
354 exception Div raised*)
355 "~~~~~ fun add_fraction_p_, args:"; val ((_: theory), t) = (thy, t);
356 val SOME ((n1, d1), (n2, d2)) = check_frac_sum t;
357 UnparseC.term n1; UnparseC.term d1; UnparseC.term n2; UnparseC.term d2;
358 val vs = TermC.vars_of t;
359 (*default_print_depth 3; 999*)
360 val (SOME _, SOME a, SOME _, SOME b) =
361 (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2);
362 (*default_print_depth 3; 999*)
364 val a = [(1, [1, 0, 0]), (~1, [0, 1, 1])]: poly
365 val b = [(1, [1, 0, 0]), (1, [0, 1, 1])]: poly
366 val ((a', b'), c) = gcd_poly a b
369 "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
370 "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
371 "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
372 val thy = @{theory Isac_Knowledge(*Partial_Fractions*)}
373 val ctxt = Proof_Context.init_global thy;
375 (*---------- (1) with Free A, B ----------------------------------------------------------------*)
376 val t = (the o (parseNEW ctxt)) "3 = A / 2 + A / 4 + (B / 2 + - 1 * B / (2::real))";
377 (* required for applying thms in rewriting \<up> ^*)
378 (* we get details from here..*)
380 Rewrite.trace_on := false; (*true false*)
381 val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t;
382 Rewrite.trace_on := false; (*true false*)
384 add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + - 1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
385 (* |||||||||||||||||||||||||||||||||||| *)
387 val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 1 GUESS 1 GUESS 1 GUESS 1 *)
388 "A / 2 + A / 4 + (B / 2 + - 1 * B / (2::real))";
389 "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
390 val NONE = (*case*) check_frac_sum t (*of*)
393 add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + - 1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
394 (* |||||||||||||||||||||||||||| *)
395 val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 2 GUESS 2 GUESS 2 GUESS 2 *)
396 "A / 4 + (B / 2 + - 1 * B / (2::real))";
397 "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
398 val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*);
399 (*+*)if (UnparseC.term n1, UnparseC.term d1) = ("A" , "4") andalso
400 (*+*) (UnparseC.term n2, UnparseC.term d2) = ("B / 2 + - 1 * B / 2", "1")
401 (*+*)then () else error "check_frac_sum (A / 4 + (B / 2 + - 1 * B / (2::real))) changed";
403 val vs = TermC.vars_of t;
404 val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) =
405 (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*);
407 "~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1);
408 val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t];
409 (*+*)if xxx = 1 then () else error "monom_of_term changed"
411 "~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Free (id, _))) =
412 (vs, (1, replicate (length vs) 0), t);
413 case vs of [Free ("A", _), Free ("B", _)] =>
414 if c = 1 andalso id = "A"
415 then () else error "monom_of_term Free changed 1"
416 | _ => error "monom_of_term Free changed 2";
418 (*---------- (2) with Const AA, BB --------------------------------------------------------------*)
419 val t = (the o (parseNEW ctxt)) "3 = AA / 2 + AA / 4 + (BB / 2 + - 1 * BB / 2)";
421 (* we get details from here..*)
423 Rewrite.trace_on := false; (*true false*)
424 val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t;
425 Rewrite.trace_on := false; (*true false*)
427 add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + - 1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
428 (* |||||||||||||||||||||||||||||||||||| *)
429 val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *)
430 "AA / 2 + AA / 4 + (BB / 2 + - 1 * BB / 2)";
431 "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
432 val NONE = (*case*) check_frac_sum t (*of*)
435 add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + - 1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
436 (* |||||||||||||||||||||||||||| *)
437 val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *)
438 "AA / 4 + (BB / 2 + - 1 * BB / 2)";
439 "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
440 val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*);
441 (*+*)if (UnparseC.term n1, UnparseC.term d1) = ("AA" , "4") andalso
442 (*+*) (UnparseC.term n2, UnparseC.term d2) = ("BB / 2 + - 1 * BB / 2", "1")
443 (*+*)then () else error "check_frac_sum (AA / 4 + (BB / 2 + - 1 * BB / 2)) changed";
445 val vs = TermC.vars_of t;
446 val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) =
447 (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*);
449 "~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1);
450 val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t];
451 (*+*)if xxx = 1 then () else error "monom_of_term changed"
453 "~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const (id, _))) =
454 (vs, (1, replicate (length vs) 0), t);
455 case vs of [Const (\<^const_name>\<open>AA\<close>, _), Const (\<^const_name>\<open>BB\<close>, _)] =>
456 if c = 1 andalso id = "Partial_Fractions.AA"
457 then () else error "monom_of_term Const changed 1"
458 | _ => error "monom_of_term Const changed 2";
461 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
462 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
463 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
464 val thy = @{theory "Rational"};
466 val t = TermC.str2term "(2 + -3 * x) / 9";
467 if NONE = rewrite_set_ thy false cancel_p t then ()
468 else error "rewrite_set_ cancel_p must return NONE, if the term cannot be cancelled";
470 "-------- example 186a";
471 val t = TermC.str2term "(14 * x * y) / (x * y)";
472 is_expanded (TermC.str2term "14 * x * y");
473 is_expanded (TermC.str2term "x * y");
474 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
475 if (UnparseC.term t', UnparseC.terms asm) = ("14 / 1", "[]")
476 then () else error "rational.sml cancel Schalk 186a";
478 "-------- example 186b";
479 val t = TermC.str2term "(60 * a * b) / ( 15 * a * b )";
480 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
481 if (UnparseC.term t', UnparseC.terms asm) = ("4 / 1", "[]")
482 then () else error "rational.sml cancel Schalk 186b";
484 "-------- example 186c";
485 val t = TermC.str2term "(144 * a \<up> 2 * b * c) / (12 * a * b * c)";
486 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
487 if (UnparseC.term t', UnparseC.terms asm) = ("12 * a / 1", "[]")
488 then () else error "rational.sml cancel Schalk 186c";
490 (* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! exception Div raised !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
491 see --- fun rewrite_set_ downto fun gcd_poly ---
492 "-------- example 187a";
493 val t = TermC.str2term "(12 * x * y) / (8 * y \<up> 2 )";
494 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
495 if (UnparseC.term t', UnparseC.terms asm) = ("3 * x / (2 * y)", "[\"4 * y ~= 0\"]")
496 then () else error "rational.sml cancel Schalk 187a";
499 (* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
500 see --- fun rewrite_set_ downto fun gcd_poly ---
501 "-------- example 187b";
502 val t = TermC.str2term "(8 * x \<up> 2 * y * z ) / (18 * x * y \<up> 2 * z )";
503 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
504 if (UnparseC.term t', UnparseC.terms asm) = ("4 * x / (9 * y)", "[\"2 * (z * (y * x)) ~= 0\"]")
505 then () else error "rational.sml cancel Schalk 187b";
508 (* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
509 see --- fun rewrite_set_ downto fun gcd_poly ---
510 "-------- example 187c";
511 val t = TermC.str2term "(9 * x \<up> 5 * y \<up> 2 * z \<up> 4) / (15 * x \<up> 6 * y \<up> 3 * z )";
512 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
513 if (UnparseC.term t', UnparseC.terms asm) =
514 ("3 * z \<up> 3 / (5 * (y * x))", "[\"3 * (z * (y \<up> 2 * x \<up> 5)) ~= 0\"]")
515 then () else error "rational.sml cancel Schalk 187c";
518 "-------- example 188a";
519 val t = TermC.str2term "(-8 + 8 * x) / (-9 + 9 * x)";
520 is_expanded (TermC.str2term "8 * x + -8");
521 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
522 if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]")
523 then () else error "rational.sml cancel Schalk 188a";
525 val t = TermC.str2term "(8*((- 1) + x))/(9*((- 1) + x))";
526 val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
527 if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]")
528 then () else error "rational.sml cancel Schalk make_polynomial 1";
530 "-------- example 188b";
531 val t = TermC.str2term "(- 15 + 5 * x) / (- 18 + 6 * x)";
532 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
533 if (UnparseC.term t', UnparseC.terms asm) = ("5 / 6", "[]")
534 then () else error "rational.sml cancel Schalk 188b";
536 "-------- example 188c";
537 val t = TermC.str2term "(a + - 1 * b) / (b + - 1 * a)";
538 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
539 if (UnparseC.term t', UnparseC.terms asm) = ("- 1 / 1", "[]")
540 then () else error "rational.sml cancel Schalk 188c";
542 is_expanded (TermC.str2term "a + - 1 * b") = true;
543 val t = TermC.str2term "((- 1)*(b + (- 1) * a))/(1*(b + (- 1) * a))";
544 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
545 if (UnparseC.term t', UnparseC.terms asm) = ("(a + - 1 * b) / (- 1 * a + b)", "[]")
546 then () else error "rational.sml cancel Schalk make_polynomial 2";
548 "-------- example 190a";
549 val t = TermC.str2term "( 27 * a \<up> 3 + 9 * a \<up> 2 + 3 * a + 1 ) / ( 27 * a \<up> 3 + 18 * a \<up> 2 + 3 * a )";
550 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
551 if (UnparseC.term t', UnparseC.terms asm) =
552 ("(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)", "[\"3 * a + 9 * a \<up> 2 \<noteq> 0\"]")
553 then () else error "rational.sml cancel Schalk 190a";
555 "-------- example 190c";
556 val t = TermC.str2term "((1 + 9 * a \<up> 2)*(1 + 3 * a))/((3 * a + 9 * a \<up> 2)*(1 + 3 * a))";
557 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
558 if (UnparseC.term t', UnparseC.terms asm) =
559 ("(1 + 3 * a + 9 * a \<up> 2 + 27 * a \<up> 3) /\n(3 * a + 18 * a \<up> 2 + 27 * a \<up> 3)", "[]")
560 then () else error "rational.sml make_polynomial Schalk 190c";
562 "-------- example 191a";
563 val t = TermC.str2term "( x \<up> 2 + - 1 * y \<up> 2 ) / ( x + y )";
564 is_expanded (TermC.str2term "x \<up> 2 + - 1 * y \<up> 2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
565 is_expanded (TermC.str2term "x + y") = true;
566 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
567 if (UnparseC.term t', UnparseC.terms asm) = ("(x + - 1 * y) / 1", "[]")
568 then () else error "rational.sml make_polynomial Schalk 191a";
570 "-------- example 191b";
571 val t = TermC.str2term "((x + (- 1) * y)*(x + y))/((1)*(x + y))";
572 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
573 if (UnparseC.term t', UnparseC.terms asm) = ("(x \<up> 2 + - 1 * y \<up> 2) / (x + y)", "[]")
574 then () else error "rational.sml make_polynomial Schalk 191b";
576 "-------- example 191c";
577 val t = TermC.str2term "( 9 * x \<up> 2 + -30 * x + 25 ) / ( 9 * x \<up> 2 + - 25 )";
578 is_expanded (TermC.str2term "9 * x \<up> 2 + -30 * x + 25") = true;
579 is_expanded (TermC.str2term "25 + -30*x + 9*x \<up> 2") = true;
580 is_expanded (TermC.str2term "- 25 + 9*x \<up> 2") = true;
582 val t = TermC.str2term "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
583 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
584 if (UnparseC.term t', UnparseC.terms asm) = ("(25 + - 30 * x + 9 * x \<up> 2) / (- 25 + 9 * x \<up> 2)", "[]")
585 then () else error "rational.sml make_polynomial Schalk 191c";
587 "-------- example 192b";
588 val t = TermC.str2term "( 7 * x \<up> 3 + - 1 * x \<up> 2 * y ) / ( 7 * x * y \<up> 2 + - 1 * y \<up> 3 )";
589 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
590 if (UnparseC.term t', UnparseC.terms asm) = ("x \<up> 2 / y \<up> 2", "[\"y \<up> 2 \<noteq> 0\"]")
591 then () else error "rational.sml cancel_p Schalk 192b";
593 val t = TermC.str2term "((x \<up> 2)*(7 * x + (- 1) * y))/((y \<up> 2)*(7 * x + (- 1) * y))";
594 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
595 if (UnparseC.term t', UnparseC.terms asm) =
596 ("(7 * x \<up> 3 + - 1 * x \<up> 2 * y) /\n(7 * x * y \<up> 2 + - 1 * y \<up> 3)", "[]")
597 then () else error "rational.sml make_polynomial Schalk 192b";
599 val t = TermC.str2term "((x \<up> 2)*(7 * x + (- 1) * y))/((y \<up> 2)*(7 * x + (- 1) * y))";
600 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
601 if (UnparseC.term t', UnparseC.terms asm) =
602 ("(7 * x \<up> 3 + - 1 * x \<up> 2 * y) /\n(7 * x * y \<up> 2 + - 1 * y \<up> 3)", "[]")
603 then () else error "rational.sml make_polynomial Schalk WN050929 not working";
605 "-------- example 193a";
606 val t = TermC.str2term "( x \<up> 2 + -6 * x + 9 ) / ( x \<up> 2 + -9 )";
607 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
608 if (UnparseC.term t', UnparseC.terms asm) = ("(- 3 + x) / (3 + x)", "[\"3 + x \<noteq> 0\"]")
609 then () else error "rational.sml cancel_p Schalk 193a";
611 "-------- example 193b";
612 val t = TermC.str2term "( x \<up> 2 + -8 * x + 16 ) / ( 2 * x \<up> 2 + -32 )";
613 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
614 if (UnparseC.term t', UnparseC.terms asm) = ("(- 4 + x) / (8 + 2 * x)", "[\"8 + 2 * x \<noteq> 0\"]")
615 then () else error "rational.sml cancel_p Schalk 193b";
617 "-------- example 193c";
618 val t = TermC.str2term "( 2 * x + -50 * x \<up> 3 ) / ( 25 * x \<up> 2 + - 10 * x + 1 )";
619 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
620 if (UnparseC.term t', UnparseC.terms asm) =
621 ("(2 * x + 10 * x \<up> 2) / (1 + - 5 * x)", "[\"1 + - 5 * x \<noteq> 0\"]")
622 then () else error "rational.sml cancel_p Schalk 193c";
624 (*WN: improved with new numerals*)
625 val t = TermC.str2term "(- 25 + 9*x \<up> 2)/(5 + 3*x)";
626 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
627 if (UnparseC.term t', UnparseC.terms asm) = ("(- 5 + 3 * x) / 1", "[]")
628 then () else error "rational.sml cancel WN 1";
630 "-------- example heuberger";
631 val t = TermC.str2term ("(x \<up> 4 + x * y + x \<up> 3 * y + y \<up> 2) / " ^
632 "(x + 5 * x \<up> 2 + y + 5 * x * y + x \<up> 2 * y \<up> 3 + x * y \<up> 4)");
633 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
634 if (UnparseC.term t', UnparseC.terms asm) =
635 ("(x \<up> 3 + y) / (1 + 5 * x + x * y \<up> 3)", "[\"1 + 5 * x + x * y \<up> 3 \<noteq> 0\"]")
636 then () else error "rational.sml cancel_p heuberger";
638 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
639 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
640 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
641 (*deleted example 204 ... 236b at update Isabelle2012-->2013*)
643 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
644 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
645 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
646 val t = TermC.str2term ("123 = (a*x)/(b*x) + (c*x)/(d*x) + (e*x)/(f*x::real)");
647 "-------- gcd_poly integration level 1: works on exact term";
648 if NONE = cancel_p_ thy t then () else error "cancel_p_ works on exact fraction";
649 if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ works on exact fraction";
651 "-------- gcd_poly integration level 2: picks out ONE appropriate subterm";
652 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
653 if UnparseC.term t' = "123 = a * x / (b * x) + c * x / (d * x) + e / f"
654 then () else error "level 2, rewrite_set_ cancel_p: changed";
655 val SOME (t', asm) = rewrite_set_ thy false add_fractions_p t;
656 if UnparseC.term t' = "123 = (b * c * x + a * d * x) / (b * d * x) + e * x / (f * x)"
657 then () else error "level 2, rewrite_set_ add_fractions_p: changed";
659 "-------- gcd_poly integration level 3: rewrites all appropriate subterms";
660 val SOME (t', asm) = rewrite_set_ thy false cancel_p_rls t;
661 if UnparseC.term t' = "123 = a / b + c / d + e / f"
662 then () else error "level 3, rewrite_set_ cancel_p_rls: changed";
663 val SOME (t', asm) = rewrite_set_ thy false add_fractions_p_rls t; (*CREATE add_fractions_p_rls*)
664 if UnparseC.term t' = "123 = (b * d * e * x + b * c * f * x + a * d * f * x) / (b * d * f * x)"
665 then () else error "level 3, rewrite_set_ add_fractions_p_rls: changed";
667 "-------- gcd_poly integration level 4: iteration cancel_p -- add_fraction_p";
668 (* simpler variant *)
669 val testrls = Rule_Set.append_rules "testrls" Rule_Set.empty [Rls_ cancel_p, Rls_ add_fractions_p]
670 val SOME (t', asm) = rewrite_set_ thy false testrls t;
671 (*Rewrite.trace_on := false; (*true false*)
672 # rls: testrls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
673 ## rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
674 ## rls: add_fractions_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f
675 ## rls: cancel_p on: 123 = (b * c * x + a * d * x) / (b * d * x) + e / f
676 ## rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f
677 ## rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
678 ## rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
679 if UnparseC.term t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
680 then () else error "level 4, rewrite_set_ *_p: changed";
682 (* complicated variant *)
683 val testrls_rls = Rule_Set.append_rules "testrls_rls" Rule_Set.empty [Rls_ cancel_p_rls, Rls_ add_fractions_p_rls];
684 val SOME (t', asm) = rewrite_set_ thy false testrls_rls t;
685 (*# rls: testrls_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
686 ## rls: cancel_p_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
687 ### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
688 ### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f
689 ### rls: cancel_p on: 123 = a * x / (b * x) + c / d + e / f
690 ### rls: cancel_p on: 123 = a / b + c / d + e / f
691 ## rls: add_fractions_p_rls on: 123 = a / b + c / d + e / f
692 ### rls: add_fractions_p on: 123 = a / b + c / d + e / f
693 ### rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f
694 ### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
695 ## rls: cancel_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
696 ### rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
697 ## rls: add_fractions_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
698 ### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
699 if UnparseC.term t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
700 then () else error "level 4, rewrite_set_ *_p_rls: changed"
702 "-------- gcd_poly integration level 5: cancel_p & add_fraction_p within norm_Rational";
703 val SOME (t', asm) = rewrite_set_ thy false norm_Rational t;
704 if UnparseC.term t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)"
705 then () else error "level 5, rewrite_set_ norm_Rational: changed"
707 "-------- reverse rewrite ----------------------------------------------------";
708 "-------- reverse rewrite ----------------------------------------------------";
709 "-------- reverse rewrite ----------------------------------------------------";
710 (** the term for which reverse rewriting is demonstrated **)
711 val t = TermC.str2term "(9 + - 1 * x \<up> 2) / (9 + 6 * x + x \<up> 2)";
712 val Rrls {scr = Rfuns {init_state = ini, locate_rule = loc,
713 next_rule = nex, normal_form = nor, ...},...} = cancel_p;
715 (** normal_form produces the result in ONE step **)
716 val SOME (t', _) = nor t;
717 if UnparseC.term t' = "(3 + - 1 * x) / (3 + x)" then ()
718 else error "rational.sml normal_form (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
720 (** initialize the interpreter state used by the 'me' **)
721 val (t, _, revsets, _) = ini t;
723 if length (hd revsets) = 11 then () else error "length of revset changed";
724 (*//----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)
725 if (revsets |> nth 1 |> nth 1 |> id_of_thm) =
726 (@{thm realpow_twoI} |> Thm.get_name_hint |> ThmC.cut_id)
727 then () else error "first element of revset changed";
729 (revsets |> nth 1 |> nth 1 |> Rule.to_string) = "Thm (\"realpow_twoI\",?r1 \<up> 2 = ?r1 * ?r1)" andalso
730 (revsets |> nth 1 |> nth 2 |> Rule.to_string) = "Thm (\"#: 9 = 3 \<up> 2\",9 = 3 \<up> 2)" andalso
731 (revsets |> nth 1 |> nth 3 |> Rule.to_string) = "Thm (\"#: 6 * x = 2 * (3 * x)\",6 * x = 2 * (3 * x))"
733 (revsets |> nth 1 |> nth 4 |> Rule.to_string) = "Thm (\"#: -3 * x = - 1 * (3 * x)\",-3 * x = - 1 * (3 * x))"
735 (revsets |> nth 1 |> nth 5 |> Rule.to_string) = "Thm (\"#: 9 = 3 * 3\",9 = 3 * 3)" andalso
736 (revsets |> nth 1 |> nth 6 |> Rule.to_string) = "Rls_ (\"sym_order_mult_rls_\")" andalso
737 (revsets |> nth 1 |> nth 7 |> Rule.to_string) =
738 "Thm (\"sym_mult.assoc\",?a * (?b * ?c) = ?a * ?b * ?c)"
739 then () else error "first 7 elements in revset changed"
740 \\----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)*)
742 (** find the rule 'r' to apply to term 't' **)
743 (*/------- WN1309: since cancel_ (accepted "-" between monomials) has been replaced by cancel_p_
744 for Isabelle2013, we don't get a working revset, but non-termination:
746 val SOME (r as (Thm (str, thm))) = nex revsets t;
748 ((3 * 3 + - 1 * x * x) / (3 * 3 + 2 * 3 * x + x * x),
749 Rls_ ("sym_order_mult_rls_"), ((3 * 3 + - 1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x), []))", "
750 ((3 * 3 + - 1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x),
751 Thm ("sym_mult.assoc", ""), ((3 * 3 + - 1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x), []))", "
752 ((3 * 3 + - 1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x),
753 Thm ("sym_mult.assoc", ""), ((3 * 3 + - 1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), []))", "
754 ((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), []))", "
757 Thm ("sym_#mult_2_3", "6 = 2 * 3")
758 ### Isabelle2009- 2 for cancel_ (not cancel_p_):
759 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))"
760 andalso ThmC.string_of_thm thm =
761 (string_of_thm (Thm.make_thm @{theory "Isac_Knowledge"}
762 (Trueprop $ (Thm.term_of o the o (TermC.parse thy)) "9 = 3 \<up> 2"))) then ()
763 else error "rational.sml next_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
764 \---------------------------------------------------------------------------------------/*)
766 (** check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
767 if the rule is OK, the term resulting from applying the rule is returned,too;
768 there might be several rule applications inbetween,
769 which are listed after the head in reverse order **)
770 (*/-------------------------------------------- Isabelle2013: this gives "error id_of_thm";
771 we don't repair this, because interaction within "reverse rewriting" never worked properly:
773 val (r, (t, asm))::_ = loc revsets t r;
774 if UnparseC.term t = "(9 - x \<up> 2) / (3 \<up> 2 + 6 * x + x \<up> 2)" andalso asm = []
775 then () else error "rational.sml locate_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
777 (* find the next rule to apply *)
778 val SOME (r as (Thm (str, thm))) = nex revsets t;
779 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso
780 ThmC.string_of_thm thm = (string_of_thm (ThmC_Def.make_thm @{theory "Isac_Knowledge"}
781 (Trueprop $ (Thm.term_of o the o (TermC.parse thy)) "9 = 3 \<up> 2"))) then ()
782 else error "rational.sml next_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
784 (*check the next rule*)
785 val (r, (t, asm)) :: _ = loc revsets t r;
786 if UnparseC.term t = "(3 \<up> 2 - x \<up> 2) / (3 \<up> 2 + 6 * x + x \<up> 2)" then ()
787 else error "rational.sml locate_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2) II";
789 (*find and check the next rules, rewrite*)
790 val SOME r = nex revsets t;
791 val (r,(t,asm))::_ = loc revsets t r;
792 if UnparseC.term t = "(3 \<up> 2 - x \<up> 2) / (3 \<up> 2 + 2 * 3 * x + x \<up> 2)" then ()
793 else error "rational.sml locate_rule II";
795 val SOME r = nex revsets t;
796 val (r,(t,asm))::_ = loc revsets t r;
797 if UnparseC.term t = "(3 - x) * (3 + x) / (3 \<up> 2 + 2 * 3 * x + x \<up> 2)" then ()
798 else error "rational.sml next_rule II";
800 val SOME r = nex revsets t;
801 val (r,(t,asm))::_ = loc revsets t r;
802 if UnparseC.term t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then ()
803 else error "rational.sml next_rule III";
805 val SOME r = nex revsets t;
806 val (r, (t, asm)) :: _ = loc revsets t r;
807 val ss = UnparseC.term t;
808 if ss = "(3 - x) / (3 + x)" andalso UnparseC.terms asm = "[\"3 + x ~= 0\"]" then ()
809 else error "rational.sml: new behav. in rev-set cancel";
810 \--------------------------------------------------------------------------------------/*)
812 "-------- 'reverse-ruleset' cancel_p -----------------------------------------";
813 "-------- 'reverse-ruleset' cancel_p -----------------------------------------";
814 "-------- 'reverse-ruleset' cancel_p -----------------------------------------";
815 (*WN130909: the example below shows, why "reverse rewriting" only worked for
818 (*the term for which reverse rewriting is demonstrated*)
819 val t = TermC.str2term "(9 + (- 1)*x \<up> 2) / (9 + ((-6)*x + x \<up> 2))";
820 val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
821 next_rule=nex,normal_form=nor,...},...} = cancel_p;
823 (*normal_form produces the result in ONE step*)
824 val SOME (t', _) = nor t;
825 if UnparseC.term t' = "(3 + x) / (3 + - 1 * x)"
826 then () else error "cancel_p normal_form CHANGED";;
828 (*initialize the interpreter state used by the 'me'*)
829 val SOME (t', asm) = cancel_p_ thy t;
830 if (UnparseC.term t', UnparseC.terms asm) = ("(3 + x) / (3 + - 1 * x)", "[\"3 + - 1 * x \<noteq> 0\"]")
831 then () else error "cancel_p CHANGED";;
833 val (t,_,revsets,_) = ini t;
835 (* WN.10.10.02: dieser Fall terminiert nicht
836 (make_polynomial enth"alt zu viele rules)
837 WN060823 'init_state' requires rewriting on specified location in the term
838 default_print_depth 99; Rfuns; default_print_depth 3;
839 WN060831 cycling "sym_order_mult_rls_" "sym_mult.assoc"
840 as was with make_polynomial before ?!?* )
842 val SOME r = nex revsets t;
843 eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))",
844 mk_thm thy "9 = 3 \<up> 2"));
845 ( *WN060831 *** id_of_thm
846 Exception- ERROR raised ...
847 val (r,(t,asm))::_ = loc revsets t r;
850 val SOME r = nex revsets t;
851 val (r,(t,asm))::_ = loc revsets t r;
855 "-------- examples: rls norm_Rational ----------------------------------------";
856 "-------- examples: rls norm_Rational ----------------------------------------";
857 "-------- examples: rls norm_Rational ----------------------------------------";
858 Rewrite.trace_on := false; (*true false*)
860 val t = TermC.str2term "Not (6*x is_atom)";
861 val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t';
863 val t = TermC.str2term "1 < 2";
864 val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t';
867 val t = TermC.str2term "(6*x) \<up> 2";
868 val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false
869 (ThmC.numerals_to_Free @{thm realpow_def_atom}) t;
870 if UnparseC.term t' = "6 * x * (6 * x) \<up> (2 + - 1)" then ()
871 else error "rational.sml powers_erls (6*x) \<up> 2";
873 val t = TermC.str2term "- 1 * (- 2 * (5 / 2 * (13 * x / 2)))";
874 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
875 if UnparseC.term t' = "65 * x / 2" then () else error "rational.sml 4";
877 val t = TermC.str2term "1 - ((13*x)/2 - 5/2) \<up> 2";
878 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
879 if UnparseC.term t' = "(- 21 + 130 * x + - 169 * x \<up> 2) / 4" then ()
880 else error "rational.sml 5";
882 (*SRAM Schalk I, p.92 Nr. 609a*)
883 val t = TermC.str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
884 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
885 if UnparseC.term t' = "(- 255 + 112 * x) / 135" then ()
886 else error "rational.sml 6";
888 (*SRAM Schalk I, p.92 Nr. 610c*)
889 val t = TermC.str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
890 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
891 if UnparseC.term t' = "(3 + x) / - 2" then () else error "rational.sml 7";
893 (*SRAM Schalk I, p.92 Nr. 476a*)
894 val t = TermC.str2term "(x \<up> 2/(1 - x \<up> 2) + 1)/(x/(1 - x) + 1) * (1 + x)";
895 (*. a/b : c/d translated to a/b * d/c .*)
896 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
897 if UnparseC.term t' = "1" then () else error "rational.sml 8";
899 (*Schalk I, p.92 Nr. 472a*)
900 val t = TermC.str2term "((8*x \<up> 2 - 32*y \<up> 2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
901 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
902 if UnparseC.term t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
904 (*Schalk I, p.70 Nr. 480b: SEE rational.sml --- nonterminating rls norm_Rational ---*)
906 (*WN130910 add_fractions_p exception Div raised + history:
907 ### WN.2.6.03 from rlang.sml 56a
908 val t = TermC.str2term "(a + b * x) / (a + - 1 * (b * x)) + (- 1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a \<up> 2 + - 1 * b \<up> 2)";
909 val NONE = rewrite_set_ thy false add_fractions_p t;
911 THE ERROR ALREADY OCCURS IN THIS PART:
912 val t = TermC.str2term "(a + b * x) / (a + - 1 * (b * x)) + (- 1 * a + b * x) / (a + b * x)";
913 val NONE = add_fraction_p_ thy t;
915 SEE Test_Some.thy: section {* add_fractions_p downto exception Div raised ===
918 "-------- rational numerals --------------------------------------------------";
919 "-------- rational numerals --------------------------------------------------";
920 "-------- rational numerals --------------------------------------------------";
921 (*SRA Schalk I, p.40 Nr. 164b *)
922 val t = TermC.str2term "(47/6 - 76/9 + 13/4)/(35/12)";
923 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
924 if UnparseC.term t = "19 / 21" then ()
925 else error "rational.sml: diff.behav. in norm_Rational_mg 1";
927 (*SRA Schalk I, p.40 Nr. 166a *)
928 val t = TermC.str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
929 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
930 if UnparseC.term t = "45 / 2" then ()
931 else error "rational.sml: diff.behav. in norm_Rational_mg 2";
933 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
934 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
935 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
937 val t = TermC.str2term "((1 + 9*a \<up> 2) * (1 + 3*a)) / ((3*a + 9*a \<up> 2) * (1 + 3*a))";
938 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
939 if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
940 then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
943 val t = TermC.str2term "(x \<up> 2 * (7*x + (- 1)*y)) / (y \<up> 2 * (7*x + (- 1)*y))";
944 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
945 if UnparseC.term t = "x \<up> 2 / y \<up> 2"
946 then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
948 (*SRC Schalk I, p.66 Nr. 379c *)
949 val t = TermC.str2term "(a - b)/(b - a)";
950 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
951 if UnparseC.term t = "- 1"
952 then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
954 (*SRC Schalk I, p.66 Nr. 380b *)
955 val t = TermC.str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))";
956 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
957 if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)"
958 then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
961 val t = TermC.str2term "((1 + 9*a \<up> 2) * (1 + 3*a)) / ((3*a + 9*a \<up> 2) * (1 + 3 * a))";
962 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
963 if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
964 then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
967 val t = TermC.str2term "(x \<up> 2 * (7*x + (- 1)*y)) / (y \<up> 2 * (7*x + (- 1)*y))";
968 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
969 if UnparseC.term t = "x \<up> 2 / y \<up> 2"
970 then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
972 (*SRC Schalk I, p.66 Nr. 379c *)
973 val t = TermC.str2term "(a - b) / (b - a)";
974 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
975 if UnparseC.term t = "- 1"
976 then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
978 (*SRC Schalk I, p.66 Nr. 380b *)
979 val t = TermC.str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))";
980 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
981 if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)"
982 then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
984 (* extreme example from somewhere *)
985 val t = TermC.str2term
986 ("(a \<up> 4 * x + - 1*a \<up> 4 * y + 4*a \<up> 3 * b * x + -4*a \<up> 3 * b * y + " ^
987 "6*a \<up> 2 * b \<up> 2 * x + -6*a \<up> 2 * b \<up> 2 * y + 4*a * b \<up> 3 * x + -4*a * b \<up> 3 * y + " ^
988 "b \<up> 4 * x + - 1*b \<up> 4 * y) " ^
989 " / (a \<up> 2 * x \<up> 3 + -3*a \<up> 2 * x \<up> 2 * y + 3*a \<up> 2 * x * y \<up> 2 + - 1*a \<up> 2 * y \<up> 3 + " ^
990 "2*a * b * x \<up> 3 + -6*a * b * x \<up> 2 * y + 6*a * b * x * y \<up> 2 + - 2*a * b * y \<up> 3 + " ^
991 "b \<up> 2 * x \<up> 3 + -3*b \<up> 2 * x \<up> 2 * y + 3*b \<up> 2 * x * y \<up> 2 + - 1*b \<up> 2 * y \<up> 3)")
992 val SOME (t, _) = rewrite_set_ thy false cancel_p t;
993 if UnparseC.term t = "(a \<up> 2 + 2 * a * b + b \<up> 2) / (x \<up> 2 + - 2 * x * y + y \<up> 2)"
994 then () else error "with Isabelle2002: NONE -- now SOME changed";
996 (*Schalk I, p.66 Nr. 381a *)
997 (* ATTENTION: here the rls is very slow. In Isabelle2002 this required 2 min *)
998 val t = TermC.str2term "18*(a + b) \<up> 3 * (a - b) \<up> 2 / (72*(a - b) \<up> 3 * (a + b) \<up> 2)";
999 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1000 if UnparseC.term t = "(a + b) / (4 * a + - 4 * b)"
1001 then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
1003 (*SRC Schalk I, p.66 Nr. 381b *)
1004 val t = TermC.str2term "(4*x \<up> 2 - 20*x + 25) / (2*x - 5) \<up> 3";
1005 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1006 if UnparseC.term t = "1 / (- 5 + 2 * x)"
1007 then () else error "rational.sml: diff.behav. in norm_Rational_mg 9";
1009 (*SRC Schalk I, p.66 Nr. 381c *)
1010 val t = TermC.str2term "(27*a \<up> 3 + 9*a \<up> 2+3*a+1) / (27*a \<up> 3 + 18*a \<up> 2+3*a)";
1011 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1012 if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
1013 then () else error "rational.sml: diff.behav. in norm_Rational_mg 10";
1015 (*SRC Schalk I, p.66 Nr. 383a *)
1016 val t = TermC.str2term "(5*a \<up> 2 - 5*a*b) / (a - b) \<up> 2";
1017 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1018 if UnparseC.term t = "- 5 * a / (- 1 * a + b)"
1019 then () else error "rational.sml: diff.behav. in norm_Rational_mg 11";
1021 "----- NOT TERMINATING ?: worked before 0707xx";
1022 val t = TermC.str2term "(a \<up> 2 - 1)*(b + 1) / ((b \<up> 2 - 1)*(a+1))";
1023 (* WN130911 "exception Div raised" by
1024 cancel_p_ thy (TermC.str2term ("(- 1 + - 1 * b + a \<up> 2 + a \<up> 2 * b) /" ^
1025 "(- 1 + - 1 * a + b \<up> 2 + a * b \<up> 2)"))
1027 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1028 if UnparseC.term t = "(1 + - 1 * a) / (1 + - 1 * b)" then ()
1029 else error "rational.sml MG tests 3e";
1032 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
1033 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
1034 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
1035 (*SRA Schalk I, p.67 Nr. 403a *)
1036 val t = TermC.str2term "4/x - 3/y - 1";
1037 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1038 if UnparseC.term t = "(- 3 * x + 4 * y + - 1 * x * y) / (x * y)"
1039 then () else error "rational.sml: diff.behav. in norm_Rational_mg 12";
1041 val t = TermC.str2term "(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a \<up> 2+3*b*c)/(a*b*c)";
1042 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1043 if UnparseC.term t = "4 / c"
1044 then () else error "rational.sml: diff.behav. in norm_Rational_mg 13";
1046 (*SRA Schalk I, p.67 Nr. 410b *)
1047 val t = TermC.str2term "1/(x+1) + 1/(x+2) - 2/(x+3)";
1048 (* WN130911 non-termination due to non-termination of
1049 cancel_p_ thy (TermC.str2term "(5 + 3 * x) / (6 + 11 * x + 6 * x \<up> 2 + x \<up> 3)")
1051 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1052 if UnparseC.term t = "(5 + 3 * x) / (6 + 11 * x + 6 * x \<up> 2 + x \<up> 3)"
1053 then () else error "rational.sml: diff.behav. in norm_Rational_mg 14";
1056 (*SRA Schalk I, p.67 Nr. 413b *)
1057 val t = TermC.str2term "(1 + x)/(1 - x) - (1 - x)/(1 + x) + 2*x/(1 - x \<up> 2)";
1058 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1059 if UnparseC.term t = "6 * x / (1 + - 1 * x \<up> 2)"
1060 then () else error "rational.sml: diff.behav. in norm_Rational_mg 15";
1062 (*SRA Schalk I, p.68 Nr. 414a *)
1063 val t = TermC.str2term "(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))";
1064 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1065 if UnparseC.term t ="(- 2 + - 5 * x + 2 * x \<up> 2) / (2 + - 3 * x + x \<up> 2)"
1066 then () else error "rational.sml: diff.behav. in norm_Rational_mg 16";
1068 (*SRA Schalk I, p.68 Nr. 428b *)
1069 val t = TermC.str2term
1070 "1/(a - b) \<up> 2 + 1/(a + b) \<up> 2 - 2/(a \<up> 2 - b \<up> 2) - 4*(b \<up> 2 - 1)/(a \<up> 2 - b \<up> 2) \<up> 2";
1071 (* WN130911 non-termination due to non-termination of
1072 cancel_p_ thy (TermC.str2term "(4 + -4 * b \<up> 2) / (a \<up> 4 + - 2 * (a \<up> 2 * b \<up> 2) + b \<up> 4)")
1074 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1075 if UnparseC.term t = "4 / (a \<up> 4 + - 2 * a \<up> 2 * b \<up> 2 + b \<up> 4)"
1076 then () else error "rational.sml: diff.behav. in norm_Rational_mg 18";
1079 (*SRA Schalk I, p.68 Nr. 430b *)
1080 val t = TermC.str2term
1081 "a \<up> 2/(a - 3*b) - 108*a*b \<up> 3/((a+3*b)*(a \<up> 2 - 9*b \<up> 2)) - 9*b \<up> 2*(a - 3*b)/(a+3*b) \<up> 2";
1082 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1083 if UnparseC.term t = "a + 3 * b"
1084 then () else error "rational.sml: diff.behav. in norm_Rational_mg 19";
1086 (*SRA Schalk I, p.68 Nr. 432 *)
1087 val t = TermC.str2term
1088 ("(a \<up> 2 + a*b) / (a \<up> 2 - b \<up> 2) - (b \<up> 2 - a*b) / (b \<up> 2 - a \<up> 2) + " ^
1089 "a \<up> 2*(a - b) / (a \<up> 3 - a \<up> 2*b) - 2*a*(a \<up> 2 - b \<up> 2) / (a \<up> 3 - a*b \<up> 2) - " ^
1090 "2*b \<up> 2 / (a \<up> 2 - b \<up> 2)");
1091 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1092 if UnparseC.term t = (*"0" ..isabisac15 | Isabelle2017..*) "0 / (a \<up> 2 + - 1 * b \<up> 2)"
1093 then () else error "rational.sml: diff.behav. in norm_Rational_mg 20";
1096 val t = TermC.str2term "3*a / (a*b) + x/y";
1097 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1098 if UnparseC.term t = "(3 * y + b * x) / (b * y)"
1099 then () else error "rational.sml: diff.behav. in norm_Rational_mg 21";
1102 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1103 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1104 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1105 (*------- SRM Schalk I, p.68 Nr. 436a *)
1106 val t = TermC.str2term "3*(x+y) / (15*(x - y)) * 25*(x - y) \<up> 2 / (18*(x + y) \<up> 2)";
1107 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1108 if UnparseC.term t = "(- 5 * x + 5 * y) / (- 18 * x + - 18 * y)"
1109 then () else error "rational.sml: diff.behav. in norm_Rational_mg 22";
1111 (*------- SRM.test Schalk I, p.68 Nr. 436b *)
1112 val t = TermC.str2term "5*a*(a - b) \<up> 2*(a + b) \<up> 3/(7*b*(a - b) \<up> 3) * 7*b/(a + b) \<up> 3";
1113 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1114 if UnparseC.term t = "5 * a / (a + - 1 * b)"
1115 then () else error "rational.sml: diff.behav. in norm_Rational_mg 23";
1117 (*------- Schalk I, p.68 Nr. 437a *)
1118 val t = TermC.str2term "(3*a - 4*b) / (4*c+3*e) * (3*a+4*b)/(9*a \<up> 2 - 16*b \<up> 2)";
1119 (* raises an exception for unclear reasons:
1120 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1122 ### rls: cancel_p on: (9 * a \<up> 2 + - 16 * b \<up> 2) / (4 * c + 3 * e) /
1123 (9 * a \<up> 2 + - 16 * b \<up> 2)
1124 exception Div raised
1127 val t = TermC.str2term
1128 ("(9 * a \<up> 2 + - 16 * b \<up> 2) / (4 * c + 3 * e) /" ^
1129 "(9 * a \<up> 2 + - 16 * b \<up> 2)");
1130 NONE = cancel_p_ thy t;
1132 if UnparseC.term t = "1 / (4 * c + 3 * e)" then ()
1133 else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1136 "----- S.K. corrected non-termination 060904";
1137 val t = TermC.str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a \<up> 2 - 16*b \<up> 2))";
1138 val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
1139 if UnparseC.term t =
1140 "(9 * a \<up> 2 + - 16 * b \<up> 2) /\n(36 * a \<up> 2 * c + 27 * a \<up> 2 * e + - 64 * b \<up> 2 * c +\n - 48 * b \<up> 2 * e)"
1141 then () else error "rational.sml: S.K.8..corrected 060904-6";
1143 "----- S.K. corrected non-termination of cancel_p_";
1144 val t'' = TermC.str2term ("(9 * a \<up> 2 + - 16 * b \<up> 2) /" ^
1145 "(36 * a \<up> 2 * c + (27 * a \<up> 2 * e + (-64 * b \<up> 2 * c + -48 * b \<up> 2 * e)))");
1146 (* /--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------\
1147 val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
1148 if UnparseC.term t' = "1 / (4 * c + 3 * e)"
1149 then () else error "rational.sml: diff.behav. in cancel_p S.K.8";
1150 \--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------/*)
1152 (*------- Schalk I, p.68 Nr. 437b*)
1153 val t = TermC.str2term "(a + b)/(x \<up> 2 - y \<up> 2) * ((x - y) \<up> 2/(a \<up> 2 - b \<up> 2))";
1154 (*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1156 #### rls: cancel_p on: (a * x \<up> 2 + - 2 * (a * (x * y)) + a * y \<up> 2 + b * x \<up> 2 +
1157 - 2 * (b * (x * y)) +
1159 (a \<up> 2 * x \<up> 2 + - 1 * (a \<up> 2 * y \<up> 2) + - 1 * (b \<up> 2 * x \<up> 2) +
1160 b \<up> 2 * y \<up> 2)
1161 exception Div raised
1164 (*------- SRM Schalk I, p.68 Nr. 438a *)
1165 val t = TermC.str2term "x*y / (x*y - y \<up> 2) * (x \<up> 2 - x*y)";
1166 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1167 if UnparseC.term t = "x \<up> 2"
1168 then () else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1170 (*------- SRM Schalk I, p.68 Nr. 439b *)
1171 val t = TermC.str2term "(4*x \<up> 2 + 4*x + 1) * ((x \<up> 2 - 2*x \<up> 3) / (4*x \<up> 2 + 2*x))";
1172 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1173 if UnparseC.term t = "(x + - 4 * x \<up> 3) / 2"
1174 then () else error "rational.sml: diff.behav. in norm_Rational_mg 25";
1176 (*------- SRM Schalk I, p.68 Nr. 440a *)
1177 val t = TermC.str2term "(x \<up> 2 - 2*x) / (x \<up> 2 - 3*x) * (x - 3) \<up> 2 / (x \<up> 2 - 4)";
1178 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1179 if UnparseC.term t = "(- 3 + x) / (2 + x)"
1180 then () else error "rational.sml: diff.behav. in norm_Rational_mg 26";
1182 "----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
1183 val t = TermC.str2term "(a \<up> 3 - 9*a) / (a \<up> 3*b - a*b \<up> 3) * (a \<up> 2*b + a*b \<up> 2) / (a+3)";
1184 (* WN130911 non-termination for unclear reasons:
1185 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1187 ... ENDS WITH THIS TRACE:
1189 ### rls: cancel_p on: (-9 * (a \<up> 3 * b) + -9 * (a \<up> 2 * b \<up> 2) + a \<up> 5 * b +
1190 a \<up> 4 * b \<up> 2) /
1191 (a \<up> 3 * b + - 1 * (a * b \<up> 3)) /
1193 BUT THIS IS CORRECTLY RECOGNISED
1194 val t = TermC.str2term
1195 ("(-9 * (a \<up> 3 * b) + -9 * (a \<up> 2 * b \<up> 2) + a \<up> 5 * b + a \<up> 4 * b \<up> 2) /" ^
1196 "(a \<up> 3 * b + - 1 * (a * b \<up> 3)) / (3 + (a::real))");
1198 NONE = cancel_p_ thy t;
1200 if UnparseC.term t = "(-3 * a + a \<up> 2) / (a + - 1 * b)" then ()
1201 else error "rational.sml: diff.behav. in norm_Rational 27";
1204 "----- SK12 works since 0707xx";
1205 val t = TermC.str2term "(a \<up> 3 - 9*a) * (a \<up> 2*b+a*b \<up> 2) / ((a \<up> 3*b - a*b \<up> 3) * (a+3))";
1206 (* WN130911 non-termination due to non-termination of
1207 cancel_p_ thy (TermC.str2term "(4 + -4 * b \<up> 2) / (a \<up> 4 + - 2 * (a \<up> 2 * b \<up> 2) + b \<up> 4)")
1209 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1210 if UnparseC.term t' = "(-3 * a + a \<up> 2) / (a + - 1 * b)" then ()
1211 else error "rational.sml: diff.behav. in norm_Rational 28";
1214 "-------- examples common denominator and multiplication from: Schalk --------";
1215 "-------- examples common denominator and multiplication from: Schalk --------";
1216 "-------- examples common denominator and multiplication from: Schalk --------";
1217 (*------- SRAM Schalk I, p.69 Nr. 441b *)
1218 val t = TermC.str2term "(4*a/3 + 3*b \<up> 2/a \<up> 3 + b/(4*a))*(4*b/(3*a))";
1219 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1220 if UnparseC.term t = "(36 * b \<up> 3 + 3 * a \<up> 2 * b \<up> 2 + 16 * a \<up> 4 * b) /\n(9 * a \<up> 4)"
1221 then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
1223 (*------- SRAM Schalk I, p.69 Nr. 442b *)
1224 val t = TermC.str2term ("(15*a \<up> 2/x \<up> 3 - 5*b \<up> 4/x \<up> 2 + 25*c \<up> 2/x) * " ^
1225 "(x \<up> 3/(5*a*b \<up> 3*c \<up> 3)) + 1/c \<up> 3 * (b*x/a - 3*a/b \<up> 3)");
1226 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1227 if UnparseC.term t = "5 * x \<up> 2 / (a * b \<up> 3 * c)"
1228 then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
1230 (*------- SRAM Schalk I, p.69 Nr. 443b *)
1231 val t = TermC.str2term "(a/2 + b/3) * (b/3 - a/2)";
1232 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1233 if UnparseC.term t = "(- 9 * a \<up> 2 + 4 * b \<up> 2) / 36"
1234 then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
1236 (*------- SRAM Schalk I, p.69 Nr. 445b *)
1237 val t = TermC.str2term "(a \<up> 2/9 + 2*a/(3*b) + 4/b \<up> 2)*(a/3 - 2/b) + 8/b \<up> 3";
1238 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1239 if UnparseC.term t = "a \<up> 3 / 27"
1240 then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
1242 (*------- SRAM Schalk I, p.69 Nr. 446b *)
1243 val t = TermC.str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x \<up> 2 - 16*y \<up> 2)";
1244 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1245 if UnparseC.term t = (*"30 * x \<up> 2 + -9 * x * y + - 20 * y \<up> 2" ..isabisac15 | Isabelle2017..*)
1246 "(- 30 * x \<up> 2 + 9 * x * y + 20 * y \<up> 2) / - 1"
1247 then () else error "rational.sml: diff.behav. in norm_Rational_mg 32";
1249 (*------- SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
1250 val t = TermC.str2term
1251 "(2*x \<up> 2/(3*y)+x/y \<up> 2)*(4*x \<up> 4/(9*y \<up> 2)+x \<up> 2/y \<up> 4)*(2*x \<up> 2/(3*y) - x/y \<up> 2)";
1252 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1253 if UnparseC.term t = "(- 81 * x \<up> 4 + 16 * x \<up> 8 * y \<up> 4) / (81 * y \<up> 8)"
1254 then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
1256 (*------- SRAM Schalk I, p.69 Nr. 450a *)
1257 val t = TermC.str2term
1258 "(4*x/(3*y)+2*y/(3*x)) \<up> 2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
1259 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1260 if UnparseC.term t = "(52 * x \<up> 2 + 16 * y \<up> 2) / (9 * y \<up> 2)"
1261 then () else error "rational.sml: diff.behav. in norm_Rational_mg 34";
1263 (*------- SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*)
1264 val t = TermC.str2term
1265 ("(15*a \<up> 4/(a*x \<up> 3) - 5*a*((b \<up> 4 - 5*c \<up> 2*x) / x \<up> 2)) * " ^
1266 "(x \<up> 3/(5*a*b \<up> 3*c \<up> 3)) + a/c \<up> 3 * (x*(b/a) - 3*b*(a/b \<up> 4))");
1267 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1268 if UnparseC.term t = "5 * x \<up> 2 / (b \<up> 3 * c)"
1269 then () else error "rational.sml: diff.behav. in norm_Rational_mg 53";
1272 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1273 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1274 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1275 "----- SRD Schalk I, p.69 Nr. 454b";
1276 val t = TermC.str2term "((2 - x)/(2*a)) / (2*a/(x - 2))";
1277 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1278 if UnparseC.term t = "(- 4 + 4 * x + - 1 * x \<up> 2) / (4 * a \<up> 2)"
1279 then () else error "rational.sml: diff.behav. in norm_Rational_mg 35";
1281 "----- SRD Schalk I, p.69 Nr. 455a";
1282 val t = TermC.str2term "(a \<up> 2 + 1)/(a \<up> 2 - 1) / ((a+1)/(a - 1))";
1283 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1284 if UnparseC.term t = "(1 + a \<up> 2) / (1 + 2 * a + a \<up> 2)" then ()
1285 else error "rational.sml: diff.behav. in norm_Rational_mg 36";
1287 "----- Schalk I, p.69 Nr. 455b";
1288 val t = TermC.str2term "(x \<up> 2 - 4)/(y \<up> 2 - 9)/((2+x)/(3 - y))";
1289 (* WN130911 non-termination due to non-termination of
1290 cancel_p_ thy (TermC.str2term ("(- 12 + 4 * y + 3 * x \<up> 2 + - 1 * (x \<up> 2 * y)) /" ^
1291 "(- 18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)"))
1293 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1294 if UnparseC.term t = "(2 + - 1 * x) / (3 + y)" then ()
1295 else error "rational.sml: diff.behav. in norm_Rational_mg 37";
1298 "----- SK060904- 1a non-termination of cancel_p_ ?: worked before 0707xx";
1299 val t = TermC.str2term "(x \<up> 2 - 4)*(3 - y) / ((y \<up> 2 - 9)*(2+x))";
1300 (* WN130911 non-termination due to non-termination of
1301 cancel_p_ thy (TermC.str2term ("(- 12 + 4 * y + 3 * x \<up> 2 + - 1 * (x \<up> 2 * y)) /" ^
1302 "(- 18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)"))
1304 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1305 if UnparseC.term t = "(2 + - 1 * x) / (3 + y)" then ()
1306 else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
1309 "----- ?: worked before 0707xx";
1310 val t = TermC.str2term "(3 + - 1 * y) / (-9 + y \<up> 2)";
1311 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1312 if UnparseC.term t = "- 1 / (3 + y)"
1313 then () else error "rational.sml: - 1 / (3 + y) norm_Rational";
1315 "----- SRD Schalk I, p.69 Nr. 456b";
1316 val t = TermC.str2term "(b \<up> 3 - b \<up> 2) / (b \<up> 2+b) / (b \<up> 2 - 1)";
1317 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1318 if UnparseC.term t = "b / (1 + 2 * b + b \<up> 2)"
1319 then () else error "rational.sml: diff.behav. in norm_Rational_mg 38";
1321 "----- SRD Schalk I, p.69 Nr. 457b";
1322 val t = TermC.str2term "(16*a \<up> 2 - 9*b \<up> 2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a \<up> 2 - 9*a \<up> 2*b \<up> 2))";
1323 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1324 if UnparseC.term t = "8 * a \<up> 2 + - 6 * a * b + - 12 * a \<up> 2 * b + 9 * a * b \<up> 2"
1325 then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
1327 "----- Schalk I, p.69 Nr. 458b works since 0707";
1328 val t = TermC.str2term "(2*a \<up> 2*x - a \<up> 2) / (a*x - b*x) / (b \<up> 2*(2*x - 1) / (x*(a - b)))";
1329 (*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1331 ### rls: cancel_p on: (- 1 * a \<up> 2 + 2 * (a \<up> 2 * x)) / (a * x + - 1 * (b * x)) /
1332 ((- 1 * b \<up> 2 + 2 * (b \<up> 2 * x)) / (a * x + - 1 * (b * x)))
1333 exception Div raised
1336 val t = TermC.str2term
1337 ("(- 1 * a \<up> 2 + 2 * (a \<up> 2 * x)) / (a * x + - 1 * (b * x)) /" ^
1338 "((- 1 * b \<up> 2 + 2 * (b \<up> 2 * x)) / (a * x + - 1 * (b * x)))");
1339 NONE = cancel_p_ thy t;
1341 if UnparseC.term t = "a \<up> 2 / b \<up> 2" then ()
1342 else error "rational.sml: diff.behav. in norm_Rational_mg 39b";
1345 "----- SRD Schalk I, p.69 Nr. 459b";
1346 val t = TermC.str2term "(a \<up> 2 - b \<up> 2)/(a*b) / (4*(a+b) \<up> 2/a)";
1347 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1348 if UnparseC.term t = "(a + - 1 * b) / (4 * a * b + 4 * b \<up> 2)" then ()
1349 else error "rational.sml: diff.behav. in norm_Rational_mg 41";
1351 "----- Schalk I, p.69 Nr. 460b nonterm.SK";
1352 val t = TermC.str2term "(9*(x \<up> 2 - 8*x + 16) / (4*(y \<up> 2 - 2*y + 1))) / ((3*x - 12) / (16*y - 16))";
1353 (*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1354 exception Div raised
1357 val t = TermC.str2term
1358 ("(144 + -72 * x + 9 * x \<up> 2) / (4 + -8 * y + 4 * y \<up> 2) /" ^
1359 "((- 12 + 3 * x) / (- 16 + 16 * y))");
1360 NONE = cancel_p_ thy t;
1362 if UnparseC.term t = !!!!!!!!!!!!!!!!!!!!!!!!!
1363 then () else error "rational.sml: diff.behav. in norm_Rational_mg 42";
1366 "----- some variant of the above; was non-terminating before";
1367 val t = TermC.str2term "9*(x \<up> 2 - 8*x+16)*(16*y - 16)/(4*(y \<up> 2 - 2*y+1)*(3*x - 12))";
1368 val SOME (t , _) = rewrite_set_ thy false norm_Rational t;
1369 if UnparseC.term t = "(48 + - 12 * x) / (1 + - 1 * y)"
1370 then () else error "some variant of the above; was non-terminating before";
1372 "----- SRD Schalk I, p.70 Nr. 472a";
1373 val t = TermC.str2term ("((8*x \<up> 2 - 32*y \<up> 2) / (2*x + 4*y)) / ((4*x - 8*y) / (x + y))");
1374 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1375 if UnparseC.term t = "x + y"
1376 then () else error "rational.sml: diff.behav. in norm_Rational_mg 43";
1378 "----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
1379 val t = TermC.str2term ("(a - (a*b + b \<up> 2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
1380 "((a - a \<up> 2/(a+b))/(a+(a*b)/(a - b)))");
1381 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1382 if UnparseC.term t = "(2 * a \<up> 3 + 2 * a \<up> 2 * b) / (a \<up> 2 * b + b \<up> 3)"
1383 then () else error "rational.sml: diff.behav. in norm_Rational_mg 51";
1385 (*SRD Schalk I, p.69 Nr. 461a *)
1386 val t = TermC.str2term "(2/(x+3) + 2/(x - 3)) / (8*x/(x \<up> 2 - 9))";
1387 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1388 if UnparseC.term t = "1 / 2"
1389 then () else error "rational.sml: diff.behav. in norm_Rational_mg 44";
1391 (*SRD Schalk I, p.69 Nr. 464b *)
1392 val t = TermC.str2term "(a - a/(a - 2)) / (a + a/(a - 2))";
1393 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1394 if UnparseC.term t = "(- 3 + a) / (- 1 + a)"
1395 then () else error "rational.sml: diff.behav. in norm_Rational_mg 45";
1397 (*SRD Schalk I, p.69 Nr. 465b *)
1398 val t = TermC.str2term "((x+3*y)/9 + (4*y \<up> 2 - 9*z \<up> 2)/(16*x)) / (x/9 + y/6 + z/4)";
1399 (* WN130911 non-termination due to non-termination of
1400 cancel_p_ thy (TermC.str2term
1401 ("("(576 * x \<up> 2 + 1728 * (x * y) + 1296 * y \<up> 2 + - 2916 * z \<up> 2) /" ^
1402 "(576 * x \<up> 2 + 864 * (x * y) + 1296 * (x * z))"))
1404 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1405 if UnparseC.term t = "(4 * x + 6 * y + -9 * z) / (4 * x)"
1406 then () else error "rational.sml: diff.behav. in norm_Rational_mg 46";
1409 (*SRD Schalk I, p.69 Nr. 466b *)
1410 val t = TermC.str2term "((1 - 7*(x - 2)/(x \<up> 2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x \<up> 2 - 25))";
1411 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1412 if UnparseC.term t = "(25 + - 10 * x + x \<up> 2) / 18"
1413 then () else error "rational.sml: diff.behav. in norm_Rational_mg 47";
1415 (*SRD Schalk I, p.70 Nr. 469 *)
1416 val t = TermC.str2term ("3*b \<up> 2 / (4*a \<up> 2 - 8*a*b + 4*b \<up> 2) / " ^
1417 "(a / (a \<up> 2*b - b \<up> 3) + (a - b) / (4*a*b \<up> 2 + 4*b \<up> 3) - 1 / (4*b \<up> 2))");
1418 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1419 if UnparseC.term t = "- 3 * b \<up> 3 / (- 2 * a + 2 * b)"
1420 then () else error "rational.sml: diff.behav. in norm_Rational_mg 48";
1422 (*//----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)
1423 "-------- me Schalk I No.186 -------------------------------------------------";
1424 "-------- me Schalk I No.186 -------------------------------------------------";
1425 "-------- me Schalk I No.186 -------------------------------------------------";
1426 val fmz = ["Term ((14 * x * y) / ( x * y ))", "normalform N"];
1428 ("Rational",["rational", "simplification"],
1429 ["simplification", "of_rationals"]);
1430 val p = e_pos'; val c = [];
1431 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
1432 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1433 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1434 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1435 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1436 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1437 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1438 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1439 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1440 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1441 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1442 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1443 case (f2str f, nxt) of
1444 ("14", ("End_Proof'", _)) => ()
1445 | _ => error "rational.sml diff.behav. in me Schalk I No.186";
1446 \\----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)*)
1448 (*//----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)
1449 "-------- interSteps ..Simp_Rat_Double_No- 1.xml ------------------------------";
1450 "-------- interSteps ..Simp_Rat_Double_No- 1.xml ------------------------------";
1451 "-------- interSteps ..Simp_Rat_Double_No- 1.xml ------------------------------";
1453 CalcTree [(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"],
1454 ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1457 autoCalculate 1 CompleteCalc;
1458 val ((pt, p), _) = get_calc 1;
1460 Test_Tool.show_pt pt;
1462 (([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))),
1463 (([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1464 (([1], Res), (2 + - 1 * x) / (2 * a) / (2 * a / (x + - 1 * 2))),
1465 (([2], Res), (2 + - 1 * x) / (2 * a) / (2 * a / (- 2 + x))),
1466 (([3], Res), (2 + - 1 * x) * (- 2 + x) / (2 * a * (2 * a))),
1467 (([4], Res), (-4 + 4 * x + - 1 * x \<up> 2) / (4 * a \<up> 2)),
1468 (([], Res), (-4 + 4 * x + - 1 * x \<up> 2) / (4 * a \<up> 2))]
1470 interSteps 1 ([1], Res);
1471 val ((pt, p), _) = get_calc 1;
1472 (*Test_Tool.show_pt pt;
1474 (([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))),
1475 (([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1476 (([1,1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1477 (([1,1], Res), (2 - x) / (2 * a) / (2 * a / (x + - 1 * 2))),
1478 (([1,2], Res), (2 + - 1 * x) / (2 * a) / (2 * a / (x + - 1 * 2))),
1479 (([1], Res), (2 + - 1 * x) / (2 * a) / (2 * a / (x + - 1 * 2))),
1480 (([2], Res), (2 + - 1 * x) / (2 * a) / (2 * a / (- 2 + x))),
1481 (([3], Res), (2 + - 1 * x) * (- 2 + x) / (2 * a * (2 * a))),
1482 (([4], Res), (-4 + 4 * x + - 1 * x \<up> 2) / (4 * a \<up> 2)),
1483 (([], Res), (-4 + 4 * x + - 1 * x \<up> 2) / (4 * a \<up> 2))]
1485 val (t, asm) = get_obj g_result pt [1, 1];
1486 if UnparseC.term t = "(2 - x) / (2 * a) / (2 * a / (x + - 1 * 2))" andalso UnparseC.terms asm = "[]"
1487 then () else error "2nd interSteps ..Simp_Rat_Double_No- 1 changed on [1, 1]";
1488 val (t, asm) = get_obj g_result pt [1, 2];
1489 if UnparseC.term t = "(2 + - 1 * x) / (2 * a) / (2 * a / (x + - 1 * 2))" andalso UnparseC.terms asm = "[]"
1490 then () else error "3rd interSteps ..Simp_Rat_Double_No- 1 changed on [1, 2]";
1491 \\----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)*)
1494 (*//----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)
1495 "-------- interSteps ..Simp_Rat_Cancel_No- 1.xml ------------------------------";
1496 "-------- interSteps ..Simp_Rat_Cancel_No- 1.xml ------------------------------";
1497 "-------- interSteps ..Simp_Rat_Cancel_No- 1.xml ------------------------------";
1499 CalcTree [(["Term ((a^2 + - 1*b^2) / (a^2 + - 2*a*b + b^2))", "normalform N"],
1500 ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1503 autoCalculate 1 CompleteCalc;
1504 val ((pt, p), _) = get_calc 1;
1505 (*Test_Tool.show_pt pt;
1507 (([], Frm), Simplify ((a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * a * b + b \<up> 2))),
1508 (([1], Frm), (a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * a * b + b \<up> 2)),
1509 (([1], Res), (a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * (a * b) + b \<up> 2)),
1510 (([2], Res), (a + b) / (a + - 1 * b)),
1511 (([], Res), (a + b) / (a + - 1 * b))]
1513 interSteps 1 ([2], Res);
1514 val ((pt, p), _) = get_calc 1;
1515 (*Test_Tool.show_pt pt;
1517 (([], Frm), Simplify ((a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * a * b + b \<up> 2))),
1518 (([1], Frm), (a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * a * b + b \<up> 2)),
1519 (([1], Res), (a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * (a * b) + b \<up> 2)),
1520 (([2,1], Frm), (a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * (a * b) + b \<up> 2)),
1521 (([2,1], Res), (a + b) / (a + - 1 * b)),
1522 (([2], Res), (a + b) / (a + - 1 * b)),
1523 (([], Res), (a + b) / (a + - 1 * b))]
1525 interSteps 1 ([2,1],Res);
1526 val ((pt, p), _) = get_calc 1;
1527 (*Test_Tool.show_pt pt;
1529 (([], Frm), Simplify ((a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * a * b + b \<up> 2))),
1530 (([1], Frm), (a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * a * b + b \<up> 2)),
1531 (([1], Res), (a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * (a * b) + b \<up> 2)),
1532 (([2,1], Frm), (a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * (a * b) + b \<up> 2)),
1533 (([2,1,1], Frm), (a \<up> 2 + - 1 * b \<up> 2) / (a \<up> 2 + - 2 * (a * b) + b \<up> 2)),
1534 (([2,1,1], Res), (a \<up> 2 + - 1 * (a * b) + a * b + - 1 * b \<up> 2) /
1535 (a \<up> 2 + - 2 * (a * b) + 1 * b \<up> 2)),
1536 (([2,1,2], Res), (a \<up> 2 + - 1 * (a * b) + a * b + - 1 * b \<up> 2) /
1537 (a \<up> 2 + - 2 * (a * b) + - 1 \<up> 2 * b \<up> 2)),
1538 (([2,1,3], Res), (a \<up> 2 + - 1 * (a * b) + a * b + - 1 * b \<up> 2) /
1539 (a \<up> 2 + - 2 * (a * b) + (- 1 * b) \<up> 2)),
1540 (([2,1,4], Res), (a * a + - 1 * (a * b) + a * b + - 1 * b \<up> 2) /
1541 (a \<up> 2 + - 2 * (a * b) + (- 1 * b) \<up> 2)),
1542 (([2,1,5], Res), (a * a + - 1 * (a * b) + a * b + - 1 * (b * b)) /
1543 (a \<up> 2 + - 2 * (a * b) + (- 1 * b) \<up> 2)),
1544 (([2,1,6], Res), (a * a + - 1 * (a * b) + a * b + - 1 * (b * b)) /
1545 (a \<up> 2 + - 1 * (2 * (a * b)) + (- 1 * b) \<up> 2)),
1546 (([2,1,7], Res), (a * a + a * (- 1 * b) + (b * a + b * (- 1 * b))) /
1547 (a \<up> 2 + 2 * (a * (- 1 * b)) + (- 1 * b) \<up> 2)),
1548 (([2,1,8], Res), (a * a + a * (- 1 * b) + (b * a + b * (- 1 * b))) /
1549 (a \<up> 2 + 2 * a * (- 1 * b) + (- 1 * b) \<up> 2)),
1550 (([2,1,9], Res), (a * (a + - 1 * b) + (b * a + b * (- 1 * b))) /
1551 (a \<up> 2 + 2 * a * (- 1 * b) + (- 1 * b) \<up> 2)),
1552 (([2,1,10], Res), (a * (a + - 1 * b) + b * (a + - 1 * b)) /
1553 (a \<up> 2 + 2 * a * (- 1 * b) + (- 1 * b) \<up> 2)),
1554 (([2,1,11], Res), (a + b) * (a + - 1 * b) / (a \<up> 2 + 2 * a * (- 1 * b) + (- 1 * b) \<up> 2)),
1555 (([2,1,12], Res), (a + b) * (a + - 1 * b) / ((a + - 1 * b) * (a + - 1 * b))),
1556 (([2,1,13], Res), (a + b) / (a + - 1 * b)),
1557 (([2,1], Res), (a + b) / (a + - 1 * b)),
1558 (([2], Res), (a + b) / (a + - 1 * b)),
1559 (([], Res), (a + b) / (a + - 1 * b))]
1561 val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*);
1562 if length newnds = 13 then () else error "rational.sml: interSteps cancel_p rev_rew_p";
1564 val p = ([2,1,9],Res);
1566 val (_, tac, _) = ME_Misc.pt_extract (pt, p);
1567 case tac of SOME (Rewrite ("sym_distrib_left", _)) => ()
1568 | _ => error "rational.sml: getTactic, sym_real_plus_binom_times1";
1569 \\----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)*)
1572 "-------- investigate rulesets for cancel_p ----------------------------------";
1573 "-------- investigate rulesets for cancel_p ----------------------------------";
1574 "-------- investigate rulesets for cancel_p ----------------------------------";
1575 val thy = @{theory "Rational"};
1576 val t = TermC.str2term "(a \<up> 2 + - 1*b \<up> 2) / (a \<up> 2 + - 2*a*b + b \<up> 2)";
1577 val tt = TermC.str2term "(1 * a + 1 * b) * (1 * a + - 1 * b)"(*numerator only*);
1579 "----- with rewrite_set_";
1580 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
1581 if UnparseC.term tt'= "a \<up> 2 + - 1 * b \<up> 2" then () else error "rls chancel_p 1";
1582 val tt = TermC.str2term "((1 * a + - 1 * b) * (1 * a + - 1 * b))"(*denominator only*);
1583 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
1584 if UnparseC.term tt' = "a \<up> 2 + - 2 * a * b + b \<up> 2" then () else error "rls chancel_p 2";
1586 "----- with Derive.do_one; WN1130912 not investigated further, will be discontinued";
1587 val SOME (tt, _) = factout_p_ thy t;
1588 if UnparseC.term tt = "(a + b) * (a + - 1 * b) / ((a + - 1 * b) * (a + - 1 * b))"
1589 then () else error "rls chancel_p 3";
1591 "--- with simpler ruleset";
1592 val {rules, rew_ord= (_, ro), ...} = Rule_Set.rep (assoc_rls "rev_rew_p");
1593 val der = Derive.do_one thy Atools_erls rules ro NONE tt;
1594 if length der = 12 then () else error "WN1130912 rls chancel_p 4";
1595 (*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
1597 (*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*)
1598 "...,(- 1 * b \<up> 2 + a \<up> 2) / (- 2 * (a * b) + a \<up> 2 + (- 1 * b) \<up> 2) ]";
1599 (*default_print_depth 99;*) map (Rule.to_string o #2) der; (*default_print_depth 3;*)
1600 (*default_print_depth 99;*) map (UnparseC.term o #1 o #3) der; (*default_print_depth 3;*)
1602 val der = Derive.do_one thy Atools_erls rules ro NONE
1603 (TermC.str2term "(1 * a + 1 * b) * (1 * a + - 1 * b)");
1604 (*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
1606 val {rules, rew_ord=(_,ro),...} = Rule_Set.rep (assoc_rls "rev_rew_p");
1607 val der = Derive.do_one thy Atools_erls rules ro NONE
1608 (TermC.str2term "(1 * a + - 1 * b) * (1 * a + - 1 * b)");
1609 (*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
1610 (*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*)
1611 (*WN060829 ...postponed*)
1614 "-------- fun eval_get_denominator -------------------------------------------";
1615 "-------- fun eval_get_denominator -------------------------------------------";
1616 "-------- fun eval_get_denominator -------------------------------------------";
1617 val thy = @{theory Isac_Knowledge};
1618 val t = Thm.term_of (the (TermC.parse thy "get_denominator ((a +x)/b)"));
1619 val SOME (_, t') = eval_get_denominator "" 0 t thy;
1620 if UnparseC.term t' = "get_denominator ((a + x) / b) = b"
1621 then () else error "get_denominator ((a + x) / b) = b"
1624 "-------- several errpats in complicated term --------------------------------";
1625 "-------- several errpats in complicated term --------------------------------";
1626 "-------- several errpats in complicated term --------------------------------";
1627 (*WN12xxxx TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one
1628 WN130912: kept this test, although not clear what for*)
1630 CalcTree [(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"],
1631 ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1634 autoCalculate 1 CompleteCalc;
1635 val ((pt, p), _) = get_calc 1;
1636 (*Test_Tool.show_pt pt;
1638 (([], Frm), Simplify ((5 * b + 25) / (a \<up> 2 - b \<up> 2) * (a - b) / (5 * b))),
1639 (([1], Frm), (5 * b + 25) / (a \<up> 2 - b \<up> 2) * (a - b) / (5 * b)),
1640 (([1], Res), (5 * b + 25) / (a \<up> 2 + - 1 * b \<up> 2) * (a + - 1 * b) / (5 * b)),
1641 (([2], Res), (5 * b + 25) * (a + - 1 * b) / (a \<up> 2 + - 1 * b \<up> 2) / (5 * b)),
1642 (([3], Res), (25 * a + - 25 * b + 5 * (a * b) + -5 * b \<up> 2) / (a \<up> 2 + - 1 * b \<up> 2) /
1644 (([4], Res), (25 + 5 * b) / (a + b) / (5 * b)),
1645 (([5], Res), (25 + 5 * b) / ((a + b) * (5 * b))),
1646 (([6], Res), (25 + 5 * b) / (5 * (a * b) + 5 * b \<up> 2)),
1647 (([7], Res), (5 + b) / (a * b + b \<up> 2)),
1648 (([], Res), (5 + b) / (a * b + b \<up> 2))] *)
1651 "-------- WN1309xx non-terminating rls norm_Rational -------------------------";
1652 "-------- WN1309xx non-terminating rls norm_Rational -------------------------";
1653 "-------- WN1309xx non-terminating rls norm_Rational -------------------------";
1654 (*------- Schalk I, p.70 Nr. 480b; a/b : c/d translated to a/b * d/c*)
1655 val t = TermC.str2term
1656 ("((12*x*y / (9*x \<up> 2 - y \<up> 2)) / (1 / (3*x - y) \<up> 2 - 1 / (3*x + y) \<up> 2)) * " ^
1657 "((1/(x - 5*y) \<up> 2 - 1/(x + 5*y) \<up> 2) / (20*x*y / (x \<up> 2 - 25*y \<up> 2)))");
1659 (*1st factor separately simplified *)
1660 val t = TermC.str2term "((12*x*y / (9*x \<up> 2 - y \<up> 2)) / (1 / (3*x - y) \<up> 2 - 1 / (3*x + y) \<up> 2))";
1661 val SOME (t', _) = rewrite_set_ thy false norm_Rational t;
1662 if UnparseC.term t' = "(- 9 * x \<up> 2 + y \<up> 2) / - 1" then () else error "Nr. 480b lhs changed";
1663 (*2nd factor separately simplified *)
1664 val t = TermC.str2term "((1/(x - 5*y) \<up> 2 - 1/(x + 5*y) \<up> 2) / (20*x*y / (x \<up> 2 - 25*y \<up> 2)))";
1665 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1666 if UnparseC.term t' = "- 1 / (- 1 * x \<up> 2 + 25 * y \<up> 2)" then () else error "Nr. 480b rhs changed";
1668 "-------- Schalk I, p.70 Nr. 477a: terms are exploding ?!?";
1669 val t = TermC.str2term ("b*y/(b - 2*y)/((b \<up> 2 - y \<up> 2)/(b+2*y)) /" ^
1670 "(b \<up> 2*y + b*y \<up> 2) * (a+x) \<up> 2 / ((b \<up> 2 - 4*y \<up> 2) * (a+2*x) \<up> 2)");
1671 (*val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
1673 ### rls: cancel_p on: (a \<up> 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \<up> 2 * y)) /
1675 ((b \<up> 2 + - 1 * y \<up> 2) / (b + 2 * y)) /
1676 (b \<up> 2 * y + b * y \<up> 2) /
1677 (a \<up> 2 * b \<up> 2 + -4 * (a \<up> 2 * y \<up> 2) + 4 * (a * (b \<up> 2 * x)) +
1678 - 16 * (a * (x * y \<up> 2)) +
1679 4 * (b \<up> 2 * x \<up> 2) +
1680 - 16 * (x \<up> 2 * y \<up> 2))
1681 exception Div raised
1684 val t = TermC.str2term
1685 ("(a \<up> 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \<up> 2 * y)) /" ^
1687 "((b \<up> 2 + - 1 * y \<up> 2) / (b + 2 * y)) /" ^
1688 "(b \<up> 2 * y + b * y \<up> 2) /" ^
1689 "(a \<up> 2 * b \<up> 2 + -4 * (a \<up> 2 * y \<up> 2) + 4 * (a * (b \<up> 2 * x)) +" ^
1690 "- 16 * (a * (x * y \<up> 2)) +" ^
1691 "4 * (b \<up> 2 * x \<up> 2) +" ^
1692 "- 16 * (x \<up> 2 * y \<up> 2))");
1693 NONE = cancel_p_ thy t;
1696 (*------- Schalk I, p.70 Nr. 476b in 2003 this worked using 10 sec. *)
1697 val t = TermC.str2term
1698 ("((a \<up> 2 - b \<up> 2)/(2*a*b) + 2*a*b/(a \<up> 2 - b \<up> 2)) / ((a \<up> 2 + b \<up> 2)/(2*a*b) + 1) / " ^
1699 "((a \<up> 2 + b \<up> 2) \<up> 2 / (a + b) \<up> 2)");
1700 (* Rewrite.trace_on := true; (*true false*)
1701 rewrite_set_ thy false norm_Rational t;
1703 #### rls: cancel_p on: (2 * (a \<up> 7 * b) + 4 * (a \<up> 6 * b \<up> 2) + 6 * (a \<up> 5 * b \<up> 3) +
1704 8 * (a \<up> 4 * b \<up> 4) +
1705 6 * (a \<up> 3 * b \<up> 5) +
1706 4 * (a \<up> 2 * b \<up> 6) +
1707 2 * (a * b \<up> 7)) /
1708 (2 * (a \<up> 9 * b) + 4 * (a \<up> 8 * b \<up> 2) +
1709 2 * (2 * (a \<up> 7 * b \<up> 3)) +
1710 4 * (a \<up> 6 * b \<up> 4) +
1711 -4 * (a \<up> 4 * b \<up> 6) +
1712 -4 * (a \<up> 3 * b \<up> 7) +
1713 -4 * (a \<up> 2 * b \<up> 8) +
1714 - 2 * (a * b \<up> 9))
1716 if UnparseC.term t = "1 / (a \<up> 2 + - 1 * b \<up> 2)" then ()
1717 else error "rational.sml: diff.behav. in norm_Rational_mg 49";
1720 "-------- Schalk I, p.70 Nr. 480a: terms are exploding ?!?";
1721 val t = TermC.str2term ("(1/x + 1/y + 1/z) / (1/x - 1/y - 1/z) / " ^
1722 "(2*x \<up> 2 / (x \<up> 2 - z \<up> 2) / (x / (x + z) + x / (x - z)))");
1723 (* Rewrite.trace_on := true; (*true false*)
1724 rewrite_set_ thy false norm_Rational t;
1726 #### rls: cancel_p on: (2 * (x \<up> 6 * (y \<up> 2 * z)) + 2 * (x \<up> 6 * (y * z \<up> 2)) +
1727 2 * (x \<up> 5 * (y \<up> 2 * z \<up> 2)) +
1728 - 2 * (x \<up> 4 * (y \<up> 2 * z \<up> 3)) +
1729 - 2 * (x \<up> 4 * (y * z \<up> 4)) +
1730 - 2 * (x \<up> 3 * (y \<up> 2 * z \<up> 4))) /
1731 (- 2 * (x \<up> 6 * (y \<up> 2 * z)) + - 2 * (x \<up> 6 * (y * z \<up> 2)) +
1732 2 * (x \<up> 5 * (y \<up> 2 * z \<up> 2)) +
1733 2 * (x \<up> 4 * (y \<up> 2 * z \<up> 3)) +
1734 2 * (x \<up> 4 * (y * z \<up> 4)) +
1735 - 2 * (x \<up> 3 * (y \<up> 2 * z \<up> 4)))
1738 "-------- Schalk I, p.60 Nr. 215d: terms are exploding, internal loop does not terminate";
1739 val t = TermC.str2term "(a-b) \<up> 3 * (x+y) \<up> 4 / ((x+y) \<up> 2 * (a-b) \<up> 5)";
1740 (* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt:
1742 val t = TermC.str2term "(a-b) \<up> 3 * (x+y) \<up> 4";
1743 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1745 "a \<up> 3 * x \<up> 4 + 4 * a \<up> 3 * x \<up> 3 * y +6 * a \<up> 3 * x \<up> 2 * y \<up> 2 +4 * a \<up> 3 * x * y \<up> 3 +a \<up> 3 * y \<up> 4 +-3 * a \<up> 2 * b * x \<up> 4 +- 12 * a \<up> 2 * b * x \<up> 3 * y +- 18 * a \<up> 2 * b * x \<up> 2 * y \<up> 2 +- 12 * a \<up> 2 * b * x * y \<up> 3 +-3 * a \<up> 2 * b * y \<up> 4 +3 * a * b \<up> 2 * x \<up> 4 +12 * a * b \<up> 2 * x \<up> 3 * y +18 * a * b \<up> 2 * x \<up> 2 * y \<up> 2 +12 * a * b \<up> 2 * x * y \<up> 3 +3 * a * b \<up> 2 * y \<up> 4 +- 1 * b \<up> 3 * x \<up> 4 +-4 * b \<up> 3 * x \<up> 3 * y +-6 * b \<up> 3 * x \<up> 2 * y \<up> 2 +-4 * b \<up> 3 * x * y \<up> 3 +- 1 * b \<up> 3 * y \<up> 4";
1746 val t = TermC.str2term "((x+y) \<up> 2 * (a-b) \<up> 5)";
1747 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1749 "a \<up> 5 * x \<up> 2 + 2 * a \<up> 5 * x * y + a \<up> 5 * y \<up> 2 +-5 * a \<up> 4 * b * x \<up> 2 +- 10 * a \<up> 4 * b * x * y +-5 * a \<up> 4 * b * y \<up> 2 +10 * a \<up> 3 * b \<up> 2 * x \<up> 2 +20 * a \<up> 3 * b \<up> 2 * x * y +10 * a \<up> 3 * b \<up> 2 * y \<up> 2 +- 10 * a \<up> 2 * b \<up> 3 * x \<up> 2 +- 20 * a \<up> 2 * b \<up> 3 * x * y +- 10 * a \<up> 2 * b \<up> 3 * y \<up> 2 +5 * a * b \<up> 4 * x \<up> 2 +10 * a * b \<up> 4 * x * y +5 * a * b \<up> 4 * y \<up> 2 +- 1 * b \<up> 5 * x \<up> 2 +- 2 * b \<up> 5 * x * y +- 1 * b \<up> 5 * y \<up> 2";
1751 anscheinend macht dem Rechner das Krzen diese Bruches keinen Spass mehr ...*)
1753 "-------- Schalk I, p.70 Nr. 480b: terms are exploding, Rewrite.trace_on stops at";
1754 val t = TermC.str2term ("((12*x*y/(9*x \<up> 2 - y \<up> 2))/" ^
1755 "(1/(3*x - y) \<up> 2 - 1/(3*x + y) \<up> 2)) *" ^
1756 "(1/(x - 5*y) \<up> 2 - 1/(x + 5*y) \<up> 2)/" ^
1757 "(20*x*y/(x \<up> 2 - 25*y \<up> 2))");
1758 (*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1760 #### rls: cancel_p on: (19440 * (x \<up> 8 * y \<up> 2) + -490320 * (x \<up> 6 * y \<up> 4) +
1761 108240 * (x \<up> 4 * y \<up> 6) +
1762 -6000 * (x \<up> 2 * y \<up> 8)) /
1763 (2160 * (x \<up> 8 * y \<up> 2) + - 108240 * (x \<up> 6 * y \<up> 4) +
1764 1362000 * (x \<up> 4 * y \<up> 6) +
1765 - 150000 * (x \<up> 2 * y \<up> 8))