# HG changeset patch # User wneuper # Date 1626411454 -7200 # Node ID 464109593df01b39fb6d0b0104f1c4a5d96f2dc0 # Parent 33e04eb1a2f0d81e0130d908b6d23a318e253ec8 separate rational-1 /-2.sml diff -r 33e04eb1a2f0 -r 464109593df0 test/Tools/isac/Knowledge/rational-1.sml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/Tools/isac/Knowledge/rational-1.sml Fri Jul 16 06:57:34 2021 +0200 @@ -0,0 +1,151 @@ +(* Title: test/Tools/isac/Knowledge/rational-1.sml + Author: Walther Neuper + Use is subject to license terms. + +Test of basic functions and application to complex examples. +*) + +"-----------------------------------------------------------------------------------------------"; +"-----------------------------------------------------------------------------------------------"; +"table of contents -----------------------------------------------------------------------------"; +"-----------------------------------------------------------------------------------------------"; +"-------- fun poly_of_term ---------------------------------------------------------------------"; +"-------- fun is_poly --------------------------------------------------------------------------"; +"-------- fun term_of_poly ---------------------------------------------------------------------"; +"-------- complex examples: rls norm_Rational --------------------------------------------------"; +"-------- complex examples cancellation from: Mathematik 1 Schalk ------------------------------"; +"-----------------------------------------------------------------------------------------------"; +"-----------------------------------------------------------------------------------------------"; + + +"-------- fun poly_of_term ---------------------------------------------------------------------"; +"-------- fun poly_of_term ---------------------------------------------------------------------"; +"-------- fun poly_of_term ---------------------------------------------------------------------"; +val thy = @{theory Partial_Fractions}; +val vs = TermC.vars_of (TermC.str2term "12 * x \ 3 * y \ 4 * z \ 6"); + +val t = TermC.str2term "-3 + -2 * x ::real"; +if poly_of_term vs t = SOME [(~3, [0, 0, 0]), (~2, [1, 0, 0])] +then () else error "poly_of_term uminus changed"; + +if poly_of_term vs (TermC.str2term "12::real") = SOME [(12, [0, 0, 0])] +then () else error "poly_of_term 1 changed"; + +if poly_of_term vs (TermC.str2term "x::real") = SOME [(1, [1, 0, 0])] +then () else error "poly_of_term 2 changed"; + +if poly_of_term vs (TermC.str2term "12 * x \ 3") = SOME [(12, [3, 0, 0])] +then () else error "poly_of_term 3 changed"; +"~~~~~ fun poly_of_term , args:"; val (vs, t) = + (vs, (TermC.str2term "12 * x \ 3")); + + monom_of_term vs (1, replicate (length vs) 0) t;(*poly malformed 1 with x \ 3*) +"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const ("Groups.times_class.times", _) $ m1 $ m2)) = + (vs, (1, replicate (length vs) 0), t); + val (c', es') = + + monom_of_term vs (c, es) m1; +"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const ("Transcendental.powr", _) $ (t as Free _) $ (Const ("Num.numeral_class.numeral", _) $ num)) ) = + (vs, (c', es'), m2); +(*+*)c = 12; +(*+*)(num |> HOLogic.dest_numeral |> list_update es (find_index (curry op = t) vs)) = [3, 0, 0]; + +if (c, num |> HOLogic.dest_numeral |> list_update es (find_index (curry op = t) vs)) = (12, [3, 0, 0]) +then () else error "monom_of_term (powr): return value CHANGED"; + +if poly_of_term vs (TermC.str2term "12 * x \ 3 * y \ 4 * z \ 6") = SOME [(12, [3, 4, 6])] +then () else error "poly_of_term 4 changed"; + +if poly_of_term vs (TermC.str2term "1 + 2 * x \ 3 * y \ 4 * z \ 6 + y") = + SOME [(1, [0, 0, 0]), (1, [0, 1, 0]), (2, [3, 4, 6])] +then () else error "poly_of_term 5 changed"; + +(*poly_of_term is quite liberal:*) +(*the coefficient may be somewhere, the order of variables and the parentheses + within a monomial are arbitrary*) +if poly_of_term vs (TermC.str2term "y \ 4 * (x \ 3 * 12 * z \ 6)") = SOME [(12, [3, 4, 6])] +then () else error "poly_of_term 6 changed"; + +(*there may even be more than 1 coefficient:*) +if poly_of_term vs (TermC.str2term "2 * y \ 4 * (x \ 3 * 6 * z \ 6)") = SOME [(12, [3, 4, 6])] +then () else error "poly_of_term 7 changed"; + +(*the order and the parentheses within monomials are arbitrary:*) +if poly_of_term vs (TermC.str2term "2 * x \ 3 * y \ 4 * z \ 6 + (7 * y \ 8 + 1)") + = SOME [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 6])] +then () else error "poly_of_term 8 changed"; + +(*from --- rls norm_Rational downto fun gcd_poly ---*) +val t = TermC.str2term (*copy from above: "::real" is not required due to " \ "*) + ("(-12 + 4 * y + 3 * x \ 2 + -1 * (x \ 2 * y)) /" ^ + "(-18 + -9 * x + 2 * y \ 2 + x * y \ 2)"); +"~~~~~ fun cancel_p_, args:"; val (t) = (t); +val opt = check_fraction t; +val SOME (numerator, denominator) = opt; +(*+*)UnparseC.term numerator = "- 12 + 4 * y + 3 * x \ 2 + - 1 * (x \ 2 * y)"; (*isa -- isa2*); +(*+*)UnparseC.term denominator = "- 18 + - 9 * x + 2 * y \ 2 + x * y \ 2"; (*isa -- isa2*); + val vs = TermC.vars_of t; +(*+*)UnparseC.terms vs = "[\"x\", \"y\"]"; + val baseT = type_of numerator + val expT = HOLogic.realT; +val (SOME _, SOME _) = (poly_of_term vs numerator, poly_of_term vs denominator); (*isa <> isa2*) + +"-------- fun is_poly --------------------------------------------------------------------------"; +"-------- fun is_poly --------------------------------------------------------------------------"; +"-------- fun is_poly --------------------------------------------------------------------------"; +if is_poly (TermC.str2term "2 * x \ 3 * y \ 4 * z \ 6 + 7 * y \ 8 + 1") +then () else error "is_poly 1 changed"; +if not (is_poly (TermC.str2term "2 * (x \ 3 * y \ 4 * z \ 6 + 7) * y \ 8 + 1")) +then () else error "is_poly 2 changed"; + +"-------- fun term_of_poly ---------------------------------------------------------------------"; +"-------- fun term_of_poly ---------------------------------------------------------------------"; +"-------- fun term_of_poly ---------------------------------------------------------------------"; +val expT = HOLogic.realT +val Free (_, baseT) = (hd o vars o TermC.str2term) "12 * x \ 3 * y \ 4 * z \ 6"; +val p = [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 5])] +val vs = TermC.vars_of (the (parseNEW ctxt "12 * x \ 3 * y \ 4 * z \ 6")) +(*precondition for [(c, es),...]: legth es = length vs*) +; +if UnparseC.term (term_of_poly baseT expT vs p) = "1 + 7 * y \ 8 + 2 * x \ 3 * y \ 4 * z \ 5" +then () else error "term_of_poly 1 changed"; + +"-------- complex examples: rls norm_Rational --------------------------------------------------"; +"-------- complex examples: rls norm_Rational --------------------------------------------------"; +"-------- complex examples: rls norm_Rational --------------------------------------------------"; +val t = TermC.str2term "(3*x+5)/18 - x/2 - -(3*x - 2)/9 = 0"; +val SOME (t', _) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; +if UnparseC.term t' = "1 / 18 = 0" then () else error "rational.sml 1"; + +val t = TermC.str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0"; +val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; +if UnparseC.term t' = "(237 + 65 * x) / 36 = 0" then () +else error "rational.sml 2"; + +val t = TermC.str2term "(1/2 + (5*x)/2) \ 2 - ((13*x)/2 - 5/2) \ 2 - (6*x) \ 2 + 29"; +val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; +if UnparseC.term t' = "23 + 35 * x + - 72 * x \ 2" then () +else error "rational.sml 3"; + +"-------- complex examples cancellation from: Mathematik 1 Schalk ------------------------------"; +"-------- complex examples cancellation from: Mathematik 1 Schalk ------------------------------"; +"-------- complex examples cancellation from: Mathematik 1 Schalk ------------------------------"; +(*Schalk I, p.60 Nr. 215c *) +val t = TermC.str2term "(a + b) \ 4 * (x - y) / ((x - y) \ 3 * (a + b) \ 2)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(a \ 2 + 2 * a * b + b \ 2) / (x \ 2 + - 2 * x * y + y \ 2)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 7"; + +(*SRC Schalk I, p.66 Nr. 381b *) +val t = TermC.str2term +"(4*x \ 2 - 20*x + 25)/(2*x - 5) \ 3"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "1 / (- 5 + 2 * x)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 9"; + +(*Schalk I, p.60 Nr. 215c *) +val t = TermC.str2term "(a + b) \ 4 * (x - y) / ((x - y) \ 3 * (a + b) \ 2)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(a \ 2 + 2 * a * b + b \ 2) / (x \ 2 + - 2 * x * y + y \ 2)" +then () else error "Schalk I, p.60 Nr. 215c: with Isabelle2002 cancellation incomplete, changed"; + diff -r 33e04eb1a2f0 -r 464109593df0 test/Tools/isac/Knowledge/rational-2.sml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/Tools/isac/Knowledge/rational-2.sml Fri Jul 16 06:57:34 2021 +0200 @@ -0,0 +1,1791 @@ +(* Title: tests for rationals + Author: Walther Neuper + Use is subject to license terms. +*) + +"-----------------------------------------------------------------------------"; +"-----------------------------------------------------------------------------"; +"table of contents -----------------------------------------------------------"; +"-----------------------------------------------------------------------------"; +"-------- integration lev.1 fun factout_p_ -----------------------------------"; +"-------- integration lev.1 fun cancel_p_ ------------------------------------"; +"-------- integration lev.1 fun common_nominator_p_ --------------------------"; +"-------- integration lev.1 fun add_fraction_p_ ------------------------------"; +"Rfuns-------- and app_rev ...traced down from rewrite_set_ until prepats ---------"; +"Rfuns-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------"; +"-------- rls norm_Rational downto fun gcd_poly ------------------------------"; +"Rfuns-------- rls norm_Rational downto fun add_fraction_p_ -----------------------"; +"----------- rewrite_set_ Partial_Fractions norm_Rational --------------------------------------"; +"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; +"----------- fun cancel_p with Const AA --------------------------------------------------------"; +"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----"; +"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------"; +"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------"; +"Rfuns-------- reverse rewrite ----------------------------------------------------"; +"Rfuns-------- 'reverse-ruleset' cancel_p -----------------------------------------"; +"-------- investigate rls norm_Rational --------------------------------------"; +"-------- examples: rls norm_Rational ----------------------------------------"; +"-------- rational numerals --------------------------------------------------"; +"-------- examples cancellation from: Mathematik 1 Schalk --------------------"; +"-------- examples common denominator from: Mathematik 1 Schalk --------------"; +"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------"; +"-------- examples common denominator and multiplication from: Schalk --------"; +"-------- examples double fractions from: Mathematik 1 Schalk ----------------"; +"-------- me Schalk I No.186 -------------------------------------------------"; +"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------"; +"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------"; +"-------- investigate rulesets for cancel_p ----------------------------------"; +"-------- fun eval_get_denominator -------------------------------------------"; +"-------- several errpats in complicated term --------------------------------"; +"-------- WN1309xx non-terminating rls norm_Rational -------------------------"; +"-----------------------------------------------------------------------------"; +"-----------------------------------------------------------------------------"; + + +"-------- integration lev.1 fun factout_p_ -----------------------------------"; +"-------- integration lev.1 fun factout_p_ -----------------------------------"; +"-------- integration lev.1 fun factout_p_ -----------------------------------"; +val t = TermC.str2term "(x \ 2 + -1*y \ 2) / (x \ 2 + -1*x*y)" +val SOME (t', asm) = factout_p_ thy t; +if UnparseC.term t' = "(x + y) * (x + - 1 * y) / (x * (x + - 1 * y))" +then () else error ("factout_p_ term 1 changed: " ^ UnparseC.term t') +; +if UnparseC.terms asm = "[\"x \ 0\", \"x + - 1 * y \ 0\"]" +then () else error "factout_p_ asm 1 changed" +; +val t = TermC.str2term "nothing + to_cancel ::real"; +if NONE = factout_p_ thy t then () else error "factout_p_ doesn't report non-applicable"; +; +val t = TermC.str2term "((3 * x \ 2 + 6 *x + 3) / (2*x + 2))"; +val SOME (t', asm) = factout_p_ thy t; +if UnparseC.term t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso + UnparseC.terms asm = "[\"1 + x \ 0\"]" +then () else error "factout_p_ 1 changed"; + +"-------- integration lev.1 fun cancel_p_ ------------------------------------"; +"-------- integration lev.1 fun cancel_p_ ------------------------------------"; +"-------- integration lev.1 fun cancel_p_ ------------------------------------"; +val t = TermC.str2term "(x \ 2 + -1*y \ 2) / (x \ 2 + -1*x*y)" +val SOME (t', asm) = cancel_p_ thy t; +if (UnparseC.term t', UnparseC.terms asm) = ("(x + y) / x", "[\"x \ 0\"]") +then () else error ("cancel_p_ (t', asm) 1 changed: " ^ UnparseC.term t') +; +val t = TermC.str2term "nothing + to_cancel ::real"; +if NONE = cancel_p_ thy t then () else error "cancel_p_ doesn't report non-applicable"; +; +val t = TermC.str2term "((3 * x \ 2 + 6 *x + 3) / (2*x + 2))"; +val SOME (t', asm) = cancel_p_ thy t; +if UnparseC.term t' = "(3 + 3 * x) / 2" andalso UnparseC.terms asm = "[]" +then () else error "cancel_p_ 1 changed"; + +"-------- integration lev.1 fun common_nominator_p_ --------------------------"; +"-------- integration lev.1 fun common_nominator_p_ --------------------------"; +"-------- integration lev.1 fun common_nominator_p_ --------------------------"; +val t = TermC.str2term ("y / (a*x + b*x + c*x) " ^ + (* n1 d1 *) + "+ a / (x*y)"); + (* n2 d2 *) +val SOME (t', asm) = common_nominator_p_ thy t; +if UnparseC.term t' = + ("y * y / (x * ((a + b + c) * y)) " ^ + (* n1 *d2'/ (c'* ( d1' *d2')) *) + "+ a * (a + b + c) / (x * ((a + b + c) * y))") + (* n2 * d1' / (c'* ( d1' *d2')) *) +then () else error "common_nominator_p_ term 1 changed"; +if UnparseC.terms asm = "[\"a + b + c \ 0\", \"y \ 0\", \"x \ 0\"]" +then () else error "common_nominator_p_ asm 1 changed" + +"-------- example in mail Nipkow"; +val t = TermC.str2term "x/(x \ 2 + -1*y \ 2) + y/(x \ 2 + -1*x*y)"; +val SOME (t', asm) = common_nominator_p_ thy t; +if UnparseC.term t' = + "x * x / ((x + - 1 * y) * ((x + y) * x)) +\ny * (x + y) / ((x + - 1 * y) * ((x + y) * x))" +then () else error "common_nominator_p_ term 2 changed" +; +if UnparseC.terms asm = "[\"x + y \ 0\", \"x \ 0\", \"x + - 1 * y \ 0\"]" +then () else error "common_nominator_p_ asm 2 changed" + +"-------- example: applicable tested by SML code"; +val t = TermC.str2term "nothing / to_add"; +if NONE = common_nominator_p_ thy t then () else error "common_nominator_p_ term 3 changed"; +; +val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))"; +val SOME (t', asm) = common_nominator_p_ thy t; +if UnparseC.term t' = + "(x + - 1) * (- 1 + x) / ((1 + x) * (- 1 + x)) +\n(x + 1) * (1 + x) / ((1 + x) * (- 1 + x))" + andalso UnparseC.terms asm = "[\"1 + x \ 0\", \"- 1 + x \ 0\"]" +then () else error "common_nominator_p_ 3 changed"; + +"-------- integration lev.1 fun add_fraction_p_ ------------------------------"; +"-------- integration lev.1 fun add_fraction_p_ ------------------------------"; +"-------- integration lev.1 fun add_fraction_p_ ------------------------------"; +val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))"; +val SOME (t', asm) = add_fraction_p_ thy t; +if UnparseC.term t' = "(2 + 2 * x \ 2) / (- 1 + x \ 2)" +then () else error "add_fraction_p_ 3 changed"; +; +if UnparseC.terms asm = "[\"- 1 + x \ 2 \ 0\"]" +then () else error "add_fraction_p_ 3 changed"; +; +val t = TermC.str2term "nothing / to_add"; +if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ term 3 changed"; +; +val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))"; +val SOME (t', asm) = add_fraction_p_ thy t; +if UnparseC.term t' = "(2 + 2 * x \ 2) / (- 1 + x \ 2)" andalso + UnparseC.terms asm = "[\"- 1 + x \ 2 \ 0\"]" +then () else error "add_fraction_p_ 3 changed"; + +"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------"; +"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------"; +"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------"; +(* trace down until prepats are evaluated + (which does not to work, because substitution is not done -- compare rew_sub!); + keep this sequence for the case, factout_p, cancel_p, common_nominator_p, add_fraction_p + (again) get prepat = [] changed to <>[]. *) +val t = TermC.str2term "(x \ 2 + -1*y \ 2) / (x \ 2 + -1*x*y)"; + +(*rewrite_set_ @{theory Isac_Knowledge} true cancel t = NONE; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) +"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (thy, false, cancel_p, t); +"~~~~~ fun rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) = + (thy, 1, bool, [], rls, term); +(*val (t', asm, rew) = app_rev thy (i+1) rrls t; rew = false!!!!!!!!!!!!!!!!!!!!!*) +"~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t); + fun chk_prepat thy erls [] t = true + | chk_prepat thy erls prepat t = + let + fun chk (pres, pat) = + (let + val subst: Type.tyenv * Envir.tenv = + Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty) + in + snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls) + end) handle Pattern.MATCH => false + fun scan_ f [] = false (*scan_ NEVER called by []*) + | scan_ f (pp::pps) = + if f pp then true else scan_ f pps; + in scan_ chk prepat end; + (* apply the normal_form of a rev-set *) + fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t = + if chk_prepat thy erls prepat t + then ((*tracing("### app_rev': t = "^UnparseC.term t);*) normal_form t) + else NONE; +(* val opt = app_rev' thy rrls t ..NONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) +"~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) = + (thy, rrls, t); +(* chk_prepat thy erls prepat t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) +(* app_sub thy i rrls t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) +"~~~~~ fun chk_prepat, args:"; val (thy, erls, prepat, t) = (thy, erls, prepat, t); + fun chk (pres, pat) = + (let + val subst: Type.tyenv * Envir.tenv = + Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty) + in + snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls) + end) handle Pattern.MATCH => false + fun scan_ f [] = false (*scan_ NEVER called by []*) + | scan_ f (pp::pps) = + if f pp then true else scan_ f pps; + +(*========== inhibit exn WN130823: prepat is empty ==================================== +(* scan_ chk prepat = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) +"~~~~~ fun , args:"; val (f, (pp::pps)) = (chk, prepat); +f; +val ([t1, t2], t) = pp; +UnparseC.term t1 = "?r is_expanded"; +UnparseC.term t2 = "?s is_expanded"; +UnparseC.term t = "?r / ?s"; +(* f pp = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) +"~~~~~ fun chk, args:"; val (pres, pat) = (pp); + val subst: Type.tyenv * Envir.tenv = + Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty) +(*subst = + ({}, {(("r", 0), ("real", Var (("r", 0), "real"))), + (("s", 0), ("real", Var (("s", 0), "real")))}*) +; + snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls) +"~~~~~ fun eval__true, args:"; val (thy, i, asms, bdv, rls) = + (thy, (i + 1), (map (Envir.subst_term subst) pres), [], erls); +UnparseC.terms asms; (* = "[\"?r is_expanded\",\"?s is_expanded\"]"*) +asms = [@{term True}] orelse asms = []; (* = false*) +asms = [@{term False}] ; (* = false*) +"~~~~~ fun chk, args:"; val (indets, (a::asms)) = ([], asms); +bdv (*= []: _a list*); +val bdv : (term * term) list = []; +rewrite__set_ thy (i+1) false; +UnparseC.term a = "?r is_expanded"; (*hier m"usste doch der Numerator eingesetzt sein ??????????????*) +val SOME (Const ("HOL.False", _), []) = rewrite__set_ thy (i+1) false bdv rls a +============ inhibit exn WN130823: prepat is empty ===================================*) + +"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------"; +"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------"; +"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------"; +val t = TermC.str2term "(12 * x * y) / (8 * y \ 2 )"; +(* "-------- example 187a": exception Div raised... +val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*) +val t = TermC.str2term "(8 * x \ 2 * y * z ) / (18 * x * y \ 2 * z )"; +(* "-------- example 187b": doesn't terminate... +val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*) +val t = TermC.str2term "(9 * x \ 5 * y \ 2 * z \ 4) / (15 * x \ 6 * y \ 3 * z )"; +(* "-------- example 187c": doesn't terminate... +val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*) +"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (@{theory Isac_Knowledge}, false, cancel_p, t); +(* WN130827: exception Div raised... +rewrite__set_ thy 1 bool [] rls term +*) +"~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) = + (thy, 1, bool, [], rls, term); +(* WN130827: exception Div raised... + val (t', asm, rew) = app_rev thy (i+1) rrls t +*) +"~~~~~ fun app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t); +(* WN130827: exception Div raised... + val opt = app_rev' thy rrls t +*) +"~~~~~ fun app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) = + (thy, rrls, t); +chk_prepat thy erls prepat t = true; +(* WN130827: exception Div raised... +normal_form t +*) +(* lookup Rational.thy, cancel_p: normal_form = cancel_p_ thy*) +"~~~~~ fun cancel_p_, args:"; val (t) = (t); +val opt = check_fraction t; +val SOME (numerator, denominator) = opt + val vs = TermC.vars_of t + val baseT = type_of numerator + val expT = HOLogic.realT +val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator); +(*"-------- example 187a": exception Div raised... +val a = [(12, [1, 1])]: poly +val b = [(8, [0, 2])]: poly + val ((a', b'), c) = gcd_poly a b +*) +(* "-------- example 187b": doesn't terminate... +val a = [(8, [2, 1, 1])]: poly +val b = [(18, [1, 2, 1])]: poly + val ((a', b'), c) = gcd_poly a b +*) +(* "-------- example 187c": doesn't terminate... +val a = [(9, [5, 2, 4])]: poly +val b = [(15, [6, 3, 1])]: poly + val ((a', b'), c) = gcd_poly a b +*) + +"-------- rls norm_Rational downto fun gcd_poly ------------------------------"; +"-------- rls norm_Rational downto fun gcd_poly ------------------------------"; +"-------- rls norm_Rational downto fun gcd_poly ------------------------------"; +val t = TermC.str2term "(x \ 2 - 4)*(3 - y) / ((y \ 2 - 9)*(2+x))"; +Rewrite.trace_on := false (*true false*); +(* trace stops with ...: (and then jEdit hangs).. +rewrite_set_ thy false norm_Rational t; +: +### rls: cancel_p on: (-12 + 4 * y + 3 * x \ 2 + -1 * (x \ 2 * y)) / +(-18 + -9 * x + 2 * y \ 2 + x * y \ 2) +*) +val t = TermC.str2term (*copy from above: "::real" is not required due to " \ "*) + ("(-12 + 4 * y + 3 * x \ 2 + -1 * (x \ 2 * y)) /" ^ + "(-18 + -9 * x + 2 * y \ 2 + x * y \ 2)"); +(*cancel_p_ thy t; +exception Div raised*) + +"~~~~~ fun cancel_p_, args:"; val (t) = (t); +val opt = check_fraction t; +val SOME (numerator, denominator) = opt + val vs = TermC.vars_of t + val baseT = type_of numerator + val expT = HOLogic.realT; +(*default_print_depth 3; 999*) +val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator); +(*default_print_depth 3; 999*) +(* does not terminate instead of returning ?: + val ((a', b'), c) = gcd_poly a b +val a = [(~12, [0, 0]), (3, [2, 0]), (4, [0, 1]), (~1, [2, 1])]: poly +val b = [(~18, [0, 0]), (~9, [1, 0]), (2, [0, 2]), (1, [1, 2])]: poly +*) + +"-------- rls norm_Rational downto fun add_fraction_p_ -----------------------"; +"-------- rls norm_Rational downto fun add_fraction_p_ -----------------------"; +"-------- rls norm_Rational downto fun add_fraction_p_ -----------------------"; +val thy = @{theory Isac_Knowledge}; +"----- SK060904-2a non-termination of add_fraction_p_"; +val t = TermC.str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^ + " (-1 * a + b * x) / (a + b * x) "); +(* rewrite_set_ thy false norm_Rational t +exception Div raised*) +(* rewrite_set_ thy false add_fractions_p t; +exception Div raised*) +"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = + (@{theory Isac_Knowledge}, false, add_fractions_p, t); +"~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) = + (thy, 1, bool, [], rls, term); +(* app_rev thy (i+1) rrls t; +exception Div raised*) +"~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t); + fun chk_prepat thy erls [] t = true + | chk_prepat thy erls prepat t = + let + fun chk (pres, pat) = + (let + val subst: Type.tyenv * Envir.tenv = + Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty) + in + snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls) + end) handle Pattern.MATCH => false + fun scan_ f [] = false (*scan_ NEVER called by []*) + | scan_ f (pp::pps) = + if f pp then true else scan_ f pps; + in scan_ chk prepat end; + (* apply the normal_form of a rev-set *) + fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t = + if chk_prepat thy erls prepat t + then ((*tracing("### app_rev': t = "^UnparseC.term t);*) normal_form t) + else NONE; +(* val opt = app_rev' thy rrls t; +exception Div raised*) +(* val opt = app_rev' thy rrls t; +exception Div raised*) +"~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) = + (thy, rrls, t); +chk_prepat thy erls prepat t = true = true; +(*normal_form t +exception Div raised*) +(* lookup Rational.thy, val add_fractions_p: normal_form = add_fraction_p_ thy*) +(*add_fraction_p_ thy t +exception Div raised*) +"~~~~~ fun add_fraction_p_, args:"; val ((_: theory), t) = (thy, t); +val SOME ((n1, d1), (n2, d2)) = check_frac_sum t; +UnparseC.term n1; UnparseC.term d1; UnparseC.term n2; UnparseC.term d2; + val vs = TermC.vars_of t; +(*default_print_depth 3; 999*) +val (SOME _, SOME a, SOME _, SOME b) = + (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2); +(*default_print_depth 3; 999*) +(* +val a = [(1, [1, 0, 0]), (~1, [0, 1, 1])]: poly +val b = [(1, [1, 0, 0]), (1, [0, 1, 1])]: poly + val ((a', b'), c) = gcd_poly a b +*) + +"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; +"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; +"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; +val thy = @{theory Isac_Knowledge(*Partial_Fractions*)} +val ctxt = Proof_Context.init_global thy; + +(*---------- (1) with Free A, B ----------------------------------------------------------------*) +val t = (the o (parseNEW ctxt)) "3 = A / 2 + A / 4 + (B / 2 + -1 * B / (2::real))"; + (* required for applying thms in rewriting \ ^*) +(* we get details from here..*) + +Rewrite.trace_on := false; +val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t; +Rewrite.trace_on := false; +(* Rewrite.trace_on: +add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) + (* |||||||||||||||||||||||||||||||||||| *) + +val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 1 GUESS 1 GUESS 1 GUESS 1 *) + "A / 2 + A / 4 + (B / 2 + -1 * B / (2::real))"; +"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); +val NONE = (*case*) check_frac_sum t (*of*) + +(* Rewrite.trace_on: +add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) + (* |||||||||||||||||||||||||||| *) +val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 2 GUESS 2 GUESS 2 GUESS 2 *) + "A / 4 + (B / 2 + -1 * B / (2::real))"; +"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); +val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*); +(*+*)if (UnparseC.term n1, UnparseC.term d1) = ("A" , "4") andalso +(*+*) (UnparseC.term n2, UnparseC.term d2) = ("B / 2 + - 1 * B / 2", "1") +(*+*)then () else error "check_frac_sum (A / 4 + (B / 2 + -1 * B / (2::real))) changed"; + + val vs = TermC.vars_of t; +val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) = + (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*); + +"~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1); +val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t]; +(*+*)if xxx = 1 then () else error "monom_of_term changed" + +"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Free (id, _))) = + (vs, (1, replicate (length vs) 0), t); +case vs of [Free ("A", _), Free ("B", _)] => + if c = 1 andalso id = "A" + then () else error "monom_of_term Free changed 1" +| _ => error "monom_of_term Free changed 2"; + +(*---------- (2) with Const AA, BB --------------------------------------------------------------*) +val t = (the o (parseNEW ctxt)) "3 = AA / 2 + AA / 4 + (BB / 2 + -1 * BB / 2)"; + (*AA :: real*) +(* we get details from here..*) + +Rewrite.trace_on := false; +val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t; +Rewrite.trace_on := false; +(* Rewrite.trace_on: +add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) + (* |||||||||||||||||||||||||||||||||||| *) +val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *) + "AA / 2 + AA / 4 + (BB / 2 + -1 * BB / 2)"; +"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); +val NONE = (*case*) check_frac_sum t (*of*) + +(* Rewrite.trace_on: +add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) + (* |||||||||||||||||||||||||||| *) +val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *) + "AA / 4 + (BB / 2 + -1 * BB / 2)"; +"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); +val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*); +(*+*)if (UnparseC.term n1, UnparseC.term d1) = ("AA" , "4") andalso +(*+*) (UnparseC.term n2, UnparseC.term d2) = ("BB / 2 + - 1 * BB / 2", "1") +(*+*)then () else error "check_frac_sum (AA / 4 + (BB / 2 + -1 * BB / 2)) changed"; + + val vs = TermC.vars_of t; +val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) = + (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*); + +"~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1); +val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t]; +(*+*)if xxx = 1 then () else error "monom_of_term changed" + +"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const (id, _))) = + (vs, (1, replicate (length vs) 0), t); +case vs of [Const ("Partial_Fractions.AA", _), Const ("Partial_Fractions.BB", _)] => + if c = 1 andalso id = "Partial_Fractions.AA" + then () else error "monom_of_term Const changed 1" +| _ => error "monom_of_term Const changed 2"; + +"----------- fun cancel_p with Const AA --------------------------------------------------------"; +"----------- fun cancel_p with Const AA --------------------------------------------------------"; +"----------- fun cancel_p with Const AA --------------------------------------------------------"; +val thy = @{theory Partial_Fractions}; +val ctxt = Proof_Context.init_global @{theory} +val SOME t = TermC.parseNEW ctxt "2 * AA / 2"; (* Const ("Free ("AA", "real") *) + +val SOME (t', _) = rewrite_set_ thy true cancel_p t; +case t' of + Const ("Rings.divide_class.divide", _) $ Const ("Partial_Fractions.AA", _) $ + Const ("Groups.one_class.one", _) => () +| _ => error "WRONG rewrite_set_ cancel_p (2 * AA / 2) \ AA changed"; + +"~~~~~ fun cancel_p , args:"; val (t) = (t); +val opt = check_fraction t +val SOME (numerator, denominator) = (*case*) opt (*of*); + +if UnparseC.term numerator = "2 * AA" andalso UnparseC.term denominator = "2" +then () else error "check_fraction (2 * AA / 2) changed"; + val vs = TermC.vars_of t; +case vs of + [Const ("Partial_Fractions.AA", _)] => () +| _ => error "rewrite_set_ cancel_p (2 * AA / 2) \ AA/1 changed"; + + +"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----"; +"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----"; +"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----"; +val thy = @{theory "Rational"}; +"-------- WN"; +val t = TermC.str2term "(2 + -3 * x) / 9"; +if NONE = rewrite_set_ thy false cancel_p t then () +else error "rewrite_set_ cancel_p must return NONE, if the term cannot be cancelled"; + +"-------- example 186a"; +val t = TermC.str2term "(14 * x * y) / (x * y)"; + is_expanded (TermC.str2term "14 * x * y"); + is_expanded (TermC.str2term "x * y"); +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("14 / 1", "[]") +then () else error "rational.sml cancel Schalk 186a"; + +"-------- example 186b"; +val t = TermC.str2term "(60 * a * b) / ( 15 * a * b )"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("4 / 1", "[]") +then () else error "rational.sml cancel Schalk 186b"; + +"-------- example 186c"; +val t = TermC.str2term "(144 * a \ 2 * b * c) / (12 * a * b * c)"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("12 * a / 1", "[]") +then () else error "rational.sml cancel Schalk 186c"; + +(* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! exception Div raised !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + see --- fun rewrite_set_ downto fun gcd_poly --- +"-------- example 187a"; +val t = TermC.str2term "(12 * x * y) / (8 * y \ 2 )"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("3 * x / (2 * y)", "[\"4 * y ~= 0\"]") +then () else error "rational.sml cancel Schalk 187a"; +*) + +(* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + see --- fun rewrite_set_ downto fun gcd_poly --- +"-------- example 187b"; +val t = TermC.str2term "(8 * x \ 2 * y * z ) / (18 * x * y \ 2 * z )"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("4 * x / (9 * y)", "[\"2 * (z * (y * x)) ~= 0\"]") +then () else error "rational.sml cancel Schalk 187b"; +*) + +(* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + see --- fun rewrite_set_ downto fun gcd_poly --- +"-------- example 187c"; +val t = TermC.str2term "(9 * x \ 5 * y \ 2 * z \ 4) / (15 * x \ 6 * y \ 3 * z )"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = + ("3 * z \ 3 / (5 * (y * x))", "[\"3 * (z * (y \ 2 * x \ 5)) ~= 0\"]") +then () else error "rational.sml cancel Schalk 187c"; +*) + +"-------- example 188a"; +val t = TermC.str2term "(-8 + 8 * x) / (-9 + 9 * x)"; + is_expanded (TermC.str2term "8 * x + -8"); +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]") +then () else error "rational.sml cancel Schalk 188a"; + +val t = TermC.str2term "(8*((-1) + x))/(9*((-1) + x))"; +val SOME (t, _) = rewrite_set_ thy false make_polynomial t; +if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]") +then () else error "rational.sml cancel Schalk make_polynomial 1"; + +"-------- example 188b"; +val t = TermC.str2term "(-15 + 5 * x) / (-18 + 6 * x)"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("5 / 6", "[]") +then () else error "rational.sml cancel Schalk 188b"; + +"-------- example 188c"; +val t = TermC.str2term "(a + -1 * b) / (b + -1 * a)"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("- 1 / 1", "[]") +then () else error "rational.sml cancel Schalk 188c"; + +is_expanded (TermC.str2term "a + -1 * b") = true; +val t = TermC.str2term "((- 1)*(b + (-1) * a))/(1*(b + (- 1) * a))"; +val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; +if (UnparseC.term t', UnparseC.terms asm) = ("(a + - 1 * b) / (- 1 * a + b)", "[]") +then () else error "rational.sml cancel Schalk make_polynomial 2"; + +"-------- example 190a"; +val t = TermC.str2term "( 27 * a \ 3 + 9 * a \ 2 + 3 * a + 1 ) / ( 27 * a \ 3 + 18 * a \ 2 + 3 * a )"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = + ("(1 + 9 * a \ 2) / (3 * a + 9 * a \ 2)", "[\"3 * a + 9 * a \ 2 \ 0\"]") +then () else error "rational.sml cancel Schalk 190a"; + +"-------- example 190c"; +val t = TermC.str2term "((1 + 9 * a \ 2)*(1 + 3 * a))/((3 * a + 9 * a \ 2)*(1 + 3 * a))"; +val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; +if (UnparseC.term t', UnparseC.terms asm) = + ("(1 + 3 * a + 9 * a \ 2 + 27 * a \ 3) /\n(3 * a + 18 * a \ 2 + 27 * a \ 3)", "[]") +then () else error "rational.sml make_polynomial Schalk 190c"; + +"-------- example 191a"; +val t = TermC.str2term "( x \ 2 + -1 * y \ 2 ) / ( x + y )"; + is_expanded (TermC.str2term "x \ 2 + - 1 * y \ 2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) + is_expanded (TermC.str2term "x + y") = true; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("(x + - 1 * y) / 1", "[]") +then () else error "rational.sml make_polynomial Schalk 191a"; + +"-------- example 191b"; +val t = TermC.str2term "((x + (- 1) * y)*(x + y))/((1)*(x + y))"; +val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; +if (UnparseC.term t', UnparseC.terms asm) = ("(x \ 2 + - 1 * y \ 2) / (x + y)", "[]") +then () else error "rational.sml make_polynomial Schalk 191b"; + +"-------- example 191c"; +val t = TermC.str2term "( 9 * x \ 2 + -30 * x + 25 ) / ( 9 * x \ 2 + -25 )"; + is_expanded (TermC.str2term "9 * x \ 2 + -30 * x + 25") = true; + is_expanded (TermC.str2term "25 + -30*x + 9*x \ 2") = true; + is_expanded (TermC.str2term "-25 + 9*x \ 2") = true; + +val t = TermC.str2term "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))"; +val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; +if (UnparseC.term t', UnparseC.terms asm) = ("(25 + - 30 * x + 9 * x \ 2) / (- 25 + 9 * x \ 2)", "[]") +then () else error "rational.sml make_polynomial Schalk 191c"; + +"-------- example 192b"; +val t = TermC.str2term "( 7 * x \ 3 + - 1 * x \ 2 * y ) / ( 7 * x * y \ 2 + - 1 * y \ 3 )"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("x \ 2 / y \ 2", "[\"y \ 2 \ 0\"]") +then () else error "rational.sml cancel_p Schalk 192b"; + +val t = TermC.str2term "((x \ 2)*(7 * x + (-1) * y))/((y \ 2)*(7 * x + (-1) * y))"; +val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; +if (UnparseC.term t', UnparseC.terms asm) = + ("(7 * x \ 3 + - 1 * x \ 2 * y) /\n(7 * x * y \ 2 + - 1 * y \ 3)", "[]") +then () else error "rational.sml make_polynomial Schalk 192b"; + +val t = TermC.str2term "((x \ 2)*(7 * x + (-1) * y))/((y \ 2)*(7 * x + (-1) * y))"; +val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; +if (UnparseC.term t', UnparseC.terms asm) = + ("(7 * x \ 3 + - 1 * x \ 2 * y) /\n(7 * x * y \ 2 + - 1 * y \ 3)", "[]") +then () else error "rational.sml make_polynomial Schalk WN050929 not working"; + +"-------- example 193a"; +val t = TermC.str2term "( x \ 2 + -6 * x + 9 ) / ( x \ 2 + -9 )"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("(- 3 + x) / (3 + x)", "[\"3 + x \ 0\"]") +then () else error "rational.sml cancel_p Schalk 193a"; + +"-------- example 193b"; +val t = TermC.str2term "( x \ 2 + -8 * x + 16 ) / ( 2 * x \ 2 + -32 )"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("(- 4 + x) / (8 + 2 * x)", "[\"8 + 2 * x \ 0\"]") +then () else error "rational.sml cancel_p Schalk 193b"; + +"-------- example 193c"; +val t = TermC.str2term "( 2 * x + -50 * x \ 3 ) / ( 25 * x \ 2 + -10 * x + 1 )"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = + ("(2 * x + 10 * x \ 2) / (1 + - 5 * x)", "[\"1 + - 5 * x \ 0\"]") +then () else error "rational.sml cancel_p Schalk 193c"; + +(*WN: improved with new numerals*) +val t = TermC.str2term "(-25 + 9*x \ 2)/(5 + 3*x)"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = ("(- 5 + 3 * x) / 1", "[]") +then () else error "rational.sml cancel WN 1"; + +"-------- example heuberger"; +val t = TermC.str2term ("(x \ 4 + x * y + x \ 3 * y + y \ 2) / " ^ + "(x + 5 * x \ 2 + y + 5 * x * y + x \ 2 * y \ 3 + x * y \ 4)"); +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if (UnparseC.term t', UnparseC.terms asm) = + ("(x \ 3 + y) / (1 + 5 * x + x * y \ 3)", "[\"1 + 5 * x + x * y \ 3 \ 0\"]") +then () else error "rational.sml cancel_p heuberger"; + +"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------"; +"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------"; +"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------"; +(*deleted example 204 ... 236b at update Isabelle2012-->2013*) + +"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------"; +"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------"; +"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------"; +val t = TermC.str2term ("123 = (a*x)/(b*x) + (c*x)/(d*x) + (e*x)/(f*x::real)"); +"-------- gcd_poly integration level 1: works on exact term"; +if NONE = cancel_p_ thy t then () else error "cancel_p_ works on exact fraction"; +if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ works on exact fraction"; + +"-------- gcd_poly integration level 2: picks out ONE appropriate subterm"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p t; +if UnparseC.term t' = "123 = a * x / (b * x) + c * x / (d * x) + e / f" +then () else error "level 2, rewrite_set_ cancel_p: changed"; +val SOME (t', asm) = rewrite_set_ thy false add_fractions_p t; +if UnparseC.term t' = "123 = (b * c * x + a * d * x) / (b * d * x) + e * x / (f * x)" +then () else error "level 2, rewrite_set_ add_fractions_p: changed"; + +"-------- gcd_poly integration level 3: rewrites all appropriate subterms"; +val SOME (t', asm) = rewrite_set_ thy false cancel_p_rls t; +if UnparseC.term t' = "123 = a / b + c / d + e / f" +then () else error "level 3, rewrite_set_ cancel_p_rls: changed"; +val SOME (t', asm) = rewrite_set_ thy false add_fractions_p_rls t; (*CREATE add_fractions_p_rls*) +if UnparseC.term t' = "123 = (b * d * e * x + b * c * f * x + a * d * f * x) / (b * d * f * x)" +then () else error "level 3, rewrite_set_ add_fractions_p_rls: changed"; + +"-------- gcd_poly integration level 4: iteration cancel_p -- add_fraction_p"; +(* simpler variant *) +val testrls = Rule_Set.append_rules "testrls" Rule_Set.empty [Rls_ cancel_p, Rls_ add_fractions_p] +val SOME (t', asm) = rewrite_set_ thy false testrls t; +(*Rewrite.trace_on := false; +# rls: testrls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) +## rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) +## rls: add_fractions_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f +## rls: cancel_p on: 123 = (b * c * x + a * d * x) / (b * d * x) + e / f +## rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f +## rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) +## rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *) +if UnparseC.term t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)" +then () else error "level 4, rewrite_set_ *_p: changed"; + +(* complicated variant *) +val testrls_rls = Rule_Set.append_rules "testrls_rls" Rule_Set.empty [Rls_ cancel_p_rls, Rls_ add_fractions_p_rls]; +val SOME (t', asm) = rewrite_set_ thy false testrls_rls t; +(*# rls: testrls_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) +## rls: cancel_p_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) +### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) +### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f +### rls: cancel_p on: 123 = a * x / (b * x) + c / d + e / f +### rls: cancel_p on: 123 = a / b + c / d + e / f +## rls: add_fractions_p_rls on: 123 = a / b + c / d + e / f +### rls: add_fractions_p on: 123 = a / b + c / d + e / f +### rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f +### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) +## rls: cancel_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) +### rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) +## rls: add_fractions_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) +### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *) +if UnparseC.term t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)" +then () else error "level 4, rewrite_set_ *_p_rls: changed" + +"-------- gcd_poly integration level 5: cancel_p & add_fraction_p within norm_Rational"; +val SOME (t', asm) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)" +then () else error "level 5, rewrite_set_ norm_Rational: changed" + +"-------- reverse rewrite ----------------------------------------------------"; +"-------- reverse rewrite ----------------------------------------------------"; +"-------- reverse rewrite ----------------------------------------------------"; +(** the term for which reverse rewriting is demonstrated **) +val t = TermC.str2term "(9 + -1 * x \ 2) / (9 + 6 * x + x \ 2)"; +val Rrls {scr = Rfuns {init_state = ini, locate_rule = loc, + next_rule = nex, normal_form = nor, ...},...} = cancel_p; + +(** normal_form produces the result in ONE step **) + val SOME (t', _) = nor t; +if UnparseC.term t' = "(3 + - 1 * x) / (3 + x)" then () +else error "rational.sml normal_form (9 - x \ 2) / (9 - 6 * x + x \ 2)"; + +(** initialize the interpreter state used by the 'me' **) + val (t, _, revsets, _) = ini t; + +if length (hd revsets) = 11 then () else error "length of revset changed"; +(*//----------------------------------TOODOO (*Rfuns revsets \ broken*) +if (revsets |> nth 1 |> nth 1 |> id_of_thm) = + (@{thm realpow_twoI} |> Thm.get_name_hint |> ThmC.cut_id) +then () else error "first element of revset changed"; +if +(revsets |> nth 1 |> nth 1 |> Rule.to_string) = "Thm (\"realpow_twoI\",?r1 \ 2 = ?r1 * ?r1)" andalso +(revsets |> nth 1 |> nth 2 |> Rule.to_string) = "Thm (\"#: 9 = 3 \ 2\",9 = 3 \ 2)" andalso +(revsets |> nth 1 |> nth 3 |> Rule.to_string) = "Thm (\"#: 6 * x = 2 * (3 * x)\",6 * x = 2 * (3 * x))" +andalso +(revsets |> nth 1 |> nth 4 |> Rule.to_string) = "Thm (\"#: -3 * x = -1 * (3 * x)\",-3 * x = -1 * (3 * x))" +andalso +(revsets |> nth 1 |> nth 5 |> Rule.to_string) = "Thm (\"#: 9 = 3 * 3\",9 = 3 * 3)" andalso +(revsets |> nth 1 |> nth 6 |> Rule.to_string) = "Rls_ (\"sym_order_mult_rls_\")" andalso +(revsets |> nth 1 |> nth 7 |> Rule.to_string) = + "Thm (\"sym_mult.assoc\",?a * (?b * ?c) = ?a * ?b * ?c)" +then () else error "first 7 elements in revset changed" + \\----------------------------------TOODOO (*Rfuns revsets \ broken*)*) + +(** find the rule 'r' to apply to term 't' **) +(*/------- WN1309: since cancel_ (accepted "-" between monomials) has been replaced by cancel_p_ + for Isabelle2013, we don't get a working revset, but non-termination: + + val SOME (r as (Thm (str, thm))) = nex revsets t; + : +((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), []))", " +((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x), + Thm ("sym_mult.assoc", ""), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x), []))", " +((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x), + Thm ("sym_mult.assoc", ""), ((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), []))", " +((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), []))", " + : +### Isabelle2002: + Thm ("sym_#mult_2_3", "6 = 2 * 3") +### Isabelle2009-2 for cancel_ (not cancel_p_): +if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" + andalso ThmC.string_of_thm thm = + (string_of_thm (Thm.make_thm @{theory "Isac_Knowledge"} + (Trueprop $ (Thm.term_of o the o (TermC.parse thy)) "9 = 3 \ 2"))) then () +else error "rational.sml next_rule (9 - x \ 2) / (9 - 6 * x + x \ 2)"; +\---------------------------------------------------------------------------------------/*) + +(** check, if the rule 'r' applied by the user to 't' belongs to the ruleset; + if the rule is OK, the term resulting from applying the rule is returned,too; + there might be several rule applications inbetween, + which are listed after the head in reverse order **) +(*/-------------------------------------------- Isabelle2013: this gives "error id_of_thm"; + we don't repair this, because interaction within "reverse rewriting" never worked properly: + + val (r, (t, asm))::_ = loc revsets t r; +if UnparseC.term t = "(9 - x \ 2) / (3 \ 2 + 6 * x + x \ 2)" andalso asm = [] +then () else error "rational.sml locate_rule (9 - x \ 2) / (9 - 6 * x + x \ 2)"; + +(* find the next rule to apply *) + val SOME (r as (Thm (str, thm))) = nex revsets t; +if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso + ThmC.string_of_thm thm = (string_of_thm (ThmC_Def.make_thm @{theory "Isac_Knowledge"} + (Trueprop $ (Thm.term_of o the o (TermC.parse thy)) "9 = 3 \ 2"))) then () +else error "rational.sml next_rule (9 - x \ 2) / (9 - 6 * x + x \ 2)"; + +(*check the next rule*) + val (r, (t, asm)) :: _ = loc revsets t r; +if UnparseC.term t = "(3 \ 2 - x \ 2) / (3 \ 2 + 6 * x + x \ 2)" then () +else error "rational.sml locate_rule (9 - x \ 2) / (9 - 6 * x + x \ 2) II"; + +(*find and check the next rules, rewrite*) + val SOME r = nex revsets t; + val (r,(t,asm))::_ = loc revsets t r; +if UnparseC.term t = "(3 \ 2 - x \ 2) / (3 \ 2 + 2 * 3 * x + x \ 2)" then () +else error "rational.sml locate_rule II"; + + val SOME r = nex revsets t; + val (r,(t,asm))::_ = loc revsets t r; +if UnparseC.term t = "(3 - x) * (3 + x) / (3 \ 2 + 2 * 3 * x + x \ 2)" then () +else error "rational.sml next_rule II"; + + val SOME r = nex revsets t; + val (r,(t,asm))::_ = loc revsets t r; +if UnparseC.term t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then () +else error "rational.sml next_rule III"; + + val SOME r = nex revsets t; + val (r, (t, asm)) :: _ = loc revsets t r; + val ss = UnparseC.term t; +if ss = "(3 - x) / (3 + x)" andalso UnparseC.terms asm = "[\"3 + x ~= 0\"]" then () +else error "rational.sml: new behav. in rev-set cancel"; +\--------------------------------------------------------------------------------------/*) + +"-------- 'reverse-ruleset' cancel_p -----------------------------------------"; +"-------- 'reverse-ruleset' cancel_p -----------------------------------------"; +"-------- 'reverse-ruleset' cancel_p -----------------------------------------"; +(*WN130909: the example below shows, why "reverse rewriting" only worked for + special cases.*) + +(*the term for which reverse rewriting is demonstrated*) +val t = TermC.str2term "(9 + (-1)*x \ 2) / (9 + ((-6)*x + x \ 2))"; +val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc, + next_rule=nex,normal_form=nor,...},...} = cancel_p; + +(*normal_form produces the result in ONE step*) +val SOME (t', _) = nor t; +if UnparseC.term t' = "(3 + x) / (3 + - 1 * x)" +then () else error "cancel_p normal_form CHANGED";; + +(*initialize the interpreter state used by the 'me'*) +val SOME (t', asm) = cancel_p_ thy t; +if (UnparseC.term t', UnparseC.terms asm) = ("(3 + x) / (3 + - 1 * x)", "[\"3 + - 1 * x \ 0\"]") +then () else error "cancel_p CHANGED";; + +val (t,_,revsets,_) = ini t; + +(* WN.10.10.02: dieser Fall terminiert nicht + (make_polynomial enth"alt zu viele rules) +WN060823 'init_state' requires rewriting on specified location in the term +default_print_depth 99; Rfuns; default_print_depth 3; +WN060831 cycling "sym_order_mult_rls_" "sym_mult.assoc" + as was with make_polynomial before ?!?* ) + +val SOME r = nex revsets t; +eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))", + mk_thm thy "9 = 3 \ 2")); +( *WN060831 *** id_of_thm + Exception- ERROR raised ... +val (r,(t,asm))::_ = loc revsets t r; +UnparseC.term t; + + val SOME r = nex revsets t; + val (r,(t,asm))::_ = loc revsets t r; + UnparseC.term t; +*) + +"-------- examples: rls norm_Rational ----------------------------------------"; +"-------- examples: rls norm_Rational ----------------------------------------"; +"-------- examples: rls norm_Rational ----------------------------------------"; +(*Rewrite.trace_on:=true;*) +val t = TermC.str2term "Not (6*x is_atom)"; +val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t'; +"HOL.True"; +val t = TermC.str2term "1 < 2"; +val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t'; +"HOL.True"; + +val t = TermC.str2term "(6*x) \ 2"; +val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false + (ThmC.numerals_to_Free @{thm realpow_def_atom}) t; +if UnparseC.term t' = "6 * x * (6 * x) \ (2 + - 1)" then () +else error "rational.sml powers_erls (6*x) \ 2"; + +val t = TermC.str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))"; +val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; +if UnparseC.term t' = "65 * x / 2" then () else error "rational.sml 4"; + +val t = TermC.str2term "1 - ((13*x)/2 - 5/2) \ 2"; +val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; +if UnparseC.term t' = "(- 21 + 130 * x + - 169 * x \ 2) / 4" then () +else error "rational.sml 5"; + +(*SRAM Schalk I, p.92 Nr. 609a*) +val t = TermC.str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54"; +val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; +if UnparseC.term t' = "(- 255 + 112 * x) / 135" then () +else error "rational.sml 6"; + +(*SRAM Schalk I, p.92 Nr. 610c*) +val t = TermC.str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2"; +val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; +if UnparseC.term t' = "(3 + x) / - 2" then () else error "rational.sml 7"; + +(*SRAM Schalk I, p.92 Nr. 476a*) +val t = TermC.str2term "(x \ 2/(1 - x \ 2) + 1)/(x/(1 - x) + 1) * (1 + x)"; +(*. a/b : c/d translated to a/b * d/c .*) +val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; +if UnparseC.term t' = "1" then () else error "rational.sml 8"; + +(*Schalk I, p.92 Nr. 472a*) +val t = TermC.str2term "((8*x \ 2 - 32*y \ 2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))"; +val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; +if UnparseC.term t' = "x + y" then () else error "rational.sml p.92 Nr. 472a"; + +(*Schalk I, p.70 Nr. 480b: SEE rational.sml --- nonterminating rls norm_Rational ---*) + +(*WN130910 add_fractions_p exception Div raised + history: +### WN.2.6.03 from rlang.sml 56a +val t = TermC.str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a \ 2 + -1 * b \ 2)"; +val NONE = rewrite_set_ thy false add_fractions_p t; + +THE ERROR ALREADY OCCURS IN THIS PART: +val t = TermC.str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)"; +val NONE = add_fraction_p_ thy t; + +SEE Test_Some.thy: section {* add_fractions_p downto exception Div raised === +*) + +"-------- rational numerals --------------------------------------------------"; +"-------- rational numerals --------------------------------------------------"; +"-------- rational numerals --------------------------------------------------"; +(*SRA Schalk I, p.40 Nr. 164b *) +val t = TermC.str2term "(47/6 - 76/9 + 13/4)/(35/12)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "19 / 21" then () +else error "rational.sml: diff.behav. in norm_Rational_mg 1"; + +(*SRA Schalk I, p.40 Nr. 166a *) +val t = TermC.str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "45 / 2" then () +else error "rational.sml: diff.behav. in norm_Rational_mg 2"; + +"-------- examples cancellation from: Mathematik 1 Schalk --------------------"; +"-------- examples cancellation from: Mathematik 1 Schalk --------------------"; +"-------- examples cancellation from: Mathematik 1 Schalk --------------------"; +(* e190c Stefan K.*) +val t = TermC.str2term "((1 + 9*a \ 2) * (1 + 3*a)) / ((3*a + 9*a \ 2) * (1 + 3*a))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(1 + 9 * a \ 2) / (3 * a + 9 * a \ 2)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 3"; + +(* e192b Stefan K.*) +val t = TermC.str2term "(x \ 2 * (7*x + (-1)*y)) / (y \ 2 * (7*x + (-1)*y))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "x \ 2 / y \ 2" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 4"; + +(*SRC Schalk I, p.66 Nr. 379c *) +val t = TermC.str2term "(a - b)/(b - a)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "- 1" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 5"; + +(*SRC Schalk I, p.66 Nr. 380b *) +val t = TermC.str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 6"; + +(* e190c Stefan K.*) +val t = TermC.str2term "((1 + 9*a \ 2) * (1 + 3*a)) / ((3*a + 9*a \ 2) * (1 + 3 * a))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(1 + 9 * a \ 2) / (3 * a + 9 * a \ 2)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 3"; + +(* e192b Stefan K.*) +val t = TermC.str2term "(x \ 2 * (7*x + (-1)*y)) / (y \ 2 * (7*x + (-1)*y))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "x \ 2 / y \ 2" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 4"; + +(*SRC Schalk I, p.66 Nr. 379c *) +val t = TermC.str2term "(a - b) / (b - a)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "- 1" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 5"; + +(*SRC Schalk I, p.66 Nr. 380b *) +val t = TermC.str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 6"; + +(* extreme example from somewhere *) +val t = TermC.str2term + ("(a \ 4 * x + -1*a \ 4 * y + 4*a \ 3 * b * x + -4*a \ 3 * b * y + " ^ + "6*a \ 2 * b \ 2 * x + -6*a \ 2 * b \ 2 * y + 4*a * b \ 3 * x + -4*a * b \ 3 * y + " ^ + "b \ 4 * x + -1*b \ 4 * y) " ^ + " / (a \ 2 * x \ 3 + -3*a \ 2 * x \ 2 * y + 3*a \ 2 * x * y \ 2 + -1*a \ 2 * y \ 3 + " ^ + "2*a * b * x \ 3 + -6*a * b * x \ 2 * y + 6*a * b * x * y \ 2 + -2*a * b * y \ 3 + " ^ + "b \ 2 * x \ 3 + -3*b \ 2 * x \ 2 * y + 3*b \ 2 * x * y \ 2 + -1*b \ 2 * y \ 3)") +val SOME (t, _) = rewrite_set_ thy false cancel_p t; +if UnparseC.term t = "(a \ 2 + 2 * a * b + b \ 2) / (x \ 2 + - 2 * x * y + y \ 2)" +then () else error "with Isabelle2002: NONE -- now SOME changed"; + +(*Schalk I, p.66 Nr. 381a *) +(* ATTENTION: here the rls is very slow. In Isabelle2002 this required 2 min *) +val t = TermC.str2term "18*(a + b) \ 3 * (a - b) \ 2 / (72*(a - b) \ 3 * (a + b) \ 2)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(a + b) / (4 * a + - 4 * b)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 8"; + +(*SRC Schalk I, p.66 Nr. 381b *) +val t = TermC.str2term "(4*x \ 2 - 20*x + 25) / (2*x - 5) \ 3"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "1 / (- 5 + 2 * x)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 9"; + +(*SRC Schalk I, p.66 Nr. 381c *) +val t = TermC.str2term "(27*a \ 3 + 9*a \ 2+3*a+1) / (27*a \ 3 + 18*a \ 2+3*a)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(1 + 9 * a \ 2) / (3 * a + 9 * a \ 2)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 10"; + +(*SRC Schalk I, p.66 Nr. 383a *) +val t = TermC.str2term "(5*a \ 2 - 5*a*b) / (a - b) \ 2"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "- 5 * a / (- 1 * a + b)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 11"; + +"----- NOT TERMINATING ?: worked before 0707xx"; +val t = TermC.str2term "(a \ 2 - 1)*(b + 1) / ((b \ 2 - 1)*(a+1))"; +(* WN130911 "exception Div raised" by + cancel_p_ thy (TermC.str2term ("(-1 + -1 * b + a \ 2 + a \ 2 * b) /" ^ + "(-1 + -1 * a + b \ 2 + a * b \ 2)")) + +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(1 + -1 * a) / (1 + -1 * b)" then () +else error "rational.sml MG tests 3e"; +*) + +"-------- examples common denominator from: Mathematik 1 Schalk --------------"; +"-------- examples common denominator from: Mathematik 1 Schalk --------------"; +"-------- examples common denominator from: Mathematik 1 Schalk --------------"; +(*SRA Schalk I, p.67 Nr. 403a *) +val t = TermC.str2term "4/x - 3/y - 1"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(- 3 * x + 4 * y + - 1 * x * y) / (x * y)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 12"; + +val t = TermC.str2term "(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a \ 2+3*b*c)/(a*b*c)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "4 / c" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 13"; + +(*SRA Schalk I, p.67 Nr. 410b *) +val t = TermC.str2term "1/(x+1) + 1/(x+2) - 2/(x+3)"; +(* WN130911 non-termination due to non-termination of + cancel_p_ thy (TermC.str2term "(5 + 3 * x) / (6 + 11 * x + 6 * x \ 2 + x \ 3)") + +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(5 + 3 * x) / (6 + 11 * x + 6 * x \ 2 + x \ 3)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 14"; +*) + +(*SRA Schalk I, p.67 Nr. 413b *) +val t = TermC.str2term "(1 + x)/(1 - x) - (1 - x)/(1 + x) + 2*x/(1 - x \ 2)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "6 * x / (1 + - 1 * x \ 2)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 15"; + +(*SRA Schalk I, p.68 Nr. 414a *) +val t = TermC.str2term "(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t ="(- 2 + - 5 * x + 2 * x \ 2) / (2 + - 3 * x + x \ 2)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 16"; + +(*SRA Schalk I, p.68 Nr. 428b *) +val t = TermC.str2term + "1/(a - b) \ 2 + 1/(a + b) \ 2 - 2/(a \ 2 - b \ 2) - 4*(b \ 2 - 1)/(a \ 2 - b \ 2) \ 2"; +(* WN130911 non-termination due to non-termination of + cancel_p_ thy (TermC.str2term "(4 + -4 * b \ 2) / (a \ 4 + -2 * (a \ 2 * b \ 2) + b \ 4)") + +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "4 / (a \ 4 + -2 * a \ 2 * b \ 2 + b \ 4)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 18"; +*) + +(*SRA Schalk I, p.68 Nr. 430b *) +val t = TermC.str2term + "a \ 2/(a - 3*b) - 108*a*b \ 3/((a+3*b)*(a \ 2 - 9*b \ 2)) - 9*b \ 2*(a - 3*b)/(a+3*b) \ 2"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "a + 3 * b" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 19"; + +(*SRA Schalk I, p.68 Nr. 432 *) +val t = TermC.str2term + ("(a \ 2 + a*b) / (a \ 2 - b \ 2) - (b \ 2 - a*b) / (b \ 2 - a \ 2) + " ^ + "a \ 2*(a - b) / (a \ 3 - a \ 2*b) - 2*a*(a \ 2 - b \ 2) / (a \ 3 - a*b \ 2) - " ^ + "2*b \ 2 / (a \ 2 - b \ 2)"); +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = (*"0" ..isabisac15 | Isabelle2017..*) "0 / (a \ 2 + - 1 * b \ 2)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 20"; + +(* some example *) +val t = TermC.str2term "3*a / (a*b) + x/y"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(3 * y + b * x) / (b * y)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 21"; + + +"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------"; +"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------"; +"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------"; +(*------- SRM Schalk I, p.68 Nr. 436a *) +val t = TermC.str2term "3*(x+y) / (15*(x - y)) * 25*(x - y) \ 2 / (18*(x + y) \ 2)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(- 5 * x + 5 * y) / (- 18 * x + - 18 * y)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 22"; + +(*------- SRM.test Schalk I, p.68 Nr. 436b *) +val t = TermC.str2term "5*a*(a - b) \ 2*(a + b) \ 3/(7*b*(a - b) \ 3) * 7*b/(a + b) \ 3"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "5 * a / (a + - 1 * b)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 23"; + +(*------- Schalk I, p.68 Nr. 437a *) +val t = TermC.str2term "(3*a - 4*b) / (4*c+3*e) * (3*a+4*b)/(9*a \ 2 - 16*b \ 2)"; +(* raises an exception for unclear reasons: +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +: +### rls: cancel_p on: (9 * a \ 2 + -16 * b \ 2) / (4 * c + 3 * e) / +(9 * a \ 2 + -16 * b \ 2) +exception Div raised + +BUT +val t = TermC.str2term + ("(9 * a \ 2 + -16 * b \ 2) / (4 * c + 3 * e) /" ^ + "(9 * a \ 2 + -16 * b \ 2)"); +NONE = cancel_p_ thy t; + +if UnparseC.term t = "1 / (4 * c + 3 * e)" then () +else error "rational.sml: diff.behav. in norm_Rational_mg 24"; +*) + +"----- S.K. corrected non-termination 060904"; +val t = TermC.str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a \ 2 - 16*b \ 2))"; +val SOME (t, _) = rewrite_set_ thy false make_polynomial t; +if UnparseC.term t = + "(9 * a \ 2 + - 16 * b \ 2) /\n(36 * a \ 2 * c + 27 * a \ 2 * e + - 64 * b \ 2 * c +\n - 48 * b \ 2 * e)" +then () else error "rational.sml: S.K.8..corrected 060904-6"; + +"----- S.K. corrected non-termination of cancel_p_"; +val t'' = TermC.str2term ("(9 * a \ 2 + -16 * b \ 2) /" ^ + "(36 * a \ 2 * c + (27 * a \ 2 * e + (-64 * b \ 2 * c + -48 * b \ 2 * e)))"); +(* /--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------\ +val SOME (t',_) = rewrite_set_ thy false cancel_p t''; +if UnparseC.term t' = "1 / (4 * c + 3 * e)" +then () else error "rational.sml: diff.behav. in cancel_p S.K.8"; + \--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------/*) + +(*------- Schalk I, p.68 Nr. 437b*) +val t = TermC.str2term "(a + b)/(x \ 2 - y \ 2) * ((x - y) \ 2/(a \ 2 - b \ 2))"; +(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +: +#### rls: cancel_p on: (a * x \ 2 + -2 * (a * (x * y)) + a * y \ 2 + b * x \ 2 + + -2 * (b * (x * y)) + + b * y \ 2) / +(a \ 2 * x \ 2 + -1 * (a \ 2 * y \ 2) + -1 * (b \ 2 * x \ 2) + + b \ 2 * y \ 2) +exception Div raised +*) + +(*------- SRM Schalk I, p.68 Nr. 438a *) +val t = TermC.str2term "x*y / (x*y - y \ 2) * (x \ 2 - x*y)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "x \ 2" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 24"; + +(*------- SRM Schalk I, p.68 Nr. 439b *) +val t = TermC.str2term "(4*x \ 2 + 4*x + 1) * ((x \ 2 - 2*x \ 3) / (4*x \ 2 + 2*x))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(x + - 4 * x \ 3) / 2" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 25"; + +(*------- SRM Schalk I, p.68 Nr. 440a *) +val t = TermC.str2term "(x \ 2 - 2*x) / (x \ 2 - 3*x) * (x - 3) \ 2 / (x \ 2 - 4)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(- 3 + x) / (2 + x)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 26"; + +"----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx"; +val t = TermC.str2term "(a \ 3 - 9*a) / (a \ 3*b - a*b \ 3) * (a \ 2*b + a*b \ 2) / (a+3)"; +(* WN130911 non-termination for unclear reasons: +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; + +... ENDS WITH THIS TRACE: +: +### rls: cancel_p on: (-9 * (a \ 3 * b) + -9 * (a \ 2 * b \ 2) + a \ 5 * b + + a \ 4 * b \ 2) / +(a \ 3 * b + -1 * (a * b \ 3)) / +(3 + a) +BUT THIS IS CORRECTLY RECOGNISED +val t = TermC.str2term + ("(-9 * (a \ 3 * b) + -9 * (a \ 2 * b \ 2) + a \ 5 * b + a \ 4 * b \ 2) /" ^ + "(a \ 3 * b + -1 * (a * b \ 3)) / (3 + (a::real))"); +AS +NONE = cancel_p_ thy t; + +if UnparseC.term t = "(-3 * a + a \ 2) / (a + -1 * b)" then () +else error "rational.sml: diff.behav. in norm_Rational 27"; +*) + +"----- SK12 works since 0707xx"; +val t = TermC.str2term "(a \ 3 - 9*a) * (a \ 2*b+a*b \ 2) / ((a \ 3*b - a*b \ 3) * (a+3))"; +(* WN130911 non-termination due to non-termination of + cancel_p_ thy (TermC.str2term "(4 + -4 * b \ 2) / (a \ 4 + -2 * (a \ 2 * b \ 2) + b \ 4)") + +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t' = "(-3 * a + a \ 2) / (a + -1 * b)" then () +else error "rational.sml: diff.behav. in norm_Rational 28"; +*) + +"-------- examples common denominator and multiplication from: Schalk --------"; +"-------- examples common denominator and multiplication from: Schalk --------"; +"-------- examples common denominator and multiplication from: Schalk --------"; +(*------- SRAM Schalk I, p.69 Nr. 441b *) +val t = TermC.str2term "(4*a/3 + 3*b \ 2/a \ 3 + b/(4*a))*(4*b/(3*a))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(36 * b \ 3 + 3 * a \ 2 * b \ 2 + 16 * a \ 4 * b) /\n(9 * a \ 4)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 28"; + +(*------- SRAM Schalk I, p.69 Nr. 442b *) +val t = TermC.str2term ("(15*a \ 2/x \ 3 - 5*b \ 4/x \ 2 + 25*c \ 2/x) * " ^ + "(x \ 3/(5*a*b \ 3*c \ 3)) + 1/c \ 3 * (b*x/a - 3*a/b \ 3)"); +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "5 * x \ 2 / (a * b \ 3 * c)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 29"; + +(*------- SRAM Schalk I, p.69 Nr. 443b *) +val t = TermC.str2term "(a/2 + b/3) * (b/3 - a/2)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(- 9 * a \ 2 + 4 * b \ 2) / 36" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 30"; + +(*------- SRAM Schalk I, p.69 Nr. 445b *) +val t = TermC.str2term "(a \ 2/9 + 2*a/(3*b) + 4/b \ 2)*(a/3 - 2/b) + 8/b \ 3"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "a \ 3 / 27" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 31"; + +(*------- SRAM Schalk I, p.69 Nr. 446b *) +val t = TermC.str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x \ 2 - 16*y \ 2)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = (*"30 * x \ 2 + -9 * x * y + -20 * y \ 2" ..isabisac15 | Isabelle2017..*) + "(- 30 * x \ 2 + 9 * x * y + 20 * y \ 2) / - 1" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 32"; + +(*------- SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*) +val t = TermC.str2term +"(2*x \ 2/(3*y)+x/y \ 2)*(4*x \ 4/(9*y \ 2)+x \ 2/y \ 4)*(2*x \ 2/(3*y) - x/y \ 2)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(- 81 * x \ 4 + 16 * x \ 8 * y \ 4) / (81 * y \ 8)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 33"; + +(*------- SRAM Schalk I, p.69 Nr. 450a *) +val t = TermC.str2term +"(4*x/(3*y)+2*y/(3*x)) \ 2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(52 * x \ 2 + 16 * y \ 2) / (9 * y \ 2)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 34"; + +(*------- SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*) +val t = TermC.str2term + ("(15*a \ 4/(a*x \ 3) - 5*a*((b \ 4 - 5*c \ 2*x) / x \ 2)) * " ^ + "(x \ 3/(5*a*b \ 3*c \ 3)) + a/c \ 3 * (x*(b/a) - 3*b*(a/b \ 4))"); +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "5 * x \ 2 / (b \ 3 * c)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 53"; + + +"-------- examples double fractions from: Mathematik 1 Schalk ----------------"; +"-------- examples double fractions from: Mathematik 1 Schalk ----------------"; +"-------- examples double fractions from: Mathematik 1 Schalk ----------------"; +"----- SRD Schalk I, p.69 Nr. 454b"; +val t = TermC.str2term "((2 - x)/(2*a)) / (2*a/(x - 2))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(- 4 + 4 * x + - 1 * x \ 2) / (4 * a \ 2)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 35"; + +"----- SRD Schalk I, p.69 Nr. 455a"; +val t = TermC.str2term "(a \ 2 + 1)/(a \ 2 - 1) / ((a+1)/(a - 1))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(1 + a \ 2) / (1 + 2 * a + a \ 2)" then () +else error "rational.sml: diff.behav. in norm_Rational_mg 36"; + +"----- Schalk I, p.69 Nr. 455b"; +val t = TermC.str2term "(x \ 2 - 4)/(y \ 2 - 9)/((2+x)/(3 - y))"; +(* WN130911 non-termination due to non-termination of + cancel_p_ thy (TermC.str2term ("(-12 + 4 * y + 3 * x \ 2 + -1 * (x \ 2 * y)) /" ^ + "(-18 + -9 * x + 2 * y \ 2 + x * y \ 2)")) + +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(2 + -1 * x) / (3 + y)" then () +else error "rational.sml: diff.behav. in norm_Rational_mg 37"; +*) + +"----- SK060904-1a non-termination of cancel_p_ ?: worked before 0707xx"; +val t = TermC.str2term "(x \ 2 - 4)*(3 - y) / ((y \ 2 - 9)*(2+x))"; +(* WN130911 non-termination due to non-termination of + cancel_p_ thy (TermC.str2term ("(-12 + 4 * y + 3 * x \ 2 + -1 * (x \ 2 * y)) /" ^ + "(-18 + -9 * x + 2 * y \ 2 + x * y \ 2)")) + +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(2 + -1 * x) / (3 + y)" then () +else error "rational.sml: diff.behav. in norm_Rational_mg 37b"; +*) + +"----- ?: worked before 0707xx"; +val t = TermC.str2term "(3 + -1 * y) / (-9 + y \ 2)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "- 1 / (3 + y)" +then () else error "rational.sml: -1 / (3 + y) norm_Rational"; + +"----- SRD Schalk I, p.69 Nr. 456b"; +val t = TermC.str2term "(b \ 3 - b \ 2) / (b \ 2+b) / (b \ 2 - 1)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "b / (1 + 2 * b + b \ 2)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 38"; + +"----- SRD Schalk I, p.69 Nr. 457b"; +val t = TermC.str2term "(16*a \ 2 - 9*b \ 2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a \ 2 - 9*a \ 2*b \ 2))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "8 * a \ 2 + - 6 * a * b + - 12 * a \ 2 * b + 9 * a * b \ 2" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 39"; + +"----- Schalk I, p.69 Nr. 458b works since 0707"; +val t = TermC.str2term "(2*a \ 2*x - a \ 2) / (a*x - b*x) / (b \ 2*(2*x - 1) / (x*(a - b)))"; +(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +: +### rls: cancel_p on: (-1 * a \ 2 + 2 * (a \ 2 * x)) / (a * x + -1 * (b * x)) / +((-1 * b \ 2 + 2 * (b \ 2 * x)) / (a * x + -1 * (b * x))) +exception Div raised + +BUT +val t = TermC.str2term + ("(-1 * a \ 2 + 2 * (a \ 2 * x)) / (a * x + -1 * (b * x)) /" ^ + "((-1 * b \ 2 + 2 * (b \ 2 * x)) / (a * x + -1 * (b * x)))"); +NONE = cancel_p_ thy t; + +if UnparseC.term t = "a \ 2 / b \ 2" then () +else error "rational.sml: diff.behav. in norm_Rational_mg 39b"; +*) + +"----- SRD Schalk I, p.69 Nr. 459b"; +val t = TermC.str2term "(a \ 2 - b \ 2)/(a*b) / (4*(a+b) \ 2/a)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(a + - 1 * b) / (4 * a * b + 4 * b \ 2)" then () +else error "rational.sml: diff.behav. in norm_Rational_mg 41"; + +"----- Schalk I, p.69 Nr. 460b nonterm.SK"; +val t = TermC.str2term "(9*(x \ 2 - 8*x + 16) / (4*(y \ 2 - 2*y + 1))) / ((3*x - 12) / (16*y - 16))"; +(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +exception Div raised + +BUT +val t = TermC.str2term + ("(144 + -72 * x + 9 * x \ 2) / (4 + -8 * y + 4 * y \ 2) /" ^ + "((-12 + 3 * x) / (-16 + 16 * y))"); +NONE = cancel_p_ thy t; + +if UnparseC.term t = !!!!!!!!!!!!!!!!!!!!!!!!! +then () else error "rational.sml: diff.behav. in norm_Rational_mg 42"; +*) + +"----- some variant of the above; was non-terminating before"; +val t = TermC.str2term "9*(x \ 2 - 8*x+16)*(16*y - 16)/(4*(y \ 2 - 2*y+1)*(3*x - 12))"; +val SOME (t , _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(48 + - 12 * x) / (1 + - 1 * y)" +then () else error "some variant of the above; was non-terminating before"; + +"----- SRD Schalk I, p.70 Nr. 472a"; +val t = TermC.str2term ("((8*x \ 2 - 32*y \ 2) / (2*x + 4*y)) / ((4*x - 8*y) / (x + y))"); +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "x + y" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 43"; + +"----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec"; +val t = TermC.str2term ("(a - (a*b + b \ 2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^ + "((a - a \ 2/(a+b))/(a+(a*b)/(a - b)))"); +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(2 * a \ 3 + 2 * a \ 2 * b) / (a \ 2 * b + b \ 3)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 51"; + +(*SRD Schalk I, p.69 Nr. 461a *) +val t = TermC.str2term "(2/(x+3) + 2/(x - 3)) / (8*x/(x \ 2 - 9))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "1 / 2" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 44"; + +(*SRD Schalk I, p.69 Nr. 464b *) +val t = TermC.str2term "(a - a/(a - 2)) / (a + a/(a - 2))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(- 3 + a) / (- 1 + a)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 45"; + +(*SRD Schalk I, p.69 Nr. 465b *) +val t = TermC.str2term "((x+3*y)/9 + (4*y \ 2 - 9*z \ 2)/(16*x)) / (x/9 + y/6 + z/4)"; +(* WN130911 non-termination due to non-termination of + cancel_p_ thy (TermC.str2term + ("("(576 * x \ 2 + 1728 * (x * y) + 1296 * y \ 2 + -2916 * z \ 2) /" ^ + "(576 * x \ 2 + 864 * (x * y) + 1296 * (x * z))")) + +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(4 * x + 6 * y + -9 * z) / (4 * x)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 46"; +*) + +(*SRD Schalk I, p.69 Nr. 466b *) +val t = TermC.str2term "((1 - 7*(x - 2)/(x \ 2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x \ 2 - 25))"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "(25 + - 10 * x + x \ 2) / 18" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 47"; + +(*SRD Schalk I, p.70 Nr. 469 *) +val t = TermC.str2term ("3*b \ 2 / (4*a \ 2 - 8*a*b + 4*b \ 2) / " ^ + "(a / (a \ 2*b - b \ 3) + (a - b) / (4*a*b \ 2 + 4*b \ 3) - 1 / (4*b \ 2))"); +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t = "- 3 * b \ 3 / (- 2 * a + 2 * b)" +then () else error "rational.sml: diff.behav. in norm_Rational_mg 48"; + +(*//----------------------------------TOODOO (*Rfuns revsets \ broken*) +"-------- me Schalk I No.186 -------------------------------------------------"; +"-------- me Schalk I No.186 -------------------------------------------------"; +"-------- me Schalk I No.186 -------------------------------------------------"; +val fmz = ["Term ((14 * x * y) / ( x * y ))", "normalform N"]; +val (dI',pI',mI') = + ("Rational",["rational", "simplification"], + ["simplification", "of_rationals"]); +val p = e_pos'; val c = []; +val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))]; +val (p,_,f,nxt,_,pt) = me nxt p c pt; +val (p,_,f,nxt,_,pt) = me nxt p c pt; +val (p,_,f,nxt,_,pt) = me nxt p c pt; +val (p,_,f,nxt,_,pt) = me nxt p c pt; +val (p,_,f,nxt,_,pt) = me nxt p c pt; +val (p,_,f,nxt,_,pt) = me nxt p c pt; +val (p,_,f,nxt,_,pt) = me nxt p c pt; +val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f; +val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f; +val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*) +val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*) +case (f2str f, nxt) of + ("14", ("End_Proof'", _)) => () + | _ => error "rational.sml diff.behav. in me Schalk I No.186"; + \\----------------------------------TOODOO (*Rfuns revsets \ broken*)*) + +(*//----------------------------------TOODOO (*Rfuns revsets \ broken*) +"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------"; +"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------"; +"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------"; +reset_states (); +CalcTree [(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"], + ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))]; +Iterator 1; +moveActiveRoot 1; +autoCalculate 1 CompleteCalc; +val ((pt, p), _) = get_calc 1; +(* +Test_Tool.show_pt pt; +[ +(([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))), +(([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))), +(([1], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))), +(([2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (-2 + x))), +(([3], Res), (2 + -1 * x) * (-2 + x) / (2 * a * (2 * a))), +(([4], Res), (-4 + 4 * x + -1 * x \ 2) / (4 * a \ 2)), +(([], Res), (-4 + 4 * x + -1 * x \ 2) / (4 * a \ 2))] +*) +interSteps 1 ([1], Res); +val ((pt, p), _) = get_calc 1; +(*Test_Tool.show_pt pt; +[ +(([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))), +(([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))), +(([1,1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))), +(([1,1], Res), (2 - x) / (2 * a) / (2 * a / (x + -1 * 2))), +(([1,2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))), +(([1], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))), +(([2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (-2 + x))), +(([3], Res), (2 + -1 * x) * (-2 + x) / (2 * a * (2 * a))), +(([4], Res), (-4 + 4 * x + -1 * x \ 2) / (4 * a \ 2)), +(([], Res), (-4 + 4 * x + -1 * x \ 2) / (4 * a \ 2))] +*) +val (t, asm) = get_obj g_result pt [1, 1]; +if UnparseC.term t = "(2 - x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso UnparseC.terms asm = "[]" +then () else error "2nd interSteps ..Simp_Rat_Double_No-1 changed on [1, 1]"; +val (t, asm) = get_obj g_result pt [1, 2]; +if UnparseC.term t = "(2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso UnparseC.terms asm = "[]" +then () else error "3rd interSteps ..Simp_Rat_Double_No-1 changed on [1, 2]"; + \\----------------------------------TOODOO (*Rfuns revsets \ broken*)*) + + +(*//----------------------------------TOODOO (*Rfuns revsets \ broken*) +"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------"; +"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------"; +"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------"; +reset_states (); +CalcTree [(["Term ((a^2 + -1*b^2) / (a^2 + -2*a*b + b^2))", "normalform N"], + ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))]; +Iterator 1; +moveActiveRoot 1; +autoCalculate 1 CompleteCalc; +val ((pt, p), _) = get_calc 1; +(*Test_Tool.show_pt pt; +[ +(([], Frm), Simplify ((a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2))), +(([1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2)), +(([1], Res), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), +(([2], Res), (a + b) / (a + -1 * b)), +(([], Res), (a + b) / (a + -1 * b))] +*) +interSteps 1 ([2], Res); +val ((pt, p), _) = get_calc 1; +(*Test_Tool.show_pt pt; +[ +(([], Frm), Simplify ((a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2))), +(([1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2)), +(([1], Res), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), +(([2,1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), +(([2,1], Res), (a + b) / (a + -1 * b)), +(([2], Res), (a + b) / (a + -1 * b)), +(([], Res), (a + b) / (a + -1 * b))] +*) +interSteps 1 ([2,1],Res); +val ((pt, p), _) = get_calc 1; +(*Test_Tool.show_pt pt; +[ +(([], Frm), Simplify ((a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2))), +(([1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2)), +(([1], Res), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), +(([2,1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), +(([2,1,1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), +(([2,1,1], Res), (a \ 2 + -1 * (a * b) + a * b + -1 * b \ 2) / +(a \ 2 + -2 * (a * b) + 1 * b \ 2)), +(([2,1,2], Res), (a \ 2 + -1 * (a * b) + a * b + -1 * b \ 2) / +(a \ 2 + -2 * (a * b) + -1 \ 2 * b \ 2)), +(([2,1,3], Res), (a \ 2 + -1 * (a * b) + a * b + -1 * b \ 2) / +(a \ 2 + -2 * (a * b) + (-1 * b) \ 2)), +(([2,1,4], Res), (a * a + -1 * (a * b) + a * b + -1 * b \ 2) / +(a \ 2 + -2 * (a * b) + (-1 * b) \ 2)), +(([2,1,5], Res), (a * a + -1 * (a * b) + a * b + -1 * (b * b)) / +(a \ 2 + -2 * (a * b) + (-1 * b) \ 2)), +(([2,1,6], Res), (a * a + -1 * (a * b) + a * b + -1 * (b * b)) / +(a \ 2 + -1 * (2 * (a * b)) + (-1 * b) \ 2)), +(([2,1,7], Res), (a * a + a * (-1 * b) + (b * a + b * (-1 * b))) / +(a \ 2 + 2 * (a * (-1 * b)) + (-1 * b) \ 2)), +(([2,1,8], Res), (a * a + a * (-1 * b) + (b * a + b * (-1 * b))) / +(a \ 2 + 2 * a * (-1 * b) + (-1 * b) \ 2)), +(([2,1,9], Res), (a * (a + -1 * b) + (b * a + b * (-1 * b))) / +(a \ 2 + 2 * a * (-1 * b) + (-1 * b) \ 2)), +(([2,1,10], Res), (a * (a + -1 * b) + b * (a + -1 * b)) / +(a \ 2 + 2 * a * (-1 * b) + (-1 * b) \ 2)), +(([2,1,11], Res), (a + b) * (a + -1 * b) / (a \ 2 + 2 * a * (-1 * b) + (-1 * b) \ 2)), +(([2,1,12], Res), (a + b) * (a + -1 * b) / ((a + -1 * b) * (a + -1 * b))), +(([2,1,13], Res), (a + b) / (a + -1 * b)), +(([2,1], Res), (a + b) / (a + -1 * b)), +(([2], Res), (a + b) / (a + -1 * b)), +(([], Res), (a + b) / (a + -1 * b))] +*) +val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*); +if length newnds = 13 then () else error "rational.sml: interSteps cancel_p rev_rew_p"; + +val p = ([2,1,9],Res); +getTactic 1 p; +val (_, tac, _) = ME_Misc.pt_extract (pt, p); +case tac of SOME (Rewrite ("sym_distrib_left", _)) => () +| _ => error "rational.sml: getTactic, sym_real_plus_binom_times1"; + \\----------------------------------TOODOO (*Rfuns revsets \ broken*)*) + + +"-------- investigate rulesets for cancel_p ----------------------------------"; +"-------- investigate rulesets for cancel_p ----------------------------------"; +"-------- investigate rulesets for cancel_p ----------------------------------"; +val thy = @{theory "Rational"}; +val t = TermC.str2term "(a \ 2 + -1*b \ 2) / (a \ 2 + -2*a*b + b \ 2)"; +val tt = TermC.str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"(*numerator only*); + +"----- with rewrite_set_"; +val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt; +if UnparseC.term tt'= "a \ 2 + - 1 * b \ 2" then () else error "rls chancel_p 1"; +val tt = TermC.str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*); +val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt; +if UnparseC.term tt' = "a \ 2 + - 2 * a * b + b \ 2" then () else error "rls chancel_p 2"; + +"----- with Derive.do_one; WN1130912 not investigated further, will be discontinued"; +val SOME (tt, _) = factout_p_ thy t; +if UnparseC.term tt = "(a + b) * (a + - 1 * b) / ((a + - 1 * b) * (a + - 1 * b))" +then () else error "rls chancel_p 3"; + +"--- with simpler ruleset"; +val {rules, rew_ord= (_, ro), ...} = Rule_Set.rep (assoc_rls "rev_rew_p"); +val der = Derive.do_one thy Atools_erls rules ro NONE tt; +if length der = 12 then () else error "WN1130912 rls chancel_p 4"; +(*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*) + +(*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*) +"...,(-1 * b \ 2 + a \ 2) / (-2 * (a * b) + a \ 2 + (-1 * b) \ 2) ]"; +(*default_print_depth 99;*) map (Rule.to_string o #2) der; (*default_print_depth 3;*) +(*default_print_depth 99;*) map (UnparseC.term o #1 o #3) der; (*default_print_depth 3;*) + +val der = Derive.do_one thy Atools_erls rules ro NONE + (TermC.str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"); +(*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*) + +val {rules, rew_ord=(_,ro),...} = Rule_Set.rep (assoc_rls "rev_rew_p"); +val der = Derive.do_one thy Atools_erls rules ro NONE + (TermC.str2term "(1 * a + -1 * b) * (1 * a + -1 * b)"); +(*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*) +(*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*) +(*WN060829 ...postponed*) + + +"-------- fun eval_get_denominator -------------------------------------------"; +"-------- fun eval_get_denominator -------------------------------------------"; +"-------- fun eval_get_denominator -------------------------------------------"; +val thy = @{theory Isac_Knowledge}; +val t = Thm.term_of (the (TermC.parse thy "get_denominator ((a +x)/b)")); +val SOME (_, t') = eval_get_denominator "" 0 t thy; +if UnparseC.term t' = "get_denominator ((a + x) / b) = b" +then () else error "get_denominator ((a + x) / b) = b" + + +"-------- several errpats in complicated term --------------------------------"; +"-------- several errpats in complicated term --------------------------------"; +"-------- several errpats in complicated term --------------------------------"; +(*WN12xxxx TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one + WN130912: kept this test, although not clear what for*) +reset_states (); +CalcTree [(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"], + ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))]; +Iterator 1; +moveActiveRoot 1; +autoCalculate 1 CompleteCalc; +val ((pt, p), _) = get_calc 1; +(*Test_Tool.show_pt pt; +[ +(([], Frm), Simplify ((5 * b + 25) / (a \ 2 - b \ 2) * (a - b) / (5 * b))), +(([1], Frm), (5 * b + 25) / (a \ 2 - b \ 2) * (a - b) / (5 * b)), +(([1], Res), (5 * b + 25) / (a \ 2 + -1 * b \ 2) * (a + -1 * b) / (5 * b)), +(([2], Res), (5 * b + 25) * (a + -1 * b) / (a \ 2 + -1 * b \ 2) / (5 * b)), +(([3], Res), (25 * a + -25 * b + 5 * (a * b) + -5 * b \ 2) / (a \ 2 + -1 * b \ 2) / +(5 * b)), +(([4], Res), (25 + 5 * b) / (a + b) / (5 * b)), +(([5], Res), (25 + 5 * b) / ((a + b) * (5 * b))), +(([6], Res), (25 + 5 * b) / (5 * (a * b) + 5 * b \ 2)), +(([7], Res), (5 + b) / (a * b + b \ 2)), +(([], Res), (5 + b) / (a * b + b \ 2))] *) + + +"-------- WN1309xx non-terminating rls norm_Rational -------------------------"; +"-------- WN1309xx non-terminating rls norm_Rational -------------------------"; +"-------- WN1309xx non-terminating rls norm_Rational -------------------------"; +(*------- Schalk I, p.70 Nr. 480b; a/b : c/d translated to a/b * d/c*) +val t = TermC.str2term + ("((12*x*y / (9*x \ 2 - y \ 2)) / (1 / (3*x - y) \ 2 - 1 / (3*x + y) \ 2)) * " ^ + "((1/(x - 5*y) \ 2 - 1/(x + 5*y) \ 2) / (20*x*y / (x \ 2 - 25*y \ 2)))"); + +(*1st factor separately simplified *) +val t = TermC.str2term "((12*x*y / (9*x \ 2 - y \ 2)) / (1 / (3*x - y) \ 2 - 1 / (3*x + y) \ 2))"; +val SOME (t', _) = rewrite_set_ thy false norm_Rational t; +if UnparseC.term t' = "(- 9 * x \ 2 + y \ 2) / - 1" then () else error "Nr. 480b lhs changed"; +(*2nd factor separately simplified *) +val t = TermC.str2term "((1/(x - 5*y) \ 2 - 1/(x + 5*y) \ 2) / (20*x*y / (x \ 2 - 25*y \ 2)))"; +val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; +if UnparseC.term t' = "- 1 / (- 1 * x \ 2 + 25 * y \ 2)" then () else error "Nr. 480b rhs changed"; + +"-------- Schalk I, p.70 Nr. 477a: terms are exploding ?!?"; +val t = TermC.str2term ("b*y/(b - 2*y)/((b \ 2 - y \ 2)/(b+2*y)) /" ^ + "(b \ 2*y + b*y \ 2) * (a+x) \ 2 / ((b \ 2 - 4*y \ 2) * (a+2*x) \ 2)"); +(*val SOME (t',_) = rewrite_set_ thy false norm_Rational t; +: +### rls: cancel_p on: (a \ 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \ 2 * y)) / +(b + -2 * y) / +((b \ 2 + -1 * y \ 2) / (b + 2 * y)) / +(b \ 2 * y + b * y \ 2) / +(a \ 2 * b \ 2 + -4 * (a \ 2 * y \ 2) + 4 * (a * (b \ 2 * x)) + + -16 * (a * (x * y \ 2)) + + 4 * (b \ 2 * x \ 2) + + -16 * (x \ 2 * y \ 2)) +exception Div raised + +BUT +val t = TermC.str2term + ("(a \ 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \ 2 * y)) /" ^ + "(b + -2 * y) /" ^ + "((b \ 2 + -1 * y \ 2) / (b + 2 * y)) /" ^ + "(b \ 2 * y + b * y \ 2) /" ^ + "(a \ 2 * b \ 2 + -4 * (a \ 2 * y \ 2) + 4 * (a * (b \ 2 * x)) +" ^ + "-16 * (a * (x * y \ 2)) +" ^ + "4 * (b \ 2 * x \ 2) +" ^ + "-16 * (x \ 2 * y \ 2))"); +NONE = cancel_p_ thy t; +*) + +(*------- Schalk I, p.70 Nr. 476b in 2003 this worked using 10 sec. *) +val t = TermC.str2term + ("((a \ 2 - b \ 2)/(2*a*b) + 2*a*b/(a \ 2 - b \ 2)) / ((a \ 2 + b \ 2)/(2*a*b) + 1) / " ^ + "((a \ 2 + b \ 2) \ 2 / (a + b) \ 2)"); +(* Rewrite.trace_on := true; +rewrite_set_ thy false norm_Rational t; +: +#### rls: cancel_p on: (2 * (a \ 7 * b) + 4 * (a \ 6 * b \ 2) + 6 * (a \ 5 * b \ 3) + + 8 * (a \ 4 * b \ 4) + + 6 * (a \ 3 * b \ 5) + + 4 * (a \ 2 * b \ 6) + + 2 * (a * b \ 7)) / +(2 * (a \ 9 * b) + 4 * (a \ 8 * b \ 2) + + 2 * (2 * (a \ 7 * b \ 3)) + + 4 * (a \ 6 * b \ 4) + + -4 * (a \ 4 * b \ 6) + + -4 * (a \ 3 * b \ 7) + + -4 * (a \ 2 * b \ 8) + + -2 * (a * b \ 9)) + +if UnparseC.term t = "1 / (a \ 2 + -1 * b \ 2)" then () +else error "rational.sml: diff.behav. in norm_Rational_mg 49"; +*) + +"-------- Schalk I, p.70 Nr. 480a: terms are exploding ?!?"; +val t = TermC.str2term ("(1/x + 1/y + 1/z) / (1/x - 1/y - 1/z) / " ^ + "(2*x \ 2 / (x \ 2 - z \ 2) / (x / (x + z) + x / (x - z)))"); +(* Rewrite.trace_on := true; +rewrite_set_ thy false norm_Rational t; +: +#### rls: cancel_p on: (2 * (x \ 6 * (y \ 2 * z)) + 2 * (x \ 6 * (y * z \ 2)) + + 2 * (x \ 5 * (y \ 2 * z \ 2)) + + -2 * (x \ 4 * (y \ 2 * z \ 3)) + + -2 * (x \ 4 * (y * z \ 4)) + + -2 * (x \ 3 * (y \ 2 * z \ 4))) / +(-2 * (x \ 6 * (y \ 2 * z)) + -2 * (x \ 6 * (y * z \ 2)) + + 2 * (x \ 5 * (y \ 2 * z \ 2)) + + 2 * (x \ 4 * (y \ 2 * z \ 3)) + + 2 * (x \ 4 * (y * z \ 4)) + + -2 * (x \ 3 * (y \ 2 * z \ 4))) +*) + +"-------- Schalk I, p.60 Nr. 215d: terms are exploding, internal loop does not terminate"; +val t = TermC.str2term "(a-b) \ 3 * (x+y) \ 4 / ((x+y) \ 2 * (a-b) \ 5)"; +(* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt: + +val t = TermC.str2term "(a-b) \ 3 * (x+y) \ 4"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +UnparseC.term t; +"a \ 3 * x \ 4 + 4 * a \ 3 * x \ 3 * y +6 * a \ 3 * x \ 2 * y \ 2 +4 * a \ 3 * x * y \ 3 +a \ 3 * y \ 4 +-3 * a \ 2 * b * x \ 4 +-12 * a \ 2 * b * x \ 3 * y +-18 * a \ 2 * b * x \ 2 * y \ 2 +-12 * a \ 2 * b * x * y \ 3 +-3 * a \ 2 * b * y \ 4 +3 * a * b \ 2 * x \ 4 +12 * a * b \ 2 * x \ 3 * y +18 * a * b \ 2 * x \ 2 * y \ 2 +12 * a * b \ 2 * x * y \ 3 +3 * a * b \ 2 * y \ 4 +-1 * b \ 3 * x \ 4 +-4 * b \ 3 * x \ 3 * y +-6 * b \ 3 * x \ 2 * y \ 2 +-4 * b \ 3 * x * y \ 3 +-1 * b \ 3 * y \ 4"; +val t = TermC.str2term "((x+y) \ 2 * (a-b) \ 5)"; +val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +UnparseC.term t; +"a \ 5 * x \ 2 + 2 * a \ 5 * x * y + a \ 5 * y \ 2 +-5 * a \ 4 * b * x \ 2 +-10 * a \ 4 * b * x * y +-5 * a \ 4 * b * y \ 2 +10 * a \ 3 * b \ 2 * x \ 2 +20 * a \ 3 * b \ 2 * x * y +10 * a \ 3 * b \ 2 * y \ 2 +-10 * a \ 2 * b \ 3 * x \ 2 +-20 * a \ 2 * b \ 3 * x * y +-10 * a \ 2 * b \ 3 * y \ 2 +5 * a * b \ 4 * x \ 2 +10 * a * b \ 4 * x * y +5 * a * b \ 4 * y \ 2 +-1 * b \ 5 * x \ 2 +-2 * b \ 5 * x * y +-1 * b \ 5 * y \ 2"; + +anscheinend macht dem Rechner das Krzen diese Bruches keinen Spass mehr ...*) + +"-------- Schalk I, p.70 Nr. 480b: terms are exploding, Rewrite.trace_on stops at"; +val t = TermC.str2term ("((12*x*y/(9*x \ 2 - y \ 2))/" ^ + "(1/(3*x - y) \ 2 - 1/(3*x + y) \ 2)) *" ^ + "(1/(x - 5*y) \ 2 - 1/(x + 5*y) \ 2)/" ^ + "(20*x*y/(x \ 2 - 25*y \ 2))"); +(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t; +: +#### rls: cancel_p on: (19440 * (x \ 8 * y \ 2) + -490320 * (x \ 6 * y \ 4) + + 108240 * (x \ 4 * y \ 6) + + -6000 * (x \ 2 * y \ 8)) / +(2160 * (x \ 8 * y \ 2) + -108240 * (x \ 6 * y \ 4) + + 1362000 * (x \ 4 * y \ 6) + + -150000 * (x \ 2 * y \ 8)) +*) + diff -r 33e04eb1a2f0 -r 464109593df0 test/Tools/isac/Knowledge/rational.sml --- a/test/Tools/isac/Knowledge/rational.sml Thu Jul 15 20:09:44 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1919 +0,0 @@ -(* Title: tests for rationals - Author: Walther Neuper - Use is subject to license terms. -*) - -"-----------------------------------------------------------------------------"; -"-----------------------------------------------------------------------------"; -"table of contents -----------------------------------------------------------"; -"-----------------------------------------------------------------------------"; -"-------- fun poly_of_term ---------------------------------------------------"; -"-------- fun is_poly --------------------------------------------------------"; -"-------- fun term_of_poly ---------------------------------------------------"; -"-------- integration lev.1 fun factout_p_ -----------------------------------"; -"-------- integration lev.1 fun cancel_p_ ------------------------------------"; -"-------- integration lev.1 fun common_nominator_p_ --------------------------"; -"-------- integration lev.1 fun add_fraction_p_ ------------------------------"; -"Rfuns-------- and app_rev ...traced down from rewrite_set_ until prepats ---------"; -"Rfuns-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------"; -"-------- rls norm_Rational downto fun gcd_poly ------------------------------"; -"Rfuns-------- rls norm_Rational downto fun add_fraction_p_ -----------------------"; -"----------- rewrite_set_ Partial_Fractions norm_Rational --------------------------------------"; -"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; -"----------- fun cancel_p with Const AA --------------------------------------------------------"; -"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----"; -"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------"; -"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------"; -"Rfuns-------- reverse rewrite ----------------------------------------------------"; -"Rfuns-------- 'reverse-ruleset' cancel_p -----------------------------------------"; -"-------- investigate rls norm_Rational --------------------------------------"; -"-------- examples: rls norm_Rational ----------------------------------------"; -"-------- rational numerals --------------------------------------------------"; -"-------- examples cancellation from: Mathematik 1 Schalk --------------------"; -"-------- examples common denominator from: Mathematik 1 Schalk --------------"; -"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------"; -"-------- examples common denominator and multiplication from: Schalk --------"; -"-------- examples double fractions from: Mathematik 1 Schalk ----------------"; -"-------- me Schalk I No.186 -------------------------------------------------"; -"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------"; -"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------"; -"-------- investigate rulesets for cancel_p ----------------------------------"; -"-------- fun eval_get_denominator -------------------------------------------"; -"-------- several errpats in complicated term --------------------------------"; -"-------- WN1309xx non-terminating rls norm_Rational -------------------------"; -"-----------------------------------------------------------------------------"; -"-----------------------------------------------------------------------------"; - - -"-------- fun poly_of_term ---------------------------------------------------"; -"-------- fun poly_of_term ---------------------------------------------------"; -"-------- fun poly_of_term ---------------------------------------------------"; -val thy = @{theory Partial_Fractions}; -val vs = TermC.vars_of (TermC.str2term "12 * x \ 3 * y \ 4 * z \ 6"); - -val t = TermC.str2term "-3 + -2 * x ::real"; -if poly_of_term vs t = SOME [(~3, [0, 0, 0]), (~2, [1, 0, 0])] -then () else error "poly_of_term uminus changed"; - -if poly_of_term vs (TermC.str2term "12::real") = SOME [(12, [0, 0, 0])] -then () else error "poly_of_term 1 changed"; - -if poly_of_term vs (TermC.str2term "x::real") = SOME [(1, [1, 0, 0])] -then () else error "poly_of_term 2 changed"; - -if poly_of_term vs (TermC.str2term "12 * x \ 3") = SOME [(12, [3, 0, 0])] -then () else error "poly_of_term 3 changed"; -"~~~~~ fun poly_of_term , args:"; val (vs, t) = - (vs, (TermC.str2term "12 * x \ 3")); - - monom_of_term vs (1, replicate (length vs) 0) t;(*poly malformed 1 with x \ 3*) -"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const ("Groups.times_class.times", _) $ m1 $ m2)) = - (vs, (1, replicate (length vs) 0), t); - val (c', es') = - - monom_of_term vs (c, es) m1; -"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const ("Transcendental.powr", _) $ (t as Free _) $ (Const ("Num.numeral_class.numeral", _) $ num)) ) = - (vs, (c', es'), m2); -(*+*)c = 12; -(*+*)(num |> HOLogic.dest_numeral |> list_update es (find_index (curry op = t) vs)) = [3, 0, 0]; - -if (c, num |> HOLogic.dest_numeral |> list_update es (find_index (curry op = t) vs)) = (12, [3, 0, 0]) -then () else error "monom_of_term (powr): return value CHANGED"; - -if poly_of_term vs (TermC.str2term "12 * x \ 3 * y \ 4 * z \ 6") = SOME [(12, [3, 4, 6])] -then () else error "poly_of_term 4 changed"; - -if poly_of_term vs (TermC.str2term "1 + 2 * x \ 3 * y \ 4 * z \ 6 + y") = - SOME [(1, [0, 0, 0]), (1, [0, 1, 0]), (2, [3, 4, 6])] -then () else error "poly_of_term 5 changed"; - -(*poly_of_term is quite liberal:*) -(*the coefficient may be somewhere, the order of variables and the parentheses - within a monomial are arbitrary*) -if poly_of_term vs (TermC.str2term "y \ 4 * (x \ 3 * 12 * z \ 6)") = SOME [(12, [3, 4, 6])] -then () else error "poly_of_term 6 changed"; - -(*there may even be more than 1 coefficient:*) -if poly_of_term vs (TermC.str2term "2 * y \ 4 * (x \ 3 * 6 * z \ 6)") = SOME [(12, [3, 4, 6])] -then () else error "poly_of_term 7 changed"; - -(*the order and the parentheses within monomials are arbitrary:*) -if poly_of_term vs (TermC.str2term "2 * x \ 3 * y \ 4 * z \ 6 + (7 * y \ 8 + 1)") - = SOME [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 6])] -then () else error "poly_of_term 8 changed"; - -(*from --- rls norm_Rational downto fun gcd_poly ---*) -val t = TermC.str2term (*copy from above: "::real" is not required due to " \ "*) - ("(-12 + 4 * y + 3 * x \ 2 + -1 * (x \ 2 * y)) /" ^ - "(-18 + -9 * x + 2 * y \ 2 + x * y \ 2)"); -"~~~~~ fun cancel_p_, args:"; val (t) = (t); -val opt = check_fraction t; -val SOME (numerator, denominator) = opt; -(*+*)UnparseC.term numerator = "- 12 + 4 * y + 3 * x \ 2 + - 1 * (x \ 2 * y)"; (*isa -- isa2*); -(*+*)UnparseC.term denominator = "- 18 + - 9 * x + 2 * y \ 2 + x * y \ 2"; (*isa -- isa2*); - val vs = TermC.vars_of t; -(*+*)UnparseC.terms vs = "[\"x\", \"y\"]"; - val baseT = type_of numerator - val expT = HOLogic.realT; -val (SOME _, SOME _) = (poly_of_term vs numerator, poly_of_term vs denominator); (*isa <> isa2*) - -"-------- fun is_poly --------------------------------------------------------"; -"-------- fun is_poly --------------------------------------------------------"; -"-------- fun is_poly --------------------------------------------------------"; -if is_poly (TermC.str2term "2 * x \ 3 * y \ 4 * z \ 6 + 7 * y \ 8 + 1") -then () else error "is_poly 1 changed"; -if not (is_poly (TermC.str2term "2 * (x \ 3 * y \ 4 * z \ 6 + 7) * y \ 8 + 1")) -then () else error "is_poly 2 changed"; - -"-------- fun term_of_poly ---------------------------------------------------"; -"-------- fun term_of_poly ---------------------------------------------------"; -"-------- fun term_of_poly ---------------------------------------------------"; -val expT = HOLogic.realT -val Free (_, baseT) = (hd o vars o TermC.str2term) "12 * x \ 3 * y \ 4 * z \ 6"; -val p = [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 5])] -val vs = TermC.vars_of (the (parseNEW ctxt "12 * x \ 3 * y \ 4 * z \ 6")) -(*precondition for [(c, es),...]: legth es = length vs*) -; -if UnparseC.term (term_of_poly baseT expT vs p) = "1 + 7 * y \ 8 + 2 * x \ 3 * y \ 4 * z \ 5" -then () else error "term_of_poly 1 changed"; - -"-------- integration lev.1 fun factout_p_ -----------------------------------"; -"-------- integration lev.1 fun factout_p_ -----------------------------------"; -"-------- integration lev.1 fun factout_p_ -----------------------------------"; -val t = TermC.str2term "(x \ 2 + -1*y \ 2) / (x \ 2 + -1*x*y)" -val SOME (t', asm) = factout_p_ thy t; -if UnparseC.term t' = "(x + y) * (x + - 1 * y) / (x * (x + - 1 * y))" -then () else error ("factout_p_ term 1 changed: " ^ UnparseC.term t') -; -if UnparseC.terms asm = "[\"x \ 0\", \"x + - 1 * y \ 0\"]" -then () else error "factout_p_ asm 1 changed" -; -val t = TermC.str2term "nothing + to_cancel ::real"; -if NONE = factout_p_ thy t then () else error "factout_p_ doesn't report non-applicable"; -; -val t = TermC.str2term "((3 * x \ 2 + 6 *x + 3) / (2*x + 2))"; -val SOME (t', asm) = factout_p_ thy t; -if UnparseC.term t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso - UnparseC.terms asm = "[\"1 + x \ 0\"]" -then () else error "factout_p_ 1 changed"; - -"-------- integration lev.1 fun cancel_p_ ------------------------------------"; -"-------- integration lev.1 fun cancel_p_ ------------------------------------"; -"-------- integration lev.1 fun cancel_p_ ------------------------------------"; -val t = TermC.str2term "(x \ 2 + -1*y \ 2) / (x \ 2 + -1*x*y)" -val SOME (t', asm) = cancel_p_ thy t; -if (UnparseC.term t', UnparseC.terms asm) = ("(x + y) / x", "[\"x \ 0\"]") -then () else error ("cancel_p_ (t', asm) 1 changed: " ^ UnparseC.term t') -; -val t = TermC.str2term "nothing + to_cancel ::real"; -if NONE = cancel_p_ thy t then () else error "cancel_p_ doesn't report non-applicable"; -; -val t = TermC.str2term "((3 * x \ 2 + 6 *x + 3) / (2*x + 2))"; -val SOME (t', asm) = cancel_p_ thy t; -if UnparseC.term t' = "(3 + 3 * x) / 2" andalso UnparseC.terms asm = "[]" -then () else error "cancel_p_ 1 changed"; - -"-------- integration lev.1 fun common_nominator_p_ --------------------------"; -"-------- integration lev.1 fun common_nominator_p_ --------------------------"; -"-------- integration lev.1 fun common_nominator_p_ --------------------------"; -val t = TermC.str2term ("y / (a*x + b*x + c*x) " ^ - (* n1 d1 *) - "+ a / (x*y)"); - (* n2 d2 *) -val SOME (t', asm) = common_nominator_p_ thy t; -if UnparseC.term t' = - ("y * y / (x * ((a + b + c) * y)) " ^ - (* n1 *d2'/ (c'* ( d1' *d2')) *) - "+ a * (a + b + c) / (x * ((a + b + c) * y))") - (* n2 * d1' / (c'* ( d1' *d2')) *) -then () else error "common_nominator_p_ term 1 changed"; -if UnparseC.terms asm = "[\"a + b + c \ 0\", \"y \ 0\", \"x \ 0\"]" -then () else error "common_nominator_p_ asm 1 changed" - -"-------- example in mail Nipkow"; -val t = TermC.str2term "x/(x \ 2 + -1*y \ 2) + y/(x \ 2 + -1*x*y)"; -val SOME (t', asm) = common_nominator_p_ thy t; -if UnparseC.term t' = - "x * x / ((x + - 1 * y) * ((x + y) * x)) +\ny * (x + y) / ((x + - 1 * y) * ((x + y) * x))" -then () else error "common_nominator_p_ term 2 changed" -; -if UnparseC.terms asm = "[\"x + y \ 0\", \"x \ 0\", \"x + - 1 * y \ 0\"]" -then () else error "common_nominator_p_ asm 2 changed" - -"-------- example: applicable tested by SML code"; -val t = TermC.str2term "nothing / to_add"; -if NONE = common_nominator_p_ thy t then () else error "common_nominator_p_ term 3 changed"; -; -val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))"; -val SOME (t', asm) = common_nominator_p_ thy t; -if UnparseC.term t' = - "(x + - 1) * (- 1 + x) / ((1 + x) * (- 1 + x)) +\n(x + 1) * (1 + x) / ((1 + x) * (- 1 + x))" - andalso UnparseC.terms asm = "[\"1 + x \ 0\", \"- 1 + x \ 0\"]" -then () else error "common_nominator_p_ 3 changed"; - -"-------- integration lev.1 fun add_fraction_p_ ------------------------------"; -"-------- integration lev.1 fun add_fraction_p_ ------------------------------"; -"-------- integration lev.1 fun add_fraction_p_ ------------------------------"; -val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))"; -val SOME (t', asm) = add_fraction_p_ thy t; -if UnparseC.term t' = "(2 + 2 * x \ 2) / (- 1 + x \ 2)" -then () else error "add_fraction_p_ 3 changed"; -; -if UnparseC.terms asm = "[\"- 1 + x \ 2 \ 0\"]" -then () else error "add_fraction_p_ 3 changed"; -; -val t = TermC.str2term "nothing / to_add"; -if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ term 3 changed"; -; -val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))"; -val SOME (t', asm) = add_fraction_p_ thy t; -if UnparseC.term t' = "(2 + 2 * x \ 2) / (- 1 + x \ 2)" andalso - UnparseC.terms asm = "[\"- 1 + x \ 2 \ 0\"]" -then () else error "add_fraction_p_ 3 changed"; - -"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------"; -"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------"; -"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------"; -(* trace down until prepats are evaluated - (which does not to work, because substitution is not done -- compare rew_sub!); - keep this sequence for the case, factout_p, cancel_p, common_nominator_p, add_fraction_p - (again) get prepat = [] changed to <>[]. *) -val t = TermC.str2term "(x \ 2 + -1*y \ 2) / (x \ 2 + -1*x*y)"; - -(*rewrite_set_ @{theory Isac_Knowledge} true cancel t = NONE; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) -"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (thy, false, cancel_p, t); -"~~~~~ fun rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) = - (thy, 1, bool, [], rls, term); -(*val (t', asm, rew) = app_rev thy (i+1) rrls t; rew = false!!!!!!!!!!!!!!!!!!!!!*) -"~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t); - fun chk_prepat thy erls [] t = true - | chk_prepat thy erls prepat t = - let - fun chk (pres, pat) = - (let - val subst: Type.tyenv * Envir.tenv = - Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty) - in - snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls) - end) handle Pattern.MATCH => false - fun scan_ f [] = false (*scan_ NEVER called by []*) - | scan_ f (pp::pps) = - if f pp then true else scan_ f pps; - in scan_ chk prepat end; - (* apply the normal_form of a rev-set *) - fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t = - if chk_prepat thy erls prepat t - then ((*tracing("### app_rev': t = "^UnparseC.term t);*) normal_form t) - else NONE; -(* val opt = app_rev' thy rrls t ..NONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) -"~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) = - (thy, rrls, t); -(* chk_prepat thy erls prepat t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) -(* app_sub thy i rrls t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) -"~~~~~ fun chk_prepat, args:"; val (thy, erls, prepat, t) = (thy, erls, prepat, t); - fun chk (pres, pat) = - (let - val subst: Type.tyenv * Envir.tenv = - Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty) - in - snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls) - end) handle Pattern.MATCH => false - fun scan_ f [] = false (*scan_ NEVER called by []*) - | scan_ f (pp::pps) = - if f pp then true else scan_ f pps; - -(*========== inhibit exn WN130823: prepat is empty ==================================== -(* scan_ chk prepat = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) -"~~~~~ fun , args:"; val (f, (pp::pps)) = (chk, prepat); -f; -val ([t1, t2], t) = pp; -UnparseC.term t1 = "?r is_expanded"; -UnparseC.term t2 = "?s is_expanded"; -UnparseC.term t = "?r / ?s"; -(* f pp = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) -"~~~~~ fun chk, args:"; val (pres, pat) = (pp); - val subst: Type.tyenv * Envir.tenv = - Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty) -(*subst = - ({}, {(("r", 0), ("real", Var (("r", 0), "real"))), - (("s", 0), ("real", Var (("s", 0), "real")))}*) -; - snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls) -"~~~~~ fun eval__true, args:"; val (thy, i, asms, bdv, rls) = - (thy, (i + 1), (map (Envir.subst_term subst) pres), [], erls); -UnparseC.terms asms; (* = "[\"?r is_expanded\",\"?s is_expanded\"]"*) -asms = [@{term True}] orelse asms = []; (* = false*) -asms = [@{term False}] ; (* = false*) -"~~~~~ fun chk, args:"; val (indets, (a::asms)) = ([], asms); -bdv (*= []: _a list*); -val bdv : (term * term) list = []; -rewrite__set_ thy (i+1) false; -UnparseC.term a = "?r is_expanded"; (*hier m"usste doch der Numerator eingesetzt sein ??????????????*) -val SOME (Const ("HOL.False", _), []) = rewrite__set_ thy (i+1) false bdv rls a -============ inhibit exn WN130823: prepat is empty ===================================*) - -"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------"; -"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------"; -"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------"; -val t = TermC.str2term "(12 * x * y) / (8 * y \ 2 )"; -(* "-------- example 187a": exception Div raised... -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*) -val t = TermC.str2term "(8 * x \ 2 * y * z ) / (18 * x * y \ 2 * z )"; -(* "-------- example 187b": doesn't terminate... -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*) -val t = TermC.str2term "(9 * x \ 5 * y \ 2 * z \ 4) / (15 * x \ 6 * y \ 3 * z )"; -(* "-------- example 187c": doesn't terminate... -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*) -"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (@{theory Isac_Knowledge}, false, cancel_p, t); -(* WN130827: exception Div raised... -rewrite__set_ thy 1 bool [] rls term -*) -"~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) = - (thy, 1, bool, [], rls, term); -(* WN130827: exception Div raised... - val (t', asm, rew) = app_rev thy (i+1) rrls t -*) -"~~~~~ fun app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t); -(* WN130827: exception Div raised... - val opt = app_rev' thy rrls t -*) -"~~~~~ fun app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) = - (thy, rrls, t); -chk_prepat thy erls prepat t = true; -(* WN130827: exception Div raised... -normal_form t -*) -(* lookup Rational.thy, cancel_p: normal_form = cancel_p_ thy*) -"~~~~~ fun cancel_p_, args:"; val (t) = (t); -val opt = check_fraction t; -val SOME (numerator, denominator) = opt - val vs = TermC.vars_of t - val baseT = type_of numerator - val expT = HOLogic.realT -val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator); -(*"-------- example 187a": exception Div raised... -val a = [(12, [1, 1])]: poly -val b = [(8, [0, 2])]: poly - val ((a', b'), c) = gcd_poly a b -*) -(* "-------- example 187b": doesn't terminate... -val a = [(8, [2, 1, 1])]: poly -val b = [(18, [1, 2, 1])]: poly - val ((a', b'), c) = gcd_poly a b -*) -(* "-------- example 187c": doesn't terminate... -val a = [(9, [5, 2, 4])]: poly -val b = [(15, [6, 3, 1])]: poly - val ((a', b'), c) = gcd_poly a b -*) - -"-------- rls norm_Rational downto fun gcd_poly ------------------------------"; -"-------- rls norm_Rational downto fun gcd_poly ------------------------------"; -"-------- rls norm_Rational downto fun gcd_poly ------------------------------"; -val t = TermC.str2term "(x \ 2 - 4)*(3 - y) / ((y \ 2 - 9)*(2+x))"; -Rewrite.trace_on := false (*true false*); -(* trace stops with ...: (and then jEdit hangs).. -rewrite_set_ thy false norm_Rational t; -: -### rls: cancel_p on: (-12 + 4 * y + 3 * x \ 2 + -1 * (x \ 2 * y)) / -(-18 + -9 * x + 2 * y \ 2 + x * y \ 2) -*) -val t = TermC.str2term (*copy from above: "::real" is not required due to " \ "*) - ("(-12 + 4 * y + 3 * x \ 2 + -1 * (x \ 2 * y)) /" ^ - "(-18 + -9 * x + 2 * y \ 2 + x * y \ 2)"); -(*cancel_p_ thy t; -exception Div raised*) - -"~~~~~ fun cancel_p_, args:"; val (t) = (t); -val opt = check_fraction t; -val SOME (numerator, denominator) = opt - val vs = TermC.vars_of t - val baseT = type_of numerator - val expT = HOLogic.realT; -(*default_print_depth 3; 999*) -val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator); -(*default_print_depth 3; 999*) -(* does not terminate instead of returning ?: - val ((a', b'), c) = gcd_poly a b -val a = [(~12, [0, 0]), (3, [2, 0]), (4, [0, 1]), (~1, [2, 1])]: poly -val b = [(~18, [0, 0]), (~9, [1, 0]), (2, [0, 2]), (1, [1, 2])]: poly -*) - -"-------- rls norm_Rational downto fun add_fraction_p_ -----------------------"; -"-------- rls norm_Rational downto fun add_fraction_p_ -----------------------"; -"-------- rls norm_Rational downto fun add_fraction_p_ -----------------------"; -val thy = @{theory Isac_Knowledge}; -"----- SK060904-2a non-termination of add_fraction_p_"; -val t = TermC.str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^ - " (-1 * a + b * x) / (a + b * x) "); -(* rewrite_set_ thy false norm_Rational t -exception Div raised*) -(* rewrite_set_ thy false add_fractions_p t; -exception Div raised*) -"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = - (@{theory Isac_Knowledge}, false, add_fractions_p, t); -"~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) = - (thy, 1, bool, [], rls, term); -(* app_rev thy (i+1) rrls t; -exception Div raised*) -"~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t); - fun chk_prepat thy erls [] t = true - | chk_prepat thy erls prepat t = - let - fun chk (pres, pat) = - (let - val subst: Type.tyenv * Envir.tenv = - Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty) - in - snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls) - end) handle Pattern.MATCH => false - fun scan_ f [] = false (*scan_ NEVER called by []*) - | scan_ f (pp::pps) = - if f pp then true else scan_ f pps; - in scan_ chk prepat end; - (* apply the normal_form of a rev-set *) - fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t = - if chk_prepat thy erls prepat t - then ((*tracing("### app_rev': t = "^UnparseC.term t);*) normal_form t) - else NONE; -(* val opt = app_rev' thy rrls t; -exception Div raised*) -(* val opt = app_rev' thy rrls t; -exception Div raised*) -"~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) = - (thy, rrls, t); -chk_prepat thy erls prepat t = true = true; -(*normal_form t -exception Div raised*) -(* lookup Rational.thy, val add_fractions_p: normal_form = add_fraction_p_ thy*) -(*add_fraction_p_ thy t -exception Div raised*) -"~~~~~ fun add_fraction_p_, args:"; val ((_: theory), t) = (thy, t); -val SOME ((n1, d1), (n2, d2)) = check_frac_sum t; -UnparseC.term n1; UnparseC.term d1; UnparseC.term n2; UnparseC.term d2; - val vs = TermC.vars_of t; -(*default_print_depth 3; 999*) -val (SOME _, SOME a, SOME _, SOME b) = - (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2); -(*default_print_depth 3; 999*) -(* -val a = [(1, [1, 0, 0]), (~1, [0, 1, 1])]: poly -val b = [(1, [1, 0, 0]), (1, [0, 1, 1])]: poly - val ((a', b'), c) = gcd_poly a b -*) - -"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; -"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; -"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; -val thy = @{theory Isac_Knowledge(*Partial_Fractions*)} -val ctxt = Proof_Context.init_global thy; - -(*---------- (1) with Free A, B ----------------------------------------------------------------*) -val t = (the o (parseNEW ctxt)) "3 = A / 2 + A / 4 + (B / 2 + -1 * B / (2::real))"; - (* required for applying thms in rewriting \ ^*) -(* we get details from here..*) - -Rewrite.trace_on := false; -val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t; -Rewrite.trace_on := false; -(* Rewrite.trace_on: -add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) - (* |||||||||||||||||||||||||||||||||||| *) - -val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 1 GUESS 1 GUESS 1 GUESS 1 *) - "A / 2 + A / 4 + (B / 2 + -1 * B / (2::real))"; -"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); -val NONE = (*case*) check_frac_sum t (*of*) - -(* Rewrite.trace_on: -add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) - (* |||||||||||||||||||||||||||| *) -val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 2 GUESS 2 GUESS 2 GUESS 2 *) - "A / 4 + (B / 2 + -1 * B / (2::real))"; -"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); -val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*); -(*+*)if (UnparseC.term n1, UnparseC.term d1) = ("A" , "4") andalso -(*+*) (UnparseC.term n2, UnparseC.term d2) = ("B / 2 + - 1 * B / 2", "1") -(*+*)then () else error "check_frac_sum (A / 4 + (B / 2 + -1 * B / (2::real))) changed"; - - val vs = TermC.vars_of t; -val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) = - (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*); - -"~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1); -val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t]; -(*+*)if xxx = 1 then () else error "monom_of_term changed" - -"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Free (id, _))) = - (vs, (1, replicate (length vs) 0), t); -case vs of [Free ("A", _), Free ("B", _)] => - if c = 1 andalso id = "A" - then () else error "monom_of_term Free changed 1" -| _ => error "monom_of_term Free changed 2"; - -(*---------- (2) with Const AA, BB --------------------------------------------------------------*) -val t = (the o (parseNEW ctxt)) "3 = AA / 2 + AA / 4 + (BB / 2 + -1 * BB / 2)"; - (*AA :: real*) -(* we get details from here..*) - -Rewrite.trace_on := false; -val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t; -Rewrite.trace_on := false; -(* Rewrite.trace_on: -add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) - (* |||||||||||||||||||||||||||||||||||| *) -val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *) - "AA / 2 + AA / 4 + (BB / 2 + -1 * BB / 2)"; -"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); -val NONE = (*case*) check_frac_sum t (*of*) - -(* Rewrite.trace_on: -add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) - (* |||||||||||||||||||||||||||| *) -val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *) - "AA / 4 + (BB / 2 + -1 * BB / 2)"; -"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); -val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*); -(*+*)if (UnparseC.term n1, UnparseC.term d1) = ("AA" , "4") andalso -(*+*) (UnparseC.term n2, UnparseC.term d2) = ("BB / 2 + - 1 * BB / 2", "1") -(*+*)then () else error "check_frac_sum (AA / 4 + (BB / 2 + -1 * BB / 2)) changed"; - - val vs = TermC.vars_of t; -val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) = - (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*); - -"~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1); -val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t]; -(*+*)if xxx = 1 then () else error "monom_of_term changed" - -"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const (id, _))) = - (vs, (1, replicate (length vs) 0), t); -case vs of [Const ("Partial_Fractions.AA", _), Const ("Partial_Fractions.BB", _)] => - if c = 1 andalso id = "Partial_Fractions.AA" - then () else error "monom_of_term Const changed 1" -| _ => error "monom_of_term Const changed 2"; - -"----------- fun cancel_p with Const AA --------------------------------------------------------"; -"----------- fun cancel_p with Const AA --------------------------------------------------------"; -"----------- fun cancel_p with Const AA --------------------------------------------------------"; -val thy = @{theory Partial_Fractions}; -val ctxt = Proof_Context.init_global @{theory} -val SOME t = TermC.parseNEW ctxt "2 * AA / 2"; (* Const ("Free ("AA", "real") *) - -val SOME (t', _) = rewrite_set_ thy true cancel_p t; -case t' of - Const ("Rings.divide_class.divide", _) $ Const ("Partial_Fractions.AA", _) $ - Const ("Groups.one_class.one", _) => () -| _ => error "WRONG rewrite_set_ cancel_p (2 * AA / 2) \ AA changed"; - -"~~~~~ fun cancel_p , args:"; val (t) = (t); -val opt = check_fraction t -val SOME (numerator, denominator) = (*case*) opt (*of*); - -if UnparseC.term numerator = "2 * AA" andalso UnparseC.term denominator = "2" -then () else error "check_fraction (2 * AA / 2) changed"; - val vs = TermC.vars_of t; -case vs of - [Const ("Partial_Fractions.AA", _)] => () -| _ => error "rewrite_set_ cancel_p (2 * AA / 2) \ AA/1 changed"; - - -"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----"; -"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----"; -"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----"; -val thy = @{theory "Rational"}; -"-------- WN"; -val t = TermC.str2term "(2 + -3 * x) / 9"; -if NONE = rewrite_set_ thy false cancel_p t then () -else error "rewrite_set_ cancel_p must return NONE, if the term cannot be cancelled"; - -"-------- example 186a"; -val t = TermC.str2term "(14 * x * y) / (x * y)"; - is_expanded (TermC.str2term "14 * x * y"); - is_expanded (TermC.str2term "x * y"); -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("14 / 1", "[]") -then () else error "rational.sml cancel Schalk 186a"; - -"-------- example 186b"; -val t = TermC.str2term "(60 * a * b) / ( 15 * a * b )"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("4 / 1", "[]") -then () else error "rational.sml cancel Schalk 186b"; - -"-------- example 186c"; -val t = TermC.str2term "(144 * a \ 2 * b * c) / (12 * a * b * c)"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("12 * a / 1", "[]") -then () else error "rational.sml cancel Schalk 186c"; - -(* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! exception Div raised !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - see --- fun rewrite_set_ downto fun gcd_poly --- -"-------- example 187a"; -val t = TermC.str2term "(12 * x * y) / (8 * y \ 2 )"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("3 * x / (2 * y)", "[\"4 * y ~= 0\"]") -then () else error "rational.sml cancel Schalk 187a"; -*) - -(* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - see --- fun rewrite_set_ downto fun gcd_poly --- -"-------- example 187b"; -val t = TermC.str2term "(8 * x \ 2 * y * z ) / (18 * x * y \ 2 * z )"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("4 * x / (9 * y)", "[\"2 * (z * (y * x)) ~= 0\"]") -then () else error "rational.sml cancel Schalk 187b"; -*) - -(* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - see --- fun rewrite_set_ downto fun gcd_poly --- -"-------- example 187c"; -val t = TermC.str2term "(9 * x \ 5 * y \ 2 * z \ 4) / (15 * x \ 6 * y \ 3 * z )"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = - ("3 * z \ 3 / (5 * (y * x))", "[\"3 * (z * (y \ 2 * x \ 5)) ~= 0\"]") -then () else error "rational.sml cancel Schalk 187c"; -*) - -"-------- example 188a"; -val t = TermC.str2term "(-8 + 8 * x) / (-9 + 9 * x)"; - is_expanded (TermC.str2term "8 * x + -8"); -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]") -then () else error "rational.sml cancel Schalk 188a"; - -val t = TermC.str2term "(8*((-1) + x))/(9*((-1) + x))"; -val SOME (t, _) = rewrite_set_ thy false make_polynomial t; -if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]") -then () else error "rational.sml cancel Schalk make_polynomial 1"; - -"-------- example 188b"; -val t = TermC.str2term "(-15 + 5 * x) / (-18 + 6 * x)"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("5 / 6", "[]") -then () else error "rational.sml cancel Schalk 188b"; - -"-------- example 188c"; -val t = TermC.str2term "(a + -1 * b) / (b + -1 * a)"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("- 1 / 1", "[]") -then () else error "rational.sml cancel Schalk 188c"; - -is_expanded (TermC.str2term "a + -1 * b") = true; -val t = TermC.str2term "((- 1)*(b + (-1) * a))/(1*(b + (- 1) * a))"; -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; -if (UnparseC.term t', UnparseC.terms asm) = ("(a + - 1 * b) / (- 1 * a + b)", "[]") -then () else error "rational.sml cancel Schalk make_polynomial 2"; - -"-------- example 190a"; -val t = TermC.str2term "( 27 * a \ 3 + 9 * a \ 2 + 3 * a + 1 ) / ( 27 * a \ 3 + 18 * a \ 2 + 3 * a )"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = - ("(1 + 9 * a \ 2) / (3 * a + 9 * a \ 2)", "[\"3 * a + 9 * a \ 2 \ 0\"]") -then () else error "rational.sml cancel Schalk 190a"; - -"-------- example 190c"; -val t = TermC.str2term "((1 + 9 * a \ 2)*(1 + 3 * a))/((3 * a + 9 * a \ 2)*(1 + 3 * a))"; -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; -if (UnparseC.term t', UnparseC.terms asm) = - ("(1 + 3 * a + 9 * a \ 2 + 27 * a \ 3) /\n(3 * a + 18 * a \ 2 + 27 * a \ 3)", "[]") -then () else error "rational.sml make_polynomial Schalk 190c"; - -"-------- example 191a"; -val t = TermC.str2term "( x \ 2 + -1 * y \ 2 ) / ( x + y )"; - is_expanded (TermC.str2term "x \ 2 + - 1 * y \ 2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) - is_expanded (TermC.str2term "x + y") = true; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("(x + - 1 * y) / 1", "[]") -then () else error "rational.sml make_polynomial Schalk 191a"; - -"-------- example 191b"; -val t = TermC.str2term "((x + (- 1) * y)*(x + y))/((1)*(x + y))"; -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; -if (UnparseC.term t', UnparseC.terms asm) = ("(x \ 2 + - 1 * y \ 2) / (x + y)", "[]") -then () else error "rational.sml make_polynomial Schalk 191b"; - -"-------- example 191c"; -val t = TermC.str2term "( 9 * x \ 2 + -30 * x + 25 ) / ( 9 * x \ 2 + -25 )"; - is_expanded (TermC.str2term "9 * x \ 2 + -30 * x + 25") = true; - is_expanded (TermC.str2term "25 + -30*x + 9*x \ 2") = true; - is_expanded (TermC.str2term "-25 + 9*x \ 2") = true; - -val t = TermC.str2term "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))"; -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; -if (UnparseC.term t', UnparseC.terms asm) = ("(25 + - 30 * x + 9 * x \ 2) / (- 25 + 9 * x \ 2)", "[]") -then () else error "rational.sml make_polynomial Schalk 191c"; - -"-------- example 192b"; -val t = TermC.str2term "( 7 * x \ 3 + - 1 * x \ 2 * y ) / ( 7 * x * y \ 2 + - 1 * y \ 3 )"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("x \ 2 / y \ 2", "[\"y \ 2 \ 0\"]") -then () else error "rational.sml cancel_p Schalk 192b"; - -val t = TermC.str2term "((x \ 2)*(7 * x + (-1) * y))/((y \ 2)*(7 * x + (-1) * y))"; -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; -if (UnparseC.term t', UnparseC.terms asm) = - ("(7 * x \ 3 + - 1 * x \ 2 * y) /\n(7 * x * y \ 2 + - 1 * y \ 3)", "[]") -then () else error "rational.sml make_polynomial Schalk 192b"; - -val t = TermC.str2term "((x \ 2)*(7 * x + (-1) * y))/((y \ 2)*(7 * x + (-1) * y))"; -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; -if (UnparseC.term t', UnparseC.terms asm) = - ("(7 * x \ 3 + - 1 * x \ 2 * y) /\n(7 * x * y \ 2 + - 1 * y \ 3)", "[]") -then () else error "rational.sml make_polynomial Schalk WN050929 not working"; - -"-------- example 193a"; -val t = TermC.str2term "( x \ 2 + -6 * x + 9 ) / ( x \ 2 + -9 )"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("(- 3 + x) / (3 + x)", "[\"3 + x \ 0\"]") -then () else error "rational.sml cancel_p Schalk 193a"; - -"-------- example 193b"; -val t = TermC.str2term "( x \ 2 + -8 * x + 16 ) / ( 2 * x \ 2 + -32 )"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("(- 4 + x) / (8 + 2 * x)", "[\"8 + 2 * x \ 0\"]") -then () else error "rational.sml cancel_p Schalk 193b"; - -"-------- example 193c"; -val t = TermC.str2term "( 2 * x + -50 * x \ 3 ) / ( 25 * x \ 2 + -10 * x + 1 )"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = - ("(2 * x + 10 * x \ 2) / (1 + - 5 * x)", "[\"1 + - 5 * x \ 0\"]") -then () else error "rational.sml cancel_p Schalk 193c"; - -(*WN: improved with new numerals*) -val t = TermC.str2term "(-25 + 9*x \ 2)/(5 + 3*x)"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = ("(- 5 + 3 * x) / 1", "[]") -then () else error "rational.sml cancel WN 1"; - -"-------- example heuberger"; -val t = TermC.str2term ("(x \ 4 + x * y + x \ 3 * y + y \ 2) / " ^ - "(x + 5 * x \ 2 + y + 5 * x * y + x \ 2 * y \ 3 + x * y \ 4)"); -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if (UnparseC.term t', UnparseC.terms asm) = - ("(x \ 3 + y) / (1 + 5 * x + x * y \ 3)", "[\"1 + 5 * x + x * y \ 3 \ 0\"]") -then () else error "rational.sml cancel_p heuberger"; - -"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------"; -"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------"; -"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------"; -(*deleted example 204 ... 236b at update Isabelle2012-->2013*) - -"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------"; -"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------"; -"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------"; -val t = TermC.str2term ("123 = (a*x)/(b*x) + (c*x)/(d*x) + (e*x)/(f*x::real)"); -"-------- gcd_poly integration level 1: works on exact term"; -if NONE = cancel_p_ thy t then () else error "cancel_p_ works on exact fraction"; -if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ works on exact fraction"; - -"-------- gcd_poly integration level 2: picks out ONE appropriate subterm"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p t; -if UnparseC.term t' = "123 = a * x / (b * x) + c * x / (d * x) + e / f" -then () else error "level 2, rewrite_set_ cancel_p: changed"; -val SOME (t', asm) = rewrite_set_ thy false add_fractions_p t; -if UnparseC.term t' = "123 = (b * c * x + a * d * x) / (b * d * x) + e * x / (f * x)" -then () else error "level 2, rewrite_set_ add_fractions_p: changed"; - -"-------- gcd_poly integration level 3: rewrites all appropriate subterms"; -val SOME (t', asm) = rewrite_set_ thy false cancel_p_rls t; -if UnparseC.term t' = "123 = a / b + c / d + e / f" -then () else error "level 3, rewrite_set_ cancel_p_rls: changed"; -val SOME (t', asm) = rewrite_set_ thy false add_fractions_p_rls t; (*CREATE add_fractions_p_rls*) -if UnparseC.term t' = "123 = (b * d * e * x + b * c * f * x + a * d * f * x) / (b * d * f * x)" -then () else error "level 3, rewrite_set_ add_fractions_p_rls: changed"; - -"-------- gcd_poly integration level 4: iteration cancel_p -- add_fraction_p"; -(* simpler variant *) -val testrls = Rule_Set.append_rules "testrls" Rule_Set.empty [Rls_ cancel_p, Rls_ add_fractions_p] -val SOME (t', asm) = rewrite_set_ thy false testrls t; -(*Rewrite.trace_on := false; -# rls: testrls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) -## rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) -## rls: add_fractions_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f -## rls: cancel_p on: 123 = (b * c * x + a * d * x) / (b * d * x) + e / f -## rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f -## rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) -## rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *) -if UnparseC.term t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)" -then () else error "level 4, rewrite_set_ *_p: changed"; - -(* complicated variant *) -val testrls_rls = Rule_Set.append_rules "testrls_rls" Rule_Set.empty [Rls_ cancel_p_rls, Rls_ add_fractions_p_rls]; -val SOME (t', asm) = rewrite_set_ thy false testrls_rls t; -(*# rls: testrls_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) -## rls: cancel_p_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) -### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) -### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f -### rls: cancel_p on: 123 = a * x / (b * x) + c / d + e / f -### rls: cancel_p on: 123 = a / b + c / d + e / f -## rls: add_fractions_p_rls on: 123 = a / b + c / d + e / f -### rls: add_fractions_p on: 123 = a / b + c / d + e / f -### rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f -### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) -## rls: cancel_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) -### rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) -## rls: add_fractions_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) -### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *) -if UnparseC.term t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)" -then () else error "level 4, rewrite_set_ *_p_rls: changed" - -"-------- gcd_poly integration level 5: cancel_p & add_fraction_p within norm_Rational"; -val SOME (t', asm) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)" -then () else error "level 5, rewrite_set_ norm_Rational: changed" - -"-------- reverse rewrite ----------------------------------------------------"; -"-------- reverse rewrite ----------------------------------------------------"; -"-------- reverse rewrite ----------------------------------------------------"; -(** the term for which reverse rewriting is demonstrated **) -val t = TermC.str2term "(9 + -1 * x \ 2) / (9 + 6 * x + x \ 2)"; -val Rrls {scr = Rfuns {init_state = ini, locate_rule = loc, - next_rule = nex, normal_form = nor, ...},...} = cancel_p; - -(** normal_form produces the result in ONE step **) - val SOME (t', _) = nor t; -if UnparseC.term t' = "(3 + - 1 * x) / (3 + x)" then () -else error "rational.sml normal_form (9 - x \ 2) / (9 - 6 * x + x \ 2)"; - -(** initialize the interpreter state used by the 'me' **) - val (t, _, revsets, _) = ini t; - -if length (hd revsets) = 11 then () else error "length of revset changed"; -(*//----------------------------------TOODOO (*Rfuns revsets \ broken*) -if (revsets |> nth 1 |> nth 1 |> id_of_thm) = - (@{thm realpow_twoI} |> Thm.get_name_hint |> ThmC.cut_id) -then () else error "first element of revset changed"; -if -(revsets |> nth 1 |> nth 1 |> Rule.to_string) = "Thm (\"realpow_twoI\",?r1 \ 2 = ?r1 * ?r1)" andalso -(revsets |> nth 1 |> nth 2 |> Rule.to_string) = "Thm (\"#: 9 = 3 \ 2\",9 = 3 \ 2)" andalso -(revsets |> nth 1 |> nth 3 |> Rule.to_string) = "Thm (\"#: 6 * x = 2 * (3 * x)\",6 * x = 2 * (3 * x))" -andalso -(revsets |> nth 1 |> nth 4 |> Rule.to_string) = "Thm (\"#: -3 * x = -1 * (3 * x)\",-3 * x = -1 * (3 * x))" -andalso -(revsets |> nth 1 |> nth 5 |> Rule.to_string) = "Thm (\"#: 9 = 3 * 3\",9 = 3 * 3)" andalso -(revsets |> nth 1 |> nth 6 |> Rule.to_string) = "Rls_ (\"sym_order_mult_rls_\")" andalso -(revsets |> nth 1 |> nth 7 |> Rule.to_string) = - "Thm (\"sym_mult.assoc\",?a * (?b * ?c) = ?a * ?b * ?c)" -then () else error "first 7 elements in revset changed" - \\----------------------------------TOODOO (*Rfuns revsets \ broken*)*) - -(** find the rule 'r' to apply to term 't' **) -(*/------- WN1309: since cancel_ (accepted "-" between monomials) has been replaced by cancel_p_ - for Isabelle2013, we don't get a working revset, but non-termination: - - val SOME (r as (Thm (str, thm))) = nex revsets t; - : -((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), []))", " -((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x), - Thm ("sym_mult.assoc", ""), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x), []))", " -((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x), - Thm ("sym_mult.assoc", ""), ((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), []))", " -((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), []))", " - : -### Isabelle2002: - Thm ("sym_#mult_2_3", "6 = 2 * 3") -### Isabelle2009-2 for cancel_ (not cancel_p_): -if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" - andalso ThmC.string_of_thm thm = - (string_of_thm (Thm.make_thm @{theory "Isac_Knowledge"} - (Trueprop $ (Thm.term_of o the o (TermC.parse thy)) "9 = 3 \ 2"))) then () -else error "rational.sml next_rule (9 - x \ 2) / (9 - 6 * x + x \ 2)"; -\---------------------------------------------------------------------------------------/*) - -(** check, if the rule 'r' applied by the user to 't' belongs to the ruleset; - if the rule is OK, the term resulting from applying the rule is returned,too; - there might be several rule applications inbetween, - which are listed after the head in reverse order **) -(*/-------------------------------------------- Isabelle2013: this gives "error id_of_thm"; - we don't repair this, because interaction within "reverse rewriting" never worked properly: - - val (r, (t, asm))::_ = loc revsets t r; -if UnparseC.term t = "(9 - x \ 2) / (3 \ 2 + 6 * x + x \ 2)" andalso asm = [] -then () else error "rational.sml locate_rule (9 - x \ 2) / (9 - 6 * x + x \ 2)"; - -(* find the next rule to apply *) - val SOME (r as (Thm (str, thm))) = nex revsets t; -if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso - ThmC.string_of_thm thm = (string_of_thm (ThmC_Def.make_thm @{theory "Isac_Knowledge"} - (Trueprop $ (Thm.term_of o the o (TermC.parse thy)) "9 = 3 \ 2"))) then () -else error "rational.sml next_rule (9 - x \ 2) / (9 - 6 * x + x \ 2)"; - -(*check the next rule*) - val (r, (t, asm)) :: _ = loc revsets t r; -if UnparseC.term t = "(3 \ 2 - x \ 2) / (3 \ 2 + 6 * x + x \ 2)" then () -else error "rational.sml locate_rule (9 - x \ 2) / (9 - 6 * x + x \ 2) II"; - -(*find and check the next rules, rewrite*) - val SOME r = nex revsets t; - val (r,(t,asm))::_ = loc revsets t r; -if UnparseC.term t = "(3 \ 2 - x \ 2) / (3 \ 2 + 2 * 3 * x + x \ 2)" then () -else error "rational.sml locate_rule II"; - - val SOME r = nex revsets t; - val (r,(t,asm))::_ = loc revsets t r; -if UnparseC.term t = "(3 - x) * (3 + x) / (3 \ 2 + 2 * 3 * x + x \ 2)" then () -else error "rational.sml next_rule II"; - - val SOME r = nex revsets t; - val (r,(t,asm))::_ = loc revsets t r; -if UnparseC.term t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then () -else error "rational.sml next_rule III"; - - val SOME r = nex revsets t; - val (r, (t, asm)) :: _ = loc revsets t r; - val ss = UnparseC.term t; -if ss = "(3 - x) / (3 + x)" andalso UnparseC.terms asm = "[\"3 + x ~= 0\"]" then () -else error "rational.sml: new behav. in rev-set cancel"; -\--------------------------------------------------------------------------------------/*) - -"-------- 'reverse-ruleset' cancel_p -----------------------------------------"; -"-------- 'reverse-ruleset' cancel_p -----------------------------------------"; -"-------- 'reverse-ruleset' cancel_p -----------------------------------------"; -(*WN130909: the example below shows, why "reverse rewriting" only worked for - special cases.*) - -(*the term for which reverse rewriting is demonstrated*) -val t = TermC.str2term "(9 + (-1)*x \ 2) / (9 + ((-6)*x + x \ 2))"; -val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc, - next_rule=nex,normal_form=nor,...},...} = cancel_p; - -(*normal_form produces the result in ONE step*) -val SOME (t', _) = nor t; -if UnparseC.term t' = "(3 + x) / (3 + - 1 * x)" -then () else error "cancel_p normal_form CHANGED";; - -(*initialize the interpreter state used by the 'me'*) -val SOME (t', asm) = cancel_p_ thy t; -if (UnparseC.term t', UnparseC.terms asm) = ("(3 + x) / (3 + - 1 * x)", "[\"3 + - 1 * x \ 0\"]") -then () else error "cancel_p CHANGED";; - -val (t,_,revsets,_) = ini t; - -(* WN.10.10.02: dieser Fall terminiert nicht - (make_polynomial enth"alt zu viele rules) -WN060823 'init_state' requires rewriting on specified location in the term -default_print_depth 99; Rfuns; default_print_depth 3; -WN060831 cycling "sym_order_mult_rls_" "sym_mult.assoc" - as was with make_polynomial before ?!?* ) - -val SOME r = nex revsets t; -eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))", - mk_thm thy "9 = 3 \ 2")); -( *WN060831 *** id_of_thm - Exception- ERROR raised ... -val (r,(t,asm))::_ = loc revsets t r; -UnparseC.term t; - - val SOME r = nex revsets t; - val (r,(t,asm))::_ = loc revsets t r; - UnparseC.term t; -*) - -"-------- examples: rls norm_Rational ----------------------------------------"; -"-------- examples: rls norm_Rational ----------------------------------------"; -"-------- examples: rls norm_Rational ----------------------------------------"; -val t = TermC.str2term "(3*x+5)/18 - x/2 - -(3*x - 2)/9 = 0"; -val SOME (t', _) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; -if UnparseC.term t' = "1 / 18 = 0" then () else error "rational.sml 1"; - -val t = TermC.str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0"; -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; -if UnparseC.term t' = "(237 + 65 * x) / 36 = 0" then () -else error "rational.sml 2"; - -val t = TermC.str2term "(1/2 + (5*x)/2) \ 2 - ((13*x)/2 - 5/2) \ 2 - (6*x) \ 2 + 29"; -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; -if UnparseC.term t' = "23 + 35 * x + - 72 * x \ 2" then () -else error "rational.sml 3"; - -(*Rewrite.trace_on:=true;*) -val t = TermC.str2term "Not (6*x is_atom)"; -val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t'; -"HOL.True"; -val t = TermC.str2term "1 < 2"; -val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t'; -"HOL.True"; - -val t = TermC.str2term "(6*x) \ 2"; -val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false - (ThmC.numerals_to_Free @{thm realpow_def_atom}) t; -if UnparseC.term t' = "6 * x * (6 * x) \ (2 + - 1)" then () -else error "rational.sml powers_erls (6*x) \ 2"; - -val t = TermC.str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))"; -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; -if UnparseC.term t' = "65 * x / 2" then () else error "rational.sml 4"; - -val t = TermC.str2term "1 - ((13*x)/2 - 5/2) \ 2"; -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; -if UnparseC.term t' = "(- 21 + 130 * x + - 169 * x \ 2) / 4" then () -else error "rational.sml 5"; - -(*SRAM Schalk I, p.92 Nr. 609a*) -val t = TermC.str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54"; -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; -if UnparseC.term t' = "(- 255 + 112 * x) / 135" then () -else error "rational.sml 6"; - -(*SRAM Schalk I, p.92 Nr. 610c*) -val t = TermC.str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2"; -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; -if UnparseC.term t' = "(3 + x) / - 2" then () else error "rational.sml 7"; - -(*SRAM Schalk I, p.92 Nr. 476a*) -val t = TermC.str2term "(x \ 2/(1 - x \ 2) + 1)/(x/(1 - x) + 1) * (1 + x)"; -(*. a/b : c/d translated to a/b * d/c .*) -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; -if UnparseC.term t' = "1" then () else error "rational.sml 8"; - -(*Schalk I, p.92 Nr. 472a*) -val t = TermC.str2term "((8*x \ 2 - 32*y \ 2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))"; -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; -if UnparseC.term t' = "x + y" then () else error "rational.sml p.92 Nr. 472a"; - -(*Schalk I, p.70 Nr. 480b: SEE rational.sml --- nonterminating rls norm_Rational ---*) - -(*WN130910 add_fractions_p exception Div raised + history: -### WN.2.6.03 from rlang.sml 56a -val t = TermC.str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a \ 2 + -1 * b \ 2)"; -val NONE = rewrite_set_ thy false add_fractions_p t; - -THE ERROR ALREADY OCCURS IN THIS PART: -val t = TermC.str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)"; -val NONE = add_fraction_p_ thy t; - -SEE Test_Some.thy: section {* add_fractions_p downto exception Div raised === -*) - -"-------- rational numerals --------------------------------------------------"; -"-------- rational numerals --------------------------------------------------"; -"-------- rational numerals --------------------------------------------------"; -(*SRA Schalk I, p.40 Nr. 164b *) -val t = TermC.str2term "(47/6 - 76/9 + 13/4)/(35/12)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "19 / 21" then () -else error "rational.sml: diff.behav. in norm_Rational_mg 1"; - -(*SRA Schalk I, p.40 Nr. 166a *) -val t = TermC.str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "45 / 2" then () -else error "rational.sml: diff.behav. in norm_Rational_mg 2"; - -"-------- examples cancellation from: Mathematik 1 Schalk --------------------"; -"-------- examples cancellation from: Mathematik 1 Schalk --------------------"; -"-------- examples cancellation from: Mathematik 1 Schalk --------------------"; -(* e190c Stefan K.*) -val t = TermC.str2term "((1 + 9*a \ 2) * (1 + 3*a)) / ((3*a + 9*a \ 2) * (1 + 3*a))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(1 + 9 * a \ 2) / (3 * a + 9 * a \ 2)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 3"; - -(* e192b Stefan K.*) -val t = TermC.str2term "(x \ 2 * (7*x + (-1)*y)) / (y \ 2 * (7*x + (-1)*y))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "x \ 2 / y \ 2" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 4"; - -(*SRC Schalk I, p.66 Nr. 379c *) -val t = TermC.str2term "(a - b)/(b - a)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "- 1" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 5"; - -(*SRC Schalk I, p.66 Nr. 380b *) -val t = TermC.str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 6"; - -(*Schalk I, p.60 Nr. 215c *) -val t = TermC.str2term "(a + b) \ 4 * (x - y) / ((x - y) \ 3 * (a + b) \ 2)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(a \ 2 + 2 * a * b + b \ 2) / (x \ 2 + - 2 * x * y + y \ 2)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 7"; - -(*SRC Schalk I, p.66 Nr. 381b *) -val t = TermC.str2term -"(4*x \ 2 - 20*x + 25)/(2*x - 5) \ 3"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "1 / (- 5 + 2 * x)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 9"; - -(* e190c Stefan K.*) -val t = TermC.str2term "((1 + 9*a \ 2) * (1 + 3*a)) / ((3*a + 9*a \ 2) * (1 + 3 * a))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(1 + 9 * a \ 2) / (3 * a + 9 * a \ 2)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 3"; - -(* e192b Stefan K.*) -val t = TermC.str2term "(x \ 2 * (7*x + (-1)*y)) / (y \ 2 * (7*x + (-1)*y))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "x \ 2 / y \ 2" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 4"; - -(*SRC Schalk I, p.66 Nr. 379c *) -val t = TermC.str2term "(a - b) / (b - a)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "- 1" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 5"; - -(*SRC Schalk I, p.66 Nr. 380b *) -val t = TermC.str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 6"; - -(*Schalk I, p.60 Nr. 215c *) -val t = TermC.str2term "(a + b) \ 4 * (x - y) / ((x - y) \ 3 * (a + b) \ 2)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(a \ 2 + 2 * a * b + b \ 2) / (x \ 2 + - 2 * x * y + y \ 2)" -then () else error "Schalk I, p.60 Nr. 215c: with Isabelle2002 cancellation incomplete, changed"; - -(* extreme example from somewhere *) -val t = TermC.str2term - ("(a \ 4 * x + -1*a \ 4 * y + 4*a \ 3 * b * x + -4*a \ 3 * b * y + " ^ - "6*a \ 2 * b \ 2 * x + -6*a \ 2 * b \ 2 * y + 4*a * b \ 3 * x + -4*a * b \ 3 * y + " ^ - "b \ 4 * x + -1*b \ 4 * y) " ^ - " / (a \ 2 * x \ 3 + -3*a \ 2 * x \ 2 * y + 3*a \ 2 * x * y \ 2 + -1*a \ 2 * y \ 3 + " ^ - "2*a * b * x \ 3 + -6*a * b * x \ 2 * y + 6*a * b * x * y \ 2 + -2*a * b * y \ 3 + " ^ - "b \ 2 * x \ 3 + -3*b \ 2 * x \ 2 * y + 3*b \ 2 * x * y \ 2 + -1*b \ 2 * y \ 3)") -val SOME (t, _) = rewrite_set_ thy false cancel_p t; -if UnparseC.term t = "(a \ 2 + 2 * a * b + b \ 2) / (x \ 2 + - 2 * x * y + y \ 2)" -then () else error "with Isabelle2002: NONE -- now SOME changed"; - -(*Schalk I, p.66 Nr. 381a *) -(* ATTENTION: here the rls is very slow. In Isabelle2002 this required 2 min *) -val t = TermC.str2term "18*(a + b) \ 3 * (a - b) \ 2 / (72*(a - b) \ 3 * (a + b) \ 2)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(a + b) / (4 * a + - 4 * b)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 8"; - -(*SRC Schalk I, p.66 Nr. 381b *) -val t = TermC.str2term "(4*x \ 2 - 20*x + 25) / (2*x - 5) \ 3"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "1 / (- 5 + 2 * x)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 9"; - -(*SRC Schalk I, p.66 Nr. 381c *) -val t = TermC.str2term "(27*a \ 3 + 9*a \ 2+3*a+1) / (27*a \ 3 + 18*a \ 2+3*a)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(1 + 9 * a \ 2) / (3 * a + 9 * a \ 2)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 10"; - -(*SRC Schalk I, p.66 Nr. 383a *) -val t = TermC.str2term "(5*a \ 2 - 5*a*b) / (a - b) \ 2"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "- 5 * a / (- 1 * a + b)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 11"; - -"----- NOT TERMINATING ?: worked before 0707xx"; -val t = TermC.str2term "(a \ 2 - 1)*(b + 1) / ((b \ 2 - 1)*(a+1))"; -(* WN130911 "exception Div raised" by - cancel_p_ thy (TermC.str2term ("(-1 + -1 * b + a \ 2 + a \ 2 * b) /" ^ - "(-1 + -1 * a + b \ 2 + a * b \ 2)")) - -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(1 + -1 * a) / (1 + -1 * b)" then () -else error "rational.sml MG tests 3e"; -*) - -"-------- examples common denominator from: Mathematik 1 Schalk --------------"; -"-------- examples common denominator from: Mathematik 1 Schalk --------------"; -"-------- examples common denominator from: Mathematik 1 Schalk --------------"; -(*SRA Schalk I, p.67 Nr. 403a *) -val t = TermC.str2term "4/x - 3/y - 1"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(- 3 * x + 4 * y + - 1 * x * y) / (x * y)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 12"; - -val t = TermC.str2term "(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a \ 2+3*b*c)/(a*b*c)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "4 / c" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 13"; - -(*SRA Schalk I, p.67 Nr. 410b *) -val t = TermC.str2term "1/(x+1) + 1/(x+2) - 2/(x+3)"; -(* WN130911 non-termination due to non-termination of - cancel_p_ thy (TermC.str2term "(5 + 3 * x) / (6 + 11 * x + 6 * x \ 2 + x \ 3)") - -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(5 + 3 * x) / (6 + 11 * x + 6 * x \ 2 + x \ 3)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 14"; -*) - -(*SRA Schalk I, p.67 Nr. 413b *) -val t = TermC.str2term "(1 + x)/(1 - x) - (1 - x)/(1 + x) + 2*x/(1 - x \ 2)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "6 * x / (1 + - 1 * x \ 2)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 15"; - -(*SRA Schalk I, p.68 Nr. 414a *) -val t = TermC.str2term "(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t ="(- 2 + - 5 * x + 2 * x \ 2) / (2 + - 3 * x + x \ 2)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 16"; - -(*SRA Schalk I, p.68 Nr. 428b *) -val t = TermC.str2term - "1/(a - b) \ 2 + 1/(a + b) \ 2 - 2/(a \ 2 - b \ 2) - 4*(b \ 2 - 1)/(a \ 2 - b \ 2) \ 2"; -(* WN130911 non-termination due to non-termination of - cancel_p_ thy (TermC.str2term "(4 + -4 * b \ 2) / (a \ 4 + -2 * (a \ 2 * b \ 2) + b \ 4)") - -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "4 / (a \ 4 + -2 * a \ 2 * b \ 2 + b \ 4)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 18"; -*) - -(*SRA Schalk I, p.68 Nr. 430b *) -val t = TermC.str2term - "a \ 2/(a - 3*b) - 108*a*b \ 3/((a+3*b)*(a \ 2 - 9*b \ 2)) - 9*b \ 2*(a - 3*b)/(a+3*b) \ 2"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "a + 3 * b" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 19"; - -(*SRA Schalk I, p.68 Nr. 432 *) -val t = TermC.str2term - ("(a \ 2 + a*b) / (a \ 2 - b \ 2) - (b \ 2 - a*b) / (b \ 2 - a \ 2) + " ^ - "a \ 2*(a - b) / (a \ 3 - a \ 2*b) - 2*a*(a \ 2 - b \ 2) / (a \ 3 - a*b \ 2) - " ^ - "2*b \ 2 / (a \ 2 - b \ 2)"); -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = (*"0" ..isabisac15 | Isabelle2017..*) "0 / (a \ 2 + - 1 * b \ 2)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 20"; - -(* some example *) -val t = TermC.str2term "3*a / (a*b) + x/y"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(3 * y + b * x) / (b * y)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 21"; - - -"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------"; -"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------"; -"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------"; -(*------- SRM Schalk I, p.68 Nr. 436a *) -val t = TermC.str2term "3*(x+y) / (15*(x - y)) * 25*(x - y) \ 2 / (18*(x + y) \ 2)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(- 5 * x + 5 * y) / (- 18 * x + - 18 * y)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 22"; - -(*------- SRM.test Schalk I, p.68 Nr. 436b *) -val t = TermC.str2term "5*a*(a - b) \ 2*(a + b) \ 3/(7*b*(a - b) \ 3) * 7*b/(a + b) \ 3"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "5 * a / (a + - 1 * b)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 23"; - -(*------- Schalk I, p.68 Nr. 437a *) -val t = TermC.str2term "(3*a - 4*b) / (4*c+3*e) * (3*a+4*b)/(9*a \ 2 - 16*b \ 2)"; -(* raises an exception for unclear reasons: -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -: -### rls: cancel_p on: (9 * a \ 2 + -16 * b \ 2) / (4 * c + 3 * e) / -(9 * a \ 2 + -16 * b \ 2) -exception Div raised - -BUT -val t = TermC.str2term - ("(9 * a \ 2 + -16 * b \ 2) / (4 * c + 3 * e) /" ^ - "(9 * a \ 2 + -16 * b \ 2)"); -NONE = cancel_p_ thy t; - -if UnparseC.term t = "1 / (4 * c + 3 * e)" then () -else error "rational.sml: diff.behav. in norm_Rational_mg 24"; -*) - -"----- S.K. corrected non-termination 060904"; -val t = TermC.str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a \ 2 - 16*b \ 2))"; -val SOME (t, _) = rewrite_set_ thy false make_polynomial t; -if UnparseC.term t = - "(9 * a \ 2 + - 16 * b \ 2) /\n(36 * a \ 2 * c + 27 * a \ 2 * e + - 64 * b \ 2 * c +\n - 48 * b \ 2 * e)" -then () else error "rational.sml: S.K.8..corrected 060904-6"; - -"----- S.K. corrected non-termination of cancel_p_"; -val t'' = TermC.str2term ("(9 * a \ 2 + -16 * b \ 2) /" ^ - "(36 * a \ 2 * c + (27 * a \ 2 * e + (-64 * b \ 2 * c + -48 * b \ 2 * e)))"); -(* /--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------\ -val SOME (t',_) = rewrite_set_ thy false cancel_p t''; -if UnparseC.term t' = "1 / (4 * c + 3 * e)" -then () else error "rational.sml: diff.behav. in cancel_p S.K.8"; - \--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------/*) - -(*------- Schalk I, p.68 Nr. 437b*) -val t = TermC.str2term "(a + b)/(x \ 2 - y \ 2) * ((x - y) \ 2/(a \ 2 - b \ 2))"; -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -: -#### rls: cancel_p on: (a * x \ 2 + -2 * (a * (x * y)) + a * y \ 2 + b * x \ 2 + - -2 * (b * (x * y)) + - b * y \ 2) / -(a \ 2 * x \ 2 + -1 * (a \ 2 * y \ 2) + -1 * (b \ 2 * x \ 2) + - b \ 2 * y \ 2) -exception Div raised -*) - -(*------- SRM Schalk I, p.68 Nr. 438a *) -val t = TermC.str2term "x*y / (x*y - y \ 2) * (x \ 2 - x*y)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "x \ 2" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 24"; - -(*------- SRM Schalk I, p.68 Nr. 439b *) -val t = TermC.str2term "(4*x \ 2 + 4*x + 1) * ((x \ 2 - 2*x \ 3) / (4*x \ 2 + 2*x))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(x + - 4 * x \ 3) / 2" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 25"; - -(*------- SRM Schalk I, p.68 Nr. 440a *) -val t = TermC.str2term "(x \ 2 - 2*x) / (x \ 2 - 3*x) * (x - 3) \ 2 / (x \ 2 - 4)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(- 3 + x) / (2 + x)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 26"; - -"----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx"; -val t = TermC.str2term "(a \ 3 - 9*a) / (a \ 3*b - a*b \ 3) * (a \ 2*b + a*b \ 2) / (a+3)"; -(* WN130911 non-termination for unclear reasons: -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; - -... ENDS WITH THIS TRACE: -: -### rls: cancel_p on: (-9 * (a \ 3 * b) + -9 * (a \ 2 * b \ 2) + a \ 5 * b + - a \ 4 * b \ 2) / -(a \ 3 * b + -1 * (a * b \ 3)) / -(3 + a) -BUT THIS IS CORRECTLY RECOGNISED -val t = TermC.str2term - ("(-9 * (a \ 3 * b) + -9 * (a \ 2 * b \ 2) + a \ 5 * b + a \ 4 * b \ 2) /" ^ - "(a \ 3 * b + -1 * (a * b \ 3)) / (3 + (a::real))"); -AS -NONE = cancel_p_ thy t; - -if UnparseC.term t = "(-3 * a + a \ 2) / (a + -1 * b)" then () -else error "rational.sml: diff.behav. in norm_Rational 27"; -*) - -"----- SK12 works since 0707xx"; -val t = TermC.str2term "(a \ 3 - 9*a) * (a \ 2*b+a*b \ 2) / ((a \ 3*b - a*b \ 3) * (a+3))"; -(* WN130911 non-termination due to non-termination of - cancel_p_ thy (TermC.str2term "(4 + -4 * b \ 2) / (a \ 4 + -2 * (a \ 2 * b \ 2) + b \ 4)") - -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t' = "(-3 * a + a \ 2) / (a + -1 * b)" then () -else error "rational.sml: diff.behav. in norm_Rational 28"; -*) - -"-------- examples common denominator and multiplication from: Schalk --------"; -"-------- examples common denominator and multiplication from: Schalk --------"; -"-------- examples common denominator and multiplication from: Schalk --------"; -(*------- SRAM Schalk I, p.69 Nr. 441b *) -val t = TermC.str2term "(4*a/3 + 3*b \ 2/a \ 3 + b/(4*a))*(4*b/(3*a))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(36 * b \ 3 + 3 * a \ 2 * b \ 2 + 16 * a \ 4 * b) /\n(9 * a \ 4)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 28"; - -(*------- SRAM Schalk I, p.69 Nr. 442b *) -val t = TermC.str2term ("(15*a \ 2/x \ 3 - 5*b \ 4/x \ 2 + 25*c \ 2/x) * " ^ - "(x \ 3/(5*a*b \ 3*c \ 3)) + 1/c \ 3 * (b*x/a - 3*a/b \ 3)"); -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "5 * x \ 2 / (a * b \ 3 * c)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 29"; - -(*------- SRAM Schalk I, p.69 Nr. 443b *) -val t = TermC.str2term "(a/2 + b/3) * (b/3 - a/2)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(- 9 * a \ 2 + 4 * b \ 2) / 36" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 30"; - -(*------- SRAM Schalk I, p.69 Nr. 445b *) -val t = TermC.str2term "(a \ 2/9 + 2*a/(3*b) + 4/b \ 2)*(a/3 - 2/b) + 8/b \ 3"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "a \ 3 / 27" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 31"; - -(*------- SRAM Schalk I, p.69 Nr. 446b *) -val t = TermC.str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x \ 2 - 16*y \ 2)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = (*"30 * x \ 2 + -9 * x * y + -20 * y \ 2" ..isabisac15 | Isabelle2017..*) - "(- 30 * x \ 2 + 9 * x * y + 20 * y \ 2) / - 1" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 32"; - -(*------- SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*) -val t = TermC.str2term -"(2*x \ 2/(3*y)+x/y \ 2)*(4*x \ 4/(9*y \ 2)+x \ 2/y \ 4)*(2*x \ 2/(3*y) - x/y \ 2)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(- 81 * x \ 4 + 16 * x \ 8 * y \ 4) / (81 * y \ 8)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 33"; - -(*------- SRAM Schalk I, p.69 Nr. 450a *) -val t = TermC.str2term -"(4*x/(3*y)+2*y/(3*x)) \ 2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(52 * x \ 2 + 16 * y \ 2) / (9 * y \ 2)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 34"; - -(*------- SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*) -val t = TermC.str2term - ("(15*a \ 4/(a*x \ 3) - 5*a*((b \ 4 - 5*c \ 2*x) / x \ 2)) * " ^ - "(x \ 3/(5*a*b \ 3*c \ 3)) + a/c \ 3 * (x*(b/a) - 3*b*(a/b \ 4))"); -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "5 * x \ 2 / (b \ 3 * c)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 53"; - - -"-------- examples double fractions from: Mathematik 1 Schalk ----------------"; -"-------- examples double fractions from: Mathematik 1 Schalk ----------------"; -"-------- examples double fractions from: Mathematik 1 Schalk ----------------"; -"----- SRD Schalk I, p.69 Nr. 454b"; -val t = TermC.str2term "((2 - x)/(2*a)) / (2*a/(x - 2))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(- 4 + 4 * x + - 1 * x \ 2) / (4 * a \ 2)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 35"; - -"----- SRD Schalk I, p.69 Nr. 455a"; -val t = TermC.str2term "(a \ 2 + 1)/(a \ 2 - 1) / ((a+1)/(a - 1))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(1 + a \ 2) / (1 + 2 * a + a \ 2)" then () -else error "rational.sml: diff.behav. in norm_Rational_mg 36"; - -"----- Schalk I, p.69 Nr. 455b"; -val t = TermC.str2term "(x \ 2 - 4)/(y \ 2 - 9)/((2+x)/(3 - y))"; -(* WN130911 non-termination due to non-termination of - cancel_p_ thy (TermC.str2term ("(-12 + 4 * y + 3 * x \ 2 + -1 * (x \ 2 * y)) /" ^ - "(-18 + -9 * x + 2 * y \ 2 + x * y \ 2)")) - -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(2 + -1 * x) / (3 + y)" then () -else error "rational.sml: diff.behav. in norm_Rational_mg 37"; -*) - -"----- SK060904-1a non-termination of cancel_p_ ?: worked before 0707xx"; -val t = TermC.str2term "(x \ 2 - 4)*(3 - y) / ((y \ 2 - 9)*(2+x))"; -(* WN130911 non-termination due to non-termination of - cancel_p_ thy (TermC.str2term ("(-12 + 4 * y + 3 * x \ 2 + -1 * (x \ 2 * y)) /" ^ - "(-18 + -9 * x + 2 * y \ 2 + x * y \ 2)")) - -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(2 + -1 * x) / (3 + y)" then () -else error "rational.sml: diff.behav. in norm_Rational_mg 37b"; -*) - -"----- ?: worked before 0707xx"; -val t = TermC.str2term "(3 + -1 * y) / (-9 + y \ 2)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "- 1 / (3 + y)" -then () else error "rational.sml: -1 / (3 + y) norm_Rational"; - -"----- SRD Schalk I, p.69 Nr. 456b"; -val t = TermC.str2term "(b \ 3 - b \ 2) / (b \ 2+b) / (b \ 2 - 1)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "b / (1 + 2 * b + b \ 2)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 38"; - -"----- SRD Schalk I, p.69 Nr. 457b"; -val t = TermC.str2term "(16*a \ 2 - 9*b \ 2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a \ 2 - 9*a \ 2*b \ 2))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "8 * a \ 2 + - 6 * a * b + - 12 * a \ 2 * b + 9 * a * b \ 2" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 39"; - -"----- Schalk I, p.69 Nr. 458b works since 0707"; -val t = TermC.str2term "(2*a \ 2*x - a \ 2) / (a*x - b*x) / (b \ 2*(2*x - 1) / (x*(a - b)))"; -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -: -### rls: cancel_p on: (-1 * a \ 2 + 2 * (a \ 2 * x)) / (a * x + -1 * (b * x)) / -((-1 * b \ 2 + 2 * (b \ 2 * x)) / (a * x + -1 * (b * x))) -exception Div raised - -BUT -val t = TermC.str2term - ("(-1 * a \ 2 + 2 * (a \ 2 * x)) / (a * x + -1 * (b * x)) /" ^ - "((-1 * b \ 2 + 2 * (b \ 2 * x)) / (a * x + -1 * (b * x)))"); -NONE = cancel_p_ thy t; - -if UnparseC.term t = "a \ 2 / b \ 2" then () -else error "rational.sml: diff.behav. in norm_Rational_mg 39b"; -*) - -"----- SRD Schalk I, p.69 Nr. 459b"; -val t = TermC.str2term "(a \ 2 - b \ 2)/(a*b) / (4*(a+b) \ 2/a)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(a + - 1 * b) / (4 * a * b + 4 * b \ 2)" then () -else error "rational.sml: diff.behav. in norm_Rational_mg 41"; - -"----- Schalk I, p.69 Nr. 460b nonterm.SK"; -val t = TermC.str2term "(9*(x \ 2 - 8*x + 16) / (4*(y \ 2 - 2*y + 1))) / ((3*x - 12) / (16*y - 16))"; -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -exception Div raised - -BUT -val t = TermC.str2term - ("(144 + -72 * x + 9 * x \ 2) / (4 + -8 * y + 4 * y \ 2) /" ^ - "((-12 + 3 * x) / (-16 + 16 * y))"); -NONE = cancel_p_ thy t; - -if UnparseC.term t = !!!!!!!!!!!!!!!!!!!!!!!!! -then () else error "rational.sml: diff.behav. in norm_Rational_mg 42"; -*) - -"----- some variant of the above; was non-terminating before"; -val t = TermC.str2term "9*(x \ 2 - 8*x+16)*(16*y - 16)/(4*(y \ 2 - 2*y+1)*(3*x - 12))"; -val SOME (t , _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(48 + - 12 * x) / (1 + - 1 * y)" -then () else error "some variant of the above; was non-terminating before"; - -"----- SRD Schalk I, p.70 Nr. 472a"; -val t = TermC.str2term ("((8*x \ 2 - 32*y \ 2) / (2*x + 4*y)) / ((4*x - 8*y) / (x + y))"); -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "x + y" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 43"; - -"----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec"; -val t = TermC.str2term ("(a - (a*b + b \ 2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^ - "((a - a \ 2/(a+b))/(a+(a*b)/(a - b)))"); -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(2 * a \ 3 + 2 * a \ 2 * b) / (a \ 2 * b + b \ 3)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 51"; - -(*SRD Schalk I, p.69 Nr. 461a *) -val t = TermC.str2term "(2/(x+3) + 2/(x - 3)) / (8*x/(x \ 2 - 9))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "1 / 2" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 44"; - -(*SRD Schalk I, p.69 Nr. 464b *) -val t = TermC.str2term "(a - a/(a - 2)) / (a + a/(a - 2))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(- 3 + a) / (- 1 + a)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 45"; - -(*SRD Schalk I, p.69 Nr. 465b *) -val t = TermC.str2term "((x+3*y)/9 + (4*y \ 2 - 9*z \ 2)/(16*x)) / (x/9 + y/6 + z/4)"; -(* WN130911 non-termination due to non-termination of - cancel_p_ thy (TermC.str2term - ("("(576 * x \ 2 + 1728 * (x * y) + 1296 * y \ 2 + -2916 * z \ 2) /" ^ - "(576 * x \ 2 + 864 * (x * y) + 1296 * (x * z))")) - -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(4 * x + 6 * y + -9 * z) / (4 * x)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 46"; -*) - -(*SRD Schalk I, p.69 Nr. 466b *) -val t = TermC.str2term "((1 - 7*(x - 2)/(x \ 2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x \ 2 - 25))"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "(25 + - 10 * x + x \ 2) / 18" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 47"; - -(*SRD Schalk I, p.70 Nr. 469 *) -val t = TermC.str2term ("3*b \ 2 / (4*a \ 2 - 8*a*b + 4*b \ 2) / " ^ - "(a / (a \ 2*b - b \ 3) + (a - b) / (4*a*b \ 2 + 4*b \ 3) - 1 / (4*b \ 2))"); -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t = "- 3 * b \ 3 / (- 2 * a + 2 * b)" -then () else error "rational.sml: diff.behav. in norm_Rational_mg 48"; - -(*//----------------------------------TOODOO (*Rfuns revsets \ broken*) -"-------- me Schalk I No.186 -------------------------------------------------"; -"-------- me Schalk I No.186 -------------------------------------------------"; -"-------- me Schalk I No.186 -------------------------------------------------"; -val fmz = ["Term ((14 * x * y) / ( x * y ))", "normalform N"]; -val (dI',pI',mI') = - ("Rational",["rational", "simplification"], - ["simplification", "of_rationals"]); -val p = e_pos'; val c = []; -val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))]; -val (p,_,f,nxt,_,pt) = me nxt p c pt; -val (p,_,f,nxt,_,pt) = me nxt p c pt; -val (p,_,f,nxt,_,pt) = me nxt p c pt; -val (p,_,f,nxt,_,pt) = me nxt p c pt; -val (p,_,f,nxt,_,pt) = me nxt p c pt; -val (p,_,f,nxt,_,pt) = me nxt p c pt; -val (p,_,f,nxt,_,pt) = me nxt p c pt; -val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f; -val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f; -val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*) -val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*) -case (f2str f, nxt) of - ("14", ("End_Proof'", _)) => () - | _ => error "rational.sml diff.behav. in me Schalk I No.186"; - \\----------------------------------TOODOO (*Rfuns revsets \ broken*)*) - -(*//----------------------------------TOODOO (*Rfuns revsets \ broken*) -"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------"; -"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------"; -"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------"; -reset_states (); -CalcTree [(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"], - ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))]; -Iterator 1; -moveActiveRoot 1; -autoCalculate 1 CompleteCalc; -val ((pt, p), _) = get_calc 1; -(* -Test_Tool.show_pt pt; -[ -(([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))), -(([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))), -(([1], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))), -(([2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (-2 + x))), -(([3], Res), (2 + -1 * x) * (-2 + x) / (2 * a * (2 * a))), -(([4], Res), (-4 + 4 * x + -1 * x \ 2) / (4 * a \ 2)), -(([], Res), (-4 + 4 * x + -1 * x \ 2) / (4 * a \ 2))] -*) -interSteps 1 ([1], Res); -val ((pt, p), _) = get_calc 1; -(*Test_Tool.show_pt pt; -[ -(([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))), -(([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))), -(([1,1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))), -(([1,1], Res), (2 - x) / (2 * a) / (2 * a / (x + -1 * 2))), -(([1,2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))), -(([1], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))), -(([2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (-2 + x))), -(([3], Res), (2 + -1 * x) * (-2 + x) / (2 * a * (2 * a))), -(([4], Res), (-4 + 4 * x + -1 * x \ 2) / (4 * a \ 2)), -(([], Res), (-4 + 4 * x + -1 * x \ 2) / (4 * a \ 2))] -*) -val (t, asm) = get_obj g_result pt [1, 1]; -if UnparseC.term t = "(2 - x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso UnparseC.terms asm = "[]" -then () else error "2nd interSteps ..Simp_Rat_Double_No-1 changed on [1, 1]"; -val (t, asm) = get_obj g_result pt [1, 2]; -if UnparseC.term t = "(2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso UnparseC.terms asm = "[]" -then () else error "3rd interSteps ..Simp_Rat_Double_No-1 changed on [1, 2]"; - \\----------------------------------TOODOO (*Rfuns revsets \ broken*)*) - - -(*//----------------------------------TOODOO (*Rfuns revsets \ broken*) -"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------"; -"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------"; -"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------"; -reset_states (); -CalcTree [(["Term ((a^2 + -1*b^2) / (a^2 + -2*a*b + b^2))", "normalform N"], - ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))]; -Iterator 1; -moveActiveRoot 1; -autoCalculate 1 CompleteCalc; -val ((pt, p), _) = get_calc 1; -(*Test_Tool.show_pt pt; -[ -(([], Frm), Simplify ((a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2))), -(([1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2)), -(([1], Res), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), -(([2], Res), (a + b) / (a + -1 * b)), -(([], Res), (a + b) / (a + -1 * b))] -*) -interSteps 1 ([2], Res); -val ((pt, p), _) = get_calc 1; -(*Test_Tool.show_pt pt; -[ -(([], Frm), Simplify ((a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2))), -(([1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2)), -(([1], Res), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), -(([2,1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), -(([2,1], Res), (a + b) / (a + -1 * b)), -(([2], Res), (a + b) / (a + -1 * b)), -(([], Res), (a + b) / (a + -1 * b))] -*) -interSteps 1 ([2,1],Res); -val ((pt, p), _) = get_calc 1; -(*Test_Tool.show_pt pt; -[ -(([], Frm), Simplify ((a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2))), -(([1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * a * b + b \ 2)), -(([1], Res), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), -(([2,1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), -(([2,1,1], Frm), (a \ 2 + -1 * b \ 2) / (a \ 2 + -2 * (a * b) + b \ 2)), -(([2,1,1], Res), (a \ 2 + -1 * (a * b) + a * b + -1 * b \ 2) / -(a \ 2 + -2 * (a * b) + 1 * b \ 2)), -(([2,1,2], Res), (a \ 2 + -1 * (a * b) + a * b + -1 * b \ 2) / -(a \ 2 + -2 * (a * b) + -1 \ 2 * b \ 2)), -(([2,1,3], Res), (a \ 2 + -1 * (a * b) + a * b + -1 * b \ 2) / -(a \ 2 + -2 * (a * b) + (-1 * b) \ 2)), -(([2,1,4], Res), (a * a + -1 * (a * b) + a * b + -1 * b \ 2) / -(a \ 2 + -2 * (a * b) + (-1 * b) \ 2)), -(([2,1,5], Res), (a * a + -1 * (a * b) + a * b + -1 * (b * b)) / -(a \ 2 + -2 * (a * b) + (-1 * b) \ 2)), -(([2,1,6], Res), (a * a + -1 * (a * b) + a * b + -1 * (b * b)) / -(a \ 2 + -1 * (2 * (a * b)) + (-1 * b) \ 2)), -(([2,1,7], Res), (a * a + a * (-1 * b) + (b * a + b * (-1 * b))) / -(a \ 2 + 2 * (a * (-1 * b)) + (-1 * b) \ 2)), -(([2,1,8], Res), (a * a + a * (-1 * b) + (b * a + b * (-1 * b))) / -(a \ 2 + 2 * a * (-1 * b) + (-1 * b) \ 2)), -(([2,1,9], Res), (a * (a + -1 * b) + (b * a + b * (-1 * b))) / -(a \ 2 + 2 * a * (-1 * b) + (-1 * b) \ 2)), -(([2,1,10], Res), (a * (a + -1 * b) + b * (a + -1 * b)) / -(a \ 2 + 2 * a * (-1 * b) + (-1 * b) \ 2)), -(([2,1,11], Res), (a + b) * (a + -1 * b) / (a \ 2 + 2 * a * (-1 * b) + (-1 * b) \ 2)), -(([2,1,12], Res), (a + b) * (a + -1 * b) / ((a + -1 * b) * (a + -1 * b))), -(([2,1,13], Res), (a + b) / (a + -1 * b)), -(([2,1], Res), (a + b) / (a + -1 * b)), -(([2], Res), (a + b) / (a + -1 * b)), -(([], Res), (a + b) / (a + -1 * b))] -*) -val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*); -if length newnds = 13 then () else error "rational.sml: interSteps cancel_p rev_rew_p"; - -val p = ([2,1,9],Res); -getTactic 1 p; -val (_, tac, _) = ME_Misc.pt_extract (pt, p); -case tac of SOME (Rewrite ("sym_distrib_left", _)) => () -| _ => error "rational.sml: getTactic, sym_real_plus_binom_times1"; - \\----------------------------------TOODOO (*Rfuns revsets \ broken*)*) - - -"-------- investigate rulesets for cancel_p ----------------------------------"; -"-------- investigate rulesets for cancel_p ----------------------------------"; -"-------- investigate rulesets for cancel_p ----------------------------------"; -val thy = @{theory "Rational"}; -val t = TermC.str2term "(a \ 2 + -1*b \ 2) / (a \ 2 + -2*a*b + b \ 2)"; -val tt = TermC.str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"(*numerator only*); - -"----- with rewrite_set_"; -val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt; -if UnparseC.term tt'= "a \ 2 + - 1 * b \ 2" then () else error "rls chancel_p 1"; -val tt = TermC.str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*); -val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt; -if UnparseC.term tt' = "a \ 2 + - 2 * a * b + b \ 2" then () else error "rls chancel_p 2"; - -"----- with Derive.do_one; WN1130912 not investigated further, will be discontinued"; -val SOME (tt, _) = factout_p_ thy t; -if UnparseC.term tt = "(a + b) * (a + - 1 * b) / ((a + - 1 * b) * (a + - 1 * b))" -then () else error "rls chancel_p 3"; - -"--- with simpler ruleset"; -val {rules, rew_ord= (_, ro), ...} = Rule_Set.rep (assoc_rls "rev_rew_p"); -val der = Derive.do_one thy Atools_erls rules ro NONE tt; -if length der = 12 then () else error "WN1130912 rls chancel_p 4"; -(*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*) - -(*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*) -"...,(-1 * b \ 2 + a \ 2) / (-2 * (a * b) + a \ 2 + (-1 * b) \ 2) ]"; -(*default_print_depth 99;*) map (Rule.to_string o #2) der; (*default_print_depth 3;*) -(*default_print_depth 99;*) map (UnparseC.term o #1 o #3) der; (*default_print_depth 3;*) - -val der = Derive.do_one thy Atools_erls rules ro NONE - (TermC.str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"); -(*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*) - -val {rules, rew_ord=(_,ro),...} = Rule_Set.rep (assoc_rls "rev_rew_p"); -val der = Derive.do_one thy Atools_erls rules ro NONE - (TermC.str2term "(1 * a + -1 * b) * (1 * a + -1 * b)"); -(*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*) -(*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*) -(*WN060829 ...postponed*) - - -"-------- fun eval_get_denominator -------------------------------------------"; -"-------- fun eval_get_denominator -------------------------------------------"; -"-------- fun eval_get_denominator -------------------------------------------"; -val thy = @{theory Isac_Knowledge}; -val t = Thm.term_of (the (TermC.parse thy "get_denominator ((a +x)/b)")); -val SOME (_, t') = eval_get_denominator "" 0 t thy; -if UnparseC.term t' = "get_denominator ((a + x) / b) = b" -then () else error "get_denominator ((a + x) / b) = b" - - -"-------- several errpats in complicated term --------------------------------"; -"-------- several errpats in complicated term --------------------------------"; -"-------- several errpats in complicated term --------------------------------"; -(*WN12xxxx TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one - WN130912: kept this test, although not clear what for*) -reset_states (); -CalcTree [(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"], - ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))]; -Iterator 1; -moveActiveRoot 1; -autoCalculate 1 CompleteCalc; -val ((pt, p), _) = get_calc 1; -(*Test_Tool.show_pt pt; -[ -(([], Frm), Simplify ((5 * b + 25) / (a \ 2 - b \ 2) * (a - b) / (5 * b))), -(([1], Frm), (5 * b + 25) / (a \ 2 - b \ 2) * (a - b) / (5 * b)), -(([1], Res), (5 * b + 25) / (a \ 2 + -1 * b \ 2) * (a + -1 * b) / (5 * b)), -(([2], Res), (5 * b + 25) * (a + -1 * b) / (a \ 2 + -1 * b \ 2) / (5 * b)), -(([3], Res), (25 * a + -25 * b + 5 * (a * b) + -5 * b \ 2) / (a \ 2 + -1 * b \ 2) / -(5 * b)), -(([4], Res), (25 + 5 * b) / (a + b) / (5 * b)), -(([5], Res), (25 + 5 * b) / ((a + b) * (5 * b))), -(([6], Res), (25 + 5 * b) / (5 * (a * b) + 5 * b \ 2)), -(([7], Res), (5 + b) / (a * b + b \ 2)), -(([], Res), (5 + b) / (a * b + b \ 2))] *) - - -"-------- WN1309xx non-terminating rls norm_Rational -------------------------"; -"-------- WN1309xx non-terminating rls norm_Rational -------------------------"; -"-------- WN1309xx non-terminating rls norm_Rational -------------------------"; -(*------- Schalk I, p.70 Nr. 480b; a/b : c/d translated to a/b * d/c*) -val t = TermC.str2term - ("((12*x*y / (9*x \ 2 - y \ 2)) / (1 / (3*x - y) \ 2 - 1 / (3*x + y) \ 2)) * " ^ - "((1/(x - 5*y) \ 2 - 1/(x + 5*y) \ 2) / (20*x*y / (x \ 2 - 25*y \ 2)))"); - -(*1st factor separately simplified *) -val t = TermC.str2term "((12*x*y / (9*x \ 2 - y \ 2)) / (1 / (3*x - y) \ 2 - 1 / (3*x + y) \ 2))"; -val SOME (t', _) = rewrite_set_ thy false norm_Rational t; -if UnparseC.term t' = "(- 9 * x \ 2 + y \ 2) / - 1" then () else error "Nr. 480b lhs changed"; -(*2nd factor separately simplified *) -val t = TermC.str2term "((1/(x - 5*y) \ 2 - 1/(x + 5*y) \ 2) / (20*x*y / (x \ 2 - 25*y \ 2)))"; -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; -if UnparseC.term t' = "- 1 / (- 1 * x \ 2 + 25 * y \ 2)" then () else error "Nr. 480b rhs changed"; - -"-------- Schalk I, p.70 Nr. 477a: terms are exploding ?!?"; -val t = TermC.str2term ("b*y/(b - 2*y)/((b \ 2 - y \ 2)/(b+2*y)) /" ^ - "(b \ 2*y + b*y \ 2) * (a+x) \ 2 / ((b \ 2 - 4*y \ 2) * (a+2*x) \ 2)"); -(*val SOME (t',_) = rewrite_set_ thy false norm_Rational t; -: -### rls: cancel_p on: (a \ 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \ 2 * y)) / -(b + -2 * y) / -((b \ 2 + -1 * y \ 2) / (b + 2 * y)) / -(b \ 2 * y + b * y \ 2) / -(a \ 2 * b \ 2 + -4 * (a \ 2 * y \ 2) + 4 * (a * (b \ 2 * x)) + - -16 * (a * (x * y \ 2)) + - 4 * (b \ 2 * x \ 2) + - -16 * (x \ 2 * y \ 2)) -exception Div raised - -BUT -val t = TermC.str2term - ("(a \ 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \ 2 * y)) /" ^ - "(b + -2 * y) /" ^ - "((b \ 2 + -1 * y \ 2) / (b + 2 * y)) /" ^ - "(b \ 2 * y + b * y \ 2) /" ^ - "(a \ 2 * b \ 2 + -4 * (a \ 2 * y \ 2) + 4 * (a * (b \ 2 * x)) +" ^ - "-16 * (a * (x * y \ 2)) +" ^ - "4 * (b \ 2 * x \ 2) +" ^ - "-16 * (x \ 2 * y \ 2))"); -NONE = cancel_p_ thy t; -*) - -(*------- Schalk I, p.70 Nr. 476b in 2003 this worked using 10 sec. *) -val t = TermC.str2term - ("((a \ 2 - b \ 2)/(2*a*b) + 2*a*b/(a \ 2 - b \ 2)) / ((a \ 2 + b \ 2)/(2*a*b) + 1) / " ^ - "((a \ 2 + b \ 2) \ 2 / (a + b) \ 2)"); -(* Rewrite.trace_on := true; -rewrite_set_ thy false norm_Rational t; -: -#### rls: cancel_p on: (2 * (a \ 7 * b) + 4 * (a \ 6 * b \ 2) + 6 * (a \ 5 * b \ 3) + - 8 * (a \ 4 * b \ 4) + - 6 * (a \ 3 * b \ 5) + - 4 * (a \ 2 * b \ 6) + - 2 * (a * b \ 7)) / -(2 * (a \ 9 * b) + 4 * (a \ 8 * b \ 2) + - 2 * (2 * (a \ 7 * b \ 3)) + - 4 * (a \ 6 * b \ 4) + - -4 * (a \ 4 * b \ 6) + - -4 * (a \ 3 * b \ 7) + - -4 * (a \ 2 * b \ 8) + - -2 * (a * b \ 9)) - -if UnparseC.term t = "1 / (a \ 2 + -1 * b \ 2)" then () -else error "rational.sml: diff.behav. in norm_Rational_mg 49"; -*) - -"-------- Schalk I, p.70 Nr. 480a: terms are exploding ?!?"; -val t = TermC.str2term ("(1/x + 1/y + 1/z) / (1/x - 1/y - 1/z) / " ^ - "(2*x \ 2 / (x \ 2 - z \ 2) / (x / (x + z) + x / (x - z)))"); -(* Rewrite.trace_on := true; -rewrite_set_ thy false norm_Rational t; -: -#### rls: cancel_p on: (2 * (x \ 6 * (y \ 2 * z)) + 2 * (x \ 6 * (y * z \ 2)) + - 2 * (x \ 5 * (y \ 2 * z \ 2)) + - -2 * (x \ 4 * (y \ 2 * z \ 3)) + - -2 * (x \ 4 * (y * z \ 4)) + - -2 * (x \ 3 * (y \ 2 * z \ 4))) / -(-2 * (x \ 6 * (y \ 2 * z)) + -2 * (x \ 6 * (y * z \ 2)) + - 2 * (x \ 5 * (y \ 2 * z \ 2)) + - 2 * (x \ 4 * (y \ 2 * z \ 3)) + - 2 * (x \ 4 * (y * z \ 4)) + - -2 * (x \ 3 * (y \ 2 * z \ 4))) -*) - -"-------- Schalk I, p.60 Nr. 215d: terms are exploding, internal loop does not terminate"; -val t = TermC.str2term "(a-b) \ 3 * (x+y) \ 4 / ((x+y) \ 2 * (a-b) \ 5)"; -(* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt: - -val t = TermC.str2term "(a-b) \ 3 * (x+y) \ 4"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -UnparseC.term t; -"a \ 3 * x \ 4 + 4 * a \ 3 * x \ 3 * y +6 * a \ 3 * x \ 2 * y \ 2 +4 * a \ 3 * x * y \ 3 +a \ 3 * y \ 4 +-3 * a \ 2 * b * x \ 4 +-12 * a \ 2 * b * x \ 3 * y +-18 * a \ 2 * b * x \ 2 * y \ 2 +-12 * a \ 2 * b * x * y \ 3 +-3 * a \ 2 * b * y \ 4 +3 * a * b \ 2 * x \ 4 +12 * a * b \ 2 * x \ 3 * y +18 * a * b \ 2 * x \ 2 * y \ 2 +12 * a * b \ 2 * x * y \ 3 +3 * a * b \ 2 * y \ 4 +-1 * b \ 3 * x \ 4 +-4 * b \ 3 * x \ 3 * y +-6 * b \ 3 * x \ 2 * y \ 2 +-4 * b \ 3 * x * y \ 3 +-1 * b \ 3 * y \ 4"; -val t = TermC.str2term "((x+y) \ 2 * (a-b) \ 5)"; -val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -UnparseC.term t; -"a \ 5 * x \ 2 + 2 * a \ 5 * x * y + a \ 5 * y \ 2 +-5 * a \ 4 * b * x \ 2 +-10 * a \ 4 * b * x * y +-5 * a \ 4 * b * y \ 2 +10 * a \ 3 * b \ 2 * x \ 2 +20 * a \ 3 * b \ 2 * x * y +10 * a \ 3 * b \ 2 * y \ 2 +-10 * a \ 2 * b \ 3 * x \ 2 +-20 * a \ 2 * b \ 3 * x * y +-10 * a \ 2 * b \ 3 * y \ 2 +5 * a * b \ 4 * x \ 2 +10 * a * b \ 4 * x * y +5 * a * b \ 4 * y \ 2 +-1 * b \ 5 * x \ 2 +-2 * b \ 5 * x * y +-1 * b \ 5 * y \ 2"; - -anscheinend macht dem Rechner das Krzen diese Bruches keinen Spass mehr ...*) - -"-------- Schalk I, p.70 Nr. 480b: terms are exploding, Rewrite.trace_on stops at"; -val t = TermC.str2term ("((12*x*y/(9*x \ 2 - y \ 2))/" ^ - "(1/(3*x - y) \ 2 - 1/(3*x + y) \ 2)) *" ^ - "(1/(x - 5*y) \ 2 - 1/(x + 5*y) \ 2)/" ^ - "(20*x*y/(x \ 2 - 25*y \ 2))"); -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t; -: -#### rls: cancel_p on: (19440 * (x \ 8 * y \ 2) + -490320 * (x \ 6 * y \ 4) + - 108240 * (x \ 4 * y \ 6) + - -6000 * (x \ 2 * y \ 8)) / -(2160 * (x \ 8 * y \ 2) + -108240 * (x \ 6 * y \ 4) + - 1362000 * (x \ 4 * y \ 6) + - -150000 * (x \ 2 * y \ 8)) -*) -