mirror of https://github.com/CGAL/cgal
make Polynomial explicit constructible from Coeff/ICoeff, which prevents bugs
This commit is contained in:
parent
c26071c2ed
commit
17cf111f69
|
|
@ -276,7 +276,7 @@ public:
|
|||
{ coeff(0) = NT(a0); reduce(); simplify_coefficients(); }
|
||||
|
||||
//! construct the constant polynomial a0
|
||||
Polynomial(const NT& a0)
|
||||
explicit Polynomial(const NT& a0)
|
||||
: Base(Rep(1, &a0))
|
||||
{ reduce(); simplify_coefficients(); }
|
||||
|
||||
|
|
@ -336,7 +336,8 @@ public:
|
|||
template <class Forward_iterator>
|
||||
Polynomial(Forward_iterator first, Forward_iterator last)
|
||||
: Base(Rep(first,last))
|
||||
{ reduce(); simplify_coefficients(); }
|
||||
{ std::cout << "FROM IT" << std::endl;
|
||||
reduce(); simplify_coefficients(); }
|
||||
|
||||
#if defined(CGAL_USE_LEDA) || defined(DOXYGEN_RUNNING)
|
||||
/*! \brief construct a polynomial from a LEDA \c array
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ Polynomial<NT> modular_gcd_utcf_algorithm_M(
|
|||
}
|
||||
if(FF1.degree() == 0 || FF2.degree() == 0){
|
||||
Poly result;
|
||||
result = CGAL::gcd(FF1.content(),FF2.content());
|
||||
result = Poly(CGAL::gcd(FF1.content(),FF2.content()));
|
||||
return CGAL::canonicalize(result);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -479,11 +479,11 @@ Polynomial<NT> pseudo_gcdex(
|
|||
// handle trivial cases
|
||||
if (x.is_zero()) {
|
||||
if (y.is_zero()) CGAL_error_msg("gcdex(0,0) is undefined");
|
||||
xf = NT(0); yf = NT(1); vf = y.unit_part();
|
||||
xf = POLY(0); yf = POLY(1); vf = y.unit_part();
|
||||
return y / vf;
|
||||
}
|
||||
if (y.is_zero()) {
|
||||
xf = NT(1); yf = NT(0); vf = x.unit_part();
|
||||
xf = POLY(1); yf = POLY(0); vf = x.unit_part();
|
||||
return x / vf;
|
||||
}
|
||||
bool swapped = x.degree() < y.degree();
|
||||
|
|
|
|||
|
|
@ -84,18 +84,19 @@ inline int square_free_factorize
|
|||
{
|
||||
typedef Polynomial<Coeff> POLY;
|
||||
typedef Polynomial_traits_d< POLY > PT;
|
||||
typedef typename PT::Construct_polynomial Construct_polynomial;
|
||||
typedef typename PT::Univariate_content_up_to_constant_factor Ucont_utcf;
|
||||
typedef typename PT::Integral_division_up_to_constant_factor Idiv_utcf;
|
||||
|
||||
if (typename PT::Total_degree()(poly) == 0){return 0;}
|
||||
|
||||
Coeff ucont_utcf = Ucont_utcf()(poly);
|
||||
POLY regular_poly = Idiv_utcf()(poly,ucont_utcf);
|
||||
POLY regular_poly = Idiv_utcf()(poly,Construct_polynomial()(ucont_utcf));
|
||||
|
||||
int result = square_free_factorize_for_regular_polynomial(
|
||||
regular_poly, factors, multiplicities);
|
||||
|
||||
if (typename PT::Total_degree()(ucont_utcf) > 0){
|
||||
if (CGAL::total_degree(ucont_utcf) > 0){
|
||||
typedef std::vector< Coeff > Factors_uc;
|
||||
typedef std::vector< int > Multiplicities_uc;
|
||||
Factors_uc factors_uc;
|
||||
|
|
@ -106,7 +107,7 @@ inline int square_free_factorize
|
|||
|
||||
for( typename Factors_uc::iterator it = factors_uc.begin();
|
||||
it != factors_uc.end(); ++it ){
|
||||
*factors++ = POLY(*it);
|
||||
*factors++ = Construct_polynomial()(*it);
|
||||
}
|
||||
for( Multiplicities_uc::iterator it = multiplicities_uc.begin();
|
||||
it != multiplicities_uc.end(); ++it ){
|
||||
|
|
|
|||
|
|
@ -156,8 +156,8 @@ CGAL_BEGIN_NAMESPACE
|
|||
typename CGAL::Algebraic_structure_traits<Polynomial>::Is_zero is_zero;
|
||||
|
||||
if(degree(P) < 1 || degree(Q) < 1) {
|
||||
*out++ = CGAL::internal::resultant_for_constant_polynomial
|
||||
<Polynomial_traits_d> (P,Q);
|
||||
*out++ = Polynomial(CGAL::internal::resultant_for_constant_polynomial
|
||||
<Polynomial_traits_d> (P,Q));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
@ -260,8 +260,8 @@ CGAL_BEGIN_NAMESPACE
|
|||
typename Polynomial_traits_d::Construct_polynomial construct;
|
||||
|
||||
if(degree(P) < 1 || degree(Q) < 1) {
|
||||
*out++ = CGAL::internal::resultant_for_constant_polynomial
|
||||
<Polynomial_traits_d> (P,Q);
|
||||
*out++ = Polynomial(CGAL::internal::resultant_for_constant_polynomial
|
||||
<Polynomial_traits_d> (P,Q));
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
@ -395,10 +395,10 @@ CGAL_BEGIN_NAMESPACE
|
|||
typename Polynomial_traits_d::Construct_polynomial construct;
|
||||
|
||||
if(degree(P) < 1 || degree(Q) < 1) {
|
||||
*sres_out++ = CGAL::internal::resultant_for_constant_polynomial
|
||||
<Polynomial_traits_d> (P,Q);
|
||||
*coP_out++ = lcoeff(Q);
|
||||
*coQ_out++ = lcoeff(P);
|
||||
*sres_out++ = Polynomial(CGAL::internal::resultant_for_constant_polynomial
|
||||
<Polynomial_traits_d> (P,Q));
|
||||
*coP_out++ = Polynomial(lcoeff(Q));
|
||||
*coQ_out++ = Polynomial(lcoeff(P));
|
||||
return sres_out;
|
||||
}
|
||||
|
||||
|
|
@ -541,7 +541,7 @@ CGAL_BEGIN_NAMESPACE
|
|||
sResP[q]=eps_p_minus_1*CGAL::ipower(lcoeff(Q),p-q-1)*Q;
|
||||
s[q]=eps_p_minus_1*CGAL::ipower(lcoeff(Q),p-q);
|
||||
sResU[q]=construct(NT(0));
|
||||
sResV[q]=eps_p_minus_1*CGAL::ipower(lcoeff(Q),p-q-1);
|
||||
sResV[q]=construct(eps_p_minus_1*CGAL::ipower(lcoeff(Q),p-q-1));
|
||||
for(int i=q+1;i<=p-2;i++) {
|
||||
sResP[i]=sResU[i]=sResV[i]=construct(NT(0));
|
||||
s[i]=NT(0);
|
||||
|
|
|
|||
|
|
@ -895,7 +895,7 @@ public:
|
|||
:public std::binary_function<Polynomial_d,Coefficient_type,Coefficient_type>{
|
||||
// Evaluate with respect to one variable
|
||||
Coefficient_type
|
||||
operator()(const Polynomial_d& p, Coefficient_type x) const {
|
||||
operator()(const Polynomial_d& p, const Coefficient_type& x) const {
|
||||
return p.evaluate(x);
|
||||
}
|
||||
#define ICOEFF typename First_if_different<Innermost_coefficient_type, Coefficient_type>::Type
|
||||
|
|
@ -915,7 +915,7 @@ public:
|
|||
typedef Coefficient_type third_argument_type;
|
||||
|
||||
Coefficient_type operator()(
|
||||
const Polynomial_d& p, Coefficient_type a, Coefficient_type b) const
|
||||
const Polynomial_d& p, const Coefficient_type& a, const Coefficient_type& b) const
|
||||
{
|
||||
return p.evaluate_homogeneous(a,b);
|
||||
}
|
||||
|
|
@ -1128,10 +1128,13 @@ struct Construct_innermost_coefficient_const_iterator_range
|
|||
|
||||
struct Integral_division_up_to_constant_factor
|
||||
:public std::binary_function<Polynomial_d, Polynomial_d, Polynomial_d> {
|
||||
|
||||
|
||||
|
||||
Polynomial_d
|
||||
operator()(const Polynomial_d& p, const Polynomial_d& q) const {
|
||||
typedef Innermost_coefficient_type IC;
|
||||
|
||||
|
||||
typename PT::Construct_polynomial construct;
|
||||
typename PT::Innermost_leading_coefficient ilcoeff;
|
||||
typename PT::Construct_innermost_coefficient_const_iterator_range range;
|
||||
|
|
|
|||
|
|
@ -826,7 +826,7 @@ void test_make_square_free(const Polynomial_traits_d&){
|
|||
Polynomial_d p;
|
||||
p = generate_sparse_random_polynomial<Polynomial_d>(3);
|
||||
|
||||
p = idiv_utcf(p, ucontent_utcf(p));
|
||||
p = idiv_utcf(p, Constructor()(ucontent_utcf(p)));
|
||||
p = make_square_free(p);
|
||||
Coeff f_intern = lcoeff(p);
|
||||
|
||||
|
|
|
|||
|
|
@ -130,11 +130,9 @@ CGAL_UNARY_POLY_FUNCTION_INDEX(Differentiate, differentiate)
|
|||
// Evaluate
|
||||
CGAL_BINARY_POLY_FUNCTION(Evaluate,evaluate)
|
||||
// EvaluateHomogeneous
|
||||
template <typename Polynomial_d> inline
|
||||
template <typename Polynomial_d, typename T> inline
|
||||
typename Polynomial_traits_d<Polynomial_d>::Evaluate_homogeneous::result_type
|
||||
evaluate_homogeneous(const Polynomial_d& p,
|
||||
const typename Polynomial_traits_d<Polynomial_d>::Coefficient_type& num,
|
||||
const typename Polynomial_traits_d<Polynomial_d>::Coefficient_type& den){
|
||||
evaluate_homogeneous(const Polynomial_d& p,const T& num, const T& den){
|
||||
typedef Polynomial_traits_d<Polynomial_d> PT;
|
||||
return typename PT::Evaluate_homogeneous()(p,num,den);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ void test_routine() {
|
|||
typedef typename Arithmetic_kernel::Rational Rational;
|
||||
typedef typename Arithmetic_kernel::Integer Integer;
|
||||
|
||||
|
||||
typedef CGAL::Polynomial<Integer> Poly_int1;
|
||||
typedef CGAL::Polynomial_traits_d<Poly_int1> Poly_int1_traits;
|
||||
|
||||
|
|
@ -323,15 +324,15 @@ void test_routine() {
|
|||
CGAL::internal::prs_polynomial_subresultants<Poly_int1_traits>
|
||||
(f,g,std::back_inserter(sres));
|
||||
CGAL_assertion(sres.size()==1);
|
||||
CGAL_assertion(sres[0].degree()==0);
|
||||
CGAL_assertion(sres[0][0]==Integer(8*8*8));
|
||||
//CGAL_assertion(sres[0].degree()==0);
|
||||
CGAL_assertion(sres[0]==Integer(8*8*8));
|
||||
sres.clear();
|
||||
|
||||
CGAL::internal::bezout_polynomial_subresultants<Poly_int1_traits>
|
||||
(f,g,std::back_inserter(sres));
|
||||
CGAL_assertion(sres.size()==1);
|
||||
CGAL_assertion(sres[0].degree()==0);
|
||||
CGAL_assertion(sres[0][0]==Integer(8*8*8));
|
||||
//CGAL_assertion(sres[0].degree()==0);
|
||||
CGAL_assertion(sres[0]==Integer(8*8*8));
|
||||
std::vector<Integer> psres;
|
||||
|
||||
CGAL::internal::prs_principal_subresultants<Poly_int1_traits>
|
||||
|
|
@ -352,19 +353,19 @@ void test_routine() {
|
|||
CGAL::internal::prs_polynomial_subresultants<Poly_int1_traits>
|
||||
(f,g,std::back_inserter(sres));
|
||||
CGAL_assertion(sres.size()==1);
|
||||
CGAL_assertion(sres[0].is_zero());
|
||||
CGAL_assertion(CGAL::is_zero(sres[0]));
|
||||
sres.clear();
|
||||
|
||||
CGAL::internal::bezout_polynomial_subresultants<Poly_int1_traits>
|
||||
(f,g,std::back_inserter(sres));
|
||||
CGAL_assertion(sres.size()==1);
|
||||
CGAL_assertion(sres[0].is_zero());
|
||||
CGAL_assertion(CGAL::is_zero(sres[0]));
|
||||
}
|
||||
{
|
||||
Poly_int1 f(Integer(7));
|
||||
Poly_int1 g(Integer(-12));
|
||||
|
||||
std::vector<Poly_int1> sres;
|
||||
std::vector<Integer> sres;
|
||||
CGAL::internal::prs_principal_subresultants<Poly_int1_traits>
|
||||
(f,g,std::back_inserter(sres));
|
||||
CGAL_assertion(sres.size()==1);
|
||||
|
|
|
|||
|
|
@ -859,10 +859,10 @@ void test_total_degree(){
|
|||
assert(CGAL::total_degree(Poly_2(0)) == 0);
|
||||
assert(CGAL::total_degree(Poly_2(1)) == 0);
|
||||
assert(CGAL::total_degree(Poly_2(Poly_1(1),Poly_1(1))) == 1);
|
||||
assert(CGAL::total_degree(Poly_2(0,0,0,1))== 3);
|
||||
assert(CGAL::total_degree(Poly_2(Poly_1(0),Poly_1(0),Poly_1(0),Poly_1(1)))== 3);
|
||||
|
||||
assert(CGAL::total_degree(Poly_2(Poly_1(1,1),Poly_1(1))) == 1);
|
||||
assert(CGAL::total_degree(Poly_2(0,0,1))== 2);
|
||||
assert(CGAL::total_degree(Poly_2(Poly_1(0),Poly_1(0),Poly_1(1)))== 2);
|
||||
assert(CGAL::total_degree(Poly_2(Poly_1(0),Poly_1(0),Poly_1(1)))== 2);
|
||||
assert(CGAL::total_degree(Poly_2(Poly_1(0),Poly_1(0),Poly_1(1,1)))== 3);
|
||||
assert(CGAL::total_degree(Poly_2(Poly_1(1),Poly_1(0),Poly_1(1,1)))== 3);
|
||||
|
|
|
|||
Loading…
Reference in New Issue