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