From 5089db3e37431e9aafff0f0359a3b6c8168fb39d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Pe=C3=B1aranda?= Date: Fri, 12 Aug 2016 15:44:37 -0300 Subject: [PATCH] Add assertions in refiners. The assertions check that the endpoints of the interval to refine have different evaluation signs, or they are the same point and its evaluation is zero. --- .../include/CGAL/RS/bisection_refiner_1.h | 8 ++--- .../include/CGAL/RS/rs3_k_refiner_1.h | 29 ++++++++++++++++--- .../include/CGAL/RS/rs3_refiner_1.h | 29 ++++++++++++++++--- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/Algebraic_kernel_d/include/CGAL/RS/bisection_refiner_1.h b/Algebraic_kernel_d/include/CGAL/RS/bisection_refiner_1.h index cfb5554f3db..bf41418b323 100644 --- a/Algebraic_kernel_d/include/CGAL/RS/bisection_refiner_1.h +++ b/Algebraic_kernel_d/include/CGAL/RS/bisection_refiner_1.h @@ -47,7 +47,7 @@ operator()(const Polynomial_&,Bound_&,Bound_&,int){ // This works with any type of polynomial, but only for Gmpfr bounds. // TODO: Beyond writing generically, optimize this function. This would -// remove the need for the next function, which essentially the same. +// remove the need for the next function, which is essentially the same. template<> void Bisection_refiner_1,Gmpfr>:: @@ -58,8 +58,6 @@ operator()(const Polynomial &pol,Gmpfr &left,Gmpfr &right,int prec){ typedef CGAL::RS_AK1::Signat_1 Signat; CGAL_precondition(left<=right); - // TODO: add precondition to check whether the interval is a point - // or the evaluations on its endpoints have different signs //std::cout<<"refining ["< &pol,Gmpfr &left,Gmpfr &right,int prec){ mpfr_t center; sl=signof(left); + CGAL_precondition(sl!=signof(right)||(left==right&&sl==ZERO)); if(sl==ZERO) return; pl=left.get_precision(); @@ -120,8 +119,6 @@ operator()(const Polynomial &pol,Gmpfr &left,Gmpfr &right,int prec){ typedef CGAL::RS_AK1::Signat_1 Signat; CGAL_precondition(left<=right); - // TODO: add precondition to check whether the interval is a point - // or the evaluations on its endpoints have different signs //std::cout<<"refining ["< &pol,Gmpfr &left,Gmpfr &right,int prec){ mpfr_t center; sl=signof(left); + CGAL_precondition(sl!=signof(right)||(left==right&&sl==ZERO)); if(sl==ZERO) return; pl=left.get_precision(); diff --git a/Algebraic_kernel_d/include/CGAL/RS/rs3_k_refiner_1.h b/Algebraic_kernel_d/include/CGAL/RS/rs3_k_refiner_1.h index e00d4eccb4e..91e5d859bb9 100644 --- a/Algebraic_kernel_d/include/CGAL/RS/rs3_k_refiner_1.h +++ b/Algebraic_kernel_d/include/CGAL/RS/rs3_k_refiner_1.h @@ -26,6 +26,11 @@ #include #include "Gmpfr_make_unique.h" +// If we want assertions, we need to evaluate. +#ifndef CGAL_NO_ASSERTIONS +#include "signat_1.h" +#endif + namespace CGAL{ namespace RS3{ @@ -51,8 +56,15 @@ operator() typedef Polynomial_traits_d Ptraits; typedef Ptraits::Degree Degree; CGAL_precondition(left<=right); - // TODO: add precondition to check whether the interval is a point - // or the evaluations on its endpoints have different signs +#ifndef CGAL_NO_ASSERTIONS + typedef Ptraits::Make_square_free Sfpart; + typedef CGAL::RS_AK1::Signat_1 + Signat; + Polynomial sfpp=Sfpart()(pol); + Signat signof(sfpp); + CGAL::Sign sl=signof(left); + CGAL_precondition(sl!=signof(right)||(left==right&&sl==ZERO)); +#endif //std::cout<<"refining ["< ZPtraits; typedef ZPtraits::Degree ZDegree; CGAL_precondition(left<=right); - // TODO: add precondition to check whether the interval is a point - // or the evaluations on its endpoints have different signs +#ifndef CGAL_NO_ASSERTIONS + typedef ZPtraits::Make_square_free ZSfpart; + typedef CGAL::RS_AK1::Signat_1 + Signat; +#endif //std::cout<<"refining ["< zpol=CGAL::RS_AK1::Polynomial_converter_1< CGAL::Polynomial, CGAL::Polynomial >()(qpol); +#ifndef CGAL_NO_ASSERTIONS + ZPolynomial zsfpp=ZSfpart()(zpol); + Signat signof(zsfpp); + CGAL::Sign sl=signof(left); + CGAL_precondition(sl!=signof(right)||(left==right&&sl==ZERO)); +#endif int deg=ZDegree()(zpol); mpz_t* coefficients=(mpz_t*)malloc((deg+1)*sizeof(mpz_t)); __mpfi_struct interval; diff --git a/Algebraic_kernel_d/include/CGAL/RS/rs3_refiner_1.h b/Algebraic_kernel_d/include/CGAL/RS/rs3_refiner_1.h index 9755484b080..62fdcaae1fe 100644 --- a/Algebraic_kernel_d/include/CGAL/RS/rs3_refiner_1.h +++ b/Algebraic_kernel_d/include/CGAL/RS/rs3_refiner_1.h @@ -26,6 +26,11 @@ #include #include "Gmpfr_make_unique.h" +// If we want assertions, we need to evaluate. +#ifndef CGAL_NO_ASSERTIONS +#include "signat_1.h" +#endif + namespace CGAL{ namespace RS3{ @@ -51,8 +56,15 @@ operator() typedef Polynomial_traits_d Ptraits; typedef Ptraits::Degree Degree; CGAL_precondition(left<=right); - // TODO: add precondition to check whether the interval is a point - // or the evaluations on its endpoints have different signs +#ifndef CGAL_NO_ASSERTIONS + typedef Ptraits::Make_square_free Sfpart; + typedef CGAL::RS_AK1::Signat_1 + Signat; + Polynomial sfpp=Sfpart()(pol); + Signat signof(sfpp); + CGAL::Sign sl=signof(left); + CGAL_precondition(sl!=signof(right)||(left==right&&sl==ZERO)); +#endif //std::cout<<"refining ["< ZPtraits; typedef ZPtraits::Degree ZDegree; CGAL_precondition(left<=right); - // TODO: add precondition to check whether the interval is a point - // or the evaluations on its endpoints have different signs +#ifndef CGAL_NO_ASSERTIONS + typedef ZPtraits::Make_square_free ZSfpart; + typedef CGAL::RS_AK1::Signat_1 + Signat; +#endif //std::cout<<"refining ["< zpol=CGAL::RS_AK1::Polynomial_converter_1< CGAL::Polynomial, CGAL::Polynomial >()(qpol); +#ifndef CGAL_NO_ASSERTIONS + ZPolynomial zsfpp=ZSfpart()(zpol); + Signat signof(zsfpp); + CGAL::Sign sl=signof(left); + CGAL_precondition(sl!=signof(right)||(left==right&&sl==ZERO)); +#endif int deg=ZDegree()(zpol); mpz_t* coefficients=(mpz_t*)malloc((deg+1)*sizeof(mpz_t)); __mpfi_struct interval;