test/Tools/isac/Knowledge/rational.sml
author Walther Neuper <neuper@ist.tugraz.at>
Sun, 29 Jul 2012 16:29:04 +0200
changeset 42449 36ac220da82e
parent 42439 94fa39284c95
child 48763 9b9936d79dbe
permissions -rw-r--r--
prepare for stepToErrorPattern
neuper@38041
     1
(* Title: tests for rationals
neuper@38041
     2
   Author: Stefan Karnel
neuper@37906
     3
   Copyright (c) Stefan Karnel 2002
neuper@37906
     4
   Use is subject to license terms.
neuper@37906
     5
neuper@38080
     6
12345678901234567890123456789012345678901234567890123456789012345678901234567890
neuper@38080
     7
        10        20        30        40        50        60        70        80
neuper@42395
     8
LEGEND
neuper@42395
     9
WN120317.TODO postponed test/../ratinal,ratinal2.sml to joint work with dmeind 
neuper@42395
    10
WN070906
neuper@37906
    11
   nonterm.SK   marks non-terminating examples
neuper@37906
    12
   ord.SK       PARTIALLY marks crucial ordering examples
neuper@37906
    13
   *SK*         of some (secondary) interest (on 070906)          
neuper@42395
    14
WN060104 transfer examples marked with (*SR..*) to the exp-collection
neuper@42395
    15
*)
neuper@37906
    16
neuper@38041
    17
"--------------------------------------------------------";
neuper@38041
    18
"--------------------------------------------------------";
neuper@38041
    19
"table of contents --------------------------------------";
neuper@38041
    20
"--------------------------------------------------------";
neuper@38041
    21
"~~~~~BEGIN: decomment structure RationalI : RATIONALI ~~";
neuper@38041
    22
"-------- ... missing WN060103 --------------------------";
neuper@38041
    23
"-------- fun monom2term,  fun poly2term' ---------------";
neuper@38041
    24
"~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
neuper@38041
    25
"-------- external calculating functions test -----------";
neuper@38041
    26
"-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
neuper@38041
    27
"-------- common_nominator_p ----------------------------";
neuper@38041
    28
"-------- reverse rewrite -------------------------------";
neuper@38041
    29
"-------- 'reverse-ruleset' cancel_p --------------------";
neuper@38041
    30
"-------- norm_Rational ---------------------------------";
neuper@38041
    31
"-------- numeral rationals -----------------------------";
neuper@38041
    32
"-------- cancellation ----------------------------------";
neuper@38041
    33
"-------- common denominator ----------------------------";
neuper@38041
    34
"-------- multiply and cancel ---------------------------";
neuper@38041
    35
"-------- common denominator and multiplication ---------";
neuper@38041
    36
"-------- double fractions ------------------------------";
neuper@38041
    37
"-------- crucial examples ------------------------------";
neuper@38041
    38
"-------- examples for Stefan Karnels thesis ------------";
neuper@38041
    39
"-------- me Schalk I No.186 ----------------------------";
neuper@38041
    40
"-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
neuper@38041
    41
"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
neuper@38041
    42
"-------- investigate rulesets for cancel_p -------------";
neuper@38041
    43
"-------- investigate format of factout_ and factout_p_ -";
neuper@38041
    44
"-------- how to stepwise construct Scripts -------------";
neuper@42301
    45
"----------- get_denominator ----------------------------";
neuper@42449
    46
"--------- several errpats in complicated term -------------------";
neuper@38041
    47
"--------------------------------------------------------";
neuper@38041
    48
"--------------------------------------------------------";
neuper@38041
    49
"--------------------------------------------------------";
neuper@37906
    50
neuper@37906
    51
neuper@38041
    52
"~~~~~BEGIN: decomment structure RationalI : RATIONALI ~~";
neuper@37906
    53
(*.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
neuper@37906
    54
    tests of internal functions: to make them work, 
neuper@37906
    55
    out-comment (*!!!*) in knowledge/Rational.ML:
neuper@37906
    56
(*##!!!
neuper@37906
    57
structure RationalI : RATIONALI =
neuper@37906
    58
struct
neuper@37906
    59
!!!##*)
neuper@37906
    60
neuper@37906
    61
(*##!!!
neuper@37906
    62
end;(*struct*)
neuper@37906
    63
open RationalI;
neuper@37906
    64
!!!##*)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.*)
neuper@37906
    65
neuper@38041
    66
"-------- ... missing WN060103 --------------------------";
neuper@38041
    67
"-------- ... missing WN060103 --------------------------";
neuper@38041
    68
"-------- ... missing WN060103 --------------------------";
neuper@37906
    69
(*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
neuper@38041
    70
writeln ("*********************   rational.sml - TESTS    *************************");
neuper@38041
    71
writeln ("***** divide tests *****");
neuper@37906
    72
val mv_pquot1 = (#1(mv_division([(1,[1,1,1]),(1,[1,1,0]),(1,[1,0,1]),(1,[0,0,0])],[(1,[1,1,0]),(1,[0,0,0])],LEX_)));
neuper@37906
    73
(* result: [(1,[0,0,1]),(1,[0,0,0])] *)
neuper@38031
    74
if mv_pquot1=[(1,[0,0,1]),(1,[0,0,0])] then () else error ("rational.sml: example failed");
neuper@37906
    75
neuper@37906
    76
val mv_prest1 = (#2(mv_division([(1,[1,1,1]),(1,[1,1,0]),(1,[1,0,1]),(1,[0,0,0])],[(1,[1,1,0]),(1,[0,0,0])],LEX_)));
neuper@37906
    77
(* result: [(1,[1,0,1]),(~1,[0,0,1])] *)
neuper@38031
    78
if mv_prest1=[(1,[1,0,1]),(~1,[0,0,1])] then () else error ("rational.sml: example failed");
neuper@37906
    79
neuper@37906
    80
val mv_pquot2 = (#1(mv_division([(4,[2]),(8,[1]),(16,[0])],[(1,[1]),(1,[0])],LEX_)));
neuper@37906
    81
(* result: [(4,[1]),(4,[0])] *)
neuper@38031
    82
if mv_pquot2=[(4,[1]),(4,[0])] then () else error ("rational.sml: example failed");
neuper@37906
    83
neuper@37906
    84
val mv_prest2 = (#2(mv_division([(4,[2]),(8,[1]),(16,[0])],[(1,[1]),(1,[0])],LEX_)));
neuper@37906
    85
(* result: [(12,[0]] *)
neuper@38031
    86
if mv_prest2=[(12,[0])] then () else error ("rational.sml: example failed");
neuper@37906
    87
neuper@37906
    88
val mv_pquot3 = (#1(mv_division([(4,[2]),(~4,[0])],[(2,[1]),(2,[0])],LEX_)));
neuper@37906
    89
(* [(2,[1]),(~2,[0])] *)
neuper@38031
    90
if mv_pquot3=[(2,[1]),(~2,[0])] then () else error ("rational.sml: example failed");
neuper@37906
    91
neuper@37906
    92
val mv_prest3 = (#2(mv_division([(1,[2]),(~1,[0])],[(2,[1]),(2,[0])],LEX_)));
neuper@37906
    93
(* [(1,[2]),(~1,[0])] *)
neuper@38031
    94
if mv_prest3=[(1,[2]),(~1,[0])] then () else error ("rational.sml: example failed");
neuper@37906
    95
neuper@37906
    96
val mv_pquot4 = (#1(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1])],[(2,[1,0,0]),(4,[0,0,1])],LEX_)));
neuper@37906
    97
(* [(1,[0,1,1])] *)
neuper@38031
    98
if mv_pquot4=[(1,[0,1,1])] then () else error ("rational.sml: example failed");
neuper@37906
    99
neuper@37906
   100
val mv_prest4 = (#2(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1])],[(2,[1,0,0]),(4,[0,0,1])],GGO_)));
neuper@37906
   101
(* [(1,[1,1,1]),(~4,[0,1,2]),(4,[1,0,1]),(3,[0,0,1])] *)
neuper@38031
   102
if mv_prest4 =[(1,[1,1,1]),(~4,[0,1,2]),(4,[1,0,1]),(3,[0,0,1])] then () else error ("rational.sml: example failed");
neuper@37906
   103
neuper@37906
   104
val mv_pquot5 = (#1(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1]),(6,[2,1,3]),(4,[0,4,1]),(1,[2,2,1])],[(1,[0,0,1])],LEX_)));
neuper@37906
   105
(* [(1,[2,2,0]),(6,[2,1,2]),(3,[1,1,0]),(4,[1,0,0]),(4,[0,4,0]),(3,[0,0,0])]*)
neuper@38031
   106
if mv_pquot5=[(1,[2,2,0]),(6,[2,1,2]),(3,[1,1,0]),(4,[1,0,0]),(4,[0,4,0]),(3,[0,0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   107
neuper@37906
   108
val mv_prest5 = (#2(mv_division([(3,[1,1,1]),(4,[1,0,1]),(3,[0,0,1]),(6,[2,1,3]),(4,[0,4,1]),(1,[2,2,1])],[(1,[0,0,1])],LEX_)));
neuper@37906
   109
(* [] *)
neuper@38031
   110
if mv_prest5=[] then () else error ("rational.sml: example failed");
neuper@37906
   111
neuper@37906
   112
(* (x^2 + 2(a+1)x + (a^2+2a+1)) / (x+a+1) = x+a+1 *)
neuper@37906
   113
val mv_pquot6 = (#1(mv_division([(1,[2,0,0]),(2,[1,1,0]),(2,[1,0,0]),(1,[0,2,0]),(2,[0,1,0]),(1,[0,0,0])],[(1,[1,0,0]),(1,[0,1,0]),(1,[0,0,0])],LEX_)));
neuper@38031
   114
if mv_pquot6=[(1,[1,0,0]),(1,[0,1,0]),(1,[0,0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   115
neuper@37906
   116
val mv_prest6 = (#2(mv_division([(1,[2,0,0]),(2,[1,1,0]),(2,[1,0,0]),(1,[0,2,0]),(2,[0,1,0]),(1,[0,0,0])],[(1,[1,0,0]),(1,[0,1,0]),(1,[0,0,0])],LEX_)));
neuper@38031
   117
if mv_prest6=[] then () else error ("rational.sml: example failed");
neuper@37906
   118
neuper@37906
   119
neuper@38041
   120
writeln ("***** MV_CONTENT-TESTS *****");
neuper@37906
   121
val mv_cont1=mv_content([(1,[2,1]),(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,1]),(1,[0,0])]);
neuper@37906
   122
(* [(1,[0,1]),(1,[0,0])] *)
neuper@38031
   123
if  mv_cont1=[(1,[0,1]),(1,[0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   124
neuper@37906
   125
val mv_pp1=mv_pp([(1,[1,1]),(1,[1,0]),(1,[0,1]),(1,[0,0])]);
neuper@37906
   126
(*[(1,[1,0]),(1,[0,0])]*)
neuper@38031
   127
if mv_pp1=[(1,[1,0]),(1,[0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   128
neuper@37906
   129
val mv_cont2=mv_content([(2,[1]),(4,[0])]);
neuper@37906
   130
(* [(2,[0])] *)
neuper@38031
   131
if mv_cont2=[(2,[0])] then () else error ("rational.sml: example failed");
neuper@37906
   132
neuper@37906
   133
val mv_pp2=mv_pp([(2,[1]),(4,[0])]);
neuper@37906
   134
(* [(1,[1]),(2,[0])] *)
neuper@38031
   135
if mv_pp2=[(1,[1]),(2,[0])] then () else error ("rational.sml: example failed");
neuper@37906
   136
neuper@37906
   137
val mv_cont3=mv_content[(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(16,[1,1,1])];
neuper@37906
   138
(* [(2,[0,0,0])] *)
neuper@38031
   139
if mv_cont3=[(2,[0,0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   140
neuper@37906
   141
val mv_pp3=mv_pp[(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(16,[1,1,1])];
neuper@37906
   142
(* [(5,[2,2,0]),(4,[2,1,1]),(8,[1,1,1]),(6,[1,0,2])] *)
neuper@38031
   143
if mv_pp3=[(5,[2,2,0]),(4,[2,1,1]),(8,[1,1,1]),(6,[1,0,2])] then () else error ("rational.sml: example failed");
neuper@37906
   144
neuper@37906
   145
val mv_cont4=mv_content[(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])];
neuper@37906
   146
(* [(1,[0,0,0])] *)
neuper@38031
   147
if mv_cont4=[(1,[0,0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   148
neuper@37906
   149
val mv_pp4=mv_pp [(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])];
neuper@37906
   150
(* [(2,[2,1,0]),(2,[1,1,0]),(3,[1,0,1]),(3,[0,0,1])] *)
neuper@38031
   151
if mv_pp4=[(2,[2,1,0]),(2,[1,1,0]),(3,[1,0,1]),(3,[0,0,1])] then () else error ("rational.sml: example failed");
neuper@37906
   152
neuper@37906
   153
val con1=mv_content([(9,[2,0]),(15,[1,1]),(12,[1,0]),(6,[0,2]),(12,[0,1])]);
neuper@37906
   154
(* [(3,[0,0])] *)
neuper@38031
   155
if con1=[(3,[0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   156
neuper@37906
   157
val pp1=mv_pp([(9,[2,0]),(15,[1,1]),(12,[1,0]),(6,[0,2]),(12,[0,1])]);
neuper@37906
   158
(* [(3,[2,0]),(5,[1,1]),(4,[1,0]),(2,[0,2]),(4,[0,1])] *)
neuper@38031
   159
if pp1=[(3,[2,0]),(5,[1,1]),(4,[1,0]),(2,[0,2]),(4,[0,1])] then () else error ("rational.sml: example failed");
neuper@37906
   160
neuper@37906
   161
val con2=mv_content([(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])]);
neuper@37906
   162
(* [(1,[0,0])] *)
neuper@38031
   163
if con2=[(1,[0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   164
neuper@37906
   165
val pp2 =mv_pp([(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])]);
neuper@37906
   166
(* [(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])] *)
neuper@38031
   167
if pp2=[(1,[2,0]),(1,[1,1]),(1,[1,0]),(1,[0,2]),(1,[0,1])] then () else error ("rational.sml: example failed");
neuper@37906
   168
neuper@37906
   169
val cont1 = mv_content [(1,[2,1,0]),(2,[2,1,0])];
neuper@37906
   170
(* [(3,[0,1,0])] *)
neuper@38031
   171
if cont1=[(3,[0,1,0])] then () else error ("rational.sml: example failed");
neuper@37906
   172
neuper@37906
   173
val pp1 = mv_pp [(1,[2,1,0]),(2,[2,1,0])];
neuper@37906
   174
(* [(1,[2,0,0])] *)
neuper@38031
   175
if pp1=[(1,[2,0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   176
neuper@37906
   177
val cont2 = mv_content [(4,[1,2,0]),(2,[2,1,0])];
neuper@37906
   178
(* [(2,[0,1,0])] *)
neuper@38031
   179
if cont2=[(2,[0,1,0])] then () else error ("rational.sml: example failed");
neuper@37906
   180
neuper@37906
   181
val pp2 = mv_pp [(4,[1,2,0]),(2,[2,1,0])];
neuper@37906
   182
(* [(1,[2,0,0]),(2,[1,1,0])] *)
neuper@38031
   183
if pp2=[(1,[2,0,0]),(2,[1,1,0])] then () else error ("rational.sml: example failed");
neuper@37906
   184
neuper@38041
   185
writeln ("********************************************************");
neuper@37906
   186
val cont3=mv_content [(65,[3,2,2]),(52,[3,2,1]),(26,[3,1,2]),(~95,[2,2,3]),(~76,[2,2,2]),(35,[2,2,1]),(28,[2,2,0]),(~38,[2,1,3]),(14,[2,1,1])];
neuper@38031
   187
if cont3=[(5,[0,2,1]),(4,[0,2,0]),(2,[0,1,1])] then () else error ("rational.sml: example failed");
neuper@37906
   188
val pp3=mv_pp [(65,[3,2,2]),(52,[3,2,1]),(26,[3,1,2]),(~95,[2,2,3]),(~76,[2,2,2]),(35,[2,2,1]),(28,[2,2,0]),(~38,[2,1,3]),(14,[2,1,1])];
neuper@37906
   189
neuper@37906
   190
neuper@38041
   191
"-------- fun monom2term,  fun poly2term' ---------------";
neuper@38041
   192
"-------- fun monom2term,  fun poly2term' ---------------";
neuper@38041
   193
"-------- fun monom2term,  fun poly2term' ---------------";
neuper@37906
   194
val t = monom2term ((3,[2,1,0]), ["c","b","a"](*reverse ???SK-*));
neuper@37906
   195
term2str t = "3 * (c ^^^ 2 * b)" (*true*);
neuper@37906
   196
neuper@37906
   197
val t = monom2term ((1,[1,0]), ["b","a"]);
neuper@37906
   198
term2str t = "b" (*true*);
neuper@37906
   199
neuper@37906
   200
val t = poly2term ([(1,[0,0,0]),(2,[1,0,0]),(3,[2,1,0]),(4,[3,2,1])], 
neuper@37906
   201
		   ["c","b","a"]);
neuper@37906
   202
term2str t = "1 + 2 * c + 3 * (c ^^^ 2 * b) + 4 * (c ^^^ 3 * (b ^^^ 2 * a))";
neuper@37906
   203
neuper@37906
   204
val t = poly2term ([(1,[1,0]),(1,[0,1])], ["b","a"]);
neuper@37906
   205
term2str t = "a + b" (*true*);
neuper@37906
   206
neuper@37906
   207
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
neuper@38041
   208
"~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
neuper@38041
   209
"~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
neuper@38041
   210
"~~~~~END: decomment structure RationalI : RATIONALI ~~~~";
neuper@37906
   211
neuper@37906
   212
neuper@37906
   213
fun parse_rat str = (term_of o the o (parse thy)) str;
neuper@37906
   214
neuper@38041
   215
writeln ("***** mv_gcd-tests *****");
neuper@37906
   216
val ggt1 = mv_gcd [(4,[2,2]),(8,[1,1]),(4,[0,0])] [(2,[1,1]),(2,[0,0])];
neuper@37906
   217
(* [(2,[1,1]),(2,[0,0])] *)
neuper@38031
   218
if ggt1=[(2,[1,1]),(2,[0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   219
neuper@37906
   220
val ggt2 = mv_gcd [(8,[2,1,1]),(12,[1,0,2]),(10,[2,2,0]),(15,[1,1,1])] [(2,[2,1,0]),(3,[1,0,1]),(2,[1,1,0]),(3,[0,0,1])];
neuper@37906
   221
(* [(2,[1,1,0]),(3,[0,0,1])] *)
neuper@38031
   222
if ggt2=[(2,[1,1,0]),(3,[0,0,1])] then () else error ("rational.sml: example failed");
neuper@37906
   223
neuper@37906
   224
neuper@37906
   225
val ggt3 = mv_gcd [(1,[2,0]),(~2,[1,1]),(1,[0,2])] [(1,[1,0]),(~1,[0,1])];
neuper@37906
   226
(* [(1,[1,0]),(~1,[0,1])] *)
neuper@38031
   227
if ggt3=[(1,[1,0]),(~1,[0,1])] then () else error ("rational.sml: example failed");
neuper@37906
   228
neuper@37906
   229
neuper@37906
   230
val ggt4 = mv_gcd [(1,[2,1,0]),(2,[2,1,0])] [(5,[1,0,0])];
neuper@37906
   231
(* [(1,[1,0,0])] *)
neuper@38031
   232
if ggt4=[(1,[1,0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   233
neuper@37906
   234
neuper@37906
   235
val ggt5 = mv_gcd [(4,[2,0]),(~8,[1,1]),(4,[0,2])] [(1,[2,0]),(~1,[0,2])];
neuper@37906
   236
(* [(1,[1,0]),(~1,[0,1])] *)
neuper@38031
   237
if ggt5=[(1,[1,0]),(~1,[0,1])] then () else error ("rational.sml: example failed");
neuper@37906
   238
neuper@37906
   239
neuper@37906
   240
val ggt6 = mv_gcd [(10,[2,1,1]),(14,[1,1,0]),(3,[1,0,1]),(20,[1,2,1])] [(5,[1,1,1]),(7,[2,1,1])];
neuper@37906
   241
(* [(1,[0,0,0])] *)
neuper@38031
   242
if ggt6=[(1,[1,0,0])] then () else error ("rational.sml: example failed");
neuper@37906
   243
neuper@38041
   244
writeln ("***** kgv-tests *****");
neuper@37906
   245
val kgv1=mv_lcm [(10,[])] [(15,[])];
neuper@37906
   246
(* [(30,[])] *)
neuper@38031
   247
if kgv1=[(30,[])] then () else error ("rational.sml: example failed");
neuper@37906
   248
neuper@37906
   249
val kgv2=mv_lcm [(1,[2,0]),(~2,[1,1]),(1,[0,2])] [(1,[1,0]),(~1,[0,1])];
neuper@37906
   250
(* [(1,[2,0]),(~2,[1,1]),(1,[0,2])] *)
neuper@38031
   251
if kgv2=[(1,[2,0]),(~2,[1,1]),(1,[0,2])] then () else error ("rational.sml: example failed");
neuper@37906
   252
neuper@37906
   253
val kgv3=mv_lcm [(4,[2,0]),(~8,[1,1]),(4,[0,2])] [(1,[2,0]),(~1,[0,2])];
neuper@37906
   254
(* [(4,[3,0]),(~4,[2,1]),(~4,[1,2]),(4,[0,3])] *)
neuper@38031
   255
if kgv3=[(4,[3,0]),(~4,[2,1]),(~4,[1,2]),(4,[0,3])] then () else error ("rational.sml: example failed");
neuper@37906
   256
neuper@37906
   257
(*!!!--------
neuper@38041
   258
writeln ("***** STEP_CANCEL_TESTS: *****");
neuper@37906
   259
neuper@37906
   260
val term2 = (term_of o the o (parse thy)) " (9 * a^^^2 * b) /  (6 * a * c)";
neuper@37906
   261
val div2 = term2str (step_cancel term2);
neuper@38031
   262
if div2 =  "3 * (a * b) * (3 * a) / (2 * c * (3 * a))" then () else error ("rational.sml: example failed");
neuper@37906
   263
neuper@37906
   264
neuper@37906
   265
val term1 = (term_of o the o (parse thy)) "(10 * a^^^2 * b * c + 14 * a * b + 3 * a * c + 20 * a * b^^^2 * c) / a";
neuper@37906
   266
val div1  = term2str(step_cancel term1);
neuper@38031
   267
if div1 =  "(3 * c + 14 * b + 20 * (b ^^^ 2 * c) + 10 * (a * (b * c))) * a / (1 * a)" then () else error ("rational.sml: example failed");
neuper@37906
   268
neuper@37906
   269
val term3 = (term_of o the o (parse thy)) "(10 * a^^^2 * b * c) / (1 * x * y * z) ";
neuper@37906
   270
val div3 = term2str(step_cancel term3);
neuper@38031
   271
if div3="10 * a ^^^ 2 * b * c / (1 * x * y * z)" then () else  error ("rational.sml: example failed");
neuper@37906
   272
neuper@37906
   273
--------------------------------------------------------------------------!!!*)
neuper@37906
   274
neuper@37906
   275
(*-----versuche 13.3.03-----
neuper@37906
   276
 val t = str2term "1 - x^^^2 - 5 * x^^^5";
neuper@37906
   277
 val vs=(((map free2str) o vars) t);
neuper@37926
   278
 val SOME ml = expanded2poly t vs;
neuper@37906
   279
 poly2term (ml, vs);
neuper@37906
   280
 poly2term'(rev(sort (mv_geq LEX_) (ml)),vs);
neuper@37906
   281
 poly2term'([(~5,[5]),(~1,[2]),(1,[0])], vs);
neuper@37906
   282
 monom2term((~5,[5]),vs);
neuper@37906
   283
 monom2term((~1,[2]),vs);
neuper@37906
   284
 val t' = monom2term((1,[0]),vs);(*uncaught exception LIST*)
neuper@37906
   285
neuper@37906
   286
 val (i,is) = (~1,[2]);
neuper@38034
   287
 val ttt = Const ("Groups.times_class.times", [HOLogic.realT,HOLogic.realT]---> HOLogic.realT) $
neuper@37906
   288
		   (Const ("uminus", HOLogic.realT --> HOLogic.realT) $
neuper@37906
   289
		   Free ((str_of_int o abs) i, HOLogic.realT)) $
neuper@37906
   290
		   powerproduct2term(is, vs);
neuper@37906
   291
 term2str ttt;
neuper@37906
   292
-------versuche 13.3.03-----*)
neuper@37906
   293
neuper@37906
   294
 val t = str2term "1 - x^^^2 - 5 * x^^^5";
neuper@37926
   295
 val SOME t' = expanded2polynomial t; term2str t';
neuper@37906
   296
"1 + - 1 * x ^^^ 2 + - 5 * x ^^^ 5";
neuper@37906
   297
 val t = str2term "1 - x";
neuper@37926
   298
 val SOME t' = expanded2polynomial t; term2str t';
neuper@37906
   299
"1 + - 1 * x";
neuper@37906
   300
 val t = str2term "1 + (-1) * x";
neuper@37926
   301
 val SOME t' = expanded2polynomial t; term2str t';
neuper@37906
   302
"1 + - 1 * x";
neuper@37906
   303
 val t = (term_of o the o (parse thy)) "1 + (-1) * x ^^^ 2 + (-5) * x ^^^5";
neuper@37926
   304
 val SOME t' = polynomial2expanded t; term2str t';
neuper@37906
   305
"1 - x ^^^ 2 - 5 * x ^^^ 5";
neuper@37906
   306
neuper@37906
   307
neuper@38041
   308
"-------- external calculating functions test -----------";
neuper@38041
   309
"-------- external calculating functions test -----------";
neuper@38041
   310
"-------- external calculating functions test -----------";
neuper@37906
   311
val t1 = (term_of o the o (parse thy)) "((3 * x^^^2 + 6 *x + 3) / (2*x + 2))";
neuper@37926
   312
val SOME (t1',asm)= factout_p_ thy t1;
neuper@37906
   313
term2str t1'; terms2str asm;
neuper@37906
   314
"(3 + 3 * x) * (1 + 1 * x) / (2 * (1 + 1 * x))";
neuper@37906
   315
"[]";
neuper@37926
   316
val SOME (t1',asm)= cancel_p_ thy t1;
neuper@37906
   317
term2str t1'; terms2str asm;
neuper@37906
   318
"(3 + 3 * x) / 2";
neuper@37906
   319
"[\"1 + 1 * x ~= 0\"]";
neuper@37906
   320
neuper@37906
   321
val t = (term_of o the o (parse thy)) "((-3 * x^^^2 + 6 *x - 3) / (2*x - 2))";
neuper@37926
   322
val SOME (t',asm)= cancel_ thy t; 
neuper@37906
   323
term2str t'; terms2str asm;
neuper@37906
   324
"(3 - 3 * x) / 2";
neuper@37906
   325
"[\"-1 + x ~= 0\"]";
neuper@37926
   326
val SOME (t',asm)= factout_ thy t;
neuper@37906
   327
term2str t'; terms2str asm;
neuper@37906
   328
"(3 - 3 * x) * (-1 + x) / (2 * (-1 + x))";
neuper@37906
   329
"[]";
neuper@37906
   330
neuper@37906
   331
val t = str2term "((x+ (-1)) / (x + 1)) + ((x + 1) / (x + (-1)))";
neuper@37926
   332
val SOME (t',asm) = add_fraction_p_ thy t;
neuper@37906
   333
term2str t'; terms2str asm;
neuper@37906
   334
"(2 + 2 * x ^^^ 2) / (-1 + 1 * x ^^^ 2)";
neuper@37906
   335
"[]";
neuper@37926
   336
val SOME (t',asm) = common_nominator_p_ thy t; 
neuper@37906
   337
term2str t'; terms2str asm;
neuper@37906
   338
"(-1 + 1 * x) * (-1 + 1 * x) / ((1 + 1 * x) * (-1 + 1 * x)) +\n(1 + 1 * x) * (1 + 1 * x) / ((1 + 1 * x) * (-1 + 1 * x))";
neuper@37906
   339
"[]";
neuper@37906
   340
neuper@37906
   341
val t = str2term "((x - 1) / (x + 1)) + ((x + 1) / (x - 1))";
neuper@37926
   342
val SOME (t',asm) = add_fraction_ thy t;
neuper@37906
   343
term2str t'; terms2str asm;
neuper@37906
   344
"(2 + 2 * x ^^^ 2) / (-1 + x ^^^ 2)";
neuper@37906
   345
"[]";
neuper@37926
   346
val SOME (t',asm) = common_nominator_ thy t; 
neuper@37906
   347
term2str t'; terms2str asm;
neuper@37906
   348
"(-1 + x) * (-1 + x) / ((1 + x) * (-1 + x)) +\n(1 + x) * (1 + x) / ((1 + x) * (-1 + x))";
neuper@37906
   349
"[]";
neuper@37906
   350
neuper@37906
   351
val t = str2term "((1) / (2*x + 2)) + ((1) / (2*x + (-2))) + ((1) / ( x^^^2 + (-1)))+((1) / (x^^^2 + (-2)*x + 1))";
neuper@37926
   352
val SOME (t',asm) = common_nominator_p_ thy t; 
neuper@37906
   353
term2str t'; terms2str asm;
neuper@37906
   354
"1 * (1 + -2 * x + 1 * x ^^^ 2) /\n((-1 + 1 * x) * (2 * ((-1 + 1 * x) * (1 + 1 * x)))) +\n(1 * (-1 + 1 * x ^^^ 2) /\n ((-1 + 1 * x) * (2 * ((-1 + 1 * x) * (1 + 1 * x)))) +\n (1 * (-2 + 2 * x) / ((-1 + 1 * x) * (2 * ((-1 + 1 * x) * (1 + 1 * x)))) +\n  1 * (#";                
neuper@37906
   355
"[]";
neuper@37926
   356
val SOME (t',asm) = add_fraction_p_ thy t; 
neuper@37906
   357
term2str t'; terms2str asm;
neuper@37906
   358
"1 * x / (1 + -2 * x + 1 * x ^^^ 2)";
neuper@37906
   359
"[\"1 + 1 * x ~= 0\"]";
neuper@37926
   360
val SOME(t',asm) = norm_rational_ thy t;
neuper@37906
   361
term2str t'; terms2str asm;
neuper@37906
   362
"1 * x / (1 + -2 * x + 1 * x ^^^ 2)";
neuper@37906
   363
"[\"1 + 1 * x ~= 0\"]";
neuper@37906
   364
neuper@37906
   365
val t3 = (term_of o the o (parse thy)) "((1) / (2*x + 2)) + ((1) / (2*x - 2)) + ((1) / ( x^^^2 - 1))+((1) / (x^^^2 - 2 * x + 1))";
neuper@37926
   366
val SOME (t3',_) = common_nominator_ thy t3; 
neuper@37926
   367
val SOME (t3'',_) = add_fraction_ thy t3; 
neuper@37906
   368
(term2str t3'); 
neuper@37906
   369
(term2str t3''); 
neuper@37906
   370
neuper@37926
   371
val SOME(t4,t5) = norm_expanded_rat_ thy t3;
neuper@37906
   372
term2str t4;
neuper@37906
   373
term2str (hd(t5));
neuper@37906
   374
neuper@37906
   375
neuper@37906
   376
neuper@37906
   377
  val t=(term_of o the o (parse thy)) "(9 - x^^^2)/(9 - 6*x + x^^^2)";
neuper@37926
   378
  val SOME (t',_) = factout_ thy t;
neuper@37926
   379
  val SOME (t'',_) = cancel_ thy t;
neuper@37906
   380
  term2str t';
neuper@37906
   381
  term2str t'';
neuper@37906
   382
  "(3 + x) * (3 - x) / ((3 - x) * (3 - x))";
neuper@37906
   383
  "(3 + x) / (3 - x)";
neuper@37906
   384
  			   
neuper@37906
   385
  val t=(term_of o the o (parse thy))
neuper@37906
   386
	    "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1 / (3 - x)";
neuper@37926
   387
  val SOME (t',_) = common_nominator_ thy t;
neuper@37926
   388
  val SOME (t'',_) = add_fraction_ thy t;
neuper@37906
   389
  term2str t';
neuper@37906
   390
  term2str t'';
neuper@37906
   391
  "(9 - x ^^^ 2) / ((3 - x) * (3 - x)) + 1 * (3 - x) / ((3 - x) * (3 - x))";
neuper@37906
   392
  "(4 + x) / (3 - x)";
neuper@37906
   393
neuper@37906
   394
(*WN021016 added -----vv---*)
neuper@37906
   395
val t = str2term "(9 - x^^^2) / (9 - 6*x + x^^^2) + 1";
neuper@37926
   396
val SOME (t',_) = common_nominator_ thy t;
neuper@37926
   397
val SOME (t'',_) = add_fraction_ thy t;
neuper@38041
   398
term2str t' = "(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n1" ^
neuper@38041
   399
		" * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
neuper@37906
   400
term2str t'' = "6 / (3 - x)" (*true*);
neuper@37906
   401
neuper@37906
   402
val t = str2term "1 + (9 - x^^^2) / (9 - 6*x + x^^^2)";
neuper@37926
   403
val SOME (t',_) = common_nominator_ thy t;
neuper@37926
   404
val SOME (t'',_) = add_fraction_ thy t;
neuper@38041
   405
term2str t' = "1 * (9 - 6 * x + x ^^^ 2) / (9 - 6 * x + x ^^^ 2) +\n" ^
neuper@38041
   406
		"(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)" (*true*);
neuper@37906
   407
term2str t'' = "6 / (3 - x)" (*true*);
neuper@37906
   408
(*WN021016 added -----^^---*)
neuper@37926
   409
(*WN030602 added -----vv--- no rewrite -> NONE !*)
neuper@37906
   410
val t = str2term "1 / a";
neuper@37926
   411
val NONE =  cancel_p_ thy t;
neuper@37926
   412
val NONE = rewrite_set_ thy false cancel_p t;
neuper@37906
   413
(*WN.2.6.03 added -------^^---*)
neuper@37906
   414
neuper@37906
   415
val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2)";
neuper@37926
   416
val SOME (t',_) = factout_ thy t;
neuper@37926
   417
val SOME (t'',_) = cancel_ thy t;
neuper@37906
   418
term2str t' = "(y + x) * (y - x) / ((y - x) * (y - x))"(*true*);
neuper@37906
   419
term2str t'' = "(y + x) / (y - x)";
neuper@37906
   420
    
neuper@37906
   421
val t = str2term "(y^^^2 - x^^^2)/(y^^^2 - 2*y*x + x^^^2) + 1 / (y - x)";
neuper@37926
   422
val SOME (t',_) = common_nominator_ thy t;
neuper@37926
   423
val SOME (t'',_) = add_fraction_ thy t;
neuper@37906
   424
term2str t' =
neuper@38041
   425
"(-1 * x ^^^ 2 + y ^^^ 2) / ((-1 * x + y) * (-1 * x + y)) +\n1" ^
neuper@38041
   426
" * (-1 * x + y) / ((-1 * x + y) * (-1 * x + y))" (*true*);
neuper@37906
   427
term2str t'' = "(-1 - x - y) / (x - y)" (*true*);
neuper@37906
   428
neuper@37906
   429
val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2) + 1 / (x - y)";
neuper@37926
   430
val SOME (t',_) = common_nominator_ thy t;
neuper@37926
   431
val SOME (t'',_) = add_fraction_ thy t;
neuper@38041
   432
if term2str t' = "(-1 * y ^^^ 2 + x ^^^ 2) / ((-1 * y + x) * (-1 * y + x))" ^
neuper@38041
   433
" +\n1 * (-1 * y + x) / ((-1 * y + x) * (-1 * y + x))" then ()
neuper@38031
   434
else error "rational.sml lex-ord 1";
neuper@37906
   435
if term2str t'' = "(-1 - y - x) / (y - x)" then ()
neuper@38031
   436
else error "rational.sml lex-ord 2";
neuper@37906
   437
(*WN.16.10.02 WN070905 lexicographische Ordnung erhalten ! SK.ord*)
neuper@37906
   438
neuper@37906
   439
neuper@37906
   440
val t = str2term "(x^^^2 - y^^^2)/(x^^^2 - 2*x*y + y^^^2)";
neuper@37926
   441
val SOME (t',_) = norm_expanded_rat_ thy t; 
neuper@37906
   442
if term2str t' = "(x + y) / (x - y)" then ()
neuper@38041
   443
else error "rational.sml term2poly: invalid x ^^^ 2 - y ^^^ 2 No.1";
neuper@37926
   444
(*val SOME (t'',_) = norm_rational_ thy t;
neuper@37906
   445
 *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial 
neuper@37906
   446
WN.16.10.02 ?! + WN060831???SK4 
neuper@37906
   447
WN070905 *** term2poly: invalid = x ^^^ 2 - y ^^^ 2*)
neuper@37906
   448
neuper@37906
   449
 
neuper@37906
   450
val t = str2term "(9 - x^^^2)/(9 - 6*x + x^^^2) + (1)/(3 + x)";
neuper@37926
   451
val SOME (t',_) = norm_expanded_rat_ thy t;
neuper@37906
   452
if term2str t' = "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)" then ()
neuper@38031
   453
else error "rational.sml (9 - x^^^2)/(9 - 6*x + x^^^2) +...";
neuper@37926
   454
(*val SOME (t'',_) = norm_rational_ thy t;
neuper@37906
   455
  *** RATIONALS_TERM2POLY_EXCEPTION: Invalid Polynomial WN.16.10.02 ?!
neuper@37906
   456
WN070906 *** term2poly: invalid = 9 - x ^^^ 2 SK.term2poly*)
neuper@37906
   457
 
neuper@37906
   458
  val t=(term_of o the o (parse thy)) 
neuper@37906
   459
	    "(9 + (-1)* x^^^2)/(9 + (-1)* 6*x + x^^^2) + (1)/(3 + x)";
neuper@37926
   460
  val SOME (t',_) = norm_expanded_rat_ thy t;
neuper@37926
   461
  val SOME (t'',_) = norm_rational_ thy t;
neuper@37906
   462
  term2str t';
neuper@37906
   463
  term2str t'';
neuper@37906
   464
  "(12 + 5 * x + x ^^^ 2) / (9 - x ^^^ 2)";
neuper@37906
   465
  "(12 + 5 * x + x ^^^ 2) / (9 + (-1) * x ^^^ 2)";
neuper@37906
   466
neuper@37906
   467
neuper@38041
   468
"-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
neuper@38041
   469
"-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
neuper@38041
   470
"-------- cancel from: Mathematik 1 Schalk Reniets Verlag";
neuper@41929
   471
val thy  = @{theory "Rational"};
neuper@37991
   472
val thy' = "Rational";
neuper@37906
   473
val rls' = "cancel";
neuper@37906
   474
val mp = "make_polynomial";
neuper@37906
   475
neuper@38041
   476
writeln ("example 186:");
neuper@38041
   477
writeln("a)");
neuper@37906
   478
val e186a'="(14 * x * y) / ( x * y )";(*SRC*)
neuper@38041
   479
rewrite_set_ thy false cancel (str2term e186a');
neuper@38041
   480
"@@@@@@@@@@@@@@";
neuper@37906
   481
val e186a = the (rewrite_set thy' false "cancel" e186a');
neuper@37906
   482
  is_expanded (parse_rat "14 * x * y");
neuper@37906
   483
  is_expanded (parse_rat "x * y");
neuper@38044
   484
if e186a = ("14 / 1", "[\"y * x ~= 0\"]") then ()
neuper@38044
   485
else error "rational.sml cancel Schalk e186a";
neuper@37906
   486
neuper@38041
   487
writeln("b)");
neuper@37906
   488
val e186b'="(60 * a * b) / ( 15 * a  * b )";
neuper@37906
   489
val e186b = the (rewrite_set thy' false "cancel" e186b');
neuper@38041
   490
writeln("c)");
neuper@37906
   491
val e186c'="(144 * a^^^2 * b * c) / (12 * a * b * c )";
neuper@37906
   492
val e186c = (the (rewrite_set thy' false "cancel" e186c'))
neuper@41930
   493
    handle e => print_exn_G e;
neuper@37906
   494
val t = (term_of o the o (parse thy)) e186c';
neuper@38044
   495
if e186c = ("12 * a / 1", "[\"12 * (c * (b * a)) ~= 0\"]") then ()
neuper@38044
   496
else error "rational.sml cancel Schalk e186c";
neuper@37906
   497
neuper@38041
   498
writeln ("example 187:");
neuper@38041
   499
writeln("a)");
neuper@37906
   500
val e187a'="(12 * x * y) / (8 * y^^^2 )";(*SRC*)
neuper@37906
   501
val e187a = the (rewrite_set thy' false "cancel" e187a');
neuper@38041
   502
writeln("b)");
neuper@37906
   503
val e187b'="(8 * x^^^2 * y * z ) / (18 * x * y^^^2 * z )";
neuper@37906
   504
val e187b = the (rewrite_set thy' false "cancel" e187b');
neuper@38041
   505
writeln("c)");
neuper@38044
   506
val e187d'="(9 * x^^^5 * y^^^2 * z^^^4) / (15 * x^^^6 * y^^^3 * z )";(*SRC*)
neuper@38044
   507
val e187d = the (rewrite_set thy' false "cancel" e187d');
neuper@38044
   508
if e187d = ("3 * z ^^^ 3 / (5 * (y * x))",
neuper@38044
   509
            "[\"3 * (z * (y ^^^ 2 * x ^^^ 5)) ~= 0\"]") then ()
neuper@38044
   510
else error "rational.sml cancel Schalk e186d";
neuper@37906
   511
neuper@38044
   512
writeln "example 188:";
neuper@37906
   513
val e188a'="(-8 + 8 * x) / (-9 + 9 * x)";(*SRC*)
neuper@37906
   514
val e188a = the (rewrite_set thy' false "cancel" e188a');
neuper@37906
   515
  is_expanded (parse_rat "8 * x + -8");
neuper@37906
   516
(* e188a = ("8 / 9",["not ((-1) + x = 0)"]) then () 13.3.03*)
neuper@38044
   517
if e188a = ("8 / 9", "[\"-1 + x ~= 0\"]") then ()
neuper@38031
   518
else error "rational.sml: e188a new behaviour";
neuper@38044
   519
neuper@38044
   520
val SOME (t,_) = rewrite_set thy' false mp "(8*((-1) + x))/(9*((-1) + x))";
neuper@38041
   521
writeln("b)");
neuper@37906
   522
val e188b'="(-15 + 5 * x) / (-18 + 6 * x)";(*SRC*)
neuper@38044
   523
val SOME (t, asm) = rewrite_set thy' false "cancel" e188b';
neuper@37906
   524
t = "5 / 6" (*true*);
neuper@38041
   525
writeln("c)");
neuper@37906
   526
neuper@37906
   527
val e188c'="( a + -1 * b ) / ( b + -1 * a )";
neuper@37906
   528
val e188c = the (rewrite_set thy' false "cancel_p" e188c');
neuper@37906
   529
(*is_expanded (parse_rat "a + -1 * b");*)
neuper@37926
   530
val SOME (t,_) = 
neuper@37906
   531
    rewrite_set thy' false mp "((-1)*(b + (-1) * a))/(1*(b + (-1) * a))";
neuper@37906
   532
if t= "(a + -1 * b) / (-1 * a + b)"  then()
neuper@38031
   533
else error "rational.sml: e188c new behaviour";
neuper@37906
   534
neuper@38041
   535
writeln ("example 190:");
neuper@38041
   536
writeln("c)");
neuper@37906
   537
val e190c'="( 27 * a^^^3 + 9 * a^^^2 + 3 * a + 1 ) / ( 27 * a^^^3 + 18 * a^^^2 + 3 * a )";
neuper@37906
   538
val e190c = the (rewrite_set thy' false "cancel" e190c');
neuper@37926
   539
val SOME (t,_) = rewrite_set thy' false mp "((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
neuper@37906
   540
if t = "(1 + 3 * a + 9 * a ^^^ 2 + 27 * a ^^^ 3) /\n(3 * a + 18 * a ^^^ 2 + 27 * a ^^^ 3)" then ()
neuper@38031
   541
else error "rational.sml: e190c new behaviour";
neuper@37906
   542
neuper@38041
   543
writeln ("example 191:");
neuper@38041
   544
writeln("a)");
neuper@37906
   545
val e191a'="( x^^^2 + -1 * y^^^2 ) / ( x + y )";
neuper@37906
   546
(*WN.23.10.02-------
neuper@37906
   547
val e191a = the (rewrite_set thy' false "cancel" e191a'); 
neuper@37906
   548
  is_expanded (parse_rat "x^^^2 + -1 * y^^^2");
neuper@37906
   549
  false;
neuper@37906
   550
  is_expanded (parse_rat "x + y");
neuper@37906
   551
  true; -----------*)
neuper@37926
   552
val SOME (t,_) = rewrite_set thy' false mp "((x + (-1) * y)*(x + y))/((1)*(x + y))";
neuper@37906
   553
(* t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then() WN.13.3.03*)
neuper@37906
   554
if t="(x ^^^ 2 + -1 * y ^^^ 2) / (x + y)" then()
neuper@38031
   555
else error "rational.sml: e191a new behaviour";
neuper@37906
   556
neuper@38041
   557
writeln("c)");
neuper@37906
   558
val e191c'="( 9 * x^^^2 + -30 * x + 25 ) / ( 9 * x^^^2 + -25 )";
neuper@37906
   559
(*WN.23.10.02-------
neuper@37906
   560
val e191c = the (rewrite_set thy' false "cancel" e191c');
neuper@37906
   561
  is_expanded (parse_rat "9 * x^^^2 + -30 * x + 25");
neuper@37906
   562
  false;
neuper@37906
   563
  is_expanded (parse_rat "25 + -30*x + 9*x^^^2");
neuper@37906
   564
  false;
neuper@37906
   565
  is_expanded (parse_rat "-25 + 9*x^^^2");
neuper@37906
   566
  true;------------*)
neuper@37926
   567
val SOME (t,_) = rewrite_set thy' false mp "(((-5) + 3 * x)*((-5) + 3 * x))/((5 + 3 * x)*((-5) + 3 * x))";
neuper@37906
   568
(* t="(25 + ((-30) * x + 9 * x ^^^ 2)) / ((-25) + 9 * x ^^^ 2)"then() 13.3.03*)
neuper@37906
   569
if t= "(25 + -30 * x + 9 * x ^^^ 2) / (-25 + 9 * x ^^^ 2)" then()
neuper@38031
   570
else error "rational.sml: 'e191c' new behaviour";
neuper@37906
   571
neuper@37906
   572
neuper@38041
   573
writeln ("example 192:");
neuper@38041
   574
writeln("b)");
neuper@37906
   575
val e192b'="( 7 * x^^^3 + -1 * x^^^2 * y ) / ( 7 * x * y^^^2 + -1 *  y^^^3 )";
neuper@37906
   576
(*WN.23.10.02-------
neuper@37906
   577
val e192b = the (rewrite_set thy' false "cancel" e192b');
neuper@37906
   578
-------------------*)
neuper@37926
   579
val SOME (t',_) = rewrite_set thy' false mp "((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
neuper@41931
   580
(*========== inhibit exn 110317 ================================================
neuper@37906
   581
if t' = "(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)"
neuper@37906
   582
(*"(-1 * y * x ^^^ 2 + 7 * x ^^^ 3) / (-1 * y ^^^ 3 + 7 * x * y ^^^ 2)"WN050929*)
neuper@38031
   583
then () else error "rational.sml: 'e192b' new behaviour";
neuper@37906
   584
(*^^^ works with MG's simplifier vvv*)
neuper@37906
   585
val t =str2term"((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
neuper@38044
   586
val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
neuper@38031
   587
if term2str t' = "(7 * x ^^^ 3 + -1 * x ^^^ 2 * y) / (7 * x * y ^^^ 2 + -1 * y ^^^ 3)" then () else error "rational.sml: 'e192b'MG new behaviour";
neuper@41931
   588
============ inhibit exn 110317 ==============================================*)
neuper@37906
   589
neuper@38041
   590
writeln ("example 193:");
neuper@38041
   591
writeln("a)");
neuper@37906
   592
val e193a'="( x^^^2 + -6 * x + 9 ) / ( x^^^2 + -9 )";
neuper@37906
   593
(*WN.23.10.02-------
neuper@37906
   594
val e193a = the (rewrite_set thy' false "cancel" e193a');
neuper@37906
   595
-------------------*)
neuper@38041
   596
writeln("b)");
neuper@37906
   597
val e193b'="( x^^^2 + -8 * x + 16 ) / ( 2 * x^^^2 + -32 )";
neuper@37906
   598
(*WN.23.10.02-------
neuper@37906
   599
val e193b = the (rewrite_set thy' false "cancel" e193b');
neuper@38041
   600
writeln("c)");
neuper@37906
   601
val e193c'="( 2 * x + -50 * x^^^3 ) / ( 25 * x^^^2 + -10 * x + 1 )";
neuper@37926
   602
val SOME(t,_) = rewrite_set thy' false "cancel" e193c';
neuper@37906
   603
-------------------*)
neuper@37906
   604
neuper@37906
   605
val wn01 = "(-25 + 9*x^^^2)/(5 + 3*x)";
neuper@38044
   606
val SOME (t, asm) = rewrite_set thy' false "cancel" wn01;
neuper@37906
   607
(* t = "((-5) + 3 * x) / 1" then () WN.13.3.03*)
neuper@38044
   608
if t = "(-5 + 3 * x) / 1" andalso asm = "[\"5 + 3 * x ~= 0\"]" then ()
neuper@38031
   609
else error "rational.sml: new behav. in cancel wn01";
neuper@37906
   610
neuper@38041
   611
"-------- common_nominator_p ----------------------------";
neuper@38041
   612
"-------- common_nominator_p ----------------------------";
neuper@38041
   613
"-------- common_nominator_p ----------------------------";
neuper@37906
   614
val rls' = "common_nominator_p";
neuper@37906
   615
neuper@38041
   616
writeln ("example 204:");
neuper@38041
   617
writeln("a)");
neuper@37906
   618
val e204a'="((5 * x) / 9) + ((3 * x) / 9) + (x / 9)";
neuper@37906
   619
val e204a = the (rewrite_set thy' false "common_nominator_p" e204a');
neuper@38041
   620
writeln("b)");
neuper@37906
   621
val e204b'="5 / x + -3 / x + -1 / x";
neuper@37906
   622
val e204b = the (rewrite_set thy' false "common_nominator_p" e204b');
neuper@38044
   623
if e204b = ("1 / x", "[]") then ()
neuper@38044
   624
else error "rational.sml common_nominator_p example e204b";
neuper@37906
   625
neuper@38041
   626
writeln ("example 205:");
neuper@38041
   627
writeln("a)");
neuper@37906
   628
val e205a'="((4 * x + 7) / 8) + ((4 * x + 3) / 8)";
neuper@37906
   629
val e205a = the (rewrite_set thy' false "common_nominator_p" e205a');
neuper@38041
   630
writeln("b)");
neuper@37906
   631
val e205b'="((5 * x + 2) / 3) + ((-2 * x + 1) / 3)";
neuper@37906
   632
val e205b = the (rewrite_set thy' false "common_nominator_p" e205b');
neuper@38044
   633
if e205b = ("(1 + x) / 1", "[]") then ()
neuper@38044
   634
else error "rational.sml common_nominator_p example e204b";
neuper@37906
   635
neuper@38041
   636
writeln ("example 206:");
neuper@38041
   637
writeln("a)");
neuper@37906
   638
val e206a'="((5 * x + 4) / (2 * x + -1)) + ((9 * x + 5) / (2 * x + -1))";
neuper@37906
   639
val e206a = the (rewrite_set thy' false "common_nominator_p" e206a'); 
neuper@38041
   640
writeln("b)");
neuper@37906
   641
val e206b'="((17 * x + -23) / (5 * x + 4)) + ((-25 + -17 * x) / (5 * x + 4))";
neuper@37906
   642
val e206b = the (rewrite_set thy' false "common_nominator_p" e206b');
neuper@37906
   643
neuper@38041
   644
writeln ("example 207:");
neuper@37906
   645
val e207'="((3 * x * y + 3 * y) / (x * y)) + ((5 * x * y + 7 * y) / (x * y)) + ((9 * x * y + -2 * y) / (x * y)) + ((x * y + 4 * y) / (x * y)) ";
neuper@37906
   646
val e207 = the (rewrite_set thy' false "common_nominator_p" e207'); 
neuper@37906
   647
neuper@38041
   648
writeln ("example 208:");
neuper@37906
   649
val e208'="((3 * x + 2) / (x + 2)) + ((5 * x + -1) / (x + 2)) + ((-7 * x + -3) / (x + 2)) + ((-1 * x + -3) / (x + 2)) ";
neuper@37906
   650
val e208 = the (rewrite_set thy' false "common_nominator_p" e208'); 
neuper@37906
   651
neuper@38041
   652
writeln ("example 209:");
neuper@37906
   653
val e209'="((3 * x + -7 * y + 3 * z) / (4)) + ((2 * x + 17 * y + 10 * z) / (4)) + ((-1 * x + 2 * y + z) / (4)) ";
neuper@37906
   654
val e209 = the (rewrite_set thy' false "common_nominator_p" e209'); 
neuper@37906
   655
neuper@38041
   656
writeln ("example 210:");
neuper@37906
   657
val e210'="((2 * x + 3 +  -1 * x^^^2) / (5 * x)) + ((5 * x^^^2 + -2 * x + 1) / (5 * x)) + ((-3 * x^^^2 + -2 * x + 1) / (5 * x)) + ((-1 * x^^^2 + -3 * x + -5) / (5 * x)) ";
neuper@37906
   658
val e210 = the (rewrite_set thy' false "common_nominator_p" e210'); 
neuper@37906
   659
neuper@38041
   660
writeln ("example 211:");
neuper@38041
   661
writeln("a)"); 
neuper@37906
   662
val e211a'="((b) / (a + -1 * b)) + ((-1 * a) / (a + -1 * b))"; 
neuper@37906
   663
val e211a = the (rewrite_set thy' false "common_nominator_p" e211a'); 
neuper@38041
   664
writeln("b)");
neuper@37906
   665
val e211b'="((b) / (b^^^2 + -1 * a^^^2)) + ((-1 * a) / (b^^^2 + -1 * a^^^2))";
neuper@37906
   666
val e211b = the (rewrite_set thy' false "common_nominator_p" e211b');
neuper@37906
   667
neuper@38041
   668
writeln ("example 212:");
neuper@38041
   669
writeln("a)");
neuper@37906
   670
val e212a'="((4) / (x)) + ((-3) / (y)) + -1";
neuper@37906
   671
val e212a = the (rewrite_set thy' false "common_nominator_p" e212a'); 
neuper@38041
   672
writeln("b)");
neuper@37906
   673
val e212b'="((4) / (x)) + ((-5) / (y)) + ((6) / (x*y))";
neuper@37906
   674
val e212b = the (rewrite_set thy' false "common_nominator_p" e212b');
neuper@37906
   675
neuper@38041
   676
writeln ("example 213:");
neuper@38041
   677
writeln("a)"); 
neuper@37906
   678
val e213a'="((5 * x) / (3 * y^^^2)) + ((19 * z) / (6 * x * y)) +  ((-2 * x) / (3 * y^^^2)) + ((7 * y^^^2) / (6 * x^^^2)) ";
neuper@37906
   679
val e213a = the (rewrite_set thy' false "common_nominator_p" e213a'); 
neuper@38041
   680
writeln("b)"); 
neuper@37906
   681
val e213b'="((2 * b) / (3 * a^^^2)) + ((3 * c) / (7 * a * b)) +  ((4 * b) / (3 * a^^^2)) + ((3 * a) / (7 * b^^^2))";
neuper@37906
   682
val e213b = the (rewrite_set thy' false "common_nominator_p" e213b');
neuper@37906
   683
neuper@38041
   684
writeln ("example 214:");
neuper@38041
   685
writeln("a)");
neuper@37906
   686
val e214a'="((3 * x + 2 * y + 2 * z) / (4)) + ((-5 * x + -3 * y) / (3)) + ((x + y + -2 * z) / (2))";
neuper@37906
   687
val e214a = the (rewrite_set thy' false "common_nominator_p" e214a'); 
neuper@38041
   688
writeln("b)");
neuper@37906
   689
val e214b'="((5 * x + 2 * y + z) / (2)) + ((-7 * x + -3 * y) / (3)) + ((3 * x + 6 * y + -1 * z) / (12))";
neuper@37906
   690
val e214b = the (rewrite_set thy' false "common_nominator_p" e214b');
neuper@37906
   691
neuper@38041
   692
writeln ("example 216:");
neuper@38041
   693
writeln("a)"); 
neuper@37906
   694
val e216a'="((2 * b + 3 * c) / (a * c)) + ((3 * a + b) / (a * b)) + ((-2 * b^^^2 + -3 * a * c) / (a * b * c))";
neuper@37906
   695
val e216a = the (rewrite_set thy' false "common_nominator_p" e216a');  
neuper@38041
   696
writeln("b)");
neuper@37906
   697
val e216b'="((2 * a + 3 * b) / (b * c)) + ((3 * c + a) / (a * c)) + ((-2 * a^^^2 + -3 * b * c) / (a * b * c))";
neuper@37906
   698
val e216b = the (rewrite_set thy' false "common_nominator_p" e216b');
neuper@37906
   699
neuper@38041
   700
writeln ("example 217:");
neuper@37906
   701
val e217'="((z + -1) / (z)) + ((3 * z ^^^2 + -6 * z + 5) / (z^^^2)) + ((-4 * z^^^3 + 7 * z^^^2 + -5 * z + 5) / (z^^^3))";
neuper@37906
   702
val e217 = the (rewrite_set thy' false "common_nominator_p" e217'); 
neuper@37906
   703
neuper@37906
   704
neuper@37906
   705
val rls' = "common_nominator";
neuper@38041
   706
writeln ("example 218:"); 
neuper@37906
   707
val e218'="((9 * a^^^3 - 5 * a^^^2 + 2 * a + 8) / (108 * a^^^4)) + ((-5 * a + 3 * a^^^2 + 4) / (8 * a^^^3)) + ((-261 * a^^^3 + 19 * a^^^2 + -112 * a + 16) / (216 * a^^^4))";
neuper@37906
   708
val e218 = the (rewrite_set thy' false "common_nominator" e218'); 
neuper@38044
   709
if e218 = ("(16 - 63 * a ^^^ 2 - 81 * a ^^^ 3) / (108 * a ^^^ 4)", "[]") then ()
neuper@38044
   710
else error "rationa.sml common_nominator example e218";
neuper@37906
   711
neuper@38041
   712
writeln ("example 219:");
neuper@38041
   713
writeln("a)");
neuper@37906
   714
val e219a'="((1) / (y + 1)) + ((1) / (y + 2)) + ((1) / (y + 3))";
neuper@37906
   715
val e219a = the (rewrite_set thy' false "common_nominator" e219a');
neuper@38041
   716
writeln("b)");
neuper@37906
   717
val e219b'="((1) / (x + 1)) + ((1) / (x + 2)) + ((-2) / (x + 3))";
neuper@37906
   718
val e219b = the (rewrite_set thy' false "common_nominator" e219b'); 
neuper@38044
   719
if e219b = ("(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)", "[]") then ()
neuper@38044
   720
else error "rationa.sml common_nominator example e219b";
neuper@37906
   721
neuper@38041
   722
writeln ("example 220:");
neuper@38041
   723
writeln("a)");
neuper@37906
   724
val e220a'="((17) / (5 * r + -2)) + ((-13) / (2 * r + 3)) + ((4) / (3 * r + -5))";
neuper@37906
   725
val e220a = the (rewrite_set thy' false "common_nominator" e220a');
neuper@38041
   726
writeln("b)");
neuper@37906
   727
val e220b'="((20 * a) / (a + -3)) + ((-19 * a) / (a + -4)) + ((a) / (a + -5))";
neuper@37906
   728
val e220b = the (rewrite_set thy' false "common_nominator" e220b'); 
neuper@37906
   729
neuper@38041
   730
writeln ("example 221:");
neuper@38041
   731
writeln("a)");
neuper@37906
   732
val e221a'="((a + b) / (a + -1 * b)) + ((a + -1 * b) / (a + b))";
neuper@37906
   733
val e221a = the (rewrite_set thy' false "common_nominator" e221a');
neuper@38041
   734
writeln("b)");
neuper@37906
   735
val e221b'="((x + -1 * y) / (x + y)) + ((x + y) / (x + -1 * y)) ";
neuper@37906
   736
val e221b = the (rewrite_set thy' false "common_nominator" e221b');
neuper@37906
   737
neuper@38041
   738
writeln ("example 222:");
neuper@38041
   739
writeln("a)");
neuper@37906
   740
val e222a'="((1 + -1 * x) / (1 + x)) + ((-1 + -1 * x) / (1 + -1 * x)) + ((4 * x) / (1 + -1 * x^^^2))";
neuper@37906
   741
val e222a = the (rewrite_set thy' false "common_nominator" e222a');
neuper@38041
   742
writeln("b)");
neuper@37906
   743
val e222b'="((1 + x ) / (1 + -1 * x)) + ((-1 + x) / (1 + x)) + ((2 * x) / (1 + -1 * x^^^2))";
neuper@37906
   744
val e222b = the (rewrite_set thy' false "common_nominator" e222b'); 
neuper@37906
   745
neuper@38041
   746
writeln ("example 225:");
neuper@38041
   747
writeln("a)");
neuper@37906
   748
val e225a'="((6 * a) / (a^^^2 + -64)) + ((a + 2) / (2 * a + 16)) + ((-1) / (2))";
neuper@37906
   749
val e225a = the (rewrite_set thy' false "common_nominator" e225a');
neuper@38041
   750
writeln("b)");
neuper@37906
   751
val e225b'="((a + 2 ) / (2 * a + 12)) + ((4 * a) / (a^^^2 + -36)) + ((-1) / (2))";
neuper@37906
   752
val e225b = the (rewrite_set thy' false "common_nominator" e225b'); 
neuper@37906
   753
neuper@38041
   754
writeln ("example 226:");
neuper@38041
   755
writeln("a)");
neuper@37906
   756
val e226a'="((35 * z) / (49 * z^^^2 + -4)) + -1 + ((14 * z + -1) / (14 * z + 4)) ";
neuper@37906
   757
val e226a = the (rewrite_set thy' false "common_nominator" e226a');
neuper@38041
   758
writeln("b)"); 
neuper@37906
   759
val e226b'="((45 * a * b) / (25 * a^^^2 + -9 * b^^^2)) + ((20 * a + 3 * b) / (10 * a + 6 * b))  + -2";
neuper@37906
   760
val e226b = the (rewrite_set thy' false "common_nominator" e226b');  
neuper@37906
   761
neuper@38041
   762
writeln ("example 227:");
neuper@38041
   763
writeln("a)");
neuper@37906
   764
val e227a'="((6 * z + 11) / (6 * z + 14)) + ((9 * z ) / (9 * z^^^2 + -49)) + -1 ";
neuper@37906
   765
val e227a = the (rewrite_set thy' false "common_nominator" e227a');
neuper@38041
   766
writeln("b)");
neuper@37906
   767
val e227b'="((16 * a + 37 * b) / (4 * a + 10 * b)) + ((6 * a * b) / (4 * a^^^2 + -25 * b^^^2)) + -4 ";
neuper@37906
   768
val e227b = the (rewrite_set thy' false "common_nominator" e227b'); 
neuper@37906
   769
neuper@38041
   770
writeln ("example 228:");
neuper@38041
   771
writeln("a)");
neuper@37906
   772
val e228a'="((7 * a + 11) / (3 * a^^^2 + -3)) + ((-2 * a + -1) / (a^^^2 + -1 * a)) + ((-1) / (3 * a + 3))";
neuper@37906
   773
val e228a = the (rewrite_set thy' false "common_nominator" e228a'); 
neuper@38041
   774
writeln("b)");
neuper@37906
   775
val e228b'="((11 * z + 2 * b) / (4 * b * z + -8 * b^^^2)) + ((-8 * z) / (z^^^2 + -4 * b^^^2)) + ((-9 * z + -2 * b) / (4 * b * z + 8 * b^^^2))";
neuper@37906
   776
val e228b = the (rewrite_set thy' false "common_nominator" e228b');  
neuper@37906
   777
neuper@37906
   778
neuper@38041
   779
writeln ("example 229:");
neuper@38041
   780
writeln("a)");
neuper@37906
   781
val e229a'="((5 * x^^^2 + y) / (x + 2 * y)) + ((-8 * x^^^3 + 4 * x^^^2 * y + 3 * x * y) / (x^^^2 + -4 * y^^^2)) + ((3 * x^^^2 + -4 * y) / (x + -2 * y))";
neuper@37906
   782
val e229a = the (rewrite_set thy' false "common_nominator" e229a'); 
neuper@38041
   783
writeln("b)");
neuper@37906
   784
val e229b'="((7 * x^^^2 + y) / (x + 3 * y)) + ((-24 * x^^^2 * y + 5 * x * y + 21 * y^^^2) / (x^^^2 + -9 * y^^^2)) + ((4 * x^^^2 + -6 * y) / (x + -3 * y))"; 
neuper@37906
   785
val e229b = the (rewrite_set thy' false "common_nominator" e229b'); 
neuper@37906
   786
 
neuper@38041
   787
writeln ("example 230:");
neuper@38041
   788
writeln("a)"); 
neuper@37906
   789
val e230a'="((5 * x^^^2 + y) / (2 * x + y)) + ((-16 * x^^^3 + 2 * x^^^2 * y + 6 * x * y) / (4 * x^^^2 + -1 * y^^^2)) + ((3 * x^^^2 + -4 * y) / (2 * x + -1 * y))";
neuper@37906
   790
val e230a = the (rewrite_set thy' false "common_nominator" e230a');
neuper@38041
   791
writeln("b)");
neuper@37906
   792
val e230b'="((7 * x^^^2 + y) / (3 * x + y)) + ((-3 * x^^^3  + 15 * x * y + -7 * x^^^2 * y + 7 * y^^^2) / (9 * x^^^2 + -1 * y^^^2)) + ((4 * x^^^2 + -6 * y) / (3 * x + -1 * y))";
neuper@37906
   793
val e230b = the (rewrite_set thy' false "common_nominator" e230b');
neuper@37906
   794
neuper@38041
   795
writeln ("example 231:");
neuper@38041
   796
writeln("a)");
neuper@37906
   797
val e231a'="((2 * x + 5 * y) / (x)) + ((2 * x^^^3 + -5 * y^^^3 + 3 * x * y^^^2) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-3 * x + -6 * y) / (x + -1 * y))";
neuper@37906
   798
val e231a = the (rewrite_set thy' false "common_nominator" e231a'); 
neuper@38041
   799
writeln("b)");
neuper@37906
   800
val e231b'="((6 * x + 2 * y) / (x)) + ((6 * x^^^2 * y + -4 * x * y^^^2 + -2 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-5 * x + -3 * y) / (x + -1 * y))";
neuper@37906
   801
val e231b = the (rewrite_set thy' false "common_nominator" e231b');
neuper@37906
   802
neuper@38041
   803
writeln ("example 232:");
neuper@38041
   804
writeln("a)");
neuper@37906
   805
val e232a'="((2 * x + 3 * y) / (x)) + ((4 * x^^^3 + -1 * x * y^^^2 + -3 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-5 * x + -6 * y) / (x + -1 * y))";
neuper@37906
   806
val e232a = the (rewrite_set thy' false "common_nominator" e232a'); 
neuper@38041
   807
writeln("b)");
neuper@37906
   808
val e232b'="((5 * x + 2 * y) / (x)) + ((2 * x^^^3 + -3 * x * y^^^2 + 3 * x^^^2 * y + -2 * y^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-6 * x + -3 * y) / (x + -1 * y))";
neuper@37906
   809
val e232b = the (rewrite_set thy' false "common_nominator" e232b');
neuper@37906
   810
neuper@38041
   811
writeln ("example 233:");
neuper@38041
   812
writeln("a)");
neuper@37906
   813
val e233a'="((5 * x + 6 * y) / (x)) + ((5 * x * y^^^2 + -6 * y^^^3 + -2 * x^^^3 + 3 * x^^^2 * y) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-2 * x + -3 * y) / (x + -1 * y))";
neuper@37906
   814
val e233a = the (rewrite_set thy' false "common_nominator" e233a'); 
neuper@38041
   815
writeln("b)");
neuper@37906
   816
val e233b'="((6 * x + 5 * y) / (x)) + ((4 * x^^^2 * y + 3 * x * y^^^2 + -5 * y^^^3 + -2 * x^^^3) / (x^^^3 + -2 * x^^^2 * y + x * y^^^2)) + ((-3 * x + -2 * y) / (x + -1 * y))";
neuper@37906
   817
val e233b = the (rewrite_set thy' false "common_nominator" e233b');
neuper@37906
   818
neuper@38041
   819
writeln ("example 234:");
neuper@38041
   820
writeln("a)");
neuper@37906
   821
val e234a'="((5 * a + b) / (2 * a * b + -2 * b^^^2)) + ((-3 * a + -1 * b) / (2 * a * b + 2 * b^^^2)) + ((-2 * a) / (a^^^2 + -1 * b^^^2))";
neuper@37906
   822
val e234a = the (rewrite_set thy' false "common_nominator" e234a'); 
neuper@38041
   823
writeln("b)"); 
neuper@37906
   824
val e234b'="((5 * a + 3 * b) / (6 * a * b + -18 * b^^^2)) + ((-3 * a + -3 * b) / (6 * a * b + 18 * b^^^2)) + ((-2 * a) / (a^^^2 + -9 * b^^^2)) ";
neuper@37906
   825
val e234b = the (rewrite_set thy' false "common_nominator" e234b');  
neuper@37906
   826
neuper@38041
   827
writeln ("example 235:");
neuper@38041
   828
writeln("a)");
neuper@37906
   829
val e235a'="((10 * x + 3 * y) / (12 * x * y + -18 * y^^^2)) + ((-6 * x + -3 * y) / (12 * x * y + 18 * y^^^2)) + ((-4 * x) / (4 * x^^^2 + -9 * y^^^2))";
neuper@37906
   830
val e235a = the (rewrite_set thy' false "common_nominator" e235a'); 
neuper@38041
   831
writeln("b)"); 
neuper@37906
   832
val e235b'="((8 * a + b) / (4 * a * b + -2 * b^^^2)) + ((-4 * a + -1 * b) / (4 * a * b + 2 * b^^^2)) + ((-2 * a) / (4 * a^^^2 + -1 * b^^^2)) ";
neuper@37906
   833
val e235b = the (rewrite_set thy' false "common_nominator" e235b');  
neuper@37906
   834
 
neuper@38041
   835
writeln ("example 236:");
neuper@38041
   836
writeln("a)"); 
neuper@37906
   837
val e236a'="((8 * a + 5 * b) / (20 * a * b + -50 * b^^^2)) + ((-4 * a + -5 * b) / (20 * a * b + 50 * b^^^2)) + ((-2 * a) / (4 * a^^^2 + -25 * b^^^2))";
neuper@37906
   838
val e236a = the (rewrite_set thy' false "common_nominator" e236a');  
neuper@38041
   839
writeln("b)");   
neuper@37906
   840
val e236b'="((24 * x + y) / (6 * x * y + -2 * y^^^2)) + ((-18 * x + -1 * y) / (6 * x * y + 2 * y^^^2)) + ((-15 * x) / (9 * x^^^2 + -1 * y^^^2)) ";
neuper@37906
   841
val e236b = the (rewrite_set thy' false "common_nominator" e236b');  
neuper@37906
   842
neuper@37906
   843
neuper@37906
   844
val rls' = "cancel";
neuper@38041
   845
writeln ("example heuberger:");
neuper@37906
   846
val eheu'="(x^^^4 + x * y + x^^^3 * y + y^^^2) / (x + 5 * x^^^2 + y + 5 * x * y + x^^^2 * y^^^3 + x * y^^^4)";
neuper@37906
   847
val eheu = the (rewrite_set thy' false "cancel" eheu');
neuper@37906
   848
neuper@37906
   849
val rls' = "common_nominator_p";
neuper@38041
   850
writeln ("example stiefel:");
neuper@37906
   851
val est1'="(7) / (-14) + (-2) / (4)";
neuper@37906
   852
val est1 = the (rewrite_set thy' false "common_nominator_p" est1');
neuper@38044
   853
if est1 = ("-1 / 1", "[]") then ()
neuper@38031
   854
else error "new behaviour in rational.sml: est1'";
neuper@37906
   855
    
neuper@37906
   856
val t = (term_of o the o (parse thy))
neuper@37906
   857
"(9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
neuper@37926
   858
val SOME (t',_) = factout_ thy t;
neuper@38044
   859
if term2str t' = "(3 + x) * (3 - x) / ((3 - x) * (3 - x))" then ()
neuper@38044
   860
else error "rational.sml factout_ (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
neuper@37906
   861
    
neuper@37906
   862
neuper@38041
   863
"-------- reverse rewrite -------------------------------";
neuper@38041
   864
"-------- reverse rewrite -------------------------------";
neuper@38041
   865
"-------- reverse rewrite -------------------------------";
neuper@37906
   866
(*WN.28.8.02: tests for the 'reverse-rewrite' functions:
neuper@37906
   867
  these are defined in Rationals.ML and stored in 
neuper@37906
   868
  the 'reverse-ruleset' cancel*)
neuper@37906
   869
neuper@37906
   870
(*the term for which reverse rewriting is demonstrated*)
neuper@37906
   871
  val t = (term_of o the o (parse thy))
neuper@37906
   872
	      "(9 - x ^^^ 2) / (9 + 6 * x + x ^^^ 2)";
neuper@37906
   873
  val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
neuper@37906
   874
  		       next_rule=nex,normal_form=nor,...},...} = cancel;
neuper@37906
   875
neuper@37906
   876
(*normal_form produces the result in ONE step*)
neuper@37926
   877
  val SOME (t',_) = nor t;
neuper@38044
   878
if term2str t' = "(3 - x) / (3 + x)" then ()
neuper@38044
   879
else error "rational.sml normal_form (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
neuper@37906
   880
neuper@37906
   881
(*initialize the interpreter state used by the 'me'*)
neuper@37906
   882
  val (t,_,revsets,_) = ini t;
neuper@37906
   883
neuper@37906
   884
(*find the rule 'r' to apply to term 't'*)
neuper@38044
   885
  val SOME (r as (Thm (str, thm))) = nex revsets t;
neuper@38044
   886
if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))"
neuper@38044
   887
   andalso string_of_thm thm = 
neuper@41929
   888
           (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
neuper@38044
   889
               (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
neuper@38044
   890
else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
neuper@38044
   891
(* before Isa02->09-2 was not checked automatically, ?was different?:
neuper@38044
   892
val SOME r = nex revsets t;
neuper@38044
   893
val r = Thm ("sym_#mult_2_3","6 = 2 * 3") : rule*)
neuper@37906
   894
neuper@38044
   895
(* check, if the rule 'r' applied by the user to 't' belongs to the ruleset;
neuper@37906
   896
  if the rule is OK, the term resulting from applying the rule is returned,too;
neuper@37906
   897
  there might be several rule applications inbetween,
neuper@38044
   898
  which are listed after the head in reverse order *)
neuper@38044
   899
  val (r, (t, asm))::_ = loc revsets t r;
neuper@38044
   900
if term2str t = "(9 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" andalso asm = []
neuper@38044
   901
then () 
neuper@38044
   902
else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
neuper@37906
   903
neuper@38044
   904
(* find the next rule to apply *)
neuper@38044
   905
  val SOME (r as (Thm (str, thm))) = nex revsets t;
neuper@38044
   906
if str = "sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))" andalso
neuper@41929
   907
   string_of_thm thm = (string_of_thm o make_thm o (cterm_of (@{theory "Isac"})))
neuper@38044
   908
                (Trueprop $ (term_of o the o (parse thy)) "9 = 3 ^^^ 2") then ()
neuper@38044
   909
else error "rational.sml next_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2)";
neuper@37906
   910
neuper@37906
   911
(*check the next rule*)
neuper@38044
   912
  val (r, (t, asm)) :: _ = loc revsets t r;
neuper@38044
   913
if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 6 * x + x ^^^ 2)" then ()
neuper@38044
   914
else error "rational.sml locate_rule (9 - x ^^^ 2) / (9 - 6 * x + x ^^^ 2) II";
neuper@37906
   915
neuper@37906
   916
(*find and check the next rules, rewrite*)
neuper@37926
   917
  val SOME r = nex revsets t;
neuper@37906
   918
  val (r,(t,asm))::_ = loc revsets t r;
neuper@38044
   919
if term2str t = "(3 ^^^ 2 - x ^^^ 2) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
neuper@38044
   920
else error "rational.sml locate_rule II";
neuper@37906
   921
neuper@37926
   922
  val SOME r = nex revsets t;
neuper@37906
   923
  val (r,(t,asm))::_ = loc revsets t r;
neuper@38044
   924
if term2str t = "(3 - x) * (3 + x) / (3 ^^^ 2 + 2 * 3 * x + x ^^^ 2)" then ()
neuper@38044
   925
else error "rational.sml next_rule II";
neuper@37906
   926
neuper@37926
   927
  val SOME r = nex revsets t;
neuper@37906
   928
  val (r,(t,asm))::_ = loc revsets t r;
neuper@38044
   929
if term2str t = "(3 - x) * (3 + x) / ((3 + x) * (3 + x))" then ()
neuper@38044
   930
else error "rational.sml next_rule III";
neuper@37906
   931
neuper@37926
   932
  val SOME r = nex revsets t;
neuper@38044
   933
  val (r, (t, asm)) :: _ = loc revsets t r;
neuper@37906
   934
  val ss = term2str t;
neuper@38044
   935
if ss = "(3 - x) / (3 + x)" andalso terms2str asm = "[\"3 + x ~= 0\"]" then ()
neuper@38044
   936
else error "rational.sml: new behav. in rev-set cancel";
neuper@37906
   937
neuper@38041
   938
"-------- 'reverse-ruleset' cancel_p --------------------";
neuper@38041
   939
"-------- 'reverse-ruleset' cancel_p --------------------";
neuper@38041
   940
"-------- 'reverse-ruleset' cancel_p --------------------";
neuper@37906
   941
(*WN.11.9.02: the 'reverse-ruleset' cancel_p*)
neuper@37906
   942
neuper@37906
   943
(*the term for which reverse rewriting is demonstrated*)
neuper@37906
   944
val t = str2term "(9 + (-1)*x^^^2) / (9 + ((-6)*x + x^^^2))";
neuper@37906
   945
val Rrls {scr=Rfuns {init_state=ini,locate_rule=loc,
neuper@37906
   946
		       next_rule=nex,normal_form=nor,...},...} = cancel_p;
neuper@37906
   947
neuper@37906
   948
(*normal_form produces the result in ONE step*)
neuper@37926
   949
val SOME (t',_) = nor t; 
neuper@37906
   950
term2str t' = "(3 + 1 * x) / (3 + -1 * x)";
neuper@37906
   951
neuper@37906
   952
(*initialize the interpreter state used by the 'me'*)
neuper@37926
   953
val SOME (t', asm) = cancel_p_ thy t;
neuper@37906
   954
term2str t' = "(3 + x) / (3 + -1 * x)" (*true*);
neuper@37906
   955
terms2str asm = "[\"3 + -1 * x ~= 0\"]" (*true*);
neuper@37906
   956
val (t,_,revsets,_) = ini t;
neuper@37906
   957
neuper@37906
   958
(* WN.10.10.02: dieser Fall terminiert nicht 
neuper@37906
   959
           (make_polynomial enth"alt zu viele rules)
neuper@37906
   960
WN060823 'init_state' requires rewriting on specified location in the term
neuper@37906
   961
print_depth 99; Rfuns; print_depth 3;
neuper@37906
   962
WN060831 cycling "sym_order_mult_rls_" "sym_real_mult_assoc"
neuper@37906
   963
         as was with make_polynomial before ?!?*)
neuper@37906
   964
neuper@37926
   965
val SOME r = nex revsets t;
neuper@37906
   966
eq_Thm (r, Thm ("sym_#power_Float ((3,0), (0,0)) __ ((2,0), (0,0))", 
neuper@38041
   967
		mk_thm thy "9 = 3 ^^^ 2"));
neuper@37906
   968
(*WN060831 *** id_of_thm
neuper@37906
   969
           Exception- ERROR raised ...
neuper@37906
   970
val (r,(t,asm))::_ = loc revsets t r;
neuper@37906
   971
term2str t;
neuper@37906
   972
neuper@37926
   973
  val SOME r = nex revsets t;
neuper@37906
   974
  val (r,(t,asm))::_ = loc revsets t r;
neuper@37906
   975
  term2str t;
neuper@37906
   976
*)
neuper@37906
   977
neuper@38041
   978
writeln "******************  all tests successfull  *************************";
neuper@37906
   979
neuper@37906
   980
neuper@37906
   981
neuper@37906
   982
(*WN.17.3.03 =========================================================vvv---*)
neuper@38041
   983
"-------- norm_Rational ---------------------------------";
neuper@38041
   984
"-------- norm_Rational ---------------------------------";
neuper@38041
   985
"-------- norm_Rational ---------------------------------";
neuper@37906
   986
val t = str2term "(3*x+5)/18 - x/2  - -(3*x - 2)/9 = 0";
neuper@37926
   987
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38031
   988
if term2str t' = "1 / 18 = 0" then () else error "rational.sml 1";
neuper@37906
   989
neuper@37906
   990
val t = str2term "(17*x - 51)/9 - (-(13*x - 3)/6) + 11 - (9*x - 7)/4 = 0";
neuper@37926
   991
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
   992
if term2str t' = "(237 + 65 * x) / 36 = 0" then () 
neuper@38031
   993
else error "rational.sml 2";
neuper@37906
   994
neuper@37906
   995
val t = str2term "(1/2 + (5*x)/2)^^^2 - ((13*x)/2 - 5/2)^^^2 - (6*x)^^^2 + 29";
neuper@37926
   996
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
   997
if term2str t' = "23 + 35 * x + -72 * x ^^^ 2" then ()
neuper@38031
   998
else error "rational.sml 3";
neuper@38046
   999
neuper@37906
  1000
(*trace_rewrite:=true;*)
neuper@37906
  1001
val t = str2term "Not (6*x is_atom)";
neuper@37926
  1002
val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
neuper@41928
  1003
"HOL.True";
neuper@37906
  1004
val t = str2term "1 < 2";
neuper@37926
  1005
val SOME (t',_) = rewrite_set_ thy false powers_erls t; term2str t';
neuper@41928
  1006
"HOL.True";
neuper@38046
  1007
neuper@37906
  1008
val t = str2term "(6*x)^^^2";
neuper@37926
  1009
val SOME (t',_) = rewrite_ thy dummy_ord powers_erls false 
neuper@38041
  1010
			   (num_str @{thm realpow_def_atom}) t;
neuper@38046
  1011
if term2str t' = "6 * x * (6 * x) ^^^ (2 + -1)" then ()
neuper@38046
  1012
else error "rational.sml powers_erls (6*x)^^^2";
neuper@37906
  1013
neuper@37906
  1014
val t = str2term "-1 * (-2 * (5 / 2 * (13 * x / 2)))";
neuper@37926
  1015
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38031
  1016
if term2str t' = "65 * x / 2" then () else error "rational.sml 4";
neuper@37906
  1017
neuper@37906
  1018
val t = str2term "1 - ((13*x)/2 - 5/2)^^^2";
neuper@37926
  1019
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
  1020
(*bef.040209: if term2str t' = "(-21 + (130 * x + -169 * x ^^^ 2)) / 4"then()*)
neuper@37906
  1021
if term2str t' = "(-21 + 130 * x + -169 * x ^^^ 2) / 4" then () 
neuper@38031
  1022
else error "rational.sml 5";
neuper@37906
  1023
neuper@37906
  1024
(*SRAM Schalk I, p.92 Nr. 609a*)
neuper@37906
  1025
val t = str2term "2*(3 - x/5)/3 - 4*(1 - x/3) - x/3 - 2*(x/2 - 1/4)/27 +5/54";
neuper@37926
  1026
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
  1027
if term2str t' = "(-255 + 112 * x) / 135" then () 
neuper@38031
  1028
else error "rational.sml 6";
neuper@37906
  1029
neuper@37906
  1030
(*SRAM Schalk I, p.92 Nr. 610c*)
neuper@37906
  1031
val t = str2term "((x- 1)/(x+1) + 1) / ((x- 1)/(x+1) - (x+1)/(x- 1)) - 2";
neuper@37926
  1032
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38031
  1033
if term2str t' = "(-3 + -1 * x) / 2" then () else error "rational.sml 7";
neuper@37906
  1034
neuper@37906
  1035
(*SRAM Schalk I, p.92 Nr. 476a*)
neuper@38046
  1036
val t = str2term "(x^^^2/(1 - x^^^2) + 1)/(x/(1 - x) + 1) * (1 + x)";
neuper@38046
  1037
(*. a/b : c/d translated to a/b * d/c .*)
neuper@37926
  1038
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38031
  1039
(*if term2str t' = "1 / 1" then () else error "rational.sml 8";3.6.03*)
neuper@38031
  1040
if term2str t' = "1" then () else error "rational.sml 8";
neuper@37906
  1041
neuper@37906
  1042
(*............................vvv---TODO: sollte gehen mit poly_order *)
neuper@37906
  1043
(*Schalk I, p.92 Nr. 472a*)
neuper@37906
  1044
val t = str2term "((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/((4*x - 8*y)/(x + y))";
neuper@37926
  1045
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38031
  1046
if term2str t' = "x + y" then () else error "rational.sml p.92 Nr. 472a";
neuper@37906
  1047
neuper@37906
  1048
(*Schalk I, p.70 Nr. 480b; a/b : c/d translated to a/b * d/c*)
neuper@38046
  1049
val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
neuper@38041
  1050
		 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
neuper@38041
  1051
		 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
neuper@38046
  1052
		 "(20*x*y/(x^^^2 - 25*y^^^2))");
neuper@37906
  1053
(*... nicht simpl, zerlegt ...*)
neuper@38046
  1054
val t = str2term ("((12*x*y/(9*x^^^2 - y^^^2))/" ^
neuper@38046
  1055
		 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2))");
neuper@37926
  1056
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
  1057
"(-12 * (x * y ^^^ 3) + 108 * (x * (y * x ^^^ 2))) / (12 * (x * y))";
neuper@37906
  1058
(*                             ~~~~~~~~~~ poly_order notwendig!*)
neuper@38046
  1059
val t = str2term ("(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
neuper@38046
  1060
		 "(20*x*y/(x^^^2 - 25*y^^^2))");
neuper@37926
  1061
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@38046
  1062
if term2str t' = "1 / (x ^^^ 2 + -25 * y ^^^ 2)" then ()
neuper@38046
  1063
else error "rational.sml norm_Rational 1 / (x ^^^ 2 + -25 * y ^^^ 2)";
neuper@37906
  1064
neuper@37906
  1065
"nonterm.SK6 ----- SK060904-2a non-termination of add_fraction_p_";
neuper@37906
  1066
(*WN.2.6.03 from rlang.sml 56a 
neuper@37906
  1067
val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x) = 4 * (a * b) / (a ^^^ 2 + -1 * b ^^^ 2)";
neuper@37926
  1068
val NONE = rewrite_set_ thy false common_nominator_p t;
neuper@37906
  1069
neuper@37906
  1070
WN060831 nonterm.SK7 
neuper@37906
  1071
val t = str2term "(a + b * x) / (a + -1 * (b * x)) + (-1 * a + b * x) / (a + b * x)";
neuper@37926
  1072
val NONE = add_fraction_p_ thy t; 
neuper@37906
  1073
*)
neuper@37906
  1074
neuper@37906
  1075
neuper@37906
  1076
(* ------------------------------------------------------------------- *)
neuper@37906
  1077
(*---------vvv------------ MG: ab 1.7.03 ----------------vvv-----------*)
neuper@37906
  1078
(*                 Simplifier fuer beliebige Buchterme                 *) 
neuper@37906
  1079
(* ------------------------------------------------------------------- *)
neuper@37906
  1080
(*----------------------- norm_Rational_mg ----------------------------*)
neuper@37906
  1081
(* ------------------------------------------------------------------- *)
neuper@37906
  1082
neuper@38041
  1083
"-------- numeral rationals -----------------------------";
neuper@38041
  1084
"-------- numeral rationals -----------------------------";
neuper@38041
  1085
"-------- numeral rationals -----------------------------";
neuper@37906
  1086
(*SRA Schalk I, p.40 Nr. 164b *)
neuper@37906
  1087
val t = str2term "(47/6 - 76/9 + 13/4)/(35/12)";
neuper@37926
  1088
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1089
term2str t;
neuper@37906
  1090
if (term2str t) = "19 / 21" then ()
neuper@38046
  1091
else error "rational.sml: diff.behav. in norm_Rational_mg 1";
neuper@37906
  1092
neuper@37906
  1093
(*SRA Schalk I, p.40 Nr. 166a *)
neuper@37906
  1094
val t = str2term "((5/4)/(4+22/7) + 37/20)*(110/3 - 110/9 * 23/11)";
neuper@37926
  1095
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1096
term2str t;
neuper@37906
  1097
if (term2str t) = "45 / 2" then ()
neuper@38046
  1098
else error "rational.sml: diff.behav. in norm_Rational_mg 2";
neuper@37906
  1099
neuper@37906
  1100
neuper@38041
  1101
"-------- cancellation ----------------------------------";
neuper@38041
  1102
"-------- cancellation ----------------------------------";
neuper@38041
  1103
"-------- cancellation ----------------------------------";
neuper@37906
  1104
(* e190c Stefan K.*)
neuper@37906
  1105
val t = str2term
neuper@37906
  1106
"((1 + 9 * a ^^^ 2)*(1 + 3 * a))/((3 * a + 9 * a ^^^ 2)*(1 + 3 * a))";
neuper@37926
  1107
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1108
term2str t;
neuper@37906
  1109
if (term2str t) = 
neuper@37906
  1110
"(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
neuper@37906
  1111
then ()
neuper@38046
  1112
else error "rational.sml: diff.behav. in norm_Rational_mg 3";
neuper@37906
  1113
neuper@37906
  1114
(* e192b Stefan K.*)
neuper@37906
  1115
val t = str2term
neuper@37906
  1116
"((x ^^^ 2)*(7 * x + (-1) * y))/((y ^^^ 2)*(7 * x + (-1) * y))";
neuper@37926
  1117
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1118
term2str t;
neuper@37906
  1119
if (term2str t) = 
neuper@37906
  1120
"x ^^^ 2 / y ^^^ 2"
neuper@37906
  1121
then ()
neuper@38046
  1122
else error "rational.sml: diff.behav. in norm_Rational_mg 4";
neuper@37906
  1123
neuper@37906
  1124
(*SRC Schalk I, p.66 Nr. 379c *)
neuper@37906
  1125
val t = str2term 
neuper@37906
  1126
"(a - b)/(b - a)";
neuper@37926
  1127
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1128
term2str t;
neuper@37906
  1129
if (term2str t) =
neuper@37906
  1130
"-1"
neuper@37906
  1131
then ()
neuper@38046
  1132
else error "rational.sml: diff.behav. in norm_Rational_mg 5";
neuper@37906
  1133
neuper@37906
  1134
(*SRC Schalk I, p.66 Nr. 380b *)
neuper@37906
  1135
val t = str2term 
neuper@37906
  1136
"15*(3*x+3)*(4*x+9)/(12*(2*x+7)*(5*x+5))";
neuper@37926
  1137
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1138
term2str t;
neuper@37906
  1139
if (term2str t) =
neuper@37906
  1140
"(27 + 12 * x) / (28 + 8 * x)"
neuper@37906
  1141
then ()
neuper@38046
  1142
else error "rational.sml: diff.behav. in norm_Rational_mg 6";
neuper@37906
  1143
neuper@37906
  1144
(*Schalk I, p.60 Nr. 215c *)
neuper@37906
  1145
(* Falsches Ergebnis: rechnet lange und cancel_p kann nicht weiter krzen!!!*)
neuper@37906
  1146
(* WN060831????MG1 
neuper@37906
  1147
val t = str2term "(a+b)^^^4*(x - y)/((x - y)^^^3*(a+b)^^^2)";
neuper@37926
  1148
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1149
term2str t;
neuper@37906
  1150
if (term2str t) =
neuper@37906
  1151
"(a ^^^ 4 * x + -1 * a ^^^ 4 * y + 4 * a ^^^ 3 * b * x + -4 * a ^^^ 3 * b * y + 6 * a ^^^ 2 * b ^^^ 2 * x + -6 * a ^^^ 2 * b ^^^ 2 * y + 4 * a * b ^^^ 3 * x + -4 * a * b ^^^ 3 * y + b ^^^ 4 * x + -1 * b ^^^ 4 * y) /(a ^^^ 2 * x ^^^ 3 + -3 * a ^^^ 2 * x ^^^ 2 * y + 3 * a ^^^ 2 * x * y ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 3 + 2 * a * b * x ^^^ 3 + -6 * a * b * x ^^^ 2 * y + 6 * a * b * x * y ^^^ 2 + -2 * a * b * y ^^^ 3 + b ^^^ 2 * x ^^^ 3 + -3 * b ^^^ 2 * x ^^^ 2 * y + 3 * b ^^^ 2 * x * y ^^^ 2 + -1 * b ^^^ 2 * y ^^^ 3)"
neuper@37906
  1152
then ()
neuper@38046
  1153
else error "rational.sml: diff.behav. in norm_Rational_mg 7";
neuper@37906
  1154
*)
neuper@37906
  1155
(*val t = str2term 
neuper@37906
  1156
"(a ^^^ 4 * x + -1 * a ^^^ 4 * y + 4 * a ^^^ 3 * b * x + -4 * a ^^^ 3 * b * y + 6 * a ^^^ 2 * b ^^^ 2 * x + -6 * a ^^^ 2 * b ^^^ 2 * y + 4 * a * b ^^^ 3 * x + -4 * a * b ^^^ 3 * y + b ^^^ 4 * x + -1 * b ^^^ 4 * y) /(a ^^^ 2 * x ^^^ 3 + -3 * a ^^^ 2 * x ^^^ 2 * y + 3 * a ^^^ 2 * x * y ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 3 + 2 * a * b * x ^^^ 3 + -6 * a * b * x ^^^ 2 * y + 6 * a * b * x * y ^^^ 2 + -2 * a * b * y ^^^ 3 + b ^^^ 2 * x ^^^ 3 + -3 * b ^^^ 2 * x ^^^ 2 * y + 3 * b ^^^ 2 * x * y ^^^ 2 + -1 * b ^^^ 2 * y ^^^ 3)"
neuper@37926
  1157
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1158
term2str t;*)
neuper@37906
  1159
(* uncaught exception nonexhaustive binding failure
neuper@37906
  1160
   raised at: stdIn:93.1-93.51 *)
neuper@37906
  1161
neuper@37906
  1162
(*Schalk I, p.66 Nr. 381a *)
neuper@37906
  1163
(* ACHTUNG: rechnet ca. 2 Minuten !!! *)
neuper@37906
  1164
(* WN060831???MG2
neuper@37906
  1165
val t = str2term "18*(a+b)^^^3*(a - b)^^^2/(72*(a - b)^^^3*(a+b)^^^2)";
neuper@37926
  1166
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1167
term2str t;
neuper@37906
  1168
if (term2str t) =
neuper@37906
  1169
"(a + b) / (4 * a + -4 * b)"
neuper@38046
  1170
then () else error "rational.sml: diff.behav. in norm_Rational_mg 8";
neuper@37906
  1171
*)
neuper@37906
  1172
neuper@37906
  1173
(*SRC Schalk I, p.66 Nr. 381b *)
neuper@37906
  1174
val t = str2term 
neuper@37906
  1175
"(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
neuper@37926
  1176
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1177
term2str t;
neuper@37906
  1178
if (term2str t) =
neuper@37906
  1179
"-1 / (5 + -2 * x)"
neuper@37906
  1180
then ()
neuper@38046
  1181
else error "rational.sml: diff.behav. in norm_Rational_mg 9";
neuper@37906
  1182
neuper@37906
  1183
(*SRC Schalk I, p.66 Nr. 381c *)
neuper@37906
  1184
val t = str2term 
neuper@37906
  1185
"(27*a^^^3+9*a^^^2+3*a+1)/(27*a^^^3+18*a^^^2+3*a)";
neuper@37926
  1186
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1187
term2str t;
neuper@37906
  1188
if (term2str t) =
neuper@37906
  1189
"(1 + 9 * a ^^^ 2) / (3 * a + 9 * a ^^^ 2)"
neuper@37906
  1190
then ()
neuper@38046
  1191
else error "rational.sml: diff.behav. in norm_Rational_mg 10";
neuper@37906
  1192
neuper@37906
  1193
(*SRC Schalk I, p.66 Nr. 383a *)
neuper@37906
  1194
val t = str2term 
neuper@37906
  1195
"(5*a^^^2 - 5*a*b)/(a - b)^^^2";
neuper@37926
  1196
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1197
term2str t;
neuper@37906
  1198
if (term2str t) =
neuper@37906
  1199
"5 * a / (a + -1 * b)"
neuper@37906
  1200
then ()
neuper@38046
  1201
else error "rational.sml: diff.behav. in norm_Rational_mg 11";
neuper@37906
  1202
neuper@37906
  1203
neuper@38041
  1204
"-------- common denominator ----------------------------";
neuper@38041
  1205
"-------- common denominator ----------------------------";
neuper@38041
  1206
"-------- common denominator ----------------------------";
neuper@37906
  1207
(*SRA Schalk I, p.67 Nr. 403a *)
neuper@37906
  1208
val t = str2term 
neuper@37906
  1209
"4/x - 3/y - 1";
neuper@37926
  1210
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1211
term2str t;
neuper@37906
  1212
if (term2str t) =
neuper@37906
  1213
"(-3 * x + 4 * y + -1 * x * y) / (x * y)"
neuper@37906
  1214
then ()
neuper@38046
  1215
else error "rational.sml: diff.behav. in norm_Rational_mg 12";
neuper@37906
  1216
neuper@37906
  1217
(*SRA Schalk I, p.67 Nr. 407b *)
neuper@37906
  1218
val t = str2term 
neuper@37906
  1219
"(2*a+3*b)/(b*c) + (3*c+a)/(a*c) - (2*a^^^2+3*b*c)/(a*b*c)";
neuper@37926
  1220
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1221
term2str t;
neuper@37906
  1222
if (term2str t) =
neuper@37906
  1223
"4 / c"
neuper@37906
  1224
then ()
neuper@38046
  1225
else error "rational.sml: diff.behav. in norm_Rational_mg 13";
neuper@37906
  1226
neuper@37906
  1227
(*SRA Schalk I, p.67 Nr. 410b *)
neuper@37906
  1228
val t = str2term 
neuper@37906
  1229
"1/(x+1) + 1/(x+2) - 2/(x+3)";
neuper@37926
  1230
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1231
term2str t;
neuper@37906
  1232
if (term2str t) =
neuper@37906
  1233
"(5 + 3 * x) / (6 + 11 * x + 6 * x ^^^ 2 + x ^^^ 3)"
neuper@37906
  1234
then ()
neuper@38046
  1235
else error "rational.sml: diff.behav. in norm_Rational_mg 14";
neuper@37906
  1236
neuper@37906
  1237
(*SRA Schalk I, p.67 Nr. 413b *)
neuper@37906
  1238
val t = str2term 
neuper@37906
  1239
"(1+x)/(1 - x) - (1 - x)/(1+x) + 2*x/(1 - x^^^2)";
neuper@37926
  1240
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1241
term2str t;
neuper@37906
  1242
if (term2str t) =
neuper@37906
  1243
"6 * x / (1 + -1 * x ^^^ 2)"
neuper@37906
  1244
then ()
neuper@38046
  1245
else error "rational.sml: diff.behav. in norm_Rational_mg 15";
neuper@37906
  1246
neuper@37906
  1247
(*SRA Schalk I, p.68 Nr. 414a *)
neuper@37906
  1248
val t = str2term 
neuper@37906
  1249
"(x + 2)/(x - 1) + (x - 3)/(x - 2) - (x + 1)/((x - 1)*(x - 2))";
neuper@37926
  1250
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1251
term2str t;
neuper@37906
  1252
if (term2str t) =
neuper@37906
  1253
"(-2 + -5 * x + 2 * x ^^^ 2) / (2 + -3 * x + x ^^^ 2)"
neuper@37906
  1254
then ()
neuper@38046
  1255
else error "rational.sml: diff.behav. in norm_Rational_mg 16";
neuper@37906
  1256
neuper@37906
  1257
(*SRA Schalk I, p.68 Nr. 423a *)
neuper@37906
  1258
val t = str2term 
neuper@37906
  1259
"(2*x+3*y)/x + (4*x^^^3 - x*y^^^2 - 3*y^^^3)/(x^^^3 - 2*x^^^2*y+x*y^^^2) - (5*x+6*y)/(x - y)";
neuper@37926
  1260
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1261
term2str t;
neuper@37906
  1262
if (term2str t) =
neuper@37906
  1263
"1"
neuper@37906
  1264
then ()
neuper@38046
  1265
else error "rational.sml: diff.behav. in norm_Rational_mg 17";
neuper@37906
  1266
neuper@37906
  1267
(*SRA Schalk I, p.68 Nr. 428b *)
neuper@37906
  1268
val t = str2term 
neuper@37906
  1269
"1/(a - b)^^^2 + 1/(a+b)^^^2 - 2/(a^^^2 - b^^^2) - 4*(b^^^2 - 1)/(a^^^2 - b^^^2)^^^2";
neuper@37926
  1270
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1271
term2str t;
neuper@37906
  1272
if (term2str t) =
neuper@37906
  1273
"4 / (a ^^^ 4 + -2 * a ^^^ 2 * b ^^^ 2 + b ^^^ 4)"
neuper@37906
  1274
then ()
neuper@38046
  1275
else error "rational.sml: diff.behav. in norm_Rational_mg 18";
neuper@37906
  1276
neuper@37906
  1277
(*SRA Schalk I, p.68 Nr. 430b *)
neuper@37906
  1278
val t = str2term 
neuper@37906
  1279
"a^^^2/(a - 3*b) - 108*a*b^^^3/((a+3*b)*(a^^^2 - 9*b^^^2)) - 9*b^^^2*(a - 3*b)/(a+3*b)^^^2";
neuper@37926
  1280
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1281
term2str t;
neuper@37906
  1282
if (term2str t) =
neuper@37906
  1283
"a + 3 * b"
neuper@37906
  1284
then ()
neuper@38046
  1285
else error "rational.sml: diff.behav. in norm_Rational_mg 19";
neuper@37906
  1286
neuper@37906
  1287
neuper@37906
  1288
(*SRA Schalk I, p.68 Nr. 432 *)
neuper@37906
  1289
val t = str2term 
neuper@37906
  1290
"(a^^^2+a*b)/(a^^^2 - b^^^2) - (b^^^2 - a*b)/(b^^^2 - a^^^2) + a^^^2*(a - b)/(a^^^3 - a^^^2*b) - 2*a*(a^^^2 - b^^^2)/(a^^^3 - a*b^^^2) - 2*b^^^2/(a^^^2 - b^^^2)";
neuper@37926
  1291
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1292
term2str t;
neuper@37906
  1293
if (term2str t) =
neuper@37906
  1294
"0"
neuper@37906
  1295
then ()
neuper@38046
  1296
else error "rational.sml: diff.behav. in norm_Rational_mg 20";
neuper@37906
  1297
neuper@37906
  1298
(*Eigenes*)
neuper@37906
  1299
val t = str2term 
neuper@37906
  1300
"3*a/(a*b) + x/y";
neuper@37926
  1301
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1302
term2str t;
neuper@37906
  1303
if (term2str t) =
neuper@37906
  1304
"(3 * y + b * x) / (b * y)"
neuper@37906
  1305
then ()
neuper@38046
  1306
else error "rational.sml: diff.behav. in norm_Rational_mg 21";
neuper@37906
  1307
neuper@37906
  1308
neuper@38041
  1309
"-------- multiply and cancel ---------------------------";
neuper@38041
  1310
"-------- multiply and cancel ---------------------------";
neuper@38041
  1311
"-------- multiply and cancel ---------------------------";
neuper@37906
  1312
(*SRM Schalk I, p.68 Nr. 436a *)
neuper@37906
  1313
val t = str2term 
neuper@37906
  1314
"3*(x+y)/(15*(x - y)) * 25*(x - y)^^^2/(18*(x+y)^^^2)";
neuper@37926
  1315
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1316
term2str t;
neuper@37906
  1317
if (term2str t) =
neuper@37906
  1318
"(5 * x + -5 * y) / (18 * x + 18 * y)"
neuper@37906
  1319
then ()
neuper@38046
  1320
else error "rational.sml: diff.behav. in norm_Rational_mg 22";
neuper@37906
  1321
neuper@37906
  1322
(*SRM.test Schalk I, p.68 Nr. 436b *)
neuper@37906
  1323
(*WN060420???MG3 crashes with method 'simplify' in 
neuper@37906
  1324
  IsacCore > Simplification > Rational Terms > Multiplication > No.2*)
neuper@37906
  1325
val t = str2term "5*a*(a - b)^^^2*(a + b)^^^3/(7*b*(a - b)^^^3) * 7*b/(a + b)^^^3";
neuper@37926
  1326
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1327
term2str t;
neuper@37906
  1328
if (term2str t) =
neuper@37906
  1329
"5 * a / (a + -1 * b)"
neuper@37906
  1330
then ()
neuper@38046
  1331
else error "rational.sml: diff.behav. in norm_Rational_mg 23";
neuper@37906
  1332
neuper@37906
  1333
(*Schalk I, p.68 Nr. 437a *)
neuper@37906
  1334
val t = str2term "(3*a - 4*b)/(4*c+3*e) * (3*a+4*b)/(9*a^^^2 - 16*b^^^2)";
neuper@37926
  1335
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1336
if (term2str t) = "1 / (4 * c + 3 * e)" then ()
neuper@38046
  1337
else error "rational.sml: diff.behav. in norm_Rational_mg 24";
neuper@37906
  1338
neuper@37906
  1339
"----- S.K. corrected non-termination 060904";
neuper@37906
  1340
val t = str2term "(3*a - 4*b) * (3*a+4*b)/((4*c+3*e)*(9*a^^^2 - 16*b^^^2))";
neuper@37926
  1341
val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
neuper@41932
  1342
term2str t';
neuper@41932
  1343
if term2str t' = 
neuper@41933
  1344
  "(9 * a ^^^ 2 + -16 * b ^^^ 2) /\n(36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c +\n -48 * b ^^^ 2 * e)"
neuper@41932
  1345
(*"(9 * a ^^^ 2 + -16 * b ^^^ 2) / (36 * a ^^^ 2 * c + 27 * a ^^^ 2 * e + -64 * b ^^^ 2 * c + -48 * b ^^^ 2 * e)"*)
neuper@41932
  1346
then () else error "rational.sml: S.K.8..corrected 060904-6";
neuper@37906
  1347
neuper@37906
  1348
"----- S.K. corrected non-termination of cancel_p_";
neuper@38046
  1349
val t'' = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
neuper@38046
  1350
"(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
neuper@37926
  1351
val SOME (t',_) = rewrite_set_ thy false cancel_p t'';
neuper@37906
  1352
if term2str t' = "1 / (4 * c + 3 * e)" then ()
neuper@38046
  1353
else error "rational.sml: diff.behav. in cancel_p S.K.8";
neuper@37906
  1354
neuper@37906
  1355
(*Schalk I, p.68 Nr. 437b *)
neuper@37906
  1356
(* nonterm.SK9 loops: cancel_p kann nicht weiter kuerzen!!! *)
neuper@37906
  1357
val t'' = str2term "(a + b)/(x^^^2 - y^^^2) * ((x - y)^^^2/(a^^^2 - b^^^2))";
neuper@37926
  1358
(* val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t'';
neuper@37906
  1359
   *)
neuper@37906
  1360
neuper@38046
  1361
"================delete===";
neuper@37906
  1362
(*a casual output from above*)
neuper@37906
  1363
val t = str2term 
neuper@37906
  1364
"(a * x ^^^ 2 + -2 * a * x * y + a * y ^^^ 2 + b * x ^^^ 2 + -2 * b * x * y + b * y ^^^ 2) /(a ^^^ 2 * x ^^^ 2 + -1 * a ^^^ 2 * y ^^^ 2 + -1 * b ^^^ 2 * x ^^^ 2 + b ^^^ 2 * y ^^^ 2)"; 
neuper@37906
  1365
(* WN060831 nonterm.SK10 
neuper@37926
  1366
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1367
term2str t;
neuper@37906
  1368
*)
neuper@37906
  1369
neuper@37906
  1370
(*SRM Schalk I, p.68 Nr. 438a *)
neuper@37906
  1371
val t = str2term 
neuper@37906
  1372
"x*y/(x*y - y^^^2)*(x^^^2 - x*y)";
neuper@37926
  1373
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1374
term2str t;
neuper@37906
  1375
if (term2str t) =
neuper@37906
  1376
"x ^^^ 2"
neuper@37906
  1377
then ()
neuper@38046
  1378
else error "rational.sml: diff.behav. in norm_Rational_mg 24";
neuper@37906
  1379
neuper@37906
  1380
(*SRM Schalk I, p.68 Nr. 439b *)
neuper@37906
  1381
val t = str2term 
neuper@37906
  1382
"(4*x^^^2+4*x+1)*((x^^^2 - 2*x^^^3)/(4*x^^^2+2*x))";
neuper@37926
  1383
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1384
term2str t;
neuper@37906
  1385
if (term2str t) =
neuper@37906
  1386
"(x + -4 * x ^^^ 3) / 2"
neuper@37906
  1387
then ()
neuper@38046
  1388
else error "rational.sml: diff.behav. in norm_Rational_mg 25";
neuper@37906
  1389
neuper@37906
  1390
(*SRM Schalk I, p.68 Nr. 440a *)
neuper@37906
  1391
val t = str2term 
neuper@37906
  1392
"(x^^^2 - 2*x)/(x^^^2 - 3*x) * (x - 3)^^^2/(x^^^2 - 4)";
neuper@37926
  1393
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1394
term2str t;
neuper@37906
  1395
if (term2str t) =
neuper@37906
  1396
"(-3 + x) / (2 + x)"
neuper@37906
  1397
then ()
neuper@38046
  1398
else error "rational.sml: diff.behav. in norm_Rational_mg 26";
neuper@37906
  1399
neuper@37906
  1400
"----- Schalk I, p.68 Nr. 440b SK11 works since 0707xx";
neuper@37906
  1401
val t = str2term 
neuper@37906
  1402
"(a^^^3 - 9*a)/(a^^^3*b - a*b^^^3)*(a^^^2*b+a*b^^^2)/(a+3)";
neuper@37926
  1403
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1404
if term2str t = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
neuper@38046
  1405
else error "rational.sml: diff.behav. in norm_Rational 27";
neuper@37906
  1406
neuper@37906
  1407
"----- SK12 works since 0707xx";
neuper@37906
  1408
val t = str2term "(a^^^3 - 9*a)*(a^^^2*b+a*b^^^2)/((a^^^3*b - a*b^^^3)*(a+3))";
neuper@37926
  1409
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; term2str t';
neuper@37906
  1410
if term2str t' = "(-3 * a + a ^^^ 2) / (a + -1 * b)" then ()
neuper@38046
  1411
else error "rational.sml: diff.behav. in norm_Rational 28";
neuper@37906
  1412
neuper@37906
  1413
neuper@38041
  1414
"-------- common denominator and multiplication ---------";
neuper@38041
  1415
"-------- common denominator and multiplication ---------";
neuper@38041
  1416
"-------- common denominator and multiplication ---------";
neuper@37906
  1417
(*SRAM Schalk I, p.69 Nr. 441b *)
neuper@37906
  1418
val t = str2term "(4*a/3 + 3*b^^^2/a^^^3 + b/(4*a))*(4*b/(3*a))";
neuper@37926
  1419
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1420
term2str t;
neuper@37906
  1421
if (term2str t) =
neuper@41932
  1422
  "(36 * b ^^^ 3 + 3 * a ^^^ 2 * b ^^^ 2 + 16 * a ^^^ 4 * b) / (9 * a ^^^ 4)"
neuper@38046
  1423
then () else error "rational.sml: diff.behav. in norm_Rational_mg 28";
neuper@37906
  1424
neuper@37906
  1425
(*SRAM Schalk I, p.69 Nr. 442b *)
neuper@37906
  1426
val t = str2term "(15*a^^^2/x^^^3 - 5*b^^^4/x^^^2 + 25*c^^^2/x)*(x^^^3/(5*a*b^^^3*c^^^3)) + 1/c^^^3 * (b*x/a - 3*a/b^^^3)";
neuper@37926
  1427
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1428
term2str t;
neuper@37906
  1429
if (term2str t) =
neuper@37906
  1430
"5 * x ^^^ 2 / (a * b ^^^ 3 * c)"
neuper@38046
  1431
then () else error "rational.sml: diff.behav. in norm_Rational_mg 29";
neuper@37906
  1432
neuper@37906
  1433
(*SRAM Schalk I, p.69 Nr. 443b *)
neuper@37906
  1434
val t = str2term "(a/2 + b/3)*(b/3 - a/2)";
neuper@37926
  1435
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1436
term2str t;
neuper@37906
  1437
if (term2str t) =
neuper@37906
  1438
"(-9 * a ^^^ 2 + 4 * b ^^^ 2) / 36"
neuper@38046
  1439
then () else error "rational.sml: diff.behav. in norm_Rational_mg 30";
neuper@37906
  1440
neuper@37906
  1441
(*SRAM Schalk I, p.69 Nr. 445b *)
neuper@37906
  1442
val t = str2term "(a^^^2/9 + 2*a/(3*b) + 4/b^^^2)*(a/3 - 2/b) + 8/b^^^3";
neuper@37926
  1443
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1444
term2str t;
neuper@37906
  1445
if (term2str t) =
neuper@37906
  1446
"a ^^^ 3 / 27"
neuper@38046
  1447
then () else error "rational.sml: diff.behav. in norm_Rational_mg 31";
neuper@37906
  1448
neuper@37906
  1449
(*SRAM Schalk I, p.69 Nr. 446b *)
neuper@37906
  1450
val t = str2term "(x/(5*x + 4*y) - y/(5*x - 4*y) + 1)*(25*x^^^2 - 16*y^^^2)";
neuper@37926
  1451
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1452
term2str t;
neuper@37906
  1453
if (term2str t) =
neuper@37906
  1454
"30 * x ^^^ 2 + -9 * x * y + -20 * y ^^^ 2"
neuper@37906
  1455
then ()
neuper@38046
  1456
else error "rational.sml: diff.behav. in norm_Rational_mg 32";
neuper@37906
  1457
neuper@37906
  1458
(*SRAM Schalk I, p.69 Nr. 449a *)(*Achtung: rechnet ca 8 Sekunden*)
neuper@37906
  1459
val t = str2term 
neuper@37906
  1460
"(2*x^^^2/(3*y)+x/y^^^2)*(4*x^^^4/(9*y^^^2)+x^^^2/y^^^4)*(2*x^^^2/(3*y) - x/y^^^2)";
neuper@37926
  1461
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1462
term2str t;
neuper@38046
  1463
if (term2str t) = "(-81 * x ^^^ 4 + 16 * x ^^^ 8 * y ^^^ 4) / (81 * y ^^^ 8)"
neuper@38046
  1464
then () else error "rational.sml: diff.behav. in norm_Rational_mg 33";
neuper@38046
  1465
neuper@37906
  1466
neuper@37906
  1467
(*SRAM Schalk I, p.69 Nr. 450a *)
neuper@37906
  1468
val t = str2term 
neuper@37906
  1469
"(4*x/(3*y)+2*y/(3*x))^^^2 - (2*y/(3*x) - 2*x/y)*(2*y/(3*x)+2*x/y)";
neuper@37926
  1470
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1471
term2str t;
neuper@37906
  1472
if (term2str t) =
neuper@37906
  1473
"(52 * x ^^^ 2 + 16 * y ^^^ 2) / (9 * y ^^^ 2)"
neuper@37906
  1474
then ()
neuper@38046
  1475
else error "rational.sml: diff.behav. in norm_Rational_mg 34";
neuper@37906
  1476
neuper@37906
  1477
neuper@38041
  1478
"-------- double fractions ------------------------------";
neuper@38041
  1479
"-------- double fractions ------------------------------";
neuper@38041
  1480
"-------- double fractions ------------------------------";
neuper@37906
  1481
(*SRD Schalk I, p.69 Nr. 454b *)
neuper@37906
  1482
val t = str2term 
neuper@37906
  1483
"((2 - x)/(2*a)) / (2*a/(x - 2))";
neuper@37926
  1484
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1485
term2str t;
neuper@37906
  1486
if (term2str t) = 
neuper@37906
  1487
"(-4 + 4 * x + -1 * x ^^^ 2) / (4 * a ^^^ 2)"
neuper@37906
  1488
then ()
neuper@38046
  1489
else error "rational.sml: diff.behav. in norm_Rational_mg 35";
neuper@37906
  1490
neuper@37906
  1491
(*SRD Schalk I, p.69 Nr. 455a *)
neuper@37906
  1492
val t = str2term 
neuper@37906
  1493
"(a^^^2 + 1)/(a^^^2 - 1) / ((a+1)/(a - 1))";
neuper@37926
  1494
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1495
term2str t;
neuper@37906
  1496
if (term2str t) = 
neuper@37906
  1497
"(1 + a ^^^ 2) / (1 + 2 * a + a ^^^ 2)" then ()
neuper@38046
  1498
else error "rational.sml: diff.behav. in norm_Rational_mg 36";
neuper@37906
  1499
neuper@37906
  1500
neuper@37906
  1501
"----- Schalk I, p.69 Nr. 455b";
neuper@37906
  1502
val t = str2term "(x^^^2 - 4)/(y^^^2 - 9)/((2+x)/(3 - y))";
neuper@37926
  1503
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1504
if term2str t = "(2 + -1 * x) / (3 + y)" then ()
neuper@38046
  1505
else error "rational.sml: diff.behav. in norm_Rational_mg 37";
neuper@37906
  1506
neuper@37906
  1507
"----- SK060904-1a non-termination of cancel_p_ ?: worked before 0707xx";
neuper@37906
  1508
val t = str2term "(x^^^2 - 4)*(3 - y)/((y^^^2 - 9)*(2+x))";
neuper@37926
  1509
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1510
if term2str t = "(2 + -1 * x) / (3 + y)" then ()
neuper@38046
  1511
else error "rational.sml: diff.behav. in norm_Rational_mg 37b";
neuper@37906
  1512
neuper@37906
  1513
"----- ?: worked before 0707xx";
neuper@37906
  1514
val t = str2term "(3 + -1 * y) / (-9 + y ^^^ 2)";
neuper@37926
  1515
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1516
if term2str t = "-1 / (3 + y)" then ()
neuper@38031
  1517
else error "rational.sml: -1 / (3 + y) norm_Rational";
neuper@37906
  1518
neuper@37906
  1519
(*SRD Schalk I, p.69 Nr. 456b *)
neuper@37906
  1520
val t = str2term 
neuper@37906
  1521
"(b^^^3 - b^^^2)/(b^^^2+b)/(b^^^2 - 1)";
neuper@37926
  1522
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1523
term2str t;
neuper@37906
  1524
if (term2str t) = "b / (1 + 2 * b + b ^^^ 2)" then ()
neuper@38046
  1525
else error "rational.sml: diff.behav. in norm_Rational_mg 38";
neuper@37906
  1526
neuper@37906
  1527
(*SRD Schalk I, p.69 Nr. 457b *)
neuper@37906
  1528
val t = str2term 
neuper@37906
  1529
"(16*a^^^2 - 9*b^^^2)/(2*a+3*a*b) / ((4*a+3*b)/(4*a^^^2 - 9*a^^^2*b^^^2))";
neuper@37926
  1530
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1531
term2str t;
neuper@37906
  1532
if (term2str t) = 
neuper@41932
  1533
  "8 * a ^^^ 2 + -6 * a * b + -12 * a ^^^ 2 * b + 9 * a * b ^^^ 2"
neuper@41932
  1534
then () else error "rational.sml: diff.behav. in norm_Rational_mg 39";
neuper@37906
  1535
neuper@37906
  1536
"----- Schalk I, p.69 Nr. 458b works since 0707";
neuper@37906
  1537
val t = str2term 
neuper@37906
  1538
"(2*a^^^2*x - a^^^2)/(a*x - b*x) / (b^^^2*(2*x - 1)/(x*(a - b)))";
neuper@37926
  1539
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1540
if term2str t = "a ^^^ 2 / b ^^^ 2" then ()
neuper@38046
  1541
else error "rational.sml: diff.behav. in norm_Rational_mg 39b";
neuper@37906
  1542
neuper@37906
  1543
(*SRD Schalk I, p.69 Nr. 459b *)
neuper@37906
  1544
val t = str2term "(a^^^2 - b^^^2)/(a*b) / (4*(a+b)^^^2/a)";
neuper@37926
  1545
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1546
if term2str t = "(a + -1 * b) / (4 * a * b + 4 * b ^^^ 2)" then ()
neuper@38046
  1547
else error "rational.sml: diff.behav. in norm_Rational_mg 41";
neuper@37906
  1548
neuper@37906
  1549
neuper@37906
  1550
(*Schalk I, p.69 Nr. 460b nonterm.SK
neuper@37906
  1551
val t = str2term 
neuper@37906
  1552
"(9*(x^^^2 - 8*x+16)/(4*(y^^^2 - 2*y+1)))/((3*x - 12)/(16*y - 16))";
neuper@37926
  1553
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1554
if term2str t = 
neuper@37906
  1555
then ()
neuper@38046
  1556
else error "rational.sml: diff.behav. in norm_Rational_mg 42";
neuper@37906
  1557
neuper@37906
  1558
val t = str2term 
neuper@37906
  1559
"9*(x^^^2 - 8*x+16)*(16*y - 16)/(4*(y^^^2 - 2*y+1)*(3*x - 12))";
neuper@37926
  1560
val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1561
... non terminating.
neuper@37926
  1562
val SOME (t',_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
  1563
"(-2304 + 1152 * x + 2304 * y + -144 * x ^^^ 2 + -1152 * x * y + 144 * x ^^^ 2 * y) /(-48 + 12 * x + 96 * y + -24 * x * y + -48 * y ^^^ 2 + 12 * x * y ^^^ 2)";
neuper@37926
  1564
val SOME (t,_) = rewrite_set_ thy false cancel_p t';
neuper@37906
  1565
... non terminating.*)
neuper@37906
  1566
neuper@37906
  1567
(*SRD Schalk I, p.70 Nr. 472a *)
neuper@38046
  1568
val t = str2term ("((8*x^^^2 - 32*y^^^2)/(2*x + 4*y))/" ^
neuper@38046
  1569
		 "((4*x - 8*y)/(x + y))");
neuper@37926
  1570
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1571
term2str t;
neuper@37906
  1572
if (term2str t) = 
neuper@37906
  1573
"x + y"
neuper@37906
  1574
then ()
neuper@38046
  1575
else error "rational.sml: diff.behav. in norm_Rational_mg 43";
neuper@37906
  1576
neuper@37906
  1577
neuper@37906
  1578
(*----------------------------------------------------------------------*)
neuper@37906
  1579
(*---------------------- Einfache Dppelbrche --------------------------*)
neuper@37906
  1580
(*----------------------------------------------------------------------*)
neuper@37906
  1581
neuper@37906
  1582
(*SRD Schalk I, p.69 Nr. 461a *)
neuper@37906
  1583
val t = str2term 
neuper@37906
  1584
"(2/(x+3) + 2/(x - 3)) / (8*x/(x^^^2 - 9))";
neuper@37926
  1585
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1586
term2str t;
neuper@37906
  1587
if (term2str t) = 
neuper@37906
  1588
"1 / 2"
neuper@37906
  1589
then ()
neuper@38046
  1590
else error "rational.sml: diff.behav. in norm_Rational_mg 44";
neuper@37906
  1591
neuper@37906
  1592
(*SRD Schalk I, p.69 Nr. 464b *)
neuper@37906
  1593
val t = str2term 
neuper@37906
  1594
"(a - a/(a - 2)) / (a + a/(a - 2))";
neuper@37926
  1595
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1596
term2str t;
neuper@37906
  1597
if (term2str t) = 
neuper@37906
  1598
"(3 + -1 * a) / (1 + -1 * a)"
neuper@37906
  1599
then ()
neuper@38046
  1600
else error "rational.sml: diff.behav. in norm_Rational_mg 45";
neuper@37906
  1601
neuper@37906
  1602
(*SRD Schalk I, p.69 Nr. 465b *)
neuper@37906
  1603
val t = str2term 
neuper@37906
  1604
"((x+3*y)/9 + (4*y^^^2 - 9*z^^^2)/(16*x)) /(x/9+y/6+z/4)";
neuper@37926
  1605
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1606
term2str t;
neuper@37906
  1607
if (term2str t) = 
neuper@37906
  1608
"(4 * x + 6 * y + -9 * z) / (4 * x)"
neuper@37906
  1609
then ()
neuper@38046
  1610
else error "rational.sml: diff.behav. in norm_Rational_mg 46";
neuper@37906
  1611
neuper@37906
  1612
(*SRD Schalk I, p.69 Nr. 466b *)
neuper@37906
  1613
val t = str2term 
neuper@37906
  1614
"((1 - 7*(x - 2)/(x^^^2 - 4)) / (6/(x+2))) / (3/(x+5)+30/(x^^^2 - 25))";
neuper@37926
  1615
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1616
term2str t;
neuper@37906
  1617
if (term2str t) = 
neuper@37906
  1618
"(25 + -10 * x + x ^^^ 2) / 18"
neuper@37906
  1619
then ()
neuper@38046
  1620
else error "rational.sml: diff.behav. in norm_Rational_mg 47";
neuper@37906
  1621
neuper@37906
  1622
(*SRD Schalk I, p.70 Nr. 469 *)
neuper@37906
  1623
val t = str2term 
neuper@37906
  1624
"3*b^^^2/(4*a^^^2 - 8*a*b + 4*b^^^2)/(a/(a^^^2*b - b^^^3) + (a - b)/(4*a*b^^^2+4*b^^^3) - 1/(4*b^^^2))";
neuper@37926
  1625
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1626
term2str t;
neuper@37906
  1627
if (term2str t) = 
neuper@37906
  1628
"3 * b ^^^ 3 / (2 * a + -2 * b)"
neuper@37906
  1629
then ()
neuper@38046
  1630
else error "rational.sml: diff.behav. in norm_Rational_mg 48";
neuper@37906
  1631
neuper@37906
  1632
(*----------------------------------------------------------------------*)
neuper@37906
  1633
(*---------------------- Mehrfache Dppelbrueche ------------------------*)
neuper@37906
  1634
(*----------------------------------------------------------------------*)
neuper@37906
  1635
neuper@37906
  1636
(*SRD.test Schalk I, p.70 Nr. 476b *) (* Rechenzeit: 10 sec *)
neuper@37906
  1637
(*WN060419 crashes with method 'simplify' ????SK*)
neuper@37906
  1638
val t = str2term 
neuper@37906
  1639
"((a^^^2 - b^^^2)/(2*a*b)+2*a*b/(a^^^2 - b^^^2))/((a^^^2+b^^^2)/(2*a*b)+1) / ((a^^^2+b^^^2)^^^2/(a+b)^^^2)";
neuper@37926
  1640
val SOME (t,_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1641
if term2str t = "1 / (a ^^^ 2 + -1 * b ^^^ 2)" then ()
neuper@38046
  1642
else error "rational.sml: diff.behav. in norm_Rational_mg 49";
neuper@37906
  1643
neuper@37906
  1644
"----- Schalk I, p.70 Nr. 477a";
neuper@37906
  1645
(* MG Achtung: terme explodieren; Bsp zu komplex; 
neuper@37906
  1646
   L???ung sollte (ziemlich grosser) Faktorisierter Ausdruck sein 
neuper@38041
  1647
val t = str2term "b*y/(b - 2*y)/((b^^^2 - y^^^2)/(b+2*y)) /" ^
neuper@38041
  1648
		 "(b^^^2*y+b*y^^^2)*(a+x)^^^2/((b^^^2 - 4*y^^^2)*(a+2*x)^^^2)";
neuper@37926
  1649
val SOME (t',_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1650
neuper@37906
  1651
neuper@38041
  1652
val t = str2term "b*y*(b+2*y)*(b^^^2 - 4*y^^^2)*(a+2*x)^^^2 / " ^
neuper@38041
  1653
		 "((b - 2*y)*(b^^^2 - y^^^2)*(b^^^2*y+b*y^^^2)*(a+x)^^^2)";
neuper@37926
  1654
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
  1655
????SK ???MG*)
neuper@37906
  1656
neuper@37906
  1657
neuper@37906
  1658
"----- Schalk I, p.70 Nr. 478b ----- Rechenzeit: 5 sec";
neuper@38046
  1659
val t = str2term ("(a - (a*b+b^^^2)/(a+b))/(b+(a - b)/(1+(a+b)/(a - b))) / " ^
neuper@38046
  1660
		 "((a - a^^^2/(a+b))/(a+(a*b)/(a - b)))");
neuper@37926
  1661
val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1662
if term2str t' = 
neuper@37906
  1663
"(2 * a ^^^ 3 + 2 * a ^^^ 2 * b) / (a ^^^ 2 * b + b ^^^ 3)"
neuper@37906
  1664
then ()
neuper@38046
  1665
else error "rational.sml: diff.behav. in norm_Rational_mg 51";
neuper@37906
  1666
neuper@37906
  1667
(* TODO.new_c:WN050820 STOP_REW_SUB introduced gave ...
neuper@38041
  1668
if term2str t' = "(a ^^^ 4 + -1 * a ^^^ 2 * b ^^^ 2) /(a * b * (b + (a * (a + -1 * b) + -1 * b * (a + -1 * b)) / (2 * a)) * (a + -1 * b))" then ()
neuper@38031
  1669
else error "rational.sml: works again";
neuper@37906
  1670
re-outcommented with TODO.new_c: cvs before 071227, 11:50*)
neuper@37906
  1671
neuper@37906
  1672
neuper@37906
  1673
neuper@37906
  1674
(*Schalk I, p.70 Nr. 480a *)
neuper@37906
  1675
(* Achtung: rechnet ewig; cancel_p kann nicht krzen: WN060831 nonterm.SK00
neuper@37906
  1676
val t = str2term 
neuper@37906
  1677
"(1/x+1/y+1/z)/(1/x - 1/y - 1/z) / (2*x^^^2/(x^^^2 - z^^^2)/(x/(x+z)+x/(x - z)))";
neuper@37926
  1678
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1679
term2str t;
neuper@37906
  1680
if (term2str t) = 
neuper@37906
  1681
neuper@37906
  1682
then ()
neuper@38046
  1683
else error "rational.sml: diff.behav. in norm_Rational_mg 52";
neuper@37906
  1684
neuper@37906
  1685
(*MG Berechne Zwischenergebnisse: WN060831 nonterm.SK00*)
neuper@37906
  1686
val t = str2term 
neuper@37906
  1687
"(1/x+1/y+1/z)/(1/x - 1/y - 1/z)";
neuper@37926
  1688
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1689
term2str t;
neuper@37906
  1690
"(x ^^^ 2 * y ^^^ 2 * z + x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2) /
neuper@37906
  1691
(-1 * x ^^^ 2 * y ^^^ 2 * z + -1 * x ^^^ 2 * y * z ^^^ 2 + x * y ^^^ 2 * z ^^^ 2)";
neuper@37906
  1692
val t = str2term 
neuper@37906
  1693
"2*x^^^2/(x^^^2 - z^^^2)/(x/(x+z)+x/(x - z))";
neuper@37926
  1694
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1695
term2str t;
neuper@37906
  1696
"1"
neuper@37906
  1697
neuper@37906
  1698
(* SK 1. Ausdruck kann nicht weiter gekrzt werden; cancel_p !!!*)
neuper@37906
  1699
###  rls: cancel_p on: 
neuper@37906
  1700
(x ^^^ 2 * (y ^^^ 2 * z) + x ^^^ 2 * (y * z ^^^ 2) + x * (y ^^^ 2 * z ^^^ 2)) /
neuper@37906
  1701
(-1 * (x ^^^ 2 * (y ^^^ 2 * z)) + -1 * (x ^^^ 2 * (y * z ^^^ 2)) + x * (y ^^^ 2 * z ^^^ 2))
neuper@37906
  1702
GC #3.61.81.101.197.17503:   (0 ms)
neuper@37906
  1703
*** RATIONALS_DIRECT_CANCEL_EXCEPTION: Invalid fraction
neuper@37906
  1704
neuper@37906
  1705
val t = str2term 
neuper@37906
  1706
"(x^^^2 * (y^^^2 * z) + x^^^2 * (y * z^^^2) + x * (y^^^2 * z^^^2)) / (-1 * (x^^^2 * (y^^^2 * z)) + -1 * (x^^^2 * (y * z^^^2)) + x * (y^^^2 * z^^^2))";
neuper@37926
  1707
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1708
term2str t;
neuper@37906
  1709
(*uncaught exception nonexhaustive binding failure*)
neuper@37906
  1710
neuper@37906
  1711
(* Das kann er aber krzen !!????: *)
neuper@37906
  1712
val t = str2term 
neuper@37906
  1713
"(x^^^2 * (y^^^2 * z) +  x * (y^^^2 * z^^^2)) / (-1 * (x^^^2 * (y * z^^^2)) + x * (y^^^2 * z^^^2))";
neuper@37926
  1714
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1715
term2str t;
neuper@37906
  1716
"(-1 * (y * x) + -1 * (z * y)) / (1 * (z * x) + -1 * (z * y))";
neuper@37906
  1717
*)
neuper@37906
  1718
neuper@37906
  1719
neuper@38041
  1720
"-------- crucial examples ------------------------------";
neuper@38041
  1721
"-------- crucial examples ------------------------------";
neuper@38041
  1722
"-------- crucial examples ------------------------------";
neuper@37906
  1723
(*Schalk I, p.60 Nr. 215d *)
neuper@37906
  1724
(* Achtung: rechnet ewig ...
neuper@37906
  1725
val t = str2term "(a-b)^^^3 * (x+y)^^^4 / ((x+y)^^^2 * (a-b)^^^5)";
neuper@37926
  1726
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1727
term2str t; noterm.SK
neuper@37906
  1728
*)
neuper@37906
  1729
neuper@37906
  1730
(* Kein Wunder, denn Z???ler und Nenner extra als Polynom dargestellt ergibt:*)
neuper@37906
  1731
(*
neuper@37906
  1732
val t = str2term "(a-b)^^^3 * (x+y)^^^4";
neuper@37926
  1733
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1734
term2str t;
neuper@38041
  1735
"a^^^3 * x^^^4 + 4 * a^^^3 * x^^^3 * y +6 * a^^^3 * x^^^2 * y^^^2 +4 * a^^^3 * x * y^^^3 +a^^^3 * y^^^4 +-3 * a^^^2 * b * x^^^4 +-12 * a^^^2 * b * x^^^3 * y +-18 * a^^^2 * b * x^^^2 * y^^^2 +-12 * a^^^2 * b * x * y^^^3 +-3 * a^^^2 * b * y^^^4 +3 * a * b^^^2 * x^^^4 +12 * a * b^^^2 * x^^^3 * y +18 * a * b^^^2 * x^^^2 * y^^^2 +12 * a * b^^^2 * x * y^^^3 +3 * a * b^^^2 * y^^^4 +-1 * b^^^3 * x^^^4 +-4 * b^^^3 * x^^^3 * y +-6 * b^^^3 * x^^^2 * y^^^2 +-4 * b^^^3 * x * y^^^3 +-1 * b^^^3 * y^^^4";
neuper@37906
  1736
val t = str2term "((x+y)^^^2 * (a-b)^^^5)";
neuper@37926
  1737
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1738
term2str t;
neuper@38041
  1739
"a^^^5 * x^^^2 + 2 * a^^^5 * x * y + a^^^5 * y^^^2 +-5 * a^^^4 * b * x^^^2 +-10 * a^^^4 * b * x * y +-5 * a^^^4 * b * y^^^2 +10 * a^^^3 * b^^^2 * x^^^2 +20 * a^^^3 * b^^^2 * x * y +10 * a^^^3 * b^^^2 * y^^^2 +-10 * a^^^2 * b^^^3 * x^^^2 +-20 * a^^^2 * b^^^3 * x * y +-10 * a^^^2 * b^^^3 * y^^^2 +5 * a * b^^^4 * x^^^2 +10 * a * b^^^4 * x * y +5 * a * b^^^4 * y^^^2 +-1 * b^^^5 * x^^^2 +-2 * b^^^5 * x * y +-1 * b^^^5 * y^^^2";
neuper@37906
  1740
*)
neuper@37906
  1741
(*anscheinend macht dem Rechner das Krzen diese Bruches keinen Spass mehr ...*)
neuper@37906
  1742
neuper@37906
  1743
(*--------------------------------------------------------------------*)
neuper@37906
  1744
(*Schalk I, p.70 Nr. 480b 
neuper@38041
  1745
val t = str2term "((12*x*y/(9*x^^^2 - y^^^2))/" ^
neuper@38041
  1746
		 "(1/(3*x - y)^^^2 - 1/(3*x + y)^^^2)) *" ^
neuper@38041
  1747
		 "(1/(x - 5*y)^^^2 - 1/(x + 5*y)^^^2)/" ^
neuper@38041
  1748
		 "(20*x*y/(x^^^2 - 25*y^^^2))";
neuper@37926
  1749
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1750
SK.nonterm
neuper@37906
  1751
Kann nicht weiter vereinfacht werden !!!!?? *)
neuper@37906
  1752
neuper@37906
  1753
(*--------------------------------------------------------------------*)
neuper@37906
  1754
"---- MGs test set";
neuper@37906
  1755
val t = str2term " (1 + x^^^5) / (y + x) + x^^^3 / x ";
neuper@37926
  1756
val SOME (t,_) = rewrite_set_ thy false common_nominator_p t;
neuper@37906
  1757
if term2str t = "(1 + x ^^^ 3 + x ^^^ 5 + y * x ^^^ 2) / (x + y)" then()
neuper@38031
  1758
else error "";
neuper@37906
  1759
neuper@37906
  1760
(*--------------------------------------------------------------------*)
neuper@37906
  1761
(* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3b
neuper@37906
  1762
   ---> Sortierung FALSCH !!  *)
neuper@37906
  1763
val t = str2term "b^^^3 * a^^^5/a ";
neuper@37926
  1764
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1765
term2str t;
neuper@37906
  1766
"1 * (a^^^4 * b^^^3) / 1"; (*OK*)
neuper@37906
  1767
neuper@37906
  1768
val t = str2term "b^^^3 * a^^^5/b ";
neuper@37926
  1769
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1770
term2str t;
neuper@37906
  1771
"1 * (b^^^2 * a^^^5) / 1"; (*cancel_p sortiert hier falsch um!*)
neuper@37906
  1772
neuper@37906
  1773
(* Problem liegt NICHT bei ord_make_polynomial! (siehe folgende Bsple) *)
neuper@37906
  1774
(*
neuper@37906
  1775
val x = str2term "x"; val bdv = str2term "bdv";
neuper@37906
  1776
val t1 = str2term "b^^^2 * a^^^5";
neuper@37906
  1777
val t2 = str2term "a^^^5 * b^^^2 ";
neuper@37906
  1778
ord_make_polynomial false Rational.thy [(x,bdv)] (t1,t2); (*false*)
neuper@37906
  1779
*)
neuper@37906
  1780
(* ==> "b^^^2 * a^^^5" > "a^^^5 * b^^^2 " ... OK!*)
neuper@37906
  1781
neuper@37906
  1782
(*--------------------------------------------------------------------*)
neuper@37906
  1783
(* cancel_p liefert nicht immer Polynomnormalform (2): WN060831???SK3c
neuper@37906
  1784
   ---> erzeugt berflssige "1 * ..."
neuper@37906
  1785
   
neuper@37906
  1786
val t = str2term "-1 / (3 + y)";
neuper@37906
  1787
(*~~         *)
neuper@37926
  1788
val SOME (t,_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1789
term2str t;
neuper@37906
  1790
"-1 / (3 + 1 * y)";
neuper@37906
  1791
(********* Das ist das PROBLEM !!!!!!!??? *******************)
neuper@37906
  1792
(* -1 im Z???ler der Angabe verursacht das Problem !*)
neuper@37906
  1793
*)
neuper@37906
  1794
neuper@37906
  1795
(* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *)
neuper@37906
  1796
"----- MGs test set";
neuper@37906
  1797
val t = str2term "(a^^^2 + -1)/(a+1)";
neuper@37926
  1798
val SOME (t',_) = rewrite_set_ thy false cancel_p t;
neuper@37906
  1799
if term2str t' = "(-1 + a) / 1" then ()
neuper@38031
  1800
else error "rational.sml MG tests 3d";
neuper@37906
  1801
neuper@37906
  1802
"----- NOT TERMINATING ?: worked before 0707xx";
neuper@37906
  1803
val t = str2term "(a^^^2 - 1)*(b + 1) / ((b^^^2 - 1)*(a+1))";
neuper@37926
  1804
val SOME (t'',_) = rewrite_set_ thy false norm_Rational t;
neuper@37906
  1805
if term2str t'' = "(1 + -1 * a) / (1 + -1 * b)" then ()
neuper@38031
  1806
else error "rational.sml MG tests 3e";
neuper@37906
  1807
neuper@37906
  1808
"----- corrected SK060905";
neuper@37906
  1809
val t = str2term "(4*x^^^2 - 20*x + 25)/(2*x - 5)^^^3";
neuper@37926
  1810
val SOME (t',_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1811
if term2str t' = "-1 / (5 + -2 * x)" then ()
neuper@38031
  1812
else error "rational.sml corrected SK060905";
neuper@37906
  1813
neuper@37906
  1814
neuper@38041
  1815
"-------- examples for Stefan Karnels thesis ------------";
neuper@38041
  1816
"-------- examples for Stefan Karnels thesis ------------";
neuper@38041
  1817
"-------- examples for Stefan Karnels thesis ------------";
neuper@37906
  1818
(*SRAM Schalk I, p.69 Nr. 442b --- abgewandelt*)
neuper@37906
  1819
val t = str2term 
neuper@37906
  1820
"(15*a^^^4/(a*x^^^3) - 5*a*((b^^^4 - 5*c^^^2*x)/x^^^2))*(x^^^3/(5*a*b^^^3*c^^^3)) + a/c^^^3 * (x*(b/a) - 3*b*(a/b^^^4))";
neuper@37926
  1821
val SOME (t,_) = rewrite_set_ thy false norm_Rational(*_mg*) t;
neuper@37906
  1822
term2str t;
neuper@37906
  1823
if (term2str t) =
neuper@37906
  1824
"5 * x ^^^ 2 / (b ^^^ 3 * c)"
neuper@37906
  1825
then ()
neuper@38046
  1826
else error "rational.sml: diff.behav. in norm_Rational_mg 53";
neuper@38046
  1827
neuper@37906
  1828
neuper@38041
  1829
"-------- me Schalk I No.186 ----------------------------";
neuper@38041
  1830
"-------- me Schalk I No.186 ----------------------------";
neuper@38041
  1831
"-------- me Schalk I No.186 ----------------------------";
neuper@38083
  1832
val fmz = ["Term ((14 * x * y) / ( x * y ))",
neuper@37906
  1833
	   "normalform N"];
neuper@37906
  1834
val (dI',pI',mI') =
neuper@37991
  1835
  ("Rational",["rational","simplification"],
neuper@37906
  1836
   ["simplification","of_rationals"]);
neuper@37906
  1837
val p = e_pos'; val c = []; 
neuper@37906
  1838
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@37906
  1839
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1840
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1841
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1842
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1843
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1844
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1845
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
  1846
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
  1847
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
  1848
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
neuper@37906
  1849
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;(*++ for explicit script*)
neuper@37906
  1850
case (f2str f, nxt) of
neuper@37906
  1851
    ("14", ("End_Proof'", _)) => ()
neuper@38031
  1852
  | _ => error "rational.sml diff.behav. in me Schalk I No.186";
neuper@37906
  1853
neuper@37906
  1854
neuper@38041
  1855
"-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
neuper@38041
  1856
"-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
neuper@38041
  1857
"-------- interSteps ..Simp_Rat_Double_No-1.xml ---------";
neuper@37906
  1858
states:=[];
neuper@37906
  1859
CalcTree
neuper@38083
  1860
[(["Term (((2 - x)/(2*a)) / (2*a/(x - 2)))", "normalform N"], 
neuper@37991
  1861
  ("Rational",["rational","simplification"],
neuper@37906
  1862
  ["simplification","of_rationals"]))];
neuper@37906
  1863
Iterator 1;
neuper@37906
  1864
moveActiveRoot 1;
neuper@37906
  1865
autoCalculate 1 CompleteCalc;
neuper@37906
  1866
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
  1867
neuper@37906
  1868
interSteps 1 ([1],Res);
neuper@37906
  1869
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
  1870
neuper@37906
  1871
neuper@38041
  1872
"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
neuper@38041
  1873
"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
neuper@38041
  1874
"-------- interSteps ..Simp_Rat_Cancel_No-1.xml ---------";
neuper@37906
  1875
states:=[];
neuper@37906
  1876
CalcTree
neuper@38083
  1877
[(["Term ((a^2 + -1*b^2) / (a^2 + -2*a*b + b^2))", "normalform N"], 
neuper@37991
  1878
  ("Rational",["rational","simplification"],
neuper@37906
  1879
  ["simplification","of_rationals"]))];
neuper@37906
  1880
Iterator 1;
neuper@37906
  1881
moveActiveRoot 1;
neuper@37906
  1882
autoCalculate 1 CompleteCalc;
neuper@37906
  1883
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@41930
  1884
(*========== inhibit exn 110314 ================================================
neuper@37906
  1885
(*with explicit script done already... and removed [1,..] at below...
neuper@37906
  1886
interSteps 1 ([1],Res);
neuper@37906
  1887
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
  1888
*)
neuper@37906
  1889
interSteps 1 ([2],Res);
neuper@37906
  1890
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
  1891
neuper@37906
  1892
interSteps 1 ([2,1],Res);
neuper@37906
  1893
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
  1894
val newnds = children (get_nd pt [2,1]) (*see "fun detailrls"*);
neuper@37906
  1895
(*if length newnds = 12 then () WN060905*)
neuper@37906
  1896
if length newnds = 13 then ()
neuper@38031
  1897
else error "rational.sml: interSteps cancel_p rev_rew_p";
neuper@37906
  1898
neuper@37906
  1899
val p = ([2,1,9],Res);
neuper@37906
  1900
getTactic 1 p;
neuper@37906
  1901
val (_, tac, _) = pt_extract (pt, p);
neuper@37926
  1902
(*case tac of SOME (Rewrite ("sym_real_plus_binom_times1", _)) => ()
neuper@37906
  1903
WN060905*)
neuper@37926
  1904
case tac of SOME (Rewrite ("sym_real_add_mult_distrib2", _)) => ()
neuper@38031
  1905
| _ => error "rational.sml: getTactic, sym_real_plus_binom_times1";
neuper@41930
  1906
============ inhibit exn 110314 ==============================================*)
neuper@37906
  1907
neuper@37906
  1908
neuper@38041
  1909
"-------- investigate rulesets for cancel_p -------------";
neuper@38041
  1910
"-------- investigate rulesets for cancel_p -------------";
neuper@38041
  1911
"-------- investigate rulesets for cancel_p -------------";
neuper@41930
  1912
val thy = @{theory "Rational"};
neuper@37906
  1913
"---------------- (a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
neuper@37906
  1914
val t = str2term "(a^^^2 + -1*b^^^2) / (a^^^2 + -2*a*b + b^^^2)";
neuper@37906
  1915
val tt = str2term "(1 * a + 1 * b) * (1 * a + -1 * b)"(*numerator only*);
neuper@37906
  1916
"----- with rewrite_set_";
neuper@37926
  1917
val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
neuper@37906
  1918
term2str tt'= "a ^^^ 2 + -1 * b ^^^ 2" (*true*);
neuper@37906
  1919
val tt = str2term "((1 * a + -1 * b) * (1 * a + -1 * b))"(*denominator only*);
neuper@37926
  1920
val SOME (tt',asm) = rewrite_set_ thy false make_polynomial tt;
neuper@37906
  1921
term2str tt' = "a ^^^ 2 + -2 * a * b + b ^^^ 2" (*true*);
neuper@37906
  1922
neuper@37906
  1923
"----- with make_deriv";
neuper@38046
  1924
val SOME (tt, _) = factout_p_ thy t; term2str tt =
neuper@37906
  1925
"(1 * a + 1 * b) * (1 * a + -1 * b) / ((1 * a + -1 * b) * (1 * a + -1 * b))";
neuper@37906
  1926
(*
neuper@37906
  1927
"--- with ruleset as before 060829";
neuper@37906
  1928
val {rules, rew_ord=(_,ro),...} =
neuper@37906
  1929
    rep_rls (assoc_rls "make_polynomial");
neuper@37926
  1930
val der = make_deriv thy Atools_erls rules ro NONE tt;
neuper@37906
  1931
print_depth 99; map (term2str o #1) der; print_depth 3;
neuper@37906
  1932
print_depth 99; map (rule2str o #2) der; print_depth 3;
neuper@38041
  1933
... did not terminate*)
neuper@37906
  1934
"--- with simpler ruleset";
neuper@37906
  1935
val {rules, rew_ord=(_,ro),...} =
neuper@37906
  1936
    rep_rls (assoc_rls "rev_rew_p");
neuper@37926
  1937
val der = make_deriv thy Atools_erls rules ro NONE tt;
neuper@37906
  1938
print_depth 99; writeln (deriv2str der); print_depth 3;
neuper@37906
  1939
neuper@37906
  1940
print_depth 99; map (term2str o #1) der; print_depth 3;
neuper@37906
  1941
"...,(-1 * b ^^^ 2 + a ^^^ 2) / (-2 * (a * b) + a ^^^ 2 + (-1 * b) ^^^ 2) ]";
neuper@37906
  1942
print_depth 99; map (rule2str o #2) der; print_depth 3;
neuper@37906
  1943
print_depth 99; map (term2str o #1 o #3) der; print_depth 3;
neuper@37906
  1944
neuper@37926
  1945
val der = make_deriv thy Atools_erls rules ro NONE 
neuper@37906
  1946
		     (str2term "(1 * a + 1 * b) * (1 * a + -1 * b)");
neuper@37906
  1947
print_depth 99; writeln (deriv2str der); print_depth 3;
neuper@37906
  1948
neuper@37906
  1949
val {rules, rew_ord=(_,ro),...} =
neuper@37906
  1950
    rep_rls (assoc_rls "rev_rew_p");
neuper@37926
  1951
val der = make_deriv thy Atools_erls rules ro NONE 
neuper@37906
  1952
		     (str2term "(1 * a + -1 * b) * (1 * a + -1 * b)");
neuper@37906
  1953
print_depth 99; writeln (deriv2str der); print_depth 3;
neuper@37906
  1954
print_depth 99; map (term2str o #1) der; print_depth 3;
neuper@37906
  1955
(*WN060829 ...postponed*)
neuper@37906
  1956
neuper@37906
  1957
neuper@38041
  1958
"-------- investigate format of factout_ and factout_p_ -";
neuper@38041
  1959
"-------- investigate format of factout_ and factout_p_ -";
neuper@38041
  1960
"-------- investigate format of factout_ and factout_p_ -";
neuper@37906
  1961
val {rules, rew_ord = (_,ro),...} = rep_rls (assoc_rls "make_polynomial");
neuper@41930
  1962
val (thy, eval_rls) = (@{theory "Rational"}, Atools_erls)(*see 'fun init_state'*);
neuper@37906
  1963
val Rrls {scr = Rfuns {init_state,...},...} = assoc_rls "cancel_p";
neuper@37906
  1964
neuper@38041
  1965
"----- see Rational.ML, local cancel_p, fun init_state";
neuper@37906
  1966
val t = str2term "(a^^^2 + (-1)*b^^^2) / (a^^^2 + (-2)*a*b + b^^^2)";
neuper@37926
  1967
val SOME (t',_) = factout_p_ thy t; term2str t';
neuper@37906
  1968
(*
neuper@37926
  1969
val rtas = reverse_deriv thy eval_rls rules ro NONE t';
neuper@37906
  1970
writeln(trtas2str rst);
neuper@37906
  1971
*)
neuper@37906
  1972
neuper@37906
  1973
neuper@38041
  1974
"----- see Rational.ML, local cancel_p, fun init_state";
neuper@37906
  1975
val t = str2term "a^^^2 / a";
neuper@37926
  1976
val SOME (t',_) = factout_p_ thy t; 
neuper@37906
  1977
term2str t' = "a * a / (1 * a)" (*true*); 
neuper@37906
  1978
(*... can be canceled with
neuper@37906
  1979
real_mult_div_cancel2 ?k ~= 0 ==> ?m * ?k / (?n * ?k) = ?m / ?n"*)
neuper@37906
  1980
(* sml/ME/rewtools.sml:
neuper@37926
  1981
val rtas = reverse_deriv thy Atools_erls rules ro NONE t';
neuper@37906
  1982
writeln (deri2str rtas);
neuper@37906
  1983
*)
neuper@37906
  1984
neuper@37906
  1985
neuper@37906
  1986
"-------- SK 060904 ----------------------------------------------";
neuper@37906
  1987
"----- order on polynomials -- input + output";
neuper@41929
  1988
val thy = @{theory "Isac"};
neuper@37906
  1989
val t = str2term "(a + -1 * b) / (-1 * a + b)";
neuper@37926
  1990
val SOME (t', _) = factout_p_ thy t; term2str t';
neuper@37926
  1991
val SOME (t', _) = cancel_p_ thy t; term2str t';
neuper@37906
  1992
neuper@37906
  1993
val t = str2term "a*b*c*d / (d*e*f*g)";
neuper@37926
  1994
val SOME (t', _) = cancel_p_ thy t; term2str t';
neuper@37906
  1995
neuper@37906
  1996
val t = str2term "a*(b*(c*d)) / (b*(e*(f*g)))";
neuper@37926
  1997
val SOME (t', _) = cancel_p_ thy t; term2str t';
neuper@37906
  1998
(*???order.SK  ???*)
neuper@37906
  1999
neuper@37906
  2000
"----- SK060904-1a non-termination of cancel_p_ ? worked before 0707xx";
neuper@37906
  2001
val t = str2term "(x^^^2 - 4)*(3 - y) / ((y^^^2 - 9)*(2+x))";
neuper@37926
  2002
val SOME (t',_) = rewrite_set_ thy false norm_Rational t; 
neuper@37906
  2003
if term2str t' = "(2 + -1 * x) / (3 + y)" then ()
neuper@38031
  2004
else error "rational.sml SK060904-1a worked since 0707xx";
neuper@37906
  2005
neuper@37906
  2006
"----- SK060904-1b non-termination of cancel_p_ ... worked before 0707xx";
neuper@41930
  2007
val t = str2term ("(9 * a ^^^ 2 + -16 * b ^^^ 2) /" ^
neuper@41930
  2008
"(36 * a^^^2 * c + (27 * a^^^2 * e + (-64 * b^^^2 * c + -48 * b^^^2 * e)))");
neuper@37926
  2009
val SOME (t',_) = cancel_p_ thy t; 
neuper@37906
  2010
if term2str t' = "1 / (4 * c + 3 * e)" then ()
neuper@38031
  2011
else error "rational.sml SK060904-1b";
neuper@37906
  2012
neuper@37906
  2013
neuper@37906
  2014
"----- SK060904-2a non-termination of add_fraction_p_";
neuper@41930
  2015
val t = str2term (" (a + b * x) / (a + -1 * (b * x)) +  " ^
neuper@41930
  2016
		  " (-1 * a + b * x) / (a + b * x)      ");
neuper@37906
  2017
(* nonterm.SK
neuper@37926
  2018
val SOME (t',_) = rewrite_set_ thy false common_nominator_p t;
neuper@37906
  2019
neuper@37906
  2020
common_nominator_p_ thy t;
neuper@38041
  2021
" (a + b * x)*(a + b * x) / ((a + -1 * (b * x))*(a + -1 * (b * x))) +  " ^
neuper@38041
  2022
" (-1 * a + b * x)*(a + -1 * (b * x)) / ((a + b * x)*(-1 * a + b * x)) ";
neuper@37906
  2023
neuper@37906
  2024
add_fraction_p_ thy t; 
neuper@38041
  2025
" ((a + b * x)*(a + b * x)  +  (-1 * a + b * x)*(a + -1 * (b * x))) /" ^
neuper@38041
  2026
" ((a + b * x)*(-1 * a + b * x))                                     ";
neuper@37979
  2027
*)
neuper@37979
  2028
neuper@37979
  2029
neuper@38041
  2030
"-------- how to stepwise construct Scripts -------------";
neuper@38041
  2031
"-------- how to stepwise construct Scripts -------------";
neuper@38041
  2032
"-------- how to stepwise construct Scripts -------------";
neuper@41929
  2033
val thy = @{theory "Rational"};
neuper@37979
  2034
(*no trailing _*)
neuper@37979
  2035
val p1 = parse thy (
neuper@37979
  2036
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37980
  2037
"  (Rewrite_Set discard_minus False                   " ^
neuper@37979
  2038
"   t_t)");
neuper@37979
  2039
neuper@37979
  2040
(*required (): (Rewrite_Set discard_minus False)*)
neuper@37979
  2041
val p2 = parse thy (
neuper@37979
  2042
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37979
  2043
"  (Rewrite_Set discard_minus False                   " ^
neuper@37979
  2044
"   t_t)");
neuper@37979
  2045
neuper@37979
  2046
val p3 = parse thy (
neuper@37979
  2047
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37979
  2048
"  ((Rewrite_Set discard_minus False)                   " ^
neuper@37979
  2049
"   t_t)");
neuper@37979
  2050
neuper@37979
  2051
val p4 = parse thy (
neuper@37979
  2052
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37979
  2053
"  ((Rewrite_Set discard_minus False)                   " ^
neuper@37979
  2054
"   t_t)");
neuper@37979
  2055
neuper@37979
  2056
val p5 = parse thy (
neuper@37979
  2057
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37979
  2058
"  ((Try (Rewrite_Set discard_minus False)                   " ^
neuper@37979
  2059
"    Try (Rewrite_Set discard_parentheses False))               " ^
neuper@37979
  2060
"   t_t)");
neuper@37979
  2061
neuper@37979
  2062
val p6 = parse thy (
neuper@37979
  2063
"Script SimplifyScript (t_t::real) =                             " ^
neuper@37979
  2064
"  ((Try (Rewrite_Set discard_minus False) @@                   " ^
neuper@37979
  2065
"    Try (Rewrite_Set rat_mult_poly False) @@                    " ^
neuper@37979
  2066
"    Try (Rewrite_Set make_rat_poly_with_parentheses False) @@   " ^
neuper@37979
  2067
"    Try (Rewrite_Set cancel_p_rls False) @@                     " ^
neuper@37979
  2068
"    (Repeat                                                     " ^
neuper@37979
  2069
"     ((Try (Rewrite_Set common_nominator_p_rls False) @@        " ^
neuper@37979
  2070
"       Try (Rewrite_Set rat_mult_div_pow False) @@              " ^
neuper@37979
  2071
"       Try (Rewrite_Set make_rat_poly_with_parentheses False) @@" ^
neuper@37979
  2072
"       Try (Rewrite_Set cancel_p_rls False) @@                  " ^
neuper@37979
  2073
"       Try (Rewrite_Set rat_reduce_1 False)))) @@               " ^
neuper@37979
  2074
"    Try (Rewrite_Set discard_parentheses False))               " ^
neuper@37979
  2075
"   t_t)"
neuper@37979
  2076
);
neuper@42301
  2077
neuper@42301
  2078
"----------- get_denominator ----------------------------";
neuper@42301
  2079
"----------- get_denominator ----------------------------";
neuper@42301
  2080
"----------- get_denominator ----------------------------";
neuper@42301
  2081
val thy = @{theory Isac};
neuper@42301
  2082
val t = term_of (the (parse thy "get_denominator ((a +x)/b)"));
neuper@42301
  2083
val SOME (_, t') = eval_get_denominator "" 0 t thy;
neuper@42301
  2084
if term2str t' = "get_denominator ((a + x) / b) = b" then ()
neuper@42301
  2085
else error "get_denominator ((a + x) / b) = b"
neuper@42301
  2086
neuper@42439
  2087
neuper@42449
  2088
"--------- several errpats in complicated term -------------------";
neuper@42449
  2089
"--------- several errpats in complicated term -------------------";
neuper@42449
  2090
"--------- several errpats in complicated term -------------------";
neuper@42449
  2091
(*TODO: instead of Gabriella's example here (27.Jul.12) find a simpler one*)
neuper@42449
  2092
states:=[];
neuper@42449
  2093
CalcTree
neuper@42449
  2094
[(["Term ((5*b + 25)/(a^2 - b^2) * (a - b)/(5*b))", "normalform N"], 
neuper@42449
  2095
  ("Rational",["rational","simplification"], ["simplification","of_rationals"]))];
neuper@42449
  2096
Iterator 1;
neuper@42449
  2097
moveActiveRoot 1;
neuper@42449
  2098
autoCalculate 1 CompleteCalc;
neuper@42449
  2099
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@42449
  2100