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://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Polynomial/include/CGAL/Polynomial/modular_gcd_utils.h $ 00015 // $Id: modular_gcd_utils.h 47300 2008-12-09 10:48:07Z hemmer $ 00016 // 00017 // 00018 // Author(s) : Michael Hemmer <hemmer@mpi-inf.mpg.de> 00019 // Dominik Huelse <dominik.huelse@gmx.de> 00020 // 00021 // ============================================================================ 00022 00027 #ifndef CGAL_POLYNOMIAL_MODULAR_GCD_UTILS_H 00028 #define CGAL_POLYNOMIAL_MODULAR_GCD_UTILS_H 00029 00030 #include <CGAL/basic.h> 00031 #include <vector> 00032 #include <CGAL/Polynomial.h> 00033 00034 #include <CGAL/Timer.h> 00035 00036 namespace CGAL{ 00037 00038 namespace CGALi { 00039 00040 template <class NT> 00041 void euclidean_division_obstinate(const NT& F1, const NT& F2, 00042 NT& Q, NT& R){ 00043 00044 CGAL_precondition(F2 != 0); 00045 00046 CGAL::div_mod(F1, F2, Q, R); 00047 CGAL_postcondition(F1 == F2*Q + R); 00048 } 00049 00050 00051 template <class NT> 00052 void euclidean_division_obstinate(const Polynomial<NT>& F1, 00053 const Polynomial<NT>& F2, 00054 Polynomial<NT>& Q, Polynomial<NT>& R){ 00055 00056 // std::cout<<" my_modular_gcd_utils "<<std::endl; 00057 CGAL_precondition(!F2.is_zero()); 00058 int d1 = F1.degree(); 00059 int d2 = F2.degree(); 00060 if ( d1 < d2 ) { 00061 Q = Polynomial<NT>(NT(0)); R = F1; 00062 CGAL_postcondition( !(boost::is_same< typename Algebraic_structure_traits<NT>::Is_exact, 00063 CGAL::Tag_true >::value) || F1 == Q*F2 + R); return; 00064 } 00065 00066 typedef std::vector<NT> Vector; 00067 Vector V_R, V_Q; 00068 V_Q.reserve(d1); 00069 if(d2==0){ 00070 for(int i=d1;i>=0;--i){ 00071 V_Q.push_back(F1[i]/F2[0]); 00072 } 00073 V_R.push_back(NT(0)); 00074 } 00075 else{ 00076 V_R.reserve(d1); 00077 V_R=Vector(F1.begin(),F1.end()); 00078 Vector tmp1; 00079 tmp1.reserve(d2); 00080 for(int k=0; k<=d1-d2; ++k){ 00081 V_Q.push_back(V_R[d1-k]/F2[d2]); 00082 for(int j=0;j<d2;++j){ 00083 tmp1.push_back(F2[j]*V_Q[k]); 00084 } 00085 V_R[d1-k]=0; 00086 for(int i=d1-d2-k;i<=d1-k-1;++i){ 00087 V_R[i]=V_R[i]-tmp1[i-(d1-d2-k)]; 00088 } 00089 tmp1.clear(); 00090 } 00091 00092 00093 } 00094 Q = Polynomial<NT>(V_Q.rbegin(),V_Q.rend()); 00095 R = Polynomial<NT>(V_R.begin(),V_R.end()); 00096 CGAL_postcondition(F1 == F2*Q + R); 00097 } 00098 00099 } // namespace CGALi 00100 } // namespace CGAL 00101 00102 #endif //#ifnedef CGAL_POLYNOMIAL_MODULAR_GCD_UTILS_H 1 00103 00104 // EOF