polynomialRing.cpp

Go to the documentation of this file.
00001 
00003 
00004 template<class TPolynomXY, class TRing>
00005 PolynomialRing<TPolynomXY, TRing>::PolynomialRing(const TRing & ring): ring_ref_m(ring)
00006         {
00007         }
00008 
00009 
00011 template<class TPolynomXY, class TRing>
00012 TPolynomXY              PolynomialRing<TPolynomXY, TRing>::addInv        (const TPolynomXY      & _polynom_ref) const
00013 {
00014 
00015         TPolynomXY  res(_polynom_ref.getDegree() );
00016         
00017         for (short  i=0; i<= _polynom_ref.getDegree(); i++)
00018                 {
00019                         for(short j=0; j<=i; j++)
00020                         {
00021                                 res.setCoeff (i-j, j , ring_ref_m.addInv( _polynom_ref.getCoeffConst(i-j, j) ) );
00022                                 #ifdef COUNT
00023                                         addCount+=1;
00024                                 #endif
00025                         }
00026                 }
00027         return res;
00028 }
00029 
00030 
00032 template<class TPolynomXY, class TRing>
00033 TPolynomXY*             PolynomialRing<TPolynomXY, TRing>::addInvReturnPtr(const        TPolynomXY      & _polynom_ref  ) const
00034 {
00035         TPolynomXY * res= new TPolynomXY(_polynom_ref.getDegree() );
00036         
00037         for (short  i=0; i<= _polynom_ref->getDegree(); i++)
00038                 {
00039                         for(short j=0; j<=i; j++)
00040                         {
00041                                 res->setCoeff (i-j, j , ring_ref_m.addInv( _polynom_ref.getCoeffConst(i-j, j) ) );
00042                                 #ifdef COUNT
00043                                         addCount+=1;
00044                                 #endif
00045                         }
00046                 }
00047         return res;
00048 }
00049 
00050 
00051 template<class TPolynomXY, class TRing>
00052         void                    PolynomialRing<TPolynomXY, TRing>::addInvInPlace(       TPolynomXY      & _polynom_ref  ) const
00053 {
00054 
00055         for (short  i=0; i<= _polynom_ref->getDegree(); i++)
00056                 {
00057                         for(short j=0; j<=i; j++)
00058                         {
00059                                 ring_ref_m.addInvInPlace( _polynom_ref.getCoeffRef(i-j, j) );
00060                                 #ifdef COUNT
00061                                         addCount+=1;
00062                                 #endif
00063                         }
00064                 }
00065         return ;
00066 }
00067 
00068 
00069 template<class TPolynomXY, class TRing>
00070 TPolynomXY              PolynomialRing<TPolynomXY, TRing>::add(const TPolynomXY & _polynom_1_ref,
00071                                                                                 const TPolynomXY & _polynom_2_ref) const
00072 {
00073 
00074         // add polynoms for different Degree currently not implemented.
00075         assert(_polynom_1_ref.getDegree()==_polynom_2_ref.getDegree() );
00076 
00077         const short resDegree= max(_polynom_1_ref.getDegree(),_polynom_2_ref.getDegree() );
00078         TPolynomXY  res (resDegree );
00079         //i-j is the x-exp and j is the y-exp., i is the currentMonomDegree
00080         for (short  currMonomDegree=0; currMonomDegree<= resDegree; currMonomDegree++)
00081                 {
00082                         for(short yExp=0; yExp<=currMonomDegree; yExp++)
00083                         {
00084                                 short xExp = currMonomDegree - yExp;
00085 
00086                                 res.setCoeff (xExp, yExp , ring_ref_m.add(      _polynom_1_ref.getCoeffConst(xExp, yExp ),
00087                                                                                 _polynom_2_ref.getCoeffConst(xExp, yExp ) 
00088                                                                 )
00089                                                         );
00090                                 #ifdef COUNT
00091                                         addCount+=1;
00092                                 #endif
00093                         }
00094                 }
00095         return res;
00096 }
00097 
00098 template<class TPolynomXY, class TRing>
00099 TPolynomXY*     PolynomialRing<TPolynomXY, TRing>::addReturnPtr( const  TPolynomXY       & _polynom_1_ref,
00100                                                                                         const   TPolynomXY       & _polynom_2_ref) const
00101 {
00102 // add polynoms for different Degree currently not implemented.
00103         assert(_polynom_1_ref.getDegree()==_polynom_2_ref.getDegree() );
00104 
00105         const short resDegree= max(_polynom_1_ref.getDegree(),_polynom_2_ref.getDegree);
00106         TPolynomXY *  res = new TPolynomXY(resDegree );
00107         //i-j is the x-exp and j is the y-exp., i is the currentMonomDegree
00108         for (short  currMonomDegree=0; currMonomDegree<= resDegree; currMonomDegree++)
00109                 {
00110                         for(short yExp=0; yExp<=currMonomDegree; yExp++)
00111                         {
00112                                 short xExp = currMonomDegree - yExp;
00113 
00114                                 res->setCoeff (xExp, yExp , ring_ref_m.add(     _polynom_1_ref.getCoeffConst(xExp, yExp ),
00115                                                                                 _polynom_2_ref.getCoeffConst(xExp, yExp ) 
00116                                                                 )
00117                                                         );
00118                                 #ifdef COUNT
00119                                         addCount+=1;
00120                                 #endif
00121                         }
00122                 }
00123         return res;
00124 }
00125 
00126 
00127 template<class TPolynomXY, class TRing>
00128 inline void                     PolynomialRing<TPolynomXY, TRing>::addInPlace(  TPolynomXY                      & _polynom_1_ref,
00129                                                                                         const TPolynomXY                & _polynom_2_ref) const
00130 {
00131         // add polynoms for different Degree currently not implemented.
00132         assert(_polynom_1_ref.getDegree() == _polynom_2_ref.getDegree() );
00133 
00134         //i-j is the x-exp and j is the y-exp., i is the currentMonomDegree
00135         for (short  currMonomDegree=0; currMonomDegree<= _polynom_1_ref.getDegree(); currMonomDegree++)
00136                 {
00137                         for(short yExp=0; yExp<=currMonomDegree; yExp++)
00138                         {
00139                                 short xExp = currMonomDegree - yExp;
00140 
00141                                         ring_ref_m.addInPlace(  _polynom_1_ref.getCoeffRef(xExp, yExp ),
00142                                                         _polynom_2_ref.getCoeffConst(xExp, yExp ) 
00143                                                         );
00144                                 #ifdef COUNT
00145                                         addCount+=1;
00146                                 #endif
00147                         }
00148                 }
00149         return ;
00150 }
00151 
00152 
00153 template<class TPolynomXY, class TRing>
00154 TPolynomXY              PolynomialRing<TPolynomXY, TRing>::scalarMultiply(const typename TPolynomXY::CoefficientType    scalar,
00155                                                                                  const  TPolynomXY                      & _polynom_ref) const
00156 {
00157         TPolynomXY  res( _polynom_ref.getDegree() );
00158         //i-j is the x-exp and j is the y-exp., i is the currentMonomDegree
00159         for (short  currMonomDegree=0; currMonomDegree<= _polynom_ref.getDegree(); currMonomDegree++)
00160                 {
00161                         for(short yExp=0; yExp <= currMonomDegree; yExp++)
00162                         {
00163                                 short xExp = currMonomDegree - yExp;
00164 
00165                                 res.setCoeff (xExp, yExp , ring_ref_m.scalarMultiply(   scalar,
00166                                                                                         _polynom_ref.getCoeffConst( xExp, yExp ) 
00167                                                         )
00168                                         );
00169                                 #ifdef COUNT
00170                                         addCount+=1;
00171                                 #endif
00172                         }
00173                 }
00174         //short polynomDegree = _polynom_ref.getDegree()
00175         //short xexp,yexp, currDegree;
00176         // begin(xexp,yexp,currDegree, polynomDegree);
00177         // while (next (xexp,yexp,polynomDegree))
00178         //for (begin(xexp,yexp,polynomDegree); !end(currDegree, polynomDegree);  next (xexp, yexp, currDegree, polynomDegree))
00179         //      res.setCoeff (xExp, yExp , ring_ref_m.scalarMultiply(   scalar,
00180         //                                                                              _polynom_ref.getCoeffConst( xExp, yExp ) 
00181         //                                              )
00182         //                              );
00183         return res;
00184 }
00185 
00186 
00187 /*
00188 // so ungefähr könnte man es mit dem Durchlaufen der Monome machen: begin() und next()
00189 // da brauchst du aber strenggenommen eine const-iterator, einen Ref-Iterator und einen normalen Iterator
00190 inline bool begin(short & xexp, short & yexp , short currDegree, int polynomialDegree)
00191 { 
00192         currDegree = 0;
00193         xexp = 0;
00194         yexp = 0;
00195         return ( polynomialDegree>=0 );
00196 }
00197 
00198 inline bool end(  short & currDegree, int polynomialDegree)
00199 { 
00200         return  (currDegree<=polynomialDegree);
00201 }
00202 
00203 // so ungefähr könnte man ex machen.
00204 inline bool nextMonomExp(short & xexp, short & yexp, short &currDegree, int polynomialDegree)
00205 {
00206         //short currDegree = xexp + yexp;
00207         if (yexp<currDegree)
00208         {
00209                 yexp++;
00210                 xexp--;
00211         }
00212         else 
00213         {
00214                 currDegree++;
00215                 xexp=currDegree;
00216                 yexp=0;
00217                 if (currDegree>polynomialDegree)
00218                         return false;
00219         }
00220         return true;
00221 
00222 }*/
00223 
00224 template<class TPolynomXY, class TRing>
00225 void            PolynomialRing<TPolynomXY, TRing>::scalarMultiplyInPlace(const typename TPolynomXY::CoefficientType     scalar,
00226                                                                                 TPolynomXY                              & _polynom_ref  ) const
00227 {
00228  
00229         //i-j is the x-exp and j is the y-exp., i is the currentMonomDegree
00230         for (short  currMonomDegree=0; currMonomDegree<= _polynom_ref.getDegree(); currMonomDegree++)
00231                 {
00232                         for(short yExp=0; yExp <= currMonomDegree; yExp++)
00233                         {
00234                                 short xExp = currMonomDegree - yExp;
00235 
00236                                 /*_polynom_ref.setCoeff (xExp, yExp , ring_ref_m.scalarMultiply(        scalar,
00237                                                                                                 _polynom_ref.getCoeffConst( xExp, yExp ) 
00238                                                         )
00239                                         );*/
00240                                          ring_ref_m.scalarMultiplyInPlace(scalar, _polynom_ref.getCoeffRef (xExp, yExp) );
00241 
00242                                 #ifdef COUNT
00243                                         addCount+=1;
00244                                 #endif
00245                         }
00246                 }
00247 }
00248 
00249 template<class TPolynomXY, class TRing>
00250 TPolynomXY*     PolynomialRing<TPolynomXY, TRing>::scalarMultiplyRetPtr(const   typename TPolynomXY::CoefficientType    scalar,
00251                                                                                 const   TPolynomXY                      & _polynom_ref) const
00252 {
00253         
00254         TPolynomXY*  res = new TPolynomXY( _polynom_ref.getDegree() );
00255         //i-j is the x-exp and j is the y-exp., i is the currentMonomDegree
00256         for (short  currMonomDegree=0; currMonomDegree<= _polynom_ref.getDegree(); currMonomDegree++)
00257                 {
00258                         for(short yExp=0; yExp <= currMonomDegree; yExp++)
00259                         {
00260                                 short xExp = currMonomDegree - yExp;
00261 
00262                                 res->setCoeff (xExp, yExp , ring_ref_m.scalarMultiply(  scalar,
00263                                                                                         _polynom_ref.getCoeffConst( xExp, yExp ) 
00264                                                         )
00265                                         );
00266                                 #ifdef COUNT
00267                                         addCount+=1;
00268                                 #endif
00269                         }
00270                 }
00271         //short polynomDegree = _polynom_ref.getDegree()
00272         //short xexp,yexp, currDegree;
00273         // begin(xexp,yexp,currDegree, polynomDegree);
00274         // while (next (xexp,yexp,polynomDegree))
00275         //for (begin(xexp,yexp,polynomDegree); !end(currDegree, polynomDegree);  next (xexp, yexp, currDegree, polynomDegree))
00276         //      res.setCoeff (xExp, yExp , ring_ref_m.scalarMultiply(   scalar,
00277         //                                                                              _polynom_ref.getCoeffConst( xExp, yExp ) 
00278         //                                              )
00279         //                              );
00280         return res;
00281 }
00282 
00284 template<class TPolynomXY, class TRing>
00285 template <class TPolynomXY_SRC_Type, class TPolynomXY_DEST_Type>
00286 void    PolynomialRing<TPolynomXY, TRing>::copyPolynomWithGivenEpsPrecision(const TPolynomXY_SRC_Type  & srcPol,
00287                                                                          TPolynomXY_DEST_Type   &        destPol, int epsPrecision)
00288 {       
00289         //assert((&srcPol) != (&destPol)) ;
00290 
00291         for (int deg = srcPol.getDegree(); deg>=0; deg--)
00292         {
00293                 for (int x_exp=deg; x_exp>=0; x_exp--)
00294                 {
00295                         int MaxEpsPrecision= min(epsPrecision, (int)srcPol.getCoeff(x_exp, deg-x_exp).getEpsPrecision() );
00296 
00297                         for (int prec=0; prec<= MaxEpsPrecision ; prec++)
00298                         {
00299                                 destPol.getCoeffRef(    x_exp, deg-x_exp).setValue(prec, 0);
00300                         }
00301 
00302                         
00303                         for (int prec=0; prec<= MaxEpsPrecision ; prec++)
00304                         {
00305                                 destPol.getCoeffRef(    x_exp, deg-x_exp).setValue(prec,
00306                                                                                         srcPol.getCoeff(x_exp, deg-x_exp).getValue(prec) );
00307                         }
00308                 }
00309         }
00310 }
00311 
00312 
00313 
00314 template<class TPolynomXY, class TRing>
00315 template <class TPolynomXY_Type>
00316 void    PolynomialRing<TPolynomXY, TRing>::convertInPlace( TPolynomXY_Type  & pol ) const
00317 {
00318         for (int deg = pol.getDegree(); deg>=0; deg--)
00319         {
00320                 for (int x_exp=deg; x_exp>=0; x_exp--)
00321                 {
00322                         int MaxEpsPrecision= (int)pol.getCoeff(x_exp, deg-x_exp).getEpsPrecision();
00323                         for (int prec=0; prec<= MaxEpsPrecision ; prec++)
00324                         {
00325                                 pol.getCoeffRef(        x_exp, deg-x_exp).setValue(prec,
00326                                                                                         ring_ref_m.ConvertScalar(pol.getCoeff(x_exp, deg-x_exp).getValue(prec)) );
00327                         }
00328                 }
00329         }
00330 }
Generated on Tue Nov 23 13:10:52 2010 for centerfocus by  doxygen 1.6.3