test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Fri, 31 Dec 2010 14:54:02 +0100
branchdecompose-isar
changeset 38083 a1d13f3de312
parent 38080 53ee777684ca
child 41928 20138d6136cd
permissions -rw-r--r--
removed error *** nxt_add: EX itm. not(dat(itm)<=dat(ori))

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