test/Tools/isac/Knowledge/poly.sml
author Walther Neuper <neuper@ist.tugraz.at>
Fri, 01 Oct 2010 18:25:06 +0200
branchisac-update-Isa09-2
changeset 38040 967fda58d1b2
parent 38039 99cb0d80ff32
child 38050 4c52ad406c20
permissions -rw-r--r--
all rewriting in test/../poly.sml works
neuper@37906
     1
(* testexamples for Poly, polynomials
neuper@37906
     2
   author: Matthias Goldgruber 2003
neuper@37906
     3
   (c) due to copyright terms
neuper@37906
     4
neuper@38022
     5
12345678901234567890123456789012345678901234567890123456789012345678901234567890
neuper@38022
     6
        10        20        30        40        50        60        70        80
neuper@38022
     7
*)
neuper@38022
     8
(*******************************************************************************
neuper@37906
     9
  WN060104 'SPB' came into 'exp_IsacCore_Simp_Poly_Book.xml'
neuper@37906
    10
	   'SPO' came into 'exp_IsacCore_Simp_Poly_Other.xml'
neuper@38022
    11
*******************************************************************************)
neuper@38022
    12
"--------------------------------------------------------";
neuper@38022
    13
"--------------------------------------------------------";
neuper@38022
    14
"table of contents --------------------------------------";
neuper@38022
    15
"--------------------------------------------------------";
neuper@38022
    16
"-------- check is'_polyexp is_polyexp ------------------";
neuper@38022
    17
"-------- build Script Expand_binoms --------------------";
neuper@38036
    18
"-------- investigate (new) uniary minus ----------------";
neuper@38036
    19
"-------- check make_polynomial with simple terms -------";
neuper@38036
    20
"-------- fun is_multUnordered --------------------------";
neuper@38036
    21
"-------- examples from textbook Schalk I ---------------";
neuper@38022
    22
"-------- Script 'simplification for_polynomials' -------";
neuper@38022
    23
"-------- check pbl  'polynomial simplification' --------";
neuper@38022
    24
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
neuper@38036
    25
"-------- interSteps for Schalk 299a --------------------";
neuper@38022
    26
"-------- norm_Poly NOT COMPLETE ------------------------";
neuper@38022
    27
"-------- ord_make_polynomial ---------------------------";
neuper@38022
    28
"--------------------------------------------------------";
neuper@38022
    29
"--------------------------------------------------------";
neuper@38022
    30
"--------------------------------------------------------";
neuper@37906
    31
neuper@37906
    32
neuper@38022
    33
"-------- check is'_polyexp is_polyexp ------------------";
neuper@38022
    34
"-------- check is'_polyexp is_polyexp ------------------";
neuper@38022
    35
"-------- check is'_polyexp is_polyexp ------------------";
neuper@38022
    36
if is_polyexp @{term "x / x"} 
neuper@38031
    37
then error "poly.sml: check is'_polyexp is_polyexp" else ();
neuper@38022
    38
neuper@38022
    39
neuper@37974
    40
"-------- build Script Expand_binoms -----------------------------";
neuper@37974
    41
"-------- build Script Expand_binoms -----------------------------";
neuper@37974
    42
"-------- build Script Expand_binoms -----------------------------";
neuper@37974
    43
val scr_expand_binoms =
neuper@37974
    44
"Script Expand_binoms t_t =" ^
neuper@37974
    45
"(Repeat                       " ^
neuper@37974
    46
"((Try (Repeat (Rewrite real_plus_binom_pow2    False))) @@ " ^
neuper@37974
    47
" (Try (Repeat (Rewrite real_plus_binom_times   False))) @@ " ^
neuper@37974
    48
" (Try (Repeat (Rewrite real_minus_binom_pow2   False))) @@ " ^
neuper@37974
    49
" (Try (Repeat (Rewrite real_minus_binom_times  False))) @@ " ^
neuper@37974
    50
" (Try (Repeat (Rewrite real_plus_minus_binom1  False))) @@ " ^
neuper@37974
    51
" (Try (Repeat (Rewrite real_plus_minus_binom2  False))) @@ " ^
neuper@37974
    52
neuper@37974
    53
" (Try (Repeat (Rewrite mult_1_left             False))) @@ " ^
neuper@37974
    54
" (Try (Repeat (Rewrite mult_zero_left             False))) @@ " ^
neuper@37974
    55
" (Try (Repeat (Rewrite add_0_left      False))) @@ " ^
neuper@37974
    56
neuper@37975
    57
" (Try (Repeat (Calculate PLUS  ))) @@ " ^
neuper@37975
    58
" (Try (Repeat (Calculate TIMES ))) @@ " ^
neuper@37975
    59
" (Try (Repeat (Calculate POWER))) @@ " ^
neuper@37974
    60
neuper@37974
    61
" (Try (Repeat (Rewrite sym_realpow_twoI        False))) @@ " ^
neuper@37974
    62
" (Try (Repeat (Rewrite realpow_plus_1          False))) @@ " ^
neuper@37974
    63
" (Try (Repeat (Rewrite sym_real_mult_2         False))) @@ " ^
neuper@37974
    64
" (Try (Repeat (Rewrite real_mult_2_assoc       False))) @@ " ^
neuper@37974
    65
neuper@37974
    66
" (Try (Repeat (Rewrite real_num_collect        False))) @@ " ^
neuper@37974
    67
" (Try (Repeat (Rewrite real_num_collect_assoc  False))) @@ " ^
neuper@37974
    68
neuper@37974
    69
" (Try (Repeat (Rewrite real_one_collect        False))) @@ " ^
neuper@37974
    70
" (Try (Repeat (Rewrite real_one_collect_assoc  False))) @@ " ^ 
neuper@37974
    71
neuper@37975
    72
" (Try (Repeat (Calculate PLUS  ))) @@ " ^
neuper@37975
    73
" (Try (Repeat (Calculate TIMES ))) @@ " ^
neuper@37975
    74
" (Try (Repeat (Calculate POWER)))) " ^  
neuper@37974
    75
" t_t)";
neuper@38036
    76
(*
neuper@37974
    77
val scr_expand_binoms =
neuper@37974
    78
"Script Expand_binoms t_t = t_t";
neuper@38036
    79
*)
neuper@37974
    80
parse thy scr_expand_binoms;
neuper@37974
    81
neuper@38036
    82
neuper@38036
    83
"-------- investigate (new) uniary minus ----------------";
neuper@38036
    84
"-------- investigate (new) uniary minus ----------------";
neuper@38036
    85
"-------- investigate (new) uniary minus ----------------";
neuper@38036
    86
val t = (#prop o rep_thm) @{thm real_diff_0}; (*"0 - ?x = - ?x"*)
neuper@37906
    87
atomty t;
neuper@37906
    88
(*** -------------
neuper@37906
    89
*** Const ( Trueprop, bool => prop)
neuper@37906
    90
*** . Const ( op =, [real, real] => bool)
neuper@37906
    91
*** . . Const ( op -, [real, real] => real)
neuper@37906
    92
*** . . . Const ( 0, real)
neuper@37906
    93
*** . . . Var ((x, 0), real)
neuper@37906
    94
*** . . Const ( uminus, real => real)
neuper@37906
    95
*** . . . Var ((x, 0), real)              *)
neuper@37906
    96
neuper@37906
    97
val t = (term_of o the o (parse thy)) "-1";
neuper@37906
    98
atomty t;
neuper@37906
    99
(*** -------------
neuper@37906
   100
*** Free ( -1, real)                      *)
neuper@37906
   101
val t = (term_of o the o (parse thy)) "- 1";
neuper@37906
   102
atomty t;
neuper@37906
   103
(*** -------------
neuper@37906
   104
*** Const ( uminus, real => real)
neuper@37906
   105
*** . Free ( 1, real)                     *)
neuper@37906
   106
neuper@37906
   107
val t = (term_of o the o (parse thy)) "-x"; (*1-x  syntyx error !!!*)
neuper@37906
   108
atomty t;
neuper@37906
   109
(**** -------------
neuper@37906
   110
*** Free ( -x, real)*)
neuper@37906
   111
val t = (term_of o the o (parse thy)) "- x";
neuper@37906
   112
atomty t;
neuper@37906
   113
(**** -------------
neuper@37906
   114
*** Free ( -x, real) !!!!!!!!!!!!!!!!!!!!!!!! is the same !!!*)
neuper@37906
   115
val t = (term_of o the o (parse thy)) "-(x)";
neuper@37906
   116
atomty t;
neuper@37906
   117
(**** -------------
neuper@37906
   118
*** Free ( -x, real)*)
neuper@37906
   119
neuper@38036
   120
(*-.-.-.-.-.-isolate response.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
neuper@38036
   121
-.-.-.-.-.-.-isolate response.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*)
neuper@37906
   122
neuper@38036
   123
"-------- check make_polynomial with simple terms -------";
neuper@38036
   124
"-------- check make_polynomial with simple terms -------";
neuper@38036
   125
"-------- check make_polynomial with simple terms -------";
neuper@38036
   126
"----- check 1 ---";
neuper@38036
   127
val t = str2term "2*3*a";
neuper@38036
   128
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   129
if term2str t = "6 * a" then () else error "check make_polynomial 1";
neuper@38036
   130
neuper@38036
   131
"----- check 2 ---";
neuper@38036
   132
val t = str2term "2*a + 3*a";
neuper@38036
   133
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   134
if term2str t = "5 * a" then () else error "check make_polynomial 2";
neuper@38036
   135
neuper@38036
   136
"----- check 3 ---";
neuper@38036
   137
val t = str2term "2*a + 3*a + 3*a";
neuper@38036
   138
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   139
if term2str t = "8 * a" then () else error "check make_polynomial 3";
neuper@38036
   140
neuper@38036
   141
"----- check 4 ---";
neuper@38036
   142
val t = str2term "3*a - 2*a";
neuper@38036
   143
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   144
if term2str t = "a" then () else error "check make_polynomial 4";
neuper@38036
   145
neuper@38036
   146
"----- check 5 ---";
neuper@38036
   147
val t = str2term "4*(3*a - 2*a)";
neuper@38036
   148
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   149
if term2str t = "4 * a" then () else error "check make_polynomial 5";
neuper@38036
   150
neuper@38036
   151
"----- check 6 ---";
neuper@38036
   152
val t = str2term "4*(3*a^^^2 - 2*a^^^2)";
neuper@38036
   153
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   154
if term2str t = "4 * a ^^^ 2" then () else error "check make_polynomial 6";
neuper@38036
   155
neuper@38036
   156
neuper@38036
   157
"-------- fun is_multUnordered --------------------------";
neuper@38036
   158
"-------- fun is_multUnordered --------------------------";
neuper@38036
   159
"-------- fun is_multUnordered --------------------------";
neuper@38036
   160
val thy = theory "Isac";
neuper@38040
   161
"===== works for a simple example, see rewrite.sml -- fun app_rev ===";
neuper@38040
   162
val t = str2term "x^^^2 * x";
neuper@38040
   163
val SOME (t', _) = rewrite_set_ thy true order_mult_ t;
neuper@38040
   164
if term2str t' = "x * x ^^^ 2" then ()
neuper@38040
   165
else error "poly.sml Poly.is'_multUnordered doesn't work";
neuper@38040
   166
neuper@38040
   167
(* 100928 trace_rewrite shows the first occurring difference in 267b:
neuper@38036
   168
###  rls: order_mult_ on: 5 * x ^^^ 2 * (2 * x ^^^ 7) + 5 * x ^^^ 2 * 3 + (6 * x ^^^ 7 + 9) + (-1 * (3 * x ^^^ 5 * (6 * x ^^^ 4)) + -1 * (3 * x ^^^ 5 * -1) +
neuper@38036
   169
 (-48 * x ^^^ 4 + 8))
neuper@38036
   170
######  rls: e_rls-is_multUnordered on: p is_multUnordered
neuper@38036
   171
#######  try calc: Poly.is'_multUnordered'
neuper@38036
   172
=======  calc. to: False  !!!!!!!!!!!!! INSTEAD OF TRUE in 2002 !!!!!!!!!!!!!
neuper@38036
   173
*)
neuper@38036
   174
val t = str2term "5 * x ^^^ 2 * (2 * x ^^^ 7) + 5 * x ^^^ 2 * 3 + (6 * x ^^^ 7 + 9) + (-1 * (3 * x ^^^ 5 * (6 * x ^^^ 4)) + -1 * (3 * x ^^^ 5 * -1) +  (-48 * x ^^^ 4 + 8))";
neuper@38036
   175
neuper@38036
   176
"----- is_multUnordered ---";
neuper@38036
   177
val tsort = sort_variables t;
neuper@38036
   178
term2str tsort = "2 * (5 * (x ^^^ 2 * x ^^^ 7)) + 3 * (5 * x ^^^ 2) + 6 * x ^^^ 7 + 9 +\n-1 * (3 * (6 * (x ^^^ 4 * x ^^^ 5))) +\n-1 * (-1 * (3 * x ^^^ 5)) +\n-48 * x ^^^ 4 +\n8";
neuper@38036
   179
is_polyexp t;
neuper@38036
   180
tsort = t;
neuper@38036
   181
is_polyexp t andalso not (t = sort_variables t);
neuper@38036
   182
if is_multUnordered t then () else error "poly.sml diff. is_multUnordered 1";
neuper@38036
   183
neuper@38036
   184
"----- eval_is_multUnordered ---";
neuper@38036
   185
val tm = str2term "(5 * x ^^^ 2 * (2 * x ^^^ 7) + 5 * x ^^^ 2 * 3 + (6 * x ^^^ 7 + 9) + (-1 * (3 * x ^^^ 5 * (6 * x ^^^ 4)) + -1 * (3 * x ^^^ 5 * -1) +  (-48 * x ^^^ 4 + 8))) is_multUnordered";
neuper@38036
   186
case eval_is_multUnordered "testid" "" tm thy of
neuper@38036
   187
    SOME (_, Const ("Trueprop", _) $ 
neuper@38036
   188
                   (Const ("op =", _) $
neuper@38036
   189
                          (Const ("Poly.is'_multUnordered", _) $ _) $ 
neuper@38036
   190
                          Const ("True", _))) => ()
neuper@38036
   191
  | _ => error "poly.sml diff. eval_is_multUnordered";
neuper@38036
   192
neuper@38040
   193
"----- rewrite_set_ STILL DIDN'T WORK";
neuper@38040
   194
val SOME (t, _) = rewrite_set_ thy true order_mult_ t;
neuper@38040
   195
term2str t;
neuper@38036
   196
neuper@38036
   197
neuper@38036
   198
"-------- examples from textbook Schalk I ---------------";
neuper@38036
   199
"-------- examples from textbook Schalk I ---------------";
neuper@38036
   200
"-------- examples from textbook Schalk I ---------------";
neuper@38036
   201
"-----SPB Schalk I p.63 No.267b ---";
neuper@38036
   202
trace_rewrite := true; tracing "-----SPB Schalk I p.63 No.267b ---begin";
neuper@37906
   203
val t = str2term
neuper@37906
   204
 	    "(5*x^^^2 + 3) * (2*x^^^7 + 3) - (3*x^^^5 + 8) * (6*x^^^4 - 1)";
neuper@37926
   205
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@38036
   206
term2str t;
neuper@38036
   207
trace_rewrite := false; tracing "-----SPB Schalk I p.63 No.267b ---end";
neuper@37906
   208
if (term2str t) = 
neuper@37906
   209
"17 + 15 * x ^^^ 2 + -48 * x ^^^ 4 + 3 * x ^^^ 5 + 6 * x ^^^ 7 + -8 * x ^^^ 9"
neuper@37906
   210
then ()
neuper@38031
   211
else error "poly.sml: diff.behav. in make_polynomial 1";
neuper@37906
   212
neuper@38036
   213
"-----SPB Schalk I p.63 No.275b ---";
neuper@37906
   214
 val t = str2term
neuper@37906
   215
 	     "(3*x^^^2 - 2*x*y + y^^^2) * (x^^^2 - 2*y^^^2)";
neuper@37926
   216
 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
   217
 term2str t;
neuper@37906
   218
if (term2str t) = 
neuper@37906
   219
"3 * x ^^^ 4 + -2 * x ^^^ 3 * y + -5 * x ^^^ 2 * y ^^^ 2 + \
neuper@37906
   220
\4 * x * y ^^^ 3 +\n-2 * y ^^^ 4"
neuper@37906
   221
then ()
neuper@38031
   222
else error "poly.sml: diff.behav. in make_polynomial 2";
neuper@37906
   223
neuper@38036
   224
"-----SPB Schalk I p.63 No.279b ---";
neuper@37906
   225
 val t = str2term
neuper@37906
   226
 	     "(x-a)*(x-b)*(x-c)*(x-d)";
neuper@37926
   227
 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
   228
 term2str t;
neuper@37906
   229
(* Richtig! *)
neuper@37906
   230
if (term2str t) = 
neuper@37906
   231
"a * b * c * d + -1 * a * b * c * x + -1 * a * b * d * x + a * b * x ^^^ 2 +\n-1 * a * c * d * x +\na * c * x ^^^ 2 +\na * d * x ^^^ 2 +\n-1 * a * x ^^^ 3 +\n-1 * b * c * d * x +\nb * c * x ^^^ 2 +\nb * d * x ^^^ 2 +\n-1 * b * x ^^^ 3 +\nc * d * x ^^^ 2 +\n-1 * c * x ^^^ 3 +\n-1 * d * x ^^^ 3 +\nx ^^^ 4"
neuper@37906
   232
then ()
neuper@38031
   233
else error "poly.sml: diff.behav. in make_polynomial 3";
neuper@37906
   234
neuper@38036
   235
"-----SPB Schalk I p.63 No.291 ---";
neuper@37906
   236
 val t = str2term
neuper@37906
   237
 "(5+96*x^^^3+8*x*(-4+(7- 3*x)*4*x))*(5*(2- 3*x)- (-15*x*(-8*x- 5)))";
neuper@37926
   238
 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
   239
 term2str t;
neuper@37906
   240
if (term2str t) = 
neuper@37906
   241
"50 + -770 * x + 4520 * x ^^^ 2 + -16320 * x ^^^ 3 + -26880 * x ^^^ 4"
neuper@37906
   242
then ()
neuper@38031
   243
else error "poly.sml: diff.behav. in make_polynomial 4";
neuper@37906
   244
neuper@38036
   245
"-----SPB Schalk I p.64 No.295c ---";
neuper@37906
   246
 val t = str2term
neuper@37906
   247
 "(13*a^^^4*b^^^9*c - 12*a^^^3*b^^^6*c^^^9)^^^2";
neuper@37926
   248
 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
   249
 term2str t;
neuper@37906
   250
if (term2str t) = 
neuper@37906
   251
"169 * a ^^^ 8 * b ^^^ 18 * c ^^^ 2 + -312 * a ^^^ 7 * b ^^^ 15 * c ^^^ 10\
neuper@37906
   252
\ +\n144 * a ^^^ 6 * b ^^^ 12 * c ^^^ 18"
neuper@37906
   253
then ()
neuper@38031
   254
else error "poly.sml: diff.behav. in make_polynomial 5";
neuper@37906
   255
neuper@38036
   256
"-----SPB Schalk I p.64 No.299a ---";
neuper@37906
   257
 val t = str2term
neuper@37906
   258
 "(x - y)*(x + y)";
neuper@37926
   259
 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
   260
 term2str t;
neuper@38036
   261
(*
neuper@38036
   262
if (term2str t) = "x ^^^ 2 + -1 * y ^^^ 2" then ()
neuper@38031
   263
else error "poly.sml: diff.behav. in make_polynomial 6";
neuper@38036
   264
*)
neuper@37906
   265
neuper@38036
   266
"-----SPB Schalk I p.64 No.300c ---";
neuper@37906
   267
 val t = str2term
neuper@37906
   268
 "(3*x^^^2*y - 1)*(3*x^^^2*y + 1)";
neuper@37926
   269
 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
   270
 term2str t;
neuper@37906
   271
if (term2str t) = 
neuper@37906
   272
"-1 + 9 * x ^^^ 4 * y ^^^ 2"
neuper@37906
   273
then ()
neuper@38031
   274
else error "poly.sml: diff.behav. in make_polynomial 7";
neuper@37906
   275
neuper@38036
   276
"-----SPB Schalk I p.64 No.302 ---";
neuper@37906
   277
val t = str2term
neuper@37906
   278
 "(13*x^^^2 + 5)*(13*x^^^2 - 5) - (5*x^^^2 + 3)*(5*x^^^2 - 3) - (12*x^^^2 + 4)*(12*x^^^2 - 4)";
neuper@37926
   279
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   280
if term2str t = "0" then ()
neuper@38031
   281
else error "poly.sml: diff.behav. in make_polynomial 8";
neuper@37906
   282
(* Bei Berechnung sollte 3 mal real_plus_minus_binom1_p aus expand_poly verwendet werden *)
neuper@37906
   283
neuper@37906
   284
neuper@38036
   285
"-----SPB Schalk I p.64 No.306a ---";
neuper@37906
   286
val t = str2term "((x^^^2 + 1)*(x^^^2 - 1))^^^2";
neuper@37926
   287
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   288
if (term2str t) = "1 + 2 * x ^^^ 4 + 2 * -2 * x ^^^ 4 + x ^^^ 8" then ()
neuper@38031
   289
else error "poly.sml: diff.behav. in make_polynomial: not confluent \
neuper@37906
   290
		 \2 * x ^^^ 4 + 2 * -2 * x ^^^ 4 = -2 * x ^^^ 4 works again";
neuper@37906
   291
neuper@37906
   292
neuper@37906
   293
(*WN071729 when reducing "rls reduce_012_" for Schaerding,
neuper@37906
   294
the above resulted in the term below ... but reduces from then correctly*)
neuper@37906
   295
val t = str2term "1 + 2 * x ^^^ 4 + 2 * -2 * x ^^^ 4 + x ^^^ 8";
neuper@37926
   296
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   297
if (term2str t) = "1 + -2 * x ^^^ 4 + x ^^^ 8" then ()
neuper@38031
   298
else error "poly.sml: diff.behav. in make_polynomial 9b";
neuper@37906
   299
neuper@38036
   300
"-----SPB Schalk I p.64 No.296a ---";
neuper@37906
   301
val t = str2term "(x - a)^^^3";
neuper@37926
   302
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   303
if (term2str t) = "-1 * a ^^^ 3 + 3 * a ^^^ 2 * x + -3 * a * x ^^^ 2 + x ^^^ 3"
neuper@38031
   304
then () else error "poly.sml: diff.behav. in make_polynomial 10";
neuper@37906
   305
neuper@38036
   306
"-----SPB Schalk I p.64 No.296c ---";
neuper@37906
   307
val t = str2term "(-3*x - 4*y)^^^3";
neuper@37926
   308
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   309
if (term2str t) = 
neuper@37906
   310
"-27 * x ^^^ 3 + -108 * x ^^^ 2 * y + -144 * x * y ^^^ 2 + -64 * y ^^^ 3"
neuper@38031
   311
then () else error "poly.sml: diff.behav. in make_polynomial 11";
neuper@37906
   312
neuper@38036
   313
"-----SPB Schalk I p.62 No.242c ---";
neuper@37906
   314
val t = str2term "x^^^(-4)*(x^^^(-4)*y^^^(-2))^^^(-1)*y^^^(-2)";
neuper@37926
   315
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   316
if (term2str t) = "1" then ()
neuper@38031
   317
else error "poly.sml: diff.behav. in make_polynomial 12";
neuper@37906
   318
neuper@38036
   319
"-----SPB Schalk I p.60 No.209a ---";
neuper@37906
   320
val t = str2term "a^^^(7-x) * a^^^x";
neuper@37926
   321
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   322
if term2str t = "a ^^^ 7" then ()
neuper@38031
   323
else error "poly.sml: diff.behav. in make_polynomial 13";
neuper@37906
   324
neuper@38036
   325
"-----SPB Schalk I p.60 No.209d ---";
neuper@37906
   326
val t = str2term "d^^^x * d^^^(x+1) * d^^^(2 - 2*x)";
neuper@37926
   327
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   328
if term2str t = "d ^^^ 3" then ()
neuper@38031
   329
else error "poly.sml: diff.behav. in make_polynomial 14";
neuper@37906
   330
neuper@37906
   331
(*---------------------------------------------------------------------*)
neuper@37906
   332
(*------------------ Bsple bei denen es Probleme gibt------------------*)
neuper@37906
   333
(*---------------------------------------------------------------------*)
neuper@37906
   334
neuper@38036
   335
"-----Schalk I p.64 No.303 ---";
neuper@37906
   336
val t = str2term "(a + 2*b)*(a^^^2 + 4*b^^^2)*(a - 2*b) - (a - 6*b)*(a^^^2 + 36*b^^^2)*(a + 6*b)";
neuper@37926
   337
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   338
if term2str t = "1280 * b ^^^ 4" then ()
neuper@38031
   339
else error "poly.sml: diff.behav. in make_polynomial 14b";
neuper@37906
   340
(* Richtig - aber Binomische Formel wurde nicht verwendet! *)
neuper@37906
   341
neuper@37906
   342
neuper@37906
   343
(*--------------------------------------------------------------------*)
neuper@37906
   344
(*----------------------- Eigene Beispiele ---------------------------*)
neuper@37906
   345
(*--------------------------------------------------------------------*)
neuper@38036
   346
"-----SPO ---";
neuper@37906
   347
val t = str2term "a^^^2*a^^^(-2)";
neuper@37926
   348
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   349
if term2str t = "1" then ()
neuper@38031
   350
else error "poly.sml: diff.behav. in make_polynomial 15";
neuper@38036
   351
"-----SPO ---";
neuper@37906
   352
val t = str2term "a + a + a";
neuper@37926
   353
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   354
if term2str t = "3 * a" then ()
neuper@38031
   355
else error "poly.sml: diff.behav. in make_polynomial 16";
neuper@38036
   356
"-----SPO ---";
neuper@37906
   357
val t = str2term "a + b + b + b";
neuper@37926
   358
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   359
if term2str t = "a + 3 * b" then ()
neuper@38031
   360
else error "poly.sml: diff.behav. in make_polynomial 17";
neuper@38036
   361
"-----SPO ---";
neuper@37906
   362
val t = str2term "a^^^2*b*b^^^(-1)";
neuper@37926
   363
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   364
if term2str t = "a ^^^ 2" then ()
neuper@38031
   365
else error "poly.sml: diff.behav. in make_polynomial 18";
neuper@38036
   366
"-----SPO ---";
neuper@37906
   367
val t = str2term "a^^^2*a^^^(-2)";
neuper@37926
   368
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   369
if (term2str t) = "1" then ()
neuper@38031
   370
else error "poly.sml: diff.behav. in make_polynomial 19";
neuper@38036
   371
"-----SPO ---";
neuper@37906
   372
val t = str2term "b + a - b";
neuper@37926
   373
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   374
if (term2str t) = "a" then ()
neuper@38031
   375
else error "poly.sml: diff.behav. in make_polynomial 20";
neuper@38036
   376
"-----SPO ---";
neuper@37906
   377
val t = str2term "b * a * a";
neuper@37926
   378
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   379
if term2str t = "a ^^^ 2 * b" then ()
neuper@38031
   380
else error "poly.sml: diff.behav. in make_polynomial 21";
neuper@38036
   381
"-----SPO ---";
neuper@37906
   382
val t = str2term "(a^^^2)^^^3";
neuper@37926
   383
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   384
if term2str t = "a ^^^ 6" then ()
neuper@38031
   385
else error "poly.sml: diff.behav. in make_polynomial 22";
neuper@38036
   386
"-----SPO ---";
neuper@37906
   387
val t = str2term "x^^^2 * y^^^2 + x * x^^^2 * y";
neuper@37926
   388
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   389
if term2str t = "x ^^^ 3 * y + x ^^^ 2 * y ^^^ 2" then ()
neuper@38031
   390
else error "poly.sml: diff.behav. in make_polynomial 23";
neuper@38036
   391
"-----SPO ---";
neuper@37906
   392
val t = (term_of o the o (parse thy)) "a^^^2 * (-a)^^^2";
neuper@37926
   393
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   394
if (term2str t) = "a ^^^ 4" then ()
neuper@38031
   395
else error "poly.sml: diff.behav. in make_polynomial 24";
neuper@38036
   396
"-----SPO ---";
neuper@37906
   397
val t = str2term "a * b * b^^^(-1) + a";
neuper@37926
   398
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   399
if (term2str t) = "2 * a" then ()
neuper@38031
   400
else error "poly.sml: diff.behav. in make_polynomial 25";
neuper@38036
   401
"-----SPO ---";
neuper@37906
   402
val t = str2term "a*c*b^^^(2*n) + 3*a + 5*b^^^(2*n)*c*b";
neuper@37926
   403
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   404
if (term2str t) = "3 * a + 5 * b ^^^ (1 + 2 * n) * c + a * b ^^^ (2 * n) * c"
neuper@38031
   405
then () else error "poly.sml: diff.behav. in make_polynomial 26";
neuper@37906
   406
neuper@37906
   407
neuper@37906
   408
(*MG.27.6.03 -------------vvv-: Verschachtelte Terme -----------*)
neuper@38036
   409
"-----SPO ---";
neuper@37906
   410
val t = str2term "(1 + (x*y*a) + x)^^^(1 + (x*y*a) + x)";
neuper@37926
   411
 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
   412
 term2str t;
neuper@37906
   413
if term2str t = "(1 + x + a * x * y) ^^^ (1 + x + a * x * y)"
neuper@38031
   414
 then () else error "poly.sml: diff.behav. in make_polynomial 27";(*SPO*)
neuper@37906
   415
val t = str2term "(1 + x*(y*z)*zz)^^^(1 + x*(y*z)*zz)";
neuper@37926
   416
 val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
   417
 term2str t;
neuper@37906
   418
if term2str t = "(1 + x * y * z * zz) ^^^ (1 + x * y * z * zz)"
neuper@38031
   419
 then () else error "poly.sml: diff.behav. in make_polynomial 28";
neuper@37906
   420
neuper@38036
   421
"-------- Script 'simplification for_polynomials' -------";
neuper@38036
   422
"-------- Script 'simplification for_polynomials' -------";
neuper@38036
   423
"-------- Script 'simplification for_polynomials' -------";
neuper@37906
   424
val str = 
neuper@38040
   425
"Script SimplifyScript (t_t::real) =                \
neuper@38040
   426
\  ((Rewrite_Set norm_Poly False) t_t)";
neuper@37906
   427
val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
neuper@37906
   428
atomty sc;
neuper@37906
   429
neuper@37906
   430
neuper@38036
   431
"-------- check pbl  'polynomial simplification' --------";
neuper@38036
   432
"-------- check pbl  'polynomial simplification' --------";
neuper@38036
   433
"-------- check pbl  'polynomial simplification' --------";
neuper@37967
   434
val fmz = ["TERM ((5*x^^^2 + 3) * (2*x^^^7 + 3) \
neuper@37906
   435
	   \- (3*x^^^5 + 8) * (6*x^^^4 - 1))",
neuper@37906
   436
	   "normalform N"];
neuper@38036
   437
"-----0 ---";
neuper@38040
   438
(*===== inhibit exn ============================================================
neuper@38040
   439
GOON
neuper@38040
   440
neuper@37906
   441
case refine fmz ["polynomial","simplification"]of
neuper@37906
   442
    [Matches (["polynomial", "simplification"], _)] => ()
neuper@38031
   443
  | _ => error "poly.sml diff.behav. in check pbl, refine";
neuper@37906
   444
(*...if there is an error, then ...*)
neuper@37906
   445
neuper@38036
   446
"-----1 ---";
neuper@37906
   447
print_depth 7;
neuper@37906
   448
val pbt = get_pbt ["polynomial","simplification"];
neuper@37906
   449
print_depth 3;
neuper@37906
   450
(*if there is ...
neuper@37906
   451
> val NoMatch' {Given=gi, Where=wh, Find=fi,...} = match_pbl fmz pbt;
neuper@37906
   452
... then trace_rewrite:*)
neuper@37906
   453
neuper@38036
   454
"-----2 ---";
neuper@37906
   455
trace_rewrite:=true; 
neuper@37906
   456
match_pbl fmz pbt;
neuper@37906
   457
trace_rewrite:=false;
neuper@37906
   458
(*... if there is no rewrite, then there is something wrong with prls*)
neuper@37906
   459
neuper@38036
   460
"-----3 ---";
neuper@37906
   461
print_depth 7;
neuper@37906
   462
val prls = (#prls o get_pbt) ["polynomial","simplification"];
neuper@37906
   463
print_depth 3;
neuper@37906
   464
val t = str2term "((5*x^^^2 + 3) * (2*x^^^7 + 3) \
neuper@37906
   465
		 \- (3*x^^^5 + 8) * (6*x^^^4 - 1)) is_polyexp";
neuper@37906
   466
trace_rewrite:=true; 
neuper@37926
   467
val SOME (t',_) = rewrite_set_ thy false prls t;
neuper@37906
   468
trace_rewrite:=false;
neuper@37906
   469
if t' = HOLogic.true_const then () 
neuper@38031
   470
else error "poly.sml: diff.behav. in check pbl 'polynomial..";
neuper@37906
   471
(*... if this works, but (*1*) does still NOT work, check types:*)
neuper@37906
   472
neuper@38036
   473
"-----4 ---";
neuper@37906
   474
show_types:=true;
neuper@37906
   475
(*
neuper@37906
   476
> val NoMatch' {Given=gi, Where=wh, Find=fi,...} = match_pbl fmz pbt;
neuper@37906
   477
val wh = [False "(t_::real => real) (is_polyexp::real)"]
neuper@37906
   478
......................^^^^^^^^^^^^...............^^^^*)
neuper@37906
   479
val Matches' _ = match_pbl fmz pbt;
neuper@37906
   480
show_types:=false;
neuper@37906
   481
neuper@37906
   482
neuper@38036
   483
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
neuper@38036
   484
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
neuper@38036
   485
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
neuper@37967
   486
val fmz = ["TERM ((5*x^^^2 + 3) * (2*x^^^7 + 3) \
neuper@37906
   487
	   \- (3*x^^^5 + 8) * (6*x^^^4 - 1))",
neuper@37906
   488
	   "normalform N"];
neuper@37906
   489
val (dI',pI',mI') =
neuper@37991
   490
  ("Poly",["polynomial","simplification"],
neuper@37906
   491
   ["simplification","for_polynomials"]);
neuper@37906
   492
val p = e_pos'; val c = []; 
neuper@37906
   493
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@37906
   494
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   495
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37924
   496
(writeln o (itms2str_ ctxt)) (get_obj g_pbl pt (fst p));
neuper@37906
   497
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   498
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   499
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   500
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   501
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
   502
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
   503
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
   504
if f2str f = 
neuper@37906
   505
"17 + 15 * x ^^^ 2 + -48 * x ^^^ 4 + 3 * x ^^^ 5 + 6 * x ^^^ 7 + -8 * x ^^^ 9"
neuper@38031
   506
then () else error "poly.sml diff.behav. in me Schalk I p.63 No.267b";
neuper@37906
   507
neuper@37906
   508
neuper@38036
   509
"-------- interSteps for Schalk 299a --------------------";
neuper@38036
   510
"-------- interSteps for Schalk 299a --------------------";
neuper@38036
   511
"-------- interSteps for Schalk 299a --------------------";
neuper@37906
   512
states:=[];
neuper@37906
   513
CalcTree
neuper@37967
   514
[(["TERM ((x - y)*(x + y))", "normalform N"], 
neuper@37991
   515
  ("Poly",["polynomial","simplification"],
neuper@37906
   516
  ["simplification","for_polynomials"]))];
neuper@37906
   517
Iterator 1;
neuper@37906
   518
moveActiveRoot 1;
neuper@37906
   519
autoCalculate 1 CompleteCalc;
neuper@37906
   520
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   521
neuper@37906
   522
interSteps 1 ([1],Res)(*<ERROR> syserror in detailstep </ERROR>*);
neuper@37906
   523
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   524
if existpt' ([1,1], Frm) pt then ()
neuper@38031
   525
else error "poly.sml: interSteps doesnt work again 1";
neuper@37906
   526
neuper@37906
   527
interSteps 1 ([1,1],Res)(*<ERROR> syserror in detailstep </ERROR>*);
neuper@37906
   528
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   529
if existpt' ([1,1,1], Frm) pt then ()
neuper@38031
   530
else error "poly.sml: interSteps doesnt work again 2";
neuper@37906
   531
neuper@37906
   532
neuper@38036
   533
"-------- norm_Poly NOT COMPLETE ------------------------";
neuper@38036
   534
"-------- norm_Poly NOT COMPLETE ------------------------";
neuper@38036
   535
"-------- norm_Poly NOT COMPLETE ------------------------";
neuper@37906
   536
trace_rewrite:=true;
neuper@37926
   537
val SOME (f',_) = rewrite_set_ thy false norm_Poly 
neuper@37906
   538
(str2term "L = k - 2 * q + (k - 2 * q) + (k - 2 * q) + (k - 2 * q) + senkrecht + oben")(*see poly.sml: -- norm_Poly NOT COMPLETE -- TODO MG*);
neuper@37906
   539
trace_rewrite:=false;
neuper@37906
   540
term2str f';
neuper@37906
   541
neuper@38036
   542
neuper@38036
   543
"-------- ord_make_polynomial ---------------------------";
neuper@38036
   544
"-------- ord_make_polynomial ---------------------------";
neuper@38036
   545
"-------- ord_make_polynomial ---------------------------";
neuper@37906
   546
val t1 = str2term "2 * b + (3 * a + 3 * b)";
neuper@37906
   547
val t2 = str2term "3 * a + 3 * b + 2 * b";
neuper@37906
   548
neuper@37906
   549
if ord_make_polynomial true Poly.thy [] (t1, t2) then ()
neuper@38031
   550
else error "poly.sml: diff.behav. in ord_make_polynomial";
neuper@37906
   551
neuper@37906
   552
(*WN071202: ^^^ why then is there no rewriting ...*)
neuper@37906
   553
val term = str2term "2*b + (3*a + 3*b)";
neuper@37926
   554
val NONE = rewrite_set_ Isac.thy false order_add_mult term;
neuper@37906
   555
neuper@37906
   556
(*or why is there no rewriting this way...*)
neuper@37906
   557
val t1 = str2term "2 * b + (3 * a + 3 * b)";
neuper@37906
   558
val t2 = str2term "3 * a + (2 * b + 3 * b)";
neuper@37906
   559
neuper@38022
   560
===== inhibit exn ?===========================================================*)
neuper@38039
   561
neuper@38039
   562
neuper@38039
   563
(*========== inhibit exn =======================================================
neuper@38039
   564
============ inhibit exn =====================================================*)
neuper@38039
   565
neuper@38039
   566
(*========== inhibit exn ?======================================================
neuper@38039
   567
============ inhibit exn ?====================================================*)
neuper@38039
   568
neuper@38039
   569
(*-.-.-.-.-.-isolate response.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
neuper@38039
   570
-.-.-.-.-.-.-isolate response.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.*)