test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 02 Sep 2013 15:17:34 +0200
changeset 52100 0831a4a6ec8a
parent 52096 ee2a5f066e44
child 52101 c3f399ce32af
permissions -rw-r--r--
GCD_Poly_ML: survey on levels integrating gcd_poly in Rational.thy
     1 (* Title: tests for rationals
     2    Author: Stefan Karnel
     3    Copyright (c) Stefan Karnel 2002
     4    Use is subject to license terms.
     5 
     6 12345678901234567890123456789012345678901234567890123456789012345678901234567890
     7         10        20        30        40        50        60        70        80
     8 LEGEND
     9 WN120317.TODO postponed test/../ratinal,ratinal2.sml to joint work with dmeind 
    10 WN070906
    11    nonterm.SK   marks non-terminating examples
    12    ord.SK       PARTIALLY marks crucial ordering examples
    13    *SK*         of some (secondary) interest (on 070906)          
    14 WN060104 transfer examples marked with (*SR..*) to the exp-collection
    15 *)
    16 
    17 "-----------------------------------------------------------------------------";
    18 "-----------------------------------------------------------------------------";
    19 "table of contents -----------------------------------------------------------";
    20 "-----------------------------------------------------------------------------";
    21 "-------- fun poly_of_term ---------------------------------------------------";
    22 "-------- fun is_poly --------------------------------------------------------";
    23 "-------- fun term_of_poly ---------------------------------------------------";
    24 "-------- fun factout_p_ -----------------------------------------------------";
    25 "-------- fun cancel_p_ ------------------------------------------------------";
    26 "-------- fun common_nominator_p_ --------------------------------------------";
    27 "-------- fun add_fraction_p_ ------------------------------------------------";
    28 "-------- TODO ---------------------------------------------------------------";
    29 "-------- and app_rev --------------------------------------------------------";
    30 "-------- external calculating functions test -----------";
    31 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
    32 "-------- common_nominator_p ----------------------------";
    33 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
    34 "-------- reverse rewrite -------------------------------";
    35 "-------- 'reverse-ruleset' cancel_p --------------------";
    36 "-------- norm_Rational ---------------------------------";
    37 "-------- numeral rationals -----------------------------";
    38 "-------- cancellation ----------------------------------";
    39 "-------- common denominator ----------------------------";
    40 "-------- multiply and cancel ---------------------------";
    41 "-------- common denominator and multiplication ---------";
    42 "-------- double fractions ------------------------------";
    43 "-------- crucial examples ------------------------------";
    44 "-------- examples for Stefan Karnels thesis ------------";
    45 "-------- me Schalk I No.186 ----------------------------";
    46 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
    47 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
    48 "-------- investigate rulesets for cancel_p -------------";
    49 "-------- investigate format of factout_ and factout_p_ -";
    50 "-------- how to stepwise construct Scripts -------------";
    51 "----------- get_denominator ----------------------------";
    52 "--------- several errpats in complicated term -------------------";
    53 "--------------------------------------------------------";
    54 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
    55 "--------------------------------------------------------";
    56 "--------------------------------------------------------";
    57 
    58 
    59 "-------- fun poly_of_term ---------------------------------------------------";
    60 "-------- fun poly_of_term ---------------------------------------------------";
    61 "-------- fun poly_of_term ---------------------------------------------------";
    62 val vs = "12 * x^^^3 * y^^^4 * z^^^6" |> str2term |> vars |> map free2str |> sort string_ord;
    63 
    64 if poly_of_term vs (str2term "12::real") = SOME [(12, [0, 0, 0])]
    65 then () else error "poly_of_term 1 changed";
    66 if poly_of_term vs (str2term "x::real") = SOME [(1, [1, 0, 0])]
    67 then () else error "poly_of_term 2 changed";
    68 if poly_of_term vs (str2term "12 * x^^^3") = SOME [(12, [3, 0, 0])]
    69 then () else error "poly_of_term 3 changed";
    70 if poly_of_term vs (str2term "12 * x^^^3 * y^^^4 * z^^^6") = SOME [(12, [3, 4, 6])]
    71 then () else error "poly_of_term 4 changed";
    72 if poly_of_term vs (str2term "1 + 2 * x^^^3 * y^^^4 * z^^^6 + y") =
    73   SOME [(1, [0, 0, 0]), (1, [0, 1, 0]), (2, [3, 4, 6])]
    74 then () else error "poly_of_term 5 changed";
    75 
    76 (*poly_of_term is quite liberal:*)
    77 (*the coefficient may be somewhere, the order of variables and the parentheses 
    78   within a monomial are arbitrary*)
    79 if poly_of_term vs (str2term "y^^^4 * (x^^^3 * 12 * z^^^6)") = SOME [(12, [3, 4, 6])]
    80 then () else error "poly_of_term 6 changed";
    81 
    82 (*there may even be more than 1 coefficient:*)
    83 if poly_of_term vs (str2term "2 * y^^^4 * (x^^^3 * 6 * z^^^6)") = SOME [(12, [3, 4, 6])]
    84 then () else error "poly_of_term 7 changed";
    85 
    86 (*the order and the parentheses within monomials are arbitrary:*)
    87 if poly_of_term vs (str2term "2 * x^^^3 * y^^^4 * z^^^6 + (7 * y^^^8 + 1)")
    88   = SOME [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 6])]
    89 then () else error "poly_of_term 8 changed";
    90 
    91 "-------- fun is_poly --------------------------------------------------------";
    92 "-------- fun is_poly --------------------------------------------------------";
    93 "-------- fun is_poly --------------------------------------------------------";
    94 if is_poly (str2term "2 * x^^^3 * y^^^4 * z^^^6 + 7 * y^^^8 + 1")
    95 then () else error "is_poly 1 changed";
    96 if not (is_poly (str2term "2 * (x^^^3 * y^^^4 * z^^^6 + 7) * y^^^8 + 1"))
    97 then () else error "is_poly 2 changed";
    98 
    99 "-------- fun term_of_poly ---------------------------------------------------";
   100 "-------- fun term_of_poly ---------------------------------------------------";
   101 "-------- fun term_of_poly ---------------------------------------------------";
   102 val expT = HOLogic.realT
   103 val Free (_, baseT) = (hd o vars o str2term) "12 * x^^^3 * y^^^4 * z^^^6";
   104 val p = [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 5])]
   105 val vs = ["x","y","z"]
   106 (*precondition for [(c, es),...]: legth es = length vs*)
   107 ;
   108 if term2str (term_of_poly baseT expT vs p) = "1 + 7 * y ^^^ 8 + 2 * x ^^^ 3 * y ^^^ 4 * z ^^^ 5"
   109 then () else error "term_of_poly 1 changed";
   110 
   111 "-------- fun factout_p_ -----------------------------------------------------";
   112 "-------- fun factout_p_ -----------------------------------------------------";
   113 "-------- fun factout_p_ -----------------------------------------------------";
   114 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)"
   115 val SOME (t', asm) = factout_p_ thy t;
   116 if term2str t' = "(x + y) * (x + -1 * y) / (x * (x + -1 * y))"
   117 then () else error ("factout_p_ term 1 changed: " ^ term2str t')
   118 ;
   119 if terms2str asm = "[\"x ~= 0\",\"x + -1 * y ~= 0\"]"
   120 then () else error "factout_p_ asm 1 changed"
   121 ;
   122 val t = str2term "nothing + to_cancel ::real";
   123 if NONE = factout_p_ thy t then () else error "factout_p_ doesn't report non-applicable";
   124 ;
   125 val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
   126 val SOME (t', asm) = factout_p_ thy t;
   127 if term2str t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso 
   128   terms2str asm = "[\"1 + x ~= 0\"]"
   129 then () else error "factout_p_ 1 changed";
   130 
   131 "-------- fun cancel_p_ ------------------------------------------------------";
   132 "-------- fun cancel_p_ ------------------------------------------------------";
   133 "-------- fun cancel_p_ ------------------------------------------------------";
   134 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)"
   135 val SOME (t', asm) = cancel_p_ thy t;
   136 if (term2str t', terms2str asm) = ("(x + y) / x", "[\"x ~= 0\"]")
   137 then () else error ("cancel_p_ (t', asm) 1 changed: " ^ term2str t')
   138 ;
   139 val t = str2term "nothing + to_cancel ::real";
   140 if NONE = cancel_p_ thy t then () else error "cancel_p_ doesn't report non-applicable";
   141 ;
   142 val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
   143 val SOME (t', asm) = cancel_p_ thy t;
   144 if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[]"
   145 then () else error "cancel_p_ 1 changed";
   146 
   147 "-------- fun common_nominator_p_ --------------------------------------------";
   148 "-------- fun common_nominator_p_ --------------------------------------------";
   149 "-------- fun common_nominator_p_ --------------------------------------------";
   150 val t = str2term ("y / (a*x + b*x + c*x) " ^
   151               (* n1    d1                   *)
   152                 "+ a / (x*y)");
   153               (* n2    d2                   *)
   154 val SOME (t', asm) = common_nominator_p_ thy t;
   155 if term2str t' =
   156       ("y * y / (x * ((a + b + c) * y)) " ^
   157   (*  n1  *d2'/ (c'* ( d1'        *d2')) *)
   158      "+ a * (a + b + c) / (x * ((a + b + c) * y))")
   159    (*  n2 * d1'         / (c'* ( d1'        *d2')) *)
   160 then () else error "common_nominator_p_ term 1 changed";
   161 if terms2str asm = "[\"a + b + c ~= 0\",\"y ~= 0\",\"x ~= 0\"]"
   162 then () else error "common_nominator_p_ asm 1 changed"
   163 
   164 "-------- example in mail Nipkow";
   165 val t = str2term "x/(x^^^2 + -1*y^^^2) + y/(x^^^2 + -1*x*y)";
   166 val SOME (t', asm) = common_nominator_p_ thy t;
   167 if term2str t' = "x * x / " ^ 
   168                  "((x + -1 * y) * ((x + y) * x))" ^
   169             " +\n" ^ 
   170                  "y * (x + y) / " ^ 
   171                  "((x + -1 * y) * ((x + y) * x))"
   172 then () else error "common_nominator_p_ term 2 changed"
   173 ;
   174 if terms2str asm = "[\"x + y ~= 0\",\"x ~= 0\",\"x + -1 * y ~= 0\"]"
   175 then () else error "common_nominator_p_ asm 2 changed"
   176 
   177 "-------- example: applicable tested by SML code";
   178 val t = str2term "nothing / to_add";
   179 if NONE = common_nominator_p_ thy t then () else error "common_nominator_p_ term 3 changed";
   180 ;
   181 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
   182 val SOME (t', asm) = common_nominator_p_ thy t;
   183 if term2str t' = 
   184   "(x + -1) * (-1 + x) / (1 * ((1 + x) * (-1 + x))) +\n(x + 1) * (1 + x) / (1 * ((1 + x) * (-1 + x)))"
   185   andalso terms2str asm = "[\"1 + x ~= 0\",\"-1 + x ~= 0\"]"
   186 then () else error "common_nominator_p_ 3 changed";
   187 
   188 "-------- fun add_fraction_p_ ------------------------------------------------";
   189 "-------- fun add_fraction_p_ ------------------------------------------------";
   190 "-------- fun add_fraction_p_ ------------------------------------------------";
   191 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
   192 val SOME (t', asm) = add_fraction_p_ thy t;
   193 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" 
   194 then () else error "add_fraction_p_ 3 changed";
   195 ;
   196 if terms2str asm = "[\"-1 + x ^^^ 2 ~= 0\"]"
   197 then () else error "add_fraction_p_ 3 changed";
   198 ;
   199 val t = str2term "nothing / to_add";
   200 if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ term 3 changed";
   201 ;
   202 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
   203 val SOME (t', asm) = add_fraction_p_ thy t;
   204 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso
   205   terms2str asm = "[\"-1 + x ^^^ 2 ~= 0\"]"
   206 then () else error "add_fraction_p_ 3 changed";
   207 
   208 "-------- TODO ---------------------------------------------------------------";
   209 "-------- TODO ---------------------------------------------------------------";
   210 "-------- TODO ---------------------------------------------------------------";
   211 
   212 
   213 
   214 "-------- and app_rev --------------------------------------------------------";
   215 "-------- and app_rev --------------------------------------------------------";
   216 "-------- and app_rev --------------------------------------------------------";
   217 (* trace down until prepats are evaluated 
   218   (which does not to work, because substitution is not done -- compare rew_sub!);
   219   keep this sequence for the case, factout_p, cancel_p, common_nominator_p, add_fraction_p
   220   (again) get prepat = [] changed to <>[]. *)
   221 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)";
   222 
   223 (*rewrite_set_ @{theory Isac} true cancel t = NONE; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
   224 "~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (thy, false, cancel_p, t);
   225 "~~~~~ fun rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
   226   (thy, 1, bool, [], rls, term);
   227 (*val (t', asm, rew) = app_rev thy (i+1) rrls t; rew = false!!!!!!!!!!!!!!!!!!!!!*)
   228 "~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
   229     fun chk_prepat thy erls [] t = true
   230       | chk_prepat thy erls prepat t =
   231         let
   232           fun chk (pres, pat) =
   233             (let 
   234               val subst: Type.tyenv * Envir.tenv =
   235                 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
   236              in
   237               snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
   238              end) handle _ => false
   239            fun scan_ f [] = false (*scan_ NEVER called by []*)
   240              | scan_ f (pp::pps) =
   241                if f pp then true else scan_ f pps;
   242         in scan_ chk prepat end;
   243     (* apply the normal_form of a rev-set *)
   244     fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
   245       if chk_prepat thy erls prepat t
   246       then ((*tracing("### app_rev': t = "^(term2str t));*) normal_form t)
   247       else NONE;
   248 (*  val opt = app_rev' thy rrls t  ..NONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
   249 "~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
   250   (thy, rrls, t);
   251 (* chk_prepat thy erls prepat t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
   252 (* app_sub thy i rrls t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
   253 "~~~~~ fun chk_prepat, args:"; val (thy, erls, prepat, t) = (thy, erls, prepat, t);
   254           fun chk (pres, pat) =
   255             (let 
   256               val subst: Type.tyenv * Envir.tenv =
   257                 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
   258              in
   259               snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
   260              end) handle _ => false
   261            fun scan_ f [] = false (*scan_ NEVER called by []*)
   262              | scan_ f (pp::pps) =
   263                if f pp then true else scan_ f pps;
   264 
   265 (*========== inhibit exn WN130823: prepat is empty ====================================
   266 (* scan_ chk prepat = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
   267 "~~~~~ fun , args:"; val (f, (pp::pps)) = (chk, prepat);
   268 f;
   269 val ([t1, t2], t) = pp;
   270 term2str t1 = "?r is_expanded";
   271 term2str t2 = "?s is_expanded";
   272 term2str t = "?r / ?s";
   273 (* f pp = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
   274 "~~~~~ fun chk, args:"; val (pres, pat) = (pp);
   275               val subst: Type.tyenv * Envir.tenv =
   276                 Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
   277 (*subst = 
   278   ({}, {(("r", 0), ("real", Var (("r", 0), "real"))), 
   279         (("s", 0), ("real", Var (("s", 0), "real")))}*)
   280 ;
   281               snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
   282 "~~~~~ fun eval__true, args:"; val (thy, i, asms, bdv, rls) =
   283   (thy, (i + 1), (map (Envir.subst_term subst) pres), [], erls);
   284 terms2str asms;                         (* = "[\"?r is_expanded\",\"?s is_expanded\"]"*)
   285 asms = [@{term True}] orelse asms = []; (* = false*)
   286 asms = [@{term False}]                ; (* = false*)
   287 "~~~~~ fun chk, args:"; val (indets, (a::asms)) = ([], asms);
   288 bdv (*= []: _a list*);
   289 val bdv : (term * term) list = [];
   290 rewrite__set_ thy (i+1) false;
   291 term2str a = "?r is_expanded"; (*hier m"usste doch der Numerator eingesetzt sein ??????????????*)
   292 val SOME (Const ("HOL.False", _), []) = rewrite__set_ thy (i+1) false bdv rls a
   293 ============ inhibit exn WN130823: prepat is empty ===================================*)
   294 
   295 (*========== inhibit exn WN130824 TODO =======================================================
   296 "-------- external calculating functions test -----------";
   297 "-------- external calculating functions test -----------";
   298 "-------- external calculating functions test -----------";
   299 val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
   300 val SOME (t', asm) = factout_p_ thy t;
   301 if term2str t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso terms2str asm = "[]"
   302 then () else error "factout_p_ 1 changed";
   303 val SOME (t', asm) = cancel_p_ thy t;
   304 if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[\"1 + x ~= 0\"]"
   305 then () else error "cancel_p_ 1 changed";
   306 
   307 val t = str2term "((-3 * x^^^2 + 6 *x - 3) / (2*x - 2))";
   308 val SOME (t', asm) = factout_(*p_*) thy t;
   309 if term2str t' = "(3 - 3 * x) * (-1 + x) / (2 * (-1 + x))" andalso terms2str asm = "[]"
   310 then () else error "factout_ 2 changed";
   311 val SOME (t', asm) = cancel_(*p_*) thy t;
   312 if term2str t' = "(3 - 3 * x) / 2" andalso terms2str asm = "[\"-1 + x ~= 0\"]"
   313 then () else error "cancel_ 2 changed";
   314 
   315 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
   316 val SOME (t', asm) = add_fraction_p_ thy t;
   317 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
   318 then () else error "add_fraction_p_ 3 changed";
   319 val SOME (t', asm) = common_nominator_p_ thy t;
   320 if term2str t' = 
   321   "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
   322   andalso terms2str asm = "[]"
   323 then () else error "common_nominator_p_ 3 changed";
   324 
   325 val t = str2term "((x - 1) / (x + 1)) + ((x + 1) / (x - 1))";
   326 val SOME (t', asm) = add_fraction_ thy t;
   327 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
   328 then () else error "factout_ 4 changed";
   329 val SOME (t', asm) = common_nominator_ thy t;
   330 if term2str t' = 
   331   "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))" 
   332   andalso terms2str asm = "[]"
   333 then () else error "cancel_ 4 changed";
   334 
   335 val t = str2term 
   336   "((1) / (2*x + 2)) + ((1) / (2*x + (-2))) + ((1) / ( x^^^2 + (-1)))+((1) / (x^^^2 + (-2)*x + 1))";
   337 val SOME (t', asm) = add_fraction_p_ thy t;
   338 if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
   339 then () else error "add_fraction_p_ 5 changed";
   340 val SOME (t', asm) = norm_rational_ thy t;
   341 if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
   342 then () else error "norm_rational_ 5 changed";
   343 ============ inhibit exn WN130826 TODO ========================================================*)
   344 
   345 
   346 "-------- cancel_p from: Mathematik 1 Schalk Reniets Verlag ------------------";
   347 "-------- cancel_p from: Mathematik 1 Schalk Reniets Verlag ------------------";
   348 "-------- cancel_p from: Mathematik 1 Schalk Reniets Verlag ------------------";
   349 val thy  = @{theory "Rational"};
   350 "-------- WN";
   351 val t = str2term "(2 + -3 * x) / 9";
   352 if NONE = rewrite_set_ thy false cancel_p t then ()
   353 else error "rewrite_set_ cancel_p must return NONE, if the term cannot be cancelled";
   354 
   355 "-------- example 186a";
   356 val t = str2term "(14 * x * y) / (x * y)";
   357   is_expanded (str2term "14 * x * y");
   358   is_expanded (str2term "x * y");
   359 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   360 if (term2str t', terms2str asm) = ("14 / 1", "[]")
   361 then () else error "rational.sml cancel Schalk 186a";
   362 
   363 "-------- example 186b";
   364 val t = str2term "(60 * a * b) / ( 15 * a  * b )";
   365 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   366 if (term2str t', terms2str asm) = ("4 / 1", "[]")
   367 then () else error "rational.sml cancel Schalk 186b";
   368 
   369 "-------- example 186c";
   370 val t = str2term "(144 * a^^^2 * b * c) / (12 * a * b * c)";
   371 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   372 if (term2str t', terms2str asm) = ("12 * a / 1", "[]")
   373 then () else error "rational.sml cancel Schalk 186c";
   374 
   375 (* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! exception Div raised !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   376   see --- fun rewrite_set_ downto fun gcd_poly ---
   377 "-------- example 187a";
   378 val t = str2term "(12 * x * y) / (8 * y^^^2 )";
   379 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   380 if (term2str t', terms2str asm) = ("3 * x / (2 * y)", "[\"4 * y ~= 0\"]")
   381 then () else error "rational.sml cancel Schalk 187a";
   382 *)
   383 
   384 (* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   385   see --- fun rewrite_set_ downto fun gcd_poly ---
   386 "-------- example 187b";
   387 val t = str2term "(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
   388 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   389 if (term2str t', terms2str asm) = ("4 * x / (9 * y)", "[\"2 * (z * (y * x)) ~= 0\"]")
   390 then () else error "rational.sml cancel Schalk 187b";
   391 *)
   392 
   393 (* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   394   see --- fun rewrite_set_ downto fun gcd_poly ---
   395 "-------- example 187c";
   396 val t = str2term "(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";
   397 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   398 if (term2str t', terms2str asm) = 
   399   ("3 * z ^^^ 3 / (5 * (y * x))", "[\"3 * (z * (y ^^^ 2 * x ^^^ 5)) ~= 0\"]") 
   400 then () else error "rational.sml cancel Schalk 187c";
   401 *)
   402 
   403 "-------- example 188a";
   404 val t = str2term "(-8 + 8 * x) / (-9 + 9 * x)";
   405   is_expanded (str2term "8 * x + -8");
   406 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   407 if (term2str t', terms2str asm) = ("8 / 9", "[]")
   408 then () else error "rational.sml cancel Schalk 188a";
   409 
   410 val t = str2term "(8*((-1) + x))/(9*((-1) + x))";
   411 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
   412 if (term2str t', terms2str asm) = ("8 / 9", "[]")
   413 then () else error "rational.sml cancel Schalk make_polynomial 1";
   414 
   415 "-------- example 188b";
   416 val t = str2term "(-15 + 5 * x) / (-18 + 6 * x)";
   417 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   418 if (term2str t', terms2str asm) = ("5 / 6", "[]")
   419 then () else error "rational.sml cancel Schalk 188b";
   420 
   421 "-------- example 188c";
   422 val t = str2term "(a + -1 * b) / (b + -1 * a)";
   423 val SOME (t', asm) = rewrite_set_ thy false  cancel_p t;
   424 if (term2str t', terms2str asm) = ("-1 / 1", "[]")
   425 then () else error "rational.sml cancel Schalk 188c";
   426 
   427 is_expanded (str2term "a + -1 * b") = true;
   428 val t = str2term "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
   429 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   430 if (term2str t', terms2str asm) = ("(a + -1 * b) / (-1 * a + b)", "[]")
   431 then () else error "rational.sml cancel Schalk make_polynomial 2";
   432 
   433 "-------- example 190a";
   434 val t = str2term "( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )";
   435 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   436 if (term2str t', terms2str asm) = 
   437   ("(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)", "[\"3 * a + 9 * a ^^^ 2 ~= 0\"]")
   438 then () else error "rational.sml cancel Schalk 190a";
   439 
   440 "-------- example 190c";
   441 val t = str2term "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
   442 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   443 if (term2str t', terms2str asm) = 
   444   ("(1 + 3 * a + 9 * a ^^^ 2 + 27 * a ^^^ 3) /\n(3 * a + 18 * a ^^^ 2 + 27 * a ^^^ 3)", "[]")
   445 then () else error "rational.sml make_polynomial Schalk 190c";
   446 
   447 "-------- example 191a";
   448 val t = str2term "( x^^^2 + -1 * y^^^2 ) / ( x + y )";
   449   is_expanded (str2term "x^^^2 + -1 * y^^^2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
   450   is_expanded (str2term "x + y") = true;
   451 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   452 if (term2str t', terms2str asm) = ("(x + -1 * y) / 1", "[]")
   453 then () else error "rational.sml make_polynomial Schalk 191a";
   454 
   455 "-------- example 191b";
   456 val t = str2term "((x + (-1) * y)*(x + y))/((1)*(x + y))";
   457 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   458 if (term2str t', terms2str asm) = ("(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)", "[]")
   459 then () else error "rational.sml make_polynomial Schalk 191b";
   460 
   461 "-------- example 191c";
   462 val t = str2term "( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )";
   463   is_expanded (str2term "9 * x^^^2 + -30 * x + 25") = true;
   464   is_expanded (str2term "25 + -30*x + 9*x^^^2") = true;
   465   is_expanded (str2term "-25 + 9*x^^^2") = true;
   466 
   467 val t = str2term "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
   468 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   469 if (term2str t', terms2str asm) = ("(25 + -30 * x + 9 * x ^^^ 2) / (-25 + 9 * x ^^^ 2)", "[]")
   470 then () else error "rational.sml make_polynomial Schalk 191c";
   471 
   472 "-------- example 192b";
   473 val t = str2term "( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 *  y^^^3 )";
   474 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   475 if (term2str t', terms2str asm) = ("x ^^^ 2 / y ^^^ 2", "[\"y ^^^ 2 ~= 0\"]")
   476 then () else error "rational.sml cancel_p Schalk 192b";
   477 
   478 val t = str2term "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
   479 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   480 if (term2str t', terms2str asm) = 
   481   ("(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)", "[]")
   482 then () else error "rational.sml make_polynomial Schalk 192b";
   483 
   484 val t = str2term "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
   485 val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   486 if (term2str t', terms2str asm) = 
   487   ("(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)", "[]")
   488 then () else error "rational.sml make_polynomial Schalk WN050929 not working";
   489 
   490 "-------- example 193a";
   491 val t = str2term "( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )";
   492 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   493 if (term2str t', terms2str asm) = ("(-3 + x) / (3 + x)", "[\"3 + x ~= 0\"]")
   494 then () else error "rational.sml cancel_p Schalk 193a";
   495 
   496 "-------- example 193b";
   497 val t = str2term "( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )";
   498 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   499 if (term2str t', terms2str asm) = ("(-4 + x) / (8 + 2 * x)", "[\"8 + 2 * x ~= 0\"]")
   500 then () else error "rational.sml cancel_p Schalk 193b";
   501 
   502 "-------- example 193c";
   503 val t = str2term "( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )";
   504 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   505 if (term2str t', terms2str asm) = 
   506   ("(2 * x + 10 * x ^^^ 2) / (1 + -5 * x)", "[\"1 + -5 * x ~= 0\"]")
   507 then () else error "rational.sml cancel_p Schalk 193c";
   508 
   509 (*WN:*)
   510 val t = str2term "(-25 + 9*x^^^2)/(5 + 3*x)";
   511 val SOME (t, asm) = rewrite_set_ thy false cancel_p t;
   512 if (term2str t', terms2str asm) = ("(2 * x + 10 * x ^^^ 2) / (1 + -5 * x)", "[]")
   513 then () else error "rational.sml cancel WN 1";
   514 
   515 (*========== inhibit exn WN130826 TODO =========================================================
   516 "-------- some old tests REVISE ! --------------------------------------------";
   517 "-------- some old tests REVISE ! --------------------------------------------";
   518 "-------- some old tests REVISE ! --------------------------------------------";
   519 (*WAS --- external calculating functions test ---*)
   520 val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
   521 val SOME (t', asm) = factout_p_ thy t;
   522 if term2str t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso terms2str asm = "[]"
   523 then () else error "factout_p_ 1 changed";
   524 val SOME (t', asm) = cancel_p_ thy t;
   525 if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[\"1 + x ~= 0\"]"
   526 then () else error "cancel_p_ 1 changed";
   527 
   528 val t = str2term "((-3 * x^^^2 + 6 *x - 3) / (2*x - 2))";
   529 val SOME (t', asm) = factout_(*p_*) thy t;
   530 if term2str t' = "(3 - 3 * x) * (-1 + x) / (2 * (-1 + x))" andalso terms2str asm = "[]"
   531 then () else error "factout_ 2 changed";
   532 val SOME (t', asm) = cancel_(*p_*) thy t;
   533 if term2str t' = "(3 - 3 * x) / 2" andalso terms2str asm = "[\"-1 + x ~= 0\"]"
   534 then () else error "cancel_ 2 changed";
   535 
   536 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
   537 val SOME (t', asm) = add_fraction_p_ thy t;
   538 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
   539 then () else error "add_fraction_p_ 3 changed";
   540 val SOME (t', asm) = common_nominator_p_ thy t;
   541 if term2str t' = 
   542   "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
   543   andalso terms2str asm = "[]"
   544 then () else error "common_nominator_p_ 3 changed";
   545 
   546 val t = str2term "((x - 1) / (x + 1)) + ((x + 1) / (x - 1))";
   547 val SOME (t', asm) = add_fraction_ thy t;
   548 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
   549 then () else error "factout_ 4 changed";
   550 val SOME (t', asm) = common_nominator_ thy t;
   551 if term2str t' = 
   552   "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))" 
   553   andalso terms2str asm = "[]"
   554 then () else error "cancel_ 4 changed";
   555 
   556 val t = str2term 
   557   "((1) / (2*x + 2)) + ((1) / (2*x + (-2))) + ((1) / ( x^^^2 + (-1)))+((1) / (x^^^2 + (-2)*x + 1))";
   558 val SOME (t', asm) = add_fraction_p_ thy t;
   559 if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
   560 then () else error "add_fraction_p_ 5 changed";
   561 val SOME (t', asm) = norm_rational_ thy t;
   562 if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
   563 then () else error "norm_rational_ 5 changed";
   564 
   565 
   566 val t3 = (term_of o the o (parse thy)) "((1) / (2*x + 2)) + ((1) / (2*x - 2)) + ((1) / ( x^^^2 - 1))+((1) / (x^^^2 - 2 * x + 1))";
   567 val SOME (t3',_) = common_nominator_ thy t3; 
   568 val SOME (t3'',_) = add_fraction_ thy t3; 
   569 (term2str t3'); 
   570 (term2str t3''); 
   571 
   572 val SOME(t4,t5) = norm_expanded_rat_ thy t3;
   573 term2str t4;
   574 term2str (hd(t5));
   575 
   576 
   577 
   578   val t=(term_of o the o (parse thy)) "(9 - x^^^2)/(9 - 6*x + x^^^2)";
   579   val SOME (t',_) = factout_ thy t;
   580   val SOME (t'',_) = cancel_ thy t;
   581   term2str t';
   582   term2str t'';
   583   "(3 + x) * (3 - x) / ((3 - x) * (3 - x))";
   584   "(3 + x) / (3 - x)";
   585   			   
   586   val t=(term_of o the o (parse thy))
   587 	    "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1 / (3 - x)";
   588   val SOME (t',_) = common_nominator_ thy t;
   589   val SOME (t'',_) = add_fraction_ thy t;
   590   term2str t';
   591   term2str t'';
   592   "(9 - x ^^^ 2) / ((3 - x) * (3 - x)) + 1 * (3 - x) / ((3 - x) * (3 - x))";
   593   "(4 + x) / (3 - x)";
   594 
   595 (*WN021016 added -----vv---*)
   596 val t = str2term "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1";
   597 val SOME (t',_) = common_nominator_ thy t;
   598 val SOME (t'',_) = add_fraction_ thy t;
   599 term2str t' = "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n1" ^
   600 		" * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
   601 term2str t'' = "6 / (3 - x)" (*true*);
   602 
   603 val t = str2term "1 + (9 - x^^^2) / (9 - 6*x + x^^^2)";
   604 val SOME (t',_) = common_nominator_ thy t;
   605 val SOME (t'',_) = add_fraction_ thy t;
   606 term2str t' = "1 * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n" ^
   607 		"(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
   608 term2str t'' = "6 / (3 - x)" (*true*);
   609 (*WN021016 added -----^^---*)
   610 (*WN030602 added -----vv--- no rewrite -> NONE !*)
   611 val t = str2term "1 / a";
   612 val NONE =  cancel_p_ thy t;
   613 val NONE = rewrite_set_ thy false cancel_p t;
   614 (*WN.2.6.03 added -------^^---*)
   615 
   616 val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2)";
   617 val SOME (t',_) = factout_ thy t;
   618 val SOME (t'',_) = cancel_ thy t;
   619 term2str t' = "(y + x) * (y - x) / ((y - x) * (y - x))"(*true*);
   620 term2str t'' = "(y + x) / (y - x)";
   621     
   622 val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2) + 1 / (y - x)";
   623 val SOME (t',_) = common_nominator_ thy t;
   624 val SOME (t'',_) = add_fraction_ thy t;
   625 term2str t' =
   626 "(-1 * x ^^^ 2 + y ^^^ 2) / ((-1 * x + y) * (-1 * x + y)) +\n1" ^
   627 " * (-1 * x + y) / ((-1 * x + y) * (-1 * x + y))" (*true*);
   628 term2str t'' = "(-1 - x - y) / (x - y)" (*true*);
   629 
   630 val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2) + 1 / (x - y)";
   631 val SOME (t',_) = common_nominator_ thy t;
   632 val SOME (t'',_) = add_fraction_ thy t;
   633 if term2str t' = "(-1 * y ^^^ 2 + x ^^^ 2) / ((-1 * y + x) * (-1 * y + x))" ^
   634 " +\n1 * (-1 * y + x) / ((-1 * y + x) * (-1 * y + x))" then ()
   635 else error "rational.sml lex-ord 1";
   636 if term2str t'' = "(-1 - y - x) / (y - x)" then ()
   637 else error "rational.sml lex-ord 2";
   638 (*WN.16.10.02 WN070905 lexicographische Ordnung erhalten *)
   639 
   640 
   641 val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2)";
   642 val SOME (t',_) = norm_expanded_rat_ thy t; 
   643 if term2str t' = "(x + y) / (x - y)" then ()
   644 else error "rational.sml term2poly: invalid x ^^^ 2 - y ^^^ 2 No.1";
   645 (*val SOME (t'',_) = norm_rational_ thy t;
   646  *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial 
   647 WN.16.10.02 ?! + WN060831???SK4 
   648 WN070905 *** term2poly: invalid = x ^^^ 2 - y ^^^ 2*)
   649 
   650  
   651 val t = str2term "(9 - x^^^2)/(9 - 6*x + x^^^2) + (1)/(3 + x)";
   652 val SOME (t',_) = norm_expanded_rat_ thy t;
   653 if term2str t' = "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)" then ()
   654 else error "rational.sml (9 - x^^^2)/(9 - 6*x + x^^^2) +...";
   655 (*val SOME (t'',_) = norm_rational_ thy t;
   656   *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial WN.16.10.02 ?!
   657 WN070906 *** term2poly: invalid = 9 - x ^^^ 2 SK.term2poly*)
   658  
   659   val t=(term_of o the o (parse thy)) 
   660 	    "(9 + (-1)* x^^^2)/(9 + (-1)* 6*x + x^^^2) + (1)/(3 + x)";
   661   val SOME (t',_) = norm_expanded_rat_ thy t;
   662   val SOME (t'',_) = norm_rational_ thy t;
   663   term2str t';
   664   term2str t'';
   665   "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)";
   666   "(12 + 5 * x + x ^^^ 2) / (9 + (-1) * x ^^^ 2)";
   667 
   668 
   669 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
   670 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
   671 "-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
   672 val thy  = @{theory "Rational"};
   673 val thy' = "Rational";
   674 val rls' = "cancel";
   675 val mp = "make_polynomial";
   676 
   677 writeln ("example 186:");
   678 writeln("a)");
   679 val e186a'="(14 * x * y) / ( x * y )";(*SRC*)
   680 rewrite_set_ thy false cancel (str2term e186a');
   681 "@@@@@@@@@@@@@@";
   682 val e186a = the (rewrite_set thy' false "cancel" e186a');
   683   is_expanded (parse_rat "14 * x * y");
   684   is_expanded (parse_rat "x * y");
   685 if e186a = ("14 / 1", "[\"y * x ~= 0\"]") then ()
   686 else error "rational.sml cancel Schalk e186a";
   687 
   688 writeln("b)");
   689 val e186b'="(60 * a * b) / ( 15 * a  * b )";
   690 val e186b = the (rewrite_set thy' false "cancel" e186b');
   691 writeln("c)");
   692 val e186c'="(144 * a^^^2 * b * c) / (12 * a * b * c )";
   693 val e186c = (the (rewrite_set thy' false "cancel" e186c'))
   694     handle e => print_exn_G e;
   695 val t = (term_of o the o (parse thy)) e186c';
   696 if e186c = ("12 * a / 1", "[\"12 * (c * (b * a)) ~= 0\"]") then ()
   697 else error "rational.sml cancel Schalk e186c";
   698 
   699 writeln ("example 187:");
   700 writeln("a)");
   701 val e187a'="(12 * x * y) / (8 * y^^^2 )";(*SRC*)
   702 val e187a = the (rewrite_set thy' false "cancel" e187a');
   703 writeln("b)");
   704 val e187b'="(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
   705 val e187b = the (rewrite_set thy' false "cancel" e187b');
   706 writeln("c)");
   707 val e187d'="(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";(*SRC*)
   708 val e187d = the (rewrite_set thy' false "cancel" e187d');
   709 if e187d = ("3 * z ^^^ 3 / (5 * (y * x))",
   710             "[\"3 * (z * (y ^^^ 2 * x ^^^ 5)) ~= 0\"]") then ()
   711 else error "rational.sml cancel Schalk e186d";
   712 
   713 writeln "example 188:";
   714 val e188a'="(-8 + 8 * x) / (-9 + 9 * x)";(*SRC*)
   715 val e188a = the (rewrite_set thy' false "cancel" e188a');
   716   is_expanded (parse_rat "8 * x + -8");
   717 (* e188a = ("8 / 9",["not ((-1) + x = 0)"]) then () 13.3.03*)
   718 if e188a = ("8 / 9", "[\"-1 + x ~= 0\"]") then ()
   719 else error "rational.sml: e188a new behaviour";
   720 
   721 val SOME (t,_) = rewrite_set thy' false mp "(8*((-1) + x))/(9*((-1) + x))";
   722 writeln("b)");
   723 val e188b'="(-15 + 5 * x) / (-18 + 6 * x)";(*SRC*)
   724 val SOME (t, asm) = rewrite_set thy' false "cancel" e188b';
   725 t = "5 / 6" (*true*);
   726 writeln("c)");
   727 
   728 val e188c'="( a + -1 * b ) / ( b + -1 * a )";
   729 val e188c = the (rewrite_set thy' false "cancel_p" e188c');
   730 (*is_expanded (parse_rat "a + -1 * b");*)
   731 val SOME (t,_) = 
   732     rewrite_set thy' false mp "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
   733 if t= "(a + -1 * b) / (-1 * a + b)"  then()
   734 else error "rational.sml: e188c new behaviour";
   735 
   736 writeln ("example 190:");
   737 writeln("c)");
   738 val e190c'="( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )";
   739 val e190c = the (rewrite_set thy' false "cancel" e190c');
   740 val SOME (t,_) = rewrite_set thy' false mp "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
   741 if t = "(1 + 3 * a + 9 * a ^^^ 2 + 27 * a ^^^ 3) /\n(3 * a + 18 * a ^^^ 2 + 27 * a ^^^ 3)" then ()
   742 else error "rational.sml: e190c new behaviour";
   743 
   744 writeln ("example 191:");
   745 writeln("a)");
   746 val e191a'="( x^^^2 + -1 * y^^^2 ) / ( x + y )";
   747 (*WN.23.10.02-------
   748 val e191a = the (rewrite_set thy' false "cancel" e191a'); 
   749   is_expanded (parse_rat "x^^^2 + -1 * y^^^2");
   750   false;
   751   is_expanded (parse_rat "x + y");
   752   true; -----------*)
   753 val SOME (t,_) = rewrite_set thy' false mp "((x + (-1) * y)*(x + y))/((1)*(x + y))";
   754 (* t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then() WN.13.3.03*)
   755 if t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then()
   756 else error "rational.sml: e191a new behaviour";
   757 
   758 writeln("c)");
   759 val e191c'="( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )";
   760 (*WN.23.10.02-------
   761 val e191c = the (rewrite_set thy' false "cancel" e191c');
   762   is_expanded (parse_rat "9 * x^^^2 + -30 * x + 25");
   763   false;
   764   is_expanded (parse_rat "25 + -30*x + 9*x^^^2");
   765   false;
   766   is_expanded (parse_rat "-25 + 9*x^^^2");
   767   true;------------*)
   768 val SOME (t,_) = rewrite_set thy' false mp "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
   769 (* t="(25 + ((-30) * x + 9 * x ^^^ 2)) / ((-25) + 9 * x ^^^ 2)"then() 13.3.03*)
   770 if t= "(25 + -30 * x + 9 * x ^^^ 2) / (-25 + 9 * x ^^^ 2)" then()
   771 else error "rational.sml: 'e191c' new behaviour";
   772 
   773 
   774 writeln ("example 192:");
   775 writeln("b)");
   776 val e192b'="( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 *  y^^^3 )";
   777 (*WN.23.10.02-------
   778 val e192b = the (rewrite_set thy' false "cancel" e192b');
   779 -------------------*)
   780 val SOME (t',_) = rewrite_set thy' false mp "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
   781 (*========== inhibit exn 110317 ================================================
   782 if t' = "(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)"
   783 (*"(-1 * y * x ^^^ 2 + 7 * x ^^^ 3) / (-1 * y ^^^ 3 + 7 * x * y ^^^ 2)"WN050929*)
   784 then () else error "rational.sml: 'e192b' new behaviour";
   785 (*^^^ works with MG's simplifier vvv*)
   786 val t =str2term"((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
   787 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
   788 if term2str t' = "(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)" then () else error "rational.sml: 'e192b'MG new behaviour";
   789 ============ inhibit exn 110317 ==============================================*)
   790 
   791 writeln ("example 193:");
   792 writeln("a)");
   793 val e193a'="( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )";
   794 (*WN.23.10.02-------
   795 val e193a = the (rewrite_set thy' false "cancel" e193a');
   796 -------------------*)
   797 writeln("b)");
   798 val e193b'="( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )";
   799 (*WN.23.10.02-------
   800 val e193b = the (rewrite_set thy' false "cancel" e193b');
   801 writeln("c)");
   802 val e193c'="( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )";
   803 val SOME(t,_) = rewrite_set thy' false "cancel" e193c';
   804 -------------------*)
   805 
   806 val wn01 = "(-25 + 9*x^^^2)/(5 + 3*x)";
   807 val SOME (t, asm) = rewrite_set thy' false "cancel" wn01;
   808 (* t = "((-5) + 3 * x) / 1" then () WN.13.3.03*)
   809 if t = "(-5 + 3 * x) / 1" andalso asm = "[\"5 + 3 * x ~= 0\"]" then ()
   810 else error "rational.sml: new behav. in cancel wn01";
   811 
   812 "-------- common_nominator_p ----------------------------";
   813 "-------- common_nominator_p ----------------------------";
   814 "-------- common_nominator_p ----------------------------";
   815 val rls' = "common_nominator_p";
   816 
   817 writeln ("example 204:");
   818 writeln("a)");
   819 val e204a'="((5 * x) / 9) + ((3 * x) / 9) + (x / 9)";
   820 val e204a = the (rewrite_set thy' false "common_nominator_p" e204a');
   821 writeln("b)");
   822 val e204b'="5 / x + -3 / x + -1 / x";
   823 val e204b = the (rewrite_set thy' false "common_nominator_p" e204b');
   824 if e204b = ("1 / x", "[]") then ()
   825 else error "rational.sml common_nominator_p example e204b";
   826 
   827 writeln ("example 205:");
   828 writeln("a)");
   829 val e205a'="((4 * x + 7) / 8) + ((4 * x + 3) / 8)";
   830 val e205a = the (rewrite_set thy' false "common_nominator_p" e205a');
   831 writeln("b)");
   832 val e205b'="((5 * x + 2) / 3) + ((-2 * x + 1) / 3)";
   833 val e205b = the (rewrite_set thy' false "common_nominator_p" e205b');
   834 if e205b = ("(1 + x) / 1", "[]") then ()
   835 else error "rational.sml common_nominator_p example e204b";
   836 
   837 writeln ("example 206:");
   838 writeln("a)");
   839 val e206a'="((5 * x + 4) / (2 * x + -1)) + ((9 * x + 5) / (2 * x + -1))";
   840 val e206a = the (rewrite_set thy' false "common_nominator_p" e206a'); 
   841 writeln("b)");
   842 val e206b'="((17 * x + -23) / (5 * x + 4)) + ((-25 + -17 * x) / (5 * x + 4))";
   843 val e206b = the (rewrite_set thy' false "common_nominator_p" e206b');
   844 
   845 writeln ("example 207:");
   846 val e207'="((3 * x * y + 3 * y) / (x * y)) + ((5 * x * y + 7 * y) / (x * y)) + ((9 * x * y + -2 * y) / (x * y)) + ((x * y + 4 * y) / (x * y)) ";
   847 val e207 = the (rewrite_set thy' false "common_nominator_p" e207'); 
   848 
   849 writeln ("example 208:");
   850 val e208'="((3 * x + 2) / (x + 2)) + ((5 * x + -1) / (x + 2)) + ((-7 * x + -3) / (x + 2)) + ((-1 * x + -3) / (x + 2)) ";
   851 val e208 = the (rewrite_set thy' false "common_nominator_p" e208'); 
   852 
   853 writeln ("example 209:");
   854 val e209'="((3 * x + -7 * y + 3 * z) / (4)) + ((2 * x + 17 * y + 10 * z) / (4)) + ((-1 * x + 2 * y + z) / (4)) ";
   855 val e209 = the (rewrite_set thy' false "common_nominator_p" e209'); 
   856 
   857 writeln ("example 210:");
   858 val e210'="((2 * x + 3 +  -1 * x^^^2) / (5 * x)) + ((5 * x^^^2 + -2 * x + 1) / (5 * x)) + ((-3 * x^^^2 + -2 * x + 1) / (5 * x)) + ((-1 * x^^^2 + -3 * x + -5) / (5 * x)) ";
   859 val e210 = the (rewrite_set thy' false "common_nominator_p" e210'); 
   860 
   861 writeln ("example 211:");
   862 writeln("a)"); 
   863 val e211a'="((b) / (a + -1 * b)) + ((-1 * a) / (a + -1 * b))"; 
   864 val e211a = the (rewrite_set thy' false "common_nominator_p" e211a'); 
   865 writeln("b)");
   866 val e211b'="((b) / (b^^^2 + -1 * a^^^2)) + ((-1 * a) / (b^^^2 + -1 * a^^^2))";
   867 val e211b = the (rewrite_set thy' false "common_nominator_p" e211b');
   868 
   869 writeln ("example 212:");
   870 writeln("a)");
   871 val e212a'="((4) / (x)) + ((-3) / (y)) + -1";
   872 val e212a = the (rewrite_set thy' false "common_nominator_p" e212a'); 
   873 writeln("b)");
   874 val e212b'="((4) / (x)) + ((-5) / (y)) + ((6) / (x*y))";
   875 val e212b = the (rewrite_set thy' false "common_nominator_p" e212b');
   876 
   877 writeln ("example 213:");
   878 writeln("a)"); 
   879 val e213a'="((5 * x) / (3 * y^^^2)) + ((19 * z) / (6 * x * y)) +  ((-2 * x) / (3 * y^^^2)) + ((7 * y^^^2) / (6 * x^^^2)) ";
   880 val e213a = the (rewrite_set thy' false "common_nominator_p" e213a'); 
   881 writeln("b)"); 
   882 val e213b'="((2 * b) / (3 * a^^^2)) + ((3 * c) / (7 * a * b)) +  ((4 * b) / (3 * a^^^2)) + ((3 * a) / (7 * b^^^2))";
   883 val e213b = the (rewrite_set thy' false "common_nominator_p" e213b');
   884 
   885 writeln ("example 214:");
   886 writeln("a)");
   887 val e214a'="((3 * x + 2 * y + 2 * z) / (4)) + ((-5 * x + -3 * y) / (3)) + ((x + y + -2 * z) / (2))";
   888 val e214a = the (rewrite_set thy' false "common_nominator_p" e214a'); 
   889 writeln("b)");
   890 val e214b'="((5 * x + 2 * y + z) / (2)) + ((-7 * x + -3 * y) / (3)) + ((3 * x + 6 * y + -1 * z) / (12))";
   891 val e214b = the (rewrite_set thy' false "common_nominator_p" e214b');
   892 
   893 writeln ("example 216:");
   894 writeln("a)"); 
   895 val e216a'="((2 * b + 3 * c) / (a * c)) + ((3 * a + b) / (a * b)) + ((-2 * b^^^2 + -3 * a * c) / (a * b * c))";
   896 val e216a = the (rewrite_set thy' false "common_nominator_p" e216a');  
   897 writeln("b)");
   898 val e216b'="((2 * a + 3 * b) / (b * c)) + ((3 * c + a) / (a * c)) + ((-2 * a^^^2 + -3 * b * c) / (a * b * c))";
   899 val e216b = the (rewrite_set thy' false "common_nominator_p" e216b');
   900 
   901 writeln ("example 217:");
   902 val e217'="((z + -1) / (z)) + ((3 * z ^^^2 + -6 * z + 5) / (z^^^2)) + ((-4 * z^^^3 + 7 * z^^^2 + -5 * z + 5) / (z^^^3))";
   903 val e217 = the (rewrite_set thy' false "common_nominator_p" e217'); 
   904 
   905 
   906 val rls' = "common_nominator";
   907 writeln ("example 218:"); 
   908 val e218'="((9 * a^^^3 - 5 * a^^^2 + 2 * a + 8) / (108 * a^^^4)) + ((-5 * a + 3 * a^^^2 + 4) / (8 * a^^^3)) + ((-261 * a^^^3 + 19 * a^^^2 + -112 * a + 16) / (216 * a^^^4))";
   909 val e218 = the (rewrite_set thy' false "common_nominator" e218'); 
   910 if e218 = ("(16 - 63 * a ^^^ 2 - 81 * a ^^^ 3) / (108 * a ^^^ 4)", "[]") then ()
   911 else error "rationa.sml common_nominator example e218";
   912 
   913 writeln ("example 219:");
   914 writeln("a)");
   915 val e219a'="((1) / (y + 1)) + ((1) / (y + 2)) + ((1) / (y + 3))";
   916 val e219a = the (rewrite_set thy' false "common_nominator" e219a');
   917 writeln("b)");
   918 val e219b'="((1) / (x + 1)) + ((1) / (x + 2)) + ((-2) / (x + 3))";
   919 val e219b = the (rewrite_set thy' false "common_nominator" e219b'); 
   920 if e219b = ("(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)", "[]") then ()
   921 else error "rationa.sml common_nominator example e219b";
   922 
   923 writeln ("example 220:");
   924 writeln("a)");
   925 val e220a'="((17) / (5 * r + -2)) + ((-13) / (2 * r + 3)) + ((4) / (3 * r + -5))";
   926 val e220a = the (rewrite_set thy' false "common_nominator" e220a');
   927 writeln("b)");
   928 val e220b'="((20 * a) / (a + -3)) + ((-19 * a) / (a + -4)) + ((a) / (a + -5))";
   929 val e220b = the (rewrite_set thy' false "common_nominator" e220b'); 
   930 
   931 writeln ("example 221:");
   932 writeln("a)");
   933 val e221a'="((a + b) / (a + -1 * b)) + ((a + -1 * b) / (a + b))";
   934 val e221a = the (rewrite_set thy' false "common_nominator" e221a');
   935 writeln("b)");
   936 val e221b'="((x + -1 * y) / (x + y)) + ((x + y) / (x + -1 * y)) ";
   937 val e221b = the (rewrite_set thy' false "common_nominator" e221b');
   938 
   939 writeln ("example 222:");
   940 writeln("a)");
   941 val e222a'="((1 + -1 * x) / (1 + x)) + ((-1 + -1 * x) / (1 + -1 * x)) + ((4 * x) / (1 + -1 * x^^^2))";
   942 val e222a = the (rewrite_set thy' false "common_nominator" e222a');
   943 writeln("b)");
   944 val e222b'="((1 + x ) / (1 + -1 * x)) + ((-1 + x) / (1 + x)) + ((2 * x) / (1 + -1 * x^^^2))";
   945 val e222b = the (rewrite_set thy' false "common_nominator" e222b'); 
   946 
   947 writeln ("example 225:");
   948 writeln("a)");
   949 val e225a'="((6 * a) / (a^^^2 + -64)) + ((a + 2) / (2 * a + 16)) + ((-1) / (2))";
   950 val e225a = the (rewrite_set thy' false "common_nominator" e225a');
   951 writeln("b)");
   952 val e225b'="((a + 2 ) / (2 * a + 12)) + ((4 * a) / (a^^^2 + -36)) + ((-1) / (2))";
   953 val e225b = the (rewrite_set thy' false "common_nominator" e225b'); 
   954 
   955 writeln ("example 226:");
   956 writeln("a)");
   957 val e226a'="((35 * z) / (49 * z^^^2 + -4)) + -1 + ((14 * z + -1) / (14 * z + 4)) ";
   958 val e226a = the (rewrite_set thy' false "common_nominator" e226a');
   959 writeln("b)"); 
   960 val e226b'="((45 * a * b) / (25 * a^^^2 + -9 * b^^^2)) + ((20 * a + 3 * b) / (10 * a + 6 * b))  + -2";
   961 val e226b = the (rewrite_set thy' false "common_nominator" e226b');  
   962 
   963 writeln ("example 227:");
   964 writeln("a)");
   965 val e227a'="((6 * z + 11) / (6 * z + 14)) + ((9 * z ) / (9 * z^^^2 + -49)) + -1 ";
   966 val e227a = the (rewrite_set thy' false "common_nominator" e227a');
   967 writeln("b)");
   968 val e227b'="((16 * a + 37 * b) / (4 * a + 10 * b)) + ((6 * a * b) / (4 * a^^^2 + -25 * b^^^2)) + -4 ";
   969 val e227b = the (rewrite_set thy' false "common_nominator" e227b'); 
   970 
   971 writeln ("example 228:");
   972 writeln("a)");
   973 val e228a'="((7 * a + 11) / (3 * a^^^2 + -3)) + ((-2 * a + -1) / (a^^^2 + -1 * a)) + ((-1) / (3 * a + 3))";
   974 val e228a = the (rewrite_set thy' false "common_nominator" e228a'); 
   975 writeln("b)");
   976 val e228b'="((11 * z + 2 * b) / (4 * b * z + -8 * b^^^2)) + ((-8 * z) / (z^^^2 + -4 * b^^^2)) + ((-9 * z + -2 * b) / (4 * b * z + 8 * b^^^2))";
   977 val e228b = the (rewrite_set thy' false "common_nominator" e228b');  
   978 
   979 
   980 writeln ("example 229:");
   981 writeln("a)");
   982 val e229a'="((5 * x^^^2 + y) / (x + 2 * y)) + ((-8 * x^^^3 + 4 * x^^^2 * y + 3 * x * y) / (x^^^2 + -4 * y^^^2)) + ((3 * x^^^2 + -4 * y) / (x + -2 * y))";
   983 val e229a = the (rewrite_set thy' false "common_nominator" e229a'); 
   984 writeln("b)");
   985 val e229b'="((7 * x^^^2 + y) / (x + 3 * y)) + ((-24 * x^^^2 * y + 5 * x * y + 21 * y^^^2) / (x^^^2 + -9 * y^^^2)) + ((4 * x^^^2 + -6 * y) / (x + -3 * y))"; 
   986 val e229b = the (rewrite_set thy' false "common_nominator" e229b'); 
   987  
   988 writeln ("example 230:");
   989 writeln("a)"); 
   990 val e230a'="((5 * x^^^2 + y) / (2 * x + y)) + ((-16 * x^^^3 + 2 * x^^^2 * y + 6 * x * y) / (4 * x^^^2 + -1 * y^^^2)) + ((3 * x^^^2 + -4 * y) / (2 * x + -1 * y))";
   991 val e230a = the (rewrite_set thy' false "common_nominator" e230a');
   992 writeln("b)");
   993 val e230b'="((7 * x^^^2 + y) / (3 * x + y)) + ((-3 * x^^^3  + 15 * x * y + -7 * x^^^2 * y + 7 * y^^^2) / (9 * x^^^2 + -1 * y^^^2)) + ((4 * x^^^2 + -6 * y) / (3 * x + -1 * y))";
   994 val e230b = the (rewrite_set thy' false "common_nominator" e230b');
   995 
   996 writeln ("example 231:");
   997 writeln("a)");
   998 val e231a'="((2 * x + 5 * y) / (x)) + ((2 * x^^^3 + -5 * y^^^3 + 3 * x * y^^^2) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-3 * x + -6 * y) / (x + -1 * y))";
   999 val e231a = the (rewrite_set thy' false "common_nominator" e231a'); 
  1000 writeln("b)");
  1001 val e231b'="((6 * x + 2 * y) / (x)) + ((6 * x^^^2 * y + -4 * x * y^^^2 + -2 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-5 * x + -3 * y) / (x + -1 * y))";
  1002 val e231b = the (rewrite_set thy' false "common_nominator" e231b');
  1003 
  1004 writeln ("example 232:");
  1005 writeln("a)");
  1006 val e232a'="((2 * x + 3 * y) / (x)) + ((4 * x^^^3 + -1 * x * y^^^2 + -3 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-5 * x + -6 * y) / (x + -1 * y))";
  1007 val e232a = the (rewrite_set thy' false "common_nominator" e232a'); 
  1008 writeln("b)");
  1009 val e232b'="((5 * x + 2 * y) / (x)) + ((2 * x^^^3 + -3 * x * y^^^2 + 3 * x^^^2 * y + -2 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-6 * x + -3 * y) / (x + -1 * y))";
  1010 val e232b = the (rewrite_set thy' false "common_nominator" e232b');
  1011 
  1012 writeln ("example 233:");
  1013 writeln("a)");
  1014 val e233a'="((5 * x + 6 * y) / (x)) + ((5 * x * y^^^2 + -6 * y^^^3 + -2 * x^^^3 + 3 * x^^^2 * y) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-2 * x + -3 * y) / (x + -1 * y))";
  1015 val e233a = the (rewrite_set thy' false "common_nominator" e233a'); 
  1016 writeln("b)");
  1017 val e233b'="((6 * x + 5 * y) / (x)) + ((4 * x^^^2 * y + 3 * x * y^^^2 + -5 * y^^^3 + -2 * x^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-3 * x + -2 * y) / (x + -1 * y))";
  1018 val e233b = the (rewrite_set thy' false "common_nominator" e233b');
  1019 
  1020 writeln ("example 234:");
  1021 writeln("a)");
  1022 val e234a'="((5 * a + b) / (2 * a * b + -2 * b^^^2)) + ((-3 * a + -1 * b) / (2 * a * b + 2 * b^^^2)) + ((-2 * a) / (a^^^2 + -1 * b^^^2))";
  1023 val e234a = the (rewrite_set thy' false "common_nominator" e234a'); 
  1024 writeln("b)"); 
  1025 val e234b'="((5 * a + 3 * b) / (6 * a * b + -18 * b^^^2)) + ((-3 * a + -3 * b) / (6 * a * b + 18 * b^^^2)) + ((-2 * a) / (a^^^2 + -9 * b^^^2)) ";
  1026 val e234b = the (rewrite_set thy' false "common_nominator" e234b');  
  1027 
  1028 writeln ("example 235:");
  1029 writeln("a)");
  1030 val e235a'="((10 * x + 3 * y) / (12 * x * y + -18 * y^^^2)) + ((-6 * x + -3 * y) / (12 * x * y + 18 * y^^^2)) + ((-4 * x) / (4 * x^^^2 + -9 * y^^^2))";
  1031 val e235a = the (rewrite_set thy' false "common_nominator" e235a'); 
  1032 writeln("b)"); 
  1033 val e235b'="((8 * a + b) / (4 * a * b + -2 * b^^^2)) + ((-4 * a + -1 * b) / (4 * a * b + 2 * b^^^2)) + ((-2 * a) / (4 * a^^^2 + -1 * b^^^2)) ";
  1034 val e235b = the (rewrite_set thy' false "common_nominator" e235b');  
  1035  
  1036 writeln ("example 236:");
  1037 writeln("a)"); 
  1038 val e236a'="((8 * a + 5 * b) / (20 * a * b + -50 * b^^^2)) + ((-4 * a + -5 * b) / (20 * a * b + 50 * b^^^2)) + ((-2 * a) / (4 * a^^^2 + -25 * b^^^2))";
  1039 val e236a = the (rewrite_set thy' false "common_nominator" e236a');  
  1040 writeln("b)");   
  1041 val e236b'="((24 * x + y) / (6 * x * y + -2 * y^^^2)) + ((-18 * x + -1 * y) / (6 * x * y + 2 * y^^^2)) + ((-15 * x) / (9 * x^^^2 + -1 * y^^^2)) ";
  1042 val e236b = the (rewrite_set thy' false "common_nominator" e236b');  
  1043 
  1044 
  1045 val rls' = "cancel";
  1046 writeln ("example heuberger:");
  1047 val eheu'="(x^^^4 + x * y + x^^^3 * y + y^^^2) / (x + 5 * x^^^2 + y + 5 * x * y + x^^^2 * y^^^3 + x * y^^^4)";
  1048 val eheu = the (rewrite_set thy' false "cancel" eheu');
  1049 
  1050 val rls' = "common_nominator_p";
  1051 writeln ("example stiefel:");
  1052 val est1'="(7) / (-14) + (-2) / (4)";
  1053 val est1 = the (rewrite_set thy' false "common_nominator_p" est1');
  1054 if est1 = ("-1 / 1", "[]") then ()
  1055 else error "new behaviour in rational.sml: est1'";
  1056     
  1057 val t = (term_of o the o (parse thy))
  1058 "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
  1059 val SOME (t',_) = factout_ thy t;
  1060 if term2str t' = "(3 + x) * (3 - x) / ((3 - x) * (3 - x))" then ()
  1061 else error "rational.sml factout_ (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
  1062     
  1063 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
  1064 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
  1065 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
  1066 val t = str2term ("123 = (a*x)/(b*x) + (c*x)/(d*x) + (e*x)/(f*x::real)");
  1067 "-------- gcd_poly integration level 1: works on exact term";
  1068 if NONE = cancel_p_ thy t then () else error "cancel_p_ works on exact fraction";
  1069 if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ works on exact fraction";
  1070 
  1071 "-------- gcd_poly integration level 2: picks out ONE appropriate subterm";
  1072 val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
  1073 if term2str t' = "123 = a * x / (b * x) + c * x / (d * x) + e / f" 
  1074 then () else error "level 2, rewrite_set_ cancel_p: changed";
  1075 val SOME (t', asm) = rewrite_set_ thy false add_fractions_p t;
  1076 if term2str t' = "123 = (b * c * x + a * d * x) / (b * d * x) + e * x / (f * x)"
  1077 then () else error "level 2, rewrite_set_ add_fractions_p: changed";
  1078 
  1079 "-------- gcd_poly integration level 3: rewrites all appropriate subterms";
  1080 val SOME (t', asm) = rewrite_set_ thy false cancel_p_rls t;
  1081 if term2str t' = "123 = a / b + c / d + e / f"
  1082 then () else error "level 3, rewrite_set_ cancel_p_rls: changed";
  1083 val SOME (t', asm) = rewrite_set_ thy false common_nominator_p_rls t; (*CREATE add_fractions_p_rls*)
  1084 if term2str t' = "123 = (b * d * e * x + b * c * f * x + a * d * f * x) / (b * d * f * x)"
  1085 then () else error "level 3, rewrite_set_ add_fractions_p_rls: changed";
  1086 
  1087 "-------- gcd_poly integration level 4: iteration cancel_p -- add_fraction_p";
  1088 (* simpler variant *)
  1089 val testrls = append_rls "testrls" e_rls [Rls_ cancel_p, Rls_ add_fractions_p]
  1090 val SOME (t', asm) = rewrite_set_ thy false testrls t;
  1091 (*trace_rewrite := false;
  1092 #  rls: testrls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
  1093 ##  rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
  1094 ##  rls: common_nominator_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f 
  1095 ##  rls: cancel_p on: 123 = (b * c * x + a * d * x) / (b * d * x) + e / f 
  1096 ##  rls: common_nominator_p on: 123 = (b * c + a * d) / (b * d) + e / f 
  1097 ##  rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) 
  1098 ##  rls: common_nominator_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
  1099 if term2str t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
  1100 then () else error "level 4, rewrite_set_ *_p: changed";
  1101 
  1102 (* complicated variant *)
  1103 val testrls_rls = append_rls "testrls_rls" e_rls [Rls_ cancel_p_rls, Rls_ common_nominator_p_rls];
  1104 val SOME (t', asm) = rewrite_set_ thy false testrls_rls t;
  1105 (*#  rls: testrls_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
  1106 ##  rls: cancel_p_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
  1107 ###  rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
  1108 ###  rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f 
  1109 ###  rls: cancel_p on: 123 = a * x / (b * x) + c / d + e / f 
  1110 ###  rls: cancel_p on: 123 = a / b + c / d + e / f 
  1111 ##  rls: common_nominator_p_rls on: 123 = a / b + c / d + e / f 
  1112 ###  rls: common_nominator_p on: 123 = a / b + c / d + e / f 
  1113 ###  rls: common_nominator_p on: 123 = (b * c + a * d) / (b * d) + e / f 
  1114 ###  rls: common_nominator_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) 
  1115 ##  rls: cancel_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) 
  1116 ###  rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) 
  1117 ##  rls: common_nominator_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) 
  1118 ###  rls: common_nominator_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
  1119 if term2str t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
  1120 then () else error "level 4, rewrite_set_ *_p_rls: changed"
  1121 
  1122 "-------- gcd_poly integration level 5: cancel_p & add_fraction_p within norm_Rational";
  1123 val SOME (t', asm) = rewrite_set_ thy false norm_Rational t;
  1124 if term2str t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)"
  1125 then () else error "level 5, rewrite_set_ norm_Rational: changed"
  1126 
  1127 "-------- reverse rewrite -------------------------------";
  1128 "-------- reverse rewrite -------------------------------";
  1129 "-------- reverse rewrite -------------------------------";
  1130 (*WN.28.8.02: tests for the 'reverse-rewrite' functions:
  1131   these are defined in Rationals.ML and stored in 
  1132   the 'reverse-ruleset' cancel*)
  1133 
  1134 (*the term for which reverse rewriting is demonstrated*)
  1135   val t = (term_of o the o (parse thy))
  1136 	      "(9 - x ^^^ 2) / (9 + 6 * x + x ^^^ 2)";
  1137   val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
  1138   		       next_rule=nex,normal_form=nor,...},...} = cancel;
  1139 
  1140 (*normal_form produces the result in ONE step*)
  1141   val SOME (t',_) = nor t;
  1142 if term2str t' = "(3 - x) / (3 + x)" then ()
  1143 else error "rational.sml normal_form (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
  1144 
  1145 (*initialize the interpreter state used by the 'me'*)
  1146   val (t,_,revsets,_) = ini t;
  1147 
  1148 (*find the rule 'r' to apply to term 't'*)
  1149   val SOME (r as (Thm (str, thm))) = nex revsets t;
  1150 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))"
  1151    andalso string_of_thm thm = 
  1152            (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
  1153                (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
  1154 else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
  1155 (* before Isa02->09-2 was not checked automatically, ?was different?:
  1156 val SOME r = nex revsets t;
  1157 val r = Thm ("sym_#mult_2_3","6 = 2 * 3") : rule*)
  1158 
  1159 (* check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
  1160   if the rule is OK, the term resulting from applying the rule is returned,too;
  1161   there might be several rule applications inbetween,
  1162   which are listed after the head in reverse order *)
  1163   val (r, (t, asm))::_ = loc revsets t r;
  1164 if term2str t = "(9 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" andalso asm = []
  1165 then () 
  1166 else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
  1167 
  1168 (* find the next rule to apply *)
  1169   val SOME (r as (Thm (str, thm))) = nex revsets t;
  1170 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso
  1171    string_of_thm thm = (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
  1172                 (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
  1173 else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
  1174 
  1175 (*check the next rule*)
  1176   val (r, (t, asm)) :: _ = loc revsets t r;
  1177 if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" then ()
  1178 else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) II";
  1179 
  1180 (*find and check the next rules, rewrite*)
  1181   val SOME r = nex revsets t;
  1182   val (r,(t,asm))::_ = loc revsets t r;
  1183 if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
  1184 else error "rational.sml locate_rule II";
  1185 
  1186   val SOME r = nex revsets t;
  1187   val (r,(t,asm))::_ = loc revsets t r;
  1188 if term2str t = "(3 - x) * (3 + x) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
  1189 else error "rational.sml next_rule II";
  1190 
  1191   val SOME r = nex revsets t;
  1192   val (r,(t,asm))::_ = loc revsets t r;
  1193 if term2str t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then ()
  1194 else error "rational.sml next_rule III";
  1195 
  1196   val SOME r = nex revsets t;
  1197   val (r, (t, asm)) :: _ = loc revsets t r;
  1198   val ss = term2str t;
  1199 if ss = "(3 - x) / (3 + x)" andalso terms2str asm = "[\"3 + x ~= 0\"]" then ()
  1200 else error "rational.sml: new behav. in rev-set cancel";
  1201 
  1202 "-------- 'reverse-ruleset' cancel_p --------------------";
  1203 "-------- 'reverse-ruleset' cancel_p --------------------";
  1204 "-------- 'reverse-ruleset' cancel_p --------------------";
  1205 (*WN.11.9.02: the 'reverse-ruleset' cancel_p*)
  1206 
  1207 (*the term for which reverse rewriting is demonstrated*)
  1208 val t = str2term "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))";
  1209 val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
  1210 		       next_rule=nex,normal_form=nor,...},...} = cancel_p;
  1211 
  1212 (*normal_form produces the result in ONE step*)
  1213 val SOME (t',_) = nor t; 
  1214 term2str t' = "(3 + 1 * x) / (3 + -1 * x)";
  1215 
  1216 (*initialize the interpreter state used by the 'me'*)
  1217 val SOME (t', asm) = cancel_p_ thy t;
  1218 term2str t' = "(3 + x) / (3 + -1 * x)" (*true*);
  1219 terms2str asm = "[\"3 + -1 * x ~= 0\"]" (*true*);
  1220 val (t,_,revsets,_) = ini t;
  1221 
  1222 (* WN.10.10.02: dieser Fall terminiert nicht 
  1223            (make_polynomial enth"alt zu viele rules)
  1224 WN060823 'init_state' requires rewriting on specified location in the term
  1225 print_depth 99; Rfuns; print_depth 3;
  1226 WN060831 cycling "sym_order_mult_rls_" "sym_mult_assoc"
  1227          as was with make_polynomial before ?!?*)
  1228 
  1229 val SOME r = nex revsets t;
  1230 eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))", 
  1231 		mk_thm thy "9 = 3 ^^^ 2"));
  1232 (*WN060831 *** id_of_thm
  1233            Exception- ERROR raised ...
  1234 val (r,(t,asm))::_ = loc revsets t r;
  1235 term2str t;
  1236 
  1237   val SOME r = nex revsets t;
  1238   val (r,(t,asm))::_ = loc revsets t r;
  1239   term2str t;
  1240 *)
  1241 
  1242 writeln "******************  all tests successfull  *************************";
  1243 
  1244 
  1245 
  1246 (*WN.17.3.03 =========================================================vvv---*)
  1247 "-------- norm_Rational ---------------------------------";
  1248 "-------- norm_Rational ---------------------------------";
  1249 "-------- norm_Rational ---------------------------------";
  1250 val t = str2term "(3*x+5)/18 - x/2  - -(3*x - 2)/9 = 0";
  1251 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1252 if term2str t' = "1 / 18 = 0" then () else error "rational.sml 1";
  1253 
  1254 val t = str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0";
  1255 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1256 if term2str t' = "(237 + 65 * x) / 36 = 0" then () 
  1257 else error "rational.sml 2";
  1258 
  1259 val t = str2term "(1/2 + (5*x)/2)^^^2 - ((13*x)/2 - 5/2)^^^2 - (6*x)^^^2 + 29";
  1260 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1261 if term2str t' = "23 + 35 * x + -72 * x ^^^ 2" then ()
  1262 else error "rational.sml 3";
  1263 
  1264 (*trace_rewrite:=true;*)
  1265 val t = str2term "Not (6*x is_atom)";
  1266 val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
  1267 "HOL.True";
  1268 val t = str2term "1 < 2";
  1269 val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
  1270 "HOL.True";
  1271 
  1272 val t = str2term "(6*x)^^^2";
  1273 val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false 
  1274 			   (num_str @{thm realpow_def_atom}) t;
  1275 if term2str t' = "6 * x * (6 * x) ^^^ (2 + -1)" then ()
  1276 else error "rational.sml powers_erls (6*x)^^^2";
  1277 
  1278 val t = str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))";
  1279 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1280 if term2str t' = "65 * x / 2" then () else error "rational.sml 4";
  1281 
  1282 val t = str2term "1 - ((13*x)/2 - 5/2)^^^2";
  1283 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1284 (*bef.040209: if term2str t' = "(-21 + (130 * x + -169 * x ^^^ 2)) / 4"then()*)
  1285 if term2str t' = "(-21 + 130 * x + -169 * x ^^^ 2) / 4" then () 
  1286 else error "rational.sml 5";
  1287 
  1288 (*SRAM Schalk I, p.92 Nr. 609a*)
  1289 val t = str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
  1290 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1291 if term2str t' = "(-255 + 112 * x) / 135" then () 
  1292 else error "rational.sml 6";
  1293 
  1294 (*SRAM Schalk I, p.92 Nr. 610c*)
  1295 val t = str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
  1296 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1297 if term2str t' = "(-3 + -1 * x) / 2" then () else error "rational.sml 7";
  1298 
  1299 (*SRAM Schalk I, p.92 Nr. 476a*)
  1300 val t = str2term "(x^^^2/(1 - x^^^2) + 1)/(x/(1 - x) + 1) * (1 + x)";
  1301 (*. a/b : c/d translated to a/b * d/c .*)
  1302 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1303 (*if term2str t' = "1 / 1" then () else error "rational.sml 8";3.6.03*)
  1304 if term2str t' = "1" then () else error "rational.sml 8";
  1305 
  1306 (*............................vvv---TODO: sollte gehen mit poly_order *)
  1307 (*Schalk I, p.92 Nr. 472a*)
  1308 val t = str2term "((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
  1309 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1310 if term2str t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
  1311 
  1312 (*Schalk I, p.70 Nr. 480b; a/b : c/d translated to a/b * d/c*)
  1313 val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
  1314 		 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
  1315 		 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
  1316 		 "(20*x*y/(x^^^2 - 25*y^^^2))");
  1317 (*... nicht simpl, zerlegt ...*)
  1318 val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
  1319 		 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2))");
  1320 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1321 "(-12 * (x * y ^^^ 3) + 108 * (x * (y * x ^^^ 2))) / (12 * (x * y))";
  1322 (*                             ~~~~~~~~~~ poly_order notwendig!*)
  1323 val t = str2term ("(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
  1324 		 "(20*x*y/(x^^^2 - 25*y^^^2))");
  1325 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1326 if term2str t' = "1 / (x ^^^ 2 + -25 * y ^^^ 2)" then ()
  1327 else error "rational.sml norm_Rational 1 / (x ^^^ 2 + -25 * y ^^^ 2)";
  1328 
  1329 "nonterm.SK6 ----- SK060904-2a non-termination of add_fraction_p_";
  1330 (*WN.2.6.03 from rlang.sml 56a 
  1331 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a ^^^ 2 + -1 * b ^^^ 2)";
  1332 val NONE = rewrite_set_ thy false common_nominator_p t;
  1333 
  1334 WN060831 nonterm.SK7 
  1335 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
  1336 val NONE = add_fraction_p_ thy t; 
  1337 *)
  1338 
  1339 
  1340 (* ------------------------------------------------------------------- *)
  1341 (*---------vvv------------ MG: ab 1.7.03 ----------------vvv-----------*)
  1342 (*                 Simplifier fuer beliebige Buchterme                 *) 
  1343 (* ------------------------------------------------------------------- *)
  1344 (*----------------------- norm_Rational_mg ----------------------------*)
  1345 (* ------------------------------------------------------------------- *)
  1346 
  1347 "-------- numeral rationals -----------------------------";
  1348 "-------- numeral rationals -----------------------------";
  1349 "-------- numeral rationals -----------------------------";
  1350 (*SRA Schalk I, p.40 Nr. 164b *)
  1351 val t = str2term "(47/6 - 76/9 + 13/4)/(35/12)";
  1352 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1353 term2str t;
  1354 if (term2str t) = "19 / 21" then ()
  1355 else error "rational.sml: diff.behav. in norm_Rational_mg 1";
  1356 
  1357 (*SRA Schalk I, p.40 Nr. 166a *)
  1358 val t = str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
  1359 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1360 term2str t;
  1361 if (term2str t) = "45 / 2" then ()
  1362 else error "rational.sml: diff.behav. in norm_Rational_mg 2";
  1363 
  1364 
  1365 "-------- cancellation ----------------------------------";
  1366 "-------- cancellation ----------------------------------";
  1367 "-------- cancellation ----------------------------------";
  1368 (* e190c Stefan K.*)
  1369 val t = str2term
  1370 "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
  1371 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1372 term2str t;
  1373 if (term2str t) = 
  1374 "(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
  1375 then ()
  1376 else error "rational.sml: diff.behav. in norm_Rational_mg 3";
  1377 
  1378 (* e192b Stefan K.*)
  1379 val t = str2term
  1380 "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
  1381 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1382 term2str t;
  1383 if (term2str t) = 
  1384 "x ^^^ 2 / y ^^^ 2"
  1385 then ()
  1386 else error "rational.sml: diff.behav. in norm_Rational_mg 4";
  1387 
  1388 (*SRC Schalk I, p.66 Nr. 379c *)
  1389 val t = str2term 
  1390 "(a - b)/(b - a)";
  1391 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1392 term2str t;
  1393 if (term2str t) =
  1394 "-1"
  1395 then ()
  1396 else error "rational.sml: diff.behav. in norm_Rational_mg 5";
  1397 
  1398 (*SRC Schalk I, p.66 Nr. 380b *)
  1399 val t = str2term 
  1400 "15*(3*x+3)*(4*x+9)/(12*(2*x+7)*(5*x+5))";
  1401 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1402 term2str t;
  1403 if (term2str t) =
  1404 "(27 + 12 * x) / (28 + 8 * x)"
  1405 then ()
  1406 else error "rational.sml: diff.behav. in norm_Rational_mg 6";
  1407 
  1408 (*Schalk I, p.60 Nr. 215c *)
  1409 (* Falsches Ergebnis: rechnet lange und cancel_p kann nicht weiter krzen!!!*)
  1410 (* WN060831????MG1 
  1411 val t = str2term "(a+b)^^^4*(x - y)/((x - y)^^^3*(a+b)^^^2)";
  1412 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1413 term2str t;
  1414 if (term2str t) =
  1415 "(a ^^^ 4 * x + -1 * a ^^^ 4 * y + 4 * a ^^^ 3 * b * x + -4 * a ^^^ 3 * b * y + 6 * a ^^^ 2 * b ^^^ 2 * x + -6 * a ^^^ 2 * b ^^^ 2 * y + 4 * a * b ^^^ 3 * x + -4 * a * b ^^^ 3 * y + b ^^^ 4 * x + -1 * b ^^^ 4 * y) /(a ^^^ 2 * x ^^^ 3 + -3 * a ^^^ 2 * x ^^^ 2 * y + 3 * a ^^^ 2 * x * y ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 3 + 2 * a * b * x ^^^ 3 + -6 * a * b * x ^^^ 2 * y + 6 * a * b * x * y ^^^ 2 + -2 * a * b * y ^^^ 3 + b ^^^ 2 * x ^^^ 3 + -3 * b ^^^ 2 * x ^^^ 2 * y + 3 * b ^^^ 2 * x * y ^^^ 2 + -1 * b ^^^ 2 * y ^^^ 3)"
  1416 then ()
  1417 else error "rational.sml: diff.behav. in norm_Rational_mg 7";
  1418 *)
  1419 (*val t = str2term 
  1420 "(a ^^^ 4 * x + -1 * a ^^^ 4 * y + 4 * a ^^^ 3 * b * x + -4 * a ^^^ 3 * b * y + 6 * a ^^^ 2 * b ^^^ 2 * x + -6 * a ^^^ 2 * b ^^^ 2 * y + 4 * a * b ^^^ 3 * x + -4 * a * b ^^^ 3 * y + b ^^^ 4 * x + -1 * b ^^^ 4 * y) /(a ^^^ 2 * x ^^^ 3 + -3 * a ^^^ 2 * x ^^^ 2 * y + 3 * a ^^^ 2 * x * y ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 3 + 2 * a * b * x ^^^ 3 + -6 * a * b * x ^^^ 2 * y + 6 * a * b * x * y ^^^ 2 + -2 * a * b * y ^^^ 3 + b ^^^ 2 * x ^^^ 3 + -3 * b ^^^ 2 * x ^^^ 2 * y + 3 * b ^^^ 2 * x * y ^^^ 2 + -1 * b ^^^ 2 * y ^^^ 3)"
  1421 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
  1422 term2str t;*)
  1423 (* uncaught exception nonexhaustive binding failure
  1424    raised at: stdIn:93.1-93.51 *)
  1425 
  1426 (*Schalk I, p.66 Nr. 381a *)
  1427 (* ACHTUNG: rechnet ca. 2 Minuten !!! *)
  1428 (* WN060831???MG2
  1429 val t = str2term "18*(a+b)^^^3*(a - b)^^^2/(72*(a - b)^^^3*(a+b)^^^2)";
  1430 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1431 term2str t;
  1432 if (term2str t) =
  1433 "(a + b) / (4 * a + -4 * b)"
  1434 then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
  1435 *)
  1436 
  1437 (*SRC Schalk I, p.66 Nr. 381b *)
  1438 val t = str2term 
  1439 "(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
  1440 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1441 term2str t;
  1442 if (term2str t) =
  1443 "-1 / (5 + -2 * x)"
  1444 then ()
  1445 else error "rational.sml: diff.behav. in norm_Rational_mg 9";
  1446 
  1447 (*SRC Schalk I, p.66 Nr. 381c *)
  1448 val t = str2term 
  1449 "(27*a^^^3+9*a^^^2+3*a+1)/(27*a^^^3+18*a^^^2+3*a)";
  1450 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1451 term2str t;
  1452 if (term2str t) =
  1453 "(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
  1454 then ()
  1455 else error "rational.sml: diff.behav. in norm_Rational_mg 10";
  1456 
  1457 (*SRC Schalk I, p.66 Nr. 383a *)
  1458 val t = str2term 
  1459 "(5*a^^^2 - 5*a*b)/(a - b)^^^2";
  1460 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1461 term2str t;
  1462 if (term2str t) =
  1463 "5 * a / (a + -1 * b)"
  1464 then ()
  1465 else error "rational.sml: diff.behav. in norm_Rational_mg 11";
  1466 
  1467 
  1468 "-------- common denominator ----------------------------";
  1469 "-------- common denominator ----------------------------";
  1470 "-------- common denominator ----------------------------";
  1471 (*SRA Schalk I, p.67 Nr. 403a *)
  1472 val t = str2term 
  1473 "4/x - 3/y - 1";
  1474 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1475 term2str t;
  1476 if (term2str t) =
  1477 "(-3 * x + 4 * y + -1 * x * y) / (x * y)"
  1478 then ()
  1479 else error "rational.sml: diff.behav. in norm_Rational_mg 12";
  1480 
  1481 (*SRA Schalk I, p.67 Nr. 407b *)
  1482 val t = str2term 
  1483 "(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a^^^2+3*b*c)/(a*b*c)";
  1484 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1485 term2str t;
  1486 if (term2str t) =
  1487 "4 / c"
  1488 then ()
  1489 else error "rational.sml: diff.behav. in norm_Rational_mg 13";
  1490 
  1491 (*SRA Schalk I, p.67 Nr. 410b *)
  1492 val t = str2term 
  1493 "1/(x+1) + 1/(x+2) - 2/(x+3)";
  1494 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1495 term2str t;
  1496 if (term2str t) =
  1497 "(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)"
  1498 then ()
  1499 else error "rational.sml: diff.behav. in norm_Rational_mg 14";
  1500 
  1501 (*SRA Schalk I, p.67 Nr. 413b *)
  1502 val t = str2term 
  1503 "(1+x)/(1 - x) - (1 - x)/(1+x) + 2*x/(1 - x^^^2)";
  1504 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1505 term2str t;
  1506 if (term2str t) =
  1507 "6 * x / (1 + -1 * x ^^^ 2)"
  1508 then ()
  1509 else error "rational.sml: diff.behav. in norm_Rational_mg 15";
  1510 
  1511 (*SRA Schalk I, p.68 Nr. 414a *)
  1512 val t = str2term 
  1513 "(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))";
  1514 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1515 term2str t;
  1516 if (term2str t) =
  1517 "(-2 + -5 * x + 2 * x ^^^ 2) / (2 + -3 * x + x ^^^ 2)"
  1518 then ()
  1519 else error "rational.sml: diff.behav. in norm_Rational_mg 16";
  1520 
  1521 (*SRA Schalk I, p.68 Nr. 423a *)
  1522 val t = str2term 
  1523 "(2*x+3*y)/x + (4*x^^^3 - x*y^^^2 - 3*y^^^3)/(x^^^3 - 2*x^^^2*y+x*y^^^2) - (5*x+6*y)/(x - y)";
  1524 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1525 term2str t;
  1526 if (term2str t) =
  1527 "1"
  1528 then ()
  1529 else error "rational.sml: diff.behav. in norm_Rational_mg 17";
  1530 
  1531 (*SRA Schalk I, p.68 Nr. 428b *)
  1532 val t = str2term 
  1533 "1/(a - b)^^^2 + 1/(a+b)^^^2 - 2/(a^^^2 - b^^^2) - 4*(b^^^2 - 1)/(a^^^2 - b^^^2)^^^2";
  1534 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1535 term2str t;
  1536 if (term2str t) =
  1537 "4 / (a ^^^ 4 + -2 * a ^^^ 2 * b ^^^ 2 + b ^^^ 4)"
  1538 then ()
  1539 else error "rational.sml: diff.behav. in norm_Rational_mg 18";
  1540 
  1541 (*SRA Schalk I, p.68 Nr. 430b *)
  1542 val t = str2term 
  1543 "a^^^2/(a - 3*b) - 108*a*b^^^3/((a+3*b)*(a^^^2 - 9*b^^^2)) - 9*b^^^2*(a - 3*b)/(a+3*b)^^^2";
  1544 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1545 term2str t;
  1546 if (term2str t) =
  1547 "a + 3 * b"
  1548 then ()
  1549 else error "rational.sml: diff.behav. in norm_Rational_mg 19";
  1550 
  1551 
  1552 (*SRA Schalk I, p.68 Nr. 432 *)
  1553 val t = str2term 
  1554 "(a^^^2+a*b)/(a^^^2 - b^^^2) - (b^^^2 - a*b)/(b^^^2 - a^^^2) + a^^^2*(a - b)/(a^^^3 - a^^^2*b) - 2*a*(a^^^2 - b^^^2)/(a^^^3 - a*b^^^2) - 2*b^^^2/(a^^^2 - b^^^2)";
  1555 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1556 term2str t;
  1557 if (term2str t) =
  1558 "0"
  1559 then ()
  1560 else error "rational.sml: diff.behav. in norm_Rational_mg 20";
  1561 
  1562 (*Eigenes*)
  1563 val t = str2term 
  1564 "3*a/(a*b) + x/y";
  1565 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1566 term2str t;
  1567 if (term2str t) =
  1568 "(3 * y + b * x) / (b * y)"
  1569 then ()
  1570 else error "rational.sml: diff.behav. in norm_Rational_mg 21";
  1571 
  1572 
  1573 "-------- multiply and cancel ---------------------------";
  1574 "-------- multiply and cancel ---------------------------";
  1575 "-------- multiply and cancel ---------------------------";
  1576 (*SRM Schalk I, p.68 Nr. 436a *)
  1577 val t = str2term 
  1578 "3*(x+y)/(15*(x - y)) * 25*(x - y)^^^2/(18*(x+y)^^^2)";
  1579 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1580 term2str t;
  1581 if (term2str t) =
  1582 "(5 * x + -5 * y) / (18 * x + 18 * y)"
  1583 then ()
  1584 else error "rational.sml: diff.behav. in norm_Rational_mg 22";
  1585 
  1586 (*SRM.test Schalk I, p.68 Nr. 436b *)
  1587 (*WN060420???MG3 crashes with method 'simplify' in 
  1588   IsacCore > Simplification > Rational Terms > Multiplication > No.2*)
  1589 val t = str2term "5*a*(a - b)^^^2*(a + b)^^^3/(7*b*(a - b)^^^3) * 7*b/(a + b)^^^3";
  1590 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1591 term2str t;
  1592 if (term2str t) =
  1593 "5 * a / (a + -1 * b)"
  1594 then ()
  1595 else error "rational.sml: diff.behav. in norm_Rational_mg 23";
  1596 
  1597 (*Schalk I, p.68 Nr. 437a *)
  1598 val t = str2term "(3*a - 4*b)/(4*c+3*e) * (3*a+4*b)/(9*a^^^2 - 16*b^^^2)";
  1599 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1600 if (term2str t) = "1 / (4 * c + 3 * e)" then ()
  1601 else error "rational.sml: diff.behav. in norm_Rational_mg 24";
  1602 
  1603 "----- S.K. corrected non-termination 060904";
  1604 val t = str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a^^^2 - 16*b^^^2))";
  1605 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
  1606 term2str t';
  1607 if term2str t' = 
  1608   "(9 * a ^^^ 2 + -16 * b ^^^ 2) /\n(36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c +\n -48 * b ^^^ 2 * e)"
  1609 (*"(9 * a ^^^ 2 + -16 * b ^^^ 2) / (36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c + -48 * b ^^^ 2 * e)"*)
  1610 then () else error "rational.sml: S.K.8..corrected 060904-6";
  1611 
  1612 "----- S.K. corrected non-termination of cancel_p_";
  1613 val t'' = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
  1614 "(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
  1615 val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
  1616 if term2str t' = "1 / (4 * c + 3 * e)" then ()
  1617 else error "rational.sml: diff.behav. in cancel_p S.K.8";
  1618 
  1619 (*Schalk I, p.68 Nr. 437b *)
  1620 (* nonterm.SK9 loops: cancel_p kann nicht weiter kuerzen!!! *)
  1621 val t'' = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
  1622 (* val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t'';
  1623    *)
  1624 
  1625 "================delete===";
  1626 (*a casual output from above*)
  1627 val t = str2term 
  1628 "(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)"; 
  1629 (* WN060831 nonterm.SK10 
  1630 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
  1631 term2str t;
  1632 *)
  1633 
  1634 (*SRM Schalk I, p.68 Nr. 438a *)
  1635 val t = str2term 
  1636 "x*y/(x*y - y^^^2)*(x^^^2 - x*y)";
  1637 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1638 term2str t;
  1639 if (term2str t) =
  1640 "x ^^^ 2"
  1641 then ()
  1642 else error "rational.sml: diff.behav. in norm_Rational_mg 24";
  1643 
  1644 (*SRM Schalk I, p.68 Nr. 439b *)
  1645 val t = str2term 
  1646 "(4*x^^^2+4*x+1)*((x^^^2 - 2*x^^^3)/(4*x^^^2+2*x))";
  1647 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1648 term2str t;
  1649 if (term2str t) =
  1650 "(x + -4 * x ^^^ 3) / 2"
  1651 then ()
  1652 else error "rational.sml: diff.behav. in norm_Rational_mg 25";
  1653 
  1654 (*SRM Schalk I, p.68 Nr. 440a *)
  1655 val t = str2term 
  1656 "(x^^^2 - 2*x)/(x^^^2 - 3*x) * (x - 3)^^^2/(x^^^2 - 4)";
  1657 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1658 term2str t;
  1659 if (term2str t) =
  1660 "(-3 + x) / (2 + x)"
  1661 then ()
  1662 else error "rational.sml: diff.behav. in norm_Rational_mg 26";
  1663 
  1664 "----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
  1665 val t = str2term 
  1666 "(a^^^3 - 9*a)/(a^^^3*b - a*b^^^3)*(a^^^2*b+a*b^^^2)/(a+3)";
  1667 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
  1668 if term2str t = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
  1669 else error "rational.sml: diff.behav. in norm_Rational 27";
  1670 
  1671 "----- SK12 works since 0707xx";
  1672 val t = str2term "(a^^^3 - 9*a)*(a^^^2*b+a*b^^^2)/((a^^^3*b - a*b^^^3)*(a+3))";
  1673 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
  1674 if term2str t' = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
  1675 else error "rational.sml: diff.behav. in norm_Rational 28";
  1676 
  1677 
  1678 "-------- common denominator and multiplication ---------";
  1679 "-------- common denominator and multiplication ---------";
  1680 "-------- common denominator and multiplication ---------";
  1681 (*SRAM Schalk I, p.69 Nr. 441b *)
  1682 val t = str2term "(4*a/3 + 3*b^^^2/a^^^3 + b/(4*a))*(4*b/(3*a))";
  1683 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1684 term2str t;
  1685 if (term2str t) =
  1686   "(36 * b ^^^ 3 + 3 * a ^^^ 2 * b ^^^ 2 + 16 * a ^^^ 4 * b) / (9 * a ^^^ 4)"
  1687 then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
  1688 
  1689 (*SRAM Schalk I, p.69 Nr. 442b *)
  1690 val t = str2term "(15*a^^^2/x^^^3 - 5*b^^^4/x^^^2 + 25*c^^^2/x)*(x^^^3/(5*a*b^^^3*c^^^3)) + 1/c^^^3 * (b*x/a - 3*a/b^^^3)";
  1691 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1692 term2str t;
  1693 if (term2str t) =
  1694 "5 * x ^^^ 2 / (a * b ^^^ 3 * c)"
  1695 then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
  1696 
  1697 (*SRAM Schalk I, p.69 Nr. 443b *)
  1698 val t = str2term "(a/2 + b/3)*(b/3 - a/2)";
  1699 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1700 term2str t;
  1701 if (term2str t) =
  1702 "(-9 * a ^^^ 2 + 4 * b ^^^ 2) / 36"
  1703 then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
  1704 
  1705 (*SRAM Schalk I, p.69 Nr. 445b *)
  1706 val t = str2term "(a^^^2/9 + 2*a/(3*b) + 4/b^^^2)*(a/3 - 2/b) + 8/b^^^3";
  1707 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1708 term2str t;
  1709 if (term2str t) =
  1710 "a ^^^ 3 / 27"
  1711 then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
  1712 
  1713 (*SRAM Schalk I, p.69 Nr. 446b *)
  1714 val t = str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x^^^2 - 16*y^^^2)";
  1715 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1716 term2str t;
  1717 if (term2str t) =
  1718 "30 * x ^^^ 2 + -9 * x * y + -20 * y ^^^ 2"
  1719 then ()
  1720 else error "rational.sml: diff.behav. in norm_Rational_mg 32";
  1721 
  1722 (*SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
  1723 val t = str2term 
  1724 "(2*x^^^2/(3*y)+x/y^^^2)*(4*x^^^4/(9*y^^^2)+x^^^2/y^^^4)*(2*x^^^2/(3*y) - x/y^^^2)";
  1725 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1726 term2str t;
  1727 if (term2str t) = "(-81 * x ^^^ 4 + 16 * x ^^^ 8 * y ^^^ 4) / (81 * y ^^^ 8)"
  1728 then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
  1729 
  1730 
  1731 (*SRAM Schalk I, p.69 Nr. 450a *)
  1732 val t = str2term 
  1733 "(4*x/(3*y)+2*y/(3*x))^^^2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
  1734 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1735 term2str t;
  1736 if (term2str t) =
  1737 "(52 * x ^^^ 2 + 16 * y ^^^ 2) / (9 * y ^^^ 2)"
  1738 then ()
  1739 else error "rational.sml: diff.behav. in norm_Rational_mg 34";
  1740 
  1741 
  1742 "-------- double fractions ------------------------------";
  1743 "-------- double fractions ------------------------------";
  1744 "-------- double fractions ------------------------------";
  1745 (*SRD Schalk I, p.69 Nr. 454b *)
  1746 val t = str2term 
  1747 "((2 - x)/(2*a)) / (2*a/(x - 2))";
  1748 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1749 term2str t;
  1750 if (term2str t) = 
  1751 "(-4 + 4 * x + -1 * x ^^^ 2) / (4 * a ^^^ 2)"
  1752 then ()
  1753 else error "rational.sml: diff.behav. in norm_Rational_mg 35";
  1754 
  1755 (*SRD Schalk I, p.69 Nr. 455a *)
  1756 val t = str2term 
  1757 "(a^^^2 + 1)/(a^^^2 - 1) / ((a+1)/(a - 1))";
  1758 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1759 term2str t;
  1760 if (term2str t) = 
  1761 "(1 + a ^^^ 2) / (1 + 2 * a + a ^^^ 2)" then ()
  1762 else error "rational.sml: diff.behav. in norm_Rational_mg 36";
  1763 
  1764 
  1765 "----- Schalk I, p.69 Nr. 455b";
  1766 val t = str2term "(x^^^2 - 4)/(y^^^2 - 9)/((2+x)/(3 - y))";
  1767 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1768 if term2str t = "(2 + -1 * x) / (3 + y)" then ()
  1769 else error "rational.sml: diff.behav. in norm_Rational_mg 37";
  1770 
  1771 "----- SK060904-1a non-termination of cancel_p_ ?: worked before 0707xx";
  1772 val t = str2term "(x^^^2 - 4)*(3 - y)/((y^^^2 - 9)*(2+x))";
  1773 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
  1774 if term2str t = "(2 + -1 * x) / (3 + y)" then ()
  1775 else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
  1776 
  1777 "----- ?: worked before 0707xx";
  1778 val t = str2term "(3 + -1 * y) / (-9 + y ^^^ 2)";
  1779 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
  1780 if term2str t = "-1 / (3 + y)" then ()
  1781 else error "rational.sml: -1 / (3 + y) norm_Rational";
  1782 
  1783 (*SRD Schalk I, p.69 Nr. 456b *)
  1784 val t = str2term 
  1785 "(b^^^3 - b^^^2)/(b^^^2+b)/(b^^^2 - 1)";
  1786 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1787 term2str t;
  1788 if (term2str t) = "b / (1 + 2 * b + b ^^^ 2)" then ()
  1789 else error "rational.sml: diff.behav. in norm_Rational_mg 38";
  1790 
  1791 (*SRD Schalk I, p.69 Nr. 457b *)
  1792 val t = str2term 
  1793 "(16*a^^^2 - 9*b^^^2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a^^^2 - 9*a^^^2*b^^^2))";
  1794 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1795 term2str t;
  1796 if (term2str t) = 
  1797   "8 * a ^^^ 2 + -6 * a * b + -12 * a ^^^ 2 * b + 9 * a * b ^^^ 2"
  1798 then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
  1799 
  1800 "----- Schalk I, p.69 Nr. 458b works since 0707";
  1801 val t = str2term 
  1802 "(2*a^^^2*x - a^^^2)/(a*x - b*x) / (b^^^2*(2*x - 1)/(x*(a - b)))";
  1803 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
  1804 if term2str t = "a ^^^ 2 / b ^^^ 2" then ()
  1805 else error "rational.sml: diff.behav. in norm_Rational_mg 39b";
  1806 
  1807 (*SRD Schalk I, p.69 Nr. 459b *)
  1808 val t = str2term "(a^^^2 - b^^^2)/(a*b) / (4*(a+b)^^^2/a)";
  1809 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
  1810 if term2str t = "(a + -1 * b) / (4 * a * b + 4 * b ^^^ 2)" then ()
  1811 else error "rational.sml: diff.behav. in norm_Rational_mg 41";
  1812 
  1813 
  1814 (*Schalk I, p.69 Nr. 460b nonterm.SK
  1815 val t = str2term 
  1816 "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
  1817 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1818 if term2str t = 
  1819 then ()
  1820 else error "rational.sml: diff.behav. in norm_Rational_mg 42";
  1821 
  1822 val t = str2term 
  1823 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
  1824 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
  1825 ... non terminating.
  1826 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
  1827 "(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)";
  1828 val SOME (t,_) = rewrite_set_ thy false cancel_p t';
  1829 ... non terminating.*)
  1830 
  1831 (*SRD Schalk I, p.70 Nr. 472a *)
  1832 val t = str2term ("((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/" ^
  1833 		 "((4*x - 8*y)/(x + y))");
  1834 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1835 term2str t;
  1836 if (term2str t) = 
  1837 "x + y"
  1838 then ()
  1839 else error "rational.sml: diff.behav. in norm_Rational_mg 43";
  1840 
  1841 
  1842 (*----------------------------------------------------------------------*)
  1843 (*---------------------- Einfache Dppelbrche --------------------------*)
  1844 (*----------------------------------------------------------------------*)
  1845 
  1846 (*SRD Schalk I, p.69 Nr. 461a *)
  1847 val t = str2term 
  1848 "(2/(x+3) + 2/(x - 3)) / (8*x/(x^^^2 - 9))";
  1849 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1850 term2str t;
  1851 if (term2str t) = 
  1852 "1 / 2"
  1853 then ()
  1854 else error "rational.sml: diff.behav. in norm_Rational_mg 44";
  1855 
  1856 (*SRD Schalk I, p.69 Nr. 464b *)
  1857 val t = str2term 
  1858 "(a - a/(a - 2)) / (a + a/(a - 2))";
  1859 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1860 term2str t;
  1861 if (term2str t) = 
  1862 "(3 + -1 * a) / (1 + -1 * a)"
  1863 then ()
  1864 else error "rational.sml: diff.behav. in norm_Rational_mg 45";
  1865 
  1866 (*SRD Schalk I, p.69 Nr. 465b *)
  1867 val t = str2term 
  1868 "((x+3*y)/9 + (4*y^^^2 - 9*z^^^2)/(16*x)) /(x/9+y/6+z/4)";
  1869 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1870 term2str t;
  1871 if (term2str t) = 
  1872 "(4 * x + 6 * y + -9 * z) / (4 * x)"
  1873 then ()
  1874 else error "rational.sml: diff.behav. in norm_Rational_mg 46";
  1875 
  1876 (*SRD Schalk I, p.69 Nr. 466b *)
  1877 val t = str2term 
  1878 "((1 - 7*(x - 2)/(x^^^2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x^^^2 - 25))";
  1879 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1880 term2str t;
  1881 if (term2str t) = 
  1882 "(25 + -10 * x + x ^^^ 2) / 18"
  1883 then ()
  1884 else error "rational.sml: diff.behav. in norm_Rational_mg 47";
  1885 
  1886 (*SRD Schalk I, p.70 Nr. 469 *)
  1887 val t = str2term 
  1888 "3*b^^^2/(4*a^^^2 - 8*a*b + 4*b^^^2)/(a/(a^^^2*b - b^^^3) + (a - b)/(4*a*b^^^2+4*b^^^3) - 1/(4*b^^^2))";
  1889 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1890 term2str t;
  1891 if (term2str t) = 
  1892 "3 * b ^^^ 3 / (2 * a + -2 * b)"
  1893 then ()
  1894 else error "rational.sml: diff.behav. in norm_Rational_mg 48";
  1895 
  1896 (*----------------------------------------------------------------------*)
  1897 (*---------------------- Mehrfache Dppelbrueche ------------------------*)
  1898 (*----------------------------------------------------------------------*)
  1899 
  1900 (*SRD.test Schalk I, p.70 Nr. 476b *) (* Rechenzeit: 10 sec *)
  1901 (*WN060419 crashes with method 'simplify' ????SK*)
  1902 val t = str2term 
  1903 "((a^^^2 - b^^^2)/(2*a*b)+2*a*b/(a^^^2 - b^^^2))/((a^^^2+b^^^2)/(2*a*b)+1) / ((a^^^2+b^^^2)^^^2/(a+b)^^^2)";
  1904 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
  1905 if term2str t = "1 / (a ^^^ 2 + -1 * b ^^^ 2)" then ()
  1906 else error "rational.sml: diff.behav. in norm_Rational_mg 49";
  1907 
  1908 "----- Schalk I, p.70 Nr. 477a";
  1909 (* MG Achtung: terme explodieren; Bsp zu komplex; 
  1910    L???ung sollte (ziemlich grosser) Faktorisierter Ausdruck sein 
  1911 val t = str2term "b*y/(b - 2*y)/((b^^^2 - y^^^2)/(b+2*y)) /" ^
  1912 		 "(b^^^2*y+b*y^^^2)*(a+x)^^^2/((b^^^2 - 4*y^^^2)*(a+2*x)^^^2)";
  1913 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
  1914 
  1915 
  1916 val t = str2term "b*y*(b+2*y)*(b^^^2 - 4*y^^^2)*(a+2*x)^^^2 / " ^
  1917 		 "((b - 2*y)*(b^^^2 - y^^^2)*(b^^^2*y+b*y^^^2)*(a+x)^^^2)";
  1918 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
  1919 ????SK ???MG*)
  1920 
  1921 
  1922 "----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
  1923 val t = str2term ("(a - (a*b+b^^^2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
  1924 		 "((a - a^^^2/(a+b))/(a+(a*b)/(a - b)))");
  1925 val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1926 if term2str t' = 
  1927 "(2 * a ^^^ 3 + 2 * a ^^^ 2 * b) / (a ^^^ 2 * b + b ^^^ 3)"
  1928 then ()
  1929 else error "rational.sml: diff.behav. in norm_Rational_mg 51";
  1930 
  1931 (* TODO.new_c:WN050820 STOP_REW_SUB introduced gave ...
  1932 if term2str t' = "(a ^^^ 4 + -1 * a ^^^ 2 * b ^^^ 2) /(a * b * (b + (a * (a + -1 * b) + -1 * b * (a + -1 * b)) / (2 * a)) * (a + -1 * b))" then ()
  1933 else error "rational.sml: works again";
  1934 re-outcommented with TODO.new_c: cvs before 071227, 11:50*)
  1935 
  1936 
  1937 
  1938 (*Schalk I, p.70 Nr. 480a *)
  1939 (* Achtung: rechnet ewig; cancel_p kann nicht krzen: WN060831 nonterm.SK00
  1940 val t = str2term 
  1941 "(1/x+1/y+1/z)/(1/x - 1/y - 1/z) / (2*x^^^2/(x^^^2 - z^^^2)/(x/(x+z)+x/(x - z)))";
  1942 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1943 term2str t;
  1944 if (term2str t) = 
  1945 
  1946 then ()
  1947 else error "rational.sml: diff.behav. in norm_Rational_mg 52";
  1948 
  1949 (*MG Berechne Zwischenergebnisse: WN060831 nonterm.SK00*)
  1950 val t = str2term 
  1951 "(1/x+1/y+1/z)/(1/x - 1/y - 1/z)";
  1952 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1953 term2str t;
  1954 "(x ^^^ 2 * y ^^^ 2 * z + x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2) /
  1955 (-1 * x ^^^ 2 * y ^^^ 2 * z + -1 * x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2)";
  1956 val t = str2term 
  1957 "2*x^^^2/(x^^^2 - z^^^2)/(x/(x+z)+x/(x - z))";
  1958 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1959 term2str t;
  1960 "1"
  1961 
  1962 (* SK 1. Ausdruck kann nicht weiter gekrzt werden; cancel_p !!!*)
  1963 ###  rls: cancel_p on: 
  1964 (x ^^^ 2 * (y ^^^ 2 * z) + x ^^^ 2 * (y * z ^^^ 2) + x * (y ^^^ 2 * z ^^^ 2)) /
  1965 (-1 * (x ^^^ 2 * (y ^^^ 2 * z)) + -1 * (x ^^^ 2 * (y * z ^^^ 2)) + x * (y ^^^ 2 * z ^^^ 2))
  1966 GC #3.61.81.101.197.17503:   (0 ms)
  1967 *** RATIONALS_DIRECT_CANCEL_EXCEPTION: Invalid fraction
  1968 
  1969 val t = str2term 
  1970 "(x^^^2 * (y^^^2 * z) + x^^^2 * (y * z^^^2) + x * (y^^^2 * z^^^2)) / (-1 * (x^^^2 * (y^^^2 * z)) + -1 * (x^^^2 * (y * z^^^2)) + x * (y^^^2 * z^^^2))";
  1971 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
  1972 term2str t;
  1973 (*uncaught exception nonexhaustive binding failure*)
  1974 
  1975 (* Das kann er aber krzen !!????: *)
  1976 val t = str2term 
  1977 "(x^^^2 * (y^^^2 * z) +  x * (y^^^2 * z^^^2)) / (-1 * (x^^^2 * (y * z^^^2)) + x * (y^^^2 * z^^^2))";
  1978 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
  1979 term2str t;
  1980 "(-1 * (y * x) + -1 * (z * y)) / (1 * (z * x) + -1 * (z * y))";
  1981 *)
  1982 
  1983 
  1984 "-------- crucial examples ------------------------------";
  1985 "-------- crucial examples ------------------------------";
  1986 "-------- crucial examples ------------------------------";
  1987 (*Schalk I, p.60 Nr. 215d *)
  1988 (* Achtung: rechnet ewig ...
  1989 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
  1990 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1991 term2str t; noterm.SK
  1992 *)
  1993 
  1994 (* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt:*)
  1995 (*
  1996 val t = str2term "(a-b)^^^3 * (x+y)^^^4";
  1997 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  1998 term2str t;
  1999 "a^^^3 * x^^^4 + 4 * a^^^3 * x^^^3 * y +6 * a^^^3 * x^^^2 * y^^^2 +4 * a^^^3 * x * y^^^3 +a^^^3 * y^^^4 +-3 * a^^^2 * b * x^^^4 +-12 * a^^^2 * b * x^^^3 * y +-18 * a^^^2 * b * x^^^2 * y^^^2 +-12 * a^^^2 * b * x * y^^^3 +-3 * a^^^2 * b * y^^^4 +3 * a * b^^^2 * x^^^4 +12 * a * b^^^2 * x^^^3 * y +18 * a * b^^^2 * x^^^2 * y^^^2 +12 * a * b^^^2 * x * y^^^3 +3 * a * b^^^2 * y^^^4 +-1 * b^^^3 * x^^^4 +-4 * b^^^3 * x^^^3 * y +-6 * b^^^3 * x^^^2 * y^^^2 +-4 * b^^^3 * x * y^^^3 +-1 * b^^^3 * y^^^4";
  2000 val t = str2term "((x+y)^^^2 * (a-b)^^^5)";
  2001 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  2002 term2str t;
  2003 "a^^^5 * x^^^2 + 2 * a^^^5 * x * y + a^^^5 * y^^^2 +-5 * a^^^4 * b * x^^^2 +-10 * a^^^4 * b * x * y +-5 * a^^^4 * b * y^^^2 +10 * a^^^3 * b^^^2 * x^^^2 +20 * a^^^3 * b^^^2 * x * y +10 * a^^^3 * b^^^2 * y^^^2 +-10 * a^^^2 * b^^^3 * x^^^2 +-20 * a^^^2 * b^^^3 * x * y +-10 * a^^^2 * b^^^3 * y^^^2 +5 * a * b^^^4 * x^^^2 +10 * a * b^^^4 * x * y +5 * a * b^^^4 * y^^^2 +-1 * b^^^5 * x^^^2 +-2 * b^^^5 * x * y +-1 * b^^^5 * y^^^2";
  2004 *)
  2005 (*anscheinend macht dem Rechner das Krzen diese Bruches keinen Spass mehr ...*)
  2006 
  2007 (*--------------------------------------------------------------------*)
  2008 (*Schalk I, p.70 Nr. 480b 
  2009 val t = str2term "((12*x*y/(9*x^^^2 - y^^^2))/" ^
  2010 		 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
  2011 		 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
  2012 		 "(20*x*y/(x^^^2 - 25*y^^^2))";
  2013 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  2014 SK.nonterm
  2015 Kann nicht weiter vereinfacht werden !!!!?? *)
  2016 
  2017 (*--------------------------------------------------------------------*)
  2018 "---- MGs test set";
  2019 val t = str2term " (1 + x^^^5) / (y + x) + x^^^3 / x ";
  2020 val SOME (t,_) = rewrite_set_ thy false common_nominator_p t;
  2021 if term2str t = "(1 + x ^^^ 3 + x ^^^ 5 + y * x ^^^ 2) / (x + y)" then()
  2022 else error "";
  2023 
  2024 (*--------------------------------------------------------------------*)
  2025 (* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3b
  2026    ---> Sortierung FALSCH !!  *)
  2027 val t = str2term "b^^^3 * a^^^5/a ";
  2028 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
  2029 term2str t;
  2030 "1 * (a^^^4 * b^^^3) / 1"; (*OK*)
  2031 
  2032 val t = str2term "b^^^3 * a^^^5/b ";
  2033 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
  2034 term2str t;
  2035 "1 * (b^^^2 * a^^^5) / 1"; (*cancel_p sortiert hier falsch um!*)
  2036 
  2037 (* Problem liegt NICHT bei ord_make_polynomial! (siehe folgende Bsple) *)
  2038 (*
  2039 val x = str2term "x"; val bdv = str2term "bdv";
  2040 val t1 = str2term "b^^^2 * a^^^5";
  2041 val t2 = str2term "a^^^5 * b^^^2 ";
  2042 ord_make_polynomial false Rational.thy [(x,bdv)] (t1,t2); (*false*)
  2043 *)
  2044 (* ==> "b^^^2 * a^^^5" > "a^^^5 * b^^^2 " ... OK!*)
  2045 
  2046 (*--------------------------------------------------------------------*)
  2047 (* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3c
  2048    ---> erzeugt berflssige "1 * ..."
  2049    
  2050 val t = str2term "-1 / (3 + y)";
  2051 (*~~         *)
  2052 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
  2053 term2str t;
  2054 "-1 / (3 + 1 * y)";
  2055 (********* Das ist das PROBLEM !!!!!!!??? *******************)
  2056 (* -1 im Z???ler der Angabe verursacht das Problem !*)
  2057 *)
  2058 
  2059 (* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
  2060 "----- MGs test set";
  2061 val t = str2term "(a^^^2 + -1)/(a+1)";
  2062 val SOME (t',_) = rewrite_set_ thy false cancel_p t;
  2063 if term2str t' = "(-1 + a) / 1" then ()
  2064 else error "rational.sml MG tests 3d";
  2065 
  2066 "----- NOT TERMINATING ?: worked before 0707xx";
  2067 val t = str2term "(a^^^2 - 1)*(b + 1) / ((b^^^2 - 1)*(a+1))";
  2068 val SOME (t'',_) = rewrite_set_ thy false norm_Rational t;
  2069 if term2str t'' = "(1 + -1 * a) / (1 + -1 * b)" then ()
  2070 else error "rational.sml MG tests 3e";
  2071 
  2072 "----- corrected SK060905";
  2073 val t = str2term "(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
  2074 val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  2075 if term2str t' = "-1 / (5 + -2 * x)" then ()
  2076 else error "rational.sml corrected SK060905";
  2077 
  2078 
  2079 "-------- examples for Stefan Karnels thesis ------------";
  2080 "-------- examples for Stefan Karnels thesis ------------";
  2081 "-------- examples for Stefan Karnels thesis ------------";
  2082 (*SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*)
  2083 val t = str2term 
  2084 "(15*a^^^4/(a*x^^^3) - 5*a*((b^^^4 - 5*c^^^2*x)/x^^^2))*(x^^^3/(5*a*b^^^3*c^^^3)) + a/c^^^3 * (x*(b/a) - 3*b*(a/b^^^4))";
  2085 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  2086 term2str t;
  2087 if (term2str t) =
  2088 "5 * x ^^^ 2 / (b ^^^ 3 * c)"
  2089 then ()
  2090 else error "rational.sml: diff.behav. in norm_Rational_mg 53";
  2091 
  2092 
  2093 "-------- me Schalk I No.186 ----------------------------";
  2094 "-------- me Schalk I No.186 ----------------------------";
  2095 "-------- me Schalk I No.186 ----------------------------";
  2096 val fmz = ["Term ((14 * x * y) / ( x * y ))",
  2097 	   "normalform N"];
  2098 val (dI',pI',mI') =
  2099   ("Rational",["rational","simplification"],
  2100    ["simplification","of_rationals"]);
  2101 val p = e_pos'; val c = []; 
  2102 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
  2103 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  2104 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  2105 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  2106 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  2107 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  2108 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  2109 val (p,_,f,nxt,_,pt) = me nxt p c pt;
  2110 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
  2111 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
  2112 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
  2113 val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
  2114 case (f2str f, nxt) of
  2115     ("14", ("End_Proof'", _)) => ()
  2116   | _ => error "rational.sml diff.behav. in me Schalk I No.186";
  2117 
  2118 
  2119 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
  2120 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
  2121 "-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
  2122 states:=[];
  2123 CalcTree
  2124 [(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"], 
  2125   ("Rational",["rational","simplification"],
  2126   ["simplification","of_rationals"]))];
  2127 Iterator 1;
  2128 moveActiveRoot 1;
  2129 autoCalculate 1 CompleteCalc;
  2130 val ((pt,p),_) = get_calc 1; show_pt pt;
  2131 
  2132 interSteps 1 ([1],Res);
  2133 val ((pt,p),_) = get_calc 1; show_pt pt;
  2134 
  2135 
  2136 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
  2137 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
  2138 "-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
  2139 states:=[];
  2140 CalcTree
  2141 [(["Term ((a^2 + -1*b^2) / (a^2 + -2*a*b + b^2))", "normalform N"], 
  2142   ("Rational",["rational","simplification"],
  2143   ["simplification","of_rationals"]))];
  2144 Iterator 1;
  2145 moveActiveRoot 1;
  2146 autoCalculate 1 CompleteCalc;
  2147 val ((pt,p),_) = get_calc 1; show_pt pt;
  2148 (*========== inhibit exn 110314 ================================================
  2149 (*with explicit script done already... and removed [1,..] at below...
  2150 interSteps 1 ([1],Res);
  2151 val ((pt,p),_) = get_calc 1; show_pt pt;
  2152 *)
  2153 interSteps 1 ([2],Res);
  2154 val ((pt,p),_) = get_calc 1; show_pt pt;
  2155 
  2156 interSteps 1 ([2,1],Res);
  2157 val ((pt,p),_) = get_calc 1; show_pt pt;
  2158 val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*);
  2159 (*if length newnds = 12 then () WN060905*)
  2160 if length newnds = 13 then ()
  2161 else error "rational.sml: interSteps cancel_p rev_rew_p";
  2162 
  2163 val p = ([2,1,9],Res);
  2164 getTactic 1 p;
  2165 val (_, tac, _) = pt_extract (pt, p);
  2166 (*case tac of SOME (Rewrite ("sym_real_plus_binom_times1", _)) => ()
  2167 WN060905*)
  2168 case tac of SOME (Rewrite ("sym_real_add_mult_distrib2", _)) => ()
  2169 | _ => error "rational.sml: getTactic, sym_real_plus_binom_times1";
  2170 ============ inhibit exn 110314 ==============================================*)
  2171 
  2172 
  2173 "-------- investigate rulesets for cancel_p -------------";
  2174 "-------- investigate rulesets for cancel_p -------------";
  2175 "-------- investigate rulesets for cancel_p -------------";
  2176 val thy = @{theory "Rational"};
  2177 "---------------- (a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
  2178 val t = str2term "(a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
  2179 val tt = str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"(*numerator only*);
  2180 "----- with rewrite_set_";
  2181 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
  2182 term2str tt'= "a ^^^ 2 + -1 * b ^^^ 2" (*true*);
  2183 val tt = str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*);
  2184 val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
  2185 term2str tt' = "a ^^^ 2 + -2 * a * b + b ^^^ 2" (*true*);
  2186 
  2187 "----- with make_deriv";
  2188 val SOME (tt, _) = factout_p_ thy t; term2str tt =
  2189 "(1 * a + 1 * b) * (1 * a + -1 * b) / ((1 * a + -1 * b) * (1 * a + -1 * b))";
  2190 (*
  2191 "--- with ruleset as before 060829";
  2192 val {rules, rew_ord=(_,ro),...} =
  2193     rep_rls (assoc_rls "make_polynomial");
  2194 val der = make_deriv thy Atools_erls rules ro NONE tt;
  2195 print_depth 99; map (term2str o #1) der; print_depth 3;
  2196 print_depth 99; map (rule2str o #2) der; print_depth 3;
  2197 ... did not terminate*)
  2198 "--- with simpler ruleset";
  2199 val {rules, rew_ord=(_,ro),...} =
  2200     rep_rls (assoc_rls "rev_rew_p");
  2201 val der = make_deriv thy Atools_erls rules ro NONE tt;
  2202 print_depth 99; writeln (deriv2str der); print_depth 3;
  2203 
  2204 print_depth 99; map (term2str o #1) der; print_depth 3;
  2205 "...,(-1 * b ^^^ 2 + a ^^^ 2) / (-2 * (a * b) + a ^^^ 2 + (-1 * b) ^^^ 2) ]";
  2206 print_depth 99; map (rule2str o #2) der; print_depth 3;
  2207 print_depth 99; map (term2str o #1 o #3) der; print_depth 3;
  2208 
  2209 val der = make_deriv thy Atools_erls rules ro NONE 
  2210 		     (str2term "(1 * a + 1 * b) * (1 * a + -1 * b)");
  2211 print_depth 99; writeln (deriv2str der); print_depth 3;
  2212 
  2213 val {rules, rew_ord=(_,ro),...} =
  2214     rep_rls (assoc_rls "rev_rew_p");
  2215 val der = make_deriv thy Atools_erls rules ro NONE 
  2216 		     (str2term "(1 * a + -1 * b) * (1 * a + -1 * b)");
  2217 print_depth 99; writeln (deriv2str der); print_depth 3;
  2218 print_depth 99; map (term2str o #1) der; print_depth 3;
  2219 (*WN060829 ...postponed*)
  2220 
  2221 
  2222 "-------- investigate format of factout_ and factout_p_ -";
  2223 "-------- investigate format of factout_ and factout_p_ -";
  2224 "-------- investigate format of factout_ and factout_p_ -";
  2225 val {rules, rew_ord = (_,ro),...} = rep_rls (assoc_rls "make_polynomial");
  2226 val (thy, eval_rls) = (@{theory "Rational"}, Atools_erls)(*see 'fun init_state'*);
  2227 val Rrls {scr = Rfuns {init_state,...},...} = assoc_rls "cancel_p";
  2228 
  2229 "----- see Rational.ML, local cancel_p, fun init_state";
  2230 val t = str2term "(a^^^2 + (-1)*b^^^2) / (a^^^2 + (-2)*a*b + b^^^2)";
  2231 val SOME (t',_) = factout_p_ thy t; term2str t';
  2232 (*
  2233 val rtas = reverse_deriv thy eval_rls rules ro NONE t';
  2234 writeln(trtas2str rst);
  2235 *)
  2236 
  2237 
  2238 "----- see Rational.ML, local cancel_p, fun init_state";
  2239 val t = str2term "a^^^2 / a";
  2240 val SOME (t',_) = factout_p_ thy t; 
  2241 term2str t' = "a * a / (1 * a)" (*true*); 
  2242 (*... can be canceled with
  2243 real_mult_div_cancel2 ?k ~= 0 ==> ?m * ?k / (?n * ?k) = ?m / ?n"*)
  2244 (* sml/ME/rewtools.sml:
  2245 val rtas = reverse_deriv thy Atools_erls rules ro NONE t';
  2246 writeln (deri2str rtas);
  2247 *)
  2248 
  2249 
  2250 "-------- SK 060904 ----------------------------------------------";
  2251 "----- order on polynomials -- input + output";
  2252 val thy = @{theory "Isac"};
  2253 val t = str2term "(a + -1 * b) / (-1 * a + b)";
  2254 val SOME (t', _) = factout_p_ thy t; term2str t';
  2255 val SOME (t', _) = cancel_p_ thy t; term2str t';
  2256 
  2257 val t = str2term "a*b*c*d / (d*e*f*g)";
  2258 val SOME (t', _) = cancel_p_ thy t; term2str t';
  2259 
  2260 val t = str2term "a*(b*(c*d)) / (b*(e*(f*g)))";
  2261 val SOME (t', _) = cancel_p_ thy t; term2str t';
  2262 (*???order.SK  ???*)
  2263 
  2264 "----- SK060904-1a non-termination of cancel_p_ ? worked before 0707xx";
  2265 val t = str2term "(x^^^2 - 4)*(3 - y) / ((y^^^2 - 9)*(2+x))";
  2266 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; 
  2267 if term2str t' = "(2 + -1 * x) / (3 + y)" then ()
  2268 else error "rational.sml SK060904-1a worked since 0707xx";
  2269 
  2270 "----- SK060904-1b non-termination of cancel_p_ ... worked before 0707xx";
  2271 val t = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
  2272 "(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
  2273 val SOME (t',_) = cancel_p_ thy t; 
  2274 if term2str t' = "1 / (4 * c + 3 * e)" then ()
  2275 else error "rational.sml SK060904-1b";
  2276 
  2277 
  2278 "----- SK060904-2a non-termination of add_fraction_p_";
  2279 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) +  " ^
  2280 		  " (-1 * a + b * x) / (a + b * x)      ");
  2281 (* nonterm.SK
  2282 val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
  2283 
  2284 common_nominator_p_ thy t;
  2285 " (a + b * x)*(a + b * x) / ((a + -1 * (b * x))*(a + -1 * (b * x))) +  " ^
  2286 " (-1 * a + b * x)*(a + -1 * (b * x)) / ((a + b * x)*(-1 * a + b * x)) ";
  2287 
  2288 add_fraction_p_ thy t; 
  2289 " ((a + b * x)*(a + b * x)  +  (-1 * a + b * x)*(a + -1 * (b * x))) /" ^
  2290 " ((a + b * x)*(-1 * a + b * x))                                     ";
  2291 *)
  2292 
  2293 
  2294 "-------- how to stepwise construct Scripts -------------";
  2295 "-------- how to stepwise construct Scripts -------------";
  2296 "-------- how to stepwise construct Scripts -------------";
  2297 val thy = @{theory "Rational"};
  2298 (*no trailing _*)
  2299 val p1 = parse thy (
  2300 "Script SimplifyScript (t_t::real) =                             " ^
  2301 "  (Rewrite_Set discard_minus False                   " ^
  2302 "   t_t)");
  2303 
  2304 (*required (): (Rewrite_Set discard_minus False)*)
  2305 val p2 = parse thy (
  2306 "Script SimplifyScript (t_t::real) =                             " ^
  2307 "  (Rewrite_Set discard_minus False                   " ^
  2308 "   t_t)");
  2309 
  2310 val p3 = parse thy (
  2311 "Script SimplifyScript (t_t::real) =                             " ^
  2312 "  ((Rewrite_Set discard_minus False)                   " ^
  2313 "   t_t)");
  2314 
  2315 val p4 = parse thy (
  2316 "Script SimplifyScript (t_t::real) =                             " ^
  2317 "  ((Rewrite_Set discard_minus False)                   " ^
  2318 "   t_t)");
  2319 
  2320 val p5 = parse thy (
  2321 "Script SimplifyScript (t_t::real) =                             " ^
  2322 "  ((Try (Rewrite_Set discard_minus False)                   " ^
  2323 "    Try (Rewrite_Set discard_parentheses False))               " ^
  2324 "   t_t)");
  2325 
  2326 val p6 = parse thy (
  2327 "Script SimplifyScript (t_t::real) =                             " ^
  2328 "  ((Try (Rewrite_Set discard_minus False) @@                   " ^
  2329 "    Try (Rewrite_Set rat_mult_poly False) @@                    " ^
  2330 "    Try (Rewrite_Set make_rat_poly_with_parentheses False) @@   " ^
  2331 "    Try (Rewrite_Set cancel_p_rls False) @@                     " ^
  2332 "    (Repeat                                                     " ^
  2333 "     ((Try (Rewrite_Set common_nominator_p_rls False) @@        " ^
  2334 "       Try (Rewrite_Set rat_mult_div_pow False) @@              " ^
  2335 "       Try (Rewrite_Set make_rat_poly_with_parentheses False) @@" ^
  2336 "       Try (Rewrite_Set cancel_p_rls False) @@                  " ^
  2337 "       Try (Rewrite_Set rat_reduce_1 False)))) @@               " ^
  2338 "    Try (Rewrite_Set discard_parentheses False))               " ^
  2339 "   t_t)"
  2340 );
  2341 
  2342 "----------- get_denominator ----------------------------";
  2343 "----------- get_denominator ----------------------------";
  2344 "----------- get_denominator ----------------------------";
  2345 val thy = @{theory Isac};
  2346 val t = term_of (the (parse thy "get_denominator ((a +x)/b)"));
  2347 val SOME (_, t') = eval_get_denominator "" 0 t thy;
  2348 if term2str t' = "get_denominator ((a + x) / b) = b" then ()
  2349 else error "get_denominator ((a + x) / b) = b"
  2350 
  2351 
  2352 "--------- several errpats in complicated term -------------------";
  2353 "--------- several errpats in complicated term -------------------";
  2354 "--------- several errpats in complicated term -------------------";
  2355 (*TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one*)
  2356 states:=[];
  2357 CalcTree
  2358 [(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"], 
  2359   ("Rational",["rational","simplification"], ["simplification","of_rationals"]))];
  2360 Iterator 1;
  2361 moveActiveRoot 1;
  2362 autoCalculate 1 CompleteCalc;
  2363 val ((pt,p),_) = get_calc 1; show_pt pt;
  2364 
  2365 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
  2366 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
  2367 "-------- nonterminating cancel_p, norm_Rational 2002 ---";
  2368 (*------------------------------------------------------------------------------------\
  2369 "--- WN121204: searched rational.sml for "nonterm", added new numbering" ^
  2370 "              and thoroughly tested with this numbering subsequently";
  2371 "--- 1 ---";
  2372 WN.2.6.03 from rlang.sml 56a 
  2373 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a ^^^ 2 + -1 * b ^^^ 2)";
  2374 val NONE = rewrite_set_ thy false common_nominator_p t;
  2375 "--- 2 ---";
  2376 WN060831 nonterm.SK7 
  2377 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
  2378 val NONE = add_fraction_p_ thy t;
  2379 "--- 3 ---";
  2380 nonterm.SK9 loops: cancel_p kann nicht weiter kuerzen!!! *)
  2381 val t'' = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
  2382 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t'';
  2383 "--- 4 ---";
  2384 val t = str2term 
  2385 "(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)"; 
  2386 WN060831 nonterm.SK10 
  2387 val SOME (t,_) = rewrite_set_ thy false cancel_p t;
  2388 term2str t;
  2389 "--- 5 ---";
  2390 val t = str2term 
  2391 "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
  2392 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  2393 if term2str t = 
  2394 then ()
  2395 else error "rational.sml: diff.behav. in norm_Rational_mg 42";
  2396 "--- 6 ---";
  2397 val t = str2term 
  2398 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
  2399 val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
  2400 ... non terminating.
  2401 "--- 7 ---";
  2402 val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
  2403 "(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)";
  2404 val SOME (t,_) = rewrite_set_ thy false cancel_p t';
  2405 "--- 8 ---";
  2406 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
  2407 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  2408 "--- 9 ---";
  2409 val t = str2term "((12*x*y/(9*x^^^2 - y^^^2))/" ^
  2410 		 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
  2411 		 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
  2412 		 "(20*x*y/(x^^^2 - 25*y^^^2))";
  2413 val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
  2414 "--- 10 ---";
  2415 SK060904-2a non-termination of add_fraction_p_";
  2416 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) +  " ^
  2417 		  " (-1 * a + b * x) / (a + b * x)      ");
  2418 (* nonterm.SK
  2419 val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
  2420 "--- 11 ---";
  2421 common_nominator_p_ thy t;
  2422 " (a + b * x)*(a + b * x) / ((a + -1 * (b * x))*(a + -1 * (b * x))) +  " ^
  2423 " (-1 * a + b * x)*(a + -1 * (b * x)) / ((a + b * x)*(-1 * a + b * x)) ";
  2424 "--- 12 ---";                             
  2425 add_fraction_p_ thy t; 
  2426 " ((a + b * x)*(a + b * x)  +  (-1 * a + b * x)*(a + -1 * (b * x))) /" ^
  2427 " ((a + b * x)*(-1 * a + b * x))                                     ";
  2428 --------------------------------------------------------------------------------------/*)
  2429 
  2430 (*------------------------------------------------------------------------------------\
  2431 "WN121205: thoroughly tested with the above numbering.";
  2432 "  errors in cancel_p: --- 4,5,6,7.";
  2433 "  error in common_nominator_p, common_nominator_p_: --- 10; 1,2?.";
  2434 "  errors caused by ruleset norm_Rational: --- 8,9.";
  2435 trace_rewrite := true;
  2436 
  2437 "--- 1 ---: non-terminating with ### add_fract: done t22 ";
  2438 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a ^^^ 2 + -1 * b ^^^ 2)";
  2439 trace_rewrite:= true;
  2440 rewrite_set_ thy false common_nominator_p t;
  2441 
  2442 "--- 2 ---: non-terminating with ### add_fract: done t22 ";
  2443 val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
  2444 add_fraction_p_ thy t;
  2445 
  2446 "--- 3 ---: norm_Rational calls Rrls cancel_p with non-normalised polys";
  2447 val t = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
  2448 rewrite_set_ thy false norm_Rational t;
  2449 (*tracing end...####  rls: cancel_p on: 
  2450 (a * x ^^^ 2 + -2 * (a * (x * y)) + a * y ^^^ 2 + b * x ^^^ 2 + -2 * (b * (x * y)) + b * y ^^^ 2) /
  2451 (a ^^^ 2 * x ^^^ 2 + -1 * (a ^^^ 2 * y ^^^ 2) + -1 * (b ^^^ 2 * x ^^^ 2) + b ^^^ 2 * y ^^^ 2) *)
  2452 
  2453 "--- 4 ---: non-terminating with Rrls cancel_p on plausible input";
  2454 val t = str2term (
  2455 "(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /"^
  2456 "(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)"); 
  2457 rewrite_set_ thy false cancel_p t;
  2458 (*#  rls: cancel_p on: 
  2459 (a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /
  2460 (a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2) *)
  2461 
  2462 "--- 5 ---: non-terminating with Rrls cancel_p on plausible input";
  2463 val t = str2term "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
  2464 rewrite_set_ thy false norm_Rational t;
  2465 (*####  rls: cancel_p on: 
  2466 (2304 + -1152 * x + -2304 * y + 144 * x ^^^ 2 + 1152 * (x * y) + -144 * (x ^^^ 2 * y)) /
  2467 (48 + -12 * x + -96 * y + 24 * (x * y) + 48 * y ^^^ 2 + -12 * (x * y ^^^ 2))  *)
  2468 
  2469 "--- 6 ---: non-terminating with Rrls cancel_p on plausible input";
  2470 val t = str2term 
  2471 "9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
  2472 rewrite_set_ thy false norm_Rational t;
  2473 (*###  rls: cancel_p on: (-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * (x * y) +
  2474  144 * (x ^^^ 2 * y)) /
  2475 (-48 + 12 * x + 96 * y + -24 * (x * y) + -48 * y ^^^ 2 + 12 * (x * y ^^^ 2)) *)
  2476 
  2477 "--- 7 ---: non-terminating with Rrls cancel_p on plausible input";
  2478 val t' = str2term (
  2479 "(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /"^
  2480 "(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)");
  2481 rewrite_set_ thy false cancel_p t';
  2482 
  2483 "--- 8 ---: bottom of output cannot be looked ad (due to looping?)";
  2484 val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
  2485 val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
  2486 
  2487 "--- 9 ---: probably error in norm_Rational";
  2488 val t = str2term (
  2489 "((12*x*y / (9*x^^^2 - y^^^2)) / (1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
  2490 		"(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2) / (20*x*y/(x^^^2 - 25*y^^^2))");
  2491 rewrite_set_ thy false norm_Rational t;
  2492 (*####  rls: cancel_p on: (19440 * (x ^^^ 8 * y ^^^ 2) + -490320 * (x ^^^ 6 * y ^^^ 4) +
  2493  108240 * (x ^^^ 4 * y ^^^ 6) +
  2494  -6000 * (x ^^^ 2 * y ^^^ 8)) /
  2495 (2160 * (x ^^^ 8 * y ^^^ 2) + -108240 * (x ^^^ 6 * y ^^^ 4) +
  2496  1362000 * (x ^^^ 4 * y ^^^ 6) +
  2497  -150000 * (x ^^^ 2 * y ^^^ 8)) *)
  2498 
  2499 "--- 10 ---: non-terminating with ### add_fract: done t22: error in common_nominator_p ";
  2500 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)");
  2501 rewrite_set_ thy false common_nominator_p t; (*### add_fract: done t22 *)
  2502 common_nominator_p_ thy t;                   (*loops without output*)
  2503 "--- reformulated 10:";
  2504 val t = str2term "(a + -1 * (b * x)) / (a + b * x)";
  2505 rewrite_set_ thy false cancel_p t = NONE;
  2506 "--- 11 ---";
  2507 "--- 12 ---";                             
  2508 "...both are to be considered after common_nominator_p_ is improved";
  2509 --------------------------------------------------------------------------------------/*)
  2510 ============ inhibit exn WN130824 TODO ======================================================*)
  2511