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