test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Wed, 28 Aug 2013 11:48:37 +0200
changeset 52095 c9fbb8171a0a
parent 52094 61cccc3f2f56
child 52096 ee2a5f066e44
permissions -rw-r--r--
GCD_Poly_ML: test 2nd level integration of gcd_poly

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