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