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