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