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