1 (* Title: tests for rationals
3 Use is subject to license terms.
6 "-----------------------------------------------------------------------------";
7 "-----------------------------------------------------------------------------";
8 "table of contents -----------------------------------------------------------";
9 "-----------------------------------------------------------------------------";
10 "-------- fun poly_of_term ---------------------------------------------------";
11 "-------- fun is_poly --------------------------------------------------------";
12 "-------- fun term_of_poly ---------------------------------------------------";
13 "-------- integration lev.1 fun factout_p_ -----------------------------------";
14 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
15 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
16 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
17 "Rfuns-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
18 "Rfuns-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
19 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
20 "Rfuns-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
21 "----------- rewrite_set_ Partial_Fractions norm_Rational --------------------------------------";
22 "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
23 "----------- fun cancel_p with Const AA --------------------------------------------------------";
24 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
25 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
26 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
27 "Rfuns-------- reverse rewrite ----------------------------------------------------";
28 "Rfuns-------- 'reverse-ruleset' cancel_p -----------------------------------------";
29 "-------- investigate rls norm_Rational --------------------------------------";
30 "-------- examples: rls norm_Rational ----------------------------------------";
31 "-------- rational numerals --------------------------------------------------";
32 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
33 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
34 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
35 "-------- examples common denominator and multiplication from: Schalk --------";
36 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
37 "-------- me Schalk I No.186 -------------------------------------------------";
38 "-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
39 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
40 "-------- investigate rulesets for cancel_p ----------------------------------";
41 "-------- fun eval_get_denominator -------------------------------------------";
42 "-------- several errpats in complicated term --------------------------------";
43 "-------- WN1309xx non-terminating rls norm_Rational -------------------------";
44 "-----------------------------------------------------------------------------";
45 "-----------------------------------------------------------------------------";
48 "-------- fun poly_of_term ---------------------------------------------------";
49 "-------- fun poly_of_term ---------------------------------------------------";
50 "-------- fun poly_of_term ---------------------------------------------------";
51 val thy = @{theory Partial_Fractions};
52 val ctxt = Proof_Context.init_global @{theory}
53 val vs = TermC.vars_of (the (parseNEW ctxt "12 * x \<up> 3 * y \<up> 4 * z \<up> 6"));
55 if poly_of_term vs (TermC.str2term "12::real") = SOME [(12, [0, 0, 0])]
56 then () else error "poly_of_term 1 changed";
58 if poly_of_term vs (TermC.str2term "x::real") = SOME [(1, [1, 0, 0])]
59 then () else error "poly_of_term 2 changed";
61 (*//---------------------------- removed error -----------------------------------------------\\*)
62 if poly_of_term vs (TermC.str2term "12 * x \<up> 3") = SOME [(12, [3, 0, 0])]
63 then () else error "poly_of_term 3 changed";
64 "~~~~~ fun poly_of_term , args:"; val (vs, t) =
65 (vs, (TermC.str2term "12 * x \<up> 3"));
67 monom_of_term vs (1, replicate (length vs) 0) t;(*poly malformed 1 with x \<up> 3*)
68 "~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const ("Groups.times_class.times", _) $ m1 $ m2)) =
69 (vs, (1, replicate (length vs) 0), t);
72 monom_of_term vs (c, es) m1;
73 "~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const ("Transcendental.powr", _) $ (t as Free _) $ (Const ("Num.numeral_class.numeral", _) $ num)) ) =
76 (*+*)(num |> HOLogic.dest_numeral |> list_update es (find_index (curry op = t) vs)) = [3, 0, 0];
78 if (c, num |> HOLogic.dest_numeral |> list_update es (find_index (curry op = t) vs)) = (12, [3, 0, 0])
79 then () else error "monom_of_term (powr): return value CHANGED";
80 (*\\---------------------------- removed error -----------------------------------------------//*)
82 if poly_of_term vs (TermC.str2term "12 * x \<up> 3 * y \<up> 4 * z \<up> 6") = SOME [(12, [3, 4, 6])]
83 then () else error "poly_of_term 4 changed";
85 if poly_of_term vs (TermC.str2term "1 + 2 * x \<up> 3 * y \<up> 4 * z \<up> 6 + y") =
86 SOME [(1, [0, 0, 0]), (1, [0, 1, 0]), (2, [3, 4, 6])]
87 then () else error "poly_of_term 5 changed";
89 (*poly_of_term is quite liberal:*)
90 (*the coefficient may be somewhere, the order of variables and the parentheses
91 within a monomial are arbitrary*)
92 if poly_of_term vs (TermC.str2term "y \<up> 4 * (x \<up> 3 * 12 * z \<up> 6)") = SOME [(12, [3, 4, 6])]
93 then () else error "poly_of_term 6 changed";
95 (*there may even be more than 1 coefficient:*)
96 if poly_of_term vs (TermC.str2term "2 * y \<up> 4 * (x \<up> 3 * 6 * z \<up> 6)") = SOME [(12, [3, 4, 6])]
97 then () else error "poly_of_term 7 changed";
99 (*the order and the parentheses within monomials are arbitrary:*)
100 if poly_of_term vs (TermC.str2term "2 * x \<up> 3 * y \<up> 4 * z \<up> 6 + (7 * y \<up> 8 + 1)")
101 = SOME [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 6])]
102 then () else error "poly_of_term 8 changed";
105 "-------- fun is_poly --------------------------------------------------------";
106 "-------- fun is_poly --------------------------------------------------------";
107 "-------- fun is_poly --------------------------------------------------------";
108 if is_poly (TermC.str2term "2 * x \<up> 3 * y \<up> 4 * z \<up> 6 + 7 * y \<up> 8 + 1")
109 then () else error "is_poly 1 changed";
110 if not (is_poly (TermC.str2term "2 * (x \<up> 3 * y \<up> 4 * z \<up> 6 + 7) * y \<up> 8 + 1"))
111 then () else error "is_poly 2 changed";
113 "-------- fun term_of_poly ---------------------------------------------------";
114 "-------- fun term_of_poly ---------------------------------------------------";
115 "-------- fun term_of_poly ---------------------------------------------------";
116 val expT = HOLogic.realT
117 val Free (_, baseT) = (hd o vars o TermC.str2term) "12 * x \<up> 3 * y \<up> 4 * z \<up> 6";
118 val p = [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 5])]
119 val vs = TermC.vars_of (the (parseNEW ctxt "12 * x \<up> 3 * y \<up> 4 * z \<up> 6"))
120 (*precondition for [(c, es),...]: legth es = length vs*)
122 if UnparseC.term (term_of_poly baseT expT vs p) = "1 + 7 * y \<up> 8 + 2 * x \<up> 3 * y \<up> 4 * z \<up> 5"
123 then () else error "term_of_poly 1 changed";
125 "-------- integration lev.1 fun factout_p_ -----------------------------------";
126 "-------- integration lev.1 fun factout_p_ -----------------------------------";
127 "-------- integration lev.1 fun factout_p_ -----------------------------------";
128 val t = TermC.str2term "(x \<up> 2 + -1*y \<up> 2) / (x \<up> 2 + -1*x*y)"
129 val SOME (t', asm) = factout_p_ thy t;
130 if UnparseC.term t' = "(x + y) * (x + -1 * y) / (x * (x + -1 * y))"
131 then () else error ("factout_p_ term 1 changed: " ^ UnparseC.term t')
133 if UnparseC.terms asm = "[\"x \<noteq> 0\",\"x + -1 * y \<noteq> 0\"]"
134 then () else error "factout_p_ asm 1 changed"
136 val t = TermC.str2term "nothing + to_cancel ::real";
137 if NONE = factout_p_ thy t then () else error "factout_p_ doesn't report non-applicable";
139 val t = TermC.str2term "((3 * x \<up> 2 + 6 *x + 3) / (2*x + 2))";
140 val SOME (t', asm) = factout_p_ thy t;
141 if UnparseC.term t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso
142 UnparseC.terms asm = "[\"1 + x \<noteq> 0\"]"
143 then () else error "factout_p_ 1 changed";
145 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
146 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
147 "-------- integration lev.1 fun cancel_p_ ------------------------------------";
148 val t = TermC.str2term "(x \<up> 2 + -1*y \<up> 2) / (x \<up> 2 + -1*x*y)"
149 val SOME (t', asm) = cancel_p_ thy t;
150 if (UnparseC.term t', UnparseC.terms asm) = ("(x + y) / x", "[\"x \<noteq> 0\"]")
151 then () else error ("cancel_p_ (t', asm) 1 changed: " ^ UnparseC.term t')
153 val t = TermC.str2term "nothing + to_cancel ::real";
154 if NONE = cancel_p_ thy t then () else error "cancel_p_ doesn't report non-applicable";
156 val t = TermC.str2term "((3 * x \<up> 2 + 6 *x + 3) / (2*x + 2))";
157 val SOME (t', asm) = cancel_p_ thy t;
158 if UnparseC.term t' = "(3 + 3 * x) / 2" andalso UnparseC.terms asm = "[]"
159 then () else error "cancel_p_ 1 changed";
161 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
162 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
163 "-------- integration lev.1 fun common_nominator_p_ --------------------------";
164 val t = TermC.str2term ("y / (a*x + b*x + c*x) " ^
168 val SOME (t', asm) = common_nominator_p_ thy t;
169 if UnparseC.term t' =
170 ("y * y / (x * ((a + b + c) * y)) " ^
171 (* n1 *d2'/ (c'* ( d1' *d2')) *)
172 "+ a * (a + b + c) / (x * ((a + b + c) * y))")
173 (* n2 * d1' / (c'* ( d1' *d2')) *)
174 then () else error "common_nominator_p_ term 1 changed";
175 if UnparseC.terms asm = "[\"a + b + c \<noteq> 0\",\"y \<noteq> 0\",\"x \<noteq> 0\"]"
176 then () else error "common_nominator_p_ asm 1 changed"
178 "-------- example in mail Nipkow";
179 val t = TermC.str2term "x/(x \<up> 2 + -1*y \<up> 2) + y/(x \<up> 2 + -1*x*y)";
180 val SOME (t', asm) = common_nominator_p_ thy t;
181 if UnparseC.term t' = "x * x / " ^
182 "((x + -1 * y) * ((x + y) * x))" ^
185 "((x + -1 * y) * ((x + y) * x))"
186 then () else error "common_nominator_p_ term 2 changed"
188 if UnparseC.terms asm = "[\"x + y \<noteq> 0\",\"x \<noteq> 0\",\"x + -1 * y \<noteq> 0\"]"
189 then () else error "common_nominator_p_ asm 2 changed"
191 "-------- example: applicable tested by SML code";
192 val t = TermC.str2term "nothing / to_add";
193 if NONE = common_nominator_p_ thy t then () else error "common_nominator_p_ term 3 changed";
195 val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
196 val SOME (t', asm) = common_nominator_p_ thy t;
197 if UnparseC.term t' =
198 "(x + -1) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(x + 1) * (1 + x) / ((1 + x) * (-1 + x))"
199 andalso UnparseC.terms asm = "[\"1 + x \<noteq> 0\",\"-1 + x \<noteq> 0\"]"
200 then () else error "common_nominator_p_ 3 changed";
202 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
203 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
204 "-------- integration lev.1 fun add_fraction_p_ ------------------------------";
205 val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
206 val SOME (t', asm) = add_fraction_p_ thy t;
207 if UnparseC.term t' = "(2 + 2 * x \<up> 2) / (-1 + x \<up> 2)"
208 then () else error "add_fraction_p_ 3 changed";
210 if UnparseC.terms asm = "[\"-1 + x \<up> 2 \<noteq> 0\"]"
211 then () else error "add_fraction_p_ 3 changed";
213 val t = TermC.str2term "nothing / to_add";
214 if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ term 3 changed";
216 val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
217 val SOME (t', asm) = add_fraction_p_ thy t;
218 if UnparseC.term t' = "(2 + 2 * x \<up> 2) / (-1 + x \<up> 2)" andalso
219 UnparseC.terms asm = "[\"-1 + x \<up> 2 \<noteq> 0\"]"
220 then () else error "add_fraction_p_ 3 changed";
222 "-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
223 "-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
224 "-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
225 (* trace down until prepats are evaluated
226 (which does not to work, because substitution is not done -- compare rew_sub!);
227 keep this sequence for the case, factout_p, cancel_p, common_nominator_p, add_fraction_p
228 (again) get prepat = [] changed to <>[]. *)
229 val t = TermC.str2term "(x \<up> 2 + -1*y \<up> 2) / (x \<up> 2 + -1*x*y)";
231 (*rewrite_set_ @{theory Isac_Knowledge} true cancel t = NONE; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
232 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (thy, false, cancel_p, t);
233 "~~~~~ fun rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
234 (thy, 1, bool, [], rls, term);
235 (*val (t', asm, rew) = app_rev thy (i+1) rrls t; rew = false!!!!!!!!!!!!!!!!!!!!!*)
236 "~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
237 fun chk_prepat thy erls [] t = true
238 | chk_prepat thy erls prepat t =
240 fun chk (pres, pat) =
242 val subst: Type.tyenv * Envir.tenv =
243 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
245 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
246 end) handle Pattern.MATCH => false
247 fun scan_ f [] = false (*scan_ NEVER called by []*)
248 | scan_ f (pp::pps) =
249 if f pp then true else scan_ f pps;
250 in scan_ chk prepat end;
251 (* apply the normal_form of a rev-set *)
252 fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
253 if chk_prepat thy erls prepat t
254 then ((*tracing("### app_rev': t = "^UnparseC.term t);*) normal_form t)
256 (* val opt = app_rev' thy rrls t ..NONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
257 "~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
259 (* chk_prepat thy erls prepat t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
260 (* app_sub thy i rrls t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
261 "~~~~~ fun chk_prepat, args:"; val (thy, erls, prepat, t) = (thy, erls, prepat, t);
262 fun chk (pres, pat) =
264 val subst: Type.tyenv * Envir.tenv =
265 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
267 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
268 end) handle Pattern.MATCH => false
269 fun scan_ f [] = false (*scan_ NEVER called by []*)
270 | scan_ f (pp::pps) =
271 if f pp then true else scan_ f pps;
273 (*========== inhibit exn WN130823: prepat is empty ====================================
274 (* scan_ chk prepat = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
275 "~~~~~ fun , args:"; val (f, (pp::pps)) = (chk, prepat);
277 val ([t1, t2], t) = pp;
278 UnparseC.term t1 = "?r is_expanded";
279 UnparseC.term t2 = "?s is_expanded";
280 UnparseC.term t = "?r / ?s";
281 (* f pp = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
282 "~~~~~ fun chk, args:"; val (pres, pat) = (pp);
283 val subst: Type.tyenv * Envir.tenv =
284 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
286 ({}, {(("r", 0), ("real", Var (("r", 0), "real"))),
287 (("s", 0), ("real", Var (("s", 0), "real")))}*)
289 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
290 "~~~~~ fun eval__true, args:"; val (thy, i, asms, bdv, rls) =
291 (thy, (i + 1), (map (Envir.subst_term subst) pres), [], erls);
292 UnparseC.terms asms; (* = "[\"?r is_expanded\",\"?s is_expanded\"]"*)
293 asms = [@{term True}] orelse asms = []; (* = false*)
294 asms = [@{term False}] ; (* = false*)
295 "~~~~~ fun chk, args:"; val (indets, (a::asms)) = ([], asms);
296 bdv (*= []: _a list*);
297 val bdv : (term * term) list = [];
298 rewrite__set_ thy (i+1) false;
299 UnparseC.term a = "?r is_expanded"; (*hier m"usste doch der Numerator eingesetzt sein ??????????????*)
300 val SOME (Const ("HOL.False", _), []) = rewrite__set_ thy (i+1) false bdv rls a
301 ============ inhibit exn WN130823: prepat is empty ===================================*)
303 "-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
304 "-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
305 "-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
306 val t = TermC.str2term "(12 * x * y) / (8 * y \<up> 2 )";
307 (* "-------- example 187a": exception Div raised...
308 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
309 val t = TermC.str2term "(8 * x \<up> 2 * y * z ) / (18 * x * y \<up> 2 * z )";
310 (* "-------- example 187b": doesn't terminate...
311 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
312 val t = TermC.str2term "(9 * x \<up> 5 * y \<up> 2 * z \<up> 4) / (15 * x \<up> 6 * y \<up> 3 * z )";
313 (* "-------- example 187c": doesn't terminate...
314 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
315 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (@{theory Isac_Knowledge}, false, cancel_p, t);
316 (* WN130827: exception Div raised...
317 rewrite__set_ thy 1 bool [] rls term
319 "~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
320 (thy, 1, bool, [], rls, term);
321 (* WN130827: exception Div raised...
322 val (t', asm, rew) = app_rev thy (i+1) rrls t
324 "~~~~~ fun app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
325 (* WN130827: exception Div raised...
326 val opt = app_rev' thy rrls t
328 "~~~~~ fun app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
330 chk_prepat thy erls prepat t = true;
331 (* WN130827: exception Div raised...
334 (* lookup Rational.thy, cancel_p: normal_form = cancel_p_ thy*)
335 "~~~~~ fun cancel_p_, args:"; val (t) = (t);
336 val opt = check_fraction t;
337 val SOME (numerator, denominator) = opt
338 val vs = TermC.vars_of t
339 val baseT = type_of numerator
340 val expT = HOLogic.realT
341 val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator);
342 (*"-------- example 187a": exception Div raised...
343 val a = [(12, [1, 1])]: poly
344 val b = [(8, [0, 2])]: poly
345 val ((a', b'), c) = gcd_poly a b
347 (* "-------- example 187b": doesn't terminate...
348 val a = [(8, [2, 1, 1])]: poly
349 val b = [(18, [1, 2, 1])]: poly
350 val ((a', b'), c) = gcd_poly a b
352 (* "-------- example 187c": doesn't terminate...
353 val a = [(9, [5, 2, 4])]: poly
354 val b = [(15, [6, 3, 1])]: poly
355 val ((a', b'), c) = gcd_poly a b
358 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
359 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
360 "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
361 val t = TermC.str2term "(x \<up> 2 - 4)*(3 - y) / ((y \<up> 2 - 9)*(2+x))";
362 Rewrite.trace_on := false (*true false*);
363 (* trace stops with ...: (and then jEdit hangs)..
364 rewrite_set_ thy false norm_Rational t;
366 ### rls: cancel_p on: (-12 + 4 * y + 3 * x \<up> 2 + -1 * (x \<up> 2 * y)) /
367 (-18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)
369 val t = TermC.str2term (*copy from above: "::real" is not required due to " \<up> "*)
370 ("(-12 + 4 * y + 3 * x \<up> 2 + -1 * (x \<up> 2 * y)) /" ^
371 "(-18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)");
373 exception Div raised*)
375 "~~~~~ fun cancel_p_, args:"; val (t) = (t);
376 val opt = check_fraction t;
377 val SOME (numerator, denominator) = opt
378 val vs = TermC.vars_of t
379 val baseT = type_of numerator
380 val expT = HOLogic.realT;
381 (*default_print_depth 3; 999*)
382 val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator);
383 (*default_print_depth 3; 999*)
384 (* does not terminate instead of returning ?:
385 val ((a', b'), c) = gcd_poly a b
386 val a = [(~12, [0, 0]), (3, [2, 0]), (4, [0, 1]), (~1, [2, 1])]: poly
387 val b = [(~18, [0, 0]), (~9, [1, 0]), (2, [0, 2]), (1, [1, 2])]: poly
390 "-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
391 "-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
392 "-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
393 val thy = @{theory Isac_Knowledge};
394 "----- SK060904-2a non-termination of add_fraction_p_";
395 val t = TermC.str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^
396 " (-1 * a + b * x) / (a + b * x) ");
397 (* rewrite_set_ thy false norm_Rational t
398 exception Div raised*)
399 (* rewrite_set_ thy false add_fractions_p t;
400 exception Div raised*)
401 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) =
402 (@{theory Isac_Knowledge}, false, add_fractions_p, t);
403 "~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
404 (thy, 1, bool, [], rls, term);
405 (* app_rev thy (i+1) rrls t;
406 exception Div raised*)
407 "~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
408 fun chk_prepat thy erls [] t = true
409 | chk_prepat thy erls prepat t =
411 fun chk (pres, pat) =
413 val subst: Type.tyenv * Envir.tenv =
414 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
416 snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
417 end) handle Pattern.MATCH => false
418 fun scan_ f [] = false (*scan_ NEVER called by []*)
419 | scan_ f (pp::pps) =
420 if f pp then true else scan_ f pps;
421 in scan_ chk prepat end;
422 (* apply the normal_form of a rev-set *)
423 fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
424 if chk_prepat thy erls prepat t
425 then ((*tracing("### app_rev': t = "^UnparseC.term t);*) normal_form t)
427 (* val opt = app_rev' thy rrls t;
428 exception Div raised*)
429 (* val opt = app_rev' thy rrls t;
430 exception Div raised*)
431 "~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
433 chk_prepat thy erls prepat t = true = true;
435 exception Div raised*)
436 (* lookup Rational.thy, val add_fractions_p: normal_form = add_fraction_p_ thy*)
437 (*add_fraction_p_ thy t
438 exception Div raised*)
439 "~~~~~ fun add_fraction_p_, args:"; val ((_: theory), t) = (thy, t);
440 val SOME ((n1, d1), (n2, d2)) = check_frac_sum t;
441 UnparseC.term n1; UnparseC.term d1; UnparseC.term n2; UnparseC.term d2;
442 val vs = TermC.vars_of t;
443 (*default_print_depth 3; 999*)
444 val (SOME _, SOME a, SOME _, SOME b) =
445 (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2);
446 (*default_print_depth 3; 999*)
448 val a = [(1, [1, 0, 0]), (~1, [0, 1, 1])]: poly
449 val b = [(1, [1, 0, 0]), (1, [0, 1, 1])]: poly
450 val ((a', b'), c) = gcd_poly a b
453 "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
454 "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
455 "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
456 val thy = @{theory Isac_Knowledge(*Partial_Fractions*)}
457 val ctxt = Proof_Context.init_global thy;
459 (*---------- (1) with Free A, B ----------------------------------------------------------------*)
460 val t = (the o (parseNEW ctxt)) "3 = A / 2 + A / 4 + (B / 2 + -1 * B / (2::real))";
461 (* required for applying thms in rewriting \<up> ^*)
462 (* we get details from here..*)
464 Rewrite.trace_on := false;
465 val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t;
466 Rewrite.trace_on := false;
468 add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
469 (* |||||||||||||||||||||||||||||||||||| *)
471 val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 1 GUESS 1 GUESS 1 GUESS 1 *)
472 "A / 2 + A / 4 + (B / 2 + -1 * B / (2::real))";
473 "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
474 val NONE = (*case*) check_frac_sum t (*of*)
477 add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
478 (* |||||||||||||||||||||||||||| *)
479 val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 2 GUESS 2 GUESS 2 GUESS 2 *)
480 "A / 4 + (B / 2 + -1 * B / (2::real))";
481 "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
482 val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*);
483 (*+*)if (UnparseC.term n1, UnparseC.term d1) = ("A" , "4") andalso
484 (*+*) (UnparseC.term n2, UnparseC.term d2) = ("B / 2 + -1 * B / 2", "1")
485 (*+*)then () else error "check_frac_sum (A / 4 + (B / 2 + -1 * B / (2::real))) changed";
487 val vs = TermC.vars_of t;
488 val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) =
489 (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*);
491 "~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1);
492 val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t];
493 (*+*)if xxx = 1 then () else error "monom_of_term changed"
495 "~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Free (id, _))) =
496 (vs, (1, replicate (length vs) 0), t);
497 case vs of [Free ("A", _), Free ("B", _)] =>
498 if c = 1 andalso id = "A"
499 then () else error "monom_of_term Free changed 1"
500 | _ => error "monom_of_term Free changed 2";
502 (*---------- (2) with Const AA, BB --------------------------------------------------------------*)
503 val t = (the o (parseNEW ctxt)) "3 = AA / 2 + AA / 4 + (BB / 2 + -1 * BB / 2)";
505 (* we get details from here..*)
507 Rewrite.trace_on := false;
508 val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t;
509 Rewrite.trace_on := false;
511 add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
512 (* |||||||||||||||||||||||||||||||||||| *)
513 val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *)
514 "AA / 2 + AA / 4 + (BB / 2 + -1 * BB / 2)";
515 "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
516 val NONE = (*case*) check_frac_sum t (*of*)
519 add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
520 (* |||||||||||||||||||||||||||| *)
521 val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *)
522 "AA / 4 + (BB / 2 + -1 * BB / 2)";
523 "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
524 val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*);
525 (*+*)if (UnparseC.term n1, UnparseC.term d1) = ("AA" , "4") andalso
526 (*+*) (UnparseC.term n2, UnparseC.term d2) = ("BB / 2 + -1 * BB / 2", "1")
527 (*+*)then () else error "check_frac_sum (AA / 4 + (BB / 2 + -1 * BB / 2)) changed";
529 val vs = TermC.vars_of t;
530 val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) =
531 (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*);
533 "~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1);
534 val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t];
535 (*+*)if xxx = 1 then () else error "monom_of_term changed"
537 "~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const (id, _))) =
538 (vs, (1, replicate (length vs) 0), t);
539 case vs of [Const ("Partial_Fractions.AA", _), Const ("Partial_Fractions.BB", _)] =>
540 if c = 1 andalso id = "Partial_Fractions.AA"
541 then () else error "monom_of_term Const changed 1"
542 | _ => error "monom_of_term Const changed 2";
544 "----------- fun cancel_p with Const AA --------------------------------------------------------";
545 "----------- fun cancel_p with Const AA --------------------------------------------------------";
546 "----------- fun cancel_p with Const AA --------------------------------------------------------";
547 val thy = @{theory Partial_Fractions};
548 val ctxt = Proof_Context.init_global @{theory}
549 val SOME t = TermC.parseNEW ctxt "2 * AA / 2"; (* Const ("Free ("AA", "real") *)
551 val SOME (t', _) = rewrite_set_ thy true cancel_p t;
553 Const ("Rings.divide_class.divide", _) $ Const ("Partial_Fractions.AA", _) $ Free ("1", _) => ()
554 | _ => error "WRONG rewrite_set_ cancel_p (2 * AA / 2) \<longrightarrow> AA changed";
556 "~~~~~ fun cancel_p , args:"; val (t) = (t);
557 val opt = check_fraction t
558 val SOME (numerator, denominator) = (*case*) opt (*of*);
560 if UnparseC.term numerator = "2 * AA" andalso UnparseC.term denominator = "2"
561 then () else error "check_fraction (2 * AA / 2) changed";
562 val vs = TermC.vars_of t;
564 [Const ("Partial_Fractions.AA", _)] => ()
565 | _ => error "rewrite_set_ cancel_p (2 * AA / 2) \<longrightarrow> AA/1 changed";
568 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
569 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
570 "-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
571 val thy = @{theory "Rational"};
573 val t = TermC.str2term "(2 + -3 * x) / 9";
574 if NONE = rewrite_set_ thy false cancel_p t then ()
575 else error "rewrite_set_ cancel_p must return NONE, if the term cannot be cancelled";
577 "-------- example 186a";
578 val t = TermC.str2term "(14 * x * y) / (x * y)";
579 is_expanded (TermC.str2term "14 * x * y");
580 is_expanded (TermC.str2term "x * y");
581 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
582 if (UnparseC.term t', UnparseC.terms asm) = ("14 / 1", "[]")
583 then () else error "rational.sml cancel Schalk 186a";
585 "-------- example 186b";
586 val t = TermC.str2term "(60 * a * b) / ( 15 * a * b )";
587 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
588 if (UnparseC.term t', UnparseC.terms asm) = ("4 / 1", "[]")
589 then () else error "rational.sml cancel Schalk 186b";
591 "-------- example 186c";
592 val t = TermC.str2term "(144 * a \<up> 2 * b * c) / (12 * a * b * c)";
593 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
594 if (UnparseC.term t', UnparseC.terms asm) = ("12 * a / 1", "[]")
595 then () else error "rational.sml cancel Schalk 186c";
597 (* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! exception Div raised !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
598 see --- fun rewrite_set_ downto fun gcd_poly ---
599 "-------- example 187a";
600 val t = TermC.str2term "(12 * x * y) / (8 * y \<up> 2 )";
601 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
602 if (UnparseC.term t', UnparseC.terms asm) = ("3 * x / (2 * y)", "[\"4 * y ~= 0\"]")
603 then () else error "rational.sml cancel Schalk 187a";
606 (* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
607 see --- fun rewrite_set_ downto fun gcd_poly ---
608 "-------- example 187b";
609 val t = TermC.str2term "(8 * x \<up> 2 * y * z ) / (18 * x * y \<up> 2 * z )";
610 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
611 if (UnparseC.term t', UnparseC.terms asm) = ("4 * x / (9 * y)", "[\"2 * (z * (y * x)) ~= 0\"]")
612 then () else error "rational.sml cancel Schalk 187b";
615 (* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
616 see --- fun rewrite_set_ downto fun gcd_poly ---
617 "-------- example 187c";
618 val t = TermC.str2term "(9 * x \<up> 5 * y \<up> 2 * z \<up> 4) / (15 * x \<up> 6 * y \<up> 3 * z )";
619 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
620 if (UnparseC.term t', UnparseC.terms asm) =
621 ("3 * z \<up> 3 / (5 * (y * x))", "[\"3 * (z * (y \<up> 2 * x \<up> 5)) ~= 0\"]")
622 then () else error "rational.sml cancel Schalk 187c";
625 "-------- example 188a";
626 val t = TermC.str2term "(-8 + 8 * x) / (-9 + 9 * x)";
627 is_expanded (TermC.str2term "8 * x + -8");
628 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
629 if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]")
630 then () else error "rational.sml cancel Schalk 188a";
632 val t = TermC.str2term "(8*((-1) + x))/(9*((-1) + x))";
633 val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
634 if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]")
635 then () else error "rational.sml cancel Schalk make_polynomial 1";
637 "-------- example 188b";
638 val t = TermC.str2term "(-15 + 5 * x) / (-18 + 6 * x)";
639 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
640 if (UnparseC.term t', UnparseC.terms asm) = ("5 / 6", "[]")
641 then () else error "rational.sml cancel Schalk 188b";
643 "-------- example 188c";
644 val t = TermC.str2term "(a + -1 * b) / (b + -1 * a)";
645 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
646 if (UnparseC.term t', UnparseC.terms asm) = ("-1 / 1", "[]")
647 then () else error "rational.sml cancel Schalk 188c";
649 is_expanded (TermC.str2term "a + -1 * b") = true;
650 val t = TermC.str2term "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
651 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
652 if (UnparseC.term t', UnparseC.terms asm) = ("(a + -1 * b) / (-1 * a + b)", "[]")
653 then () else error "rational.sml cancel Schalk make_polynomial 2";
655 "-------- example 190a";
656 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 )";
657 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
658 if (UnparseC.term t', UnparseC.terms asm) =
659 ("(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)", "[\"3 * a + 9 * a \<up> 2 \<noteq> 0\"]")
660 then () else error "rational.sml cancel Schalk 190a";
662 "-------- example 190c";
663 val t = TermC.str2term "((1 + 9 * a \<up> 2)*(1 + 3 * a))/((3 * a + 9 * a \<up> 2)*(1 + 3 * a))";
664 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
665 if (UnparseC.term t', UnparseC.terms asm) =
666 ("(1 + 3 * a + 9 * a \<up> 2 + 27 * a \<up> 3) /\n(3 * a + 18 * a \<up> 2 + 27 * a \<up> 3)", "[]")
667 then () else error "rational.sml make_polynomial Schalk 190c";
669 "-------- example 191a";
670 val t = TermC.str2term "( x \<up> 2 + -1 * y \<up> 2 ) / ( x + y )";
671 is_expanded (TermC.str2term "x \<up> 2 + -1 * y \<up> 2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
672 is_expanded (TermC.str2term "x + y") = true;
673 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
674 if (UnparseC.term t', UnparseC.terms asm) = ("(x + -1 * y) / 1", "[]")
675 then () else error "rational.sml make_polynomial Schalk 191a";
677 "-------- example 191b";
678 val t = TermC.str2term "((x + (-1) * y)*(x + y))/((1)*(x + y))";
679 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
680 if (UnparseC.term t', UnparseC.terms asm) = ("(x \<up> 2 + -1 * y \<up> 2) / (x + y)", "[]")
681 then () else error "rational.sml make_polynomial Schalk 191b";
683 "-------- example 191c";
684 val t = TermC.str2term "( 9 * x \<up> 2 + -30 * x + 25 ) / ( 9 * x \<up> 2 + -25 )";
685 is_expanded (TermC.str2term "9 * x \<up> 2 + -30 * x + 25") = true;
686 is_expanded (TermC.str2term "25 + -30*x + 9*x \<up> 2") = true;
687 is_expanded (TermC.str2term "-25 + 9*x \<up> 2") = true;
689 val t = TermC.str2term "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
690 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
691 if (UnparseC.term t', UnparseC.terms asm) = ("(25 + -30 * x + 9 * x \<up> 2) / (-25 + 9 * x \<up> 2)", "[]")
692 then () else error "rational.sml make_polynomial Schalk 191c";
694 "-------- example 192b";
695 val t = TermC.str2term "( 7 * x \<up> 3 + -1 * x \<up> 2 * y ) / ( 7 * x * y \<up> 2 + -1 * y \<up> 3 )";
696 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
697 if (UnparseC.term t', UnparseC.terms asm) = ("x \<up> 2 / y \<up> 2", "[\"y \<up> 2 \<noteq> 0\"]")
698 then () else error "rational.sml cancel_p Schalk 192b";
700 val t = TermC.str2term "((x \<up> 2)*(7 * x + (-1) * y))/((y \<up> 2)*(7 * x + (-1) * y))";
701 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
702 if (UnparseC.term t', UnparseC.terms asm) =
703 ("(7 * x \<up> 3 + -1 * x \<up> 2 * y) / (7 * x * y \<up> 2 + -1 * y \<up> 3)", "[]")
704 then () else error "rational.sml make_polynomial Schalk 192b";
706 val t = TermC.str2term "((x \<up> 2)*(7 * x + (-1) * y))/((y \<up> 2)*(7 * x + (-1) * y))";
707 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
708 if (UnparseC.term t', UnparseC.terms asm) =
709 ("(7 * x \<up> 3 + -1 * x \<up> 2 * y) / (7 * x * y \<up> 2 + -1 * y \<up> 3)", "[]")
710 then () else error "rational.sml make_polynomial Schalk WN050929 not working";
712 "-------- example 193a";
713 val t = TermC.str2term "( x \<up> 2 + -6 * x + 9 ) / ( x \<up> 2 + -9 )";
714 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
715 if (UnparseC.term t', UnparseC.terms asm) = ("(-3 + x) / (3 + x)", "[\"3 + x \<noteq> 0\"]")
716 then () else error "rational.sml cancel_p Schalk 193a";
718 "-------- example 193b";
719 val t = TermC.str2term "( x \<up> 2 + -8 * x + 16 ) / ( 2 * x \<up> 2 + -32 )";
720 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
721 if (UnparseC.term t', UnparseC.terms asm) = ("(-4 + x) / (8 + 2 * x)", "[\"8 + 2 * x \<noteq> 0\"]")
722 then () else error "rational.sml cancel_p Schalk 193b";
724 "-------- example 193c";
725 val t = TermC.str2term "( 2 * x + -50 * x \<up> 3 ) / ( 25 * x \<up> 2 + -10 * x + 1 )";
726 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
727 if (UnparseC.term t', UnparseC.terms asm) =
728 ("(2 * x + 10 * x \<up> 2) / (1 + -5 * x)", "[\"1 + -5 * x \<noteq> 0\"]")
729 then () else error "rational.sml cancel_p Schalk 193c";
732 val t = TermC.str2term "(-25 + 9*x \<up> 2)/(5 + 3*x)";
733 val SOME (t, asm) = rewrite_set_ thy false cancel_p t;
734 if (UnparseC.term t', UnparseC.terms asm) = ("(2 * x + 10 * x \<up> 2) / (1 + -5 * x)", "[]")
735 then () else error "rational.sml cancel WN 1";
737 "-------- example heuberger";
738 val t = TermC.str2term ("(x \<up> 4 + x * y + x \<up> 3 * y + y \<up> 2) / " ^
739 "(x + 5 * x \<up> 2 + y + 5 * x * y + x \<up> 2 * y \<up> 3 + x * y \<up> 4)");
740 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
741 if (UnparseC.term t', UnparseC.terms asm) =
742 ("(x \<up> 3 + y) / (1 + 5 * x + x * y \<up> 3)", "[\"1 + 5 * x + x * y \<up> 3 \<noteq> 0\"]")
743 then () else error "rational.sml cancel_p heuberger";
745 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
746 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
747 "-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
748 (*deleted example 204 ... 236b at update Isabelle2012-->2013*)
750 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
751 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
752 "-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
753 val t = TermC.str2term ("123 = (a*x)/(b*x) + (c*x)/(d*x) + (e*x)/(f*x::real)");
754 "-------- gcd_poly integration level 1: works on exact term";
755 if NONE = cancel_p_ thy t then () else error "cancel_p_ works on exact fraction";
756 if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ works on exact fraction";
758 "-------- gcd_poly integration level 2: picks out ONE appropriate subterm";
759 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
760 if UnparseC.term t' = "123 = a * x / (b * x) + c * x / (d * x) + e / f"
761 then () else error "level 2, rewrite_set_ cancel_p: changed";
762 val SOME (t', asm) = rewrite_set_ thy false add_fractions_p t;
763 if UnparseC.term t' = "123 = (b * c * x + a * d * x) / (b * d * x) + e * x / (f * x)"
764 then () else error "level 2, rewrite_set_ add_fractions_p: changed";
766 "-------- gcd_poly integration level 3: rewrites all appropriate subterms";
767 val SOME (t', asm) = rewrite_set_ thy false cancel_p_rls t;
768 if UnparseC.term t' = "123 = a / b + c / d + e / f"
769 then () else error "level 3, rewrite_set_ cancel_p_rls: changed";
770 val SOME (t', asm) = rewrite_set_ thy false add_fractions_p_rls t; (*CREATE add_fractions_p_rls*)
771 if UnparseC.term t' = "123 = (b * d * e * x + b * c * f * x + a * d * f * x) / (b * d * f * x)"
772 then () else error "level 3, rewrite_set_ add_fractions_p_rls: changed";
774 "-------- gcd_poly integration level 4: iteration cancel_p -- add_fraction_p";
775 (* simpler variant *)
776 val testrls = Rule_Set.append_rules "testrls" Rule_Set.empty [Rls_ cancel_p, Rls_ add_fractions_p]
777 val SOME (t', asm) = rewrite_set_ thy false testrls t;
778 (*Rewrite.trace_on := false;
779 # rls: testrls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
780 ## rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
781 ## rls: add_fractions_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f
782 ## rls: cancel_p on: 123 = (b * c * x + a * d * x) / (b * d * x) + e / f
783 ## rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f
784 ## rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
785 ## rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
786 if UnparseC.term t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
787 then () else error "level 4, rewrite_set_ *_p: changed";
789 (* complicated variant *)
790 val testrls_rls = Rule_Set.append_rules "testrls_rls" Rule_Set.empty [Rls_ cancel_p_rls, Rls_ add_fractions_p_rls];
791 val SOME (t', asm) = rewrite_set_ thy false testrls_rls t;
792 (*# rls: testrls_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
793 ## rls: cancel_p_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
794 ### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
795 ### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f
796 ### rls: cancel_p on: 123 = a * x / (b * x) + c / d + e / f
797 ### rls: cancel_p on: 123 = a / b + c / d + e / f
798 ## rls: add_fractions_p_rls on: 123 = a / b + c / d + e / f
799 ### rls: add_fractions_p on: 123 = a / b + c / d + e / f
800 ### rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f
801 ### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
802 ## rls: cancel_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
803 ### rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
804 ## rls: add_fractions_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
805 ### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
806 if UnparseC.term t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
807 then () else error "level 4, rewrite_set_ *_p_rls: changed"
809 "-------- gcd_poly integration level 5: cancel_p & add_fraction_p within norm_Rational";
810 val SOME (t', asm) = rewrite_set_ thy false norm_Rational t;
811 if UnparseC.term t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)"
812 then () else error "level 5, rewrite_set_ norm_Rational: changed"
814 "-------- reverse rewrite ----------------------------------------------------";
815 "-------- reverse rewrite ----------------------------------------------------";
816 "-------- reverse rewrite ----------------------------------------------------";
817 (** the term for which reverse rewriting is demonstrated **)
818 val t = TermC.str2term "(9 + -1 * x \<up> 2) / (9 + 6 * x + x \<up> 2)";
819 val Rrls {scr = Rfuns {init_state = ini, locate_rule = loc,
820 next_rule = nex, normal_form = nor, ...},...} = cancel_p;
822 (** normal_form produces the result in ONE step **)
823 val SOME (t',_) = nor t;
824 if UnparseC.term t' = "(3 + -1 * x) / (3 + x)" then ()
825 else error "rational.sml normal_form (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
827 (** initialize the interpreter state used by the 'me' **)
828 val (t, _, revsets, _) = ini t;
830 if length (hd revsets) = 11 then () else error "length of revset changed";
831 if (revsets |> nth 1 |> nth 1 |> id_of_thm) =
832 (@{thm realpow_twoI} |> Thm.get_name_hint |> ThmC.cut_id)
833 then () else error "first element of revset changed";
835 (revsets |> nth 1 |> nth 1 |> Rule.to_string) = "Thm (\"realpow_twoI\",?r1 \<up> 2 = ?r1 * ?r1)" andalso
836 (revsets |> nth 1 |> nth 2 |> Rule.to_string) = "Thm (\"#: 9 = 3 \<up> 2\",9 = 3 \<up> 2)" andalso
837 (revsets |> nth 1 |> nth 3 |> Rule.to_string) = "Thm (\"#: 6 * x = 2 * (3 * x)\",6 * x = 2 * (3 * x))"
839 (revsets |> nth 1 |> nth 4 |> Rule.to_string) = "Thm (\"#: -3 * x = -1 * (3 * x)\",-3 * x = -1 * (3 * x))"
841 (revsets |> nth 1 |> nth 5 |> Rule.to_string) = "Thm (\"#: 9 = 3 * 3\",9 = 3 * 3)" andalso
842 (revsets |> nth 1 |> nth 6 |> Rule.to_string) = "Rls_ (\"sym_order_mult_rls_\")" andalso
843 (revsets |> nth 1 |> nth 7 |> Rule.to_string) =
844 "Thm (\"sym_mult.assoc\",?a * (?b * ?c) = ?a * ?b * ?c)"
845 then () else error "first 7 elements in revset changed"
847 (** find the rule 'r' to apply to term 't' **)
848 (*/------- WN1309: since cancel_ (accepted "-" between monomials) has been replaced by cancel_p_
849 for Isabelle2013, we don't get a working revset, but non-termination:
851 val SOME (r as (Thm (str, thm))) = nex revsets t;
853 ((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x),
854 Rls_ ("sym_order_mult_rls_"), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x), []))", "
855 ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x),
856 Thm ("sym_mult.assoc", ""), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x), []))", "
857 ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x),
858 Thm ("sym_mult.assoc", ""), ((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), []))", "
859 ((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), []))", "
862 Thm ("sym_#mult_2_3", "6 = 2 * 3")
863 ### Isabelle2009-2 for cancel_ (not cancel_p_):
864 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))"
865 andalso ThmC.string_of_thm thm =
866 (string_of_thm (Thm.make_thm @{theory "Isac_Knowledge"}
867 (Trueprop $ (Thm.term_of o the o (TermC.parse thy)) "9 = 3 \<up> 2"))) then ()
868 else error "rational.sml next_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
869 \---------------------------------------------------------------------------------------/*)
871 (** check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
872 if the rule is OK, the term resulting from applying the rule is returned,too;
873 there might be several rule applications inbetween,
874 which are listed after the head in reverse order **)
875 (*/-------------------------------------------- Isabelle2013: this gives "error id_of_thm";
876 we don't repair this, because interaction within "reverse rewriting" never worked properly:
878 val (r, (t, asm))::_ = loc revsets t r;
879 if UnparseC.term t = "(9 - x \<up> 2) / (3 \<up> 2 + 6 * x + x \<up> 2)" andalso asm = []
880 then () else error "rational.sml locate_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
882 (* find the next rule to apply *)
883 val SOME (r as (Thm (str, thm))) = nex revsets t;
884 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso
885 ThmC.string_of_thm thm = (string_of_thm (ThmC_Def.make_thm @{theory "Isac_Knowledge"}
886 (Trueprop $ (Thm.term_of o the o (TermC.parse thy)) "9 = 3 \<up> 2"))) then ()
887 else error "rational.sml next_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
889 (*check the next rule*)
890 val (r, (t, asm)) :: _ = loc revsets t r;
891 if UnparseC.term t = "(3 \<up> 2 - x \<up> 2) / (3 \<up> 2 + 6 * x + x \<up> 2)" then ()
892 else error "rational.sml locate_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2) II";
894 (*find and check the next rules, rewrite*)
895 val SOME r = nex revsets t;
896 val (r,(t,asm))::_ = loc revsets t r;
897 if UnparseC.term t = "(3 \<up> 2 - x \<up> 2) / (3 \<up> 2 + 2 * 3 * x + x \<up> 2)" then ()
898 else error "rational.sml locate_rule II";
900 val SOME r = nex revsets t;
901 val (r,(t,asm))::_ = loc revsets t r;
902 if UnparseC.term t = "(3 - x) * (3 + x) / (3 \<up> 2 + 2 * 3 * x + x \<up> 2)" then ()
903 else error "rational.sml next_rule II";
905 val SOME r = nex revsets t;
906 val (r,(t,asm))::_ = loc revsets t r;
907 if UnparseC.term t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then ()
908 else error "rational.sml next_rule III";
910 val SOME r = nex revsets t;
911 val (r, (t, asm)) :: _ = loc revsets t r;
912 val ss = UnparseC.term t;
913 if ss = "(3 - x) / (3 + x)" andalso UnparseC.terms asm = "[\"3 + x ~= 0\"]" then ()
914 else error "rational.sml: new behav. in rev-set cancel";
915 \--------------------------------------------------------------------------------------/*)
917 "-------- 'reverse-ruleset' cancel_p -----------------------------------------";
918 "-------- 'reverse-ruleset' cancel_p -----------------------------------------";
919 "-------- 'reverse-ruleset' cancel_p -----------------------------------------";
920 (*WN130909: the example below shows, why "reverse rewriting" only worked for
923 (*the term for which reverse rewriting is demonstrated*)
924 val t = TermC.str2term "(9 + (-1)*x \<up> 2) / (9 + ((-6)*x + x \<up> 2))";
925 val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
926 next_rule=nex,normal_form=nor,...},...} = cancel_p;
928 (*normal_form produces the result in ONE step*)
929 val SOME (t',_) = nor t;
930 UnparseC.term t' = "(3 + 1 * x) / (3 + -1 * x)";
932 (*initialize the interpreter state used by the 'me'*)
933 val SOME (t', asm) = cancel_p_ thy t;
934 UnparseC.term t' = "(3 + x) / (3 + -1 * x)" (*true*);
935 UnparseC.terms asm = "[\"3 + -1 * x ~= 0\"]" (*true*);
936 val (t,_,revsets,_) = ini t;
938 (* WN.10.10.02: dieser Fall terminiert nicht
939 (make_polynomial enth"alt zu viele rules)
940 WN060823 'init_state' requires rewriting on specified location in the term
941 default_print_depth 99; Rfuns; default_print_depth 3;
942 WN060831 cycling "sym_order_mult_rls_" "sym_mult.assoc"
943 as was with make_polynomial before ?!?*)
945 val SOME r = nex revsets t;
946 eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))",
947 mk_thm thy "9 = 3 \<up> 2"));
948 (*WN060831 *** id_of_thm
949 Exception- ERROR raised ...
950 val (r,(t,asm))::_ = loc revsets t r;
953 val SOME r = nex revsets t;
954 val (r,(t,asm))::_ = loc revsets t r;
958 "-------- examples: rls norm_Rational ----------------------------------------";
959 "-------- examples: rls norm_Rational ----------------------------------------";
960 "-------- examples: rls norm_Rational ----------------------------------------";
961 val t = TermC.str2term "(3*x+5)/18 - x/2 - -(3*x - 2)/9 = 0";
962 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
963 if UnparseC.term t' = "1 / 18 = 0" then () else error "rational.sml 1";
965 val t = TermC.str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0";
966 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
967 if UnparseC.term t' = "(237 + 65 * x) / 36 = 0" then ()
968 else error "rational.sml 2";
970 val t = TermC.str2term "(1/2 + (5*x)/2) \<up> 2 - ((13*x)/2 - 5/2) \<up> 2 - (6*x) \<up> 2 + 29";
971 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
972 if UnparseC.term t' = "23 + 35 * x + -72 * x \<up> 2" then ()
973 else error "rational.sml 3";
975 (*Rewrite.trace_on:=true;*)
976 val t = TermC.str2term "Not (6*x is_atom)";
977 val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t';
979 val t = TermC.str2term "1 < 2";
980 val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t';
983 val t = TermC.str2term "(6*x) \<up> 2";
984 val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false
985 (ThmC.numerals_to_Free @{thm realpow_def_atom}) t;
986 if UnparseC.term t' = "6 * x * (6 * x) \<up> (2 + -1)" then ()
987 else error "rational.sml powers_erls (6*x) \<up> 2";
989 val t = TermC.str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))";
990 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
991 if UnparseC.term t' = "65 * x / 2" then () else error "rational.sml 4";
993 val t = TermC.str2term "1 - ((13*x)/2 - 5/2) \<up> 2";
994 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
995 if UnparseC.term t' = "(-21 + 130 * x + -169 * x \<up> 2) / 4" then ()
996 else error "rational.sml 5";
998 (*SRAM Schalk I, p.92 Nr. 609a*)
999 val t = TermC.str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
1000 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1001 if UnparseC.term t' = "(-255 + 112 * x) / 135" then ()
1002 else error "rational.sml 6";
1004 (*SRAM Schalk I, p.92 Nr. 610c*)
1005 val t = TermC.str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
1006 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1007 if UnparseC.term t' = "(3 + x) / -2" then () else error "rational.sml 7";
1009 (*SRAM Schalk I, p.92 Nr. 476a*)
1010 val t = TermC.str2term "(x \<up> 2/(1 - x \<up> 2) + 1)/(x/(1 - x) + 1) * (1 + x)";
1011 (*. a/b : c/d translated to a/b * d/c .*)
1012 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1013 if UnparseC.term t' = "1" then () else error "rational.sml 8";
1015 (*Schalk I, p.92 Nr. 472a*)
1016 val t = TermC.str2term "((8*x \<up> 2 - 32*y \<up> 2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
1017 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1018 if UnparseC.term t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
1020 (*Schalk I, p.70 Nr. 480b: SEE rational.sml --- nonterminating rls norm_Rational ---*)
1022 (*WN130910 add_fractions_p exception Div raised + history:
1023 ### WN.2.6.03 from rlang.sml 56a
1024 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)";
1025 val NONE = rewrite_set_ thy false add_fractions_p t;
1027 THE ERROR ALREADY OCCURS IN THIS PART:
1028 val t = TermC.str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
1029 val NONE = add_fraction_p_ thy t;
1031 SEE Test_Some.thy: section {* add_fractions_p downto exception Div raised ===
1034 "-------- rational numerals --------------------------------------------------";
1035 "-------- rational numerals --------------------------------------------------";
1036 "-------- rational numerals --------------------------------------------------";
1037 (*SRA Schalk I, p.40 Nr. 164b *)
1038 val t = TermC.str2term "(47/6 - 76/9 + 13/4)/(35/12)";
1039 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1041 if UnparseC.term t = "19 / 21" then ()
1042 else error "rational.sml: diff.behav. in norm_Rational_mg 1";
1044 (*SRA Schalk I, p.40 Nr. 166a *)
1045 val t = TermC.str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
1046 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1048 if UnparseC.term t = "45 / 2" then ()
1049 else error "rational.sml: diff.behav. in norm_Rational_mg 2";
1051 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
1052 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
1053 "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
1054 (* e190c Stefan K.*)
1055 val t = TermC.str2term "((1 + 9*a \<up> 2) * (1 + 3*a)) / ((3*a + 9*a \<up> 2) * (1 + 3*a))";
1056 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1057 if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
1058 then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
1060 (* e192b Stefan K.*)
1061 val t = TermC.str2term "(x \<up> 2 * (7*x + (-1)*y)) / (y \<up> 2 * (7*x + (-1)*y))";
1062 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1063 if UnparseC.term t = "x \<up> 2 / y \<up> 2"
1064 then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
1066 (*SRC Schalk I, p.66 Nr. 379c *)
1067 val t = TermC.str2term "(a - b)/(b - a)";
1068 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1070 if UnparseC.term t = "-1"
1071 then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
1073 (*SRC Schalk I, p.66 Nr. 380b *)
1074 val t = TermC.str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))";
1075 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1076 if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)"
1077 then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
1079 (*Schalk I, p.60 Nr. 215c: was not cancelled with Isabelle2002 *)
1080 val t = TermC.str2term "(a + b) \<up> 4 * (x - y) / ((x - y) \<up> 3 * (a + b) \<up> 2)";
1081 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1082 if UnparseC.term t = "(a \<up> 2 + 2 * a * b + b \<up> 2) / (x \<up> 2 + -2 * x * y + y \<up> 2)"
1083 then () else error "rational.sml: diff.behav. in norm_Rational_mg 7";
1085 (*SRC Schalk I, p.66 Nr. 381b *)
1086 val t = TermC.str2term
1087 "(4*x \<up> 2 - 20*x + 25)/(2*x - 5) \<up> 3";
1088 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1089 if UnparseC.term t = "1 / (-5 + 2 * x)"
1090 then () else error "rational.sml: diff.behav. in norm_Rational_mg 9";
1092 (* e190c Stefan K.*)
1093 val t = TermC.str2term "((1 + 9*a \<up> 2) * (1 + 3*a)) / ((3*a + 9*a \<up> 2) * (1 + 3 * a))";
1094 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1095 if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
1096 then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
1098 (* e192b Stefan K.*)
1099 val t = TermC.str2term "(x \<up> 2 * (7*x + (-1)*y)) / (y \<up> 2 * (7*x + (-1)*y))";
1100 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1101 if UnparseC.term t = "x \<up> 2 / y \<up> 2"
1102 then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
1104 (*SRC Schalk I, p.66 Nr. 379c *)
1105 val t = TermC.str2term "(a - b) / (b - a)";
1106 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1107 if UnparseC.term t = "-1"
1108 then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
1110 (*SRC Schalk I, p.66 Nr. 380b *)
1111 val t = TermC.str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))";
1112 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1113 if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)"
1114 then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
1116 (*Schalk I, p.60 Nr. 215c *)
1117 val t = TermC.str2term "(a + b) \<up> 4 * (x - y) / ((x - y) \<up> 3 * (a + b) \<up> 2)";
1118 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1119 if UnparseC.term t = "(a \<up> 2 + 2 * a * b + b \<up> 2) / (x \<up> 2 + -2 * x * y + y \<up> 2)"
1120 then () else error "Schalk I, p.60 Nr. 215c: with Isabelle2002 cancellation incomplete, changed";
1122 (* extreme example from somewhere *)
1123 val t = TermC.str2term
1124 ("(a \<up> 4 * x + -1*a \<up> 4 * y + 4*a \<up> 3 * b * x + -4*a \<up> 3 * b * y + " ^
1125 "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 + " ^
1126 "b \<up> 4 * x + -1*b \<up> 4 * y) " ^
1127 " / (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 + " ^
1128 "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 + " ^
1129 "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)")
1130 val SOME (t, _) = rewrite_set_ thy false cancel_p t;
1131 if UnparseC.term t = "(a \<up> 2 + 2 * a * b + b \<up> 2) / (x \<up> 2 + -2 * x * y + y \<up> 2)"
1132 then () else error "with Isabelle2002: NONE -- now SOME changed";
1134 (*Schalk I, p.66 Nr. 381a *)
1135 (* ATTENTION: here the rls is very slow. In Isabelle2002 this required 2 min *)
1136 val t = TermC.str2term "18*(a + b) \<up> 3 * (a - b) \<up> 2 / (72*(a - b) \<up> 3 * (a + b) \<up> 2)";
1137 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1138 if UnparseC.term t = "(a + b) / (4 * a + -4 * b)"
1139 then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
1141 (*SRC Schalk I, p.66 Nr. 381b *)
1142 val t = TermC.str2term "(4*x \<up> 2 - 20*x + 25) / (2*x - 5) \<up> 3";
1143 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1144 if UnparseC.term t = "1 / (-5 + 2 * x)"
1145 then () else error "rational.sml: diff.behav. in norm_Rational_mg 9";
1147 (*SRC Schalk I, p.66 Nr. 381c *)
1148 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)";
1149 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1150 if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
1151 then () else error "rational.sml: diff.behav. in norm_Rational_mg 10";
1153 (*SRC Schalk I, p.66 Nr. 383a *)
1154 val t = TermC.str2term "(5*a \<up> 2 - 5*a*b) / (a - b) \<up> 2";
1155 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1156 if UnparseC.term t = "-5 * a / (-1 * a + b)"
1157 then () else error "rational.sml: diff.behav. in norm_Rational_mg 11";
1159 "----- NOT TERMINATING ?: worked before 0707xx";
1160 val t = TermC.str2term "(a \<up> 2 - 1)*(b + 1) / ((b \<up> 2 - 1)*(a+1))";
1161 (* WN130911 "exception Div raised" by
1162 cancel_p_ thy (TermC.str2term ("(-1 + -1 * b + a \<up> 2 + a \<up> 2 * b) /" ^
1163 "(-1 + -1 * a + b \<up> 2 + a * b \<up> 2)"))
1165 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1166 if UnparseC.term t = "(1 + -1 * a) / (1 + -1 * b)" then ()
1167 else error "rational.sml MG tests 3e";
1170 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
1171 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
1172 "-------- examples common denominator from: Mathematik 1 Schalk --------------";
1173 (*SRA Schalk I, p.67 Nr. 403a *)
1174 val t = TermC.str2term "4/x - 3/y - 1";
1175 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1176 if UnparseC.term t = "(-3 * x + 4 * y + -1 * x * y) / (x * y)"
1177 then () else error "rational.sml: diff.behav. in norm_Rational_mg 12";
1179 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)";
1180 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1181 if UnparseC.term t = "4 / c"
1182 then () else error "rational.sml: diff.behav. in norm_Rational_mg 13";
1184 (*SRA Schalk I, p.67 Nr. 410b *)
1185 val t = TermC.str2term "1/(x+1) + 1/(x+2) - 2/(x+3)";
1186 (* WN130911 non-termination due to non-termination of
1187 cancel_p_ thy (TermC.str2term "(5 + 3 * x) / (6 + 11 * x + 6 * x \<up> 2 + x \<up> 3)")
1189 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1190 if UnparseC.term t = "(5 + 3 * x) / (6 + 11 * x + 6 * x \<up> 2 + x \<up> 3)"
1191 then () else error "rational.sml: diff.behav. in norm_Rational_mg 14";
1194 (*SRA Schalk I, p.67 Nr. 413b *)
1195 val t = TermC.str2term "(1 + x)/(1 - x) - (1 - x)/(1 + x) + 2*x/(1 - x \<up> 2)";
1196 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1197 if UnparseC.term t = "6 * x / (1 + -1 * x \<up> 2)"
1198 then () else error "rational.sml: diff.behav. in norm_Rational_mg 15";
1200 (*SRA Schalk I, p.68 Nr. 414a *)
1201 val t = TermC.str2term "(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))";
1202 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1203 if UnparseC.term t ="(-2 + -5 * x + 2 * x \<up> 2) / (2 + -3 * x + x \<up> 2)"
1204 then () else error "rational.sml: diff.behav. in norm_Rational_mg 16";
1206 (*SRA Schalk I, p.68 Nr. 428b *)
1207 val t = TermC.str2term
1208 "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";
1209 (* WN130911 non-termination due to non-termination of
1210 cancel_p_ thy (TermC.str2term "(4 + -4 * b \<up> 2) / (a \<up> 4 + -2 * (a \<up> 2 * b \<up> 2) + b \<up> 4)")
1212 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1213 if UnparseC.term t = "4 / (a \<up> 4 + -2 * a \<up> 2 * b \<up> 2 + b \<up> 4)"
1214 then () else error "rational.sml: diff.behav. in norm_Rational_mg 18";
1217 (*SRA Schalk I, p.68 Nr. 430b *)
1218 val t = TermC.str2term
1219 "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";
1220 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1221 if UnparseC.term t = "a + 3 * b"
1222 then () else error "rational.sml: diff.behav. in norm_Rational_mg 19";
1224 (*SRA Schalk I, p.68 Nr. 432 *)
1225 val t = TermC.str2term
1226 ("(a \<up> 2 + a*b) / (a \<up> 2 - b \<up> 2) - (b \<up> 2 - a*b) / (b \<up> 2 - a \<up> 2) + " ^
1227 "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) - " ^
1228 "2*b \<up> 2 / (a \<up> 2 - b \<up> 2)");
1229 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1230 if UnparseC.term t = (*"0" ..isabisac15 | Isabelle2017..*) "0 / (a \<up> 2 + -1 * b \<up> 2)"
1231 then () else error "rational.sml: diff.behav. in norm_Rational_mg 20";
1234 val t = TermC.str2term "3*a / (a*b) + x/y";
1235 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1236 if UnparseC.term t = "(3 * y + b * x) / (b * y)"
1237 then () else error "rational.sml: diff.behav. in norm_Rational_mg 21";
1239 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1240 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1241 "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1242 (*------- SRM Schalk I, p.68 Nr. 436a *)
1243 val t = TermC.str2term "3*(x+y) / (15*(x - y)) * 25*(x - y) \<up> 2 / (18*(x + y) \<up> 2)";
1244 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1245 if UnparseC.term t = "(-5 * x + 5 * y) / (-18 * x + -18 * y)"
1246 then () else error "rational.sml: diff.behav. in norm_Rational_mg 22";
1248 (*------- SRM.test Schalk I, p.68 Nr. 436b *)
1249 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";
1250 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1251 if UnparseC.term t = "5 * a / (a + -1 * b)"
1252 then () else error "rational.sml: diff.behav. in norm_Rational_mg 23";
1254 (*------- Schalk I, p.68 Nr. 437a *)
1255 val t = TermC.str2term "(3*a - 4*b) / (4*c+3*e) * (3*a+4*b)/(9*a \<up> 2 - 16*b \<up> 2)";
1256 (* raises an exception for unclear reasons:
1257 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1259 ### rls: cancel_p on: (9 * a \<up> 2 + -16 * b \<up> 2) / (4 * c + 3 * e) /
1260 (9 * a \<up> 2 + -16 * b \<up> 2)
1261 exception Div raised
1264 val t = TermC.str2term
1265 ("(9 * a \<up> 2 + -16 * b \<up> 2) / (4 * c + 3 * e) /" ^
1266 "(9 * a \<up> 2 + -16 * b \<up> 2)");
1267 NONE = cancel_p_ thy t;
1269 if UnparseC.term t = "1 / (4 * c + 3 * e)" then ()
1270 else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1273 "----- S.K. corrected non-termination 060904";
1274 val t = TermC.str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a \<up> 2 - 16*b \<up> 2))";
1275 val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
1276 if UnparseC.term t =
1277 "(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)"
1278 (*"(9 * a \<up> 2 + -16 * b \<up> 2) / (36 * a \<up> 2 * c + 27 * a \<up> 2 * e + -64 * b \<up> 2 * c + -48 * b \<up> 2 * e)"*)
1279 then () else error "rational.sml: S.K.8..corrected 060904-6";
1281 "----- S.K. corrected non-termination of cancel_p_";
1282 val t'' = TermC.str2term ("(9 * a \<up> 2 + -16 * b \<up> 2) /" ^
1283 "(36 * a \<up> 2 * c + (27 * a \<up> 2 * e + (-64 * b \<up> 2 * c + -48 * b \<up> 2 * e)))");
1284 (* /--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------\
1285 val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
1286 if UnparseC.term t' = "1 / (4 * c + 3 * e)"
1287 then () else error "rational.sml: diff.behav. in cancel_p S.K.8";
1288 \--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------/*)
1290 (*------- Schalk I, p.68 Nr. 437b*)
1291 val t = TermC.str2term "(a + b)/(x \<up> 2 - y \<up> 2) * ((x - y) \<up> 2/(a \<up> 2 - b \<up> 2))";
1292 (*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1294 #### rls: cancel_p on: (a * x \<up> 2 + -2 * (a * (x * y)) + a * y \<up> 2 + b * x \<up> 2 +
1295 -2 * (b * (x * y)) +
1297 (a \<up> 2 * x \<up> 2 + -1 * (a \<up> 2 * y \<up> 2) + -1 * (b \<up> 2 * x \<up> 2) +
1298 b \<up> 2 * y \<up> 2)
1299 exception Div raised
1302 (*------- SRM Schalk I, p.68 Nr. 438a *)
1303 val t = TermC.str2term "x*y / (x*y - y \<up> 2) * (x \<up> 2 - x*y)";
1304 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1305 if UnparseC.term t = "x \<up> 2"
1306 then () else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1308 (*------- SRM Schalk I, p.68 Nr. 439b *)
1309 val t = TermC.str2term "(4*x \<up> 2 + 4*x + 1) * ((x \<up> 2 - 2*x \<up> 3) / (4*x \<up> 2 + 2*x))";
1310 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1311 if UnparseC.term t = "(x + -4 * x \<up> 3) / 2"
1312 then () else error "rational.sml: diff.behav. in norm_Rational_mg 25";
1314 (*------- SRM Schalk I, p.68 Nr. 440a *)
1315 val t = TermC.str2term "(x \<up> 2 - 2*x) / (x \<up> 2 - 3*x) * (x - 3) \<up> 2 / (x \<up> 2 - 4)";
1316 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1317 if UnparseC.term t = "(-3 + x) / (2 + x)"
1318 then () else error "rational.sml: diff.behav. in norm_Rational_mg 26";
1320 "----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
1321 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)";
1322 (* WN130911 non-termination for unclear reasons:
1323 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1325 ... ENDS WITH THIS TRACE:
1327 ### rls: cancel_p on: (-9 * (a \<up> 3 * b) + -9 * (a \<up> 2 * b \<up> 2) + a \<up> 5 * b +
1328 a \<up> 4 * b \<up> 2) /
1329 (a \<up> 3 * b + -1 * (a * b \<up> 3)) /
1331 BUT THIS IS CORRECTLY RECOGNISED
1332 val t = TermC.str2term
1333 ("(-9 * (a \<up> 3 * b) + -9 * (a \<up> 2 * b \<up> 2) + a \<up> 5 * b + a \<up> 4 * b \<up> 2) /" ^
1334 "(a \<up> 3 * b + -1 * (a * b \<up> 3)) / (3 + (a::real))");
1336 NONE = cancel_p_ thy t;
1338 if UnparseC.term t = "(-3 * a + a \<up> 2) / (a + -1 * b)" then ()
1339 else error "rational.sml: diff.behav. in norm_Rational 27";
1342 "----- SK12 works since 0707xx";
1343 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))";
1344 (* WN130911 non-termination due to non-termination of
1345 cancel_p_ thy (TermC.str2term "(4 + -4 * b \<up> 2) / (a \<up> 4 + -2 * (a \<up> 2 * b \<up> 2) + b \<up> 4)")
1347 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1348 if UnparseC.term t' = "(-3 * a + a \<up> 2) / (a + -1 * b)" then ()
1349 else error "rational.sml: diff.behav. in norm_Rational 28";
1352 "-------- examples common denominator and multiplication from: Schalk --------";
1353 "-------- examples common denominator and multiplication from: Schalk --------";
1354 "-------- examples common denominator and multiplication from: Schalk --------";
1355 (*------- SRAM Schalk I, p.69 Nr. 441b *)
1356 val t = TermC.str2term "(4*a/3 + 3*b \<up> 2/a \<up> 3 + b/(4*a))*(4*b/(3*a))";
1357 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1358 if UnparseC.term t = "(36 * b \<up> 3 + 3 * a \<up> 2 * b \<up> 2 + 16 * a \<up> 4 * b) / (9 * a \<up> 4)"
1359 then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
1361 (*------- SRAM Schalk I, p.69 Nr. 442b *)
1362 val t = TermC.str2term ("(15*a \<up> 2/x \<up> 3 - 5*b \<up> 4/x \<up> 2 + 25*c \<up> 2/x) * " ^
1363 "(x \<up> 3/(5*a*b \<up> 3*c \<up> 3)) + 1/c \<up> 3 * (b*x/a - 3*a/b \<up> 3)");
1364 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1365 if UnparseC.term t = "5 * x \<up> 2 / (a * b \<up> 3 * c)"
1366 then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
1368 (*------- SRAM Schalk I, p.69 Nr. 443b *)
1369 val t = TermC.str2term "(a/2 + b/3) * (b/3 - a/2)";
1370 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1371 if UnparseC.term t = "(-9 * a \<up> 2 + 4 * b \<up> 2) / 36"
1372 then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
1374 (*------- SRAM Schalk I, p.69 Nr. 445b *)
1375 val t = TermC.str2term "(a \<up> 2/9 + 2*a/(3*b) + 4/b \<up> 2)*(a/3 - 2/b) + 8/b \<up> 3";
1376 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1377 if UnparseC.term t = "a \<up> 3 / 27"
1378 then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
1380 (*------- SRAM Schalk I, p.69 Nr. 446b *)
1381 val t = TermC.str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x \<up> 2 - 16*y \<up> 2)";
1382 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1383 if UnparseC.term t = (*"30 * x \<up> 2 + -9 * x * y + -20 * y \<up> 2" ..isabisac15 | Isabelle2017..*)
1384 "(-30 * x \<up> 2 + 9 * x * y + 20 * y \<up> 2) / -1"
1385 then () else error "rational.sml: diff.behav. in norm_Rational_mg 32";
1387 (*------- SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
1388 val t = TermC.str2term
1389 "(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)";
1390 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1391 if UnparseC.term t = "(-81 * x \<up> 4 + 16 * x \<up> 8 * y \<up> 4) / (81 * y \<up> 8)"
1392 then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
1394 (*------- SRAM Schalk I, p.69 Nr. 450a *)
1395 val t = TermC.str2term
1396 "(4*x/(3*y)+2*y/(3*x)) \<up> 2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
1397 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1398 if UnparseC.term t = "(52 * x \<up> 2 + 16 * y \<up> 2) / (9 * y \<up> 2)"
1399 then () else error "rational.sml: diff.behav. in norm_Rational_mg 34";
1401 (*------- SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*)
1402 val t = TermC.str2term
1403 ("(15*a \<up> 4/(a*x \<up> 3) - 5*a*((b \<up> 4 - 5*c \<up> 2*x) / x \<up> 2)) * " ^
1404 "(x \<up> 3/(5*a*b \<up> 3*c \<up> 3)) + a/c \<up> 3 * (x*(b/a) - 3*b*(a/b \<up> 4))");
1405 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1406 if UnparseC.term t = "5 * x \<up> 2 / (b \<up> 3 * c)"
1407 then () else error "rational.sml: diff.behav. in norm_Rational_mg 53";
1410 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1411 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1412 "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1413 "----- SRD Schalk I, p.69 Nr. 454b";
1414 val t = TermC.str2term "((2 - x)/(2*a)) / (2*a/(x - 2))";
1415 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1416 if UnparseC.term t = "(-4 + 4 * x + -1 * x \<up> 2) / (4 * a \<up> 2)"
1417 then () else error "rational.sml: diff.behav. in norm_Rational_mg 35";
1419 "----- SRD Schalk I, p.69 Nr. 455a";
1420 val t = TermC.str2term "(a \<up> 2 + 1)/(a \<up> 2 - 1) / ((a+1)/(a - 1))";
1421 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1422 if UnparseC.term t = "(1 + a \<up> 2) / (1 + 2 * a + a \<up> 2)" then ()
1423 else error "rational.sml: diff.behav. in norm_Rational_mg 36";
1425 "----- Schalk I, p.69 Nr. 455b";
1426 val t = TermC.str2term "(x \<up> 2 - 4)/(y \<up> 2 - 9)/((2+x)/(3 - y))";
1427 (* WN130911 non-termination due to non-termination of
1428 cancel_p_ thy (TermC.str2term ("(-12 + 4 * y + 3 * x \<up> 2 + -1 * (x \<up> 2 * y)) /" ^
1429 "(-18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)"))
1431 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1432 if UnparseC.term t = "(2 + -1 * x) / (3 + y)" then ()
1433 else error "rational.sml: diff.behav. in norm_Rational_mg 37";
1436 "----- SK060904-1a non-termination of cancel_p_ ?: worked before 0707xx";
1437 val t = TermC.str2term "(x \<up> 2 - 4)*(3 - y) / ((y \<up> 2 - 9)*(2+x))";
1438 (* WN130911 non-termination due to non-termination of
1439 cancel_p_ thy (TermC.str2term ("(-12 + 4 * y + 3 * x \<up> 2 + -1 * (x \<up> 2 * y)) /" ^
1440 "(-18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)"))
1442 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1443 if UnparseC.term t = "(2 + -1 * x) / (3 + y)" then ()
1444 else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
1447 "----- ?: worked before 0707xx";
1448 val t = TermC.str2term "(3 + -1 * y) / (-9 + y \<up> 2)";
1449 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1450 if UnparseC.term t = "-1 / (3 + y)"
1451 then () else error "rational.sml: -1 / (3 + y) norm_Rational";
1453 "----- SRD Schalk I, p.69 Nr. 456b";
1454 val t = TermC.str2term "(b \<up> 3 - b \<up> 2) / (b \<up> 2+b) / (b \<up> 2 - 1)";
1455 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1456 if UnparseC.term t = "b / (1 + 2 * b + b \<up> 2)"
1457 then () else error "rational.sml: diff.behav. in norm_Rational_mg 38";
1459 "----- SRD Schalk I, p.69 Nr. 457b";
1460 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))";
1461 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1462 if UnparseC.term t = "8 * a \<up> 2 + -6 * a * b + -12 * a \<up> 2 * b + 9 * a * b \<up> 2"
1463 then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
1465 "----- Schalk I, p.69 Nr. 458b works since 0707";
1466 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)))";
1467 (*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1469 ### rls: cancel_p on: (-1 * a \<up> 2 + 2 * (a \<up> 2 * x)) / (a * x + -1 * (b * x)) /
1470 ((-1 * b \<up> 2 + 2 * (b \<up> 2 * x)) / (a * x + -1 * (b * x)))
1471 exception Div raised
1474 val t = TermC.str2term
1475 ("(-1 * a \<up> 2 + 2 * (a \<up> 2 * x)) / (a * x + -1 * (b * x)) /" ^
1476 "((-1 * b \<up> 2 + 2 * (b \<up> 2 * x)) / (a * x + -1 * (b * x)))");
1477 NONE = cancel_p_ thy t;
1479 if UnparseC.term t = "a \<up> 2 / b \<up> 2" then ()
1480 else error "rational.sml: diff.behav. in norm_Rational_mg 39b";
1483 "----- SRD Schalk I, p.69 Nr. 459b";
1484 val t = TermC.str2term "(a \<up> 2 - b \<up> 2)/(a*b) / (4*(a+b) \<up> 2/a)";
1485 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1486 if UnparseC.term t = "(a + -1 * b) / (4 * a * b + 4 * b \<up> 2)" then ()
1487 else error "rational.sml: diff.behav. in norm_Rational_mg 41";
1489 "----- Schalk I, p.69 Nr. 460b nonterm.SK";
1490 val t = TermC.str2term "(9*(x \<up> 2 - 8*x + 16) / (4*(y \<up> 2 - 2*y + 1))) / ((3*x - 12) / (16*y - 16))";
1491 (*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1492 exception Div raised
1495 val t = TermC.str2term
1496 ("(144 + -72 * x + 9 * x \<up> 2) / (4 + -8 * y + 4 * y \<up> 2) /" ^
1497 "((-12 + 3 * x) / (-16 + 16 * y))");
1498 NONE = cancel_p_ thy t;
1500 if UnparseC.term t = !!!!!!!!!!!!!!!!!!!!!!!!!
1501 then () else error "rational.sml: diff.behav. in norm_Rational_mg 42";
1504 "----- some variant of the above; was non-terminating before";
1505 val t = TermC.str2term "9*(x \<up> 2 - 8*x+16)*(16*y - 16)/(4*(y \<up> 2 - 2*y+1)*(3*x - 12))";
1506 val SOME (t , _) = rewrite_set_ thy false norm_Rational t;
1507 if UnparseC.term t = "(48 + -12 * x) / (1 + -1 * y)"
1508 then () else error "some variant of the above; was non-terminating before";
1510 "----- SRD Schalk I, p.70 Nr. 472a";
1511 val t = TermC.str2term ("((8*x \<up> 2 - 32*y \<up> 2) / (2*x + 4*y)) / ((4*x - 8*y) / (x + y))");
1512 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1513 if UnparseC.term t = "x + y"
1514 then () else error "rational.sml: diff.behav. in norm_Rational_mg 43";
1516 "----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
1517 val t = TermC.str2term ("(a - (a*b + b \<up> 2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
1518 "((a - a \<up> 2/(a+b))/(a+(a*b)/(a - b)))");
1519 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1520 if UnparseC.term t = "(2 * a \<up> 3 + 2 * a \<up> 2 * b) / (a \<up> 2 * b + b \<up> 3)"
1521 then () else error "rational.sml: diff.behav. in norm_Rational_mg 51";
1523 (*SRD Schalk I, p.69 Nr. 461a *)
1524 val t = TermC.str2term "(2/(x+3) + 2/(x - 3)) / (8*x/(x \<up> 2 - 9))";
1525 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1526 if UnparseC.term t = "1 / 2"
1527 then () else error "rational.sml: diff.behav. in norm_Rational_mg 44";
1529 (*SRD Schalk I, p.69 Nr. 464b *)
1530 val t = TermC.str2term "(a - a/(a - 2)) / (a + a/(a - 2))";
1531 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1532 if UnparseC.term t = "(-3 + a) / (-1 + a)"
1533 then () else error "rational.sml: diff.behav. in norm_Rational_mg 45";
1535 (*SRD Schalk I, p.69 Nr. 465b *)
1536 val t = TermC.str2term "((x+3*y)/9 + (4*y \<up> 2 - 9*z \<up> 2)/(16*x)) / (x/9 + y/6 + z/4)";
1537 (* WN130911 non-termination due to non-termination of
1538 cancel_p_ thy (TermC.str2term
1539 ("("(576 * x \<up> 2 + 1728 * (x * y) + 1296 * y \<up> 2 + -2916 * z \<up> 2) /" ^
1540 "(576 * x \<up> 2 + 864 * (x * y) + 1296 * (x * z))"))
1542 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1543 if UnparseC.term t = "(4 * x + 6 * y + -9 * z) / (4 * x)"
1544 then () else error "rational.sml: diff.behav. in norm_Rational_mg 46";
1547 (*SRD Schalk I, p.69 Nr. 466b *)
1548 val t = TermC.str2term "((1 - 7*(x - 2)/(x \<up> 2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x \<up> 2 - 25))";
1549 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1550 if UnparseC.term t = "(25 + -10 * x + x \<up> 2) / 18"
1551 then () else error "rational.sml: diff.behav. in norm_Rational_mg 47";
1553 (*SRD Schalk I, p.70 Nr. 469 *)
1554 val t = TermC.str2term ("3*b \<up> 2 / (4*a \<up> 2 - 8*a*b + 4*b \<up> 2) / " ^
1555 "(a / (a \<up> 2*b - b \<up> 3) + (a - b) / (4*a*b \<up> 2 + 4*b \<up> 3) - 1 / (4*b \<up> 2))");
1556 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1557 if UnparseC.term t = "-3 * b \<up> 3 / (-2 * a + 2 * b)"
1558 then () else error "rational.sml: diff.behav. in norm_Rational_mg 48";
1560 "-------- me Schalk I No.186 -------------------------------------------------";
1561 "-------- me Schalk I No.186 -------------------------------------------------";
1562 "-------- me Schalk I No.186 -------------------------------------------------";
1563 val fmz = ["Term ((14 * x * y) / ( x * y ))", "normalform N"];
1565 ("Rational",["rational", "simplification"],
1566 ["simplification", "of_rationals"]);
1567 val p = e_pos'; val c = [];
1568 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
1569 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1570 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1571 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1572 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1573 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1574 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1575 val (p,_,f,nxt,_,pt) = me nxt p c pt;
1576 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1577 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1578 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1579 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1580 case (f2str f, nxt) of
1581 ("14", ("End_Proof'", _)) => ()
1582 | _ => error "rational.sml diff.behav. in me Schalk I No.186";
1584 "-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
1585 "-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
1586 "-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
1588 CalcTree [(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"],
1589 ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1592 autoCalculate 1 CompleteCalc;
1593 val ((pt, p), _) = get_calc 1;
1595 Test_Tool.show_pt pt;
1597 (([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))),
1598 (([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1599 (([1], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))),
1600 (([2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (-2 + x))),
1601 (([3], Res), (2 + -1 * x) * (-2 + x) / (2 * a * (2 * a))),
1602 (([4], Res), (-4 + 4 * x + -1 * x \<up> 2) / (4 * a \<up> 2)),
1603 (([], Res), (-4 + 4 * x + -1 * x \<up> 2) / (4 * a \<up> 2))]
1605 interSteps 1 ([1], Res);
1606 val ((pt, p), _) = get_calc 1;
1607 (*Test_Tool.show_pt pt;
1609 (([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))),
1610 (([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1611 (([1,1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1612 (([1,1], Res), (2 - x) / (2 * a) / (2 * a / (x + -1 * 2))),
1613 (([1,2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))),
1614 (([1], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))),
1615 (([2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (-2 + x))),
1616 (([3], Res), (2 + -1 * x) * (-2 + x) / (2 * a * (2 * a))),
1617 (([4], Res), (-4 + 4 * x + -1 * x \<up> 2) / (4 * a \<up> 2)),
1618 (([], Res), (-4 + 4 * x + -1 * x \<up> 2) / (4 * a \<up> 2))]
1620 val (t, asm) = get_obj g_result pt [1, 1];
1621 if UnparseC.term t = "(2 - x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso UnparseC.terms asm = "[]"
1622 then () else error "2nd interSteps ..Simp_Rat_Double_No-1 changed on [1, 1]";
1623 val (t, asm) = get_obj g_result pt [1, 2];
1624 if UnparseC.term t = "(2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso UnparseC.terms asm = "[]"
1625 then () else error "3rd interSteps ..Simp_Rat_Double_No-1 changed on [1, 2]";
1628 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
1629 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
1630 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
1632 CalcTree [(["Term ((a^2 + -1*b^2) / (a^2 + -2*a*b + b^2))", "normalform N"],
1633 ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1636 autoCalculate 1 CompleteCalc;
1637 val ((pt, p), _) = get_calc 1;
1638 (*Test_Tool.show_pt pt;
1640 (([], Frm), Simplify ((a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2))),
1641 (([1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2)),
1642 (([1], Res), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1643 (([2], Res), (a + b) / (a + -1 * b)),
1644 (([], Res), (a + b) / (a + -1 * b))]
1646 interSteps 1 ([2], Res);
1647 val ((pt, p), _) = get_calc 1;
1648 (*Test_Tool.show_pt pt;
1650 (([], Frm), Simplify ((a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2))),
1651 (([1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2)),
1652 (([1], Res), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1653 (([2,1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1654 (([2,1], Res), (a + b) / (a + -1 * b)),
1655 (([2], Res), (a + b) / (a + -1 * b)),
1656 (([], Res), (a + b) / (a + -1 * b))]
1658 interSteps 1 ([2,1],Res);
1659 val ((pt, p), _) = get_calc 1;
1660 (*Test_Tool.show_pt pt;
1662 (([], Frm), Simplify ((a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2))),
1663 (([1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2)),
1664 (([1], Res), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1665 (([2,1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1666 (([2,1,1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1667 (([2,1,1], Res), (a \<up> 2 + -1 * (a * b) + a * b + -1 * b \<up> 2) /
1668 (a \<up> 2 + -2 * (a * b) + 1 * b \<up> 2)),
1669 (([2,1,2], Res), (a \<up> 2 + -1 * (a * b) + a * b + -1 * b \<up> 2) /
1670 (a \<up> 2 + -2 * (a * b) + -1 \<up> 2 * b \<up> 2)),
1671 (([2,1,3], Res), (a \<up> 2 + -1 * (a * b) + a * b + -1 * b \<up> 2) /
1672 (a \<up> 2 + -2 * (a * b) + (-1 * b) \<up> 2)),
1673 (([2,1,4], Res), (a * a + -1 * (a * b) + a * b + -1 * b \<up> 2) /
1674 (a \<up> 2 + -2 * (a * b) + (-1 * b) \<up> 2)),
1675 (([2,1,5], Res), (a * a + -1 * (a * b) + a * b + -1 * (b * b)) /
1676 (a \<up> 2 + -2 * (a * b) + (-1 * b) \<up> 2)),
1677 (([2,1,6], Res), (a * a + -1 * (a * b) + a * b + -1 * (b * b)) /
1678 (a \<up> 2 + -1 * (2 * (a * b)) + (-1 * b) \<up> 2)),
1679 (([2,1,7], Res), (a * a + a * (-1 * b) + (b * a + b * (-1 * b))) /
1680 (a \<up> 2 + 2 * (a * (-1 * b)) + (-1 * b) \<up> 2)),
1681 (([2,1,8], Res), (a * a + a * (-1 * b) + (b * a + b * (-1 * b))) /
1682 (a \<up> 2 + 2 * a * (-1 * b) + (-1 * b) \<up> 2)),
1683 (([2,1,9], Res), (a * (a + -1 * b) + (b * a + b * (-1 * b))) /
1684 (a \<up> 2 + 2 * a * (-1 * b) + (-1 * b) \<up> 2)),
1685 (([2,1,10], Res), (a * (a + -1 * b) + b * (a + -1 * b)) /
1686 (a \<up> 2 + 2 * a * (-1 * b) + (-1 * b) \<up> 2)),
1687 (([2,1,11], Res), (a + b) * (a + -1 * b) / (a \<up> 2 + 2 * a * (-1 * b) + (-1 * b) \<up> 2)),
1688 (([2,1,12], Res), (a + b) * (a + -1 * b) / ((a + -1 * b) * (a + -1 * b))),
1689 (([2,1,13], Res), (a + b) / (a + -1 * b)),
1690 (([2,1], Res), (a + b) / (a + -1 * b)),
1691 (([2], Res), (a + b) / (a + -1 * b)),
1692 (([], Res), (a + b) / (a + -1 * b))]
1694 val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*);
1695 if length newnds = 13 then () else error "rational.sml: interSteps cancel_p rev_rew_p";
1697 val p = ([2,1,9],Res);
1699 val (_, tac, _) = ME_Misc.pt_extract (pt, p);
1700 case tac of SOME (Rewrite ("sym_distrib_left", _)) => ()
1701 | _ => error "rational.sml: getTactic, sym_real_plus_binom_times1";
1704 "-------- investigate rulesets for cancel_p ----------------------------------";
1705 "-------- investigate rulesets for cancel_p ----------------------------------";
1706 "-------- investigate rulesets for cancel_p ----------------------------------";
1707 val thy = @{theory "Rational"};
1708 val t = TermC.str2term "(a \<up> 2 + -1*b \<up> 2) / (a \<up> 2 + -2*a*b + b \<up> 2)";
1709 val tt = TermC.str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"(*numerator only*);
1711 "----- with rewrite_set_";
1712 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
1713 if UnparseC.term tt'= "a \<up> 2 + -1 * b \<up> 2" then () else error "rls chancel_p 1";
1714 val tt = TermC.str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*);
1715 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
1716 if UnparseC.term tt' = "a \<up> 2 + -2 * a * b + b \<up> 2" then () else error "rls chancel_p 2";
1718 "----- with Derive.do_one; WN1130912 not investigated further, will be discontinued";
1719 val SOME (tt, _) = factout_p_ thy t;
1720 if UnparseC.term tt = "(a + b) * (a + -1 * b) / ((a + -1 * b) * (a + -1 * b))"
1721 then () else error "rls chancel_p 3";
1722 UnparseC.term tt = "(1 * a + 1 * b) * (1 * a + -1 * b) / ((1 * a + -1 * b) * (1 * a + -1 * b))";
1724 "--- with simpler ruleset";
1725 val {rules, rew_ord= (_, ro), ...} = Rule_Set.rep (assoc_rls "rev_rew_p");
1726 val der = Derive.do_one thy Atools_erls rules ro NONE tt;
1727 if length der = 12 then () else error "WN1130912 rls chancel_p 4";
1728 (*default_print_depth 99;*) writeln (deriv2str der); (*default_print_depth 3;*)
1730 (*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*)
1731 "...,(-1 * b \<up> 2 + a \<up> 2) / (-2 * (a * b) + a \<up> 2 + (-1 * b) \<up> 2) ]";
1732 (*default_print_depth 99;*) map (Rule.to_string o #2) der; (*default_print_depth 3;*)
1733 (*default_print_depth 99;*) map (UnparseC.term o #1 o #3) der; (*default_print_depth 3;*)
1735 val der = Derive.do_one thy Atools_erls rules ro NONE
1736 (TermC.str2term "(1 * a + 1 * b) * (1 * a + -1 * b)");
1737 (*default_print_depth 99;*) writeln (deriv2str der); (*default_print_depth 3;*)
1739 val {rules, rew_ord=(_,ro),...} = Rule_Set.rep (assoc_rls "rev_rew_p");
1740 val der = Derive.do_one thy Atools_erls rules ro NONE
1741 (TermC.str2term "(1 * a + -1 * b) * (1 * a + -1 * b)");
1742 (*default_print_depth 99;*) writeln (deriv2str der); (*default_print_depth 3;*)
1743 (*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*)
1744 (*WN060829 ...postponed*)
1747 "-------- fun eval_get_denominator -------------------------------------------";
1748 "-------- fun eval_get_denominator -------------------------------------------";
1749 "-------- fun eval_get_denominator -------------------------------------------";
1750 val thy = @{theory Isac_Knowledge};
1751 val t = Thm.term_of (the (TermC.parse thy "get_denominator ((a +x)/b)"));
1752 val SOME (_, t') = eval_get_denominator "" 0 t thy;
1753 if UnparseC.term t' = "get_denominator ((a + x) / b) = b"
1754 then () else error "get_denominator ((a + x) / b) = b"
1757 "-------- several errpats in complicated term --------------------------------";
1758 "-------- several errpats in complicated term --------------------------------";
1759 "-------- several errpats in complicated term --------------------------------";
1760 (*WN12xxxx TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one
1761 WN130912: kept this test, although not clear what for*)
1763 CalcTree [(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"],
1764 ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1767 autoCalculate 1 CompleteCalc;
1768 val ((pt, p), _) = get_calc 1;
1769 (*Test_Tool.show_pt pt;
1771 (([], Frm), Simplify ((5 * b + 25) / (a \<up> 2 - b \<up> 2) * (a - b) / (5 * b))),
1772 (([1], Frm), (5 * b + 25) / (a \<up> 2 - b \<up> 2) * (a - b) / (5 * b)),
1773 (([1], Res), (5 * b + 25) / (a \<up> 2 + -1 * b \<up> 2) * (a + -1 * b) / (5 * b)),
1774 (([2], Res), (5 * b + 25) * (a + -1 * b) / (a \<up> 2 + -1 * b \<up> 2) / (5 * b)),
1775 (([3], Res), (25 * a + -25 * b + 5 * (a * b) + -5 * b \<up> 2) / (a \<up> 2 + -1 * b \<up> 2) /
1777 (([4], Res), (25 + 5 * b) / (a + b) / (5 * b)),
1778 (([5], Res), (25 + 5 * b) / ((a + b) * (5 * b))),
1779 (([6], Res), (25 + 5 * b) / (5 * (a * b) + 5 * b \<up> 2)),
1780 (([7], Res), (5 + b) / (a * b + b \<up> 2)),
1781 (([], Res), (5 + b) / (a * b + b \<up> 2))] *)
1784 "-------- WN1309xx non-terminating rls norm_Rational -------------------------";
1785 "-------- WN1309xx non-terminating rls norm_Rational -------------------------";
1786 "-------- WN1309xx non-terminating rls norm_Rational -------------------------";
1787 (*------- Schalk I, p.70 Nr. 480b; a/b : c/d translated to a/b * d/c*)
1788 val t = TermC.str2term
1789 ("((12*x*y / (9*x \<up> 2 - y \<up> 2)) / (1 / (3*x - y) \<up> 2 - 1 / (3*x + y) \<up> 2)) * " ^
1790 "((1/(x - 5*y) \<up> 2 - 1/(x + 5*y) \<up> 2) / (20*x*y / (x \<up> 2 - 25*y \<up> 2)))");
1792 (*1st factor separately simplified *)
1793 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))";
1794 val SOME (t', _) = rewrite_set_ thy false norm_Rational t;
1795 if UnparseC.term t' = "(-9 * x \<up> 2 + y \<up> 2) / -1" then () else error "Nr. 480b lhs changed";
1796 (*2nd factor separately simplified *)
1797 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)))";
1798 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1799 if UnparseC.term t' = "-1 / (-1 * x \<up> 2 + 25 * y \<up> 2)" then () else error "Nr. 480b rhs changed";
1801 "-------- Schalk I, p.70 Nr. 477a: terms are exploding ?!?";
1802 val t = TermC.str2term ("b*y/(b - 2*y)/((b \<up> 2 - y \<up> 2)/(b+2*y)) /" ^
1803 "(b \<up> 2*y + b*y \<up> 2) * (a+x) \<up> 2 / ((b \<up> 2 - 4*y \<up> 2) * (a+2*x) \<up> 2)");
1804 (*val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
1806 ### rls: cancel_p on: (a \<up> 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \<up> 2 * y)) /
1808 ((b \<up> 2 + -1 * y \<up> 2) / (b + 2 * y)) /
1809 (b \<up> 2 * y + b * y \<up> 2) /
1810 (a \<up> 2 * b \<up> 2 + -4 * (a \<up> 2 * y \<up> 2) + 4 * (a * (b \<up> 2 * x)) +
1811 -16 * (a * (x * y \<up> 2)) +
1812 4 * (b \<up> 2 * x \<up> 2) +
1813 -16 * (x \<up> 2 * y \<up> 2))
1814 exception Div raised
1817 val t = TermC.str2term
1818 ("(a \<up> 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \<up> 2 * y)) /" ^
1820 "((b \<up> 2 + -1 * y \<up> 2) / (b + 2 * y)) /" ^
1821 "(b \<up> 2 * y + b * y \<up> 2) /" ^
1822 "(a \<up> 2 * b \<up> 2 + -4 * (a \<up> 2 * y \<up> 2) + 4 * (a * (b \<up> 2 * x)) +" ^
1823 "-16 * (a * (x * y \<up> 2)) +" ^
1824 "4 * (b \<up> 2 * x \<up> 2) +" ^
1825 "-16 * (x \<up> 2 * y \<up> 2))");
1826 NONE = cancel_p_ thy t;
1829 (*------- Schalk I, p.70 Nr. 476b in 2003 this worked using 10 sec. *)
1830 val t = TermC.str2term
1831 ("((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) / " ^
1832 "((a \<up> 2 + b \<up> 2) \<up> 2 / (a + b) \<up> 2)");
1833 (* Rewrite.trace_on := true;
1834 rewrite_set_ thy false norm_Rational t;
1836 #### rls: cancel_p on: (2 * (a \<up> 7 * b) + 4 * (a \<up> 6 * b \<up> 2) + 6 * (a \<up> 5 * b \<up> 3) +
1837 8 * (a \<up> 4 * b \<up> 4) +
1838 6 * (a \<up> 3 * b \<up> 5) +
1839 4 * (a \<up> 2 * b \<up> 6) +
1840 2 * (a * b \<up> 7)) /
1841 (2 * (a \<up> 9 * b) + 4 * (a \<up> 8 * b \<up> 2) +
1842 2 * (2 * (a \<up> 7 * b \<up> 3)) +
1843 4 * (a \<up> 6 * b \<up> 4) +
1844 -4 * (a \<up> 4 * b \<up> 6) +
1845 -4 * (a \<up> 3 * b \<up> 7) +
1846 -4 * (a \<up> 2 * b \<up> 8) +
1847 -2 * (a * b \<up> 9))
1849 if UnparseC.term t = "1 / (a \<up> 2 + -1 * b \<up> 2)" then ()
1850 else error "rational.sml: diff.behav. in norm_Rational_mg 49";
1853 "-------- Schalk I, p.70 Nr. 480a: terms are exploding ?!?";
1854 val t = TermC.str2term ("(1/x + 1/y + 1/z) / (1/x - 1/y - 1/z) / " ^
1855 "(2*x \<up> 2 / (x \<up> 2 - z \<up> 2) / (x / (x + z) + x / (x - z)))");
1856 (* Rewrite.trace_on := true;
1857 rewrite_set_ thy false norm_Rational t;
1859 #### rls: cancel_p on: (2 * (x \<up> 6 * (y \<up> 2 * z)) + 2 * (x \<up> 6 * (y * z \<up> 2)) +
1860 2 * (x \<up> 5 * (y \<up> 2 * z \<up> 2)) +
1861 -2 * (x \<up> 4 * (y \<up> 2 * z \<up> 3)) +
1862 -2 * (x \<up> 4 * (y * z \<up> 4)) +
1863 -2 * (x \<up> 3 * (y \<up> 2 * z \<up> 4))) /
1864 (-2 * (x \<up> 6 * (y \<up> 2 * z)) + -2 * (x \<up> 6 * (y * z \<up> 2)) +
1865 2 * (x \<up> 5 * (y \<up> 2 * z \<up> 2)) +
1866 2 * (x \<up> 4 * (y \<up> 2 * z \<up> 3)) +
1867 2 * (x \<up> 4 * (y * z \<up> 4)) +
1868 -2 * (x \<up> 3 * (y \<up> 2 * z \<up> 4)))
1871 "-------- Schalk I, p.60 Nr. 215d: terms are exploding, internal loop does not terminate";
1872 val t = TermC.str2term "(a-b) \<up> 3 * (x+y) \<up> 4 / ((x+y) \<up> 2 * (a-b) \<up> 5)";
1873 (* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt:
1875 val t = TermC.str2term "(a-b) \<up> 3 * (x+y) \<up> 4";
1876 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1878 "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";
1879 val t = TermC.str2term "((x+y) \<up> 2 * (a-b) \<up> 5)";
1880 val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1882 "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";
1884 anscheinend macht dem Rechner das Krzen diese Bruches keinen Spass mehr ...*)
1886 "-------- Schalk I, p.70 Nr. 480b: terms are exploding, Rewrite.trace_on stops at";
1887 val t = TermC.str2term ("((12*x*y/(9*x \<up> 2 - y \<up> 2))/" ^
1888 "(1/(3*x - y) \<up> 2 - 1/(3*x + y) \<up> 2)) *" ^
1889 "(1/(x - 5*y) \<up> 2 - 1/(x + 5*y) \<up> 2)/" ^
1890 "(20*x*y/(x \<up> 2 - 25*y \<up> 2))");
1891 (*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1893 #### rls: cancel_p on: (19440 * (x \<up> 8 * y \<up> 2) + -490320 * (x \<up> 6 * y \<up> 4) +
1894 108240 * (x \<up> 4 * y \<up> 6) +
1895 -6000 * (x \<up> 2 * y \<up> 8)) /
1896 (2160 * (x \<up> 8 * y \<up> 2) + -108240 * (x \<up> 6 * y \<up> 4) +
1897 1362000 * (x \<up> 4 * y \<up> 6) +
1898 -150000 * (x \<up> 2 * y \<up> 8))