include/borderbasix/pol2ter.cc File Reference

#include "ugly.cc"

Go to the source code of this file.

Classes

Defines

Functions

Variables


Define Documentation

#define polter   pol

Definition at line 1 of file pol2ter.cc.

Referenced by convert().


Function Documentation

void compress_ind (  ) 
pol convert ( const polyalp &  P,
const Base b 
) [inline]

Definition at line 196 of file pol2ter.cc.

References Iszero(), mon2int(), nbbits, and polter.

00197 {
00198   typedef typename polyalp::order_t ord;
00199   typedef typename polyalp::monom_t mon;
00200   typedef typename mon::coeff_t coeff;
00201   coeff *tmp;
00202   polter res;
00203   int i,maxind=-1,j,p=0;
00204   i=0;
00205   res.ind=mon(0);
00206   for(typename polyalp::const_iterator iter=P.begin();iter!=P.end();iter++)
00207     if ((IsinB(*iter,b))&&(mon2int(*iter)>maxind))
00208       maxind=mon2int(*iter);
00209   maxind++;
00210   res.sizenf=(maxind/8)+1;
00211   res.nfind=(unsigned char*)malloc((maxind/8+1));
00212   memset(res.nfind,0,res.sizenf);
00213   tmp=(coeff*)MAC_REV_MALLOC<coeff>((maxind)*sizeof(coeff));
00214   for(int i=0;i<maxind;i++)
00215     tmp[i]=0;
00216   for(typename polyalp::const_iterator iter=P.begin();iter!=P.end();iter++)
00217     {
00218       if(IsinB(*iter,b))
00219         {
00220           if(!Iszero(iter->GetCoeff()))
00221             {
00222               int stockind=mon2int(*iter);
00223               tmp[stockind]=iter->GetCoeff();
00224               res.nfind[stockind/8]|=(unsigned char)(1<<(stockind%8));
00225               p++;
00226             }
00227         }
00228       else
00229         res.ind=*iter;
00230     }
00231   res.size=p;//l'ind n'est pas comptabilise dans la nf
00232   res.nf=(coeff*)MAC_REV_MALLOC<coeff>(res.size*sizeof(coeff));
00233    for( i=0;i<res.size;i++)
00234     res.nf[i]=0;
00235  
00236   j=0;
00237   for(int i=0;i<maxind;i++)
00238     if(!Iszero(coeff(tmp[i])))
00239       res.nf[j++]=tmp[i];
00240   MAC_REV_FREE<coeff>(tmp,(maxind)*sizeof(coeff));
00241   
00242   p=0;
00243   for(int i=0;i<res.sizenf;i++)
00244     p+=nbbits[res.nfind[i]];
00245 #ifdef DEB
00246   cout<<"pol.size "<<P.size()<<" kkk "<<p<<endl; 
00247 #endif
00248   return res;
00249 }

int Degree ( const pol< mon, T > &  p  )  [inline]

Definition at line 252 of file pol2ter.cc.

References int2mon(), and Iszero().

00253 {
00254   int mmax=-1;
00255   for(int i=0;i<p.sizenf;i++)
00256     if(p.nfind[i])
00257       {
00258         mon tmpmon;
00259         for(int j=0;j<8;j++)
00260           if((p.nfind[i]>>j)&1)
00261             {
00262               int2mon(8*i+j,tmpmon);
00263               mmax=(mmax<tmpmon.GetDegree())?tmpmon.GetDegree():mmax;
00264             }
00265       }
00266   if(!Iszero(p.ind.GetCoeff()))
00267      mmax=(mmax<p.ind.GetDegree())?p.ind.GetDegree():mmax;
00268   return mmax;//p.ind.GetDegree();
00269 }

Mon divmon ( const Mon mon,
int  i,
const Base b 
) [inline]

Definition at line 179 of file pol2ter.cc.

00180 {
00181   Mon res(1);
00182   for(int j=0;j<b.nvar();j++)
00183     if(i==j)
00184       {
00185         res*=Mon(j,mon.GetDegree(j)-1);
00186       }
00187   else 
00188     {
00189       res*=Mon(j,mon.GetDegree(j));
00190     }
00191   return res;
00192 }

int hasmonom ( const pol< mon, T > &  p,
const mon m 
) [inline]

Definition at line 272 of file pol2ter.cc.

References mon2int().

00273 {
00274   int res=0,i,tmpind=mon2int(m);
00275   return (tmpind/8<p.sizenf) && ((p.nfind[tmpind/8]>>(tmpind%8))&1);
00276 }

polyalp invconv ( const pol< mon, T > &  p  )  [inline]

Definition at line 143 of file pol2ter.cc.

References int2mon(), Iszero(), and nbbits.

00144 {
00145   typedef typename polyalp::order_t ord;
00146   polyalp res(0);
00147   T *tmpptr=p.nf;
00148   int counter=0,decalage=0;
00149   mon tmp;
00150   for(int i=0;i<p.sizenf;i++)
00151     {
00152       unsigned char motif=p.nfind[i]&255;
00153       unsigned nb_repete=p.nfind[i]>>8;
00154       decalage=0;
00155       for(int j=0;j<8;j++)
00156         if ((p.nfind[i]>>j)&1)
00157           {
00158             for(int k=0;k<nb_repete;k++)
00159               {
00160                 int2mon(counter+8*k+j,tmp);
00161                 res+=tmp*(*(tmpptr+decalage+k*nbbits[motif]));
00162               }
00163             decalage++;
00164           }
00165       tmpptr+=nbbits[motif]*nb_repete;
00166     }
00167   if (!Iszero(p.ind.GetCoeff()))
00168     res+=p.ind;
00169   //cout<<"res dans invconv"<<endl<<res<<endl;
00170   return res;
00171 }

void MAC_REV_FREE ( void *  ptr,
int  size 
) [inline]

Definition at line 65 of file memory.cc.

00066 {
00067   if(size>0)
00068     CLEAR_ELEM<T>(ptr,size);
00069   free(ptr);
00070 }

void* MAC_REV_MALLOC ( int  size  )  [inline]

Definition at line 39 of file memory.cc.

Referenced by Dump().

00040 {
00041   //cout<<"c'est celui la "<<endl;
00042   void * res;
00043   res=malloc(size);
00044   INIT_ELEM<T>(res,size);
00045   return res;
00046 }

void* MAC_REV_REALLOC ( void *  ptr,
int  ,
int   
) [inline]

Definition at line 49 of file memory.cc.

Referenced by freeint2mon(), and putmon2().

00050 {
00051   void *res=ptr;
00052   if(size<newsize)
00053     {
00054       res=realloc(ptr,newsize);
00055       INIT_ELEM<T>((char*)res+size,newsize-size);
00056     }
00057   if(size>newsize)
00058     {
00059       CLEAR_ELEM<T>((char*)ptr+newsize,size-newsize);
00060       res=realloc(ptr,newsize);
00061     }
00062   return res;
00063 }


Variable Documentation

int nbbits[256] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8}

Definition at line 4 of file pol2ter.cc.

Referenced by convert(), and invconv().


Generated on 6 Dec 2012 for borderbasix by  doxygen 1.6.1