test/Tools/isac/Knowledge/poly.sml
author Walther Neuper <wneuper@ist.tugraz.at>
Fri, 08 May 2015 15:43:15 +0200
changeset 59117 e92d1e6a3497
parent 59111 c730b643bc0e
child 59188 c477d0f79ab9
permissions -rw-r--r--
Isabelle201302 --> Isabelle2014: negative numbers' representation changed
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@42395
     7
LEGEND:
neuper@42395
     8
WN060104: examples marked with 'SPB' came into 'exp_IsacCore_Simp_Poly_Book.xml'
neuper@42395
     9
          examples marked with 'SPO' came into 'exp_IsacCore_Simp_Poly_Other.xml'
neuper@38022
    10
*)
neuper@42395
    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@42395
    17
"-------- investigate (new 2002) uniary minus -----------";
neuper@38036
    18
"-------- check make_polynomial with simple terms -------";
neuper@38036
    19
"-------- fun is_multUnordered --------------------------";
neuper@38036
    20
"-------- examples from textbook Schalk I ---------------";
neuper@38022
    21
"-------- check pbl  'polynomial simplification' --------";
neuper@38022
    22
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
neuper@38036
    23
"-------- interSteps for Schalk 299a --------------------";
neuper@38022
    24
"-------- norm_Poly NOT COMPLETE ------------------------";
neuper@38022
    25
"-------- ord_make_polynomial ---------------------------";
neuper@38022
    26
"--------------------------------------------------------";
neuper@38022
    27
"--------------------------------------------------------";
neuper@38022
    28
"--------------------------------------------------------";
neuper@37906
    29
neuper@37906
    30
neuper@38022
    31
"-------- check is'_polyexp is_polyexp ------------------";
neuper@38022
    32
"-------- check is'_polyexp is_polyexp ------------------";
neuper@38022
    33
"-------- check is'_polyexp is_polyexp ------------------";
neuper@38022
    34
if is_polyexp @{term "x / x"} 
neuper@38031
    35
then error "poly.sml: check is'_polyexp is_polyexp" else ();
neuper@38022
    36
neuper@42395
    37
"-------- investigate (new 2002) uniary minus -----------";
neuper@42395
    38
"-------- investigate (new 2002) uniary minus -----------";
neuper@42395
    39
"-------- investigate (new 2002) uniary minus -----------";
neuper@42395
    40
(*---------------------------------------------- vvvvvvvvvvvvvv -----------------------*)
neuper@38036
    41
val t = (#prop o rep_thm) @{thm real_diff_0}; (*"0 - ?x = - ?x"*)
neuper@37906
    42
atomty t;
wneuper@59117
    43
(*
wneuper@59117
    44
*** Const (HOL.Trueprop, bool => prop)
wneuper@59117
    45
*** . Const (HOL.eq, real => real => bool)
wneuper@59117
    46
*** . . Const (Groups.minus_class.minus, real => real => real)
wneuper@59117
    47
*** . . . Const (Groups.zero_class.zero, real)
neuper@37906
    48
*** . . . Var ((x, 0), real)
wneuper@59117
    49
*** . . Const (Groups.uminus_class.uminus, real => real)
wneuper@59117
    50
*** . . . Var ((x, 0), real)
wneuper@59117
    51
*)
neuper@42395
    52
case t of
neuper@42395
    53
  Const ("HOL.Trueprop", _) $
wneuper@59117
    54
    (Const ("HOL.eq", _) $ 
wneuper@59117
    55
      (Const ("Groups.minus_class.minus", _) $ Const ("Groups.zero_class.zero", _) $ 
wneuper@59117
    56
        Var (("x", 0), _)) $
wneuper@59117
    57
             (Const ("Groups.uminus_class.uminus", _) $ Var (("x", 0), _))) => ()
neuper@42395
    58
| _ => error "internal representation of \"0 - ?x = - ?x\" changed";
neuper@37906
    59
neuper@42395
    60
(*----------------------------------- vvvv --------------------------------------------*)
neuper@37906
    61
val t = (term_of o the o (parse thy)) "-1";
neuper@37906
    62
atomty t;
neuper@37906
    63
(*** -------------
neuper@37906
    64
*** Free ( -1, real)                      *)
neuper@42395
    65
case t of
neuper@42395
    66
  Free ("-1", _) => ()
neuper@42395
    67
| _ => error "internal representation of \"-1\" changed";
neuper@42395
    68
(*----------------------------------- vvvvv -------------------------------------------*)
neuper@37906
    69
val t = (term_of o the o (parse thy)) "- 1";
neuper@37906
    70
atomty t;
wneuper@59117
    71
(*
wneuper@59117
    72
*** 
wneuper@59117
    73
*** Free (-1, real)
wneuper@59117
    74
*** 
wneuper@59117
    75
*)
neuper@42395
    76
case t of
wneuper@59117
    77
 Free ("-1", _) => ()
neuper@42395
    78
| _ => error "internal representation of \"- 1\" changed";
neuper@37906
    79
neuper@42395
    80
"======= these external values all have the same internal representation";
neuper@42395
    81
(* "1-x" causes syntyx error --- binary minus detected by blank inbetween !!!*)
neuper@42395
    82
(*----------------------------------- vvvvv -------------------------------------------*)
neuper@42395
    83
val t = (term_of o the o (parse thy)) "-x";
neuper@37906
    84
atomty t;
neuper@37906
    85
(**** -------------
neuper@37906
    86
*** Free ( -x, real)*)
neuper@42395
    87
case t of
neuper@42395
    88
  Const ("Groups.uminus_class.uminus", _) $ Free ("x", _) => ()
neuper@42395
    89
| _ => error "internal representation of \"-x\" changed";
neuper@42395
    90
(*----------------------------------- vvvvv -------------------------------------------*)
neuper@37906
    91
val t = (term_of o the o (parse thy)) "- x";
neuper@37906
    92
atomty t;
neuper@37906
    93
(**** -------------
neuper@37906
    94
*** Free ( -x, real) !!!!!!!!!!!!!!!!!!!!!!!! is the same !!!*)
neuper@42395
    95
case t of
neuper@42395
    96
  Const ("Groups.uminus_class.uminus", _) $ Free ("x", _) => ()
neuper@42395
    97
| _ => error "internal representation of \"- x\" changed";
neuper@42395
    98
(*----------------------------------- vvvvvv ------------------------------------------*)
neuper@37906
    99
val t = (term_of o the o (parse thy)) "-(x)";
neuper@37906
   100
atomty t;
neuper@37906
   101
(**** -------------
neuper@37906
   102
*** Free ( -x, real)*)
neuper@42395
   103
case t of
neuper@42395
   104
  Const ("Groups.uminus_class.uminus", _) $ Free ("x", _) => ()
neuper@42395
   105
| _ => error "internal representation of \"-(x)\" changed";
neuper@37906
   106
neuper@38036
   107
"-------- check make_polynomial with simple terms -------";
neuper@38036
   108
"-------- check make_polynomial with simple terms -------";
neuper@38036
   109
"-------- check make_polynomial with simple terms -------";
neuper@38036
   110
"----- check 1 ---";
neuper@38036
   111
val t = str2term "2*3*a";
neuper@38036
   112
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   113
if term2str t = "6 * a" then () else error "check make_polynomial 1";
neuper@38036
   114
neuper@38036
   115
"----- check 2 ---";
neuper@38036
   116
val t = str2term "2*a + 3*a";
neuper@38036
   117
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   118
if term2str t = "5 * a" then () else error "check make_polynomial 2";
neuper@38036
   119
neuper@38036
   120
"----- check 3 ---";
neuper@38036
   121
val t = str2term "2*a + 3*a + 3*a";
neuper@38036
   122
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   123
if term2str t = "8 * a" then () else error "check make_polynomial 3";
neuper@38036
   124
neuper@38036
   125
"----- check 4 ---";
neuper@38036
   126
val t = str2term "3*a - 2*a";
neuper@38036
   127
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   128
if term2str t = "a" then () else error "check make_polynomial 4";
neuper@38036
   129
neuper@38036
   130
"----- check 5 ---";
neuper@38036
   131
val t = str2term "4*(3*a - 2*a)";
neuper@38036
   132
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   133
if term2str t = "4 * a" then () else error "check make_polynomial 5";
neuper@38036
   134
neuper@38036
   135
"----- check 6 ---";
neuper@38036
   136
val t = str2term "4*(3*a^^^2 - 2*a^^^2)";
neuper@38036
   137
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
neuper@38036
   138
if term2str t = "4 * a ^^^ 2" then () else error "check make_polynomial 6";
neuper@38036
   139
neuper@38036
   140
"-------- fun is_multUnordered --------------------------";
neuper@38036
   141
"-------- fun is_multUnordered --------------------------";
neuper@38036
   142
"-------- fun is_multUnordered --------------------------";
neuper@41929
   143
val thy = @{theory "Isac"};
neuper@38040
   144
"===== works for a simple example, see rewrite.sml -- fun app_rev ===";
neuper@38040
   145
val t = str2term "x^^^2 * x";
neuper@38040
   146
val SOME (t', _) = rewrite_set_ thy true order_mult_ t;
neuper@38040
   147
if term2str t' = "x * x ^^^ 2" then ()
neuper@38040
   148
else error "poly.sml Poly.is'_multUnordered doesn't work";
neuper@38040
   149
neuper@38040
   150
(* 100928 trace_rewrite shows the first occurring difference in 267b:
neuper@38036
   151
###  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
   152
 (-48 * x ^^^ 4 + 8))
neuper@38036
   153
######  rls: e_rls-is_multUnordered on: p is_multUnordered
neuper@38036
   154
#######  try calc: Poly.is'_multUnordered'
neuper@38036
   155
=======  calc. to: False  !!!!!!!!!!!!! INSTEAD OF TRUE in 2002 !!!!!!!!!!!!!
neuper@38036
   156
*)
neuper@38036
   157
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
   158
neuper@38036
   159
"----- is_multUnordered ---";
neuper@38036
   160
val tsort = sort_variables t;
neuper@38036
   161
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
   162
is_polyexp t;
neuper@38036
   163
tsort = t;
neuper@38036
   164
is_polyexp t andalso not (t = sort_variables t);
neuper@38036
   165
if is_multUnordered t then () else error "poly.sml diff. is_multUnordered 1";
neuper@38036
   166
neuper@38036
   167
"----- eval_is_multUnordered ---";
neuper@38036
   168
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
   169
case eval_is_multUnordered "testid" "" tm thy of
neuper@41924
   170
    SOME (_, Const ("HOL.Trueprop", _) $ 
neuper@41922
   171
                   (Const ("HOL.eq", _) $
neuper@38036
   172
                          (Const ("Poly.is'_multUnordered", _) $ _) $ 
neuper@41928
   173
                          Const ("HOL.True", _))) => ()
neuper@38036
   174
  | _ => error "poly.sml diff. eval_is_multUnordered";
neuper@38036
   175
neuper@38040
   176
"----- rewrite_set_ STILL DIDN'T WORK";
neuper@38040
   177
val SOME (t, _) = rewrite_set_ thy true order_mult_ t;
neuper@38040
   178
term2str t;
neuper@38036
   179
neuper@38036
   180
"-------- examples from textbook Schalk I ---------------";
neuper@38036
   181
"-------- examples from textbook Schalk I ---------------";
neuper@38036
   182
"-------- examples from textbook Schalk I ---------------";
neuper@38036
   183
"-----SPB Schalk I p.63 No.267b ---";
neuper@42395
   184
val t = str2term "(5*x^^^2 + 3) * (2*x^^^7 + 3) - (3*x^^^5 + 8) * (6*x^^^4 - 1)";
neuper@37926
   185
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@42395
   186
if (term2str t) = "17 + 15 * x ^^^ 2 + -48 * x ^^^ 4 + 3 * x ^^^ 5 + 6 * x ^^^ 7 + -8 * x ^^^ 9"
neuper@42395
   187
then () else error "poly.sml: diff.behav. in make_polynomial 1";
neuper@37906
   188
neuper@38036
   189
"-----SPB Schalk I p.63 No.275b ---";
neuper@42395
   190
val t = str2term "(3*x^^^2 - 2*x*y + y^^^2) * (x^^^2 - 2*y^^^2)";
neuper@42395
   191
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@42395
   192
if (term2str t) = ("3 * x ^^^ 4 + -2 * x ^^^ 3 * y + -5 * x ^^^ 2 * y ^^^ 2 + " ^
neuper@42395
   193
  "4 * x * y ^^^ 3 +\n-2 * y ^^^ 4")
neuper@42395
   194
then () else error "poly.sml: diff.behav. in make_polynomial 2";
neuper@37906
   195
neuper@38036
   196
"-----SPB Schalk I p.63 No.279b ---";
neuper@42395
   197
val t = str2term "(x-a)*(x-b)*(x-c)*(x-d)";
neuper@42395
   198
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
   199
if (term2str t) = 
neuper@42395
   200
  ("a * b * c * d + -1 * a * b * c * x + -1 * a * b * d * x + a * b * x ^^^ 2 +\n" ^
neuper@42395
   201
  "-1 * a * c * d * x +\na * c * x ^^^ 2 +\na * d * x ^^^ 2 +\n-1 * a * x ^^^ 3 +\n" ^
neuper@42395
   202
  "-1 * b * c * d * x +\nb * c * x ^^^ 2 +\nb * d * x ^^^ 2 +\n-1 * b * x ^^^ 3 +\n" ^
neuper@42395
   203
  "c * d * x ^^^ 2 +\n-1 * c * x ^^^ 3 +\n-1 * d * x ^^^ 3 +\nx ^^^ 4")
neuper@42395
   204
then () else error "poly.sml: diff.behav. in make_polynomial 3";
neuper@37906
   205
neuper@38036
   206
"-----SPB Schalk I p.63 No.291 ---";
neuper@42395
   207
val t = str2term "(5+96*x^^^3+8*x*(-4+(7- 3*x)*4*x))*(5*(2- 3*x)- (-15*x*(-8*x- 5)))";
neuper@42395
   208
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@42395
   209
if (term2str t) = "50 + -770 * x + 4520 * x ^^^ 2 + -16320 * x ^^^ 3 + -26880 * x ^^^ 4"
neuper@42395
   210
then () else error "poly.sml: diff.behav. in make_polynomial 4";
neuper@37906
   211
neuper@38036
   212
"-----SPB Schalk I p.64 No.295c ---";
neuper@42395
   213
val t = str2term "(13*a^^^4*b^^^9*c - 12*a^^^3*b^^^6*c^^^9)^^^2";
neuper@42395
   214
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@42395
   215
if (term2str t) = ("169 * a ^^^ 8 * b ^^^ 18 * c ^^^ 2 + -312 * a ^^^ 7 * b ^^^ 15 * c ^^^ 10" ^
neuper@42395
   216
  " +\n144 * a ^^^ 6 * b ^^^ 12 * c ^^^ 18")
neuper@42395
   217
then ()else error "poly.sml: diff.behav. in make_polynomial 5";
neuper@37906
   218
neuper@38036
   219
"-----SPB Schalk I p.64 No.299a ---";
neuper@42395
   220
val t = str2term "(x - y)*(x + y)";
neuper@42395
   221
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@42395
   222
if (term2str t) = "x ^^^ 2 + -1 * y ^^^ 2"
neuper@42395
   223
then () else error "poly.sml: diff.behav. in make_polynomial 6";
neuper@37906
   224
neuper@38036
   225
"-----SPB Schalk I p.64 No.300c ---";
neuper@42395
   226
val t = str2term "(3*x^^^2*y - 1)*(3*x^^^2*y + 1)";
neuper@42395
   227
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@42395
   228
if (term2str t) = "-1 + 9 * x ^^^ 4 * y ^^^ 2"
neuper@42395
   229
then () else error "poly.sml: diff.behav. in make_polynomial 7";
neuper@37906
   230
neuper@38036
   231
"-----SPB Schalk I p.64 No.302 ---";
neuper@37906
   232
val t = str2term
neuper@42395
   233
  "(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@42395
   234
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@42395
   235
if term2str t = "0"
neuper@42395
   236
then () else error "poly.sml: diff.behav. in make_polynomial 8";
neuper@42395
   237
(* RL?MG?: Bei Berechnung sollte 3 mal real_plus_minus_binom1_p aus expand_poly verwendet werden *)
neuper@37906
   238
neuper@38036
   239
"-----SPB Schalk I p.64 No.306a ---";
neuper@37906
   240
val t = str2term "((x^^^2 + 1)*(x^^^2 - 1))^^^2";
neuper@37926
   241
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   242
if (term2str t) = "1 + 2 * x ^^^ 4 + 2 * -2 * x ^^^ 4 + x ^^^ 8" then ()
neuper@42395
   243
else error "poly.sml: diff.behav. in 2 * x ^^^ 4 + 2 * -2 * x ^^^ 4 = -2 * x ^^^ 4";
neuper@37906
   244
neuper@37906
   245
(*WN071729 when reducing "rls reduce_012_" for Schaerding,
neuper@37906
   246
the above resulted in the term below ... but reduces from then correctly*)
neuper@37906
   247
val t = str2term "1 + 2 * x ^^^ 4 + 2 * -2 * x ^^^ 4 + x ^^^ 8";
neuper@37926
   248
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@42395
   249
if (term2str t) = "1 + -2 * x ^^^ 4 + x ^^^ 8"
neuper@42395
   250
then () else error "poly.sml: diff.behav. in make_polynomial 9b";
neuper@37906
   251
neuper@38036
   252
"-----SPB Schalk I p.64 No.296a ---";
neuper@37906
   253
val t = str2term "(x - a)^^^3";
neuper@37926
   254
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   255
if (term2str t) = "-1 * a ^^^ 3 + 3 * a ^^^ 2 * x + -3 * a * x ^^^ 2 + x ^^^ 3"
neuper@38031
   256
then () else error "poly.sml: diff.behav. in make_polynomial 10";
neuper@37906
   257
neuper@38036
   258
"-----SPB Schalk I p.64 No.296c ---";
neuper@37906
   259
val t = str2term "(-3*x - 4*y)^^^3";
neuper@37926
   260
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@42395
   261
if (term2str t) = "-27 * x ^^^ 3 + -108 * x ^^^ 2 * y + -144 * x * y ^^^ 2 + -64 * y ^^^ 3"
neuper@38031
   262
then () else error "poly.sml: diff.behav. in make_polynomial 11";
neuper@37906
   263
neuper@38036
   264
"-----SPB Schalk I p.62 No.242c ---";
neuper@37906
   265
val t = str2term "x^^^(-4)*(x^^^(-4)*y^^^(-2))^^^(-1)*y^^^(-2)";
neuper@37926
   266
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@42395
   267
if (term2str t) = "1"
neuper@42395
   268
then () else error "poly.sml: diff.behav. in make_polynomial 12";
neuper@37906
   269
neuper@38036
   270
"-----SPB Schalk I p.60 No.209a ---";
neuper@37906
   271
val t = str2term "a^^^(7-x) * a^^^x";
neuper@37926
   272
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@42395
   273
if term2str t = "a ^^^ 7"
neuper@42395
   274
then () else error "poly.sml: diff.behav. in make_polynomial 13";
neuper@37906
   275
neuper@38036
   276
"-----SPB Schalk I p.60 No.209d ---";
neuper@37906
   277
val t = str2term "d^^^x * d^^^(x+1) * d^^^(2 - 2*x)";
neuper@37926
   278
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@42395
   279
if term2str t = "d ^^^ 3"
neuper@42395
   280
then () else error "poly.sml: diff.behav. in make_polynomial 14";
neuper@37906
   281
neuper@37906
   282
(*---------------------------------------------------------------------*)
neuper@42395
   283
(*---------------- ?RL?Bsple bei denen es Probleme gibt----------------*)
neuper@37906
   284
(*---------------------------------------------------------------------*)
neuper@38036
   285
"-----Schalk I p.64 No.303 ---";
neuper@37906
   286
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
   287
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@42395
   288
if term2str t = "1280 * b ^^^ 4"
neuper@42395
   289
then () else error "poly.sml: diff.behav. in make_polynomial 14b";
neuper@37906
   290
(* Richtig - aber Binomische Formel wurde nicht verwendet! *)
neuper@37906
   291
neuper@37906
   292
(*--------------------------------------------------------------------*)
neuper@37906
   293
(*----------------------- Eigene Beispiele ---------------------------*)
neuper@37906
   294
(*--------------------------------------------------------------------*)
neuper@38036
   295
"-----SPO ---";
neuper@37906
   296
val t = str2term "a^^^2*a^^^(-2)";
neuper@37926
   297
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   298
if term2str t = "1" then ()
neuper@38031
   299
else error "poly.sml: diff.behav. in make_polynomial 15";
neuper@38036
   300
"-----SPO ---";
neuper@37906
   301
val t = str2term "a + a + a";
neuper@37926
   302
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   303
if term2str t = "3 * a" then ()
neuper@38031
   304
else error "poly.sml: diff.behav. in make_polynomial 16";
neuper@38036
   305
"-----SPO ---";
neuper@37906
   306
val t = str2term "a + b + b + b";
neuper@37926
   307
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   308
if term2str t = "a + 3 * b" then ()
neuper@38031
   309
else error "poly.sml: diff.behav. in make_polynomial 17";
neuper@38036
   310
"-----SPO ---";
neuper@37906
   311
val t = str2term "a^^^2*b*b^^^(-1)";
neuper@37926
   312
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   313
if term2str t = "a ^^^ 2" then ()
neuper@38031
   314
else error "poly.sml: diff.behav. in make_polynomial 18";
neuper@38036
   315
"-----SPO ---";
neuper@37906
   316
val t = str2term "a^^^2*a^^^(-2)";
neuper@37926
   317
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   318
if (term2str t) = "1" then ()
neuper@38031
   319
else error "poly.sml: diff.behav. in make_polynomial 19";
neuper@38036
   320
"-----SPO ---";
neuper@37906
   321
val t = str2term "b + a - b";
neuper@37926
   322
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   323
if (term2str t) = "a" then ()
neuper@38031
   324
else error "poly.sml: diff.behav. in make_polynomial 20";
neuper@38036
   325
"-----SPO ---";
neuper@37906
   326
val t = str2term "b * a * a";
neuper@37926
   327
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   328
if term2str t = "a ^^^ 2 * b" then ()
neuper@38031
   329
else error "poly.sml: diff.behav. in make_polynomial 21";
neuper@38036
   330
"-----SPO ---";
neuper@37906
   331
val t = str2term "(a^^^2)^^^3";
neuper@37926
   332
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   333
if term2str t = "a ^^^ 6" then ()
neuper@38031
   334
else error "poly.sml: diff.behav. in make_polynomial 22";
neuper@38036
   335
"-----SPO ---";
neuper@37906
   336
val t = str2term "x^^^2 * y^^^2 + x * x^^^2 * y";
neuper@37926
   337
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   338
if term2str t = "x ^^^ 3 * y + x ^^^ 2 * y ^^^ 2" then ()
neuper@38031
   339
else error "poly.sml: diff.behav. in make_polynomial 23";
neuper@38036
   340
"-----SPO ---";
neuper@37906
   341
val t = (term_of o the o (parse thy)) "a^^^2 * (-a)^^^2";
neuper@37926
   342
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   343
if (term2str t) = "a ^^^ 4" then ()
neuper@38031
   344
else error "poly.sml: diff.behav. in make_polynomial 24";
neuper@38036
   345
"-----SPO ---";
neuper@37906
   346
val t = str2term "a * b * b^^^(-1) + a";
neuper@37926
   347
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   348
if (term2str t) = "2 * a" then ()
neuper@38031
   349
else error "poly.sml: diff.behav. in make_polynomial 25";
neuper@38036
   350
"-----SPO ---";
neuper@37906
   351
val t = str2term "a*c*b^^^(2*n) + 3*a + 5*b^^^(2*n)*c*b";
neuper@37926
   352
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; term2str t;
neuper@37906
   353
if (term2str t) = "3 * a + 5 * b ^^^ (1 + 2 * n) * c + a * b ^^^ (2 * n) * c"
neuper@38031
   354
then () else error "poly.sml: diff.behav. in make_polynomial 26";
neuper@37906
   355
neuper@42395
   356
(*MG030627 -------------vvv-: Verschachtelte Terme -----------*)
neuper@38036
   357
"-----SPO ---";
neuper@37906
   358
val t = str2term "(1 + (x*y*a) + x)^^^(1 + (x*y*a) + x)";
neuper@42395
   359
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
   360
if term2str t = "(1 + x + a * x * y) ^^^ (1 + x + a * x * y)"
neuper@42395
   361
then () else error "poly.sml: diff.behav. in make_polynomial 27";(*SPO*)
neuper@42395
   362
neuper@37906
   363
val t = str2term "(1 + x*(y*z)*zz)^^^(1 + x*(y*z)*zz)";
neuper@42395
   364
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
neuper@37906
   365
if term2str t = "(1 + x * y * z * zz) ^^^ (1 + x * y * z * zz)"
neuper@42395
   366
then () else error "poly.sml: diff.behav. in make_polynomial 28";
neuper@37906
   367
neuper@38036
   368
"-------- check pbl  'polynomial simplification' --------";
neuper@38036
   369
"-------- check pbl  'polynomial simplification' --------";
neuper@38036
   370
"-------- check pbl  'polynomial simplification' --------";
neuper@42395
   371
val fmz = ["Term ((5*x^^^2 + 3) * (2*x^^^7 + 3) - (3*x^^^5 + 8) * (6*x^^^4 - 1))", "normalform N"];
neuper@38036
   372
"-----0 ---";
neuper@37906
   373
case refine fmz ["polynomial","simplification"]of
neuper@37906
   374
    [Matches (["polynomial", "simplification"], _)] => ()
neuper@38031
   375
  | _ => error "poly.sml diff.behav. in check pbl, refine";
neuper@37906
   376
(*...if there is an error, then ...*)
neuper@37906
   377
neuper@38036
   378
"-----1 ---";
wneuper@59111
   379
default_print_depth 7;
neuper@37906
   380
val pbt = get_pbt ["polynomial","simplification"];
wneuper@59111
   381
default_print_depth 3;
neuper@37906
   382
(*if there is ...
neuper@37906
   383
> val NoMatch' {Given=gi, Where=wh, Find=fi,...} = match_pbl fmz pbt;
neuper@37906
   384
... then trace_rewrite:*)
neuper@37906
   385
neuper@38036
   386
"-----2 ---";
neuper@52101
   387
trace_rewrite := false;
neuper@37906
   388
match_pbl fmz pbt;
neuper@42395
   389
trace_rewrite := false;
neuper@37906
   390
(*... if there is no rewrite, then there is something wrong with prls*)
neuper@52101
   391
                              
neuper@38036
   392
"-----3 ---";
wneuper@59111
   393
default_print_depth 7;
neuper@37906
   394
val prls = (#prls o get_pbt) ["polynomial","simplification"];
wneuper@59111
   395
default_print_depth 3;
neuper@42395
   396
val t = str2term "((5*x^^^2 + 3) * (2*x^^^7 + 3) - (3*x^^^5 + 8) * (6*x^^^4 - 1)) is_polyexp";
neuper@37926
   397
val SOME (t',_) = rewrite_set_ thy false prls t;
neuper@48760
   398
if t' = @{term True} then () 
neuper@38031
   399
else error "poly.sml: diff.behav. in check pbl 'polynomial..";
neuper@42395
   400
(*... if this works, but --1-- does still NOT work, check types:*)
neuper@37906
   401
neuper@38036
   402
"-----4 ---";
neuper@42395
   403
(*show_types:=true;*)
neuper@37906
   404
(*
neuper@37906
   405
> val NoMatch' {Given=gi, Where=wh, Find=fi,...} = match_pbl fmz pbt;
neuper@37906
   406
val wh = [False "(t_::real => real) (is_polyexp::real)"]
neuper@37906
   407
......................^^^^^^^^^^^^...............^^^^*)
neuper@37906
   408
val Matches' _ = match_pbl fmz pbt;
neuper@42395
   409
(*show_types:=false;*)
neuper@37906
   410
neuper@38036
   411
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
neuper@38036
   412
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
neuper@38036
   413
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
neuper@42395
   414
val fmz = ["Term ((5*x^^^2 + 3) * (2*x^^^7 + 3) - (3*x^^^5 + 8) * (6*x^^^4 - 1))", "normalform N"];
neuper@37906
   415
val (dI',pI',mI') =
neuper@37991
   416
  ("Poly",["polynomial","simplification"],
neuper@37906
   417
   ["simplification","for_polynomials"]);
neuper@37906
   418
val p = e_pos'; val c = []; 
neuper@37906
   419
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@37906
   420
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   421
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37924
   422
(writeln o (itms2str_ ctxt)) (get_obj g_pbl pt (fst p));
neuper@37906
   423
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   424
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   425
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   426
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   427
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
   428
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@37906
   429
val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f;
neuper@42395
   430
if f2str f = "17 + 15 * x ^^^ 2 + -48 * x ^^^ 4 + 3 * x ^^^ 5 + 6 * x ^^^ 7 + -8 * x ^^^ 9"
neuper@38031
   431
then () else error "poly.sml diff.behav. in me Schalk I p.63 No.267b";
neuper@37906
   432
neuper@38036
   433
"-------- interSteps for Schalk 299a --------------------";
neuper@38036
   434
"-------- interSteps for Schalk 299a --------------------";
neuper@38036
   435
"-------- interSteps for Schalk 299a --------------------";
s1210629013@55445
   436
reset_states ();
neuper@37906
   437
CalcTree
neuper@42395
   438
[(["Term ((x - y)*(x + (y::real)))", "normalform N"], 
neuper@37991
   439
  ("Poly",["polynomial","simplification"],
neuper@37906
   440
  ["simplification","for_polynomials"]))];
neuper@37906
   441
Iterator 1;
neuper@37906
   442
moveActiveRoot 1;
s1210629013@55446
   443
autoCalculate' 1 CompleteCalc;
neuper@37906
   444
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   445
neuper@37906
   446
interSteps 1 ([1],Res)(*<ERROR> syserror in detailstep </ERROR>*);
neuper@37906
   447
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   448
if existpt' ([1,1], Frm) pt then ()
neuper@38031
   449
else error "poly.sml: interSteps doesnt work again 1";
neuper@37906
   450
neuper@37906
   451
interSteps 1 ([1,1],Res)(*<ERROR> syserror in detailstep </ERROR>*);
neuper@37906
   452
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@42395
   453
(*============ inhibit exn WN120316 ==============================================
neuper@37906
   454
if existpt' ([1,1,1], Frm) pt then ()
neuper@38031
   455
else error "poly.sml: interSteps doesnt work again 2";
neuper@42395
   456
============ inhibit exn WN120316 ==============================================*)
neuper@37906
   457
neuper@38036
   458
"-------- norm_Poly NOT COMPLETE ------------------------";
neuper@38036
   459
"-------- norm_Poly NOT COMPLETE ------------------------";
neuper@38036
   460
"-------- norm_Poly NOT COMPLETE ------------------------";
neuper@37926
   461
val SOME (f',_) = rewrite_set_ thy false norm_Poly 
neuper@42395
   462
(str2term "L = k - 2 * q + (k - 2 * q) + (k - 2 * q) + (k - 2 * q) + senkrecht + oben");
neuper@42395
   463
if term2str f' = "L = 2 * 2 * k + oben + 2 * -4 * q + senkrecht"
neuper@42395
   464
then ((*norm_Poly NOT COMPLETE -- TODO MG*))
neuper@42395
   465
else error "norm_Poly changed behavior";
neuper@38036
   466
neuper@38036
   467
"-------- ord_make_polynomial ---------------------------";
neuper@38036
   468
"-------- ord_make_polynomial ---------------------------";
neuper@38036
   469
"-------- ord_make_polynomial ---------------------------";
neuper@37906
   470
val t1 = str2term "2 * b + (3 * a + 3 * b)";
neuper@37906
   471
val t2 = str2term "3 * a + 3 * b + 2 * b";
neuper@37906
   472
neuper@42395
   473
if ord_make_polynomial true thy [] (t1, t2) then ()
neuper@38031
   474
else error "poly.sml: diff.behav. in ord_make_polynomial";
neuper@37906
   475
neuper@37906
   476
(*WN071202: ^^^ why then is there no rewriting ...*)
neuper@37906
   477
val term = str2term "2*b + (3*a + 3*b)";
neuper@41929
   478
val NONE = rewrite_set_ (@{theory "Isac"}) false order_add_mult term;
neuper@37906
   479
neuper@37906
   480
(*or why is there no rewriting this way...*)
neuper@37906
   481
val t1 = str2term "2 * b + (3 * a + 3 * b)";
neuper@37906
   482
val t2 = str2term "3 * a + (2 * b + 3 * b)";
neuper@37906
   483