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