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