BWAPI
|
00001 // Copyright (c) 2002-2008 Max-Planck-Institute Saarbruecken (Germany) 00002 // 00003 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or 00004 // modify it under the terms of the GNU Lesser General Public License as 00005 // published by the Free Software Foundation; version 2.1 of the License. 00006 // See the file LICENSE.LGPL distributed with CGAL. 00007 // 00008 // Licensees holding a valid commercial license may use this file in 00009 // accordance with the commercial license agreement provided with the software. 00010 // 00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 // 00014 // $URL: svn+ssh://afabri@scm.gforge.inria.fr/svn/cgal/trunk/Polynomial/include/CGAL/Polynomial/polynomial_functions.h $ 00015 // $Id: polynomial_functions.h 46402 2008-10-21 16:20:05Z eric $ 00016 // 00017 // 00018 // Author(s) : Michael Hemmer 00019 // 00020 // ============================================================================ 00021 00022 // TODO: The comments are all original EXACUS comments and aren't adapted. So 00023 // they may be wrong now. 00024 00025 #ifndef CGAL_POLYNOMIAL_MODULAR_FILTER_H 00026 #define CGAL_POLYNOMIAL_MODULAR_FILTER_H 00027 00028 #include <CGAL/basic.h> 00029 00030 #include <CGAL/Polynomial.h> 00031 #include <CGAL/polynomial_utils.h> 00032 #include <CGAL/Polynomial/prs_resultant.h> 00033 #include <CGAL/Modular_traits.h> 00034 00035 CGAL_BEGIN_NAMESPACE 00036 00037 namespace CGALi { 00038 template <class NT> inline 00039 bool 00040 may_have_common_factor_( 00041 const Polynomial<NT>& p1, 00042 const Polynomial<NT>& p2, 00043 ::CGAL::Tag_true){ 00044 00045 // Enforce IEEE double precision and to nearest before using modular arithmetic 00046 CGAL::Protect_FPU_rounding<true> pfr(CGAL_FE_TONEAREST); 00047 00048 CGAL_precondition(p1.degree()!=-1); 00049 CGAL_precondition(p2.degree()!=-1); 00050 00051 if(CGAL::total_degree(p1) == 0){ return p1.is_zero();} 00052 if(CGAL::total_degree(p2) == 0){ return p2.is_zero();} 00053 00054 typedef Polynomial<NT> Polynomial_nt; 00055 typedef Modular_traits<Polynomial_nt> MT; 00056 typedef typename MT::Residue_type Polynomial_mt; 00057 00058 typename MT::Modular_image modular_image; 00059 00060 typename CGAL::Polynomial_traits_d<Polynomial_nt>::Degree_vector 00061 degree_vector_nt; 00062 00063 typename CGAL::Polynomial_traits_d<Polynomial_mt>::Degree_vector 00064 degree_vector_mt; 00065 00066 Polynomial_mt m1=modular_image(p1); 00067 Polynomial_mt m2=modular_image(p2); 00068 00069 CGAL::Exponent_vector exp_vec_nt_1 = degree_vector_nt( p1 ); 00070 CGAL::Exponent_vector exp_vec_nt_2 = degree_vector_nt( p2 ); 00071 CGAL::Exponent_vector exp_vec_mt_1 = degree_vector_mt( m1 ); 00072 CGAL::Exponent_vector exp_vec_mt_2 = degree_vector_mt( m2 ); 00073 00074 // return true if the exponent vector changes (degree loss) 00075 if( (exp_vec_nt_1 != exp_vec_mt_1) || 00076 (exp_vec_nt_2 != exp_vec_mt_2 ) ) 00077 return true; 00078 00079 typename CGAL::Polynomial_traits_d<Polynomial_mt>::Total_degree 00080 tdegree_mt; 00081 00082 if( tdegree_mt( CGAL::gcd( m1, m2 ) ) > 0 ) 00083 return true; 00084 else 00085 return false; 00086 } 00087 00088 template <class NT> inline 00089 bool may_have_common_factor_(const Polynomial<NT>& p1, 00090 const Polynomial<NT>& p2, 00091 ::CGAL::Tag_false) {return true;} 00092 00105 template <class NT> inline 00106 bool may_have_common_factor(const Polynomial<NT>& P, 00107 const Polynomial<NT>& Q){ 00108 // TODO: Should this compiler switch be renamed? 00109 #ifdef CGAL_MODULAR_FILTER_OFF 00110 return true; 00111 #endif 00112 00113 CGAL_precondition( Residue::get_current_prime()!=0 ); 00114 typedef Polynomial<NT> POLY; 00115 typedef Modular_traits<POLY> Mtr; 00116 typename Mtr::Is_modularizable is_modularizable; 00117 return CGALi::may_have_common_factor_(P,Q,is_modularizable); 00118 } 00119 00130 template <class NT> inline 00131 bool may_have_multiple_factor_(const Polynomial<NT>& P, CGAL::Tag_true ){ 00132 00133 // Enforce IEEE double precision and to nearest before using modular arithmetic 00134 CGAL::Protect_FPU_rounding<true> pfr(CGAL_FE_TONEAREST); 00135 00136 // Create modular images of p 00137 typedef Polynomial<NT> Polynomial_nt; 00138 typedef Modular_traits<Polynomial_nt> MT; 00139 typedef typename MT::Residue_type Polynomial_mt; 00140 00141 typename MT::Modular_image modular_image; 00142 00143 typename CGAL::Polynomial_traits_d<Polynomial_nt>::Degree_vector 00144 degree_vector_nt; 00145 00146 typename CGAL::Polynomial_traits_d<Polynomial_mt>::Degree_vector 00147 degree_vector_mt; 00148 00149 Polynomial_mt m = modular_image( P ); 00150 00151 CGAL::Exponent_vector exp_vec_nt = degree_vector_nt( P ); 00152 CGAL::Exponent_vector exp_vec_mt = degree_vector_mt( m ); 00153 00154 if( exp_vec_nt != exp_vec_mt ) 00155 return true; 00156 00157 // Check modular image to be square free 00158 typename CGAL::Polynomial_traits_d< Polynomial_mt >::Is_square_free 00159 is_square_free; 00160 00161 return( !is_square_free( m ) ); 00162 } 00163 00164 template< class NT > inline 00165 bool may_have_multiple_factor_( const Polynomial<NT>&, CGAL::Tag_false ) { 00166 return true; 00167 } 00168 00169 template< class NT > inline 00170 bool may_have_multiple_factor( const Polynomial<NT>& P ) { 00171 if(P.degree() <= 1) 00172 return false; 00173 00174 // Modular filter 00175 CGAL_precondition( Residue::get_current_prime()!=0 ); 00176 typedef Polynomial<NT> POLY; 00177 typedef Modular_traits<POLY> Mtr; 00178 typename Mtr::Is_modularizable is_modularizable; 00179 return CGALi::may_have_multiple_factor_(P, is_modularizable); 00180 } 00181 00182 } //namespace CGALi 00183 CGAL_END_NAMESPACE 00184 00185 #endif //CGAL_MODULAR_FILTER_H