Borderbasix

symbo2.hpp
Go to the documentation of this file.
1 #ifdef COEFF
2 #define tutu(a) a
3 #define toto(a) tutu(a)
4 #define OLD_COEFF toto(COEFF)
5 //#undef COEFF
6 #endif
7 OLD_COEFF machin;
8 #define COEFF mpq_t
9 #define PREFIX mpq
10 #include"ptpol.c"
11 
12 template<>
13 mpq_t &harewell<mpq_t>::operator() (const int &i,const int &j,const mpq_t &d)
14 {
15  cout<<"Nein Nein!!!!!!!!!!!"<<endl;
16  static mpq_t toto;
17  return toto;
18 }
19 
20 template<>
21 ptpol_t &harewell<ptpol_t>::operator() (const int &i,const int &j,const ptpol_t &d)
22 {
23  cout<<"Nein Nein!!!!!!!!!!!"<<endl;
24  static ptpol_t toto;
25  return toto;
26 }
27 
28 template<>
29 mpq_t & harewell<mpq_t>::operator() (const int &i,const int &j)
30 {
31  static mpq_t d;
32  cout<<"Nein!!!!!!!!!!!"<<endl;
33  //cout<<*(int*)NULL<<endl;
34  int colbegin=colptr[j]
35  ,colend=(j+1<this->ncol)?colptr[j+1]:nnz;
36  int t;
37  //for(t=colbegin;(t<colend)&&(i>rowind[t]);t++) ;
38  //le 17/07/2001 idee pouvoir permutter les ligne plus facilement
39  for(t=colbegin;(t<colend)&&(i!=rowind[t]);t++);
40  if (t>=colend) return d;
41  return ((i==(rowind[t]))?(((mpq_t*)(nzval))[t]):d);
42 }
43 
44 template<>
45 ptpol_t & harewell<ptpol_t>::operator() (const int &i,const int &j)
46 {
47  static ptpol_t d;
48  cout<<"Nein!!!!!!!!!!!"<<endl;
49  // cout<<*(int*)NULL<<endl;
50  int colbegin=colptr[j]
51  ,colend=(j+1<this->ncol)?colptr[j+1]:nnz;
52  int t;
53  //for(t=colbegin;(t<colend)&&(i>rowind[t]);t++) ;
54  //le 17/07/2001 idee pouvoir permutter les ligne plus facilement
55  for(t=colbegin;(t<colend)&&(i!=rowind[t]);t++);
56  if (t>=colend) return d;
57  return ((i==(rowind[t]))?(((ptpol_t*)(nzval))[t]):d);
58 }
59 
60 template<>
61 harewell<mpq_t>::harewell(const int nrow,const int ncol)
62 {
63  //Pour eviter le undefined behavior on met tous lespointeurs non initialises a NULL
64  this->nrow=nrow;
65  this->ncol=ncol;
66  this->rowind=(int*)malloc(sizeof(int)*(this->ncol));
67  this->colptr=(int*)malloc(sizeof(int)*(1+this->ncol));
68  this->nzval=malloc(sizeof(mpq_t)*(this->ncol));
69  this->nnz=this->ncol;
70  for(int i=0;i<this->ncol;i++)
71  {
72  this->rowind[i]=i;
73  this->colptr[i]=i;
74  mpq_init(((mpq_t*)this->nzval)[i]);
75  }
76  this->colptr[this->ncol]=this->nnz;
77 }
78 
79 
80 template<>
81 harewell<ptpol_t>::harewell(const int nrow,const int ncol)
82 {
83  //Pour eviter le undefined behavior on met tous lespointeurs non initialises a NULL
84  this->nrow=nrow;
85  this->ncol=ncol;
86  this->rowind=(int*)malloc(sizeof(int)*(this->ncol));
87  this->colptr=(int*)malloc(sizeof(int)*(1+this->ncol));
88  this->nzval=malloc(sizeof(ptpol_t)*(this->ncol));
89  this->nnz=this->ncol;
90  for(int i=0;i<this->ncol;i++)
91  {
92  this->rowind[i]=i;
93  this->colptr[i]=i;
94  ptpol_init(((ptpol_t*)this->nzval)[i]);
95  }
96  this->colptr[this->ncol]=this->nnz;
97 }
98 
99 void harewell_set_coeff(harewell<mpq_t> &mat,int i,int j, mpq_t coeff)
100 {
101  mpq_t zero;
102  mpq_init(zero);
103  int colbegin=mat.colptr[j],colend=(j+1<mat.ncol)?mat.colptr[j+1]:mat.nnz;
104  int t,carry=0;;
105  for(t=colbegin;(t<colend)&&(i!=(mat.rowind[t]));t++);
106  if (t>=colend) {t--;carry=1;};
107  if (mat.rowind[t]==i) // je suis tombe sur un coeff qui etait deja pas nul
108  {
109  if (mpq_cmp(coeff,zero))//super on ne vire rien on change un valeur!!!!
110  {
111  mpq_set(((mpq_t *)(mat.nzval))[t],coeff);
112  }
113  else//aie on vire un truc
114  {
115  if ((t==colbegin)&&(colend==colbegin+1))
116  mpq_set(((mpq_t *)(mat.nzval))[t],coeff);//on ne cree pas de colonnes de zeros!!!
117  else
118  {
119  //on ne cree jamais de colonnes de 0
120  //le formatNC ne les gerent pas!!!
121  memmove(((mpq_t*)(mat.nzval)+t)
122  ,((mpq_t*)(mat.nzval))+t+1,(mat.nnz-t-1)*sizeof(mpq_t));
123  memmove(((int*)(mat.rowind)+t),((int*)(mat.rowind))+t+1
124  ,(mat.nnz-t-1)*sizeof(int));
125  mat.nnz--;
126  //reglage des colptr
127  for(int k=j+1;k<mat.ncol;k++)
128  mat.colptr[k]--;
129  //reglage des nnz
130  mat.colptr[mat.ncol]=mat.nnz;
131  }
132  }
133  }
134  else//il faut creer la place pour le nouveau coeff
135  // il n'y a pas l'equivalent realloc en C++ !!!!!
136  if (!mpq_cmp(coeff,zero)) {}
137  else
138  {
139  mat.nnz++;
140  t+=carry;
141  //
142  //les champs dynamiques sont supposes alloues par malloc
143  //et pas par new!!!!!! c pour connexion avec super lu
144  // qui bricole sa memoire avec malloc
145  //
146  mpq_t* tmpnzval=(mpq_t*)malloc(sizeof(mpq_t)*(mat.nnz));
147  int *tmprowind=(int*)malloc(sizeof(int)*mat.nnz);
148  memcpy(((mpq_t*)(tmpnzval)),((mpq_t*)(mat.nzval)),(t)*sizeof(mpq_t));
149  memcpy(tmprowind,(mat.rowind),(t)*sizeof(int));
150  mpq_init(tmpnzval[t]);
151  mpq_set(tmpnzval[t],coeff);
152  tmprowind[t]=i;
153  if (t==colbegin) mat.colptr[j]=t;//on met a jour pour la nvlle valeur
154  for (int i=j+1;i<mat.ncol;i++)
155  mat.colptr[i]++;//il faut decaler les indices de 1
156  memcpy(((mpq_t*)(tmpnzval))+t+1,
157  ((mpq_t*)(mat.nzval))+t,(mat.nnz-t-1)*sizeof(mpq_t));
158  memcpy(tmprowind+t+1,mat.rowind+t,(mat.nnz-t-1)*sizeof(int));
159  //for (k=t;k<nnz-1;k++)
160  //{
161  // tmpnzval[k+1]=((T*)(nzval))[k];
162  // tmprowind[k+1]=rowind[k];
163  //};
164  free(mat.nzval);
165  mat.nzval=(void*)tmpnzval;
166  free(mat.rowind);
167  mat.rowind=tmprowind;
168  mat.colptr[mat.ncol]=mat.nnz;//le colptr[ncol] c nnz recopie pour
169  // usage interne a la lib apres.
170  }
171 }
172 
173 void harewell_set_coeff(harewell<ptpol_t> &mat,int i,int j, ptpol_t coeff)
174 {
175  int colbegin=mat.colptr[j],colend=(j+1<mat.ncol)?mat.colptr[j+1]:mat.nnz;
176  int t,carry=0;;
177  for(t=colbegin;(t<colend)&&(i!=(mat.rowind[t]));t++);
178  if (t>=colend) {t--;carry=1;};
179  if (mat.rowind[t]==i) // je suis tombe sur un coeff qui etait deja pas nul
180  {
181  //cout<<"je passe par la"<<endl;
182  //ptpol_out_str(stdout,coeff);
183  //cout<<endl<<"la comparaison "<<ptpol_cmp_ui(coeff,0)<<endl;
184  if (ptpol_cmp_ui(coeff,0))//super on ne vire rien on change un valeur!!!!
185  {
186  //cout<<"je fait un set"<<endl;
187  ptpol_set(((ptpol_t *)(mat.nzval))[t],coeff);
188  }
189  else//aie on vire un truc
190  {
191  if ((t==colbegin)&&(colend==colbegin+1))
192  ptpol_set(((ptpol_t *)(mat.nzval))[t],coeff);//on ne cree pas de colonnes de zeros!!!
193  else
194  {
195  //on ne cree jamais de colonnes de 0
196  //le formatNC ne les gerent pas!!!
197  memmove(((ptpol_t*)(mat.nzval)+t)
198  ,((ptpol_t*)(mat.nzval))+t+1,(mat.nnz-t-1)*sizeof(ptpol_t));
199  memmove(((int*)(mat.rowind)+t),((int*)(mat.rowind))+t+1
200  ,(mat.nnz-t-1)*sizeof(int));
201  mat.nnz--;
202  //reglage des colptr
203  for(int k=j+1;k<mat.ncol;k++)
204  mat.colptr[k]--;
205  //reglage des nnz
206  mat.colptr[mat.ncol]=mat.nnz;
207  }
208  }
209  }
210  else//il faut creer la place pour le nouveau coeff
211  // il n'y a pas l'equivalent realloc en C++ !!!!!
212  if (!ptpol_cmp_ui(coeff,0)) {}
213  else
214  {
215  mat.nnz++;
216  t+=carry;
217  //
218  //les champs dynamiques sont supposes alloues par malloc
219  //et pas par new!!!!!! c pour connexion avec super lu
220  // qui bricole sa memoire avec malloc
221  //
222  ptpol_t* tmpnzval=(ptpol_t*)malloc(sizeof(ptpol_t)*(mat.nnz));
223  int *tmprowind=(int*)malloc(sizeof(int)*mat.nnz);
224  memcpy(((ptpol_t*)(tmpnzval)),((ptpol_t*)(mat.nzval)),(t)*sizeof(ptpol_t));
225  memcpy(tmprowind,(mat.rowind),(t)*sizeof(int));
226  ptpol_init(tmpnzval[t]);
227  ptpol_set(tmpnzval[t],coeff);
228  tmprowind[t]=i;
229  if (t==colbegin) mat.colptr[j]=t;//on met a jour pour la nvlle valeur
230  for (int i=j+1;i<mat.ncol;i++)
231  mat.colptr[i]++;//il faut decaler les indices de 1
232  memcpy(((ptpol_t*)(tmpnzval))+t+1,
233  ((ptpol_t*)(mat.nzval))+t,(mat.nnz-t-1)*sizeof(ptpol_t));
234  memcpy(tmprowind+t+1,mat.rowind+t,(mat.nnz-t-1)*sizeof(int));
235  //for (k=t;k<nnz-1;k++)
236  //{
237  // tmpnzval[k+1]=((T*)(nzval))[k];
238  // tmprowind[k+1]=rowind[k];
239  //};
240  free(mat.nzval);
241  mat.nzval=(void*)tmpnzval;
242  free(mat.rowind);
243  mat.rowind=tmprowind;
244  mat.colptr[mat.ncol]=mat.nnz;//le colptr[ncol] c nnz recopie pour
245  // usage interne a la lib apres.
246  }
247 }
248 
249 void harwell_get_coeff(ptpol_t & res,const harewell<ptpol_t> & mat,
250  int i, int j)
251 {
252  int colbegin=mat.colptr[j]
253  ,colend=(j+1<mat.ncol)?mat.colptr[j+1]:mat.nnz;
254  int t;
255  // cout<<"colbeg "<<colbegin<<endl;
256  //cout<<"colend "<<colend<<endl;
257  for(t=colbegin;
258  (t<colend)
259  &&(i!=mat.rowind[t]);t++);
260  //cout<<mat.rowind[t]<<endl;
261  if (t>=colend) {ptpol_set_d(res,0);return;}
262  if (i==(mat.rowind[t]))
263  ptpol_set(res,(((ptpol_t*)(mat.nzval))[t]));
264  else
265  ptpol_set_d(res,0);
266 }
267 
268 void harwell_get_coeff(mpq_t & res,const harewell<mpq_t> & mat,
269  int i, int j)
270 {
271  int colbegin=mat.colptr[j]
272  ,colend=(j+1<mat.ncol)?mat.colptr[j+1]:mat.nnz;
273  int t;
274  for(t=colbegin;(t<colend)&&(i!=mat.rowind[t]);t++);
275  if (t>=colend)
276  {
277  mpq_set_d(res,0);
278  return;
279  }
280 
281  if (i==(mat.rowind[t]))
282  mpq_set(res,(((mpq_t*)(mat.nzval))[t]));
283  else
284  mpq_set_d(res,0);
285 }
286 void harwell_get_coeff(__mpq_struct *res,const harewell<__mpq_struct*> & mat,
287  int i, int j)
288 {
289  int colbegin=mat.colptr[j]
290  ,colend=(j+1<mat.ncol)?mat.colptr[j+1]:mat.nnz;
291  int t;
292  for(t=colbegin;(t<colend)&&(i!=mat.rowind[t]);t++);
293  if (t>=colend) mpq_set_d(res,0);
294  if (i==(mat.rowind[t]))
295  mpq_set(res,(((mpq_t*)(mat.nzval))[t]));
296  else
297  mpq_set_d(res,0);
298 }
299 
300 int Iszerop(const ptpol_t c)
301 {
302  return ptpol_isNull(c);
303 }
304 
305 void swapcol(harewell<ptpol_t> &m,int k, int l)
306 {
307  ptpol_t tmp,tmp2;
308  ptpol_init(tmp); ptpol_init(tmp2);
309  for(int i=0;i<m.nrow;i++)
310  {
311  harwell_get_coeff(tmp,m,i,k);
312  //cout<<"coeff lu"<<endl;
313  //ptpol_out_str(stdout,tmp);
314  //cout<<endl;
315  harwell_get_coeff(tmp2,m,i,l);
316  //cout<<"coeff lu2"<<endl;
317  //ptpol_out_str(stdout,tmp2);
318  //cout<<endl;
319  harewell_set_coeff(m,i,k,tmp2);
320  //cout<<"-------------"<<endl;
321  harewell_set_coeff(m,i,l,tmp);
322 
323  harwell_get_coeff(tmp,m,i,k);
324  //cout<<"coeff relu"<<endl;
325  //ptpol_out_str(stdout,tmp);
326  //cout<<endl;
327  //harwell_get_coeff(tmp2,m,i,l);
328  //cout<<"coeff relu2"<<endl;
329  //ptpol_out_str(stdout,tmp2);
330  //cout<<endl;
331 
332 }
333  ptpol_clear(tmp); ptpol_clear(tmp2);
334 }
335 
336 void swaprow(harewell<ptpol_t> &m,int k, int l)
337 {
338  ptpol_t tmp,tmp2;
339  ptpol_init(tmp); ptpol_init(tmp2);
340  for(int i=0;i<m.ncol;i++)
341  {
342  harwell_get_coeff(tmp,m,k,i);
343  harwell_get_coeff(tmp2,m,l,i);
344  harewell_set_coeff(m,k,i,tmp2);
345  harewell_set_coeff(m,l,i,tmp);
346  }
347  ptpol_clear(tmp); ptpol_clear(tmp2);
348 }
349 
350 template <typename typmat>
351 void Triang(typmat & M)
352 {
353  ptpol_t d,un,tmp,tmp2;
354  ptpol_init(d);
355  ptpol_init(tmp);
356  ptpol_init(tmp2);
357  ptpol_init(un);
358  ptpol_set_d(d,1);
359  ptpol_set_d(un,1);
360  int l,tmpl;
361  for(int k=0; k<M.nrow;k++)
362  {
363  //cout<<"la matrice ici"<<endl;
364  //printmatpol(M);
365  ptpol_set_d(tmp,0);
366  ptpol_set_d(tmp2,0);
367  for(l=k;(l<M.nrow);l++)
368  //for(l=k;(l>=0) && (Iszerop(tmp));l--)
369  {
370  harwell_get_coeff(tmp,M,l,k);
371  if (Iszerop(tmp2)
372  || ((!Iszerop(tmp)) && (tmp->degree<tmp2->degree)))
373  {
374  tmpl=l+1;
375  ptpol_set(tmp2,tmp);
376  }
377  //cout<<"valeur de tmp"<<endl;
378  //ptpol_out_str(stdout,tmp);
379  //cout<<" "<<Iszerop(tmp)<<endl;
380 
381  }
382  //l++;
383  l=tmpl;
384  ptpol_set(tmp,tmp2);
385  l--;
386  cout<<"mon pivot "<<l<<" et "<<k<<endl;
387  ptpol_out_str(stdout,tmp);cout<<endl;
388  swaprow(M,k,l);
389  //cout<<"la matrice apres swap"<<endl;
390  //printmatpol(M);
391  //ptpol_out_str(stdout,tmp);
392  //cout<<endl;
393 
394  if(l!=M.nrow){
395  //if(l!=-1){
396  if(k>0) harwell_get_coeff(d,M,k-1,k-1); //d=M(k-1,k-1);
397  //if(k<M.col-1) harwell_get_coeff(d,M,k-1,k-1); //d=M(k-1,k-1);
398  for(int i=k+1; i<M.nrow; i++)
399  //for(int i=k-1; i>=0; i--)
400  {
401  ptpol_t c;
402  ptpol_init(c);
403  harwell_get_coeff(c,M,i,k);
404  for(int j=k; j<M.ncol; j++)
405  //for(int j=k; j<M.nrow; j++)
406  {
407  //cout<<"i "<<i<<" j "<<j<<endl;
408  harwell_get_coeff(tmp,M,i,j);
409  harwell_get_coeff(tmp2,M,k,k);
410  ptpol_karatsuba_mul(tmp2,tmp,tmp2);
411  harwell_get_coeff(tmp,M,k,j);
412  ptpol_karatsuba_mul(tmp,tmp,c);
413  ptpol_sub(tmp2,tmp2,tmp);
414 
415 
416  //M(i,j)-=c*M(k,j);
417  if (!Iszerop(tmp2) && (!Iszerop(d)) && (ptpol_cmp(d, un)))
418  ptpol_div(tmp2,tmp2,d);
419  harewell_set_coeff(M,i,j,tmp2);
420  }
421  ptpol_clear(c);
422 
423  //M(i,k)=C(0);
424  }
425  }
426  }
427  ptpol_clear(tmp);
428  ptpol_clear(tmp2);
429  ptpol_clear(d);
430  ptpol_clear(un);
431 }
432 
433 template <typename typmat>
434 void Triangsave(typmat & M)
435 {
436  ptpol_t d,un,tmp,tmp2;
437  ptpol_init(d);
438  ptpol_init(tmp);
439  ptpol_init(tmp2);
440  ptpol_init(un);
441  ptpol_set_d(d,1);
442  ptpol_set_d(un,1);
443  int l;
444  for(int k=0; k<M.ncol;k++)
445  //for(int k=M.ncol-1; k>=0;k--)
446  {
447  //cout<<"la matrice ici"<<endl;
448  //printmatpol(M);
449  ptpol_set_d(tmp,0);
450  for(l=k;(l<M.ncol) && (Iszerop(tmp));l++)
451  //for(l=k;(l>=0) && (Iszerop(tmp));l--)
452  {
453  harwell_get_coeff(tmp,M,k,l);
454  //cout<<"valeur de tmp"<<endl;
455  //ptpol_out_str(stdout,tmp);
456  //cout<<" "<<Iszerop(tmp)<<endl;
457 
458  }
459  //l++;
460  l--;
461  //cout<<"mon pivot "<<l<<" et "<<k<<endl;
462  swapcol(M,k,l);
463  //cout<<"la matrice apres swap"<<endl;
464  //printmatpol(M);
465 
466  ptpol_out_str(stdout,tmp);
467  cout<<endl;
468  if(l!=M.ncol){
469  //if(l!=-1){
470  if(k>0) harwell_get_coeff(d,M,k-1,k-1); //d=M(k-1,k-1);
471  //if(k<M.col-1) harwell_get_coeff(d,M,k-1,k-1); //d=M(k-1,k-1);
472  for(int i=k+1; i<M.ncol; i++)
473  //for(int i=k-1; i>=0; i--)
474  {
475  ptpol_t c;
476  ptpol_init(c);
477  harwell_get_coeff(c,M,k,i);
478  for(int j=k; j<M.nrow; j++)
479  //for(int j=k; j<M.nrow; j++)
480  {
481  //cout<<"i "<<i<<" j "<<j<<endl;
482  harwell_get_coeff(tmp,M,j,i);
483  harwell_get_coeff(tmp2,M,k,k);
484  ptpol_karatsuba_mul(tmp2,tmp,tmp2);
485  harwell_get_coeff(tmp,M,j,k);
486  ptpol_karatsuba_mul(tmp,tmp,c);
487  ptpol_sub(tmp2,tmp2,tmp);
488 
489 
490  //M(i,j)-=c*M(k,j);
491  if (!Iszerop(tmp2) && (!Iszerop(d)) && (ptpol_cmp(d, un)))
492  ptpol_div(tmp2,tmp2,d);
493  harewell_set_coeff(M,j,i,tmp2);
494  }
495  ptpol_clear(c);
496 
497  //M(i,k)=C(0);
498  }
499  }
500  }
501  ptpol_clear(tmp);
502  ptpol_clear(tmp2);
503  ptpol_clear(d);
504  ptpol_clear(un);
505 }
506 
507 template<typename typmat, typename typsec>
508 void SolveUff_restricted(const typmat &mat, typsec &sec)
509 {
510  ptpol_t accu;
511  ptpol_init(accu);
512  ptpol_set_d(accu,1);
513  cout<<mat.ncol<<" "<<mat.nrow<<endl;
514  for(int i=mat.nrow-2;i>=0;i--)
515  {
516  int j;
517 
518  cout<<"je tourne la "<<i<<endl;
519  //la matrice est permutee par rapport a la forme
520  //triangulaire sup
521  ptpol_t tmp;
522  ptpol_init(tmp);
523  for(j=0;(j<(mat.ncol-1)) && Iszerop(tmp);j++)
524  {
525  harwell_get_coeff(tmp,mat,i,j);
526  //cout<<"valeur de tmp"<<endl;
527  //ptpol_out_str(stdout,tmp);
528  //cout<<" "<<Iszerop(tmp)<<endl;
529  }
530  j--;
531  //cout<<"j vaut "<<j<<" "<<mat.ncol<<endl;
532  if(j==mat.ncol-1)
533  {
534  cout<<"Merde a la ligne "<<i<<endl;
535  exit(10);
536  }
537  for(int k=0;k<mat.nrow-1;k++)
538  {
539  //cout<<"ici"<<endl;
540  //harwell_get_coeff(tmp,mat,k,j);
541  if(k!=i)
542  ptpol_karatsuba_mul(sec[k],sec[k],tmp);
543 #if 0
544  ptpol_div_r(accu,sec[k],sec[mat.nrow-1]);
545  cout<<endl<<"valeur de accu"<<endl;
546  ptpol_out_str(stdout,accu);
547  cout<<" "<<endl;
548  cout<<"valeur de scxe[k]"<<endl;
549  ptpol_out_str(stdout,sec[k]);
550  cout<<" "<<endl;
551  cout<<"valeur de charpoly"<<endl;
552  ptpol_out_str(stdout,sec[mat.nrow-1]);
553  cout<<" "<<endl;
554 #endif
555  ptpol_div_r(sec[k],sec[k],sec[mat.nrow-1]);
556  //cout<<"apres mul"<<endl;
557  //if(!Iszerop(accu))
558  // ptpol_div(sec[k],sec[k],accu);
559  }
560  //harwell_get_coeff(accu,mat,i,j);
561  for(int k=i-1;k>=0;k--)
562  {
563  // cout<<"la"<<endl;
564  harwell_get_coeff(tmp,mat,k,j);
565  ptpol_karatsuba_mul(tmp,sec[i],tmp);
566  //ptpol_div_r(sec[k],sec[k],sec[mat.nrow-1]);
567  ptpol_sub(sec[k],sec[k],tmp);//sec[k]-=sec[i]*mat(k,j);
568  }
569  ptpol_clear(tmp);
570  }
571 }
572 
573 template<typename typmat, typename typsec>
574 void SolveUff_restrictedsave(const typmat &mat, typsec &sec)
575 {
576  ptpol_t accu;
577  ptpol_init(accu);
578  ptpol_set_d(accu,1);
579  for(int i=1;i<mat.nrow;i++)
580  {
581  int j;
582 
583  cout<<"je tourne la"<<endl;
584  //la matrice est permutee par rapport a la forme
585  //triangulaire sup
586  ptpol_t tmp;
587  ptpol_init(tmp);
588  for(j=mat.ncol-1;j>=0 && Iszerop(tmp);j--)
589  {
590  harwell_get_coeff(tmp,mat,i,j);
591  //cout<<"valeur de tmp"<<endl;
592  // ptpol_out_str(stdout,tmp);
593  // cout<<" "<<Iszerop(tmp)<<endl;
594  }
595  if(j==-1)
596  {
597  cout<<"Merde a la ligne "<<i<<endl;
598  exit(10);
599  }
600  for(int k=i;k<mat.nrow;k++)
601  {
602  //cout<<"ici"<<endl;
603  //harwell_get_coeff(tmp,mat,k,j);
604  ptpol_karatsuba_mul(sec[k],sec[k],tmp);
605  //cout<<"apres mul"<<endl;
606  if(!Iszerop(accu))
607  ptpol_div(sec[k],sec[k],accu);
608  }
609  harwell_get_coeff(accu,mat,i,j);
610  for(int k=i+1;k<mat.nrow;k++)
611  {
612  // cout<<"la"<<endl;
613  harwell_get_coeff(tmp,mat,k,j);
614  ptpol_karatsuba_mul(tmp,sec[i-1],tmp);
615  ptpol_sub(sec[k-1],sec[k-1],tmp);//sec[k]-=sec[i]*mat(k,j);
616 
617  }
618  ptpol_clear(tmp);
619  }
620 }
621 
622 void printmatpol(harewell<ptpol_t> &m)
623 {
624  int i;
625  ptpol_t tmp;
626  ptpol_init(tmp);
627  cout<<"nrow "<<m.nrow<<" ncol "<<m.ncol<<endl;
628  cout<<"[";
629  for(i=0;i<m.nrow-1;i++)
630  {
631  int j;
632  cout<<"[";
633  for(j=0;j<m.ncol-1;j++)
634  {
635  harwell_get_coeff(tmp,m,i,j); ptpol_out_str(stdout,tmp);
636  cout<<",";
637  }
638  harwell_get_coeff(tmp,m,i,j);
639  ptpol_out_str(stdout,tmp);
640  cout<<"],"<<endl;
641  }
642  {
643  int j;
644  cout<<"[";
645  for(j=0;j<m.ncol-1;j++)
646  {
647  harwell_get_coeff(tmp,m,i,j);
648  ptpol_out_str(stdout,tmp);
649  cout<<",";
650  }
651  harwell_get_coeff(tmp,m,i,j);
652  ptpol_out_str(stdout,tmp);
653  cout<<"]"<<endl;
654  }
655  cout<<"]"<<endl;
656  ptpol_clear(tmp);
657 }
658 
659 template<typename typmat, typename typres, typename typmon
660  , typename typdump, typename Base>
661 void symbo(typres &res, const list<typmat> &lmat, const typmon &stockmon
662  ,const typdump &dump, const Base &b)
663 {
664  typedef typename typdump::value_type::pol_t mpoly;
665  typedef typename mpoly::coeff_t coeff;
666  ptpol_t pol_x;
667  ptpol_t *secmembre;
668  int stockcol;
669  int coldim=lmat.front().nrow,rowdim=lmat.front().ncol;
670  harewell<ptpol_t> combilin(coldim,rowdim),Xid(coldim,rowdim);
671  ptpol_init(pol_x);
672  ptpol_set_d(pol_x,1);
673  ptpol_mulvar(pol_x,pol_x,1);
674  cout<<"debut symbo"<<endl;
675  for(typename list<typmat>::const_iterator itercomb=lmat.begin()
676  ;itercomb!=lmat.end();itercomb++)
677  {
678  COEFF tmpcoeff,tmpcoeff2;
679  ptpol_t tmp,tmp2;
680  gen_init(tmpcoeff); gen_init(tmpcoeff2);
681  gen_set_d(tmpcoeff2,rand()%32051);
682  ptpol_init(tmp);ptpol_init(tmp2);
683  for(int i=0;i<combilin.nrow;i++)
684  for(int j=0;j<combilin.ncol;j++)
685  {
686  harwell_get_coeff(tmpcoeff,*itercomb,i,j);
687  gen_mul(tmpcoeff,tmpcoeff,tmpcoeff2);
688 
689  harwell_get_coeff(tmp,combilin,i,j);
690  ptpol_set_coeff(tmp2,tmpcoeff);
691 
692  ptpol_add(tmp,tmp,tmp2);
693  harewell_set_coeff(combilin,i,j,tmp);
694  // combilin(i,j,combilin(i,j)
695  // +UPolyDense<upar<coeff> >(coeff(rand()%13)
696  // *((*itercomb)(i,j)),0));
697  }
698  gen_clear(tmpcoeff);gen_clear(tmpcoeff2);
699  ptpol_clear(tmp);
700  ptpol_clear(tmp2);
701  }
702  for(int i=0;i<Xid.nrow;i++)
703  {
704  ptpol_t tmp;
705  ptpol_init(tmp);
706  harwell_get_coeff(tmp,combilin,i,i);
707  ptpol_sub(tmp,tmp,pol_x);
708  harewell_set_coeff(combilin,i,i,tmp);
709  ptpol_clear(tmp);
710  }
711  //cout<<combilin.nnz<<endl;
712  // for(int i=0;i<combilin.ncol;i++)
713  //cout<<"colptr "<<i<<" "<<combilin.colptr[i]<<endl;
714  cout<<"combilin"<<endl;
715  printmatpol(combilin);
716  Triang(combilin);
717  cout<<"apres triang"<<endl;
718  printmatpol(combilin);
719  //for(int i=0;i<combilin.ncol;i++)
720  //
721  // for(int j=i;j<combilin.ncol;j++)
722  //{
723  // harwell_get_coeff(pol_x,combilin,i,j);
724  // ptpol_out_str(stdout,pol_x);
725  // printf("\n");
726  // }
727  harwell_get_coeff(res[b.nbvar()],combilin,combilin.nrow-1,combilin.ncol-1);
728  secmembre=(ptpol_t*)malloc((combilin.nrow)*sizeof(ptpol_t));
729  for(int i=0;i<combilin.nrow;i++)
730  ptpol_init(secmembre[i]);
731  for(stockcol=0;Iszerop(secmembre[0]);stockcol++)
732  harwell_get_coeff(secmembre[0],combilin,combilin.nrow-1,stockcol);
733  stockcol--;
734  cout<<"stockcol "<<stockcol<<endl;
735  for(int i=0;i<combilin.nrow;i++)
736  {
737  harwell_get_coeff(secmembre[i],combilin,i,stockcol);
738  }
739 #if 0
740  printf("\navant------------------\n");
741  for(int j=0;j<combilin.nrow-1;j++)
742  {
743  ptpol_out_str(stdout,secmembre[j]);
744  printf("\n------------------\n");
745  }
746 #endif
747  //combilin.ncol--;
748  //combilin.nrow--;
749  SolveUff_restricted(combilin,secmembre);
750 #if 0
751  printf("\napres------------------\n");
752  for(int j=0;j<combilin.nrow-1;j++)
753  {
754  ptpol_out_str(stdout,secmembre[j]);
755  printf("\n------------------\n");
756  }
757 #endif
758  ptpol_out_str(stdout,secmembre[combilin.nrow-1]);
759  printf("\n------------------\n");
760  for(int i=0;i<b.nbvar();i++)
761  {
762  mpoly tmp;
763  tmp.size=-1;
764  int j=0;
765  findcorresppol(mon(i,1),dump,tmp);
766  for(typename typmon::const_iterator iter=stockmon.begin()
767  ;*iter!=mon(i,1) && iter!=stockmon.end();j++,iter++);
768  if (tmp.size == -1)
769  {
770  *res[i]=*secmembre[j];
771  cout<<"je trouve x"<<i<<" a la position "<<j<<endl;
772  }
773  else
774  {
775  cout<<"je ne trouve pas x"<<i<<" a la position "<<j<<endl;
776  *res[i]=*pol_x;
777  }
778  }
779  *res[b.nbvar()]=*secmembre[0];
780  ptpol_out_str(stdout, res[b.nbvar()]);
781  printf("ttttttttttttttttttttt\n");
782 }
783 #ifdef OLD_COEFF
784 
785 //#undef COEFF
786 #define COEFF toto(OLD_COEFF)
787 #endif
void Triang(typmat &M)
Definition: symbo2.hpp:351
void printmatpol(harewell< ptpol_t > &m)
Definition: symbo2.hpp:622
void free(void *)
void Triangsave(typmat &M)
Definition: symbo2.hpp:434
void findcorresppol(const mon &m, const typdump &dump, pol &res)
Definition: corealgo.hpp:2031
void swaprow(harewell< ptpol_t > &m, int k, int l)
Definition: symbo2.hpp:336
OLD_COEFF machin
Definition: symbo2.hpp:7
void * malloc(YYSIZE_T)
void SolveUff_restricted(const typmat &mat, typsec &sec)
Definition: symbo2.hpp:508
int nbvar()
Definition: types.hpp:37
MSKconetypee MSKrealt MSKint32t MSKint32t j
Definition: mosek.h:2421
MSKint32t k
Definition: mosek.h:2713
void harwell_get_coeff(ptpol_t &res, const harewell< ptpol_t > &mat, int i, int j)
Definition: symbo2.hpp:249
Mon mon
Definition: solver_bb_floating.cpp:136
void SolveUff_restrictedsave(const typmat &mat, typsec &sec)
Definition: symbo2.hpp:574
Definition: types.hpp:14
MSKrealt * c
Definition: mosek.h:2678
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
void symbo(typres &res, const list< typmat > &lmat, const typmon &stockmon, const typdump &dump, const Base &b)
Definition: symbo2.hpp:661
#define COEFF
Definition: symbo2.hpp:8
void swapcol(harewell< ptpol_t > &m, int k, int l)
Definition: symbo2.hpp:305
int Iszerop(const ptpol_t c)
Definition: symbo2.hpp:300
void harewell_set_coeff(harewell< mpq_t > &mat, int i, int j, mpq_t coeff)
Definition: symbo2.hpp:99
Home  |  Download & InstallContributions