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 --------------------------------------------------------------------"; |
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>, _))) => () |
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 ---"; |