synaps/mpol/approximate.h

Go to the documentation of this file.
00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS.               *
00003 *      V.t TRAN , GALAAD, INRIA                                      *
00004 **********************************************************************/
00005 #ifndef SYNAPS_RESULTANT_APPROXIMATE_H
00006 #define SYNAPS_RESULTANT_APPROXIMATE_H
00007 //---------------------------------------------------------------------
00008 #include <synaps/init.h>
00009 #include <synaps/linalg.h>
00010 #include <synaps/mpol/MPOLDST.m>
00011 #include <synaps/mpol/matrixof.h>
00012 
00013 __BEGIN_NAMESPACE_SYNAPS
00014 
00015 
00024 template<class POL>
00025 POL MonomV(const int v, const int n)
00026 {
00027   typedef typename POL::monom_t MON;
00028   int d1,d2;
00029   POL p(0);
00030   for (int j=0;j<=v;j++) {
00031     POL tmp(MON(0,j));
00032     p = p+tmp;
00033   }
00034 
00035   for (int i=1;i<n;i++) {
00036     POL p1(0), p3(0);
00037     for (int j=1;j<=v;j++) {
00038       POL tmp(MON(i,j));
00039       p1 = p1+tmp;//creation of monome xi^j
00040     }
00041 
00042     for (typename POL::const_iterator pp=p.begin();pp!=p.end();pp++) {
00043       POL k1(*pp); d1= MPOLDST::degree(k1);
00044       POL p2(0);
00045       for (typename POL::const_iterator tt=p1.begin();tt!=p1.end();tt++){
00046                 POL k2(*tt); d2 = MPOLDST::degree(k2);
00047                 if (d1+d2<=v)//satisfied
00048                   p2+=k2*k1;    
00049       }
00050       p3+=p2;
00051     }
00052     p+=p3;
00053   }
00054   return p;
00055 };
00056 
00060 template<class LP>
00061 LP baseLocal(const LP & f, const std::vector<int> & d, const int nv)
00062 {
00063   typedef typename LP::value_type POL;
00064   LP bas;
00065   int n = f.size();
00066   for (int i=0;i<n;i++) {
00067     POL mv = MonomV<POL>(d[i],nv); //number of variables = nv
00068     for (int j=0;j<nv;j++) //shift the variables
00069       mv = MPOLDST::swap(mv, j, j+n);
00070     for (typename POL::const_iterator mm=mv.begin();mm!=mv.end();mm++) {
00071       bas.push_back(f[i]*(*mm));
00072     }
00073   }
00074   return bas;
00075 };
00076 
00085 template <class MAT, class LL>
00086 MAT evaluation(const LL& f,
00087                const std::vector<int> & d,
00088                const std::vector<double>& u,
00089                const int cas=1)
00090 {
00091   typedef typename LL::value_type POL;
00092   typedef typename POL::monom_t MON;
00093   int n=f.size();
00094   int nv = numvar(f)-n; //number of variables
00095   LL bas = baseLocal<LL>(f,d,nv);
00096   int nz = bas.size(), v=0;
00097 
00098   MAT res;
00099   POL tmp;
00100   matrixof::reserve(res,nz,nz,1);
00101   switch (cas){
00102   case 1://e(U) simple
00103         for (int i=0;i<nz;i++) {
00104           v = 0;
00105           for (typename LL::const_iterator pp = bas.begin();pp!=bas.end();pp++) {
00106                 POL tmp = (*pp);
00107                 for (int j=n;j<n+nv;j++)
00108                   tmp = MPOLDST::subs(tmp,j,u[i*nv+j-n]);//replace variables by values
00109                 matrixof::assigncoeff(res,i,v++,tmp);
00110           }
00111         }
00112         break;
00113   case 2://e(U) & e(U')
00114         int vu=0;
00115         int i=0;
00116         while (i<nz) {
00117           v = 0;
00118           for (typename LL::const_iterator pp = bas.begin();pp!=bas.end();pp++) {
00119                 tmp = (*pp);    //evaluation
00120                 for (int j=n;j<n+nv;j++)
00121                   tmp = MPOLDST::subs(tmp,j,u[vu*nv+j-n]);
00122                 matrixof::assigncoeff(res,i,v++,tmp);
00123           }
00124           i++; int k=0;
00125 
00126           while (i<nz && k<nv) {
00127                 v=0;
00128                 for (typename LL::const_iterator pp = bas.begin();pp!=bas.end();pp++) {
00129                   POL tmp1 = (*pp);
00130                   MPOLDST::diff(tmp,tmp1,n+k);//derivation with n+k
00131                   for (int j=n;j<n+nv;j++)
00132                         tmp = MPOLDST::subs(tmp,j,u[vu*nv+j-n]);
00133                   matrixof::assigncoeff(res,i,v++,tmp);
00134                 }
00135                 i++; k++;
00136           }
00137           vu++;
00138         }
00139         break;
00140   }
00141 
00142   return res;
00143 };
00144 
00154 template<class LL>
00155 typename LL::value_type Elim_Approximate(const LL& f,
00156                                          const std::vector<int> & d,
00157                                          const std::vector<double> & u,
00158                                          const int cas=1)
00159 {
00160   typedef typename LL::value_type POL;
00161   typedef MatrDse<POL, linalg::rep2d<POL> > MAT;
00162 
00163   MAT res = evaluation<MAT, LL>(f,d,u,cas);
00164 #ifdef DEBUG
00165   std::cout<<"Matrix E :\n"<<res<<std::endl;
00166 #endif
00167   POL D = Det(/*Berko(),*/res);
00168   return D;
00169 };
00170 
00171 
00172 __END_NAMESPACE_SYNAPS
00173 
00174 //---------------------------------------------------------------------
00175 #endif // SYNAPS_RESULTANT_APPROXIMATE_H
00176 

SYNAPS DOCUMENTATION
logo