test/Tools/isac/Knowledge/polyminus.sml
author wneuper <walther.neuper@jku.at>
Thu, 15 Jul 2021 20:02:16 +0200
changeset 60325 a7c0e6ab4883
parent 60324 5c7128feb370
child 60329 0c10aeff57d7
permissions -rw-r--r--
rewrite.sml + poly.sml + rational.sml + polyminus.sml: ok
wneuper@59582
     1
(* title:  Knowledge/polyminus.sml
neuper@37906
     2
   author: Walther Neuper
neuper@37906
     3
   WN071207,
neuper@37906
     4
   (c) due to copyright terms
neuper@37906
     5
*)
neuper@38037
     6
"--------------------------------------------------------";
neuper@38037
     7
"--------------------------------------------------------";
neuper@38037
     8
"table of contents --------------------------------------";
neuper@38037
     9
"--------------------------------------------------------";
walther@60325
    10
"----------- fun identifier --------------------------------------------------------------------";
walther@60324
    11
"----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
walther@60324
    12
"----------- fun ist_monom ---------------------------------------------------------------------";
neuper@38037
    13
"----------- fun eval_ist_monom -------------------------";
neuper@38037
    14
"----------- watch order_add_mult  ----------------------";
neuper@38037
    15
"----------- build predicate for +- ordering ------------";
neuper@38037
    16
"----------- build fasse_zusammen -----------------------";
neuper@38037
    17
"----------- build verschoenere -------------------------";
neuper@38037
    18
"----------- met simplification for_polynomials with_minu";
neuper@38080
    19
"----------- me simplification.for_polynomials.with_minus";
neuper@38037
    20
"----------- pbl polynom vereinfachen p.33 --------------";
neuper@38037
    21
"----------- met probe fuer_polynom ---------------------";
neuper@38037
    22
"----------- pbl polynom probe --------------------------";
neuper@38037
    23
"----------- pbl klammer polynom vereinfachen p.34 ------";
neuper@38037
    24
"----------- try fun applyTactics -----------------------";
neuper@38037
    25
"----------- pbl binom polynom vereinfachen p.39 --------";
neuper@38037
    26
"----------- pbl binom polynom vereinfachen: cube -------";
walther@59968
    27
"----------- Refine.refine Vereinfache -------------------------";
walther@59973
    28
"----------- *** Problem.prep_input: syntax error in '#Where' of [v";
neuper@38037
    29
"--------------------------------------------------------";
neuper@38037
    30
"--------------------------------------------------------";
neuper@38037
    31
"--------------------------------------------------------";
neuper@38037
    32
neuper@41929
    33
val thy = @{theory "PolyMinus"};
neuper@37906
    34
walther@60325
    35
"----------- fun identifier --------------------------------------------------------------------";
walther@60325
    36
"----------- fun identifier --------------------------------------------------------------------";
walther@60325
    37
"----------- fun identifier --------------------------------------------------------------------";
walther@60325
    38
if identifier (TermC.str2term "12 ::real") = "12"     then () else error "identifier 1";
walther@60325
    39
if identifier (TermC.str2term "a ::real") = "a"       then () else error "identifier 2";
walther@60325
    40
if identifier (TermC.str2term "3 * a ::real") = "a"   then () else error "identifier 3";
walther@60325
    41
if identifier (TermC.str2term "a \<up> 2 ::real") = "a"   then () else error "identifier 4";
walther@60325
    42
if identifier (TermC.str2term "3*a \<up> 2 ::real") = "a" then () else error "identifier 5";
walther@60325
    43
if identifier (TermC.str2term "a * b ::real") = "b"   then () else error "identifier 5b";
walther@60324
    44
walther@60325
    45
(*these are strange (see "specific monomials" in comment to fun.def.)..*)
walther@60325
    46
if identifier (TermC.str2term "a*b ::real") = "b"     then () else error "identifier 6";
walther@60325
    47
if identifier (TermC.str2term "(3*a*b) ::real") = "b" then () else error "identifier 7";
walther@60324
    48
walther@60324
    49
walther@60324
    50
"----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
walther@60324
    51
"----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
walther@60324
    52
"----------- fun eval_kleiner, fun kleiner -----------------------------------------------------";
walther@60325
    53
"a" < "b";
walther@60325
    54
"ba" < "ab";
walther@60325
    55
"123" < "a"; (*unused due to ---vvv*)
walther@60325
    56
"12" < "3"; (*true !!!*)
walther@60325
    57
walther@60325
    58
" a kleiner b ==> (b + a) = (a + b)";
walther@60325
    59
TermC.str2term "aaa";
walther@60325
    60
TermC.str2term "222 * aaa";
walther@60325
    61
walther@60325
    62
case eval_kleiner 0 0 (TermC.str2term "123 kleiner 32") 0 of
walther@60325
    63
    SOME ("123 kleiner 32 = False", _) => ()
walther@60325
    64
  | _ => error "polyminus.sml: 12 kleiner 9 = False";
walther@60325
    65
case eval_kleiner 0 0 (TermC.str2term "a kleiner b") 0 of
walther@60325
    66
    SOME ("a kleiner b = True", _) => ()
walther@60325
    67
  | _ => error "polyminus.sml: a kleiner b = True";
walther@60325
    68
case eval_kleiner 0 0 (TermC.str2term "(10*g) kleiner f") 0 of
walther@60325
    69
    SOME ("10 * g kleiner f = False", _) => ()
walther@60325
    70
  | _ => error "polyminus.sml: 10 * g kleiner f = False";
walther@60325
    71
case eval_kleiner 0 0 (TermC.str2term "(a \<up> 2) kleiner b") 0 of
walther@60325
    72
    SOME ("a \<up> 2 kleiner b = True", _) => ()
walther@60325
    73
  | _ => error "polyminus.sml: a \<up> 2 kleiner b = True";
walther@60325
    74
case eval_kleiner 0 0 (TermC.str2term "(3*a \<up> 2) kleiner b") 0 of
walther@60325
    75
    SOME ("3 * a \<up> 2 kleiner b = True", _) => ()
walther@60325
    76
  | _ => error "polyminus.sml: 3 * a \<up> 2 kleiner b = True";
walther@60325
    77
case eval_kleiner 0 0 (TermC.str2term "(a*b) kleiner c") 0 of
walther@60325
    78
    SOME ("a * b kleiner c = True", _) => ()
walther@60325
    79
  | _ => error "polyminus.sml: a * b kleiner b = True";
walther@60325
    80
case eval_kleiner 0 0 (TermC.str2term "(3*a*b) kleiner c") 0 of
walther@60325
    81
    SOME ("3 * a * b kleiner c = True", _) => ()
walther@60325
    82
  | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
walther@60325
    83
walther@60325
    84
walther@60324
    85
val t = TermC.str2term "12 kleiner 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * (g::real)";
walther@60324
    86
val SOME ("12 kleiner 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g = True", _) =
walther@60324
    87
           eval_kleiner "aaa" "bbb" t "ccc";
walther@60324
    88
"~~~~~ fun eval_kleiner , args:"; val (_, _, (p as (Const ("PolyMinus.kleiner",_) $ a $ b)), _) =
walther@60324
    89
  ("aaa", "bbb", t, "ccc");
walther@60324
    90
    (*if*) TermC.is_num b (*else*);
walther@60324
    91
walther@60324
    92
   	(*if*) identifier a < identifier b  (*else*);
walther@60324
    93
"~~~~~ fun identifier , args:"; val (t) = (a);
walther@60324
    94
(*+*)case a of
walther@60324
    95
  Const ("Num.numeral_class.numeral", _) $ (Const ("Num.num.Bit0", _) $
walther@60324
    96
    (Const ("Num.num.Bit0", _) $ (Const ("Num.num.Bit1", _) $ Const ("Num.num.One", _)))) => ()
walther@60325
    97
| _ => error "eval_kleiner CHANGED";                                                 (*isa*)
walther@60325
    98
walther@60325
    99
walther@60325
   100
"----------- fun ist_monom ---------------------------------------------------------------------";
walther@60325
   101
"----------- fun ist_monom ---------------------------------------------------------------------";
walther@60325
   102
"----------- fun ist_monom ---------------------------------------------------------------------";
walther@60325
   103
val t = TermC.str2term "0 ::real";
walther@60325
   104
 if ist_monom t then () else error "ist_monom 1";
walther@60325
   105
walther@60325
   106
val t = TermC.str2term "a";
walther@60325
   107
if ist_monom t then () else error "ist_monom 2";
walther@60325
   108
walther@60325
   109
val t = TermC.str2term "2 * a";
walther@60325
   110
if ist_monom t then () else error "ist_monom 3";
walther@60325
   111
walther@60325
   112
val t = TermC.str2term "2 * a * b";
walther@60325
   113
if ist_monom t then () else error "ist_monom 4";
walther@60325
   114
walther@60325
   115
val t = TermC.str2term "a * b";
walther@60325
   116
if ist_monom t then () else error "ist_monom 5";
walther@60325
   117
walther@60325
   118
(*not covered before NEW numerals*)
walther@60325
   119
val t = TermC.str2term "2 * a \<up> 2 * b";
walther@60325
   120
if ist_monom t then () else error "ist_monom 6";
walther@60325
   121
walther@60325
   122
(*not covered before NEW numerals*)
walther@60325
   123
val t = TermC.str2term "a \<up> 2 * b \<up> 3";
walther@60325
   124
if ist_monom t then () else error "ist_monom 7";
walther@60325
   125
walther@60325
   126
val t = TermC.str2term "a \<up> 2 * 4 * b \<up> 3 * 5";
walther@60325
   127
if ist_monom t then () else error "ist_monom 8";
walther@60324
   128
walther@60324
   129
neuper@37906
   130
"----------- fun eval_ist_monom ----------------------------------";
neuper@37906
   131
"----------- fun eval_ist_monom ----------------------------------";
neuper@37906
   132
"----------- fun eval_ist_monom ----------------------------------";
walther@60230
   133
case eval_ist_monom 0 0 (TermC.str2term "12 ist_monom") 0 of
neuper@37926
   134
    SOME ("12 ist_monom = True", _) => ()
neuper@38031
   135
  | _ => error "polyminus.sml: 12 ist_monom = True";
neuper@37906
   136
walther@60230
   137
case eval_ist_monom 0 0 (TermC.str2term "a ist_monom") 0 of
neuper@37926
   138
    SOME ("a ist_monom = True", _) => ()
neuper@38031
   139
  | _ => error "polyminus.sml: a ist_monom = True";
neuper@37906
   140
walther@60230
   141
case eval_ist_monom 0 0 (TermC.str2term "(3*a) ist_monom") 0 of
neuper@37926
   142
    SOME ("3 * a ist_monom = True", _) => ()
neuper@38031
   143
  | _ => error "polyminus.sml: 3 * a ist_monom = True";
neuper@37906
   144
walther@60242
   145
case eval_ist_monom 0 0 (TermC.str2term "(a \<up> 2) ist_monom") 0 of 
walther@60242
   146
   SOME ("a \<up> 2 ist_monom = True", _) => ()
walther@60242
   147
  | _ => error "polyminus.sml: a \<up> 2 ist_monom = True";
neuper@37906
   148
walther@60242
   149
case eval_ist_monom 0 0 (TermC.str2term "(3*a \<up> 2) ist_monom") 0 of
walther@60242
   150
    SOME ("3 * a \<up> 2 ist_monom = True", _) => ()
walther@60242
   151
  | _ => error "polyminus.sml: 3*a \<up> 2 ist_monom = True";
neuper@37906
   152
walther@60230
   153
case eval_ist_monom 0 0 (TermC.str2term "(a*b) ist_monom") 0 of
neuper@37926
   154
    SOME ("a * b ist_monom = True", _) => ()
neuper@38031
   155
  | _ => error "polyminus.sml: a*b ist_monom = True";
neuper@37906
   156
walther@60230
   157
case eval_ist_monom 0 0 (TermC.str2term "(3*a*b) ist_monom") 0 of
neuper@37926
   158
    SOME ("3 * a * b ist_monom = True", _) => ()
neuper@38031
   159
  | _ => error "polyminus.sml: 3*a*b ist_monom = True";
neuper@37906
   160
neuper@37906
   161
neuper@37906
   162
"----------- watch order_add_mult  -------------------------------";
neuper@37906
   163
"----------- watch order_add_mult  -------------------------------";
neuper@37906
   164
"----------- watch order_add_mult  -------------------------------";
neuper@37906
   165
"----- with these simple variables it works...";
walther@59901
   166
(*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
walther@59901
   167
Rewrite.trace_on:=false;
walther@60230
   168
val t = TermC.str2term "((a + d) + c) + b";
walther@59868
   169
val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
walther@59868
   170
if UnparseC.term t = "a + (b + (c + d))" then ()
neuper@38031
   171
else error "polyminus.sml 1 watch order_add_mult";
walther@59901
   172
Rewrite.trace_on:=false;
neuper@37906
   173
neuper@37906
   174
"----- the same stepwise...";
neuper@41929
   175
val od = ord_make_polynomial true (@{theory "Poly"});
walther@60230
   176
val t = TermC.str2term "((a + d) + c) + b";
neuper@37906
   177
"((a + d) + c) + b"; 
walther@59868
   178
val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
neuper@37906
   179
"b + ((a + d) + c)";
walther@59868
   180
val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t; UnparseC.term t;
neuper@37906
   181
"b + (c + (a + d))";
walther@59868
   182
val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
neuper@37906
   183
"b + (a + (c + d))";
walther@59868
   184
val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
neuper@37906
   185
"a + (b + (c + d))";
walther@59868
   186
if UnparseC.term t = "a + (b + (c + d))" then ()
neuper@38031
   187
else error "polyminus.sml 2 watch order_add_mult";
neuper@37906
   188
neuper@37906
   189
"----- if parentheses are right, left_commute is (almost) sufficient...";
walther@60230
   190
val t = TermC.str2term "a + (d + (c + b))";
neuper@37906
   191
"a + (d + (c + b))";
walther@59868
   192
val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
neuper@37906
   193
"a + (c + (d + b))";
walther@59868
   194
val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.commute} t;UnparseC.term t;
neuper@37906
   195
"a + (c + (b + d))";
walther@59868
   196
val SOME (t,_) = rewrite_ thy od Rule_Set.empty true @{thm add.left_commute} t;UnparseC.term t;
neuper@37906
   197
"a + (b + (c + d))";
neuper@37906
   198
neuper@37906
   199
"----- but we do not want the parentheses at right; thus: cond.rew.";
neuper@37906
   200
"WN0712707 complicated monomials do not yet work ...";
walther@60230
   201
val t = TermC.str2term "((5*a + 4*d) + 3*c) + 2*b";
walther@59868
   202
val SOME (t,_) = rewrite_set_ thy false order_add_mult t; UnparseC.term t;
walther@59868
   203
if UnparseC.term t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
neuper@38031
   204
else error "polyminus.sml: order_add_mult changed";
neuper@37906
   205
neuper@37906
   206
"----- here we see rew_sub going into subterm with ord.rew....";
neuper@41929
   207
val od = ord_make_polynomial false (@{theory "Poly"});
walther@60230
   208
val t = TermC.str2term "b + a + c + d";
walther@59868
   209
val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
walther@59868
   210
val SOME (t,_) = rewrite_ thy od Rule_Set.empty false @{thm add.commute} t; UnparseC.term t;
neuper@37906
   211
(*@@@ rew_sub gosub: t = d + (b + a + c)
neuper@37906
   212
  @@@ rew_sub begin: t = b + a + c*)
neuper@37906
   213
neuper@37906
   214
neuper@37906
   215
"----------- build predicate for +- ordering ---------------------";
neuper@37906
   216
"----------- build predicate for +- ordering ---------------------";
neuper@37906
   217
"----------- build predicate for +- ordering ---------------------";
neuper@37906
   218
"a" < "b";
neuper@37906
   219
"ba" < "ab";
neuper@37906
   220
"123" < "a"; (*unused due to ---vvv*)
neuper@37906
   221
"12" < "3"; (*true !!!*)
neuper@37906
   222
neuper@37906
   223
" a kleiner b ==> (b + a) = (a + b)";
walther@60230
   224
TermC.str2term "aaa";
walther@60230
   225
TermC.str2term "222 * aaa";
neuper@42390
   226
walther@60230
   227
case eval_kleiner 0 0 (TermC.str2term "123 kleiner 32") 0 of
neuper@42390
   228
    SOME ("123 kleiner 32 = False", _) => ()
neuper@38031
   229
  | _ => error "polyminus.sml: 12 kleiner 9 = False";
neuper@42390
   230
walther@60230
   231
case eval_kleiner 0 0 (TermC.str2term "a kleiner b") 0 of
neuper@37926
   232
    SOME ("a kleiner b = True", _) => ()
neuper@38031
   233
  | _ => error "polyminus.sml: a kleiner b = True";
neuper@37906
   234
walther@60230
   235
case eval_kleiner 0 0 (TermC.str2term "(10*g) kleiner f") 0 of
neuper@37926
   236
    SOME ("10 * g kleiner f = False", _) => ()
neuper@38031
   237
  | _ => error "polyminus.sml: 10 * g kleiner f = False";
neuper@37906
   238
walther@60242
   239
case eval_kleiner 0 0 (TermC.str2term "(a \<up> 2) kleiner b") 0 of
walther@60242
   240
    SOME ("a \<up> 2 kleiner b = True", _) => ()
walther@60242
   241
  | _ => error "polyminus.sml: a \<up> 2 kleiner b = True";
neuper@37906
   242
walther@60242
   243
case eval_kleiner 0 0 (TermC.str2term "(3*a \<up> 2) kleiner b") 0 of
walther@60242
   244
    SOME ("3 * a \<up> 2 kleiner b = True", _) => ()
walther@60242
   245
  | _ => error "polyminus.sml: 3 * a \<up> 2 kleiner b = True";
neuper@37906
   246
walther@60230
   247
case eval_kleiner 0 0 (TermC.str2term "(a*b) kleiner c") 0 of
neuper@37926
   248
    SOME ("a * b kleiner c = True", _) => ()
neuper@38031
   249
  | _ => error "polyminus.sml: a * b kleiner b = True";
neuper@37906
   250
walther@60230
   251
case eval_kleiner 0 0 (TermC.str2term "(3*a*b) kleiner c") 0 of
neuper@37926
   252
    SOME ("3 * a * b kleiner c = True", _) => ()
neuper@38031
   253
  | _ => error "polyminus.sml: 3 * a * b kleiner b = True";
neuper@37906
   254
neuper@42390
   255
"======= compare tausche_plus with real_num_collect";
neuper@37906
   256
val od = dummy_ord;
neuper@37906
   257
neuper@37906
   258
val erls = erls_ordne_alphabetisch;
walther@60230
   259
val t = TermC.str2term "b + a";
walther@59868
   260
val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
walther@59868
   261
if UnparseC.term t = "a + b" then ()
neuper@38031
   262
else error "polyminus.sml: ordne_alphabetisch1 b + a";
neuper@37906
   263
neuper@37906
   264
val erls = Atools_erls;
walther@60230
   265
val t = TermC.str2term "2*a + 3*a";
walther@59868
   266
val SOME (t,_) = rewrite_ thy od erls false @{thm real_num_collect} t; UnparseC.term t;
neuper@37906
   267
neuper@42390
   268
"======= test rewrite_, rewrite_set_";
walther@59901
   269
(*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
neuper@37906
   270
val erls = erls_ordne_alphabetisch;
walther@60230
   271
val t = TermC.str2term "b + a";
walther@59868
   272
val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
walther@59868
   273
if UnparseC.term t = "a + b" then ()
neuper@38031
   274
else error "polyminus.sml: ordne_alphabetisch a + b";
neuper@37906
   275
walther@60230
   276
val t = TermC.str2term "2*b + a";
walther@59868
   277
val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
walther@59868
   278
if UnparseC.term t = "a + 2 * b" then ()
neuper@38031
   279
else error "polyminus.sml: ordne_alphabetisch a + 2 * b";
neuper@37906
   280
walther@60230
   281
val t = TermC.str2term "a + c + b";
walther@59868
   282
val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
walther@59868
   283
if UnparseC.term t = "a + b + c" then ()
neuper@38031
   284
else error "polyminus.sml: ordne_alphabetisch a + b + c";
neuper@37906
   285
neuper@42390
   286
"======= rewrite goes into subterms";
walther@60325
   287
val t = TermC.str2term "a + c + b + d ::real";
walther@59868
   288
val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus_plus} t; UnparseC.term t;
walther@59868
   289
if UnparseC.term t = "a + b + c + d" then ()
neuper@38031
   290
else error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
neuper@37906
   291
walther@60230
   292
val t = TermC.str2term "a + c + d + b";
walther@59868
   293
val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; UnparseC.term t;
walther@59868
   294
if UnparseC.term t = "a + b + c + d" then ()
neuper@38031
   295
else error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
neuper@37906
   296
neuper@42390
   297
"======= here we see rew_sub going into subterm with cond.rew....";
walther@60230
   298
val t = TermC.str2term "b + a + c + d";
walther@59868
   299
val SOME (t,_) = rewrite_ thy od erls false @{thm tausche_plus} t; UnparseC.term t;
walther@59868
   300
if UnparseC.term t = "a + b + c + d" then ()
neuper@38031
   301
else error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
neuper@37906
   302
neuper@42390
   303
"======= compile rls for the most complicated terms";
walther@60230
   304
val t = TermC.str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
neuper@37906
   305
"5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
neuper@37926
   306
val SOME (t,_) = rewrite_set_ thy false ordne_alphabetisch t; 
walther@59868
   307
if UnparseC.term t = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g"
neuper@38031
   308
then () else error "polyminus.sml: ordne_alphabetisch finished";
neuper@37906
   309
neuper@37906
   310
neuper@37906
   311
"----------- build fasse_zusammen --------------------------------";
neuper@37906
   312
"----------- build fasse_zusammen --------------------------------";
neuper@37906
   313
"----------- build fasse_zusammen --------------------------------";
walther@60230
   314
val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";
neuper@37926
   315
val SOME (t,_) = rewrite_set_ thy false fasse_zusammen t;
walther@60325
   316
if UnparseC.term t = "3 + - 2 * e + 2 * f + 2 * g" then ()
neuper@38031
   317
else error "polyminus.sml: fasse_zusammen finished";
neuper@37906
   318
neuper@37906
   319
"----------- build verschoenere ----------------------------------";
neuper@37906
   320
"----------- build verschoenere ----------------------------------";
neuper@37906
   321
"----------- build verschoenere ----------------------------------";
walther@60230
   322
val t = TermC.str2term "3 + -2 * e + 2 * f + 2 * g";
neuper@37926
   323
val SOME (t,_) = rewrite_set_ thy false verschoenere t;
walther@59868
   324
if UnparseC.term t = "3 - 2 * e + 2 * f + 2 * g" then ()
neuper@38031
   325
else error "polyminus.sml: verschoenere 3 + -2 * e ...";
neuper@37906
   326
walther@59901
   327
(*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
walther@59901
   328
Rewrite.trace_on:=false;
neuper@37906
   329
neuper@37906
   330
"----------- met simplification for_polynomials with_minus -------";
neuper@37906
   331
"----------- met simplification for_polynomials with_minus -------";
neuper@37906
   332
"----------- met simplification for_polynomials with_minus -------";
neuper@37906
   333
val str = 
wneuper@59585
   334
"Program SimplifyScript (t_t::real) =                \
walther@59637
   335
\  (((Try (Rewrite_Set ordne_alphabetisch False)) #>     \
walther@59637
   336
\    (Try (Rewrite_Set fasse_zusammen False)) #>     \
neuper@38080
   337
\    (Try (Rewrite_Set verschoenere False))) t_t)"
walther@60230
   338
val sc = (inst_abs o Thm.term_of o the o (TermC.parse thy)) str;
walther@60230
   339
TermC.atomty sc;
neuper@37906
   340
neuper@38080
   341
"----------- me simplification.for_polynomials.with_minus";
neuper@38080
   342
"----------- me simplification.for_polynomials.with_minus";
neuper@38080
   343
"----------- me simplification.for_polynomials.with_minus";
neuper@38080
   344
val c = [];
neuper@38080
   345
val (p,_,f,nxt,_,pt) = 
neuper@38080
   346
      CalcTreeTEST 
neuper@38083
   347
        [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
neuper@38080
   348
           "normalform N"],
walther@59997
   349
	          ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
walther@59997
   350
	           ["simplification", "for_polynomials", "with_minus"]))];
neuper@38080
   351
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@38085
   352
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@38085
   353
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@38085
   354
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@38085
   355
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@38085
   356
val (p,_,f,nxt,_,pt) = me nxt p c pt;
neuper@37906
   357
neuper@38085
   358
val (p,_,f,nxt,_,pt) = me nxt p c pt;
walther@60325
   359
   f2str f = "5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";      (*isa == isa2*)
walther@60325
   360
val (p''''',_,f,nxt''''',_,pt''''') = me nxt p c pt;
walther@60325
   361
   val                                 (*^^^*) Rewrite_Set "ordne_alphabetisch" = nxt;
walther@60325
   362
   f2str f = "- 9 + 12 + 5 * e - 7 * e + 6 * f - 4 * f - 8 * g + 10 * g";    (*isa2*)
walther@60325
   363
val (p,_,f,nxt,_,pt) = me nxt''''' p''''' c pt''''';
walther@60325
   364
   f2str f = "3 + - 2 * e + 2 * f + 2 * g";                                  (*isa2*)
neuper@38085
   365
val (p,_,f,nxt,_,pt) = me nxt p c pt;
walther@60325
   366
   f2str f = "3 - 2 * e + 2 * f + 2 * g";                                    (*isa2*)
neuper@38085
   367
val (p,_,f,nxt,_,pt) = me nxt p c pt;
walther@60325
   368
   f2str f = "3 - 2 * e + 2 * f + 2 * g";                                    (*isa2*)
walther@60325
   369
if f2str f = "3 - 2 * e + 2 * f + 2 * g"                                     (*isa2*)
walther@59749
   370
then case nxt of End_Proof' => () | _ =>  error "me simplification.for_polynomials.with_minus 1"
walther@59749
   371
else error "polyminus.sml: me simplification.for_polynomials.with_minus 2";
neuper@38085
   372
neuper@37906
   373
"----------- pbl polynom vereinfachen p.33 -----------------------";
neuper@37906
   374
"----------- pbl polynom vereinfachen p.33 -----------------------";
neuper@37906
   375
"----------- pbl polynom vereinfachen p.33 -----------------------";
neuper@37906
   376
"----------- 140 c ---";
s1210629013@55445
   377
reset_states ();
neuper@38083
   378
CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
neuper@37906
   379
	    "normalform N"],
walther@59997
   380
	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
walther@59997
   381
	    ["simplification", "for_polynomials", "with_minus"]))];
neuper@37906
   382
moveActiveRoot 1;
wneuper@59248
   383
autoCalculate 1 CompleteCalc;
walther@59983
   384
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@37906
   385
if p = ([], Res) andalso 
walther@59868
   386
   UnparseC.term (get_obj g_res pt (fst p)) = "3 - 2 * e + 2 * f + 2 * g"
neuper@38031
   387
then () else error "polyminus.sml: Vereinfache (3 - 2 * e + 2 * f...";
neuper@37906
   388
neuper@42390
   389
"======= 140 d ---";
s1210629013@55445
   390
reset_states ();
neuper@38083
   391
CalcTree [(["Term (-r - 2*s - 3*t + 5 + 4*r + 8*s - 5*t - 2)",
neuper@37906
   392
	    "normalform N"],
walther@59997
   393
	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
walther@59997
   394
	    ["simplification", "for_polynomials", "with_minus"]))];
neuper@37906
   395
moveActiveRoot 1;
wneuper@59248
   396
autoCalculate 1 CompleteCalc;
walther@59983
   397
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@37906
   398
if p = ([], Res) andalso 
walther@59868
   399
   UnparseC.term (get_obj g_res pt (fst p)) = "3 + 3 * r + 6 * s - 8 * t"
neuper@38031
   400
then () else error "polyminus.sml: Vereinfache 140 d)";
neuper@37906
   401
neuper@42390
   402
"======= 139 c ---";
s1210629013@55445
   403
reset_states ();
neuper@38083
   404
CalcTree [(["Term (3*e - 6*f - 8*e - 4*f + 5*e + 7*f)",
neuper@37906
   405
	    "normalform N"],
walther@59997
   406
	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
walther@59997
   407
	    ["simplification", "for_polynomials", "with_minus"]))];
neuper@37906
   408
moveActiveRoot 1;
wneuper@59248
   409
autoCalculate 1 CompleteCalc;
walther@59983
   410
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@37906
   411
if p = ([], Res) andalso 
walther@59868
   412
   UnparseC.term (get_obj g_res pt (fst p)) = "- (3 * f)"
neuper@38031
   413
then () else error "polyminus.sml: Vereinfache 139 c)";
neuper@37906
   414
neuper@42390
   415
"======= 139 b ---";
s1210629013@55445
   416
reset_states ();
neuper@38083
   417
CalcTree [(["Term (8*u - 5*v - 5*u + 7*v - 6*u - 3*v)",
neuper@37906
   418
	    "normalform N"],
walther@59997
   419
	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
walther@59997
   420
	    ["simplification", "for_polynomials", "with_minus"]))];
neuper@37906
   421
moveActiveRoot 1;
wneuper@59248
   422
autoCalculate 1 CompleteCalc;
walther@59983
   423
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@37906
   424
if p = ([], Res) andalso 
walther@60325
   425
   UnparseC.term (get_obj g_res pt (fst p)) = "- 3 * u - v"
neuper@38031
   426
then () else error "polyminus.sml: Vereinfache 139 b)";
neuper@37906
   427
neuper@42390
   428
"======= 138 a ---";
s1210629013@55445
   429
reset_states ();
neuper@38083
   430
CalcTree [(["Term (2*u - 3*v - 6*u + 5*v)",
neuper@37906
   431
	    "normalform N"],
walther@59997
   432
	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
walther@59997
   433
	    ["simplification", "for_polynomials", "with_minus"]))];
neuper@37906
   434
moveActiveRoot 1;
wneuper@59248
   435
autoCalculate 1 CompleteCalc;
walther@59983
   436
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@37906
   437
if p = ([], Res) andalso 
walther@60325
   438
   UnparseC.term (get_obj g_res pt (fst p)) = "- 4 * u + 2 * v"
neuper@38031
   439
then () else error "polyminus.sml: Vereinfache 138 a)";
neuper@37906
   440
neuper@37906
   441
"----------- met probe fuer_polynom ------------------------------";
neuper@37906
   442
"----------- met probe fuer_polynom ------------------------------";
neuper@37906
   443
"----------- met probe fuer_polynom ------------------------------";
neuper@37906
   444
val str = 
wneuper@59585
   445
"Program ProbeScript (e_e::bool) (w_s::bool list) =\
neuper@37991
   446
\ (let e_e = Take e_e;                             \
neuper@38085
   447
\      e_e = Substitute w_s e_e                    \
walther@59637
   448
\ in (Repeat((Try (Repeat (Calculate ''TIMES''))) #>  \
walther@59637
   449
\            (Try (Repeat (Calculate ''PLUS''))) #>  \
wneuper@59488
   450
\            (Try (Repeat (Calculate ''MINUS''))))) e_e)"
walther@60230
   451
val sc = (inst_abs o Thm.term_of o the o (TermC.parse thy)) str;
walther@60230
   452
TermC.atomty sc;
neuper@37906
   453
neuper@37906
   454
"----------- pbl polynom probe -----------------------------------";
neuper@37906
   455
"----------- pbl polynom probe -----------------------------------";
neuper@37906
   456
"----------- pbl polynom probe -----------------------------------";
s1210629013@55445
   457
reset_states ();
bonzai@41949
   458
CalcTree [(["Pruefe ((5::int)*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12 =\
wneuper@59582
   459
	    \3 - 2 * e + 2 * f + 2 * (g::int))",
wneuper@59582
   460
	    "mitWert [e = (1::int), f = (2::int), g = (3::int)]",
neuper@37906
   461
	    "Geprueft b"],
walther@59997
   462
	   ("PolyMinus",["polynom", "probe"],
walther@59997
   463
	    ["probe", "fuer_polynom"]))];
neuper@37906
   464
moveActiveRoot 1;
wneuper@59248
   465
autoCalculate 1 CompleteCalc;
wneuper@59248
   466
(* autoCalculate 1 CompleteCalcHead;
walther@59747
   467
   autoCalculate 1 (Steps 1);
walther@59747
   468
   autoCalculate 1 (Steps 1);
walther@59868
   469
   val ((pt,p),_) = get_calc 1; UnparseC.term (get_obj g_res pt (fst p));
neuper@37906
   470
@@@@@WN081114 gives "??.empty", all "Pruefe" are the same,
neuper@37906
   471
although analogies work in interface.sml: FIXME.WN081114 in "Pruefe"*)
neuper@37906
   472
val ((pt,p),_) = get_calc 1;
walther@59868
   473
if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "11 = 11"
neuper@38031
   474
then () else error "polyminus.sml: Probe 11 = 11";
walther@59983
   475
Test_Tool.show_pt pt;
t@42115
   476
neuper@37906
   477
"----------- pbl klammer polynom vereinfachen p.34 ---------------";
neuper@37906
   478
"----------- pbl klammer polynom vereinfachen p.34 ---------------";
neuper@37906
   479
"----------- pbl klammer polynom vereinfachen p.34 ---------------";
s1210629013@55445
   480
reset_states ();
neuper@38083
   481
CalcTree [(["Term (2*u - 5 - (3 - 4*u) + (8*u + 9))",
neuper@37906
   482
	    "normalform N"],
walther@59997
   483
	   ("PolyMinus",["klammer", "polynom", "vereinfachen"],
walther@59997
   484
	    ["simplification", "for_polynomials", "with_parentheses"]))];
neuper@37906
   485
moveActiveRoot 1;
wneuper@59248
   486
autoCalculate 1 CompleteCalc;
neuper@37906
   487
val ((pt,p),_) = get_calc 1;
neuper@37906
   488
if p = ([], Res) andalso 
walther@59868
   489
   UnparseC.term (get_obj g_res pt (fst p)) = "1 + 14 * u"
neuper@38031
   490
then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
walther@59983
   491
Test_Tool.show_pt pt;
neuper@37906
   492
neuper@42390
   493
"======= probe p.34 -----";
s1210629013@55445
   494
reset_states ();
wneuper@59582
   495
CalcTree [(["Pruefe (2*u - 5 - (3 - 4*u) + (8*u + 9) = 1 + 14 * (u::int))",
wneuper@59582
   496
	    "mitWert [u = (2::int)]",
neuper@37906
   497
	    "Geprueft b"],
walther@59997
   498
	   ("PolyMinus",["polynom", "probe"],
walther@59997
   499
	    ["probe", "fuer_polynom"]))];
neuper@37906
   500
moveActiveRoot 1;
wneuper@59248
   501
autoCalculate 1 CompleteCalc;
neuper@37906
   502
val ((pt,p),_) = get_calc 1;
walther@59868
   503
if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "29 = 29"
neuper@38031
   504
then () else error "polyminus.sml: Probe 29 = 29";
walther@59983
   505
Test_Tool.show_pt pt;
neuper@37906
   506
neuper@37906
   507
"----------- try fun applyTactics --------------------------------";
neuper@37906
   508
"----------- try fun applyTactics --------------------------------";
neuper@37906
   509
"----------- try fun applyTactics --------------------------------";
s1210629013@55445
   510
reset_states ();
neuper@38083
   511
CalcTree [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
neuper@37906
   512
	    "normalform N"],
walther@59997
   513
	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
walther@59997
   514
	    ["simplification", "for_polynomials", "with_minus"]))];
neuper@37906
   515
moveActiveRoot 1;
wneuper@59248
   516
autoCalculate 1 CompleteCalcHead;
walther@59747
   517
autoCalculate 1 (Steps 1);
walther@59747
   518
autoCalculate 1 (Steps 1);
walther@59983
   519
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
walther@60242
   520
"----- 1  \<up> ";
neuper@37906
   521
fetchApplicableTactics 1 0 p;
walther@59823
   522
val appltacs = specific_from_prog pt p;
neuper@37906
   523
applyTactic 1 p (hd appltacs) (*addiere_x_plus_minus*);
walther@59983
   524
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
walther@60242
   525
"----- 2  \<up> ";
walther@59901
   526
(*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
neuper@37906
   527
val erls = erls_ordne_alphabetisch;
walther@60230
   528
val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
neuper@37926
   529
val SOME (t',_) = 
wneuper@59592
   530
    rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus} t;
walther@59868
   531
UnparseC.term t';     "- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f - 8 * g + 10 * g";
neuper@37906
   532
walther@60230
   533
val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
neuper@37926
   534
val NONE = 
wneuper@59592
   535
    rewrite_ (@{theory "Isac_Knowledge"}) e_rew_ord erls false @{thm tausche_minus_plus} t;
neuper@37906
   536
walther@60230
   537
val t = TermC.str2term "- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f - 8 * g + 10 * g";
neuper@37926
   538
val SOME (t',_) = 
wneuper@59592
   539
    rewrite_set_ (@{theory "Isac_Knowledge"}) false ordne_alphabetisch t;
walther@59868
   540
UnparseC.term t';     "- 9 + 12 + 5 * e - 7 * e - 8 * g + 10 * g + (- 4 + 6) * f";
walther@59901
   541
Rewrite.trace_on := false;
neuper@37906
   542
neuper@37906
   543
walther@59823
   544
applyTactic 1 p (hd (specific_from_prog pt p)) (*tausche_minus*);
walther@59983
   545
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
walther@60242
   546
"----- 3  \<up> ";
walther@59823
   547
applyTactic 1 p (hd (specific_from_prog pt p)) (**);
walther@59983
   548
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
walther@60242
   549
"----- 4  \<up> ";
walther@59823
   550
applyTactic 1 p (hd (specific_from_prog pt p)) (**);
walther@59983
   551
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
walther@60242
   552
"----- 5  \<up> ";
walther@59823
   553
applyTactic 1 p (hd (specific_from_prog pt p)) (**);
walther@59983
   554
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
walther@60242
   555
"----- 6  \<up> ";
neuper@37906
   556
neuper@37906
   557
(*<CALCMESSAGE> failure </CALCMESSAGE>
walther@59823
   558
applyTactic 1 p (hd (specific_from_prog pt p)) (**);
walther@59983
   559
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
walther@60242
   560
"----- 7  \<up> ";
neuper@37906
   561
*)
wneuper@59248
   562
autoCalculate 1 CompleteCalc;
walther@59983
   563
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
neuper@37906
   564
(*independent from failure above: met_simp_poly_minus not confluent:
neuper@37906
   565
(([9], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f)),
neuper@37906
   566
(([], Res), - (8 * g) + 10 * g + (3 - 2 * e + 2 * f))]
neuper@37906
   567
~~~~~~~~~~~###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*)
t@42115
   568
neuper@37906
   569
neuper@42107
   570
"#############################################################################";
s1210629013@55445
   571
reset_states ();
neuper@38083
   572
CalcTree [(["Term (- (8 * g) + 10 * g + h)",
neuper@37906
   573
	    "normalform N"],
walther@59997
   574
	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
walther@59997
   575
	    ["simplification", "for_polynomials", "with_minus"]))];
neuper@37906
   576
moveActiveRoot 1;
wneuper@59248
   577
autoCalculate 1 CompleteCalc;
walther@59983
   578
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
walther@59868
   579
if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "2 * g + h"
neuper@38031
   580
then () else error "polyminus.sml: addiere_vor_minus";
neuper@37906
   581
neuper@37906
   582
neuper@42107
   583
"#############################################################################";
s1210629013@55445
   584
reset_states ();
neuper@38083
   585
CalcTree [(["Term (- (8 * g) + 10 * g + f)",
neuper@37906
   586
	    "normalform N"],
walther@59997
   587
	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
walther@59997
   588
	    ["simplification", "for_polynomials", "with_minus"]))];
neuper@37906
   589
moveActiveRoot 1;
wneuper@59248
   590
autoCalculate 1 CompleteCalc;
walther@59983
   591
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
walther@59868
   592
if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "f + 2 * g"
neuper@38031
   593
then () else error "polyminus.sml: tausche_vor_plus";
neuper@37906
   594
neuper@37906
   595
"----------- pbl binom polynom vereinfachen p.39 -----------------";
neuper@37906
   596
"----------- pbl binom polynom vereinfachen p.39 -----------------";
neuper@37906
   597
"----------- pbl binom polynom vereinfachen p.39 -----------------";
neuper@37906
   598
val rls = klammern_ausmultiplizieren;
walther@60230
   599
val t = TermC.str2term "(3 * a + 2) * (4 * a - 1)";
walther@59868
   600
val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
neuper@37906
   601
"3 * a * (4 * a) - 3 * a * 1 + (2 * (4 * a) - 2 * 1)";
neuper@37906
   602
val rls = discard_parentheses;
walther@59868
   603
val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
neuper@37906
   604
"3 * a * 4 * a - 3 * a * 1 + (2 * 4 * a - 2 * 1)";
neuper@37906
   605
val rls = ordne_monome;
walther@59868
   606
val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
neuper@37906
   607
"3 * 4 * a * a - 1 * 3 * a + (2 * 4 * a - 1 * 2)";
neuper@37906
   608
(*
walther@60230
   609
val t = TermC.str2term "3 * a * 4 * a";
neuper@37906
   610
val rls = ordne_monome;
walther@59868
   611
val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
neuper@37906
   612
*)
neuper@37906
   613
val rls = klammern_aufloesen;
walther@59868
   614
val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
neuper@37906
   615
"3 * 4 * a * a - 1 * 3 * a + 2 * 4 * a - 1 * 2";
neuper@37906
   616
val rls = ordne_alphabetisch;
neuper@37906
   617
(*TODO: make is_monom more general, a*a=a^2, ...*)
walther@59868
   618
val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
neuper@37906
   619
"3 * 4 * a * a - 1 * 2 - 1 * 3 * a + 2 * 4 * a";
neuper@41977
   620
(*STOPPED.WN080104
neuper@37906
   621
val rls = fasse_zusammen;
walther@59868
   622
val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
neuper@37906
   623
val rls = verschoenere;
walther@59868
   624
val SOME (t,_) = rewrite_set_ thy false rls t; UnparseC.term t;
neuper@37906
   625
*)
neuper@37906
   626
neuper@37906
   627
(*@@@@@@@*)
s1210629013@55445
   628
reset_states ();
neuper@38083
   629
CalcTree [(["Term ((3*a + 2) * (4*a - 1))",
neuper@37906
   630
	    "normalform N"],
walther@59997
   631
	   ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
walther@59997
   632
	    ["simplification", "for_polynomials", "with_parentheses_mult"]))];
neuper@37906
   633
moveActiveRoot 1;
wneuper@59248
   634
autoCalculate 1 CompleteCalc;
walther@59983
   635
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
walther@60325
   636
walther@60325
   637
if p = ([], Res) andalso
walther@60325
   638
   UnparseC.term (get_obj g_res pt (fst p)) =(*"- 2 + 12 * a \<up> 2 + 5 * a" with OLD numerals*)
walther@60325
   639
                                               "- 2 + 5 * a + 12 * a \<up> 2"
neuper@38031
   640
then () else error "polyminus.sml: Vereinfache (2*u - 5 - (3 - ...";
t@42111
   641
neuper@37906
   642
"----------- pbl binom polynom vereinfachen: cube ----------------";
neuper@37906
   643
"----------- pbl binom polynom vereinfachen: cube ----------------";
neuper@37906
   644
"----------- pbl binom polynom vereinfachen: cube ----------------";
s1210629013@55445
   645
reset_states ();
neuper@38083
   646
CalcTree [(["Term (8*(a - q) + a - 2*q + 3*(a - 2*q))", "normalform N"],
walther@59997
   647
	   ("PolyMinus",["binom_klammer", "polynom", "vereinfachen"],
walther@59997
   648
	    ["simplification", "for_polynomials", "with_parentheses_mult"]))];
neuper@37906
   649
moveActiveRoot 1;
wneuper@59248
   650
autoCalculate 1 CompleteCalc;
walther@59983
   651
val ((pt,p),_) = get_calc 1; Test_Tool.show_pt pt;
walther@59868
   652
if p = ([], Res) andalso UnparseC.term (get_obj g_res pt (fst p)) = "12 * a - 16 * q" 
neuper@42107
   653
then () else error "pbl binom polynom vereinfachen: cube";
neuper@37906
   654
walther@59968
   655
"----------- Refine.refine Vereinfache ----------------------------------";
walther@59968
   656
"----------- Refine.refine Vereinfache ----------------------------------";
walther@59968
   657
"----------- Refine.refine Vereinfache ----------------------------------";
neuper@42390
   658
val fmz = ["Term (8*(a - q) + a - 2*q + 3*(a - 2*(q::real)))", "normalform (N::real)"];
wneuper@59348
   659
(*default_print_depth 11;*)
wenzelm@60237
   660
val matches = Refine.refine fmz ["vereinfachen"];
wneuper@59348
   661
(*default_print_depth 3;*)
neuper@37906
   662
neuper@37906
   663
"----- go into details, if it seems not to work -----";
neuper@37906
   664
"--- does the predicate evaluate correctly ?";
walther@60230
   665
val t = TermC.str2term 
neuper@42390
   666
	    "matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q + 3 * (a - 2 * (q::real)))";
walther@59603
   667
val ma = eval_matchsub "" "Prog_Expr.matchsub" t thy;
neuper@37906
   668
case ma of
neuper@37926
   669
    SOME ("matchsub (?a * (?b - ?c)) (8 * (a - q) + \
neuper@37906
   670
	  \a - 2 * q + 3 * (a - 2 * q)) = True", _) => ()
neuper@38031
   671
  | _ => error "polyminus.sml matchsub (?a * (?b - ?c)...A";
neuper@37906
   672
neuper@37906
   673
"--- does the respective prls rewrite ?";
walther@59852
   674
val prls = Rule_Set.append_rules "prls_pbl_vereinf_poly" Rule_Set.empty 
walther@60278
   675
	     [Eval ("Poly.is_polyexp", eval_is_polyexp ""),
walther@59878
   676
	      Eval ("Prog_Expr.matchsub", eval_matchsub ""),
neuper@38085
   677
	      Thm ("or_true",@{thm or_true}),
neuper@37906
   678
	      (*"(?a | True) = True"*)
neuper@38085
   679
	      Thm ("or_false",@{thm or_false}),
neuper@37906
   680
	      (*"(?a | False) = ?a"*)
walther@59871
   681
	      Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
neuper@37906
   682
	      (*"(~ True) = False"*)
walther@59871
   683
	      Thm ("not_false",ThmC.numerals_to_Free @{thm not_false})
neuper@37906
   684
	      (*"(~ False) = True"*)];
walther@59901
   685
(*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
neuper@37926
   686
val SOME (t', _) = rewrite_set_ thy false prls t;
walther@59901
   687
Rewrite.trace_on := false;
neuper@37906
   688
neuper@37906
   689
"--- does the respective prls rewrite the whole predicate ?";
walther@60230
   690
val t = TermC.str2term 
neuper@37906
   691
	    "Not (matchsub (?a * (?b + ?c)) (8 * (a - q) + a - 2 * q) | \
neuper@37906
   692
	    \     matchsub (?a * (?b - ?c)) (8 * (a - q) + a - 2 * q) | \
neuper@37906
   693
	    \     matchsub ((?b + ?c) * ?a) (8 * (a - q) + a - 2 * q) | \
neuper@37906
   694
	    \     matchsub ((?b - ?c) * ?a) (8 * (a - q) + a - 2 * q) )";
walther@59901
   695
(*Rewrite.trace_on := true; ..stopped Test_Isac.thy*)
neuper@37926
   696
val SOME (t', _) = rewrite_set_ thy false prls t;
walther@59901
   697
Rewrite.trace_on := false;
walther@59868
   698
if UnparseC.term t' = "False" then ()
neuper@38031
   699
else error "polyminus.sml Not (matchsub (?a * (?b + ?c)) (8 ...";
neuper@37906
   700
walther@59973
   701
"----------- *** Problem.prep_input: syntax error in '#Where' of [v";
walther@59973
   702
"----------- *** Problem.prep_input: syntax error in '#Where' of [v";
walther@59973
   703
"----------- *** Problem.prep_input: syntax error in '#Where' of [v";
neuper@38037
   704
(*see test/../termC.sml for details*)
walther@60230
   705
val t = TermC.parse_patt thy "t_t is_polyexp";
walther@60230
   706
val t = TermC.parse_patt thy ("Not (matchsub (?a + (?b + ?c)) t_t | " ^
neuper@38037
   707
	                "     matchsub (?a + (?b - ?c)) t_t | " ^
neuper@38037
   708
	                "     matchsub (?a - (?b + ?c)) t_t | " ^
neuper@38037
   709
	                "     matchsub (?a + (?b - ?c)) t_t )");
neuper@42390
   710
(*show_types := true;
walther@59868
   711
if UnparseC.term t = "~ (matchsub ((?a::real) + ((?b::real) + (?c::real))) (t_t::real) |\n   matchsub (?a + (?b - ?c)) t_t |\n   matchsub (?a - (?b + ?c)) t_t | matchsub (?a + (?b - ?c)) t_t)"
neuper@38038
   712
then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
neuper@42390
   713
show_types := false;*)
walther@59868
   714
if UnparseC.term t =
wneuper@59371
   715
  "\<not> (matchsub (?a + (?b + ?c)) t_t \<or>\n        " ^
wneuper@59371
   716
  "matchsub (?a + (?b - ?c)) t_t \<or>\n        " ^
wneuper@59371
   717
  "matchsub (?a - (?b + ?c)) t_t \<or> " ^
wneuper@59371
   718
  "matchsub (?a + (?b - ?c)) t_t)"
neuper@42390
   719
then () else error "polyminus.sml type-structure of \"?a :: real\" changed 1";
neuper@37906
   720