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