test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Wed, 08 Sep 2010 16:47:22 +0200
branchisac-update-Isa09-2
changeset 37991 028442673981
parent 37980 c0a9d6bdc1d6
child 38031 460c24a6a6ba
permissions -rw-r--r--
tuned src + test

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