lemon/polynomial.h
changeset 2388 c6d537888fe5
parent 2207 75a29ac69c19
child 2391 14a343be7a5a
equal deleted inserted replaced
2:d981c2423dfc 3:762bbfa57ffd
    48     ///\e
    48     ///\e
    49     template<class U> Polynomial(const U &u) : _coeff(1,u) {}
    49     template<class U> Polynomial(const U &u) : _coeff(1,u) {}
    50     ///\e
    50     ///\e
    51     template<class U> Polynomial(const Polynomial<U> &u) : _coeff(u.deg()+1)
    51     template<class U> Polynomial(const Polynomial<U> &u) : _coeff(u.deg()+1)
    52     {
    52     {
    53       for(int i=0;i<(int)_coeff.size();i++) _coeff[i]=u[i];
    53       for(int i=0;i<int(_coeff.size());i++) _coeff[i]=u[i];
    54     }
    54     }
    55     ///Query the degree of the polynomial.
    55     ///Query the degree of the polynomial.
    56     
    56     
    57     ///Query the degree of the polynomial.
    57     ///Query the degree of the polynomial.
    58     ///\warning This number differs from real degree of the polinomial if
    58     ///\warning This number differs from real degree of the polinomial if
   109     }
   109     }
   110     
   110     
   111     ///Derivate the polynomial (in place)
   111     ///Derivate the polynomial (in place)
   112     Polynomial &derivateMyself()
   112     Polynomial &derivateMyself()
   113     {
   113     {
   114       for(int i=1;i<(int)_coeff.size();i++) _coeff[i-1]=i*_coeff[i];
   114       for(int i=1;i<int(_coeff.size());i++) _coeff[i-1]=i*_coeff[i];
   115       _coeff.pop_back();
   115       _coeff.pop_back();
   116       return *this;
   116       return *this;
   117     }
   117     }
   118     
   118     
   119     ///Return the derivate of the polynomial
   119     ///Return the derivate of the polynomial
   120     Polynomial derivate() const
   120     Polynomial derivate() const
   121     {
   121     {
   122       Polynomial tmp(deg()-1);
   122       Polynomial tmp(deg()-1);
   123       for(int i=1;i<(int)_coeff.size();i++) tmp[i-1]=i*_coeff[i];
   123       for(int i=1;i<int(_coeff.size());i++) tmp[i-1]=i*_coeff[i];
   124       return tmp;
   124       return tmp;
   125     }
   125     }
   126 
   126 
   127     ///Integrate the polynomial (in place)
   127     ///Integrate the polynomial (in place)
   128     Polynomial &integrateMyself()
   128     Polynomial &integrateMyself()
   136     ///Return the integrate of the polynomial
   136     ///Return the integrate of the polynomial
   137     Polynomial integrate() const
   137     Polynomial integrate() const
   138     {
   138     {
   139       Polynomial tmp(deg()+1);
   139       Polynomial tmp(deg()+1);
   140       tmp[0]=0;
   140       tmp[0]=0;
   141       for(int i=0;i<(int)_coeff.size();i++) tmp[i+1]=_coeff[i]/(i+1);
   141       for(int i=0;i<int(_coeff.size());i++) tmp[i+1]=_coeff[i]/(i+1);
   142       return tmp;
   142       return tmp;
   143     }
   143     }
   144 
   144 
   145     ///\e
   145     ///\e
   146     template<class U>
   146     template<class U>
   147     Polynomial &operator+=(const Polynomial<U> &p)
   147     Polynomial &operator+=(const Polynomial<U> &p)
   148     {
   148     {
   149       if(p.deg()>deg()) _coeff.resize(p.deg()+1);
   149       if(p.deg()>deg()) _coeff.resize(p.deg()+1);
   150       for(int i=0;i<=(int)std::min(deg(),p.deg());i++)
   150       for(int i=0;i<=int(std::min(deg(),p.deg()));i++)
   151 	_coeff[i]+=p[i];
   151 	_coeff[i]+=p[i];
   152       return *this;
   152       return *this;
   153     }
   153     }
   154     ///\e
   154     ///\e
   155     template<class U>
   155     template<class U>