test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Thu, 06 Oct 2011 17:43:00 +0200
branchdecompose-isar
changeset 42301 93083d4e05d8
parent 41933 8d38adf87848
child 42395 308050197b06
permissions -rw-r--r--
intermed. Build_Inverse_Z_Transform:

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