Processing math: 0%
DGtal 2.0.0
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 std::allocator_traits< Alloc >::template rebind_alloc< MPolyNM1 >,(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.

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 > &f, const MPolynomial< 1, TRing, TAlloc > &g, MPolynomial< 1, TRing, TAlloc > &q, MPolynomial< 1, TRing, TAlloc > &r)
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 969 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 990 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 991 of file MPolynomial.h.

◆ Ring

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

Definition at line 989 of file MPolynomial.h.

◆ Size

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

Definition at line 1001 of file MPolynomial.h.

◆ Storage

template<int n, typename TRing, class TAlloc>
typedef IVector< MPolyNM1, typename std::allocator_traits<Alloc>::template rebind_alloc<MPolyNM1>, (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 1000 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 1019 of file MPolynomial.h.

1020 : myValue(s)
1021 {}
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.

Referenced by DGtal::MPolynomial< 0, TRing, TAlloc >::operator*(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator+(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator-(), DGtal::MPolynomial< 0, TRing, TAlloc >::operator-(), and DGtal::MPolynomial< 0, TRing, TAlloc >::operator/().

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

1051 : myValue( allocator )
1052 {}

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

1058 : myValue( 1, MPolyNM1( v ), allocator )
1059 {}
MPolynomial< n - 1, Ring, Alloc > MPolyNM1

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

1067 : myValue( 1, pdm1 )
1068 {}

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

1077 : myValue( p.degree() + 1, MPolyNM1(), allocator )
1078 {
1079 for ( Size i = 0; i < myValue.size(); ++i )
1080 myValue[i] = p[i];
1081 normalize();
1082 }
Storage::Size 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
Returns
the allocator for this object.

Definition at line 1112 of file MPolynomial.h.

1113 {
1114 return myValue.getAllocator();
1115 }

Referenced by DGtal::derivative(), DGtal::MPolynomial< n - 1, Ring, Alloc >::euclidDiv, DGtal::gcd(), and DGtal::MPolynomial< Space::dimension, Scalar >::operator*().

◆ 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

Tests whether this polynomial is the zero polynomial.

Definition at line 1142 of file MPolynomial.h.

1143 {
1144 return myValue.size() == 0;
1145 }

Referenced by DGtal::gcd(), DGtal::MPolynomial< Space::dimension, Scalar >::normalize(), DGtal::MPolynomial< Space::dimension, Scalar >::operator*(), and DGtal::MPolynomial< Space::dimension, Scalar >::selfDisplay().

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

1135 {
1136 return myValue.size() ? myValue.back() : myZeroPolynomial;
1137 }
static MPolyNM1 myZeroPolynomial
The zero polynomial of n-1 variables for a n-multivariate polynomial.

Referenced by DGtal::MPolynomial< n - 1, Ring, Alloc >::euclidDiv, DGtal::gcd(), and 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 1030 of file MPolynomial.h.

1031 {
1032 Size dp1 = myValue.size();
1033 while ( dp1 )
1034 {
1035 if (myValue[dp1 - 1].isZero())
1036 --dp1;
1037 else
1038 break;
1039 }
1040 if (dp1 < myValue.size())
1041 myValue.resize(dp1);
1042 }
bool isZero() const

Referenced by DGtal::MPolynomialDerivativeComputer< N, n, Ring, Alloc >::computeDerivative(), DGtal::MPolynomialDerivativeComputer< 0, n, Ring, Alloc >::computeDerivative(), DGtal::MPolynomial< n - 1, Ring, Alloc >::euclidDiv, DGtal::Xe_kComputer< n, Ring, Alloc >::get(), DGtal::MPolynomial< Space::dimension, Scalar >::MPolynomial(), DGtal::MPolynomial< Space::dimension, Scalar >::operator*(), DGtal::MPolynomial< Space::dimension, Scalar >::operator+(), DGtal::MPolynomial< Space::dimension, Scalar >::operator+(), DGtal::MPolynomial< Space::dimension, Scalar >::operator+(), DGtal::MPolynomial< Space::dimension, Scalar >::operator+=(), DGtal::MPolynomial< Space::dimension, Scalar >::operator+=(), DGtal::MPolynomial< Space::dimension, Scalar >::operator+=(), DGtal::MPolynomial< Space::dimension, Scalar >::operator-(), DGtal::MPolynomial< Space::dimension, Scalar >::operator-(), DGtal::MPolynomial< Space::dimension, Scalar >::operator-(), DGtal::MPolynomial< Space::dimension, Scalar >::operator-=(), DGtal::MPolynomial< Space::dimension, Scalar >::operator-=(), DGtal::MPolynomial< Space::dimension, Scalar >::operator-=(), and DGtal::MPolynomial< Space::dimension, Scalar >::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 1510 of file MPolynomial.h.

1511 {
1512 return !(*this == q);
1513 }

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

1535 {
1536 return !(*this == v);
1537 }

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

1175 {
1177 }
friend class MPolynomialEvaluator

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

1189 {
1191 }

◆ 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.

Definition at line 1472 of file MPolynomial.h.

1473 {
1474 int d = p.degree() + degree();
1475 if (d < -1)
1476 d = -1;
1477 MPolynomial r( true, d + 1, getAllocator() );
1478 if (!isZero() && !p.isZero())
1479 for ( Size i = 0; i < r.myValue.size(); ++i )
1480 for ( Size j = 0; j < myValue.size(); ++j )
1481 if (i < j + p.myValue.size())
1482 r[i] += myValue[j] * p[i - j];
1483 r.normalize();
1484 return r;
1485 }
Size size() const
Alloc getAllocator() const
MPolynomial(bool, Size s, const Alloc &)

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

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

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

1228 {
1229 return *this = *this * p;
1230 }

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

1238 {
1239 MPolynomial r( *this );
1240 for ( Size i = 0; i < myValue.size(); ++i )
1241 myValue[i] *= v;
1242 return *this;
1243 }

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

1352 {
1353 MPolynomial r(*this);
1354 if (r.myValue.size() < 1)
1355 r.myValue.resize(1);
1356 r[0] += q;
1357 r.normalize();
1358 return r;
1359 }
void resize(Size aSize, const T &entry=T())

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

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

◆ 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 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-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 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 }

◆ 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 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 }

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

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

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

1276 {
1277 MPolynomial r( true, myValue.size(), getAllocator() );
1278 for ( Size i = 0; i < myValue.size(); ++i )
1279 r[i] = -myValue[i];
1280 return r;
1281 }

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

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

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

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

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

1398 {
1399 MPolynomial r(*this);
1400 if (r.myValue.size() < 1)
1401 r.myValue.resize(1);
1402 r[0] -= v;
1403 r.normalize();
1404 return r;
1405 }

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

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

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

1336 {
1337 if (myValue.size() < q.myValue.size())
1338 myValue.resize(q.myValue.size());
1339 for ( Size i = 0; i < q.myValue.size(); ++i )
1340 myValue[i] -= q[i];
1341 normalize();
1342 return *this;
1343 }

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

1457 {
1458 if (myValue.size() < 1)
1459 myValue.resize(1);
1460 myValue[0] -= v;
1461 normalize();
1462 return *this;
1463 }

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

1215 {
1216 MPolynomial r(*this);
1217 for ( Size i = 0; i < myValue.size(); ++i )
1218 r[i] /= v;
1219 return r;
1220 }

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

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

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

1092 {
1093 myValue.resize(p.degree() + 1);
1094 for ( Size i = 0; i < myValue.size(); ++i )
1095 myValue[i] = p[i];
1096 normalize();
1097 return *this;
1098 }

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

1496 {
1497 if (myValue.size() != q.myValue.size())
1498 return false;
1499 for (Size i = 0; i < myValue.size(); ++i)
1500 if (myValue[i] != q[i])
1501 return false;
1502 return true;
1503 }

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

1521 {
1522 if ((v == 0) && (myValue.size() == 0))
1523 return true;
1524 if (myValue.size() != 1)
1525 return false;
1526 return myValue[0] == v;
1527 }

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

1153 {
1154 if (i >= myValue.size())
1155 myValue.resize(i + 1);
1156 return myValue[i];
1157 }

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

1163 {
1164 return i < myValue.size() ? myValue[i] : myZeroPolynomial;
1165 }

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

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

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

1105 {
1106 myValue.swap(p.myValue);
1107 }

◆ euclidDiv

template<int n, typename TRing, class TAlloc>
void euclidDiv ( const MPolynomial< 1, TRing, TAlloc > & f,
const MPolynomial< 1, TRing, TAlloc > & g,
MPolynomial< 1, TRing, TAlloc > & q,
MPolynomial< 1, TRing, TAlloc > & r )
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 974 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

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

1265 {
1266 MPolynomial r(p);
1267 for ( Size i = 0; i < p.myValue.size(); ++i )
1268 r[i] *= v;
1269 return r;
1270 }

Field Documentation

◆ myValue

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

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


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