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