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