1.1 --- a/test/Tools/isac/Knowledge/rational.sml Thu Jul 15 20:09:44 2021 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,1919 +0,0 @@
1.4 -(* Title: tests for rationals
1.5 - Author: Walther Neuper
1.6 - Use is subject to license terms.
1.7 -*)
1.8 -
1.9 -"-----------------------------------------------------------------------------";
1.10 -"-----------------------------------------------------------------------------";
1.11 -"table of contents -----------------------------------------------------------";
1.12 -"-----------------------------------------------------------------------------";
1.13 -"-------- fun poly_of_term ---------------------------------------------------";
1.14 -"-------- fun is_poly --------------------------------------------------------";
1.15 -"-------- fun term_of_poly ---------------------------------------------------";
1.16 -"-------- integration lev.1 fun factout_p_ -----------------------------------";
1.17 -"-------- integration lev.1 fun cancel_p_ ------------------------------------";
1.18 -"-------- integration lev.1 fun common_nominator_p_ --------------------------";
1.19 -"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
1.20 -"Rfuns-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
1.21 -"Rfuns-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
1.22 -"-------- rls norm_Rational downto fun gcd_poly ------------------------------";
1.23 -"Rfuns-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
1.24 -"----------- rewrite_set_ Partial_Fractions norm_Rational --------------------------------------";
1.25 -"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
1.26 -"----------- fun cancel_p with Const AA --------------------------------------------------------";
1.27 -"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
1.28 -"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
1.29 -"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
1.30 -"Rfuns-------- reverse rewrite ----------------------------------------------------";
1.31 -"Rfuns-------- 'reverse-ruleset' cancel_p -----------------------------------------";
1.32 -"-------- investigate rls norm_Rational --------------------------------------";
1.33 -"-------- examples: rls norm_Rational ----------------------------------------";
1.34 -"-------- rational numerals --------------------------------------------------";
1.35 -"-------- examples cancellation from: Mathematik 1 Schalk --------------------";
1.36 -"-------- examples common denominator from: Mathematik 1 Schalk --------------";
1.37 -"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1.38 -"-------- examples common denominator and multiplication from: Schalk --------";
1.39 -"-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1.40 -"-------- me Schalk I No.186 -------------------------------------------------";
1.41 -"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
1.42 -"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
1.43 -"-------- investigate rulesets for cancel_p ----------------------------------";
1.44 -"-------- fun eval_get_denominator -------------------------------------------";
1.45 -"-------- several errpats in complicated term --------------------------------";
1.46 -"-------- WN1309xx non-terminating rls norm_Rational -------------------------";
1.47 -"-----------------------------------------------------------------------------";
1.48 -"-----------------------------------------------------------------------------";
1.49 -
1.50 -
1.51 -"-------- fun poly_of_term ---------------------------------------------------";
1.52 -"-------- fun poly_of_term ---------------------------------------------------";
1.53 -"-------- fun poly_of_term ---------------------------------------------------";
1.54 -val thy = @{theory Partial_Fractions};
1.55 -val vs = TermC.vars_of (TermC.str2term "12 * x \<up> 3 * y \<up> 4 * z \<up> 6");
1.56 -
1.57 -val t = TermC.str2term "-3 + -2 * x ::real";
1.58 -if poly_of_term vs t = SOME [(~3, [0, 0, 0]), (~2, [1, 0, 0])]
1.59 -then () else error "poly_of_term uminus changed";
1.60 -
1.61 -if poly_of_term vs (TermC.str2term "12::real") = SOME [(12, [0, 0, 0])]
1.62 -then () else error "poly_of_term 1 changed";
1.63 -
1.64 -if poly_of_term vs (TermC.str2term "x::real") = SOME [(1, [1, 0, 0])]
1.65 -then () else error "poly_of_term 2 changed";
1.66 -
1.67 -if poly_of_term vs (TermC.str2term "12 * x \<up> 3") = SOME [(12, [3, 0, 0])]
1.68 -then () else error "poly_of_term 3 changed";
1.69 -"~~~~~ fun poly_of_term , args:"; val (vs, t) =
1.70 - (vs, (TermC.str2term "12 * x \<up> 3"));
1.71 -
1.72 - monom_of_term vs (1, replicate (length vs) 0) t;(*poly malformed 1 with x \<up> 3*)
1.73 -"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const ("Groups.times_class.times", _) $ m1 $ m2)) =
1.74 - (vs, (1, replicate (length vs) 0), t);
1.75 - val (c', es') =
1.76 -
1.77 - monom_of_term vs (c, es) m1;
1.78 -"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const ("Transcendental.powr", _) $ (t as Free _) $ (Const ("Num.numeral_class.numeral", _) $ num)) ) =
1.79 - (vs, (c', es'), m2);
1.80 -(*+*)c = 12;
1.81 -(*+*)(num |> HOLogic.dest_numeral |> list_update es (find_index (curry op = t) vs)) = [3, 0, 0];
1.82 -
1.83 -if (c, num |> HOLogic.dest_numeral |> list_update es (find_index (curry op = t) vs)) = (12, [3, 0, 0])
1.84 -then () else error "monom_of_term (powr): return value CHANGED";
1.85 -
1.86 -if poly_of_term vs (TermC.str2term "12 * x \<up> 3 * y \<up> 4 * z \<up> 6") = SOME [(12, [3, 4, 6])]
1.87 -then () else error "poly_of_term 4 changed";
1.88 -
1.89 -if poly_of_term vs (TermC.str2term "1 + 2 * x \<up> 3 * y \<up> 4 * z \<up> 6 + y") =
1.90 - SOME [(1, [0, 0, 0]), (1, [0, 1, 0]), (2, [3, 4, 6])]
1.91 -then () else error "poly_of_term 5 changed";
1.92 -
1.93 -(*poly_of_term is quite liberal:*)
1.94 -(*the coefficient may be somewhere, the order of variables and the parentheses
1.95 - within a monomial are arbitrary*)
1.96 -if poly_of_term vs (TermC.str2term "y \<up> 4 * (x \<up> 3 * 12 * z \<up> 6)") = SOME [(12, [3, 4, 6])]
1.97 -then () else error "poly_of_term 6 changed";
1.98 -
1.99 -(*there may even be more than 1 coefficient:*)
1.100 -if poly_of_term vs (TermC.str2term "2 * y \<up> 4 * (x \<up> 3 * 6 * z \<up> 6)") = SOME [(12, [3, 4, 6])]
1.101 -then () else error "poly_of_term 7 changed";
1.102 -
1.103 -(*the order and the parentheses within monomials are arbitrary:*)
1.104 -if poly_of_term vs (TermC.str2term "2 * x \<up> 3 * y \<up> 4 * z \<up> 6 + (7 * y \<up> 8 + 1)")
1.105 - = SOME [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 6])]
1.106 -then () else error "poly_of_term 8 changed";
1.107 -
1.108 -(*from --- rls norm_Rational downto fun gcd_poly ---*)
1.109 -val t = TermC.str2term (*copy from above: "::real" is not required due to " \<up> "*)
1.110 - ("(-12 + 4 * y + 3 * x \<up> 2 + -1 * (x \<up> 2 * y)) /" ^
1.111 - "(-18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)");
1.112 -"~~~~~ fun cancel_p_, args:"; val (t) = (t);
1.113 -val opt = check_fraction t;
1.114 -val SOME (numerator, denominator) = opt;
1.115 -(*+*)UnparseC.term numerator = "- 12 + 4 * y + 3 * x \<up> 2 + - 1 * (x \<up> 2 * y)"; (*isa -- isa2*);
1.116 -(*+*)UnparseC.term denominator = "- 18 + - 9 * x + 2 * y \<up> 2 + x * y \<up> 2"; (*isa -- isa2*);
1.117 - val vs = TermC.vars_of t;
1.118 -(*+*)UnparseC.terms vs = "[\"x\", \"y\"]";
1.119 - val baseT = type_of numerator
1.120 - val expT = HOLogic.realT;
1.121 -val (SOME _, SOME _) = (poly_of_term vs numerator, poly_of_term vs denominator); (*isa <> isa2*)
1.122 -
1.123 -"-------- fun is_poly --------------------------------------------------------";
1.124 -"-------- fun is_poly --------------------------------------------------------";
1.125 -"-------- fun is_poly --------------------------------------------------------";
1.126 -if is_poly (TermC.str2term "2 * x \<up> 3 * y \<up> 4 * z \<up> 6 + 7 * y \<up> 8 + 1")
1.127 -then () else error "is_poly 1 changed";
1.128 -if not (is_poly (TermC.str2term "2 * (x \<up> 3 * y \<up> 4 * z \<up> 6 + 7) * y \<up> 8 + 1"))
1.129 -then () else error "is_poly 2 changed";
1.130 -
1.131 -"-------- fun term_of_poly ---------------------------------------------------";
1.132 -"-------- fun term_of_poly ---------------------------------------------------";
1.133 -"-------- fun term_of_poly ---------------------------------------------------";
1.134 -val expT = HOLogic.realT
1.135 -val Free (_, baseT) = (hd o vars o TermC.str2term) "12 * x \<up> 3 * y \<up> 4 * z \<up> 6";
1.136 -val p = [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 5])]
1.137 -val vs = TermC.vars_of (the (parseNEW ctxt "12 * x \<up> 3 * y \<up> 4 * z \<up> 6"))
1.138 -(*precondition for [(c, es),...]: legth es = length vs*)
1.139 -;
1.140 -if UnparseC.term (term_of_poly baseT expT vs p) = "1 + 7 * y \<up> 8 + 2 * x \<up> 3 * y \<up> 4 * z \<up> 5"
1.141 -then () else error "term_of_poly 1 changed";
1.142 -
1.143 -"-------- integration lev.1 fun factout_p_ -----------------------------------";
1.144 -"-------- integration lev.1 fun factout_p_ -----------------------------------";
1.145 -"-------- integration lev.1 fun factout_p_ -----------------------------------";
1.146 -val t = TermC.str2term "(x \<up> 2 + -1*y \<up> 2) / (x \<up> 2 + -1*x*y)"
1.147 -val SOME (t', asm) = factout_p_ thy t;
1.148 -if UnparseC.term t' = "(x + y) * (x + - 1 * y) / (x * (x + - 1 * y))"
1.149 -then () else error ("factout_p_ term 1 changed: " ^ UnparseC.term t')
1.150 -;
1.151 -if UnparseC.terms asm = "[\"x \<noteq> 0\", \"x + - 1 * y \<noteq> 0\"]"
1.152 -then () else error "factout_p_ asm 1 changed"
1.153 -;
1.154 -val t = TermC.str2term "nothing + to_cancel ::real";
1.155 -if NONE = factout_p_ thy t then () else error "factout_p_ doesn't report non-applicable";
1.156 -;
1.157 -val t = TermC.str2term "((3 * x \<up> 2 + 6 *x + 3) / (2*x + 2))";
1.158 -val SOME (t', asm) = factout_p_ thy t;
1.159 -if UnparseC.term t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso
1.160 - UnparseC.terms asm = "[\"1 + x \<noteq> 0\"]"
1.161 -then () else error "factout_p_ 1 changed";
1.162 -
1.163 -"-------- integration lev.1 fun cancel_p_ ------------------------------------";
1.164 -"-------- integration lev.1 fun cancel_p_ ------------------------------------";
1.165 -"-------- integration lev.1 fun cancel_p_ ------------------------------------";
1.166 -val t = TermC.str2term "(x \<up> 2 + -1*y \<up> 2) / (x \<up> 2 + -1*x*y)"
1.167 -val SOME (t', asm) = cancel_p_ thy t;
1.168 -if (UnparseC.term t', UnparseC.terms asm) = ("(x + y) / x", "[\"x \<noteq> 0\"]")
1.169 -then () else error ("cancel_p_ (t', asm) 1 changed: " ^ UnparseC.term t')
1.170 -;
1.171 -val t = TermC.str2term "nothing + to_cancel ::real";
1.172 -if NONE = cancel_p_ thy t then () else error "cancel_p_ doesn't report non-applicable";
1.173 -;
1.174 -val t = TermC.str2term "((3 * x \<up> 2 + 6 *x + 3) / (2*x + 2))";
1.175 -val SOME (t', asm) = cancel_p_ thy t;
1.176 -if UnparseC.term t' = "(3 + 3 * x) / 2" andalso UnparseC.terms asm = "[]"
1.177 -then () else error "cancel_p_ 1 changed";
1.178 -
1.179 -"-------- integration lev.1 fun common_nominator_p_ --------------------------";
1.180 -"-------- integration lev.1 fun common_nominator_p_ --------------------------";
1.181 -"-------- integration lev.1 fun common_nominator_p_ --------------------------";
1.182 -val t = TermC.str2term ("y / (a*x + b*x + c*x) " ^
1.183 - (* n1 d1 *)
1.184 - "+ a / (x*y)");
1.185 - (* n2 d2 *)
1.186 -val SOME (t', asm) = common_nominator_p_ thy t;
1.187 -if UnparseC.term t' =
1.188 - ("y * y / (x * ((a + b + c) * y)) " ^
1.189 - (* n1 *d2'/ (c'* ( d1' *d2')) *)
1.190 - "+ a * (a + b + c) / (x * ((a + b + c) * y))")
1.191 - (* n2 * d1' / (c'* ( d1' *d2')) *)
1.192 -then () else error "common_nominator_p_ term 1 changed";
1.193 -if UnparseC.terms asm = "[\"a + b + c \<noteq> 0\", \"y \<noteq> 0\", \"x \<noteq> 0\"]"
1.194 -then () else error "common_nominator_p_ asm 1 changed"
1.195 -
1.196 -"-------- example in mail Nipkow";
1.197 -val t = TermC.str2term "x/(x \<up> 2 + -1*y \<up> 2) + y/(x \<up> 2 + -1*x*y)";
1.198 -val SOME (t', asm) = common_nominator_p_ thy t;
1.199 -if UnparseC.term t' =
1.200 - "x * x / ((x + - 1 * y) * ((x + y) * x)) +\ny * (x + y) / ((x + - 1 * y) * ((x + y) * x))"
1.201 -then () else error "common_nominator_p_ term 2 changed"
1.202 -;
1.203 -if UnparseC.terms asm = "[\"x + y \<noteq> 0\", \"x \<noteq> 0\", \"x + - 1 * y \<noteq> 0\"]"
1.204 -then () else error "common_nominator_p_ asm 2 changed"
1.205 -
1.206 -"-------- example: applicable tested by SML code";
1.207 -val t = TermC.str2term "nothing / to_add";
1.208 -if NONE = common_nominator_p_ thy t then () else error "common_nominator_p_ term 3 changed";
1.209 -;
1.210 -val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
1.211 -val SOME (t', asm) = common_nominator_p_ thy t;
1.212 -if UnparseC.term t' =
1.213 - "(x + - 1) * (- 1 + x) / ((1 + x) * (- 1 + x)) +\n(x + 1) * (1 + x) / ((1 + x) * (- 1 + x))"
1.214 - andalso UnparseC.terms asm = "[\"1 + x \<noteq> 0\", \"- 1 + x \<noteq> 0\"]"
1.215 -then () else error "common_nominator_p_ 3 changed";
1.216 -
1.217 -"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
1.218 -"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
1.219 -"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
1.220 -val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
1.221 -val SOME (t', asm) = add_fraction_p_ thy t;
1.222 -if UnparseC.term t' = "(2 + 2 * x \<up> 2) / (- 1 + x \<up> 2)"
1.223 -then () else error "add_fraction_p_ 3 changed";
1.224 -;
1.225 -if UnparseC.terms asm = "[\"- 1 + x \<up> 2 \<noteq> 0\"]"
1.226 -then () else error "add_fraction_p_ 3 changed";
1.227 -;
1.228 -val t = TermC.str2term "nothing / to_add";
1.229 -if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ term 3 changed";
1.230 -;
1.231 -val t = TermC.str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
1.232 -val SOME (t', asm) = add_fraction_p_ thy t;
1.233 -if UnparseC.term t' = "(2 + 2 * x \<up> 2) / (- 1 + x \<up> 2)" andalso
1.234 - UnparseC.terms asm = "[\"- 1 + x \<up> 2 \<noteq> 0\"]"
1.235 -then () else error "add_fraction_p_ 3 changed";
1.236 -
1.237 -"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
1.238 -"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
1.239 -"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
1.240 -(* trace down until prepats are evaluated
1.241 - (which does not to work, because substitution is not done -- compare rew_sub!);
1.242 - keep this sequence for the case, factout_p, cancel_p, common_nominator_p, add_fraction_p
1.243 - (again) get prepat = [] changed to <>[]. *)
1.244 -val t = TermC.str2term "(x \<up> 2 + -1*y \<up> 2) / (x \<up> 2 + -1*x*y)";
1.245 -
1.246 -(*rewrite_set_ @{theory Isac_Knowledge} true cancel t = NONE; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
1.247 -"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (thy, false, cancel_p, t);
1.248 -"~~~~~ fun rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
1.249 - (thy, 1, bool, [], rls, term);
1.250 -(*val (t', asm, rew) = app_rev thy (i+1) rrls t; rew = false!!!!!!!!!!!!!!!!!!!!!*)
1.251 -"~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
1.252 - fun chk_prepat thy erls [] t = true
1.253 - | chk_prepat thy erls prepat t =
1.254 - let
1.255 - fun chk (pres, pat) =
1.256 - (let
1.257 - val subst: Type.tyenv * Envir.tenv =
1.258 - Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
1.259 - in
1.260 - snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
1.261 - end) handle Pattern.MATCH => false
1.262 - fun scan_ f [] = false (*scan_ NEVER called by []*)
1.263 - | scan_ f (pp::pps) =
1.264 - if f pp then true else scan_ f pps;
1.265 - in scan_ chk prepat end;
1.266 - (* apply the normal_form of a rev-set *)
1.267 - fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
1.268 - if chk_prepat thy erls prepat t
1.269 - then ((*tracing("### app_rev': t = "^UnparseC.term t);*) normal_form t)
1.270 - else NONE;
1.271 -(* val opt = app_rev' thy rrls t ..NONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
1.272 -"~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
1.273 - (thy, rrls, t);
1.274 -(* chk_prepat thy erls prepat t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
1.275 -(* app_sub thy i rrls t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
1.276 -"~~~~~ fun chk_prepat, args:"; val (thy, erls, prepat, t) = (thy, erls, prepat, t);
1.277 - fun chk (pres, pat) =
1.278 - (let
1.279 - val subst: Type.tyenv * Envir.tenv =
1.280 - Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
1.281 - in
1.282 - snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
1.283 - end) handle Pattern.MATCH => false
1.284 - fun scan_ f [] = false (*scan_ NEVER called by []*)
1.285 - | scan_ f (pp::pps) =
1.286 - if f pp then true else scan_ f pps;
1.287 -
1.288 -(*========== inhibit exn WN130823: prepat is empty ====================================
1.289 -(* scan_ chk prepat = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
1.290 -"~~~~~ fun , args:"; val (f, (pp::pps)) = (chk, prepat);
1.291 -f;
1.292 -val ([t1, t2], t) = pp;
1.293 -UnparseC.term t1 = "?r is_expanded";
1.294 -UnparseC.term t2 = "?s is_expanded";
1.295 -UnparseC.term t = "?r / ?s";
1.296 -(* f pp = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
1.297 -"~~~~~ fun chk, args:"; val (pres, pat) = (pp);
1.298 - val subst: Type.tyenv * Envir.tenv =
1.299 - Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
1.300 -(*subst =
1.301 - ({}, {(("r", 0), ("real", Var (("r", 0), "real"))),
1.302 - (("s", 0), ("real", Var (("s", 0), "real")))}*)
1.303 -;
1.304 - snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
1.305 -"~~~~~ fun eval__true, args:"; val (thy, i, asms, bdv, rls) =
1.306 - (thy, (i + 1), (map (Envir.subst_term subst) pres), [], erls);
1.307 -UnparseC.terms asms; (* = "[\"?r is_expanded\",\"?s is_expanded\"]"*)
1.308 -asms = [@{term True}] orelse asms = []; (* = false*)
1.309 -asms = [@{term False}] ; (* = false*)
1.310 -"~~~~~ fun chk, args:"; val (indets, (a::asms)) = ([], asms);
1.311 -bdv (*= []: _a list*);
1.312 -val bdv : (term * term) list = [];
1.313 -rewrite__set_ thy (i+1) false;
1.314 -UnparseC.term a = "?r is_expanded"; (*hier m"usste doch der Numerator eingesetzt sein ??????????????*)
1.315 -val SOME (Const ("HOL.False", _), []) = rewrite__set_ thy (i+1) false bdv rls a
1.316 -============ inhibit exn WN130823: prepat is empty ===================================*)
1.317 -
1.318 -"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
1.319 -"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
1.320 -"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
1.321 -val t = TermC.str2term "(12 * x * y) / (8 * y \<up> 2 )";
1.322 -(* "-------- example 187a": exception Div raised...
1.323 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
1.324 -val t = TermC.str2term "(8 * x \<up> 2 * y * z ) / (18 * x * y \<up> 2 * z )";
1.325 -(* "-------- example 187b": doesn't terminate...
1.326 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
1.327 -val t = TermC.str2term "(9 * x \<up> 5 * y \<up> 2 * z \<up> 4) / (15 * x \<up> 6 * y \<up> 3 * z )";
1.328 -(* "-------- example 187c": doesn't terminate...
1.329 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
1.330 -"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (@{theory Isac_Knowledge}, false, cancel_p, t);
1.331 -(* WN130827: exception Div raised...
1.332 -rewrite__set_ thy 1 bool [] rls term
1.333 -*)
1.334 -"~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
1.335 - (thy, 1, bool, [], rls, term);
1.336 -(* WN130827: exception Div raised...
1.337 - val (t', asm, rew) = app_rev thy (i+1) rrls t
1.338 -*)
1.339 -"~~~~~ fun app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
1.340 -(* WN130827: exception Div raised...
1.341 - val opt = app_rev' thy rrls t
1.342 -*)
1.343 -"~~~~~ fun app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
1.344 - (thy, rrls, t);
1.345 -chk_prepat thy erls prepat t = true;
1.346 -(* WN130827: exception Div raised...
1.347 -normal_form t
1.348 -*)
1.349 -(* lookup Rational.thy, cancel_p: normal_form = cancel_p_ thy*)
1.350 -"~~~~~ fun cancel_p_, args:"; val (t) = (t);
1.351 -val opt = check_fraction t;
1.352 -val SOME (numerator, denominator) = opt
1.353 - val vs = TermC.vars_of t
1.354 - val baseT = type_of numerator
1.355 - val expT = HOLogic.realT
1.356 -val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator);
1.357 -(*"-------- example 187a": exception Div raised...
1.358 -val a = [(12, [1, 1])]: poly
1.359 -val b = [(8, [0, 2])]: poly
1.360 - val ((a', b'), c) = gcd_poly a b
1.361 -*)
1.362 -(* "-------- example 187b": doesn't terminate...
1.363 -val a = [(8, [2, 1, 1])]: poly
1.364 -val b = [(18, [1, 2, 1])]: poly
1.365 - val ((a', b'), c) = gcd_poly a b
1.366 -*)
1.367 -(* "-------- example 187c": doesn't terminate...
1.368 -val a = [(9, [5, 2, 4])]: poly
1.369 -val b = [(15, [6, 3, 1])]: poly
1.370 - val ((a', b'), c) = gcd_poly a b
1.371 -*)
1.372 -
1.373 -"-------- rls norm_Rational downto fun gcd_poly ------------------------------";
1.374 -"-------- rls norm_Rational downto fun gcd_poly ------------------------------";
1.375 -"-------- rls norm_Rational downto fun gcd_poly ------------------------------";
1.376 -val t = TermC.str2term "(x \<up> 2 - 4)*(3 - y) / ((y \<up> 2 - 9)*(2+x))";
1.377 -Rewrite.trace_on := false (*true false*);
1.378 -(* trace stops with ...: (and then jEdit hangs)..
1.379 -rewrite_set_ thy false norm_Rational t;
1.380 -:
1.381 -### rls: cancel_p on: (-12 + 4 * y + 3 * x \<up> 2 + -1 * (x \<up> 2 * y)) /
1.382 -(-18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)
1.383 -*)
1.384 -val t = TermC.str2term (*copy from above: "::real" is not required due to " \<up> "*)
1.385 - ("(-12 + 4 * y + 3 * x \<up> 2 + -1 * (x \<up> 2 * y)) /" ^
1.386 - "(-18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)");
1.387 -(*cancel_p_ thy t;
1.388 -exception Div raised*)
1.389 -
1.390 -"~~~~~ fun cancel_p_, args:"; val (t) = (t);
1.391 -val opt = check_fraction t;
1.392 -val SOME (numerator, denominator) = opt
1.393 - val vs = TermC.vars_of t
1.394 - val baseT = type_of numerator
1.395 - val expT = HOLogic.realT;
1.396 -(*default_print_depth 3; 999*)
1.397 -val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator);
1.398 -(*default_print_depth 3; 999*)
1.399 -(* does not terminate instead of returning ?:
1.400 - val ((a', b'), c) = gcd_poly a b
1.401 -val a = [(~12, [0, 0]), (3, [2, 0]), (4, [0, 1]), (~1, [2, 1])]: poly
1.402 -val b = [(~18, [0, 0]), (~9, [1, 0]), (2, [0, 2]), (1, [1, 2])]: poly
1.403 -*)
1.404 -
1.405 -"-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
1.406 -"-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
1.407 -"-------- rls norm_Rational downto fun add_fraction_p_ -----------------------";
1.408 -val thy = @{theory Isac_Knowledge};
1.409 -"----- SK060904-2a non-termination of add_fraction_p_";
1.410 -val t = TermC.str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^
1.411 - " (-1 * a + b * x) / (a + b * x) ");
1.412 -(* rewrite_set_ thy false norm_Rational t
1.413 -exception Div raised*)
1.414 -(* rewrite_set_ thy false add_fractions_p t;
1.415 -exception Div raised*)
1.416 -"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) =
1.417 - (@{theory Isac_Knowledge}, false, add_fractions_p, t);
1.418 -"~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
1.419 - (thy, 1, bool, [], rls, term);
1.420 -(* app_rev thy (i+1) rrls t;
1.421 -exception Div raised*)
1.422 -"~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
1.423 - fun chk_prepat thy erls [] t = true
1.424 - | chk_prepat thy erls prepat t =
1.425 - let
1.426 - fun chk (pres, pat) =
1.427 - (let
1.428 - val subst: Type.tyenv * Envir.tenv =
1.429 - Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
1.430 - in
1.431 - snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
1.432 - end) handle Pattern.MATCH => false
1.433 - fun scan_ f [] = false (*scan_ NEVER called by []*)
1.434 - | scan_ f (pp::pps) =
1.435 - if f pp then true else scan_ f pps;
1.436 - in scan_ chk prepat end;
1.437 - (* apply the normal_form of a rev-set *)
1.438 - fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
1.439 - if chk_prepat thy erls prepat t
1.440 - then ((*tracing("### app_rev': t = "^UnparseC.term t);*) normal_form t)
1.441 - else NONE;
1.442 -(* val opt = app_rev' thy rrls t;
1.443 -exception Div raised*)
1.444 -(* val opt = app_rev' thy rrls t;
1.445 -exception Div raised*)
1.446 -"~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
1.447 - (thy, rrls, t);
1.448 -chk_prepat thy erls prepat t = true = true;
1.449 -(*normal_form t
1.450 -exception Div raised*)
1.451 -(* lookup Rational.thy, val add_fractions_p: normal_form = add_fraction_p_ thy*)
1.452 -(*add_fraction_p_ thy t
1.453 -exception Div raised*)
1.454 -"~~~~~ fun add_fraction_p_, args:"; val ((_: theory), t) = (thy, t);
1.455 -val SOME ((n1, d1), (n2, d2)) = check_frac_sum t;
1.456 -UnparseC.term n1; UnparseC.term d1; UnparseC.term n2; UnparseC.term d2;
1.457 - val vs = TermC.vars_of t;
1.458 -(*default_print_depth 3; 999*)
1.459 -val (SOME _, SOME a, SOME _, SOME b) =
1.460 - (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2);
1.461 -(*default_print_depth 3; 999*)
1.462 -(*
1.463 -val a = [(1, [1, 0, 0]), (~1, [0, 1, 1])]: poly
1.464 -val b = [(1, [1, 0, 0]), (1, [0, 1, 1])]: poly
1.465 - val ((a', b'), c) = gcd_poly a b
1.466 -*)
1.467 -
1.468 -"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
1.469 -"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
1.470 -"----------- fun check_frac_sum with Free A and Const AA ---------------------------------------";
1.471 -val thy = @{theory Isac_Knowledge(*Partial_Fractions*)}
1.472 -val ctxt = Proof_Context.init_global thy;
1.473 -
1.474 -(*---------- (1) with Free A, B ----------------------------------------------------------------*)
1.475 -val t = (the o (parseNEW ctxt)) "3 = A / 2 + A / 4 + (B / 2 + -1 * B / (2::real))";
1.476 - (* required for applying thms in rewriting \<up> ^*)
1.477 -(* we get details from here..*)
1.478 -
1.479 -Rewrite.trace_on := false;
1.480 -val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t;
1.481 -Rewrite.trace_on := false;
1.482 -(* Rewrite.trace_on:
1.483 -add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
1.484 - (* |||||||||||||||||||||||||||||||||||| *)
1.485 -
1.486 -val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 1 GUESS 1 GUESS 1 GUESS 1 *)
1.487 - "A / 2 + A / 4 + (B / 2 + -1 * B / (2::real))";
1.488 -"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
1.489 -val NONE = (*case*) check_frac_sum t (*of*)
1.490 -
1.491 -(* Rewrite.trace_on:
1.492 -add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
1.493 - (* |||||||||||||||||||||||||||| *)
1.494 -val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| GUESS 2 GUESS 2 GUESS 2 GUESS 2 *)
1.495 - "A / 4 + (B / 2 + -1 * B / (2::real))";
1.496 -"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
1.497 -val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*);
1.498 -(*+*)if (UnparseC.term n1, UnparseC.term d1) = ("A" , "4") andalso
1.499 -(*+*) (UnparseC.term n2, UnparseC.term d2) = ("B / 2 + - 1 * B / 2", "1")
1.500 -(*+*)then () else error "check_frac_sum (A / 4 + (B / 2 + -1 * B / (2::real))) changed";
1.501 -
1.502 - val vs = TermC.vars_of t;
1.503 -val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) =
1.504 - (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*);
1.505 -
1.506 -"~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1);
1.507 -val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t];
1.508 -(*+*)if xxx = 1 then () else error "monom_of_term changed"
1.509 -
1.510 -"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Free (id, _))) =
1.511 - (vs, (1, replicate (length vs) 0), t);
1.512 -case vs of [Free ("A", _), Free ("B", _)] =>
1.513 - if c = 1 andalso id = "A"
1.514 - then () else error "monom_of_term Free changed 1"
1.515 -| _ => error "monom_of_term Free changed 2";
1.516 -
1.517 -(*---------- (2) with Const AA, BB --------------------------------------------------------------*)
1.518 -val t = (the o (parseNEW ctxt)) "3 = AA / 2 + AA / 4 + (BB / 2 + -1 * BB / 2)";
1.519 - (*AA :: real*)
1.520 -(* we get details from here..*)
1.521 -
1.522 -Rewrite.trace_on := false;
1.523 -val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t;
1.524 -Rewrite.trace_on := false;
1.525 -(* Rewrite.trace_on:
1.526 -add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
1.527 - (* |||||||||||||||||||||||||||||||||||| *)
1.528 -val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *)
1.529 - "AA / 2 + AA / 4 + (BB / 2 + -1 * BB / 2)";
1.530 -"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
1.531 -val NONE = (*case*) check_frac_sum t (*of*)
1.532 -
1.533 -(* Rewrite.trace_on:
1.534 -add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + -1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
1.535 - (* |||||||||||||||||||||||||||| *)
1.536 -val t = (the o (parseNEW ctxt))(* ||||||||||||||||||||||||| *)
1.537 - "AA / 4 + (BB / 2 + -1 * BB / 2)";
1.538 -"~~~~~ fun add_fraction_p_ , ad-hoc args:"; val (t) = (t);
1.539 -val SOME ((n1, d1), (n2, d2)) = (*case*) check_frac_sum t (*of*);
1.540 -(*+*)if (UnparseC.term n1, UnparseC.term d1) = ("AA" , "4") andalso
1.541 -(*+*) (UnparseC.term n2, UnparseC.term d2) = ("BB / 2 + - 1 * BB / 2", "1")
1.542 -(*+*)then () else error "check_frac_sum (AA / 4 + (BB / 2 + -1 * BB / 2)) changed";
1.543 -
1.544 - val vs = TermC.vars_of t;
1.545 -val (SOME [(1, [1, 0])], SOME [(4, [0, 0])], NONE, SOME [(1, [0, 0])]) =
1.546 - (*case*) (poly_of_term vs n1, poly_of_term vs d1, poly_of_term vs n2, poly_of_term vs d2) (*of*);
1.547 -
1.548 -"~~~~~ fun poly_of_term , args:"; val (vs, t) = (vs, n1);
1.549 -val SOME [(1, [xxx, 0])] = SOME [monom_of_term vs (1, replicate (length vs) 0) t];
1.550 -(*+*)if xxx = 1 then () else error "monom_of_term changed"
1.551 -
1.552 -"~~~~~ fun monom_of_term , args:"; val (vs, (c, es), (Const (id, _))) =
1.553 - (vs, (1, replicate (length vs) 0), t);
1.554 -case vs of [Const ("Partial_Fractions.AA", _), Const ("Partial_Fractions.BB", _)] =>
1.555 - if c = 1 andalso id = "Partial_Fractions.AA"
1.556 - then () else error "monom_of_term Const changed 1"
1.557 -| _ => error "monom_of_term Const changed 2";
1.558 -
1.559 -"----------- fun cancel_p with Const AA --------------------------------------------------------";
1.560 -"----------- fun cancel_p with Const AA --------------------------------------------------------";
1.561 -"----------- fun cancel_p with Const AA --------------------------------------------------------";
1.562 -val thy = @{theory Partial_Fractions};
1.563 -val ctxt = Proof_Context.init_global @{theory}
1.564 -val SOME t = TermC.parseNEW ctxt "2 * AA / 2"; (* Const ("Free ("AA", "real") *)
1.565 -
1.566 -val SOME (t', _) = rewrite_set_ thy true cancel_p t;
1.567 -case t' of
1.568 - Const ("Rings.divide_class.divide", _) $ Const ("Partial_Fractions.AA", _) $
1.569 - Const ("Groups.one_class.one", _) => ()
1.570 -| _ => error "WRONG rewrite_set_ cancel_p (2 * AA / 2) \<longrightarrow> AA changed";
1.571 -
1.572 -"~~~~~ fun cancel_p , args:"; val (t) = (t);
1.573 -val opt = check_fraction t
1.574 -val SOME (numerator, denominator) = (*case*) opt (*of*);
1.575 -
1.576 -if UnparseC.term numerator = "2 * AA" andalso UnparseC.term denominator = "2"
1.577 -then () else error "check_fraction (2 * AA / 2) changed";
1.578 - val vs = TermC.vars_of t;
1.579 -case vs of
1.580 - [Const ("Partial_Fractions.AA", _)] => ()
1.581 -| _ => error "rewrite_set_ cancel_p (2 * AA / 2) \<longrightarrow> AA/1 changed";
1.582 -
1.583 -
1.584 -"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
1.585 -"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
1.586 -"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
1.587 -val thy = @{theory "Rational"};
1.588 -"-------- WN";
1.589 -val t = TermC.str2term "(2 + -3 * x) / 9";
1.590 -if NONE = rewrite_set_ thy false cancel_p t then ()
1.591 -else error "rewrite_set_ cancel_p must return NONE, if the term cannot be cancelled";
1.592 -
1.593 -"-------- example 186a";
1.594 -val t = TermC.str2term "(14 * x * y) / (x * y)";
1.595 - is_expanded (TermC.str2term "14 * x * y");
1.596 - is_expanded (TermC.str2term "x * y");
1.597 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.598 -if (UnparseC.term t', UnparseC.terms asm) = ("14 / 1", "[]")
1.599 -then () else error "rational.sml cancel Schalk 186a";
1.600 -
1.601 -"-------- example 186b";
1.602 -val t = TermC.str2term "(60 * a * b) / ( 15 * a * b )";
1.603 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.604 -if (UnparseC.term t', UnparseC.terms asm) = ("4 / 1", "[]")
1.605 -then () else error "rational.sml cancel Schalk 186b";
1.606 -
1.607 -"-------- example 186c";
1.608 -val t = TermC.str2term "(144 * a \<up> 2 * b * c) / (12 * a * b * c)";
1.609 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.610 -if (UnparseC.term t', UnparseC.terms asm) = ("12 * a / 1", "[]")
1.611 -then () else error "rational.sml cancel Schalk 186c";
1.612 -
1.613 -(* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! exception Div raised !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.614 - see --- fun rewrite_set_ downto fun gcd_poly ---
1.615 -"-------- example 187a";
1.616 -val t = TermC.str2term "(12 * x * y) / (8 * y \<up> 2 )";
1.617 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.618 -if (UnparseC.term t', UnparseC.terms asm) = ("3 * x / (2 * y)", "[\"4 * y ~= 0\"]")
1.619 -then () else error "rational.sml cancel Schalk 187a";
1.620 -*)
1.621 -
1.622 -(* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.623 - see --- fun rewrite_set_ downto fun gcd_poly ---
1.624 -"-------- example 187b";
1.625 -val t = TermC.str2term "(8 * x \<up> 2 * y * z ) / (18 * x * y \<up> 2 * z )";
1.626 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.627 -if (UnparseC.term t', UnparseC.terms asm) = ("4 * x / (9 * y)", "[\"2 * (z * (y * x)) ~= 0\"]")
1.628 -then () else error "rational.sml cancel Schalk 187b";
1.629 -*)
1.630 -
1.631 -(* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1.632 - see --- fun rewrite_set_ downto fun gcd_poly ---
1.633 -"-------- example 187c";
1.634 -val t = TermC.str2term "(9 * x \<up> 5 * y \<up> 2 * z \<up> 4) / (15 * x \<up> 6 * y \<up> 3 * z )";
1.635 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.636 -if (UnparseC.term t', UnparseC.terms asm) =
1.637 - ("3 * z \<up> 3 / (5 * (y * x))", "[\"3 * (z * (y \<up> 2 * x \<up> 5)) ~= 0\"]")
1.638 -then () else error "rational.sml cancel Schalk 187c";
1.639 -*)
1.640 -
1.641 -"-------- example 188a";
1.642 -val t = TermC.str2term "(-8 + 8 * x) / (-9 + 9 * x)";
1.643 - is_expanded (TermC.str2term "8 * x + -8");
1.644 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.645 -if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]")
1.646 -then () else error "rational.sml cancel Schalk 188a";
1.647 -
1.648 -val t = TermC.str2term "(8*((-1) + x))/(9*((-1) + x))";
1.649 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
1.650 -if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]")
1.651 -then () else error "rational.sml cancel Schalk make_polynomial 1";
1.652 -
1.653 -"-------- example 188b";
1.654 -val t = TermC.str2term "(-15 + 5 * x) / (-18 + 6 * x)";
1.655 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.656 -if (UnparseC.term t', UnparseC.terms asm) = ("5 / 6", "[]")
1.657 -then () else error "rational.sml cancel Schalk 188b";
1.658 -
1.659 -"-------- example 188c";
1.660 -val t = TermC.str2term "(a + -1 * b) / (b + -1 * a)";
1.661 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.662 -if (UnparseC.term t', UnparseC.terms asm) = ("- 1 / 1", "[]")
1.663 -then () else error "rational.sml cancel Schalk 188c";
1.664 -
1.665 -is_expanded (TermC.str2term "a + -1 * b") = true;
1.666 -val t = TermC.str2term "((- 1)*(b + (-1) * a))/(1*(b + (- 1) * a))";
1.667 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
1.668 -if (UnparseC.term t', UnparseC.terms asm) = ("(a + - 1 * b) / (- 1 * a + b)", "[]")
1.669 -then () else error "rational.sml cancel Schalk make_polynomial 2";
1.670 -
1.671 -"-------- example 190a";
1.672 -val t = TermC.str2term "( 27 * a \<up> 3 + 9 * a \<up> 2 + 3 * a + 1 ) / ( 27 * a \<up> 3 + 18 * a \<up> 2 + 3 * a )";
1.673 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.674 -if (UnparseC.term t', UnparseC.terms asm) =
1.675 - ("(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)", "[\"3 * a + 9 * a \<up> 2 \<noteq> 0\"]")
1.676 -then () else error "rational.sml cancel Schalk 190a";
1.677 -
1.678 -"-------- example 190c";
1.679 -val t = TermC.str2term "((1 + 9 * a \<up> 2)*(1 + 3 * a))/((3 * a + 9 * a \<up> 2)*(1 + 3 * a))";
1.680 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
1.681 -if (UnparseC.term t', UnparseC.terms asm) =
1.682 - ("(1 + 3 * a + 9 * a \<up> 2 + 27 * a \<up> 3) /\n(3 * a + 18 * a \<up> 2 + 27 * a \<up> 3)", "[]")
1.683 -then () else error "rational.sml make_polynomial Schalk 190c";
1.684 -
1.685 -"-------- example 191a";
1.686 -val t = TermC.str2term "( x \<up> 2 + -1 * y \<up> 2 ) / ( x + y )";
1.687 - is_expanded (TermC.str2term "x \<up> 2 + - 1 * y \<up> 2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
1.688 - is_expanded (TermC.str2term "x + y") = true;
1.689 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.690 -if (UnparseC.term t', UnparseC.terms asm) = ("(x + - 1 * y) / 1", "[]")
1.691 -then () else error "rational.sml make_polynomial Schalk 191a";
1.692 -
1.693 -"-------- example 191b";
1.694 -val t = TermC.str2term "((x + (- 1) * y)*(x + y))/((1)*(x + y))";
1.695 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
1.696 -if (UnparseC.term t', UnparseC.terms asm) = ("(x \<up> 2 + - 1 * y \<up> 2) / (x + y)", "[]")
1.697 -then () else error "rational.sml make_polynomial Schalk 191b";
1.698 -
1.699 -"-------- example 191c";
1.700 -val t = TermC.str2term "( 9 * x \<up> 2 + -30 * x + 25 ) / ( 9 * x \<up> 2 + -25 )";
1.701 - is_expanded (TermC.str2term "9 * x \<up> 2 + -30 * x + 25") = true;
1.702 - is_expanded (TermC.str2term "25 + -30*x + 9*x \<up> 2") = true;
1.703 - is_expanded (TermC.str2term "-25 + 9*x \<up> 2") = true;
1.704 -
1.705 -val t = TermC.str2term "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
1.706 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
1.707 -if (UnparseC.term t', UnparseC.terms asm) = ("(25 + - 30 * x + 9 * x \<up> 2) / (- 25 + 9 * x \<up> 2)", "[]")
1.708 -then () else error "rational.sml make_polynomial Schalk 191c";
1.709 -
1.710 -"-------- example 192b";
1.711 -val t = TermC.str2term "( 7 * x \<up> 3 + - 1 * x \<up> 2 * y ) / ( 7 * x * y \<up> 2 + - 1 * y \<up> 3 )";
1.712 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.713 -if (UnparseC.term t', UnparseC.terms asm) = ("x \<up> 2 / y \<up> 2", "[\"y \<up> 2 \<noteq> 0\"]")
1.714 -then () else error "rational.sml cancel_p Schalk 192b";
1.715 -
1.716 -val t = TermC.str2term "((x \<up> 2)*(7 * x + (-1) * y))/((y \<up> 2)*(7 * x + (-1) * y))";
1.717 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
1.718 -if (UnparseC.term t', UnparseC.terms asm) =
1.719 - ("(7 * x \<up> 3 + - 1 * x \<up> 2 * y) /\n(7 * x * y \<up> 2 + - 1 * y \<up> 3)", "[]")
1.720 -then () else error "rational.sml make_polynomial Schalk 192b";
1.721 -
1.722 -val t = TermC.str2term "((x \<up> 2)*(7 * x + (-1) * y))/((y \<up> 2)*(7 * x + (-1) * y))";
1.723 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
1.724 -if (UnparseC.term t', UnparseC.terms asm) =
1.725 - ("(7 * x \<up> 3 + - 1 * x \<up> 2 * y) /\n(7 * x * y \<up> 2 + - 1 * y \<up> 3)", "[]")
1.726 -then () else error "rational.sml make_polynomial Schalk WN050929 not working";
1.727 -
1.728 -"-------- example 193a";
1.729 -val t = TermC.str2term "( x \<up> 2 + -6 * x + 9 ) / ( x \<up> 2 + -9 )";
1.730 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.731 -if (UnparseC.term t', UnparseC.terms asm) = ("(- 3 + x) / (3 + x)", "[\"3 + x \<noteq> 0\"]")
1.732 -then () else error "rational.sml cancel_p Schalk 193a";
1.733 -
1.734 -"-------- example 193b";
1.735 -val t = TermC.str2term "( x \<up> 2 + -8 * x + 16 ) / ( 2 * x \<up> 2 + -32 )";
1.736 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.737 -if (UnparseC.term t', UnparseC.terms asm) = ("(- 4 + x) / (8 + 2 * x)", "[\"8 + 2 * x \<noteq> 0\"]")
1.738 -then () else error "rational.sml cancel_p Schalk 193b";
1.739 -
1.740 -"-------- example 193c";
1.741 -val t = TermC.str2term "( 2 * x + -50 * x \<up> 3 ) / ( 25 * x \<up> 2 + -10 * x + 1 )";
1.742 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.743 -if (UnparseC.term t', UnparseC.terms asm) =
1.744 - ("(2 * x + 10 * x \<up> 2) / (1 + - 5 * x)", "[\"1 + - 5 * x \<noteq> 0\"]")
1.745 -then () else error "rational.sml cancel_p Schalk 193c";
1.746 -
1.747 -(*WN: improved with new numerals*)
1.748 -val t = TermC.str2term "(-25 + 9*x \<up> 2)/(5 + 3*x)";
1.749 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.750 -if (UnparseC.term t', UnparseC.terms asm) = ("(- 5 + 3 * x) / 1", "[]")
1.751 -then () else error "rational.sml cancel WN 1";
1.752 -
1.753 -"-------- example heuberger";
1.754 -val t = TermC.str2term ("(x \<up> 4 + x * y + x \<up> 3 * y + y \<up> 2) / " ^
1.755 - "(x + 5 * x \<up> 2 + y + 5 * x * y + x \<up> 2 * y \<up> 3 + x * y \<up> 4)");
1.756 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.757 -if (UnparseC.term t', UnparseC.terms asm) =
1.758 - ("(x \<up> 3 + y) / (1 + 5 * x + x * y \<up> 3)", "[\"1 + 5 * x + x * y \<up> 3 \<noteq> 0\"]")
1.759 -then () else error "rational.sml cancel_p heuberger";
1.760 -
1.761 -"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
1.762 -"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
1.763 -"-------- rewrite_set_ add_fractions_p from: Mathematik 1 Schalk -------------";
1.764 -(*deleted example 204 ... 236b at update Isabelle2012-->2013*)
1.765 -
1.766 -"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
1.767 -"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
1.768 -"-------- integration lev.1 -- lev.5: cancel_p_ & add_fractions_p_ -----------";
1.769 -val t = TermC.str2term ("123 = (a*x)/(b*x) + (c*x)/(d*x) + (e*x)/(f*x::real)");
1.770 -"-------- gcd_poly integration level 1: works on exact term";
1.771 -if NONE = cancel_p_ thy t then () else error "cancel_p_ works on exact fraction";
1.772 -if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ works on exact fraction";
1.773 -
1.774 -"-------- gcd_poly integration level 2: picks out ONE appropriate subterm";
1.775 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.776 -if UnparseC.term t' = "123 = a * x / (b * x) + c * x / (d * x) + e / f"
1.777 -then () else error "level 2, rewrite_set_ cancel_p: changed";
1.778 -val SOME (t', asm) = rewrite_set_ thy false add_fractions_p t;
1.779 -if UnparseC.term t' = "123 = (b * c * x + a * d * x) / (b * d * x) + e * x / (f * x)"
1.780 -then () else error "level 2, rewrite_set_ add_fractions_p: changed";
1.781 -
1.782 -"-------- gcd_poly integration level 3: rewrites all appropriate subterms";
1.783 -val SOME (t', asm) = rewrite_set_ thy false cancel_p_rls t;
1.784 -if UnparseC.term t' = "123 = a / b + c / d + e / f"
1.785 -then () else error "level 3, rewrite_set_ cancel_p_rls: changed";
1.786 -val SOME (t', asm) = rewrite_set_ thy false add_fractions_p_rls t; (*CREATE add_fractions_p_rls*)
1.787 -if UnparseC.term t' = "123 = (b * d * e * x + b * c * f * x + a * d * f * x) / (b * d * f * x)"
1.788 -then () else error "level 3, rewrite_set_ add_fractions_p_rls: changed";
1.789 -
1.790 -"-------- gcd_poly integration level 4: iteration cancel_p -- add_fraction_p";
1.791 -(* simpler variant *)
1.792 -val testrls = Rule_Set.append_rules "testrls" Rule_Set.empty [Rls_ cancel_p, Rls_ add_fractions_p]
1.793 -val SOME (t', asm) = rewrite_set_ thy false testrls t;
1.794 -(*Rewrite.trace_on := false;
1.795 -# rls: testrls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
1.796 -## rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
1.797 -## rls: add_fractions_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f
1.798 -## rls: cancel_p on: 123 = (b * c * x + a * d * x) / (b * d * x) + e / f
1.799 -## rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f
1.800 -## rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
1.801 -## rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
1.802 -if UnparseC.term t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
1.803 -then () else error "level 4, rewrite_set_ *_p: changed";
1.804 -
1.805 -(* complicated variant *)
1.806 -val testrls_rls = Rule_Set.append_rules "testrls_rls" Rule_Set.empty [Rls_ cancel_p_rls, Rls_ add_fractions_p_rls];
1.807 -val SOME (t', asm) = rewrite_set_ thy false testrls_rls t;
1.808 -(*# rls: testrls_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
1.809 -## rls: cancel_p_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
1.810 -### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x)
1.811 -### rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f
1.812 -### rls: cancel_p on: 123 = a * x / (b * x) + c / d + e / f
1.813 -### rls: cancel_p on: 123 = a / b + c / d + e / f
1.814 -## rls: add_fractions_p_rls on: 123 = a / b + c / d + e / f
1.815 -### rls: add_fractions_p on: 123 = a / b + c / d + e / f
1.816 -### rls: add_fractions_p on: 123 = (b * c + a * d) / (b * d) + e / f
1.817 -### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
1.818 -## rls: cancel_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
1.819 -### rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
1.820 -## rls: add_fractions_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)
1.821 -### rls: add_fractions_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
1.822 -if UnparseC.term t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
1.823 -then () else error "level 4, rewrite_set_ *_p_rls: changed"
1.824 -
1.825 -"-------- gcd_poly integration level 5: cancel_p & add_fraction_p within norm_Rational";
1.826 -val SOME (t', asm) = rewrite_set_ thy false norm_Rational t;
1.827 -if UnparseC.term t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)"
1.828 -then () else error "level 5, rewrite_set_ norm_Rational: changed"
1.829 -
1.830 -"-------- reverse rewrite ----------------------------------------------------";
1.831 -"-------- reverse rewrite ----------------------------------------------------";
1.832 -"-------- reverse rewrite ----------------------------------------------------";
1.833 -(** the term for which reverse rewriting is demonstrated **)
1.834 -val t = TermC.str2term "(9 + -1 * x \<up> 2) / (9 + 6 * x + x \<up> 2)";
1.835 -val Rrls {scr = Rfuns {init_state = ini, locate_rule = loc,
1.836 - next_rule = nex, normal_form = nor, ...},...} = cancel_p;
1.837 -
1.838 -(** normal_form produces the result in ONE step **)
1.839 - val SOME (t', _) = nor t;
1.840 -if UnparseC.term t' = "(3 + - 1 * x) / (3 + x)" then ()
1.841 -else error "rational.sml normal_form (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
1.842 -
1.843 -(** initialize the interpreter state used by the 'me' **)
1.844 - val (t, _, revsets, _) = ini t;
1.845 -
1.846 -if length (hd revsets) = 11 then () else error "length of revset changed";
1.847 -(*//----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)
1.848 -if (revsets |> nth 1 |> nth 1 |> id_of_thm) =
1.849 - (@{thm realpow_twoI} |> Thm.get_name_hint |> ThmC.cut_id)
1.850 -then () else error "first element of revset changed";
1.851 -if
1.852 -(revsets |> nth 1 |> nth 1 |> Rule.to_string) = "Thm (\"realpow_twoI\",?r1 \<up> 2 = ?r1 * ?r1)" andalso
1.853 -(revsets |> nth 1 |> nth 2 |> Rule.to_string) = "Thm (\"#: 9 = 3 \<up> 2\",9 = 3 \<up> 2)" andalso
1.854 -(revsets |> nth 1 |> nth 3 |> Rule.to_string) = "Thm (\"#: 6 * x = 2 * (3 * x)\",6 * x = 2 * (3 * x))"
1.855 -andalso
1.856 -(revsets |> nth 1 |> nth 4 |> Rule.to_string) = "Thm (\"#: -3 * x = -1 * (3 * x)\",-3 * x = -1 * (3 * x))"
1.857 -andalso
1.858 -(revsets |> nth 1 |> nth 5 |> Rule.to_string) = "Thm (\"#: 9 = 3 * 3\",9 = 3 * 3)" andalso
1.859 -(revsets |> nth 1 |> nth 6 |> Rule.to_string) = "Rls_ (\"sym_order_mult_rls_\")" andalso
1.860 -(revsets |> nth 1 |> nth 7 |> Rule.to_string) =
1.861 - "Thm (\"sym_mult.assoc\",?a * (?b * ?c) = ?a * ?b * ?c)"
1.862 -then () else error "first 7 elements in revset changed"
1.863 - \\----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)*)
1.864 -
1.865 -(** find the rule 'r' to apply to term 't' **)
1.866 -(*/------- WN1309: since cancel_ (accepted "-" between monomials) has been replaced by cancel_p_
1.867 - for Isabelle2013, we don't get a working revset, but non-termination:
1.868 -
1.869 - val SOME (r as (Thm (str, thm))) = nex revsets t;
1.870 - :
1.871 -((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x),
1.872 - Rls_ ("sym_order_mult_rls_"), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x), []))", "
1.873 -((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x),
1.874 - Thm ("sym_mult.assoc", ""), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x), []))", "
1.875 -((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x),
1.876 - Thm ("sym_mult.assoc", ""), ((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), []))", "
1.877 -((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), []))", "
1.878 - :
1.879 -### Isabelle2002:
1.880 - Thm ("sym_#mult_2_3", "6 = 2 * 3")
1.881 -### Isabelle2009-2 for cancel_ (not cancel_p_):
1.882 -if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))"
1.883 - andalso ThmC.string_of_thm thm =
1.884 - (string_of_thm (Thm.make_thm @{theory "Isac_Knowledge"}
1.885 - (Trueprop $ (Thm.term_of o the o (TermC.parse thy)) "9 = 3 \<up> 2"))) then ()
1.886 -else error "rational.sml next_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
1.887 -\---------------------------------------------------------------------------------------/*)
1.888 -
1.889 -(** check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
1.890 - if the rule is OK, the term resulting from applying the rule is returned,too;
1.891 - there might be several rule applications inbetween,
1.892 - which are listed after the head in reverse order **)
1.893 -(*/-------------------------------------------- Isabelle2013: this gives "error id_of_thm";
1.894 - we don't repair this, because interaction within "reverse rewriting" never worked properly:
1.895 -
1.896 - val (r, (t, asm))::_ = loc revsets t r;
1.897 -if UnparseC.term t = "(9 - x \<up> 2) / (3 \<up> 2 + 6 * x + x \<up> 2)" andalso asm = []
1.898 -then () else error "rational.sml locate_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
1.899 -
1.900 -(* find the next rule to apply *)
1.901 - val SOME (r as (Thm (str, thm))) = nex revsets t;
1.902 -if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso
1.903 - ThmC.string_of_thm thm = (string_of_thm (ThmC_Def.make_thm @{theory "Isac_Knowledge"}
1.904 - (Trueprop $ (Thm.term_of o the o (TermC.parse thy)) "9 = 3 \<up> 2"))) then ()
1.905 -else error "rational.sml next_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2)";
1.906 -
1.907 -(*check the next rule*)
1.908 - val (r, (t, asm)) :: _ = loc revsets t r;
1.909 -if UnparseC.term t = "(3 \<up> 2 - x \<up> 2) / (3 \<up> 2 + 6 * x + x \<up> 2)" then ()
1.910 -else error "rational.sml locate_rule (9 - x \<up> 2) / (9 - 6 * x + x \<up> 2) II";
1.911 -
1.912 -(*find and check the next rules, rewrite*)
1.913 - val SOME r = nex revsets t;
1.914 - val (r,(t,asm))::_ = loc revsets t r;
1.915 -if UnparseC.term t = "(3 \<up> 2 - x \<up> 2) / (3 \<up> 2 + 2 * 3 * x + x \<up> 2)" then ()
1.916 -else error "rational.sml locate_rule II";
1.917 -
1.918 - val SOME r = nex revsets t;
1.919 - val (r,(t,asm))::_ = loc revsets t r;
1.920 -if UnparseC.term t = "(3 - x) * (3 + x) / (3 \<up> 2 + 2 * 3 * x + x \<up> 2)" then ()
1.921 -else error "rational.sml next_rule II";
1.922 -
1.923 - val SOME r = nex revsets t;
1.924 - val (r,(t,asm))::_ = loc revsets t r;
1.925 -if UnparseC.term t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then ()
1.926 -else error "rational.sml next_rule III";
1.927 -
1.928 - val SOME r = nex revsets t;
1.929 - val (r, (t, asm)) :: _ = loc revsets t r;
1.930 - val ss = UnparseC.term t;
1.931 -if ss = "(3 - x) / (3 + x)" andalso UnparseC.terms asm = "[\"3 + x ~= 0\"]" then ()
1.932 -else error "rational.sml: new behav. in rev-set cancel";
1.933 -\--------------------------------------------------------------------------------------/*)
1.934 -
1.935 -"-------- 'reverse-ruleset' cancel_p -----------------------------------------";
1.936 -"-------- 'reverse-ruleset' cancel_p -----------------------------------------";
1.937 -"-------- 'reverse-ruleset' cancel_p -----------------------------------------";
1.938 -(*WN130909: the example below shows, why "reverse rewriting" only worked for
1.939 - special cases.*)
1.940 -
1.941 -(*the term for which reverse rewriting is demonstrated*)
1.942 -val t = TermC.str2term "(9 + (-1)*x \<up> 2) / (9 + ((-6)*x + x \<up> 2))";
1.943 -val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
1.944 - next_rule=nex,normal_form=nor,...},...} = cancel_p;
1.945 -
1.946 -(*normal_form produces the result in ONE step*)
1.947 -val SOME (t', _) = nor t;
1.948 -if UnparseC.term t' = "(3 + x) / (3 + - 1 * x)"
1.949 -then () else error "cancel_p normal_form CHANGED";;
1.950 -
1.951 -(*initialize the interpreter state used by the 'me'*)
1.952 -val SOME (t', asm) = cancel_p_ thy t;
1.953 -if (UnparseC.term t', UnparseC.terms asm) = ("(3 + x) / (3 + - 1 * x)", "[\"3 + - 1 * x \<noteq> 0\"]")
1.954 -then () else error "cancel_p CHANGED";;
1.955 -
1.956 -val (t,_,revsets,_) = ini t;
1.957 -
1.958 -(* WN.10.10.02: dieser Fall terminiert nicht
1.959 - (make_polynomial enth"alt zu viele rules)
1.960 -WN060823 'init_state' requires rewriting on specified location in the term
1.961 -default_print_depth 99; Rfuns; default_print_depth 3;
1.962 -WN060831 cycling "sym_order_mult_rls_" "sym_mult.assoc"
1.963 - as was with make_polynomial before ?!?* )
1.964 -
1.965 -val SOME r = nex revsets t;
1.966 -eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))",
1.967 - mk_thm thy "9 = 3 \<up> 2"));
1.968 -( *WN060831 *** id_of_thm
1.969 - Exception- ERROR raised ...
1.970 -val (r,(t,asm))::_ = loc revsets t r;
1.971 -UnparseC.term t;
1.972 -
1.973 - val SOME r = nex revsets t;
1.974 - val (r,(t,asm))::_ = loc revsets t r;
1.975 - UnparseC.term t;
1.976 -*)
1.977 -
1.978 -"-------- examples: rls norm_Rational ----------------------------------------";
1.979 -"-------- examples: rls norm_Rational ----------------------------------------";
1.980 -"-------- examples: rls norm_Rational ----------------------------------------";
1.981 -val t = TermC.str2term "(3*x+5)/18 - x/2 - -(3*x - 2)/9 = 0";
1.982 -val SOME (t', _) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1.983 -if UnparseC.term t' = "1 / 18 = 0" then () else error "rational.sml 1";
1.984 -
1.985 -val t = TermC.str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0";
1.986 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1.987 -if UnparseC.term t' = "(237 + 65 * x) / 36 = 0" then ()
1.988 -else error "rational.sml 2";
1.989 -
1.990 -val t = TermC.str2term "(1/2 + (5*x)/2) \<up> 2 - ((13*x)/2 - 5/2) \<up> 2 - (6*x) \<up> 2 + 29";
1.991 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1.992 -if UnparseC.term t' = "23 + 35 * x + - 72 * x \<up> 2" then ()
1.993 -else error "rational.sml 3";
1.994 -
1.995 -(*Rewrite.trace_on:=true;*)
1.996 -val t = TermC.str2term "Not (6*x is_atom)";
1.997 -val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t';
1.998 -"HOL.True";
1.999 -val t = TermC.str2term "1 < 2";
1.1000 -val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t';
1.1001 -"HOL.True";
1.1002 -
1.1003 -val t = TermC.str2term "(6*x) \<up> 2";
1.1004 -val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false
1.1005 - (ThmC.numerals_to_Free @{thm realpow_def_atom}) t;
1.1006 -if UnparseC.term t' = "6 * x * (6 * x) \<up> (2 + - 1)" then ()
1.1007 -else error "rational.sml powers_erls (6*x) \<up> 2";
1.1008 -
1.1009 -val t = TermC.str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))";
1.1010 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1.1011 -if UnparseC.term t' = "65 * x / 2" then () else error "rational.sml 4";
1.1012 -
1.1013 -val t = TermC.str2term "1 - ((13*x)/2 - 5/2) \<up> 2";
1.1014 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1.1015 -if UnparseC.term t' = "(- 21 + 130 * x + - 169 * x \<up> 2) / 4" then ()
1.1016 -else error "rational.sml 5";
1.1017 -
1.1018 -(*SRAM Schalk I, p.92 Nr. 609a*)
1.1019 -val t = TermC.str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
1.1020 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1.1021 -if UnparseC.term t' = "(- 255 + 112 * x) / 135" then ()
1.1022 -else error "rational.sml 6";
1.1023 -
1.1024 -(*SRAM Schalk I, p.92 Nr. 610c*)
1.1025 -val t = TermC.str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
1.1026 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1.1027 -if UnparseC.term t' = "(3 + x) / - 2" then () else error "rational.sml 7";
1.1028 -
1.1029 -(*SRAM Schalk I, p.92 Nr. 476a*)
1.1030 -val t = TermC.str2term "(x \<up> 2/(1 - x \<up> 2) + 1)/(x/(1 - x) + 1) * (1 + x)";
1.1031 -(*. a/b : c/d translated to a/b * d/c .*)
1.1032 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1.1033 -if UnparseC.term t' = "1" then () else error "rational.sml 8";
1.1034 -
1.1035 -(*Schalk I, p.92 Nr. 472a*)
1.1036 -val t = TermC.str2term "((8*x \<up> 2 - 32*y \<up> 2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
1.1037 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1.1038 -if UnparseC.term t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
1.1039 -
1.1040 -(*Schalk I, p.70 Nr. 480b: SEE rational.sml --- nonterminating rls norm_Rational ---*)
1.1041 -
1.1042 -(*WN130910 add_fractions_p exception Div raised + history:
1.1043 -### WN.2.6.03 from rlang.sml 56a
1.1044 -val t = TermC.str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a \<up> 2 + -1 * b \<up> 2)";
1.1045 -val NONE = rewrite_set_ thy false add_fractions_p t;
1.1046 -
1.1047 -THE ERROR ALREADY OCCURS IN THIS PART:
1.1048 -val t = TermC.str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
1.1049 -val NONE = add_fraction_p_ thy t;
1.1050 -
1.1051 -SEE Test_Some.thy: section {* add_fractions_p downto exception Div raised ===
1.1052 -*)
1.1053 -
1.1054 -"-------- rational numerals --------------------------------------------------";
1.1055 -"-------- rational numerals --------------------------------------------------";
1.1056 -"-------- rational numerals --------------------------------------------------";
1.1057 -(*SRA Schalk I, p.40 Nr. 164b *)
1.1058 -val t = TermC.str2term "(47/6 - 76/9 + 13/4)/(35/12)";
1.1059 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1060 -if UnparseC.term t = "19 / 21" then ()
1.1061 -else error "rational.sml: diff.behav. in norm_Rational_mg 1";
1.1062 -
1.1063 -(*SRA Schalk I, p.40 Nr. 166a *)
1.1064 -val t = TermC.str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
1.1065 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1066 -if UnparseC.term t = "45 / 2" then ()
1.1067 -else error "rational.sml: diff.behav. in norm_Rational_mg 2";
1.1068 -
1.1069 -"-------- examples cancellation from: Mathematik 1 Schalk --------------------";
1.1070 -"-------- examples cancellation from: Mathematik 1 Schalk --------------------";
1.1071 -"-------- examples cancellation from: Mathematik 1 Schalk --------------------";
1.1072 -(* e190c Stefan K.*)
1.1073 -val t = TermC.str2term "((1 + 9*a \<up> 2) * (1 + 3*a)) / ((3*a + 9*a \<up> 2) * (1 + 3*a))";
1.1074 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1075 -if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
1.1076 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
1.1077 -
1.1078 -(* e192b Stefan K.*)
1.1079 -val t = TermC.str2term "(x \<up> 2 * (7*x + (-1)*y)) / (y \<up> 2 * (7*x + (-1)*y))";
1.1080 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1081 -if UnparseC.term t = "x \<up> 2 / y \<up> 2"
1.1082 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
1.1083 -
1.1084 -(*SRC Schalk I, p.66 Nr. 379c *)
1.1085 -val t = TermC.str2term "(a - b)/(b - a)";
1.1086 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1087 -if UnparseC.term t = "- 1"
1.1088 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
1.1089 -
1.1090 -(*SRC Schalk I, p.66 Nr. 380b *)
1.1091 -val t = TermC.str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))";
1.1092 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1093 -if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)"
1.1094 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
1.1095 -
1.1096 -(*Schalk I, p.60 Nr. 215c *)
1.1097 -val t = TermC.str2term "(a + b) \<up> 4 * (x - y) / ((x - y) \<up> 3 * (a + b) \<up> 2)";
1.1098 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1099 -if UnparseC.term t = "(a \<up> 2 + 2 * a * b + b \<up> 2) / (x \<up> 2 + - 2 * x * y + y \<up> 2)"
1.1100 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 7";
1.1101 -
1.1102 -(*SRC Schalk I, p.66 Nr. 381b *)
1.1103 -val t = TermC.str2term
1.1104 -"(4*x \<up> 2 - 20*x + 25)/(2*x - 5) \<up> 3";
1.1105 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1106 -if UnparseC.term t = "1 / (- 5 + 2 * x)"
1.1107 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 9";
1.1108 -
1.1109 -(* e190c Stefan K.*)
1.1110 -val t = TermC.str2term "((1 + 9*a \<up> 2) * (1 + 3*a)) / ((3*a + 9*a \<up> 2) * (1 + 3 * a))";
1.1111 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1112 -if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
1.1113 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
1.1114 -
1.1115 -(* e192b Stefan K.*)
1.1116 -val t = TermC.str2term "(x \<up> 2 * (7*x + (-1)*y)) / (y \<up> 2 * (7*x + (-1)*y))";
1.1117 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1118 -if UnparseC.term t = "x \<up> 2 / y \<up> 2"
1.1119 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
1.1120 -
1.1121 -(*SRC Schalk I, p.66 Nr. 379c *)
1.1122 -val t = TermC.str2term "(a - b) / (b - a)";
1.1123 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1124 -if UnparseC.term t = "- 1"
1.1125 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
1.1126 -
1.1127 -(*SRC Schalk I, p.66 Nr. 380b *)
1.1128 -val t = TermC.str2term "15*(3*x + 3) * (4*x + 9) / (12*(2*x + 7) * (5*x + 5))";
1.1129 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1130 -if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)"
1.1131 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
1.1132 -
1.1133 -(*Schalk I, p.60 Nr. 215c *)
1.1134 -val t = TermC.str2term "(a + b) \<up> 4 * (x - y) / ((x - y) \<up> 3 * (a + b) \<up> 2)";
1.1135 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1136 -if UnparseC.term t = "(a \<up> 2 + 2 * a * b + b \<up> 2) / (x \<up> 2 + - 2 * x * y + y \<up> 2)"
1.1137 -then () else error "Schalk I, p.60 Nr. 215c: with Isabelle2002 cancellation incomplete, changed";
1.1138 -
1.1139 -(* extreme example from somewhere *)
1.1140 -val t = TermC.str2term
1.1141 - ("(a \<up> 4 * x + -1*a \<up> 4 * y + 4*a \<up> 3 * b * x + -4*a \<up> 3 * b * y + " ^
1.1142 - "6*a \<up> 2 * b \<up> 2 * x + -6*a \<up> 2 * b \<up> 2 * y + 4*a * b \<up> 3 * x + -4*a * b \<up> 3 * y + " ^
1.1143 - "b \<up> 4 * x + -1*b \<up> 4 * y) " ^
1.1144 - " / (a \<up> 2 * x \<up> 3 + -3*a \<up> 2 * x \<up> 2 * y + 3*a \<up> 2 * x * y \<up> 2 + -1*a \<up> 2 * y \<up> 3 + " ^
1.1145 - "2*a * b * x \<up> 3 + -6*a * b * x \<up> 2 * y + 6*a * b * x * y \<up> 2 + -2*a * b * y \<up> 3 + " ^
1.1146 - "b \<up> 2 * x \<up> 3 + -3*b \<up> 2 * x \<up> 2 * y + 3*b \<up> 2 * x * y \<up> 2 + -1*b \<up> 2 * y \<up> 3)")
1.1147 -val SOME (t, _) = rewrite_set_ thy false cancel_p t;
1.1148 -if UnparseC.term t = "(a \<up> 2 + 2 * a * b + b \<up> 2) / (x \<up> 2 + - 2 * x * y + y \<up> 2)"
1.1149 -then () else error "with Isabelle2002: NONE -- now SOME changed";
1.1150 -
1.1151 -(*Schalk I, p.66 Nr. 381a *)
1.1152 -(* ATTENTION: here the rls is very slow. In Isabelle2002 this required 2 min *)
1.1153 -val t = TermC.str2term "18*(a + b) \<up> 3 * (a - b) \<up> 2 / (72*(a - b) \<up> 3 * (a + b) \<up> 2)";
1.1154 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1155 -if UnparseC.term t = "(a + b) / (4 * a + - 4 * b)"
1.1156 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
1.1157 -
1.1158 -(*SRC Schalk I, p.66 Nr. 381b *)
1.1159 -val t = TermC.str2term "(4*x \<up> 2 - 20*x + 25) / (2*x - 5) \<up> 3";
1.1160 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1161 -if UnparseC.term t = "1 / (- 5 + 2 * x)"
1.1162 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 9";
1.1163 -
1.1164 -(*SRC Schalk I, p.66 Nr. 381c *)
1.1165 -val t = TermC.str2term "(27*a \<up> 3 + 9*a \<up> 2+3*a+1) / (27*a \<up> 3 + 18*a \<up> 2+3*a)";
1.1166 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1167 -if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
1.1168 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 10";
1.1169 -
1.1170 -(*SRC Schalk I, p.66 Nr. 383a *)
1.1171 -val t = TermC.str2term "(5*a \<up> 2 - 5*a*b) / (a - b) \<up> 2";
1.1172 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1173 -if UnparseC.term t = "- 5 * a / (- 1 * a + b)"
1.1174 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 11";
1.1175 -
1.1176 -"----- NOT TERMINATING ?: worked before 0707xx";
1.1177 -val t = TermC.str2term "(a \<up> 2 - 1)*(b + 1) / ((b \<up> 2 - 1)*(a+1))";
1.1178 -(* WN130911 "exception Div raised" by
1.1179 - cancel_p_ thy (TermC.str2term ("(-1 + -1 * b + a \<up> 2 + a \<up> 2 * b) /" ^
1.1180 - "(-1 + -1 * a + b \<up> 2 + a * b \<up> 2)"))
1.1181 -
1.1182 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1183 -if UnparseC.term t = "(1 + -1 * a) / (1 + -1 * b)" then ()
1.1184 -else error "rational.sml MG tests 3e";
1.1185 -*)
1.1186 -
1.1187 -"-------- examples common denominator from: Mathematik 1 Schalk --------------";
1.1188 -"-------- examples common denominator from: Mathematik 1 Schalk --------------";
1.1189 -"-------- examples common denominator from: Mathematik 1 Schalk --------------";
1.1190 -(*SRA Schalk I, p.67 Nr. 403a *)
1.1191 -val t = TermC.str2term "4/x - 3/y - 1";
1.1192 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1193 -if UnparseC.term t = "(- 3 * x + 4 * y + - 1 * x * y) / (x * y)"
1.1194 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 12";
1.1195 -
1.1196 -val t = TermC.str2term "(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a \<up> 2+3*b*c)/(a*b*c)";
1.1197 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1198 -if UnparseC.term t = "4 / c"
1.1199 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 13";
1.1200 -
1.1201 -(*SRA Schalk I, p.67 Nr. 410b *)
1.1202 -val t = TermC.str2term "1/(x+1) + 1/(x+2) - 2/(x+3)";
1.1203 -(* WN130911 non-termination due to non-termination of
1.1204 - cancel_p_ thy (TermC.str2term "(5 + 3 * x) / (6 + 11 * x + 6 * x \<up> 2 + x \<up> 3)")
1.1205 -
1.1206 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1207 -if UnparseC.term t = "(5 + 3 * x) / (6 + 11 * x + 6 * x \<up> 2 + x \<up> 3)"
1.1208 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 14";
1.1209 -*)
1.1210 -
1.1211 -(*SRA Schalk I, p.67 Nr. 413b *)
1.1212 -val t = TermC.str2term "(1 + x)/(1 - x) - (1 - x)/(1 + x) + 2*x/(1 - x \<up> 2)";
1.1213 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1214 -if UnparseC.term t = "6 * x / (1 + - 1 * x \<up> 2)"
1.1215 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 15";
1.1216 -
1.1217 -(*SRA Schalk I, p.68 Nr. 414a *)
1.1218 -val t = TermC.str2term "(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))";
1.1219 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1220 -if UnparseC.term t ="(- 2 + - 5 * x + 2 * x \<up> 2) / (2 + - 3 * x + x \<up> 2)"
1.1221 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 16";
1.1222 -
1.1223 -(*SRA Schalk I, p.68 Nr. 428b *)
1.1224 -val t = TermC.str2term
1.1225 - "1/(a - b) \<up> 2 + 1/(a + b) \<up> 2 - 2/(a \<up> 2 - b \<up> 2) - 4*(b \<up> 2 - 1)/(a \<up> 2 - b \<up> 2) \<up> 2";
1.1226 -(* WN130911 non-termination due to non-termination of
1.1227 - cancel_p_ thy (TermC.str2term "(4 + -4 * b \<up> 2) / (a \<up> 4 + -2 * (a \<up> 2 * b \<up> 2) + b \<up> 4)")
1.1228 -
1.1229 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1230 -if UnparseC.term t = "4 / (a \<up> 4 + -2 * a \<up> 2 * b \<up> 2 + b \<up> 4)"
1.1231 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 18";
1.1232 -*)
1.1233 -
1.1234 -(*SRA Schalk I, p.68 Nr. 430b *)
1.1235 -val t = TermC.str2term
1.1236 - "a \<up> 2/(a - 3*b) - 108*a*b \<up> 3/((a+3*b)*(a \<up> 2 - 9*b \<up> 2)) - 9*b \<up> 2*(a - 3*b)/(a+3*b) \<up> 2";
1.1237 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1238 -if UnparseC.term t = "a + 3 * b"
1.1239 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 19";
1.1240 -
1.1241 -(*SRA Schalk I, p.68 Nr. 432 *)
1.1242 -val t = TermC.str2term
1.1243 - ("(a \<up> 2 + a*b) / (a \<up> 2 - b \<up> 2) - (b \<up> 2 - a*b) / (b \<up> 2 - a \<up> 2) + " ^
1.1244 - "a \<up> 2*(a - b) / (a \<up> 3 - a \<up> 2*b) - 2*a*(a \<up> 2 - b \<up> 2) / (a \<up> 3 - a*b \<up> 2) - " ^
1.1245 - "2*b \<up> 2 / (a \<up> 2 - b \<up> 2)");
1.1246 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1247 -if UnparseC.term t = (*"0" ..isabisac15 | Isabelle2017..*) "0 / (a \<up> 2 + - 1 * b \<up> 2)"
1.1248 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 20";
1.1249 -
1.1250 -(* some example *)
1.1251 -val t = TermC.str2term "3*a / (a*b) + x/y";
1.1252 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1253 -if UnparseC.term t = "(3 * y + b * x) / (b * y)"
1.1254 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 21";
1.1255 -
1.1256 -
1.1257 -"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1.1258 -"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1.1259 -"-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
1.1260 -(*------- SRM Schalk I, p.68 Nr. 436a *)
1.1261 -val t = TermC.str2term "3*(x+y) / (15*(x - y)) * 25*(x - y) \<up> 2 / (18*(x + y) \<up> 2)";
1.1262 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1263 -if UnparseC.term t = "(- 5 * x + 5 * y) / (- 18 * x + - 18 * y)"
1.1264 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 22";
1.1265 -
1.1266 -(*------- SRM.test Schalk I, p.68 Nr. 436b *)
1.1267 -val t = TermC.str2term "5*a*(a - b) \<up> 2*(a + b) \<up> 3/(7*b*(a - b) \<up> 3) * 7*b/(a + b) \<up> 3";
1.1268 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1269 -if UnparseC.term t = "5 * a / (a + - 1 * b)"
1.1270 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 23";
1.1271 -
1.1272 -(*------- Schalk I, p.68 Nr. 437a *)
1.1273 -val t = TermC.str2term "(3*a - 4*b) / (4*c+3*e) * (3*a+4*b)/(9*a \<up> 2 - 16*b \<up> 2)";
1.1274 -(* raises an exception for unclear reasons:
1.1275 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1276 -:
1.1277 -### rls: cancel_p on: (9 * a \<up> 2 + -16 * b \<up> 2) / (4 * c + 3 * e) /
1.1278 -(9 * a \<up> 2 + -16 * b \<up> 2)
1.1279 -exception Div raised
1.1280 -
1.1281 -BUT
1.1282 -val t = TermC.str2term
1.1283 - ("(9 * a \<up> 2 + -16 * b \<up> 2) / (4 * c + 3 * e) /" ^
1.1284 - "(9 * a \<up> 2 + -16 * b \<up> 2)");
1.1285 -NONE = cancel_p_ thy t;
1.1286 -
1.1287 -if UnparseC.term t = "1 / (4 * c + 3 * e)" then ()
1.1288 -else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1.1289 -*)
1.1290 -
1.1291 -"----- S.K. corrected non-termination 060904";
1.1292 -val t = TermC.str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a \<up> 2 - 16*b \<up> 2))";
1.1293 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
1.1294 -if UnparseC.term t =
1.1295 - "(9 * a \<up> 2 + - 16 * b \<up> 2) /\n(36 * a \<up> 2 * c + 27 * a \<up> 2 * e + - 64 * b \<up> 2 * c +\n - 48 * b \<up> 2 * e)"
1.1296 -then () else error "rational.sml: S.K.8..corrected 060904-6";
1.1297 -
1.1298 -"----- S.K. corrected non-termination of cancel_p_";
1.1299 -val t'' = TermC.str2term ("(9 * a \<up> 2 + -16 * b \<up> 2) /" ^
1.1300 - "(36 * a \<up> 2 * c + (27 * a \<up> 2 * e + (-64 * b \<up> 2 * c + -48 * b \<up> 2 * e)))");
1.1301 -(* /--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------\
1.1302 -val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
1.1303 -if UnparseC.term t' = "1 / (4 * c + 3 * e)"
1.1304 -then () else error "rational.sml: diff.behav. in cancel_p S.K.8";
1.1305 - \--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------/*)
1.1306 -
1.1307 -(*------- Schalk I, p.68 Nr. 437b*)
1.1308 -val t = TermC.str2term "(a + b)/(x \<up> 2 - y \<up> 2) * ((x - y) \<up> 2/(a \<up> 2 - b \<up> 2))";
1.1309 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1310 -:
1.1311 -#### rls: cancel_p on: (a * x \<up> 2 + -2 * (a * (x * y)) + a * y \<up> 2 + b * x \<up> 2 +
1.1312 - -2 * (b * (x * y)) +
1.1313 - b * y \<up> 2) /
1.1314 -(a \<up> 2 * x \<up> 2 + -1 * (a \<up> 2 * y \<up> 2) + -1 * (b \<up> 2 * x \<up> 2) +
1.1315 - b \<up> 2 * y \<up> 2)
1.1316 -exception Div raised
1.1317 -*)
1.1318 -
1.1319 -(*------- SRM Schalk I, p.68 Nr. 438a *)
1.1320 -val t = TermC.str2term "x*y / (x*y - y \<up> 2) * (x \<up> 2 - x*y)";
1.1321 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1322 -if UnparseC.term t = "x \<up> 2"
1.1323 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 24";
1.1324 -
1.1325 -(*------- SRM Schalk I, p.68 Nr. 439b *)
1.1326 -val t = TermC.str2term "(4*x \<up> 2 + 4*x + 1) * ((x \<up> 2 - 2*x \<up> 3) / (4*x \<up> 2 + 2*x))";
1.1327 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1328 -if UnparseC.term t = "(x + - 4 * x \<up> 3) / 2"
1.1329 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 25";
1.1330 -
1.1331 -(*------- SRM Schalk I, p.68 Nr. 440a *)
1.1332 -val t = TermC.str2term "(x \<up> 2 - 2*x) / (x \<up> 2 - 3*x) * (x - 3) \<up> 2 / (x \<up> 2 - 4)";
1.1333 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1334 -if UnparseC.term t = "(- 3 + x) / (2 + x)"
1.1335 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 26";
1.1336 -
1.1337 -"----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
1.1338 -val t = TermC.str2term "(a \<up> 3 - 9*a) / (a \<up> 3*b - a*b \<up> 3) * (a \<up> 2*b + a*b \<up> 2) / (a+3)";
1.1339 -(* WN130911 non-termination for unclear reasons:
1.1340 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1341 -
1.1342 -... ENDS WITH THIS TRACE:
1.1343 -:
1.1344 -### rls: cancel_p on: (-9 * (a \<up> 3 * b) + -9 * (a \<up> 2 * b \<up> 2) + a \<up> 5 * b +
1.1345 - a \<up> 4 * b \<up> 2) /
1.1346 -(a \<up> 3 * b + -1 * (a * b \<up> 3)) /
1.1347 -(3 + a)
1.1348 -BUT THIS IS CORRECTLY RECOGNISED
1.1349 -val t = TermC.str2term
1.1350 - ("(-9 * (a \<up> 3 * b) + -9 * (a \<up> 2 * b \<up> 2) + a \<up> 5 * b + a \<up> 4 * b \<up> 2) /" ^
1.1351 - "(a \<up> 3 * b + -1 * (a * b \<up> 3)) / (3 + (a::real))");
1.1352 -AS
1.1353 -NONE = cancel_p_ thy t;
1.1354 -
1.1355 -if UnparseC.term t = "(-3 * a + a \<up> 2) / (a + -1 * b)" then ()
1.1356 -else error "rational.sml: diff.behav. in norm_Rational 27";
1.1357 -*)
1.1358 -
1.1359 -"----- SK12 works since 0707xx";
1.1360 -val t = TermC.str2term "(a \<up> 3 - 9*a) * (a \<up> 2*b+a*b \<up> 2) / ((a \<up> 3*b - a*b \<up> 3) * (a+3))";
1.1361 -(* WN130911 non-termination due to non-termination of
1.1362 - cancel_p_ thy (TermC.str2term "(4 + -4 * b \<up> 2) / (a \<up> 4 + -2 * (a \<up> 2 * b \<up> 2) + b \<up> 4)")
1.1363 -
1.1364 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1365 -if UnparseC.term t' = "(-3 * a + a \<up> 2) / (a + -1 * b)" then ()
1.1366 -else error "rational.sml: diff.behav. in norm_Rational 28";
1.1367 -*)
1.1368 -
1.1369 -"-------- examples common denominator and multiplication from: Schalk --------";
1.1370 -"-------- examples common denominator and multiplication from: Schalk --------";
1.1371 -"-------- examples common denominator and multiplication from: Schalk --------";
1.1372 -(*------- SRAM Schalk I, p.69 Nr. 441b *)
1.1373 -val t = TermC.str2term "(4*a/3 + 3*b \<up> 2/a \<up> 3 + b/(4*a))*(4*b/(3*a))";
1.1374 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1375 -if UnparseC.term t = "(36 * b \<up> 3 + 3 * a \<up> 2 * b \<up> 2 + 16 * a \<up> 4 * b) /\n(9 * a \<up> 4)"
1.1376 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
1.1377 -
1.1378 -(*------- SRAM Schalk I, p.69 Nr. 442b *)
1.1379 -val t = TermC.str2term ("(15*a \<up> 2/x \<up> 3 - 5*b \<up> 4/x \<up> 2 + 25*c \<up> 2/x) * " ^
1.1380 - "(x \<up> 3/(5*a*b \<up> 3*c \<up> 3)) + 1/c \<up> 3 * (b*x/a - 3*a/b \<up> 3)");
1.1381 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1382 -if UnparseC.term t = "5 * x \<up> 2 / (a * b \<up> 3 * c)"
1.1383 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
1.1384 -
1.1385 -(*------- SRAM Schalk I, p.69 Nr. 443b *)
1.1386 -val t = TermC.str2term "(a/2 + b/3) * (b/3 - a/2)";
1.1387 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1388 -if UnparseC.term t = "(- 9 * a \<up> 2 + 4 * b \<up> 2) / 36"
1.1389 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
1.1390 -
1.1391 -(*------- SRAM Schalk I, p.69 Nr. 445b *)
1.1392 -val t = TermC.str2term "(a \<up> 2/9 + 2*a/(3*b) + 4/b \<up> 2)*(a/3 - 2/b) + 8/b \<up> 3";
1.1393 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1394 -if UnparseC.term t = "a \<up> 3 / 27"
1.1395 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
1.1396 -
1.1397 -(*------- SRAM Schalk I, p.69 Nr. 446b *)
1.1398 -val t = TermC.str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x \<up> 2 - 16*y \<up> 2)";
1.1399 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1400 -if UnparseC.term t = (*"30 * x \<up> 2 + -9 * x * y + -20 * y \<up> 2" ..isabisac15 | Isabelle2017..*)
1.1401 - "(- 30 * x \<up> 2 + 9 * x * y + 20 * y \<up> 2) / - 1"
1.1402 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 32";
1.1403 -
1.1404 -(*------- SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
1.1405 -val t = TermC.str2term
1.1406 -"(2*x \<up> 2/(3*y)+x/y \<up> 2)*(4*x \<up> 4/(9*y \<up> 2)+x \<up> 2/y \<up> 4)*(2*x \<up> 2/(3*y) - x/y \<up> 2)";
1.1407 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1408 -if UnparseC.term t = "(- 81 * x \<up> 4 + 16 * x \<up> 8 * y \<up> 4) / (81 * y \<up> 8)"
1.1409 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
1.1410 -
1.1411 -(*------- SRAM Schalk I, p.69 Nr. 450a *)
1.1412 -val t = TermC.str2term
1.1413 -"(4*x/(3*y)+2*y/(3*x)) \<up> 2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
1.1414 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1415 -if UnparseC.term t = "(52 * x \<up> 2 + 16 * y \<up> 2) / (9 * y \<up> 2)"
1.1416 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 34";
1.1417 -
1.1418 -(*------- SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*)
1.1419 -val t = TermC.str2term
1.1420 - ("(15*a \<up> 4/(a*x \<up> 3) - 5*a*((b \<up> 4 - 5*c \<up> 2*x) / x \<up> 2)) * " ^
1.1421 - "(x \<up> 3/(5*a*b \<up> 3*c \<up> 3)) + a/c \<up> 3 * (x*(b/a) - 3*b*(a/b \<up> 4))");
1.1422 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1423 -if UnparseC.term t = "5 * x \<up> 2 / (b \<up> 3 * c)"
1.1424 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 53";
1.1425 -
1.1426 -
1.1427 -"-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1.1428 -"-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1.1429 -"-------- examples double fractions from: Mathematik 1 Schalk ----------------";
1.1430 -"----- SRD Schalk I, p.69 Nr. 454b";
1.1431 -val t = TermC.str2term "((2 - x)/(2*a)) / (2*a/(x - 2))";
1.1432 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1433 -if UnparseC.term t = "(- 4 + 4 * x + - 1 * x \<up> 2) / (4 * a \<up> 2)"
1.1434 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 35";
1.1435 -
1.1436 -"----- SRD Schalk I, p.69 Nr. 455a";
1.1437 -val t = TermC.str2term "(a \<up> 2 + 1)/(a \<up> 2 - 1) / ((a+1)/(a - 1))";
1.1438 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1439 -if UnparseC.term t = "(1 + a \<up> 2) / (1 + 2 * a + a \<up> 2)" then ()
1.1440 -else error "rational.sml: diff.behav. in norm_Rational_mg 36";
1.1441 -
1.1442 -"----- Schalk I, p.69 Nr. 455b";
1.1443 -val t = TermC.str2term "(x \<up> 2 - 4)/(y \<up> 2 - 9)/((2+x)/(3 - y))";
1.1444 -(* WN130911 non-termination due to non-termination of
1.1445 - cancel_p_ thy (TermC.str2term ("(-12 + 4 * y + 3 * x \<up> 2 + -1 * (x \<up> 2 * y)) /" ^
1.1446 - "(-18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)"))
1.1447 -
1.1448 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1449 -if UnparseC.term t = "(2 + -1 * x) / (3 + y)" then ()
1.1450 -else error "rational.sml: diff.behav. in norm_Rational_mg 37";
1.1451 -*)
1.1452 -
1.1453 -"----- SK060904-1a non-termination of cancel_p_ ?: worked before 0707xx";
1.1454 -val t = TermC.str2term "(x \<up> 2 - 4)*(3 - y) / ((y \<up> 2 - 9)*(2+x))";
1.1455 -(* WN130911 non-termination due to non-termination of
1.1456 - cancel_p_ thy (TermC.str2term ("(-12 + 4 * y + 3 * x \<up> 2 + -1 * (x \<up> 2 * y)) /" ^
1.1457 - "(-18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)"))
1.1458 -
1.1459 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1460 -if UnparseC.term t = "(2 + -1 * x) / (3 + y)" then ()
1.1461 -else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
1.1462 -*)
1.1463 -
1.1464 -"----- ?: worked before 0707xx";
1.1465 -val t = TermC.str2term "(3 + -1 * y) / (-9 + y \<up> 2)";
1.1466 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1467 -if UnparseC.term t = "- 1 / (3 + y)"
1.1468 -then () else error "rational.sml: -1 / (3 + y) norm_Rational";
1.1469 -
1.1470 -"----- SRD Schalk I, p.69 Nr. 456b";
1.1471 -val t = TermC.str2term "(b \<up> 3 - b \<up> 2) / (b \<up> 2+b) / (b \<up> 2 - 1)";
1.1472 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1473 -if UnparseC.term t = "b / (1 + 2 * b + b \<up> 2)"
1.1474 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 38";
1.1475 -
1.1476 -"----- SRD Schalk I, p.69 Nr. 457b";
1.1477 -val t = TermC.str2term "(16*a \<up> 2 - 9*b \<up> 2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a \<up> 2 - 9*a \<up> 2*b \<up> 2))";
1.1478 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1479 -if UnparseC.term t = "8 * a \<up> 2 + - 6 * a * b + - 12 * a \<up> 2 * b + 9 * a * b \<up> 2"
1.1480 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
1.1481 -
1.1482 -"----- Schalk I, p.69 Nr. 458b works since 0707";
1.1483 -val t = TermC.str2term "(2*a \<up> 2*x - a \<up> 2) / (a*x - b*x) / (b \<up> 2*(2*x - 1) / (x*(a - b)))";
1.1484 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1485 -:
1.1486 -### rls: cancel_p on: (-1 * a \<up> 2 + 2 * (a \<up> 2 * x)) / (a * x + -1 * (b * x)) /
1.1487 -((-1 * b \<up> 2 + 2 * (b \<up> 2 * x)) / (a * x + -1 * (b * x)))
1.1488 -exception Div raised
1.1489 -
1.1490 -BUT
1.1491 -val t = TermC.str2term
1.1492 - ("(-1 * a \<up> 2 + 2 * (a \<up> 2 * x)) / (a * x + -1 * (b * x)) /" ^
1.1493 - "((-1 * b \<up> 2 + 2 * (b \<up> 2 * x)) / (a * x + -1 * (b * x)))");
1.1494 -NONE = cancel_p_ thy t;
1.1495 -
1.1496 -if UnparseC.term t = "a \<up> 2 / b \<up> 2" then ()
1.1497 -else error "rational.sml: diff.behav. in norm_Rational_mg 39b";
1.1498 -*)
1.1499 -
1.1500 -"----- SRD Schalk I, p.69 Nr. 459b";
1.1501 -val t = TermC.str2term "(a \<up> 2 - b \<up> 2)/(a*b) / (4*(a+b) \<up> 2/a)";
1.1502 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1503 -if UnparseC.term t = "(a + - 1 * b) / (4 * a * b + 4 * b \<up> 2)" then ()
1.1504 -else error "rational.sml: diff.behav. in norm_Rational_mg 41";
1.1505 -
1.1506 -"----- Schalk I, p.69 Nr. 460b nonterm.SK";
1.1507 -val t = TermC.str2term "(9*(x \<up> 2 - 8*x + 16) / (4*(y \<up> 2 - 2*y + 1))) / ((3*x - 12) / (16*y - 16))";
1.1508 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1509 -exception Div raised
1.1510 -
1.1511 -BUT
1.1512 -val t = TermC.str2term
1.1513 - ("(144 + -72 * x + 9 * x \<up> 2) / (4 + -8 * y + 4 * y \<up> 2) /" ^
1.1514 - "((-12 + 3 * x) / (-16 + 16 * y))");
1.1515 -NONE = cancel_p_ thy t;
1.1516 -
1.1517 -if UnparseC.term t = !!!!!!!!!!!!!!!!!!!!!!!!!
1.1518 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 42";
1.1519 -*)
1.1520 -
1.1521 -"----- some variant of the above; was non-terminating before";
1.1522 -val t = TermC.str2term "9*(x \<up> 2 - 8*x+16)*(16*y - 16)/(4*(y \<up> 2 - 2*y+1)*(3*x - 12))";
1.1523 -val SOME (t , _) = rewrite_set_ thy false norm_Rational t;
1.1524 -if UnparseC.term t = "(48 + - 12 * x) / (1 + - 1 * y)"
1.1525 -then () else error "some variant of the above; was non-terminating before";
1.1526 -
1.1527 -"----- SRD Schalk I, p.70 Nr. 472a";
1.1528 -val t = TermC.str2term ("((8*x \<up> 2 - 32*y \<up> 2) / (2*x + 4*y)) / ((4*x - 8*y) / (x + y))");
1.1529 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1530 -if UnparseC.term t = "x + y"
1.1531 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 43";
1.1532 -
1.1533 -"----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
1.1534 -val t = TermC.str2term ("(a - (a*b + b \<up> 2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
1.1535 - "((a - a \<up> 2/(a+b))/(a+(a*b)/(a - b)))");
1.1536 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1537 -if UnparseC.term t = "(2 * a \<up> 3 + 2 * a \<up> 2 * b) / (a \<up> 2 * b + b \<up> 3)"
1.1538 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 51";
1.1539 -
1.1540 -(*SRD Schalk I, p.69 Nr. 461a *)
1.1541 -val t = TermC.str2term "(2/(x+3) + 2/(x - 3)) / (8*x/(x \<up> 2 - 9))";
1.1542 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1543 -if UnparseC.term t = "1 / 2"
1.1544 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 44";
1.1545 -
1.1546 -(*SRD Schalk I, p.69 Nr. 464b *)
1.1547 -val t = TermC.str2term "(a - a/(a - 2)) / (a + a/(a - 2))";
1.1548 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1549 -if UnparseC.term t = "(- 3 + a) / (- 1 + a)"
1.1550 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 45";
1.1551 -
1.1552 -(*SRD Schalk I, p.69 Nr. 465b *)
1.1553 -val t = TermC.str2term "((x+3*y)/9 + (4*y \<up> 2 - 9*z \<up> 2)/(16*x)) / (x/9 + y/6 + z/4)";
1.1554 -(* WN130911 non-termination due to non-termination of
1.1555 - cancel_p_ thy (TermC.str2term
1.1556 - ("("(576 * x \<up> 2 + 1728 * (x * y) + 1296 * y \<up> 2 + -2916 * z \<up> 2) /" ^
1.1557 - "(576 * x \<up> 2 + 864 * (x * y) + 1296 * (x * z))"))
1.1558 -
1.1559 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1560 -if UnparseC.term t = "(4 * x + 6 * y + -9 * z) / (4 * x)"
1.1561 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 46";
1.1562 -*)
1.1563 -
1.1564 -(*SRD Schalk I, p.69 Nr. 466b *)
1.1565 -val t = TermC.str2term "((1 - 7*(x - 2)/(x \<up> 2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x \<up> 2 - 25))";
1.1566 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1567 -if UnparseC.term t = "(25 + - 10 * x + x \<up> 2) / 18"
1.1568 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 47";
1.1569 -
1.1570 -(*SRD Schalk I, p.70 Nr. 469 *)
1.1571 -val t = TermC.str2term ("3*b \<up> 2 / (4*a \<up> 2 - 8*a*b + 4*b \<up> 2) / " ^
1.1572 - "(a / (a \<up> 2*b - b \<up> 3) + (a - b) / (4*a*b \<up> 2 + 4*b \<up> 3) - 1 / (4*b \<up> 2))");
1.1573 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1574 -if UnparseC.term t = "- 3 * b \<up> 3 / (- 2 * a + 2 * b)"
1.1575 -then () else error "rational.sml: diff.behav. in norm_Rational_mg 48";
1.1576 -
1.1577 -(*//----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)
1.1578 -"-------- me Schalk I No.186 -------------------------------------------------";
1.1579 -"-------- me Schalk I No.186 -------------------------------------------------";
1.1580 -"-------- me Schalk I No.186 -------------------------------------------------";
1.1581 -val fmz = ["Term ((14 * x * y) / ( x * y ))", "normalform N"];
1.1582 -val (dI',pI',mI') =
1.1583 - ("Rational",["rational", "simplification"],
1.1584 - ["simplification", "of_rationals"]);
1.1585 -val p = e_pos'; val c = [];
1.1586 -val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
1.1587 -val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.1588 -val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.1589 -val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.1590 -val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.1591 -val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.1592 -val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.1593 -val (p,_,f,nxt,_,pt) = me nxt p c pt;
1.1594 -val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1.1595 -val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
1.1596 -val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1.1597 -val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
1.1598 -case (f2str f, nxt) of
1.1599 - ("14", ("End_Proof'", _)) => ()
1.1600 - | _ => error "rational.sml diff.behav. in me Schalk I No.186";
1.1601 - \\----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)*)
1.1602 -
1.1603 -(*//----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)
1.1604 -"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
1.1605 -"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
1.1606 -"-------- interSteps ..Simp_Rat_Double_No-1.xml ------------------------------";
1.1607 -reset_states ();
1.1608 -CalcTree [(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"],
1.1609 - ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1.1610 -Iterator 1;
1.1611 -moveActiveRoot 1;
1.1612 -autoCalculate 1 CompleteCalc;
1.1613 -val ((pt, p), _) = get_calc 1;
1.1614 -(*
1.1615 -Test_Tool.show_pt pt;
1.1616 -[
1.1617 -(([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))),
1.1618 -(([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1.1619 -(([1], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))),
1.1620 -(([2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (-2 + x))),
1.1621 -(([3], Res), (2 + -1 * x) * (-2 + x) / (2 * a * (2 * a))),
1.1622 -(([4], Res), (-4 + 4 * x + -1 * x \<up> 2) / (4 * a \<up> 2)),
1.1623 -(([], Res), (-4 + 4 * x + -1 * x \<up> 2) / (4 * a \<up> 2))]
1.1624 -*)
1.1625 -interSteps 1 ([1], Res);
1.1626 -val ((pt, p), _) = get_calc 1;
1.1627 -(*Test_Tool.show_pt pt;
1.1628 -[
1.1629 -(([], Frm), Simplify ((2 - x) / (2 * a) / (2 * a / (x - 2)))),
1.1630 -(([1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1.1631 -(([1,1], Frm), (2 - x) / (2 * a) / (2 * a / (x - 2))),
1.1632 -(([1,1], Res), (2 - x) / (2 * a) / (2 * a / (x + -1 * 2))),
1.1633 -(([1,2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))),
1.1634 -(([1], Res), (2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))),
1.1635 -(([2], Res), (2 + -1 * x) / (2 * a) / (2 * a / (-2 + x))),
1.1636 -(([3], Res), (2 + -1 * x) * (-2 + x) / (2 * a * (2 * a))),
1.1637 -(([4], Res), (-4 + 4 * x + -1 * x \<up> 2) / (4 * a \<up> 2)),
1.1638 -(([], Res), (-4 + 4 * x + -1 * x \<up> 2) / (4 * a \<up> 2))]
1.1639 -*)
1.1640 -val (t, asm) = get_obj g_result pt [1, 1];
1.1641 -if UnparseC.term t = "(2 - x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso UnparseC.terms asm = "[]"
1.1642 -then () else error "2nd interSteps ..Simp_Rat_Double_No-1 changed on [1, 1]";
1.1643 -val (t, asm) = get_obj g_result pt [1, 2];
1.1644 -if UnparseC.term t = "(2 + -1 * x) / (2 * a) / (2 * a / (x + -1 * 2))" andalso UnparseC.terms asm = "[]"
1.1645 -then () else error "3rd interSteps ..Simp_Rat_Double_No-1 changed on [1, 2]";
1.1646 - \\----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)*)
1.1647 -
1.1648 -
1.1649 -(*//----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)
1.1650 -"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
1.1651 -"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
1.1652 -"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ------------------------------";
1.1653 -reset_states ();
1.1654 -CalcTree [(["Term ((a^2 + -1*b^2) / (a^2 + -2*a*b + b^2))", "normalform N"],
1.1655 - ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1.1656 -Iterator 1;
1.1657 -moveActiveRoot 1;
1.1658 -autoCalculate 1 CompleteCalc;
1.1659 -val ((pt, p), _) = get_calc 1;
1.1660 -(*Test_Tool.show_pt pt;
1.1661 -[
1.1662 -(([], Frm), Simplify ((a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2))),
1.1663 -(([1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2)),
1.1664 -(([1], Res), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1.1665 -(([2], Res), (a + b) / (a + -1 * b)),
1.1666 -(([], Res), (a + b) / (a + -1 * b))]
1.1667 -*)
1.1668 -interSteps 1 ([2], Res);
1.1669 -val ((pt, p), _) = get_calc 1;
1.1670 -(*Test_Tool.show_pt pt;
1.1671 -[
1.1672 -(([], Frm), Simplify ((a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2))),
1.1673 -(([1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2)),
1.1674 -(([1], Res), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1.1675 -(([2,1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1.1676 -(([2,1], Res), (a + b) / (a + -1 * b)),
1.1677 -(([2], Res), (a + b) / (a + -1 * b)),
1.1678 -(([], Res), (a + b) / (a + -1 * b))]
1.1679 -*)
1.1680 -interSteps 1 ([2,1],Res);
1.1681 -val ((pt, p), _) = get_calc 1;
1.1682 -(*Test_Tool.show_pt pt;
1.1683 -[
1.1684 -(([], Frm), Simplify ((a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2))),
1.1685 -(([1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * a * b + b \<up> 2)),
1.1686 -(([1], Res), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1.1687 -(([2,1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1.1688 -(([2,1,1], Frm), (a \<up> 2 + -1 * b \<up> 2) / (a \<up> 2 + -2 * (a * b) + b \<up> 2)),
1.1689 -(([2,1,1], Res), (a \<up> 2 + -1 * (a * b) + a * b + -1 * b \<up> 2) /
1.1690 -(a \<up> 2 + -2 * (a * b) + 1 * b \<up> 2)),
1.1691 -(([2,1,2], Res), (a \<up> 2 + -1 * (a * b) + a * b + -1 * b \<up> 2) /
1.1692 -(a \<up> 2 + -2 * (a * b) + -1 \<up> 2 * b \<up> 2)),
1.1693 -(([2,1,3], Res), (a \<up> 2 + -1 * (a * b) + a * b + -1 * b \<up> 2) /
1.1694 -(a \<up> 2 + -2 * (a * b) + (-1 * b) \<up> 2)),
1.1695 -(([2,1,4], Res), (a * a + -1 * (a * b) + a * b + -1 * b \<up> 2) /
1.1696 -(a \<up> 2 + -2 * (a * b) + (-1 * b) \<up> 2)),
1.1697 -(([2,1,5], Res), (a * a + -1 * (a * b) + a * b + -1 * (b * b)) /
1.1698 -(a \<up> 2 + -2 * (a * b) + (-1 * b) \<up> 2)),
1.1699 -(([2,1,6], Res), (a * a + -1 * (a * b) + a * b + -1 * (b * b)) /
1.1700 -(a \<up> 2 + -1 * (2 * (a * b)) + (-1 * b) \<up> 2)),
1.1701 -(([2,1,7], Res), (a * a + a * (-1 * b) + (b * a + b * (-1 * b))) /
1.1702 -(a \<up> 2 + 2 * (a * (-1 * b)) + (-1 * b) \<up> 2)),
1.1703 -(([2,1,8], Res), (a * a + a * (-1 * b) + (b * a + b * (-1 * b))) /
1.1704 -(a \<up> 2 + 2 * a * (-1 * b) + (-1 * b) \<up> 2)),
1.1705 -(([2,1,9], Res), (a * (a + -1 * b) + (b * a + b * (-1 * b))) /
1.1706 -(a \<up> 2 + 2 * a * (-1 * b) + (-1 * b) \<up> 2)),
1.1707 -(([2,1,10], Res), (a * (a + -1 * b) + b * (a + -1 * b)) /
1.1708 -(a \<up> 2 + 2 * a * (-1 * b) + (-1 * b) \<up> 2)),
1.1709 -(([2,1,11], Res), (a + b) * (a + -1 * b) / (a \<up> 2 + 2 * a * (-1 * b) + (-1 * b) \<up> 2)),
1.1710 -(([2,1,12], Res), (a + b) * (a + -1 * b) / ((a + -1 * b) * (a + -1 * b))),
1.1711 -(([2,1,13], Res), (a + b) / (a + -1 * b)),
1.1712 -(([2,1], Res), (a + b) / (a + -1 * b)),
1.1713 -(([2], Res), (a + b) / (a + -1 * b)),
1.1714 -(([], Res), (a + b) / (a + -1 * b))]
1.1715 -*)
1.1716 -val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*);
1.1717 -if length newnds = 13 then () else error "rational.sml: interSteps cancel_p rev_rew_p";
1.1718 -
1.1719 -val p = ([2,1,9],Res);
1.1720 -getTactic 1 p;
1.1721 -val (_, tac, _) = ME_Misc.pt_extract (pt, p);
1.1722 -case tac of SOME (Rewrite ("sym_distrib_left", _)) => ()
1.1723 -| _ => error "rational.sml: getTactic, sym_real_plus_binom_times1";
1.1724 - \\----------------------------------TOODOO (*Rfuns revsets \<longrightarrow> broken*)*)
1.1725 -
1.1726 -
1.1727 -"-------- investigate rulesets for cancel_p ----------------------------------";
1.1728 -"-------- investigate rulesets for cancel_p ----------------------------------";
1.1729 -"-------- investigate rulesets for cancel_p ----------------------------------";
1.1730 -val thy = @{theory "Rational"};
1.1731 -val t = TermC.str2term "(a \<up> 2 + -1*b \<up> 2) / (a \<up> 2 + -2*a*b + b \<up> 2)";
1.1732 -val tt = TermC.str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"(*numerator only*);
1.1733 -
1.1734 -"----- with rewrite_set_";
1.1735 -val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
1.1736 -if UnparseC.term tt'= "a \<up> 2 + - 1 * b \<up> 2" then () else error "rls chancel_p 1";
1.1737 -val tt = TermC.str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*);
1.1738 -val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
1.1739 -if UnparseC.term tt' = "a \<up> 2 + - 2 * a * b + b \<up> 2" then () else error "rls chancel_p 2";
1.1740 -
1.1741 -"----- with Derive.do_one; WN1130912 not investigated further, will be discontinued";
1.1742 -val SOME (tt, _) = factout_p_ thy t;
1.1743 -if UnparseC.term tt = "(a + b) * (a + - 1 * b) / ((a + - 1 * b) * (a + - 1 * b))"
1.1744 -then () else error "rls chancel_p 3";
1.1745 -
1.1746 -"--- with simpler ruleset";
1.1747 -val {rules, rew_ord= (_, ro), ...} = Rule_Set.rep (assoc_rls "rev_rew_p");
1.1748 -val der = Derive.do_one thy Atools_erls rules ro NONE tt;
1.1749 -if length der = 12 then () else error "WN1130912 rls chancel_p 4";
1.1750 -(*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
1.1751 -
1.1752 -(*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*)
1.1753 -"...,(-1 * b \<up> 2 + a \<up> 2) / (-2 * (a * b) + a \<up> 2 + (-1 * b) \<up> 2) ]";
1.1754 -(*default_print_depth 99;*) map (Rule.to_string o #2) der; (*default_print_depth 3;*)
1.1755 -(*default_print_depth 99;*) map (UnparseC.term o #1 o #3) der; (*default_print_depth 3;*)
1.1756 -
1.1757 -val der = Derive.do_one thy Atools_erls rules ro NONE
1.1758 - (TermC.str2term "(1 * a + 1 * b) * (1 * a + -1 * b)");
1.1759 -(*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
1.1760 -
1.1761 -val {rules, rew_ord=(_,ro),...} = Rule_Set.rep (assoc_rls "rev_rew_p");
1.1762 -val der = Derive.do_one thy Atools_erls rules ro NONE
1.1763 - (TermC.str2term "(1 * a + -1 * b) * (1 * a + -1 * b)");
1.1764 -(*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
1.1765 -(*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*)
1.1766 -(*WN060829 ...postponed*)
1.1767 -
1.1768 -
1.1769 -"-------- fun eval_get_denominator -------------------------------------------";
1.1770 -"-------- fun eval_get_denominator -------------------------------------------";
1.1771 -"-------- fun eval_get_denominator -------------------------------------------";
1.1772 -val thy = @{theory Isac_Knowledge};
1.1773 -val t = Thm.term_of (the (TermC.parse thy "get_denominator ((a +x)/b)"));
1.1774 -val SOME (_, t') = eval_get_denominator "" 0 t thy;
1.1775 -if UnparseC.term t' = "get_denominator ((a + x) / b) = b"
1.1776 -then () else error "get_denominator ((a + x) / b) = b"
1.1777 -
1.1778 -
1.1779 -"-------- several errpats in complicated term --------------------------------";
1.1780 -"-------- several errpats in complicated term --------------------------------";
1.1781 -"-------- several errpats in complicated term --------------------------------";
1.1782 -(*WN12xxxx TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one
1.1783 - WN130912: kept this test, although not clear what for*)
1.1784 -reset_states ();
1.1785 -CalcTree [(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"],
1.1786 - ("Rational", ["rational", "simplification"], ["simplification", "of_rationals"]))];
1.1787 -Iterator 1;
1.1788 -moveActiveRoot 1;
1.1789 -autoCalculate 1 CompleteCalc;
1.1790 -val ((pt, p), _) = get_calc 1;
1.1791 -(*Test_Tool.show_pt pt;
1.1792 -[
1.1793 -(([], Frm), Simplify ((5 * b + 25) / (a \<up> 2 - b \<up> 2) * (a - b) / (5 * b))),
1.1794 -(([1], Frm), (5 * b + 25) / (a \<up> 2 - b \<up> 2) * (a - b) / (5 * b)),
1.1795 -(([1], Res), (5 * b + 25) / (a \<up> 2 + -1 * b \<up> 2) * (a + -1 * b) / (5 * b)),
1.1796 -(([2], Res), (5 * b + 25) * (a + -1 * b) / (a \<up> 2 + -1 * b \<up> 2) / (5 * b)),
1.1797 -(([3], Res), (25 * a + -25 * b + 5 * (a * b) + -5 * b \<up> 2) / (a \<up> 2 + -1 * b \<up> 2) /
1.1798 -(5 * b)),
1.1799 -(([4], Res), (25 + 5 * b) / (a + b) / (5 * b)),
1.1800 -(([5], Res), (25 + 5 * b) / ((a + b) * (5 * b))),
1.1801 -(([6], Res), (25 + 5 * b) / (5 * (a * b) + 5 * b \<up> 2)),
1.1802 -(([7], Res), (5 + b) / (a * b + b \<up> 2)),
1.1803 -(([], Res), (5 + b) / (a * b + b \<up> 2))] *)
1.1804 -
1.1805 -
1.1806 -"-------- WN1309xx non-terminating rls norm_Rational -------------------------";
1.1807 -"-------- WN1309xx non-terminating rls norm_Rational -------------------------";
1.1808 -"-------- WN1309xx non-terminating rls norm_Rational -------------------------";
1.1809 -(*------- Schalk I, p.70 Nr. 480b; a/b : c/d translated to a/b * d/c*)
1.1810 -val t = TermC.str2term
1.1811 - ("((12*x*y / (9*x \<up> 2 - y \<up> 2)) / (1 / (3*x - y) \<up> 2 - 1 / (3*x + y) \<up> 2)) * " ^
1.1812 - "((1/(x - 5*y) \<up> 2 - 1/(x + 5*y) \<up> 2) / (20*x*y / (x \<up> 2 - 25*y \<up> 2)))");
1.1813 -
1.1814 -(*1st factor separately simplified *)
1.1815 -val t = TermC.str2term "((12*x*y / (9*x \<up> 2 - y \<up> 2)) / (1 / (3*x - y) \<up> 2 - 1 / (3*x + y) \<up> 2))";
1.1816 -val SOME (t', _) = rewrite_set_ thy false norm_Rational t;
1.1817 -if UnparseC.term t' = "(- 9 * x \<up> 2 + y \<up> 2) / - 1" then () else error "Nr. 480b lhs changed";
1.1818 -(*2nd factor separately simplified *)
1.1819 -val t = TermC.str2term "((1/(x - 5*y) \<up> 2 - 1/(x + 5*y) \<up> 2) / (20*x*y / (x \<up> 2 - 25*y \<up> 2)))";
1.1820 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
1.1821 -if UnparseC.term t' = "- 1 / (- 1 * x \<up> 2 + 25 * y \<up> 2)" then () else error "Nr. 480b rhs changed";
1.1822 -
1.1823 -"-------- Schalk I, p.70 Nr. 477a: terms are exploding ?!?";
1.1824 -val t = TermC.str2term ("b*y/(b - 2*y)/((b \<up> 2 - y \<up> 2)/(b+2*y)) /" ^
1.1825 - "(b \<up> 2*y + b*y \<up> 2) * (a+x) \<up> 2 / ((b \<up> 2 - 4*y \<up> 2) * (a+2*x) \<up> 2)");
1.1826 -(*val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
1.1827 -:
1.1828 -### rls: cancel_p on: (a \<up> 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \<up> 2 * y)) /
1.1829 -(b + -2 * y) /
1.1830 -((b \<up> 2 + -1 * y \<up> 2) / (b + 2 * y)) /
1.1831 -(b \<up> 2 * y + b * y \<up> 2) /
1.1832 -(a \<up> 2 * b \<up> 2 + -4 * (a \<up> 2 * y \<up> 2) + 4 * (a * (b \<up> 2 * x)) +
1.1833 - -16 * (a * (x * y \<up> 2)) +
1.1834 - 4 * (b \<up> 2 * x \<up> 2) +
1.1835 - -16 * (x \<up> 2 * y \<up> 2))
1.1836 -exception Div raised
1.1837 -
1.1838 -BUT
1.1839 -val t = TermC.str2term
1.1840 - ("(a \<up> 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \<up> 2 * y)) /" ^
1.1841 - "(b + -2 * y) /" ^
1.1842 - "((b \<up> 2 + -1 * y \<up> 2) / (b + 2 * y)) /" ^
1.1843 - "(b \<up> 2 * y + b * y \<up> 2) /" ^
1.1844 - "(a \<up> 2 * b \<up> 2 + -4 * (a \<up> 2 * y \<up> 2) + 4 * (a * (b \<up> 2 * x)) +" ^
1.1845 - "-16 * (a * (x * y \<up> 2)) +" ^
1.1846 - "4 * (b \<up> 2 * x \<up> 2) +" ^
1.1847 - "-16 * (x \<up> 2 * y \<up> 2))");
1.1848 -NONE = cancel_p_ thy t;
1.1849 -*)
1.1850 -
1.1851 -(*------- Schalk I, p.70 Nr. 476b in 2003 this worked using 10 sec. *)
1.1852 -val t = TermC.str2term
1.1853 - ("((a \<up> 2 - b \<up> 2)/(2*a*b) + 2*a*b/(a \<up> 2 - b \<up> 2)) / ((a \<up> 2 + b \<up> 2)/(2*a*b) + 1) / " ^
1.1854 - "((a \<up> 2 + b \<up> 2) \<up> 2 / (a + b) \<up> 2)");
1.1855 -(* Rewrite.trace_on := true;
1.1856 -rewrite_set_ thy false norm_Rational t;
1.1857 -:
1.1858 -#### rls: cancel_p on: (2 * (a \<up> 7 * b) + 4 * (a \<up> 6 * b \<up> 2) + 6 * (a \<up> 5 * b \<up> 3) +
1.1859 - 8 * (a \<up> 4 * b \<up> 4) +
1.1860 - 6 * (a \<up> 3 * b \<up> 5) +
1.1861 - 4 * (a \<up> 2 * b \<up> 6) +
1.1862 - 2 * (a * b \<up> 7)) /
1.1863 -(2 * (a \<up> 9 * b) + 4 * (a \<up> 8 * b \<up> 2) +
1.1864 - 2 * (2 * (a \<up> 7 * b \<up> 3)) +
1.1865 - 4 * (a \<up> 6 * b \<up> 4) +
1.1866 - -4 * (a \<up> 4 * b \<up> 6) +
1.1867 - -4 * (a \<up> 3 * b \<up> 7) +
1.1868 - -4 * (a \<up> 2 * b \<up> 8) +
1.1869 - -2 * (a * b \<up> 9))
1.1870 -
1.1871 -if UnparseC.term t = "1 / (a \<up> 2 + -1 * b \<up> 2)" then ()
1.1872 -else error "rational.sml: diff.behav. in norm_Rational_mg 49";
1.1873 -*)
1.1874 -
1.1875 -"-------- Schalk I, p.70 Nr. 480a: terms are exploding ?!?";
1.1876 -val t = TermC.str2term ("(1/x + 1/y + 1/z) / (1/x - 1/y - 1/z) / " ^
1.1877 - "(2*x \<up> 2 / (x \<up> 2 - z \<up> 2) / (x / (x + z) + x / (x - z)))");
1.1878 -(* Rewrite.trace_on := true;
1.1879 -rewrite_set_ thy false norm_Rational t;
1.1880 -:
1.1881 -#### rls: cancel_p on: (2 * (x \<up> 6 * (y \<up> 2 * z)) + 2 * (x \<up> 6 * (y * z \<up> 2)) +
1.1882 - 2 * (x \<up> 5 * (y \<up> 2 * z \<up> 2)) +
1.1883 - -2 * (x \<up> 4 * (y \<up> 2 * z \<up> 3)) +
1.1884 - -2 * (x \<up> 4 * (y * z \<up> 4)) +
1.1885 - -2 * (x \<up> 3 * (y \<up> 2 * z \<up> 4))) /
1.1886 -(-2 * (x \<up> 6 * (y \<up> 2 * z)) + -2 * (x \<up> 6 * (y * z \<up> 2)) +
1.1887 - 2 * (x \<up> 5 * (y \<up> 2 * z \<up> 2)) +
1.1888 - 2 * (x \<up> 4 * (y \<up> 2 * z \<up> 3)) +
1.1889 - 2 * (x \<up> 4 * (y * z \<up> 4)) +
1.1890 - -2 * (x \<up> 3 * (y \<up> 2 * z \<up> 4)))
1.1891 -*)
1.1892 -
1.1893 -"-------- Schalk I, p.60 Nr. 215d: terms are exploding, internal loop does not terminate";
1.1894 -val t = TermC.str2term "(a-b) \<up> 3 * (x+y) \<up> 4 / ((x+y) \<up> 2 * (a-b) \<up> 5)";
1.1895 -(* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt:
1.1896 -
1.1897 -val t = TermC.str2term "(a-b) \<up> 3 * (x+y) \<up> 4";
1.1898 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1899 -UnparseC.term t;
1.1900 -"a \<up> 3 * x \<up> 4 + 4 * a \<up> 3 * x \<up> 3 * y +6 * a \<up> 3 * x \<up> 2 * y \<up> 2 +4 * a \<up> 3 * x * y \<up> 3 +a \<up> 3 * y \<up> 4 +-3 * a \<up> 2 * b * x \<up> 4 +-12 * a \<up> 2 * b * x \<up> 3 * y +-18 * a \<up> 2 * b * x \<up> 2 * y \<up> 2 +-12 * a \<up> 2 * b * x * y \<up> 3 +-3 * a \<up> 2 * b * y \<up> 4 +3 * a * b \<up> 2 * x \<up> 4 +12 * a * b \<up> 2 * x \<up> 3 * y +18 * a * b \<up> 2 * x \<up> 2 * y \<up> 2 +12 * a * b \<up> 2 * x * y \<up> 3 +3 * a * b \<up> 2 * y \<up> 4 +-1 * b \<up> 3 * x \<up> 4 +-4 * b \<up> 3 * x \<up> 3 * y +-6 * b \<up> 3 * x \<up> 2 * y \<up> 2 +-4 * b \<up> 3 * x * y \<up> 3 +-1 * b \<up> 3 * y \<up> 4";
1.1901 -val t = TermC.str2term "((x+y) \<up> 2 * (a-b) \<up> 5)";
1.1902 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1903 -UnparseC.term t;
1.1904 -"a \<up> 5 * x \<up> 2 + 2 * a \<up> 5 * x * y + a \<up> 5 * y \<up> 2 +-5 * a \<up> 4 * b * x \<up> 2 +-10 * a \<up> 4 * b * x * y +-5 * a \<up> 4 * b * y \<up> 2 +10 * a \<up> 3 * b \<up> 2 * x \<up> 2 +20 * a \<up> 3 * b \<up> 2 * x * y +10 * a \<up> 3 * b \<up> 2 * y \<up> 2 +-10 * a \<up> 2 * b \<up> 3 * x \<up> 2 +-20 * a \<up> 2 * b \<up> 3 * x * y +-10 * a \<up> 2 * b \<up> 3 * y \<up> 2 +5 * a * b \<up> 4 * x \<up> 2 +10 * a * b \<up> 4 * x * y +5 * a * b \<up> 4 * y \<up> 2 +-1 * b \<up> 5 * x \<up> 2 +-2 * b \<up> 5 * x * y +-1 * b \<up> 5 * y \<up> 2";
1.1905 -
1.1906 -anscheinend macht dem Rechner das Krzen diese Bruches keinen Spass mehr ...*)
1.1907 -
1.1908 -"-------- Schalk I, p.70 Nr. 480b: terms are exploding, Rewrite.trace_on stops at";
1.1909 -val t = TermC.str2term ("((12*x*y/(9*x \<up> 2 - y \<up> 2))/" ^
1.1910 - "(1/(3*x - y) \<up> 2 - 1/(3*x + y) \<up> 2)) *" ^
1.1911 - "(1/(x - 5*y) \<up> 2 - 1/(x + 5*y) \<up> 2)/" ^
1.1912 - "(20*x*y/(x \<up> 2 - 25*y \<up> 2))");
1.1913 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
1.1914 -:
1.1915 -#### rls: cancel_p on: (19440 * (x \<up> 8 * y \<up> 2) + -490320 * (x \<up> 6 * y \<up> 4) +
1.1916 - 108240 * (x \<up> 4 * y \<up> 6) +
1.1917 - -6000 * (x \<up> 2 * y \<up> 8)) /
1.1918 -(2160 * (x \<up> 8 * y \<up> 2) + -108240 * (x \<up> 6 * y \<up> 4) +
1.1919 - 1362000 * (x \<up> 4 * y \<up> 6) +
1.1920 - -150000 * (x \<up> 2 * y \<up> 8))
1.1921 -*)
1.1922 -