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