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_ ------------------------------"; wneuper@59569: "Rfuns-------- and app_rev ...traced down from rewrite_set_ until prepats ---------"; wneuper@59569: "Rfuns-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------"; neuper@52104: "-------- rls norm_Rational downto fun gcd_poly ------------------------------"; wneuper@59569: "Rfuns-------- rls norm_Rational downto fun add_fraction_p_ -----------------------"; wneuper@59533: "----------- rewrite_set_ Partial_Fractions norm_Rational --------------------------------------"; wneuper@59531: "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; wneuper@59533: "----------- fun cancel_p with Const AA --------------------------------------------------------"; 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_ -----------"; wneuper@59569: "Rfuns-------- reverse rewrite ----------------------------------------------------"; wneuper@59569: "Rfuns-------- '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 ---------------------------------------------------"; wneuper@59533: val thy = @{theory Partial_Fractions}; wneuper@59533: val ctxt = Proof_Context.init_global @{theory} wneuper@59533: val vs = TermC.vars_of (the (parseNEW ctxt "12 * x^^^3 * y^^^4 * z^^^6")); neuper@52087: walther@60230: if poly_of_term vs (TermC.str2term "12::real") = SOME [(12, [0, 0, 0])] neuper@52087: then () else error "poly_of_term 1 changed"; walther@60230: if poly_of_term vs (TermC.str2term "x::real") = SOME [(1, [1, 0, 0])] neuper@52087: then () else error "poly_of_term 2 changed"; walther@60230: if poly_of_term vs (TermC.str2term "12 * x^^^3") = SOME [(12, [3, 0, 0])] neuper@52087: then () else error "poly_of_term 3 changed"; walther@60230: if poly_of_term vs (TermC.str2term "12 * x^^^3 * y^^^4 * z^^^6") = SOME [(12, [3, 4, 6])] neuper@52087: then () else error "poly_of_term 4 changed"; walther@60230: if poly_of_term vs (TermC.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*) walther@60230: if poly_of_term vs (TermC.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:*) walther@60230: if poly_of_term vs (TermC.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:*) walther@60230: if poly_of_term vs (TermC.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 --------------------------------------------------------"; walther@60230: if is_poly (TermC.str2term "2 * x^^^3 * y^^^4 * z^^^6 + 7 * y^^^8 + 1") neuper@52087: then () else error "is_poly 1 changed"; walther@60230: if not (is_poly (TermC.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 walther@60230: val Free (_, baseT) = (hd o vars o TermC.str2term) "12 * x^^^3 * y^^^4 * z^^^6"; neuper@52087: val p = [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 5])] wneuper@59533: val vs = TermC.vars_of (the (parseNEW ctxt "12 * x^^^3 * y^^^4 * z^^^6")) neuper@52087: (*precondition for [(c, es),...]: legth es = length vs*) neuper@52087: ; walther@59868: if UnparseC.term (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_ -----------------------------------"; walther@60230: val t = TermC.str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)" neuper@52092: val SOME (t', asm) = factout_p_ thy t; walther@59868: if UnparseC.term t' = "(x + y) * (x + -1 * y) / (x * (x + -1 * y))" walther@59868: then () else error ("factout_p_ term 1 changed: " ^ UnparseC.term t') neuper@52092: ; walther@59868: if UnparseC.terms asm = "[\"x \ 0\",\"x + -1 * y \ 0\"]" neuper@52092: then () else error "factout_p_ asm 1 changed" neuper@52092: ; walther@60230: val t = TermC.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: ; walther@60230: val t = TermC.str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))"; neuper@52093: val SOME (t', asm) = factout_p_ thy t; walther@59868: if UnparseC.term t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso walther@59868: UnparseC.terms 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_ ------------------------------------"; walther@60230: val t = TermC.str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)" neuper@52093: val SOME (t', asm) = cancel_p_ thy t; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = ("(x + y) / x", "[\"x \ 0\"]") walther@59868: then () else error ("cancel_p_ (t', asm) 1 changed: " ^ UnparseC.term t') neuper@52093: ; walther@60230: val t = TermC.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: ; walther@60230: val t = TermC.str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))"; neuper@52093: val SOME (t', asm) = cancel_p_ thy t; walther@59868: if UnparseC.term t' = "(3 + 3 * x) / 2" andalso UnparseC.terms 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_ --------------------------"; walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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"; walther@59868: if UnparseC.terms 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"; walther@60230: val t = TermC.str2term "x/(x^^^2 + -1*y^^^2) + y/(x^^^2 + -1*x*y)"; neuper@52092: val SOME (t', asm) = common_nominator_p_ thy t; walther@59868: if UnparseC.term 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: ; walther@59868: if UnparseC.terms 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"; walther@60230: val t = TermC.str2term "nothing / to_add"; neuper@52092: if NONE = common_nominator_p_ thy t then () else error "common_nominator_p_ term 3 changed"; neuper@52093: ; walther@60230: val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))"; neuper@52093: val SOME (t', asm) = common_nominator_p_ thy t; walther@59868: if UnparseC.term t' = neuper@52101: "(x + -1) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(x + 1) * (1 + x) / ((1 + x) * (-1 + x))" walther@59868: andalso UnparseC.terms 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_ ------------------------------"; walther@60230: val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))"; neuper@52092: val SOME (t', asm) = add_fraction_p_ thy t; walther@59868: if UnparseC.term t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" neuper@52092: then () else error "add_fraction_p_ 3 changed"; neuper@52093: ; walther@59868: if UnparseC.terms asm = "[\"-1 + x ^^^ 2 \ 0\"]" neuper@52092: then () else error "add_fraction_p_ 3 changed"; neuper@52093: ; walther@60230: val t = TermC.str2term "nothing / to_add"; neuper@52093: if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ term 3 changed"; neuper@52093: ; walther@60230: val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))"; neuper@52093: val SOME (t', asm) = add_fraction_p_ thy t; walther@59868: if UnparseC.term t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso walther@59868: UnparseC.terms 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 <>[]. *) walther@60230: val t = TermC.str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)"; neuper@52085: wneuper@59592: (*rewrite_set_ @{theory Isac_Knowledge} 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 walther@59868: then ((*tracing("### app_rev': t = "^UnparseC.term 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; walther@59868: UnparseC.term t1 = "?r is_expanded"; walther@59868: UnparseC.term t2 = "?s is_expanded"; walther@59868: UnparseC.term 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); walther@59868: UnparseC.terms 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; walther@59868: UnparseC.term 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 ----------------------"; walther@60230: val t = TermC.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;*) walther@60230: val t = TermC.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;*) walther@60230: val t = TermC.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;*) wneuper@59592: "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (@{theory Isac_Knowledge}, 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 walther@60230: val vs = TermC.vars_of t 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 ------------------------------"; walther@60230: val t = TermC.str2term "(x^^^2 - 4)*(3 - y) / ((y^^^2 - 9)*(2+x))"; walther@59901: Rewrite.trace_on := 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: *) walther@60230: val t = TermC.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 walther@60230: val vs = TermC.vars_of t neuper@52104: val baseT = type_of numerator neuper@52104: val expT = HOLogic.realT; wneuper@59348: (*default_print_depth 3; 999*) neuper@52104: val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator); wneuper@59348: (*default_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_ -----------------------"; wneuper@59592: val thy = @{theory Isac_Knowledge}; neuper@52105: "----- SK060904-2a non-termination of add_fraction_p_"; walther@60230: val t = TermC.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) = wneuper@59592: (@{theory Isac_Knowledge}, 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 walther@59868: then ((*tracing("### app_rev': t = "^UnparseC.term 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; walther@59868: UnparseC.term n1; UnparseC.term d1; UnparseC.term n2; UnparseC.term d2; walther@60230: val vs = TermC.vars_of t; wneuper@59348: (*default_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); wneuper@59348: (*default_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: wneuper@59531: "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; wneuper@59531: "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; wneuper@59531: "----------- fun check_frac_sum with Free A and Const AA ---------------------------------------"; wneuper@59592: val thy = @{theory Isac_Knowledge(*Partial_Fractions*)} wneuper@59531: val ctxt = Proof_Context.init_global thy; wneuper@59531: wneuper@59531: (*---------- (1) with Free A, B ----------------------------------------------------------------*) wneuper@59531: val t = (the o (parseNEW ctxt)) "3 = A / 2 + A / 4 + (B / 2 + -1 * B / (2::real))"; wneuper@59531: (* required for applying thms in rewriting ^^^^*) wneuper@59531: (* we get details from here..*) wneuper@59531: walther@59901: Rewrite.trace_on := false; wneuper@59531: val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t; walther@59918: Rewrite.trace_on := false; walther@59901: (* Rewrite.trace_on: wneuper@59531: add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) wneuper@59531: (* |||||||||||||||||||||||||||||||||||| *) wneuper@59531: wneuper@59531: val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 1 GUESS 1 GUESS 1 GUESS 1 *) wneuper@59531: "A / 2 + A / 4 + (B / 2 + -1 * B / (2::real))"; wneuper@59531: "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); wneuper@59531: val NONE = (*case*) check_frac_sum t (*of*) wneuper@59531: walther@59901: (* Rewrite.trace_on: wneuper@59531: add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) wneuper@59531: (* |||||||||||||||||||||||||||| *) wneuper@59531: val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 2 GUESS 2 GUESS 2 GUESS 2 *) wneuper@59531: "A / 4 + (B / 2 + -1 * B / (2::real))"; wneuper@59531: "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); wneuper@59531: val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*); walther@59868: (*+*)if (UnparseC.term n1, UnparseC.term d1) = ("A" , "4") andalso walther@59868: (*+*) (UnparseC.term n2, UnparseC.term d2) = ("B / 2 + -1 * B / 2", "1") wneuper@59531: (*+*)then () else error "check_frac_sum (A / 4 + (B / 2 + -1 * B / (2::real))) changed"; wneuper@59531: walther@60230: val vs = TermC.vars_of t; wneuper@59531: val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) = wneuper@59531: (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*); wneuper@59531: wneuper@59531: "~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1); wneuper@59531: val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t]; wneuper@59531: (*+*)if xxx = 1 then () else error "monom_of_term changed" wneuper@59531: wneuper@59531: "~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Free (id, _))) = wneuper@59531: (vs, (1, replicate (length vs) 0), t); wneuper@59533: case vs of [Free ("A", _), Free ("B", _)] => wneuper@59533: if c = 1 andalso id = "A" wneuper@59533: then () else error "monom_of_term Free changed 1" wneuper@59533: | _ => error "monom_of_term Free changed 2"; wneuper@59531: wneuper@59531: (*---------- (2) with Const AA, BB --------------------------------------------------------------*) wneuper@59531: val t = (the o (parseNEW ctxt)) "3 = AA / 2 + AA / 4 + (BB / 2 + -1 * BB / 2)"; wneuper@59531: (*AA :: real*) wneuper@59531: (* we get details from here..*) wneuper@59531: walther@59918: Rewrite.trace_on := false; wneuper@59531: val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t; walther@59918: Rewrite.trace_on := false; walther@59901: (* Rewrite.trace_on: wneuper@59531: add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) wneuper@59531: (* |||||||||||||||||||||||||||||||||||| *) wneuper@59531: val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *) wneuper@59531: "AA / 2 + AA / 4 + (BB / 2 + -1 * BB / 2)"; wneuper@59531: "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); wneuper@59531: val NONE = (*case*) check_frac_sum t (*of*) wneuper@59531: walther@59901: (* Rewrite.trace_on: wneuper@59531: add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *) wneuper@59531: (* |||||||||||||||||||||||||||| *) wneuper@59531: val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *) wneuper@59531: "AA / 4 + (BB / 2 + -1 * BB / 2)"; wneuper@59531: "~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t); wneuper@59531: val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*); walther@59868: (*+*)if (UnparseC.term n1, UnparseC.term d1) = ("AA" , "4") andalso walther@59868: (*+*) (UnparseC.term n2, UnparseC.term d2) = ("BB / 2 + -1 * BB / 2", "1") wneuper@59531: (*+*)then () else error "check_frac_sum (AA / 4 + (BB / 2 + -1 * BB / 2)) changed"; wneuper@59531: walther@60230: val vs = TermC.vars_of t; wneuper@59531: val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) = wneuper@59531: (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*); wneuper@59531: wneuper@59531: "~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1); wneuper@59531: val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t]; wneuper@59531: (*+*)if xxx = 1 then () else error "monom_of_term changed" wneuper@59531: wneuper@59531: "~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const (id, _))) = wneuper@59531: (vs, (1, replicate (length vs) 0), t); wneuper@59533: case vs of [Const ("Partial_Fractions.AA", _), Const ("Partial_Fractions.BB", _)] => wneuper@59533: if c = 1 andalso id = "Partial_Fractions.AA" wneuper@59533: then () else error "monom_of_term Const changed 1" wneuper@59533: | _ => error "monom_of_term Const changed 2"; wneuper@59533: wneuper@59533: "----------- fun cancel_p with Const AA --------------------------------------------------------"; wneuper@59533: "----------- fun cancel_p with Const AA --------------------------------------------------------"; wneuper@59533: "----------- fun cancel_p with Const AA --------------------------------------------------------"; wneuper@59533: val thy = @{theory Partial_Fractions}; wneuper@59533: val ctxt = Proof_Context.init_global @{theory} wneuper@59533: val SOME t = TermC.parseNEW ctxt "2 * AA / 2"; (* Const ("Free ("AA", "real") *) wneuper@59533: wneuper@59533: val SOME (t', _) = rewrite_set_ thy true cancel_p t; wneuper@59533: case t' of wneuper@59533: Const ("Rings.divide_class.divide", _) $ Const ("Partial_Fractions.AA", _) $ Free ("1", _) => () wneuper@59533: | _ => error "WRONG rewrite_set_ cancel_p (2 * AA / 2) \ AA changed"; wneuper@59533: wneuper@59533: "~~~~~ fun cancel_p , args:"; val (t) = (t); wneuper@59533: val opt = check_fraction t wneuper@59533: val SOME (numerator, denominator) = (*case*) opt (*of*); wneuper@59533: walther@59868: if UnparseC.term numerator = "2 * AA" andalso UnparseC.term denominator = "2" wneuper@59533: then () else error "check_fraction (2 * AA / 2) changed"; wneuper@59533: val vs = TermC.vars_of t; wneuper@59533: case vs of wneuper@59533: [Const ("Partial_Fractions.AA", _)] => () wneuper@59533: | _ => error "rewrite_set_ cancel_p (2 * AA / 2) \ AA/1 changed"; wneuper@59531: wneuper@59531: 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"; walther@60230: val t = TermC.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"; walther@60230: val t = TermC.str2term "(14 * x * y) / (x * y)"; walther@60230: is_expanded (TermC.str2term "14 * x * y"); walther@60230: is_expanded (TermC.str2term "x * y"); neuper@52095: val SOME (t', asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = ("14 / 1", "[]") neuper@52092: then () else error "rational.sml cancel Schalk 186a"; neuper@52092: neuper@52092: "-------- example 186b"; walther@60230: val t = TermC.str2term "(60 * a * b) / ( 15 * a * b )"; neuper@52095: val SOME (t', asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = ("4 / 1", "[]") neuper@52092: then () else error "rational.sml cancel Schalk 186b"; neuper@52092: neuper@52092: "-------- example 186c"; walther@60230: val t = TermC.str2term "(144 * a^^^2 * b * c) / (12 * a * b * c)"; neuper@52095: val SOME (t', asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.str2term "(12 * x * y) / (8 * y^^^2 )"; neuper@52095: val SOME (t', asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.str2term "(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )"; neuper@52095: val SOME (t', asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.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; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.str2term "(-8 + 8 * x) / (-9 + 9 * x)"; walther@60230: is_expanded (TermC.str2term "8 * x + -8"); neuper@52095: val SOME (t', asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]") neuper@52092: then () else error "rational.sml cancel Schalk 188a"; neuper@52092: walther@60230: val t = TermC.str2term "(8*((-1) + x))/(9*((-1) + x))"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false make_polynomial t; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]") neuper@52092: then () else error "rational.sml cancel Schalk make_polynomial 1"; neuper@52092: neuper@52092: "-------- example 188b"; walther@60230: val t = TermC.str2term "(-15 + 5 * x) / (-18 + 6 * x)"; neuper@52095: val SOME (t', asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = ("5 / 6", "[]") neuper@52092: then () else error "rational.sml cancel Schalk 188b"; neuper@52092: neuper@52092: "-------- example 188c"; walther@60230: val t = TermC.str2term "(a + -1 * b) / (b + -1 * a)"; neuper@52095: val SOME (t', asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = ("-1 / 1", "[]") neuper@52092: then () else error "rational.sml cancel Schalk 188c"; neuper@52092: walther@60230: is_expanded (TermC.str2term "a + -1 * b") = true; walther@60230: val t = TermC.str2term "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))"; neuper@52092: val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.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; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = wneuper@59369: ("(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"; walther@60230: val t = TermC.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; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.str2term "( x^^^2 + -1 * y^^^2 ) / ( x + y )"; walther@60230: is_expanded (TermC.str2term "x^^^2 + -1 * y^^^2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*) walther@60230: is_expanded (TermC.str2term "x + y") = true; neuper@52095: val SOME (t', asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = ("(x + -1 * y) / 1", "[]") neuper@52095: then () else error "rational.sml make_polynomial Schalk 191a"; neuper@52092: neuper@52092: "-------- example 191b"; walther@60230: val t = TermC.str2term "((x + (-1) * y)*(x + y))/((1)*(x + y))"; neuper@52092: val SOME (t', asm) = rewrite_set_ thy false make_polynomial t; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.str2term "( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )"; walther@60230: is_expanded (TermC.str2term "9 * x^^^2 + -30 * x + 25") = true; walther@60230: is_expanded (TermC.str2term "25 + -30*x + 9*x^^^2") = true; walther@60230: is_expanded (TermC.str2term "-25 + 9*x^^^2") = true; neuper@52092: walther@60230: val t = TermC.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; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.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; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = ("x ^^^ 2 / y ^^^ 2", "[\"y ^^^ 2 \ 0\"]") neuper@52095: then () else error "rational.sml cancel_p Schalk 192b"; neuper@52092: walther@60230: val t = TermC.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; walther@59868: if (UnparseC.term t', UnparseC.terms 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: walther@60230: val t = TermC.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; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.str2term "( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )"; neuper@52095: val SOME (t', asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.str2term "( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )"; neuper@52095: val SOME (t', asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.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; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = wneuper@59369: ("(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:*) walther@60230: val t = TermC.str2term "(-25 + 9*x^^^2)/(5 + 3*x)"; neuper@52095: val SOME (t, asm) = rewrite_set_ thy false cancel_p t; walther@59868: if (UnparseC.term t', UnparseC.terms 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"; walther@60230: val t = TermC.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; walther@59868: if (UnparseC.term t', UnparseC.terms asm) = wneuper@59369: ("(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_ -----------"; walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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; walther@59868: if UnparseC.term 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; walther@59868: if UnparseC.term 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*) walther@59868: if UnparseC.term 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 *) walther@59852: val testrls = Rule_Set.append_rules "testrls" Rule_Set.empty [Rls_ cancel_p, Rls_ add_fractions_p] neuper@52100: val SOME (t', asm) = rewrite_set_ thy false testrls t; walther@59901: (*Rewrite.trace_on := 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) *) walther@59868: if UnparseC.term 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 *) walther@59852: val testrls_rls = Rule_Set.append_rules "testrls_rls" Rule_Set.empty [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) *) walther@59868: if UnparseC.term 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; walther@59868: if UnparseC.term 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 **) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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) = walther@59876: (@{thm realpow_twoI} |> Thm.get_name_hint |> ThmC.cut_id) neuper@52101: then () else error "first element of revset changed"; neuper@52101: if walther@59867: (revsets |> nth 1 |> nth 1 |> Rule.to_string) = "Thm (\"realpow_twoI\",?r1 ^^^ 2 = ?r1 * ?r1)" andalso walther@59867: (revsets |> nth 1 |> nth 2 |> Rule.to_string) = "Thm (\"#: 9 = 3 ^^^ 2\",9 = 3 ^^^ 2)" andalso walther@59867: (revsets |> nth 1 |> nth 3 |> Rule.to_string) = "Thm (\"#: 6 * x = 2 * (3 * x)\",6 * x = 2 * (3 * x))" neuper@55485: andalso walther@59867: (revsets |> nth 1 |> nth 4 |> Rule.to_string) = "Thm (\"#: -3 * x = -1 * (3 * x)\",-3 * x = -1 * (3 * x))" neuper@55485: andalso walther@59867: (revsets |> nth 1 |> nth 5 |> Rule.to_string) = "Thm (\"#: 9 = 3 * 3\",9 = 3 * 3)" andalso walther@59867: (revsets |> nth 1 |> nth 6 |> Rule.to_string) = "Rls_ (\"sym_order_mult_rls_\")" andalso walther@59867: (revsets |> nth 1 |> nth 7 |> Rule.to_string) = walther@59877: "Thm (\"sym_mult.assoc\",?a * (?b * ?c) = ?a * ?b * ?c)" 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), walther@59997: 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), walther@59997: 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), walther@59997: Thm ("sym_mult.assoc", ""), ((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), []))", " walther@59997: ((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))" walther@59875: andalso ThmC.string_of_thm thm = walther@59874: (string_of_thm (Thm.make_thm @{theory "Isac_Knowledge"} walther@60230: (Trueprop $ (Thm.term_of o the o (TermC.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; walther@59868: if UnparseC.term 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 walther@59875: ThmC.string_of_thm thm = (string_of_thm (ThmC_Def.make_thm @{theory "Isac_Knowledge"} walther@60230: (Trueprop $ (Thm.term_of o the o (TermC.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; walther@59868: if UnparseC.term 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; walther@59868: if UnparseC.term 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; walther@59868: if UnparseC.term 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; walther@59868: if UnparseC.term 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; walther@59868: val ss = UnparseC.term t; walther@59868: if ss = "(3 - x) / (3 + x)" andalso UnparseC.terms 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*) walther@60230: val t = TermC.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; walther@59868: UnparseC.term 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; walther@59868: UnparseC.term t' = "(3 + x) / (3 + -1 * x)" (*true*); walther@59868: UnparseC.terms 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 wneuper@59111: default_print_depth 99; Rfuns; default_print_depth 3; walther@59877: 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; walther@59868: UnparseC.term t; neuper@37906: neuper@37926: val SOME r = nex revsets t; neuper@37906: val (r,(t,asm))::_ = loc revsets t r; walther@59868: UnparseC.term t; neuper@52101: *) neuper@37906: neuper@52101: "-------- examples: rls norm_Rational ----------------------------------------"; neuper@52101: "-------- examples: rls norm_Rational ----------------------------------------"; neuper@52101: "-------- examples: rls norm_Rational ----------------------------------------"; walther@60230: val t = TermC.str2term "(3*x+5)/18 - x/2 - -(3*x - 2)/9 = 0"; walther@59868: val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; walther@59868: if UnparseC.term t' = "1 / 18 = 0" then () else error "rational.sml 1"; neuper@37906: walther@60230: val t = TermC.str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0"; walther@59868: val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; walther@59868: if UnparseC.term t' = "(237 + 65 * x) / 36 = 0" then () neuper@38031: else error "rational.sml 2"; neuper@37906: walther@60230: val t = TermC.str2term "(1/2 + (5*x)/2)^^^2 - ((13*x)/2 - 5/2)^^^2 - (6*x)^^^2 + 29"; walther@59868: val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; walther@59868: if UnparseC.term t' = "23 + 35 * x + -72 * x ^^^ 2" then () neuper@38031: else error "rational.sml 3"; neuper@38046: walther@59901: (*Rewrite.trace_on:=true;*) walther@60230: val t = TermC.str2term "Not (6*x is_atom)"; walther@59868: val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t'; neuper@41928: "HOL.True"; walther@60230: val t = TermC.str2term "1 < 2"; walther@59868: val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t'; neuper@41928: "HOL.True"; neuper@38046: walther@60230: val t = TermC.str2term "(6*x)^^^2"; neuper@37926: val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false walther@59871: (ThmC.numerals_to_Free @{thm realpow_def_atom}) t; walther@59868: if UnparseC.term t' = "6 * x * (6 * x) ^^^ (2 + -1)" then () neuper@38046: else error "rational.sml powers_erls (6*x)^^^2"; neuper@37906: walther@60230: val t = TermC.str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))"; walther@59868: val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; walther@59868: if UnparseC.term t' = "65 * x / 2" then () else error "rational.sml 4"; neuper@37906: walther@60230: val t = TermC.str2term "1 - ((13*x)/2 - 5/2)^^^2"; walther@59868: val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; walther@59868: if UnparseC.term 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*) walther@60230: val t = TermC.str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54"; walther@59868: val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; walther@59868: if UnparseC.term t' = "(-255 + 112 * x) / 135" then () neuper@38031: else error "rational.sml 6"; neuper@37906: neuper@37906: (*SRAM Schalk I, p.92 Nr. 610c*) walther@60230: val t = TermC.str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2"; walther@59868: val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; walther@59868: if UnparseC.term t' = "(3 + x) / -2" then () else error "rational.sml 7"; neuper@37906: neuper@37906: (*SRAM Schalk I, p.92 Nr. 476a*) walther@60230: val t = TermC.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 .*) walther@59868: val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; walther@59868: if UnparseC.term t' = "1" then () else error "rational.sml 8"; neuper@37906: neuper@37906: (*Schalk I, p.92 Nr. 472a*) walther@60230: val t = TermC.str2term "((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))"; walther@59868: val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; walther@59868: if UnparseC.term 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 walther@60230: val t = TermC.str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a ^^^ 2 + -1 * b ^^^ 2)"; neuper@52105: val NONE = rewrite_set_ thy false add_fractions_p t; neuper@37906: neuper@52105: THE ERROR ALREADY OCCURS IN THIS PART: walther@60230: val t = TermC.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 *) walther@60230: val t = TermC.str2term "(47/6 - 76/9 + 13/4)/(35/12)"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: UnparseC.term t; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: UnparseC.term t; walther@59868: if UnparseC.term 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.*) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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.*) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.str2term "(a - b)/(b - a)"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: UnparseC.term t; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.str2term "(a + b)^^^4 * (x - y) / ((x - y)^^^3 * (a + b)^^^2)"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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.*) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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.*) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.str2term "(a - b) / (b - a)"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.str2term "(a + b)^^^4 * (x - y) / ((x - y)^^^3 * (a + b)^^^2)"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.str2term "(4*x^^^2 - 20*x + 25) / (2*x - 5)^^^3"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.str2term "(5*a^^^2 - 5*a*b) / (a - b)^^^2"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.str2term "(a^^^2 - 1)*(b + 1) / ((b^^^2 - 1)*(a+1))"; neuper@52105: (* WN130911 "exception Div raised" by walther@60230: cancel_p_ thy (TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.str2term "4/x - 3/y - 1"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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: walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.str2term "1/(x+1) + 1/(x+2) - 2/(x+3)"; neuper@52105: (* WN130911 non-termination due to non-termination of walther@60230: cancel_p_ thy (TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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 walther@60230: cancel_p_ thy (TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term t = (*"0" ..isabisac15 | Isabelle2017..*) "0 / (a ^^^ 2 + -1 * b ^^^ 2)" neuper@52105: then () else error "rational.sml: diff.behav. in norm_Rational_mg 20"; neuper@37906: neuper@52105: (* some example *) walther@60230: val t = TermC.str2term "3*a / (a*b) + x/y"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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 walther@60230: val t = TermC.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: walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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_"; walther@60230: val t'' = TermC.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)))"); wneuper@59369: (* /--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------\ neuper@37926: val SOME (t',_) = rewrite_set_ thy false cancel_p t''; walther@59868: if UnparseC.term t' = "1 / (4 * c + 3 * e)" neuper@52105: then () else error "rational.sml: diff.behav. in cancel_p S.K.8"; wneuper@59369: \--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------/*) neuper@37906: neuper@52105: (*------- Schalk I, p.68 Nr. 437b*) walther@60230: val t = TermC.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 *) walther@60230: val t = TermC.str2term "x*y / (x*y - y^^^2) * (x^^^2 - x*y)"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.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 walther@60230: val t = TermC.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: walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.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 walther@60230: cancel_p_ thy (TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.str2term "(a/2 + b/3) * (b/3 - a/2)"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term t = (*"30 * x ^^^ 2 + -9 * x * y + -20 * y ^^^ 2" ..isabisac15 | Isabelle2017..*) wneuper@59369: "(-30 * x ^^^ 2 + 9 * x * y + 20 * y ^^^ 2) / -1" 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*) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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*) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.str2term "((2 - x)/(2*a)) / (2*a/(x - 2))"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.str2term "(a^^^2 + 1)/(a^^^2 - 1) / ((a+1)/(a - 1))"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.str2term "(x^^^2 - 4)/(y^^^2 - 9)/((2+x)/(3 - y))"; neuper@52105: (* WN130911 non-termination due to non-termination of walther@60230: cancel_p_ thy (TermC.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; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.str2term "(x^^^2 - 4)*(3 - y) / ((y^^^2 - 9)*(2+x))"; neuper@52105: (* WN130911 non-termination due to non-termination of walther@60230: cancel_p_ thy (TermC.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; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.str2term "(3 + -1 * y) / (-9 + y ^^^ 2)"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.str2term "(b^^^3 - b^^^2) / (b^^^2+b) / (b^^^2 - 1)"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.str2term "(16*a^^^2 - 9*b^^^2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a^^^2 - 9*a^^^2*b^^^2))"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.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 walther@60230: val t = TermC.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: walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.str2term "(a^^^2 - b^^^2)/(a*b) / (4*(a+b)^^^2/a)"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.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 walther@60230: val t = TermC.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: walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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"; walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.str2term "(2/(x+3) + 2/(x - 3)) / (8*x/(x^^^2 - 9))"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.str2term "(a - a/(a - 2)) / (a + a/(a - 2))"; neuper@52105: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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 walther@60230: cancel_p_ thy (TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term 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') = walther@59997: ("Rational",["rational", "simplification"], walther@59997: ["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 ------------------------------"; s1210629013@55445: reset_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; wneuper@59248: autoCalculate 1 CompleteCalc; neuper@52105: val ((pt, p), _) = get_calc 1; neuper@52105: (* walther@59983: Test_Tool.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; walther@59983: (*Test_Tool.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]; walther@59868: if UnparseC.term t = "(2 - x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso UnparseC.terms 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]; walther@59868: if UnparseC.term t = "(2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso UnparseC.terms 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 ------------------------------"; s1210629013@55445: reset_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; wneuper@59248: autoCalculate 1 CompleteCalc; neuper@52105: val ((pt, p), _) = get_calc 1; walther@59983: (*Test_Tool.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; walther@59983: (*Test_Tool.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; walther@59983: (*Test_Tool.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; walther@59983: val (_, tac, _) = ME_Misc.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"}; walther@60230: val t = TermC.str2term "(a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)"; walther@60230: val tt = TermC.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; walther@59868: if UnparseC.term tt'= "a ^^^ 2 + -1 * b ^^^ 2" then () else error "rls chancel_p 1"; walther@60230: val tt = TermC.str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*); neuper@37926: val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt; walther@59868: if UnparseC.term tt' = "a ^^^ 2 + -2 * a * b + b ^^^ 2" then () else error "rls chancel_p 2"; neuper@37906: walther@59906: "----- with .make_deriv; WN1130912 not investigated further, will be discontinued"; neuper@52105: val SOME (tt, _) = factout_p_ thy t; walther@59868: if UnparseC.term tt = "(a + b) * (a + -1 * b) / ((a + -1 * b) * (a + -1 * b))" neuper@52105: then () else error "rls chancel_p 3"; walther@59868: UnparseC.term tt = "(1 * a + 1 * b) * (1 * a + -1 * b) / ((1 * a + -1 * b) * (1 * a + -1 * b))"; neuper@52105: neuper@52105: "--- with simpler ruleset"; walther@59852: val {rules, rew_ord= (_, ro), ...} = Rule_Set.rep (assoc_rls "rev_rew_p"); walther@59906: 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"; wneuper@59348: (*default_print_depth 99;*) writeln (deriv2str der); (*default_print_depth 3;*) neuper@37906: walther@59868: (*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*) neuper@37906: "...,(-1 * b ^^^ 2 + a ^^^ 2) / (-2 * (a * b) + a ^^^ 2 + (-1 * b) ^^^ 2) ]"; walther@59867: (*default_print_depth 99;*) map (Rule.to_string o #2) der; (*default_print_depth 3;*) walther@59868: (*default_print_depth 99;*) map (UnparseC.term o #1 o #3) der; (*default_print_depth 3;*) neuper@37906: walther@59906: val der = .make_deriv thy Atools_erls rules ro NONE walther@60230: (TermC.str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"); wneuper@59348: (*default_print_depth 99;*) writeln (deriv2str der); (*default_print_depth 3;*) neuper@37906: walther@59852: val {rules, rew_ord=(_,ro),...} = Rule_Set.rep (assoc_rls "rev_rew_p"); walther@59906: val der = .make_deriv thy Atools_erls rules ro NONE walther@60230: (TermC.str2term "(1 * a + -1 * b) * (1 * a + -1 * b)"); wneuper@59348: (*default_print_depth 99;*) writeln (deriv2str der); (*default_print_depth 3;*) walther@59868: (*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_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 -------------------------------------------"; wneuper@59592: val thy = @{theory Isac_Knowledge}; walther@60230: val t = Thm.term_of (the (TermC.parse thy "get_denominator ((a +x)/b)")); neuper@42301: val SOME (_, t') = eval_get_denominator "" 0 t thy; walther@59868: if UnparseC.term 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*) s1210629013@55445: reset_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; wneuper@59248: autoCalculate 1 CompleteCalc; neuper@52105: val ((pt, p), _) = get_calc 1; walther@59983: (*Test_Tool.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*) walther@60230: val t = TermC.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 *) walther@60230: val t = TermC.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; walther@59868: if UnparseC.term t' = "(-9 * x ^^^ 2 + y ^^^ 2) / -1" then () else error "Nr. 480b lhs changed"; neuper@52106: (*2nd factor separately simplified *) walther@60230: val t = TermC.str2term "((1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2) / (20*x*y / (x^^^2 - 25*y^^^2)))"; walther@59868: val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t'; walther@59868: if UnparseC.term 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 ?!?"; walther@60230: val t = TermC.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 walther@60230: val t = TermC.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. *) walther@60230: val t = TermC.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)"); walther@59901: (* Rewrite.trace_on := 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: walther@59868: if UnparseC.term 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 ?!?"; walther@60230: val t = TermC.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)))"); walther@59901: (* Rewrite.trace_on := 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"; walther@60230: val t = TermC.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: walther@60230: val t = TermC.str2term "(a-b)^^^3 * (x+y)^^^4"; neuper@52106: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: UnparseC.term 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"; walther@60230: val t = TermC.str2term "((x+y)^^^2 * (a-b)^^^5)"; neuper@52106: val SOME (t, _) = rewrite_set_ thy false norm_Rational t; walther@59868: UnparseC.term 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: walther@59901: "-------- Schalk I, p.70 Nr. 480b: terms are exploding, Rewrite.trace_on stops at"; walther@60230: val t = TermC.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: