Borderbasix

pol.hpp
Go to the documentation of this file.
1 #include"ugly.hpp"
2 template<typename T> void *MAC_REV_MALLOC(int size);
3 template<typename T> void *MAC_REV_REALLOC(void*ptr,int,int);
4 
5 template<typename mon,typename T>
6 struct pol
7 {
8  typedef mon monom_t;
9  typedef T coeff_t;
10  int size;
12  T * nf;
13  // pol operator*(const mon&t);//multi par un monome
14  pol operator*(const T &t);
15  pol &operator-=(const pol& Q);
16  pol &operator=(const pol&Q);
17  pol &operator/=(const T &t);
18  ~pol() {};
19 };
20 
21 //
22 //
23 //
24 // Attention deux operateurs de multiplication
25 
26 //
27 //un par un monom constant alp
28 //Buggy function no change of indices... :-((((
29 //comented the
30 //Tue Dec 4 16:39:25 MET 2001
31 // template<typename mon,typename T>
32 // pol<mon,T> pol<mon,T>::operator*(const pol<mon,T>::monom_t & toto)
33 // {
34 // // cout<<"size "<<size<<endl;
35 // //cout<<"ind "<<ind<<endl;
36 // //cout<<"nf "<<nf<<endl;
37 // //cout<<"monom "<<toto<<endl;
38 // T tmp=toto.GetCoeff();
39 // int tmpsize=this->size;
40 // for(int i=0;i<tmpsize;i++)
41 // nf[i]*=tmp;
42 // return *this;
43 // }
44 //
45 //l'autre par un coeff constant
46 //
47 
48 template<typename mon,typename T>
50 {
51  int tmpsize=this->size;
52  for(int i=0;i<tmpsize;i++)
53  nf[i]*=toto;
54  return *this;
55 }
56 template<typename mon,typename T>
58 {
59  typedef typename mon::coeff_t mcoeff_t;
60  int tmpsize=Q.size;
61  //cout<<"op-="<<size<<endl;
62  if (size<Q.size)
63  {
64  nf=(mcoeff_t*)
65  MAC_REV_REALLOC<mcoeff_t>(nf,sizeof(T)*size
66  ,sizeof(T)*Q.size);
67  for(int i=size;i<Q.size;i++)
68  nf[i]=0;
69  size=Q.size;
70  }
71  //if(min>Q.size) min=Q.size;
72  for(int i=0;i<tmpsize;i++)
73  nf[i]-=Q.nf[i];
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  size=Q.size;
86  ind=Q.ind;
87  return *this;
88 }
89 
90 template<typename mon,typename T>
92 {
93  for(int i=0;i<this->size;i++)
94  nf[i]/=t;
95  return *this;
96 }
97 template<typename polyalp,typename poly>
98 polyalp invconv(const poly & p)
99 {
100  typedef typename polyalp::monom_t mon;
101  typedef typename polyalp::order_t ord;
102  polyalp res(0);
103  // cout<<"p.size "<<p.size<<endl;
104  for(int i=0;i<p.size;i++)
105  {
106  if (!Iszero(p.nf[i]))
107  {
108  mon tmp;
109  int2mon(i,tmp);
110  //cout<<"i vaut"<<i<<endl;
111  //cout<<"j'aoute le monome "<<tmp<<endl;
112  //cout<<"LE COEFF EST "<<p.nf[i]<<endl;
113  //cout<<"res dans invconv"<<endl<<res<<endl;
114  res+=tmp*p.nf[i];
115  }
116  }
117  if (!Iszero(p.ind.GetCoeff()))
118  res+=p.ind;
119  //cout<<"res dans invconv"<<endl<<res<<endl;
120  return res;
121 }
122 
123 
124 // renvoit mon/x_i .... mais suppose qu'on ne fait pas n'importe quoi
125 //necessaire pour convert
126 
127 template <typename Mon,typename Base>
128 Mon divmon(const Mon &mon,int i,const Base &b)
129 {
130  Mon res(1);
131  for(int j=0;j<b.nvar();j++)
132  if(i==j)
133  {
134  res*=Mon(j,mon.GetDegree(j)-1);
135  }
136  else
137  {
138  res*=Mon(j,mon.GetDegree(j));
139  }
140  return res;
141 }
142 
143 //convertie un polyalp en pol
144 template<typename pol,typename polyalp,typename Base>
145 pol convert(const polyalp &P,const Base &b)
146 {
147  typedef typename polyalp::order_t ord;
148  typedef typename polyalp::monom_t mon;
149  typedef typename mon::coeff_t coeff;
150  pol res;
151  int max=0;
152  // cout<<"entree de convert"<<endl;
153  //cout<<"le pol que g ici c "<<P<<endl;
154  for(typename polyalp::const_iterator iter=P.begin();iter!=P.end();iter++)
155  {
156  if(IsinB(*iter,b))
157  {
158  //int toto=mon2int(*iter),tutu=mon2int(*iter);
159  max=(max<mon2int(*iter))?mon2int(*iter):max;
160  // cout<<"mon2int(*iter)"<<toto<<" "<<tutu<<endl;
161  }
162  else {/*cout<<*iter<<" n'est pas dans B "<<endl;*/};
163  }
164  res.size=max+1;
165  res.nf=(coeff*)MAC_REV_MALLOC<coeff>(res.size*sizeof(coeff));
166  for(int i=0;i<res.size;i++)
167  res.nf[i]=0;
168  //memset((void*)res.nf,0,res.size*sizeof(coeff));
169  for(typename polyalp::const_iterator iter=P.begin();iter!=P.end();iter++)
170  if(IsinB(*iter,b))
171  {
172  //cout<<"mon2int("<<*iter<<") "<<mon2int(*iter)<<" et size "<<res.size<<endl;
173  res.nf[mon2int(*iter)]=iter->GetCoeff();
174  }
175  else
176  {
177  // cout<<"le monome "<<*iter<<" et le coeff "<<iter->GetCoeff()<<endl;
178  //printf("le vrai nom est %.32f\n",iter->GetCoeff());
179  if(!Iszero(coeff(iter->GetCoeff())))
180  //le pol devrait NE PAS CONTENIR DE MONOME
181  //EN DEHORS DU QUOTIENT AUTRE QUE x_i^{d_i}
182  {
183  // int i;
184  // cout<<"trouve monome correspondant a la description "<<*iter<<endl;
185  res.ind=*iter;
186  //res.size--;
187  //res/=iter->GetCoeff();
188  }
189  }
190  return res;
191 }
192 
193 template<typename mon,typename T>
194 int Degree(const pol<mon,T> &p)
195 {
196  int mmax=-1;
197  for(int i=0;i<p.size;i++)
198  if(!Iszero(p.nf[i]))
199  {
200  mon tmpmon;
201  int2mon(i,tmpmon);
202  mmax=(mmax<tmpmon.GetDegree())?tmpmon.GetDegree():mmax;
203  }
204  if(!Iszero(p.ind.GetCoeff()))
205  mmax=(mmax<p.ind.GetDegree())?p.ind.GetDegree():mmax;
206  return mmax;//p.ind.GetDegree();
207 }
208 
209 template<typename mon ,typename T>
211 {
212  mon tmp;
213  int2mon(j,tmp);
214  return tmp;
215 }
216 
217 
mon monofindex(int j, pol< mon, T > &p)
Definition: pol.hpp:210
#define max(a, b)
Definition: alp_f2c.H:167
C GetCoeff() const
Definition: Monom.hpp:67
Definition: pol.hpp:6
typpol nf(int var, int indmon, const typdump &dump, const Base &b)
Definition: corealgo.hpp:1001
void * MAC_REV_REALLOC(void *ptr, int, int)
Definition: memory.hpp:49
T coeff_t
Definition: pol.hpp:9
int mon2int(const mon &mm)
Definition: placemon.hpp:294
MSKconetypee MSKrealt MSKint32t MSKint32t j
Definition: mosek.h:2421
~pol()
Definition: pol.hpp:18
void int2mon(const int &i, mon &res)
Definition: placemon.hpp:288
C coeff_t
Definition: Monom.hpp:26
pol & operator=(const pol &Q)
Definition: pol.hpp:82
mon monom_t
Definition: pol.hpp:8
int Degree(const pol< mon, T > &p)
Definition: pol.hpp:194
int IsinB(const mon &m, const Base &b)
Definition: IsinB3.hpp:68
void * MAC_REV_MALLOC(int size)
Definition: memory.hpp:39
Mon divmon(const Mon &mon, int i, const Base &b)
Definition: pol.hpp:128
Mon mon
Definition: solver_bb_floating.cpp:136
Definition: types.hpp:14
exponent_t GetDegree() const
Definition: Monom.hpp:70
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
int Iszero(const Scl< MPQ > &c)
Definition: Iszero.hpp:14
Monom< COEFF, dynamicexp<'x'> > Mon
Definition: solver_bb_floating.cpp:134
int size
Definition: pol.hpp:10
pol & operator/=(const T &t)
Definition: pol.hpp:91
mon ind
Definition: pol.hpp:11
Multivariate monomials.
Definition: Monom.hpp:21
polyalp invconv(const poly &p)
Definition: pol.hpp:98
pol & operator-=(const pol &Q)
Definition: pol.hpp:57
T * nf
Definition: pol.hpp:12
pol operator*(const T &t)
Definition: pol.hpp:49
pol convert(const polyalp &P, const Base &b)
Definition: pol.hpp:145
Home  |  Download & InstallContributions