test/Tools/isac/Knowledge/poly-1.sml
changeset 60565 f92963a33fe3
parent 60509 2e0b7ca391dc
child 60660 c4b24621077e
equal deleted inserted replaced
60564:90ea835c07b3 60565:f92963a33fe3
    28 
    28 
    29 
    29 
    30 "-------- fun is_polyexp -----------------------------------------------------------------------";
    30 "-------- fun is_polyexp -----------------------------------------------------------------------";
    31 "-------- fun is_polyexp -----------------------------------------------------------------------";
    31 "-------- fun is_polyexp -----------------------------------------------------------------------";
    32 "-------- fun is_polyexp -----------------------------------------------------------------------";
    32 "-------- fun is_polyexp -----------------------------------------------------------------------";
    33 val t = TermC.str2term "x / x";
    33 val t = TermC.parse_test @{context} "x / x";
    34 if is_polyexp t then error "NOT is_polyexp (x / x)" else ();
    34 if is_polyexp t then error "NOT is_polyexp (x / x)" else ();
    35 
    35 
    36 val t = TermC.str2term "- 1 * A * 3";
    36 val t = TermC.parse_test @{context} "- 1 * A * 3";
    37 if is_polyexp t then () else error "is_polyexp (- 1 * A * 3)";
    37 if is_polyexp t then () else error "is_polyexp (- 1 * A * 3)";
    38 
    38 
    39 val t = TermC.str2term "- 1 * AA * 3";
    39 val t = TermC.parse_test @{context} "- 1 * AA * 3";
    40 if is_polyexp t then () else error "is_polyexp (- 1 * AA * 3)";
    40 if is_polyexp t then () else error "is_polyexp (- 1 * AA * 3)";
    41 
    41 
    42 val t = TermC.str2term "x * x + x * y + (- 1 * y * x + - 1 * y * y)::real";
    42 val t = TermC.parse_test @{context} "x * x + x * y + (- 1 * y * x + - 1 * y * y)::real";
    43 if is_polyexp t then () else error "is_polyexp (x * x + x * y + (- 1 * y * x + - 1 * y * y))";
    43 if is_polyexp t then () else error "is_polyexp (x * x + x * y + (- 1 * y * x + - 1 * y * y))";
    44 
    44 
    45 "-------- fun has_degree_in --------------------------------------------------------------------";
    45 "-------- fun has_degree_in --------------------------------------------------------------------";
    46 "-------- fun has_degree_in --------------------------------------------------------------------";
    46 "-------- fun has_degree_in --------------------------------------------------------------------";
    47 "-------- fun has_degree_in --------------------------------------------------------------------";
    47 "-------- fun has_degree_in --------------------------------------------------------------------";
   262 
   262 
   263 "-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
   263 "-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
   264 "-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
   264 "-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
   265 "-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
   265 "-------- fun is_addUnordered (x \<up> 2 * y \<up> 2 + x \<up> 3 * y) --------------------------------------";
   266 val ctxt = Proof_Context.init_global @{theory}
   266 val ctxt = Proof_Context.init_global @{theory}
   267 val t = TermC.str2term "x \<up> 2 * y \<up> 2 + x * x \<up> 2 * y";
   267 val t = TermC.parse_test @{context} "x \<up> 2 * y \<up> 2 + x * x \<up> 2 * y";
   268 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   268 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   269    UnparseC.term t = "x \<up> 2 * y \<up> 2 + x \<up> 3 * y";
   269    UnparseC.term t = "x \<up> 2 * y \<up> 2 + x \<up> 3 * y";
   270 if UnparseC.term t = "x \<up> 3 * y + x \<up> 2 * y \<up> 2" then ()
   270 if UnparseC.term t = "x \<up> 3 * y + x \<up> 2 * y \<up> 2" then ()
   271 else error "poly.sml: diff.behav. in make_polynomial 23";
   271 else error "poly.sml: diff.behav. in make_polynomial 23";
   272 
   272 
   278 ########  eval asms: "x \<up> 2 * y \<up> 2 + x \<up> 3 * y is_addUnordered = False"  (*isa*)
   278 ########  eval asms: "x \<up> 2 * y \<up> 2 + x \<up> 3 * y is_addUnordered = False"  (*isa*)
   279                                                                               True"   (*isa2*)
   279                                                                               True"   (*isa2*)
   280 #######  calc. to: False  (*isa*)
   280 #######  calc. to: False  (*isa*)
   281                    True   (*isa2*)
   281                    True   (*isa2*)
   282 ( **)
   282 ( **)
   283         if is_addUnordered (TermC.str2term "x \<up> 2 * y \<up> 2 + x \<up> 3 * y ::real") then ()
   283         if is_addUnordered (TermC.parse_test @{context} "x \<up> 2 * y \<up> 2 + x \<up> 3 * y ::real") then ()
   284 else error"is_addUnordered  x \<up> 2 * y \<up> 2 + x \<up> 3 * y"; (*isa == isa2*)
   284 else error"is_addUnordered  x \<up> 2 * y \<up> 2 + x \<up> 3 * y"; (*isa == isa2*)
   285 "~~~~~ fun is_addUnordered , args:"; val (t) = (TermC.str2term "x \<up> 2 * y \<up> 2 + x \<up> 3 * y ::real");
   285 "~~~~~ fun is_addUnordered , args:"; val (t) = (TermC.parse_test @{context} "x \<up> 2 * y \<up> 2 + x \<up> 3 * y ::real");
   286       ((is_polyexp t) andalso not (t = sort_monoms t)) = false;  (*isa == isa2*)
   286       ((is_polyexp t) andalso not (t = sort_monoms t)) = false;  (*isa == isa2*)
   287 
   287 
   288 (*+*) if is_polyexp t = true then () else error "is_polyexp  x \<up> 2 * y \<up> 2 + x \<up> 3 * y";
   288 (*+*) if is_polyexp t = true then () else error "is_polyexp  x \<up> 2 * y \<up> 2 + x \<up> 3 * y";
   289 
   289 
   290 (*+*) if                           t = sort_monoms t = false then () else error "sort_monoms 123";
   290 (*+*) if                           t = sort_monoms t = false then () else error "sort_monoms 123";
   410 
   410 
   411 "-------- check make_polynomial with simple terms ----------------------------------------------";
   411 "-------- check make_polynomial with simple terms ----------------------------------------------";
   412 "-------- check make_polynomial with simple terms ----------------------------------------------";
   412 "-------- check make_polynomial with simple terms ----------------------------------------------";
   413 "-------- check make_polynomial with simple terms ----------------------------------------------";
   413 "-------- check make_polynomial with simple terms ----------------------------------------------";
   414 "----- check 1 ---";
   414 "----- check 1 ---";
   415 val t = TermC.str2term "2*3*a";
   415 val t = TermC.parse_test @{context} "2*3*a";
   416 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   416 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   417 if UnparseC.term t = "6 * a" then () else error "check make_polynomial 1";
   417 if UnparseC.term t = "6 * a" then () else error "check make_polynomial 1";
   418 
   418 
   419 "----- check 2 ---";
   419 "----- check 2 ---";
   420 val t = TermC.str2term "2*a + 3*a";
   420 val t = TermC.parse_test @{context} "2*a + 3*a";
   421 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   421 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   422 if UnparseC.term t = "5 * a" then () else error "check make_polynomial 2";
   422 if UnparseC.term t = "5 * a" then () else error "check make_polynomial 2";
   423 
   423 
   424 "----- check 3 ---";
   424 "----- check 3 ---";
   425 val t = TermC.str2term "2*a + 3*a + 3*a";
   425 val t = TermC.parse_test @{context} "2*a + 3*a + 3*a";
   426 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   426 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   427 if UnparseC.term t = "8 * a" then () else error "check make_polynomial 3";
   427 if UnparseC.term t = "8 * a" then () else error "check make_polynomial 3";
   428 
   428 
   429 "----- check 4 ---";
   429 "----- check 4 ---";
   430 val t = TermC.str2term "3*a - 2*a";
   430 val t = TermC.parse_test @{context} "3*a - 2*a";
   431 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   431 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   432 if UnparseC.term t = "a" then () else error "check make_polynomial 4";
   432 if UnparseC.term t = "a" then () else error "check make_polynomial 4";
   433 
   433 
   434 "----- check 5 ---";
   434 "----- check 5 ---";
   435 val t = TermC.str2term "4*(3*a - 2*a)";
   435 val t = TermC.parse_test @{context} "4*(3*a - 2*a)";
   436 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   436 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   437 if UnparseC.term t = "4 * a" then () else error "check make_polynomial 5";
   437 if UnparseC.term t = "4 * a" then () else error "check make_polynomial 5";
   438 
   438 
   439 "----- check 6 ---";
   439 "----- check 6 ---";
   440 val t = TermC.str2term "4*(3*a \<up> 2 - 2*a \<up> 2)";
   440 val t = TermC.parse_test @{context} "4*(3*a \<up> 2 - 2*a \<up> 2)";
   441 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   441 val SOME (t, _) = rewrite_set_ ctxt false make_polynomial t;
   442 if UnparseC.term t = "4 * a \<up> 2" then () else error "check make_polynomial 6";
   442 if UnparseC.term t = "4 * a \<up> 2" then () else error "check make_polynomial 6";
   443 
   443 
   444 "-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
   444 "-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
   445 "-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
   445 "-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
   446 "-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
   446 "-------- fun is_multUnordered (x \<up> 2 * x) -----------------------------------------------------";
   447 val thy = @{theory "Isac_Knowledge"};
   447 val thy = @{theory "Isac_Knowledge"};
   448 "===== works for a simple example, see rewrite.sml -- fun app_rev ===";
   448 "===== works for a simple example, see rewrite.sml -- fun app_rev ===";
   449 val t = TermC.str2term "x \<up> 2 * x";
   449 val t = TermC.parse_test @{context} "x \<up> 2 * x";
   450 val SOME (t', _) = rewrite_set_ ctxt true order_mult_ t;
   450 val SOME (t', _) = rewrite_set_ ctxt true order_mult_ t;
   451 if UnparseC.term t' = "x * x \<up> 2" then ()
   451 if UnparseC.term t' = "x * x \<up> 2" then ()
   452 else error "poly.sml Poly.is_multUnordered doesn't work";
   452 else error "poly.sml Poly.is_multUnordered doesn't work";
   453 
   453 
   454 (* 100928 Rewrite.trace_on shows the first occurring difference in 267b:
   454 (* 100928 Rewrite.trace_on shows the first occurring difference in 267b:
   456  (-48 * x \<up> 4 + 8))
   456  (-48 * x \<up> 4 + 8))
   457 ######  rls: Rule_Set.empty-is_multUnordered on: p is_multUnordered
   457 ######  rls: Rule_Set.empty-is_multUnordered on: p is_multUnordered
   458 #######  try calc: Poly.is_multUnordered'
   458 #######  try calc: Poly.is_multUnordered'
   459 =======  calc. to: False  !!!!!!!!!!!!! INSTEAD OF TRUE in 2002 !!!!!!!!!!!!!
   459 =======  calc. to: False  !!!!!!!!!!!!! INSTEAD OF TRUE in 2002 !!!!!!!!!!!!!
   460 *)
   460 *)
   461 val t = TermC.str2term "5 * x \<up> 2 * (2 * x \<up> 7) + 5 * x \<up> 2 * 3 + (6 * x \<up> 7 + 9) + (- 1 * (3 * x \<up> 5 * (6 * x \<up> 4)) + - 1 * (3 * x \<up> 5 * - 1) +  (-48 * x \<up> 4 + 8))";
   461 val t = TermC.parse_test @{context} "5 * x \<up> 2 * (2 * x \<up> 7) + 5 * x \<up> 2 * 3 + (6 * x \<up> 7 + 9) + (- 1 * (3 * x \<up> 5 * (6 * x \<up> 4)) + - 1 * (3 * x \<up> 5 * - 1) +  (-48 * x \<up> 4 + 8))";
   462 
   462 
   463 "----- is_multUnordered ---";
   463 "----- is_multUnordered ---";
   464 val tsort = sort_variables t;
   464 val tsort = sort_variables t;
   465 UnparseC.term tsort = "2 * (5 * (x \<up> 2 * x \<up> 7)) + 3 * (5 * x \<up> 2) + 6 * x \<up> 7 + 9 +\n- 1 * (3 * (6 * (x \<up> 4 * x \<up> 5))) +\n- 1 * (- 1 * (3 * x \<up> 5)) +\n-48 * x \<up> 4 +\n8";
   465 UnparseC.term tsort = "2 * (5 * (x \<up> 2 * x \<up> 7)) + 3 * (5 * x \<up> 2) + 6 * x \<up> 7 + 9 +\n- 1 * (3 * (6 * (x \<up> 4 * x \<up> 5))) +\n- 1 * (- 1 * (3 * x \<up> 5)) +\n-48 * x \<up> 4 +\n8";
   466 is_polyexp t;
   466 is_polyexp t;
   467 tsort = t;
   467 tsort = t;
   468 is_polyexp t andalso not (t = sort_variables t);
   468 is_polyexp t andalso not (t = sort_variables t);
   469 if is_multUnordered t then () else error "poly.sml diff. is_multUnordered 1";
   469 if is_multUnordered t then () else error "poly.sml diff. is_multUnordered 1";
   470 
   470 
   471 "----- eval_is_multUnordered ---";
   471 "----- eval_is_multUnordered ---";
   472 val tm = TermC.str2term "(5 * x \<up> 2 * (2 * x \<up> 7) + 5 * x \<up> 2 * 3 + (6 * x \<up> 7 + 9) + (- 1 * (3 * x \<up> 5 * (6 * x \<up> 4)) + - 1 * (3 * x \<up> 5 * - 1) +  (-48 * x \<up> 4 + 8))) is_multUnordered";
   472 val tm = TermC.parse_test @{context} "(5 * x \<up> 2 * (2 * x \<up> 7) + 5 * x \<up> 2 * 3 + (6 * x \<up> 7 + 9) + (- 1 * (3 * x \<up> 5 * (6 * x \<up> 4)) + - 1 * (3 * x \<up> 5 * - 1) +  (-48 * x \<up> 4 + 8))) is_multUnordered";
   473 case eval_is_multUnordered "testid" "" tm @{context} of
   473 case eval_is_multUnordered "testid" "" tm @{context} of
   474     SOME (_, Const (\<^const_name>\<open>Trueprop\<close>, _) $ 
   474     SOME (_, Const (\<^const_name>\<open>Trueprop\<close>, _) $ 
   475                    (Const (\<^const_name>\<open>HOL.eq\<close>, _) $
   475                    (Const (\<^const_name>\<open>HOL.eq\<close>, _) $
   476                           (Const (\<^const_name>\<open>is_multUnordered\<close>, _) $ _) $ 
   476                           (Const (\<^const_name>\<open>is_multUnordered\<close>, _) $ _) $ 
   477                           Const (\<^const_name>\<open>True\<close>, _))) => ()
   477                           Const (\<^const_name>\<open>True\<close>, _))) => ()
   484 
   484 
   485 "-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
   485 "-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
   486 "-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
   486 "-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
   487 "-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
   487 "-------- fun is_multUnordered (3 * a + - 2 * a) -----------------------------------------------";
   488 val thy = @{theory "Isac_Knowledge"};
   488 val thy = @{theory "Isac_Knowledge"};
   489 val t as (_ $ arg) = TermC.str2term "(3 * a + - 2 * a) is_multUnordered";
   489 val t as (_ $ arg) = TermC.parse_test @{context} "(3 * a + - 2 * a) is_multUnordered";
   490 
   490 
   491 (*+*)if UnparseC.term (sort_variables arg) = "3 * a + - 2 * a" andalso is_polyexp arg = true
   491 (*+*)if UnparseC.term (sort_variables arg) = "3 * a + - 2 * a" andalso is_polyexp arg = true
   492 (*+*)  andalso not (is_multUnordered arg)
   492 (*+*)  andalso not (is_multUnordered arg)
   493 (*+*)then () else error "sort_variables  3 * a + - 2 * a   CHANGED";
   493 (*+*)then () else error "sort_variables  3 * a + - 2 * a   CHANGED";
   494 
   494 
   499         Const (\<^const_name>\<open>False\<close>, _))) => ()
   499         Const (\<^const_name>\<open>False\<close>, _))) => ()
   500 (*      Const (\<^const_name>\<open>True\<close>, _))) => ()   <<<<<--------------------------- this is false*)
   500 (*      Const (\<^const_name>\<open>True\<close>, _))) => ()   <<<<<--------------------------- this is false*)
   501 | _ => error "eval_is_multUnordered  3 * a + - 2 * a  CHANGED";
   501 | _ => error "eval_is_multUnordered  3 * a + - 2 * a  CHANGED";
   502 
   502 
   503 "----- is_multUnordered --- (- 2 * a) is_multUnordered = False";
   503 "----- is_multUnordered --- (- 2 * a) is_multUnordered = False";
   504 val t as (_ $ arg) = TermC.str2term "(- 2 * a) is_multUnordered";
   504 val t as (_ $ arg) = TermC.parse_test @{context} "(- 2 * a) is_multUnordered";
   505 
   505 
   506 (*+*)if UnparseC.term (sort_variables arg) = "- 2 * a" andalso is_polyexp arg = true
   506 (*+*)if UnparseC.term (sort_variables arg) = "- 2 * a" andalso is_polyexp arg = true
   507 (*+*)  andalso not (is_multUnordered arg)
   507 (*+*)  andalso not (is_multUnordered arg)
   508 (*+*)then () else error "sort_variables  - 2 * a   CHANGED";
   508 (*+*)then () else error "sort_variables  - 2 * a   CHANGED";
   509 
   509 
   513       Const (\<^const_name>\<open>Trueprop\<close>, _) $ (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ _ $
   513       Const (\<^const_name>\<open>Trueprop\<close>, _) $ (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ _ $
   514         Const (\<^const_name>\<open>False\<close>, _))) => ()
   514         Const (\<^const_name>\<open>False\<close>, _))) => ()
   515 | _ => error "eval_is_multUnordered  3 * a + - 2 * a  CHANGED";
   515 | _ => error "eval_is_multUnordered  3 * a + - 2 * a  CHANGED";
   516 
   516 
   517 "----- is_multUnordered --- (a) is_multUnordered = False";
   517 "----- is_multUnordered --- (a) is_multUnordered = False";
   518 val t as (_ $ arg) = TermC.str2term "(a) is_multUnordered";
   518 val t as (_ $ arg) = TermC.parse_test @{context} "(a) is_multUnordered";
   519 
   519 
   520 (*+*)if UnparseC.term (sort_variables arg) = "a" andalso is_polyexp arg = true
   520 (*+*)if UnparseC.term (sort_variables arg) = "a" andalso is_polyexp arg = true
   521 (*+*)  andalso not (is_multUnordered arg)
   521 (*+*)  andalso not (is_multUnordered arg)
   522 (*+*)then () else error "sort_variables   a   CHANGED";
   522 (*+*)then () else error "sort_variables   a   CHANGED";
   523 
   523 
   527       Const (\<^const_name>\<open>Trueprop\<close>, _) $ (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ _ $
   527       Const (\<^const_name>\<open>Trueprop\<close>, _) $ (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ _ $
   528         Const (\<^const_name>\<open>False\<close>, _))) => ()
   528         Const (\<^const_name>\<open>False\<close>, _))) => ()
   529 | _ => error "eval_is_multUnordered  3 * a + - 2 * a  CHANGED";
   529 | _ => error "eval_is_multUnordered  3 * a + - 2 * a  CHANGED";
   530 
   530 
   531 "----- is_multUnordered --- (- 2) is_multUnordered = False";
   531 "----- is_multUnordered --- (- 2) is_multUnordered = False";
   532 val t as (_ $ arg) = TermC.str2term "(- 2) is_multUnordered";
   532 val t as (_ $ arg) = TermC.parse_test @{context} "(- 2) is_multUnordered";
   533 
   533 
   534 (*+*)if UnparseC.term (sort_variables arg) = "- 2" andalso is_polyexp arg = true
   534 (*+*)if UnparseC.term (sort_variables arg) = "- 2" andalso is_polyexp arg = true
   535 (*+*)  andalso not (is_multUnordered arg)
   535 (*+*)  andalso not (is_multUnordered arg)
   536 (*+*)then () else error "sort_variables   - 2   CHANGED";
   536 (*+*)then () else error "sort_variables   - 2   CHANGED";
   537 
   537 
   565 N:x \<up> 3 + - 1 * (3 * (a * x \<up> 2))  +  3 * (a \<up> 2 * (x * (- 1) \<up> 2))  +  a \<up> 3 * (- 1) \<up> 3 
   565 N:x \<up> 3 + - 1 * (3 * (a * x \<up> 2))  +  3 * (a \<up> 2 * (x * (- 1) \<up> 2))  +  a \<up> 3 * (- 1) \<up> 3 
   566 --------+--------------------------+---------------------------------+---------------------------<>
   566 --------+--------------------------+---------------------------------+---------------------------<>
   567 O:x \<up> 3 + - 1  * (3 * (a * x \<up> 2))  +  - 1 \<up> 2 * (3 * (a \<up> 2 * x))     +  - 1 \<up> 3 * a \<up> 3 
   567 O:x \<up> 3 + - 1  * (3 * (a * x \<up> 2))  +  - 1 \<up> 2 * (3 * (a \<up> 2 * x))     +  - 1 \<up> 3 * a \<up> 3 
   568 -------------------------------------------------------------------------------------------------<>
   568 -------------------------------------------------------------------------------------------------<>
   569 *)
   569 *)
   570 val t = TermC.str2term "x \<up> 3 + 3 * x \<up> 2 * (- 1 * a) + 3 * x * ((- 1) \<up> 2 * a \<up> 2) + (- 1) \<up> 3 * a \<up> 3";
   570 val t = TermC.parse_test @{context} "x \<up> 3 + 3 * x \<up> 2 * (- 1 * a) + 3 * x * ((- 1) \<up> 2 * a \<up> 2) + (- 1) \<up> 3 * a \<up> 3";
   571 (*
   571 (*
   572 "~~~~~ fun is_multUnordered
   572 "~~~~~ fun is_multUnordered
   573 "~~~~~~~ fun sort_variables
   573 "~~~~~~~ fun sort_variables
   574 "~~~~~~~~~ val sort_varList
   574 "~~~~~~~~~ val sort_varList
   575 *)
   575 *)
   634 
   634 
   635 
   635 
   636 "-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
   636 "-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
   637 "-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
   637 "-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
   638 "-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
   638 "-------- fun is_multUnordered  b * a * a ------------------------------------------------------";
   639 val t = TermC.str2term "b * a * a";
   639 val t = TermC.parse_test @{context} "b * a * a";
   640 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   640 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   641 if UnparseC.term t = "a \<up> 2 * b" then ()
   641 if UnparseC.term t = "a \<up> 2 * b" then ()
   642 else error "poly.sml: diff.behav. in make_polynomial 21";
   642 else error "poly.sml: diff.behav. in make_polynomial 21";
   643 
   643 
   644 "~~~~~ fun is_multUnordered , args:"; val (t) = (@{term "b * a * a::real"});
   644 "~~~~~ fun is_multUnordered , args:"; val (t) = (@{term "b * a * a::real"});
   657 
   657 
   658 
   658 
   659 "-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
   659 "-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
   660 "-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
   660 "-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
   661 "-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
   661 "-------- fun is_multUnordered 2*3*a -----------------------------------------------------------";
   662 val t = TermC.str2term "2*3*a";
   662 val t = TermC.parse_test @{context} "2*3*a";
   663 val SOME (t', _) = rewrite_set_ ctxt false make_polynomial t;
   663 val SOME (t', _) = rewrite_set_ ctxt false make_polynomial t;
   664 (*+*)if UnparseC.term t' = "6 * a" then () else error "rewrite_set_ 2*3*a CHANGED";
   664 (*+*)if UnparseC.term t' = "6 * a" then () else error "rewrite_set_ 2*3*a CHANGED";
   665 (*
   665 (*
   666 ##  try calc: "Groups.times_class.times" 
   666 ##  try calc: "Groups.times_class.times" 
   667 ##  rls: order_mult_rls_ on: 6 * a 
   667 ##  rls: order_mult_rls_ on: 6 * a 
   671 ########  eval asms: "6 * a is_multUnordered = True"    (*isa*)
   671 ########  eval asms: "6 * a is_multUnordered = True"    (*isa*)
   672                                              = False"   (*isa2*)
   672                                              = False"   (*isa2*)
   673 #######  calc. to: True  (*isa*)
   673 #######  calc. to: True  (*isa*)
   674                    False (*isa2*)
   674                    False (*isa2*)
   675 *)
   675 *)
   676 val t = TermC.str2term "(6 * a) is_multUnordered"; 
   676 val t = TermC.parse_test @{context} "(6 * a) is_multUnordered"; 
   677 val SOME
   677 val SOME
   678     (_, t') =
   678     (_, t') =
   679            eval_is_multUnordered "xxx" () t @{context};
   679            eval_is_multUnordered "xxx" () t @{context};
   680 (*+*)if UnparseC.term t' = "6 * a is_multUnordered = False" then () 
   680 (*+*)if UnparseC.term t' = "6 * a is_multUnordered = False" then () 
   681 (*+*)else error "6 * a is_multUnordered = False CHANGED";
   681 (*+*)else error "6 * a is_multUnordered = False CHANGED";
   700 "-------- norm_Poly with AlgEin ----------------------------------------------------------------";
   700 "-------- norm_Poly with AlgEin ----------------------------------------------------------------";
   701 val thy = @{theory AlgEin};
   701 val thy = @{theory AlgEin};
   702 val ctxt = Proof_Context.init_global thy;
   702 val ctxt = Proof_Context.init_global thy;
   703 
   703 
   704 val SOME (f',_) = rewrite_set_ ctxt false norm_Poly
   704 val SOME (f',_) = rewrite_set_ ctxt false norm_Poly
   705 (TermC.str2term "L = k - 2 * q + (k - 2 * q) + (k - 2 * q) + (k - 2 * q) + senkrecht + oben");
   705 (TermC.parse_test @{context} "L = k - 2 * q + (k - 2 * q) + (k - 2 * q) + (k - 2 * q) + senkrecht + oben");
   706 if UnparseC.term f' = "L = 2 * 2 * k + 2 * - 4 * q + senkrecht + oben"
   706 if UnparseC.term f' = "L = 2 * 2 * k + 2 * - 4 * q + senkrecht + oben"
   707 then ((*norm_Poly NOT COMPLETE -- TODO MG*))
   707 then ((*norm_Poly NOT COMPLETE -- TODO MG*))
   708 else error "norm_Poly changed behavior";
   708 else error "norm_Poly changed behavior";
   709 (* isa:
   709 (* isa:
   710 ##  rls: order_add_rls_ on: L = k + - 2 * q + k + - 2 * q + k + - 2 * q + k + - 2 * q + senkrecht + oben 
   710 ##  rls: order_add_rls_ on: L = k + - 2 * q + k + - 2 * q + k + - 2 * q + k + - 2 * q + senkrecht + oben 
   718 #######  try calc: "Poly.is_addUnordered" 
   718 #######  try calc: "Poly.is_addUnordered" 
   719 #######  try calc: "Poly.is_addUnordered" 
   719 #######  try calc: "Poly.is_addUnordered" 
   720 ###  rls: order_add_ on: L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben 
   720 ###  rls: order_add_ on: L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben 
   721 *)
   721 *)
   722 "~~~~~ fun sort_monoms , args:"; val (t) =
   722 "~~~~~ fun sort_monoms , args:"; val (t) =
   723   (TermC.str2term "L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben");
   723   (TermC.parse_test @{context} "L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben");
   724 (*+*)val t' =
   724 (*+*)val t' =
   725            sort_monoms t;
   725            sort_monoms t;
   726 (*+*)UnparseC.term t' = "L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben"; (*isa*)
   726 (*+*)UnparseC.term t' = "L = k + k + k + k + - 2 * q + - 2 * q + - 2 * q + - 2 * q + senkrecht + oben"; (*isa*)
   727 
   727 
   728 
   728 
   729 "-------- complex examples from textbook Schalk I ----------------------------------------------";
   729 "-------- complex examples from textbook Schalk I ----------------------------------------------";
   730 "-------- complex examples from textbook Schalk I ----------------------------------------------";
   730 "-------- complex examples from textbook Schalk I ----------------------------------------------";
   731 "-------- complex examples from textbook Schalk I ----------------------------------------------";
   731 "-------- complex examples from textbook Schalk I ----------------------------------------------";
   732 val t = TermC.str2term "1 + 2 * x \<up> 4 + 2 * - 2 * x \<up> 4 + x \<up> 8";
   732 val t = TermC.parse_test @{context} "1 + 2 * x \<up> 4 + 2 * - 2 * x \<up> 4 + x \<up> 8";
   733 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   733 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   734 if (UnparseC.term t) = "1 + - 2 * x \<up> 4 + x \<up> 8"
   734 if (UnparseC.term t) = "1 + - 2 * x \<up> 4 + x \<up> 8"
   735 then () else error "poly.sml: diff.behav. in make_polynomial 9b";
   735 then () else error "poly.sml: diff.behav. in make_polynomial 9b";
   736 
   736 
   737 "-----SPB Schalk I p.64 No.296a ---";
   737 "-----SPB Schalk I p.64 No.296a ---";
   738 val t = TermC.str2term "(x - a) \<up> 3";
   738 val t = TermC.parse_test @{context} "(x - a) \<up> 3";
   739 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   739 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   740 if (UnparseC.term t) = "- 1 * a \<up> 3 + 3 * a \<up> 2 * x + - 3 * a * x \<up> 2 + x \<up> 3"
   740 if (UnparseC.term t) = "- 1 * a \<up> 3 + 3 * a \<up> 2 * x + - 3 * a * x \<up> 2 + x \<up> 3"
   741 then () else error "poly.sml: diff.behav. in make_polynomial 10";
   741 then () else error "poly.sml: diff.behav. in make_polynomial 10";
   742 
   742 
   743 "-----SPB Schalk I p.64 No.296c ---";
   743 "-----SPB Schalk I p.64 No.296c ---";
   744 val t = TermC.str2term "(-3*x - 4*y) \<up> 3";
   744 val t = TermC.parse_test @{context} "(-3*x - 4*y) \<up> 3";
   745 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   745 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   746 if (UnparseC.term t) = "- 27 * x \<up> 3 + - 108 * x \<up> 2 * y + - 144 * x * y \<up> 2 +\n- 64 * y \<up> 3"
   746 if (UnparseC.term t) = "- 27 * x \<up> 3 + - 108 * x \<up> 2 * y + - 144 * x * y \<up> 2 +\n- 64 * y \<up> 3"
   747 then () else error "poly.sml: diff.behav. in make_polynomial 11";
   747 then () else error "poly.sml: diff.behav. in make_polynomial 11";
   748 
   748 
   749 "-----SPB Schalk I p.62 No.242c ---";
   749 "-----SPB Schalk I p.62 No.242c ---";
   750 val t = TermC.str2term "x \<up> (- 4)*(x \<up> (- 4)*y \<up> (- 2)) \<up> (- 1)*y \<up> (- 2)";
   750 val t = TermC.parse_test @{context} "x \<up> (- 4)*(x \<up> (- 4)*y \<up> (- 2)) \<up> (- 1)*y \<up> (- 2)";
   751 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   751 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   752 if (UnparseC.term t) = "1"
   752 if (UnparseC.term t) = "1"
   753 then () else error "poly.sml: diff.behav. in make_polynomial 12";
   753 then () else error "poly.sml: diff.behav. in make_polynomial 12";
   754 
   754 
   755 "-----SPB Schalk I p.60 No.209a ---";
   755 "-----SPB Schalk I p.60 No.209a ---";
   756 val t = TermC.str2term "a \<up> (7-x) * a \<up> x";
   756 val t = TermC.parse_test @{context} "a \<up> (7-x) * a \<up> x";
   757 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   757 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   758 if UnparseC.term t = "a \<up> 7"
   758 if UnparseC.term t = "a \<up> 7"
   759 then () else error "poly.sml: diff.behav. in make_polynomial 13";
   759 then () else error "poly.sml: diff.behav. in make_polynomial 13";
   760 
   760 
   761 "-----SPB Schalk I p.60 No.209d ---";
   761 "-----SPB Schalk I p.60 No.209d ---";
   762 val t = TermC.str2term "d \<up> x * d \<up> (x+1) * d \<up> (2 - 2*x)";
   762 val t = TermC.parse_test @{context} "d \<up> x * d \<up> (x+1) * d \<up> (2 - 2*x)";
   763 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   763 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   764 if UnparseC.term t = "d \<up> 3"
   764 if UnparseC.term t = "d \<up> 3"
   765 then () else error "poly.sml: diff.behav. in make_polynomial 14";
   765 then () else error "poly.sml: diff.behav. in make_polynomial 14";
   766 
   766 
   767 
   767 
   768 "-------- complex Eigene Beispiele (Mathias Goldgruber) ----------------------------------------";
   768 "-------- complex Eigene Beispiele (Mathias Goldgruber) ----------------------------------------";
   769 "-------- complex Eigene Beispiele (Mathias Goldgruber) ----------------------------------------";
   769 "-------- complex Eigene Beispiele (Mathias Goldgruber) ----------------------------------------";
   770 "-------- complex Eigene Beispiele (Mathias Goldgruber) ----------------------------------------";
   770 "-------- complex Eigene Beispiele (Mathias Goldgruber) ----------------------------------------";
   771 "-----SPO ---";
   771 "-----SPO ---";
   772 val t = TermC.str2term "a \<up> 2*a \<up> (- 2)";
   772 val t = TermC.parse_test @{context} "a \<up> 2*a \<up> (- 2)";
   773 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   773 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   774 if UnparseC.term t = "1" then ()
   774 if UnparseC.term t = "1" then ()
   775 else error "poly.sml: diff.behav. in make_polynomial 15";
   775 else error "poly.sml: diff.behav. in make_polynomial 15";
   776 
   776 
   777 "-----SPO ---";
   777 "-----SPO ---";
   778 val t = TermC.str2term "a \<up> 2*b*b \<up> (- 1)";
   778 val t = TermC.parse_test @{context} "a \<up> 2*b*b \<up> (- 1)";
   779 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   779 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   780 if UnparseC.term t = "a \<up> 2" then ()
   780 if UnparseC.term t = "a \<up> 2" then ()
   781 else error "poly.sml: diff.behav. in make_polynomial 18";
   781 else error "poly.sml: diff.behav. in make_polynomial 18";
   782 "-----SPO ---";
   782 "-----SPO ---";
   783 val t = TermC.str2term "a \<up> 2*a \<up> (- 2)";
   783 val t = TermC.parse_test @{context} "a \<up> 2*a \<up> (- 2)";
   784 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   784 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   785 if (UnparseC.term t) = "1" then ()
   785 if (UnparseC.term t) = "1" then ()
   786 else error "poly.sml: diff.behav. in make_polynomial 19";
   786 else error "poly.sml: diff.behav. in make_polynomial 19";
   787 "-----SPO ---";
   787 "-----SPO ---";
   788 val t = TermC.str2term "b + a - b";
   788 val t = TermC.parse_test @{context} "b + a - b";
   789 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   789 val SOME (t,_) = rewrite_set_ ctxt false make_polynomial t; UnparseC.term t;
   790 if (UnparseC.term t) = "a" then ()
   790 if (UnparseC.term t) = "a" then ()
   791 else error "poly.sml: diff.behav. in make_polynomial 20";
   791 else error "poly.sml: diff.behav. in make_polynomial 20";
   792 
   792 
   793 "-----SPO ---";
   793 "-----SPO ---";