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