test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Sat, 17 Mar 2012 12:52:30 +0100
changeset 42395 308050197b06
parent 42301 93083d4e05d8
child 42439 94fa39284c95
permissions -rw-r--r--
uncomment test/../root,equation,poly.sml (Isabelle 2002 --> 2011)

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