test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 16 Sep 2013 12:20:00 +0200
changeset 52105 2786cc9704c8
parent 52104 83166e7c7e52
child 52106 7f3760f39bdc
permissions -rw-r--r--
Test_Isac works again, perfectly ..

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