00001 #ifndef ALREADY_io
00002 #define ALREADY_io
00003
00004 #include "borderbasix/mpoly/lex.yy.c"
00005 #include<stdio.h>
00006 #include<iostream>
00007 #include<iomanip>
00008
00009 template<typename typmat>
00010 void affdebug2(const typmat &m)
00011 {
00012 cout<<"[";
00013 for(int i=0;i<m.nrow;i++)
00014 {
00015 cout<<"[";
00016 for(int j=0;j<m.ncol-1;j++)
00017 {
00018 if (m(i,j)!=0) {printf("*");}
00019 else {printf(" ");}
00020 }
00021
00022 printf("]\n");
00023 }
00024 cout<<"]"<<endl;
00025 }
00026 template<typename typmat>
00027 void affdebug(const typmat &m)
00028 {
00029 int i;
00030 cout<<setprecision(6);
00031 cout<<"nrow "<<m.nrow<<" ncol "<<m.ncol<<endl;
00032 cout<<"[";
00033 for(i=0;i<m.nrow-1;i++)
00034 {
00035 int j;
00036 cout<<"[";
00037 for(j=0;j<m.ncol-1;j++)
00038 {
00039
00040 cout<<m(i,j)<<",";
00041 }
00042 cout<<m(i,j)<<"],"<<endl;
00043 }
00044 {
00045 int j;
00046 cout<<"[";
00047 for(j=0;j<m.ncol-1;j++)
00048 cout<<m(i,j)<<",";
00049 cout<<m(i,j)<<"]"<<endl;
00050 }
00051 cout<<"]"<<endl<<setprecision(16);
00052 }
00053
00054 template<template<typename T> class typmat,typename toto >
00055 void printmatfile(const typmat<toto> & m,const char * name,FILE * fic)
00056 {}
00057 #define _COMPLEX_
00058 #ifdef _COMPLEX_
00059 #include<complex>
00060 template<template<typename T> class typmat >
00061 void printmatfile(const typmat<complex<double> > & m,const char * name,FILE * fic)
00062 {int i;
00063 fprintf(fic,"%s:=[",name);
00064 for(i=0;i<m.nrow-1;i++)
00065 {
00066 int j;
00067 fprintf(fic,"[");
00068 for(j=0;j<m.ncol-1;j++)
00069 {
00070 fprintf(fic,"%.16f+(%.16f)*I,",m(i,j).real(),m(i,j).imag());
00071 }
00072
00073 fprintf(fic,"%.16f+(%.16f)*I],\n",m(i,j).real(),m(i,j).imag());
00074 }
00075 {
00076 int j;
00077 fprintf(fic,"[");
00078 for(j=0;j<m.ncol-1;j++)
00079 {
00080
00081 fprintf(fic,"%.16f+(%.16f)*I,",m(i,j).real(),m(i,j).imag());
00082 }
00083
00084 fprintf(fic,"%.16f+(%.16f)*I]\n];\n",m(i,j).real(),m(i,j).imag());
00085 }
00086 }
00087
00088 template<template<typename T> class typmat >
00089 void printmatfile(const typmat<complex<long double> > & m,const char * name,
00090 FILE * fic)
00091 {int i;
00092 if(m.nrow==0) return;
00093 fprintf(fic,"%s:=[",name);
00094 for(i=0;i<m.nrow-1;i++)
00095 {
00096 int j;
00097 fprintf(fic,"[");
00098 for(j=0;j<m.ncol-1;j++)
00099 {
00100 fprintf(fic,"%.16Lf+(%.16Lf)*I,",m(i,j).real(),m(i,j).imag());
00101 }
00102
00103 fprintf(fic,"%.16Lf+(%.16Lf)*I],\n",m(i,j).real(),m(i,j).imag());
00104 }
00105 {
00106 int j;
00107 fprintf(fic,"[");
00108 for(j=0;j<m.ncol-1;j++)
00109 {
00110
00111 fprintf(fic,"%.16Lf+(%.16Lf)*I,",m(i,j).real(),m(i,j).imag());
00112 }
00113
00114 fprintf(fic,"%.16Lf+(%.16Lf)*I]\n];\n",m(i,j).real(),m(i,j).imag());
00115 }
00116 }
00117
00118 template<template<typename T> class typmat >
00119 void printmatfile(const typmat<complex<RR> > & m,const char * name,FILE * fic)
00120 {
00121 int i;
00122 fprintf(fic,"%s:=[",name);
00123 for(i=0;i<m.nrow-1;i++)
00124 {
00125 int j;
00126 fprintf(fic,"[");
00127 for(j=0;j<m.ncol-1;j++)
00128 {
00129 mpf_out_str(fic,10,NBDIGITS,m(i,j).real().rep());
00130 fprintf(fic,"+I*(");
00131 mpf_out_str(fic,10,NBDIGITS,m(i,j).imag().rep());
00132 fprintf(fic,"),");
00133 }
00134
00135 mpf_out_str(fic,10,NBDIGITS,(m(i,j).real().rep()));
00136 fprintf(fic,"+I*(");
00137 mpf_out_str(fic,10,NBDIGITS,m(i,j).imag().rep());
00138 fprintf(fic,")],");
00139
00140
00141 }
00142 {
00143 int j;
00144 fprintf(fic,"[");
00145 for(j=0;j<m.ncol-1;j++)
00146 {
00147
00148 mpf_out_str(fic,10,NBDIGITS,(m(i,j).real().rep()));
00149 fprintf(fic,"+I*(");
00150 mpf_out_str(fic,10,NBDIGITS,m(i,j).imag().rep());
00151 fprintf(fic,"),");
00152
00153
00154 }
00155
00156
00157 mpf_out_str(fic,10,NBDIGITS,(m(i,j).real().rep()));
00158 fprintf(fic,"+I*(");
00159 mpf_out_str(fic,10,NBDIGITS,m(i,j).imag().rep());
00160 fprintf(fic,")]\n];\n");
00161
00162 }
00163 }
00164
00165 template<template<typename T> class typmat >
00166 void printmatfilescilab(const typmat<complex<double> > & m,const char * name,FILE * fic)
00167 {int i;
00168 fprintf(fic,"%s=[",name);
00169 for(i=0;i<m.nrow-1;i++)
00170 {
00171 int j;
00172 fprintf(fic,"");
00173 for(j=0;j<m.ncol-1;j++)
00174 {
00175 fprintf(fic,"%.16e+(%.16e)*I,",m(i,j).real(),m(i,j).imag());
00176 }
00177
00178 fprintf(fic,"%.16e+(%.16e)*I;\n",m(i,j).real(),m(i,j).imag());
00179 }
00180 {
00181 int j;
00182 fprintf(fic,"");
00183 for(j=0;j<m.ncol-1;j++)
00184 {
00185
00186 fprintf(fic,"%.16e+(%.16e)*I,",m(i,j).real(),m(i,j).imag());
00187 }
00188
00189 fprintf(fic,"%.16e+(%.16e)*I\n];\n",m(i,j).real(),m(i,j).imag());
00190 }
00191 }
00192
00193 template<template<typename T> class typmat >
00194 void printmatfilescilab(const typmat<complex<long double> > & m,const char * name,FILE * fic)
00195 {int i;
00196 fprintf(fic,"%s=[",name);
00197 for(i=0;i<m.nrow-1;i++)
00198 {
00199 int j;
00200 fprintf(fic,"");
00201 for(j=0;j<m.ncol-1;j++)
00202 {
00203 fprintf(fic,"%.32Le+(%.32Le)*I,",m(i,j).real(),m(i,j).imag());
00204 }
00205
00206 fprintf(fic,"%.32Le+(%.32Le)*I;\n",m(i,j).real(),m(i,j).imag());
00207 }
00208 {
00209 int j;
00210 fprintf(fic,"");
00211 for(j=0;j<m.ncol-1;j++)
00212 {
00213
00214 fprintf(fic,"%.32Le+(%.32Le)*I,",m(i,j).real(),m(i,j).imag());
00215 }
00216
00217 fprintf(fic,"%.32Le+(%.32Le)*I\n];\n",m(i,j).real(),m(i,j).imag());
00218 }
00219 }
00220 #endif
00221
00222 template<template<typename T> class typmat >
00223 void printmatfile(const typmat<double> & m,const char * name,FILE * fic)
00224 {
00225 int i;
00226 fprintf(fic,"%s:=[",name);
00227 for(i=0;i<m.nrow-1;i++)
00228 {
00229 int j;
00230 fprintf(fic,"[");
00231 for(j=0;j<m.ncol-1;j++)
00232 {
00233 fprintf(fic,"%.16f,",m(i,j));
00234 }
00235
00236 fprintf(fic,"%.16f],\n",m(i,j));
00237 }
00238 {
00239 int j;
00240 fprintf(fic,"[");
00241 for(j=0;j<m.ncol-1;j++)
00242 {
00243
00244 fprintf(fic,"%.16f,",m(i,j));
00245 }
00246
00247 fprintf(fic,"%.16f]\n];\n",m(i,j));
00248 }
00249 }
00250
00251 template<template<typename T> class typmat >
00252 void printmatfile(const typmat<long double> & m,const char * name,FILE * fic)
00253 {
00254 int i;
00255 fprintf(fic,"%s:=[",name);
00256 for(i=0;i<m.nrow-1;i++)
00257 {
00258 int j;
00259 fprintf(fic,"[");
00260 for(j=0;j<m.ncol-1;j++)
00261 {
00262 fprintf(fic,"%.16Lf,",m(i,j));
00263 }
00264
00265 fprintf(fic,"%.16Lf],\n",m(i,j));
00266 }
00267 {
00268 int j;
00269 fprintf(fic,"[");
00270 for(j=0;j<m.ncol-1;j++)
00271 {
00272
00273 fprintf(fic,"%.16Lf,",m(i,j));
00274 }
00275
00276 fprintf(fic,"%.16Lf]\n];\n",m(i,j));
00277 }
00278 }
00279
00280 #ifdef MON_PREMIER
00281 template<template<typename T> class typmat ,typename TT>
00282 void printmatfile(const typmat<Z<MON_PREMIER,TT> > & m,const char * name,FILE * fic)
00283 {
00284 int i;
00285 fprintf(fic,"%s:=[",name);
00286 for(i=0;i<m.nrow-1;i++)
00287 {
00288 int j;
00289 fprintf(fic,"[");
00290 for(j=0;j<m.ncol-1;j++)
00291 {
00292 fprintf(fic,"%d,",m(i,j).rep);
00293 }
00294
00295 fprintf(fic,"%d],\n",m(i,j).rep);
00296 }
00297 {
00298 int j;
00299 fprintf(fic,"[");
00300 for(j=0;j<m.ncol-1;j++)
00301 {
00302
00303 fprintf(fic,"%d,",m(i,j).rep);
00304 }
00305
00306 fprintf(fic,"%d]\n];\n",m(i,j).rep);
00307 }
00308 }
00309 #endif
00310
00311 template<template<typename T> class typmat >
00312 void printmatfile(const typmat<Scl<MPQ> > & m,const char * name,FILE * fic)
00313 {
00314 int i;
00315 fprintf(fic,"%s:=[",name);
00316 for(i=0;i<m.nrow-1;i++)
00317 {
00318 int j;
00319 fprintf(fic,"[");
00320 for(j=0;j<m.ncol-1;j++)
00321 {
00322 mpq_out_str(fic,10,&(m(i,j).rep()));
00323 fprintf(fic,",");
00324 }
00325 mpq_out_str(fic,10,&(m(i,j).rep()));
00326 fprintf(fic,"],\n");
00327 }
00328 {
00329 int j;
00330 fprintf(fic,"[");
00331 for(j=0;j<m.ncol-1;j++)
00332 {
00333 mpq_out_str(fic,10,&(m(i,j).rep()));
00334 fprintf(fic,",");
00335 }
00336 mpq_out_str(fic,10,&(m(i,j).rep()));
00337 fprintf(fic,"]\n];\n");
00338 }
00339 }
00340
00341 template<template<typename T> class typmat >
00342 void printmatfile(const typmat<Scl<MPAI> > & m,const char * name,FILE * fic)
00343 {
00344 int i;
00345 fprintf(fic,"%s:=[",name);
00346 for(i=0;i<m.nrow-1;i++)
00347 {
00348 int j;
00349 fprintf(fic,"[");
00350 for(j=0;j<m.ncol-1;j++)
00351 {
00352 mpai_out_str(fic,&(m(i,j).rep()));
00353 fprintf(fic,",");
00354 }
00355 mpai_out_str(fic,&(m(i,j).rep()));
00356 fprintf(fic,"],\n");
00357 }
00358 {
00359 int j;
00360 fprintf(fic,"[");
00361 for(j=0;j<m.ncol-1;j++)
00362 {
00363 mpai_out_str(fic,&(m(i,j).rep()));
00364 fprintf(fic,",");
00365 }
00366 mpai_out_str(fic,&(m(i,j).rep()));
00367 fprintf(fic,"]\n];\n");
00368 }
00369 }
00370
00371 template<template<typename T> class typmat >
00372 void printmatfile_pequan(const typmat<Scl<MPF> > & m,FILE * fic)
00373 {
00374 int i,j;
00375 fprintf(fic,"%d %d\n",m.nrow,m.ncol);
00376 for(i=0;i<m.nrow;i++)
00377 {
00378 for(j=0;j<m.ncol;j++)
00379 {
00380 fprintf(fic,"%d %d ",i,j);
00381 mpf_out_str(fic,10,NBDIGITS,(m(i,j).rep()));
00382 fprintf(fic,"\n");
00383 }
00384 }
00385 }
00386
00387 template<template<typename T> class typmat >
00388 void printmatfile(const typmat<Scl<MPF> > & m,char * name,FILE * fic)
00389 {
00390 int i;
00391 fprintf(fic,"%s:=[",name);
00392 for(i=0;i<m.nrow-1;i++)
00393 {
00394 int j;
00395 fprintf(fic,"[");
00396 for(j=0;j<m.ncol-1;j++)
00397 {
00398 mpf_out_str(fic,10,NBDIGITS,(m(i,j).rep()));
00399 fprintf(fic,",");
00400 }
00401 mpf_out_str(fic,10,NBDIGITS,(m(i,j).rep()));
00402 fprintf(fic,"],\n");
00403 }
00404 {
00405 int j;
00406 fprintf(fic,"[");
00407 for(j=0;j<m.ncol-1;j++)
00408 {
00409 mpf_out_str(fic,10,NBDIGITS,(m(i,j).rep()));
00410 fprintf(fic,",");
00411 }
00412 mpf_out_str(fic,10,NBDIGITS,(m(i,j).rep()));
00413 fprintf(fic,"]\n];\n");
00414 }
00415 }
00416
00417
00418
00419
00420
00421
00422
00423 template <typename typP>
00424 void readfile(typP &toto,char *name)
00425 {
00426
00427 typedef typename typP::value_type pol;
00428 pol p;
00429 FILE *fic=fopen(name,"r");
00430 char * chaine=(char*)malloc(10000001);
00431 for (;fgets(chaine,10000000,fic)!=NULL;)
00432 {
00433 printf("chainelue %s\n",chaine);
00434 cout<<"flush"<<endl;
00435 fflush(stdout);
00436 cout<<"despuesfflush"<<endl;
00437 cout<<pol(chaine)<<endl;
00438 toto.push_back(p=pol(chaine));
00439 cout<<"g pushe "<<p<<endl;
00440 }
00441 fclose(fic);
00442 free(chaine);
00443 }
00444
00445 void printcoeff(FILE *fic, double c)
00446 {
00447 fprintf(fic,"%f",c);
00448 }
00449
00450 void printcoeff(FILE *fic, long double c)
00451 {
00452 fprintf(fic,"%Lf",c);
00453 }
00454
00455 void printcoeff(FILE *fic, Scl<MPQ> c)
00456 {
00457 mpq_out_str(fic,10,&c.data);
00458 }
00459
00460 void printcoeff(FILE *fic, Scl<MPF> c)
00461 {
00462 mpf_out_str(fic,10,30,c.data);
00463 }
00464
00465 void printcoeff(FILE *fic, mpf_class c)
00466 {
00467 mpf_out_str(fic,10,30,c.get_mpf_t());
00468 }
00469
00470 #ifdef MON_PREMIER
00471 template<typename T>
00472 void printcoeff(FILE *fic, Z<MON_PREMIER,T> c)
00473 {
00474 fprintf(fic,"%d",c.rep);
00475 }
00476 #endif
00477
00478 void printmon(FILE *fic, mon m)
00479 {
00480 printcoeff(fic,m.GetCoeff());
00481 for(int i=0;i<=lvar(m.rep);i++)
00482 {
00483 if (m.GetDegree(i)>=1)
00484 {
00485 fprintf(fic,"*x%d",i);
00486 if (m.GetDegree(i)>1)
00487 fprintf(fic,"^%d",(int)m.GetDegree(i));
00488 }
00489 }
00490 }
00491
00492 template<typename typdump>
00493 void printdump(FILE *fic, const typdump &dump)
00494 {
00495 fprintf(fic,"#begin: dump\n");
00496 for(typename typdump::const_iterator iter=dump.begin();
00497 iter!=dump.end();iter++)
00498 {
00499 fprintf(fic,"k: %d\n",iter->k);
00500 fprintf(fic,"size: %d",iter->size);
00501 for(int i=0;i<iter->size;i++)
00502 {
00503 printmon(fic,iter->nf[i].ind);
00504 fprintf(fic,"\n");
00505 for(int j=0;j<iter->nf[i].size;j++)
00506 {
00507 if(j>0)
00508 fprintf(fic,"+");
00509 fprintf(fic,"(");
00510 printcoeff(fic,iter->nf[i].nf[j]);
00511 fprintf(fic,")*");
00512 printmon(fic,monofindex(j,iter->nf[i]));
00513
00514 }
00515 fprintf(fic,"\n");
00516 }
00517 }
00518 fprintf(fic,"#end: dump\n");
00519 }
00520
00521 template <typename typdump>
00522 void readdump(FILE *fic,typdump &toto)
00523 {
00524 typedef typename typdump::value_type pol;
00525 pol p;
00526 char * chaine=(char*)malloc(10000001);
00527 for (;fgets(chaine,10000000,fic)!=NULL;)
00528 {
00529 printf("chainelue %s\n",chaine);fflush(stdout);
00530 toto.push_back(p=pol(chaine));
00531 cout<<"g pushe "<<p<<endl;
00532 }
00533 free(chaine);
00534 }
00535 #endif //ALREADY_io