Merge branch 'cgal/releases/CGAL-4.14-branch'
whitespace+tab removal, merged with option -Xignore-all-space
This commit is contained in:
@@ -3,80 +3,80 @@
|
||||
|
||||
#ifdef CGAL_USE_GMP
|
||||
|
||||
#include <CGAL/Gmpz.h>
|
||||
#include <CGAL/Gmpz.h>
|
||||
#include <CGAL/Polynomial.h>
|
||||
|
||||
// Function in case Polynomial is Modularizable
|
||||
template< typename Polynomial >
|
||||
bool may_have_common_factor(
|
||||
const Polynomial& p1, const Polynomial& p2, CGAL::Tag_true){
|
||||
std::cout<< "The type is modularizable" << std::endl;
|
||||
std::cout<< "The type is modularizable" << std::endl;
|
||||
|
||||
// Enforce IEEE double precision and rounding mode to nearest
|
||||
// before useing modular arithmetic
|
||||
// Enforce IEEE double precision and rounding mode to nearest
|
||||
// before useing modular arithmetic
|
||||
CGAL::Protect_FPU_rounding<true> pfr(CGAL_FE_TONEAREST);
|
||||
|
||||
|
||||
// Use Modular_traits to convert to polynomials with modular coefficients
|
||||
typedef CGAL::Modular_traits<Polynomial> MT;
|
||||
typedef typename MT::Residue_type MPolynomial;
|
||||
typedef typename MT::Modular_image Modular_image;
|
||||
MPolynomial mp1 = Modular_image()(p1);
|
||||
MPolynomial mp2 = Modular_image()(p2);
|
||||
|
||||
// check for unlucky primes, the polynomials should not lose a degree
|
||||
|
||||
// check for unlucky primes, the polynomials should not lose a degree
|
||||
typename CGAL::Polynomial_traits_d<Polynomial>::Degree degree;
|
||||
typename CGAL::Polynomial_traits_d<MPolynomial>::Degree mdegree;
|
||||
if ( degree(p1) != mdegree(mp1)) return true;
|
||||
if ( degree(p2) != mdegree(mp2)) return true;
|
||||
if ( degree(p1) != mdegree(mp1)) return true;
|
||||
if ( degree(p2) != mdegree(mp2)) return true;
|
||||
|
||||
// compute gcd for modular images
|
||||
// compute gcd for modular images
|
||||
MPolynomial mg = CGAL::gcd(mp1,mp2);
|
||||
|
||||
// if the modular gcd is not trivial: return true
|
||||
|
||||
// if the modular gcd is not trivial: return true
|
||||
if ( mdegree(mg) > 0 ){
|
||||
std::cout << "The gcd may be non trivial" << std::endl;
|
||||
return true;
|
||||
}else{
|
||||
std::cout << "The gcd is trivial" << std::endl;
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// This function returns true, since the filter is not applicable
|
||||
// This function returns true, since the filter is not applicable
|
||||
template< typename Polynomial >
|
||||
bool may_have_common_factor(
|
||||
const Polynomial&, const Polynomial&, CGAL::Tag_false){
|
||||
std::cout<< "The type is not modularizable" << std::endl;
|
||||
return true;
|
||||
std::cout<< "The type is not modularizable" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
template< typename Polynomial >
|
||||
Polynomial modular_filtered_gcd(const Polynomial& p1, const Polynomial& p2){
|
||||
typedef CGAL::Modular_traits<Polynomial> MT;
|
||||
typedef typename MT::Is_modularizable Is_modularizable;
|
||||
|
||||
// Try to avoid actual gcd computation
|
||||
|
||||
// Try to avoid actual gcd computation
|
||||
if (may_have_common_factor(p1,p2, Is_modularizable())){
|
||||
// Compute gcd, since the filter indicates a common factor
|
||||
return CGAL::gcd(p1,p2);
|
||||
}else{
|
||||
typename CGAL::Polynomial_traits_d<Polynomial>::Univariate_content content;
|
||||
typename CGAL::Polynomial_traits_d<Polynomial>::Construct_polynomial construct;
|
||||
return construct(CGAL::gcd(content(p1),content(p2))); // return trivial gcd
|
||||
return construct(CGAL::gcd(content(p1),content(p2))); // return trivial gcd
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
CGAL::set_pretty_mode(std::cout);
|
||||
|
||||
typedef CGAL::Gmpz NT;
|
||||
typedef CGAL::Polynomial<NT> Poly;
|
||||
|
||||
typedef CGAL::Gmpz NT;
|
||||
typedef CGAL::Polynomial<NT> Poly;
|
||||
CGAL::Polynomial_traits_d<Poly>::Construct_polynomial construct;
|
||||
|
||||
Poly f1=construct(NT(2), NT(6), NT(4));
|
||||
Poly f1=construct(NT(2), NT(6), NT(4));
|
||||
Poly f2=construct(NT(12), NT(4), NT(8));
|
||||
Poly f3=construct(NT(3), NT(4));
|
||||
|
||||
|
||||
std::cout << "f1 : " << f1 << std::endl;
|
||||
std::cout << "f2 : " << f2 << std::endl;
|
||||
|
||||
@@ -87,7 +87,7 @@ int main(){
|
||||
std::cout << std::endl;
|
||||
Poly p1 = f1*f3;
|
||||
Poly p2 = f2*f3;
|
||||
|
||||
|
||||
std::cout << "f3 : " << f3 << std::endl;
|
||||
std::cout << "p1=f1*f3 : " << p1 << std::endl;
|
||||
std::cout << "p2=f2*f3 : " << p2 << std::endl;
|
||||
@@ -100,7 +100,7 @@ int main(){
|
||||
#else
|
||||
|
||||
int main (){
|
||||
std::cout << " This example needs GMP! " << std::endl;
|
||||
std::cout << " This example needs GMP! " << std::endl;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user