3 #define toto(a) tutu(a)
4 #define OLD_COEFF toto(COEFF)
13 mpq_t &harewell<mpq_t>::operator() (
const int &
i,
const int &
j,
const mpq_t &d)
15 cout<<
"Nein Nein!!!!!!!!!!!"<<endl;
21 ptpol_t &harewell<ptpol_t>::operator() (
const int &
i,
const int &
j,
const ptpol_t &d)
23 cout<<
"Nein Nein!!!!!!!!!!!"<<endl;
29 mpq_t & harewell<mpq_t>::operator() (
const int &
i,
const int &
j)
32 cout<<
"Nein!!!!!!!!!!!"<<endl;
34 int colbegin=colptr[
j]
35 ,colend=(j+1<this->ncol)?colptr[j+1]:nnz;
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);
45 ptpol_t & harewell<ptpol_t>::operator() (
const int &i,
const int &j)
48 cout<<
"Nein!!!!!!!!!!!"<<endl;
50 int colbegin=colptr[
j]
51 ,colend=(j+1<this->ncol)?colptr[j+1]:nnz;
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);
61 harewell<mpq_t>::harewell(
const int nrow,
const int 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));
70 for(
int i=0;i<this->ncol;i++)
74 mpq_init(((mpq_t*)this->nzval)[i]);
76 this->colptr[this->ncol]=this->nnz;
81 harewell<ptpol_t>::harewell(
const int nrow,
const int 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));
90 for(
int i=0;i<this->ncol;i++)
94 ptpol_init(((ptpol_t*)this->nzval)[i]);
96 this->colptr[this->ncol]=this->nnz;
103 int colbegin=mat.colptr[
j],colend=(j+1<mat.ncol)?mat.colptr[j+1]:mat.nnz;
105 for(t=colbegin;(t<colend)&&(i!=(mat.rowind[t]));t++);
106 if (t>=colend) {t--;carry=1;};
107 if (mat.rowind[t]==i)
109 if (mpq_cmp(coeff,zero))
111 mpq_set(((mpq_t *)(mat.nzval))[t],coeff);
115 if ((t==colbegin)&&(colend==colbegin+1))
116 mpq_set(((mpq_t *)(mat.nzval))[t],coeff);
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));
127 for(
int k=j+1;
k<mat.ncol;
k++)
130 mat.colptr[mat.ncol]=mat.nnz;
136 if (!mpq_cmp(coeff,zero)) {}
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);
153 if (t==colbegin) mat.colptr[
j]=t;
154 for (
int i=j+1;i<mat.ncol;i++)
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));
165 mat.nzval=(
void*)tmpnzval;
167 mat.rowind=tmprowind;
168 mat.colptr[mat.ncol]=mat.nnz;
175 int colbegin=mat.colptr[
j],colend=(j+1<mat.ncol)?mat.colptr[j+1]:mat.nnz;
177 for(t=colbegin;(t<colend)&&(i!=(mat.rowind[t]));t++);
178 if (t>=colend) {t--;carry=1;};
179 if (mat.rowind[t]==i)
184 if (ptpol_cmp_ui(coeff,0))
187 ptpol_set(((ptpol_t *)(mat.nzval))[t],coeff);
191 if ((t==colbegin)&&(colend==colbegin+1))
192 ptpol_set(((ptpol_t *)(mat.nzval))[t],coeff);
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));
203 for(
int k=j+1;
k<mat.ncol;
k++)
206 mat.colptr[mat.ncol]=mat.nnz;
212 if (!ptpol_cmp_ui(coeff,0)) {}
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);
229 if (t==colbegin) mat.colptr[
j]=t;
230 for (
int i=j+1;i<mat.ncol;i++)
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));
241 mat.nzval=(
void*)tmpnzval;
243 mat.rowind=tmprowind;
244 mat.colptr[mat.ncol]=mat.nnz;
252 int colbegin=mat.colptr[
j]
253 ,colend=(j+1<mat.ncol)?mat.colptr[j+1]:mat.nnz;
259 &&(i!=mat.rowind[t]);t++);
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]));
271 int colbegin=mat.colptr[
j]
272 ,colend=(j+1<mat.ncol)?mat.colptr[j+1]:mat.nnz;
274 for(t=colbegin;(t<colend)&&(i!=mat.rowind[t]);t++);
281 if (i==(mat.rowind[t]))
282 mpq_set(res,(((mpq_t*)(mat.nzval))[t]));
289 int colbegin=mat.colptr[
j]
290 ,colend=(j+1<mat.ncol)?mat.colptr[j+1]:mat.nnz;
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]));
302 return ptpol_isNull(c);
308 ptpol_init(tmp); ptpol_init(tmp2);
309 for(
int i=0;i<m.nrow;i++)
333 ptpol_clear(tmp); ptpol_clear(tmp2);
339 ptpol_init(tmp); ptpol_init(tmp2);
340 for(
int i=0;i<m.ncol;i++)
347 ptpol_clear(tmp); ptpol_clear(tmp2);
350 template <
typename typmat>
353 ptpol_t d,un,tmp,tmp2;
361 for(
int k=0;
k<M.nrow;
k++)
367 for(l=
k;(l<M.nrow);l++)
372 || ((!
Iszerop(tmp)) && (tmp->degree<tmp2->degree)))
386 cout<<
"mon pivot "<<l<<
" et "<<
k<<endl;
387 ptpol_out_str(stdout,tmp);cout<<endl;
398 for(
int i=
k+1; i<M.nrow; i++)
404 for(
int j=
k; j<M.ncol; j++)
410 ptpol_karatsuba_mul(tmp2,tmp,tmp2);
412 ptpol_karatsuba_mul(tmp,tmp,c);
413 ptpol_sub(tmp2,tmp2,tmp);
418 ptpol_div(tmp2,tmp2,d);
433 template <
typename typmat>
436 ptpol_t d,un,tmp,tmp2;
444 for(
int k=0;
k<M.ncol;
k++)
450 for(l=
k;(l<M.ncol) && (
Iszerop(tmp));l++)
466 ptpol_out_str(stdout,tmp);
472 for(
int i=
k+1; i<M.ncol; i++)
478 for(
int j=
k; j<M.nrow; j++)
484 ptpol_karatsuba_mul(tmp2,tmp,tmp2);
486 ptpol_karatsuba_mul(tmp,tmp,c);
487 ptpol_sub(tmp2,tmp2,tmp);
492 ptpol_div(tmp2,tmp2,d);
507 template<
typename typmat,
typename typsec>
513 cout<<mat.ncol<<
" "<<mat.nrow<<endl;
514 for(
int i=mat.nrow-2;i>=0;i--)
518 cout<<
"je tourne la "<<i<<endl;
523 for(j=0;(j<(mat.ncol-1)) &&
Iszerop(tmp);j++)
534 cout<<
"Merde a la ligne "<<i<<endl;
537 for(
int k=0;
k<mat.nrow-1;
k++)
542 ptpol_karatsuba_mul(sec[
k],sec[k],tmp);
544 ptpol_div_r(accu,sec[k],sec[mat.nrow-1]);
545 cout<<endl<<
"valeur de accu"<<endl;
546 ptpol_out_str(stdout,accu);
548 cout<<
"valeur de scxe[k]"<<endl;
549 ptpol_out_str(stdout,sec[k]);
551 cout<<
"valeur de charpoly"<<endl;
552 ptpol_out_str(stdout,sec[mat.nrow-1]);
555 ptpol_div_r(sec[k],sec[k],sec[mat.nrow-1]);
561 for(
int k=i-1;
k>=0;
k--)
565 ptpol_karatsuba_mul(tmp,sec[i],tmp);
567 ptpol_sub(sec[
k],sec[k],tmp);
573 template<
typename typmat,
typename typsec>
579 for(
int i=1;i<mat.nrow;i++)
583 cout<<
"je tourne la"<<endl;
588 for(j=mat.ncol-1;j>=0 &&
Iszerop(tmp);j--)
597 cout<<
"Merde a la ligne "<<i<<endl;
600 for(
int k=i;
k<mat.nrow;
k++)
604 ptpol_karatsuba_mul(sec[
k],sec[k],tmp);
607 ptpol_div(sec[k],sec[k],accu);
610 for(
int k=i+1;
k<mat.nrow;
k++)
614 ptpol_karatsuba_mul(tmp,sec[i-1],tmp);
615 ptpol_sub(sec[
k-1],sec[
k-1],tmp);
627 cout<<
"nrow "<<m.nrow<<
" ncol "<<m.ncol<<endl;
629 for(i=0;i<m.nrow-1;i++)
633 for(j=0;j<m.ncol-1;j++)
639 ptpol_out_str(stdout,tmp);
645 for(j=0;j<m.ncol-1;j++)
648 ptpol_out_str(stdout,tmp);
652 ptpol_out_str(stdout,tmp);
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)
664 typedef typename typdump::value_type::pol_t mpoly;
665 typedef typename mpoly::coeff_t coeff;
669 int coldim=lmat.front().nrow,rowdim=lmat.front().ncol;
670 harewell<ptpol_t> combilin(coldim,rowdim),Xid(coldim,rowdim);
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++)
678 COEFF tmpcoeff,tmpcoeff2;
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++)
687 gen_mul(tmpcoeff,tmpcoeff,tmpcoeff2);
690 ptpol_set_coeff(tmp2,tmpcoeff);
692 ptpol_add(tmp,tmp,tmp2);
698 gen_clear(tmpcoeff);gen_clear(tmpcoeff2);
702 for(
int i=0;i<Xid.nrow;i++)
707 ptpol_sub(tmp,tmp,pol_x);
714 cout<<
"combilin"<<endl;
717 cout<<
"apres triang"<<endl;
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++)
734 cout<<
"stockcol "<<stockcol<<endl;
735 for(
int i=0;i<combilin.nrow;i++)
740 printf(
"\navant------------------\n");
741 for(
int j=0;j<combilin.nrow-1;j++)
743 ptpol_out_str(stdout,secmembre[j]);
744 printf(
"\n------------------\n");
751 printf(
"\napres------------------\n");
752 for(
int j=0;j<combilin.nrow-1;j++)
754 ptpol_out_str(stdout,secmembre[j]);
755 printf(
"\n------------------\n");
758 ptpol_out_str(stdout,secmembre[combilin.nrow-1]);
759 printf(
"\n------------------\n");
760 for(
int i=0;i<b.
nbvar();i++)
766 for(
typename typmon::const_iterator iter=stockmon.begin()
767 ;*iter!=
mon(i,1) && iter!=stockmon.end();j++,iter++);
770 *res[
i]=*secmembre[
j];
771 cout<<
"je trouve x"<<i<<
" a la position "<<j<<endl;
775 cout<<
"je ne trouve pas x"<<i<<
" a la position "<<j<<endl;
779 *res[b.
nbvar()]=*secmembre[0];
780 ptpol_out_str(stdout, res[b.
nbvar()]);
781 printf(
"ttttttttttttttttttttt\n");
786 #define COEFF toto(OLD_COEFF)
void Triang(typmat &M)
Definition: symbo2.hpp:351
void printmatpol(harewell< ptpol_t > &m)
Definition: symbo2.hpp:622
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 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
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