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