DGtal 1.3.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
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>

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
Examples
math/polynomial-derivative.cpp, math/polynomial-read.cpp, math/polynomial2-derivative.cpp, and topology/trackImplicitPolynomialSurfaceToOFF.cpp.

Definition at line 954 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 975 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 976 of file MPolynomial.h.

◆ Ring

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

Definition at line 974 of file MPolynomial.h.

◆ Size

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

Definition at line 986 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 985 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

Private constructor for initializing an array of size s.

Definition at line 1004 of file MPolynomial.h.

1005 : myValue(s)
1006 {}

◆ 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 1035 of file MPolynomial.h.

1036 : myValue( allocator )
1037 {}

◆ 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 1042 of file MPolynomial.h.

1043 : myValue( 1, MPolyNM1( v ), allocator )
1044 {}
MPolynomial< n - 1, Ring, Alloc > MPolyNM1
Definition: MPolynomial.h:976

◆ 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 1050 of file MPolynomial.h.

1052 : myValue( 1, pdm1 )
1053 {}

◆ 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 1060 of file MPolynomial.h.

1062 : myValue( p.degree() + 1, MPolyNM1(), allocator )
1063 {
1064 for ( Size i = 0; i < myValue.size(); ++i )
1065 myValue[i] = p[i];
1066 normalize();
1067 }
Size size() const
Definition: MPolynomial.h:742
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

◆ 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 1119 of file MPolynomial.h.

1120 {
1121 return myValue.size() ? myValue.back() : myZeroPolynomial;
1122 }
const T & back() const
Definition: MPolynomial.h:762
static MPolyNM1 myZeroPolynomial
The zero polynomial of n-1 variables for a n-multivariate polynomial.
Definition: MPolynomial.h:991

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 1015 of file MPolynomial.h.

1016 {
1017 Size dp1 = myValue.size();
1018 while ( dp1 )
1019 {
1020 if (myValue[dp1 - 1].isZero())
1021 --dp1;
1022 else
1023 break;
1024 }
1025 if (dp1 < myValue.size())
1026 myValue.resize(dp1);
1027 }
void resize(Size aSize, const T &entry=T())
Definition: MPolynomial.h:747
bool isZero() const
Definition: MPolynomial.h:1127

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 1495 of file MPolynomial.h.

1496 {
1497 return !(*this == q);
1498 }

◆ 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 1519 of file MPolynomial.h.

1520 {
1521 return !(*this == v);
1522 }

◆ 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 1159 of file MPolynomial.h.

1160 {
1161 return MPolynomialEvaluator<n, Ring, Alloc, Ring>( *this, x );
1162 }

◆ 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 1173 of file MPolynomial.h.

1174 {
1175 return MPolynomialEvaluator<n, Ring, Alloc, Ring2>( *this, x );
1176 }

◆ 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 1457 of file MPolynomial.h.

1458 {
1459 int d = p.degree() + degree();
1460 if (d < -1)
1461 d = -1;
1462 MPolynomial r( true, d + 1, getAllocator() );
1463 if (!isZero() && !p.isZero())
1464 for ( Size i = 0; i < r.myValue.size(); ++i )
1465 for ( Size j = 0; j < myValue.size(); ++j )
1466 if (i < j + p.myValue.size())
1467 r[i] += myValue[j] * p[i - j];
1468 r.normalize();
1469 return r;
1470 }
Alloc getAllocator() const
Definition: MPolynomial.h:1097
int degree() const
Definition: MPolynomial.h:1109
MPolynomial(bool, Size s, const Alloc &)
Definition: MPolynomial.h:1004

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 1186 of file MPolynomial.h.

1187 {
1188 MPolynomial r(*this);
1189 for ( Size i = 0; i < myValue.size(); ++i )
1190 r[i] *= v;
1191 return r;
1192 }

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 1212 of file MPolynomial.h.

1213 {
1214 return *this = *this * p;
1215 }

◆ 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 1222 of file MPolynomial.h.

1223 {
1224 MPolynomial r( *this );
1225 for ( Size i = 0; i < myValue.size(); ++i )
1226 myValue[i] *= v;
1227 return *this;
1228 }

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 1336 of file MPolynomial.h.

1337 {
1338 MPolynomial r(*this);
1339 if (r.myValue.size() < 1)
1340 r.myValue.resize(1);
1341 r[0] += q;
1342 r.normalize();
1343 return r;
1344 }

◆ 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 1273 of file MPolynomial.h.

1274 {
1275 MPolynomial r(*this);
1276 if (r.myValue.size() < q.myValue.size())
1277 r.myValue.resize(q.myValue.size());
1278 for ( Size i = 0; i < q.myValue.size(); ++i )
1279 r[i] += q[i];
1280 r.normalize();
1281 return r;
1282 }

◆ 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 1367 of file MPolynomial.h.

1368 {
1369 MPolynomial r(*this);
1370 if (r.myValue.size() < 1)
1371 r.myValue.resize(1);
1372 r[0] += v;
1373 r.normalize();
1374 return r;
1375 }

◆ 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 1398 of file MPolynomial.h.

1399 {
1400 if (myValue.size() < 1)
1401 myValue.resize(1);
1402 myValue[0] += q;
1403 normalize();
1404 return *this;
1405 }

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 1305 of file MPolynomial.h.

1306 {
1307 if (myValue.size() < q.myValue.size())
1308 myValue.resize(q.myValue.size());
1309 for ( Size i = 0; i < q.myValue.size(); ++i )
1310 myValue[i] += q[i];
1311 normalize();
1312 return *this;
1313 }

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 1427 of file MPolynomial.h.

1428 {
1429 if (myValue.size() < 1)
1430 myValue.resize(1);
1431 myValue[0] += v;
1432 normalize();
1433 return *this;
1434 }

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 1260 of file MPolynomial.h.

1261 {
1262 MPolynomial r( true, myValue.size(), getAllocator() );
1263 for ( Size i = 0; i < myValue.size(); ++i )
1264 r[i] = -myValue[i];
1265 return r;
1266 }

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 1352 of file MPolynomial.h.

1353 {
1354 MPolynomial r(*this);
1355 if (r.myValue.size() < 1)
1356 r.myValue.resize(1);
1357 r[0] -= q;
1358 r.normalize();
1359 return r;
1360 }

◆ 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 1289 of file MPolynomial.h.

1290 {
1291 MPolynomial r(*this);
1292 if (r.myValue.size() < q.myValue.size())
1293 r.myValue.resize(q.myValue.size());
1294 for ( Size i = 0; i < q.myValue.size(); ++i )
1295 r[i] -= q[i];
1296 r.normalize();
1297 return r;
1298 }

◆ 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 1382 of file MPolynomial.h.

1383 {
1384 MPolynomial r(*this);
1385 if (r.myValue.size() < 1)
1386 r.myValue.resize(1);
1387 r[0] -= v;
1388 r.normalize();
1389 return r;
1390 }

◆ 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 1413 of file MPolynomial.h.

1414 {
1415 if (myValue.size() < 1)
1416 myValue.resize(1);
1417 myValue[0] -= q;
1418 normalize();
1419 return *this;
1420 }

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 1320 of file MPolynomial.h.

1321 {
1322 if (myValue.size() < q.myValue.size())
1323 myValue.resize(q.myValue.size());
1324 for ( Size i = 0; i < q.myValue.size(); ++i )
1325 myValue[i] -= q[i];
1326 normalize();
1327 return *this;
1328 }

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 1441 of file MPolynomial.h.

1442 {
1443 if (myValue.size() < 1)
1444 myValue.resize(1);
1445 myValue[0] -= v;
1446 normalize();
1447 return *this;
1448 }

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 1199 of file MPolynomial.h.

1200 {
1201 MPolynomial r(*this);
1202 for ( Size i = 0; i < myValue.size(); ++i )
1203 r[i] /= v;
1204 return r;
1205 }

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 1235 of file MPolynomial.h.

1236 {
1237 for ( Size i = 0; i < myValue.size(); ++i )
1238 myValue[i] /= v;
1239 return *this;
1240 }

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 1075 of file MPolynomial.h.

1077 {
1078 myValue.resize(p.degree() + 1);
1079 for ( Size i = 0; i < myValue.size(); ++i )
1080 myValue[i] = p[i];
1081 normalize();
1082 return *this;
1083 }

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 1480 of file MPolynomial.h.

1481 {
1482 if (myValue.size() != q.myValue.size())
1483 return false;
1484 for (Size i = 0; i < myValue.size(); ++i)
1485 if (myValue[i] != q[i])
1486 return false;
1487 return true;
1488 }

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 1505 of file MPolynomial.h.

1506 {
1507 if ((v == 0) && (myValue.size() == 0))
1508 return true;
1509 if (myValue.size() != 1)
1510 return false;
1511 return myValue[0] == v;
1512 }

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 1137 of file MPolynomial.h.

1138 {
1139 if (i >= myValue.size())
1140 myValue.resize(i + 1);
1141 return myValue[i];
1142 }

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 1147 of file MPolynomial.h.

1148 {
1149 return i < myValue.size() ? myValue[i] : myZeroPolynomial;
1150 }

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 1536 of file MPolynomial.h.

1537 {
1538 if (isZero())
1539 s << (Ring) 0;
1540 else
1541 {
1542 Size nonzero = 0;
1543 for (Size i = 0; i < myValue.size(); ++i)
1544 if (!myValue[i].isZero())
1545 ++nonzero;
1546 if (nonzero > 1) s << "(";
1547 bool first = true;
1548 for (Size i = 0; i < myValue.size(); ++i)
1549 if (!myValue[i].isZero())
1550 {
1551 if (first) first = false;
1552 else s << " + ";
1553 myValue[i].selfDisplay(s, N);
1554 if (i > 0)
1555 {
1556 s << " ";
1557 s << "X_" << N - n;
1558 if (i > 1) s << "^" << i;
1559 }
1560 }
1561 if (nonzero > 1)
1562 s << ")";
1563 }
1564 }

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 1089 of file MPolynomial.h.

1090 {
1091 myValue.swap(p.myValue);
1092 }
void swap(IVector &v)
Definition: MPolynomial.h:772

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 959 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 968 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 971 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 1249 of file MPolynomial.h.

1250 {
1251 MPolynomial r(p);
1252 for ( Size i = 0; i < p.myValue.size(); ++i )
1253 r[i] *= v;
1254 return r;
1255 }

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 998 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 991 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: