test/Tools/isac/Knowledge/rational-old.sml
author Walther Neuper <neuper@ist.tugraz.at>
Tue, 28 Sep 2010 09:06:56 +0200
branchisac-update-Isa09-2
changeset 38031 460c24a6a6ba
parent 37991 028442673981
child 38043 6a36acec95d9
permissions -rw-r--r--
tuned error and writeln

# raise error --> error
# writeln in atomtyp, atomty, atomt and xmlsrc
     1 (* tests for rationals
     2    Stefan Karnel
     3    2002
     4    use"../kbtest/rational.sml";
     5    use"kbtest/rational.sml";
     6    use"rational.sml";
     7 *)
     8 
     9 (*--------------------------------15.10.02---
    10 (* tests*)
    11 print("\n\n*********************   tests    *************************\n\n");
    12 print("\n\n***** divide tests *****\n");
    13 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_)));
    14 (* result: [(1,[0,0,1]),(1,[0,0,0])] *)
    15 if mv_pquot1=[(1,[0,0,1]),(1,[0,0,0])] then () else error ("Test failed");
    16 
    17 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_)));
    18 (* result: [(1,[1,0,1]),(~1,[0,0,1])] *)
    19 if mv_prest1=[(1,[1,0,1]),(~1,[0,0,1])] then () else error ("Test failed");
    20 
    21 val mv_pquot2 = (#1(mv_division([(4,[2]),(8,[1]),(16,[0])],[(1,[1]),(1,[0])],LEX_)));
    22 (* result: [(4,[1]),(4,[0])] *)
    23 if mv_pquot2=[(4,[1]),(4,[0])] then () else error ("Test failed");
    24 
    25 val mv_prest2 = (#2(mv_division([(4,[2]),(8,[1]),(16,[0])],[(1,[1]),(1,[0])],LEX_))); 
    26 (* result: [(12,[0]] *)
    27 if mv_prest2=[(12,[0])] then () else error ("Test failed");
    28 
    29 val mv_pquot3 = (#1(mv_division([(4,[2]),(~4,[0])],[(2,[1]),(2,[0])],LEX_)));
    30 (* [(2,[1]),(~2,[0])] *)
    31 if mv_pquot3=[(2,[1]),(~2,[0])] then () else error ("Test failed");
    32 
    33 val mv_prest3 = (#2(mv_division([(1,[2]),(~1,[0])],[(2,[1]),(2,[0])],LEX_)));
    34 (* [(1,[2]),(~1,[0])] *)
    35 if mv_prest3=[(1,[2]),(~1,[0])] then () else error ("Test failed");
    36 
    37 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_)));
    38 (* [(1,[0,1,1])] *)
    39 if mv_pquot4=[(1,[0,1,1])] then () else error ("Test failed");
    40 
    41 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_)));
    42 (* [(1,[1,1,1]),(~4,[0,1,2]),(4,[1,0,1]),(3,[0,0,1])] *)
    43 if mv_prest4 =[(1,[1,1,1]),(~4,[0,1,2]),(4,[1,0,1]),(3,[0,0,1])] then () else error ("Test failed");
    44 
    45 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_))); 
    46 (* [(1,[2,2,0]),(6,[2,1,2]),(3,[1,1,0]),(4,[1,0,0]),(4,[0,4,0]),(3,[0,0,0])]*)
    47 if mv_pquot5=[(1,[2,2,0]),(6,[2,1,2]),(3,[1,1,0]),(4,[1,0,0]),(4,[0,4,0]),(3,[0,0,0])] then () else error ("Test failed");
    48 
    49 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_)));
    50 (* [] *)
    51 if mv_prest5=[] then () else error ("Test failed");
    52 
    53 (* (x^2 + 2(a+1)x + (a^2+2a+1)) / (x+a+1) = x+a+1 *)
    54 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_)));
    55 if mv_pquot6=[(1,[1,0,0]),(1,[0,1,0]),(1,[0,0,0])] then () else error ("Test failed");
    56 
    57 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_)));
    58 if mv_prest6=[] then () else error ("Test failed");
    59 
    60 (* Exception tests *)
    61 (* mv_division ([(1,[0,0,0])],[(0,[1,2,3])],LEX_); *)
    62 
    63 print("\n\n***** MV_CONTENT-TESTS *****\n");
    64 val mv_cont1=mv_content([(1,[2,1]),(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,1]),(1,[0,0])]); 
    65 (* [(1,[0,1]),(1,[0,0])] *)
    66 if  mv_cont1=[(1,[0,1]),(1,[0,0])] then () else error ("Test failed");
    67 
    68 val mv_pp1=mv_pp([(1,[1,1]),(1,[1,0]),(1,[0,1]),(1,[0,0])]); 
    69 (*[(1,[1,0]),(1,[0,0])]*)
    70 if mv_pp1=[(1,[1,0]),(1,[0,0])] then () else error ("Test failed");
    71 
    72 val mv_cont2=mv_content([(2,[1]),(4,[0])]);
    73 (* [(2,[0])] *)
    74 if mv_cont2=[(2,[0])] then () else error ("Test failed");
    75 
    76 val mv_pp2=mv_pp([(2,[1]),(4,[0])]);
    77 (* [(1,[1]),(2,[0])] *)
    78 if mv_pp2=[(1,[1]),(2,[0])] then () else error ("Test failed");
    79 
    80 val mv_cont3=mv_content[(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(16,[1,1,1])];
    81 (* [(2,[0,0,0])] *)
    82 if mv_cont3=[(2,[0,0,0])] then () else error ("Test failed");
    83 
    84 val mv_pp3=mv_pp[(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(16,[1,1,1])];
    85 (* [(5,[2,2,0]),(4,[2,1,1]),(8,[1,1,1]),(6,[1,0,2])] *)
    86 if mv_pp3=[(5,[2,2,0]),(4,[2,1,1]),(8,[1,1,1]),(6,[1,0,2])] then () else error ("Test failed");
    87 
    88 val mv_cont4=mv_content[(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])];
    89 (* [(1,[0,0,0])] *)
    90 if mv_cont4=[(1,[0,0,0])] then () else error ("Test failed");
    91 
    92 val mv_pp4=mv_pp [(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])]; 
    93 (* [(2,[2,1,0]),(2,[1,1,0]),(3,[1,0,1]),(3,[0,0,1])] *)
    94 if mv_pp4=[(2,[2,1,0]),(2,[1,1,0]),(3,[1,0,1]),(3,[0,0,1])] then () else error ("Test failed");
    95 
    96 val con1=mv_content([(9,[2,0]),(15,[1,1]),(12,[1,0]),(6,[0,2]),(12,[0,1])]);
    97 (* [(3,[0,0])] *) 
    98 if con1=[(3,[0,0])] then () else error ("Test failed");
    99 
   100 val pp1=mv_pp([(9,[2,0]),(15,[1,1]),(12,[1,0]),(6,[0,2]),(12,[0,1])]);
   101 (* [(3,[2,0]),(5,[1,1]),(4,[1,0]),(2,[0,2]),(4,[0,1])] *) 
   102 if pp1=[(3,[2,0]),(5,[1,1]),(4,[1,0]),(2,[0,2]),(4,[0,1])] then () else error ("Test failed");
   103 
   104 val con2=mv_content([(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])]); 
   105 (* [(1,[0,0])] *)
   106 if con2=[(1,[0,0])] then () else error ("Test failed");
   107 
   108 val pp2 =mv_pp([(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])]); 
   109 (* [(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])] *)
   110 if pp2=[(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])] then () else error ("Test failed");
   111 
   112 val cont1 = mv_content [(1,[2,1,0]),(2,[2,1,0])]; 
   113 (* [(3,[0,1,0])] *)
   114 if cont1=[(3,[0,1,0])] then () else error ("Test failed");
   115 
   116 val pp1 = mv_pp [(1,[2,1,0]),(2,[2,1,0])]; 
   117 (* [(1,[2,0,0])] *)
   118 if pp1=[(1,[2,0,0])] then () else error ("Test failed");
   119 
   120 val cont2 = mv_content [(4,[1,2,0]),(2,[2,1,0])]; 
   121 (* [(2,[0,1,0])] *)
   122 if cont2=[(2,[0,1,0])] then () else error ("Test failed");
   123 
   124 val pp2 = mv_pp [(4,[1,2,0]),(2,[2,1,0])];
   125 (* [(1,[2,0,0]),(2,[1,1,0])] *)
   126 if pp2=[(1,[2,0,0]),(2,[1,1,0])] then () else error ("Test failed");
   127 
   128 print("\n\n\n\n********************************************************\n\n");
   129 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])];
   130 (*if cont3=[(1,[0,1,0])] then () else error ("Test failed"); *)
   131 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])];
   132 
   133 
   134 print("\n\n***** gcd-tests *****\n"); 
   135 val ggt1 = gcd_poly [(4,[2,2]),(8,[1,1]),(4,[0,0])] [(2,[1,1]),(2,[0,0])]; 
   136 (* [(2,[1,1]),(2,[0,0])] *)
   137 if ggt1=[(2,[1,1]),(2,[0,0])] then () else error ("Test failed");
   138 
   139 val ggt2 = gcd_poly [(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])];
   140 (* [(2,[1,1,0]),(3,[0,0,1])] *)
   141 if ggt2=[(2,[1,1,0]),(3,[0,0,1])] then () else error ("Test failed");
   142 
   143 val ggt3 = gcd_poly [(1,[2,0,0]),(~2,[1,0,1]),(1,[0,0,2])] [(1,[1,0,0]),(~1,[0,0,1])]; 
   144 (* [(1,[1,0,0]),(~1,[0,0,1])] *)
   145 if ggt3=[(1,[1,0,0]),(~1,[0,0,1])] then () else error ("Test failed");
   146 
   147 val ggt4 = gcd_poly [(1,[2,1,0]),(2,[2,1,0])] [(5,[1,0,0])]; 
   148 (* [(1,[1,0,0])] *)
   149 if ggt4=[(1,[1,0,0])] then () else error ("Test failed");
   150 
   151 val ggt5 = gcd_poly [(4,[2,0,0]),(~8,[1,0,1]),(4,[0,0,2])] [(1,[2,0,0]),(~1,[0,0,2])]; 
   152 (* [(1,[1,0,0]),(~1,[0,0,1])] *)
   153 if ggt5=[(1,[1,0,0]),(~1,[0,0,1])] then () else error ("Test failed");
   154 
   155 val ggt6 = gcd_poly [(10,[2,1,1]),(14,[1,1,0]),(3,[1,0,1]),(20,[1,2,1])] [(5,[1,1,1]),(7,[2,1,1])];
   156 (* [(1,[0,0,0])] *)
   157 if ggt6=[(1,[1,0,0])] then () else error ("Test failed");
   158 
   159 val ggt7 = gcd_poly [(~169,[4,3,3]),(273,[4,2,2]),(247,[3,3,4]),(~91,[3,3,2]),(78,[3,3,1]),(~399,[3,2,3]),(147,[3,2,1]),(~114,[2,3,2]),(42,[2,3,0])]  [(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])];
   160 (* [(13,[3,1,1]),(~19,[2,1,2]),(7,[2,1,0])] *)
   161 if ggt7=[(13,[3,1,1]),(~19,[2,1,2]),(7,[2,1,0])] then () else error ("Test failed");
   162 
   163 print("\n\n***** kgv-tests *****\n"); 
   164 val kgv1=lcm_poly [(10,[])] [(15,[])];
   165 (* [(30,[])] *)
   166 if kgv1=[(30,[])] then () else error ("Test failed");
   167 
   168 val kgv2=lcm_poly [(1,[2,0,0]),(~2,[1,0,1]),(1,[0,0,2])] [(1,[1,0,0]),(~1,[0,0,1])]; 
   169 (* [(1,[2,0,0]),(~2,[1,0,1]),(1,[0,0,2])] *)
   170 if kgv2=[(1,[2,0,0]),(~2,[1,0,1]),(1,[0,0,2])] then () else error ("Test failed");
   171 
   172 val kgv3=lcm_poly [(4,[2,0,0]),(~8,[1,0,1]),(4,[0,0,2])] [(1,[2,0,0]),(~1,[0,0,2])]; 
   173 (* [(4,[3,0,0]),(~4,[2,0,1]),(~4,[1,0,2]),(4,[0,0,3])] *)
   174 if kgv3=[(4,[3,0,0]),(~4,[2,0,1]),(~4,[1,0,2]),(4,[0,0,3])] then () else error ("Test failed");
   175 
   176 (*
   177 print("***** TERM2POLY-TESTS *****\n"); 
   178 val t0 = (term_of o the o (parse thy)) "3 * 4";
   179 val t1 = (term_of o the o (parse thy)) "27";
   180 val t11= (term_of o the o (parse thy)) "27 * c";
   181 val t2 = (term_of o the o (parse thy)) "b";
   182 val t23= (term_of o the o (parse thy)) "c^^^7";
   183 val t24= (term_of o the o (parse thy)) "5 * c^^^7";
   184 val t26= (term_of o the o (parse thy)) "a * b"; 
   185 val t3 = (term_of o the o (parse thy)) "2  +  a";
   186 val t4 = (term_of o the o (parse thy)) "b  +  a";
   187 val t5 = (term_of o the o (parse thy)) "2  +  a^^^3";*)
   188 val t6 = (term_of o the o (parse thy)) "5*a^^^2*b^^^3*c+4*a^^^4*b+2*a*c";
   189 val t7 = (term_of o the o (parse thy)) "a-b";
   190 (*
   191 (the o term2poly) t0;
   192 (the o term2poly) t1;
   193 (the o term2poly) t11;
   194 (the o term2poly) t2;
   195 (the o term2poly) t23;
   196 (the o term2poly) t24;
   197 (the o term2poly) t26;
   198 (the o term2poly) t3;
   199 (the o term2poly) t4;
   200 (the o term2poly) t5;
   201 (the o term2poly) t6;
   202 (the o term2poly) t7;*)
   203 
   204 
   205 print("\n\n***** STEP_CANCEL_TESTS: *****\n");
   206 (*
   207 val term2 = (term_of o the o (parse thy)) " (9 * a^^^2 * b) ///  (6 * a * c)";
   208 val div2   = step_cancel term2;
   209 atomt div2; 
   210 *)
   211 
   212 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";
   213 val div1  = step_cancel term1;
   214 (*if div1 =  (term_of o the o (parse thy)) "((10 * a * b * c + 14 * b + 3 * c + 20 * b^^^2 * c) * a) /// (1 * a)" then () else raise error ("Test failed");*)
   215 
   216 val term2 = (term_of o the o (parse thy)) "(10 * a^^^2 * b * c + 14 * a * b + 3 * a * c + 20 * a * b^^^2 * c) /// (5 * a * b * c  +  7 * a^^^2 * b * c) ";
   217 val div2  = step_cancel term2;
   218 (*if div2 = ([(10,[1,1,1]),(20,[0,2,1]),(14,[0,1,0]),(3,[0,0,1])],[(1,[1,0,0])],[(7,[1,1,1]),(5,[0,1,1])]) then () else raise error ("Test failed");*)
   219 
   220 
   221 val term3 = (term_of o the o (parse thy)) "(10 * a^^^2 * b * c) /// (1 * x * y * z) ";
   222 val div3 = step_cancel term3;
   223 
   224 
   225 
   226 (*val mul1=(term_of o the o (parse thy)) "(5*a*b*c+4*a*b+2*a*c)"; 
   227 val mul2=(the (term2poly((term_of o the o (parse thy)) "13*a^^^2*b*c+7*a*b-19*a*b*c^^^2")));
   228 val mul3=(the (term2poly((term_of o the o (parse thy)) "6*a*b^^^2-13*a^^^2*b^^^2*c^^^2+21*a^^^2*b*c")));
   229 val t1=mv_mul(mul1,mul2,LEX_);
   230 val t2=mv_mul(mul3,mul2,LEX_);
   231 val div3=step_cancel t1 t2;
   232 if div3=([(5,[0,1,1]),(4,[0,1,0]),(2,[0,0,1])],[(13,[3,1,1]),(~19,[2,1,2]),(7,[2,1,0])],[(~13,[1,2,2]),(21,[1,1,1]),(6,[0,2,0])]) then () else error ("Test failed");*)
   233 
   234 print("\n\n***** all tests successfull ;-) ******\n\n");
   235 
   236 
   237 
   238 val thy = Rational.thy;
   239 val rls = Prls {func=cancel};
   240 val t = (term_of o the o (parse thy)) 
   241 	    "(1 + 1 * a ^^^ 1)///(-2 + 2 * a ^^^ 2)";
   242 val (t,asm) = the (rewrite_set_ thy eval_rls false rls t);
   243 
   244 
   245 val thy' = "Rational";
   246 val rls' = "cancel";
   247 val t' = "(1 + 1 * a ^^^ 1)///(-2 + 2 * a ^^^ 2)";
   248 val (t',asm') = the (rewrite_set thy' "eval_rls" false rls' t');
   249 (*if t' = "1 /// (-2 + 2 * a)" then ()
   250 else error "tests/rationals.sml(1): new behaviour";*)
   251 
   252 
   253 val thy' = "Rational";
   254 val rls' = "cancel";
   255 val t' = "(10 * a^^^2 * b * c + 14 * a * b + 3 * a * c + 20 * a * b^^^2 * c) /// (5 * a * b * c  +  7 * a^^^2 * b * c) ";
   256 val (t',asm') = the (rewrite_set thy' "eval_rls" false rls' t');
   257 
   258 val thy' = "Rational";
   259 val rls' = "cancel";
   260 val t' = "(a^^^2 * b  + 2 * a * b +  b ) /// ( a^^^2   - 1 )";
   261 val (t',asm') = the (rewrite_set thy' "eval_rls" false rls' t');
   262 
   263 (*
   264 val term2 = (term_of o the o (parse thy))  "(a^^^2 * b  + 2 * a * b +  b ) /// ( a^^^2   - 1 )";
   265 val div2  = direct_cancel term2;
   266 val t = (term_of o the o (parse thy)) "(1 + 1 * a ^^^ 1)///(-2 + 2 * a ^^^ 2) = 0";*)
   267 
   268 
   269 
   270 (*WN folgendes aus examples he"uberkopiert ...*)
   271 
   272 (* examples from:
   273    Mathematik 1
   274    Schalk 
   275    Reniets Verlag *)
   276 
   277 val thy' = "Rational";
   278 val rls' = "cancel";
   279 val mp = "make_polynomial";
   280 
   281 (* page 63 *)
   282 
   283 print("\n\nexample 186:\n");
   284 print("a)\n");
   285 val e186a'="(14 * x * y) / ( x * y )";
   286 val e186a = the (rewrite_set thy' "rational_erls" false rls' e186a');
   287 print("b)\n");
   288 val e186b'="(60 * a * b) / ( 15 * a  * b )";
   289 val e186b = the (rewrite_set thy' "rational_erls" false rls' e186b');
   290 print("c)\n");
   291 val e186c'="(144 * a^^^2 * b * c) / (12 * a * b * c )";
   292 val e186c = (the (rewrite_set thy' "rational_erls" false rls' e186c'))
   293     handle e => print_exn e;
   294 val t = (term_of o the o (parse thy)) e186c';
   295 atomt t;
   296 
   297 print("\n\nexample 187:\n");
   298 print("a)\n");
   299 val e187a'="(12 * x * y) / (8 * y^^^2 )";
   300 val e187a = the (rewrite_set thy' "rational_erls" false rls' e187a');
   301 print("b)\n");
   302 val e187b'="(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
   303 val e187b = the (rewrite_set thy' "rational_erls" false rls' e187b');
   304 print("c)\n");
   305 val e187c'="(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";
   306 val e187c = the (rewrite_set thy' "rational_erls" false rls' e187c');
   307 
   308 print("\n\nexample 188:\n");
   309 print("a)\n");
   310 val e188a'="(8 * x + -8) / (9 * x + -9 )";
   311 val e188a = the (rewrite_set thy' "rational_erls" false rls' e188a');
   312 val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "(8*((-1) + x))/(9*((-1) + x))";
   313 if t="((-8) + 8 * x) / ((-9) + 9 * x)"then()
   314 else error "rationals.sml: e188a new behaviour";
   315 print("b)\n");
   316 val e188b'="(5 * x + -15) / (6 * x + -18 )";
   317 val e188b = the (rewrite_set thy' "rational_erls" false rls' e188b');
   318 print("c)\n");
   319 val e188c'="( a + -1 * b ) / ( b + -1 * a )";
   320 val e188c = the (rewrite_set thy' "rational_erls" false rls' e188c');
   321 val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
   322 if t="(a + -1 * b) / (b + -1 * a)"then()
   323 else error "rationals.sml: e188c new behaviour";
   324 
   325 print("\n\nexample 190:\n");
   326 print("c)\n");
   327 val e190c'="( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )";
   328 val e190c = the (rewrite_set thy' "rational_erls" false rls' e190c');
   329 val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
   330 if t="(1 + (3 * a + (27 * a ^^^ 3 + 9 * a ^^^ 2))) /\n(3 * a + (18 * a ^^^ 2 + 27 * a ^^^ 3))"then()
   331 (*TERMORDER               ~~~~~~~       ~~~~~~~*)
   332 else error "rationals.sml: e190c new behaviour";
   333 
   334 print("\n\nexample 191:\n");
   335 print("a)\n");
   336 val e191a'="( x^^^2 + -1 * y^^^2 ) / ( x + y )";
   337 val e191a = the (rewrite_set thy' "rational_erls" false rls' e191a'); 
   338 val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "((x + (-1) * y)*(x + y))/((1)*(x + y))";
   339 if t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)"then()
   340 else error "rationals.sml: e191a new behaviour";
   341 print("c)\n");
   342 val e191c'="( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )";
   343 val e191c = the (rewrite_set thy' "rational_erls" false rls' e191c');
   344 val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
   345 if t="(25 + ((-30) * x + 9 * x ^^^ 2)) / ((-25) + 9 * x ^^^ 2)"then()
   346 else error "rationals.sml: 'e191c' new behaviour";
   347 
   348 print("\n\nexample 192:\n");
   349 print("b)\n");
   350 val e192b'="( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 *  y^^^3 )";
   351 val e192b = the (rewrite_set thy' "rational_erls" false rls' e192b');
   352 val SOME (t,_) = rewrite_set thy' "rational_erls" false mp "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
   353 if t="(7 * x ^^^ 3 + -1 * (y * x ^^^ 2)) / (-1 * y ^^^ 3 + 7 * (x * y ^^^ 2))"then()
   354 (*TERMORDER                ~~~~~*)
   355 else error "rationals.sml: 'e192b' new behaviour";
   356 
   357 print("\n\nexample 193:\n");
   358 print("a)\n");
   359 val e193a'="( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )";
   360 val e193a = the (rewrite_set thy' "rational_erls" false rls' e193a');
   361 print("b)\n");
   362 val e193b'="( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )";
   363 val e193b = the (rewrite_set thy' "rational_erls" false rls' e193b');
   364 print("c)\n");
   365 val e193c'="( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )";
   366 val SOME(t,_) = rewrite_set thy' "rational_erls" false rls' e193c';
   367 --------------------------------15.10.02---*)
   368 
   369 
   370 (*---------- WN: 10.9.02:
   371 ML> val e204a = the (rewrite_set thy' "rational_erls" false rls' e204a');
   372 *** RATIONALS_STEP_CANCEL_EXCEPTION: Invalid fraction                           
   373 print("\n\nexample 204:\n");
   374 print("a)\n");
   375 val e204a'="((5 * x) / 9) + ((3 * x) / 9) + (x / 9)";
   376 val e204a = the (rewrite_set thy' "rational_erls" false rls' e204a');
   377 print("b)\n");
   378 val e204b'="5 / x + -3 / x + -1 / x";
   379 val e204b = the (rewrite_set thy' "rational_erls" false rls' e204b');
   380 
   381 print("\n\nexample 205:\n");
   382 print("a)\n");
   383 val e205a'="((4 * x + 7) / 8) + ((4 * x + 3) / 8)";
   384 val e205a = the (rewrite_set thy' "rational_erls" false rls' e205a');
   385 print("b)\n");
   386 val e205b'="((5 * x + 2) / 3) + ((-2 * x + 1) / 3)";
   387 val e205b = the (rewrite_set thy' "rational_erls" false rls' e205b');
   388 
   389 print("\n\nexample 206:\n");
   390 print("a)\n");
   391 val e206a'="((5 * x + 4) / (2 * x + -1)) + ((9 * x + 5) / (2 * x + -1))";
   392 val e206a = the (rewrite_set thy' "rational_erls" false rls' e206a'); 
   393 print("b)\n");
   394 val e206b'="((17 * x + -23) / (5 * x + 4)) + ((-25 + -17 * x) / (5 * x + 4))";
   395 val e206b = the (rewrite_set thy' "rational_erls" false rls' e206b');
   396 
   397 print("\n\nexample 207:\n");
   398 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)) ";
   399 val e207 = the (rewrite_set thy' "rational_erls" false rls' e207'); 
   400 
   401 print("\n\nexample 208:\n");
   402 val e208'="((3 * x + 2) / (x + 2)) + ((5 * x + -1) / (x + 2)) + ((-7 * x + -3) / (x + 2)) + ((-1 * x + -3) / (x + 2)) ";
   403 val e208 = the (rewrite_set thy' "rational_erls" false rls' e208'); 
   404 
   405 print("\n\nexample 209:\n");
   406 val e209'="((3 * x + -7 * y + 3 * z) / (4)) + ((2 * x + 17 * y + 10 * z) / (4)) + ((-1 * x + 2 * y + z) / (4)) ";
   407 val e209 = the (rewrite_set thy' "rational_erls" false rls' e209'); 
   408 
   409 print("\n\nexample 210:\n");
   410 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)) ";
   411 val e210 = the (rewrite_set thy' "rational_erls" false rls' e210'); 
   412 
   413 print("\n\nexample 211:\n");
   414 print("a)\n"); 
   415 val e211a'="((b) / (a + -1 * b)) + ((-1 * a) / (a + -1 * b))"; 
   416 val e211a = the (rewrite_set thy' "rational_erls" false rls' e211a'); 
   417 print("b)\n");
   418 val e211b'="((b) / (b^^^2 + -1 * a^^^2)) + ((-1 * a) / (b^^^2 + -1 * a^^^2))";
   419 val e211b = the (rewrite_set thy' "rational_erls" false rls' e211b');
   420 
   421 print("\n\nexample 212:\n");
   422 print("a)\n");
   423 val e212a'="((4) / (x)) + ((-3) / (y)) + -1";
   424 val e212a = the (rewrite_set thy' "rational_erls" false rls' e212a'); 
   425 print("b)\n");
   426 val e212b'="((4) / (x)) + ((-5) / (y)) + ((6) / (x*y))";
   427 val e212b = the (rewrite_set thy' "rational_erls" false rls' e212b');
   428 
   429 print("\n\nexample 213:\n");
   430 print("a)\n"); 
   431 val e213a'="((5 * x) / (3 * y^^^2)) + ((19 * z) / (6 * x * y)) +  ((-2 * x) / (3 * y^^^2)) + ((7 * y^^^2) / (6 * x^^^2)) ";
   432 val e213a = the (rewrite_set thy' "rational_erls" false rls' e213a'); 
   433 print("b)\n"); 
   434 val e213b'="((2 * b) / (3 * a^^^2)) + ((3 * c) / (7 * a * b)) +  ((4 * b) / (3 * a^^^2)) + ((3 * a) / (7 * b^^^2))";
   435 val e213b = the (rewrite_set thy' "rational_erls" false rls' e213b');
   436 
   437 print("\n\nexample 214:\n");
   438 print("a)\n");
   439 val e214a'="((3 * x + 2 * y + 2 * z) / (4)) + ((-5 * x + -3 * y) / (3)) + ((x + y + -2 * z) / (2))";
   440 val e214a = the (rewrite_set thy' "rational_erls" false rls' e214a'); 
   441 print("b)\n");
   442 val e214b'="((5 * x + 2 * y + z) / (2)) + ((-7 * x + -3 * y) / (3)) + ((3 * x + 6 * y + -1 * z) / (12))";
   443 val e214b = the (rewrite_set thy' "rational_erls" false rls' e214b');
   444 
   445 print("\n\nexample 216:\n");
   446 print("a)\n"); 
   447 val e216a'="((2 * b + 3 * c) / (a * c)) + ((3 * a + b) / (a * b)) + ((-2 * b^^^2 + -3 * a * c) / (a * b * c))";
   448 val e216a = the (rewrite_set thy' "rational_erls" false rls' e216a');  
   449 print("b)\n");
   450 val e216b'="((2 * a + 3 * b) / (b * c)) + ((3 * c + a) / (a * c)) + ((-2 * a^^^2 + -3 * b * c) / (a * b * c))";
   451 val e216b = the (rewrite_set thy' "rational_erls" false rls' e216b');
   452 
   453 print("\n\nexample 217:\n");
   454 val e217'="((z + -1) / (z)) + ((3 * z ^^^2 + -6 * z + 5) / (z^^^2)) + ((-4 * z^^^3 + 7 * z^^^2 + -5 * z + 5) / (z^^^3))";
   455 val e217 = the (rewrite_set thy' "rational_erls" false rls' e217'); 
   456 
   457 print("\n\nexample 218:\n");
   458 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))";
   459 val e218 = the (rewrite_set thy' "rational_erls" false rls' e218'); 
   460 
   461 print("\n\nexample 219:\n");
   462 print("a)\n");
   463 val e219a'="((1) / (y + 1)) + ((1) / (y + 2)) + ((1) / (y + 3))";
   464 val e219a = the (rewrite_set thy' "rational_erls" false rls' e219a');
   465 print("b)\n");
   466 val e219b'="((1) / (x + 1)) + ((1) / (x + 2)) + ((-2) / (x + 3))";
   467 val e219b = the (rewrite_set thy' "rational_erls" false rls' e219b'); 
   468 
   469 print("\n\nexample 220:\n");
   470 print("a)\n");
   471 val e220a'="((17) / (5 * r + -2)) + ((-13) / (2 * r + 3)) + ((4) / (3 * r + -5))";
   472 val e220a = the (rewrite_set thy' "rational_erls" false rls' e220a');
   473 print("b)\n");
   474 val e220b'="((20 * a) / (a + -3)) + ((-19 * a) / (a + -4)) + ((a) / (a + -5))";
   475 val e220b = the (rewrite_set thy' "rational_erls" false rls' e220b'); 
   476 
   477 print("\n\nexample 221:\n");
   478 print("a)\n");
   479 val e221a'="((a + b) / (a + -1 * b)) + ((a + -1 * b) / (a + b))";
   480 val e221a = the (rewrite_set thy' "rational_erls" false rls' e221a');
   481 print("b)\n");
   482 val e221b'="((x + -1 * y) / (x + y)) + ((x + y) / (x + -1 * y)) ";
   483 val e221b = the (rewrite_set thy' "rational_erls" false rls' e221b');
   484 
   485 print("\n\nexample 222:\n");
   486 print("a)\n");
   487 val e222a'="((1 + -1 * x) / (1 + x)) + ((-1 + -1 * x) / (1 + -1 * x)) + ((4 * x) / (1 + -1 * x^^^2))";
   488 val e222a = the (rewrite_set thy' "rational_erls" false rls' e222a');
   489 print("b)\n");
   490 val e222b'="((1 + x ) / (1 + -1 * x)) + ((-1 + x) / (1 + x)) + ((2 * x) / (1 + -1 * x^^^2))";
   491 val e222b = the (rewrite_set thy' "rational_erls" false rls' e222b'); 
   492 
   493 print("\n\nexample 225:\n");
   494 print("a)\n");
   495 val e225a'="((6 * a) / (a^^^2 + -64)) + ((a + 2) / (2 * a + 16)) + ((-1) / (2))";
   496 val e225a = the (rewrite_set thy' "rational_erls" false rls' e225a');
   497 print("b)\n");
   498 val e225b'="((a + 2 ) / (2 * a + 12)) + ((4 * a) / (a^^^2 + -36)) + ((-1) / (2))";
   499 val e225b = the (rewrite_set thy' "rational_erls" false rls' e225b'); 
   500 
   501 print("\n\nexample 226:\n");
   502 print("a)\n");
   503 val e226a'="((35 * z) / (49 * z^^^2 + -4)) + -1 + ((14 * z + -1) / (14 * z + 4)) ";
   504 val e226a = the (rewrite_set thy' "rational_erls" false rls' e226a');
   505 print("b)\n"); 
   506 val e226b'="((45 * a * b) / (25 * a^^^2 + -9 * b^^^2)) + ((20 * a + 3 * b) / (10 * a + 6 * b))  + -2";
   507 val e226b = the (rewrite_set thy' "rational_erls" false rls' e226b');  
   508 
   509 print("\n\nexample 227:\n");
   510 print("a)\n");
   511 val e227a'="((6 * z + 11) / (6 * z + 14)) + ((9 * z ) / (9 * z^^^2 + -49)) + -1 ";
   512 val e227a = the (rewrite_set thy' "rational_erls" false rls' e227a');
   513 print("b)\n");
   514 val e227b'="((16 * a + 37 * b) / (4 * a + 10 * b)) + ((6 * a * b) / (4 * a^^^2 + -25 * b^^^2)) + -4 ";
   515 val e227b = the (rewrite_set thy' "rational_erls" false rls' e227b'); 
   516 
   517 print("\n\nexample 228:\n");
   518 print("a)\n");
   519 val e228a'="((7 * a + 11) / (3 * a^^^2 + -3)) + ((-2 * a + -1) / (a^^^2 + -1 * a)) + ((-1) / (3 * a + 3))";
   520 val e228a = the (rewrite_set thy' "rational_erls" false rls' e228a'); 
   521 print("b)\n");
   522 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))";
   523 val e228b = the (rewrite_set thy' "rational_erls" false rls' e228b');  
   524 
   525 
   526 print("\n\nexample 229:\n");
   527 print("a)\n");
   528 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))";
   529 val e229a = the (rewrite_set thy' "rational_erls" false rls' e229a'); 
   530 print("b)\n");
   531 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))"; 
   532 val e229b = the (rewrite_set thy' "rational_erls" false rls' e229b'); 
   533  
   534 print("\n\nexample 230:\n");
   535 print("a)\n"); 
   536 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))";
   537 val e230a = the (rewrite_set thy' "rational_erls" false rls' e230a');
   538 print("b)\n");
   539 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))";
   540 val e230b = the (rewrite_set thy' "rational_erls" false rls' e230b');
   541 
   542 print("\n\nexample 231:\n");
   543 print("a)\n");
   544 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))";
   545 val e231a = the (rewrite_set thy' "rational_erls" false rls' e231a'); 
   546 print("b)\n");
   547 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))";
   548 val e231b = the (rewrite_set thy' "rational_erls" false rls' e231b');
   549 
   550 print("\n\nexample 232:\n");
   551 print("a)\n");
   552 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))";
   553 val e232a = the (rewrite_set thy' "rational_erls" false rls' e232a'); 
   554 print("b)\n");
   555 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))";
   556 val e232b = the (rewrite_set thy' "rational_erls" false rls' e232b');
   557 
   558 print("\n\nexample 233:\n");
   559 print("a)\n");
   560 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))";
   561 val e233a = the (rewrite_set thy' "rational_erls" false rls' e233a'); 
   562 print("b)\n");
   563 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))";
   564 val e233b = the (rewrite_set thy' "rational_erls" false rls' e233b');
   565 
   566 print("\n\nexample 234:\n");
   567 print("a)\n");
   568 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))";
   569 val e234a = the (rewrite_set thy' "rational_erls" false rls' e234a'); 
   570 print("b)\n"); 
   571 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)) ";
   572 val e234b = the (rewrite_set thy' "rational_erls" false rls' e234b');  
   573 
   574 print("\n\nexample 235:\n");
   575 print("a)\n");
   576 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))";
   577 val e235a = the (rewrite_set thy' "rational_erls" false rls' e235a'); 
   578 print("b)\n"); 
   579 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)) ";
   580 val e235b = the (rewrite_set thy' "rational_erls" false rls' e235b');  
   581  
   582 print("\n\nexample 236:\n");
   583 print("a)\n"); 
   584 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))";
   585 val e236a = the (rewrite_set thy' "rational_erls" false rls' e236a');  
   586 print("b)\n");   
   587 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)) ";
   588 val e236b = the (rewrite_set thy' "rational_erls" false rls' e236b');  
   589 
   590 print("\n\nexample heuberger:\n");
   591 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)";
   592 val eheu = the (rewrite_set thy' "rational_erls" false rls' eheu');
   593 
   594 print("\n\nexample stiefel:\n");
   595 val est1'="(7) / (-14) + (-2) / (4)";
   596 val est1 = the (rewrite_set thy' "rational_erls" false rls' est1');
   597 if est1 = ("(-1) / 1",[]) then ()
   598 else error "new behaviour in rationals.sml: est1'";
   599 -------------------------------------------------------------------------*)
   600 
   601 
   602 (*
   603    val t = (term_of o the o (parse thy))
   604 	    "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
   605    val SOME (t',_) = factor_expanded_ thy t;
   606    term2str t';
   607  
   608    "((-3) - x) * ((-3) + x) / (((-3) + x) * ((-3) + x))"
   609    "(3 + x) * (3 - x) / ((3 - x) * (3 - x))"
   610 *)
   611 
   612 
   613 
   614 (*WN.28.8.02: tests for the 'reverse-rewrite' functions:
   615   these are defined in Rationals.ML and stored in 
   616   the 'reverse-ruleset' cancel*)
   617 
   618 (*the term for which reverse rewriting is demonstrated*)
   619   val t = (term_of o the o (parse thy))
   620 	      "(9 - x ^^^ 2) / (9 + 6 * x + x ^^^ 2)";
   621   val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
   622   		       next_rule=nex,normal_form=nor,...},...} = cancel;
   623 
   624 (*normal_form produces the result in ONE step*)
   625   val SOME (t',_) = nor t;
   626   term2str t';
   627 
   628 (*initialize the interpreter state used by the 'me'*)
   629   val (t,_,revsets,_) = ini t;
   630 
   631 (*find the rule 'r' to apply to term 't'*)
   632   val SOME r = nex revsets t;
   633   (*val r = Thm ("sym_#mult_2_3","6 = 2 * 3") : rule*)
   634 
   635 (*check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
   636   if the rule is OK, the term resulting from applying the rule is returned,too;
   637   there might be several rule applications inbetween,
   638   which are listed after the thead in reverse order*)
   639   val (r,(t,asm))::_ = loc revsets t r;
   640   term2str t;
   641   "(9 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)";
   642 
   643 (*find the next rule to apply*)
   644   val SOME r = nex revsets t;
   645   (*val r = Thm ("sym_#power_3_2","9 = 3 ^^^ 2") : rule*)
   646 
   647 (*check the next rule*)
   648   val (r,(t,asm))::_ = loc revsets t r;
   649   term2str t;
   650   "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)";
   651 
   652 (*find and check the next rules, rewrite*)
   653   val SOME r = nex revsets t;
   654   val (r,(t,asm))::_ = loc revsets t r;
   655   term2str t;
   656   "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)";
   657 
   658   val SOME r = nex revsets t;
   659   val (r,(t,asm))::_ = loc revsets t r;
   660   term2str t;
   661   "(3 - x) * (3 + x) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)";
   662 
   663   val SOME r = nex revsets t;
   664   val (r,(t,asm))::_ = loc revsets t r;
   665   term2str t;
   666   "(3 - x) * (3 + x) / ((3 + x) * (3 + x))";
   667 
   668   val SOME r = nex revsets t;
   669   val (r,(t,asm))::_ = loc revsets t r;
   670   val ss = term2str t;
   671   if ss = "(3 - x) / (3 + x)" then ()
   672   else error "rational.sml: new behav. in rev-set cancel";
   673   terms2str asm; 
   674 
   675 
   676 
   677 (*WN.11.9.02: the 'reverse-ruleset' cancel*)
   678 
   679   (*the term for which reverse rewriting is demonstrated*)
   680   val t = (term_of o the o (parse thy))
   681 	      "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))";
   682   val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
   683   		       next_rule=nex,normal_form=nor,...},...} = cancel;
   684   (*normal_form produces the result in ONE step*)
   685   val SOME (t',_) = nor t;
   686   term2str t';
   687   (*initialize the interpreter state used by the 'me'*)
   688   val (t,_,revsets,_) = ini t;
   689 (*
   690  val [rs] = revsets;
   691  filter_out (eq_Thms ["sym_real_add_zero_left",
   692 		      "sym_real_mult_0",
   693 		      "sym_real_mult_1"]) rs;
   694 
   695  10.10.02: dieser Fall terminiert nicht (make_poly enth"alt zu viele rules)
   696   val SOME r = nex revsets t;
   697   val (r,(t,asm))::_ = loc revsets t r;
   698   term2str t;
   699 
   700   val SOME r = nex revsets t;
   701   val (r,(t,asm))::_ = loc revsets t r;
   702   term2str t;
   703 
   704  ------ revset ----------------------------------------------------
   705 /// [Thm ("sym_real_add_zero_left","?z = 0 + ?z"),
   706 ///  Thm ("sym_real_mult_0","0 = 0 * ?z"),
   707 !    Thm ("sym_#mult_2_(-3)","(-6) * x = 2 * ((-3) * x)"),
   708 !    Thm ("sym_#add_(-3)_3","0 = (-3) + 3"),
   709  
   710 ?    Thm ("sym_real_num_collect_assoc",
   711        "[| ?l is_const; ?m is_const |]
   712   	==> (?l + ?m) * ?n + ?k = ?l * ?n + (?m * ?n + ?k)"),
   713 OK   Thm ("sym_real_mult_2_assoc","2 * ?z1.0 + ?k = ?z1.0 + (?z1.0 + ?k)"),
   714 OK   Thm ("sym_real_add_left_commute","?y + (?x + ?z) = ?x + (?y + ?z)"),
   715 ///  Thm ("sym_real_mult_1","?z = 1 * ?z"),
   716 !    Thm ("sym_#power_3_2","9 = 3 ^^^ 2"),
   717 !    Thm ("sym_#mult_-1_-1","1 * x ^^^ 2 = -1 * (-1 * x ^^^ 2)"),
   718 !    Thm ("sym_#mult_-1_3","(-3) * x = -1 * (3 * x)"),
   719 OK   Thm ("realpow_twoI","?r1 ^^^ 2 = ?r1 * ?r1"  [.]),
   720 OK   Thm ("sym_real_add_assoc",
   721       "?z1.0 + (?z2.0 + ?z3.0) = ?z1.0 + ?z2.0 + ?z3.0"),
   722 OK   Thm
   723      ("sym_real_mult_assoc","?z1.0 * (?z2.0 * ?z3.0) = ?z1.0 * ?z2.0 * ?z3.0"),
   724 OK   Thm ("sym_real_mult_left_commute",
   725       "?z2.0 * (?z1.0 * ?z3.0) = ?z1.0 * (?z2.0 * ?z3.0)"),
   726 OK   Thm ("sym_real_mult_commute","?w * ?z = ?z * ?w"),
   727 ?    Thm ("sym_real_add_mult_distrib2",
   728       "?w * ?z1.0 + ?w * ?z2.0 = ?w * (?z1.0 + ?z2.0)"),
   729 ?    Thm ("sym_real_add_mult_distrib",
   730       "?z1.0 * ?w + ?z2.0 * ?w = (?z1.0 + ?z2.0) * ?w"),
   731 OK   Thm ("real_mult_div_cancel2","?k ~= 0 ==> ?m * ?k / (?n * ?k) = ?m / ?n")]
   732  -------- revset ---------------------------------------------------- 
   733 
   734   val t = (term_of o the o (parse thy)) "(-6) * x";
   735   val t = (term_of o the o (parse thy)) 
   736 	      "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))";
   737   val thm = (mk_thm thy "(-6) * x = 2 * ((-3) * x)") 
   738       handle e => print_exn e;
   739   val SOME (t',_) = rewrite_ thy e_rew_ord e_rls false thm t;     
   740   term2str t';
   741 ----------------------------------------------------------------------*)
   742 
   743 
   744 
   745 (* SK: Testbeispiele --- WN kopiert Rational.ML -> rational.sml-----
   746 
   747 val t1 = (term_of o the o (parse thy)) "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
   748 val SOME (t1',rest)= cancel_ thy t1;
   749 val SOME (t1'',_)= factor_out_gcd_ thy t1;
   750 print(term2str t1'^" + Einschr\"ankung: "^term2str (hd(rest)));
   751 term2str t1'';
   752 
   753 val t1 = (term_of o the o (parse thy)) "((-3 * x^^^2 + 6 *x - 3) / (2*x - 2))";
   754 val SOME (t1',_)= cancel_ thy t1;
   755 val SOME (t1'',_)= factor_expanded_ thy t1;
   756 term2str t1';
   757 term2str t1'';
   758 
   759 val t2 = (term_of o the o (parse thy)) "((x+ (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
   760 val SOME (t2',_) = add_fractions_ thy t2;
   761 val SOME (t2'',_) = common_nominators_ thy t2; 
   762 term2str t2';
   763 term2str t2'';
   764 
   765 val t2 = (term_of o the o (parse thy)) "((x - 1) / (x + 1)) + ((x + 1) / (x - 1))";
   766 val SOME (t2',_) = add_expanded_frac_ thy t2;
   767 val SOME (t2'',_) = common_expanded_nom_ thy t2; 
   768 term2str t2';
   769 term2str t2'';
   770 
   771 
   772 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))";
   773 val SOME (t3',_) = common_nominators_ thy t3; 
   774 val SOME (t3'',_) = add_fractions_ thy t3; 
   775 (term2str t3');
   776 (term2str t3'');
   777 
   778 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))";
   779 val SOME (t3',_) = common_expanded_nom_ thy t3; 
   780 val SOME (t3'',_) = add_expanded_frac_ thy t3; 
   781 (term2str t3');
   782 (term2str t3'');
   783 -------------------------------*)
   784 
   785 (*
   786 val SOME(t4,t5) = norm_rational_ thy t3;
   787 term2str t4;
   788 term2str (hd(t5));*)
   789 
   790 (*val test1 = (term_of o the o (parse thy)) "1 - x^^^2 - 5 * x^^^5";
   791 val test2 = (term_of o the o (parse thy)) "1 + (-1) * x ^^^ 2 + (-5) * x ^^^ 5";
   792 val test2 = (term_of o the o (parse thy)) "1 - x";
   793 val test2 = (term_of o the o (parse thy)) "1 + (-1) * x";
   794 term2str(expanded2term(test1));
   795 term2str(term2expanded(test2)); *)
   796 
   797 
   798 
   799 (* WN kopiert 16.10.02 Rational.ML -> rational.sml-----vvv---*)
   800 
   801   val t=(term_of o the o (parse thy)) "(9 - x^^^2)/(9 - 6*x + x^^^2)";
   802   val SOME (t',_) = factout_ thy t;
   803   val SOME (t'',_) = cancel_ thy t;
   804   term2str t';
   805   term2str t'';
   806   "(3 + x) * (3 - x) / ((3 - x) * (3 - x))";
   807   "(3 + x) / (3 - x)";
   808   			   
   809   val t=(term_of o the o(parse thy))
   810 	    "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1 / (3 - x)";
   811   val SOME (t',_) = common_nominator_ thy t;
   812   val SOME (t'',_) = add_fraction_ thy t;
   813   term2str t';
   814   term2str t'';
   815   "(9 - x ^^^ 2) / ((3 - x) * (3 - x)) + 1 * (3 - x) / ((3 - x) * (3 - x))";
   816   "(4 + x) / (3 - x)";
   817 
   818   (*WN.16.10.02 hinzugef"ugt -----vv---*)
   819   val t=(term_of o the o(parse thy))
   820 	    "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1";
   821   val SOME (t',_) = common_nominator_ thy t;
   822   val SOME (t'',_) = add_fraction_ thy t;
   823   term2str t';
   824   term2str t'';
   825   "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\
   826   \1 * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
   827   "6 / (3 - x)";
   828 
   829   val t=(term_of o the o(parse thy))
   830 	    "1 + (9 - x^^^2) / (9 - 6*x + x^^^2)";
   831   val SOME (t',_) = common_nominator_ thy t;
   832   val SOME (t'',_) = add_fraction_ thy t;
   833   term2str t';
   834   term2str t'';
   835   "1 * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\
   836   \(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
   837   "6 / (3 - x)";
   838   (*WN.16.10.02 hinzugef"ugt -----^^---*)
   839 
   840   val t=(term_of o the o (parse thy)) 
   841   	    "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2)";
   842   val SOME (t',_) = factout_ thy t;
   843   val SOME (t'',_) = cancel_ thy t;
   844   term2str t';
   845   term2str t'';
   846   "(y + x) * (y - x) / ((y - x) * (y - x))";
   847   "(y + x) / (y - x)";
   848     
   849   val t=(term_of o the o (parse thy)) 
   850 	    "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2) + 1 / (y - x)";
   851   val SOME (t',_) = common_nominator_ thy t;
   852   val SOME (t'',_) = add_fraction_ thy t;
   853   term2str t';
   854   term2str t'';
   855   "((-1) * x ^^^ 2 + y ^^^ 2) / (((-1) * x + y) * ((-1) * x + y)) +\
   856   \1 * ((-1) * x + y) / (((-1) * x + y) * ((-1) * x + y))";
   857   "((-1) - x - y) / (x - y)";
   858   (*WN.16.10.02     ^^^^^^^ Reihenfolge aus Angabe umgekehrt ?!*)
   859 
   860   val t=(term_of o the o (parse thy)) 
   861 	    "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2) + 1 / (x - y)";
   862   val SOME (t',_) = common_nominator_ thy t;
   863   val SOME (t'',_) = add_fraction_ thy t;
   864   term2str t';
   865   term2str t'';
   866   "((-1) * y ^^^ 2 + x ^^^ 2) / (((-1) * y + x) * ((-1) * y + x)) +\
   867   \1 * ((-1) * y + x) / (((-1) * y + x) * ((-1) * y + x))";
   868   "((-1) - y - x) / (y - x)";
   869   (*WN.16.10.02     ^^^^^^^ lexicographische Ordnung ?!*)
   870 
   871   val t=(term_of o the o (parse thy)) 
   872   	    "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2)";
   873   val SOME (t',_) = norm_expanded_rat_ thy t;
   874   term2str t';
   875   "(y + x) / (y - x)";
   876 (*val SOME (t'',_) = norm_rational_ thy t;
   877   term2str t'';
   878   *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial 
   879   WN.16.10.02 ?!*)
   880  
   881   val t=(term_of o the o (parse thy)) 
   882 	    "(9 - x^^^2)/(9 - 6*x + x^^^2) + (1)/(3 + x)";
   883   val SOME (t',_) = norm_expanded_rat_ thy t;
   884   term2str t';
   885   "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)";
   886 (*val SOME (t'',_) = norm_rational_ thy t;
   887   term2str t'';
   888   *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial
   889   WN.16.10.02 ?!*)
   890  
   891   val t=(term_of o the o (parse thy)) 
   892 	    "(9 + (-1)* x^^^2)/(9 + (-1)* 6*x + x^^^2) + (1)/(3 + x)";
   893   val SOME (t',_) = norm_expanded_rat_ thy t;
   894   val SOME (t'',_) = norm_rational_ thy t;
   895   term2str t';
   896   term2str t'';
   897   "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)";
   898   "(12 + 5 * x + x ^^^ 2) / (9 + (-1) * x ^^^ 2)";
   899 (* WN kopiert 16.10.02 Rational.ML -> rational.sml-----^^^---*)
   900 
   901 
   902