test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Tue, 05 Oct 2010 16:46:56 +0200
branchisac-update-Isa09-2
changeset 38046 17861d5d115f
parent 38044 c99116c5e9a8
child 38080 53ee777684ca
permissions -rw-r--r--
repaired 'fun calc_equ' for "op <", completed rewriting in test/../rational.sml

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