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