mirror of https://github.com/CGAL/cgal
125 lines
3.4 KiB
C++
125 lines
3.4 KiB
C++
|
|
// currently using modular arithmetic is far to slow,
|
|
// that is, we use interpolation for multivariate resultants
|
|
// but no modular arithmetic.
|
|
|
|
// These are the defaults
|
|
//#define CGAL_RESULTANT_USE_MODULAR_ARITHMETIC 0
|
|
//#define CGAL_RESULTANT_USE_DECOMPOSE 1
|
|
//#define CGAL_RESULTANT_USE_INTERPOLATE 1
|
|
|
|
#include <CGAL/basic.h>
|
|
|
|
#include <cassert>
|
|
#include <iostream>
|
|
|
|
#include <CGAL/Polynomial/resultant.h>
|
|
|
|
#include <CGAL/Arithmetic_kernel.h>
|
|
#include <CGAL/Modular.h>
|
|
#include <CGAL/Sqrt_extension.h>
|
|
#include <CGAL/Polynomial.h>
|
|
#include <CGAL/Polynomial_traits_d.h>
|
|
|
|
#include <CGAL/Random.h>
|
|
#include <CGAL/Timer.h>
|
|
|
|
#include <CGAL/gen_sparse_polynomial.h>
|
|
|
|
static CGAL::Random my_rnd(346); // some seed
|
|
|
|
template<class Polynomial_d>
|
|
void test_resultant(){
|
|
typedef typename CGAL::Polynomial_traits_d<Polynomial_d> PT;
|
|
typedef typename PT::Coefficient Coeff;
|
|
typename PT::Resultant resultant;
|
|
|
|
{
|
|
Polynomial_d A(0);
|
|
Polynomial_d B(0);
|
|
assert(resultant(A,B)==Coeff(0));
|
|
}{
|
|
Polynomial_d A(4);
|
|
Polynomial_d B(8);
|
|
assert(resultant(A,B)==Coeff(1));
|
|
}{
|
|
Polynomial_d f(Coeff(2),Coeff(7),Coeff(1),Coeff(8),Coeff(1),Coeff(8));
|
|
Polynomial_d g(Coeff(3),Coeff(1),Coeff(4),Coeff(1),Coeff(5),Coeff(9));
|
|
assert(resultant(f,g) == Coeff(230664271L)); // Maple
|
|
|
|
Polynomial_d h(Coeff(3),Coeff(4),Coeff(7),Coeff(7));
|
|
Polynomial_d fh(f*h);
|
|
Polynomial_d gh(g*h);
|
|
assert(resultant(fh,gh) == Coeff(0) );
|
|
}
|
|
|
|
|
|
for (int k = 0; k < 1; k++){
|
|
Polynomial_d F2 =
|
|
CGAL::generate_sparse_random_polynomial<Polynomial_d>(my_rnd,5);
|
|
Polynomial_d F1 =
|
|
CGAL::generate_sparse_random_polynomial<Polynomial_d>(my_rnd,5);
|
|
Polynomial_d G1 = typename PT::Move()(F1,PT::d-1,0);
|
|
Polynomial_d G2 = typename PT::Move()(F2,PT::d-1,0);
|
|
|
|
CGAL::Timer timer_new;
|
|
timer_new.start();
|
|
Coeff F = resultant(F1,F2,PT::d-1);
|
|
Coeff G = resultant(G1,G2,0);
|
|
timer_new.stop();
|
|
|
|
assert(F==G);
|
|
}
|
|
std::cout << "end resultant: " << PT::d << std::endl;
|
|
}
|
|
|
|
|
|
int main(){
|
|
|
|
CGAL::Timer timer;
|
|
timer.start();
|
|
//CGAL::force_ieee_double_precision();
|
|
CGAL::set_pretty_mode(std::cout);
|
|
|
|
typedef CGAL::Arithmetic_kernel AK;
|
|
typedef AK::Integer Integer;
|
|
typedef CGAL::Polynomial<Integer> Polynomial_1;
|
|
typedef CGAL::Polynomial<Polynomial_1> Polynomial_2;
|
|
typedef CGAL::Polynomial<Polynomial_2> Polynomial_3;
|
|
|
|
test_resultant<Polynomial_1>();
|
|
test_resultant<Polynomial_2>();
|
|
test_resultant<Polynomial_3>();
|
|
|
|
typedef CGAL::Polynomial<CGAL::Modular> MPolynomial_1;
|
|
typedef CGAL::Polynomial<MPolynomial_1> MPolynomial_2;
|
|
typedef CGAL::Polynomial<MPolynomial_2> MPolynomial_3;
|
|
|
|
test_resultant<MPolynomial_1>();
|
|
test_resultant<MPolynomial_2>();
|
|
test_resultant<MPolynomial_3>();
|
|
|
|
typedef CGAL::Polynomial<AK::Rational> RPolynomial_1;
|
|
typedef CGAL::Polynomial<RPolynomial_1> RPolynomial_2;
|
|
typedef CGAL::Polynomial<RPolynomial_2> RPolynomial_3;
|
|
|
|
test_resultant<RPolynomial_1>();
|
|
test_resultant<RPolynomial_2>();
|
|
test_resultant<RPolynomial_3>();
|
|
|
|
typedef CGAL::Sqrt_extension<AK::Integer, AK::Integer> EXT;
|
|
typedef CGAL::Polynomial<EXT> EPolynomial_1;
|
|
typedef CGAL::Polynomial<EPolynomial_1> EPolynomial_2;
|
|
typedef CGAL::Polynomial<EPolynomial_2> EPolynomial_3;
|
|
|
|
test_resultant<EPolynomial_1>();
|
|
test_resultant<EPolynomial_2>();
|
|
test_resultant<EPolynomial_3>();
|
|
timer.stop();
|
|
|
|
std::cout <<" TOTAL TIME: " << timer.time();
|
|
}
|
|
|
|
|
|
|