monom< C, E > Struct Template Reference

Monomial class. More...

#include <monomial.hpp>

List of all members.

Public Types

Public Member Functions

Public Attributes

Static Public Attributes

Friends


Detailed Description

template<class C, class E = dynamic_exp<int>>
struct mmx::monom< C, E >

Monomial class.

Definition at line 62 of file monomial.hpp.


Member Typedef Documentation

typedef C coeff_t

Definition at line 86 of file monomial.hpp.

typedef E container_t

Definition at line 82 of file monomial.hpp.

typedef E exp_t

Definition at line 75 of file monomial.hpp.

typedef E::exponent_t exponent_t

Definition at line 83 of file monomial.hpp.

typedef int index_t

Definition at line 81 of file monomial.hpp.

typedef C Scalar

Definition at line 87 of file monomial.hpp.

typedef monom<C,E> self_t

Definition at line 88 of file monomial.hpp.

typedef E::size_type size_type

Definition at line 85 of file monomial.hpp.


Constructor & Destructor Documentation

monom (  )  [inline]

Definition at line 91 of file monomial.hpp.

References monom< C, E >::rep().

00091          : _coef(),_expt() {
00092     rep().resize(0); //COUNT<self_t>(' ');
00093   }

monom ( const C &  c,
const exp_t r 
) [inline]

Definition at line 95 of file monomial.hpp.

00095 :_coef(c), _expt(r){}

monom ( const C &  c  )  [inline]

Definition at line 96 of file monomial.hpp.

References monom< C, E >::rep().

00096                     : _coef(c),_expt() {
00097     rep().resize(0);
00098   } 

monom ( int  i  )  [inline]

Definition at line 99 of file monomial.hpp.

References monom< C, E >::rep().

00099               :_coef(i), _expt() {
00100     rep().resize(0);
00101   }

monom ( const std::string &  s,
int  d,
variables vars = variables::default_ 
) [inline]

monom x[i]**d

Construction of the monom $x_{i}^{d}$.

Definition at line 284 of file monomial.hpp.

References monom< C, E >::rep().

00285                                      :_coef(1) {
00286   if(d == 0)
00287     rep().resize(0);
00288  else
00289      {
00290        int i=vars[s];
00291        rep().reserve(i+1);
00292        for(int j=0;j<i;j++) rep().set_expt(j,0);
00293        rep().set_expt(i,d);
00294      }
00295 }

monom ( const C &  c,
unsigned  s,
const AsSize  
) [inline]

Definition at line 104 of file monomial.hpp.

00104 :_coef(c),_expt(s){}

monom ( const C &  c,
int  d,
unsigned  i 
) [inline]

monom c*x[i]**d

Construction of the monom $c\,x_{v}^{d}$.

Definition at line 299 of file monomial.hpp.

References monom< C, E >::rep().

00299                                              :_coef(c) {
00300   if(d == 0)
00301     rep().resize(0);
00302   else
00303     {
00304       rep().reserve(v+1);
00305       for(unsigned j=0;j<v;j++) rep().set_expt(j,0);
00306       rep().set_expt(v,d);
00307     }
00308 }

monom ( const C &  c,
int  s,
int *  t 
) [inline]

Definition at line 108 of file monomial.hpp.

References monom< C, E >::rep().

00108                                    :_coef(c), _expt(s){
00109     for(int i=0;i<s;i++) rep()[i]= t[i];
00110   }

monom ( const char *  s,
variables vars = monom< C, E >::var 
) [inline]

Definition at line 312 of file monomial.hpp.

References mmx::assign(), C, COEF, Monomial, synaps_input, synaps_inputlim, mmx::synaps_inputptr, TERMINATE, XID, yylex(), and yylval.

00312                                                  {
00313   int n = strlen(s);
00314   if (s[n-1]=='\n') {n--;}
00315   if(s[n-1]==';')
00316     {
00317       synaps_input = new char[n+1];
00318       memcpy(synaps_input,s,n); synaps_input[n]='\0';
00319       synaps_inputlim = synaps_input + n;
00320     }
00321   else
00322     {
00323       synaps_input = new char[n+2];
00324       memcpy(synaps_input,s,n); 
00325       synaps_input[n]=';'; synaps_input[n+1]='\0';
00326       synaps_inputlim = synaps_input + n+1;
00327     }
00328   synaps_inputptr=synaps_input;
00329   *this = Monomial((C)1);
00330   int Ask;
00331 
00332   for (;;) {
00333     Ask = yylex();
00334     if (Ask == COEF) { /* monome constant */
00335       C c;
00336       let::assign(c,yylval);
00337       free(yylval);
00338       *this *= c;
00339     }
00340     else if (Ask == XID) {
00341       char* p = strchr(yylval,'^');
00342       if (p == NULL)
00343         {
00344           *this *= Monomial(vars[std::string(yylval)],1);
00345         }
00346       else {
00347         p++;
00348         *this *= Monomial(vars[std::string(yylval,p-1)], atoi(p));
00349       }
00350       free(yylval);
00351     }
00352     else if (Ask == TERMINATE) {
00353       break;
00354     }
00355   }
00356   delete[] synaps_input;
00357 }

monom ( const monom< C, E > &  m  )  [inline]

Definition at line 114 of file monomial.hpp.

00114 :_coef(m._coef),_expt(m._expt) {}


Member Function Documentation

int* begin (  )  const [inline]

Definition at line 133 of file monomial.hpp.

References monom< C, E >::rep().

00133 { return rep().begin(); }

int* begin (  )  [inline]

Definition at line 132 of file monomial.hpp.

References monom< C, E >::rep().

00132 { return rep().begin(); }

C& coeff (  )  [inline]

Definition at line 129 of file monomial.hpp.

References monom< C, E >::_coef, and C.

00129 { return _coef; }

const C& coeff (  )  const [inline]
exponent_t exponent ( size_type  i  )  const [inline]

Definition at line 142 of file monomial.hpp.

References monom< C, E >::rep().

00142 { return rep()[i]; }

exponent_t expt ( size_type  i  )  const [inline]

Definition at line 141 of file monomial.hpp.

References monom< C, E >::rep().

00141 { return rep()[i]; }

int l_variable (  )  const [inline]

Definition at line 137 of file monomial.hpp.

References mmx::lvar(), and monom< C, E >::rep().

00137 { return lvar(rep()); }

unsigned nbvar (  )  const [inline]

Definition at line 138 of file monomial.hpp.

References mmx::lvar(), and monom< C, E >::rep().

00138 { return lvar(rep())+1; }

int nvars (  )  const [inline]

Definition at line 136 of file monomial.hpp.

References mmx::lvar(), and monom< C, E >::rep().

00136 { return lvar(rep()); }

bool operator!= ( int  n  )  const [inline]

Definition at line 149 of file monomial.hpp.

00149 {return !(*this==n);}

monom< C, E > & operator*= ( const C &  c  )  [inline]

Definition at line 405 of file monomial.hpp.

References monom< C, E >::coeff(), mmx::erase(), and monom< C, E >::rep().

00405                                   {
00406   coeff() *= c;
00407   if (coeff()==0) erase(rep());
00408   return *this;
00409 }

monom< C, E > & operator*= ( const self_t m  )  [inline]

Definition at line 395 of file monomial.hpp.

References mmx::add(), monom< C, E >::coeff(), mmx::erase(), and monom< C, E >::rep().

00395                                          {
00396   coeff() *= m.coeff();
00397   if (coeff()!=0)
00398     array::add(rep(),m.rep());
00399   else
00400     erase(rep());
00401   return *this;
00402 }

monom< C, E > & operator+= ( const self_t m  )  [inline]

Definition at line 367 of file monomial.hpp.

References monom< C, E >::coeff(), mmx::erase(), and monom< C, E >::rep().

00367                                          {
00368   coeff() += m.coeff();
00369   if (coeff()==0) erase(rep());
00370   return *this;
00371 }

self_t operator- (  )  const [inline]

Definition at line 168 of file monomial.hpp.

References monom< C, E >::_coef, and monom< C, E >::rep().

00168 {return self_t(-_coef,rep());}

monom< C, E > & operator-= ( const self_t m  )  [inline]

Definition at line 374 of file monomial.hpp.

References monom< C, E >::coeff(), mmx::erase(), and monom< C, E >::rep().

00374                                          {
00375   coeff() -= m.coeff();
00376   if (coeff()==0) erase(rep());
00377   return *this;
00378 }

monom< C, E > & operator/= ( const C &  c  )  [inline]

Definition at line 412 of file monomial.hpp.

References assert, monom< C, E >::coeff(), mmx::erase(), and monom< C, E >::rep().

00412                                   {
00413   assert(c !=0);
00414   coeff() /= c;
00415   if (coeff()==0) erase(rep());
00416   return *this;
00417 }

self_t& operator= ( const self_t m  )  [inline]

Definition at line 120 of file monomial.hpp.

References monom< C, E >::_coef, monom< C, E >::_expt, and monom< C, E >::coeff().

00121     {
00122       _coef = m.coeff(); 
00123       _expt = m._expt; 
00124       return *this;
00125     };

bool operator== ( int  n  )  const [inline]

Definition at line 360 of file monomial.hpp.

References monom< C, E >::coeff().

00360                                  {
00361   return (coeff()==n);
00362 }

exponent_t operator[] ( size_type  i  )  const [inline]

Definition at line 140 of file monomial.hpp.

References monom< C, E >::rep().

00140 { return rep()[i]; }

const E& rep (  )  const [inline]

Definition at line 74 of file monomial.hpp.

References monom< C, E >::_expt.

00074 {return (_expt);}

E& rep (  )  [inline]
void set_coeff ( const C &  c  )  [inline]

Definition at line 130 of file monomial.hpp.

References monom< C, E >::_coef.

00130 { _coef = c; }

self_t& set_expt ( size_type  i,
exponent_t  d 
) [inline]

Definition at line 144 of file monomial.hpp.

References monom< C, E >::rep().

00145     {rep().set_expt(i,d);return *this; }

unsigned size ( void   )  const [inline]

Definition at line 135 of file monomial.hpp.

References monom< C, E >::rep().

Referenced by as_helper< monom< T, TR >, monom< F, FR > >::cv(), and mmx::sparse::print_dual().

00135 { return rep().size(); }


Friends And Related Function Documentation

bool IsComparable ( const self_t m1,
const self_t m2 
) [friend]

Definition at line 162 of file monomial.hpp.

00163   {
00164     return m1.rep() == m2.rep();
00165   }

bool operator!= ( const self_t m1,
const self_t m2 
) [friend]

Definition at line 157 of file monomial.hpp.

00158   {
00159     return !(m1 == m2);
00160   }

bool operator== ( const self_t m1,
const self_t m2 
) [friend]

Definition at line 152 of file monomial.hpp.

00153   {
00154     return m1._coef == m2._coef && m1.rep() == m2.rep();
00155   }


Member Data Documentation

C _coef
E _expt

Definition at line 72 of file monomial.hpp.

Referenced by monom< C, E >::operator=(), and monom< C, E >::rep().

variables var [inline, static]

Definition at line 78 of file monomial.hpp.


The documentation for this struct was generated from the following file:

Generated on 6 Dec 2012 for realroot by  doxygen 1.6.1