test/Tools/isac/Knowledge/rational-2.sml
changeset 60500 59a3af532717
parent 60477 4ac966aaa785
child 60504 8cc1415b3530
     1.1 --- a/test/Tools/isac/Knowledge/rational-2.sml	Thu Jul 28 11:43:27 2022 +0200
     1.2 +++ b/test/Tools/isac/Knowledge/rational-2.sml	Sat Jul 30 16:47:45 2022 +0200
     1.3 @@ -158,7 +158,7 @@
     1.4                val subst: Type.tyenv * Envir.tenv =
     1.5                  Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
     1.6               in
     1.7 -              snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
     1.8 +              snd (eval__true ctxt (i + 1) (map (Envir.subst_term subst) pres) [] erls)
     1.9               end) handle Pattern.MATCH => false
    1.10             fun scan_ f [] = false (*scan_ NEVER called by []*)
    1.11               | scan_ f (pp::pps) =
    1.12 @@ -180,7 +180,7 @@
    1.13                val subst: Type.tyenv * Envir.tenv =
    1.14                  Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
    1.15               in
    1.16 -              snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
    1.17 +              snd (eval__true ctxt (i + 1) (map (Envir.subst_term subst) pres) [] erls)
    1.18               end) handle Pattern.MATCH => false
    1.19             fun scan_ f [] = false (*scan_ NEVER called by []*)
    1.20               | scan_ f (pp::pps) =
    1.21 @@ -275,8 +275,7 @@
    1.22  "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
    1.23  "-------- rls norm_Rational downto fun gcd_poly ------------------------------";
    1.24  val t = TermC.str2term "(x \<up> 2 - 4)*(3 - y) / ((y \<up> 2 - 9)*(2+x))";
    1.25 -Rewrite.trace_on := false (*true false*);
    1.26 -(* trace stops with ...: (and then jEdit hangs)..
    1.27 +(* trace_rewrite stops with ...: (and then jEdit hangs)..
    1.28  rewrite_set_ thy false norm_Rational t;
    1.29  :
    1.30  ###  rls: cancel_p on: (- 12 + 4 * y + 3 * x \<up> 2 + - 1 * (x \<up> 2 * y)) /
    1.31 @@ -329,7 +328,7 @@
    1.32                val subst: Type.tyenv * Envir.tenv =
    1.33                  Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
    1.34               in
    1.35 -              snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
    1.36 +              snd (eval__true ctxt (i + 1) (map (Envir.subst_term subst) pres) [] erls)
    1.37               end) handle Pattern.MATCH => false
    1.38             fun scan_ f [] = false (*scan_ NEVER called by []*)
    1.39               | scan_ f (pp::pps) =
    1.40 @@ -377,9 +376,7 @@
    1.41                                  (* required for applying thms in rewriting  \<up> ^*)
    1.42  (* we get details from here..*)
    1.43  
    1.44 -Rewrite.trace_on := false; (*true false*)
    1.45 -val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t;
    1.46 -Rewrite.trace_on := false; (*true false*)
    1.47 +val SOME (t', _) = Rewrite.rewrite_set_ ctxt true add_fractions_p t;
    1.48  (* Rewrite.trace_on:
    1.49  add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + - 1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
    1.50                       (* |||||||||||||||||||||||||||||||||||| *)
    1.51 @@ -420,9 +417,7 @@
    1.52                                      (*AA :: real*)
    1.53  (* we get details from here..*)
    1.54  
    1.55 -Rewrite.trace_on := false; (*true false*)
    1.56 -val SOME (t', _) = Rewrite.rewrite_set_ thy true add_fractions_p t;
    1.57 -Rewrite.trace_on := false; (*true false*)
    1.58 +val SOME (t', _) = Rewrite.rewrite_set_ ctxt true add_fractions_p t;
    1.59  (* Rewrite.trace_on:
    1.60  add_fractions_p on: 3 = A / 2 + A / 4 + (B / 2 + - 1 * B / 2) --> 3 = A / 2 + A / 4 + 0 / 2 *)
    1.61                       (* |||||||||||||||||||||||||||||||||||| *)
    1.62 @@ -462,26 +457,26 @@
    1.63  val thy  = @{theory "Rational"};
    1.64  "-------- WN";
    1.65  val t = TermC.str2term "(2 + -3 * x) / 9";
    1.66 -if NONE = rewrite_set_ thy false cancel_p t then ()
    1.67 +if NONE = rewrite_set_ ctxt false cancel_p t then ()
    1.68  else error "rewrite_set_ cancel_p must return NONE, if the term cannot be cancelled";
    1.69  
    1.70  "-------- example 186a";
    1.71  val t = TermC.str2term "(14 * x * y) / (x * y)";
    1.72    is_expanded (TermC.str2term "14 * x * y");
    1.73    is_expanded (TermC.str2term "x * y");
    1.74 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
    1.75 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
    1.76  if (UnparseC.term t', UnparseC.terms asm) = ("14 / 1", "[]")
    1.77  then () else error "rational.sml cancel Schalk 186a";
    1.78  
    1.79  "-------- example 186b";
    1.80  val t = TermC.str2term "(60 * a * b) / ( 15 * a  * b )";
    1.81 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
    1.82 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
    1.83  if (UnparseC.term t', UnparseC.terms asm) = ("4 / 1", "[]")
    1.84  then () else error "rational.sml cancel Schalk 186b";
    1.85  
    1.86  "-------- example 186c";
    1.87  val t = TermC.str2term "(144 * a \<up> 2 * b * c) / (12 * a * b * c)";
    1.88 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
    1.89 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
    1.90  if (UnparseC.term t', UnparseC.terms asm) = ("12 * a / 1", "[]")
    1.91  then () else error "rational.sml cancel Schalk 186c";
    1.92  
    1.93 @@ -489,7 +484,7 @@
    1.94    see --- fun rewrite_set_ downto fun gcd_poly ---
    1.95  "-------- example 187a";
    1.96  val t = TermC.str2term "(12 * x * y) / (8 * y \<up> 2 )";
    1.97 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
    1.98 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
    1.99  if (UnparseC.term t', UnparseC.terms asm) = ("3 * x / (2 * y)", "[\"4 * y ~= 0\"]")
   1.100  then () else error "rational.sml cancel Schalk 187a";
   1.101  *)
   1.102 @@ -498,7 +493,7 @@
   1.103    see --- fun rewrite_set_ downto fun gcd_poly ---
   1.104  "-------- example 187b";
   1.105  val t = TermC.str2term "(8 * x \<up> 2 * y * z ) / (18 * x * y \<up> 2 * z )";
   1.106 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.107 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.108  if (UnparseC.term t', UnparseC.terms asm) = ("4 * x / (9 * y)", "[\"2 * (z * (y * x)) ~= 0\"]")
   1.109  then () else error "rational.sml cancel Schalk 187b";
   1.110  *)
   1.111 @@ -507,7 +502,7 @@
   1.112    see --- fun rewrite_set_ downto fun gcd_poly ---
   1.113  "-------- example 187c";
   1.114  val t = TermC.str2term "(9 * x \<up> 5 * y \<up> 2 * z \<up> 4) / (15 * x \<up> 6 * y \<up> 3 * z )";
   1.115 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.116 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.117  if (UnparseC.term t', UnparseC.terms asm) = 
   1.118    ("3 * z \<up> 3 / (5 * (y * x))", "[\"3 * (z * (y \<up> 2 * x \<up> 5)) ~= 0\"]") 
   1.119  then () else error "rational.sml cancel Schalk 187c";
   1.120 @@ -516,43 +511,43 @@
   1.121  "-------- example 188a";
   1.122  val t = TermC.str2term "(-8 + 8 * x) / (-9 + 9 * x)";
   1.123    is_expanded (TermC.str2term "8 * x + -8");
   1.124 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.125 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.126  if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]")
   1.127  then () else error "rational.sml cancel Schalk 188a";
   1.128  
   1.129  val t = TermC.str2term "(8*((- 1) + x))/(9*((- 1) + x))";
   1.130 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
   1.131 +val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   1.132  if (UnparseC.term t', UnparseC.terms asm) = ("8 / 9", "[]")
   1.133  then () else error "rational.sml cancel Schalk make_polynomial 1";
   1.134  
   1.135  "-------- example 188b";
   1.136  val t = TermC.str2term "(- 15 + 5 * x) / (- 18 + 6 * x)";
   1.137 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.138 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.139  if (UnparseC.term t', UnparseC.terms asm) = ("5 / 6", "[]")
   1.140  then () else error "rational.sml cancel Schalk 188b";
   1.141  
   1.142  "-------- example 188c";
   1.143  val t = TermC.str2term "(a + - 1 * b) / (b + - 1 * a)";
   1.144 -val SOME (t', asm) = rewrite_set_ thy false  cancel_p t;
   1.145 +val SOME (t', asm) = rewrite_set_ ctxt false  cancel_p t;
   1.146  if (UnparseC.term t', UnparseC.terms asm) = ("- 1 / 1", "[]")
   1.147  then () else error "rational.sml cancel Schalk 188c";
   1.148  
   1.149  is_expanded (TermC.str2term "a + - 1 * b") = true;
   1.150  val t = TermC.str2term "((- 1)*(b + (- 1) * a))/(1*(b + (- 1) * a))";
   1.151 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   1.152 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
   1.153  if (UnparseC.term t', UnparseC.terms asm) = ("(a + - 1 * b) / (- 1 * a + b)", "[]")
   1.154  then () else error "rational.sml cancel Schalk make_polynomial 2";
   1.155  
   1.156  "-------- example 190a";
   1.157  val t = TermC.str2term "( 27 * a \<up> 3 + 9 * a \<up> 2 + 3 * a + 1 ) / ( 27 * a \<up> 3 + 18 * a \<up> 2 + 3 * a )";
   1.158 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.159 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.160  if (UnparseC.term t', UnparseC.terms asm) = 
   1.161    ("(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)", "[\"3 * a + 9 * a \<up> 2 \<noteq> 0\"]")
   1.162  then () else error "rational.sml cancel Schalk 190a";
   1.163  
   1.164  "-------- example 190c";
   1.165  val t = TermC.str2term "((1 + 9 * a \<up> 2)*(1 + 3 * a))/((3 * a + 9 * a \<up> 2)*(1 + 3 * a))";
   1.166 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   1.167 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
   1.168  if (UnparseC.term t', UnparseC.terms asm) = 
   1.169    ("(1 + 3 * a + 9 * a \<up> 2 + 27 * a \<up> 3) /\n(3 * a + 18 * a \<up> 2 + 27 * a \<up> 3)", "[]")
   1.170  then () else error "rational.sml make_polynomial Schalk 190c";
   1.171 @@ -561,13 +556,13 @@
   1.172  val t = TermC.str2term "( x \<up> 2 + - 1 * y \<up> 2 ) / ( x + y )";
   1.173    is_expanded (TermC.str2term "x \<up> 2 + - 1 * y \<up> 2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
   1.174    is_expanded (TermC.str2term "x + y") = true;
   1.175 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.176 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.177  if (UnparseC.term t', UnparseC.terms asm) = ("(x + - 1 * y) / 1", "[]")
   1.178  then () else error "rational.sml make_polynomial Schalk 191a";
   1.179  
   1.180  "-------- example 191b";
   1.181  val t = TermC.str2term "((x + (- 1) * y)*(x + y))/((1)*(x + y))";
   1.182 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   1.183 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
   1.184  if (UnparseC.term t', UnparseC.terms asm) = ("(x \<up> 2 + - 1 * y \<up> 2) / (x + y)", "[]")
   1.185  then () else error "rational.sml make_polynomial Schalk 191b";
   1.186  
   1.187 @@ -578,57 +573,57 @@
   1.188    is_expanded (TermC.str2term "- 25 + 9*x \<up> 2") = true;
   1.189  
   1.190  val t = TermC.str2term "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
   1.191 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   1.192 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
   1.193  if (UnparseC.term t', UnparseC.terms asm) = ("(25 + - 30 * x + 9 * x \<up> 2) / (- 25 + 9 * x \<up> 2)", "[]")
   1.194  then () else error "rational.sml make_polynomial Schalk 191c";
   1.195  
   1.196  "-------- example 192b";
   1.197  val t = TermC.str2term "( 7 * x \<up> 3 + - 1 * x \<up> 2 * y ) / ( 7 * x * y \<up> 2 + - 1 *  y \<up> 3 )";
   1.198 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.199 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.200  if (UnparseC.term t', UnparseC.terms asm) = ("x \<up> 2 / y \<up> 2", "[\"y \<up> 2 \<noteq> 0\"]")
   1.201  then () else error "rational.sml cancel_p Schalk 192b";
   1.202  
   1.203  val t = TermC.str2term "((x \<up> 2)*(7 * x + (- 1) * y))/((y \<up> 2)*(7 * x + (- 1) * y))";
   1.204 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   1.205 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
   1.206  if (UnparseC.term t', UnparseC.terms asm) = 
   1.207    ("(7 * x \<up> 3 + - 1 * x \<up> 2 * y) /\n(7 * x * y \<up> 2 + - 1 * y \<up> 3)", "[]")
   1.208  then () else error "rational.sml make_polynomial Schalk 192b";
   1.209  
   1.210  val t = TermC.str2term "((x \<up> 2)*(7 * x + (- 1) * y))/((y \<up> 2)*(7 * x + (- 1) * y))";
   1.211 -val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
   1.212 +val SOME (t', asm) = rewrite_set_ ctxt false make_polynomial t;
   1.213  if (UnparseC.term t', UnparseC.terms asm) = 
   1.214    ("(7 * x \<up> 3 + - 1 * x \<up> 2 * y) /\n(7 * x * y \<up> 2 + - 1 * y \<up> 3)", "[]")
   1.215  then () else error "rational.sml make_polynomial Schalk WN050929 not working";
   1.216  
   1.217  "-------- example 193a";
   1.218  val t = TermC.str2term "( x \<up> 2 + -6 * x + 9 ) / ( x \<up> 2 + -9 )";
   1.219 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.220 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.221  if (UnparseC.term t', UnparseC.terms asm) = ("(- 3 + x) / (3 + x)", "[\"3 + x \<noteq> 0\"]")
   1.222  then () else error "rational.sml cancel_p Schalk 193a";
   1.223  
   1.224  "-------- example 193b";
   1.225  val t = TermC.str2term "( x \<up> 2 + -8 * x + 16 ) / ( 2 * x \<up> 2 + -32 )";
   1.226 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.227 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.228  if (UnparseC.term t', UnparseC.terms asm) = ("(- 4 + x) / (8 + 2 * x)", "[\"8 + 2 * x \<noteq> 0\"]")
   1.229  then () else error "rational.sml cancel_p Schalk 193b";
   1.230  
   1.231  "-------- example 193c";
   1.232  val t = TermC.str2term "( 2 * x + -50 * x \<up> 3 ) / ( 25 * x \<up> 2 + - 10 * x + 1 )";
   1.233 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.234 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.235  if (UnparseC.term t', UnparseC.terms asm) = 
   1.236    ("(2 * x + 10 * x \<up> 2) / (1 + - 5 * x)", "[\"1 + - 5 * x \<noteq> 0\"]")
   1.237  then () else error "rational.sml cancel_p Schalk 193c";
   1.238  
   1.239  (*WN: improved with new numerals*)
   1.240  val t = TermC.str2term "(- 25 + 9*x \<up> 2)/(5 + 3*x)";
   1.241 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.242 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.243  if (UnparseC.term t', UnparseC.terms asm) = ("(- 5 + 3 * x) / 1", "[]")
   1.244  then () else error "rational.sml cancel WN 1";
   1.245  
   1.246  "-------- example heuberger";
   1.247  val t = TermC.str2term ("(x \<up> 4 + x * y + x \<up> 3 * y + y \<up> 2) / " ^
   1.248    "(x + 5 * x \<up> 2 + y + 5 * x * y + x \<up> 2 * y \<up> 3 + x * y \<up> 4)");
   1.249 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.250 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.251  if (UnparseC.term t', UnparseC.terms asm) = 
   1.252    ("(x \<up> 3 + y) / (1 + 5 * x + x * y \<up> 3)", "[\"1 + 5 * x + x * y \<up> 3 \<noteq> 0\"]")
   1.253  then () else error "rational.sml cancel_p heuberger";
   1.254 @@ -647,25 +642,25 @@
   1.255  if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ works on exact fraction";
   1.256  
   1.257  "-------- gcd_poly integration level 2: picks out ONE appropriate subterm";
   1.258 -val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
   1.259 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p t;
   1.260  if UnparseC.term t' = "123 = a * x / (b * x) + c * x / (d * x) + e / f" 
   1.261  then () else error "level 2, rewrite_set_ cancel_p: changed";
   1.262 -val SOME (t', asm) = rewrite_set_ thy false add_fractions_p t;
   1.263 +val SOME (t', asm) = rewrite_set_ ctxt false add_fractions_p t;
   1.264  if UnparseC.term t' = "123 = (b * c * x + a * d * x) / (b * d * x) + e * x / (f * x)"
   1.265  then () else error "level 2, rewrite_set_ add_fractions_p: changed";
   1.266  
   1.267  "-------- gcd_poly integration level 3: rewrites all appropriate subterms";
   1.268 -val SOME (t', asm) = rewrite_set_ thy false cancel_p_rls t;
   1.269 +val SOME (t', asm) = rewrite_set_ ctxt false cancel_p_rls t;
   1.270  if UnparseC.term t' = "123 = a / b + c / d + e / f"
   1.271  then () else error "level 3, rewrite_set_ cancel_p_rls: changed";
   1.272 -val SOME (t', asm) = rewrite_set_ thy false add_fractions_p_rls t; (*CREATE add_fractions_p_rls*)
   1.273 +val SOME (t', asm) = rewrite_set_ ctxt false add_fractions_p_rls t; (*CREATE add_fractions_p_rls*)
   1.274  if UnparseC.term t' = "123 = (b * d * e * x + b * c * f * x + a * d * f * x) / (b * d * f * x)"
   1.275  then () else error "level 3, rewrite_set_ add_fractions_p_rls: changed";
   1.276  
   1.277  "-------- gcd_poly integration level 4: iteration cancel_p -- add_fraction_p";
   1.278  (* simpler variant *)
   1.279  val testrls = Rule_Set.append_rules "testrls" Rule_Set.empty [Rls_ cancel_p, Rls_ add_fractions_p]
   1.280 -val SOME (t', asm) = rewrite_set_ thy false testrls t;
   1.281 +val SOME (t', asm) = rewrite_set_ ctxt false testrls t;
   1.282  (*Rewrite.trace_on := false; (*true false*)
   1.283  #  rls: testrls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
   1.284  ##  rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
   1.285 @@ -679,7 +674,7 @@
   1.286  
   1.287  (* complicated variant *)
   1.288  val testrls_rls = Rule_Set.append_rules "testrls_rls" Rule_Set.empty [Rls_ cancel_p_rls, Rls_ add_fractions_p_rls];
   1.289 -val SOME (t', asm) = rewrite_set_ thy false testrls_rls t;
   1.290 +val SOME (t', asm) = rewrite_set_ ctxt false testrls_rls t;
   1.291  (*#  rls: testrls_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
   1.292  ##  rls: cancel_p_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
   1.293  ###  rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
   1.294 @@ -698,7 +693,7 @@
   1.295  then () else error "level 4, rewrite_set_ *_p_rls: changed"
   1.296  
   1.297  "-------- gcd_poly integration level 5: cancel_p & add_fraction_p within norm_Rational";
   1.298 -val SOME (t', asm) = rewrite_set_ thy false norm_Rational t;
   1.299 +val SOME (t', asm) = rewrite_set_ ctxt false norm_Rational t;
   1.300  if UnparseC.term t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)"
   1.301  then () else error "level 5, rewrite_set_ norm_Rational: changed"
   1.302  
   1.303 @@ -851,49 +846,47 @@
   1.304  "-------- examples: rls norm_Rational ----------------------------------------";
   1.305  "-------- examples: rls norm_Rational ----------------------------------------";
   1.306  "-------- examples: rls norm_Rational ----------------------------------------";
   1.307 -Rewrite.trace_on := false; (*true false*)
   1.308 -
   1.309  val t = TermC.str2term "Not (6*x is_atom)";
   1.310 -val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t';
   1.311 +val SOME (t',_) = rewrite_set_ ctxt false powers_erls t; UnparseC.term t';
   1.312  "HOL.True";
   1.313  val t = TermC.str2term "1 < 2";
   1.314 -val SOME (t',_) = rewrite_set_ thy false powers_erls t; UnparseC.term t';
   1.315 +val SOME (t',_) = rewrite_set_ ctxt false powers_erls t; UnparseC.term t';
   1.316  "HOL.True";
   1.317  
   1.318  val t = TermC.str2term "(6*x) \<up> 2";
   1.319 -val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false @{thm realpow_def_atom} t;
   1.320 +val SOME (t',_) = rewrite_ ctxt dummy_ord powers_erls false @{thm realpow_def_atom} t;
   1.321  if UnparseC.term t' = "6 * x * (6 * x) \<up> (2 + - 1)" then ()
   1.322  else error "rational.sml powers_erls (6*x) \<up> 2";
   1.323  
   1.324  val t = TermC.str2term "- 1 * (- 2 * (5 / 2 * (13 * x / 2)))";
   1.325 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
   1.326 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
   1.327  if UnparseC.term t' = "65 * x / 2" then () else error "rational.sml 4";
   1.328  
   1.329  val t = TermC.str2term "1 - ((13*x)/2 - 5/2) \<up> 2";
   1.330 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
   1.331 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
   1.332  if UnparseC.term t' = "(- 21 + 130 * x + - 169 * x \<up> 2) / 4" then () 
   1.333  else error "rational.sml 5";
   1.334  
   1.335  (*SRAM Schalk I, p.92 Nr. 609a*)
   1.336  val t = TermC.str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
   1.337 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
   1.338 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
   1.339  if UnparseC.term t' = "(- 255 + 112 * x) / 135" then () 
   1.340  else error "rational.sml 6";
   1.341  
   1.342  (*SRAM Schalk I, p.92 Nr. 610c*)
   1.343  val t = TermC.str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
   1.344 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
   1.345 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
   1.346  if UnparseC.term t' = "(3 + x) / - 2" then () else error "rational.sml 7";
   1.347  
   1.348  (*SRAM Schalk I, p.92 Nr. 476a*)
   1.349  val t = TermC.str2term "(x \<up> 2/(1 - x \<up> 2) + 1)/(x/(1 - x) + 1) * (1 + x)";
   1.350  (*. a/b : c/d translated to a/b * d/c .*)
   1.351 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
   1.352 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
   1.353  if UnparseC.term t' = "1" then () else error "rational.sml 8";
   1.354  
   1.355  (*Schalk I, p.92 Nr. 472a*)
   1.356  val t = TermC.str2term "((8*x \<up> 2 - 32*y \<up> 2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
   1.357 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
   1.358 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
   1.359  if UnparseC.term t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
   1.360  
   1.361  (*Schalk I, p.70 Nr. 480b: SEE rational.sml --- nonterminating rls norm_Rational ---*)
   1.362 @@ -901,11 +894,11 @@
   1.363  (*WN130910 add_fractions_p exception Div raised + history:
   1.364  ### WN.2.6.03 from rlang.sml 56a 
   1.365  val t = TermC.str2term "(a + b * x) / (a + - 1 * (b * x)) + (- 1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a \<up> 2 + - 1 * b \<up> 2)";
   1.366 -val NONE = rewrite_set_ thy false add_fractions_p t;
   1.367 +val NONE = rewrite_set_ ctxt false add_fractions_p t;
   1.368  
   1.369  THE ERROR ALREADY OCCURS IN THIS PART:
   1.370  val t = TermC.str2term "(a + b * x) / (a + - 1 * (b * x)) + (- 1 * a + b * x) / (a + b * x)";
   1.371 -val NONE = add_fraction_p_ thy t;
   1.372 +val NONE = add_fraction_p_ ctxt t;
   1.373  
   1.374  SEE Test_Some.thy: section {* add_fractions_p downto exception Div raised ===
   1.375  *)
   1.376 @@ -915,13 +908,13 @@
   1.377  "-------- rational numerals --------------------------------------------------";
   1.378  (*SRA Schalk I, p.40 Nr. 164b *)
   1.379  val t = TermC.str2term "(47/6 - 76/9 + 13/4)/(35/12)";
   1.380 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.381 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.382  if UnparseC.term t = "19 / 21" then ()
   1.383  else error "rational.sml: diff.behav. in norm_Rational_mg 1";
   1.384  
   1.385  (*SRA Schalk I, p.40 Nr. 166a *)
   1.386  val t = TermC.str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
   1.387 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.388 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.389  if UnparseC.term t = "45 / 2" then ()
   1.390  else error "rational.sml: diff.behav. in norm_Rational_mg 2";
   1.391  
   1.392 @@ -930,49 +923,49 @@
   1.393  "-------- examples cancellation from: Mathematik 1 Schalk --------------------";
   1.394  (* e190c Stefan K.*)
   1.395  val t = TermC.str2term "((1 + 9*a \<up> 2) * (1 + 3*a)) / ((3*a + 9*a \<up> 2) * (1 + 3*a))";
   1.396 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.397 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.398  if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
   1.399  then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
   1.400  
   1.401  (* e192b Stefan K.*)
   1.402  val t = TermC.str2term "(x \<up> 2 * (7*x + (- 1)*y))  /  (y \<up> 2 * (7*x + (- 1)*y))";
   1.403 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.404 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.405  if UnparseC.term t = "x \<up> 2 / y \<up> 2"
   1.406  then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
   1.407  
   1.408  (*SRC Schalk I, p.66 Nr. 379c *)
   1.409  val t = TermC.str2term "(a - b)/(b - a)";
   1.410 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.411 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.412  if UnparseC.term t = "- 1"
   1.413  then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
   1.414  
   1.415  (*SRC Schalk I, p.66 Nr. 380b *)
   1.416  val t = TermC.str2term "15*(3*x + 3) * (4*x + 9)  /  (12*(2*x + 7) * (5*x + 5))";
   1.417 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.418 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.419  if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)"
   1.420  then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
   1.421  
   1.422  (* e190c Stefan K.*)
   1.423  val t = TermC.str2term "((1 + 9*a \<up> 2) * (1 + 3*a))  /  ((3*a + 9*a \<up> 2) * (1 + 3 * a))";
   1.424 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.425 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.426  if UnparseC.term t =  "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
   1.427  then () else error "rational.sml: diff.behav. in norm_Rational_mg 3";
   1.428  
   1.429  (* e192b Stefan K.*)
   1.430  val t = TermC.str2term "(x \<up> 2 * (7*x + (- 1)*y))  /  (y \<up> 2 * (7*x + (- 1)*y))";
   1.431 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.432 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.433  if UnparseC.term t = "x \<up> 2 / y \<up> 2"
   1.434  then () else error "rational.sml: diff.behav. in norm_Rational_mg 4";
   1.435  
   1.436  (*SRC Schalk I, p.66 Nr. 379c *)
   1.437  val t = TermC.str2term "(a - b) / (b - a)";
   1.438 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.439 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.440  if UnparseC.term t = "- 1"
   1.441  then () else error "rational.sml: diff.behav. in norm_Rational_mg 5";
   1.442  
   1.443  (*SRC Schalk I, p.66 Nr. 380b *)
   1.444  val t = TermC.str2term "15*(3*x + 3) * (4*x + 9)  /  (12*(2*x + 7) * (5*x + 5))";
   1.445 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.446 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.447  if UnparseC.term t = "(27 + 12 * x) / (28 + 8 * x)"
   1.448  then () else error "rational.sml: diff.behav. in norm_Rational_mg 6";
   1.449  
   1.450 @@ -984,32 +977,32 @@
   1.451    " / (a \<up> 2 * x \<up> 3  +  -3*a \<up> 2 * x \<up> 2 * y  +  3*a \<up> 2 * x * y \<up> 2  +  - 1*a \<up> 2 * y \<up> 3 + " ^
   1.452        "2*a * b * x \<up> 3  +  -6*a * b * x \<up> 2 * y  +  6*a * b * x * y \<up> 2  +  - 2*a * b * y \<up> 3 + " ^
   1.453        "b \<up> 2 * x \<up> 3  +  -3*b \<up> 2 * x \<up> 2 * y  +  3*b \<up> 2 * x * y \<up> 2  +  - 1*b \<up> 2 * y \<up> 3)")
   1.454 -val SOME (t, _) = rewrite_set_ thy false cancel_p t;
   1.455 +val SOME (t, _) = rewrite_set_ ctxt false cancel_p t;
   1.456  if UnparseC.term t = "(a \<up> 2 + 2 * a * b + b \<up> 2) / (x \<up> 2 + - 2 * x * y + y \<up> 2)"
   1.457  then () else error "with Isabelle2002: NONE -- now SOME changed";
   1.458  
   1.459  (*Schalk I, p.66 Nr. 381a *)
   1.460  (* ATTENTION: here the rls is very slow. In Isabelle2002 this required 2 min *)
   1.461  val t = TermC.str2term "18*(a + b) \<up> 3 * (a - b) \<up> 2 / (72*(a - b) \<up> 3 * (a + b) \<up> 2)";
   1.462 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.463 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.464  if UnparseC.term t = "(a + b) / (4 * a + - 4 * b)"
   1.465  then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
   1.466  
   1.467  (*SRC Schalk I, p.66 Nr. 381b *)
   1.468  val t = TermC.str2term "(4*x \<up> 2 - 20*x + 25) / (2*x - 5) \<up> 3";
   1.469 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.470 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.471  if UnparseC.term t = "1 / (- 5 + 2 * x)"
   1.472  then () else error "rational.sml: diff.behav. in norm_Rational_mg 9";
   1.473  
   1.474  (*SRC Schalk I, p.66 Nr. 381c *)
   1.475  val t = TermC.str2term "(27*a \<up> 3 + 9*a \<up> 2+3*a+1) / (27*a \<up> 3 + 18*a \<up> 2+3*a)";
   1.476 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.477 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.478  if UnparseC.term t = "(1 + 9 * a \<up> 2) / (3 * a + 9 * a \<up> 2)"
   1.479  then () else error "rational.sml: diff.behav. in norm_Rational_mg 10";
   1.480  
   1.481  (*SRC Schalk I, p.66 Nr. 383a *)
   1.482  val t = TermC.str2term "(5*a \<up> 2 - 5*a*b) / (a - b) \<up> 2";
   1.483 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.484 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.485  if UnparseC.term t = "- 5 * a / (- 1 * a + b)"
   1.486  then () else error "rational.sml: diff.behav. in norm_Rational_mg 11";
   1.487  
   1.488 @@ -1019,7 +1012,7 @@
   1.489    cancel_p_ thy (TermC.str2term ("(- 1 + - 1 * b + a \<up> 2 + a \<up> 2 * b) /" ^
   1.490                             "(- 1 + - 1 * a + b \<up> 2 + a * b \<up> 2)"))
   1.491  
   1.492 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.493 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.494  if UnparseC.term t = "(1 + - 1 * a) / (1 + - 1 * b)" then ()
   1.495  else error "rational.sml MG tests 3e";
   1.496  *)
   1.497 @@ -1029,12 +1022,12 @@
   1.498  "-------- examples common denominator from: Mathematik 1 Schalk --------------";
   1.499  (*SRA Schalk I, p.67 Nr. 403a *)
   1.500  val t = TermC.str2term "4/x - 3/y - 1";
   1.501 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.502 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.503  if UnparseC.term t = "(- 3 * x + 4 * y + - 1 * x * y) / (x * y)"
   1.504  then () else error "rational.sml: diff.behav. in norm_Rational_mg 12";
   1.505  
   1.506  val t = TermC.str2term "(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a \<up> 2+3*b*c)/(a*b*c)";
   1.507 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.508 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.509  if UnparseC.term t = "4 / c"
   1.510  then () else error "rational.sml: diff.behav. in norm_Rational_mg 13";
   1.511  
   1.512 @@ -1043,20 +1036,20 @@
   1.513  (* WN130911 non-termination due to non-termination of
   1.514    cancel_p_ thy (TermC.str2term "(5 + 3 * x) / (6 + 11 * x + 6 * x \<up> 2 + x \<up> 3)")
   1.515  
   1.516 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.517 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.518  if UnparseC.term t = "(5 + 3 * x) / (6 + 11 * x + 6 * x \<up> 2 + x \<up> 3)"
   1.519  then () else error "rational.sml: diff.behav. in norm_Rational_mg 14";
   1.520  *)
   1.521  
   1.522  (*SRA Schalk I, p.67 Nr. 413b *)
   1.523  val t = TermC.str2term "(1 + x)/(1 - x)  -  (1 - x)/(1 + x)  +  2*x/(1 - x \<up> 2)";
   1.524 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.525 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.526  if UnparseC.term t = "6 * x / (1 + - 1 * x \<up> 2)"
   1.527  then () else error "rational.sml: diff.behav. in norm_Rational_mg 15";
   1.528  
   1.529  (*SRA Schalk I, p.68 Nr. 414a *)
   1.530  val t = TermC.str2term "(x + 2)/(x - 1)  +  (x - 3)/(x - 2)  -  (x + 1)/((x - 1)*(x - 2))";
   1.531 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.532 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.533  if UnparseC.term t ="(- 2 + - 5 * x + 2 * x \<up> 2) / (2 + - 3 * x + x \<up> 2)"
   1.534  then () else error "rational.sml: diff.behav. in norm_Rational_mg 16";
   1.535  
   1.536 @@ -1066,7 +1059,7 @@
   1.537  (* WN130911 non-termination due to non-termination of
   1.538    cancel_p_ thy (TermC.str2term "(4 + -4 * b \<up> 2) / (a \<up> 4 + - 2 * (a \<up> 2 * b \<up> 2) + b \<up> 4)")
   1.539  
   1.540 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.541 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.542  if UnparseC.term t = "4 / (a \<up> 4 + - 2 * a \<up> 2 * b \<up> 2 + b \<up> 4)"
   1.543  then () else error "rational.sml: diff.behav. in norm_Rational_mg 18";
   1.544  *)
   1.545 @@ -1074,7 +1067,7 @@
   1.546  (*SRA Schalk I, p.68 Nr. 430b *)
   1.547  val t = TermC.str2term 
   1.548    "a \<up> 2/(a - 3*b) - 108*a*b \<up> 3/((a+3*b)*(a \<up> 2 - 9*b \<up> 2)) - 9*b \<up> 2*(a - 3*b)/(a+3*b) \<up> 2";
   1.549 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.550 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.551  if UnparseC.term t = "a + 3 * b"
   1.552  then () else error "rational.sml: diff.behav. in norm_Rational_mg 19";
   1.553  
   1.554 @@ -1083,13 +1076,13 @@
   1.555    ("(a \<up> 2 + a*b) / (a \<up> 2 - b \<up> 2)  -  (b \<up> 2 - a*b) / (b \<up> 2 - a \<up> 2)  +  " ^
   1.556    "a \<up> 2*(a - b) / (a \<up> 3 - a \<up> 2*b)  -  2*a*(a \<up> 2 - b \<up> 2) / (a \<up> 3 - a*b \<up> 2)  -  " ^
   1.557    "2*b \<up> 2 / (a \<up> 2 - b \<up> 2)");
   1.558 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.559 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.560  if UnparseC.term t = (*"0" ..isabisac15 | Isabelle2017..*)  "0 / (a \<up> 2 + - 1 * b \<up> 2)"
   1.561  then () else error "rational.sml: diff.behav. in norm_Rational_mg 20";
   1.562  
   1.563  (* some example *)
   1.564  val t = TermC.str2term "3*a / (a*b)  +  x/y";
   1.565 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.566 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.567  if UnparseC.term t = "(3 * y + b * x) / (b * y)"
   1.568  then () else error "rational.sml: diff.behav. in norm_Rational_mg 21";
   1.569  
   1.570 @@ -1099,20 +1092,20 @@
   1.571  "-------- examples multiply and cancel from: Mathematik 1 Schalk -------------";
   1.572  (*------- SRM Schalk I, p.68 Nr. 436a *)
   1.573  val t = TermC.str2term "3*(x+y) / (15*(x - y))  *   25*(x - y) \<up> 2 / (18*(x + y) \<up> 2)";
   1.574 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.575 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.576  if UnparseC.term t = "(- 5 * x + 5 * y) / (- 18 * x + - 18 * y)"
   1.577  then () else error "rational.sml: diff.behav. in norm_Rational_mg 22";
   1.578  
   1.579  (*------- SRM.test Schalk I, p.68 Nr. 436b *)
   1.580  val t = TermC.str2term "5*a*(a - b) \<up> 2*(a + b) \<up> 3/(7*b*(a - b) \<up> 3) * 7*b/(a + b) \<up> 3";
   1.581 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.582 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.583  if UnparseC.term t = "5 * a / (a + - 1 * b)"
   1.584  then () else error "rational.sml: diff.behav. in norm_Rational_mg 23";
   1.585  
   1.586  (*------- Schalk I, p.68 Nr. 437a *)
   1.587  val t = TermC.str2term "(3*a - 4*b) / (4*c+3*e)  *  (3*a+4*b)/(9*a \<up> 2 - 16*b \<up> 2)";
   1.588  (* raises an exception for unclear reasons:
   1.589 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.590 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.591  :
   1.592  ###  rls: cancel_p on: (9 * a \<up> 2 + - 16 * b \<up> 2) / (4 * c + 3 * e) /
   1.593  (9 * a \<up> 2 + - 16 * b \<up> 2) 
   1.594 @@ -1130,7 +1123,7 @@
   1.595  
   1.596  "----- S.K. corrected non-termination 060904";
   1.597  val t = TermC.str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a \<up> 2 - 16*b \<up> 2))";
   1.598 -val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
   1.599 +val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   1.600  if UnparseC.term t = 
   1.601    "(9 * a \<up> 2 + - 16 * b \<up> 2) /\n(36 * a \<up> 2 * c + 27 * a \<up> 2 * e + - 64 * b \<up> 2 * c +\n - 48 * b \<up> 2 * e)"
   1.602  then () else error "rational.sml: S.K.8..corrected 060904-6";
   1.603 @@ -1139,14 +1132,14 @@
   1.604  val t'' = TermC.str2term ("(9 * a \<up> 2 + - 16 * b \<up> 2) /" ^
   1.605    "(36 * a \<up> 2 * c + (27 * a \<up> 2 * e + (-64 * b \<up> 2 * c + -48 * b \<up> 2 * e)))");
   1.606  (* /--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------\
   1.607 -val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
   1.608 +val SOME (t',_) = rewrite_set_ ctxt false cancel_p t'';
   1.609  if UnparseC.term t' = "1 / (4 * c + 3 * e)"
   1.610  then () else error "rational.sml: diff.behav. in cancel_p S.K.8";
   1.611     \--- DOES NOT TERMINATE AT TRANSITION isabisac15 --> Isabelle2017 --------------------------/*)
   1.612  
   1.613  (*------- Schalk I, p.68 Nr. 437b*)
   1.614  val t = TermC.str2term "(a + b)/(x \<up> 2 - y \<up> 2) * ((x - y) \<up> 2/(a \<up> 2 - b \<up> 2))";
   1.615 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.616 +(*val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.617  :
   1.618  ####  rls: cancel_p on: (a * x \<up> 2 + - 2 * (a * (x * y)) + a * y \<up> 2 + b * x \<up> 2 +
   1.619   - 2 * (b * (x * y)) +
   1.620 @@ -1158,26 +1151,26 @@
   1.621  
   1.622  (*------- SRM Schalk I, p.68 Nr. 438a *)
   1.623  val t = TermC.str2term "x*y / (x*y - y \<up> 2)  *  (x \<up> 2 - x*y)";
   1.624 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.625 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.626  if UnparseC.term t = "x \<up> 2"
   1.627  then () else error "rational.sml: diff.behav. in norm_Rational_mg 24";
   1.628  
   1.629  (*------- SRM Schalk I, p.68 Nr. 439b *)
   1.630  val t = TermC.str2term "(4*x \<up> 2 + 4*x + 1)  *  ((x \<up> 2 - 2*x \<up> 3) / (4*x \<up> 2 + 2*x))";
   1.631 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.632 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.633  if UnparseC.term t = "(x + - 4 * x \<up> 3) / 2"
   1.634  then () else error "rational.sml: diff.behav. in norm_Rational_mg 25";
   1.635  
   1.636  (*------- SRM Schalk I, p.68 Nr. 440a *)
   1.637  val t = TermC.str2term "(x \<up> 2 - 2*x) / (x \<up> 2 - 3*x)  *  (x - 3) \<up> 2 / (x \<up> 2 - 4)";
   1.638 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.639 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.640  if UnparseC.term t = "(- 3 + x) / (2 + x)"
   1.641  then () else error "rational.sml: diff.behav. in norm_Rational_mg 26";
   1.642  
   1.643  "----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
   1.644  val t = TermC.str2term "(a \<up> 3 - 9*a) / (a \<up> 3*b - a*b \<up> 3)  *  (a \<up> 2*b + a*b \<up> 2) / (a+3)";
   1.645  (* WN130911 non-termination for unclear reasons:
   1.646 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.647 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.648  
   1.649  ... ENDS WITH THIS TRACE:
   1.650  :
   1.651 @@ -1201,7 +1194,7 @@
   1.652  (* WN130911 non-termination due to non-termination of
   1.653    cancel_p_ thy (TermC.str2term "(4 + -4 * b \<up> 2) / (a \<up> 4 + - 2 * (a \<up> 2 * b \<up> 2) + b \<up> 4)")
   1.654  
   1.655 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.656 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.657  if UnparseC.term t' = "(-3 * a + a \<up> 2) / (a + - 1 * b)" then ()
   1.658  else error "rational.sml: diff.behav. in norm_Rational 28";
   1.659  *)
   1.660 @@ -1211,32 +1204,32 @@
   1.661  "-------- examples common denominator and multiplication from: Schalk --------";
   1.662  (*------- SRAM Schalk I, p.69 Nr. 441b *)
   1.663  val t = TermC.str2term "(4*a/3 + 3*b \<up> 2/a \<up> 3 + b/(4*a))*(4*b/(3*a))";
   1.664 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.665 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.666  if UnparseC.term t = "(36 * b \<up> 3 + 3 * a \<up> 2 * b \<up> 2 + 16 * a \<up> 4 * b) /\n(9 * a \<up> 4)"
   1.667  then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
   1.668  
   1.669  (*------- SRAM Schalk I, p.69 Nr. 442b *)
   1.670  val t = TermC.str2term ("(15*a \<up> 2/x \<up> 3 - 5*b \<up> 4/x \<up> 2 + 25*c \<up> 2/x) * " ^
   1.671    "(x \<up> 3/(5*a*b \<up> 3*c \<up> 3)) + 1/c \<up> 3 * (b*x/a - 3*a/b \<up> 3)");
   1.672 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.673 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.674  if UnparseC.term t = "5 * x \<up> 2 / (a * b \<up> 3 * c)"
   1.675  then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
   1.676  
   1.677  (*------- SRAM Schalk I, p.69 Nr. 443b *)
   1.678  val t = TermC.str2term "(a/2 + b/3) * (b/3 - a/2)";
   1.679 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.680 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.681  if UnparseC.term t = "(- 9 * a \<up> 2 + 4 * b \<up> 2) / 36"
   1.682  then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
   1.683  
   1.684  (*------- SRAM Schalk I, p.69 Nr. 445b *)
   1.685  val t = TermC.str2term "(a \<up> 2/9 + 2*a/(3*b) + 4/b \<up> 2)*(a/3 - 2/b) + 8/b \<up> 3";
   1.686 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.687 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.688  if UnparseC.term t = "a \<up> 3 / 27"
   1.689  then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
   1.690  
   1.691  (*------- SRAM Schalk I, p.69 Nr. 446b *)
   1.692  val t = TermC.str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x \<up> 2 - 16*y \<up> 2)";
   1.693 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.694 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.695  if UnparseC.term t = (*"30 * x \<up> 2 + -9 * x * y + - 20 * y \<up> 2" ..isabisac15 | Isabelle2017..*)
   1.696                    "(- 30 * x \<up> 2 + 9 * x * y + 20 * y \<up> 2) / - 1"
   1.697  then () else error "rational.sml: diff.behav. in norm_Rational_mg 32";
   1.698 @@ -1244,14 +1237,14 @@
   1.699  (*------- SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
   1.700  val t = TermC.str2term 
   1.701  "(2*x \<up> 2/(3*y)+x/y \<up> 2)*(4*x \<up> 4/(9*y \<up> 2)+x \<up> 2/y \<up> 4)*(2*x \<up> 2/(3*y) - x/y \<up> 2)";
   1.702 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.703 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.704  if UnparseC.term t = "(- 81 * x \<up> 4 + 16 * x \<up> 8 * y \<up> 4) / (81 * y \<up> 8)"
   1.705  then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
   1.706  
   1.707  (*------- SRAM Schalk I, p.69 Nr. 450a *)
   1.708  val t = TermC.str2term 
   1.709  "(4*x/(3*y)+2*y/(3*x)) \<up> 2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
   1.710 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.711 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.712  if UnparseC.term t = "(52 * x \<up> 2 + 16 * y \<up> 2) / (9 * y \<up> 2)"
   1.713  then () else error "rational.sml: diff.behav. in norm_Rational_mg 34";
   1.714  
   1.715 @@ -1259,7 +1252,7 @@
   1.716  val t = TermC.str2term 
   1.717    ("(15*a \<up> 4/(a*x \<up> 3)  -  5*a*((b \<up> 4 - 5*c \<up> 2*x) / x \<up> 2))  *  " ^
   1.718    "(x \<up> 3/(5*a*b \<up> 3*c \<up> 3))   +   a/c \<up> 3 * (x*(b/a) - 3*b*(a/b \<up> 4))");
   1.719 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.720 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.721  if UnparseC.term t = "5 * x \<up> 2 / (b \<up> 3 * c)"
   1.722  then () else error "rational.sml: diff.behav. in norm_Rational_mg 53";
   1.723  
   1.724 @@ -1269,13 +1262,13 @@
   1.725  "-------- examples double fractions from: Mathematik 1 Schalk ----------------";
   1.726  "----- SRD Schalk I, p.69 Nr. 454b";
   1.727  val t = TermC.str2term "((2 - x)/(2*a)) / (2*a/(x - 2))";
   1.728 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.729 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.730  if UnparseC.term t = "(- 4 + 4 * x + - 1 * x \<up> 2) / (4 * a \<up> 2)"
   1.731  then () else error "rational.sml: diff.behav. in norm_Rational_mg 35";
   1.732  
   1.733  "----- SRD Schalk I, p.69 Nr. 455a";
   1.734  val t = TermC.str2term "(a \<up> 2 + 1)/(a \<up> 2 - 1) / ((a+1)/(a - 1))";
   1.735 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.736 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.737  if UnparseC.term t = "(1 + a \<up> 2) / (1 + 2 * a + a \<up> 2)" then ()
   1.738  else error "rational.sml: diff.behav. in norm_Rational_mg 36";
   1.739  
   1.740 @@ -1285,7 +1278,7 @@
   1.741    cancel_p_ thy (TermC.str2term ("(- 12 + 4 * y + 3 * x \<up> 2 + - 1 * (x \<up> 2 * y)) /" ^
   1.742                             "(- 18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)"))
   1.743  
   1.744 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.745 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.746  if UnparseC.term t = "(2 + - 1 * x) / (3 + y)" then ()
   1.747  else error "rational.sml: diff.behav. in norm_Rational_mg 37";
   1.748  *)
   1.749 @@ -1296,32 +1289,32 @@
   1.750    cancel_p_ thy (TermC.str2term ("(- 12 + 4 * y + 3 * x \<up> 2 + - 1 * (x \<up> 2 * y)) /" ^
   1.751                             "(- 18 + -9 * x + 2 * y \<up> 2 + x * y \<up> 2)"))
   1.752  
   1.753 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.754 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.755  if UnparseC.term t = "(2 + - 1 * x) / (3 + y)" then ()
   1.756  else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
   1.757  *)
   1.758  
   1.759  "----- ?: worked before 0707xx";
   1.760  val t = TermC.str2term "(3 + - 1 * y) / (-9 + y \<up> 2)";
   1.761 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.762 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.763  if UnparseC.term t = "- 1 / (3 + y)"
   1.764  then () else error "rational.sml: - 1 / (3 + y) norm_Rational";
   1.765  
   1.766  "----- SRD Schalk I, p.69 Nr. 456b";
   1.767  val t = TermC.str2term "(b \<up> 3 - b \<up> 2) / (b \<up> 2+b) / (b \<up> 2 - 1)";
   1.768 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.769 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.770  if UnparseC.term t = "b / (1 + 2 * b + b \<up> 2)"
   1.771  then () else error "rational.sml: diff.behav. in norm_Rational_mg 38";
   1.772  
   1.773  "----- SRD Schalk I, p.69 Nr. 457b";
   1.774  val t = TermC.str2term "(16*a \<up> 2 - 9*b \<up> 2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a \<up> 2 - 9*a \<up> 2*b \<up> 2))";
   1.775 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.776 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.777  if UnparseC.term t = "8 * a \<up> 2 + - 6 * a * b + - 12 * a \<up> 2 * b + 9 * a * b \<up> 2"
   1.778  then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
   1.779  
   1.780  "----- Schalk I, p.69 Nr. 458b works since 0707";
   1.781  val t = TermC.str2term "(2*a \<up> 2*x - a \<up> 2) / (a*x - b*x) / (b \<up> 2*(2*x - 1) / (x*(a - b)))";
   1.782 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.783 +(*val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.784  :
   1.785  ###  rls: cancel_p on: (- 1 * a \<up> 2 + 2 * (a \<up> 2 * x)) / (a * x + - 1 * (b * x)) /
   1.786  ((- 1 * b \<up> 2 + 2 * (b \<up> 2 * x)) / (a * x + - 1 * (b * x))) 
   1.787 @@ -1339,13 +1332,13 @@
   1.788  
   1.789  "----- SRD Schalk I, p.69 Nr. 459b";
   1.790  val t = TermC.str2term "(a \<up> 2 - b \<up> 2)/(a*b) / (4*(a+b) \<up> 2/a)";
   1.791 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.792 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.793  if UnparseC.term t = "(a + - 1 * b) / (4 * a * b + 4 * b \<up> 2)" then ()
   1.794  else error "rational.sml: diff.behav. in norm_Rational_mg 41";
   1.795  
   1.796  "----- Schalk I, p.69 Nr. 460b nonterm.SK";
   1.797  val t = TermC.str2term "(9*(x \<up> 2 - 8*x + 16) / (4*(y \<up> 2 - 2*y + 1))) / ((3*x - 12) / (16*y - 16))";
   1.798 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.799 +(*val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.800  exception Div raised
   1.801  
   1.802  BUT
   1.803 @@ -1360,32 +1353,32 @@
   1.804  
   1.805  "----- some variant of the above; was non-terminating before";
   1.806  val t = TermC.str2term "9*(x \<up> 2 - 8*x+16)*(16*y - 16)/(4*(y \<up> 2 - 2*y+1)*(3*x - 12))";
   1.807 -val SOME (t , _) = rewrite_set_ thy false norm_Rational t;
   1.808 +val SOME (t , _) = rewrite_set_ ctxt false norm_Rational t;
   1.809  if UnparseC.term t = "(48 + - 12 * x) / (1 + - 1 * y)"
   1.810  then () else error "some variant of the above; was non-terminating before";
   1.811  
   1.812  "----- SRD Schalk I, p.70 Nr. 472a";
   1.813  val t = TermC.str2term ("((8*x \<up> 2 - 32*y \<up> 2) / (2*x + 4*y))  /  ((4*x - 8*y) / (x + y))");
   1.814 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.815 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.816  if UnparseC.term t = "x + y"
   1.817  then () else error "rational.sml: diff.behav. in norm_Rational_mg 43";
   1.818  
   1.819  "----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
   1.820  val t = TermC.str2term ("(a - (a*b + b \<up> 2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
   1.821  		 "((a - a \<up> 2/(a+b))/(a+(a*b)/(a - b)))");
   1.822 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.823 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.824  if UnparseC.term t = "(2 * a \<up> 3 + 2 * a \<up> 2 * b) / (a \<up> 2 * b + b \<up> 3)"
   1.825  then () else error "rational.sml: diff.behav. in norm_Rational_mg 51";
   1.826  
   1.827  (*SRD Schalk I, p.69 Nr. 461a *)
   1.828  val t = TermC.str2term "(2/(x+3) + 2/(x - 3)) / (8*x/(x \<up> 2 - 9))";
   1.829 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.830 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.831  if UnparseC.term t = "1 / 2"
   1.832  then () else error "rational.sml: diff.behav. in norm_Rational_mg 44";
   1.833  
   1.834  (*SRD Schalk I, p.69 Nr. 464b *)
   1.835  val t = TermC.str2term "(a - a/(a - 2)) / (a + a/(a - 2))";
   1.836 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.837 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.838  if UnparseC.term t = "(- 3 + a) / (- 1 + a)"
   1.839  then () else error "rational.sml: diff.behav. in norm_Rational_mg 45";
   1.840  
   1.841 @@ -1396,21 +1389,21 @@
   1.842      ("("(576 * x \<up> 2 + 1728 * (x * y) + 1296 * y \<up> 2 + - 2916 * z \<up> 2) /" ^
   1.843        "(576 * x \<up> 2 + 864 * (x * y) + 1296 * (x * z))"))
   1.844  
   1.845 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.846 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.847  if UnparseC.term t = "(4 * x + 6 * y + -9 * z) / (4 * x)"
   1.848  then () else error "rational.sml: diff.behav. in norm_Rational_mg 46";
   1.849  *)
   1.850  
   1.851  (*SRD Schalk I, p.69 Nr. 466b *)
   1.852  val t = TermC.str2term "((1 - 7*(x - 2)/(x \<up> 2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x \<up> 2 - 25))";
   1.853 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.854 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.855  if UnparseC.term t = "(25 + - 10 * x + x \<up> 2) / 18"
   1.856  then () else error "rational.sml: diff.behav. in norm_Rational_mg 47";
   1.857  
   1.858  (*SRD Schalk I, p.70 Nr. 469 *)
   1.859  val t = TermC.str2term ("3*b \<up> 2 / (4*a \<up> 2 - 8*a*b + 4*b \<up> 2) / " ^
   1.860    "(a / (a \<up> 2*b - b \<up> 3)  +  (a - b) / (4*a*b \<up> 2 + 4*b \<up> 3)  -  1 / (4*b \<up> 2))");
   1.861 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.862 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.863  if UnparseC.term t = "- 3 * b \<up> 3 / (- 2 * a + 2 * b)"
   1.864  then () else error "rational.sml: diff.behav. in norm_Rational_mg 48";
   1.865  
   1.866 @@ -1569,10 +1562,10 @@
   1.867  val tt = TermC.str2term "(1 * a + 1 * b) * (1 * a + - 1 * b)"(*numerator only*);
   1.868  
   1.869  "----- with rewrite_set_";
   1.870 -val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
   1.871 +val SOME (tt',asm) = rewrite_set_ ctxt false make_polynomial tt;
   1.872  if UnparseC.term tt'= "a \<up> 2 + - 1 * b \<up> 2" then () else error "rls chancel_p 1";
   1.873  val tt = TermC.str2term "((1 * a + - 1 * b) * (1 * a + - 1 * b))"(*denominator only*);
   1.874 -val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
   1.875 +val SOME (tt',asm) = rewrite_set_ ctxt false make_polynomial tt;
   1.876  if UnparseC.term tt' = "a \<up> 2 + - 2 * a * b + b \<up> 2" then () else error "rls chancel_p 2";
   1.877  
   1.878  "----- with Derive.do_one; WN1130912 not investigated further, will be discontinued";
   1.879 @@ -1582,7 +1575,7 @@
   1.880  
   1.881  "--- with simpler ruleset";
   1.882  val {rules, rew_ord= (_, ro), ...} = Rule_Set.rep (assoc_rls "rev_rew_p");
   1.883 -val der = Derive.do_one thy Atools_erls rules ro NONE tt;
   1.884 +val der = Derive.do_one ctxt Atools_erls rules ro NONE tt;
   1.885  if length der = 12 then () else error "WN1130912 rls chancel_p 4";
   1.886  (*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
   1.887  
   1.888 @@ -1591,12 +1584,12 @@
   1.889  (*default_print_depth 99;*) map (Rule.to_string o #2) der; (*default_print_depth 3;*)
   1.890  (*default_print_depth 99;*) map (UnparseC.term o #1 o #3) der; (*default_print_depth 3;*)
   1.891  
   1.892 -val der = Derive.do_one thy Atools_erls rules ro NONE 
   1.893 +val der = Derive.do_one ctxt Atools_erls rules ro NONE 
   1.894  	(TermC.str2term "(1 * a + 1 * b) * (1 * a + - 1 * b)");
   1.895  (*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
   1.896  
   1.897  val {rules, rew_ord=(_,ro),...} = Rule_Set.rep (assoc_rls "rev_rew_p");
   1.898 -val der = Derive.do_one thy Atools_erls rules ro NONE 
   1.899 +val der = Derive.do_one ctxt Atools_erls rules ro NONE 
   1.900  	(TermC.str2term "(1 * a + - 1 * b) * (1 * a + - 1 * b)");
   1.901  (*default_print_depth 99;*) writeln (Derive.deriv2str der); (*default_print_depth 3;*)
   1.902  (*default_print_depth 99;*) map (UnparseC.term o #1) der; (*default_print_depth 3;*)
   1.903 @@ -1651,17 +1644,17 @@
   1.904  
   1.905  (*1st factor separately simplified *)
   1.906  val t = TermC.str2term "((12*x*y / (9*x \<up> 2 - y \<up> 2))  /  (1 / (3*x - y) \<up> 2 - 1 / (3*x + y) \<up> 2))";
   1.907 -val SOME (t', _) = rewrite_set_ thy false norm_Rational t; 
   1.908 +val SOME (t', _) = rewrite_set_ ctxt false norm_Rational t; 
   1.909  if UnparseC.term t' = "(- 9 * x \<up> 2 + y \<up> 2) / - 1" then () else error "Nr. 480b lhs changed";
   1.910  (*2nd factor separately simplified *)
   1.911  val t = TermC.str2term "((1/(x - 5*y) \<up> 2  -  1/(x + 5*y) \<up> 2)  /  (20*x*y / (x \<up> 2 - 25*y \<up> 2)))";
   1.912 -val SOME (t',_) = rewrite_set_ thy false norm_Rational t; UnparseC.term t';
   1.913 +val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t; UnparseC.term t';
   1.914  if UnparseC.term t' = "- 1 / (- 1 * x \<up> 2 + 25 * y \<up> 2)" then () else error "Nr. 480b rhs changed";
   1.915  
   1.916  "-------- Schalk I, p.70 Nr. 477a: terms are exploding ?!?";
   1.917  val t = TermC.str2term ("b*y/(b - 2*y)/((b \<up> 2 - y \<up> 2)/(b+2*y))  /" ^
   1.918  		 "(b \<up> 2*y + b*y \<up> 2) * (a+x) \<up> 2  /  ((b \<up> 2 - 4*y \<up> 2) * (a+2*x) \<up> 2)");
   1.919 -(*val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
   1.920 +(*val SOME (t',_) = rewrite_set_ ctxt false norm_Rational t;
   1.921  :
   1.922  ###  rls: cancel_p on: (a \<up> 2 * (b * y) + 2 * (a * (b * (x * y))) + b * (x \<up> 2 * y)) /
   1.923  (b + - 2 * y) /
   1.924 @@ -1691,7 +1684,7 @@
   1.925    ("((a \<up> 2 - b \<up> 2)/(2*a*b) + 2*a*b/(a \<up> 2 - b \<up> 2))  /  ((a \<up> 2 + b \<up> 2)/(2*a*b) + 1)    / " ^
   1.926     "((a \<up> 2 + b \<up> 2) \<up> 2  /  (a + b) \<up> 2)");
   1.927  (* Rewrite.trace_on := true; (*true false*)
   1.928 -rewrite_set_ thy false norm_Rational t;
   1.929 +rewrite_set_ ctxt false norm_Rational t;
   1.930  :
   1.931  ####  rls: cancel_p on: (2 * (a \<up> 7 * b) + 4 * (a \<up> 6 * b \<up> 2) + 6 * (a \<up> 5 * b \<up> 3) +
   1.932   8 * (a \<up> 4 * b \<up> 4) +
   1.933 @@ -1714,7 +1707,7 @@
   1.934  val t = TermC.str2term ("(1/x + 1/y + 1/z)  /  (1/x - 1/y - 1/z)  /  " ^
   1.935    "(2*x \<up> 2 / (x \<up> 2 - z \<up> 2) / (x / (x + z)  +  x / (x - z)))");
   1.936  (* Rewrite.trace_on := true; (*true false*)
   1.937 -rewrite_set_ thy false norm_Rational t;
   1.938 +rewrite_set_ ctxt false norm_Rational t;
   1.939  :
   1.940  ####  rls: cancel_p on: (2 * (x \<up> 6 * (y \<up> 2 * z)) + 2 * (x \<up> 6 * (y * z \<up> 2)) +
   1.941   2 * (x \<up> 5 * (y \<up> 2 * z \<up> 2)) +
   1.942 @@ -1733,11 +1726,11 @@
   1.943  (* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt:
   1.944  
   1.945  val t = TermC.str2term "(a-b) \<up> 3 * (x+y) \<up> 4";
   1.946 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.947 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.948  UnparseC.term t;
   1.949  "a \<up> 3 * x \<up> 4 + 4 * a \<up> 3 * x \<up> 3 * y +6 * a \<up> 3 * x \<up> 2 * y \<up> 2 +4 * a \<up> 3 * x * y \<up> 3 +a \<up> 3 * y \<up> 4 +-3 * a \<up> 2 * b * x \<up> 4 +- 12 * a \<up> 2 * b * x \<up> 3 * y +- 18 * a \<up> 2 * b * x \<up> 2 * y \<up> 2 +- 12 * a \<up> 2 * b * x * y \<up> 3 +-3 * a \<up> 2 * b * y \<up> 4 +3 * a * b \<up> 2 * x \<up> 4 +12 * a * b \<up> 2 * x \<up> 3 * y +18 * a * b \<up> 2 * x \<up> 2 * y \<up> 2 +12 * a * b \<up> 2 * x * y \<up> 3 +3 * a * b \<up> 2 * y \<up> 4 +- 1 * b \<up> 3 * x \<up> 4 +-4 * b \<up> 3 * x \<up> 3 * y +-6 * b \<up> 3 * x \<up> 2 * y \<up> 2 +-4 * b \<up> 3 * x * y \<up> 3 +- 1 * b \<up> 3 * y \<up> 4";
   1.950  val t = TermC.str2term "((x+y) \<up> 2 * (a-b) \<up> 5)";
   1.951 -val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.952 +val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.953  UnparseC.term t;
   1.954  "a \<up> 5 * x \<up> 2 + 2 * a \<up> 5 * x * y + a \<up> 5 * y \<up> 2 +-5 * a \<up> 4 * b * x \<up> 2 +- 10 * a \<up> 4 * b * x * y +-5 * a \<up> 4 * b * y \<up> 2 +10 * a \<up> 3 * b \<up> 2 * x \<up> 2 +20 * a \<up> 3 * b \<up> 2 * x * y +10 * a \<up> 3 * b \<up> 2 * y \<up> 2 +- 10 * a \<up> 2 * b \<up> 3 * x \<up> 2 +- 20 * a \<up> 2 * b \<up> 3 * x * y +- 10 * a \<up> 2 * b \<up> 3 * y \<up> 2 +5 * a * b \<up> 4 * x \<up> 2 +10 * a * b \<up> 4 * x * y +5 * a * b \<up> 4 * y \<up> 2 +- 1 * b \<up> 5 * x \<up> 2 +- 2 * b \<up> 5 * x * y +- 1 * b \<up> 5 * y \<up> 2";
   1.955  
   1.956 @@ -1748,7 +1741,7 @@
   1.957  		 "(1/(3*x - y) \<up> 2 - 1/(3*x + y) \<up> 2)) *" ^
   1.958  		 "(1/(x - 5*y) \<up> 2 - 1/(x + 5*y) \<up> 2)/" ^
   1.959  		 "(20*x*y/(x \<up> 2 - 25*y \<up> 2))");
   1.960 -(*val SOME (t, _) = rewrite_set_ thy false norm_Rational t;
   1.961 +(*val SOME (t, _) = rewrite_set_ ctxt false norm_Rational t;
   1.962  :
   1.963  ####  rls: cancel_p on: (19440 * (x \<up> 8 * y \<up> 2) + -490320 * (x \<up> 6 * y \<up> 4) +
   1.964   108240 * (x \<up> 4 * y \<up> 6) +