DGtal  1.5.beta
DGtal::MPolynomial< n, TRing, TAlloc > Class Template Reference

Aim: Represents a multivariate polynomial, i.e. an element of \( K[X_0, ..., X_{n-1}] \), where K is some ring or field. More...

#include <DGtal/math/MPolynomial.h>

Inheritance diagram for DGtal::MPolynomial< n, TRing, TAlloc >:
[legend]

Public Types

typedef TRing Ring
 
typedef TAlloc Alloc
 
typedef MPolynomial< n - 1, Ring, AllocMPolyNM1
 
typedef IVector< MPolyNM1, typename Alloc::template rebind< MPolyNM1 >::other,(n >1) > Storage
 
typedef Storage::Size Size
 

Public Member Functions

void normalize ()
 
 MPolynomial (const Alloc &allocator=Alloc())
 
 MPolynomial (const Ring &v, const Alloc &allocator=Alloc())
 
 MPolynomial (const MPolyNM1 &pdm1, const Alloc &)
 
template<typename Ring2 , typename Alloc2 >
 MPolynomial (const MPolynomial< n, Ring2, Alloc2 > &p, const Alloc &allocator=Alloc())
 
template<typename Ring2 , typename Alloc2 >
MPolynomialoperator= (const MPolynomial< n, Ring2, Alloc2 > &p)
 
void swap (MPolynomial &p)
 
Alloc getAllocator () const
 
int degree () const
 
const MPolyNM1leading () const
 
bool isZero () const
 
MPolyNM1operator[] (Size i)
 
const MPolyNM1operator[] (Size i) const
 
MPolynomialEvaluator< n, Ring, Alloc, Ringoperator() (const Ring &x) const
 
template<typename Ring2 >
MPolynomialEvaluator< n, Ring, Alloc, Ring2 > operator() (const Ring2 &x) const
 
MPolynomial operator* (const Ring &v) const
 
MPolynomial operator/ (const Ring &v) const
 
MPolynomialoperator*= (const MPolynomial &p)
 
MPolynomialoperator*= (const Ring &v)
 
MPolynomialoperator/= (const Ring &v)
 
MPolynomial operator- () const
 
MPolynomial operator+ (const MPolynomial &q) const
 
MPolynomial operator- (const MPolynomial &q) const
 
MPolynomialoperator+= (const MPolynomial &q)
 
MPolynomialoperator-= (const MPolynomial &q)
 
MPolynomial operator+ (const MPolyNM1 &q) const
 
MPolynomial operator- (const MPolyNM1 &q) const
 
MPolynomial operator+ (const Ring &v) const
 
MPolynomial operator- (const Ring &v) const
 
MPolynomialoperator+= (const MPolyNM1 &q)
 
MPolynomialoperator-= (const MPolyNM1 &q)
 
MPolynomialoperator+= (const Ring &v)
 
MPolynomialoperator-= (const Ring &v)
 
MPolynomial operator* (const MPolynomial &p) const
 
bool operator== (const MPolynomial &q) const
 
bool operator!= (const MPolynomial &q) const
 
bool operator== (const Ring &v) const
 
bool operator!= (const Ring &v) const
 
void selfDisplay (std::ostream &s, int N=n) const
 
bool isValid () const
 

Private Member Functions

 MPolynomial (bool, Size s, const Alloc &)
 

Private Attributes

Storage myValue
 

Static Private Attributes

static MPolyNM1 myZeroPolynomial
 The zero polynomial of n-1 variables for a n-multivariate polynomial. More...
 

Friends

template<int NN, int nn, typename TT , typename AA >
class MPolynomialDerivativeComputer
 
template<int nn, typename TT , typename AA , typename SS >
class MPolynomialEvaluator
 
template<int nn, typename TT , typename HLHL , typename AA , typename SS >
class MPolynomialEvaluatorImpl
 
void euclidDiv (const MPolynomial< 1, TRing, TAlloc > &, const MPolynomial< 1, TRing, TAlloc > &, MPolynomial< 1, TRing, TAlloc > &, MPolynomial< 1, TRing, TAlloc > &)
 
MPolynomial operator* (const Ring &v, const MPolynomial &p)
 

Detailed Description

template<int n, typename TRing, class TAlloc>
class DGtal::MPolynomial< n, TRing, TAlloc >

Aim: Represents a multivariate polynomial, i.e. an element of \( K[X_0, ..., X_{n-1}] \), where K is some ring or field.

Description of template class 'MPolynomial'

Monomials are products of power of variables, like xy^2z^3. Polynomials in n variables are constructed recursively with polynomials in n - 1 variables.

There is a specialization for polynomials with no indeterminates, i.e. constants.

See also
dgtal_multivariate_polynomial
Template Parameters
nthe number of variables or indeterminates.
TRingthe type chosen for the polynomial, defines also the type of the coefficents (generally int, float or double).
TAllocis an allocator for TRing, for example std::allocator<TRing>; this is also the default parameter. Usually this parameter does not needs to be changed.

This class is a backport from Spielwiese.

Author
Felix Fontein (felix.nosp@m.@fon.nosp@m.tein..nosp@m.de), University of Zurich, Switzerland

Definition at line 964 of file MPolynomial.h.

Member Typedef Documentation

◆ Alloc

template<int n, typename TRing , class TAlloc >
typedef TAlloc DGtal::MPolynomial< n, TRing, TAlloc >::Alloc

Definition at line 985 of file MPolynomial.h.

◆ MPolyNM1

template<int n, typename TRing , class TAlloc >
typedef MPolynomial< n - 1, Ring, Alloc > DGtal::MPolynomial< n, TRing, TAlloc >::MPolyNM1

Definition at line 986 of file MPolynomial.h.

◆ Ring

template<int n, typename TRing , class TAlloc >
typedef TRing DGtal::MPolynomial< n, TRing, TAlloc >::Ring

Definition at line 984 of file MPolynomial.h.

◆ Size

template<int n, typename TRing , class TAlloc >
typedef Storage::Size DGtal::MPolynomial< n, TRing, TAlloc >::Size

Definition at line 996 of file MPolynomial.h.

◆ Storage

template<int n, typename TRing , class TAlloc >
typedef IVector< MPolyNM1, typename Alloc::template rebind<MPolyNM1 >::other, (n>1) > DGtal::MPolynomial< n, TRing, TAlloc >::Storage

The type for the vector storing polynomials coefficients. For 0 or 1 variables, uses a standard vector, for more variables, uses a specific vector of pointers to polynomials, with adequate allocators. This is for efficiency purposes.

Definition at line 995 of file MPolynomial.h.

Constructor & Destructor Documentation

◆ MPolynomial() [1/5]

template<int n, typename TRing , class TAlloc >
DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial ( bool  ,
Size  s,
const Alloc  
)
inlineprivate

◆ MPolynomial() [2/5]

template<int n, typename TRing , class TAlloc >
DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial ( const Alloc allocator = Alloc())
inline

Constructs a zero polynomial

Definition at line 1045 of file MPolynomial.h.

1046  : myValue( allocator )
1047  {}

◆ MPolynomial() [3/5]

template<int n, typename TRing , class TAlloc >
DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial ( const Ring v,
const Alloc allocator = Alloc() 
)
inline

Constructs a constant polynomial with constant term v.

Definition at line 1052 of file MPolynomial.h.

1053  : myValue( 1, MPolyNM1( v ), allocator )
1054  {}
MPolynomial< n - 1, Ring, Alloc > MPolyNM1
Definition: MPolynomial.h:986

◆ MPolynomial() [4/5]

template<int n, typename TRing , class TAlloc >
DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial ( const MPolyNM1 pdm1,
const Alloc  
)
inline

Constructs a polynomial of type MPolynomial<n, Ring> which is initialized with a polynomial of type MPolynomial<n-1, Ring>.

Definition at line 1060 of file MPolynomial.h.

1062  : myValue( 1, pdm1 )
1063  {}

◆ MPolynomial() [5/5]

template<int n, typename TRing , class TAlloc >
template<typename Ring2 , typename Alloc2 >
DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial ( const MPolynomial< n, Ring2, Alloc2 > &  p,
const Alloc allocator = Alloc() 
)
inline

Casts a polynomial of type MPolynomial<n, Ring2, Alloc2> to a polynomial of type MPolynomial<n, Ring, Alloc>.

Definition at line 1070 of file MPolynomial.h.

1072  : myValue( p.degree() + 1, MPolyNM1(), allocator )
1073  {
1074  for ( Size i = 0; i < myValue.size(); ++i )
1075  myValue[i] = p[i];
1076  normalize();
1077  }
Size size() const
Definition: MPolynomial.h:752
HalfEdgeDataStructure::Size Size

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::MPolynomial< n, TRing, TAlloc >::normalize(), and DGtal::IVector< T, TAlloc, usePointers >::size().

Member Function Documentation

◆ degree()

template<int n, typename TRing , class TAlloc >
int DGtal::MPolynomial< n, TRing, TAlloc >::degree ( ) const
inline
Returns
the degree of this polynomial. If this is the zero polynomial, the degree is -1.

Definition at line 1119 of file MPolynomial.h.

1120  {
1121  return (int)(myValue.size() - 1);
1122  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and DGtal::IVector< T, TAlloc, usePointers >::size().

Referenced by DGtal::EhrhartPolynomial< TSpace, TInteger >::countInterior(), DGtal::MPolynomial< n, TRing, TAlloc >::operator*(), DGtal::EhrhartPolynomial< TSpace, TInteger >::remainderInterior(), and testMPolynomial().

◆ getAllocator()

template<int n, typename TRing , class TAlloc >
Alloc DGtal::MPolynomial< n, TRing, TAlloc >::getAllocator ( ) const
inline

◆ isValid()

template<int n, typename TRing , class TAlloc >
bool DGtal::MPolynomial< n, TRing, TAlloc >::isValid ( ) const

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

◆ isZero()

template<int n, typename TRing , class TAlloc >
bool DGtal::MPolynomial< n, TRing, TAlloc >::isZero ( ) const
inline

◆ leading()

template<int n, typename TRing , class TAlloc >
const MPolyNM1& DGtal::MPolynomial< n, TRing, TAlloc >::leading ( ) const
inline
Returns
the leading term (of type MPolynomial<n-1, Ring>) of the first indeterminate. Returns 0 (of type MPolynomial<n-1, Ring>) in case of the zero polynomial.

Definition at line 1129 of file MPolynomial.h.

1130  {
1131  return myValue.size() ? myValue.back() : myZeroPolynomial;
1132  }
const T & back() const
Definition: MPolynomial.h:772
static MPolyNM1 myZeroPolynomial
The zero polynomial of n-1 variables for a n-multivariate polynomial.
Definition: MPolynomial.h:1001

References DGtal::IVector< T, TAlloc, usePointers >::back(), DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::MPolynomial< n, TRing, TAlloc >::myZeroPolynomial, and DGtal::IVector< T, TAlloc, usePointers >::size().

Referenced by testMPolynomial().

◆ normalize()

template<int n, typename TRing , class TAlloc >
void DGtal::MPolynomial< n, TRing, TAlloc >::normalize ( )
inline

Adjusts the size of myValue that the leading term and degree can be computed trivially. This must be called only after calls to the non-const operator[], in which the degree of the polynomial has potentially been changed.

Definition at line 1025 of file MPolynomial.h.

1026  {
1027  Size dp1 = myValue.size();
1028  while ( dp1 )
1029  {
1030  if (myValue[dp1 - 1].isZero())
1031  --dp1;
1032  else
1033  break;
1034  }
1035  if (dp1 < myValue.size())
1036  myValue.resize(dp1);
1037  }
void resize(Size aSize, const T &entry=T())
Definition: MPolynomial.h:757
bool isZero() const
Definition: MPolynomial.h:1137

References DGtal::MPolynomial< n, TRing, TAlloc >::isZero(), DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::IVector< T, TAlloc, usePointers >::resize(), and DGtal::IVector< T, TAlloc, usePointers >::size().

Referenced by DGtal::MPolynomialDerivativeComputer< 0, n, Ring, Alloc >::computeDerivative(), DGtal::MPolynomialDerivativeComputer< N, n, Ring, Alloc >::computeDerivative(), DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial(), DGtal::MPolynomial< n, TRing, TAlloc >::operator+=(), DGtal::MPolynomial< n, TRing, TAlloc >::operator-=(), and DGtal::MPolynomial< n, TRing, TAlloc >::operator=().

◆ operator!=() [1/2]

template<int n, typename TRing , class TAlloc >
bool DGtal::MPolynomial< n, TRing, TAlloc >::operator!= ( const MPolynomial< n, TRing, TAlloc > &  q) const
inline

Inequality operator.

Parameters
qany polynomial of the same type as this.
Returns
'true' iff this polynomial is different from q.

Definition at line 1505 of file MPolynomial.h.

1506  {
1507  return !(*this == q);
1508  }

◆ operator!=() [2/2]

template<int n, typename TRing , class TAlloc >
bool DGtal::MPolynomial< n, TRing, TAlloc >::operator!= ( const Ring v) const
inline

Inequality operator with a constant.

Parameters
vany value in the ring.
Returns
'true' iff this polynomial is different from v.

Definition at line 1529 of file MPolynomial.h.

1530  {
1531  return !(*this == v);
1532  }

◆ operator()() [1/2]

template<int n, typename TRing , class TAlloc >
MPolynomialEvaluator<n, Ring, Alloc, Ring> DGtal::MPolynomial< n, TRing, TAlloc >::operator() ( const Ring x) const
inline

Evaluation in x.

Parameters
xa value in the ring.
Returns
a functor for performing this evaluation

Definition at line 1169 of file MPolynomial.h.

1170  {
1171  return MPolynomialEvaluator<n, Ring, Alloc, Ring>( *this, x );
1172  }

◆ operator()() [2/2]

template<int n, typename TRing , class TAlloc >
template<typename Ring2 >
MPolynomialEvaluator<n, Ring, Alloc, Ring2> DGtal::MPolynomial< n, TRing, TAlloc >::operator() ( const Ring2 &  x) const
inline

Evaluation in x of type Ring2.

Template Parameters
Ring2another ring (like a polynomial with less variables).
Parameters
xa value in this ring.
Returns
a functor for performing this evaluation

Definition at line 1183 of file MPolynomial.h.

1184  {
1185  return MPolynomialEvaluator<n, Ring, Alloc, Ring2>( *this, x );
1186  }

◆ operator*() [1/2]

template<int n, typename TRing , class TAlloc >
MPolynomial DGtal::MPolynomial< n, TRing, TAlloc >::operator* ( const MPolynomial< n, TRing, TAlloc > &  p) const
inline

Multiplies the polynomial with another polynomial.

Parameters
pany polynomial of the same type.
Returns
the corresponding polynomial.
Todo:
Multiplication could be optimized for monovariate polynomials.

Definition at line 1467 of file MPolynomial.h.

1468  {
1469  int d = p.degree() + degree();
1470  if (d < -1)
1471  d = -1;
1472  MPolynomial r( true, d + 1, getAllocator() );
1473  if (!isZero() && !p.isZero())
1474  for ( Size i = 0; i < r.myValue.size(); ++i )
1475  for ( Size j = 0; j < myValue.size(); ++j )
1476  if (i < j + p.myValue.size())
1477  r[i] += myValue[j] * p[i - j];
1478  r.normalize();
1479  return r;
1480  }
Alloc getAllocator() const
Definition: MPolynomial.h:1107
int degree() const
Definition: MPolynomial.h:1119
MPolynomial(bool, Size s, const Alloc &)
Definition: MPolynomial.h:1014

References DGtal::MPolynomial< n, TRing, TAlloc >::degree(), DGtal::MPolynomial< n, TRing, TAlloc >::getAllocator(), DGtal::MPolynomial< n, TRing, TAlloc >::isZero(), DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator*() [2/2]

template<int n, typename TRing , class TAlloc >
MPolynomial DGtal::MPolynomial< n, TRing, TAlloc >::operator* ( const Ring v) const
inline

Multiply by constant.

Parameters
vany value in the ring.
Returns
the corresponding polynomial.

Definition at line 1196 of file MPolynomial.h.

1197  {
1198  MPolynomial r(*this);
1199  for ( Size i = 0; i < myValue.size(); ++i )
1200  r[i] *= v;
1201  return r;
1202  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator*=() [1/2]

template<int n, typename TRing , class TAlloc >
MPolynomial& DGtal::MPolynomial< n, TRing, TAlloc >::operator*= ( const MPolynomial< n, TRing, TAlloc > &  p)
inline

Self-multiplication by other polynomial.

Parameters
pany polynomial of the same type.
Returns
a reference to this.

Definition at line 1222 of file MPolynomial.h.

1223  {
1224  return *this = *this * p;
1225  }

◆ operator*=() [2/2]

template<int n, typename TRing , class TAlloc >
MPolynomial& DGtal::MPolynomial< n, TRing, TAlloc >::operator*= ( const Ring v)
inline

Self-multiplication by a constant.

Parameters
vany value in the ring.
Returns
a reference to this.

Definition at line 1232 of file MPolynomial.h.

1233  {
1234  MPolynomial r( *this );
1235  for ( Size i = 0; i < myValue.size(); ++i )
1236  myValue[i] *= v;
1237  return *this;
1238  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator+() [1/3]

template<int n, typename TRing , class TAlloc >
MPolynomial DGtal::MPolynomial< n, TRing, TAlloc >::operator+ ( const MPolyNM1 q) const
inline

Computes the sum of this polynomial with a polynomial with one less variable.

Parameters
qany polynomial with n-1 indeterminates in the same ring.
Returns
the corresponding polynomial.

Definition at line 1346 of file MPolynomial.h.

1347  {
1348  MPolynomial r(*this);
1349  if (r.myValue.size() < 1)
1350  r.myValue.resize(1);
1351  r[0] += q;
1352  r.normalize();
1353  return r;
1354  }

◆ operator+() [2/3]

template<int n, typename TRing , class TAlloc >
MPolynomial DGtal::MPolynomial< n, TRing, TAlloc >::operator+ ( const MPolynomial< n, TRing, TAlloc > &  q) const
inline

Computes the sum of two polynomials.

Parameters
qany polynomial of this type.
Returns
the corresponding polynomial.

Definition at line 1283 of file MPolynomial.h.

1284  {
1285  MPolynomial r(*this);
1286  if (r.myValue.size() < q.myValue.size())
1287  r.myValue.resize(q.myValue.size());
1288  for ( Size i = 0; i < q.myValue.size(); ++i )
1289  r[i] += q[i];
1290  r.normalize();
1291  return r;
1292  }

◆ operator+() [3/3]

template<int n, typename TRing , class TAlloc >
MPolynomial DGtal::MPolynomial< n, TRing, TAlloc >::operator+ ( const Ring v) const
inline

Addition with a constant.

Parameters
vany value in the ring.
Returns
the corresponding polynomial.

Definition at line 1377 of file MPolynomial.h.

1378  {
1379  MPolynomial r(*this);
1380  if (r.myValue.size() < 1)
1381  r.myValue.resize(1);
1382  r[0] += v;
1383  r.normalize();
1384  return r;
1385  }

◆ operator+=() [1/3]

template<int n, typename TRing , class TAlloc >
MPolynomial& DGtal::MPolynomial< n, TRing, TAlloc >::operator+= ( const MPolyNM1 q)
inline

Self-addition of this polynomial with a polynomial with one less variable.

Parameters
qany polynomial with n-1 indeterminates in the same ring.
Returns
a reference to this.

Definition at line 1408 of file MPolynomial.h.

1409  {
1410  if (myValue.size() < 1)
1411  myValue.resize(1);
1412  myValue[0] += q;
1413  normalize();
1414  return *this;
1415  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::MPolynomial< n, TRing, TAlloc >::normalize(), DGtal::IVector< T, TAlloc, usePointers >::resize(), and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator+=() [2/3]

template<int n, typename TRing , class TAlloc >
MPolynomial& DGtal::MPolynomial< n, TRing, TAlloc >::operator+= ( const MPolynomial< n, TRing, TAlloc > &  q)
inline

Adds q to this polynomial.

Parameters
qany polynomial of this type.
Returns
a reference to this.

Definition at line 1315 of file MPolynomial.h.

1316  {
1317  if (myValue.size() < q.myValue.size())
1318  myValue.resize(q.myValue.size());
1319  for ( Size i = 0; i < q.myValue.size(); ++i )
1320  myValue[i] += q[i];
1321  normalize();
1322  return *this;
1323  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::MPolynomial< n, TRing, TAlloc >::normalize(), DGtal::IVector< T, TAlloc, usePointers >::resize(), and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator+=() [3/3]

template<int n, typename TRing , class TAlloc >
MPolynomial& DGtal::MPolynomial< n, TRing, TAlloc >::operator+= ( const Ring v)
inline

Self-addition of a constant.

Parameters
vany value in the ring.
Returns
a reference to this.

Definition at line 1437 of file MPolynomial.h.

1438  {
1439  if (myValue.size() < 1)
1440  myValue.resize(1);
1441  myValue[0] += v;
1442  normalize();
1443  return *this;
1444  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::MPolynomial< n, TRing, TAlloc >::normalize(), DGtal::IVector< T, TAlloc, usePointers >::resize(), and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator-() [1/4]

template<int n, typename TRing , class TAlloc >
MPolynomial DGtal::MPolynomial< n, TRing, TAlloc >::operator- ( ) const
inline
Returns
the additive inverse of the polynomial.

Definition at line 1270 of file MPolynomial.h.

1271  {
1272  MPolynomial r( true, myValue.size(), getAllocator() );
1273  for ( Size i = 0; i < myValue.size(); ++i )
1274  r[i] = -myValue[i];
1275  return r;
1276  }

References DGtal::MPolynomial< n, TRing, TAlloc >::getAllocator(), DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator-() [2/4]

template<int n, typename TRing , class TAlloc >
MPolynomial DGtal::MPolynomial< n, TRing, TAlloc >::operator- ( const MPolyNM1 q) const
inline

Computes the difference of this polynomial with a polynomial with one less variable.

Parameters
qany polynomial with n-1 indeterminates in the same ring.
Returns
the corresponding polynomial.

Definition at line 1362 of file MPolynomial.h.

1363  {
1364  MPolynomial r(*this);
1365  if (r.myValue.size() < 1)
1366  r.myValue.resize(1);
1367  r[0] -= q;
1368  r.normalize();
1369  return r;
1370  }

◆ operator-() [3/4]

template<int n, typename TRing , class TAlloc >
MPolynomial DGtal::MPolynomial< n, TRing, TAlloc >::operator- ( const MPolynomial< n, TRing, TAlloc > &  q) const
inline

Computes the difference of two polynomials.

Parameters
qany polynomial of this type.
Returns
the corresponding polynomial.

Definition at line 1299 of file MPolynomial.h.

1300  {
1301  MPolynomial r(*this);
1302  if (r.myValue.size() < q.myValue.size())
1303  r.myValue.resize(q.myValue.size());
1304  for ( Size i = 0; i < q.myValue.size(); ++i )
1305  r[i] -= q[i];
1306  r.normalize();
1307  return r;
1308  }

◆ operator-() [4/4]

template<int n, typename TRing , class TAlloc >
MPolynomial DGtal::MPolynomial< n, TRing, TAlloc >::operator- ( const Ring v) const
inline

Difference to a constant.

Parameters
vany value in the ring.
Returns
the corresponding polynomial.

Definition at line 1392 of file MPolynomial.h.

1393  {
1394  MPolynomial r(*this);
1395  if (r.myValue.size() < 1)
1396  r.myValue.resize(1);
1397  r[0] -= v;
1398  r.normalize();
1399  return r;
1400  }

◆ operator-=() [1/3]

template<int n, typename TRing , class TAlloc >
MPolynomial& DGtal::MPolynomial< n, TRing, TAlloc >::operator-= ( const MPolyNM1 q)
inline

Self-subtraction of this polynomial with a polynomial with one less variable.

Parameters
qany polynomial with n-1 indeterminates in the same ring.
Returns
a reference to this.

Definition at line 1423 of file MPolynomial.h.

1424  {
1425  if (myValue.size() < 1)
1426  myValue.resize(1);
1427  myValue[0] -= q;
1428  normalize();
1429  return *this;
1430  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::MPolynomial< n, TRing, TAlloc >::normalize(), DGtal::IVector< T, TAlloc, usePointers >::resize(), and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator-=() [2/3]

template<int n, typename TRing , class TAlloc >
MPolynomial& DGtal::MPolynomial< n, TRing, TAlloc >::operator-= ( const MPolynomial< n, TRing, TAlloc > &  q)
inline

Subtracts q from this polynomial.

Parameters
qany polynomial of this type.
Returns
a reference to this.

Definition at line 1330 of file MPolynomial.h.

1331  {
1332  if (myValue.size() < q.myValue.size())
1333  myValue.resize(q.myValue.size());
1334  for ( Size i = 0; i < q.myValue.size(); ++i )
1335  myValue[i] -= q[i];
1336  normalize();
1337  return *this;
1338  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::MPolynomial< n, TRing, TAlloc >::normalize(), DGtal::IVector< T, TAlloc, usePointers >::resize(), and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator-=() [3/3]

template<int n, typename TRing , class TAlloc >
MPolynomial& DGtal::MPolynomial< n, TRing, TAlloc >::operator-= ( const Ring v)
inline

Self-subtraction of a constant.

Parameters
vany value in the ring.
Returns
a reference to this.

Definition at line 1451 of file MPolynomial.h.

1452  {
1453  if (myValue.size() < 1)
1454  myValue.resize(1);
1455  myValue[0] -= v;
1456  normalize();
1457  return *this;
1458  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::MPolynomial< n, TRing, TAlloc >::normalize(), DGtal::IVector< T, TAlloc, usePointers >::resize(), and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator/()

template<int n, typename TRing , class TAlloc >
MPolynomial DGtal::MPolynomial< n, TRing, TAlloc >::operator/ ( const Ring v) const
inline

Divide by constant.

Parameters
vany value in the ring.
Returns
the corresponding polynomial.

Definition at line 1209 of file MPolynomial.h.

1210  {
1211  MPolynomial r(*this);
1212  for ( Size i = 0; i < myValue.size(); ++i )
1213  r[i] /= v;
1214  return r;
1215  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator/=()

template<int n, typename TRing , class TAlloc >
MPolynomial& DGtal::MPolynomial< n, TRing, TAlloc >::operator/= ( const Ring v)
inline

Self-division by a constant.

Parameters
vany value in the ring.
Returns
a reference to this.

Definition at line 1245 of file MPolynomial.h.

1246  {
1247  for ( Size i = 0; i < myValue.size(); ++i )
1248  myValue[i] /= v;
1249  return *this;
1250  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator=()

template<int n, typename TRing , class TAlloc >
template<typename Ring2 , typename Alloc2 >
MPolynomial& DGtal::MPolynomial< n, TRing, TAlloc >::operator= ( const MPolynomial< n, Ring2, Alloc2 > &  p)
inline

Copies a polynomial of type MPolynomial<n, Ring2, Alloc2> to this polynomial (of type MPolynomial<n, Ring, Alloc>).

Definition at line 1085 of file MPolynomial.h.

1087  {
1088  myValue.resize(p.degree() + 1);
1089  for ( Size i = 0; i < myValue.size(); ++i )
1090  myValue[i] = p[i];
1091  normalize();
1092  return *this;
1093  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::MPolynomial< n, TRing, TAlloc >::normalize(), DGtal::IVector< T, TAlloc, usePointers >::resize(), and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator==() [1/2]

template<int n, typename TRing , class TAlloc >
bool DGtal::MPolynomial< n, TRing, TAlloc >::operator== ( const MPolynomial< n, TRing, TAlloc > &  q) const
inline

Equality operator.

Parameters
qany polynomial of the same type as this.
Returns
'true' iff this polynomial is equal to q.

Definition at line 1490 of file MPolynomial.h.

1491  {
1492  if (myValue.size() != q.myValue.size())
1493  return false;
1494  for (Size i = 0; i < myValue.size(); ++i)
1495  if (myValue[i] != q[i])
1496  return false;
1497  return true;
1498  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator==() [2/2]

template<int n, typename TRing , class TAlloc >
bool DGtal::MPolynomial< n, TRing, TAlloc >::operator== ( const Ring v) const
inline

Equality operator with a constant.

Parameters
vany value in the ring.
Returns
'true' iff this polynomial is equal to v.

Definition at line 1515 of file MPolynomial.h.

1516  {
1517  if ((v == 0) && (myValue.size() == 0))
1518  return true;
1519  if (myValue.size() != 1)
1520  return false;
1521  return myValue[0] == v;
1522  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator[]() [1/2]

template<int n, typename TRing , class TAlloc >
MPolyNM1& DGtal::MPolynomial< n, TRing, TAlloc >::operator[] ( Size  i)
inline
Returns
a reference to the i-th coefficient. If i > degree(), the array myValue is enlarged. Afterwards, one should better call normalize() to make sure future operations are correct.

Definition at line 1147 of file MPolynomial.h.

1148  {
1149  if (i >= myValue.size())
1150  myValue.resize(i + 1);
1151  return myValue[i];
1152  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::IVector< T, TAlloc, usePointers >::resize(), and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ operator[]() [2/2]

template<int n, typename TRing , class TAlloc >
const MPolyNM1& DGtal::MPolynomial< n, TRing, TAlloc >::operator[] ( Size  i) const
inline
Returns
a reference to the i-th coefficient, or zero if i > degree().

Definition at line 1157 of file MPolynomial.h.

1158  {
1159  return i < myValue.size() ? myValue[i] : myZeroPolynomial;
1160  }

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, DGtal::MPolynomial< n, TRing, TAlloc >::myZeroPolynomial, and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ selfDisplay()

template<int n, typename TRing , class TAlloc >
void DGtal::MPolynomial< n, TRing, TAlloc >::selfDisplay ( std::ostream &  s,
int  N = n 
) const
inline

Prints this polynomial to the stream s. N gives the number of variables; this is needed for recursive printing.

Parameters
sthe output stream where the object is written.
Nthe number of variables.

Definition at line 1546 of file MPolynomial.h.

1547  {
1548  if (isZero())
1549  s << (Ring) 0;
1550  else
1551  {
1552  Size nonzero = 0;
1553  for (Size i = 0; i < myValue.size(); ++i)
1554  if (!myValue[i].isZero())
1555  ++nonzero;
1556  if (nonzero > 1) s << "(";
1557  bool first = true;
1558  for (Size i = 0; i < myValue.size(); ++i)
1559  if (!myValue[i].isZero())
1560  {
1561  if (first) first = false;
1562  else s << " + ";
1563  myValue[i].selfDisplay(s, N);
1564  if (i > 0)
1565  {
1566  s << " ";
1567  s << "X_" << N - n;
1568  if (i > 1) s << "^" << i;
1569  }
1570  }
1571  if (nonzero > 1)
1572  s << ")";
1573  }
1574  }

References DGtal::MPolynomial< n, TRing, TAlloc >::isZero(), DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and DGtal::IVector< T, TAlloc, usePointers >::size().

◆ swap()

template<int n, typename TRing , class TAlloc >
void DGtal::MPolynomial< n, TRing, TAlloc >::swap ( MPolynomial< n, TRing, TAlloc > &  p)
inline

Swaps two polynomials.

Parameters
pthe polynomial to exchange with.

Definition at line 1099 of file MPolynomial.h.

1100  {
1101  myValue.swap(p.myValue);
1102  }
void swap(IVector &v)
Definition: MPolynomial.h:782

References DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and DGtal::IVector< T, TAlloc, usePointers >::swap().

Friends And Related Function Documentation

◆ euclidDiv

template<int n, typename TRing , class TAlloc >
void euclidDiv ( const MPolynomial< 1, TRing, TAlloc > &  ,
const MPolynomial< 1, TRing, TAlloc > &  ,
MPolynomial< 1, TRing, TAlloc > &  ,
MPolynomial< 1, TRing, TAlloc > &   
)
friend

Forward declaration, to be able to declare this as a friend.

◆ MPolynomialDerivativeComputer

template<int n, typename TRing , class TAlloc >
template<int NN, int nn, typename TT , typename AA >
friend class MPolynomialDerivativeComputer
friend

Definition at line 969 of file MPolynomial.h.

◆ MPolynomialEvaluator

template<int n, typename TRing , class TAlloc >
template<int nn, typename TT , typename AA , typename SS >
friend class MPolynomialEvaluator
friend

Definition at line 978 of file MPolynomial.h.

◆ MPolynomialEvaluatorImpl

template<int n, typename TRing , class TAlloc >
template<int nn, typename TT , typename HLHL , typename AA , typename SS >
friend class MPolynomialEvaluatorImpl
friend

Definition at line 981 of file MPolynomial.h.

◆ operator*

template<int n, typename TRing , class TAlloc >
MPolynomial operator* ( const Ring v,
const MPolynomial< n, TRing, TAlloc > &  p 
)
friend

Multiplication by a constant from the left.

Parameters
vany value in the ring.
pany polynomial of this type.
Returns
the corresponding polynomial.

Definition at line 1259 of file MPolynomial.h.

1260  {
1261  MPolynomial r(p);
1262  for ( Size i = 0; i < p.myValue.size(); ++i )
1263  r[i] *= v;
1264  return r;
1265  }

Field Documentation

◆ myValue

template<int n, typename TRing , class TAlloc >
Storage DGtal::MPolynomial< n, TRing, TAlloc >::myValue
private

The vector storing polynomials coefficients. For 0 or 1 variables, uses a standard vector, for more variables, uses a specific vector of pointers to polynomials, with adequate allocators. This is for efficiency purposes.

Definition at line 1008 of file MPolynomial.h.

Referenced by DGtal::MPolynomialDerivativeComputer< 0, n, Ring, Alloc >::computeDerivative(), DGtal::MPolynomialDerivativeComputer< N, n, Ring, Alloc >::computeDerivative(), DGtal::MPolynomial< n, TRing, TAlloc >::degree(), DGtal::MPolynomialEvaluator< n, TRing, TAlloc, TX >::evaluate(), DGtal::MPolynomial< n, TRing, TAlloc >::getAllocator(), DGtal::MPolynomial< 0, TRing, TAlloc >::isZero(), DGtal::MPolynomial< n, TRing, TAlloc >::isZero(), DGtal::MPolynomial< n, TRing, TAlloc >::leading(), DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial(), DGtal::MPolynomial< n, TRing, TAlloc >::normalize(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator const Ring &(), DGtal::MPolynomialEvaluator< n, TRing, TAlloc, TX >::operator MPolyNM1(), DGtal::MPolynomialEvaluator< 1, TRing, TAlloc, TX >::operator X(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator!=(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator()(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator*(), DGtal::MPolynomial< n, TRing, TAlloc >::operator*(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator*=(), DGtal::MPolynomial< n, TRing, TAlloc >::operator*=(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator+(), DGtal::MPolynomial< n, TRing, TAlloc >::operator+=(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator+=(), DGtal::MPolynomial< n, TRing, TAlloc >::operator-(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator-(), DGtal::MPolynomial< n, TRing, TAlloc >::operator-=(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator-=(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator/(), DGtal::MPolynomial< n, TRing, TAlloc >::operator/(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator/=(), DGtal::MPolynomial< n, TRing, TAlloc >::operator/=(), DGtal::MPolynomial< n, TRing, TAlloc >::operator=(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator=(), DGtal::MPolynomial< n, TRing, TAlloc >::operator==(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator==(), DGtal::MPolynomial< n, TRing, TAlloc >::operator[](), DGtal::MPolynomial< n, TRing, TAlloc >::selfDisplay(), DGtal::MPolynomial< 0, TRing, TAlloc >::selfDisplay(), DGtal::MPolynomial< 0, TRing, TAlloc >::swap(), and DGtal::MPolynomial< n, TRing, TAlloc >::swap().

◆ myZeroPolynomial

template<int n, typename TRing , class TAlloc >
MPolyNM1 DGtal::MPolynomial< n, TRing, TAlloc >::myZeroPolynomial
staticprivate

The zero polynomial of n-1 variables for a n-multivariate polynomial.

Definition at line 1001 of file MPolynomial.h.

Referenced by DGtal::MPolynomial< n, TRing, TAlloc >::leading(), and DGtal::MPolynomial< n, TRing, TAlloc >::operator[]().


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