test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Sat, 24 Aug 2013 11:18:43 +0200
changeset 52085 39f0a7b9b054
parent 48788 c102346a2958
child 52087 dacbaaea9f95
permissions -rw-r--r--
GCD_Poly_ML: reformat specific part of rewriter

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