Borderbasix

pol3sdp.hpp
Go to the documentation of this file.
1 #include"ugly.hpp"
2 #define SIZE_LIMB 100
3 //
4 //
5 //Les trois types de limb :
6 // 0 = vide
7 // 1 = dense
8 // 2 = creux
9 //
10 //
11 
12 template<typename T> void *MAC_REV_MALLOC(int size);
13 template<typename T> void *MAC_REV_REALLOC(void*ptr,int,int);
14 template<typename T> void MAC_REV_FREE(void*ptr,int size);
15 
16 template<typename mon,typename T>
17 struct polmix
18 {
19  typedef mon monom_t;
20  typedef T coeff_t;
21  mon ind;
22  int nblimb;
23  int *type_limb;
24  int *size_limb;
25  T ** nf;
26  int **nfind;
27 
28  // pol operator*(const mon&t);//multi par un monome
29  pol operator*(const T &t);
30  pol &operator-=(const pol& Q);
31  pol &operator=(const pol&Q);
32  pol &operator/=(const T &t);
33 };
34 //
35 //l'autre par un coeff constant
36 //
37 template<typename mon,typename T>
40 {
41  int tmpsize=this->size;
42  for(int i=0;i<nblib;i++)
43  {
44  if(this->type_limb[i]!=0)//vide?
45  {
46  if(this->type_limb[i]==1)//dense
47  for(int j=0;j<SIZE_LIMB;j++)
48  this->nf[i][j]*=toto;
49  else
50  if(this->type_limb[i]==2) //creux
51  {
52  for(int j=0;j<this->size_limb[i];j++)
53  this->nf[i][j]*=toto;
54  }
55  }
56  }
57  return *this;
58 }
59 
60 template<typename mon,typename T>
62 {
63  typedef typename mon::coeff_t mcoeff_t;
64  int nblimb2treat;
65  if (this->nblimb<Q.nblimb)
66  nblimb2treat=this->nblimb;
67  else
68  nblimb2treat=Q.nblimb;
69  for(int i=0;i<nblimb2treat;i++)
70  {
71  add_limb[3*this->type_limb[i]+Q.type_limb[i]](*this,Q);
72  //add_limb tableau de fonctions ajoutant suivant les cas
73  }
74  return *this;
75 }
76 //attention l'operateur -= n'agit que sur les nf
77 
78 //
79 //operateur d'affectation sans recopie de nf!!!!
80 //
81 template<typename mon,typename T>
83 {
84  nf=Q.nf;
85  nfind=Q.nfind;
86  size=Q.size;
87  ind=Q.ind;
88  return *this;
89 }
90 
91 template<typename mon,typename T>
93 {
94  for(int i=0;i<this->size;i++)
95  nf[i]/=t;
96  return *this;
97 }
98 
99 template<typename polmixyalp,typename polmixy>
100 polmixyalp invconv(const polmixy & p)
101 {
102  typedef typename polyalp::monom_t mon;
103  typedef typename polyalp::order_t ord;
104  polyalp res(0);
105  // cout<<"p.size "<<p.size<<endl;
106  for(int i=0;i<p.size;i++)
107  {
108  if (!Iszero(p.nf[i]))
109  {
110  mon tmp;
111  int2mon(p.nfind[i],tmp);
112  //cout<<"i vaut"<<i<<endl;
113  //cout<<"j'aoute le monome "<<tmp<<endl;
114  //cout<<"LE COEFF EST "<<p.nf[i]<<endl;
115  //cout<<"res dans invconv"<<endl<<res<<endl;
116  res+=tmp*p.nf[i];
117  }
118  }
119  if (!Iszero(p.ind.GetCoeff()))
120  res+=p.ind;
121  //cout<<"res dans invconv"<<endl<<res<<endl;
122  return res;
123 }
124 
125 
126 // renvoit mon/x_i .... mais suppose qu'on ne fait pas n'importe quoi
127 //necessaire pour convert
128 
129 template <typename Mon,typename Base>
130 Mon divmon(const Mon &mon,int i,const Base &b)
131 {
132  Mon res(1);
133  for(int j=0;j<b.nvar();j++)
134  if(i==j)
135  {
136  res*=Mon(j,mon.GetDegree(j)-1);
137  }
138  else
139  {
140  res*=Mon(j,mon.GetDegree(j));
141  }
142  return res;
143 }
144 
145 //converti un polmixyalp en polmix
146 template<typename polmix,typename polyalp,typename Base>
147 polmix convert(const polyalp &P,const Base &b)
148 {
149  typedef typename polyalp::order_t ord;
150  typedef typename polyalp::monom_t mon;
151  typedef typename mon::coeff_t coeff;
152  polmix res;
153  int i;
154  res.size=P.size()-1;//l'ind n'est pas comptabilise dans la nf
155  res.nf=(coeff*)MAC_REV_MALLOC<coeff>(res.size*sizeof(coeff));
156  res.nfind=(int*)MAC_REV_MALLOC<int>(res.size*sizeof(int));
157  for( i=0;i<res.size;i++)
158  res.nf[i]=0;
159  i=0;
160  //memset((void*)res.nf,0,res.size*sizeof(coeff));
161  for(typename polyalp::const_iterator iter=P.begin();iter!=P.end();iter++)
162  if(IsinB(*iter,b))
163  {
164  //cout<<"mon2int("<<*iter<<") "<<mon2int(*iter)<<" et size "<<res.size<<endl;
165  res.nf[i]=iter->GetCoeff();
166  res.nfind[i++]=mon2int(*iter);
167  }
168  else
169  {
170  // cout<<"le monome "<<*iter<<" et le coeff "<<iter->GetCoeff()<<endl;
171  //printf("le vrai nom est %.32f\n",iter->GetCoeff());
172  if(!Iszero(coeff(iter->GetCoeff())))
173  //le polmix devrait NE PAS CONTENIR DE MONOME
174  //EN DEHORS DU QUOTIENT AUTRE QUE x_i^{d_i}
175  {
176  // int i;
177  // cout<<"trouve monome correspondant a la description "<<*iter<<endl;
178  res.ind=*iter;
179  //res.size--;
180  //res/=iter->GetCoeff();
181  }
182  }
183  /*
184  //TRi a bulle a remplcer
185  for(int i=1;i<res.size;i++)
186  for(int j=0;j<res.size-i;j++)
187  {
188  if(res.nfind[j]>res.nfind[j+1])
189  {
190  coeff tmpcoeff=res.nf[j];
191  int tmpind=res.nfind[j];
192  res.nf[j]=res.nf[j+1];
193  res.nfind[j]=res.nfind[j+1];
194  res.nf[j+1]=tmpcoeff;
195  res.nfind[j+1]=tmpind;
196  }
197  }
198  */
199  sortpolmix(res);
200  return res;
201 }
202 
203 template<typename mon,typename T>
204 int Degree(const polmix<mon,T> &p)
205 {
206  int mmax=-1;
207  for(int i=0;i<p.size;i++)
208  if(!Iszero(p.nf[i]))
209  {
210  mon tmpmon;
211  int2mon(p.nfind[i],tmpmon);
212  mmax=(mmax<tmpmon.GetDegree())?tmpmon.GetDegree():mmax;
213  }
214  if(!Iszero(p.ind.GetCoeff()))
215  mmax=(mmax<p.ind.GetDegree())?p.ind.GetDegree():mmax;
216  return mmax;//p.ind.GetDegree();
217 }
218 
219 template<typename mon,typename T>
220 int hasmonom(const polmix<mon,T>& p,const mon & m)
221 {
222  int res=0,i,tmpind=mon2int(m);
223  for(i=0;i<p.size&&p.nfind[i]<tmpind;i++);
224  if(i<p.size&&p.nfind[i]==tmpind&&!Iszero(p.nf[i]))
225  res=1;
226  return res;
227 }
228 
229 template<typename T>
230 void simqsort(T * coeff, int * ind, int sizesort)
231 {
232  int i,j=sizesort-1,stockind;
233  T stock;
234  //cout<<"en entree du tri"<<endl;
235  //for(i=0;i<sizesort;i++)
236  // cout<<ind[i]<<" ";
237  //cout<<endl;
238  if (sizesort<=1) return;
239  stockind=ind[0];
240  stock=*coeff;
241  for(i=1;i<=j;i++)
242  {
243  if(stockind<ind[i])
244  {
245  for(;j>=i&&ind[j]>stockind;j--);
246  // cout<<"la place "<<j<<endl;
247  if(i<=j)
248  {
249  coeff[i-1]=coeff[j];
250  ind[i-1]=ind[j];
251  ind[j]=ind[i];
252  coeff[j]=coeff[i];
253  }
254  else break;
255  }
256  else
257  {
258  coeff[i-1]=coeff[i];
259  ind[i-1]=ind[i];
260  }
261  }
262  coeff[i-1]=stock;
263  ind[i-1]=stockind;
264  //cout<<"i ici "<<i<<endl;
265  simqsort(coeff,ind,i-1);
266  simqsort(coeff+i,ind+i,sizesort-i);
267  //cout<<"le resulat du tri"<<endl;
268  //for(i=0;i<sizesort;i++)
269  // cout<<ind[i]<<" ";
270  //cout<<endl;
271 }
272 
273 template<typename mon, typename T>
275 {
276  simqsort(p.nf,p.nfind,p.size);
277 
278 }
279 
mon monom_t
Definition: pol3sdp.hpp:19
pol & operator/=(const T &t)
Definition: pol3.hpp:92
void * MAC_REV_REALLOC(void *ptr, int, int)
Definition: memory.hpp:49
void MAC_REV_FREE(void *ptr, int size)
Definition: memory.hpp:65
void * MAC_REV_MALLOC(int size)
Definition: memory.hpp:39
C GetCoeff() const
Definition: Monom.hpp:67
Definition: pol.hpp:6
polmix convert(const polyalp &P, const Base &b)
Definition: pol3sdp.hpp:147
int * type_limb
Definition: pol3.hpp:23
typpol nf(int var, int indmon, const typdump &dump, const Base &b)
Definition: corealgo.hpp:1001
polmixyalp invconv(const polmixy &p)
Definition: pol3sdp.hpp:100
T ** nf
Definition: pol3.hpp:25
pol & operator=(const pol &Q)
int hasmonom(const polmix< mon, T > &p, const mon &m)
Definition: pol3sdp.hpp:220
int mon2int(const mon &mm)
Definition: placemon.hpp:294
MSKconetypee MSKrealt MSKint32t MSKint32t j
Definition: mosek.h:2421
void int2mon(const int &i, mon &res)
Definition: placemon.hpp:288
void sortpol(polmix< mon, T > &p)
Definition: pol3sdp.hpp:274
C coeff_t
Definition: Monom.hpp:26
void simqsort(T *coeff, int *ind, int sizesort)
Definition: pol3sdp.hpp:230
pol & operator-=(const pol &Q)
int IsinB(const mon &m, const Base &b)
Definition: IsinB3.hpp:68
Mon mon
Definition: solver_bb_floating.cpp:136
int nblimb
Definition: pol3.hpp:22
Definition: types.hpp:14
exponent_t GetDegree() const
Definition: Monom.hpp:70
Definition: pol3.hpp:17
mon ind
Definition: pol3.hpp:21
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
pol operator*(const T &t)
int Iszero(const Scl< MPQ > &c)
Definition: Iszero.hpp:14
#define SIZE_LIMB
Definition: pol3sdp.hpp:2
Monom< COEFF, dynamicexp<'x'> > Mon
Definition: solver_bb_floating.cpp:134
int * size_limb
Definition: pol3.hpp:24
int ** nfind
Definition: pol3.hpp:26
Mon divmon(const Mon &mon, int i, const Base &b)
Definition: pol3sdp.hpp:130
int Degree(const polmix< mon, T > &p)
Definition: pol3sdp.hpp:204
Multivariate monomials.
Definition: Monom.hpp:21
T coeff_t
Definition: pol3sdp.hpp:20
Home  |  Download & InstallContributions