Multivariate polynomials

The multivariate polynomials

template<class C, 
         class O=Dlex, 
         class R=std::list<Monom<C,dynamicexp<'x'> > > >  
struct MPol<C,O,R>;

are parameterised by

Containers for multivariate polynomials

The containers R for this class could be list, vector, ... or any container with the member function insert.

Example

o+

#include <synaps/mpol.h>

typedef MPol<double> mpol_t;
typedef mpol_t::monom_t mon_t;

int main (int argc, char **argv)
{
  using namespace std;
  mpol_t p0("x1+x2+1"), p1("x2+x1^2+1");
  cout<<p0<<", "<<p1<<endl;
  //| p0 = x1 + x2 + 1, p1 = x1^2 + x2 + 1

  mpol_t p2(p0+p1); cout<<p2<<endl;p2+=p1-p0; cout<<p2<<endl;
  //| x1^2 + x1 + 2*x2 + 2

  p2+=p1-p0; cout<<p2<<endl;
  //| 2*x1^2 + 2*x2 + 2

  p2 =p0-p1; cout<<p2<<endl;
  //| -x1^2 + x1

  p2=p0 -p1*mon_t(2); cout<<p2<<endl;
  //| - 2*x1^2 + x1 - x2 - 1
}

Variable environments

The default names for the variables are x0, x1, x2, ... But one can use specific variable environments, in order to precise which variables we want to consider. The class Variables which implements such dictionnary between the internal variables xi and the one we want, can be used either when constructing a polynomial or when printing it. For instance,
    Variables V("u v");
    MPol<double> p("u^2+v*u-v+2*u-1", V);
defines a dictionnary V where the variable u is x0, v is x1 so that the polynomial p which is constructed from the string "u\^{ </tt>2+..."} is in fact:
    x0^2+x0*x1+2*x0-x1-1
The name of the variables can be recovered from their indices {V[0], V[1]}. If new variable names are used when constructing a polynomial, they are added to the dictionnary V, in the order they are parsed:
    MPol<double> q("u^3-w+t", V);
Now V[2] is w, and V[3] the variable t. Notice, that here if we use an index $i \geqslant 4$, we get for V[i], the variable xi. In order to print the polynomial, with the appropriate variable names, instead of the operator <<, one can use the following functions: \
    Variables W("a b c d");
    print(std::cout,p,W)<< std::endl;
In this example, it yields:
    a^2+a*b+2*a-b-1

o+

#include <synaps/mpol.h>

typedef MPol<double> mpol_t;
int main(int argc, char** argv) 
{
  Variables V("u v");
  mpol_t p("u^2+v*u-v+2*u-1",V);
  std::cout << p<< std::endl;
  //| x0^2+x0*x1+2*x0-x1-1

  std::cout<<V[0]<<std::endl;
  //| u
  std::cout<<V[1]<<std::endl;
  //| v

  MPol<double> q("u^3-w+t", V); 
  std::cout<<V[2]<<std::endl;
  //| w
  std::cout<<V[3]<<std::endl;
  //| t
  std::cout<<V[4]<<std::endl;
  //| x4

  Variables W("a b c d");
  print(std::cout,p,W)<<std::endl;
  //| a^2+a*b+2*a-b-1
  print(std::cout,p)<<std::endl;
  //| x0^2+x0*x1+2*x0-x1-1
}

Sorting monomials

Different ordering on monomials are available:

They provide the operator(m1,m2) and less(m1,m2) which compare two monomials m1, m2, using the functions m[i] and m.size().

Implementation


SYNAPS DOCUMENTATION
logo