// Copyright (c) 2008 Max-Planck-Institute Saarbruecken (Germany). // All rights reserved. // // This file is part of CGAL (www.cgal.org) // // $URL: https://github.com/CGAL/cgal/blob/v5.1/Polynomial/include/CGAL/Polynomial/polynomial_gcd_ntl.h $ // $Id: polynomial_gcd_ntl.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // // Author(s) : Michael Kerber // Dominik Huelse // Michael Hemmer // Eric Berberich // ============================================================================ /*! \file CGAL/Polynomial/polynomial_gcd_ntl.h * \brief special polynomial gcd function via NTL */ #ifndef CGAL_POLYNOMIAL_GCD_NTL_H #define CGAL_POLYNOMIAL_GCD_NTL_H #include #ifndef CGAL_USE_NTL #warning This header file needs NTL installed in order to work properly. #endif #ifdef CGAL_USE_LEDA #include #endif #ifdef CGAL_USE_CORE #include #endif #include #include #include #include #include namespace CGAL{ template class Polynomial; // fwd template class Polynomial_traits_d; } // namespace CGAL // This part forms the bridge to NTL to use the modular gcd algorithm. If // NTL is not available, the usual strategy is applied. namespace CGAL { namespace internal { // Forward template Polynomial gcd_utcf( const Polynomial& FF1 , const Polynomial& FF2 ); template inline void polynomial_to_ntl(const PolyInt& p, NTL::ZZX& q) { std::stringstream ss; ss << "[ "; for(int i=0;i<=p.degree();i++) { ss << p[i] << " "; } ss << "]"; ss >> q; } template inline void ntl_to_polynomial(const NTL::ZZX& q,PolyInt& p) { int d = NTL::deg(q); if(d==-1) { p=PolyInt(1); return; } std::stringstream ss; ss << "P["; ss << d; for(int i=0;i<=d;i++) { ss << "(" << i << "," << NTL::coeff(q,i) << ")"; } ss << "]"; p=PolyInt::input_ascii(ss); } template Polynomial inline modular_NTL_gcd_for_univariate_integer_polynomials (Polynomial p1, Polynomial p2) { // std::cout<<" NTL GCD"< g; internal::polynomial_to_ntl(p1,q1); internal::polynomial_to_ntl(p2,q2); #ifdef CGAL_MODULAR_GCD_TIMER timer_ntl2.start(); #endif NTL::GCD(h,q1,q2); #ifdef CGAL_MODULAR_GCD_TIMER timer_ntl2.stop(); #endif internal::ntl_to_polynomial(h,g); return g; } template Polynomial inline canonical_modular_NTL_gcd_for_univariate_integer_polynomials (Polynomial p1, Polynomial p2) { // std::cout<<" NTL canonical GCD"< inline CGAL::Polynomial gcd_utcf_(const CGAL::Polynomial& p1, const CGAL::Polynomial& p2) { CGAL::Polynomial gcd = internal::canonical_modular_NTL_gcd_for_univariate_integer_polynomials(p1,p2); return gcd; } template <> inline CGAL::Polynomial gcd_(const CGAL::Polynomial& p1, const CGAL::Polynomial& p2) { return internal::modular_NTL_gcd_for_univariate_integer_polynomials(p1,p2); } #endif // CGAL_USE_LEDA #ifdef CGAL_USE_CORE template <> inline Polynomial gcd_utcf_(const Polynomial& p1, const Polynomial& p2) { Polynomial gcd = canonical_modular_NTL_gcd_for_univariate_integer_polynomials(p1,p2); return gcd; } template <> inline Polynomial gcd_(const Polynomial& p1, const Polynomial& p2) { return modular_NTL_gcd_for_univariate_integer_polynomials(p1,p2); } #endif //CGAL_USE_CORE } // namespace internal } // namespace CGAL #endif // CGAL_POLYNOMIAL_GCD_NTL_H // EOF