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