1.1 --- a/test/Tools/isac/Knowledge/rational.sml Mon Sep 02 15:17:34 2013 +0200
1.2 +++ b/test/Tools/isac/Knowledge/rational.sml Mon Sep 02 16:16:08 2013 +0200
1.3 @@ -1,17 +1,6 @@
1.4 (* Title: tests for rationals
1.5 - Author: Stefan Karnel
1.6 - Copyright (c) Stefan Karnel 2002
1.7 + Author: Walther Neuper
1.8 Use is subject to license terms.
1.9 -
1.10 -12345678901234567890123456789012345678901234567890123456789012345678901234567890
1.11 - 10 20 30 40 50 60 70 80
1.12 -LEGEND
1.13 -WN120317.TODO postponed test/../ratinal,ratinal2.sml to joint work with dmeind
1.14 -WN070906
1.15 - nonterm.SK marks non-terminating examples
1.16 - ord.SK PARTIALLY marks crucial ordering examples
1.17 - *SK* of some (secondary) interest (on 070906)
1.18 -WN060104 transfer examples marked with (*SR..*) to the exp-collection
1.19 *)
1.20
1.21 "-----------------------------------------------------------------------------";
1.22 @@ -21,19 +10,19 @@
1.23 "-------- fun poly_of_term ---------------------------------------------------";
1.24 "-------- fun is_poly --------------------------------------------------------";
1.25 "-------- fun term_of_poly ---------------------------------------------------";
1.26 -"-------- fun factout_p_ -----------------------------------------------------";
1.27 -"-------- fun cancel_p_ ------------------------------------------------------";
1.28 -"-------- fun common_nominator_p_ --------------------------------------------";
1.29 -"-------- fun add_fraction_p_ ------------------------------------------------";
1.30 -"-------- TODO ---------------------------------------------------------------";
1.31 -"-------- and app_rev --------------------------------------------------------";
1.32 -"-------- external calculating functions test -----------";
1.33 -"-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
1.34 -"-------- common_nominator_p ----------------------------";
1.35 +"-------- integration lev.1 fun factout_p_ -----------------------------------";
1.36 +"-------- integration lev.1 fun cancel_p_ ------------------------------------";
1.37 +"-------- integration lev.1 fun common_nominator_p_ --------------------------";
1.38 +"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
1.39 +"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
1.40 +"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
1.41 +"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
1.42 +"-------- rewrite_set_ common_nominator_p from: Mathematik 1 Schalk ----------";
1.43 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
1.44 -"-------- reverse rewrite -------------------------------";
1.45 -"-------- 'reverse-ruleset' cancel_p --------------------";
1.46 -"-------- norm_Rational ---------------------------------";
1.47 +"-------- reverse rewrite ----------------------------------------------------";
1.48 +"-------- 'reverse-ruleset' cancel_p -----------------------------------------";
1.49 +"-------- investigate rls norm_Rational --------------------------------------";
1.50 +"-------- examples: rls norm_Rational ----------------------------------------";
1.51 "-------- numeral rationals -----------------------------";
1.52 "-------- cancellation ----------------------------------";
1.53 "-------- common denominator ----------------------------";
1.54 @@ -108,9 +97,9 @@
1.55 if term2str (term_of_poly baseT expT vs p) = "1 + 7 * y ^^^ 8 + 2 * x ^^^ 3 * y ^^^ 4 * z ^^^ 5"
1.56 then () else error "term_of_poly 1 changed";
1.57
1.58 -"-------- fun factout_p_ -----------------------------------------------------";
1.59 -"-------- fun factout_p_ -----------------------------------------------------";
1.60 -"-------- fun factout_p_ -----------------------------------------------------";
1.61 +"-------- integration lev.1 fun factout_p_ -----------------------------------";
1.62 +"-------- integration lev.1 fun factout_p_ -----------------------------------";
1.63 +"-------- integration lev.1 fun factout_p_ -----------------------------------";
1.64 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)"
1.65 val SOME (t', asm) = factout_p_ thy t;
1.66 if term2str t' = "(x + y) * (x + -1 * y) / (x * (x + -1 * y))"
1.67 @@ -128,9 +117,9 @@
1.68 terms2str asm = "[\"1 + x ~= 0\"]"
1.69 then () else error "factout_p_ 1 changed";
1.70
1.71 -"-------- fun cancel_p_ ------------------------------------------------------";
1.72 -"-------- fun cancel_p_ ------------------------------------------------------";
1.73 -"-------- fun cancel_p_ ------------------------------------------------------";
1.74 +"-------- integration lev.1 fun cancel_p_ ------------------------------------";
1.75 +"-------- integration lev.1 fun cancel_p_ ------------------------------------";
1.76 +"-------- integration lev.1 fun cancel_p_ ------------------------------------";
1.77 val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)"
1.78 val SOME (t', asm) = cancel_p_ thy t;
1.79 if (term2str t', terms2str asm) = ("(x + y) / x", "[\"x ~= 0\"]")
1.80 @@ -144,9 +133,9 @@
1.81 if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[]"
1.82 then () else error "cancel_p_ 1 changed";
1.83
1.84 -"-------- fun common_nominator_p_ --------------------------------------------";
1.85 -"-------- fun common_nominator_p_ --------------------------------------------";
1.86 -"-------- fun common_nominator_p_ --------------------------------------------";
1.87 +"-------- integration lev.1 fun common_nominator_p_ --------------------------";
1.88 +"-------- integration lev.1 fun common_nominator_p_ --------------------------";
1.89 +"-------- integration lev.1 fun common_nominator_p_ --------------------------";
1.90 val t = str2term ("y / (a*x + b*x + c*x) " ^
1.91 (* n1 d1 *)
1.92 "+ a / (x*y)");
1.93 @@ -181,13 +170,13 @@
1.94 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
1.95 val SOME (t', asm) = common_nominator_p_ thy t;
1.96 if term2str t' =
1.97 - "(x + -1) * (-1 + x) / (1 * ((1 + x) * (-1 + x))) +\n(x + 1) * (1 + x) / (1 * ((1 + x) * (-1 + x)))"
1.98 + "(x + -1) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(x + 1) * (1 + x) / ((1 + x) * (-1 + x))"
1.99 andalso terms2str asm = "[\"1 + x ~= 0\",\"-1 + x ~= 0\"]"
1.100 then () else error "common_nominator_p_ 3 changed";
1.101
1.102 -"-------- fun add_fraction_p_ ------------------------------------------------";
1.103 -"-------- fun add_fraction_p_ ------------------------------------------------";
1.104 -"-------- fun add_fraction_p_ ------------------------------------------------";
1.105 +"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
1.106 +"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
1.107 +"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
1.108 val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
1.109 val SOME (t', asm) = add_fraction_p_ thy t;
1.110 if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)"
1.111 @@ -205,15 +194,9 @@
1.112 terms2str asm = "[\"-1 + x ^^^ 2 ~= 0\"]"
1.113 then () else error "add_fraction_p_ 3 changed";
1.114
1.115 -"-------- TODO ---------------------------------------------------------------";
1.116 -"-------- TODO ---------------------------------------------------------------";
1.117 -"-------- TODO ---------------------------------------------------------------";
1.118 -
1.119 -
1.120 -
1.121 -"-------- and app_rev --------------------------------------------------------";
1.122 -"-------- and app_rev --------------------------------------------------------";
1.123 -"-------- and app_rev --------------------------------------------------------";
1.124 +"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
1.125 +"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
1.126 +"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
1.127 (* trace down until prepats are evaluated
1.128 (which does not to work, because substitution is not done -- compare rew_sub!);
1.129 keep this sequence for the case, factout_p, cancel_p, common_nominator_p, add_fraction_p
1.130 @@ -292,60 +275,64 @@
1.131 val SOME (Const ("HOL.False", _), []) = rewrite__set_ thy (i+1) false bdv rls a
1.132 ============ inhibit exn WN130823: prepat is empty ===================================*)
1.133
1.134 -(*========== inhibit exn WN130824 TODO =======================================================
1.135 -"-------- external calculating functions test -----------";
1.136 -"-------- external calculating functions test -----------";
1.137 -"-------- external calculating functions test -----------";
1.138 -val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
1.139 -val SOME (t', asm) = factout_p_ thy t;
1.140 -if term2str t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso terms2str asm = "[]"
1.141 -then () else error "factout_p_ 1 changed";
1.142 -val SOME (t', asm) = cancel_p_ thy t;
1.143 -if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[\"1 + x ~= 0\"]"
1.144 -then () else error "cancel_p_ 1 changed";
1.145 +"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
1.146 +"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
1.147 +"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
1.148 +val t = str2term "(12 * x * y) / (8 * y^^^2 )";
1.149 +(* "-------- example 187a": exception Div raised...
1.150 +val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
1.151 +val t = str2term "(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
1.152 +(* "-------- example 187b": doesn't terminate...
1.153 +val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
1.154 +val t = str2term "(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";
1.155 +(* "-------- example 187c": doesn't terminate...
1.156 +val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
1.157 +"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (@{theory Isac}, false, cancel_p, t);
1.158 +(* WN130827: exception Div raised...
1.159 +rewrite__set_ thy 1 bool [] rls term
1.160 +*)
1.161 +"~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
1.162 + (thy, 1, bool, [], rls, term);
1.163 +(* WN130827: exception Div raised...
1.164 + val (t', asm, rew) = app_rev thy (i+1) rrls t
1.165 +*)
1.166 +"~~~~~ fun app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
1.167 +(* WN130827: exception Div raised...
1.168 + val opt = app_rev' thy rrls t
1.169 +*)
1.170 +"~~~~~ fun app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
1.171 + (thy, rrls, t);
1.172 +chk_prepat thy erls prepat t = true;
1.173 +(* WN130827: exception Div raised...
1.174 +normal_form t
1.175 +*)
1.176 +(* lookup Rational.thy, cancel_p: normal_form = cancel_p_ thy*)
1.177 +"~~~~~ fun cancel_p_, args:"; val (t) = (t);
1.178 +val opt = check_fraction t;
1.179 +val SOME (numerator, denominator) = opt
1.180 + val vs = t |> vars |> map free2str |> sort string_ord
1.181 + val baseT = type_of numerator
1.182 + val expT = HOLogic.realT
1.183 +val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator);
1.184 +(*"-------- example 187a": exception Div raised...
1.185 +val a = [(12, [1, 1])]: poly
1.186 +val b = [(8, [0, 2])]: poly
1.187 + val ((a', b'), c) = gcd_poly a b
1.188 +*)
1.189 +(* "-------- example 187b": doesn't terminate...
1.190 +val a = [(8, [2, 1, 1])]: poly
1.191 +val b = [(18, [1, 2, 1])]: poly
1.192 + val ((a', b'), c) = gcd_poly a b
1.193 +*)
1.194 +(* "-------- example 187c": doesn't terminate...
1.195 +val a = [(9, [5, 2, 4])]: poly
1.196 +val b = [(15, [6, 3, 1])]: poly
1.197 + val ((a', b'), c) = gcd_poly a b
1.198 +*)
1.199
1.200 -val t = str2term "((-3 * x^^^2 + 6 *x - 3) / (2*x - 2))";
1.201 -val SOME (t', asm) = factout_(*p_*) thy t;
1.202 -if term2str t' = "(3 - 3 * x) * (-1 + x) / (2 * (-1 + x))" andalso terms2str asm = "[]"
1.203 -then () else error "factout_ 2 changed";
1.204 -val SOME (t', asm) = cancel_(*p_*) thy t;
1.205 -if term2str t' = "(3 - 3 * x) / 2" andalso terms2str asm = "[\"-1 + x ~= 0\"]"
1.206 -then () else error "cancel_ 2 changed";
1.207 -
1.208 -val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
1.209 -val SOME (t', asm) = add_fraction_p_ thy t;
1.210 -if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
1.211 -then () else error "add_fraction_p_ 3 changed";
1.212 -val SOME (t', asm) = common_nominator_p_ thy t;
1.213 -if term2str t' =
1.214 - "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
1.215 - andalso terms2str asm = "[]"
1.216 -then () else error "common_nominator_p_ 3 changed";
1.217 -
1.218 -val t = str2term "((x - 1) / (x + 1)) + ((x + 1) / (x - 1))";
1.219 -val SOME (t', asm) = add_fraction_ thy t;
1.220 -if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
1.221 -then () else error "factout_ 4 changed";
1.222 -val SOME (t', asm) = common_nominator_ thy t;
1.223 -if term2str t' =
1.224 - "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
1.225 - andalso terms2str asm = "[]"
1.226 -then () else error "cancel_ 4 changed";
1.227 -
1.228 -val t = str2term
1.229 - "((1) / (2*x + 2)) + ((1) / (2*x + (-2))) + ((1) / ( x^^^2 + (-1)))+((1) / (x^^^2 + (-2)*x + 1))";
1.230 -val SOME (t', asm) = add_fraction_p_ thy t;
1.231 -if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
1.232 -then () else error "add_fraction_p_ 5 changed";
1.233 -val SOME (t', asm) = norm_rational_ thy t;
1.234 -if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
1.235 -then () else error "norm_rational_ 5 changed";
1.236 -============ inhibit exn WN130826 TODO ========================================================*)
1.237 -
1.238 -
1.239 -"-------- cancel_p from: Mathematik 1 Schalk Reniets Verlag ------------------";
1.240 -"-------- cancel_p from: Mathematik 1 Schalk Reniets Verlag ------------------";
1.241 -"-------- cancel_p from: Mathematik 1 Schalk Reniets Verlag ------------------";
1.242 +"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
1.243 +"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
1.244 +"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
1.245 val thy = @{theory "Rational"};
1.246 "-------- WN";
1.247 val t = str2term "(2 + -3 * x) / 9";
1.248 @@ -512,554 +499,19 @@
1.249 if (term2str t', terms2str asm) = ("(2 * x + 10 * x ^^^ 2) / (1 + -5 * x)", "[]")
1.250 then () else error "rational.sml cancel WN 1";
1.251
1.252 -(*========== inhibit exn WN130826 TODO =========================================================
1.253 -"-------- some old tests REVISE ! --------------------------------------------";
1.254 -"-------- some old tests REVISE ! --------------------------------------------";
1.255 -"-------- some old tests REVISE ! --------------------------------------------";
1.256 -(*WAS --- external calculating functions test ---*)
1.257 -val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
1.258 -val SOME (t', asm) = factout_p_ thy t;
1.259 -if term2str t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso terms2str asm = "[]"
1.260 -then () else error "factout_p_ 1 changed";
1.261 -val SOME (t', asm) = cancel_p_ thy t;
1.262 -if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[\"1 + x ~= 0\"]"
1.263 -then () else error "cancel_p_ 1 changed";
1.264 +"-------- example heuberger";
1.265 +val t = str2term ("(x^^^4 + x * y + x^^^3 * y + y^^^2) / " ^
1.266 + "(x + 5 * x^^^2 + y + 5 * x * y + x^^^2 * y^^^3 + x * y^^^4)");
1.267 +val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
1.268 +if (term2str t', terms2str asm) =
1.269 + ("(x ^^^ 3 + y) / (1 + 5 * x + x * y ^^^ 3)", "[\"1 + 5 * x + x * y ^^^ 3 ~= 0\"]")
1.270 +then () else error "rational.sml cancel_p heuberger";
1.271
1.272 -val t = str2term "((-3 * x^^^2 + 6 *x - 3) / (2*x - 2))";
1.273 -val SOME (t', asm) = factout_(*p_*) thy t;
1.274 -if term2str t' = "(3 - 3 * x) * (-1 + x) / (2 * (-1 + x))" andalso terms2str asm = "[]"
1.275 -then () else error "factout_ 2 changed";
1.276 -val SOME (t', asm) = cancel_(*p_*) thy t;
1.277 -if term2str t' = "(3 - 3 * x) / 2" andalso terms2str asm = "[\"-1 + x ~= 0\"]"
1.278 -then () else error "cancel_ 2 changed";
1.279 +"-------- rewrite_set_ common_nominator_p from: Mathematik 1 Schalk ----------";
1.280 +"-------- rewrite_set_ common_nominator_p from: Mathematik 1 Schalk ----------";
1.281 +"-------- rewrite_set_ common_nominator_p from: Mathematik 1 Schalk ----------";
1.282 +(*deleted example 204 ... 236b at update Isabelle2012-->2013*)
1.283
1.284 -val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
1.285 -val SOME (t', asm) = add_fraction_p_ thy t;
1.286 -if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
1.287 -then () else error "add_fraction_p_ 3 changed";
1.288 -val SOME (t', asm) = common_nominator_p_ thy t;
1.289 -if term2str t' =
1.290 - "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
1.291 - andalso terms2str asm = "[]"
1.292 -then () else error "common_nominator_p_ 3 changed";
1.293 -
1.294 -val t = str2term "((x - 1) / (x + 1)) + ((x + 1) / (x - 1))";
1.295 -val SOME (t', asm) = add_fraction_ thy t;
1.296 -if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso terms2str asm = "[]"
1.297 -then () else error "factout_ 4 changed";
1.298 -val SOME (t', asm) = common_nominator_ thy t;
1.299 -if term2str t' =
1.300 - "(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))"
1.301 - andalso terms2str asm = "[]"
1.302 -then () else error "cancel_ 4 changed";
1.303 -
1.304 -val t = str2term
1.305 - "((1) / (2*x + 2)) + ((1) / (2*x + (-2))) + ((1) / ( x^^^2 + (-1)))+((1) / (x^^^2 + (-2)*x + 1))";
1.306 -val SOME (t', asm) = add_fraction_p_ thy t;
1.307 -if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
1.308 -then () else error "add_fraction_p_ 5 changed";
1.309 -val SOME (t', asm) = norm_rational_ thy t;
1.310 -if term2str t' = "x / (1 + -2 * x + x ^^^ 2)" andalso terms2str asm = "[\"1 + x ~= 0\"]"
1.311 -then () else error "norm_rational_ 5 changed";
1.312 -
1.313 -
1.314 -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))";
1.315 -val SOME (t3',_) = common_nominator_ thy t3;
1.316 -val SOME (t3'',_) = add_fraction_ thy t3;
1.317 -(term2str t3');
1.318 -(term2str t3'');
1.319 -
1.320 -val SOME(t4,t5) = norm_expanded_rat_ thy t3;
1.321 -term2str t4;
1.322 -term2str (hd(t5));
1.323 -
1.324 -
1.325 -
1.326 - val t=(term_of o the o (parse thy)) "(9 - x^^^2)/(9 - 6*x + x^^^2)";
1.327 - val SOME (t',_) = factout_ thy t;
1.328 - val SOME (t'',_) = cancel_ thy t;
1.329 - term2str t';
1.330 - term2str t'';
1.331 - "(3 + x) * (3 - x) / ((3 - x) * (3 - x))";
1.332 - "(3 + x) / (3 - x)";
1.333 -
1.334 - val t=(term_of o the o (parse thy))
1.335 - "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1 / (3 - x)";
1.336 - val SOME (t',_) = common_nominator_ thy t;
1.337 - val SOME (t'',_) = add_fraction_ thy t;
1.338 - term2str t';
1.339 - term2str t'';
1.340 - "(9 - x ^^^ 2) / ((3 - x) * (3 - x)) + 1 * (3 - x) / ((3 - x) * (3 - x))";
1.341 - "(4 + x) / (3 - x)";
1.342 -
1.343 -(*WN021016 added -----vv---*)
1.344 -val t = str2term "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1";
1.345 -val SOME (t',_) = common_nominator_ thy t;
1.346 -val SOME (t'',_) = add_fraction_ thy t;
1.347 -term2str t' = "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n1" ^
1.348 - " * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
1.349 -term2str t'' = "6 / (3 - x)" (*true*);
1.350 -
1.351 -val t = str2term "1 + (9 - x^^^2) / (9 - 6*x + x^^^2)";
1.352 -val SOME (t',_) = common_nominator_ thy t;
1.353 -val SOME (t'',_) = add_fraction_ thy t;
1.354 -term2str t' = "1 * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n" ^
1.355 - "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
1.356 -term2str t'' = "6 / (3 - x)" (*true*);
1.357 -(*WN021016 added -----^^---*)
1.358 -(*WN030602 added -----vv--- no rewrite -> NONE !*)
1.359 -val t = str2term "1 / a";
1.360 -val NONE = cancel_p_ thy t;
1.361 -val NONE = rewrite_set_ thy false cancel_p t;
1.362 -(*WN.2.6.03 added -------^^---*)
1.363 -
1.364 -val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2)";
1.365 -val SOME (t',_) = factout_ thy t;
1.366 -val SOME (t'',_) = cancel_ thy t;
1.367 -term2str t' = "(y + x) * (y - x) / ((y - x) * (y - x))"(*true*);
1.368 -term2str t'' = "(y + x) / (y - x)";
1.369 -
1.370 -val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2) + 1 / (y - x)";
1.371 -val SOME (t',_) = common_nominator_ thy t;
1.372 -val SOME (t'',_) = add_fraction_ thy t;
1.373 -term2str t' =
1.374 -"(-1 * x ^^^ 2 + y ^^^ 2) / ((-1 * x + y) * (-1 * x + y)) +\n1" ^
1.375 -" * (-1 * x + y) / ((-1 * x + y) * (-1 * x + y))" (*true*);
1.376 -term2str t'' = "(-1 - x - y) / (x - y)" (*true*);
1.377 -
1.378 -val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2) + 1 / (x - y)";
1.379 -val SOME (t',_) = common_nominator_ thy t;
1.380 -val SOME (t'',_) = add_fraction_ thy t;
1.381 -if term2str t' = "(-1 * y ^^^ 2 + x ^^^ 2) / ((-1 * y + x) * (-1 * y + x))" ^
1.382 -" +\n1 * (-1 * y + x) / ((-1 * y + x) * (-1 * y + x))" then ()
1.383 -else error "rational.sml lex-ord 1";
1.384 -if term2str t'' = "(-1 - y - x) / (y - x)" then ()
1.385 -else error "rational.sml lex-ord 2";
1.386 -(*WN.16.10.02 WN070905 lexicographische Ordnung erhalten *)
1.387 -
1.388 -
1.389 -val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2)";
1.390 -val SOME (t',_) = norm_expanded_rat_ thy t;
1.391 -if term2str t' = "(x + y) / (x - y)" then ()
1.392 -else error "rational.sml term2poly: invalid x ^^^ 2 - y ^^^ 2 No.1";
1.393 -(*val SOME (t'',_) = norm_rational_ thy t;
1.394 - *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial
1.395 -WN.16.10.02 ?! + WN060831???SK4
1.396 -WN070905 *** term2poly: invalid = x ^^^ 2 - y ^^^ 2*)
1.397 -
1.398 -
1.399 -val t = str2term "(9 - x^^^2)/(9 - 6*x + x^^^2) + (1)/(3 + x)";
1.400 -val SOME (t',_) = norm_expanded_rat_ thy t;
1.401 -if term2str t' = "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)" then ()
1.402 -else error "rational.sml (9 - x^^^2)/(9 - 6*x + x^^^2) +...";
1.403 -(*val SOME (t'',_) = norm_rational_ thy t;
1.404 - *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial WN.16.10.02 ?!
1.405 -WN070906 *** term2poly: invalid = 9 - x ^^^ 2 SK.term2poly*)
1.406 -
1.407 - val t=(term_of o the o (parse thy))
1.408 - "(9 + (-1)* x^^^2)/(9 + (-1)* 6*x + x^^^2) + (1)/(3 + x)";
1.409 - val SOME (t',_) = norm_expanded_rat_ thy t;
1.410 - val SOME (t'',_) = norm_rational_ thy t;
1.411 - term2str t';
1.412 - term2str t'';
1.413 - "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)";
1.414 - "(12 + 5 * x + x ^^^ 2) / (9 + (-1) * x ^^^ 2)";
1.415 -
1.416 -
1.417 -"-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
1.418 -"-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
1.419 -"-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
1.420 -val thy = @{theory "Rational"};
1.421 -val thy' = "Rational";
1.422 -val rls' = "cancel";
1.423 -val mp = "make_polynomial";
1.424 -
1.425 -writeln ("example 186:");
1.426 -writeln("a)");
1.427 -val e186a'="(14 * x * y) / ( x * y )";(*SRC*)
1.428 -rewrite_set_ thy false cancel (str2term e186a');
1.429 -"@@@@@@@@@@@@@@";
1.430 -val e186a = the (rewrite_set thy' false "cancel" e186a');
1.431 - is_expanded (parse_rat "14 * x * y");
1.432 - is_expanded (parse_rat "x * y");
1.433 -if e186a = ("14 / 1", "[\"y * x ~= 0\"]") then ()
1.434 -else error "rational.sml cancel Schalk e186a";
1.435 -
1.436 -writeln("b)");
1.437 -val e186b'="(60 * a * b) / ( 15 * a * b )";
1.438 -val e186b = the (rewrite_set thy' false "cancel" e186b');
1.439 -writeln("c)");
1.440 -val e186c'="(144 * a^^^2 * b * c) / (12 * a * b * c )";
1.441 -val e186c = (the (rewrite_set thy' false "cancel" e186c'))
1.442 - handle e => print_exn_G e;
1.443 -val t = (term_of o the o (parse thy)) e186c';
1.444 -if e186c = ("12 * a / 1", "[\"12 * (c * (b * a)) ~= 0\"]") then ()
1.445 -else error "rational.sml cancel Schalk e186c";
1.446 -
1.447 -writeln ("example 187:");
1.448 -writeln("a)");
1.449 -val e187a'="(12 * x * y) / (8 * y^^^2 )";(*SRC*)
1.450 -val e187a = the (rewrite_set thy' false "cancel" e187a');
1.451 -writeln("b)");
1.452 -val e187b'="(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
1.453 -val e187b = the (rewrite_set thy' false "cancel" e187b');
1.454 -writeln("c)");
1.455 -val e187d'="(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";(*SRC*)
1.456 -val e187d = the (rewrite_set thy' false "cancel" e187d');
1.457 -if e187d = ("3 * z ^^^ 3 / (5 * (y * x))",
1.458 - "[\"3 * (z * (y ^^^ 2 * x ^^^ 5)) ~= 0\"]") then ()
1.459 -else error "rational.sml cancel Schalk e186d";
1.460 -
1.461 -writeln "example 188:";
1.462 -val e188a'="(-8 + 8 * x) / (-9 + 9 * x)";(*SRC*)
1.463 -val e188a = the (rewrite_set thy' false "cancel" e188a');
1.464 - is_expanded (parse_rat "8 * x + -8");
1.465 -(* e188a = ("8 / 9",["not ((-1) + x = 0)"]) then () 13.3.03*)
1.466 -if e188a = ("8 / 9", "[\"-1 + x ~= 0\"]") then ()
1.467 -else error "rational.sml: e188a new behaviour";
1.468 -
1.469 -val SOME (t,_) = rewrite_set thy' false mp "(8*((-1) + x))/(9*((-1) + x))";
1.470 -writeln("b)");
1.471 -val e188b'="(-15 + 5 * x) / (-18 + 6 * x)";(*SRC*)
1.472 -val SOME (t, asm) = rewrite_set thy' false "cancel" e188b';
1.473 -t = "5 / 6" (*true*);
1.474 -writeln("c)");
1.475 -
1.476 -val e188c'="( a + -1 * b ) / ( b + -1 * a )";
1.477 -val e188c = the (rewrite_set thy' false "cancel_p" e188c');
1.478 -(*is_expanded (parse_rat "a + -1 * b");*)
1.479 -val SOME (t,_) =
1.480 - rewrite_set thy' false mp "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
1.481 -if t= "(a + -1 * b) / (-1 * a + b)" then()
1.482 -else error "rational.sml: e188c new behaviour";
1.483 -
1.484 -writeln ("example 190:");
1.485 -writeln("c)");
1.486 -val e190c'="( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )";
1.487 -val e190c = the (rewrite_set thy' false "cancel" e190c');
1.488 -val SOME (t,_) = rewrite_set thy' false mp "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
1.489 -if t = "(1 + 3 * a + 9 * a ^^^ 2 + 27 * a ^^^ 3) /\n(3 * a + 18 * a ^^^ 2 + 27 * a ^^^ 3)" then ()
1.490 -else error "rational.sml: e190c new behaviour";
1.491 -
1.492 -writeln ("example 191:");
1.493 -writeln("a)");
1.494 -val e191a'="( x^^^2 + -1 * y^^^2 ) / ( x + y )";
1.495 -(*WN.23.10.02-------
1.496 -val e191a = the (rewrite_set thy' false "cancel" e191a');
1.497 - is_expanded (parse_rat "x^^^2 + -1 * y^^^2");
1.498 - false;
1.499 - is_expanded (parse_rat "x + y");
1.500 - true; -----------*)
1.501 -val SOME (t,_) = rewrite_set thy' false mp "((x + (-1) * y)*(x + y))/((1)*(x + y))";
1.502 -(* t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then() WN.13.3.03*)
1.503 -if t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then()
1.504 -else error "rational.sml: e191a new behaviour";
1.505 -
1.506 -writeln("c)");
1.507 -val e191c'="( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )";
1.508 -(*WN.23.10.02-------
1.509 -val e191c = the (rewrite_set thy' false "cancel" e191c');
1.510 - is_expanded (parse_rat "9 * x^^^2 + -30 * x + 25");
1.511 - false;
1.512 - is_expanded (parse_rat "25 + -30*x + 9*x^^^2");
1.513 - false;
1.514 - is_expanded (parse_rat "-25 + 9*x^^^2");
1.515 - true;------------*)
1.516 -val SOME (t,_) = rewrite_set thy' false mp "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
1.517 -(* t="(25 + ((-30) * x + 9 * x ^^^ 2)) / ((-25) + 9 * x ^^^ 2)"then() 13.3.03*)
1.518 -if t= "(25 + -30 * x + 9 * x ^^^ 2) / (-25 + 9 * x ^^^ 2)" then()
1.519 -else error "rational.sml: 'e191c' new behaviour";
1.520 -
1.521 -
1.522 -writeln ("example 192:");
1.523 -writeln("b)");
1.524 -val e192b'="( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 * y^^^3 )";
1.525 -(*WN.23.10.02-------
1.526 -val e192b = the (rewrite_set thy' false "cancel" e192b');
1.527 --------------------*)
1.528 -val SOME (t',_) = rewrite_set thy' false mp "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
1.529 -(*========== inhibit exn 110317 ================================================
1.530 -if t' = "(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)"
1.531 -(*"(-1 * y * x ^^^ 2 + 7 * x ^^^ 3) / (-1 * y ^^^ 3 + 7 * x * y ^^^ 2)"WN050929*)
1.532 -then () else error "rational.sml: 'e192b' new behaviour";
1.533 -(*^^^ works with MG's simplifier vvv*)
1.534 -val t =str2term"((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
1.535 -val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
1.536 -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";
1.537 -============ inhibit exn 110317 ==============================================*)
1.538 -
1.539 -writeln ("example 193:");
1.540 -writeln("a)");
1.541 -val e193a'="( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )";
1.542 -(*WN.23.10.02-------
1.543 -val e193a = the (rewrite_set thy' false "cancel" e193a');
1.544 --------------------*)
1.545 -writeln("b)");
1.546 -val e193b'="( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )";
1.547 -(*WN.23.10.02-------
1.548 -val e193b = the (rewrite_set thy' false "cancel" e193b');
1.549 -writeln("c)");
1.550 -val e193c'="( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )";
1.551 -val SOME(t,_) = rewrite_set thy' false "cancel" e193c';
1.552 --------------------*)
1.553 -
1.554 -val wn01 = "(-25 + 9*x^^^2)/(5 + 3*x)";
1.555 -val SOME (t, asm) = rewrite_set thy' false "cancel" wn01;
1.556 -(* t = "((-5) + 3 * x) / 1" then () WN.13.3.03*)
1.557 -if t = "(-5 + 3 * x) / 1" andalso asm = "[\"5 + 3 * x ~= 0\"]" then ()
1.558 -else error "rational.sml: new behav. in cancel wn01";
1.559 -
1.560 -"-------- common_nominator_p ----------------------------";
1.561 -"-------- common_nominator_p ----------------------------";
1.562 -"-------- common_nominator_p ----------------------------";
1.563 -val rls' = "common_nominator_p";
1.564 -
1.565 -writeln ("example 204:");
1.566 -writeln("a)");
1.567 -val e204a'="((5 * x) / 9) + ((3 * x) / 9) + (x / 9)";
1.568 -val e204a = the (rewrite_set thy' false "common_nominator_p" e204a');
1.569 -writeln("b)");
1.570 -val e204b'="5 / x + -3 / x + -1 / x";
1.571 -val e204b = the (rewrite_set thy' false "common_nominator_p" e204b');
1.572 -if e204b = ("1 / x", "[]") then ()
1.573 -else error "rational.sml common_nominator_p example e204b";
1.574 -
1.575 -writeln ("example 205:");
1.576 -writeln("a)");
1.577 -val e205a'="((4 * x + 7) / 8) + ((4 * x + 3) / 8)";
1.578 -val e205a = the (rewrite_set thy' false "common_nominator_p" e205a');
1.579 -writeln("b)");
1.580 -val e205b'="((5 * x + 2) / 3) + ((-2 * x + 1) / 3)";
1.581 -val e205b = the (rewrite_set thy' false "common_nominator_p" e205b');
1.582 -if e205b = ("(1 + x) / 1", "[]") then ()
1.583 -else error "rational.sml common_nominator_p example e204b";
1.584 -
1.585 -writeln ("example 206:");
1.586 -writeln("a)");
1.587 -val e206a'="((5 * x + 4) / (2 * x + -1)) + ((9 * x + 5) / (2 * x + -1))";
1.588 -val e206a = the (rewrite_set thy' false "common_nominator_p" e206a');
1.589 -writeln("b)");
1.590 -val e206b'="((17 * x + -23) / (5 * x + 4)) + ((-25 + -17 * x) / (5 * x + 4))";
1.591 -val e206b = the (rewrite_set thy' false "common_nominator_p" e206b');
1.592 -
1.593 -writeln ("example 207:");
1.594 -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)) ";
1.595 -val e207 = the (rewrite_set thy' false "common_nominator_p" e207');
1.596 -
1.597 -writeln ("example 208:");
1.598 -val e208'="((3 * x + 2) / (x + 2)) + ((5 * x + -1) / (x + 2)) + ((-7 * x + -3) / (x + 2)) + ((-1 * x + -3) / (x + 2)) ";
1.599 -val e208 = the (rewrite_set thy' false "common_nominator_p" e208');
1.600 -
1.601 -writeln ("example 209:");
1.602 -val e209'="((3 * x + -7 * y + 3 * z) / (4)) + ((2 * x + 17 * y + 10 * z) / (4)) + ((-1 * x + 2 * y + z) / (4)) ";
1.603 -val e209 = the (rewrite_set thy' false "common_nominator_p" e209');
1.604 -
1.605 -writeln ("example 210:");
1.606 -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)) ";
1.607 -val e210 = the (rewrite_set thy' false "common_nominator_p" e210');
1.608 -
1.609 -writeln ("example 211:");
1.610 -writeln("a)");
1.611 -val e211a'="((b) / (a + -1 * b)) + ((-1 * a) / (a + -1 * b))";
1.612 -val e211a = the (rewrite_set thy' false "common_nominator_p" e211a');
1.613 -writeln("b)");
1.614 -val e211b'="((b) / (b^^^2 + -1 * a^^^2)) + ((-1 * a) / (b^^^2 + -1 * a^^^2))";
1.615 -val e211b = the (rewrite_set thy' false "common_nominator_p" e211b');
1.616 -
1.617 -writeln ("example 212:");
1.618 -writeln("a)");
1.619 -val e212a'="((4) / (x)) + ((-3) / (y)) + -1";
1.620 -val e212a = the (rewrite_set thy' false "common_nominator_p" e212a');
1.621 -writeln("b)");
1.622 -val e212b'="((4) / (x)) + ((-5) / (y)) + ((6) / (x*y))";
1.623 -val e212b = the (rewrite_set thy' false "common_nominator_p" e212b');
1.624 -
1.625 -writeln ("example 213:");
1.626 -writeln("a)");
1.627 -val e213a'="((5 * x) / (3 * y^^^2)) + ((19 * z) / (6 * x * y)) + ((-2 * x) / (3 * y^^^2)) + ((7 * y^^^2) / (6 * x^^^2)) ";
1.628 -val e213a = the (rewrite_set thy' false "common_nominator_p" e213a');
1.629 -writeln("b)");
1.630 -val e213b'="((2 * b) / (3 * a^^^2)) + ((3 * c) / (7 * a * b)) + ((4 * b) / (3 * a^^^2)) + ((3 * a) / (7 * b^^^2))";
1.631 -val e213b = the (rewrite_set thy' false "common_nominator_p" e213b');
1.632 -
1.633 -writeln ("example 214:");
1.634 -writeln("a)");
1.635 -val e214a'="((3 * x + 2 * y + 2 * z) / (4)) + ((-5 * x + -3 * y) / (3)) + ((x + y + -2 * z) / (2))";
1.636 -val e214a = the (rewrite_set thy' false "common_nominator_p" e214a');
1.637 -writeln("b)");
1.638 -val e214b'="((5 * x + 2 * y + z) / (2)) + ((-7 * x + -3 * y) / (3)) + ((3 * x + 6 * y + -1 * z) / (12))";
1.639 -val e214b = the (rewrite_set thy' false "common_nominator_p" e214b');
1.640 -
1.641 -writeln ("example 216:");
1.642 -writeln("a)");
1.643 -val e216a'="((2 * b + 3 * c) / (a * c)) + ((3 * a + b) / (a * b)) + ((-2 * b^^^2 + -3 * a * c) / (a * b * c))";
1.644 -val e216a = the (rewrite_set thy' false "common_nominator_p" e216a');
1.645 -writeln("b)");
1.646 -val e216b'="((2 * a + 3 * b) / (b * c)) + ((3 * c + a) / (a * c)) + ((-2 * a^^^2 + -3 * b * c) / (a * b * c))";
1.647 -val e216b = the (rewrite_set thy' false "common_nominator_p" e216b');
1.648 -
1.649 -writeln ("example 217:");
1.650 -val e217'="((z + -1) / (z)) + ((3 * z ^^^2 + -6 * z + 5) / (z^^^2)) + ((-4 * z^^^3 + 7 * z^^^2 + -5 * z + 5) / (z^^^3))";
1.651 -val e217 = the (rewrite_set thy' false "common_nominator_p" e217');
1.652 -
1.653 -
1.654 -val rls' = "common_nominator";
1.655 -writeln ("example 218:");
1.656 -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))";
1.657 -val e218 = the (rewrite_set thy' false "common_nominator" e218');
1.658 -if e218 = ("(16 - 63 * a ^^^ 2 - 81 * a ^^^ 3) / (108 * a ^^^ 4)", "[]") then ()
1.659 -else error "rationa.sml common_nominator example e218";
1.660 -
1.661 -writeln ("example 219:");
1.662 -writeln("a)");
1.663 -val e219a'="((1) / (y + 1)) + ((1) / (y + 2)) + ((1) / (y + 3))";
1.664 -val e219a = the (rewrite_set thy' false "common_nominator" e219a');
1.665 -writeln("b)");
1.666 -val e219b'="((1) / (x + 1)) + ((1) / (x + 2)) + ((-2) / (x + 3))";
1.667 -val e219b = the (rewrite_set thy' false "common_nominator" e219b');
1.668 -if e219b = ("(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)", "[]") then ()
1.669 -else error "rationa.sml common_nominator example e219b";
1.670 -
1.671 -writeln ("example 220:");
1.672 -writeln("a)");
1.673 -val e220a'="((17) / (5 * r + -2)) + ((-13) / (2 * r + 3)) + ((4) / (3 * r + -5))";
1.674 -val e220a = the (rewrite_set thy' false "common_nominator" e220a');
1.675 -writeln("b)");
1.676 -val e220b'="((20 * a) / (a + -3)) + ((-19 * a) / (a + -4)) + ((a) / (a + -5))";
1.677 -val e220b = the (rewrite_set thy' false "common_nominator" e220b');
1.678 -
1.679 -writeln ("example 221:");
1.680 -writeln("a)");
1.681 -val e221a'="((a + b) / (a + -1 * b)) + ((a + -1 * b) / (a + b))";
1.682 -val e221a = the (rewrite_set thy' false "common_nominator" e221a');
1.683 -writeln("b)");
1.684 -val e221b'="((x + -1 * y) / (x + y)) + ((x + y) / (x + -1 * y)) ";
1.685 -val e221b = the (rewrite_set thy' false "common_nominator" e221b');
1.686 -
1.687 -writeln ("example 222:");
1.688 -writeln("a)");
1.689 -val e222a'="((1 + -1 * x) / (1 + x)) + ((-1 + -1 * x) / (1 + -1 * x)) + ((4 * x) / (1 + -1 * x^^^2))";
1.690 -val e222a = the (rewrite_set thy' false "common_nominator" e222a');
1.691 -writeln("b)");
1.692 -val e222b'="((1 + x ) / (1 + -1 * x)) + ((-1 + x) / (1 + x)) + ((2 * x) / (1 + -1 * x^^^2))";
1.693 -val e222b = the (rewrite_set thy' false "common_nominator" e222b');
1.694 -
1.695 -writeln ("example 225:");
1.696 -writeln("a)");
1.697 -val e225a'="((6 * a) / (a^^^2 + -64)) + ((a + 2) / (2 * a + 16)) + ((-1) / (2))";
1.698 -val e225a = the (rewrite_set thy' false "common_nominator" e225a');
1.699 -writeln("b)");
1.700 -val e225b'="((a + 2 ) / (2 * a + 12)) + ((4 * a) / (a^^^2 + -36)) + ((-1) / (2))";
1.701 -val e225b = the (rewrite_set thy' false "common_nominator" e225b');
1.702 -
1.703 -writeln ("example 226:");
1.704 -writeln("a)");
1.705 -val e226a'="((35 * z) / (49 * z^^^2 + -4)) + -1 + ((14 * z + -1) / (14 * z + 4)) ";
1.706 -val e226a = the (rewrite_set thy' false "common_nominator" e226a');
1.707 -writeln("b)");
1.708 -val e226b'="((45 * a * b) / (25 * a^^^2 + -9 * b^^^2)) + ((20 * a + 3 * b) / (10 * a + 6 * b)) + -2";
1.709 -val e226b = the (rewrite_set thy' false "common_nominator" e226b');
1.710 -
1.711 -writeln ("example 227:");
1.712 -writeln("a)");
1.713 -val e227a'="((6 * z + 11) / (6 * z + 14)) + ((9 * z ) / (9 * z^^^2 + -49)) + -1 ";
1.714 -val e227a = the (rewrite_set thy' false "common_nominator" e227a');
1.715 -writeln("b)");
1.716 -val e227b'="((16 * a + 37 * b) / (4 * a + 10 * b)) + ((6 * a * b) / (4 * a^^^2 + -25 * b^^^2)) + -4 ";
1.717 -val e227b = the (rewrite_set thy' false "common_nominator" e227b');
1.718 -
1.719 -writeln ("example 228:");
1.720 -writeln("a)");
1.721 -val e228a'="((7 * a + 11) / (3 * a^^^2 + -3)) + ((-2 * a + -1) / (a^^^2 + -1 * a)) + ((-1) / (3 * a + 3))";
1.722 -val e228a = the (rewrite_set thy' false "common_nominator" e228a');
1.723 -writeln("b)");
1.724 -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))";
1.725 -val e228b = the (rewrite_set thy' false "common_nominator" e228b');
1.726 -
1.727 -
1.728 -writeln ("example 229:");
1.729 -writeln("a)");
1.730 -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))";
1.731 -val e229a = the (rewrite_set thy' false "common_nominator" e229a');
1.732 -writeln("b)");
1.733 -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))";
1.734 -val e229b = the (rewrite_set thy' false "common_nominator" e229b');
1.735 -
1.736 -writeln ("example 230:");
1.737 -writeln("a)");
1.738 -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))";
1.739 -val e230a = the (rewrite_set thy' false "common_nominator" e230a');
1.740 -writeln("b)");
1.741 -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))";
1.742 -val e230b = the (rewrite_set thy' false "common_nominator" e230b');
1.743 -
1.744 -writeln ("example 231:");
1.745 -writeln("a)");
1.746 -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))";
1.747 -val e231a = the (rewrite_set thy' false "common_nominator" e231a');
1.748 -writeln("b)");
1.749 -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))";
1.750 -val e231b = the (rewrite_set thy' false "common_nominator" e231b');
1.751 -
1.752 -writeln ("example 232:");
1.753 -writeln("a)");
1.754 -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))";
1.755 -val e232a = the (rewrite_set thy' false "common_nominator" e232a');
1.756 -writeln("b)");
1.757 -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))";
1.758 -val e232b = the (rewrite_set thy' false "common_nominator" e232b');
1.759 -
1.760 -writeln ("example 233:");
1.761 -writeln("a)");
1.762 -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))";
1.763 -val e233a = the (rewrite_set thy' false "common_nominator" e233a');
1.764 -writeln("b)");
1.765 -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))";
1.766 -val e233b = the (rewrite_set thy' false "common_nominator" e233b');
1.767 -
1.768 -writeln ("example 234:");
1.769 -writeln("a)");
1.770 -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))";
1.771 -val e234a = the (rewrite_set thy' false "common_nominator" e234a');
1.772 -writeln("b)");
1.773 -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)) ";
1.774 -val e234b = the (rewrite_set thy' false "common_nominator" e234b');
1.775 -
1.776 -writeln ("example 235:");
1.777 -writeln("a)");
1.778 -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))";
1.779 -val e235a = the (rewrite_set thy' false "common_nominator" e235a');
1.780 -writeln("b)");
1.781 -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)) ";
1.782 -val e235b = the (rewrite_set thy' false "common_nominator" e235b');
1.783 -
1.784 -writeln ("example 236:");
1.785 -writeln("a)");
1.786 -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))";
1.787 -val e236a = the (rewrite_set thy' false "common_nominator" e236a');
1.788 -writeln("b)");
1.789 -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)) ";
1.790 -val e236b = the (rewrite_set thy' false "common_nominator" e236b');
1.791 -
1.792 -
1.793 -val rls' = "cancel";
1.794 -writeln ("example heuberger:");
1.795 -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)";
1.796 -val eheu = the (rewrite_set thy' false "cancel" eheu');
1.797 -
1.798 -val rls' = "common_nominator_p";
1.799 -writeln ("example stiefel:");
1.800 -val est1'="(7) / (-14) + (-2) / (4)";
1.801 -val est1 = the (rewrite_set thy' false "common_nominator_p" est1');
1.802 -if est1 = ("-1 / 1", "[]") then ()
1.803 -else error "new behaviour in rational.sml: est1'";
1.804 -
1.805 -val t = (term_of o the o (parse thy))
1.806 -"(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1.807 -val SOME (t',_) = factout_ thy t;
1.808 -if term2str t' = "(3 + x) * (3 - x) / ((3 - x) * (3 - x))" then ()
1.809 -else error "rational.sml factout_ (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1.810 -
1.811 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
1.812 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
1.813 "-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
1.814 @@ -1124,46 +576,75 @@
1.815 if term2str t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)"
1.816 then () else error "level 5, rewrite_set_ norm_Rational: changed"
1.817
1.818 -"-------- reverse rewrite -------------------------------";
1.819 -"-------- reverse rewrite -------------------------------";
1.820 -"-------- reverse rewrite -------------------------------";
1.821 -(*WN.28.8.02: tests for the 'reverse-rewrite' functions:
1.822 - these are defined in Rationals.ML and stored in
1.823 - the 'reverse-ruleset' cancel*)
1.824 +"-------- reverse rewrite ----------------------------------------------------";
1.825 +"-------- reverse rewrite ----------------------------------------------------";
1.826 +"-------- reverse rewrite ----------------------------------------------------";
1.827 +(** the term for which reverse rewriting is demonstrated **)
1.828 +val t = str2term "(9 + -1 * x ^^^ 2) / (9 + 6 * x + x ^^^ 2)";
1.829 +val Rrls {scr = Rfuns {init_state = ini, locate_rule = loc,
1.830 + next_rule = nex, normal_form = nor, ...},...} = cancel_p;
1.831
1.832 -(*the term for which reverse rewriting is demonstrated*)
1.833 - val t = (term_of o the o (parse thy))
1.834 - "(9 - x ^^^ 2) / (9 + 6 * x + x ^^^ 2)";
1.835 - val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
1.836 - next_rule=nex,normal_form=nor,...},...} = cancel;
1.837 -
1.838 -(*normal_form produces the result in ONE step*)
1.839 +(** normal_form produces the result in ONE step **)
1.840 val SOME (t',_) = nor t;
1.841 -if term2str t' = "(3 - x) / (3 + x)" then ()
1.842 +if term2str t' = "(3 + -1 * x) / (3 + x)" then ()
1.843 else error "rational.sml normal_form (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1.844
1.845 -(*initialize the interpreter state used by the 'me'*)
1.846 - val (t,_,revsets,_) = ini t;
1.847 +(** initialize the interpreter state used by the 'me' **)
1.848 + val (t, _, revsets, _) = ini t;
1.849
1.850 -(*find the rule 'r' to apply to term 't'*)
1.851 +if length (hd revsets) = 11 then () else error "length of revset changed";
1.852 +if (revsets |> nth 1 |> nth 1 |> id_of_thm) =
1.853 + (@{thm realpow_twoI} |> string_of_thm |> thmID_of_derivation_name)
1.854 +then () else error "first element of revset changed";
1.855 +if
1.856 +(revsets |> nth 1 |> nth 1 |> rule2str) = "Thm (\"realpow_twoI\",??.unknown)" andalso
1.857 +(revsets |> nth 1 |> nth 2 |> rule2str) =
1.858 + "Thm (\"sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))\",??.unknown)" andalso
1.859 +(revsets |> nth 1 |> nth 3 |> rule2str) =
1.860 + "Thm (\"sym_#mult_Float ((2,0), (0,0)) __ ((3,0), (0,0))\",??.unknown)" andalso
1.861 +(revsets |> nth 1 |> nth 4 |> rule2str) =
1.862 + "Thm (\"sym_#mult_Float ((~1,0), (0,0)) __ ((3,0), (0,0))\",??.unknown)" andalso
1.863 +(revsets |> nth 1 |> nth 5 |> rule2str) =
1.864 + "Thm (\"sym_#mult_Float ((3,0), (0,0)) __ ((3,0), (0,0))\",??.unknown)" andalso
1.865 +(revsets |> nth 1 |> nth 6 |> rule2str) = "Rls_ (\"sym_order_mult_rls_\")" andalso
1.866 +(revsets |> nth 1 |> nth 7 |> rule2str) =
1.867 + "Thm (\"sym_mult_assoc\",Groups.semigroup_mult_class.mult_assoc)"
1.868 +then () else error "first 7 elements in revset changed"
1.869 +
1.870 +(** find the rule 'r' to apply to term 't' **)
1.871 +(*/------- since cancel_ (accepted "-" between monomials) has been replaced by cancel_p_
1.872 + for Isabelle2013, we don't get a working revset, but non-termination:
1.873 +
1.874 val SOME (r as (Thm (str, thm))) = nex revsets t;
1.875 + :
1.876 +((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x),
1.877 + Rls_ ("sym_order_mult_rls_"), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x), []))","
1.878 +((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x),
1.879 + Thm ("sym_mult_assoc",""), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x), []))","
1.880 +((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x),
1.881 + Thm ("sym_mult_assoc",""), ((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), []))","
1.882 +((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), Rls_ ("sym_order_mult_rls_"), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x), []))","
1.883 + :
1.884 +### Isabelle2002:
1.885 + Thm ("sym_#mult_2_3", "6 = 2 * 3")
1.886 +### Isabelle2009-2 for cancel_ (not cancel_p_):
1.887 if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))"
1.888 andalso string_of_thm thm =
1.889 (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
1.890 (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
1.891 else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1.892 -(* before Isa02->09-2 was not checked automatically, ?was different?:
1.893 -val SOME r = nex revsets t;
1.894 -val r = Thm ("sym_#mult_2_3","6 = 2 * 3") : rule*)
1.895 +\---------------------------------------------------------------------------------------/*)
1.896
1.897 -(* check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
1.898 +(** check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
1.899 if the rule is OK, the term resulting from applying the rule is returned,too;
1.900 there might be several rule applications inbetween,
1.901 - which are listed after the head in reverse order *)
1.902 + which are listed after the head in reverse order **)
1.903 +(*/-------------------------------------------- Isabelle2013: this gives "error id_of_thm";
1.904 + we don't repair this, because interaction within "reverse rewriting" never worked properly:
1.905 +
1.906 val (r, (t, asm))::_ = loc revsets t r;
1.907 if term2str t = "(9 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" andalso asm = []
1.908 -then ()
1.909 -else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1.910 +then () else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
1.911
1.912 (* find the next rule to apply *)
1.913 val SOME (r as (Thm (str, thm))) = nex revsets t;
1.914 @@ -1198,11 +679,13 @@
1.915 val ss = term2str t;
1.916 if ss = "(3 - x) / (3 + x)" andalso terms2str asm = "[\"3 + x ~= 0\"]" then ()
1.917 else error "rational.sml: new behav. in rev-set cancel";
1.918 +\--------------------------------------------------------------------------------------/*)
1.919
1.920 -"-------- 'reverse-ruleset' cancel_p --------------------";
1.921 -"-------- 'reverse-ruleset' cancel_p --------------------";
1.922 -"-------- 'reverse-ruleset' cancel_p --------------------";
1.923 -(*WN.11.9.02: the 'reverse-ruleset' cancel_p*)
1.924 +"-------- 'reverse-ruleset' cancel_p -----------------------------------------";
1.925 +"-------- 'reverse-ruleset' cancel_p -----------------------------------------";
1.926 +"-------- 'reverse-ruleset' cancel_p -----------------------------------------";
1.927 +(*Isabelle2013: the example below shows, why "reverse rewriting" only worked for
1.928 + special cases.*)
1.929
1.930 (*the term for which reverse rewriting is demonstrated*)
1.931 val t = str2term "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))";
1.932 @@ -1237,16 +720,12 @@
1.933 val SOME r = nex revsets t;
1.934 val (r,(t,asm))::_ = loc revsets t r;
1.935 term2str t;
1.936 -*)
1.937 +*)
1.938
1.939 -writeln "****************** all tests successfull *************************";
1.940 -
1.941 -
1.942 -
1.943 -(*WN.17.3.03 =========================================================vvv---*)
1.944 -"-------- norm_Rational ---------------------------------";
1.945 -"-------- norm_Rational ---------------------------------";
1.946 -"-------- norm_Rational ---------------------------------";
1.947 +(*========== inhibit exn WN130824 TODO =======================================================
1.948 +"-------- examples: rls norm_Rational ----------------------------------------";
1.949 +"-------- examples: rls norm_Rational ----------------------------------------";
1.950 +"-------- examples: rls norm_Rational ----------------------------------------";
1.951 val t = str2term "(3*x+5)/18 - x/2 - -(3*x - 2)/9 = 0";
1.952 val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
1.953 if term2str t' = "1 / 18 = 0" then () else error "rational.sml 1";
1.954 @@ -2415,7 +1894,7 @@
1.955 SK060904-2a non-termination of add_fraction_p_";
1.956 val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + " ^
1.957 " (-1 * a + b * x) / (a + b * x) ");
1.958 -(* nonterm.SK
1.959 +(* nonterm.SK = WN130830
1.960 val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
1.961 "--- 11 ---";
1.962 common_nominator_p_ thy t;
1.963 @@ -2432,11 +1911,11 @@
1.964 " errors in cancel_p: --- 4,5,6,7.";
1.965 " error in common_nominator_p, common_nominator_p_: --- 10; 1,2?.";
1.966 " errors caused by ruleset norm_Rational: --- 8,9.";
1.967 -trace_rewrite := true;
1.968 +trace_rewrite := false;
1.969
1.970 -"--- 1 ---: non-terminating with ### add_fract: done t22 ";
1.971 +"--- 1 ---: non-terminating with ### add_fract: done t22 "; = WN130830
1.972 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)";
1.973 -trace_rewrite:= true;
1.974 +trace_rewrite := false;
1.975 rewrite_set_ thy false common_nominator_p t;
1.976
1.977 "--- 2 ---: non-terminating with ### add_fract: done t22 ";