test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 14 Mar 2011 16:50:44 +0100
branchdecompose-isar
changeset 41930 6aa90baf7780
parent 41929 e4b645e5f25b
child 41931 ca6aac81b893
permissions -rw-r--r--
intermed.update Isabelle2011: tests finished...

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