test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 02 Sep 2013 16:16:08 +0200
changeset 52101 c3f399ce32af
parent 52100 0831a4a6ec8a
child 52104 83166e7c7e52
permissions -rw-r--r--
Test_Isac works again, almost ..

4 files raise errors:
# Interpret/solve.sml: "solve.sml: interSteps on norm_Rational 2"
# Interpret/inform.sml: "inform.sml: [rational,simplification] 2"
# Knowledge/partial_fractions.sml: "autoCalculate for met_partial_fraction changed: final result"
# Knowledge/eqsystem.sml: "eqsystem.sml: exp 7.70 normalize 4x4 by rewrite changed"

The chunk of changes is due to the fact, that Isac's code still is unstable.
The changes are accumulated since e8f46493af82.
neuper@38041
     1
(* Title: tests for rationals
neuper@52101
     2
   Author: Walther Neuper
neuper@37906
     3
   Use is subject to license terms.
neuper@42395
     4
*)
neuper@37906
     5
neuper@52092
     6
"-----------------------------------------------------------------------------";
neuper@52092
     7
"-----------------------------------------------------------------------------";
neuper@52092
     8
"table of contents -----------------------------------------------------------";
neuper@52092
     9
"-----------------------------------------------------------------------------";
neuper@52087
    10
"-------- fun poly_of_term ---------------------------------------------------";
neuper@52087
    11
"-------- fun is_poly --------------------------------------------------------";
neuper@52087
    12
"-------- fun term_of_poly ---------------------------------------------------";
neuper@52101
    13
"-------- integration lev.1 fun factout_p_ -----------------------------------";
neuper@52101
    14
"-------- integration lev.1 fun cancel_p_ ------------------------------------";
neuper@52101
    15
"-------- integration lev.1 fun common_nominator_p_ --------------------------";
neuper@52101
    16
"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
neuper@52101
    17
"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
neuper@52101
    18
"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
neuper@52101
    19
"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
neuper@52101
    20
"-------- rewrite_set_ common_nominator_p from: Mathematik 1 Schalk ----------";
neuper@52100
    21
"-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
neuper@52101
    22
"-------- reverse rewrite ----------------------------------------------------";
neuper@52101
    23
"-------- 'reverse-ruleset' cancel_p -----------------------------------------";
neuper@52101
    24
"-------- investigate rls norm_Rational --------------------------------------";
neuper@52101
    25
"-------- examples: rls norm_Rational ----------------------------------------";
neuper@38041
    26
"-------- numeral rationals -----------------------------";
neuper@38041
    27
"-------- cancellation ----------------------------------";
neuper@38041
    28
"-------- common denominator ----------------------------";
neuper@38041
    29
"-------- multiply and cancel ---------------------------";
neuper@38041
    30
"-------- common denominator and multiplication ---------";
neuper@38041
    31
"-------- double fractions ------------------------------";
neuper@38041
    32
"-------- crucial examples ------------------------------";
neuper@38041
    33
"-------- examples for Stefan Karnels thesis ------------";
neuper@38041
    34
"-------- me Schalk I No.186 ----------------------------";
neuper@38041
    35
"-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
neuper@38041
    36
"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
neuper@38041
    37
"-------- investigate rulesets for cancel_p -------------";
neuper@38041
    38
"-------- investigate format of factout_ and factout_p_ -";
neuper@38041
    39
"-------- how to stepwise construct Scripts -------------";
neuper@42301
    40
"----------- get_denominator ----------------------------";
neuper@42449
    41
"--------- several errpats in complicated term -------------------";
neuper@38041
    42
"--------------------------------------------------------";
neuper@48788
    43
"-------- nonterminating cancel_p, norm_Rational 2002 ---";
neuper@38041
    44
"--------------------------------------------------------";
neuper@38041
    45
"--------------------------------------------------------";
neuper@37906
    46
neuper@37906
    47
neuper@52087
    48
"-------- fun poly_of_term ---------------------------------------------------";
neuper@52087
    49
"-------- fun poly_of_term ---------------------------------------------------";
neuper@52087
    50
"-------- fun poly_of_term ---------------------------------------------------";
neuper@52087
    51
val vs = "12 * x^^^3 * y^^^4 * z^^^6" |> str2term |> vars |> map free2str |> sort string_ord;
neuper@52087
    52
neuper@52087
    53
if poly_of_term vs (str2term "12::real") = SOME [(12, [0, 0, 0])]
neuper@52087
    54
then () else error "poly_of_term 1 changed";
neuper@52087
    55
if poly_of_term vs (str2term "x::real") = SOME [(1, [1, 0, 0])]
neuper@52087
    56
then () else error "poly_of_term 2 changed";
neuper@52087
    57
if poly_of_term vs (str2term "12 * x^^^3") = SOME [(12, [3, 0, 0])]
neuper@52087
    58
then () else error "poly_of_term 3 changed";
neuper@52087
    59
if poly_of_term vs (str2term "12 * x^^^3 * y^^^4 * z^^^6") = SOME [(12, [3, 4, 6])]
neuper@52087
    60
then () else error "poly_of_term 4 changed";
neuper@52087
    61
if poly_of_term vs (str2term "1 + 2 * x^^^3 * y^^^4 * z^^^6 + y") =
neuper@52087
    62
  SOME [(1, [0, 0, 0]), (1, [0, 1, 0]), (2, [3, 4, 6])]
neuper@52087
    63
then () else error "poly_of_term 5 changed";
neuper@52087
    64
neuper@52087
    65
(*poly_of_term is quite liberal:*)
neuper@52087
    66
(*the coefficient may be somewhere, the order of variables and the parentheses 
neuper@52087
    67
  within a monomial are arbitrary*)
neuper@52087
    68
if poly_of_term vs (str2term "y^^^4 * (x^^^3 * 12 * z^^^6)") = SOME [(12, [3, 4, 6])]
neuper@52087
    69
then () else error "poly_of_term 6 changed";
neuper@52087
    70
neuper@52087
    71
(*there may even be more than 1 coefficient:*)
neuper@52087
    72
if poly_of_term vs (str2term "2 * y^^^4 * (x^^^3 * 6 * z^^^6)") = SOME [(12, [3, 4, 6])]
neuper@52087
    73
then () else error "poly_of_term 7 changed";
neuper@52087
    74
neuper@52087
    75
(*the order and the parentheses within monomials are arbitrary:*)
neuper@52087
    76
if poly_of_term vs (str2term "2 * x^^^3 * y^^^4 * z^^^6 + (7 * y^^^8 + 1)")
neuper@52087
    77
  = SOME [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 6])]
neuper@52087
    78
then () else error "poly_of_term 8 changed";
neuper@52087
    79
neuper@52087
    80
"-------- fun is_poly --------------------------------------------------------";
neuper@52087
    81
"-------- fun is_poly --------------------------------------------------------";
neuper@52087
    82
"-------- fun is_poly --------------------------------------------------------";
neuper@52087
    83
if is_poly (str2term "2 * x^^^3 * y^^^4 * z^^^6 + 7 * y^^^8 + 1")
neuper@52087
    84
then () else error "is_poly 1 changed";
neuper@52087
    85
if not (is_poly (str2term "2 * (x^^^3 * y^^^4 * z^^^6 + 7) * y^^^8 + 1"))
neuper@52087
    86
then () else error "is_poly 2 changed";
neuper@52087
    87
neuper@52087
    88
"-------- fun term_of_poly ---------------------------------------------------";
neuper@52087
    89
"-------- fun term_of_poly ---------------------------------------------------";
neuper@52087
    90
"-------- fun term_of_poly ---------------------------------------------------";
neuper@52087
    91
val expT = HOLogic.realT
neuper@52087
    92
val Free (_, baseT) = (hd o vars o str2term) "12 * x^^^3 * y^^^4 * z^^^6";
neuper@52087
    93
val p = [(1, [0, 0, 0]), (7, [0, 8, 0]), (2, [3, 4, 5])]
neuper@52087
    94
val vs = ["x","y","z"]
neuper@52087
    95
(*precondition for [(c, es),...]: legth es = length vs*)
neuper@52087
    96
;
neuper@52087
    97
if term2str (term_of_poly baseT expT vs p) = "1 + 7 * y ^^^ 8 + 2 * x ^^^ 3 * y ^^^ 4 * z ^^^ 5"
neuper@52087
    98
then () else error "term_of_poly 1 changed";
neuper@52087
    99
neuper@52101
   100
"-------- integration lev.1 fun factout_p_ -----------------------------------";
neuper@52101
   101
"-------- integration lev.1 fun factout_p_ -----------------------------------";
neuper@52101
   102
"-------- integration lev.1 fun factout_p_ -----------------------------------";
neuper@52092
   103
val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)"
neuper@52092
   104
val SOME (t', asm) = factout_p_ thy t;
neuper@52092
   105
if term2str t' = "(x + y) * (x + -1 * y) / (x * (x + -1 * y))"
neuper@52092
   106
then () else error ("factout_p_ term 1 changed: " ^ term2str t')
neuper@52092
   107
;
neuper@52093
   108
if terms2str asm = "[\"x ~= 0\",\"x + -1 * y ~= 0\"]"
neuper@52092
   109
then () else error "factout_p_ asm 1 changed"
neuper@52092
   110
;
neuper@52092
   111
val t = str2term "nothing + to_cancel ::real";
neuper@52092
   112
if NONE = factout_p_ thy t then () else error "factout_p_ doesn't report non-applicable";
neuper@52093
   113
;
neuper@52093
   114
val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
neuper@52093
   115
val SOME (t', asm) = factout_p_ thy t;
neuper@52093
   116
if term2str t' = "(3 + 3 * x) * (1 + x) / (2 * (1 + x))" andalso 
neuper@52094
   117
  terms2str asm = "[\"1 + x ~= 0\"]"
neuper@52093
   118
then () else error "factout_p_ 1 changed";
neuper@52093
   119
neuper@52101
   120
"-------- integration lev.1 fun cancel_p_ ------------------------------------";
neuper@52101
   121
"-------- integration lev.1 fun cancel_p_ ------------------------------------";
neuper@52101
   122
"-------- integration lev.1 fun cancel_p_ ------------------------------------";
neuper@52093
   123
val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)"
neuper@52093
   124
val SOME (t', asm) = cancel_p_ thy t;
neuper@52094
   125
if (term2str t', terms2str asm) = ("(x + y) / x", "[\"x ~= 0\"]")
neuper@52093
   126
then () else error ("cancel_p_ (t', asm) 1 changed: " ^ term2str t')
neuper@52093
   127
;
neuper@52093
   128
val t = str2term "nothing + to_cancel ::real";
neuper@52093
   129
if NONE = cancel_p_ thy t then () else error "cancel_p_ doesn't report non-applicable";
neuper@52093
   130
;
neuper@52093
   131
val t = str2term "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
neuper@52093
   132
val SOME (t', asm) = cancel_p_ thy t;
neuper@52094
   133
if term2str t' = "(3 + 3 * x) / 2" andalso terms2str asm = "[]"
neuper@52093
   134
then () else error "cancel_p_ 1 changed";
neuper@52092
   135
neuper@52101
   136
"-------- integration lev.1 fun common_nominator_p_ --------------------------";
neuper@52101
   137
"-------- integration lev.1 fun common_nominator_p_ --------------------------";
neuper@52101
   138
"-------- integration lev.1 fun common_nominator_p_ --------------------------";
neuper@52092
   139
val t = str2term ("y / (a*x + b*x + c*x) " ^
neuper@52092
   140
              (* n1    d1                   *)
neuper@52092
   141
                "+ a / (x*y)");
neuper@52092
   142
              (* n2    d2                   *)
neuper@52092
   143
val SOME (t', asm) = common_nominator_p_ thy t;
neuper@52092
   144
if term2str t' =
neuper@52092
   145
      ("y * y / (x * ((a + b + c) * y)) " ^
neuper@52092
   146
  (*  n1  *d2'/ (c'* ( d1'        *d2')) *)
neuper@52092
   147
     "+ a * (a + b + c) / (x * ((a + b + c) * y))")
neuper@52092
   148
   (*  n2 * d1'         / (c'* ( d1'        *d2')) *)
neuper@52092
   149
then () else error "common_nominator_p_ term 1 changed";
neuper@52093
   150
if terms2str asm = "[\"a + b + c ~= 0\",\"y ~= 0\",\"x ~= 0\"]"
neuper@52092
   151
then () else error "common_nominator_p_ asm 1 changed"
neuper@52092
   152
neuper@52092
   153
"-------- example in mail Nipkow";
neuper@52092
   154
val t = str2term "x/(x^^^2 + -1*y^^^2) + y/(x^^^2 + -1*x*y)";
neuper@52092
   155
val SOME (t', asm) = common_nominator_p_ thy t;
neuper@52092
   156
if term2str t' = "x * x / " ^ 
neuper@52092
   157
                 "((x + -1 * y) * ((x + y) * x))" ^
neuper@52092
   158
            " +\n" ^ 
neuper@52092
   159
                 "y * (x + y) / " ^ 
neuper@52092
   160
                 "((x + -1 * y) * ((x + y) * x))"
neuper@52092
   161
then () else error "common_nominator_p_ term 2 changed"
neuper@52092
   162
;
neuper@52093
   163
if terms2str asm = "[\"x + y ~= 0\",\"x ~= 0\",\"x + -1 * y ~= 0\"]"
neuper@52092
   164
then () else error "common_nominator_p_ asm 2 changed"
neuper@52092
   165
neuper@52092
   166
"-------- example: applicable tested by SML code";
neuper@52092
   167
val t = str2term "nothing / to_add";
neuper@52092
   168
if NONE = common_nominator_p_ thy t then () else error "common_nominator_p_ term 3 changed";
neuper@52093
   169
;
neuper@52093
   170
val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
neuper@52093
   171
val SOME (t', asm) = common_nominator_p_ thy t;
neuper@52093
   172
if term2str t' = 
neuper@52101
   173
   "(x + -1) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(x + 1) * (1 + x) / ((1 + x) * (-1 + x))"
neuper@52094
   174
  andalso terms2str asm = "[\"1 + x ~= 0\",\"-1 + x ~= 0\"]"
neuper@52093
   175
then () else error "common_nominator_p_ 3 changed";
neuper@52092
   176
neuper@52101
   177
"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
neuper@52101
   178
"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
neuper@52101
   179
"-------- integration lev.1 fun add_fraction_p_ ------------------------------";
neuper@52092
   180
val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
neuper@52092
   181
val SOME (t', asm) = add_fraction_p_ thy t;
neuper@52092
   182
if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" 
neuper@52092
   183
then () else error "add_fraction_p_ 3 changed";
neuper@52093
   184
;
neuper@52093
   185
if terms2str asm = "[\"-1 + x ^^^ 2 ~= 0\"]"
neuper@52092
   186
then () else error "add_fraction_p_ 3 changed";
neuper@52093
   187
;
neuper@52093
   188
val t = str2term "nothing / to_add";
neuper@52093
   189
if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ term 3 changed";
neuper@52093
   190
;
neuper@52093
   191
val t = str2term "((x + (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
neuper@52093
   192
val SOME (t', asm) = add_fraction_p_ thy t;
neuper@52093
   193
if term2str t' = "(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)" andalso
neuper@52093
   194
  terms2str asm = "[\"-1 + x ^^^ 2 ~= 0\"]"
neuper@52093
   195
then () else error "add_fraction_p_ 3 changed";
neuper@52092
   196
neuper@52101
   197
"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
neuper@52101
   198
"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
neuper@52101
   199
"-------- and app_rev ...traced down from rewrite_set_ until prepats ---------";
neuper@52085
   200
(* trace down until prepats are evaluated 
neuper@52085
   201
  (which does not to work, because substitution is not done -- compare rew_sub!);
neuper@52085
   202
  keep this sequence for the case, factout_p, cancel_p, common_nominator_p, add_fraction_p
neuper@52085
   203
  (again) get prepat = [] changed to <>[]. *)
neuper@52085
   204
val t = str2term "(x^^^2 + -1*y^^^2) / (x^^^2 + -1*x*y)";
neuper@52085
   205
neuper@52085
   206
(*rewrite_set_ @{theory Isac} true cancel t = NONE; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
neuper@52085
   207
"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (thy, false, cancel_p, t);
neuper@52085
   208
"~~~~~ fun rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
neuper@52085
   209
  (thy, 1, bool, [], rls, term);
neuper@52085
   210
(*val (t', asm, rew) = app_rev thy (i+1) rrls t; rew = false!!!!!!!!!!!!!!!!!!!!!*)
neuper@52092
   211
"~~~~~ and app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
neuper@52085
   212
    fun chk_prepat thy erls [] t = true
neuper@52085
   213
      | chk_prepat thy erls prepat t =
neuper@52085
   214
        let
neuper@52085
   215
          fun chk (pres, pat) =
neuper@52085
   216
            (let 
neuper@52085
   217
              val subst: Type.tyenv * Envir.tenv =
neuper@52085
   218
                Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
neuper@52085
   219
             in
neuper@52085
   220
              snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
neuper@52085
   221
             end) handle _ => false
neuper@52085
   222
           fun scan_ f [] = false (*scan_ NEVER called by []*)
neuper@52085
   223
             | scan_ f (pp::pps) =
neuper@52085
   224
               if f pp then true else scan_ f pps;
neuper@52085
   225
        in scan_ chk prepat end;
neuper@52085
   226
    (* apply the normal_form of a rev-set *)
neuper@52085
   227
    fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
neuper@52085
   228
      if chk_prepat thy erls prepat t
neuper@52085
   229
      then ((*tracing("### app_rev': t = "^(term2str t));*) normal_form t)
neuper@52085
   230
      else NONE;
neuper@52085
   231
(*  val opt = app_rev' thy rrls t  ..NONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
neuper@52085
   232
"~~~~~ and app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
neuper@52085
   233
  (thy, rrls, t);
neuper@52085
   234
(* chk_prepat thy erls prepat t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
neuper@52085
   235
(* app_sub thy i rrls t = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
neuper@52085
   236
"~~~~~ fun chk_prepat, args:"; val (thy, erls, prepat, t) = (thy, erls, prepat, t);
neuper@52085
   237
          fun chk (pres, pat) =
neuper@52085
   238
            (let 
neuper@52085
   239
              val subst: Type.tyenv * Envir.tenv =
neuper@52085
   240
                Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
neuper@52085
   241
             in
neuper@52085
   242
              snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
neuper@52085
   243
             end) handle _ => false
neuper@52085
   244
           fun scan_ f [] = false (*scan_ NEVER called by []*)
neuper@52085
   245
             | scan_ f (pp::pps) =
neuper@52085
   246
               if f pp then true else scan_ f pps;
neuper@52085
   247
neuper@52088
   248
(*========== inhibit exn WN130823: prepat is empty ====================================
neuper@52085
   249
(* scan_ chk prepat = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
neuper@52085
   250
"~~~~~ fun , args:"; val (f, (pp::pps)) = (chk, prepat);
neuper@52085
   251
f;
neuper@52085
   252
val ([t1, t2], t) = pp;
neuper@52085
   253
term2str t1 = "?r is_expanded";
neuper@52085
   254
term2str t2 = "?s is_expanded";
neuper@52085
   255
term2str t = "?r / ?s";
neuper@52085
   256
(* f pp = false!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
neuper@52085
   257
"~~~~~ fun chk, args:"; val (pres, pat) = (pp);
neuper@52085
   258
              val subst: Type.tyenv * Envir.tenv =
neuper@52085
   259
                Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty)
neuper@52085
   260
(*subst = 
neuper@52085
   261
  ({}, {(("r", 0), ("real", Var (("r", 0), "real"))), 
neuper@52085
   262
        (("s", 0), ("real", Var (("s", 0), "real")))}*)
neuper@52085
   263
;
neuper@52085
   264
              snd (eval__true thy (i + 1) (map (Envir.subst_term subst) pres) [] erls)
neuper@52085
   265
"~~~~~ fun eval__true, args:"; val (thy, i, asms, bdv, rls) =
neuper@52085
   266
  (thy, (i + 1), (map (Envir.subst_term subst) pres), [], erls);
neuper@52085
   267
terms2str asms;                         (* = "[\"?r is_expanded\",\"?s is_expanded\"]"*)
neuper@52085
   268
asms = [@{term True}] orelse asms = []; (* = false*)
neuper@52085
   269
asms = [@{term False}]                ; (* = false*)
neuper@52085
   270
"~~~~~ fun chk, args:"; val (indets, (a::asms)) = ([], asms);
neuper@52085
   271
bdv (*= []: _a list*);
neuper@52085
   272
val bdv : (term * term) list = [];
neuper@52085
   273
rewrite__set_ thy (i+1) false;
neuper@52085
   274
term2str a = "?r is_expanded"; (*hier m"usste doch der Numerator eingesetzt sein ??????????????*)
neuper@52085
   275
val SOME (Const ("HOL.False", _), []) = rewrite__set_ thy (i+1) false bdv rls a
neuper@52088
   276
============ inhibit exn WN130823: prepat is empty ===================================*)
neuper@37906
   277
neuper@52101
   278
"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
neuper@52101
   279
"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
neuper@52101
   280
"-------- fun rewrite_set_ cancel_p downto fun gcd_poly ----------------------";
neuper@52101
   281
val t = str2term "(12 * x * y) / (8 * y^^^2 )";
neuper@52101
   282
(* "-------- example 187a": exception Div raised...
neuper@52101
   283
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
neuper@52101
   284
val t = str2term "(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
neuper@52101
   285
(* "-------- example 187b": doesn't terminate...
neuper@52101
   286
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
neuper@52101
   287
val t = str2term "(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";
neuper@52101
   288
(* "-------- example 187c": doesn't terminate...
neuper@52101
   289
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;*)
neuper@52101
   290
"~~~~~ fun rewrite_set_, args:"; val (thy, bool, rls, term) = (@{theory Isac}, false, cancel_p, t);
neuper@52101
   291
(* WN130827: exception Div raised...
neuper@52101
   292
rewrite__set_ thy 1 bool [] rls term
neuper@52101
   293
*)
neuper@52101
   294
"~~~~~ and rewrite__set_, args:"; val (thy, i, _, _, (rrls as Rrls _), t) =
neuper@52101
   295
  (thy, 1, bool, [], rls, term);
neuper@52101
   296
(* WN130827: exception Div raised...
neuper@52101
   297
	val (t', asm, rew) = app_rev thy (i+1) rrls t
neuper@52101
   298
*)
neuper@52101
   299
"~~~~~ fun app_rev, args:"; val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
neuper@52101
   300
(* WN130827: exception Div raised...
neuper@52101
   301
    val opt = app_rev' thy rrls t
neuper@52101
   302
*)
neuper@52101
   303
"~~~~~ fun app_rev', args:"; val (thy, (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}), t) =
neuper@52101
   304
  (thy, rrls, t);
neuper@52101
   305
chk_prepat thy erls prepat t    = true;
neuper@52101
   306
(* WN130827: exception Div raised...
neuper@52101
   307
normal_form t
neuper@52101
   308
*)
neuper@52101
   309
(* lookup Rational.thy, cancel_p: normal_form = cancel_p_ thy*)
neuper@52101
   310
"~~~~~ fun cancel_p_, args:"; val (t) = (t);
neuper@52101
   311
val opt = check_fraction t;
neuper@52101
   312
val SOME (numerator, denominator) = opt
neuper@52101
   313
        val vs = t |> vars |> map free2str |> sort string_ord
neuper@52101
   314
        val baseT = type_of numerator
neuper@52101
   315
        val expT = HOLogic.realT
neuper@52101
   316
val (SOME a, SOME b) = (poly_of_term vs numerator, poly_of_term vs denominator);
neuper@52101
   317
(*"-------- example 187a": exception Div raised...
neuper@52101
   318
val a = [(12, [1, 1])]: poly
neuper@52101
   319
val b = [(8, [0, 2])]: poly
neuper@52101
   320
              val ((a', b'), c) = gcd_poly a b
neuper@52101
   321
*)
neuper@52101
   322
(* "-------- example 187b": doesn't terminate...
neuper@52101
   323
val a = [(8, [2, 1, 1])]: poly
neuper@52101
   324
val b = [(18, [1, 2, 1])]: poly
neuper@52101
   325
              val ((a', b'), c) = gcd_poly a b
neuper@52101
   326
*)
neuper@52101
   327
(* "-------- example 187c": doesn't terminate...
neuper@52101
   328
val a = [(9, [5, 2, 4])]: poly
neuper@52101
   329
val b = [(15, [6, 3, 1])]: poly
neuper@52101
   330
              val ((a', b'), c) = gcd_poly a b
neuper@52101
   331
*)
neuper@37906
   332
neuper@52101
   333
"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
neuper@52101
   334
"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
neuper@52101
   335
"-------- rewrite_set_ cancel_p from: Mathematik 1 Schalk Reniets Verlag -----";
neuper@52092
   336
val thy  = @{theory "Rational"};
neuper@52096
   337
"-------- WN";
neuper@52096
   338
val t = str2term "(2 + -3 * x) / 9";
neuper@52096
   339
if NONE = rewrite_set_ thy false cancel_p t then ()
neuper@52096
   340
else error "rewrite_set_ cancel_p must return NONE, if the term cannot be cancelled";
neuper@52096
   341
neuper@52092
   342
"-------- example 186a";
neuper@52092
   343
val t = str2term "(14 * x * y) / (x * y)";
neuper@52092
   344
  is_expanded (str2term "14 * x * y");
neuper@52092
   345
  is_expanded (str2term "x * y");
neuper@52095
   346
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52095
   347
if (term2str t', terms2str asm) = ("14 / 1", "[]")
neuper@52092
   348
then () else error "rational.sml cancel Schalk 186a";
neuper@52092
   349
neuper@52092
   350
"-------- example 186b";
neuper@52092
   351
val t = str2term "(60 * a * b) / ( 15 * a  * b )";
neuper@52095
   352
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52095
   353
if (term2str t', terms2str asm) = ("4 / 1", "[]")
neuper@52092
   354
then () else error "rational.sml cancel Schalk 186b";
neuper@52092
   355
neuper@52092
   356
"-------- example 186c";
neuper@52092
   357
val t = str2term "(144 * a^^^2 * b * c) / (12 * a * b * c)";
neuper@52095
   358
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52095
   359
if (term2str t', terms2str asm) = ("12 * a / 1", "[]")
neuper@52092
   360
then () else error "rational.sml cancel Schalk 186c";
neuper@52092
   361
neuper@52095
   362
(* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! exception Div raised !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
neuper@52095
   363
  see --- fun rewrite_set_ downto fun gcd_poly ---
neuper@52092
   364
"-------- example 187a";
neuper@52092
   365
val t = str2term "(12 * x * y) / (8 * y^^^2 )";
neuper@52095
   366
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52092
   367
if (term2str t', terms2str asm) = ("3 * x / (2 * y)", "[\"4 * y ~= 0\"]")
neuper@52092
   368
then () else error "rational.sml cancel Schalk 187a";
neuper@52095
   369
*)
neuper@52092
   370
neuper@52095
   371
(* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
neuper@52095
   372
  see --- fun rewrite_set_ downto fun gcd_poly ---
neuper@52092
   373
"-------- example 187b";
neuper@52092
   374
val t = str2term "(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
neuper@52095
   375
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52092
   376
if (term2str t', terms2str asm) = ("4 * x / (9 * y)", "[\"2 * (z * (y * x)) ~= 0\"]")
neuper@52092
   377
then () else error "rational.sml cancel Schalk 187b";
neuper@52095
   378
*)
neuper@52092
   379
neuper@52095
   380
(* doesn't terminate !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
neuper@52095
   381
  see --- fun rewrite_set_ downto fun gcd_poly ---
neuper@52092
   382
"-------- example 187c";
neuper@52092
   383
val t = str2term "(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";
neuper@52095
   384
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52092
   385
if (term2str t', terms2str asm) = 
neuper@52092
   386
  ("3 * z ^^^ 3 / (5 * (y * x))", "[\"3 * (z * (y ^^^ 2 * x ^^^ 5)) ~= 0\"]") 
neuper@52092
   387
then () else error "rational.sml cancel Schalk 187c";
neuper@52095
   388
*)
neuper@52092
   389
neuper@52092
   390
"-------- example 188a";
neuper@52092
   391
val t = str2term "(-8 + 8 * x) / (-9 + 9 * x)";
neuper@52092
   392
  is_expanded (str2term "8 * x + -8");
neuper@52095
   393
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52095
   394
if (term2str t', terms2str asm) = ("8 / 9", "[]")
neuper@52092
   395
then () else error "rational.sml cancel Schalk 188a";
neuper@52092
   396
neuper@52092
   397
val t = str2term "(8*((-1) + x))/(9*((-1) + x))";
neuper@52095
   398
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@52095
   399
if (term2str t', terms2str asm) = ("8 / 9", "[]")
neuper@52092
   400
then () else error "rational.sml cancel Schalk make_polynomial 1";
neuper@52092
   401
neuper@52092
   402
"-------- example 188b";
neuper@52092
   403
val t = str2term "(-15 + 5 * x) / (-18 + 6 * x)";
neuper@52095
   404
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52095
   405
if (term2str t', terms2str asm) = ("5 / 6", "[]")
neuper@52092
   406
then () else error "rational.sml cancel Schalk 188b";
neuper@52092
   407
neuper@52092
   408
"-------- example 188c";
neuper@52092
   409
val t = str2term "(a + -1 * b) / (b + -1 * a)";
neuper@52095
   410
val SOME (t', asm) = rewrite_set_ thy false  cancel_p t;
neuper@52095
   411
if (term2str t', terms2str asm) = ("-1 / 1", "[]")
neuper@52092
   412
then () else error "rational.sml cancel Schalk 188c";
neuper@52092
   413
neuper@52095
   414
is_expanded (str2term "a + -1 * b") = true;
neuper@52092
   415
val t = str2term "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
neuper@52092
   416
val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
neuper@52092
   417
if (term2str t', terms2str asm) = ("(a + -1 * b) / (-1 * a + b)", "[]")
neuper@52092
   418
then () else error "rational.sml cancel Schalk make_polynomial 2";
neuper@52092
   419
neuper@52092
   420
"-------- example 190a";
neuper@52092
   421
val t = str2term "( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )";
neuper@52095
   422
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52092
   423
if (term2str t', terms2str asm) = 
neuper@52095
   424
  ("(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)", "[\"3 * a + 9 * a ^^^ 2 ~= 0\"]")
neuper@52092
   425
then () else error "rational.sml cancel Schalk 190a";
neuper@52092
   426
neuper@52092
   427
"-------- example 190c";
neuper@52092
   428
val t = str2term "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
neuper@52092
   429
val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
neuper@52092
   430
if (term2str t', terms2str asm) = 
neuper@52092
   431
  ("(1 + 3 * a + 9 * a ^^^ 2 + 27 * a ^^^ 3) /\n(3 * a + 18 * a ^^^ 2 + 27 * a ^^^ 3)", "[]")
neuper@52092
   432
then () else error "rational.sml make_polynomial Schalk 190c";
neuper@52092
   433
neuper@52092
   434
"-------- example 191a";
neuper@52092
   435
val t = str2term "( x^^^2 + -1 * y^^^2 ) / ( x + y )";
neuper@52092
   436
  is_expanded (str2term "x^^^2 + -1 * y^^^2") = false; (*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*)
neuper@52092
   437
  is_expanded (str2term "x + y") = true;
neuper@52095
   438
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52095
   439
if (term2str t', terms2str asm) = ("(x + -1 * y) / 1", "[]")
neuper@52095
   440
then () else error "rational.sml make_polynomial Schalk 191a";
neuper@52092
   441
neuper@52092
   442
"-------- example 191b";
neuper@52092
   443
val t = str2term "((x + (-1) * y)*(x + y))/((1)*(x + y))";
neuper@52092
   444
val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
neuper@52092
   445
if (term2str t', terms2str asm) = ("(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)", "[]")
neuper@52092
   446
then () else error "rational.sml make_polynomial Schalk 191b";
neuper@52092
   447
neuper@52092
   448
"-------- example 191c";
neuper@52092
   449
val t = str2term "( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )";
neuper@52095
   450
  is_expanded (str2term "9 * x^^^2 + -30 * x + 25") = true;
neuper@52095
   451
  is_expanded (str2term "25 + -30*x + 9*x^^^2") = true;
neuper@52092
   452
  is_expanded (str2term "-25 + 9*x^^^2") = true;
neuper@52092
   453
neuper@52092
   454
val t = str2term "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
neuper@52092
   455
val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
neuper@52092
   456
if (term2str t', terms2str asm) = ("(25 + -30 * x + 9 * x ^^^ 2) / (-25 + 9 * x ^^^ 2)", "[]")
neuper@52092
   457
then () else error "rational.sml make_polynomial Schalk 191c";
neuper@52092
   458
neuper@52092
   459
"-------- example 192b";
neuper@52092
   460
val t = str2term "( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 *  y^^^3 )";
neuper@52095
   461
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52095
   462
if (term2str t', terms2str asm) = ("x ^^^ 2 / y ^^^ 2", "[\"y ^^^ 2 ~= 0\"]")
neuper@52095
   463
then () else error "rational.sml cancel_p Schalk 192b";
neuper@52092
   464
neuper@52092
   465
val t = str2term "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
neuper@52092
   466
val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
neuper@52092
   467
if (term2str t', terms2str asm) = 
neuper@52092
   468
  ("(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)", "[]")
neuper@52092
   469
then () else error "rational.sml make_polynomial Schalk 192b";
neuper@52092
   470
neuper@52092
   471
val t = str2term "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
neuper@52092
   472
val SOME (t', asm) = rewrite_set_ thy false make_polynomial t;
neuper@52092
   473
if (term2str t', terms2str asm) = 
neuper@52092
   474
  ("(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)", "[]")
neuper@52095
   475
then () else error "rational.sml make_polynomial Schalk WN050929 not working";
neuper@52092
   476
neuper@52092
   477
"-------- example 193a";
neuper@52092
   478
val t = str2term "( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )";
neuper@52095
   479
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52095
   480
if (term2str t', terms2str asm) = ("(-3 + x) / (3 + x)", "[\"3 + x ~= 0\"]")
neuper@52095
   481
then () else error "rational.sml cancel_p Schalk 193a";
neuper@52092
   482
neuper@52092
   483
"-------- example 193b";
neuper@52092
   484
val t = str2term "( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )";
neuper@52095
   485
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52095
   486
if (term2str t', terms2str asm) = ("(-4 + x) / (8 + 2 * x)", "[\"8 + 2 * x ~= 0\"]")
neuper@52095
   487
then () else error "rational.sml cancel_p Schalk 193b";
neuper@52092
   488
neuper@52092
   489
"-------- example 193c";
neuper@52092
   490
val t = str2term "( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )";
neuper@52095
   491
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52095
   492
if (term2str t', terms2str asm) = 
neuper@52095
   493
  ("(2 * x + 10 * x ^^^ 2) / (1 + -5 * x)", "[\"1 + -5 * x ~= 0\"]")
neuper@52095
   494
then () else error "rational.sml cancel_p Schalk 193c";
neuper@52092
   495
neuper@52092
   496
(*WN:*)
neuper@52092
   497
val t = str2term "(-25 + 9*x^^^2)/(5 + 3*x)";
neuper@52095
   498
val SOME (t, asm) = rewrite_set_ thy false cancel_p t;
neuper@52095
   499
if (term2str t', terms2str asm) = ("(2 * x + 10 * x ^^^ 2) / (1 + -5 * x)", "[]")
neuper@52092
   500
then () else error "rational.sml cancel WN 1";
neuper@52092
   501
neuper@52101
   502
"-------- example heuberger";
neuper@52101
   503
val t = str2term ("(x^^^4 + x * y + x^^^3 * y + y^^^2) / " ^
neuper@52101
   504
  "(x + 5 * x^^^2 + y + 5 * x * y + x^^^2 * y^^^3 + x * y^^^4)");
neuper@52101
   505
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52101
   506
if (term2str t', terms2str asm) = 
neuper@52101
   507
  ("(x ^^^ 3 + y) / (1 + 5 * x + x * y ^^^ 3)", "[\"1 + 5 * x + x * y ^^^ 3 ~= 0\"]")
neuper@52101
   508
then () else error "rational.sml cancel_p heuberger";
neuper@52092
   509
neuper@52101
   510
"-------- rewrite_set_ common_nominator_p from: Mathematik 1 Schalk ----------";
neuper@52101
   511
"-------- rewrite_set_ common_nominator_p from: Mathematik 1 Schalk ----------";
neuper@52101
   512
"-------- rewrite_set_ common_nominator_p from: Mathematik 1 Schalk ----------";
neuper@52101
   513
(*deleted example 204 ... 236b at update Isabelle2012-->2013*)
neuper@52092
   514
neuper@52100
   515
"-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
neuper@52100
   516
"-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
neuper@52100
   517
"-------- integration lev.1 -- lev.5: cancel_p_ & common_nominator_p_ --------";
neuper@52100
   518
val t = str2term ("123 = (a*x)/(b*x) + (c*x)/(d*x) + (e*x)/(f*x::real)");
neuper@52100
   519
"-------- gcd_poly integration level 1: works on exact term";
neuper@52100
   520
if NONE = cancel_p_ thy t then () else error "cancel_p_ works on exact fraction";
neuper@52100
   521
if NONE = add_fraction_p_ thy t then () else error "add_fraction_p_ works on exact fraction";
neuper@52100
   522
neuper@52100
   523
"-------- gcd_poly integration level 2: picks out ONE appropriate subterm";
neuper@52100
   524
val SOME (t', asm) = rewrite_set_ thy false cancel_p t;
neuper@52100
   525
if term2str t' = "123 = a * x / (b * x) + c * x / (d * x) + e / f" 
neuper@52100
   526
then () else error "level 2, rewrite_set_ cancel_p: changed";
neuper@52100
   527
val SOME (t', asm) = rewrite_set_ thy false add_fractions_p t;
neuper@52100
   528
if term2str t' = "123 = (b * c * x + a * d * x) / (b * d * x) + e * x / (f * x)"
neuper@52100
   529
then () else error "level 2, rewrite_set_ add_fractions_p: changed";
neuper@52100
   530
neuper@52100
   531
"-------- gcd_poly integration level 3: rewrites all appropriate subterms";
neuper@52100
   532
val SOME (t', asm) = rewrite_set_ thy false cancel_p_rls t;
neuper@52100
   533
if term2str t' = "123 = a / b + c / d + e / f"
neuper@52100
   534
then () else error "level 3, rewrite_set_ cancel_p_rls: changed";
neuper@52100
   535
val SOME (t', asm) = rewrite_set_ thy false common_nominator_p_rls t; (*CREATE add_fractions_p_rls*)
neuper@52100
   536
if term2str t' = "123 = (b * d * e * x + b * c * f * x + a * d * f * x) / (b * d * f * x)"
neuper@52100
   537
then () else error "level 3, rewrite_set_ add_fractions_p_rls: changed";
neuper@52100
   538
neuper@52100
   539
"-------- gcd_poly integration level 4: iteration cancel_p -- add_fraction_p";
neuper@52100
   540
(* simpler variant *)
neuper@52100
   541
val testrls = append_rls "testrls" e_rls [Rls_ cancel_p, Rls_ add_fractions_p]
neuper@52100
   542
val SOME (t', asm) = rewrite_set_ thy false testrls t;
neuper@52100
   543
(*trace_rewrite := false;
neuper@52100
   544
#  rls: testrls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
neuper@52100
   545
##  rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
neuper@52100
   546
##  rls: common_nominator_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f 
neuper@52100
   547
##  rls: cancel_p on: 123 = (b * c * x + a * d * x) / (b * d * x) + e / f 
neuper@52100
   548
##  rls: common_nominator_p on: 123 = (b * c + a * d) / (b * d) + e / f 
neuper@52100
   549
##  rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) 
neuper@52100
   550
##  rls: common_nominator_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
neuper@52100
   551
if term2str t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
neuper@52100
   552
then () else error "level 4, rewrite_set_ *_p: changed";
neuper@52100
   553
neuper@52100
   554
(* complicated variant *)
neuper@52100
   555
val testrls_rls = append_rls "testrls_rls" e_rls [Rls_ cancel_p_rls, Rls_ common_nominator_p_rls];
neuper@52100
   556
val SOME (t', asm) = rewrite_set_ thy false testrls_rls t;
neuper@52100
   557
(*#  rls: testrls_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
neuper@52100
   558
##  rls: cancel_p_rls on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
neuper@52100
   559
###  rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e * x / (f * x) 
neuper@52100
   560
###  rls: cancel_p on: 123 = a * x / (b * x) + c * x / (d * x) + e / f 
neuper@52100
   561
###  rls: cancel_p on: 123 = a * x / (b * x) + c / d + e / f 
neuper@52100
   562
###  rls: cancel_p on: 123 = a / b + c / d + e / f 
neuper@52100
   563
##  rls: common_nominator_p_rls on: 123 = a / b + c / d + e / f 
neuper@52100
   564
###  rls: common_nominator_p on: 123 = a / b + c / d + e / f 
neuper@52100
   565
###  rls: common_nominator_p on: 123 = (b * c + a * d) / (b * d) + e / f 
neuper@52100
   566
###  rls: common_nominator_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) 
neuper@52100
   567
##  rls: cancel_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) 
neuper@52100
   568
###  rls: cancel_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) 
neuper@52100
   569
##  rls: common_nominator_p_rls on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) 
neuper@52100
   570
###  rls: common_nominator_p on: 123 = (b * d * e + b * c * f + a * d * f) / (b * d * f) *)
neuper@52100
   571
if term2str t' = "123 = (b * d * e + b * c * f + a * d * f) / (b * d * f)"
neuper@52100
   572
then () else error "level 4, rewrite_set_ *_p_rls: changed"
neuper@52100
   573
neuper@52100
   574
"-------- gcd_poly integration level 5: cancel_p & add_fraction_p within norm_Rational";
neuper@52100
   575
val SOME (t', asm) = rewrite_set_ thy false norm_Rational t;
neuper@52100
   576
if term2str t' = "123 = (a * d * f + b * c * f + b * d * e) / (b * d * f)"
neuper@52100
   577
then () else error "level 5, rewrite_set_ norm_Rational: changed"
neuper@37906
   578
neuper@52101
   579
"-------- reverse rewrite ----------------------------------------------------";
neuper@52101
   580
"-------- reverse rewrite ----------------------------------------------------";
neuper@52101
   581
"-------- reverse rewrite ----------------------------------------------------";
neuper@52101
   582
(** the term for which reverse rewriting is demonstrated **)
neuper@52101
   583
val t = str2term "(9 + -1 * x ^^^ 2) / (9 + 6 * x + x ^^^ 2)";
neuper@52101
   584
val Rrls {scr = Rfuns {init_state = ini, locate_rule = loc,
neuper@52101
   585
  next_rule = nex, normal_form = nor, ...},...} = cancel_p;
neuper@37906
   586
neuper@52101
   587
(** normal_form produces the result in ONE step **)
neuper@37926
   588
  val SOME (t',_) = nor t;
neuper@52101
   589
if term2str t' = "(3 + -1 * x) / (3 + x)" then ()
neuper@38044
   590
else error "rational.sml normal_form (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
neuper@37906
   591
neuper@52101
   592
(** initialize the interpreter state used by the 'me' **)
neuper@52101
   593
  val (t, _, revsets, _) = ini t;
neuper@37906
   594
neuper@52101
   595
if length (hd revsets) = 11 then () else error "length of revset changed";
neuper@52101
   596
if (revsets |> nth 1 |> nth 1 |> id_of_thm) = 
neuper@52101
   597
  (@{thm realpow_twoI} |> string_of_thm |> thmID_of_derivation_name)
neuper@52101
   598
then () else error "first element of revset changed";
neuper@52101
   599
if
neuper@52101
   600
(revsets |> nth 1 |> nth 1 |> rule2str) = "Thm (\"realpow_twoI\",??.unknown)" andalso
neuper@52101
   601
(revsets |> nth 1 |> nth 2 |> rule2str) = 
neuper@52101
   602
  "Thm (\"sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))\",??.unknown)" andalso
neuper@52101
   603
(revsets |> nth 1 |> nth 3 |> rule2str) = 
neuper@52101
   604
  "Thm (\"sym_#mult_Float ((2,0), (0,0)) __ ((3,0), (0,0))\",??.unknown)" andalso
neuper@52101
   605
(revsets |> nth 1 |> nth 4 |> rule2str) = 
neuper@52101
   606
  "Thm (\"sym_#mult_Float ((~1,0), (0,0)) __ ((3,0), (0,0))\",??.unknown)" andalso
neuper@52101
   607
(revsets |> nth 1 |> nth 5 |> rule2str) = 
neuper@52101
   608
  "Thm (\"sym_#mult_Float ((3,0), (0,0)) __ ((3,0), (0,0))\",??.unknown)" andalso
neuper@52101
   609
(revsets |> nth 1 |> nth 6 |> rule2str) = "Rls_ (\"sym_order_mult_rls_\")" andalso
neuper@52101
   610
(revsets |> nth 1 |> nth 7 |> rule2str) = 
neuper@52101
   611
  "Thm (\"sym_mult_assoc\",Groups.semigroup_mult_class.mult_assoc)"
neuper@52101
   612
then () else error "first 7 elements in revset changed"
neuper@52101
   613
neuper@52101
   614
(** find the rule 'r' to apply to term 't' **)
neuper@52101
   615
(*/------- since cancel_ (accepted "-" between monomials) has been replaced by cancel_p_ 
neuper@52101
   616
  for Isabelle2013, we don't get a working revset, but non-termination:
neuper@52101
   617
neuper@38044
   618
  val SOME (r as (Thm (str, thm))) = nex revsets t;
neuper@52101
   619
  :
neuper@52101
   620
((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), 
neuper@52101
   621
  Rls_ ("sym_order_mult_rls_"), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x), []))","
neuper@52101
   622
((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * (3 * x) + x * x), 
neuper@52101
   623
  Thm ("sym_mult_assoc",""), ((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x), []))","
neuper@52101
   624
((3 * 3 + -1 * (x * x)) / (3 * 3 + 2 * 3 * x + x * x), 
neuper@52101
   625
  Thm ("sym_mult_assoc",""), ((3 * 3 + -1 * x * x) / (3 * 3 + 2 * 3 * x + x * x), []))","
neuper@52101
   626
((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), []))","
neuper@52101
   627
 :
neuper@52101
   628
### Isabelle2002:
neuper@52101
   629
  Thm ("sym_#mult_2_3", "6 = 2 * 3")
neuper@52101
   630
### Isabelle2009-2 for cancel_ (not cancel_p_):
neuper@38044
   631
if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))"
neuper@38044
   632
   andalso string_of_thm thm = 
neuper@41929
   633
           (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
neuper@38044
   634
               (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
neuper@38044
   635
else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
neuper@52101
   636
\---------------------------------------------------------------------------------------/*)
neuper@37906
   637
neuper@52101
   638
(** check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
neuper@37906
   639
  if the rule is OK, the term resulting from applying the rule is returned,too;
neuper@37906
   640
  there might be several rule applications inbetween,
neuper@52101
   641
  which are listed after the head in reverse order **)
neuper@52101
   642
(*/-------------------------------------------- Isabelle2013: this gives "error id_of_thm";
neuper@52101
   643
  we don't repair this, because interaction within "reverse rewriting" never worked properly:
neuper@52101
   644
neuper@38044
   645
  val (r, (t, asm))::_ = loc revsets t r;
neuper@38044
   646
if term2str t = "(9 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" andalso asm = []
neuper@52101
   647
then () else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
neuper@37906
   648
neuper@38044
   649
(* find the next rule to apply *)
neuper@38044
   650
  val SOME (r as (Thm (str, thm))) = nex revsets t;
neuper@38044
   651
if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso
neuper@41929
   652
   string_of_thm thm = (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
neuper@38044
   653
                (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
neuper@38044
   654
else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
neuper@37906
   655
neuper@37906
   656
(*check the next rule*)
neuper@38044
   657
  val (r, (t, asm)) :: _ = loc revsets t r;
neuper@38044
   658
if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" then ()
neuper@38044
   659
else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) II";
neuper@37906
   660
neuper@37906
   661
(*find and check the next rules, rewrite*)
neuper@37926
   662
  val SOME r = nex revsets t;
neuper@37906
   663
  val (r,(t,asm))::_ = loc revsets t r;
neuper@38044
   664
if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
neuper@38044
   665
else error "rational.sml locate_rule II";
neuper@37906
   666
neuper@37926
   667
  val SOME r = nex revsets t;
neuper@37906
   668
  val (r,(t,asm))::_ = loc revsets t r;
neuper@38044
   669
if term2str t = "(3 - x) * (3 + x) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
neuper@38044
   670
else error "rational.sml next_rule II";
neuper@37906
   671
neuper@37926
   672
  val SOME r = nex revsets t;
neuper@37906
   673
  val (r,(t,asm))::_ = loc revsets t r;
neuper@38044
   674
if term2str t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then ()
neuper@38044
   675
else error "rational.sml next_rule III";
neuper@37906
   676
neuper@37926
   677
  val SOME r = nex revsets t;
neuper@38044
   678
  val (r, (t, asm)) :: _ = loc revsets t r;
neuper@37906
   679
  val ss = term2str t;
neuper@38044
   680
if ss = "(3 - x) / (3 + x)" andalso terms2str asm = "[\"3 + x ~= 0\"]" then ()
neuper@38044
   681
else error "rational.sml: new behav. in rev-set cancel";
neuper@52101
   682
\--------------------------------------------------------------------------------------/*)
neuper@37906
   683
neuper@52101
   684
"-------- 'reverse-ruleset' cancel_p -----------------------------------------";
neuper@52101
   685
"-------- 'reverse-ruleset' cancel_p -----------------------------------------";
neuper@52101
   686
"-------- 'reverse-ruleset' cancel_p -----------------------------------------";
neuper@52101
   687
(*Isabelle2013: the example below shows, why "reverse rewriting" only worked for
neuper@52101
   688
  special cases.*)
neuper@37906
   689
neuper@37906
   690
(*the term for which reverse rewriting is demonstrated*)
neuper@37906
   691
val t = str2term "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))";
neuper@37906
   692
val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
neuper@37906
   693
		       next_rule=nex,normal_form=nor,...},...} = cancel_p;
neuper@37906
   694
neuper@37906
   695
(*normal_form produces the result in ONE step*)
neuper@37926
   696
val SOME (t',_) = nor t; 
neuper@37906
   697
term2str t' = "(3 + 1 * x) / (3 + -1 * x)";
neuper@37906
   698
neuper@37906
   699
(*initialize the interpreter state used by the 'me'*)
neuper@37926
   700
val SOME (t', asm) = cancel_p_ thy t;
neuper@37906
   701
term2str t' = "(3 + x) / (3 + -1 * x)" (*true*);
neuper@37906
   702
terms2str asm = "[\"3 + -1 * x ~= 0\"]" (*true*);
neuper@37906
   703
val (t,_,revsets,_) = ini t;
neuper@37906
   704
neuper@37906
   705
(* WN.10.10.02: dieser Fall terminiert nicht 
neuper@37906
   706
           (make_polynomial enth"alt zu viele rules)
neuper@37906
   707
WN060823 'init_state' requires rewriting on specified location in the term
neuper@37906
   708
print_depth 99; Rfuns; print_depth 3;
neuper@48763
   709
WN060831 cycling "sym_order_mult_rls_" "sym_mult_assoc"
neuper@37906
   710
         as was with make_polynomial before ?!?*)
neuper@37906
   711
neuper@37926
   712
val SOME r = nex revsets t;
neuper@37906
   713
eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))", 
neuper@38041
   714
		mk_thm thy "9 = 3 ^^^ 2"));
neuper@37906
   715
(*WN060831 *** id_of_thm
neuper@37906
   716
           Exception- ERROR raised ...
neuper@37906
   717
val (r,(t,asm))::_ = loc revsets t r;
neuper@37906
   718
term2str t;
neuper@37906
   719
neuper@37926
   720
  val SOME r = nex revsets t;
neuper@37906
   721
  val (r,(t,asm))::_ = loc revsets t r;
neuper@37906
   722
  term2str t;
neuper@52101
   723
*)                    
neuper@37906
   724
neuper@52101
   725
(*========== inhibit exn WN130824 TODO =======================================================
neuper@52101
   726
"-------- examples: rls norm_Rational ----------------------------------------";
neuper@52101
   727
"-------- examples: rls norm_Rational ----------------------------------------";
neuper@52101
   728
"-------- examples: rls norm_Rational ----------------------------------------";
neuper@37906
   729
val t = str2term "(3*x+5)/18 - x/2  - -(3*x - 2)/9 = 0";
neuper@37926
   730
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38031
   731
if term2str t' = "1 / 18 = 0" then () else error "rational.sml 1";
neuper@37906
   732
neuper@37906
   733
val t = str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0";
neuper@37926
   734
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
   735
if term2str t' = "(237 + 65 * x) / 36 = 0" then () 
neuper@38031
   736
else error "rational.sml 2";
neuper@37906
   737
neuper@37906
   738
val t = str2term "(1/2 + (5*x)/2)^^^2 - ((13*x)/2 - 5/2)^^^2 - (6*x)^^^2 + 29";
neuper@37926
   739
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
   740
if term2str t' = "23 + 35 * x + -72 * x ^^^ 2" then ()
neuper@38031
   741
else error "rational.sml 3";
neuper@38046
   742
neuper@37906
   743
(*trace_rewrite:=true;*)
neuper@37906
   744
val t = str2term "Not (6*x is_atom)";
neuper@37926
   745
val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
neuper@41928
   746
"HOL.True";
neuper@37906
   747
val t = str2term "1 < 2";
neuper@37926
   748
val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
neuper@41928
   749
"HOL.True";
neuper@38046
   750
neuper@37906
   751
val t = str2term "(6*x)^^^2";
neuper@37926
   752
val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false 
neuper@38041
   753
			   (num_str @{thm realpow_def_atom}) t;
neuper@38046
   754
if term2str t' = "6 * x * (6 * x) ^^^ (2 + -1)" then ()
neuper@38046
   755
else error "rational.sml powers_erls (6*x)^^^2";
neuper@37906
   756
neuper@37906
   757
val t = str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))";
neuper@37926
   758
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38031
   759
if term2str t' = "65 * x / 2" then () else error "rational.sml 4";
neuper@37906
   760
neuper@37906
   761
val t = str2term "1 - ((13*x)/2 - 5/2)^^^2";
neuper@37926
   762
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
   763
(*bef.040209: if term2str t' = "(-21 + (130 * x + -169 * x ^^^ 2)) / 4"then()*)
neuper@37906
   764
if term2str t' = "(-21 + 130 * x + -169 * x ^^^ 2) / 4" then () 
neuper@38031
   765
else error "rational.sml 5";
neuper@37906
   766
neuper@37906
   767
(*SRAM Schalk I, p.92 Nr. 609a*)
neuper@37906
   768
val t = str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
neuper@37926
   769
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
   770
if term2str t' = "(-255 + 112 * x) / 135" then () 
neuper@38031
   771
else error "rational.sml 6";
neuper@37906
   772
neuper@37906
   773
(*SRAM Schalk I, p.92 Nr. 610c*)
neuper@37906
   774
val t = str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
neuper@37926
   775
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38031
   776
if term2str t' = "(-3 + -1 * x) / 2" then () else error "rational.sml 7";
neuper@37906
   777
neuper@37906
   778
(*SRAM Schalk I, p.92 Nr. 476a*)
neuper@38046
   779
val t = str2term "(x^^^2/(1 - x^^^2) + 1)/(x/(1 - x) + 1) * (1 + x)";
neuper@38046
   780
(*. a/b : c/d translated to a/b * d/c .*)
neuper@37926
   781
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38031
   782
(*if term2str t' = "1 / 1" then () else error "rational.sml 8";3.6.03*)
neuper@38031
   783
if term2str t' = "1" then () else error "rational.sml 8";
neuper@37906
   784
neuper@37906
   785
(*............................vvv---TODO: sollte gehen mit poly_order *)
neuper@37906
   786
(*Schalk I, p.92 Nr. 472a*)
neuper@37906
   787
val t = str2term "((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
neuper@37926
   788
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38031
   789
if term2str t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
neuper@37906
   790
neuper@37906
   791
(*Schalk I, p.70 Nr. 480b; a/b : c/d translated to a/b * d/c*)
neuper@38046
   792
val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
neuper@38041
   793
		 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
neuper@38041
   794
		 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
neuper@38046
   795
		 "(20*x*y/(x^^^2 - 25*y^^^2))");
neuper@37906
   796
(*... nicht simpl, zerlegt ...*)
neuper@38046
   797
val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
neuper@38046
   798
		 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2))");
neuper@37926
   799
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
   800
"(-12 * (x * y ^^^ 3) + 108 * (x * (y * x ^^^ 2))) / (12 * (x * y))";
neuper@37906
   801
(*                             ~~~~~~~~~~ poly_order notwendig!*)
neuper@38046
   802
val t = str2term ("(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
neuper@38046
   803
		 "(20*x*y/(x^^^2 - 25*y^^^2))");
neuper@37926
   804
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38046
   805
if term2str t' = "1 / (x ^^^ 2 + -25 * y ^^^ 2)" then ()
neuper@38046
   806
else error "rational.sml norm_Rational 1 / (x ^^^ 2 + -25 * y ^^^ 2)";
neuper@37906
   807
neuper@37906
   808
"nonterm.SK6 ----- SK060904-2a non-termination of add_fraction_p_";
neuper@37906
   809
(*WN.2.6.03 from rlang.sml 56a 
neuper@37906
   810
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)";
neuper@37926
   811
val NONE = rewrite_set_ thy false common_nominator_p t;
neuper@37906
   812
neuper@37906
   813
WN060831 nonterm.SK7 
neuper@37906
   814
val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
neuper@37926
   815
val NONE = add_fraction_p_ thy t; 
neuper@37906
   816
*)
neuper@37906
   817
neuper@37906
   818
neuper@37906
   819
(* ------------------------------------------------------------------- *)
neuper@37906
   820
(*---------vvv------------ MG: ab 1.7.03 ----------------vvv-----------*)
neuper@37906
   821
(*                 Simplifier fuer beliebige Buchterme                 *) 
neuper@37906
   822
(* ------------------------------------------------------------------- *)
neuper@37906
   823
(*----------------------- norm_Rational_mg ----------------------------*)
neuper@37906
   824
(* ------------------------------------------------------------------- *)
neuper@37906
   825
neuper@38041
   826
"-------- numeral rationals -----------------------------";
neuper@38041
   827
"-------- numeral rationals -----------------------------";
neuper@38041
   828
"-------- numeral rationals -----------------------------";
neuper@37906
   829
(*SRA Schalk I, p.40 Nr. 164b *)
neuper@37906
   830
val t = str2term "(47/6 - 76/9 + 13/4)/(35/12)";
neuper@37926
   831
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   832
term2str t;
neuper@37906
   833
if (term2str t) = "19 / 21" then ()
neuper@38046
   834
else error "rational.sml: diff.behav. in norm_Rational_mg 1";
neuper@37906
   835
neuper@37906
   836
(*SRA Schalk I, p.40 Nr. 166a *)
neuper@37906
   837
val t = str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
neuper@37926
   838
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   839
term2str t;
neuper@37906
   840
if (term2str t) = "45 / 2" then ()
neuper@38046
   841
else error "rational.sml: diff.behav. in norm_Rational_mg 2";
neuper@37906
   842
neuper@37906
   843
neuper@38041
   844
"-------- cancellation ----------------------------------";
neuper@38041
   845
"-------- cancellation ----------------------------------";
neuper@38041
   846
"-------- cancellation ----------------------------------";
neuper@37906
   847
(* e190c Stefan K.*)
neuper@37906
   848
val t = str2term
neuper@37906
   849
"((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
neuper@37926
   850
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   851
term2str t;
neuper@37906
   852
if (term2str t) = 
neuper@37906
   853
"(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
neuper@37906
   854
then ()
neuper@38046
   855
else error "rational.sml: diff.behav. in norm_Rational_mg 3";
neuper@37906
   856
neuper@37906
   857
(* e192b Stefan K.*)
neuper@37906
   858
val t = str2term
neuper@37906
   859
"((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
neuper@37926
   860
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   861
term2str t;
neuper@37906
   862
if (term2str t) = 
neuper@37906
   863
"x ^^^ 2 / y ^^^ 2"
neuper@37906
   864
then ()
neuper@38046
   865
else error "rational.sml: diff.behav. in norm_Rational_mg 4";
neuper@37906
   866
neuper@37906
   867
(*SRC Schalk I, p.66 Nr. 379c *)
neuper@37906
   868
val t = str2term 
neuper@37906
   869
"(a - b)/(b - a)";
neuper@37926
   870
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   871
term2str t;
neuper@37906
   872
if (term2str t) =
neuper@37906
   873
"-1"
neuper@37906
   874
then ()
neuper@38046
   875
else error "rational.sml: diff.behav. in norm_Rational_mg 5";
neuper@37906
   876
neuper@37906
   877
(*SRC Schalk I, p.66 Nr. 380b *)
neuper@37906
   878
val t = str2term 
neuper@37906
   879
"15*(3*x+3)*(4*x+9)/(12*(2*x+7)*(5*x+5))";
neuper@37926
   880
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   881
term2str t;
neuper@37906
   882
if (term2str t) =
neuper@37906
   883
"(27 + 12 * x) / (28 + 8 * x)"
neuper@37906
   884
then ()
neuper@38046
   885
else error "rational.sml: diff.behav. in norm_Rational_mg 6";
neuper@37906
   886
neuper@37906
   887
(*Schalk I, p.60 Nr. 215c *)
neuper@37906
   888
(* Falsches Ergebnis: rechnet lange und cancel_p kann nicht weiter krzen!!!*)
neuper@37906
   889
(* WN060831????MG1 
neuper@37906
   890
val t = str2term "(a+b)^^^4*(x - y)/((x - y)^^^3*(a+b)^^^2)";
neuper@37926
   891
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   892
term2str t;
neuper@37906
   893
if (term2str t) =
neuper@37906
   894
"(a ^^^ 4 * x + -1 * a ^^^ 4 * y + 4 * a ^^^ 3 * b * x + -4 * a ^^^ 3 * b * y + 6 * a ^^^ 2 * b ^^^ 2 * x + -6 * a ^^^ 2 * b ^^^ 2 * y + 4 * a * b ^^^ 3 * x + -4 * a * b ^^^ 3 * y + b ^^^ 4 * x + -1 * b ^^^ 4 * y) /(a ^^^ 2 * x ^^^ 3 + -3 * a ^^^ 2 * x ^^^ 2 * y + 3 * a ^^^ 2 * x * y ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 3 + 2 * a * b * x ^^^ 3 + -6 * a * b * x ^^^ 2 * y + 6 * a * b * x * y ^^^ 2 + -2 * a * b * y ^^^ 3 + b ^^^ 2 * x ^^^ 3 + -3 * b ^^^ 2 * x ^^^ 2 * y + 3 * b ^^^ 2 * x * y ^^^ 2 + -1 * b ^^^ 2 * y ^^^ 3)"
neuper@37906
   895
then ()
neuper@38046
   896
else error "rational.sml: diff.behav. in norm_Rational_mg 7";
neuper@37906
   897
*)
neuper@37906
   898
(*val t = str2term 
neuper@37906
   899
"(a ^^^ 4 * x + -1 * a ^^^ 4 * y + 4 * a ^^^ 3 * b * x + -4 * a ^^^ 3 * b * y + 6 * a ^^^ 2 * b ^^^ 2 * x + -6 * a ^^^ 2 * b ^^^ 2 * y + 4 * a * b ^^^ 3 * x + -4 * a * b ^^^ 3 * y + b ^^^ 4 * x + -1 * b ^^^ 4 * y) /(a ^^^ 2 * x ^^^ 3 + -3 * a ^^^ 2 * x ^^^ 2 * y + 3 * a ^^^ 2 * x * y ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 3 + 2 * a * b * x ^^^ 3 + -6 * a * b * x ^^^ 2 * y + 6 * a * b * x * y ^^^ 2 + -2 * a * b * y ^^^ 3 + b ^^^ 2 * x ^^^ 3 + -3 * b ^^^ 2 * x ^^^ 2 * y + 3 * b ^^^ 2 * x * y ^^^ 2 + -1 * b ^^^ 2 * y ^^^ 3)"
neuper@37926
   900
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
   901
term2str t;*)
neuper@37906
   902
(* uncaught exception nonexhaustive binding failure
neuper@37906
   903
   raised at: stdIn:93.1-93.51 *)
neuper@37906
   904
neuper@37906
   905
(*Schalk I, p.66 Nr. 381a *)
neuper@37906
   906
(* ACHTUNG: rechnet ca. 2 Minuten !!! *)
neuper@37906
   907
(* WN060831???MG2
neuper@37906
   908
val t = str2term "18*(a+b)^^^3*(a - b)^^^2/(72*(a - b)^^^3*(a+b)^^^2)";
neuper@37926
   909
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   910
term2str t;
neuper@37906
   911
if (term2str t) =
neuper@37906
   912
"(a + b) / (4 * a + -4 * b)"
neuper@38046
   913
then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
neuper@37906
   914
*)
neuper@37906
   915
neuper@37906
   916
(*SRC Schalk I, p.66 Nr. 381b *)
neuper@37906
   917
val t = str2term 
neuper@37906
   918
"(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
neuper@37926
   919
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   920
term2str t;
neuper@37906
   921
if (term2str t) =
neuper@37906
   922
"-1 / (5 + -2 * x)"
neuper@37906
   923
then ()
neuper@38046
   924
else error "rational.sml: diff.behav. in norm_Rational_mg 9";
neuper@37906
   925
neuper@37906
   926
(*SRC Schalk I, p.66 Nr. 381c *)
neuper@37906
   927
val t = str2term 
neuper@37906
   928
"(27*a^^^3+9*a^^^2+3*a+1)/(27*a^^^3+18*a^^^2+3*a)";
neuper@37926
   929
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   930
term2str t;
neuper@37906
   931
if (term2str t) =
neuper@37906
   932
"(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
neuper@37906
   933
then ()
neuper@38046
   934
else error "rational.sml: diff.behav. in norm_Rational_mg 10";
neuper@37906
   935
neuper@37906
   936
(*SRC Schalk I, p.66 Nr. 383a *)
neuper@37906
   937
val t = str2term 
neuper@37906
   938
"(5*a^^^2 - 5*a*b)/(a - b)^^^2";
neuper@37926
   939
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   940
term2str t;
neuper@37906
   941
if (term2str t) =
neuper@37906
   942
"5 * a / (a + -1 * b)"
neuper@37906
   943
then ()
neuper@38046
   944
else error "rational.sml: diff.behav. in norm_Rational_mg 11";
neuper@37906
   945
neuper@37906
   946
neuper@38041
   947
"-------- common denominator ----------------------------";
neuper@38041
   948
"-------- common denominator ----------------------------";
neuper@38041
   949
"-------- common denominator ----------------------------";
neuper@37906
   950
(*SRA Schalk I, p.67 Nr. 403a *)
neuper@37906
   951
val t = str2term 
neuper@37906
   952
"4/x - 3/y - 1";
neuper@37926
   953
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   954
term2str t;
neuper@37906
   955
if (term2str t) =
neuper@37906
   956
"(-3 * x + 4 * y + -1 * x * y) / (x * y)"
neuper@37906
   957
then ()
neuper@38046
   958
else error "rational.sml: diff.behav. in norm_Rational_mg 12";
neuper@37906
   959
neuper@37906
   960
(*SRA Schalk I, p.67 Nr. 407b *)
neuper@37906
   961
val t = str2term 
neuper@37906
   962
"(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a^^^2+3*b*c)/(a*b*c)";
neuper@37926
   963
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   964
term2str t;
neuper@37906
   965
if (term2str t) =
neuper@37906
   966
"4 / c"
neuper@37906
   967
then ()
neuper@38046
   968
else error "rational.sml: diff.behav. in norm_Rational_mg 13";
neuper@37906
   969
neuper@37906
   970
(*SRA Schalk I, p.67 Nr. 410b *)
neuper@37906
   971
val t = str2term 
neuper@37906
   972
"1/(x+1) + 1/(x+2) - 2/(x+3)";
neuper@37926
   973
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   974
term2str t;
neuper@37906
   975
if (term2str t) =
neuper@37906
   976
"(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)"
neuper@37906
   977
then ()
neuper@38046
   978
else error "rational.sml: diff.behav. in norm_Rational_mg 14";
neuper@37906
   979
neuper@37906
   980
(*SRA Schalk I, p.67 Nr. 413b *)
neuper@37906
   981
val t = str2term 
neuper@37906
   982
"(1+x)/(1 - x) - (1 - x)/(1+x) + 2*x/(1 - x^^^2)";
neuper@37926
   983
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   984
term2str t;
neuper@37906
   985
if (term2str t) =
neuper@37906
   986
"6 * x / (1 + -1 * x ^^^ 2)"
neuper@37906
   987
then ()
neuper@38046
   988
else error "rational.sml: diff.behav. in norm_Rational_mg 15";
neuper@37906
   989
neuper@37906
   990
(*SRA Schalk I, p.68 Nr. 414a *)
neuper@37906
   991
val t = str2term 
neuper@37906
   992
"(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))";
neuper@37926
   993
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
   994
term2str t;
neuper@37906
   995
if (term2str t) =
neuper@37906
   996
"(-2 + -5 * x + 2 * x ^^^ 2) / (2 + -3 * x + x ^^^ 2)"
neuper@37906
   997
then ()
neuper@38046
   998
else error "rational.sml: diff.behav. in norm_Rational_mg 16";
neuper@37906
   999
neuper@37906
  1000
(*SRA Schalk I, p.68 Nr. 423a *)
neuper@37906
  1001
val t = str2term 
neuper@37906
  1002
"(2*x+3*y)/x + (4*x^^^3 - x*y^^^2 - 3*y^^^3)/(x^^^3 - 2*x^^^2*y+x*y^^^2) - (5*x+6*y)/(x - y)";
neuper@37926
  1003
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1004
term2str t;
neuper@37906
  1005
if (term2str t) =
neuper@37906
  1006
"1"
neuper@37906
  1007
then ()
neuper@38046
  1008
else error "rational.sml: diff.behav. in norm_Rational_mg 17";
neuper@37906
  1009
neuper@37906
  1010
(*SRA Schalk I, p.68 Nr. 428b *)
neuper@37906
  1011
val t = str2term 
neuper@37906
  1012
"1/(a - b)^^^2 + 1/(a+b)^^^2 - 2/(a^^^2 - b^^^2) - 4*(b^^^2 - 1)/(a^^^2 - b^^^2)^^^2";
neuper@37926
  1013
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1014
term2str t;
neuper@37906
  1015
if (term2str t) =
neuper@37906
  1016
"4 / (a ^^^ 4 + -2 * a ^^^ 2 * b ^^^ 2 + b ^^^ 4)"
neuper@37906
  1017
then ()
neuper@38046
  1018
else error "rational.sml: diff.behav. in norm_Rational_mg 18";
neuper@37906
  1019
neuper@37906
  1020
(*SRA Schalk I, p.68 Nr. 430b *)
neuper@37906
  1021
val t = str2term 
neuper@37906
  1022
"a^^^2/(a - 3*b) - 108*a*b^^^3/((a+3*b)*(a^^^2 - 9*b^^^2)) - 9*b^^^2*(a - 3*b)/(a+3*b)^^^2";
neuper@37926
  1023
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1024
term2str t;
neuper@37906
  1025
if (term2str t) =
neuper@37906
  1026
"a + 3 * b"
neuper@37906
  1027
then ()
neuper@38046
  1028
else error "rational.sml: diff.behav. in norm_Rational_mg 19";
neuper@37906
  1029
neuper@37906
  1030
neuper@37906
  1031
(*SRA Schalk I, p.68 Nr. 432 *)
neuper@37906
  1032
val t = str2term 
neuper@37906
  1033
"(a^^^2+a*b)/(a^^^2 - b^^^2) - (b^^^2 - a*b)/(b^^^2 - a^^^2) + a^^^2*(a - b)/(a^^^3 - a^^^2*b) - 2*a*(a^^^2 - b^^^2)/(a^^^3 - a*b^^^2) - 2*b^^^2/(a^^^2 - b^^^2)";
neuper@37926
  1034
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1035
term2str t;
neuper@37906
  1036
if (term2str t) =
neuper@37906
  1037
"0"
neuper@37906
  1038
then ()
neuper@38046
  1039
else error "rational.sml: diff.behav. in norm_Rational_mg 20";
neuper@37906
  1040
neuper@37906
  1041
(*Eigenes*)
neuper@37906
  1042
val t = str2term 
neuper@37906
  1043
"3*a/(a*b) + x/y";
neuper@37926
  1044
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1045
term2str t;
neuper@37906
  1046
if (term2str t) =
neuper@37906
  1047
"(3 * y + b * x) / (b * y)"
neuper@37906
  1048
then ()
neuper@38046
  1049
else error "rational.sml: diff.behav. in norm_Rational_mg 21";
neuper@37906
  1050
neuper@37906
  1051
neuper@38041
  1052
"-------- multiply and cancel ---------------------------";
neuper@38041
  1053
"-------- multiply and cancel ---------------------------";
neuper@38041
  1054
"-------- multiply and cancel ---------------------------";
neuper@37906
  1055
(*SRM Schalk I, p.68 Nr. 436a *)
neuper@37906
  1056
val t = str2term 
neuper@37906
  1057
"3*(x+y)/(15*(x - y)) * 25*(x - y)^^^2/(18*(x+y)^^^2)";
neuper@37926
  1058
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1059
term2str t;
neuper@37906
  1060
if (term2str t) =
neuper@37906
  1061
"(5 * x + -5 * y) / (18 * x + 18 * y)"
neuper@37906
  1062
then ()
neuper@38046
  1063
else error "rational.sml: diff.behav. in norm_Rational_mg 22";
neuper@37906
  1064
neuper@37906
  1065
(*SRM.test Schalk I, p.68 Nr. 436b *)
neuper@37906
  1066
(*WN060420???MG3 crashes with method 'simplify' in 
neuper@37906
  1067
  IsacCore > Simplification > Rational Terms > Multiplication > No.2*)
neuper@37906
  1068
val t = str2term "5*a*(a - b)^^^2*(a + b)^^^3/(7*b*(a - b)^^^3) * 7*b/(a + b)^^^3";
neuper@37926
  1069
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1070
term2str t;
neuper@37906
  1071
if (term2str t) =
neuper@37906
  1072
"5 * a / (a + -1 * b)"
neuper@37906
  1073
then ()
neuper@38046
  1074
else error "rational.sml: diff.behav. in norm_Rational_mg 23";
neuper@37906
  1075
neuper@37906
  1076
(*Schalk I, p.68 Nr. 437a *)
neuper@37906
  1077
val t = str2term "(3*a - 4*b)/(4*c+3*e) * (3*a+4*b)/(9*a^^^2 - 16*b^^^2)";
neuper@37926
  1078
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1079
if (term2str t) = "1 / (4 * c + 3 * e)" then ()
neuper@38046
  1080
else error "rational.sml: diff.behav. in norm_Rational_mg 24";
neuper@37906
  1081
neuper@37906
  1082
"----- S.K. corrected non-termination 060904";
neuper@37906
  1083
val t = str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a^^^2 - 16*b^^^2))";
neuper@37926
  1084
val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
neuper@41932
  1085
term2str t';
neuper@41932
  1086
if term2str t' = 
neuper@41933
  1087
  "(9 * a ^^^ 2 + -16 * b ^^^ 2) /\n(36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c +\n -48 * b ^^^ 2 * e)"
neuper@41932
  1088
(*"(9 * a ^^^ 2 + -16 * b ^^^ 2) / (36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c + -48 * b ^^^ 2 * e)"*)
neuper@41932
  1089
then () else error "rational.sml: S.K.8..corrected 060904-6";
neuper@37906
  1090
neuper@37906
  1091
"----- S.K. corrected non-termination of cancel_p_";
neuper@38046
  1092
val t'' = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
neuper@38046
  1093
"(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
neuper@37926
  1094
val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
neuper@37906
  1095
if term2str t' = "1 / (4 * c + 3 * e)" then ()
neuper@38046
  1096
else error "rational.sml: diff.behav. in cancel_p S.K.8";
neuper@37906
  1097
neuper@37906
  1098
(*Schalk I, p.68 Nr. 437b *)
neuper@37906
  1099
(* nonterm.SK9 loops: cancel_p kann nicht weiter kuerzen!!! *)
neuper@37906
  1100
val t'' = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
neuper@37926
  1101
(* val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t'';
neuper@37906
  1102
   *)
neuper@37906
  1103
neuper@38046
  1104
"================delete===";
neuper@37906
  1105
(*a casual output from above*)
neuper@37906
  1106
val t = str2term 
neuper@37906
  1107
"(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)"; 
neuper@37906
  1108
(* WN060831 nonterm.SK10 
neuper@37926
  1109
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1110
term2str t;
neuper@37906
  1111
*)
neuper@37906
  1112
neuper@37906
  1113
(*SRM Schalk I, p.68 Nr. 438a *)
neuper@37906
  1114
val t = str2term 
neuper@37906
  1115
"x*y/(x*y - y^^^2)*(x^^^2 - x*y)";
neuper@37926
  1116
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1117
term2str t;
neuper@37906
  1118
if (term2str t) =
neuper@37906
  1119
"x ^^^ 2"
neuper@37906
  1120
then ()
neuper@38046
  1121
else error "rational.sml: diff.behav. in norm_Rational_mg 24";
neuper@37906
  1122
neuper@37906
  1123
(*SRM Schalk I, p.68 Nr. 439b *)
neuper@37906
  1124
val t = str2term 
neuper@37906
  1125
"(4*x^^^2+4*x+1)*((x^^^2 - 2*x^^^3)/(4*x^^^2+2*x))";
neuper@37926
  1126
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1127
term2str t;
neuper@37906
  1128
if (term2str t) =
neuper@37906
  1129
"(x + -4 * x ^^^ 3) / 2"
neuper@37906
  1130
then ()
neuper@38046
  1131
else error "rational.sml: diff.behav. in norm_Rational_mg 25";
neuper@37906
  1132
neuper@37906
  1133
(*SRM Schalk I, p.68 Nr. 440a *)
neuper@37906
  1134
val t = str2term 
neuper@37906
  1135
"(x^^^2 - 2*x)/(x^^^2 - 3*x) * (x - 3)^^^2/(x^^^2 - 4)";
neuper@37926
  1136
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1137
term2str t;
neuper@37906
  1138
if (term2str t) =
neuper@37906
  1139
"(-3 + x) / (2 + x)"
neuper@37906
  1140
then ()
neuper@38046
  1141
else error "rational.sml: diff.behav. in norm_Rational_mg 26";
neuper@37906
  1142
neuper@37906
  1143
"----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
neuper@37906
  1144
val t = str2term 
neuper@37906
  1145
"(a^^^3 - 9*a)/(a^^^3*b - a*b^^^3)*(a^^^2*b+a*b^^^2)/(a+3)";
neuper@37926
  1146
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1147
if term2str t = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
neuper@38046
  1148
else error "rational.sml: diff.behav. in norm_Rational 27";
neuper@37906
  1149
neuper@37906
  1150
"----- SK12 works since 0707xx";
neuper@37906
  1151
val t = str2term "(a^^^3 - 9*a)*(a^^^2*b+a*b^^^2)/((a^^^3*b - a*b^^^3)*(a+3))";
neuper@37926
  1152
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
  1153
if term2str t' = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
neuper@38046
  1154
else error "rational.sml: diff.behav. in norm_Rational 28";
neuper@37906
  1155
neuper@37906
  1156
neuper@38041
  1157
"-------- common denominator and multiplication ---------";
neuper@38041
  1158
"-------- common denominator and multiplication ---------";
neuper@38041
  1159
"-------- common denominator and multiplication ---------";
neuper@37906
  1160
(*SRAM Schalk I, p.69 Nr. 441b *)
neuper@37906
  1161
val t = str2term "(4*a/3 + 3*b^^^2/a^^^3 + b/(4*a))*(4*b/(3*a))";
neuper@37926
  1162
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1163
term2str t;
neuper@37906
  1164
if (term2str t) =
neuper@41932
  1165
  "(36 * b ^^^ 3 + 3 * a ^^^ 2 * b ^^^ 2 + 16 * a ^^^ 4 * b) / (9 * a ^^^ 4)"
neuper@38046
  1166
then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
neuper@37906
  1167
neuper@37906
  1168
(*SRAM Schalk I, p.69 Nr. 442b *)
neuper@37906
  1169
val t = str2term "(15*a^^^2/x^^^3 - 5*b^^^4/x^^^2 + 25*c^^^2/x)*(x^^^3/(5*a*b^^^3*c^^^3)) + 1/c^^^3 * (b*x/a - 3*a/b^^^3)";
neuper@37926
  1170
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1171
term2str t;
neuper@37906
  1172
if (term2str t) =
neuper@37906
  1173
"5 * x ^^^ 2 / (a * b ^^^ 3 * c)"
neuper@38046
  1174
then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
neuper@37906
  1175
neuper@37906
  1176
(*SRAM Schalk I, p.69 Nr. 443b *)
neuper@37906
  1177
val t = str2term "(a/2 + b/3)*(b/3 - a/2)";
neuper@37926
  1178
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1179
term2str t;
neuper@37906
  1180
if (term2str t) =
neuper@37906
  1181
"(-9 * a ^^^ 2 + 4 * b ^^^ 2) / 36"
neuper@38046
  1182
then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
neuper@37906
  1183
neuper@37906
  1184
(*SRAM Schalk I, p.69 Nr. 445b *)
neuper@37906
  1185
val t = str2term "(a^^^2/9 + 2*a/(3*b) + 4/b^^^2)*(a/3 - 2/b) + 8/b^^^3";
neuper@37926
  1186
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1187
term2str t;
neuper@37906
  1188
if (term2str t) =
neuper@37906
  1189
"a ^^^ 3 / 27"
neuper@38046
  1190
then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
neuper@37906
  1191
neuper@37906
  1192
(*SRAM Schalk I, p.69 Nr. 446b *)
neuper@37906
  1193
val t = str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x^^^2 - 16*y^^^2)";
neuper@37926
  1194
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1195
term2str t;
neuper@37906
  1196
if (term2str t) =
neuper@37906
  1197
"30 * x ^^^ 2 + -9 * x * y + -20 * y ^^^ 2"
neuper@37906
  1198
then ()
neuper@38046
  1199
else error "rational.sml: diff.behav. in norm_Rational_mg 32";
neuper@37906
  1200
neuper@37906
  1201
(*SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
neuper@37906
  1202
val t = str2term 
neuper@37906
  1203
"(2*x^^^2/(3*y)+x/y^^^2)*(4*x^^^4/(9*y^^^2)+x^^^2/y^^^4)*(2*x^^^2/(3*y) - x/y^^^2)";
neuper@37926
  1204
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1205
term2str t;
neuper@38046
  1206
if (term2str t) = "(-81 * x ^^^ 4 + 16 * x ^^^ 8 * y ^^^ 4) / (81 * y ^^^ 8)"
neuper@38046
  1207
then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
neuper@38046
  1208
neuper@37906
  1209
neuper@37906
  1210
(*SRAM Schalk I, p.69 Nr. 450a *)
neuper@37906
  1211
val t = str2term 
neuper@37906
  1212
"(4*x/(3*y)+2*y/(3*x))^^^2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
neuper@37926
  1213
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1214
term2str t;
neuper@37906
  1215
if (term2str t) =
neuper@37906
  1216
"(52 * x ^^^ 2 + 16 * y ^^^ 2) / (9 * y ^^^ 2)"
neuper@37906
  1217
then ()
neuper@38046
  1218
else error "rational.sml: diff.behav. in norm_Rational_mg 34";
neuper@37906
  1219
neuper@37906
  1220
neuper@38041
  1221
"-------- double fractions ------------------------------";
neuper@38041
  1222
"-------- double fractions ------------------------------";
neuper@38041
  1223
"-------- double fractions ------------------------------";
neuper@37906
  1224
(*SRD Schalk I, p.69 Nr. 454b *)
neuper@37906
  1225
val t = str2term 
neuper@37906
  1226
"((2 - x)/(2*a)) / (2*a/(x - 2))";
neuper@37926
  1227
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1228
term2str t;
neuper@37906
  1229
if (term2str t) = 
neuper@37906
  1230
"(-4 + 4 * x + -1 * x ^^^ 2) / (4 * a ^^^ 2)"
neuper@37906
  1231
then ()
neuper@38046
  1232
else error "rational.sml: diff.behav. in norm_Rational_mg 35";
neuper@37906
  1233
neuper@37906
  1234
(*SRD Schalk I, p.69 Nr. 455a *)
neuper@37906
  1235
val t = str2term 
neuper@37906
  1236
"(a^^^2 + 1)/(a^^^2 - 1) / ((a+1)/(a - 1))";
neuper@37926
  1237
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1238
term2str t;
neuper@37906
  1239
if (term2str t) = 
neuper@37906
  1240
"(1 + a ^^^ 2) / (1 + 2 * a + a ^^^ 2)" then ()
neuper@38046
  1241
else error "rational.sml: diff.behav. in norm_Rational_mg 36";
neuper@37906
  1242
neuper@37906
  1243
neuper@37906
  1244
"----- Schalk I, p.69 Nr. 455b";
neuper@37906
  1245
val t = str2term "(x^^^2 - 4)/(y^^^2 - 9)/((2+x)/(3 - y))";
neuper@37926
  1246
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1247
if term2str t = "(2 + -1 * x) / (3 + y)" then ()
neuper@38046
  1248
else error "rational.sml: diff.behav. in norm_Rational_mg 37";
neuper@37906
  1249
neuper@37906
  1250
"----- SK060904-1a non-termination of cancel_p_ ?: worked before 0707xx";
neuper@37906
  1251
val t = str2term "(x^^^2 - 4)*(3 - y)/((y^^^2 - 9)*(2+x))";
neuper@37926
  1252
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1253
if term2str t = "(2 + -1 * x) / (3 + y)" then ()
neuper@38046
  1254
else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
neuper@37906
  1255
neuper@37906
  1256
"----- ?: worked before 0707xx";
neuper@37906
  1257
val t = str2term "(3 + -1 * y) / (-9 + y ^^^ 2)";
neuper@37926
  1258
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1259
if term2str t = "-1 / (3 + y)" then ()
neuper@38031
  1260
else error "rational.sml: -1 / (3 + y) norm_Rational";
neuper@37906
  1261
neuper@37906
  1262
(*SRD Schalk I, p.69 Nr. 456b *)
neuper@37906
  1263
val t = str2term 
neuper@37906
  1264
"(b^^^3 - b^^^2)/(b^^^2+b)/(b^^^2 - 1)";
neuper@37926
  1265
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1266
term2str t;
neuper@37906
  1267
if (term2str t) = "b / (1 + 2 * b + b ^^^ 2)" then ()
neuper@38046
  1268
else error "rational.sml: diff.behav. in norm_Rational_mg 38";
neuper@37906
  1269
neuper@37906
  1270
(*SRD Schalk I, p.69 Nr. 457b *)
neuper@37906
  1271
val t = str2term 
neuper@37906
  1272
"(16*a^^^2 - 9*b^^^2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a^^^2 - 9*a^^^2*b^^^2))";
neuper@37926
  1273
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1274
term2str t;
neuper@37906
  1275
if (term2str t) = 
neuper@41932
  1276
  "8 * a ^^^ 2 + -6 * a * b + -12 * a ^^^ 2 * b + 9 * a * b ^^^ 2"
neuper@41932
  1277
then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
neuper@37906
  1278
neuper@37906
  1279
"----- Schalk I, p.69 Nr. 458b works since 0707";
neuper@37906
  1280
val t = str2term 
neuper@37906
  1281
"(2*a^^^2*x - a^^^2)/(a*x - b*x) / (b^^^2*(2*x - 1)/(x*(a - b)))";
neuper@37926
  1282
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1283
if term2str t = "a ^^^ 2 / b ^^^ 2" then ()
neuper@38046
  1284
else error "rational.sml: diff.behav. in norm_Rational_mg 39b";
neuper@37906
  1285
neuper@37906
  1286
(*SRD Schalk I, p.69 Nr. 459b *)
neuper@37906
  1287
val t = str2term "(a^^^2 - b^^^2)/(a*b) / (4*(a+b)^^^2/a)";
neuper@37926
  1288
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1289
if term2str t = "(a + -1 * b) / (4 * a * b + 4 * b ^^^ 2)" then ()
neuper@38046
  1290
else error "rational.sml: diff.behav. in norm_Rational_mg 41";
neuper@37906
  1291
neuper@37906
  1292
neuper@37906
  1293
(*Schalk I, p.69 Nr. 460b nonterm.SK
neuper@37906
  1294
val t = str2term 
neuper@37906
  1295
"(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
neuper@37926
  1296
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1297
if term2str t = 
neuper@37906
  1298
then ()
neuper@38046
  1299
else error "rational.sml: diff.behav. in norm_Rational_mg 42";
neuper@37906
  1300
neuper@37906
  1301
val t = str2term 
neuper@37906
  1302
"9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
neuper@37926
  1303
val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1304
... non terminating.
neuper@37926
  1305
val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
  1306
"(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)";
neuper@37926
  1307
val SOME (t,_) = rewrite_set_ thy false cancel_p t';
neuper@37906
  1308
... non terminating.*)
neuper@37906
  1309
neuper@37906
  1310
(*SRD Schalk I, p.70 Nr. 472a *)
neuper@38046
  1311
val t = str2term ("((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/" ^
neuper@38046
  1312
		 "((4*x - 8*y)/(x + y))");
neuper@37926
  1313
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1314
term2str t;
neuper@37906
  1315
if (term2str t) = 
neuper@37906
  1316
"x + y"
neuper@37906
  1317
then ()
neuper@38046
  1318
else error "rational.sml: diff.behav. in norm_Rational_mg 43";
neuper@37906
  1319
neuper@37906
  1320
neuper@37906
  1321
(*----------------------------------------------------------------------*)
neuper@37906
  1322
(*---------------------- Einfache Dppelbrche --------------------------*)
neuper@37906
  1323
(*----------------------------------------------------------------------*)
neuper@37906
  1324
neuper@37906
  1325
(*SRD Schalk I, p.69 Nr. 461a *)
neuper@37906
  1326
val t = str2term 
neuper@37906
  1327
"(2/(x+3) + 2/(x - 3)) / (8*x/(x^^^2 - 9))";
neuper@37926
  1328
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1329
term2str t;
neuper@37906
  1330
if (term2str t) = 
neuper@37906
  1331
"1 / 2"
neuper@37906
  1332
then ()
neuper@38046
  1333
else error "rational.sml: diff.behav. in norm_Rational_mg 44";
neuper@37906
  1334
neuper@37906
  1335
(*SRD Schalk I, p.69 Nr. 464b *)
neuper@37906
  1336
val t = str2term 
neuper@37906
  1337
"(a - a/(a - 2)) / (a + a/(a - 2))";
neuper@37926
  1338
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1339
term2str t;
neuper@37906
  1340
if (term2str t) = 
neuper@37906
  1341
"(3 + -1 * a) / (1 + -1 * a)"
neuper@37906
  1342
then ()
neuper@38046
  1343
else error "rational.sml: diff.behav. in norm_Rational_mg 45";
neuper@37906
  1344
neuper@37906
  1345
(*SRD Schalk I, p.69 Nr. 465b *)
neuper@37906
  1346
val t = str2term 
neuper@37906
  1347
"((x+3*y)/9 + (4*y^^^2 - 9*z^^^2)/(16*x)) /(x/9+y/6+z/4)";
neuper@37926
  1348
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1349
term2str t;
neuper@37906
  1350
if (term2str t) = 
neuper@37906
  1351
"(4 * x + 6 * y + -9 * z) / (4 * x)"
neuper@37906
  1352
then ()
neuper@38046
  1353
else error "rational.sml: diff.behav. in norm_Rational_mg 46";
neuper@37906
  1354
neuper@37906
  1355
(*SRD Schalk I, p.69 Nr. 466b *)
neuper@37906
  1356
val t = str2term 
neuper@37906
  1357
"((1 - 7*(x - 2)/(x^^^2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x^^^2 - 25))";
neuper@37926
  1358
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1359
term2str t;
neuper@37906
  1360
if (term2str t) = 
neuper@37906
  1361
"(25 + -10 * x + x ^^^ 2) / 18"
neuper@37906
  1362
then ()
neuper@38046
  1363
else error "rational.sml: diff.behav. in norm_Rational_mg 47";
neuper@37906
  1364
neuper@37906
  1365
(*SRD Schalk I, p.70 Nr. 469 *)
neuper@37906
  1366
val t = str2term 
neuper@37906
  1367
"3*b^^^2/(4*a^^^2 - 8*a*b + 4*b^^^2)/(a/(a^^^2*b - b^^^3) + (a - b)/(4*a*b^^^2+4*b^^^3) - 1/(4*b^^^2))";
neuper@37926
  1368
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1369
term2str t;
neuper@37906
  1370
if (term2str t) = 
neuper@37906
  1371
"3 * b ^^^ 3 / (2 * a + -2 * b)"
neuper@37906
  1372
then ()
neuper@38046
  1373
else error "rational.sml: diff.behav. in norm_Rational_mg 48";
neuper@37906
  1374
neuper@37906
  1375
(*----------------------------------------------------------------------*)
neuper@37906
  1376
(*---------------------- Mehrfache Dppelbrueche ------------------------*)
neuper@37906
  1377
(*----------------------------------------------------------------------*)
neuper@37906
  1378
neuper@37906
  1379
(*SRD.test Schalk I, p.70 Nr. 476b *) (* Rechenzeit: 10 sec *)
neuper@37906
  1380
(*WN060419 crashes with method 'simplify' ????SK*)
neuper@37906
  1381
val t = str2term 
neuper@37906
  1382
"((a^^^2 - b^^^2)/(2*a*b)+2*a*b/(a^^^2 - b^^^2))/((a^^^2+b^^^2)/(2*a*b)+1) / ((a^^^2+b^^^2)^^^2/(a+b)^^^2)";
neuper@37926
  1383
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1384
if term2str t = "1 / (a ^^^ 2 + -1 * b ^^^ 2)" then ()
neuper@38046
  1385
else error "rational.sml: diff.behav. in norm_Rational_mg 49";
neuper@37906
  1386
neuper@37906
  1387
"----- Schalk I, p.70 Nr. 477a";
neuper@37906
  1388
(* MG Achtung: terme explodieren; Bsp zu komplex; 
neuper@37906
  1389
   L???ung sollte (ziemlich grosser) Faktorisierter Ausdruck sein 
neuper@38041
  1390
val t = str2term "b*y/(b - 2*y)/((b^^^2 - y^^^2)/(b+2*y)) /" ^
neuper@38041
  1391
		 "(b^^^2*y+b*y^^^2)*(a+x)^^^2/((b^^^2 - 4*y^^^2)*(a+2*x)^^^2)";
neuper@37926
  1392
val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1393
neuper@37906
  1394
neuper@38041
  1395
val t = str2term "b*y*(b+2*y)*(b^^^2 - 4*y^^^2)*(a+2*x)^^^2 / " ^
neuper@38041
  1396
		 "((b - 2*y)*(b^^^2 - y^^^2)*(b^^^2*y+b*y^^^2)*(a+x)^^^2)";
neuper@37926
  1397
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
  1398
????SK ???MG*)
neuper@37906
  1399
neuper@37906
  1400
neuper@37906
  1401
"----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
neuper@38046
  1402
val t = str2term ("(a - (a*b+b^^^2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
neuper@38046
  1403
		 "((a - a^^^2/(a+b))/(a+(a*b)/(a - b)))");
neuper@37926
  1404
val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1405
if term2str t' = 
neuper@37906
  1406
"(2 * a ^^^ 3 + 2 * a ^^^ 2 * b) / (a ^^^ 2 * b + b ^^^ 3)"
neuper@37906
  1407
then ()
neuper@38046
  1408
else error "rational.sml: diff.behav. in norm_Rational_mg 51";
neuper@37906
  1409
neuper@37906
  1410
(* TODO.new_c:WN050820 STOP_REW_SUB introduced gave ...
neuper@38041
  1411
if term2str t' = "(a ^^^ 4 + -1 * a ^^^ 2 * b ^^^ 2) /(a * b * (b + (a * (a + -1 * b) + -1 * b * (a + -1 * b)) / (2 * a)) * (a + -1 * b))" then ()
neuper@38031
  1412
else error "rational.sml: works again";
neuper@37906
  1413
re-outcommented with TODO.new_c: cvs before 071227, 11:50*)
neuper@37906
  1414
neuper@37906
  1415
neuper@37906
  1416
neuper@37906
  1417
(*Schalk I, p.70 Nr. 480a *)
neuper@37906
  1418
(* Achtung: rechnet ewig; cancel_p kann nicht krzen: WN060831 nonterm.SK00
neuper@37906
  1419
val t = str2term 
neuper@37906
  1420
"(1/x+1/y+1/z)/(1/x - 1/y - 1/z) / (2*x^^^2/(x^^^2 - z^^^2)/(x/(x+z)+x/(x - z)))";
neuper@37926
  1421
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1422
term2str t;
neuper@37906
  1423
if (term2str t) = 
neuper@37906
  1424
neuper@37906
  1425
then ()
neuper@38046
  1426
else error "rational.sml: diff.behav. in norm_Rational_mg 52";
neuper@37906
  1427
neuper@37906
  1428
(*MG Berechne Zwischenergebnisse: WN060831 nonterm.SK00*)
neuper@37906
  1429
val t = str2term 
neuper@37906
  1430
"(1/x+1/y+1/z)/(1/x - 1/y - 1/z)";
neuper@37926
  1431
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1432
term2str t;
neuper@37906
  1433
"(x ^^^ 2 * y ^^^ 2 * z + x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2) /
neuper@37906
  1434
(-1 * x ^^^ 2 * y ^^^ 2 * z + -1 * x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2)";
neuper@37906
  1435
val t = str2term 
neuper@37906
  1436
"2*x^^^2/(x^^^2 - z^^^2)/(x/(x+z)+x/(x - z))";
neuper@37926
  1437
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1438
term2str t;
neuper@37906
  1439
"1"
neuper@37906
  1440
neuper@37906
  1441
(* SK 1. Ausdruck kann nicht weiter gekrzt werden; cancel_p !!!*)
neuper@37906
  1442
###  rls: cancel_p on: 
neuper@37906
  1443
(x ^^^ 2 * (y ^^^ 2 * z) + x ^^^ 2 * (y * z ^^^ 2) + x * (y ^^^ 2 * z ^^^ 2)) /
neuper@37906
  1444
(-1 * (x ^^^ 2 * (y ^^^ 2 * z)) + -1 * (x ^^^ 2 * (y * z ^^^ 2)) + x * (y ^^^ 2 * z ^^^ 2))
neuper@37906
  1445
GC #3.61.81.101.197.17503:   (0 ms)
neuper@37906
  1446
*** RATIONALS_DIRECT_CANCEL_EXCEPTION: Invalid fraction
neuper@37906
  1447
neuper@37906
  1448
val t = str2term 
neuper@37906
  1449
"(x^^^2 * (y^^^2 * z) + x^^^2 * (y * z^^^2) + x * (y^^^2 * z^^^2)) / (-1 * (x^^^2 * (y^^^2 * z)) + -1 * (x^^^2 * (y * z^^^2)) + x * (y^^^2 * z^^^2))";
neuper@37926
  1450
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1451
term2str t;
neuper@37906
  1452
(*uncaught exception nonexhaustive binding failure*)
neuper@37906
  1453
neuper@37906
  1454
(* Das kann er aber krzen !!????: *)
neuper@37906
  1455
val t = str2term 
neuper@37906
  1456
"(x^^^2 * (y^^^2 * z) +  x * (y^^^2 * z^^^2)) / (-1 * (x^^^2 * (y * z^^^2)) + x * (y^^^2 * z^^^2))";
neuper@37926
  1457
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1458
term2str t;
neuper@37906
  1459
"(-1 * (y * x) + -1 * (z * y)) / (1 * (z * x) + -1 * (z * y))";
neuper@37906
  1460
*)
neuper@37906
  1461
neuper@37906
  1462
neuper@38041
  1463
"-------- crucial examples ------------------------------";
neuper@38041
  1464
"-------- crucial examples ------------------------------";
neuper@38041
  1465
"-------- crucial examples ------------------------------";
neuper@37906
  1466
(*Schalk I, p.60 Nr. 215d *)
neuper@37906
  1467
(* Achtung: rechnet ewig ...
neuper@37906
  1468
val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
neuper@37926
  1469
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1470
term2str t; noterm.SK
neuper@37906
  1471
*)
neuper@37906
  1472
neuper@37906
  1473
(* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt:*)
neuper@37906
  1474
(*
neuper@37906
  1475
val t = str2term "(a-b)^^^3 * (x+y)^^^4";
neuper@37926
  1476
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1477
term2str t;
neuper@38041
  1478
"a^^^3 * x^^^4 + 4 * a^^^3 * x^^^3 * y +6 * a^^^3 * x^^^2 * y^^^2 +4 * a^^^3 * x * y^^^3 +a^^^3 * y^^^4 +-3 * a^^^2 * b * x^^^4 +-12 * a^^^2 * b * x^^^3 * y +-18 * a^^^2 * b * x^^^2 * y^^^2 +-12 * a^^^2 * b * x * y^^^3 +-3 * a^^^2 * b * y^^^4 +3 * a * b^^^2 * x^^^4 +12 * a * b^^^2 * x^^^3 * y +18 * a * b^^^2 * x^^^2 * y^^^2 +12 * a * b^^^2 * x * y^^^3 +3 * a * b^^^2 * y^^^4 +-1 * b^^^3 * x^^^4 +-4 * b^^^3 * x^^^3 * y +-6 * b^^^3 * x^^^2 * y^^^2 +-4 * b^^^3 * x * y^^^3 +-1 * b^^^3 * y^^^4";
neuper@37906
  1479
val t = str2term "((x+y)^^^2 * (a-b)^^^5)";
neuper@37926
  1480
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1481
term2str t;
neuper@38041
  1482
"a^^^5 * x^^^2 + 2 * a^^^5 * x * y + a^^^5 * y^^^2 +-5 * a^^^4 * b * x^^^2 +-10 * a^^^4 * b * x * y +-5 * a^^^4 * b * y^^^2 +10 * a^^^3 * b^^^2 * x^^^2 +20 * a^^^3 * b^^^2 * x * y +10 * a^^^3 * b^^^2 * y^^^2 +-10 * a^^^2 * b^^^3 * x^^^2 +-20 * a^^^2 * b^^^3 * x * y +-10 * a^^^2 * b^^^3 * y^^^2 +5 * a * b^^^4 * x^^^2 +10 * a * b^^^4 * x * y +5 * a * b^^^4 * y^^^2 +-1 * b^^^5 * x^^^2 +-2 * b^^^5 * x * y +-1 * b^^^5 * y^^^2";
neuper@37906
  1483
*)
neuper@37906
  1484
(*anscheinend macht dem Rechner das Krzen diese Bruches keinen Spass mehr ...*)
neuper@37906
  1485
neuper@37906
  1486
(*--------------------------------------------------------------------*)
neuper@37906
  1487
(*Schalk I, p.70 Nr. 480b 
neuper@38041
  1488
val t = str2term "((12*x*y/(9*x^^^2 - y^^^2))/" ^
neuper@38041
  1489
		 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
neuper@38041
  1490
		 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
neuper@38041
  1491
		 "(20*x*y/(x^^^2 - 25*y^^^2))";
neuper@37926
  1492
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1493
SK.nonterm
neuper@37906
  1494
Kann nicht weiter vereinfacht werden !!!!?? *)
neuper@37906
  1495
neuper@37906
  1496
(*--------------------------------------------------------------------*)
neuper@37906
  1497
"---- MGs test set";
neuper@37906
  1498
val t = str2term " (1 + x^^^5) / (y + x) + x^^^3 / x ";
neuper@37926
  1499
val SOME (t,_) = rewrite_set_ thy false common_nominator_p t;
neuper@37906
  1500
if term2str t = "(1 + x ^^^ 3 + x ^^^ 5 + y * x ^^^ 2) / (x + y)" then()
neuper@38031
  1501
else error "";
neuper@37906
  1502
neuper@37906
  1503
(*--------------------------------------------------------------------*)
neuper@37906
  1504
(* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3b
neuper@37906
  1505
   ---> Sortierung FALSCH !!  *)
neuper@37906
  1506
val t = str2term "b^^^3 * a^^^5/a ";
neuper@37926
  1507
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1508
term2str t;
neuper@37906
  1509
"1 * (a^^^4 * b^^^3) / 1"; (*OK*)
neuper@37906
  1510
neuper@37906
  1511
val t = str2term "b^^^3 * a^^^5/b ";
neuper@37926
  1512
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1513
term2str t;
neuper@37906
  1514
"1 * (b^^^2 * a^^^5) / 1"; (*cancel_p sortiert hier falsch um!*)
neuper@37906
  1515
neuper@37906
  1516
(* Problem liegt NICHT bei ord_make_polynomial! (siehe folgende Bsple) *)
neuper@37906
  1517
(*
neuper@37906
  1518
val x = str2term "x"; val bdv = str2term "bdv";
neuper@37906
  1519
val t1 = str2term "b^^^2 * a^^^5";
neuper@37906
  1520
val t2 = str2term "a^^^5 * b^^^2 ";
neuper@37906
  1521
ord_make_polynomial false Rational.thy [(x,bdv)] (t1,t2); (*false*)
neuper@37906
  1522
*)
neuper@37906
  1523
(* ==> "b^^^2 * a^^^5" > "a^^^5 * b^^^2 " ... OK!*)
neuper@37906
  1524
neuper@37906
  1525
(*--------------------------------------------------------------------*)
neuper@37906
  1526
(* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3c
neuper@37906
  1527
   ---> erzeugt berflssige "1 * ..."
neuper@37906
  1528
   
neuper@37906
  1529
val t = str2term "-1 / (3 + y)";
neuper@37906
  1530
(*~~         *)
neuper@37926
  1531
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1532
term2str t;
neuper@37906
  1533
"-1 / (3 + 1 * y)";
neuper@37906
  1534
(********* Das ist das PROBLEM !!!!!!!??? *******************)
neuper@37906
  1535
(* -1 im Z???ler der Angabe verursacht das Problem !*)
neuper@37906
  1536
*)
neuper@37906
  1537
neuper@37906
  1538
(* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
neuper@37906
  1539
"----- MGs test set";
neuper@37906
  1540
val t = str2term "(a^^^2 + -1)/(a+1)";
neuper@37926
  1541
val SOME (t',_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1542
if term2str t' = "(-1 + a) / 1" then ()
neuper@38031
  1543
else error "rational.sml MG tests 3d";
neuper@37906
  1544
neuper@37906
  1545
"----- NOT TERMINATING ?: worked before 0707xx";
neuper@37906
  1546
val t = str2term "(a^^^2 - 1)*(b + 1) / ((b^^^2 - 1)*(a+1))";
neuper@37926
  1547
val SOME (t'',_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1548
if term2str t'' = "(1 + -1 * a) / (1 + -1 * b)" then ()
neuper@38031
  1549
else error "rational.sml MG tests 3e";
neuper@37906
  1550
neuper@37906
  1551
"----- corrected SK060905";
neuper@37906
  1552
val t = str2term "(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
neuper@37926
  1553
val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1554
if term2str t' = "-1 / (5 + -2 * x)" then ()
neuper@38031
  1555
else error "rational.sml corrected SK060905";
neuper@37906
  1556
neuper@37906
  1557
neuper@38041
  1558
"-------- examples for Stefan Karnels thesis ------------";
neuper@38041
  1559
"-------- examples for Stefan Karnels thesis ------------";
neuper@38041
  1560
"-------- examples for Stefan Karnels thesis ------------";
neuper@37906
  1561
(*SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*)
neuper@37906
  1562
val t = str2term 
neuper@37906
  1563
"(15*a^^^4/(a*x^^^3) - 5*a*((b^^^4 - 5*c^^^2*x)/x^^^2))*(x^^^3/(5*a*b^^^3*c^^^3)) + a/c^^^3 * (x*(b/a) - 3*b*(a/b^^^4))";
neuper@37926
  1564
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1565
term2str t;
neuper@37906
  1566
if (term2str t) =
neuper@37906
  1567
"5 * x ^^^ 2 / (b ^^^ 3 * c)"
neuper@37906
  1568
then ()
neuper@38046
  1569
else error "rational.sml: diff.behav. in norm_Rational_mg 53";
neuper@38046
  1570
neuper@37906
  1571
neuper@38041
  1572
"-------- me Schalk I No.186 ----------------------------";
neuper@38041
  1573
"-------- me Schalk I No.186 ----------------------------";
neuper@38041
  1574
"-------- me Schalk I No.186 ----------------------------";
neuper@38083
  1575
val fmz = ["Term ((14 * x * y) / ( x * y ))",
neuper@37906
  1576
	   "normalform N"];
neuper@37906
  1577
val (dI',pI',mI') =
neuper@37991
  1578
  ("Rational",["rational","simplification"],
neuper@37906
  1579
   ["simplification","of_rationals"]);
neuper@37906
  1580
val p = e_pos'; val c = []; 
neuper@37906
  1581
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@37906
  1582
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1583
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1584
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1585
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1586
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1587
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1588
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1589
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
  1590
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
  1591
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
neuper@37906
  1592
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
neuper@37906
  1593
case (f2str f, nxt) of
neuper@37906
  1594
    ("14", ("End_Proof'", _)) => ()
neuper@38031
  1595
  | _ => error "rational.sml diff.behav. in me Schalk I No.186";
neuper@37906
  1596
neuper@37906
  1597
neuper@38041
  1598
"-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
neuper@38041
  1599
"-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
neuper@38041
  1600
"-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
neuper@37906
  1601
states:=[];
neuper@37906
  1602
CalcTree
neuper@38083
  1603
[(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"], 
neuper@37991
  1604
  ("Rational",["rational","simplification"],
neuper@37906
  1605
  ["simplification","of_rationals"]))];
neuper@37906
  1606
Iterator 1;
neuper@37906
  1607
moveActiveRoot 1;
neuper@37906
  1608
autoCalculate 1 CompleteCalc;
neuper@37906
  1609
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
  1610
neuper@37906
  1611
interSteps 1 ([1],Res);
neuper@37906
  1612
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
  1613
neuper@37906
  1614
neuper@38041
  1615
"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
neuper@38041
  1616
"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
neuper@38041
  1617
"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
neuper@37906
  1618
states:=[];
neuper@37906
  1619
CalcTree
neuper@38083
  1620
[(["Term ((a^2 + -1*b^2) / (a^2 + -2*a*b + b^2))", "normalform N"], 
neuper@37991
  1621
  ("Rational",["rational","simplification"],
neuper@37906
  1622
  ["simplification","of_rationals"]))];
neuper@37906
  1623
Iterator 1;
neuper@37906
  1624
moveActiveRoot 1;
neuper@37906
  1625
autoCalculate 1 CompleteCalc;
neuper@37906
  1626
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@41930
  1627
(*========== inhibit exn 110314 ================================================
neuper@37906
  1628
(*with explicit script done already... and removed [1,..] at below...
neuper@37906
  1629
interSteps 1 ([1],Res);
neuper@37906
  1630
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
  1631
*)
neuper@37906
  1632
interSteps 1 ([2],Res);
neuper@37906
  1633
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
  1634
neuper@37906
  1635
interSteps 1 ([2,1],Res);
neuper@37906
  1636
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
  1637
val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*);
neuper@37906
  1638
(*if length newnds = 12 then () WN060905*)
neuper@37906
  1639
if length newnds = 13 then ()
neuper@38031
  1640
else error "rational.sml: interSteps cancel_p rev_rew_p";
neuper@37906
  1641
neuper@37906
  1642
val p = ([2,1,9],Res);
neuper@37906
  1643
getTactic 1 p;
neuper@37906
  1644
val (_, tac, _) = pt_extract (pt, p);
neuper@37926
  1645
(*case tac of SOME (Rewrite ("sym_real_plus_binom_times1", _)) => ()
neuper@37906
  1646
WN060905*)
neuper@37926
  1647
case tac of SOME (Rewrite ("sym_real_add_mult_distrib2", _)) => ()
neuper@38031
  1648
| _ => error "rational.sml: getTactic, sym_real_plus_binom_times1";
neuper@41930
  1649
============ inhibit exn 110314 ==============================================*)
neuper@37906
  1650
neuper@37906
  1651
neuper@38041
  1652
"-------- investigate rulesets for cancel_p -------------";
neuper@38041
  1653
"-------- investigate rulesets for cancel_p -------------";
neuper@38041
  1654
"-------- investigate rulesets for cancel_p -------------";
neuper@41930
  1655
val thy = @{theory "Rational"};
neuper@37906
  1656
"---------------- (a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
neuper@37906
  1657
val t = str2term "(a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
neuper@37906
  1658
val tt = str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"(*numerator only*);
neuper@37906
  1659
"----- with rewrite_set_";
neuper@37926
  1660
val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
neuper@37906
  1661
term2str tt'= "a ^^^ 2 + -1 * b ^^^ 2" (*true*);
neuper@37906
  1662
val tt = str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*);
neuper@37926
  1663
val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
neuper@37906
  1664
term2str tt' = "a ^^^ 2 + -2 * a * b + b ^^^ 2" (*true*);
neuper@37906
  1665
neuper@37906
  1666
"----- with make_deriv";
neuper@38046
  1667
val SOME (tt, _) = factout_p_ thy t; term2str tt =
neuper@37906
  1668
"(1 * a + 1 * b) * (1 * a + -1 * b) / ((1 * a + -1 * b) * (1 * a + -1 * b))";
neuper@37906
  1669
(*
neuper@37906
  1670
"--- with ruleset as before 060829";
neuper@37906
  1671
val {rules, rew_ord=(_,ro),...} =
neuper@37906
  1672
    rep_rls (assoc_rls "make_polynomial");
neuper@37926
  1673
val der = make_deriv thy Atools_erls rules ro NONE tt;
neuper@37906
  1674
print_depth 99; map (term2str o #1) der; print_depth 3;
neuper@37906
  1675
print_depth 99; map (rule2str o #2) der; print_depth 3;
neuper@38041
  1676
... did not terminate*)
neuper@37906
  1677
"--- with simpler ruleset";
neuper@37906
  1678
val {rules, rew_ord=(_,ro),...} =
neuper@37906
  1679
    rep_rls (assoc_rls "rev_rew_p");
neuper@37926
  1680
val der = make_deriv thy Atools_erls rules ro NONE tt;
neuper@37906
  1681
print_depth 99; writeln (deriv2str der); print_depth 3;
neuper@37906
  1682
neuper@37906
  1683
print_depth 99; map (term2str o #1) der; print_depth 3;
neuper@37906
  1684
"...,(-1 * b ^^^ 2 + a ^^^ 2) / (-2 * (a * b) + a ^^^ 2 + (-1 * b) ^^^ 2) ]";
neuper@37906
  1685
print_depth 99; map (rule2str o #2) der; print_depth 3;
neuper@37906
  1686
print_depth 99; map (term2str o #1 o #3) der; print_depth 3;
neuper@37906
  1687
neuper@37926
  1688
val der = make_deriv thy Atools_erls rules ro NONE 
neuper@37906
  1689
		     (str2term "(1 * a + 1 * b) * (1 * a + -1 * b)");
neuper@37906
  1690
print_depth 99; writeln (deriv2str der); print_depth 3;
neuper@37906
  1691
neuper@37906
  1692
val {rules, rew_ord=(_,ro),...} =
neuper@37906
  1693
    rep_rls (assoc_rls "rev_rew_p");
neuper@37926
  1694
val der = make_deriv thy Atools_erls rules ro NONE 
neuper@37906
  1695
		     (str2term "(1 * a + -1 * b) * (1 * a + -1 * b)");
neuper@37906
  1696
print_depth 99; writeln (deriv2str der); print_depth 3;
neuper@37906
  1697
print_depth 99; map (term2str o #1) der; print_depth 3;
neuper@37906
  1698
(*WN060829 ...postponed*)
neuper@37906
  1699
neuper@37906
  1700
neuper@38041
  1701
"-------- investigate format of factout_ and factout_p_ -";
neuper@38041
  1702
"-------- investigate format of factout_ and factout_p_ -";
neuper@38041
  1703
"-------- investigate format of factout_ and factout_p_ -";
neuper@37906
  1704
val {rules, rew_ord = (_,ro),...} = rep_rls (assoc_rls "make_polynomial");
neuper@41930
  1705
val (thy, eval_rls) = (@{theory "Rational"}, Atools_erls)(*see 'fun init_state'*);
neuper@37906
  1706
val Rrls {scr = Rfuns {init_state,...},...} = assoc_rls "cancel_p";
neuper@37906
  1707
neuper@38041
  1708
"----- see Rational.ML, local cancel_p, fun init_state";
neuper@37906
  1709
val t = str2term "(a^^^2 + (-1)*b^^^2) / (a^^^2 + (-2)*a*b + b^^^2)";
neuper@37926
  1710
val SOME (t',_) = factout_p_ thy t; term2str t';
neuper@37906
  1711
(*
neuper@37926
  1712
val rtas = reverse_deriv thy eval_rls rules ro NONE t';
neuper@37906
  1713
writeln(trtas2str rst);
neuper@37906
  1714
*)
neuper@37906
  1715
neuper@37906
  1716
neuper@38041
  1717
"----- see Rational.ML, local cancel_p, fun init_state";
neuper@37906
  1718
val t = str2term "a^^^2 / a";
neuper@37926
  1719
val SOME (t',_) = factout_p_ thy t; 
neuper@37906
  1720
term2str t' = "a * a / (1 * a)" (*true*); 
neuper@37906
  1721
(*... can be canceled with
neuper@37906
  1722
real_mult_div_cancel2 ?k ~= 0 ==> ?m * ?k / (?n * ?k) = ?m / ?n"*)
neuper@37906
  1723
(* sml/ME/rewtools.sml:
neuper@37926
  1724
val rtas = reverse_deriv thy Atools_erls rules ro NONE t';
neuper@37906
  1725
writeln (deri2str rtas);
neuper@37906
  1726
*)
neuper@37906
  1727
neuper@37906
  1728
neuper@37906
  1729
"-------- SK 060904 ----------------------------------------------";
neuper@37906
  1730
"----- order on polynomials -- input + output";
neuper@41929
  1731
val thy = @{theory "Isac"};
neuper@37906
  1732
val t = str2term "(a + -1 * b) / (-1 * a + b)";
neuper@37926
  1733
val SOME (t', _) = factout_p_ thy t; term2str t';
neuper@37926
  1734
val SOME (t', _) = cancel_p_ thy t; term2str t';
neuper@37906
  1735
neuper@37906
  1736
val t = str2term "a*b*c*d / (d*e*f*g)";
neuper@37926
  1737
val SOME (t', _) = cancel_p_ thy t; term2str t';
neuper@37906
  1738
neuper@37906
  1739
val t = str2term "a*(b*(c*d)) / (b*(e*(f*g)))";
neuper@37926
  1740
val SOME (t', _) = cancel_p_ thy t; term2str t';
neuper@37906
  1741
(*???order.SK  ???*)
neuper@37906
  1742
neuper@37906
  1743
"----- SK060904-1a non-termination of cancel_p_ ? worked before 0707xx";
neuper@37906
  1744
val t = str2term "(x^^^2 - 4)*(3 - y) / ((y^^^2 - 9)*(2+x))";
neuper@37926
  1745
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; 
neuper@37906
  1746
if term2str t' = "(2 + -1 * x) / (3 + y)" then ()
neuper@38031
  1747
else error "rational.sml SK060904-1a worked since 0707xx";
neuper@37906
  1748
neuper@37906
  1749
"----- SK060904-1b non-termination of cancel_p_ ... worked before 0707xx";
neuper@41930
  1750
val t = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
neuper@41930
  1751
"(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
neuper@37926
  1752
val SOME (t',_) = cancel_p_ thy t; 
neuper@37906
  1753
if term2str t' = "1 / (4 * c + 3 * e)" then ()
neuper@38031
  1754
else error "rational.sml SK060904-1b";
neuper@37906
  1755
neuper@37906
  1756
neuper@37906
  1757
"----- SK060904-2a non-termination of add_fraction_p_";
neuper@41930
  1758
val t = str2term (" (a + b * x) / (a + -1 * (b * x)) +  " ^
neuper@41930
  1759
		  " (-1 * a + b * x) / (a + b * x)      ");
neuper@37906
  1760
(* nonterm.SK
neuper@37926
  1761
val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
neuper@37906
  1762
neuper@37906
  1763
common_nominator_p_ thy t;
neuper@38041
  1764
" (a + b * x)*(a + b * x) / ((a + -1 * (b * x))*(a + -1 * (b * x))) +  " ^
neuper@38041
  1765
" (-1 * a + b * x)*(a + -1 * (b * x)) / ((a + b * x)*(-1 * a + b * x)) ";
neuper@37906
  1766
neuper@37906
  1767
add_fraction_p_ thy t; 
neuper@38041
  1768
" ((a + b * x)*(a + b * x)  +  (-1 * a + b * x)*(a + -1 * (b * x))) /" ^
neuper@38041
  1769
" ((a + b * x)*(-1 * a + b * x))                                     ";
neuper@37979
  1770
*)
neuper@37979
  1771
neuper@37979
  1772
neuper@38041
  1773
"-------- how to stepwise construct Scripts -------------";
neuper@38041
  1774
"-------- how to stepwise construct Scripts -------------";
neuper@38041
  1775
"-------- how to stepwise construct Scripts -------------";
neuper@41929
  1776
val thy = @{theory "Rational"};
neuper@37979
  1777
(*no trailing _*)
neuper@37979
  1778
val p1 = parse thy (
neuper@37979
  1779
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37980
  1780
"  (Rewrite_Set discard_minus False                   " ^
neuper@37979
  1781
"   t_t)");
neuper@37979
  1782
neuper@37979
  1783
(*required (): (Rewrite_Set discard_minus False)*)
neuper@37979
  1784
val p2 = parse thy (
neuper@37979
  1785
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37979
  1786
"  (Rewrite_Set discard_minus False                   " ^
neuper@37979
  1787
"   t_t)");
neuper@37979
  1788
neuper@37979
  1789
val p3 = parse thy (
neuper@37979
  1790
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37979
  1791
"  ((Rewrite_Set discard_minus False)                   " ^
neuper@37979
  1792
"   t_t)");
neuper@37979
  1793
neuper@37979
  1794
val p4 = parse thy (
neuper@37979
  1795
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37979
  1796
"  ((Rewrite_Set discard_minus False)                   " ^
neuper@37979
  1797
"   t_t)");
neuper@37979
  1798
neuper@37979
  1799
val p5 = parse thy (
neuper@37979
  1800
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37979
  1801
"  ((Try (Rewrite_Set discard_minus False)                   " ^
neuper@37979
  1802
"    Try (Rewrite_Set discard_parentheses False))               " ^
neuper@37979
  1803
"   t_t)");
neuper@37979
  1804
neuper@37979
  1805
val p6 = parse thy (
neuper@37979
  1806
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37979
  1807
"  ((Try (Rewrite_Set discard_minus False) @@                   " ^
neuper@37979
  1808
"    Try (Rewrite_Set rat_mult_poly False) @@                    " ^
neuper@37979
  1809
"    Try (Rewrite_Set make_rat_poly_with_parentheses False) @@   " ^
neuper@37979
  1810
"    Try (Rewrite_Set cancel_p_rls False) @@                     " ^
neuper@37979
  1811
"    (Repeat                                                     " ^
neuper@37979
  1812
"     ((Try (Rewrite_Set common_nominator_p_rls False) @@        " ^
neuper@37979
  1813
"       Try (Rewrite_Set rat_mult_div_pow False) @@              " ^
neuper@37979
  1814
"       Try (Rewrite_Set make_rat_poly_with_parentheses False) @@" ^
neuper@37979
  1815
"       Try (Rewrite_Set cancel_p_rls False) @@                  " ^
neuper@37979
  1816
"       Try (Rewrite_Set rat_reduce_1 False)))) @@               " ^
neuper@37979
  1817
"    Try (Rewrite_Set discard_parentheses False))               " ^
neuper@37979
  1818
"   t_t)"
neuper@37979
  1819
);
neuper@42301
  1820
neuper@42301
  1821
"----------- get_denominator ----------------------------";
neuper@42301
  1822
"----------- get_denominator ----------------------------";
neuper@42301
  1823
"----------- get_denominator ----------------------------";
neuper@42301
  1824
val thy = @{theory Isac};
neuper@42301
  1825
val t = term_of (the (parse thy "get_denominator ((a +x)/b)"));
neuper@42301
  1826
val SOME (_, t') = eval_get_denominator "" 0 t thy;
neuper@42301
  1827
if term2str t' = "get_denominator ((a + x) / b) = b" then ()
neuper@42301
  1828
else error "get_denominator ((a + x) / b) = b"
neuper@42301
  1829
neuper@42439
  1830
neuper@42449
  1831
"--------- several errpats in complicated term -------------------";
neuper@42449
  1832
"--------- several errpats in complicated term -------------------";
neuper@42449
  1833
"--------- several errpats in complicated term -------------------";
neuper@42449
  1834
(*TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one*)
neuper@42449
  1835
states:=[];
neuper@42449
  1836
CalcTree
neuper@42449
  1837
[(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"], 
neuper@42449
  1838
  ("Rational",["rational","simplification"], ["simplification","of_rationals"]))];
neuper@42449
  1839
Iterator 1;
neuper@42449
  1840
moveActiveRoot 1;
neuper@42449
  1841
autoCalculate 1 CompleteCalc;
neuper@42449
  1842
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@42449
  1843
neuper@48788
  1844
"-------- nonterminating cancel_p, norm_Rational 2002 ---";
neuper@48788
  1845
"-------- nonterminating cancel_p, norm_Rational 2002 ---";
neuper@48788
  1846
"-------- nonterminating cancel_p, norm_Rational 2002 ---";
neuper@48788
  1847
(*------------------------------------------------------------------------------------\
neuper@48788
  1848
"--- WN121204: searched rational.sml for "nonterm", added new numbering" ^
neuper@48788
  1849
"              and thoroughly tested with this numbering subsequently";
neuper@48788
  1850
"--- 1 ---";
neuper@48788
  1851
WN.2.6.03 from rlang.sml 56a 
neuper@48788
  1852
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)";
neuper@48788
  1853
val NONE = rewrite_set_ thy false common_nominator_p t;
neuper@48788
  1854
"--- 2 ---";
neuper@48788
  1855
WN060831 nonterm.SK7 
neuper@48788
  1856
val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
neuper@48788
  1857
val NONE = add_fraction_p_ thy t;
neuper@48788
  1858
"--- 3 ---";
neuper@48788
  1859
nonterm.SK9 loops: cancel_p kann nicht weiter kuerzen!!! *)
neuper@48788
  1860
val t'' = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
neuper@48788
  1861
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t'';
neuper@48788
  1862
"--- 4 ---";
neuper@48788
  1863
val t = str2term 
neuper@48788
  1864
"(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)"; 
neuper@48788
  1865
WN060831 nonterm.SK10 
neuper@48788
  1866
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@48788
  1867
term2str t;
neuper@48788
  1868
"--- 5 ---";
neuper@48788
  1869
val t = str2term 
neuper@48788
  1870
"(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
neuper@48788
  1871
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@48788
  1872
if term2str t = 
neuper@48788
  1873
then ()
neuper@48788
  1874
else error "rational.sml: diff.behav. in norm_Rational_mg 42";
neuper@48788
  1875
"--- 6 ---";
neuper@48788
  1876
val t = str2term 
neuper@48788
  1877
"9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
neuper@48788
  1878
val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
neuper@48788
  1879
... non terminating.
neuper@48788
  1880
"--- 7 ---";
neuper@48788
  1881
val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
neuper@48788
  1882
"(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)";
neuper@48788
  1883
val SOME (t,_) = rewrite_set_ thy false cancel_p t';
neuper@48788
  1884
"--- 8 ---";
neuper@48788
  1885
val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
neuper@48788
  1886
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@48788
  1887
"--- 9 ---";
neuper@48788
  1888
val t = str2term "((12*x*y/(9*x^^^2 - y^^^2))/" ^
neuper@48788
  1889
		 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
neuper@48788
  1890
		 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
neuper@48788
  1891
		 "(20*x*y/(x^^^2 - 25*y^^^2))";
neuper@48788
  1892
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@48788
  1893
"--- 10 ---";
neuper@48788
  1894
SK060904-2a non-termination of add_fraction_p_";
neuper@48788
  1895
val t = str2term (" (a + b * x) / (a + -1 * (b * x)) +  " ^
neuper@48788
  1896
		  " (-1 * a + b * x) / (a + b * x)      ");
neuper@52101
  1897
(* nonterm.SK = WN130830
neuper@48788
  1898
val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
neuper@48788
  1899
"--- 11 ---";
neuper@48788
  1900
common_nominator_p_ thy t;
neuper@48788
  1901
" (a + b * x)*(a + b * x) / ((a + -1 * (b * x))*(a + -1 * (b * x))) +  " ^
neuper@48788
  1902
" (-1 * a + b * x)*(a + -1 * (b * x)) / ((a + b * x)*(-1 * a + b * x)) ";
neuper@48788
  1903
"--- 12 ---";                             
neuper@48788
  1904
add_fraction_p_ thy t; 
neuper@48788
  1905
" ((a + b * x)*(a + b * x)  +  (-1 * a + b * x)*(a + -1 * (b * x))) /" ^
neuper@48788
  1906
" ((a + b * x)*(-1 * a + b * x))                                     ";
neuper@48788
  1907
--------------------------------------------------------------------------------------/*)
neuper@48788
  1908
neuper@48788
  1909
(*------------------------------------------------------------------------------------\
neuper@48788
  1910
"WN121205: thoroughly tested with the above numbering.";
neuper@48788
  1911
"  errors in cancel_p: --- 4,5,6,7.";
neuper@48788
  1912
"  error in common_nominator_p, common_nominator_p_: --- 10; 1,2?.";
neuper@48788
  1913
"  errors caused by ruleset norm_Rational: --- 8,9.";
neuper@52101
  1914
trace_rewrite := false;
neuper@48788
  1915
neuper@52101
  1916
"--- 1 ---: non-terminating with ### add_fract: done t22 "; = WN130830
neuper@48788
  1917
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)";
neuper@52101
  1918
trace_rewrite := false;
neuper@48788
  1919
rewrite_set_ thy false common_nominator_p t;
neuper@48788
  1920
neuper@48788
  1921
"--- 2 ---: non-terminating with ### add_fract: done t22 ";
neuper@48788
  1922
val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
neuper@48788
  1923
add_fraction_p_ thy t;
neuper@48788
  1924
neuper@48788
  1925
"--- 3 ---: norm_Rational calls Rrls cancel_p with non-normalised polys";
neuper@48788
  1926
val t = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
neuper@48788
  1927
rewrite_set_ thy false norm_Rational t;
neuper@48788
  1928
(*tracing end...####  rls: cancel_p on: 
neuper@48788
  1929
(a * x ^^^ 2 + -2 * (a * (x * y)) + a * y ^^^ 2 + b * x ^^^ 2 + -2 * (b * (x * y)) + b * y ^^^ 2) /
neuper@48788
  1930
(a ^^^ 2 * x ^^^ 2 + -1 * (a ^^^ 2 * y ^^^ 2) + -1 * (b ^^^ 2 * x ^^^ 2) + b ^^^ 2 * y ^^^ 2) *)
neuper@48788
  1931
neuper@48788
  1932
"--- 4 ---: non-terminating with Rrls cancel_p on plausible input";
neuper@48788
  1933
val t = str2term (
neuper@48788
  1934
"(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /"^
neuper@48788
  1935
"(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)"); 
neuper@48788
  1936
rewrite_set_ thy false cancel_p t;
neuper@48788
  1937
(*#  rls: cancel_p on: 
neuper@48788
  1938
(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /
neuper@48788
  1939
(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2) *)
neuper@48788
  1940
neuper@48788
  1941
"--- 5 ---: non-terminating with Rrls cancel_p on plausible input";
neuper@48788
  1942
val t = str2term "(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
neuper@48788
  1943
rewrite_set_ thy false norm_Rational t;
neuper@48788
  1944
(*####  rls: cancel_p on: 
neuper@48788
  1945
(2304 + -1152 * x + -2304 * y + 144 * x ^^^ 2 + 1152 * (x * y) + -144 * (x ^^^ 2 * y)) /
neuper@48788
  1946
(48 + -12 * x + -96 * y + 24 * (x * y) + 48 * y ^^^ 2 + -12 * (x * y ^^^ 2))  *)
neuper@48788
  1947
neuper@48788
  1948
"--- 6 ---: non-terminating with Rrls cancel_p on plausible input";
neuper@48788
  1949
val t = str2term 
neuper@48788
  1950
"9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
neuper@48788
  1951
rewrite_set_ thy false norm_Rational t;
neuper@48788
  1952
(*###  rls: cancel_p on: (-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * (x * y) +
neuper@48788
  1953
 144 * (x ^^^ 2 * y)) /
neuper@48788
  1954
(-48 + 12 * x + 96 * y + -24 * (x * y) + -48 * y ^^^ 2 + 12 * (x * y ^^^ 2)) *)
neuper@48788
  1955
neuper@48788
  1956
"--- 7 ---: non-terminating with Rrls cancel_p on plausible input";
neuper@48788
  1957
val t' = str2term (
neuper@48788
  1958
"(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /"^
neuper@48788
  1959
"(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)");
neuper@48788
  1960
rewrite_set_ thy false cancel_p t';
neuper@48788
  1961
neuper@48788
  1962
"--- 8 ---: bottom of output cannot be looked ad (due to looping?)";
neuper@48788
  1963
val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
neuper@48788
  1964
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@48788
  1965
neuper@48788
  1966
"--- 9 ---: probably error in norm_Rational";
neuper@48788
  1967
val t = str2term (
neuper@48788
  1968
"((12*x*y / (9*x^^^2 - y^^^2)) / (1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
neuper@48788
  1969
		"(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2) / (20*x*y/(x^^^2 - 25*y^^^2))");
neuper@48788
  1970
rewrite_set_ thy false norm_Rational t;
neuper@48788
  1971
(*####  rls: cancel_p on: (19440 * (x ^^^ 8 * y ^^^ 2) + -490320 * (x ^^^ 6 * y ^^^ 4) +
neuper@48788
  1972
 108240 * (x ^^^ 4 * y ^^^ 6) +
neuper@48788
  1973
 -6000 * (x ^^^ 2 * y ^^^ 8)) /
neuper@48788
  1974
(2160 * (x ^^^ 8 * y ^^^ 2) + -108240 * (x ^^^ 6 * y ^^^ 4) +
neuper@48788
  1975
 1362000 * (x ^^^ 4 * y ^^^ 6) +
neuper@48788
  1976
 -150000 * (x ^^^ 2 * y ^^^ 8)) *)
neuper@48788
  1977
neuper@48788
  1978
"--- 10 ---: non-terminating with ### add_fract: done t22: error in common_nominator_p ";
neuper@48788
  1979
val t = str2term (" (a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)");
neuper@48788
  1980
rewrite_set_ thy false common_nominator_p t; (*### add_fract: done t22 *)
neuper@48788
  1981
common_nominator_p_ thy t;                   (*loops without output*)
neuper@48788
  1982
"--- reformulated 10:";
neuper@48788
  1983
val t = str2term "(a + -1 * (b * x)) / (a + b * x)";
neuper@48788
  1984
rewrite_set_ thy false cancel_p t = NONE;
neuper@48788
  1985
"--- 11 ---";
neuper@48788
  1986
"--- 12 ---";                             
neuper@48788
  1987
"...both are to be considered after common_nominator_p_ is improved";
neuper@48788
  1988
--------------------------------------------------------------------------------------/*)
neuper@52088
  1989
============ inhibit exn WN130824 TODO ======================================================*)
neuper@48788
  1990