mirror of https://github.com/CGAL/cgal
216 lines
5.4 KiB
C
216 lines
5.4 KiB
C
#define CGAL_CHECK_EXACTNESS
|
|
#define CGAL_CHECK_EXPENSIVE
|
|
|
|
#include <CGAL/basic.h>
|
|
#include <CGAL/Polynomial/basic.h>
|
|
#include <CGAL/Polynomial/Polynomial.h>
|
|
#include <CGAL/Polynomial/internal/Rational/Rational_traits_base.h>
|
|
|
|
#include <CGAL/Polynomial/internal/Filtered_rational/Filtered_rational_traits.h>
|
|
#include <CGAL/Polynomial/Default_filtering_traits.h>
|
|
|
|
#include <CGAL/Gmpq.h>
|
|
#include <vector>
|
|
|
|
//#include "write_maple_functions.h"
|
|
|
|
#include <CGAL/CORE_Expr.h>
|
|
|
|
bool for_maple=false;
|
|
|
|
template <class Polynomial>
|
|
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 <class Polynomial>
|
|
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 <class Traits>
|
|
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<NT> Polynomial;
|
|
|
|
typedef CGAL_POLYNOMIAL_NS::internal::Rational_traits_base<Polynomial>
|
|
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<NT> FT;
|
|
typedef CGAL_POLYNOMIAL_NS::internal::Filtered_rational_traits<FT> Tr;
|
|
Tr tr;
|
|
test_polynomial(tr);
|
|
}
|
|
|
|
return 0;
|
|
}
|