test/Tools/isac/Knowledge/poly.sml
author wneuper <walther.neuper@jku.at>
Tue, 01 Jun 2021 15:41:23 +0200
changeset 60317 638d02a9a96a
parent 60278 343efa173023
child 60318 e6e7a9b9ced7
permissions -rw-r--r--
Test_Some.thy with looping ML<>
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
"--------------------------------------------------------";
wneuper@59529
    16
"----------- fun is_polyexp --------------------------------------------------------------------";
wneuper@59522
    17
"----------- fun has_degree_in -----------------------------------------------------------------";
wneuper@59522
    18
"----------- fun mono_deg_in -------------------------------------------------------------------";
wneuper@59522
    19
"----------- fun mono_deg_in -------------------------------------------------------------------";
wneuper@59522
    20
"----------- eval_ for is_expanded_in, is_poly_in, has_degree_in -------------------------------";
neuper@42395
    21
"-------- investigate (new 2002) uniary minus -----------";
walther@60317
    22
"----------- fun sort_variables ----------------------------------------------------------------";
neuper@38036
    23
"-------- check make_polynomial with simple terms -------";
neuper@38036
    24
"-------- fun is_multUnordered --------------------------";
neuper@38036
    25
"-------- examples from textbook Schalk I ---------------";
neuper@38022
    26
"-------- check pbl  'polynomial simplification' --------";
neuper@38022
    27
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
neuper@38036
    28
"-------- interSteps for Schalk 299a --------------------";
neuper@38022
    29
"-------- norm_Poly NOT COMPLETE ------------------------";
neuper@38022
    30
"-------- ord_make_polynomial ---------------------------";
neuper@38022
    31
"--------------------------------------------------------";
neuper@38022
    32
"--------------------------------------------------------";
neuper@38022
    33
"--------------------------------------------------------";
neuper@37906
    34
neuper@37906
    35
wneuper@59529
    36
"----------- fun is_polyexp --------------------------------------------------------------------";
wneuper@59529
    37
"----------- fun is_polyexp --------------------------------------------------------------------";
wneuper@59529
    38
"----------- fun is_polyexp --------------------------------------------------------------------";
wneuper@59529
    39
val thy = @{theory Partial_Fractions};
wneuper@59529
    40
val ctxt = Proof_Context.init_global thy;
wneuper@59529
    41
wneuper@59529
    42
val t = (the o (parseNEW  ctxt)) "x / x";
wneuper@59529
    43
if is_polyexp t then error "NOT is_polyexp (x / x)" else ();
wneuper@59529
    44
wneuper@59529
    45
val t = (the o (parseNEW  ctxt)) "-1 * A * 3";
wneuper@59529
    46
if is_polyexp t then () else error "is_polyexp (-1 * A * 3)";
wneuper@59529
    47
wneuper@59529
    48
val t = (the o (parseNEW  ctxt)) "-1 * AA * 3";
wneuper@59529
    49
if is_polyexp t then () else error "is_polyexp (-1 * AA * 3)";
neuper@38022
    50
wneuper@59522
    51
"----------- fun has_degree_in -----------------------------------------------------------------";
wneuper@59522
    52
"----------- fun has_degree_in -----------------------------------------------------------------";
wneuper@59522
    53
"----------- fun has_degree_in -----------------------------------------------------------------";
walther@60230
    54
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
    55
val t = (Thm.term_of o the o (TermC.parse thy)) "1";
wneuper@59522
    56
if has_degree_in t v = 0 then () else error "has_degree_in (1) x";
wneuper@59522
    57
walther@60230
    58
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
    59
val t = (Thm.term_of o the o (TermC.parse thy)) "1";
wneuper@59522
    60
if has_degree_in t v = 0 then () else error "has_degree_in (1) AA";
wneuper@59522
    61
wneuper@59522
    62
(*----------*)
walther@60230
    63
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
    64
val t = (Thm.term_of o the o (TermC.parse thy)) "a*b+c";
wneuper@59522
    65
if has_degree_in t v = 0 then () else error "has_degree_in (a*b+c) x";
wneuper@59522
    66
walther@60230
    67
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
    68
val t = (Thm.term_of o the o (TermC.parse thy)) "a*b+c";
wneuper@59522
    69
if has_degree_in t v = 0 then () else error "has_degree_in (a*b+c) AA";
wneuper@59522
    70
wneuper@59522
    71
(*----------*)
walther@60230
    72
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
    73
val t = (Thm.term_of o the o (TermC.parse thy)) "a*x+c";
wneuper@59522
    74
if has_degree_in t v = ~1 then () else error "has_degree_in (a*x+c) x";
wneuper@59522
    75
walther@60230
    76
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
    77
val t = (Thm.term_of o the o (TermC.parse thy)) "a*AA+c";
wneuper@59522
    78
if has_degree_in t v = ~1 then () else error "has_degree_in (a*AA+c) AA";
wneuper@59522
    79
wneuper@59522
    80
(*----------*)
walther@60230
    81
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60242
    82
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*x \<up> 7";
walther@60242
    83
if has_degree_in t v = 7 then () else error "has_degree_in ((a*b+c)*x \<up> 7) x";
wneuper@59522
    84
walther@60230
    85
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60242
    86
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*AA \<up> 7";
walther@60242
    87
if has_degree_in t v = 7 then () else error "has_degree_in ((a*b+c)*AA \<up> 7) AA";
wneuper@59522
    88
wneuper@59522
    89
(*----------*)
walther@60230
    90
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60242
    91
val t = (Thm.term_of o the o (TermC.parse thy)) "x \<up> 7";
walther@60242
    92
if has_degree_in t v = 7 then () else error "has_degree_in (x \<up> 7) x";
wneuper@59522
    93
walther@60230
    94
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60242
    95
val t = (Thm.term_of o the o (TermC.parse thy)) "AA \<up> 7";
walther@60242
    96
if has_degree_in t v = 7 then () else error "has_degree_in (AA \<up> 7) AA";
wneuper@59522
    97
wneuper@59522
    98
(*----------*)
walther@60230
    99
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   100
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*x";
wneuper@59522
   101
if has_degree_in t v = 1 then () else error "has_degree_in ((a*b+c)*x) x";
wneuper@59522
   102
walther@60230
   103
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   104
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*AA";
wneuper@59522
   105
if has_degree_in t v = 1 then () else error "has_degree_in ((a*b+c)*AA) AA";
wneuper@59522
   106
wneuper@59522
   107
(*----------*)
walther@60230
   108
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   109
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+x)*x";
wneuper@59522
   110
if has_degree_in t v = ~1 then () else error "has_degree_in (a*b+x)*x() x";
wneuper@59522
   111
walther@60230
   112
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   113
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+AA)*AA";
wneuper@59522
   114
if has_degree_in t v = ~1 then () else error "has_degree_in ((a*b+AA)*AA) AA";
wneuper@59522
   115
wneuper@59522
   116
(*----------*)
walther@60230
   117
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   118
val t = (Thm.term_of o the o (TermC.parse thy)) "x";
wneuper@59522
   119
if has_degree_in t v = 1 then () else error "has_degree_in (x) x";
wneuper@59522
   120
walther@60230
   121
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   122
val t = (Thm.term_of o the o (TermC.parse thy)) "AA";
wneuper@59522
   123
if has_degree_in t v = 1 then () else error "has_degree_in (AA) AA";
wneuper@59522
   124
wneuper@59522
   125
(*----------*)
walther@60230
   126
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   127
val t = (Thm.term_of o the o (TermC.parse thy)) "ab - (a*b)*x";
wneuper@59522
   128
if has_degree_in t v = 1 then () else error "has_degree_in (ab - (a*b)*x) x";
wneuper@59522
   129
walther@60230
   130
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   131
val t = (Thm.term_of o the o (TermC.parse thy)) "ab - (a*b)*AA";
wneuper@59522
   132
if has_degree_in t v = 1 then () else error "has_degree_in (ab - (a*b)*AA) AA";
wneuper@59522
   133
wneuper@59522
   134
"----------- fun mono_deg_in -------------------------------------------------------------------";
wneuper@59522
   135
"----------- fun mono_deg_in -------------------------------------------------------------------";
wneuper@59522
   136
"----------- fun mono_deg_in -------------------------------------------------------------------";
walther@60230
   137
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
wneuper@59522
   138
walther@60242
   139
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*x \<up> 7";
walther@60242
   140
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in ((a*b+c)*x \<up> 7) x changed";
wneuper@59522
   141
walther@60242
   142
val t = (Thm.term_of o the o (TermC.parse thy)) "x \<up> 7";
walther@60242
   143
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in (x \<up> 7) x changed";
wneuper@59522
   144
walther@60230
   145
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*x";
wneuper@59522
   146
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in ((a*b+c)*x) x changed";
wneuper@59522
   147
walther@60230
   148
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+x)*x";
wneuper@59522
   149
if mono_deg_in t v = NONE then () else error "mono_deg_in ((a*b+x)*x) x changed";
wneuper@59522
   150
walther@60230
   151
val t = (Thm.term_of o the o (TermC.parse thy)) "x";
wneuper@59522
   152
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in (x) x changed";
wneuper@59522
   153
walther@60230
   154
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)";
wneuper@59522
   155
if mono_deg_in t v = SOME 0 then () else error "mono_deg_in ((a*b+c)) x changed";
wneuper@59522
   156
walther@60230
   157
val t = (Thm.term_of o the o (TermC.parse thy)) "ab - (a*b)*x";
wneuper@59522
   158
if mono_deg_in t v = NONE then () else error "mono_deg_in (ab - (a*b)*x) x changed";
wneuper@59522
   159
wneuper@59522
   160
(*. . . . . . . . . . . . the same with Const ("Partial_Functions.AA", _) . . . . . . . . . . . *)
wneuper@59522
   161
val thy = @{theory Partial_Fractions}
walther@60230
   162
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
wneuper@59522
   163
walther@60242
   164
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*AA \<up> 7";
walther@60242
   165
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in ((a*b+c)*AA \<up> 7) AA changed";
wneuper@59522
   166
walther@60242
   167
val t = (Thm.term_of o the o (TermC.parse thy)) "AA \<up> 7";
walther@60242
   168
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in (AA \<up> 7) AA changed";
wneuper@59522
   169
walther@60230
   170
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*AA";
wneuper@59522
   171
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in ((a*b+c)*AA) AA changed";
wneuper@59522
   172
walther@60230
   173
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+AA)*AA";
wneuper@59522
   174
if mono_deg_in t v = NONE then () else error "mono_deg_in ((a*b+AA)*AA) AA changed";
wneuper@59522
   175
walther@60230
   176
val t = (Thm.term_of o the o (TermC.parse thy)) "AA";
wneuper@59522
   177
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in (AA) AA changed";
wneuper@59522
   178
walther@60230
   179
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)";
wneuper@59522
   180
if mono_deg_in t v = SOME 0 then () else error "mono_deg_in ((a*b+c)) AA changed";
wneuper@59522
   181
walther@60230
   182
val t = (Thm.term_of o the o (TermC.parse thy)) "ab - (a*b)*AA";
wneuper@59522
   183
if mono_deg_in t v = NONE then () else error "mono_deg_in (ab - (a*b)*AA) AA changed";
wneuper@59522
   184
wneuper@59522
   185
"----------- rewrite_set_ has_degree_in Const ('Partial_Fractions', _) -------------------------";
wneuper@59522
   186
"----------- rewrite_set_ has_degree_in Const ('Partial_Fractions', _) -------------------------";
wneuper@59522
   187
"----------- rewrite_set_ has_degree_in Const ('Partial_Fractions', _) -------------------------";
wneuper@59522
   188
val thy = @{theory Partial_Fractions}
walther@60242
   189
val expr = (Thm.term_of o the o (TermC.parse thy)) "((-8 - 2*x + x \<up> 2) has_degree_in x) = 2";
wneuper@59522
   190
val SOME (Const ("HOL.True", _), []) = rewrite_set_ thy false PolyEq_prls expr;
wneuper@59522
   191
walther@60242
   192
val expr = (Thm.term_of o the o (TermC.parse thy)) "((-8 - 2*AA + AA \<up> 2) has_degree_in AA) = 2";
wneuper@59522
   193
val SOME (Const ("HOL.True", _), []) = rewrite_set_ thy false PolyEq_prls expr;
wneuper@59522
   194
wneuper@59522
   195
"----------- eval_ for is_expanded_in, is_poly_in, has_degree_in -------------------------------";
wneuper@59522
   196
"----------- eval_ for is_expanded_in, is_poly_in, has_degree_in -------------------------------";
wneuper@59522
   197
"----------- eval_ for is_expanded_in, is_poly_in, has_degree_in -------------------------------";
walther@60242
   198
val t = (Thm.term_of o the o (TermC.parse thy)) "(-8 - 2*x + x \<up> 2) is_expanded_in x";
wneuper@59522
   199
val SOME (id, t') = eval_is_expanded_in 0 0 t 0;
walther@60317
   200
if UnparseC.term t' = "- 8 - 2 * x + x \<up> 2 is_expanded_in x = True"
walther@60317
   201
         andalso id = "- 8 - 2 * x + x \<up> 2 is_expanded_in x = True"
wneuper@59522
   202
then () else error "eval_is_expanded_in x ..changed";
wneuper@59522
   203
wneuper@59522
   204
val thy = @{theory Partial_Fractions}
walther@60242
   205
val t = (Thm.term_of o the o (TermC.parse thy)) "(-8 - 2*AA + AA \<up> 2) is_expanded_in AA";
wneuper@59522
   206
val SOME (id, t') = eval_is_expanded_in 0 0 t 0;
walther@60317
   207
if  UnparseC.term t' = "- 8 - 2 * AA + AA \<up> 2 is_expanded_in AA = True"
walther@60317
   208
          andalso id = "- 8 - 2 * AA + AA \<up> 2 is_expanded_in AA = True"
wneuper@59522
   209
then () else error "eval_is_expanded_in AA ..changed";
wneuper@59522
   210
wneuper@59522
   211
walther@60242
   212
val t = (Thm.term_of o the o (TermC.parse thy)) "(8 + 2*x + x \<up> 2) is_poly_in x";
wneuper@59522
   213
val SOME (id, t') = eval_is_poly_in 0 0 t 0;
walther@60242
   214
if  UnparseC.term t' = "8 + 2 * x + x \<up> 2 is_poly_in x = True"
walther@60242
   215
          andalso id = "8 + 2 * x + x \<up> 2 is_poly_in x = True"
wneuper@59522
   216
then () else error "is_poly_in x ..changed";
wneuper@59522
   217
walther@60242
   218
val t = (Thm.term_of o the o (TermC.parse thy)) "(8 + 2*AA + AA \<up> 2) is_poly_in AA";
wneuper@59522
   219
val SOME (id, t') = eval_is_poly_in 0 0 t 0;
walther@60242
   220
if  UnparseC.term t' = "8 + 2 * AA + AA \<up> 2 is_poly_in AA = True"
walther@60242
   221
          andalso id = "8 + 2 * AA + AA \<up> 2 is_poly_in AA = True"
wneuper@59522
   222
then () else error "is_poly_in AA ..changed";
wneuper@59522
   223
wneuper@59522
   224
wneuper@59522
   225
val thy = @{theory Partial_Fractions}
walther@60242
   226
val expr = (Thm.term_of o the o (TermC.parse thy)) "((-8 - 2*x + x \<up> 2) has_degree_in x) = 2";
wneuper@59522
   227
val SOME (Const ("HOL.True", _), []) = rewrite_set_ thy false PolyEq_prls expr;
wneuper@59522
   228
walther@60242
   229
val expr = (Thm.term_of o the o (TermC.parse thy)) "((-8 - 2*AA + AA \<up> 2) has_degree_in AA) = 2";
wneuper@59522
   230
val SOME (Const ("HOL.True", _), []) = rewrite_set_ thy false PolyEq_prls expr;
wneuper@59522
   231
neuper@42395
   232
"-------- investigate (new 2002) uniary minus -----------";
neuper@42395
   233
"-------- investigate (new 2002) uniary minus -----------";
neuper@42395
   234
"-------- investigate (new 2002) uniary minus -----------";
neuper@42395
   235
(*---------------------------------------------- vvvvvvvvvvvvvv -----------------------*)
wenzelm@60203
   236
val t = Thm.prop_of @{thm real_diff_0}; (*"0 - ?x = - ?x"*)
walther@60230
   237
TermC.atomty t;
wneuper@59117
   238
(*
wneuper@59117
   239
*** Const (HOL.Trueprop, bool => prop)
wneuper@59117
   240
*** . Const (HOL.eq, real => real => bool)
wneuper@59117
   241
*** . . Const (Groups.minus_class.minus, real => real => real)
wneuper@59117
   242
*** . . . Const (Groups.zero_class.zero, real)
neuper@37906
   243
*** . . . Var ((x, 0), real)
wneuper@59117
   244
*** . . Const (Groups.uminus_class.uminus, real => real)
wneuper@59117
   245
*** . . . Var ((x, 0), real)
wneuper@59117
   246
*)
neuper@42395
   247
case t of
neuper@42395
   248
  Const ("HOL.Trueprop", _) $
wneuper@59117
   249
    (Const ("HOL.eq", _) $ 
wneuper@59117
   250
      (Const ("Groups.minus_class.minus", _) $ Const ("Groups.zero_class.zero", _) $ 
wneuper@59117
   251
        Var (("x", 0), _)) $
wneuper@59117
   252
             (Const ("Groups.uminus_class.uminus", _) $ Var (("x", 0), _))) => ()
neuper@42395
   253
| _ => error "internal representation of \"0 - ?x = - ?x\" changed";
neuper@37906
   254
neuper@42395
   255
(*----------------------------------- vvvv --------------------------------------------*)
walther@60230
   256
val t = (Thm.term_of o the o (TermC.parse thy)) "-1";
walther@60230
   257
TermC.atomty t;
neuper@37906
   258
(*** -------------
neuper@37906
   259
*** Free ( -1, real)                      *)
neuper@42395
   260
case t of
neuper@42395
   261
  Free ("-1", _) => ()
neuper@42395
   262
| _ => error "internal representation of \"-1\" changed";
neuper@42395
   263
(*----------------------------------- vvvvv -------------------------------------------*)
walther@60230
   264
val t = (Thm.term_of o the o (TermC.parse thy)) "- 1";
walther@60230
   265
TermC.atomty t;
wneuper@59117
   266
(*
wneuper@59117
   267
*** 
wneuper@59117
   268
*** Free (-1, real)
wneuper@59117
   269
*** 
wneuper@59117
   270
*)
neuper@42395
   271
case t of
wneuper@59117
   272
 Free ("-1", _) => ()
neuper@42395
   273
| _ => error "internal representation of \"- 1\" changed";
neuper@37906
   274
neuper@42395
   275
"======= these external values all have the same internal representation";
neuper@42395
   276
(* "1-x" causes syntyx error --- binary minus detected by blank inbetween !!!*)
neuper@42395
   277
(*----------------------------------- vvvvv -------------------------------------------*)
walther@60230
   278
val t = (Thm.term_of o the o (TermC.parse thy)) "-x";
walther@60230
   279
TermC.atomty t;
neuper@37906
   280
(**** -------------
neuper@37906
   281
*** Free ( -x, real)*)
neuper@42395
   282
case t of
neuper@42395
   283
  Const ("Groups.uminus_class.uminus", _) $ Free ("x", _) => ()
neuper@42395
   284
| _ => error "internal representation of \"-x\" changed";
neuper@42395
   285
(*----------------------------------- vvvvv -------------------------------------------*)
walther@60230
   286
val t = (Thm.term_of o the o (TermC.parse thy)) "- x";
walther@60230
   287
TermC.atomty t;
neuper@37906
   288
(**** -------------
neuper@37906
   289
*** Free ( -x, real) !!!!!!!!!!!!!!!!!!!!!!!! is the same !!!*)
neuper@42395
   290
case t of
neuper@42395
   291
  Const ("Groups.uminus_class.uminus", _) $ Free ("x", _) => ()
neuper@42395
   292
| _ => error "internal representation of \"- x\" changed";
neuper@42395
   293
(*----------------------------------- vvvvvv ------------------------------------------*)
walther@60230
   294
val t = (Thm.term_of o the o (TermC.parse thy)) "-(x)";
walther@60230
   295
TermC.atomty t;
neuper@37906
   296
(**** -------------
neuper@37906
   297
*** Free ( -x, real)*)
neuper@42395
   298
case t of
neuper@42395
   299
  Const ("Groups.uminus_class.uminus", _) $ Free ("x", _) => ()
neuper@42395
   300
| _ => error "internal representation of \"-(x)\" changed";
neuper@37906
   301
neuper@38036
   302
"-------- check make_polynomial with simple terms -------";
neuper@38036
   303
"-------- check make_polynomial with simple terms -------";
neuper@38036
   304
"-------- check make_polynomial with simple terms -------";
neuper@38036
   305
"----- check 1 ---";
walther@60230
   306
val t = TermC.str2term "2*3*a";
neuper@38036
   307
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@59868
   308
if UnparseC.term t = "6 * a" then () else error "check make_polynomial 1";
neuper@38036
   309
neuper@38036
   310
"----- check 2 ---";
walther@60230
   311
val t = TermC.str2term "2*a + 3*a";
neuper@38036
   312
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@59868
   313
if UnparseC.term t = "5 * a" then () else error "check make_polynomial 2";
neuper@38036
   314
neuper@38036
   315
"----- check 3 ---";
walther@60230
   316
val t = TermC.str2term "2*a + 3*a + 3*a";
neuper@38036
   317
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@59868
   318
if UnparseC.term t = "8 * a" then () else error "check make_polynomial 3";
neuper@38036
   319
neuper@38036
   320
"----- check 4 ---";
walther@60230
   321
val t = TermC.str2term "3*a - 2*a";
neuper@38036
   322
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@59868
   323
if UnparseC.term t = "a" then () else error "check make_polynomial 4";
neuper@38036
   324
neuper@38036
   325
"----- check 5 ---";
walther@60230
   326
val t = TermC.str2term "4*(3*a - 2*a)";
neuper@38036
   327
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@59868
   328
if UnparseC.term t = "4 * a" then () else error "check make_polynomial 5";
neuper@38036
   329
neuper@38036
   330
"----- check 6 ---";
walther@60242
   331
val t = TermC.str2term "4*(3*a \<up> 2 - 2*a \<up> 2)";
neuper@38036
   332
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@60242
   333
if UnparseC.term t = "4 * a \<up> 2" then () else error "check make_polynomial 6";
neuper@38036
   334
neuper@38036
   335
"-------- fun is_multUnordered --------------------------";
neuper@38036
   336
"-------- fun is_multUnordered --------------------------";
neuper@38036
   337
"-------- fun is_multUnordered --------------------------";
wneuper@59592
   338
val thy = @{theory "Isac_Knowledge"};
neuper@38040
   339
"===== works for a simple example, see rewrite.sml -- fun app_rev ===";
walther@60242
   340
val t = TermC.str2term "x \<up> 2 * x";
neuper@38040
   341
val SOME (t', _) = rewrite_set_ thy true order_mult_ t;
walther@60242
   342
if UnparseC.term t' = "x * x \<up> 2" then ()
walther@60278
   343
else error "poly.sml Poly.is_multUnordered doesn't work";
neuper@38040
   344
walther@59901
   345
(* 100928 Rewrite.trace_on shows the first occurring difference in 267b:
walther@60242
   346
###  rls: order_mult_ on: 5 * x \<up> 2 * (2 * x \<up> 7) + 5 * x \<up> 2 * 3 + (6 * x \<up> 7 + 9) + (-1 * (3 * x \<up> 5 * (6 * x \<up> 4)) + -1 * (3 * x \<up> 5 * -1) +
walther@60242
   347
 (-48 * x \<up> 4 + 8))
walther@59852
   348
######  rls: Rule_Set.empty-is_multUnordered on: p is_multUnordered
walther@60278
   349
#######  try calc: Poly.is_multUnordered'
neuper@38036
   350
=======  calc. to: False  !!!!!!!!!!!!! INSTEAD OF TRUE in 2002 !!!!!!!!!!!!!
neuper@38036
   351
*)
walther@60242
   352
val t = TermC.str2term "5 * x \<up> 2 * (2 * x \<up> 7) + 5 * x \<up> 2 * 3 + (6 * x \<up> 7 + 9) + (-1 * (3 * x \<up> 5 * (6 * x \<up> 4)) + -1 * (3 * x \<up> 5 * -1) +  (-48 * x \<up> 4 + 8))";
neuper@38036
   353
neuper@38036
   354
"----- is_multUnordered ---";
neuper@38036
   355
val tsort = sort_variables t;
walther@60242
   356
UnparseC.term tsort = "2 * (5 * (x \<up> 2 * x \<up> 7)) + 3 * (5 * x \<up> 2) + 6 * x \<up> 7 + 9 +\n-1 * (3 * (6 * (x \<up> 4 * x \<up> 5))) +\n-1 * (-1 * (3 * x \<up> 5)) +\n-48 * x \<up> 4 +\n8";
neuper@38036
   357
is_polyexp t;
neuper@38036
   358
tsort = t;
neuper@38036
   359
is_polyexp t andalso not (t = sort_variables t);
neuper@38036
   360
if is_multUnordered t then () else error "poly.sml diff. is_multUnordered 1";
neuper@38036
   361
neuper@38036
   362
"----- eval_is_multUnordered ---";
walther@60242
   363
val tm = TermC.str2term "(5 * x \<up> 2 * (2 * x \<up> 7) + 5 * x \<up> 2 * 3 + (6 * x \<up> 7 + 9) + (-1 * (3 * x \<up> 5 * (6 * x \<up> 4)) + -1 * (3 * x \<up> 5 * -1) +  (-48 * x \<up> 4 + 8))) is_multUnordered";
neuper@38036
   364
case eval_is_multUnordered "testid" "" tm thy of
neuper@41924
   365
    SOME (_, Const ("HOL.Trueprop", _) $ 
neuper@41922
   366
                   (Const ("HOL.eq", _) $
walther@60278
   367
                          (Const ("Poly.is_multUnordered", _) $ _) $ 
neuper@41928
   368
                          Const ("HOL.True", _))) => ()
neuper@38036
   369
  | _ => error "poly.sml diff. eval_is_multUnordered";
neuper@38036
   370
neuper@38040
   371
"----- rewrite_set_ STILL DIDN'T WORK";
neuper@38040
   372
val SOME (t, _) = rewrite_set_ thy true order_mult_ t;
walther@59868
   373
UnparseC.term t;
neuper@38036
   374
neuper@38036
   375
"-------- examples from textbook Schalk I ---------------";
neuper@38036
   376
"-------- examples from textbook Schalk I ---------------";
neuper@38036
   377
"-------- examples from textbook Schalk I ---------------";
neuper@38036
   378
"-----SPB Schalk I p.63 No.267b ---";
walther@60242
   379
(*associate poly* )
walther@60242
   380
val t = TermC.str2term "(5*x \<up> 2 + 3) * (2*x \<up> 7 + 3) - (3*x \<up> 5 + 8) * (6*x \<up> 4 - 1)";
walther@59868
   381
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   382
if (UnparseC.term t) = "17 + 15 * x \<up> 2 + -48 * x \<up> 4 + 3 * x \<up> 5 + 6 * x \<up> 7 + -8 * x \<up> 9"
neuper@42395
   383
then () else error "poly.sml: diff.behav. in make_polynomial 1";
neuper@37906
   384
neuper@38036
   385
"-----SPB Schalk I p.63 No.275b ---";
walther@60242
   386
val t = TermC.str2term "(3*x \<up> 2 - 2*x*y + y \<up> 2) * (x \<up> 2 - 2*y \<up> 2)";
neuper@42395
   387
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60242
   388
if (UnparseC.term t) = ("3 * x \<up> 4 + -2 * x \<up> 3 * y + -5 * x \<up> 2 * y \<up> 2 + " ^
walther@60242
   389
  "4 * x * y \<up> 3 +\n-2 * y \<up> 4")
neuper@42395
   390
then () else error "poly.sml: diff.behav. in make_polynomial 2";
neuper@37906
   391
neuper@38036
   392
"-----SPB Schalk I p.63 No.279b ---";
walther@60230
   393
val t = TermC.str2term "(x-a)*(x-b)*(x-c)*(x-d)";
neuper@42395
   394
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@59868
   395
if (UnparseC.term t) = 
walther@60242
   396
  ("a * b * c * d + -1 * a * b * c * x + -1 * a * b * d * x + a * b * x \<up> 2 +\n" ^
walther@60242
   397
  "-1 * a * c * d * x +\na * c * x \<up> 2 +\na * d * x \<up> 2 +\n-1 * a * x \<up> 3 +\n" ^
walther@60242
   398
  "-1 * b * c * d * x +\nb * c * x \<up> 2 +\nb * d * x \<up> 2 +\n-1 * b * x \<up> 3 +\n" ^
walther@60242
   399
  "c * d * x \<up> 2 +\n-1 * c * x \<up> 3 +\n-1 * d * x \<up> 3 +\nx \<up> 4")
neuper@42395
   400
then () else error "poly.sml: diff.behav. in make_polynomial 3";
walther@60242
   401
( *associate poly*)
neuper@37906
   402
neuper@38036
   403
"-----SPB Schalk I p.63 No.291 ---";
walther@60242
   404
val t = TermC.str2term "(5+96*x \<up> 3+8*x*(-4+(7- 3*x)*4*x))*(5*(2- 3*x)- (-15*x*(-8*x- 5)))";
neuper@42395
   405
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60242
   406
if (UnparseC.term t) = "50 + -770 * x + 4520 * x \<up> 2 + -16320 * x \<up> 3 + -26880 * x \<up> 4"
neuper@42395
   407
then () else error "poly.sml: diff.behav. in make_polynomial 4";
neuper@37906
   408
walther@60242
   409
(*associate poly* )
neuper@38036
   410
"-----SPB Schalk I p.64 No.295c ---";
walther@60242
   411
val t = TermC.str2term "(13*a \<up> 4*b \<up> 9*c - 12*a \<up> 3*b \<up> 6*c \<up> 9) \<up> 2";
neuper@42395
   412
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60242
   413
if (UnparseC.term t) = ("169 * a \<up> 8 * b \<up> 18 * c \<up> 2 + -312 * a \<up> 7 * b \<up> 15 * c \<up> 10" ^
walther@60242
   414
  " +\n144 * a \<up> 6 * b \<up> 12 * c \<up> 18")
neuper@42395
   415
then ()else error "poly.sml: diff.behav. in make_polynomial 5";
walther@60242
   416
( *associate poly*)
neuper@37906
   417
neuper@38036
   418
"-----SPB Schalk I p.64 No.299a ---";
walther@60230
   419
val t = TermC.str2term "(x - y)*(x + y)";
neuper@42395
   420
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60242
   421
if (UnparseC.term t) = "x \<up> 2 + -1 * y \<up> 2"
neuper@42395
   422
then () else error "poly.sml: diff.behav. in make_polynomial 6";
neuper@37906
   423
neuper@38036
   424
"-----SPB Schalk I p.64 No.300c ---";
walther@60242
   425
val t = TermC.str2term "(3*x \<up> 2*y - 1)*(3*x \<up> 2*y + 1)";
neuper@42395
   426
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60242
   427
if (UnparseC.term t) = "-1 + 9 * x \<up> 4 * y \<up> 2"
neuper@42395
   428
then () else error "poly.sml: diff.behav. in make_polynomial 7";
neuper@37906
   429
neuper@38036
   430
"-----SPB Schalk I p.64 No.302 ---";
walther@60230
   431
val t = TermC.str2term
walther@60242
   432
  "(13*x \<up> 2 + 5)*(13*x \<up> 2 - 5) - (5*x \<up> 2 + 3)*(5*x \<up> 2 - 3) - (12*x \<up> 2 + 4)*(12*x \<up> 2 - 4)";
neuper@42395
   433
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@59868
   434
if UnparseC.term t = "0"
neuper@42395
   435
then () else error "poly.sml: diff.behav. in make_polynomial 8";
neuper@42395
   436
(* RL?MG?: Bei Berechnung sollte 3 mal real_plus_minus_binom1_p aus expand_poly verwendet werden *)
neuper@37906
   437
neuper@38036
   438
"-----SPB Schalk I p.64 No.306a ---";
walther@60242
   439
val t = TermC.str2term "((x \<up> 2 + 1)*(x \<up> 2 - 1)) \<up> 2";
walther@59868
   440
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   441
if (UnparseC.term t) = "1 + 2 * x \<up> 4 + 2 * -2 * x \<up> 4 + x \<up> 8" then ()
walther@60242
   442
else error "poly.sml: diff.behav. in 2 * x \<up> 4 + 2 * -2 * x \<up> 4 = -2 * x \<up> 4";
neuper@37906
   443
neuper@37906
   444
(*WN071729 when reducing "rls reduce_012_" for Schaerding,
neuper@37906
   445
the above resulted in the term below ... but reduces from then correctly*)
walther@60242
   446
val t = TermC.str2term "1 + 2 * x \<up> 4 + 2 * -2 * x \<up> 4 + x \<up> 8";
walther@59868
   447
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   448
if (UnparseC.term t) = "1 + -2 * x \<up> 4 + x \<up> 8"
neuper@42395
   449
then () else error "poly.sml: diff.behav. in make_polynomial 9b";
neuper@37906
   450
neuper@38036
   451
"-----SPB Schalk I p.64 No.296a ---";
walther@60242
   452
val t = TermC.str2term "(x - a) \<up> 3";
walther@59868
   453
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   454
if (UnparseC.term t) = "-1 * a \<up> 3 + 3 * a \<up> 2 * x + -3 * a * x \<up> 2 + x \<up> 3"
neuper@38031
   455
then () else error "poly.sml: diff.behav. in make_polynomial 10";
neuper@37906
   456
neuper@38036
   457
"-----SPB Schalk I p.64 No.296c ---";
walther@60242
   458
val t = TermC.str2term "(-3*x - 4*y) \<up> 3";
walther@59868
   459
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60248
   460
if (UnparseC.term t) = "-27 * x \<up> 3 + -108 * x \<up> 2 * y + -144 * x * y \<up> 2 +\n-64 * y \<up> 3"
neuper@38031
   461
then () else error "poly.sml: diff.behav. in make_polynomial 11";
neuper@37906
   462
neuper@38036
   463
"-----SPB Schalk I p.62 No.242c ---";
walther@60242
   464
val t = TermC.str2term "x \<up> (-4)*(x \<up> (-4)*y \<up> (-2)) \<up> (-1)*y \<up> (-2)";
walther@59868
   465
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
   466
if (UnparseC.term t) = "1"
neuper@42395
   467
then () else error "poly.sml: diff.behav. in make_polynomial 12";
neuper@37906
   468
neuper@38036
   469
"-----SPB Schalk I p.60 No.209a ---";
walther@60242
   470
val t = TermC.str2term "a \<up> (7-x) * a \<up> x";
walther@59868
   471
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   472
if UnparseC.term t = "a \<up> 7"
neuper@42395
   473
then () else error "poly.sml: diff.behav. in make_polynomial 13";
neuper@37906
   474
neuper@38036
   475
"-----SPB Schalk I p.60 No.209d ---";
walther@60242
   476
val t = TermC.str2term "d \<up> x * d \<up> (x+1) * d \<up> (2 - 2*x)";
walther@59868
   477
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   478
if UnparseC.term t = "d \<up> 3"
neuper@42395
   479
then () else error "poly.sml: diff.behav. in make_polynomial 14";
neuper@37906
   480
neuper@37906
   481
(*---------------------------------------------------------------------*)
neuper@42395
   482
(*---------------- ?RL?Bsple bei denen es Probleme gibt----------------*)
neuper@37906
   483
(*---------------------------------------------------------------------*)
neuper@38036
   484
"-----Schalk I p.64 No.303 ---";
walther@60242
   485
val t = TermC.str2term "(a + 2*b)*(a \<up> 2 + 4*b \<up> 2)*(a - 2*b) - (a - 6*b)*(a \<up> 2 + 36*b \<up> 2)*(a + 6*b)";
walther@59868
   486
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   487
if UnparseC.term t = "1280 * b \<up> 4"
neuper@42395
   488
then () else error "poly.sml: diff.behav. in make_polynomial 14b";
neuper@37906
   489
(* Richtig - aber Binomische Formel wurde nicht verwendet! *)
neuper@37906
   490
neuper@37906
   491
(*--------------------------------------------------------------------*)
neuper@37906
   492
(*----------------------- Eigene Beispiele ---------------------------*)
neuper@37906
   493
(*--------------------------------------------------------------------*)
neuper@38036
   494
"-----SPO ---";
walther@60242
   495
val t = TermC.str2term "a \<up> 2*a \<up> (-2)";
walther@59868
   496
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
   497
if UnparseC.term t = "1" then ()
neuper@38031
   498
else error "poly.sml: diff.behav. in make_polynomial 15";
neuper@38036
   499
"-----SPO ---";
walther@60230
   500
val t = TermC.str2term "a + a + a";
walther@59868
   501
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
   502
if UnparseC.term t = "3 * a" then ()
neuper@38031
   503
else error "poly.sml: diff.behav. in make_polynomial 16";
neuper@38036
   504
"-----SPO ---";
walther@60230
   505
val t = TermC.str2term "a + b + b + b";
walther@59868
   506
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
   507
if UnparseC.term t = "a + 3 * b" then ()
neuper@38031
   508
else error "poly.sml: diff.behav. in make_polynomial 17";
neuper@38036
   509
"-----SPO ---";
walther@60242
   510
val t = TermC.str2term "a \<up> 2*b*b \<up> (-1)";
walther@59868
   511
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   512
if UnparseC.term t = "a \<up> 2" then ()
neuper@38031
   513
else error "poly.sml: diff.behav. in make_polynomial 18";
neuper@38036
   514
"-----SPO ---";
walther@60242
   515
val t = TermC.str2term "a \<up> 2*a \<up> (-2)";
walther@59868
   516
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
   517
if (UnparseC.term t) = "1" then ()
neuper@38031
   518
else error "poly.sml: diff.behav. in make_polynomial 19";
neuper@38036
   519
"-----SPO ---";
walther@60230
   520
val t = TermC.str2term "b + a - b";
walther@59868
   521
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
   522
if (UnparseC.term t) = "a" then ()
neuper@38031
   523
else error "poly.sml: diff.behav. in make_polynomial 20";
neuper@38036
   524
"-----SPO ---";
walther@60230
   525
val t = TermC.str2term "b * a * a";
walther@59868
   526
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   527
if UnparseC.term t = "a \<up> 2 * b" then ()
neuper@38031
   528
else error "poly.sml: diff.behav. in make_polynomial 21";
neuper@38036
   529
"-----SPO ---";
walther@60242
   530
val t = TermC.str2term "(a \<up> 2) \<up> 3";
walther@59868
   531
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   532
if UnparseC.term t = "a \<up> 6" then ()
neuper@38031
   533
else error "poly.sml: diff.behav. in make_polynomial 22";
neuper@38036
   534
"-----SPO ---";
walther@60242
   535
val t = TermC.str2term "x \<up> 2 * y \<up> 2 + x * x \<up> 2 * y";
walther@59868
   536
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   537
if UnparseC.term t = "x \<up> 3 * y + x \<up> 2 * y \<up> 2" then ()
neuper@38031
   538
else error "poly.sml: diff.behav. in make_polynomial 23";
neuper@38036
   539
"-----SPO ---";
walther@60242
   540
val t = (Thm.term_of o the o (TermC.parse thy)) "a \<up> 2 * (-a) \<up> 2";
walther@59868
   541
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   542
if (UnparseC.term t) = "a \<up> 4" then ()
neuper@38031
   543
else error "poly.sml: diff.behav. in make_polynomial 24";
neuper@38036
   544
"-----SPO ---";
walther@60242
   545
val t = TermC.str2term "a * b * b \<up> (-1) + a";
walther@59868
   546
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
   547
if (UnparseC.term t) = "2 * a" then ()
neuper@38031
   548
else error "poly.sml: diff.behav. in make_polynomial 25";
neuper@38036
   549
"-----SPO ---";
walther@60242
   550
val t = TermC.str2term "a*c*b \<up> (2*n) + 3*a + 5*b \<up> (2*n)*c*b";
walther@59868
   551
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
   552
if (UnparseC.term t) = "3 * a + 5 * b \<up> (1 + 2 * n) * c + a * b \<up> (2 * n) * c"
neuper@38031
   553
then () else error "poly.sml: diff.behav. in make_polynomial 26";
neuper@37906
   554
neuper@42395
   555
(*MG030627 -------------vvv-: Verschachtelte Terme -----------*)
neuper@38036
   556
"-----SPO ---";
walther@60242
   557
val t = TermC.str2term "(1 + (x*y*a) + x) \<up> (1 + (x*y*a) + x)";
neuper@42395
   558
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60242
   559
if UnparseC.term t = "(1 + x + a * x * y) \<up> (1 + x + a * x * y)"
neuper@42395
   560
then () else error "poly.sml: diff.behav. in make_polynomial 27";(*SPO*)
neuper@42395
   561
walther@60242
   562
val t = TermC.str2term "(1 + x*(y*z)*zz) \<up> (1 + x*(y*z)*zz)";
neuper@42395
   563
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60242
   564
if UnparseC.term t = "(1 + x * y * z * zz) \<up> (1 + x * y * z * zz)"
neuper@42395
   565
then () else error "poly.sml: diff.behav. in make_polynomial 28";
neuper@37906
   566
neuper@38036
   567
"-------- check pbl  'polynomial simplification' --------";
neuper@38036
   568
"-------- check pbl  'polynomial simplification' --------";
neuper@38036
   569
"-------- check pbl  'polynomial simplification' --------";
walther@60242
   570
val fmz = ["Term ((5*x \<up> 2 + 3) * (2*x \<up> 7 + 3) - (3*x \<up> 5 + 8) * (6*x \<up> 4 - 1))", "normalform N"];
neuper@38036
   571
"-----0 ---";
walther@59997
   572
case Refine.refine fmz ["polynomial", "simplification"]of
walther@59984
   573
    [M_Match.Matches (["polynomial", "simplification"], _)] => ()
walther@59968
   574
  | _ => error "poly.sml diff.behav. in check pbl, Refine.refine";
neuper@37906
   575
(*...if there is an error, then ...*)
neuper@37906
   576
neuper@38036
   577
"-----1 ---";
wneuper@59348
   578
(*default_print_depth 7;*)
walther@59997
   579
val pbt = Problem.from_store ["polynomial", "simplification"];
wneuper@59348
   580
(*default_print_depth 3;*)
neuper@37906
   581
(*if there is ...
walther@59984
   582
> val M_Match.NoMatch' {Given=gi, Where=wh, Find=fi,...} = M_Match.match_pbl fmz pbt;
walther@59901
   583
... then Rewrite.trace_on:*)
walther@60242
   584
                           
neuper@38036
   585
"-----2 ---";
walther@59901
   586
Rewrite.trace_on := false;
walther@59984
   587
M_Match.match_pbl fmz pbt;
walther@59901
   588
Rewrite.trace_on := false;
neuper@37906
   589
(*... if there is no rewrite, then there is something wrong with prls*)
neuper@52101
   590
                              
neuper@38036
   591
"-----3 ---";
wneuper@59348
   592
(*default_print_depth 7;*)
walther@59997
   593
val prls = (#prls o Problem.from_store) ["polynomial", "simplification"];
wneuper@59348
   594
(*default_print_depth 3;*)
walther@60242
   595
val t = TermC.str2term "((5*x \<up> 2 + 3) * (2*x \<up> 7 + 3) - (3*x \<up> 5 + 8) * (6*x \<up> 4 - 1)) is_polyexp";
neuper@37926
   596
val SOME (t',_) = rewrite_set_ thy false prls t;
neuper@48760
   597
if t' = @{term True} then () 
neuper@38031
   598
else error "poly.sml: diff.behav. in check pbl 'polynomial..";
neuper@42395
   599
(*... if this works, but --1-- does still NOT work, check types:*)
neuper@37906
   600
neuper@38036
   601
"-----4 ---";
neuper@42395
   602
(*show_types:=true;*)
neuper@37906
   603
(*
walther@59984
   604
> val M_Match.NoMatch' {Given=gi, Where=wh, Find=fi,...} = M_Match.match_pbl fmz pbt;
neuper@37906
   605
val wh = [False "(t_::real => real) (is_polyexp::real)"]
walther@60242
   606
...................... \<up> \<up> \<up>  \<up> ............... \<up> ^*)
walther@59984
   607
val M_Match.Matches' _ = M_Match.match_pbl fmz pbt;
neuper@42395
   608
(*show_types:=false;*)
neuper@37906
   609
walther@59787
   610
neuper@38036
   611
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
neuper@38036
   612
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
neuper@38036
   613
"-------- me 'poly. simpl.' Schalk I p.63 No.267b -------";
walther@60242
   614
val fmz = ["Term ((5*x \<up> 2 + 3) * (2*x \<up> 7 + 3) - (3*x \<up> 5 + 8) * (6*x \<up> 4 - 1))", "normalform N"];
neuper@37906
   615
val (dI',pI',mI') =
walther@59997
   616
  ("Poly",["polynomial", "simplification"],
walther@59997
   617
   ["simplification", "for_polynomials"]);
neuper@37906
   618
val p = e_pos'; val c = []; 
neuper@37906
   619
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
walther@60242
   620
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Add_Given "Term\n ((5 * x \<up> 2 + 3) * (2 * x \<up> 7 + 3) -\n  (3 * x \<up> 5 + 8) * (6 * x \<up> 4 - 1))"*)
walther@59787
   621
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Add_Find "normalform N"*)
walther@59787
   622
walther@59997
   623
(*+* )if I_Model.to_string ctxt (get_obj g_pbl pt (fst p)) =
walther@60242
   624
(*+*)  "[\n(0 ,[] ,false ,#Find ,Inc ??.Simplify.normalform ,(??.empty, [])), \n(1 ,[1] ,true ,#Given ,Cor ??.Simplify.Term\n ((5 * x \<up> 2 + 3) * (2 * x \<up> 7 + 3) -\n  (3 * x \<up> 5 + 8) * (6 * x \<up> 4 - 1)) ,(t_t, [(5 * x \<up> 2 + 3) * (2 * x \<up> 7 + 3) -\n(3 * x \<up> 5 + 8) * (6 * x \<up> 4 - 1)]))]"
walther@59943
   625
(*+*)then () else error "No.267b: I_Model.T CHANGED";
walther@59997
   626
( *+ ...could not be repaired in child of 7e314dd233fd ?!?*)
walther@59787
   627
walther@59787
   628
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*nxt = Specify_Theory "Poly"*)
walther@59787
   629
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Specify_Problem ["polynomial", "simplification"]*)
walther@59787
   630
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Specify_Method ["simplification", "for_polynomials"]*)
walther@59787
   631
(*[], Met*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Apply_Method ["simplification", "for_polynomials"]*)
walther@59787
   632
(*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Rewrite_Set "norm_Poly"*)
walther@59787
   633
walther@60242
   634
(*+*)if f2str f = "(5 * x \<up> 2 + 3) * (2 * x \<up> 7 + 3) -\n(3 * x \<up> 5 + 8) * (6 * x \<up> 4 - 1)"
walther@59787
   635
(*+*)then () else error "";
walther@59787
   636
walther@59787
   637
(*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Empty_Tac: ERROR DETECTED Feb.2020*)
walther@59787
   638
walther@60248
   639
(*+*)if f2str f = "17 + 15 * x \<up> 2 + -48 * x \<up> 4 + 3 * x \<up> 5 + 6 * x \<up> 7 +\n-8 * x \<up> 9"
walther@60248
   640
(*+*)then () else error "poly.sml diff.behav. in me Schalk I p.63 No.267b -1";
walther@59787
   641
walther@59790
   642
(*[1], Res* )val (p,_,f,nxt,_,pt) = me nxt p c pt;( *SINCE Feb.2020 LItool.find_next_step without result*)
walther@59787
   643
walther@59787
   644
neuper@37906
   645
neuper@38036
   646
"-------- interSteps for Schalk 299a --------------------";
neuper@38036
   647
"-------- interSteps for Schalk 299a --------------------";
neuper@38036
   648
"-------- interSteps for Schalk 299a --------------------";
s1210629013@55445
   649
reset_states ();
neuper@37906
   650
CalcTree
neuper@42395
   651
[(["Term ((x - y)*(x + (y::real)))", "normalform N"], 
walther@59997
   652
  ("Poly",["polynomial", "simplification"],
walther@59997
   653
  ["simplification", "for_polynomials"]))];
neuper@37906
   654
Iterator 1;
neuper@37906
   655
moveActiveRoot 1;
wneuper@59248
   656
autoCalculate 1 CompleteCalc;
walther@59983
   657
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@37906
   658
walther@59833
   659
interSteps 1 ([1],Res)(*<ERROR> syserror in Detail_Step.go </ERROR>*);
walther@59983
   660
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@37906
   661
if existpt' ([1,1], Frm) pt then ()
neuper@38031
   662
else error "poly.sml: interSteps doesnt work again 1";
neuper@37906
   663
walther@59833
   664
interSteps 1 ([1,1],Res)(*<ERROR> syserror in Detail_Step.go </ERROR>*);
walther@59983
   665
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@42395
   666
(*============ inhibit exn WN120316 ==============================================
neuper@37906
   667
if existpt' ([1,1,1], Frm) pt then ()
neuper@38031
   668
else error "poly.sml: interSteps doesnt work again 2";
neuper@42395
   669
============ inhibit exn WN120316 ==============================================*)
neuper@37906
   670
neuper@38036
   671
"-------- norm_Poly NOT COMPLETE ------------------------";
neuper@38036
   672
"-------- norm_Poly NOT COMPLETE ------------------------";
neuper@38036
   673
"-------- norm_Poly NOT COMPLETE ------------------------";
walther@60267
   674
val thy = @{theory AlgEin};
wneuper@59529
   675
wneuper@59529
   676
val SOME (f',_) = rewrite_set_ thy false norm_Poly
walther@60230
   677
(TermC.str2term "L = k - 2 * q + (k - 2 * q) + (k - 2 * q) + (k - 2 * q) + senkrecht + oben");
walther@60267
   678
if UnparseC.term f' = "L = senkrecht + oben + 2 * 2 * k + 2 * -4 * q"
neuper@42395
   679
then ((*norm_Poly NOT COMPLETE -- TODO MG*))
neuper@42395
   680
else error "norm_Poly changed behavior";
neuper@38036
   681
neuper@38036
   682
"-------- ord_make_polynomial ---------------------------";
neuper@38036
   683
"-------- ord_make_polynomial ---------------------------";
neuper@38036
   684
"-------- ord_make_polynomial ---------------------------";
walther@60230
   685
val t1 = TermC.str2term "2 * b + (3 * a + 3 * b)";
walther@60230
   686
val t2 = TermC.str2term "3 * a + 3 * b + 2 * b";
neuper@37906
   687
neuper@42395
   688
if ord_make_polynomial true thy [] (t1, t2) then ()
neuper@38031
   689
else error "poly.sml: diff.behav. in ord_make_polynomial";
neuper@37906
   690
walther@60242
   691
(*WN071202: \<up> why then is there no rewriting ...*)
walther@60230
   692
val term = TermC.str2term "2*b + (3*a + 3*b)";
wneuper@59592
   693
val NONE = rewrite_set_ (@{theory "Isac_Knowledge"}) false order_add_mult term;
neuper@37906
   694
neuper@37906
   695
(*or why is there no rewriting this way...*)
walther@60230
   696
val t1 = TermC.str2term "2 * b + (3 * a + 3 * b)";
walther@60230
   697
val t2 = TermC.str2term "3 * a + (2 * b + 3 * b)";
neuper@37906
   698