test/Tools/isac/Knowledge/poly-1.sml
author wneuper <Walther.Neuper@jku.at>
Thu, 04 Aug 2022 12:48:37 +0200
changeset 60509 2e0b7ca391dc
parent 60500 59a3af532717
child 60565 f92963a33fe3
permissions -rw-r--r--
polish naming in Rewrite_Order
walther@60328
     1
(* Title: test/Tools/isac/Knowledge/poly-1.sml
walther@60328
     2
   Author: Walther Neuper
walther@60328
     3
   Use is subject to license terms.
walther@60328
     4
walther@60328
     5
Test of basic functions and application to complex examples.
walther@60328
     6
*)
walther@60328
     7
walther@60328
     8
"-----------------------------------------------------------------------------------------------";
walther@60328
     9
"-----------------------------------------------------------------------------------------------";
walther@60328
    10
"table of contents -----------------------------------------------------------------------------";
walther@60328
    11
"-----------------------------------------------------------------------------------------------";
walther@60328
    12
"-------- fun is_polyexp -----------------------------------------------------------------------";
walther@60328
    13
"-------- fun has_degree_in --------------------------------------------------------------------";
walther@60328
    14
"-------- fun mono_deg_in ----------------------------------------------------------------------";
walther@60328
    15
"-------- fun sort_variables -------------------------------------------------------------------";
walther@60328
    16
"-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
walther@60328
    17
"-------- check make_polynomial with simple terms ----------------------------------------------";
walther@60328
    18
"-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
walther@60328
    19
"-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
walther@60328
    20
"-------- fun is_multUnordered (x - a) \<up> 3 -----------------------------------------------------";
walther@60328
    21
"-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
walther@60328
    22
"-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
walther@60328
    23
"-------- norm_Poly with AlgEin ----------------------------------------------------------------";
walther@60328
    24
"-------- complex examples from textbook Schalk I ----------------------------------------------";
walther@60328
    25
"-------- complex Eigene Beispiele (Mathias Goldgruber) ----------------------------------------";
walther@60328
    26
"-----------------------------------------------------------------------------------------------";
walther@60328
    27
"-----------------------------------------------------------------------------------------------";
walther@60328
    28
walther@60328
    29
walther@60328
    30
"-------- fun is_polyexp -----------------------------------------------------------------------";
walther@60328
    31
"-------- fun is_polyexp -----------------------------------------------------------------------";
walther@60328
    32
"-------- fun is_polyexp -----------------------------------------------------------------------";
walther@60328
    33
val t = TermC.str2term "x / x";
walther@60328
    34
if is_polyexp t then error "NOT is_polyexp (x / x)" else ();
walther@60328
    35
walther@60329
    36
val t = TermC.str2term "- 1 * A * 3";
walther@60329
    37
if is_polyexp t then () else error "is_polyexp (- 1 * A * 3)";
walther@60328
    38
walther@60329
    39
val t = TermC.str2term "- 1 * AA * 3";
walther@60329
    40
if is_polyexp t then () else error "is_polyexp (- 1 * AA * 3)";
walther@60328
    41
walther@60328
    42
val t = TermC.str2term "x * x + x * y + (- 1 * y * x + - 1 * y * y)::real";
walther@60328
    43
if is_polyexp t then () else error "is_polyexp (x * x + x * y + (- 1 * y * x + - 1 * y * y))";
walther@60328
    44
walther@60328
    45
"-------- fun has_degree_in --------------------------------------------------------------------";
walther@60328
    46
"-------- fun has_degree_in --------------------------------------------------------------------";
walther@60328
    47
"-------- fun has_degree_in --------------------------------------------------------------------";
Walther@60424
    48
val thy = @{theory}
Walther@60424
    49
val ctxt = Proof_Context.init_global thy
Walther@60424
    50
val v = TermC.parseNEW' ctxt "x";
Walther@60424
    51
val t = TermC.parseNEW' ctxt "1";
walther@60328
    52
if has_degree_in t v = 0 then () else error "has_degree_in (1) x";
walther@60328
    53
Walther@60424
    54
val v = TermC.parseNEW' ctxt "AA";
Walther@60424
    55
val t = TermC.parseNEW' ctxt "1";
walther@60328
    56
if has_degree_in t v = 0 then () else error "has_degree_in (1) AA";
walther@60328
    57
walther@60328
    58
(*----------*)
Walther@60424
    59
val v = TermC.parseNEW' ctxt "x";
Walther@60424
    60
val t = TermC.parseNEW' ctxt "a*b+c";
walther@60328
    61
if has_degree_in t v = 0 then () else error "has_degree_in (a*b+c) x";
walther@60328
    62
Walther@60424
    63
val v = TermC.parseNEW' ctxt "AA";
Walther@60424
    64
val t = TermC.parseNEW' ctxt "a*b+c";
walther@60328
    65
if has_degree_in t v = 0 then () else error "has_degree_in (a*b+c) AA";
walther@60328
    66
walther@60328
    67
(*----------*)
Walther@60424
    68
val v = TermC.parseNEW' ctxt "x";
Walther@60424
    69
val t = TermC.parseNEW' ctxt "a*x+c";
walther@60328
    70
if has_degree_in t v = ~1 then () else error "has_degree_in (a*x+c) x";
walther@60328
    71
Walther@60424
    72
val v = TermC.parseNEW' ctxt "AA";
Walther@60424
    73
val t = TermC.parseNEW' ctxt "a*AA+c";
walther@60328
    74
if has_degree_in t v = ~1 then () else error "has_degree_in (a*AA+c) AA";
walther@60328
    75
walther@60328
    76
(*----------*)
Walther@60424
    77
val v = TermC.parseNEW' ctxt "x::real";
Walther@60424
    78
val t = TermC.parseNEW' ctxt "((a::real)*b+c)*x \<up> 7";
walther@60328
    79
if has_degree_in t v = 7 then () else error "has_degree_in ((a*b+c)*x \<up> 7) x";
walther@60328
    80
Walther@60424
    81
val v = TermC.parseNEW' ctxt "AA";
Walther@60424
    82
val t = TermC.parseNEW' ctxt "(a*b+c)*AA \<up> 7";
walther@60328
    83
if has_degree_in t v = 7 then () else error "has_degree_in ((a*b+c)*AA \<up> 7) AA";
walther@60328
    84
walther@60328
    85
(*----------*)
Walther@60424
    86
val v = TermC.parseNEW' ctxt "x::real";
Walther@60424
    87
val t = TermC.parseNEW' ctxt "x \<up> 7";
walther@60328
    88
if has_degree_in t v = 7 then () else error "has_degree_in (x \<up> 7) x";
walther@60328
    89
Walther@60424
    90
val v = TermC.parseNEW' ctxt "AA";
Walther@60424
    91
val t = TermC.parseNEW' ctxt "AA \<up> 7";
walther@60328
    92
if has_degree_in t v = 7 then () else error "has_degree_in (AA \<up> 7) AA";
walther@60328
    93
walther@60328
    94
(*----------*)
Walther@60424
    95
val v = TermC.parseNEW' ctxt "x::real";
Walther@60424
    96
val t = TermC.parseNEW' ctxt "(a*b+c)*x::real";
walther@60328
    97
if has_degree_in t v = 1 then () else error "has_degree_in ((a*b+c)*x) x";
walther@60328
    98
Walther@60424
    99
val v = TermC.parseNEW' ctxt "AA";
Walther@60424
   100
val t = TermC.parseNEW' ctxt "(a*b+c)*AA";
walther@60328
   101
if has_degree_in t v = 1 then () else error "has_degree_in ((a*b+c)*AA) AA";
walther@60328
   102
walther@60328
   103
(*----------*)
Walther@60424
   104
val v = TermC.parseNEW' ctxt "x::real";
Walther@60424
   105
val t = TermC.parseNEW' ctxt "(a*b+x)*x";
walther@60328
   106
if has_degree_in t v = ~1 then () else error "has_degree_in (a*b+x)*x() x";
walther@60328
   107
Walther@60424
   108
val v = TermC.parseNEW' ctxt "AA";
Walther@60424
   109
val t = TermC.parseNEW' ctxt "(a*b+AA)*AA";
walther@60328
   110
if has_degree_in t v = ~1 then () else error "has_degree_in ((a*b+AA)*AA) AA";
walther@60328
   111
walther@60328
   112
(*----------*)
Walther@60424
   113
val v = TermC.parseNEW' ctxt "x";
Walther@60424
   114
val t = TermC.parseNEW' ctxt "x";
walther@60328
   115
if has_degree_in t v = 1 then () else error "has_degree_in (x) x";
walther@60328
   116
Walther@60424
   117
val v = TermC.parseNEW' ctxt "AA";
Walther@60424
   118
val t = TermC.parseNEW' ctxt "AA";
walther@60328
   119
if has_degree_in t v = 1 then () else error "has_degree_in (AA) AA";
walther@60328
   120
walther@60328
   121
(*----------*)
Walther@60424
   122
val v = TermC.parseNEW' ctxt "x::real";
Walther@60424
   123
val t = TermC.parseNEW' ctxt "ab - (a*b)*(x::real)";
walther@60328
   124
if has_degree_in t v = 1 then () else error "has_degree_in (ab - (a*b)*x) x";
walther@60328
   125
Walther@60424
   126
val v = TermC.parseNEW' ctxt "AA";
Walther@60424
   127
val t = TermC.parseNEW' ctxt "ab - (a*b)*AA";
walther@60328
   128
if has_degree_in t v = 1 then () else error "has_degree_in (ab - (a*b)*AA) AA";
walther@60328
   129
walther@60328
   130
"-------- fun mono_deg_in ----------------------------------------------------------------------";
walther@60328
   131
"-------- fun mono_deg_in ----------------------------------------------------------------------";
walther@60328
   132
"-------- fun mono_deg_in ----------------------------------------------------------------------";
Walther@60424
   133
val v = TermC.parseNEW' ctxt "x::real";
walther@60328
   134
Walther@60424
   135
val t = TermC.parseNEW' ctxt "(a*b+c)*x \<up> 7";
walther@60328
   136
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in ((a*b+c)*x \<up> 7) x changed";
walther@60328
   137
Walther@60424
   138
val t = TermC.parseNEW' ctxt "(x::real) \<up> 7";
walther@60328
   139
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in (x \<up> 7) x changed";
walther@60328
   140
Walther@60424
   141
val t = TermC.parseNEW' ctxt "(a*b+c)*x::real";
walther@60328
   142
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in ((a*b+c)*x) x changed";
walther@60328
   143
Walther@60424
   144
val t = TermC.parseNEW' ctxt "(a*b+x)*x";
walther@60328
   145
if mono_deg_in t v = NONE then () else error "mono_deg_in ((a*b+x)*x) x changed";
walther@60328
   146
Walther@60424
   147
val t = TermC.parseNEW' ctxt "x::real";
walther@60328
   148
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in (x) x changed";
walther@60328
   149
Walther@60424
   150
val t = TermC.parseNEW' ctxt "(a*b+c)";
walther@60328
   151
if mono_deg_in t v = SOME 0 then () else error "mono_deg_in ((a*b+c)) x changed";
walther@60328
   152
Walther@60424
   153
val t = TermC.parseNEW' ctxt "ab - (a*b)*x";
walther@60328
   154
if mono_deg_in t v = NONE then () else error "mono_deg_in (ab - (a*b)*x) x changed";
walther@60328
   155
walther@60336
   156
(*. . . . . . . . . . . . the same with Const (\<^const_name>\<open>AA\<close>, _) . . . . . . . . . . . *)
walther@60328
   157
val thy = @{theory Partial_Fractions}
Walther@60424
   158
val ctxt = Proof_Context.init_global thy
Walther@60424
   159
val v = TermC.parseNEW' ctxt "AA";
walther@60328
   160
Walther@60424
   161
val t = TermC.parseNEW' ctxt "(a*b+c)*AA \<up> 7";
walther@60328
   162
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in ((a*b+c)*AA \<up> 7) AA changed";
walther@60328
   163
Walther@60424
   164
val t = TermC.parseNEW' ctxt "AA \<up> 7";
walther@60328
   165
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in (AA \<up> 7) AA changed";
walther@60328
   166
Walther@60424
   167
val t = TermC.parseNEW' ctxt "(a*b+c)*AA";
walther@60328
   168
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in ((a*b+c)*AA) AA changed";
walther@60328
   169
Walther@60424
   170
val t = TermC.parseNEW' ctxt "(a*b+AA)*AA";
walther@60328
   171
if mono_deg_in t v = NONE then () else error "mono_deg_in ((a*b+AA)*AA) AA changed";
walther@60328
   172
Walther@60424
   173
val t = TermC.parseNEW' ctxt "AA";
walther@60328
   174
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in (AA) AA changed";
walther@60328
   175
Walther@60424
   176
val t = TermC.parseNEW' ctxt "(a*b+c)";
walther@60328
   177
if mono_deg_in t v = SOME 0 then () else error "mono_deg_in ((a*b+c)) AA changed";
walther@60328
   178
Walther@60424
   179
val t = TermC.parseNEW' ctxt "ab - (a*b)*AA";
walther@60328
   180
if mono_deg_in t v = NONE then () else error "mono_deg_in (ab - (a*b)*AA) AA changed";
walther@60328
   181
walther@60328
   182
walther@60328
   183
"-------- fun sort_variables -------------------------------------------------------------------";
walther@60328
   184
"-------- fun sort_variables -------------------------------------------------------------------";
walther@60328
   185
"-------- fun sort_variables -------------------------------------------------------------------";
walther@60328
   186
if "---" < "123" andalso "123" < "a" andalso "a" < "cba" then ()
walther@60328
   187
else error "lexicographic order CHANGED";
walther@60328
   188
walther@60328
   189
(*--------------vvvvvvvvvvvvvvv-----------------------------------------------------------------*)
walther@60328
   190
val t =  @{term "3 * b + a * 2"}; (*------------------------------------------------------------*)
walther@60328
   191
val t' =  sort_variables t;
walther@60328
   192
if UnparseC.term t' = "(3::'a) * b + (2::'a) * a" then ()
walther@60328
   193
else error "sort_variables  3 * b + a * 2  CHANGED";
walther@60328
   194
walther@60328
   195
"~~~~~~~ fun sort_variables , args:"; val (t) = (t);
walther@60328
   196
  	val ll =  map monom2list (poly2list t);
walther@60328
   197
walther@60328
   198
(*+*)UnparseC.terms (poly2list t) = "[\"(3::'a) * b\", \"a * (2::'a)\"]";
walther@60336
   199
(*+*)val [ [(Const (\<^const_name>\<open>numeral\<close>, _) $ _), Free ("b", _)],
walther@60336
   200
(*+*)      [Free ("a", _), (Const (\<^const_name>\<open>numeral\<close>, _) $ _)]
walther@60328
   201
(*+*)    ] = map monom2list (poly2list t);
walther@60328
   202
walther@60328
   203
  	val lls = map sort_varList ll;
walther@60328
   204
walther@60328
   205
(*+*)case map sort_varList ll of
walther@60336
   206
(*+*)  [ [Const (\<^const_name>\<open>numeral\<close>, _) $ _, Free ("b", _)],
walther@60336
   207
(*+*)    [Const (\<^const_name>\<open>numeral\<close>, _) $ _, Free ("a", _)]
walther@60328
   208
(*+*)  ] => ()
walther@60328
   209
(*+*)| _ => error "map sort_varList CHANGED";
walther@60328
   210
walther@60328
   211
  	val T = type_of t;
walther@60328
   212
  	val ls = map (create_monom T) lls;
walther@60328
   213
walther@60336
   214
(*+*)val [Const (\<^const_name>\<open>times\<close>, _) $ _ $ Free ("b", _),
walther@60336
   215
(*+*)     Const (\<^const_name>\<open>times\<close>, _) $ _ $ Free ("a", _)] = map (create_monom T) lls;
walther@60328
   216
walther@60328
   217
(*+*)case map (create_monom T) lls of
walther@60336
   218
(*+*)  [Const (\<^const_name>\<open>times\<close>, _) $ (Const (\<^const_name>\<open>numeral\<close>, _) $ _) $ Free ("b", _),
walther@60336
   219
(*+*)   Const (\<^const_name>\<open>times\<close>, _) $ (Const (\<^const_name>\<open>numeral\<close>, _) $ _) $ Free ("a", _)
walther@60328
   220
(*+*)  ] => ()
walther@60328
   221
(*+*)| _ => error "map (create_monom T) CHANGED";
walther@60328
   222
walther@60328
   223
  val xxx = (*in*) create_polynom T ls (*end*);
walther@60328
   224
walther@60328
   225
(*+*)if UnparseC.term xxx = "(3::'a) * b + (2::'a) * a" then ()
walther@60328
   226
(*+*)else error "create_polynom CHANGED";
walther@60328
   227
(* done by rewriting>              2 * a +       3 * b ? *)
walther@60328
   228
walther@60328
   229
(*---------------vvvvvvvvvvvvvvvvvvvvvv---------------------------------------------------------*)
walther@60328
   230
val t =  @{term "3 * a + - 2 * a ::real"}; (*---------------------------------------------------*)
walther@60328
   231
val t' =     sort_variables t;
walther@60328
   232
if UnparseC.term t' = "3 * a + - 2 * a" then ()
walther@60328
   233
else error "sort_variables  3 * a + - 2 * a  CHANGED";
walther@60328
   234
walther@60328
   235
"~~~~~~~ fun sort_variables , args:"; val (t) = (t);
walther@60328
   236
  	val ll =  map monom2list (poly2list t);
walther@60328
   237
walther@60336
   238
(*+*)val [ [Const (\<^const_name>\<open>numeral\<close>, _) $ _, Free ("a", _)],
walther@60336
   239
(*+*)      [Const (\<^const_name>\<open>uminus\<close>, _) $ _, Free ("a", _)] (*already correct order*)
walther@60328
   240
(*+*)    ] = map monom2list (poly2list t);
walther@60328
   241
walther@60328
   242
  	val lls = map
walther@60328
   243
           sort_varList ll;
walther@60328
   244
walther@60336
   245
(*+*)val [ [Const (\<^const_name>\<open>numeral\<close>, _) $ _, Free ("a", _)],
walther@60336
   246
(*+*)      [Const (\<^const_name>\<open>uminus\<close>, _) $ _, Free ("a", _)] (*ERROR: NO swap here*)
walther@60328
   247
(*+*)    ] = map sort_varList ll;
walther@60328
   248
walther@60328
   249
       map sort_varList ll;
walther@60328
   250
"~~~~~ val sort_varList , args:"; val (ts) = (nth 2 ll);
walther@60328
   251
val sorted = sort var_ord ts;
walther@60328
   252
walther@60328
   253
(*+*)if UnparseC.terms ts = "[\"- 2\", \"a\"]" andalso UnparseC.terms sorted = "[\"- 2\", \"a\"]"
walther@60328
   254
(*+*)then () else error "sort var_ord  [\"- 2\", \"a\"]  CHANGED";
walther@60328
   255
walther@60328
   256
walther@60328
   257
(*+*)if UnparseC.term (nth 1 ts) = "- 2" andalso get_basStr (nth 1 ts) = "-2"
walther@60328
   258
(*+*)then () else error "get_basStr  - 2  CHANGED";
walther@60328
   259
(*+*)if UnparseC.term (nth 2 ts) = "a" andalso get_basStr (nth 2 ts) = "a"
walther@60328
   260
(*+*)then () else error "get_basStr  a  CHANGED";
walther@60328
   261
walther@60328
   262
walther@60328
   263
"-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
walther@60328
   264
"-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
walther@60328
   265
"-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
Walther@60500
   266
val ctxt = Proof_Context.init_global @{theory}
walther@60328
   267
val t = TermC.str2term "x \<up> 2 * y \<up> 2 + x * x \<up> 2 * y";
Walther@60500
   268
val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60328
   269
   UnparseC.term t = "x \<up> 2 * y \<up> 2 + x \<up> 3 * y";
walther@60328
   270
if UnparseC.term t = "x \<up> 3 * y + x \<up> 2 * y \<up> 2" then ()
walther@60328
   271
else error "poly.sml: diff.behav. in make_polynomial 23";
walther@60328
   272
walther@60328
   273
(** )
walther@60328
   274
##  rls: order_add_rls_ on: x \<up> 2 * y \<up> 2 + x \<up> 3 * y 
walther@60328
   275
###  rls: order_add_ on: x \<up> 2 * y \<up> 2 + x \<up> 3 * y 
walther@60328
   276
######  rls: Rule_Set.empty-is_addUnordered on: x \<up> 2 * y \<up> 2 + x \<up> 3 * y is_addUnordered 
walther@60328
   277
#######  try calc: "Poly.is_addUnordered" 
walther@60328
   278
########  eval asms: "x \<up> 2 * y \<up> 2 + x \<up> 3 * y is_addUnordered = False"  (*isa*)
walther@60328
   279
                                                                              True"   (*isa2*)
walther@60328
   280
#######  calc. to: False  (*isa*)
walther@60328
   281
                   True   (*isa2*)
walther@60328
   282
( **)
walther@60328
   283
        if is_addUnordered (TermC.str2term "x \<up> 2 * y \<up> 2 + x \<up> 3 * y ::real") then ()
walther@60328
   284
else error"is_addUnordered  x \<up> 2 * y \<up> 2 + x \<up> 3 * y"; (*isa == isa2*)
walther@60328
   285
"~~~~~ fun is_addUnordered , args:"; val (t) = (TermC.str2term "x \<up> 2 * y \<up> 2 + x \<up> 3 * y ::real");
walther@60328
   286
      ((is_polyexp t) andalso not (t = sort_monoms t)) = false;  (*isa == isa2*)
walther@60328
   287
walther@60328
   288
(*+*) if is_polyexp t = true then () else error "is_polyexp  x \<up> 2 * y \<up> 2 + x \<up> 3 * y";
walther@60328
   289
walther@60328
   290
(*+*) if                           t = sort_monoms t = false then () else error "sort_monoms 123";
walther@60328
   291
"~~~~~~~ fun sort_monoms , args:"; val (t) = (t);
walther@60328
   292
  	val ll =  map monom2list (poly2list t);
walther@60328
   293
  	val lls = sort_monList ll;
walther@60328
   294
walther@60328
   295
(*+*)map UnparseC.terms lls = ["[\"x \<up> 2\", \"y \<up> 2\"]", "[\"x \<up> 3\", \"y\"]"]; (*isa*)
walther@60328
   296
(*+*)map UnparseC.terms lls = ["[\"x \<up> 3\", \"y\"]", "[\"x \<up> 2\", \"y \<up> 2\"]"]; (*isa2*)
walther@60328
   297
walther@60328
   298
"~~~~~~~~~~~ fun koeff_degree_ord , args:"; val () = ();
walther@60328
   299
(* we check all elements at once..*)
walther@60328
   300
val eee1 = ll |> nth 1; UnparseC.terms eee1 = "[\"x \<up> 2\", \"y \<up> 2\"]";
walther@60328
   301
val eee2 = ll |> nth 2; UnparseC.terms eee2 = "[\"x \<up> 3\", \"y\"]";    
walther@60328
   302
walther@60328
   303
(*1*)if koeff_degree_ord (eee1, eee1) = EQUAL   then () else error "(eee1, eee1) CHANGED";
walther@60328
   304
(*2*)if koeff_degree_ord (eee1, eee2) = GREATER then () else error "(eee1, eee2) CHANGED";
walther@60328
   305
(*3*)if koeff_degree_ord (eee2, eee1) = LESS    then () else error "(eee2, eee1) CHANGED"; (*isa*)
walther@60328
   306
(*4*)if koeff_degree_ord (eee2, eee2) = EQUAL   then () else error "(eee2, eee2) CHANGED";
walther@60328
   307
(* isa -- isa2:
walther@60328
   308
(*1*){a = "var_ord_revPow ", at_bt = "(x \<up> 2, x \<up> 2)", sort_args = "(x, 2), (x, 2)"}                                           (*isa == isa2*)
walther@60328
   309
(*1*){a = "var_ord_revPow ", at_bt = "(y \<up> 2, y \<up> 2)", sort_args = "(y, 2), (y, 2)"}                                            (*isa == isa2*)
walther@60328
   310
(*1*){a = "compare_koeff_ord ", ats_bts = "([\"x \<up> 2\", \"y \<up> 2\"], [\"x \<up> 2\", \"y \<up> 2\"])", sort_args = "(---, ---)"} (*isa == isa2*) 
walther@60328
   311
walther@60328
   312
(*2*){a = "var_ord_revPow ", at_bt = "(x \<up> 2, x \<up> 3)", sort_args = "(x, 2), (x, 3)"}                                           (*isa == isa2*) 
walther@60328
   313
walther@60328
   314
(*3*)k{a = "var_ord_revPow ", at_bt = "(x \<up> 3, x \<up> 2)", sort_args = "(x, 3), (x, 2)"}                                           (*isa == isa2*) 
walther@60328
   315
walther@60328
   316
(*4*){a = "var_ord_revPow ", at_bt = "(x \<up> 3, x \<up> 3)", sort_args = "(x, 3), (x, 3)"}                                           (*isa == isa2*)
walther@60328
   317
(*4*){a = "var_ord_revPow ", at_bt = "(y, y)", sort_args = "(y, ---), (y, ---)"}                                                       (*isa == isa2*)
walther@60328
   318
(*4*){a = "compare_koeff_ord ", ats_bts = "([\"x \<up> 3\", \"y\"], [\"x \<up> 3\", \"y\"])", sort_args = "(---, ---)"}                (*isa == isa2*) 
walther@60328
   319
val it = true: bool
walther@60328
   320
val it = true: bool
walther@60328
   321
val it = true: bool
walther@60328
   322
val it = true: bool*)
walther@60328
   323
walther@60328
   324
"~~~~~~~~~~~~~ fun degree_ord , args:"; val () = ();
walther@60328
   325
(*1*)if degree_ord (eee1, eee1) = EQUAL   then () else error "degree_ord (eee1, eee1) CHANGED";
walther@60328
   326
(*2*)if degree_ord (eee1, eee2) = GREATER    then () else error "degree_ord (eee1, eee2) CHANGED";(*isa*)
walther@60328
   327
(*{a = "int_ord (4, 10003) = ", z = LESS}      isa
walther@60328
   328
  {a = "int_ord (4, 4) = ", z = EQUAL}         isa2*)
walther@60328
   329
(*3*)if degree_ord (eee2, eee1) = LESS then () else error "degree_ord (eee2, eee1) CHANGED";(*isa*)
walther@60328
   330
(*4*)if degree_ord (eee2, eee2) = EQUAL   then () else error "degree_ord (eee2, eee2) CHANGED";
walther@60328
   331
(* isa -- isa2:
walther@60328
   332
(*1*){a = "int_ord (10002, 10002) = ", z = EQUAL}                                                          (*isa*)
walther@60328
   333
     {a = "int_ord (4, 4) = ", z = EQUAL}                                                                    (*isa2*)
walther@60328
   334
(*1*){a = "dict_cond_ord", args = "([\"x \<up> 2\", \"y \<up> 2\"], [\"x \<up> 2\", \"y \<up> 2\"])", is_nums = "(false, false)"}  (*isa*)
walther@60328
   335
(*1*){a = "var_ord_revPow ", at_bt = "(x \<up> 2, x \<up> 2)", sort_args = "(x, 2), (x, 2)"}               (*isa*)
walther@60328
   336
(*1*){a = "dict_cond_ord", args = "([\"y \<up> 2\"], [\"y \<up> 2\"])", is_nums = "(false, false)"}        (*isa*)
walther@60328
   337
(*1*){a = "var_ord_revPow ", at_bt = "(y \<up> 2, y \<up> 2)", sort_args = "(y, 2), (y, 2)"}               (*isa*)
walther@60328
   338
(*1*){a = "dict_cond_ord ([], [])"}                                                                        (*isa*)
walther@60328
   339
walther@60328
   340
(*2*){a = "int_ord (10002, 10003) = ", z = LESS}                                                           (*isa*)
walther@60328
   341
     {a = "int_ord (4, 4) = ", z = EQUAL}                                                                    (*isa2*)
walther@60328
   342
     {a = "dict_cond_ord", args = "([\"x \<up> 2\", \"y \<up> 2\"], [\"x \<up> 3\", \"y\"])", is_nums = "(false, false)"} (*isa2*)
walther@60328
   343
(*2*){a = "var_ord_revPow ", at_bt = "(x \<up> 2, x \<up> 3)", sort_args = "(x, 2), (x, 3)"}                 (*isa2*)
walther@60328
   344
walther@60328
   345
(*3*){a = "int_ord (10003, 10002) = ", z = GREATER}                                                       (*isa*)
walther@60328
   346
     {a = "int_ord (4, 4) = ", z = EQUAL}                                                                    (*isa2*)
walther@60328
   347
     {a = "dict_cond_ord", args = "([\"x \<up> 3\", \"y\"], [\"x \<up> 2\", \"y \<up> 2\"])", is_nums = "(false, false)"}
walther@60328
   348
(*3*){a = "var_ord_revPow ", at_bt = "(x \<up> 3, x \<up> 2)", sort_args = "(x, 3), (x, 2)"}                (*isa == isa2*)
walther@60328
   349
walther@60328
   350
(*4*){a = "int_ord (10003, 10003) = ", z = EQUAL}                                                         (*isa*)
walther@60328
   351
     {a = "int_ord (4, 4) = ", z = EQUAL}                                                                    (*isa2*)
walther@60328
   352
(*4*){a = "dict_cond_ord", args = "([\"x \<up> 3\", \"y\"], [\"x \<up> 3\", \"y\"])", is_nums = "(false, false)"} (*isa == isa2*)
walther@60328
   353
(*4*){a = "var_ord_revPow ", at_bt = "(x \<up> 3, x \<up> 3)", sort_args = "(x, 3), (x, 3)"}              (*isa == isa2*)
walther@60328
   354
(*4*){a = "dict_cond_ord", args = "([\"y\"], [\"y\"])", is_nums = "(false, false)"}                       (*isa == isa2*)
walther@60328
   355
(*4*){a = "var_ord_revPow ", at_bt = "(y, y)", sort_args = "(y, ---), (y, ---)"}                          (*isa == isa2*)
walther@60328
   356
(*4*){a = "dict_cond_ord ([], [])"}                                                                       (*isa == isa2*)
walther@60328
   357
walther@60328
   358
val it = true: bool
walther@60328
   359
val it = false: bool
walther@60328
   360
val it = false: bool
walther@60328
   361
val it = true: bool
walther@60328
   362
*)
walther@60328
   363
walther@60328
   364
(*+*) if monom_degree eee1 = 4 then () else error "monom_degree [\"x \<up> 2\", \"y \<up> 2\"] CHANGED";
walther@60328
   365
"~~~~~~~~~~~~~~~ fun monom_degree , args:"; val (l) = (eee1);
walther@60328
   366
"~~~~~ fun counter , args:"; val (n, x :: xs) = (0, l); (*--------------------------OPEN local\* )
walther@60328
   367
	    (*if*) (is_nums x) (*else*);
wenzelm@60405
   368
  val (Const (\<^const_name>\<open>realpow\<close>, _) $ Free _ $ t) =
walther@60328
   369
      (*case*) x (*of*); 
walther@60328
   370
(*+*)UnparseC.term x = "x \<up> 2";
walther@60328
   371
            (*if*) TermC.is_num t (*then*);
walther@60328
   372
walther@60328
   373
           counter (t |> HOLogic.dest_number |> snd |> curry op + n, xs);
walther@60328
   374
"~~~~~ fun counter , args:"; val (n, x :: xs) = (t |> HOLogic.dest_number |> snd |> curry op + n, xs);
walther@60328
   375
	    (*if*) (is_nums x) (*else*);
wenzelm@60405
   376
  val (Const (\<^const_name>\<open>realpow\<close>, _) $ Free _ $ t) =
walther@60328
   377
      (*case*) x (*of*); 
walther@60328
   378
(*+*)UnparseC.term x = "y \<up> 2";
walther@60328
   379
            (*if*) TermC.is_num t (*then*);
walther@60328
   380
walther@60328
   381
  val return =
walther@60328
   382
      counter (t |> HOLogic.dest_number |> snd |> curry op + n, xs);
walther@60328
   383
if return = 4 then () else error "monom_degree [\"x \<up> 2\", \"y \<up> 2\"] CHANGED";
walther@60328
   384
( *---------------------------------------------------------------------------------OPEN local/*)
walther@60328
   385
walther@60328
   386
(*+*)if monom_degree eee2 = 4 andalso monom_degree eee2 = 4 then ()
walther@60328
   387
else error "monom_degree  [\"x \<up> 3\", \"y\"] CHANGED";
walther@60328
   388
"~~~~~~~~~~~~~~~ fun monom_degree , args:"; val (l) = (eee2);
walther@60328
   389
"~~~~~ fun counter , args:"; val (n, x :: xs) = (0, l); (*--------------------------OPEN local\* )
walther@60328
   390
	    (*if*) (is_nums x) (*else*);
wenzelm@60405
   391
val (Const (\<^const_name>\<open>realpow\<close>, _) $ Free _ $ t) =
walther@60328
   392
      (*case*) x (*of*); 
walther@60328
   393
(*+*)UnparseC.term x = "x \<up> 3";
walther@60328
   394
            (*if*) TermC.is_num t (*then*);
walther@60328
   395
walther@60328
   396
      counter (t |> HOLogic.dest_number |> snd |> curry op + n, xs);
walther@60328
   397
"~~~~~ fun counter , args:"; val (n, x :: xs) = (t |> HOLogic.dest_number |> snd |> curry op + n, xs);
walther@60328
   398
	    (*if*) (is_nums x) (*else*);
walther@60328
   399
val _ = (*the default case*)
walther@60328
   400
      (*case*) x (*of*); 
walther@60328
   401
( *---------------------------------------------------------------------------------OPEN local/*)
walther@60328
   402
walther@60328
   403
"~~~~~~~~~~~~~~~ fun dict_cond_ord , args:"; val () = ();
walther@60328
   404
val xxx = dict_cond_ord var_ord_revPow is_nums;
walther@60328
   405
(*1*)if xxx (eee1, eee1) = EQUAL   then () else error "dict_cond_ord (eee1, eee1) CHANGED";
walther@60328
   406
(*2*)if xxx (eee1, eee2) = GREATER then () else error "dict_cond_ord (eee1, eee2) CHANGED";
walther@60328
   407
(*3*)if xxx (eee2, eee1) = LESS    then () else error "dict_cond_ord (eee2, eee1) CHANGED";
walther@60328
   408
(*4*)if xxx (eee2, eee2) = EQUAL   then () else error "dict_cond_ord (eee2, eee2) CHANGED";
walther@60328
   409
walther@60328
   410
walther@60328
   411
"-------- check make_polynomial with simple terms ----------------------------------------------";
walther@60328
   412
"-------- check make_polynomial with simple terms ----------------------------------------------";
walther@60328
   413
"-------- check make_polynomial with simple terms ----------------------------------------------";
walther@60328
   414
"----- check 1 ---";
walther@60328
   415
val t = TermC.str2term "2*3*a";
Walther@60500
   416
val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
walther@60328
   417
if UnparseC.term t = "6 * a" then () else error "check make_polynomial 1";
walther@60328
   418
walther@60328
   419
"----- check 2 ---";
walther@60328
   420
val t = TermC.str2term "2*a + 3*a";
Walther@60500
   421
val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
walther@60328
   422
if UnparseC.term t = "5 * a" then () else error "check make_polynomial 2";
walther@60328
   423
walther@60328
   424
"----- check 3 ---";
walther@60328
   425
val t = TermC.str2term "2*a + 3*a + 3*a";
Walther@60500
   426
val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
walther@60328
   427
if UnparseC.term t = "8 * a" then () else error "check make_polynomial 3";
walther@60328
   428
walther@60328
   429
"----- check 4 ---";
walther@60328
   430
val t = TermC.str2term "3*a - 2*a";
Walther@60500
   431
val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
walther@60328
   432
if UnparseC.term t = "a" then () else error "check make_polynomial 4";
walther@60328
   433
walther@60328
   434
"----- check 5 ---";
walther@60328
   435
val t = TermC.str2term "4*(3*a - 2*a)";
Walther@60500
   436
val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
walther@60328
   437
if UnparseC.term t = "4 * a" then () else error "check make_polynomial 5";
walther@60328
   438
walther@60328
   439
"----- check 6 ---";
walther@60328
   440
val t = TermC.str2term "4*(3*a \<up> 2 - 2*a \<up> 2)";
Walther@60500
   441
val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
walther@60328
   442
if UnparseC.term t = "4 * a \<up> 2" then () else error "check make_polynomial 6";
walther@60328
   443
walther@60328
   444
"-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
walther@60328
   445
"-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
walther@60328
   446
"-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
walther@60328
   447
val thy = @{theory "Isac_Knowledge"};
walther@60328
   448
"===== works for a simple example, see rewrite.sml -- fun app_rev ===";
walther@60328
   449
val t = TermC.str2term "x \<up> 2 * x";
Walther@60500
   450
val SOME (t', _) = rewrite_set_ ctxt true order_mult_ t;
walther@60328
   451
if UnparseC.term t' = "x * x \<up> 2" then ()
walther@60328
   452
else error "poly.sml Poly.is_multUnordered doesn't work";
walther@60328
   453
walther@60328
   454
(* 100928 Rewrite.trace_on shows the first occurring difference in 267b:
walther@60329
   455
###  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@60328
   456
 (-48 * x \<up> 4 + 8))
walther@60328
   457
######  rls: Rule_Set.empty-is_multUnordered on: p is_multUnordered
walther@60328
   458
#######  try calc: Poly.is_multUnordered'
walther@60328
   459
=======  calc. to: False  !!!!!!!!!!!!! INSTEAD OF TRUE in 2002 !!!!!!!!!!!!!
walther@60328
   460
*)
walther@60329
   461
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))";
walther@60328
   462
walther@60328
   463
"----- is_multUnordered ---";
walther@60328
   464
val tsort = sort_variables t;
walther@60329
   465
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";
walther@60328
   466
is_polyexp t;
walther@60328
   467
tsort = t;
walther@60328
   468
is_polyexp t andalso not (t = sort_variables t);
walther@60328
   469
if is_multUnordered t then () else error "poly.sml diff. is_multUnordered 1";
walther@60328
   470
walther@60328
   471
"----- eval_is_multUnordered ---";
walther@60329
   472
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";
Walther@60509
   473
case eval_is_multUnordered "testid" "" tm @{context} of
walther@60336
   474
    SOME (_, Const (\<^const_name>\<open>Trueprop\<close>, _) $ 
walther@60336
   475
                   (Const (\<^const_name>\<open>HOL.eq\<close>, _) $
walther@60336
   476
                          (Const (\<^const_name>\<open>is_multUnordered\<close>, _) $ _) $ 
walther@60336
   477
                          Const (\<^const_name>\<open>True\<close>, _))) => ()
walther@60328
   478
  | _ => error "poly.sml diff. eval_is_multUnordered";
walther@60328
   479
walther@60328
   480
"----- rewrite_set_ STILL DIDN'T WORK";
Walther@60500
   481
val SOME (t, _) = rewrite_set_ ctxt true order_mult_ t;
walther@60328
   482
UnparseC.term t;
walther@60328
   483
walther@60328
   484
walther@60328
   485
"-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
walther@60328
   486
"-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
walther@60328
   487
"-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
walther@60328
   488
val thy = @{theory "Isac_Knowledge"};
walther@60328
   489
val t as (_ $ arg) = TermC.str2term "(3 * a + - 2 * a) is_multUnordered";
walther@60328
   490
walther@60328
   491
(*+*)if UnparseC.term (sort_variables arg) = "3 * a + - 2 * a" andalso is_polyexp arg = true
walther@60328
   492
(*+*)  andalso not (is_multUnordered arg)
walther@60328
   493
(*+*)then () else error "sort_variables  3 * a + - 2 * a   CHANGED";
walther@60328
   494
Walther@60509
   495
case eval_is_multUnordered "xxx " "yyy " t @{context} of
walther@60328
   496
  SOME
walther@60328
   497
    ("xxx 3 * a + - 2 * a_",
walther@60336
   498
      Const (\<^const_name>\<open>Trueprop\<close>, _) $ (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ _ $
walther@60336
   499
        Const (\<^const_name>\<open>False\<close>, _))) => ()
walther@60336
   500
(*      Const (\<^const_name>\<open>True\<close>, _))) => ()   <<<<<--------------------------- this is false*)
walther@60329
   501
| _ => error "eval_is_multUnordered  3 * a + - 2 * a  CHANGED";
walther@60328
   502
walther@60328
   503
"----- is_multUnordered --- (- 2 * a) is_multUnordered = False";
walther@60328
   504
val t as (_ $ arg) = TermC.str2term "(- 2 * a) is_multUnordered";
walther@60328
   505
walther@60328
   506
(*+*)if UnparseC.term (sort_variables arg) = "- 2 * a" andalso is_polyexp arg = true
walther@60328
   507
(*+*)  andalso not (is_multUnordered arg)
walther@60328
   508
(*+*)then () else error "sort_variables  - 2 * a   CHANGED";
walther@60328
   509
Walther@60509
   510
case eval_is_multUnordered "xxx " "yyy " t @{context} of
walther@60328
   511
  SOME
walther@60328
   512
    ("xxx - 2 * a_",
walther@60336
   513
      Const (\<^const_name>\<open>Trueprop\<close>, _) $ (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ _ $
walther@60336
   514
        Const (\<^const_name>\<open>False\<close>, _))) => ()
walther@60329
   515
| _ => error "eval_is_multUnordered  3 * a + - 2 * a  CHANGED";
walther@60328
   516
walther@60328
   517
"----- is_multUnordered --- (a) is_multUnordered = False";
walther@60328
   518
val t as (_ $ arg) = TermC.str2term "(a) is_multUnordered";
walther@60328
   519
walther@60328
   520
(*+*)if UnparseC.term (sort_variables arg) = "a" andalso is_polyexp arg = true
walther@60328
   521
(*+*)  andalso not (is_multUnordered arg)
walther@60328
   522
(*+*)then () else error "sort_variables   a   CHANGED";
walther@60328
   523
Walther@60509
   524
case eval_is_multUnordered "xxx " "yyy " t @{context} of
walther@60328
   525
  SOME
walther@60328
   526
    ("xxx a_",
walther@60336
   527
      Const (\<^const_name>\<open>Trueprop\<close>, _) $ (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ _ $
walther@60336
   528
        Const (\<^const_name>\<open>False\<close>, _))) => ()
walther@60329
   529
| _ => error "eval_is_multUnordered  3 * a + - 2 * a  CHANGED";
walther@60328
   530
walther@60328
   531
"----- is_multUnordered --- (- 2) is_multUnordered = False";
walther@60328
   532
val t as (_ $ arg) = TermC.str2term "(- 2) is_multUnordered";
walther@60328
   533
walther@60328
   534
(*+*)if UnparseC.term (sort_variables arg) = "- 2" andalso is_polyexp arg = true
walther@60328
   535
(*+*)  andalso not (is_multUnordered arg)
walther@60328
   536
(*+*)then () else error "sort_variables   - 2   CHANGED";
walther@60328
   537
Walther@60509
   538
case eval_is_multUnordered "xxx " "yyy " t @{context} of
walther@60328
   539
  SOME
walther@60328
   540
    ("xxx - 2_",
walther@60336
   541
      Const (\<^const_name>\<open>Trueprop\<close>, _) $ (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ _ $
walther@60336
   542
        Const (\<^const_name>\<open>False\<close>, _))) => ()
walther@60329
   543
| _ => error "eval_is_multUnordered  3 * a + - 2 * a  CHANGED";
walther@60328
   544
walther@60328
   545
walther@60328
   546
"-------- fun is_multUnordered (x - a) \<up> 3 -----------------------------------------------------";
walther@60328
   547
"-------- fun is_multUnordered (x - a) \<up> 3 -----------------------------------------------------";
walther@60328
   548
"-------- fun is_multUnordered (x - a) \<up> 3 -----------------------------------------------------";
walther@60328
   549
(*  ca.line 45 of Rewrite.trace_on:
walther@60328
   550
##  rls: order_mult_rls_ on: 
walther@60328
   551
  x \<up> 3 + 3 * x \<up> 2 * (- 1 * a) + 3 * x * ((- 1) \<up> 2 * a \<up> 2) + (- 1) \<up> 3 * a \<up> 3 
walther@60328
   552
###  rls: order_mult_ on:
walther@60328
   553
  x \<up> 3 + 3 * x \<up> 2 * (- 1 * a) + 3 * x * ((- 1) \<up> 2 * a \<up> 2) + (- 1) \<up> 3 * a \<up> 3 
walther@60328
   554
######  rls: Rule_Set.empty-is_multUnordered on: 
walther@60328
   555
  x \<up> 3 + 3 * x \<up> 2 * (- 1 * a) + 3 * x * ((- 1) \<up> 2 * a \<up> 2) + (- 1) \<up> 3 * a \<up> 3 is_multUnordered 
walther@60328
   556
#######  try calc: "Poly.is_multUnordered" 
walther@60328
   557
########  eval asms: 
walther@60328
   558
N:x \<up> 3 + 3 * x \<up> 2 * (- 1 * a) + 3 * x * ((- 1) \<up> 2 * a \<up> 2) + (- 1) \<up> 3 * a \<up> 3 is_multUnordered = True" 
walther@60328
   559
-------------------------------------------------------------------------------------------------==
walther@60329
   560
O:x \<up> 3 + 3 * x \<up> 2 * (- 1 * a)  + 3 * x * (- 1    \<up> 2 * a \<up> 2) + - 1    \<up> 3 * a \<up> 3 is_multUnordered = True" 
walther@60328
   561
#######  calc. to: True 
walther@60328
   562
#######  try calc: "Poly.is_multUnordered" 
walther@60328
   563
#######  try calc: "Poly.is_multUnordered" 
walther@60328
   564
###  rls: order_mult_ on: 
walther@60328
   565
N:x \<up> 3 + - 1 * (3 * (a * x \<up> 2))  +  3 * (a \<up> 2 * (x * (- 1) \<up> 2))  +  a \<up> 3 * (- 1) \<up> 3 
walther@60328
   566
--------+--------------------------+---------------------------------+---------------------------<>
walther@60329
   567
O:x \<up> 3 + - 1  * (3 * (a * x \<up> 2))  +  - 1 \<up> 2 * (3 * (a \<up> 2 * x))     +  - 1 \<up> 3 * a \<up> 3 
walther@60328
   568
-------------------------------------------------------------------------------------------------<>
walther@60328
   569
*)
walther@60328
   570
val t = TermC.str2term "x \<up> 3 + 3 * x \<up> 2 * (- 1 * a) + 3 * x * ((- 1) \<up> 2 * a \<up> 2) + (- 1) \<up> 3 * a \<up> 3";
walther@60328
   571
(*
walther@60328
   572
"~~~~~ fun is_multUnordered
walther@60328
   573
"~~~~~~~ fun sort_variables
walther@60328
   574
"~~~~~~~~~ val sort_varList
walther@60328
   575
*)
walther@60328
   576
"~~~~~ fun is_multUnordered , args:"; val (t) = (t);
walther@60328
   577
     is_polyexp t = true;
walther@60328
   578
walther@60328
   579
  val return =
walther@60328
   580
             sort_variables t;
walther@60328
   581
(*+*)if UnparseC.term return =
walther@60328
   582
(*+*)  "x \<up> 3 + - 1 * (3 * (a * x \<up> 2)) +\n(- 1) \<up> 2 * (3 * (a \<up> 2 * x)) +\n(- 1) \<up> 3 * a \<up> 3"
walther@60328
   583
(*+*)then () else error "sort_variables  x \<up> 3 + - 1 * (3 * (a * x \<up> 2)) .. CHANGED";
walther@60328
   584
walther@60328
   585
"~~~~~~~ fun sort_variables , args:"; val (t) = (t);
walther@60328
   586
  	val ll = map monom2list (poly2list t);
walther@60328
   587
  	val lls = map sort_varList ll; 
walther@60328
   588
walther@60328
   589
(*+*)val ori3 = nth 3 ll;
walther@60328
   590
(*+*)val mon3 = nth 3 lls;
walther@60328
   591
walther@60328
   592
(*+*)if UnparseC.terms (nth 1 ll) = "[\"x \<up> 3\"]" then () else error "nth 1 ll";
walther@60328
   593
(*+*)if UnparseC.terms (nth 2 ll) = "[\"3\", \"x \<up> 2\", \"- 1\", \"a\"]" then () else error "nth 3 ll";
walther@60328
   594
(*+*)if UnparseC.terms ori3       = "[\"3\", \"x\", \"(- 1) \<up> 2\", \"a \<up> 2\"]" then () else error "nth 3 ll";
walther@60328
   595
(*+*)if UnparseC.terms (nth 4 ll) = "[\"(- 1) \<up> 3\", \"a \<up> 3\"]" then () else error "nth 4 ll";
walther@60328
   596
walther@60328
   597
(*+*)if UnparseC.terms (nth 1 lls) = "[\"x \<up> 3\"]" then () else error "nth 1 lls";
walther@60328
   598
(*+*)if UnparseC.terms (nth 2 lls) = "[\"- 1\", \"3\", \"a\", \"x \<up> 2\"]" then () else error "nth 2 lls";
walther@60328
   599
(*+*)if UnparseC.terms mon3 = "[\"(- 1) \<up> 2\", \"3\", \"a \<up> 2\", \"x\"]" then () else error "nth 3 lls";
walther@60328
   600
(*+*)if UnparseC.terms (nth 4 lls) = "[\"(- 1) \<up> 3\", \"a \<up> 3\"]" then () else error "nth 4 lls";
walther@60328
   601
walther@60328
   602
"~~~~~~~~~ val sort_varList , args:"; val (ori3) = (ori3);
walther@60328
   603
(* Output below with:
walther@60328
   604
val sort_varList = sort var_ord;
walther@60328
   605
fun var_ord (a,b: term) = 
walther@60328
   606
(@{print} {a = "var_ord ", a_b = "(" ^ UnparseC.term a ^ ", " ^ UnparseC.term b ^ ")",
walther@60328
   607
   sort_args = "(" ^ get_basStr a ^ ", " ^ get_potStr a ^ "), (" ^ get_basStr b ^ ", " ^ get_potStr b ^ ")"};
walther@60328
   608
  prod_ord string_ord string_ord 
walther@60328
   609
  ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b))
walther@60328
   610
);
walther@60328
   611
*)
walther@60328
   612
(*+*)val xxx = sort_varList ori3;
walther@60328
   613
(*
walther@60328
   614
{a = "sort_varList", args = "[\"3\", \"x\", \"(- 1) \<up> 2\", \"a \<up> 2\"]"} (*isa*)
walther@60328
   615
{a = "sort_varList", args = "[\"3\", \"x\", \"(- 1) \<up> 2\", \"a \<up> 2\"]"} (*isa2*)
walther@60328
   616
      
walther@60328
   617
isa                                            isa2
walther@60328
   618
{a = "var_ord ", a_b = "(3, x)"}               {a = "var_ord ", a_b = "(3, x)"}
walther@60328
   619
  {sort_args = "(|||, ||||||), (x, ---)"}        {sort_args = "(|||, ||||||), (x, ---)"}
walther@60328
   620
{a = "var_ord ", a_b = "(x, (- 1) \<up> 2)"}       {a = "var_ord ", a_b = "(x, (- 1) \<up> 2)"}
walther@60328
   621
  {sort_args = "(x, ---), (|||, ||||||)"}        {sort_args = "(x, ---), (|||, ||||||)"}
walther@60328
   622
{a = "var_ord ", a_b = "((- 1) \<up> 2, a \<up> 2)"}   {a = "var_ord ", a_b = "((- 1) \<up> 2, a \<up> 2)"}
walther@60328
   623
  {sort_args = "(|||, ||||||), (a, 2)"}          {sort_args = "(|||, ||||||), (a, |||)"}
walther@60328
   624
                                  ^^^                                             ^^^
walther@60328
   625
walther@60328
   626
{a = "var_ord ", a_b = "(x, a \<up> 2)"}           {a = "var_ord ", a_b = "(x, a \<up> 2)"}
walther@60328
   627
  {sort_args = "(x, ---), (a, 2)"}               {sort_args = "(x, ---), (a, |||)"}
walther@60328
   628
                             ^^^                                             ^^^
walther@60328
   629
{a = "var_ord ", a_b = "(x, (- 1) \<up> 2)"}       {a = "var_ord ", a_b = "(x, (- 1) \<up> 2)"}
walther@60328
   630
  {sort_args = "(x, ---), (|||, ||||||)"}        {sort_args = "(x, ---), (|||, ||||||)"}
walther@60328
   631
{a = "var_ord ", a_b = "(3, (- 1) \<up> 2)"}       {a = "var_ord ", a_b = "(3, (- 1) \<up> 2)"}
walther@60328
   632
  {sort_args = "(|||, ||||||), (|||, ||||||)"}   {sort_args = "(|||, ||||||), (|||, ||||||)"}
walther@60328
   633
*)
walther@60328
   634
walther@60328
   635
walther@60328
   636
"-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
walther@60328
   637
"-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
walther@60328
   638
"-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
walther@60328
   639
val t = TermC.str2term "b * a * a";
Walther@60500
   640
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60328
   641
if UnparseC.term t = "a \<up> 2 * b" then ()
walther@60328
   642
else error "poly.sml: diff.behav. in make_polynomial 21";
walther@60328
   643
walther@60328
   644
"~~~~~ fun is_multUnordered , args:"; val (t) = (@{term "b * a * a::real"});
walther@60328
   645
    ((is_polyexp t) andalso not (t = sort_variables t)) = true;  (*isa == isa2*)
walther@60328
   646
walther@60328
   647
(*+*)if    is_polyexp t then () else error "is_polyexp a \<up> 2 * b CHANGED";
walther@60336
   648
"~~~~~ fun is_polyexp , args:"; val (Const (\<^const_name>\<open>times\<close>,_) $ num $ Free _) = (t);
walther@60328
   649
    (*if*) TermC.is_num num (*else*);
walther@60328
   650
walther@60336
   651
"~~~~~ fun is_polyexp , args:"; val (Const (\<^const_name>\<open>times\<close>,_) $ num $ Free _) = (num);
walther@60328
   652
    (*if*) TermC.is_num num (*else*);
walther@60328
   653
      (*if*) TermC.is_variable num (*then*);
walther@60328
   654
walther@60328
   655
                           val xxx = sort_variables t;
walther@60328
   656
(*+*)if UnparseC.term xxx = "a * (a * b)" then () else error "sort_variables a \<up> 2 * b CHANGED";
walther@60328
   657
walther@60328
   658
walther@60328
   659
"-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
walther@60328
   660
"-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
walther@60328
   661
"-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
walther@60328
   662
val t = TermC.str2term "2*3*a";
Walther@60500
   663
val SOME (t', _) = rewrite_set_ ctxt false make_polynomial t;
walther@60328
   664
(*+*)if UnparseC.term t' = "6 * a" then () else error "rewrite_set_ 2*3*a CHANGED";
walther@60328
   665
(*
walther@60328
   666
##  try calc: "Groups.times_class.times" 
walther@60328
   667
##  rls: order_mult_rls_ on: 6 * a 
walther@60328
   668
###  rls: order_mult_ on: 6 * a 
walther@60328
   669
######  rls: Rule_Set.empty-is_multUnordered on: 6 * a is_multUnordered 
walther@60328
   670
#######  try calc: "Poly.is_multUnordered" 
walther@60328
   671
########  eval asms: "6 * a is_multUnordered = True"    (*isa*)
walther@60328
   672
                                             = False"   (*isa2*)
walther@60328
   673
#######  calc. to: True  (*isa*)
walther@60328
   674
                   False (*isa2*)
walther@60328
   675
*)
walther@60328
   676
val t = TermC.str2term "(6 * a) is_multUnordered"; 
walther@60328
   677
val SOME
walther@60328
   678
    (_, t') =
Walther@60509
   679
           eval_is_multUnordered "xxx" () t @{context};
walther@60328
   680
(*+*)if UnparseC.term t' = "6 * a is_multUnordered = False" then () 
walther@60328
   681
(*+*)else error "6 * a is_multUnordered = False CHANGED";
walther@60328
   682
walther@60328
   683
"~~~~~ fun eval_is_multUnordered , args:"; val ((thmid:string), _,
walther@60336
   684
		       (t as (Const (\<^const_name>\<open>is_multUnordered\<close>, _) $ arg)), thy) = ("xxx", (), t, @{theory});
walther@60328
   685
    (*if*) is_multUnordered arg (*else*);
walther@60328
   686
walther@60328
   687
"~~~~~ fun is_multUnordered , args:"; val (t) = (arg);
walther@60328
   688
  val return =
walther@60328
   689
     ((is_polyexp t) andalso not (t = sort_variables t));
walther@60328
   690
walther@60328
   691
(*+*)return = false;                                             (*isa*)
walther@60328
   692
(*+*)  is_polyexp t = true;                                      (*isa*)
walther@60328
   693
(*+*)                        not (t = sort_variables t) = false; (*isa*)
walther@60328
   694
walther@60328
   695
                            val xxx = sort_variables t;
walther@60328
   696
(*+*)if UnparseC.term xxx = "6 * a" then () else error "2*3*a is_multUnordered CHANGED";
walther@60328
   697
walther@60328
   698
"-------- norm_Poly with AlgEin ----------------------------------------------------------------";
walther@60328
   699
"-------- norm_Poly with AlgEin ----------------------------------------------------------------";
walther@60328
   700
"-------- norm_Poly with AlgEin ----------------------------------------------------------------";
walther@60328
   701
val thy = @{theory AlgEin};
Walther@60424
   702
val ctxt = Proof_Context.init_global thy;
walther@60328
   703
Walther@60500
   704
val SOME (f',_) = rewrite_set_ ctxt false norm_Poly
walther@60328
   705
(TermC.str2term "L = k - 2 * q + (k - 2 * q) + (k - 2 * q) + (k - 2 * q) + senkrecht + oben");
walther@60328
   706
if UnparseC.term f' = "L = 2 * 2 * k + 2 * - 4 * q + senkrecht + oben"
walther@60328
   707
then ((*norm_Poly NOT COMPLETE -- TODO MG*))
walther@60328
   708
else error "norm_Poly changed behavior";
walther@60328
   709
(* isa:
walther@60328
   710
##  rls: order_add_rls_ on: L = k + - 2 * q + k + - 2 * q + k + - 2 * q + k + - 2 * q + senkrecht + oben 
walther@60328
   711
###  rls: order_add_ on: L = k + - 2 * q + k + - 2 * q + k + - 2 * q + k + - 2 * q + senkrecht + oben 
walther@60328
   712
######  rls: Rule_Set.empty-is_addUnordered on: k + - 2 * q + k + - 2 * q + k + - 2 * q + k + - 2 * q + senkrecht +
walther@60328
   713
oben is_addUnordered 
walther@60328
   714
#######  try calc: "Poly.is_addUnordered" 
walther@60328
   715
########  eval asms: "k + - 2 * q + k + - 2 * q + k + - 2 * q + k + - 2 * q + senkrecht +
walther@60328
   716
oben is_addUnordered = True" 
walther@60328
   717
#######  calc. to: True 
walther@60328
   718
#######  try calc: "Poly.is_addUnordered" 
walther@60328
   719
#######  try calc: "Poly.is_addUnordered" 
walther@60328
   720
###  rls: order_add_ on: L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben 
walther@60328
   721
*)
walther@60328
   722
"~~~~~ fun sort_monoms , args:"; val (t) =
walther@60328
   723
  (TermC.str2term "L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben");
walther@60328
   724
(*+*)val t' =
walther@60328
   725
           sort_monoms t;
walther@60328
   726
(*+*)UnparseC.term t' = "L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben"; (*isa*)
walther@60328
   727
walther@60328
   728
walther@60328
   729
"-------- complex examples from textbook Schalk I ----------------------------------------------";
walther@60328
   730
"-------- complex examples from textbook Schalk I ----------------------------------------------";
walther@60328
   731
"-------- complex examples from textbook Schalk I ----------------------------------------------";
walther@60329
   732
val t = TermC.str2term "1 + 2 * x \<up> 4 + 2 * - 2 * x \<up> 4 + x \<up> 8";
Walther@60500
   733
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60329
   734
if (UnparseC.term t) = "1 + - 2 * x \<up> 4 + x \<up> 8"
walther@60328
   735
then () else error "poly.sml: diff.behav. in make_polynomial 9b";
walther@60328
   736
walther@60328
   737
"-----SPB Schalk I p.64 No.296a ---";
walther@60328
   738
val t = TermC.str2term "(x - a) \<up> 3";
Walther@60500
   739
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60329
   740
if (UnparseC.term t) = "- 1 * a \<up> 3 + 3 * a \<up> 2 * x + - 3 * a * x \<up> 2 + x \<up> 3"
walther@60328
   741
then () else error "poly.sml: diff.behav. in make_polynomial 10";
walther@60328
   742
walther@60328
   743
"-----SPB Schalk I p.64 No.296c ---";
walther@60328
   744
val t = TermC.str2term "(-3*x - 4*y) \<up> 3";
Walther@60500
   745
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60329
   746
if (UnparseC.term t) = "- 27 * x \<up> 3 + - 108 * x \<up> 2 * y + - 144 * x * y \<up> 2 +\n- 64 * y \<up> 3"
walther@60328
   747
then () else error "poly.sml: diff.behav. in make_polynomial 11";
walther@60328
   748
walther@60328
   749
"-----SPB Schalk I p.62 No.242c ---";
walther@60329
   750
val t = TermC.str2term "x \<up> (- 4)*(x \<up> (- 4)*y \<up> (- 2)) \<up> (- 1)*y \<up> (- 2)";
Walther@60500
   751
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60328
   752
if (UnparseC.term t) = "1"
walther@60328
   753
then () else error "poly.sml: diff.behav. in make_polynomial 12";
walther@60328
   754
walther@60328
   755
"-----SPB Schalk I p.60 No.209a ---";
walther@60328
   756
val t = TermC.str2term "a \<up> (7-x) * a \<up> x";
Walther@60500
   757
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60328
   758
if UnparseC.term t = "a \<up> 7"
walther@60328
   759
then () else error "poly.sml: diff.behav. in make_polynomial 13";
walther@60328
   760
walther@60328
   761
"-----SPB Schalk I p.60 No.209d ---";
walther@60328
   762
val t = TermC.str2term "d \<up> x * d \<up> (x+1) * d \<up> (2 - 2*x)";
Walther@60500
   763
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60328
   764
if UnparseC.term t = "d \<up> 3"
walther@60328
   765
then () else error "poly.sml: diff.behav. in make_polynomial 14";
walther@60328
   766
walther@60328
   767
walther@60328
   768
"-------- complex Eigene Beispiele (Mathias Goldgruber) ----------------------------------------";
walther@60328
   769
"-------- complex Eigene Beispiele (Mathias Goldgruber) ----------------------------------------";
walther@60328
   770
"-------- complex Eigene Beispiele (Mathias Goldgruber) ----------------------------------------";
walther@60328
   771
"-----SPO ---";
walther@60329
   772
val t = TermC.str2term "a \<up> 2*a \<up> (- 2)";
Walther@60500
   773
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60328
   774
if UnparseC.term t = "1" then ()
walther@60328
   775
else error "poly.sml: diff.behav. in make_polynomial 15";
walther@60328
   776
walther@60328
   777
"-----SPO ---";
walther@60329
   778
val t = TermC.str2term "a \<up> 2*b*b \<up> (- 1)";
Walther@60500
   779
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60328
   780
if UnparseC.term t = "a \<up> 2" then ()
walther@60328
   781
else error "poly.sml: diff.behav. in make_polynomial 18";
walther@60328
   782
"-----SPO ---";
walther@60329
   783
val t = TermC.str2term "a \<up> 2*a \<up> (- 2)";
Walther@60500
   784
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60328
   785
if (UnparseC.term t) = "1" then ()
walther@60328
   786
else error "poly.sml: diff.behav. in make_polynomial 19";
walther@60328
   787
"-----SPO ---";
walther@60328
   788
val t = TermC.str2term "b + a - b";
Walther@60500
   789
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60328
   790
if (UnparseC.term t) = "a" then ()
walther@60328
   791
else error "poly.sml: diff.behav. in make_polynomial 20";
walther@60328
   792
walther@60328
   793
"-----SPO ---";
Walther@60424
   794
val t = TermC.parseNEW' ctxt "a \<up> 2 * (-a) \<up> 2";
Walther@60500
   795
val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
walther@60328
   796
if (UnparseC.term t) = "a \<up> 4" then ()
walther@60328
   797
else error "poly.sml: diff.behav. in make_polynomial 24";