#define CGAL_CHECK_EXACTNESS #define CGAL_CHECK_EXPENSIVE #include #include #include #include #include #include #include #include //#include "write_maple_functions.h" #include bool for_maple=false; template void write(const char *expr, const Polynomial &v) { if (for_maple) { std::cout << "evalb(simplify(expand(" << expr << ")) = " << v << ");\n"; } else { std::cout << expr << ": " << v << std::endl; } } template void write_variable(const char *name, const Polynomial &v) { if (for_maple) { std::cout << name << ":=" << v << ":\n"; } else { std::cout << name << ": " << v << std::endl; } } template void test_polynomial(const Traits &tr) { typedef typename Traits::Construct_function CF; typedef typename Traits::Function Polynomial; typedef typename Polynomial::NT NT; CF cf= tr.construct_function_object(); NT v[] = {-1, 2, 27, -17, 0, 0}; // NT v[] = {0, 0, 0, 0, 0, 0}; Polynomial p(v, v+6); Polynomial q(v, v+3); NT a(2); write_variable( "p", p); write_variable("q", q ); write("-p", (-p)); CGAL_assertion(-p == cf(1,-2,-27,17)); write("p-p",(p-p)); CGAL_assertion((p-p) == cf(0)); write("p+q" , (p+q) ); CGAL_assertion(p+q == cf( -2, 4, 54, -17)); write("p-q" , (p-q)); CGAL_assertion(p-q == cf(0,0,0,-17)); write("q*(p-q)" , q*(p-q) ); CGAL_assertion(q*(p-q) == cf(0,0,0,17,-34,-459)); write_variable( "a", a); write("(p-q)+a" , ((p-q)+a) ); CGAL_assertion((p-q)+a == cf(2, 0, 0, -17)); write("(p-q)-a" , ((p-q)-a) ); CGAL_assertion((p-q)-a == cf(-2, 0, 0, -17)); write("a*(p-q)" , (a*(p-q)) ); CGAL_assertion((a*(p-q)) == cf(0,0,0,-34)); write("(p-q)*a" , ((p-q)*a) ); CGAL_assertion(((p-q)*a) == cf(0,0,0,-34)); write("(p-q)/a" , ((p-q)/a) ); CGAL_assertion(((p-q)/a) == cf(0,0,0,-NT(17)/NT(2))); write("subs(t=-t, p)", tr.negate_variable_object()(p) ); CGAL_assertion(tr.negate_variable_object()(p) == cf( -1, -2, 27, 17)); write("t^degree(p) * subs(t=(1/t), p)", tr.invert_variable_object()(p) ); CGAL_assertion( tr.invert_variable_object()(p) == cf(-17, 27, 2, -1)); //write("diff(p,t)", tr.differentiate_object()(p) ); NT v1[] = {-1, 1}; NT v2[] = {-2, 1}; Polynomial r = Polynomial(v1, v1+2); Polynomial s = Polynomial(v2, v2+2); p = r * r * s + NT(1); write_variable( "p", p); CGAL_assertion(p == cf(-1, 5, -4, 1)); q = r * s; write_variable("q", q ); CGAL_assertion(q == cf( 2, -3, 1)); write("rem(p,q,t)", tr.remainder_object()(p,q) ); CGAL_assertion(tr.remainder_object()(p,q) == cf(1)); write("prem(p,q,t)", tr.pseudo_remainder_object()(p,q) ); CGAL_assertion(tr.pseudo_remainder_object()(p,q) == cf(1)); write("quo(p,q,t)", tr.quotient_object()(p,q) ); CGAL_assertion(tr.quotient_object()(p,q) == cf(-1,1)); write("pquo(p,q,t)", tr.pseudo_quotient_object()(p,q) ); CGAL_assertion(tr.pseudo_quotient_object()(p,q) == cf(-1,1)); p = r * r * s * s * s; write_variable( "p", p); CGAL_assertion(p == cf(-8, 28, -38, 25, -8, 1)); q = r * s; write_variable("q", q ); CGAL_assertion(q == cf(2,-3,1)); write("rem(p,q,t)", tr.remainder_object()(p,q) ); CGAL_assertion(tr.remainder_object()(p,q) == cf(0)); write("prem(p,q,t)", tr.pseudo_remainder_object()(p,q) ); CGAL_assertion(tr.pseudo_remainder_object()(p,q) == cf(0)); write("quo(p,q,t)", tr.quotient_object()(p,q) ); CGAL_assertion(tr.quotient_object()(p,q) == cf(-4, 8, -5, 1)); write("pquo(p,q,t)", tr.pseudo_quotient_object()(p,q) ); CGAL_assertion(tr.pseudo_quotient_object()(p,q) == cf(-4, 8, -5, 1)); int shift = 6; write("p * t^6", tr.shift_power_object(shift)(p) ); CGAL_assertion(tr.shift_power_object(shift)(p) == cf(0,0,0,0,0,0,-8, 28, -38, 25, -8, 1)); NT v3[] = {0, 1}; Polynomial t = Polynomial(v3, v3+2); p = t * t; write_variable( "p", p); NT new_zero = NT(-1); write("subs(t=t-1,p)", tr.rational_translate_zero_object(new_zero)(p)); CGAL_assertion(tr.rational_translate_zero_object(new_zero)(p) == cf(1, -2, 1)); } int main(int argc, char* argv[]) { //CORE::extLong pi=CORE_posInfty; // CORE::Expr ep(CORE_posInfty); //std::cout << /*pi << " " <<*/ ep << std::endl; if ( argc > 1 ) { for_maple = atoi(argv[1]); } /*if (for_maple){ write_maple_functions(std::cout); }*/ { typedef CGAL::Gmpq NT; typedef CGAL_POLYNOMIAL_NS::Polynomial Polynomial; typedef CGAL_POLYNOMIAL_NS::internal::Rational_traits_base Rational_traits; Rational_traits tr; test_polynomial(tr); } std::cout <<"\n\n\n\n\n"; { typedef CGAL::Gmpq NT; typedef CGAL_POLYNOMIAL_NS::Default_filtering_traits FT; typedef CGAL_POLYNOMIAL_NS::internal::Filtered_rational_traits Tr; Tr tr; test_polynomial(tr); } return 0; }