test/Tools/isac/Knowledge/poly.sml
author wneuper <walther.neuper@jku.at>
Sat, 03 Jul 2021 16:21:07 +0200
changeset 60318 e6e7a9b9ced7
parent 60317 638d02a9a96a
child 60325 a7c0e6ab4883
permissions -rw-r--r--
//test/../rewrite.sml,poly.sml WORK
walther@60318
     1
(* Knowledge/poly.sml
neuper@37906
     2
   author: Matthias Goldgruber 2003
neuper@37906
     3
   (c) due to copyright terms
neuper@37906
     4
neuper@42395
     5
LEGEND:
neuper@42395
     6
WN060104: examples marked with 'SPB' came into 'exp_IsacCore_Simp_Poly_Book.xml'
neuper@42395
     7
          examples marked with 'SPO' came into 'exp_IsacCore_Simp_Poly_Other.xml'
neuper@38022
     8
*)
neuper@42395
     9
walther@60318
    10
"-----------------------------------------------------------------------------------------------";
walther@60318
    11
"-----------------------------------------------------------------------------------------------";
walther@60318
    12
"table of contents -----------------------------------------------------------------------------";
walther@60318
    13
"-----------------------------------------------------------------------------------------------";
walther@60318
    14
"-------- survey on parallel rewrite-breakers AND code with @{print} ---------------------------";
walther@60318
    15
"-------- thm sym_real_mult_minus1 loops with new numerals -------------------------------------";
walther@60318
    16
"-------- fun is_polyexp -----------------------------------------------------------------------";
walther@60318
    17
"-------- fun has_degree_in --------------------------------------------------------------------";
walther@60318
    18
"-------- fun mono_deg_in ----------------------------------------------------------------------";
walther@60318
    19
"-------- rewrite_set_ has_degree_in Const ('Partial_Fractions', _) ----------------------------";
walther@60318
    20
"-------- eval_ for is_expanded_in, is_poly_in, has_degree_in ----------------------------------";
walther@60318
    21
"-------- investigate (new 2002) uniary minus --------------------------------------------------";
walther@60318
    22
"-------- fun sort_variables -------------------------------------------------------------------";
walther@60318
    23
"-------- rebuild fun is_addUnordered (1 + 2 * x \<up> 4 + - 4 * x \<up> 4 + x \<up> 8) ---------------------";
walther@60318
    24
"-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
walther@60318
    25
"-------- check make_polynomial with simple terms ----------------------------------------------";
walther@60318
    26
"-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
walther@60318
    27
"-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
walther@60318
    28
"-------- fun is_multUnordered (x - a) \<up> 3 -----------------------------------------------------";
walther@60318
    29
"-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
walther@60318
    30
"-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
walther@60318
    31
"-------- examples from textbook Schalk I ------------------------------------------------------";
walther@60318
    32
"-------- ?RL?Bsple bei denen es Probleme gibt--------------------------------------------------";
walther@60318
    33
"-------- Eigene Beispiele (Mathias Goldgruber) ------------------------------------------------";
walther@60318
    34
"-------- check pbl  'polynomial simplification' -----------------------------------------------";
walther@60318
    35
"-------- me 'poly. simpl.' Schalk I p.63 No.267b ----------------------------------------------";
walther@60318
    36
"-------- interSteps for Schalk 299a -----------------------------------------------------------";
walther@60318
    37
"-------- norm_Poly NOT COMPLETE ---------------------------------------------------------------";
walther@60318
    38
"-------- ord_make_polynomial ------------------------------------------------------------------";
walther@60318
    39
"-----------------------------------------------------------------------------------------------";
walther@60318
    40
"-----------------------------------------------------------------------------------------------";
walther@60318
    41
"-----------------------------------------------------------------------------------------------";
neuper@37906
    42
neuper@37906
    43
walther@60318
    44
"-------- survey on parallel rewrite-breakers AND code with @{print} ---------------------------";
walther@60318
    45
"-------- survey on parallel rewrite-breakers AND code with @{print} ---------------------------";
walther@60318
    46
"-------- survey on parallel rewrite-breakers AND code with @{print} ---------------------------";
walther@60318
    47
(* indentation indicates call hierarchy:
walther@60318
    48
"~~~~~ fun is_addUnordered
walther@60318
    49
"~~~~~~~ fun is_polyexp
walther@60318
    50
"~~~~~~~ fun sort_monoms
walther@60318
    51
"~~~~~~~~~ fun sort_monList
walther@60318
    52
"~~~~~~~~~~~ fun koeff_degree_ord    : term list * term list -> order
walther@60318
    53
"~~~~~~~~~~~~~ fun degree_ord        : term list * term list -> order
walther@60318
    54
"~~~~~~~~~~~~~~~ fun dict_cond_ord   : ('a * 'a -> order) -> ('a -> bool) -> 'a list * 'a list -> order
walther@60318
    55
"~~~~~~~~~~~~~~~~~ fun var_ord_revPow: term * term -> order
walther@60318
    56
"~~~~~~~~~~~~~~~~~~~ fun get_basStr  : term -> string                       used twice --vv
walther@60318
    57
"~~~~~~~~~~~~~~~~~~~ fun get_potStr  : term -> string                       used twice --vv
walther@60318
    58
"~~~~~~~~~~~~~~~ fun monom_degree    : term list -> int
walther@60318
    59
"~~~~~~~~~~~~~ fun compare_koeff_ord : term list * term list -> order
walther@60318
    60
"~~~~~~~~~~~~~~~ fun get_koeff_of_mon: term list -> term option
walther@60318
    61
"~~~~~~~~~~~~~~~~~ fun koeff2ordStr  : term option -> string
walther@60318
    62
"~~~~~ fun is_multUnordered
walther@60318
    63
"~~~~~~~ fun sort_variables
walther@60318
    64
"~~~~~~~~~ fun sort_varList
walther@60318
    65
"~~~~~~~~~~~ fun var_ord
walther@60318
    66
"~~~~~~~~~~~~~ fun get_basStr                                               used twice --^^
walther@60318
    67
"~~~~~~~~~~~~~ fun get_potStr                                               used twice --^^
wneuper@59529
    68
walther@60318
    69
fun int_ord (i1, i2) =
walther@60318
    70
(@{print} {a = "int_ord (" ^ string_of_int i1 ^ ", " ^ string_of_int i2 ^ ") = ", z = Int.compare (i1, i2)};
walther@60318
    71
  Int.compare (i1, i2)
walther@60318
    72
);
walther@60318
    73
fun var_ord (a, b) = 
walther@60318
    74
(@{print} {a = "var_ord ", a_b = "(" ^ UnparseC.term a ^ ", " ^ UnparseC.term b ^ ")",
walther@60318
    75
   sort_args = "(" ^ get_basStr a ^ ", " ^ get_potStr a ^ "), (" ^ get_basStr b ^ ", " ^ get_potStr b ^ ")"};
walther@60318
    76
  prod_ord string_ord string_ord 
walther@60318
    77
  ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b))
walther@60318
    78
);
walther@60318
    79
fun var_ord_revPow (a, b: term) = 
walther@60318
    80
(@{print} {a = "var_ord_revPow ", at_bt = "(" ^ UnparseC.term a ^ ", " ^ UnparseC.term b ^ ")",
walther@60318
    81
    sort_args = "(" ^ get_basStr a ^ ", " ^ get_potStr a ^ "), (" ^ get_basStr b ^ ", " ^ get_potStr b ^ ")"};
walther@60318
    82
  prod_ord string_ord string_ord_rev 
walther@60318
    83
    ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b))
walther@60318
    84
);
walther@60318
    85
fun sort_varList ts =
walther@60318
    86
(@{print} {a = "sort_varList", args = UnparseC.terms ts};
walther@60318
    87
  sort var_ord ts
walther@60318
    88
);
walther@60318
    89
fun dict_cond_ord _ _ ([], [])     = (@{print} {a = "dict_cond_ord ([], [])"}; EQUAL)
walther@60318
    90
  | dict_cond_ord _ _ ([], _ :: _) = (@{print} {a = "dict_cond_ord ([], _ :: _)"}; LESS)
walther@60318
    91
  | dict_cond_ord _ _ (_ :: _, []) = (@{print} {a = "dict_cond_ord (_ :: _, [])"}; GREATER)
walther@60318
    92
  | dict_cond_ord elem_ord cond (x :: xs, y :: ys) =
walther@60318
    93
    (@{print} {a = "dict_cond_ord", args = "(" ^ UnparseC.terms (x :: xs) ^ ", " ^ UnparseC.terms (y :: ys) ^ ")", 
walther@60318
    94
      is_nums = "(" ^ LibraryC.bool2str (cond x) ^ ", " ^ LibraryC.bool2str (cond y) ^ ")"};
walther@60318
    95
     case (cond x, cond y) of 
walther@60318
    96
	    (false, false) =>
walther@60318
    97
        (case elem_ord (x, y) of 
walther@60318
    98
				  EQUAL => dict_cond_ord elem_ord cond (xs, ys) 
walther@60318
    99
			  | ord => ord)
walther@60318
   100
    | (false, true)  => dict_cond_ord elem_ord cond (x :: xs, ys)
walther@60318
   101
    | (true, false)  => dict_cond_ord elem_ord cond (xs, y :: ys)
walther@60318
   102
    | (true, true)  =>  dict_cond_ord elem_ord cond (xs, ys)
walther@60318
   103
);
walther@60318
   104
fun compare_koeff_ord (xs, ys) =
walther@60318
   105
(@{print} {a = "compare_koeff_ord ", ats_bts = "(" ^ UnparseC.terms xs ^ ", " ^ UnparseC.terms ys ^ ")",
walther@60318
   106
    sort_args = "(" ^ (koeff2ordStr o get_koeff_of_mon) xs ^ ", " ^ (koeff2ordStr o get_koeff_of_mon) ys ^ ")"};
walther@60318
   107
  string_ord
walther@60318
   108
  ((koeff2ordStr o get_koeff_of_mon) xs,
walther@60318
   109
   (koeff2ordStr o get_koeff_of_mon) ys)
walther@60318
   110
);
walther@60318
   111
fun var_ord (a,b: term) = 
walther@60318
   112
(@{print} {a = "var_ord ", a_b = "(" ^ UnparseC.term a ^ ", " ^ UnparseC.term b ^ ")",
walther@60318
   113
   sort_args = "(" ^ get_basStr a ^ ", " ^ get_potStr a ^ "), (" ^ get_basStr b ^ ", " ^ get_potStr b ^ ")"};
walther@60318
   114
  prod_ord string_ord string_ord 
walther@60318
   115
  ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b))
walther@60318
   116
);
walther@60318
   117
*)
walther@60318
   118
walther@60318
   119
walther@60318
   120
"-------- thm sym_real_mult_minus1 loops with new numerals -------------------------------------";
walther@60318
   121
"-------- thm sym_real_mult_minus1 loops with new numerals -------------------------------------";
walther@60318
   122
"-------- thm sym_real_mult_minus1 loops with new numerals -------------------------------------";
walther@60318
   123
(* thus   ^^^^^^^^^^^^^^^^^^^^^^^^ excluded from rls.
walther@60318
   124
walther@60318
   125
  sym_real_mult_minus1                                  =     "- ?z = - 1 * ?z" *)
walther@60318
   126
@{thm real_mult_minus1};                              (* = "- 1 * ?z = - ?z"     *)
walther@60318
   127
val thm_isac = ThmC.sym_thm @{thm real_mult_minus1};  (* =     "- ?z = - 1 * ?z" *)
walther@60318
   128
val SOME t_isac = TermC.parseNEW @{context} "3 * a + - 1 * (2 * a):: real";
walther@60318
   129
walther@60318
   130
val SOME (t', []) = rewrite_ @{theory} tless_true Rule_Set.empty true thm_isac t_isac;
walther@60318
   131
if UnparseC.term t' = "3 * a + - 1 * 1 * (2 * a)" then ((*thm did NOT apply to Free ("-1", _)*))
walther@60318
   132
else error "thm  - ?z = - 1 * ?z  loops with new numerals";
walther@60318
   133
walther@60318
   134
walther@60318
   135
"-------- fun is_polyexp -----------------------------------------------------------------------";
walther@60318
   136
"-------- fun is_polyexp -----------------------------------------------------------------------";
walther@60318
   137
"-------- fun is_polyexp -----------------------------------------------------------------------";
walther@60318
   138
val t = TermC.str2term "x / x";
wneuper@59529
   139
if is_polyexp t then error "NOT is_polyexp (x / x)" else ();
wneuper@59529
   140
walther@60318
   141
val t = TermC.str2term "-1 * A * 3";
wneuper@59529
   142
if is_polyexp t then () else error "is_polyexp (-1 * A * 3)";
wneuper@59529
   143
walther@60318
   144
val t = TermC.str2term "-1 * AA * 3";
wneuper@59529
   145
if is_polyexp t then () else error "is_polyexp (-1 * AA * 3)";
neuper@38022
   146
walther@60318
   147
val t = TermC.str2term "x * x + x * y + (- 1 * y * x + - 1 * y * y)::real";
walther@60318
   148
if is_polyexp t then () else error "is_polyexp (x * x + x * y + (- 1 * y * x + - 1 * y * y))";
walther@60318
   149
walther@60318
   150
"-------- fun has_degree_in --------------------------------------------------------------------";
walther@60318
   151
"-------- fun has_degree_in --------------------------------------------------------------------";
walther@60318
   152
"-------- fun has_degree_in --------------------------------------------------------------------";
walther@60230
   153
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   154
val t = (Thm.term_of o the o (TermC.parse thy)) "1";
wneuper@59522
   155
if has_degree_in t v = 0 then () else error "has_degree_in (1) x";
wneuper@59522
   156
walther@60230
   157
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   158
val t = (Thm.term_of o the o (TermC.parse thy)) "1";
wneuper@59522
   159
if has_degree_in t v = 0 then () else error "has_degree_in (1) AA";
wneuper@59522
   160
wneuper@59522
   161
(*----------*)
walther@60230
   162
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   163
val t = (Thm.term_of o the o (TermC.parse thy)) "a*b+c";
wneuper@59522
   164
if has_degree_in t v = 0 then () else error "has_degree_in (a*b+c) x";
wneuper@59522
   165
walther@60230
   166
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   167
val t = (Thm.term_of o the o (TermC.parse thy)) "a*b+c";
wneuper@59522
   168
if has_degree_in t v = 0 then () else error "has_degree_in (a*b+c) AA";
wneuper@59522
   169
wneuper@59522
   170
(*----------*)
walther@60230
   171
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   172
val t = (Thm.term_of o the o (TermC.parse thy)) "a*x+c";
wneuper@59522
   173
if has_degree_in t v = ~1 then () else error "has_degree_in (a*x+c) x";
wneuper@59522
   174
walther@60230
   175
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   176
val t = (Thm.term_of o the o (TermC.parse thy)) "a*AA+c";
wneuper@59522
   177
if has_degree_in t v = ~1 then () else error "has_degree_in (a*AA+c) AA";
wneuper@59522
   178
wneuper@59522
   179
(*----------*)
walther@60230
   180
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60242
   181
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*x \<up> 7";
walther@60242
   182
if has_degree_in t v = 7 then () else error "has_degree_in ((a*b+c)*x \<up> 7) x";
wneuper@59522
   183
walther@60230
   184
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60242
   185
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*AA \<up> 7";
walther@60242
   186
if has_degree_in t v = 7 then () else error "has_degree_in ((a*b+c)*AA \<up> 7) AA";
wneuper@59522
   187
wneuper@59522
   188
(*----------*)
walther@60230
   189
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60242
   190
val t = (Thm.term_of o the o (TermC.parse thy)) "x \<up> 7";
walther@60242
   191
if has_degree_in t v = 7 then () else error "has_degree_in (x \<up> 7) x";
wneuper@59522
   192
walther@60230
   193
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60242
   194
val t = (Thm.term_of o the o (TermC.parse thy)) "AA \<up> 7";
walther@60242
   195
if has_degree_in t v = 7 then () else error "has_degree_in (AA \<up> 7) AA";
wneuper@59522
   196
wneuper@59522
   197
(*----------*)
walther@60230
   198
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   199
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*x";
wneuper@59522
   200
if has_degree_in t v = 1 then () else error "has_degree_in ((a*b+c)*x) x";
wneuper@59522
   201
walther@60230
   202
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   203
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*AA";
wneuper@59522
   204
if has_degree_in t v = 1 then () else error "has_degree_in ((a*b+c)*AA) AA";
wneuper@59522
   205
wneuper@59522
   206
(*----------*)
walther@60230
   207
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   208
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+x)*x";
wneuper@59522
   209
if has_degree_in t v = ~1 then () else error "has_degree_in (a*b+x)*x() x";
wneuper@59522
   210
walther@60230
   211
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   212
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+AA)*AA";
wneuper@59522
   213
if has_degree_in t v = ~1 then () else error "has_degree_in ((a*b+AA)*AA) AA";
wneuper@59522
   214
wneuper@59522
   215
(*----------*)
walther@60230
   216
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   217
val t = (Thm.term_of o the o (TermC.parse thy)) "x";
wneuper@59522
   218
if has_degree_in t v = 1 then () else error "has_degree_in (x) x";
wneuper@59522
   219
walther@60230
   220
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   221
val t = (Thm.term_of o the o (TermC.parse thy)) "AA";
wneuper@59522
   222
if has_degree_in t v = 1 then () else error "has_degree_in (AA) AA";
wneuper@59522
   223
wneuper@59522
   224
(*----------*)
walther@60230
   225
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
walther@60230
   226
val t = (Thm.term_of o the o (TermC.parse thy)) "ab - (a*b)*x";
wneuper@59522
   227
if has_degree_in t v = 1 then () else error "has_degree_in (ab - (a*b)*x) x";
wneuper@59522
   228
walther@60230
   229
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
walther@60230
   230
val t = (Thm.term_of o the o (TermC.parse thy)) "ab - (a*b)*AA";
wneuper@59522
   231
if has_degree_in t v = 1 then () else error "has_degree_in (ab - (a*b)*AA) AA";
wneuper@59522
   232
walther@60318
   233
"-------- fun mono_deg_in ----------------------------------------------------------------------";
walther@60318
   234
"-------- fun mono_deg_in ----------------------------------------------------------------------";
walther@60318
   235
"-------- fun mono_deg_in ----------------------------------------------------------------------";
walther@60230
   236
val v = (Thm.term_of o the o (TermC.parse thy)) "x";
wneuper@59522
   237
walther@60242
   238
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*x \<up> 7";
walther@60242
   239
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in ((a*b+c)*x \<up> 7) x changed";
wneuper@59522
   240
walther@60242
   241
val t = (Thm.term_of o the o (TermC.parse thy)) "x \<up> 7";
walther@60242
   242
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in (x \<up> 7) x changed";
wneuper@59522
   243
walther@60230
   244
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*x";
wneuper@59522
   245
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in ((a*b+c)*x) x changed";
wneuper@59522
   246
walther@60230
   247
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+x)*x";
wneuper@59522
   248
if mono_deg_in t v = NONE then () else error "mono_deg_in ((a*b+x)*x) x changed";
wneuper@59522
   249
walther@60230
   250
val t = (Thm.term_of o the o (TermC.parse thy)) "x";
wneuper@59522
   251
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in (x) x changed";
wneuper@59522
   252
walther@60230
   253
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)";
wneuper@59522
   254
if mono_deg_in t v = SOME 0 then () else error "mono_deg_in ((a*b+c)) x changed";
wneuper@59522
   255
walther@60230
   256
val t = (Thm.term_of o the o (TermC.parse thy)) "ab - (a*b)*x";
wneuper@59522
   257
if mono_deg_in t v = NONE then () else error "mono_deg_in (ab - (a*b)*x) x changed";
wneuper@59522
   258
wneuper@59522
   259
(*. . . . . . . . . . . . the same with Const ("Partial_Functions.AA", _) . . . . . . . . . . . *)
wneuper@59522
   260
val thy = @{theory Partial_Fractions}
walther@60230
   261
val v = (Thm.term_of o the o (TermC.parse thy)) "AA";
wneuper@59522
   262
walther@60242
   263
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*AA \<up> 7";
walther@60242
   264
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in ((a*b+c)*AA \<up> 7) AA changed";
wneuper@59522
   265
walther@60242
   266
val t = (Thm.term_of o the o (TermC.parse thy)) "AA \<up> 7";
walther@60242
   267
if mono_deg_in t v = SOME 7 then () else error "mono_deg_in (AA \<up> 7) AA changed";
wneuper@59522
   268
walther@60230
   269
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)*AA";
wneuper@59522
   270
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in ((a*b+c)*AA) AA changed";
wneuper@59522
   271
walther@60230
   272
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+AA)*AA";
wneuper@59522
   273
if mono_deg_in t v = NONE then () else error "mono_deg_in ((a*b+AA)*AA) AA changed";
wneuper@59522
   274
walther@60230
   275
val t = (Thm.term_of o the o (TermC.parse thy)) "AA";
wneuper@59522
   276
if mono_deg_in t v = SOME 1 then () else error "mono_deg_in (AA) AA changed";
wneuper@59522
   277
walther@60230
   278
val t = (Thm.term_of o the o (TermC.parse thy)) "(a*b+c)";
wneuper@59522
   279
if mono_deg_in t v = SOME 0 then () else error "mono_deg_in ((a*b+c)) AA changed";
wneuper@59522
   280
walther@60230
   281
val t = (Thm.term_of o the o (TermC.parse thy)) "ab - (a*b)*AA";
wneuper@59522
   282
if mono_deg_in t v = NONE then () else error "mono_deg_in (ab - (a*b)*AA) AA changed";
wneuper@59522
   283
walther@60318
   284
"-------- rewrite_set_ has_degree_in Const ('Partial_Fractions', _) ----------------------------";
walther@60318
   285
"-------- rewrite_set_ has_degree_in Const ('Partial_Fractions', _) ----------------------------";
walther@60318
   286
"-------- rewrite_set_ has_degree_in Const ('Partial_Fractions', _) ----------------------------";
wneuper@59522
   287
val thy = @{theory Partial_Fractions}
walther@60242
   288
val expr = (Thm.term_of o the o (TermC.parse thy)) "((-8 - 2*x + x \<up> 2) has_degree_in x) = 2";
wneuper@59522
   289
val SOME (Const ("HOL.True", _), []) = rewrite_set_ thy false PolyEq_prls expr;
wneuper@59522
   290
walther@60242
   291
val expr = (Thm.term_of o the o (TermC.parse thy)) "((-8 - 2*AA + AA \<up> 2) has_degree_in AA) = 2";
wneuper@59522
   292
val SOME (Const ("HOL.True", _), []) = rewrite_set_ thy false PolyEq_prls expr;
wneuper@59522
   293
walther@60318
   294
"-------- eval_ for is_expanded_in, is_poly_in, has_degree_in ----------------------------------";
walther@60318
   295
"-------- eval_ for is_expanded_in, is_poly_in, has_degree_in ----------------------------------";
walther@60318
   296
"-------- eval_ for is_expanded_in, is_poly_in, has_degree_in ----------------------------------";
walther@60242
   297
val t = (Thm.term_of o the o (TermC.parse thy)) "(-8 - 2*x + x \<up> 2) is_expanded_in x";
wneuper@59522
   298
val SOME (id, t') = eval_is_expanded_in 0 0 t 0;
walther@60317
   299
if UnparseC.term t' = "- 8 - 2 * x + x \<up> 2 is_expanded_in x = True"
walther@60317
   300
         andalso id = "- 8 - 2 * x + x \<up> 2 is_expanded_in x = True"
wneuper@59522
   301
then () else error "eval_is_expanded_in x ..changed";
wneuper@59522
   302
wneuper@59522
   303
val thy = @{theory Partial_Fractions}
walther@60242
   304
val t = (Thm.term_of o the o (TermC.parse thy)) "(-8 - 2*AA + AA \<up> 2) is_expanded_in AA";
wneuper@59522
   305
val SOME (id, t') = eval_is_expanded_in 0 0 t 0;
walther@60317
   306
if  UnparseC.term t' = "- 8 - 2 * AA + AA \<up> 2 is_expanded_in AA = True"
walther@60317
   307
          andalso id = "- 8 - 2 * AA + AA \<up> 2 is_expanded_in AA = True"
wneuper@59522
   308
then () else error "eval_is_expanded_in AA ..changed";
wneuper@59522
   309
wneuper@59522
   310
walther@60242
   311
val t = (Thm.term_of o the o (TermC.parse thy)) "(8 + 2*x + x \<up> 2) is_poly_in x";
wneuper@59522
   312
val SOME (id, t') = eval_is_poly_in 0 0 t 0;
walther@60242
   313
if  UnparseC.term t' = "8 + 2 * x + x \<up> 2 is_poly_in x = True"
walther@60242
   314
          andalso id = "8 + 2 * x + x \<up> 2 is_poly_in x = True"
wneuper@59522
   315
then () else error "is_poly_in x ..changed";
wneuper@59522
   316
walther@60242
   317
val t = (Thm.term_of o the o (TermC.parse thy)) "(8 + 2*AA + AA \<up> 2) is_poly_in AA";
wneuper@59522
   318
val SOME (id, t') = eval_is_poly_in 0 0 t 0;
walther@60242
   319
if  UnparseC.term t' = "8 + 2 * AA + AA \<up> 2 is_poly_in AA = True"
walther@60242
   320
          andalso id = "8 + 2 * AA + AA \<up> 2 is_poly_in AA = True"
wneuper@59522
   321
then () else error "is_poly_in AA ..changed";
wneuper@59522
   322
wneuper@59522
   323
wneuper@59522
   324
val thy = @{theory Partial_Fractions}
walther@60242
   325
val expr = (Thm.term_of o the o (TermC.parse thy)) "((-8 - 2*x + x \<up> 2) has_degree_in x) = 2";
wneuper@59522
   326
val SOME (Const ("HOL.True", _), []) = rewrite_set_ thy false PolyEq_prls expr;
wneuper@59522
   327
walther@60242
   328
val expr = (Thm.term_of o the o (TermC.parse thy)) "((-8 - 2*AA + AA \<up> 2) has_degree_in AA) = 2";
wneuper@59522
   329
val SOME (Const ("HOL.True", _), []) = rewrite_set_ thy false PolyEq_prls expr;
wneuper@59522
   330
walther@60318
   331
"-------- investigate (new 2002) uniary minus --------------------------------------------------";
walther@60318
   332
"-------- investigate (new 2002) uniary minus --------------------------------------------------";
walther@60318
   333
"-------- investigate (new 2002) uniary minus --------------------------------------------------";
wenzelm@60203
   334
val t = Thm.prop_of @{thm real_diff_0}; (*"0 - ?x = - ?x"*)
walther@60230
   335
TermC.atomty t;
wneuper@59117
   336
(*
wneuper@59117
   337
*** Const (HOL.Trueprop, bool => prop)
wneuper@59117
   338
*** . Const (HOL.eq, real => real => bool)
wneuper@59117
   339
*** . . Const (Groups.minus_class.minus, real => real => real)
wneuper@59117
   340
*** . . . Const (Groups.zero_class.zero, real)
neuper@37906
   341
*** . . . Var ((x, 0), real)
wneuper@59117
   342
*** . . Const (Groups.uminus_class.uminus, real => real)
wneuper@59117
   343
*** . . . Var ((x, 0), real)
wneuper@59117
   344
*)
neuper@42395
   345
case t of
neuper@42395
   346
  Const ("HOL.Trueprop", _) $
wneuper@59117
   347
    (Const ("HOL.eq", _) $ 
wneuper@59117
   348
      (Const ("Groups.minus_class.minus", _) $ Const ("Groups.zero_class.zero", _) $ 
wneuper@59117
   349
        Var (("x", 0), _)) $
wneuper@59117
   350
             (Const ("Groups.uminus_class.uminus", _) $ Var (("x", 0), _))) => ()
neuper@42395
   351
| _ => error "internal representation of \"0 - ?x = - ?x\" changed";
neuper@37906
   352
walther@60318
   353
walther@60230
   354
val t = (Thm.term_of o the o (TermC.parse thy)) "- 1";
walther@60230
   355
TermC.atomty t;
wneuper@59117
   356
(*
wneuper@59117
   357
*** 
wneuper@59117
   358
*** Free (-1, real)
wneuper@59117
   359
*** 
wneuper@59117
   360
*)
neuper@42395
   361
case t of
walther@60318
   362
 Const ("Groups.uminus_class.uminus", _) $ Const ("Groups.one_class.one", _) => ()
neuper@42395
   363
| _ => error "internal representation of \"- 1\" changed";
neuper@37906
   364
neuper@42395
   365
"======= these external values all have the same internal representation";
neuper@42395
   366
(* "1-x" causes syntyx error --- binary minus detected by blank inbetween !!!*)
neuper@42395
   367
(*----------------------------------- vvvvv -------------------------------------------*)
walther@60230
   368
val t = (Thm.term_of o the o (TermC.parse thy)) "-x";
walther@60230
   369
TermC.atomty t;
neuper@37906
   370
(**** -------------
neuper@37906
   371
*** Free ( -x, real)*)
neuper@42395
   372
case t of
neuper@42395
   373
  Const ("Groups.uminus_class.uminus", _) $ Free ("x", _) => ()
neuper@42395
   374
| _ => error "internal representation of \"-x\" changed";
neuper@42395
   375
(*----------------------------------- vvvvv -------------------------------------------*)
walther@60230
   376
val t = (Thm.term_of o the o (TermC.parse thy)) "- x";
walther@60230
   377
TermC.atomty t;
neuper@37906
   378
(**** -------------
neuper@37906
   379
*** Free ( -x, real) !!!!!!!!!!!!!!!!!!!!!!!! is the same !!!*)
neuper@42395
   380
case t of
neuper@42395
   381
  Const ("Groups.uminus_class.uminus", _) $ Free ("x", _) => ()
neuper@42395
   382
| _ => error "internal representation of \"- x\" changed";
neuper@42395
   383
(*----------------------------------- vvvvvv ------------------------------------------*)
walther@60230
   384
val t = (Thm.term_of o the o (TermC.parse thy)) "-(x)";
walther@60230
   385
TermC.atomty t;
neuper@37906
   386
(**** -------------
neuper@37906
   387
*** Free ( -x, real)*)
neuper@42395
   388
case t of
neuper@42395
   389
  Const ("Groups.uminus_class.uminus", _) $ Free ("x", _) => ()
neuper@42395
   390
| _ => error "internal representation of \"-(x)\" changed";
neuper@37906
   391
walther@60318
   392
walther@60318
   393
"-------- fun sort_variables -------------------------------------------------------------------";
walther@60318
   394
"-------- fun sort_variables -------------------------------------------------------------------";
walther@60318
   395
"-------- fun sort_variables -------------------------------------------------------------------";
walther@60318
   396
if "---" < "123" andalso "123" < "a" andalso "a" < "cba" then ()
walther@60318
   397
else error "lexicographic order CHANGED";
walther@60318
   398
walther@60318
   399
(*--------------vvvvvvvvvvvvvvv-----------------------------------------------------------------*)
walther@60318
   400
val t =  @{term "3 * b + a * 2"}; (*------------------------------------------------------------*)
walther@60318
   401
val t' =  sort_variables t;
walther@60318
   402
if UnparseC.term t' = "(3::'a) * b + (2::'a) * a" then ()
walther@60318
   403
else error "sort_variables  3 * b + a * 2  CHANGED";
walther@60318
   404
walther@60318
   405
"~~~~~~~ fun sort_variables , args:"; val (t) = (t);
walther@60318
   406
  	val ll =  map monom2list (poly2list t);
walther@60318
   407
walther@60318
   408
(*+*)UnparseC.terms (poly2list t) = "[\"(3::'a) * b\", \"a * (2::'a)\"]";
walther@60318
   409
(*+*)val [ [(Const ("Num.numeral_class.numeral", _) $ _), Free ("b", _)],
walther@60318
   410
(*+*)      [Free ("a", _), (Const ("Num.numeral_class.numeral", _) $ _)]
walther@60318
   411
(*+*)    ] = map monom2list (poly2list t);
walther@60318
   412
walther@60318
   413
  	val lls = map sort_varList ll;
walther@60318
   414
walther@60318
   415
(*+*)case map sort_varList ll of
walther@60318
   416
(*+*)  [ [Const ("Num.numeral_class.numeral", _) $ _, Free ("b", _)],
walther@60318
   417
(*+*)    [Const ("Num.numeral_class.numeral", _) $ _, Free ("a", _)]
walther@60318
   418
(*+*)  ] => ()
walther@60318
   419
(*+*)| _ => error "map sort_varList CHANGED";
walther@60318
   420
walther@60318
   421
  	val T = type_of t;
walther@60318
   422
  	val ls = map (create_monom T) lls;
walther@60318
   423
walther@60318
   424
(*+*)val [Const ("Groups.times_class.times", _) $ _ $ Free ("b", _),
walther@60318
   425
(*+*)     Const ("Groups.times_class.times", _) $ _ $ Free ("a", _)] = map (create_monom T) lls;
walther@60318
   426
walther@60318
   427
(*+*)case map (create_monom T) lls of
walther@60318
   428
(*+*)  [Const ("Groups.times_class.times", _) $ (Const ("Num.numeral_class.numeral", _) $ _) $ Free ("b", _),
walther@60318
   429
(*+*)   Const ("Groups.times_class.times", _) $ (Const ("Num.numeral_class.numeral", _) $ _) $ Free ("a", _)
walther@60318
   430
(*+*)  ] => ()
walther@60318
   431
(*+*)| _ => error "map (create_monom T) CHANGED";
walther@60318
   432
walther@60318
   433
  val xxx = (*in*) create_polynom T ls (*end*);
walther@60318
   434
walther@60318
   435
(*+*)if UnparseC.term xxx = "(3::'a) * b + (2::'a) * a" then ()
walther@60318
   436
(*+*)else error "create_polynom CHANGED";
walther@60318
   437
(* done by rewriting>              2 * a +       3 * b ? *)
walther@60318
   438
walther@60318
   439
(*---------------vvvvvvvvvvvvvvvvvvvvvv---------------------------------------------------------*)
walther@60318
   440
val t =  @{term "3 * a + - 2 * a ::real"}; (*---------------------------------------------------*)
walther@60318
   441
val t' =     sort_variables t;
walther@60318
   442
if UnparseC.term t' = "3 * a + - 2 * a" then ()
walther@60318
   443
else error "sort_variables  3 * a + - 2 * a  CHANGED";
walther@60318
   444
walther@60318
   445
"~~~~~~~ fun sort_variables , args:"; val (t) = (t);
walther@60318
   446
  	val ll =  map monom2list (poly2list t);
walther@60318
   447
walther@60318
   448
(*+*)val [ [Const ("Num.numeral_class.numeral", _) $ _, Free ("a", _)],
walther@60318
   449
(*+*)      [Const ("Groups.uminus_class.uminus", _) $ _, Free ("a", _)] (*already correct order*)
walther@60318
   450
(*+*)    ] = map monom2list (poly2list t);
walther@60318
   451
walther@60318
   452
  	val lls = map
walther@60318
   453
           sort_varList ll;
walther@60318
   454
walther@60318
   455
(*+*)val [ [Const ("Num.numeral_class.numeral", _) $ _, Free ("a", _)],
walther@60318
   456
(*+*)      [Const ("Groups.uminus_class.uminus", _) $ _, Free ("a", _)] (*ERROR: NO swap here*)
walther@60318
   457
(*+*)    ] = map sort_varList ll;
walther@60318
   458
walther@60318
   459
       map sort_varList ll;
walther@60318
   460
"~~~~~ val sort_varList , args:"; val (ts) = (nth 2 ll);
walther@60318
   461
val sorted = sort var_ord ts;
walther@60318
   462
walther@60318
   463
(*+*)if UnparseC.terms ts = "[\"- 2\", \"a\"]" andalso UnparseC.terms sorted = "[\"- 2\", \"a\"]"
walther@60318
   464
(*+*)then () else error "sort var_ord  [\"- 2\", \"a\"]  CHANGED";
walther@60318
   465
walther@60318
   466
walther@60318
   467
(*+*)if UnparseC.term (nth 1 ts) = "- 2" andalso get_basStr (nth 1 ts) = "-2"
walther@60318
   468
(*+*)then () else error "get_basStr  - 2  CHANGED";
walther@60318
   469
(*+*)if UnparseC.term (nth 2 ts) = "a" andalso get_basStr (nth 2 ts) = "a"
walther@60318
   470
(*+*)then () else error "get_basStr  a  CHANGED";
walther@60318
   471
walther@60318
   472
walther@60318
   473
"-------- rebuild fun is_addUnordered (1 + 2 * x \<up> 4 + - 4 * x \<up> 4 + x \<up> 8) ---------------------";
walther@60318
   474
"-------- rebuild fun is_addUnordered (1 + 2 * x \<up> 4 + - 4 * x \<up> 4 + x \<up> 8) ---------------------";
walther@60318
   475
"-------- rebuild fun is_addUnordered (1 + 2 * x \<up> 4 + - 4 * x \<up> 4 + x \<up> 8) ---------------------";
walther@60318
   476
(* indentation partially indicates call hierarchy:
walther@60318
   477
"~~~~~ fun is_addUnordered
walther@60318
   478
"~~~~~~~ fun is_polyexp
walther@60318
   479
"~~~~~~~ fun sort_monoms
walther@60318
   480
"~~~~~~~~~ fun sort_monList
walther@60318
   481
"~~~~~~~~~~~ fun koeff_degree_ord
walther@60318
   482
"~~~~~~~~~~~~~ fun degree_ord
walther@60318
   483
"~~~~~~~~~~~~~~~ fun dict_cond_ord
walther@60318
   484
"~~~~~~~~~~~~~~~~~ fun var_ord_revPow
walther@60318
   485
"~~~~~~~~~~~~~~~~~~~ fun get_basStr         used twice --vv
walther@60318
   486
"~~~~~~~~~~~~~~~~~~~ fun get_potStr         used twice --vv
walther@60318
   487
"~~~~~~~~~~~~~~~ fun monom_degree
walther@60318
   488
"~~~~~~~~~~~~~ fun compare_koeff_ord
walther@60318
   489
"~~~~~~~~~~~~~~~ fun get_koeff_of_mon
walther@60318
   490
"~~~~~~~~~~~~~~~~~ fun koeff2ordStr
walther@60318
   491
"~~~~~ fun is_multUnordered
walther@60318
   492
"~~~~~~~ fun sort_variables
walther@60318
   493
"~~~~~~~~~ fun sort_varList
walther@60318
   494
"~~~~~~~~~~~ fun var_ord
walther@60318
   495
"~~~~~~~~~~~~~ fun get_basStr               used twice --^^
walther@60318
   496
"~~~~~~~~~~~~~ fun get_potStr               used twice --^^
walther@60318
   497
*)
walther@60318
   498
val t = TermC.str2term "(1 + 2 * x \<up> 4 + - 4 * x \<up> 4 + x \<up> 8) is_addUnordered";
walther@60318
   499
walther@60318
   500
           eval_is_addUnordered "xxx" "yyy" t @{theory};
walther@60318
   501
"~~~~~ fun eval_is_addUnordered , args:"; val ((thmid:string), _, 
walther@60318
   502
		       (t as (Const("Poly.is_addUnordered", _) $ arg)), thy) =
walther@60318
   503
  ("xxx", "yyy", t, @{theory});
walther@60318
   504
walther@60318
   505
    (*if*) is_addUnordered arg;
walther@60318
   506
"~~~~~ fun is_addUnordered , args:"; val (t) = (arg);
walther@60318
   507
  ((is_polyexp t) andalso not (t = sort_monoms t));
walther@60318
   508
walther@60318
   509
        (t = sort_monoms t);
walther@60318
   510
"~~~~~~~ fun sort_monoms , args:"; val (t) = (t);
walther@60318
   511
  	val ll =  map monom2list (poly2list t);
walther@60318
   512
  	val lls =
walther@60318
   513
walther@60318
   514
           sort_monList ll;
walther@60318
   515
"~~~~~~~~~ fun sort_monList , args:"; val (ll) = (ll);
walther@60318
   516
      val xxx = 
walther@60318
   517
walther@60318
   518
            sort koeff_degree_ord ll(*return value*);
walther@60318
   519
"~~~~~~~~~~~ fun koeff_degree_ord , args:"; val (ll) = (ll);
walther@60318
   520
                 koeff_degree_ord: term list * term list -> order;
walther@60318
   521
(*we check all elements at once..*)
walther@60318
   522
val eee1 = ll |> nth 1;
walther@60318
   523
val eee2 = ll |> nth 2;
walther@60318
   524
val eee3 = ll |> nth 3;
walther@60318
   525
val eee3 = ll |> nth 3;
walther@60318
   526
val eee4 = ll |> nth 4;
walther@60318
   527
walther@60318
   528
if UnparseC.terms eee1 = "[\"1\"]" then () else error "eee1 CHANGED";
walther@60318
   529
if UnparseC.terms eee2 = "[\"2\", \"x \<up> 4\"]" then () else error "eee2 CHANGED";
walther@60318
   530
if UnparseC.terms eee3 = "[\"- 4\", \"x \<up> 4\"]" then () else error "eee3 CHANGED";
walther@60318
   531
if UnparseC.terms eee4 = "[\"x \<up> 8\"]" then () else error "eee4 CHANGED";
walther@60318
   532
walther@60318
   533
if koeff_degree_ord (eee1, eee1) = EQUAL   then () else error "(eee1, eee1) CHANGED";
walther@60318
   534
if koeff_degree_ord (eee1, eee2) = LESS    then () else error "(eee1, eee2) CHANGED";
walther@60318
   535
if koeff_degree_ord (eee1, eee3) = LESS    then () else error "(eee1, eee3) CHANGED";
walther@60318
   536
if koeff_degree_ord (eee1, eee4) = LESS    then () else error "(eee1, eee4) CHANGED";
walther@60318
   537
walther@60318
   538
if koeff_degree_ord (eee2, eee1) = GREATER then () else error "(eee2, eee1) CHANGED";
walther@60318
   539
if koeff_degree_ord (eee2, eee2) = EQUAL   then () else error "(eee2, eee4) CHANGED";
walther@60318
   540
if koeff_degree_ord (eee2, eee3) = LESS    then () else error "(eee2, eee3) CHANGED";
walther@60318
   541
if koeff_degree_ord (eee2, eee4) = LESS    then () else error "(eee2, eee4) CHANGED";
walther@60318
   542
walther@60318
   543
if koeff_degree_ord (eee3, eee1) = GREATER then () else error "(eee3, eee1) CHANGED";
walther@60318
   544
if koeff_degree_ord (eee3, eee2) = GREATER then () else error "(eee3, eee4) CHANGED";
walther@60318
   545
if koeff_degree_ord (eee3, eee3) = EQUAL   then () else error "(eee3, eee3) CHANGED";
walther@60318
   546
if koeff_degree_ord (eee3, eee4) = LESS    then () else error "(eee3, eee4) CHANGED";
walther@60318
   547
walther@60318
   548
if koeff_degree_ord (eee4, eee1) = GREATER then () else error "(eee4, eee1) CHANGED";
walther@60318
   549
if koeff_degree_ord (eee4, eee2) = GREATER then () else error "(eee4, eee4) CHANGED";
walther@60318
   550
if koeff_degree_ord (eee4, eee3) = GREATER then () else error "(eee4, eee3) CHANGED";
walther@60318
   551
if koeff_degree_ord (eee4, eee4) = EQUAL   then () else error "(eee4, eee4) CHANGED";
walther@60318
   552
walther@60318
   553
"~~~~~~~~~~~~~ fun degree_ord , args:"; val () = ();
walther@60318
   554
                   degree_ord: term list * term list -> order;
walther@60318
   555
walther@60318
   556
if degree_ord (eee1, eee1) = EQUAL   then () else error "degree_ord (eee1, eee1) CHANGED";
walther@60318
   557
if degree_ord (eee1, eee2) = LESS    then () else error "degree_ord (eee1, eee2) CHANGED";
walther@60318
   558
if degree_ord (eee1, eee3) = LESS    then () else error "degree_ord (eee1, eee3) CHANGED";
walther@60318
   559
if degree_ord (eee1, eee4) = LESS    then () else error "degree_ord (eee1, eee4) CHANGED";
walther@60318
   560
walther@60318
   561
if degree_ord (eee2, eee1) = GREATER then () else error "degree_ord (eee2, eee1) CHANGED";
walther@60318
   562
if degree_ord (eee2, eee2) = EQUAL   then () else error "degree_ord (eee2, eee4) CHANGED";
walther@60318
   563
if degree_ord (eee2, eee3) = EQUAL   then () else error "degree_ord (eee2, eee3) CHANGED";
walther@60318
   564
if degree_ord (eee2, eee4) = LESS    then () else error "degree_ord (eee2, eee4) CHANGED";
walther@60318
   565
walther@60318
   566
if degree_ord (eee3, eee1) = GREATER then () else error "degree_ord (eee3, eee1) CHANGED";
walther@60318
   567
if degree_ord (eee3, eee2) = EQUAL   then () else error "degree_ord (eee3, eee4) CHANGED";
walther@60318
   568
if degree_ord (eee3, eee3) = EQUAL   then () else error "degree_ord (eee3, eee3) CHANGED";
walther@60318
   569
if degree_ord (eee3, eee4) = LESS    then () else error "degree_ord (eee3, eee4) CHANGED";
walther@60318
   570
walther@60318
   571
if degree_ord (eee4, eee1) = GREATER then () else error "degree_ord (eee4, eee1) CHANGED";
walther@60318
   572
if degree_ord (eee4, eee2) = GREATER then () else error "degree_ord (eee4, eee4) CHANGED";
walther@60318
   573
if degree_ord (eee4, eee3) = GREATER then () else error "degree_ord (eee4, eee3) CHANGED";
walther@60318
   574
if degree_ord (eee4, eee4) = EQUAL   then () else error "degree_ord (eee4, eee4) CHANGED";
walther@60318
   575
walther@60318
   576
"~~~~~~~~~~~~~~~ fun dict_cond_ord , args:"; val () = ();
walther@60318
   577
dict_cond_ord: (term * term -> order) -> (term -> bool) -> term list * term list -> order;
walther@60318
   578
dict_cond_ord var_ord_revPow: (term -> bool) -> term list * term list -> order;
walther@60318
   579
dict_cond_ord var_ord_revPow is_nums: term list * term list -> order;
walther@60318
   580
val xxx = dict_cond_ord var_ord_revPow is_nums;
walther@60318
   581
(* output from:
walther@60318
   582
fun var_ord_revPow (a,b: term) =
walther@60318
   583
 (@ {print} {a = "var_ord_revPow ", ab = "(" ^ UnparseC.term a ^ ", " ^ UnparseC.term b ^ ")"};
walther@60318
   584
  @ {print} {z = "(" ^ get_basStr a ^ ", " ^ get_potStr a ^ "), (" ^ get_basStr b ^ ", " ^ get_potStr b ^ ")"};
walther@60318
   585
  prod_ord string_ord string_ord_rev 
walther@60318
   586
    ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b)));
walther@60318
   587
*)
walther@60318
   588
if xxx (eee1, eee1) = EQUAL then () else error "dict_cond_ord ..(eee1, eee1) CHANGED";
walther@60318
   589
if xxx (eee1, eee2) = LESS  then () else error "dict_cond_ord ..(eee1, eee2) CHANGED";
walther@60318
   590
if xxx (eee1, eee3) = LESS  then () else error "dict_cond_ord ..(eee1, eee3) CHANGED";
walther@60318
   591
if xxx (eee1, eee4) = LESS  then () else error "dict_cond_ord ..(eee1, eee4) CHANGED";
walther@60318
   592
(*-------------------------------------------------------------------------------------*)
walther@60318
   593
if xxx (eee2, eee1) = GREATER then () else error "dict_cond_ord ..(eee2, eee1) CHANGED";
walther@60318
   594
if xxx (eee2, eee2) = EQUAL   then () else error "dict_cond_ord ..(eee2, eee2) CHANGED";
walther@60318
   595
if xxx (eee2, eee3) = EQUAL   then () else error "dict_cond_ord ..(eee2, eee3) CHANGED";
walther@60318
   596
if xxx (eee2, eee4) = GREATER then () else error "dict_cond_ord ..(eee2, eee4) CHANGED";
walther@60318
   597
(*-------------------------------------------------------------------------------------*)
walther@60318
   598
if xxx (eee3, eee1) = GREATER then () else error "dict_cond_ord ..(eee3, eee1) CHANGED";
walther@60318
   599
if xxx (eee3, eee2) = EQUAL   then () else error "dict_cond_ord ..(eee3, eee2) CHANGED";
walther@60318
   600
if xxx (eee3, eee3) = EQUAL   then () else error "dict_cond_ord ..(eee3, eee3) CHANGED";
walther@60318
   601
if xxx (eee3, eee4) = GREATER then () else error "dict_cond_ord ..(eee3, eee4) CHANGED";
walther@60318
   602
(*-------------------------------------------------------------------------------------*)
walther@60318
   603
if xxx (eee4, eee1) = GREATER then () else error "dict_cond_ord ..(eee4, eee1) CHANGED";
walther@60318
   604
if xxx (eee4, eee2) = LESS    then () else error "dict_cond_ord ..(eee4, eee2) CHANGED";
walther@60318
   605
if xxx (eee4, eee3) = LESS    then () else error "dict_cond_ord ..(eee4, eee3) CHANGED";
walther@60318
   606
if xxx (eee4, eee4) = EQUAL   then () else error "dict_cond_ord ..(eee4, eee4) CHANGED";
walther@60318
   607
(*-------------------------------------------------------------------------------------*)
walther@60318
   608
walther@60318
   609
"~~~~~~~~~~~~~~~ fun monom_degree , args:"; val () = ();
walther@60318
   610
(* we check all at once//*)
walther@60318
   611
if monom_degree eee1 = 0 then () else error "monom_degree eee1 CHANGED";
walther@60318
   612
if monom_degree eee2 = 4 then () else error "monom_degree eee2 CHANGED";
walther@60318
   613
if monom_degree eee3 = 4 then () else error "monom_degree eee3 CHANGED";
walther@60318
   614
if monom_degree eee4 = 8 then () else error "monom_degree eee4 CHANGED";
walther@60318
   615
walther@60318
   616
"~~~~~~~~~~~~~ fun compare_koeff_ord , args:"; val () = ();
walther@60318
   617
                   compare_koeff_ord: term list * term list -> order;
walther@60318
   618
(* we check all at once//*)
walther@60318
   619
if compare_koeff_ord (eee1, eee1) = EQUAL   then () else error "_koeff_ord (eee1, eee1) CHANGED";
walther@60318
   620
if compare_koeff_ord (eee1, eee2) = LESS    then () else error "_koeff_ord (eee1, eee2) CHANGED";
walther@60318
   621
if compare_koeff_ord (eee1, eee3) = LESS    then () else error "_koeff_ord (eee1, eee3) CHANGED";
walther@60318
   622
if compare_koeff_ord (eee1, eee4) = GREATER then () else error "_koeff_ord (eee1, eee4) CHANGED";
walther@60318
   623
walther@60318
   624
if compare_koeff_ord (eee2, eee1) = GREATER then () else error "_koeff_ord (eee2, eee1) CHANGED";
walther@60318
   625
if compare_koeff_ord (eee2, eee2) = EQUAL   then () else error "_koeff_ord (eee2, eee2) CHANGED";
walther@60318
   626
if compare_koeff_ord (eee2, eee3) = LESS    then () else error "_koeff_ord (eee2, eee3) CHANGED";
walther@60318
   627
if compare_koeff_ord (eee2, eee4) = GREATER then () else error "_koeff_ord (eee2, eee4) CHANGED";
walther@60318
   628
walther@60318
   629
if compare_koeff_ord (eee3, eee1) = GREATER then () else error "_koeff_ord (eee3, eee1) CHANGED";
walther@60318
   630
if compare_koeff_ord (eee3, eee2) = GREATER then () else error "_koeff_ord (eee3, eee2) CHANGED";
walther@60318
   631
if compare_koeff_ord (eee3, eee3) = EQUAL   then () else error "_koeff_ord (eee3, eee3) CHANGED";
walther@60318
   632
if compare_koeff_ord (eee3, eee4) = GREATER then () else error "_koeff_ord (eee3, eee4) CHANGED";
walther@60318
   633
walther@60318
   634
if compare_koeff_ord (eee4, eee1) = LESS    then () else error "_koeff_ord (eee4, eee1) CHANGED";
walther@60318
   635
if compare_koeff_ord (eee4, eee2) = LESS    then () else error "_koeff_ord (eee4, eee2) CHANGED";
walther@60318
   636
if compare_koeff_ord (eee4, eee3) = LESS    then () else error "_koeff_ord (eee4, eee3) CHANGED";
walther@60318
   637
if compare_koeff_ord (eee4, eee4) = EQUAL   then () else error "_koeff_ord (eee4, eee4) CHANGED";
walther@60318
   638
walther@60318
   639
"~~~~~~~~~~~~~~~ fun get_koeff_of_mon , args:"; val () = ();
walther@60318
   640
           get_koeff_of_mon: term list -> term option;
walther@60318
   641
walther@60318
   642
val SOME xxx1 = get_koeff_of_mon eee1;
walther@60318
   643
val SOME xxx2 = get_koeff_of_mon eee2;
walther@60318
   644
val SOME xxx3 = get_koeff_of_mon eee3;
walther@60318
   645
val NONE = get_koeff_of_mon eee4;
walther@60318
   646
walther@60318
   647
if UnparseC.term xxx1 = "1"   then () else error "get_koeff_of_mon eee1 CHANGED";
walther@60318
   648
if UnparseC.term xxx2 = "2"   then () else error "get_koeff_of_mon eee2 CHANGED";
walther@60318
   649
if UnparseC.term xxx3 = "- 4" then () else error "get_koeff_of_mon eee3 CHANGED";
walther@60318
   650
walther@60318
   651
"~~~~~~~~~~~~~~~~~ fun koeff2ordStr , args:"; val () = ();
walther@60318
   652
                       koeff2ordStr: term option -> string;
walther@60318
   653
if koeff2ordStr (SOME xxx1) = "1"   then () else error "koeff2ordStr eee1 CHANGED";
walther@60318
   654
if koeff2ordStr (SOME xxx2) = "2"   then () else error "koeff2ordStr eee2 CHANGED";
walther@60318
   655
if koeff2ordStr (SOME xxx3) = "40"  then () else error "koeff2ordStr eee3 CHANGED";
walther@60318
   656
if koeff2ordStr NONE        = "---" then () else error "koeff2ordStr eee4 CHANGED";
walther@60318
   657
walther@60318
   658
walther@60318
   659
"-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
walther@60318
   660
"-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
walther@60318
   661
"-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
walther@60318
   662
val t = TermC.str2term "x \<up> 2 * y \<up> 2 + x * x \<up> 2 * y";
walther@60318
   663
Rewrite.trace_on := false;
walther@60318
   664
val SOME (t, _) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60318
   665
   UnparseC.term t = "x \<up> 2 * y \<up> 2 + x \<up> 3 * y";
walther@60318
   666
if UnparseC.term t = "x \<up> 3 * y + x \<up> 2 * y \<up> 2" then ()
walther@60318
   667
else error "poly.sml: diff.behav. in make_polynomial 23";
walther@60318
   668
walther@60318
   669
(** )
walther@60318
   670
##  rls: order_add_rls_ on: x \<up> 2 * y \<up> 2 + x \<up> 3 * y 
walther@60318
   671
###  rls: order_add_ on: x \<up> 2 * y \<up> 2 + x \<up> 3 * y 
walther@60318
   672
######  rls: Rule_Set.empty-is_addUnordered on: x \<up> 2 * y \<up> 2 + x \<up> 3 * y is_addUnordered 
walther@60318
   673
#######  try calc: "Poly.is_addUnordered" 
walther@60318
   674
########  eval asms: "x \<up> 2 * y \<up> 2 + x \<up> 3 * y is_addUnordered = False"  (*isa*)
walther@60318
   675
                                                                              True"   (*isa2*)
walther@60318
   676
#######  calc. to: False  (*isa*)
walther@60318
   677
                   True   (*isa2*)
walther@60318
   678
( **)
walther@60318
   679
        if is_addUnordered (TermC.str2term "x \<up> 2 * y \<up> 2 + x \<up> 3 * y ::real") then ()
walther@60318
   680
else error"is_addUnordered  x \<up> 2 * y \<up> 2 + x \<up> 3 * y"; (*isa == isa2*)
walther@60318
   681
"~~~~~ fun is_addUnordered , args:"; val (t) = (TermC.str2term "x \<up> 2 * y \<up> 2 + x \<up> 3 * y ::real");
walther@60318
   682
      ((is_polyexp t) andalso not (t = sort_monoms t)) = false;  (*isa == isa2*)
walther@60318
   683
walther@60318
   684
(*+*) if is_polyexp t = true then () else error "is_polyexp  x \<up> 2 * y \<up> 2 + x \<up> 3 * y";
walther@60318
   685
walther@60318
   686
(*+*) if                           t = sort_monoms t = false then () else error "sort_monoms 123";
walther@60318
   687
"~~~~~~~ fun sort_monoms , args:"; val (t) = (t);
walther@60318
   688
  	val ll =  map monom2list (poly2list t);
walther@60318
   689
  	val lls = sort_monList ll;
walther@60318
   690
walther@60318
   691
(*+*)map UnparseC.terms lls = ["[\"x \<up> 2\", \"y \<up> 2\"]", "[\"x \<up> 3\", \"y\"]"]; (*isa*)
walther@60318
   692
(*+*)map UnparseC.terms lls = ["[\"x \<up> 3\", \"y\"]", "[\"x \<up> 2\", \"y \<up> 2\"]"]; (*isa2*)
walther@60318
   693
walther@60318
   694
"~~~~~~~~~~~ fun koeff_degree_ord , args:"; val () = ();
walther@60318
   695
(* we check all elements at once..*)
walther@60318
   696
val eee1 = ll |> nth 1; UnparseC.terms eee1 = "[\"x \<up> 2\", \"y \<up> 2\"]";
walther@60318
   697
val eee2 = ll |> nth 2; UnparseC.terms eee2 = "[\"x \<up> 3\", \"y\"]";    
walther@60318
   698
walther@60318
   699
(*1*)if koeff_degree_ord (eee1, eee1) = EQUAL   then () else error "(eee1, eee1) CHANGED";
walther@60318
   700
(*2*)if koeff_degree_ord (eee1, eee2) = GREATER then () else error "(eee1, eee2) CHANGED";
walther@60318
   701
(*3*)if koeff_degree_ord (eee2, eee1) = LESS    then () else error "(eee2, eee1) CHANGED"; (*isa*)
walther@60318
   702
(*4*)if koeff_degree_ord (eee2, eee2) = EQUAL   then () else error "(eee2, eee2) CHANGED";
walther@60318
   703
(* isa -- isa2:
walther@60318
   704
(*1*){a = "var_ord_revPow ", at_bt = "(x \<up> 2, x \<up> 2)", sort_args = "(x, 2), (x, 2)"}                                           (*isa == isa2*)
walther@60318
   705
(*1*){a = "var_ord_revPow ", at_bt = "(y \<up> 2, y \<up> 2)", sort_args = "(y, 2), (y, 2)"}                                            (*isa == isa2*)
walther@60318
   706
(*1*){a = "compare_koeff_ord ", ats_bts = "([\"x \<up> 2\", \"y \<up> 2\"], [\"x \<up> 2\", \"y \<up> 2\"])", sort_args = "(---, ---)"} (*isa == isa2*) 
walther@60318
   707
walther@60318
   708
(*2*){a = "var_ord_revPow ", at_bt = "(x \<up> 2, x \<up> 3)", sort_args = "(x, 2), (x, 3)"}                                           (*isa == isa2*) 
walther@60318
   709
walther@60318
   710
(*3*)k{a = "var_ord_revPow ", at_bt = "(x \<up> 3, x \<up> 2)", sort_args = "(x, 3), (x, 2)"}                                           (*isa == isa2*) 
walther@60318
   711
walther@60318
   712
(*4*){a = "var_ord_revPow ", at_bt = "(x \<up> 3, x \<up> 3)", sort_args = "(x, 3), (x, 3)"}                                           (*isa == isa2*)
walther@60318
   713
(*4*){a = "var_ord_revPow ", at_bt = "(y, y)", sort_args = "(y, ---), (y, ---)"}                                                       (*isa == isa2*)
walther@60318
   714
(*4*){a = "compare_koeff_ord ", ats_bts = "([\"x \<up> 3\", \"y\"], [\"x \<up> 3\", \"y\"])", sort_args = "(---, ---)"}                (*isa == isa2*) 
walther@60318
   715
val it = true: bool
walther@60318
   716
val it = true: bool
walther@60318
   717
val it = true: bool
walther@60318
   718
val it = true: bool*)
walther@60318
   719
walther@60318
   720
"~~~~~~~~~~~~~ fun degree_ord , args:"; val () = ();
walther@60318
   721
(*1*)if degree_ord (eee1, eee1) = EQUAL   then () else error "degree_ord (eee1, eee1) CHANGED";
walther@60318
   722
(*2*)if degree_ord (eee1, eee2) = GREATER    then () else error "degree_ord (eee1, eee2) CHANGED";(*isa*)
walther@60318
   723
(*{a = "int_ord (4, 10003) = ", z = LESS}      isa
walther@60318
   724
  {a = "int_ord (4, 4) = ", z = EQUAL}         isa2*)
walther@60318
   725
(*3*)if degree_ord (eee2, eee1) = LESS then () else error "degree_ord (eee2, eee1) CHANGED";(*isa*)
walther@60318
   726
(*4*)if degree_ord (eee2, eee2) = EQUAL   then () else error "degree_ord (eee2, eee2) CHANGED";
walther@60318
   727
(* isa -- isa2:
walther@60318
   728
(*1*){a = "int_ord (10002, 10002) = ", z = EQUAL}                                                          (*isa*)
walther@60318
   729
     {a = "int_ord (4, 4) = ", z = EQUAL}                                                                    (*isa2*)
walther@60318
   730
(*1*){a = "dict_cond_ord", args = "([\"x \<up> 2\", \"y \<up> 2\"], [\"x \<up> 2\", \"y \<up> 2\"])", is_nums = "(false, false)"}  (*isa*)
walther@60318
   731
(*1*){a = "var_ord_revPow ", at_bt = "(x \<up> 2, x \<up> 2)", sort_args = "(x, 2), (x, 2)"}               (*isa*)
walther@60318
   732
(*1*){a = "dict_cond_ord", args = "([\"y \<up> 2\"], [\"y \<up> 2\"])", is_nums = "(false, false)"}        (*isa*)
walther@60318
   733
(*1*){a = "var_ord_revPow ", at_bt = "(y \<up> 2, y \<up> 2)", sort_args = "(y, 2), (y, 2)"}               (*isa*)
walther@60318
   734
(*1*){a = "dict_cond_ord ([], [])"}                                                                        (*isa*)
walther@60318
   735
walther@60318
   736
(*2*){a = "int_ord (10002, 10003) = ", z = LESS}                                                           (*isa*)
walther@60318
   737
     {a = "int_ord (4, 4) = ", z = EQUAL}                                                                    (*isa2*)
walther@60318
   738
     {a = "dict_cond_ord", args = "([\"x \<up> 2\", \"y \<up> 2\"], [\"x \<up> 3\", \"y\"])", is_nums = "(false, false)"} (*isa2*)
walther@60318
   739
(*2*){a = "var_ord_revPow ", at_bt = "(x \<up> 2, x \<up> 3)", sort_args = "(x, 2), (x, 3)"}                 (*isa2*)
walther@60318
   740
walther@60318
   741
(*3*){a = "int_ord (10003, 10002) = ", z = GREATER}                                                       (*isa*)
walther@60318
   742
     {a = "int_ord (4, 4) = ", z = EQUAL}                                                                    (*isa2*)
walther@60318
   743
     {a = "dict_cond_ord", args = "([\"x \<up> 3\", \"y\"], [\"x \<up> 2\", \"y \<up> 2\"])", is_nums = "(false, false)"}
walther@60318
   744
(*3*){a = "var_ord_revPow ", at_bt = "(x \<up> 3, x \<up> 2)", sort_args = "(x, 3), (x, 2)"}                (*isa == isa2*)
walther@60318
   745
walther@60318
   746
(*4*){a = "int_ord (10003, 10003) = ", z = EQUAL}                                                         (*isa*)
walther@60318
   747
     {a = "int_ord (4, 4) = ", z = EQUAL}                                                                    (*isa2*)
walther@60318
   748
(*4*){a = "dict_cond_ord", args = "([\"x \<up> 3\", \"y\"], [\"x \<up> 3\", \"y\"])", is_nums = "(false, false)"} (*isa == isa2*)
walther@60318
   749
(*4*){a = "var_ord_revPow ", at_bt = "(x \<up> 3, x \<up> 3)", sort_args = "(x, 3), (x, 3)"}              (*isa == isa2*)
walther@60318
   750
(*4*){a = "dict_cond_ord", args = "([\"y\"], [\"y\"])", is_nums = "(false, false)"}                       (*isa == isa2*)
walther@60318
   751
(*4*){a = "var_ord_revPow ", at_bt = "(y, y)", sort_args = "(y, ---), (y, ---)"}                          (*isa == isa2*)
walther@60318
   752
(*4*){a = "dict_cond_ord ([], [])"}                                                                       (*isa == isa2*)
walther@60318
   753
walther@60318
   754
val it = true: bool
walther@60318
   755
val it = false: bool
walther@60318
   756
val it = false: bool
walther@60318
   757
val it = true: bool
walther@60318
   758
*)
walther@60318
   759
walther@60318
   760
(*+*) if monom_degree eee1 = 4 then () else error "monom_degree [\"x \<up> 2\", \"y \<up> 2\"] CHANGED";
walther@60318
   761
"~~~~~~~~~~~~~~~ fun monom_degree , args:"; val (l) = (eee1);
walther@60318
   762
"~~~~~ fun counter , args:"; val (n, x :: xs) = (0, l); (*--------------------------OPEN local\* )
walther@60318
   763
	    (*if*) (is_nums x) (*else*);
walther@60318
   764
  val (Const ("Transcendental.powr", _) $ Free _ $ t) =
walther@60318
   765
      (*case*) x (*of*); 
walther@60318
   766
(*+*)UnparseC.term x = "x \<up> 2";
walther@60318
   767
            (*if*) TermC.is_num t (*then*);
walther@60318
   768
walther@60318
   769
           counter (t |> HOLogic.dest_number |> snd |> curry op + n, xs);
walther@60318
   770
"~~~~~ fun counter , args:"; val (n, x :: xs) = (t |> HOLogic.dest_number |> snd |> curry op + n, xs);
walther@60318
   771
	    (*if*) (is_nums x) (*else*);
walther@60318
   772
  val (Const ("Transcendental.powr", _) $ Free _ $ t) =
walther@60318
   773
      (*case*) x (*of*); 
walther@60318
   774
(*+*)UnparseC.term x = "y \<up> 2";
walther@60318
   775
            (*if*) TermC.is_num t (*then*);
walther@60318
   776
walther@60318
   777
  val return =
walther@60318
   778
      counter (t |> HOLogic.dest_number |> snd |> curry op + n, xs);
walther@60318
   779
if return = 4 then () else error "monom_degree [\"x \<up> 2\", \"y \<up> 2\"] CHANGED";
walther@60318
   780
( *---------------------------------------------------------------------------------OPEN local/*)
walther@60318
   781
walther@60318
   782
(*+*)if monom_degree eee2 = 4 andalso monom_degree eee2 = 4 then ()
walther@60318
   783
else error "monom_degree  [\"x \<up> 3\", \"y\"] CHANGED";
walther@60318
   784
"~~~~~~~~~~~~~~~ fun monom_degree , args:"; val (l) = (eee2);
walther@60318
   785
"~~~~~ fun counter , args:"; val (n, x :: xs) = (0, l); (*--------------------------OPEN local\* )
walther@60318
   786
	    (*if*) (is_nums x) (*else*);
walther@60318
   787
val (Const ("Transcendental.powr", _) $ Free _ $ t) =
walther@60318
   788
      (*case*) x (*of*); 
walther@60318
   789
(*+*)UnparseC.term x = "x \<up> 3";
walther@60318
   790
            (*if*) TermC.is_num t (*then*);
walther@60318
   791
walther@60318
   792
      counter (t |> HOLogic.dest_number |> snd |> curry op + n, xs);
walther@60318
   793
"~~~~~ fun counter , args:"; val (n, x :: xs) = (t |> HOLogic.dest_number |> snd |> curry op + n, xs);
walther@60318
   794
	    (*if*) (is_nums x) (*else*);
walther@60318
   795
val _ = (*the default case*)
walther@60318
   796
      (*case*) x (*of*); 
walther@60318
   797
( *---------------------------------------------------------------------------------OPEN local/*)
walther@60318
   798
walther@60318
   799
"~~~~~~~~~~~~~~~ fun dict_cond_ord , args:"; val () = ();
walther@60318
   800
val xxx = dict_cond_ord var_ord_revPow is_nums;
walther@60318
   801
(*1*)if xxx (eee1, eee1) = EQUAL   then () else error "dict_cond_ord (eee1, eee1) CHANGED";
walther@60318
   802
(*2*)if xxx (eee1, eee2) = GREATER then () else error "dict_cond_ord (eee1, eee2) CHANGED";
walther@60318
   803
(*3*)if xxx (eee2, eee1) = LESS    then () else error "dict_cond_ord (eee2, eee1) CHANGED";
walther@60318
   804
(*4*)if xxx (eee2, eee2) = EQUAL   then () else error "dict_cond_ord (eee2, eee2) CHANGED";
walther@60318
   805
walther@60318
   806
walther@60318
   807
"-------- check make_polynomial with simple terms ----------------------------------------------";
walther@60318
   808
"-------- check make_polynomial with simple terms ----------------------------------------------";
walther@60318
   809
"-------- check make_polynomial with simple terms ----------------------------------------------";
neuper@38036
   810
"----- check 1 ---";
walther@60230
   811
val t = TermC.str2term "2*3*a";
neuper@38036
   812
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@59868
   813
if UnparseC.term t = "6 * a" then () else error "check make_polynomial 1";
neuper@38036
   814
neuper@38036
   815
"----- check 2 ---";
walther@60230
   816
val t = TermC.str2term "2*a + 3*a";
neuper@38036
   817
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@59868
   818
if UnparseC.term t = "5 * a" then () else error "check make_polynomial 2";
neuper@38036
   819
neuper@38036
   820
"----- check 3 ---";
walther@60230
   821
val t = TermC.str2term "2*a + 3*a + 3*a";
neuper@38036
   822
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@59868
   823
if UnparseC.term t = "8 * a" then () else error "check make_polynomial 3";
neuper@38036
   824
neuper@38036
   825
"----- check 4 ---";
walther@60230
   826
val t = TermC.str2term "3*a - 2*a";
neuper@38036
   827
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@59868
   828
if UnparseC.term t = "a" then () else error "check make_polynomial 4";
neuper@38036
   829
neuper@38036
   830
"----- check 5 ---";
walther@60230
   831
val t = TermC.str2term "4*(3*a - 2*a)";
neuper@38036
   832
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@59868
   833
if UnparseC.term t = "4 * a" then () else error "check make_polynomial 5";
neuper@38036
   834
neuper@38036
   835
"----- check 6 ---";
walther@60242
   836
val t = TermC.str2term "4*(3*a \<up> 2 - 2*a \<up> 2)";
neuper@38036
   837
val SOME (t, _) = rewrite_set_ thy false make_polynomial t;
walther@60242
   838
if UnparseC.term t = "4 * a \<up> 2" then () else error "check make_polynomial 6";
neuper@38036
   839
walther@60318
   840
"-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
walther@60318
   841
"-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
walther@60318
   842
"-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
wneuper@59592
   843
val thy = @{theory "Isac_Knowledge"};
neuper@38040
   844
"===== works for a simple example, see rewrite.sml -- fun app_rev ===";
walther@60242
   845
val t = TermC.str2term "x \<up> 2 * x";
neuper@38040
   846
val SOME (t', _) = rewrite_set_ thy true order_mult_ t;
walther@60242
   847
if UnparseC.term t' = "x * x \<up> 2" then ()
walther@60278
   848
else error "poly.sml Poly.is_multUnordered doesn't work";
neuper@38040
   849
walther@59901
   850
(* 100928 Rewrite.trace_on shows the first occurring difference in 267b:
walther@60242
   851
###  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
   852
 (-48 * x \<up> 4 + 8))
walther@59852
   853
######  rls: Rule_Set.empty-is_multUnordered on: p is_multUnordered
walther@60278
   854
#######  try calc: Poly.is_multUnordered'
neuper@38036
   855
=======  calc. to: False  !!!!!!!!!!!!! INSTEAD OF TRUE in 2002 !!!!!!!!!!!!!
neuper@38036
   856
*)
walther@60242
   857
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
   858
neuper@38036
   859
"----- is_multUnordered ---";
neuper@38036
   860
val tsort = sort_variables t;
walther@60242
   861
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
   862
is_polyexp t;
neuper@38036
   863
tsort = t;
neuper@38036
   864
is_polyexp t andalso not (t = sort_variables t);
neuper@38036
   865
if is_multUnordered t then () else error "poly.sml diff. is_multUnordered 1";
neuper@38036
   866
neuper@38036
   867
"----- eval_is_multUnordered ---";
walther@60242
   868
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
   869
case eval_is_multUnordered "testid" "" tm thy of
neuper@41924
   870
    SOME (_, Const ("HOL.Trueprop", _) $ 
neuper@41922
   871
                   (Const ("HOL.eq", _) $
walther@60278
   872
                          (Const ("Poly.is_multUnordered", _) $ _) $ 
neuper@41928
   873
                          Const ("HOL.True", _))) => ()
neuper@38036
   874
  | _ => error "poly.sml diff. eval_is_multUnordered";
neuper@38036
   875
neuper@38040
   876
"----- rewrite_set_ STILL DIDN'T WORK";
neuper@38040
   877
val SOME (t, _) = rewrite_set_ thy true order_mult_ t;
walther@59868
   878
UnparseC.term t;
neuper@38036
   879
walther@60318
   880
walther@60318
   881
"-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
walther@60318
   882
"-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
walther@60318
   883
"-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
walther@60318
   884
val thy = @{theory "Isac_Knowledge"};
walther@60318
   885
val t as (_ $ arg) = TermC.str2term "(3 * a + - 2 * a) is_multUnordered";
walther@60318
   886
walther@60318
   887
(*+*)if UnparseC.term (sort_variables arg) = "3 * a + - 2 * a" andalso is_polyexp arg = true
walther@60318
   888
(*+*)  andalso not (is_multUnordered arg)
walther@60318
   889
(*+*)then () else error "sort_variables  3 * a + - 2 * a   CHANGED";
walther@60318
   890
walther@60318
   891
case eval_is_multUnordered "xxx " "yyy " t thy of
walther@60318
   892
  SOME
walther@60318
   893
    ("xxx 3 * a + - 2 * a_",
walther@60318
   894
      Const ("HOL.Trueprop", _) $ (Const ("HOL.eq", _) $ _ $
walther@60318
   895
        Const ("HOL.False", _))) => ()
walther@60318
   896
(*      Const ("HOL.True", _))) => ()   <<<<<--------------------------- this is false*)
walther@60318
   897
| _ => error "eval_is_multUnordered  3 * a + -2 * a  CHANGED";
walther@60318
   898
walther@60318
   899
"----- is_multUnordered --- (- 2 * a) is_multUnordered = False";
walther@60318
   900
val t as (_ $ arg) = TermC.str2term "(- 2 * a) is_multUnordered";
walther@60318
   901
walther@60318
   902
(*+*)if UnparseC.term (sort_variables arg) = "- 2 * a" andalso is_polyexp arg = true
walther@60318
   903
(*+*)  andalso not (is_multUnordered arg)
walther@60318
   904
(*+*)then () else error "sort_variables  - 2 * a   CHANGED";
walther@60318
   905
walther@60318
   906
case eval_is_multUnordered "xxx " "yyy " t thy of
walther@60318
   907
  SOME
walther@60318
   908
    ("xxx - 2 * a_",
walther@60318
   909
      Const ("HOL.Trueprop", _) $ (Const ("HOL.eq", _) $ _ $
walther@60318
   910
        Const ("HOL.False", _))) => ()
walther@60318
   911
| _ => error "eval_is_multUnordered  3 * a + -2 * a  CHANGED";
walther@60318
   912
walther@60318
   913
"----- is_multUnordered --- (a) is_multUnordered = False";
walther@60318
   914
val t as (_ $ arg) = TermC.str2term "(a) is_multUnordered";
walther@60318
   915
walther@60318
   916
(*+*)if UnparseC.term (sort_variables arg) = "a" andalso is_polyexp arg = true
walther@60318
   917
(*+*)  andalso not (is_multUnordered arg)
walther@60318
   918
(*+*)then () else error "sort_variables   a   CHANGED";
walther@60318
   919
walther@60318
   920
case eval_is_multUnordered "xxx " "yyy " t thy of
walther@60318
   921
  SOME
walther@60318
   922
    ("xxx a_",
walther@60318
   923
      Const ("HOL.Trueprop", _) $ (Const ("HOL.eq", _) $ _ $
walther@60318
   924
        Const ("HOL.False", _))) => ()
walther@60318
   925
| _ => error "eval_is_multUnordered  3 * a + -2 * a  CHANGED";
walther@60318
   926
walther@60318
   927
"----- is_multUnordered --- (- 2) is_multUnordered = False";
walther@60318
   928
val t as (_ $ arg) = TermC.str2term "(- 2) is_multUnordered";
walther@60318
   929
walther@60318
   930
(*+*)if UnparseC.term (sort_variables arg) = "- 2" andalso is_polyexp arg = true
walther@60318
   931
(*+*)  andalso not (is_multUnordered arg)
walther@60318
   932
(*+*)then () else error "sort_variables   - 2   CHANGED";
walther@60318
   933
walther@60318
   934
case eval_is_multUnordered "xxx " "yyy " t thy of
walther@60318
   935
  SOME
walther@60318
   936
    ("xxx - 2_",
walther@60318
   937
      Const ("HOL.Trueprop", _) $ (Const ("HOL.eq", _) $ _ $
walther@60318
   938
        Const ("HOL.False", _))) => ()
walther@60318
   939
| _ => error "eval_is_multUnordered  3 * a + -2 * a  CHANGED";
walther@60318
   940
walther@60318
   941
walther@60318
   942
"-------- fun is_multUnordered (x - a) \<up> 3 -----------------------------------------------------";
walther@60318
   943
"-------- fun is_multUnordered (x - a) \<up> 3 -----------------------------------------------------";
walther@60318
   944
"-------- fun is_multUnordered (x - a) \<up> 3 -----------------------------------------------------";
walther@60318
   945
(*  ca.line 45 of Rewrite.trace_on:
walther@60318
   946
##  rls: order_mult_rls_ on: 
walther@60318
   947
  x \<up> 3 + 3 * x \<up> 2 * (- 1 * a) + 3 * x * ((- 1) \<up> 2 * a \<up> 2) + (- 1) \<up> 3 * a \<up> 3 
walther@60318
   948
###  rls: order_mult_ on:
walther@60318
   949
  x \<up> 3 + 3 * x \<up> 2 * (- 1 * a) + 3 * x * ((- 1) \<up> 2 * a \<up> 2) + (- 1) \<up> 3 * a \<up> 3 
walther@60318
   950
######  rls: Rule_Set.empty-is_multUnordered on: 
walther@60318
   951
  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@60318
   952
#######  try calc: "Poly.is_multUnordered" 
walther@60318
   953
########  eval asms: 
walther@60318
   954
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@60318
   955
-------------------------------------------------------------------------------------------------==
walther@60318
   956
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@60318
   957
#######  calc. to: True 
walther@60318
   958
#######  try calc: "Poly.is_multUnordered" 
walther@60318
   959
#######  try calc: "Poly.is_multUnordered" 
walther@60318
   960
###  rls: order_mult_ on: 
walther@60318
   961
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@60318
   962
--------+--------------------------+---------------------------------+---------------------------<>
walther@60318
   963
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@60318
   964
-------------------------------------------------------------------------------------------------<>
walther@60318
   965
*)
walther@60318
   966
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@60318
   967
(*
walther@60318
   968
"~~~~~ fun is_multUnordered
walther@60318
   969
"~~~~~~~ fun sort_variables
walther@60318
   970
"~~~~~~~~~ val sort_varList
walther@60318
   971
*)
walther@60318
   972
"~~~~~ fun is_multUnordered , args:"; val (t) = (t);
walther@60318
   973
     is_polyexp t = true;
walther@60318
   974
walther@60318
   975
  val return =
walther@60318
   976
             sort_variables t;
walther@60318
   977
(*+*)if UnparseC.term return =
walther@60318
   978
(*+*)  "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@60318
   979
(*+*)then () else error "sort_variables  x \<up> 3 + - 1 * (3 * (a * x \<up> 2)) .. CHANGED";
walther@60318
   980
walther@60318
   981
"~~~~~~~ fun sort_variables , args:"; val (t) = (t);
walther@60318
   982
  	val ll = map monom2list (poly2list t);
walther@60318
   983
  	val lls = map sort_varList ll; 
walther@60318
   984
walther@60318
   985
(*+*)val ori3 = nth 3 ll;
walther@60318
   986
(*+*)val mon3 = nth 3 lls;
walther@60318
   987
walther@60318
   988
(*+*)if UnparseC.terms (nth 1 ll) = "[\"x \<up> 3\"]" then () else error "nth 1 ll";
walther@60318
   989
(*+*)if UnparseC.terms (nth 2 ll) = "[\"3\", \"x \<up> 2\", \"- 1\", \"a\"]" then () else error "nth 3 ll";
walther@60318
   990
(*+*)if UnparseC.terms ori3       = "[\"3\", \"x\", \"(- 1) \<up> 2\", \"a \<up> 2\"]" then () else error "nth 3 ll";
walther@60318
   991
(*+*)if UnparseC.terms (nth 4 ll) = "[\"(- 1) \<up> 3\", \"a \<up> 3\"]" then () else error "nth 4 ll";
walther@60318
   992
walther@60318
   993
(*+*)if UnparseC.terms (nth 1 lls) = "[\"x \<up> 3\"]" then () else error "nth 1 lls";
walther@60318
   994
(*+*)if UnparseC.terms (nth 2 lls) = "[\"- 1\", \"3\", \"a\", \"x \<up> 2\"]" then () else error "nth 2 lls";
walther@60318
   995
(*+*)if UnparseC.terms mon3 = "[\"(- 1) \<up> 2\", \"3\", \"a \<up> 2\", \"x\"]" then () else error "nth 3 lls";
walther@60318
   996
(*+*)if UnparseC.terms (nth 4 lls) = "[\"(- 1) \<up> 3\", \"a \<up> 3\"]" then () else error "nth 4 lls";
walther@60318
   997
walther@60318
   998
"~~~~~~~~~ val sort_varList , args:"; val (ori3) = (ori3);
walther@60318
   999
(* Output below with:
walther@60318
  1000
val sort_varList = sort var_ord;
walther@60318
  1001
fun var_ord (a,b: term) = 
walther@60318
  1002
(@{print} {a = "var_ord ", a_b = "(" ^ UnparseC.term a ^ ", " ^ UnparseC.term b ^ ")",
walther@60318
  1003
   sort_args = "(" ^ get_basStr a ^ ", " ^ get_potStr a ^ "), (" ^ get_basStr b ^ ", " ^ get_potStr b ^ ")"};
walther@60318
  1004
  prod_ord string_ord string_ord 
walther@60318
  1005
  ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b))
walther@60318
  1006
);
walther@60318
  1007
*)
walther@60318
  1008
(*+*)val xxx = sort_varList ori3;
walther@60318
  1009
(*
walther@60318
  1010
{a = "sort_varList", args = "[\"3\", \"x\", \"(- 1) \<up> 2\", \"a \<up> 2\"]"} (*isa*)
walther@60318
  1011
{a = "sort_varList", args = "[\"3\", \"x\", \"(- 1) \<up> 2\", \"a \<up> 2\"]"} (*isa2*)
walther@60318
  1012
      
walther@60318
  1013
isa                                            isa2
walther@60318
  1014
{a = "var_ord ", a_b = "(3, x)"}               {a = "var_ord ", a_b = "(3, x)"}
walther@60318
  1015
  {sort_args = "(|||, ||||||), (x, ---)"}        {sort_args = "(|||, ||||||), (x, ---)"}
walther@60318
  1016
{a = "var_ord ", a_b = "(x, (- 1) \<up> 2)"}       {a = "var_ord ", a_b = "(x, (- 1) \<up> 2)"}
walther@60318
  1017
  {sort_args = "(x, ---), (|||, ||||||)"}        {sort_args = "(x, ---), (|||, ||||||)"}
walther@60318
  1018
{a = "var_ord ", a_b = "((- 1) \<up> 2, a \<up> 2)"}   {a = "var_ord ", a_b = "((- 1) \<up> 2, a \<up> 2)"}
walther@60318
  1019
  {sort_args = "(|||, ||||||), (a, 2)"}          {sort_args = "(|||, ||||||), (a, |||)"}
walther@60318
  1020
                                  ^^^                                             ^^^
walther@60318
  1021
walther@60318
  1022
{a = "var_ord ", a_b = "(x, a \<up> 2)"}           {a = "var_ord ", a_b = "(x, a \<up> 2)"}
walther@60318
  1023
  {sort_args = "(x, ---), (a, 2)"}               {sort_args = "(x, ---), (a, |||)"}
walther@60318
  1024
                             ^^^                                             ^^^
walther@60318
  1025
{a = "var_ord ", a_b = "(x, (- 1) \<up> 2)"}       {a = "var_ord ", a_b = "(x, (- 1) \<up> 2)"}
walther@60318
  1026
  {sort_args = "(x, ---), (|||, ||||||)"}        {sort_args = "(x, ---), (|||, ||||||)"}
walther@60318
  1027
{a = "var_ord ", a_b = "(3, (- 1) \<up> 2)"}       {a = "var_ord ", a_b = "(3, (- 1) \<up> 2)"}
walther@60318
  1028
  {sort_args = "(|||, ||||||), (|||, ||||||)"}   {sort_args = "(|||, ||||||), (|||, ||||||)"}
walther@60318
  1029
*)
walther@60318
  1030
walther@60318
  1031
walther@60318
  1032
"-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
walther@60318
  1033
"-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
walther@60318
  1034
"-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
walther@60318
  1035
val t = TermC.str2term "b * a * a";
walther@60318
  1036
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60318
  1037
if UnparseC.term t = "a \<up> 2 * b" then ()
walther@60318
  1038
else error "poly.sml: diff.behav. in make_polynomial 21";
walther@60318
  1039
walther@60318
  1040
"~~~~~ fun is_multUnordered , args:"; val (t) = (@{term "b * a * a::real"});
walther@60318
  1041
    ((is_polyexp t) andalso not (t = sort_variables t)) = true;  (*isa == isa2*)
walther@60318
  1042
walther@60318
  1043
(*+*)if    is_polyexp t then () else error "is_polyexp a \<up> 2 * b CHANGED";
walther@60318
  1044
"~~~~~ fun is_polyexp , args:"; val (Const ("Groups.times_class.times",_) $ num $ Free _) = (t);
walther@60318
  1045
    (*if*) TermC.is_num num (*else*);
walther@60318
  1046
walther@60318
  1047
"~~~~~ fun is_polyexp , args:"; val (Const ("Groups.times_class.times",_) $ num $ Free _) = (num);
walther@60318
  1048
    (*if*) TermC.is_num num (*else*);
walther@60318
  1049
      (*if*) TermC.is_variable num (*then*);
walther@60318
  1050
walther@60318
  1051
                           val xxx = sort_variables t;
walther@60318
  1052
(*+*)if UnparseC.term xxx = "a * (a * b)" then () else error "sort_variables a \<up> 2 * b CHANGED";
walther@60318
  1053
walther@60318
  1054
walther@60318
  1055
"-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
walther@60318
  1056
"-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
walther@60318
  1057
"-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
walther@60318
  1058
val t = TermC.str2term "2*3*a";
walther@60318
  1059
val SOME (t', _) = rewrite_set_ thy false make_polynomial t;
walther@60318
  1060
(*+*)if UnparseC.term t' = "6 * a" then () else error "rewrite_set_ 2*3*a CHANGED";
walther@60318
  1061
(*
walther@60318
  1062
##  try calc: "Groups.times_class.times" 
walther@60318
  1063
##  rls: order_mult_rls_ on: 6 * a 
walther@60318
  1064
###  rls: order_mult_ on: 6 * a 
walther@60318
  1065
######  rls: Rule_Set.empty-is_multUnordered on: 6 * a is_multUnordered 
walther@60318
  1066
#######  try calc: "Poly.is_multUnordered" 
walther@60318
  1067
########  eval asms: "6 * a is_multUnordered = True"    (*isa*)
walther@60318
  1068
                                             = False"   (*isa2*)
walther@60318
  1069
#######  calc. to: True  (*isa*)
walther@60318
  1070
                   False (*isa2*)
walther@60318
  1071
*)
walther@60318
  1072
val t = TermC.str2term "(6 * a) is_multUnordered"; 
walther@60318
  1073
val SOME
walther@60318
  1074
    (_, t') =
walther@60318
  1075
           eval_is_multUnordered "xxx" () t @{theory};
walther@60318
  1076
(*+*)if UnparseC.term t' = "6 * a is_multUnordered = False" then () 
walther@60318
  1077
(*+*)else error "6 * a is_multUnordered = False CHANGED";
walther@60318
  1078
walther@60318
  1079
"~~~~~ fun eval_is_multUnordered , args:"; val ((thmid:string), _,
walther@60318
  1080
		       (t as (Const("Poly.is_multUnordered", _) $ arg)), thy) = ("xxx", (), t, @{theory});
walther@60318
  1081
    (*if*) is_multUnordered arg (*else*);
walther@60318
  1082
walther@60318
  1083
"~~~~~ fun is_multUnordered , args:"; val (t) = (arg);
walther@60318
  1084
  val return =
walther@60318
  1085
     ((is_polyexp t) andalso not (t = sort_variables t));
walther@60318
  1086
walther@60318
  1087
(*+*)return = false;                                             (*isa*)
walther@60318
  1088
(*+*)  is_polyexp t = true;                                      (*isa*)
walther@60318
  1089
(*+*)                        not (t = sort_variables t) = false; (*isa*)
walther@60318
  1090
walther@60318
  1091
                            val xxx = sort_variables t;
walther@60318
  1092
(*+*)if UnparseC.term xxx = "6 * a" then () else error "2*3*a is_multUnordered CHANGED";
walther@60318
  1093
walther@60318
  1094
walther@60318
  1095
"-------- examples from textbook Schalk I ------------------------------------------------------";
walther@60318
  1096
"-------- examples from textbook Schalk I ------------------------------------------------------";
walther@60318
  1097
"-------- examples from textbook Schalk I ------------------------------------------------------";
neuper@38036
  1098
"-----SPB Schalk I p.63 No.267b ---";
walther@60242
  1099
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@60318
  1100
val SOME (t, _) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60318
  1101
if UnparseC.term t = "17 + 15 * x \<up> 2 + - 48 * x \<up> 4 + 3 * x \<up> 5 + 6 * x \<up> 7 +\n- 8 * x \<up> 9"
neuper@42395
  1102
then () else error "poly.sml: diff.behav. in make_polynomial 1";
neuper@37906
  1103
neuper@38036
  1104
"-----SPB Schalk I p.63 No.275b ---";
walther@60242
  1105
val t = TermC.str2term "(3*x \<up> 2 - 2*x*y + y \<up> 2) * (x \<up> 2 - 2*y \<up> 2)";
neuper@42395
  1106
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60318
  1107
if UnparseC.term t = 
walther@60318
  1108
  "3 * x \<up> 4 + - 2 * x \<up> 3 * y + - 5 * x \<up> 2 * y \<up> 2 +\n4 * x * y \<up> 3 +\n- 2 * y \<up> 4"
neuper@42395
  1109
then () else error "poly.sml: diff.behav. in make_polynomial 2";
neuper@37906
  1110
neuper@38036
  1111
"-----SPB Schalk I p.63 No.279b ---";
walther@60230
  1112
val t = TermC.str2term "(x-a)*(x-b)*(x-c)*(x-d)";
neuper@42395
  1113
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60318
  1114
if UnparseC.term t = 
walther@60318
  1115
  ("a * b * c * d + - 1 * a * b * c * x + - 1 * a * b * d * x +\na * b * x \<up> 2 +\n" ^
walther@60318
  1116
  "- 1 * a * c * d * x +\na * c * x \<up> 2 +\na * d * x \<up> 2 +\n- 1 * a * x \<up> 3 +\n" ^
walther@60318
  1117
  "- 1 * b * c * d * x +\nb * c * x \<up> 2 +\nb * d * x \<up> 2 +\n- 1 * b * x \<up> 3 +\nc" ^
walther@60318
  1118
  " * d * x \<up> 2 +\n- 1 * c * x \<up> 3 +\n- 1 * d * x \<up> 3 +\nx \<up> 4")
neuper@42395
  1119
then () else error "poly.sml: diff.behav. in make_polynomial 3";
walther@60318
  1120
(*associate poly*)
neuper@37906
  1121
neuper@38036
  1122
"-----SPB Schalk I p.63 No.291 ---";
walther@60242
  1123
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
  1124
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60318
  1125
if UnparseC.term t = "50 + - 770 * x + 4520 * x \<up> 2 + - 16320 * x \<up> 3 +\n- 26880 * x \<up> 4"
neuper@42395
  1126
then () else error "poly.sml: diff.behav. in make_polynomial 4";
neuper@37906
  1127
neuper@38036
  1128
"-----SPB Schalk I p.64 No.295c ---";
walther@60242
  1129
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
  1130
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60318
  1131
if UnparseC.term t =
walther@60318
  1132
  "169 * a \<up> 8 * b \<up> 18 * c \<up> 2 +\n- 312 * a \<up> 7 * b \<up> 15 * c \<up> 10 +\n144 * a \<up> 6 * b \<up> 12 * c \<up> 18"
neuper@42395
  1133
then ()else error "poly.sml: diff.behav. in make_polynomial 5";
neuper@37906
  1134
neuper@38036
  1135
"-----SPB Schalk I p.64 No.299a ---";
walther@60230
  1136
val t = TermC.str2term "(x - y)*(x + y)";
neuper@42395
  1137
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60318
  1138
if UnparseC.term t = "x \<up> 2 + - 1 * y \<up> 2"
neuper@42395
  1139
then () else error "poly.sml: diff.behav. in make_polynomial 6";
neuper@37906
  1140
neuper@38036
  1141
"-----SPB Schalk I p.64 No.300c ---";
walther@60242
  1142
val t = TermC.str2term "(3*x \<up> 2*y - 1)*(3*x \<up> 2*y + 1)";
neuper@42395
  1143
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@60318
  1144
if UnparseC.term t = "- 1 + 9 * x \<up> 4 * y \<up> 2"
neuper@42395
  1145
then () else error "poly.sml: diff.behav. in make_polynomial 7";
neuper@37906
  1146
neuper@38036
  1147
"-----SPB Schalk I p.64 No.302 ---";
walther@60230
  1148
val t = TermC.str2term
walther@60242
  1149
  "(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
  1150
val SOME (t,_) = rewrite_set_ thy false make_polynomial t;
walther@59868
  1151
if UnparseC.term t = "0"
neuper@42395
  1152
then () else error "poly.sml: diff.behav. in make_polynomial 8";
neuper@42395
  1153
(* RL?MG?: Bei Berechnung sollte 3 mal real_plus_minus_binom1_p aus expand_poly verwendet werden *)
neuper@37906
  1154
neuper@38036
  1155
"-----SPB Schalk I p.64 No.306a ---";
walther@60242
  1156
val t = TermC.str2term "((x \<up> 2 + 1)*(x \<up> 2 - 1)) \<up> 2";
walther@59868
  1157
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60318
  1158
if UnparseC.term t = "1 + 2 * x \<up> 4 + 2 * - 2 * x \<up> 4 + x \<up> 8" then ()
walther@60242
  1159
else error "poly.sml: diff.behav. in 2 * x \<up> 4 + 2 * -2 * x \<up> 4 = -2 * x \<up> 4";
neuper@37906
  1160
neuper@37906
  1161
(*WN071729 when reducing "rls reduce_012_" for Schaerding,
neuper@37906
  1162
the above resulted in the term below ... but reduces from then correctly*)
walther@60242
  1163
val t = TermC.str2term "1 + 2 * x \<up> 4 + 2 * -2 * x \<up> 4 + x \<up> 8";
walther@59868
  1164
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60318
  1165
if UnparseC.term t = "1 + - 2 * x \<up> 4 + x \<up> 8"
neuper@42395
  1166
then () else error "poly.sml: diff.behav. in make_polynomial 9b";
neuper@37906
  1167
neuper@38036
  1168
"-----SPB Schalk I p.64 No.296a ---";
walther@60242
  1169
val t = TermC.str2term "(x - a) \<up> 3";
walther@59868
  1170
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60318
  1171
walther@60318
  1172
val NONE = eval_is_even "aaa" "bbb" (TermC.str2term "3::real") "ccc";
walther@60318
  1173
walther@60318
  1174
if UnparseC.term t = "- 1 * a \<up> 3 + 3 * a \<up> 2 * x + - 3 * a * x \<up> 2 + x \<up> 3"
neuper@38031
  1175
then () else error "poly.sml: diff.behav. in make_polynomial 10";
neuper@37906
  1176
neuper@38036
  1177
"-----SPB Schalk I p.64 No.296c ---";
walther@60242
  1178
val t = TermC.str2term "(-3*x - 4*y) \<up> 3";
walther@59868
  1179
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60318
  1180
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
  1181
then () else error "poly.sml: diff.behav. in make_polynomial 11";
neuper@37906
  1182
neuper@38036
  1183
"-----SPB Schalk I p.62 No.242c ---";
walther@60242
  1184
val t = TermC.str2term "x \<up> (-4)*(x \<up> (-4)*y \<up> (-2)) \<up> (-1)*y \<up> (-2)";
walther@59868
  1185
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60318
  1186
if UnparseC.term t = "1"
neuper@42395
  1187
then () else error "poly.sml: diff.behav. in make_polynomial 12";
neuper@37906
  1188
neuper@38036
  1189
"-----SPB Schalk I p.60 No.209a ---";
walther@60242
  1190
val t = TermC.str2term "a \<up> (7-x) * a \<up> x";
walther@59868
  1191
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
  1192
if UnparseC.term t = "a \<up> 7"
neuper@42395
  1193
then () else error "poly.sml: diff.behav. in make_polynomial 13";
neuper@37906
  1194
neuper@38036
  1195
"-----SPB Schalk I p.60 No.209d ---";
walther@60242
  1196
val t = TermC.str2term "d \<up> x * d \<up> (x+1) * d \<up> (2 - 2*x)";
walther@59868
  1197
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
  1198
if UnparseC.term t = "d \<up> 3"
neuper@42395
  1199
then () else error "poly.sml: diff.behav. in make_polynomial 14";
neuper@37906
  1200
walther@60318
  1201
"-------- ?RL?Bsple bei denen es Probleme gibt--------------------------------------------------";
walther@60318
  1202
"-------- ?RL?Bsple bei denen es Probleme gibt--------------------------------------------------";
walther@60318
  1203
"-------- ?RL?Bsple bei denen es Probleme gibt--------------------------------------------------";
neuper@38036
  1204
"-----Schalk I p.64 No.303 ---";
walther@60242
  1205
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@60318
  1206
(*SOMETIMES LOOPS---------------------------------------------------------------------------\\*)
walther@60318
  1207
val SOME (t, _) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
  1208
if UnparseC.term t = "1280 * b \<up> 4"
neuper@42395
  1209
then () else error "poly.sml: diff.behav. in make_polynomial 14b";
neuper@37906
  1210
(* Richtig - aber Binomische Formel wurde nicht verwendet! *)
walther@60318
  1211
(*SOMETIMES LOOPS--------------------------------------------------------------------------//*)
neuper@37906
  1212
walther@60318
  1213
"-------- Eigene Beispiele (Mathias Goldgruber) ------------------------------------------------";
walther@60318
  1214
"-------- Eigene Beispiele (Mathias Goldgruber) ------------------------------------------------";
walther@60318
  1215
"-------- Eigene Beispiele (Mathias Goldgruber) ------------------------------------------------";
neuper@38036
  1216
"-----SPO ---";
walther@60242
  1217
val t = TermC.str2term "a \<up> 2*a \<up> (-2)";
walther@59868
  1218
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
  1219
if UnparseC.term t = "1" then ()
neuper@38031
  1220
else error "poly.sml: diff.behav. in make_polynomial 15";
neuper@38036
  1221
"-----SPO ---";
walther@60230
  1222
val t = TermC.str2term "a + a + a";
walther@59868
  1223
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
  1224
if UnparseC.term t = "3 * a" then ()
neuper@38031
  1225
else error "poly.sml: diff.behav. in make_polynomial 16";
neuper@38036
  1226
"-----SPO ---";
walther@60230
  1227
val t = TermC.str2term "a + b + b + b";
walther@59868
  1228
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
  1229
if UnparseC.term t = "a + 3 * b" then ()
neuper@38031
  1230
else error "poly.sml: diff.behav. in make_polynomial 17";
neuper@38036
  1231
"-----SPO ---";
walther@60242
  1232
val t = TermC.str2term "a \<up> 2*b*b \<up> (-1)";
walther@59868
  1233
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
  1234
if UnparseC.term t = "a \<up> 2" then ()
neuper@38031
  1235
else error "poly.sml: diff.behav. in make_polynomial 18";
neuper@38036
  1236
"-----SPO ---";
walther@60242
  1237
val t = TermC.str2term "a \<up> 2*a \<up> (-2)";
walther@59868
  1238
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
  1239
if (UnparseC.term t) = "1" then ()
neuper@38031
  1240
else error "poly.sml: diff.behav. in make_polynomial 19";
neuper@38036
  1241
"-----SPO ---";
walther@60230
  1242
val t = TermC.str2term "b + a - b";
walther@59868
  1243
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@59868
  1244
if (UnparseC.term t) = "a" then ()
neuper@38031
  1245
else error "poly.sml: diff.behav. in make_polynomial 20";
neuper@38036
  1246
"-----SPO ---";
walther@60230
  1247
val t = TermC.str2term "b * a * a";
walther@59868
  1248
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
  1249
if UnparseC.term t = "a \<up> 2 * b" then ()
neuper@38031
  1250
else error "poly.sml: diff.behav. in make_polynomial 21";
neuper@38036
  1251
"-----SPO ---";
walther@60242
  1252
val t = TermC.str2term "(a \<up> 2) \<up> 3";
walther@59868
  1253
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
  1254
if UnparseC.term t = "a \<up> 6" then ()
neuper@38031
  1255
else error "poly.sml: diff.behav. in make_polynomial 22";
neuper@38036
  1256
"-----SPO ---";
walther@60242
  1257
val t = TermC.str2term "x \<up> 2 * y \<up> 2 + x * x \<up> 2 * y";
walther@59868
  1258
val SOME (t,_) = rewrite_set_ thy false make_polynomial t; UnparseC.term t;
walther@60242
  1259
if UnparseC.term t = "x \<up> 3 * y + x \<up> 2 * y \<up> 2" then ()
neuper@38031
  1260
else error "poly.sml: diff.behav. in make_polynomial 23";
neuper@38036
  1261
"-----SPO ---";
walther@60242
  1262
val t = (Thm.term_of o the o (TermC.parse thy)) "a \<up> 2 * (-a) \<up> 2";
walther@60318
  1263
val SOME (t,_) = rewrite_set_ @{theory} false make_polynomial t; UnparseC.term t;
walther@60242
  1264
if (UnparseC.term t) = "a \<up> 4" then ()
neuper@38031
  1265
else error "poly.sml: diff.behav. in make_polynomial 24";
neuper@38036
  1266
"-----SPO ---";
walther@60242
  1267
val t = TermC.str2term "a * b * b \<up> (-1) + a";
walther@60318
  1268
val SOME (t,_) = rewrite_set_ @{theory} false make_polynomial t; UnparseC.term t;
walther@60318
  1269
if UnparseC.term t = "2 * a" then ()
neuper@38031
  1270
else error "poly.sml: diff.behav. in make_polynomial 25";
neuper@38036
  1271
"-----SPO ---";
walther@60242
  1272
val t = TermC.str2term "a*c*b \<up> (2*n) + 3*a + 5*b \<up> (2*n)*c*b";
walther@60318
  1273
val SOME (t,_) = rewrite_set_ @{theory} false make_polynomial t; UnparseC.term t;
walther@60318
  1274
if UnparseC.term t = "3 * a + 5 * b \<up> (1 + 2 * n) * c + a * b \<up> (2 * n) * c"
neuper@38031
  1275
then () else error "poly.sml: diff.behav. in make_polynomial 26";
neuper@37906
  1276
neuper@42395
  1277
(*MG030627 -------------vvv-: Verschachtelte Terme -----------*)
neuper@38036
  1278
"-----SPO ---";
walther@60242
  1279
val t = TermC.str2term "(1 + (x*y*a) + x) \<up> (1 + (x*y*a) + x)";
walther@60318
  1280
val SOME (t,_) = rewrite_set_ @{theory} false make_polynomial t;
walther@60242
  1281
if UnparseC.term t = "(1 + x + a * x * y) \<up> (1 + x + a * x * y)"
neuper@42395
  1282
then () else error "poly.sml: diff.behav. in make_polynomial 27";(*SPO*)
neuper@42395
  1283
walther@60242
  1284
val t = TermC.str2term "(1 + x*(y*z)*zz) \<up> (1 + x*(y*z)*zz)";
walther@60318
  1285
val SOME (t,_) = rewrite_set_ @{theory} false make_polynomial t;
walther@60242
  1286
if UnparseC.term t = "(1 + x * y * z * zz) \<up> (1 + x * y * z * zz)"
neuper@42395
  1287
then () else error "poly.sml: diff.behav. in make_polynomial 28";
neuper@37906
  1288
walther@60318
  1289
"-------- check pbl  'polynomial simplification' -----------------------------------------------";
walther@60318
  1290
"-------- check pbl  'polynomial simplification' -----------------------------------------------";
walther@60318
  1291
"-------- check pbl  'polynomial simplification' -----------------------------------------------";
walther@60242
  1292
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
  1293
"-----0 ---";
walther@60318
  1294
case Refine.refine fmz ["polynomial", "simplification"] of
walther@59984
  1295
    [M_Match.Matches (["polynomial", "simplification"], _)] => ()
walther@59968
  1296
  | _ => error "poly.sml diff.behav. in check pbl, Refine.refine";
neuper@37906
  1297
(*...if there is an error, then ...*)
neuper@37906
  1298
neuper@38036
  1299
"-----1 ---";
wneuper@59348
  1300
(*default_print_depth 7;*)
walther@59997
  1301
val pbt = Problem.from_store ["polynomial", "simplification"];
wneuper@59348
  1302
(*default_print_depth 3;*)
neuper@37906
  1303
(*if there is ...
walther@59984
  1304
> val M_Match.NoMatch' {Given=gi, Where=wh, Find=fi,...} = M_Match.match_pbl fmz pbt;
walther@59901
  1305
... then Rewrite.trace_on:*)
walther@60242
  1306
                           
neuper@38036
  1307
"-----2 ---";
walther@59901
  1308
Rewrite.trace_on := false;
walther@59984
  1309
M_Match.match_pbl fmz pbt;
walther@59901
  1310
Rewrite.trace_on := false;
neuper@37906
  1311
(*... if there is no rewrite, then there is something wrong with prls*)
neuper@52101
  1312
                              
neuper@38036
  1313
"-----3 ---";
wneuper@59348
  1314
(*default_print_depth 7;*)
walther@59997
  1315
val prls = (#prls o Problem.from_store) ["polynomial", "simplification"];
wneuper@59348
  1316
(*default_print_depth 3;*)
walther@60242
  1317
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
  1318
val SOME (t',_) = rewrite_set_ thy false prls t;
neuper@48760
  1319
if t' = @{term True} then () 
neuper@38031
  1320
else error "poly.sml: diff.behav. in check pbl 'polynomial..";
neuper@42395
  1321
(*... if this works, but --1-- does still NOT work, check types:*)
neuper@37906
  1322
neuper@38036
  1323
"-----4 ---";
neuper@42395
  1324
(*show_types:=true;*)
neuper@37906
  1325
(*
walther@59984
  1326
> val M_Match.NoMatch' {Given=gi, Where=wh, Find=fi,...} = M_Match.match_pbl fmz pbt;
neuper@37906
  1327
val wh = [False "(t_::real => real) (is_polyexp::real)"]
walther@60242
  1328
...................... \<up> \<up> \<up>  \<up> ............... \<up> ^*)
walther@59984
  1329
val M_Match.Matches' _ = M_Match.match_pbl fmz pbt;
neuper@42395
  1330
(*show_types:=false;*)
neuper@37906
  1331
walther@59787
  1332
walther@60318
  1333
"-------- me 'poly. simpl.' Schalk I p.63 No.267b ----------------------------------------------";
walther@60318
  1334
"-------- me 'poly. simpl.' Schalk I p.63 No.267b ----------------------------------------------";
walther@60318
  1335
"-------- me 'poly. simpl.' Schalk I p.63 No.267b ----------------------------------------------";
walther@60242
  1336
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
  1337
val (dI',pI',mI') =
walther@59997
  1338
  ("Poly",["polynomial", "simplification"],
walther@59997
  1339
   ["simplification", "for_polynomials"]);
neuper@37906
  1340
val p = e_pos'; val c = []; 
neuper@37906
  1341
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
walther@60242
  1342
(*[], 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
  1343
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Add_Find "normalform N"*)
walther@59787
  1344
walther@59997
  1345
(*+* )if I_Model.to_string ctxt (get_obj g_pbl pt (fst p)) =
walther@60242
  1346
(*+*)  "[\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
  1347
(*+*)then () else error "No.267b: I_Model.T CHANGED";
walther@59997
  1348
( *+ ...could not be repaired in child of 7e314dd233fd ?!?*)
walther@59787
  1349
walther@59787
  1350
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*nxt = Specify_Theory "Poly"*)
walther@59787
  1351
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Specify_Problem ["polynomial", "simplification"]*)
walther@59787
  1352
(*[], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Specify_Method ["simplification", "for_polynomials"]*)
walther@59787
  1353
(*[], Met*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Apply_Method ["simplification", "for_polynomials"]*)
walther@59787
  1354
(*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Rewrite_Set "norm_Poly"*)
walther@59787
  1355
walther@60242
  1356
(*+*)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
  1357
(*+*)then () else error "";
walther@59787
  1358
walther@59787
  1359
(*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p c pt;(*Empty_Tac: ERROR DETECTED Feb.2020*)
walther@59787
  1360
walther@60318
  1361
(*+*)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
  1362
(*+*)then () else error "poly.sml diff.behav. in me Schalk I p.63 No.267b -1";
walther@59787
  1363
walther@59790
  1364
(*[1], Res* )val (p,_,f,nxt,_,pt) = me nxt p c pt;( *SINCE Feb.2020 LItool.find_next_step without result*)
walther@59787
  1365
walther@59787
  1366
neuper@37906
  1367
walther@60318
  1368
"-------- interSteps for Schalk 299a -----------------------------------------------------------";
walther@60318
  1369
"-------- interSteps for Schalk 299a -----------------------------------------------------------";
walther@60318
  1370
"-------- interSteps for Schalk 299a -----------------------------------------------------------";
s1210629013@55445
  1371
reset_states ();
neuper@37906
  1372
CalcTree
neuper@42395
  1373
[(["Term ((x - y)*(x + (y::real)))", "normalform N"], 
walther@59997
  1374
  ("Poly",["polynomial", "simplification"],
walther@59997
  1375
  ["simplification", "for_polynomials"]))];
neuper@37906
  1376
Iterator 1;
neuper@37906
  1377
moveActiveRoot 1;
wneuper@59248
  1378
autoCalculate 1 CompleteCalc;
walther@59983
  1379
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@37906
  1380
walther@59833
  1381
interSteps 1 ([1],Res)(*<ERROR> syserror in Detail_Step.go </ERROR>*);
walther@59983
  1382
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@37906
  1383
if existpt' ([1,1], Frm) pt then ()
neuper@38031
  1384
else error "poly.sml: interSteps doesnt work again 1";
neuper@37906
  1385
walther@59833
  1386
interSteps 1 ([1,1],Res)(*<ERROR> syserror in Detail_Step.go </ERROR>*);
walther@59983
  1387
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@42395
  1388
(*============ inhibit exn WN120316 ==============================================
neuper@37906
  1389
if existpt' ([1,1,1], Frm) pt then ()
neuper@38031
  1390
else error "poly.sml: interSteps doesnt work again 2";
neuper@42395
  1391
============ inhibit exn WN120316 ==============================================*)
neuper@37906
  1392
walther@60318
  1393
"-------- norm_Poly NOT COMPLETE ---------------------------------------------------------------";
walther@60318
  1394
"-------- norm_Poly NOT COMPLETE ---------------------------------------------------------------";
walther@60318
  1395
"-------- norm_Poly NOT COMPLETE ---------------------------------------------------------------";
walther@60267
  1396
val thy = @{theory AlgEin};
wneuper@59529
  1397
wneuper@59529
  1398
val SOME (f',_) = rewrite_set_ thy false norm_Poly
walther@60230
  1399
(TermC.str2term "L = k - 2 * q + (k - 2 * q) + (k - 2 * q) + (k - 2 * q) + senkrecht + oben");
walther@60318
  1400
if UnparseC.term f' = "L = 2 * 2 * k + 2 * - 4 * q + senkrecht + oben"
neuper@42395
  1401
then ((*norm_Poly NOT COMPLETE -- TODO MG*))
neuper@42395
  1402
else error "norm_Poly changed behavior";
walther@60318
  1403
(* isa:
walther@60318
  1404
##  rls: order_add_rls_ on: L = k + - 2 * q + k + - 2 * q + k + - 2 * q + k + - 2 * q + senkrecht + oben 
walther@60318
  1405
###  rls: order_add_ on: L = k + - 2 * q + k + - 2 * q + k + - 2 * q + k + - 2 * q + senkrecht + oben 
walther@60318
  1406
######  rls: Rule_Set.empty-is_addUnordered on: k + - 2 * q + k + - 2 * q + k + - 2 * q + k + - 2 * q + senkrecht +
walther@60318
  1407
oben is_addUnordered 
walther@60318
  1408
#######  try calc: "Poly.is_addUnordered" 
walther@60318
  1409
########  eval asms: "k + - 2 * q + k + - 2 * q + k + - 2 * q + k + - 2 * q + senkrecht +
walther@60318
  1410
oben is_addUnordered = True" 
walther@60318
  1411
#######  calc. to: True 
walther@60318
  1412
#######  try calc: "Poly.is_addUnordered" 
walther@60318
  1413
#######  try calc: "Poly.is_addUnordered" 
walther@60318
  1414
###  rls: order_add_ on: L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben 
walther@60318
  1415
*)
walther@60318
  1416
"~~~~~ fun sort_monoms , args:"; val (t) =
walther@60318
  1417
  (TermC.str2term "L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben");
walther@60318
  1418
(*+*)val t' =
walther@60318
  1419
           sort_monoms t;
walther@60318
  1420
(*+*)UnparseC.term t' = "L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben"; (*isa*)
neuper@38036
  1421
walther@60318
  1422
"-------- ord_make_polynomial ------------------------------------------------------------------";
walther@60318
  1423
"-------- ord_make_polynomial ------------------------------------------------------------------";
walther@60318
  1424
"-------- ord_make_polynomial ------------------------------------------------------------------";
walther@60230
  1425
val t1 = TermC.str2term "2 * b + (3 * a + 3 * b)";
walther@60318
  1426
val t2 = TermC.str2term "(3 * a + 3 * b) + 2 * b";
neuper@37906
  1427
neuper@42395
  1428
if ord_make_polynomial true thy [] (t1, t2) then ()
neuper@38031
  1429
else error "poly.sml: diff.behav. in ord_make_polynomial";
walther@60318
  1430
(*SO: WHY IS THERE NO REWRITING ...*)
neuper@37906
  1431
walther@60230
  1432
val term = TermC.str2term "2*b + (3*a + 3*b)";
walther@60318
  1433
(*+++*)val SOME (t', []) = rewrite_set_ @{theory "Isac_Knowledge"} false order_add_mult term;
walther@60318
  1434
(*+++*)if UnparseC.term t' = "a * 3 + (b * 2 + b * 3)" then () else error "no rewriting ?!?";
walther@60318
  1435
(* before dropping ThmC.numerals_to_Free this was
walther@60318
  1436
val NONE = rewrite_set_ @ {theory "Isac_Knowledge"} false order_add_mult term;
walther@60318
  1437
SO: WHY IS THERE NO REWRITING ?!?
walther@60318
  1438
*)
neuper@37906
  1439