File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
DGtal::MPolynomial< 0, TRing, TAlloc > Class Template Reference

Aim: Specialization of MPolynomial for degree 0. More...

#include <DGtal/math/MPolynomial.h>

Inheritance diagram for DGtal::MPolynomial< 0, 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

 MPolynomial (const Ring &v=0, const Alloc &allocator=Alloc())
 MPolynomial (const Alloc &allocator)
bool isZero () const
 operator const Ring & () const
MPolynomialoperator= (const Ring &v)
Ring operator() () const
MPolynomial operator* (const Ring &v) const
MPolynomial operator/ (const Ring &v) const
MPolynomial operator+ (const Ring &v) const
MPolynomial operator- (const Ring &v) const
MPolynomial operator- () const
MPolynomialoperator*= (const Ring &v)
MPolynomialoperator/= (const Ring &v)
MPolynomialoperator+= (const Ring &v)
MPolynomialoperator-= (const Ring &v)
bool operator== (const Ring &v) const
bool operator!= (const Ring &v) const
void selfDisplay (std::ostream &s, int) const
void swap (MPolynomial &p)
Alloc getAllocator () const
void normalize ()
int degree () const
const MPolyNM1leading () const
MPolyNM1operator[] (Size i)
bool isValid () const

Private Attributes

Alloc myAllocator
Ring myValue

Static Private Attributes

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

Friends

class MPolynomialDerivativeComputer
class MPolynomialEvaluator
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)

Detailed Description

template<typename TRing, typename TAlloc>
class DGtal::MPolynomial< 0, TRing, TAlloc >

Aim: Specialization of MPolynomial for degree 0.

Description of template class 'MPolynomial'

Stores a polynomial of degree 0, i.e. a scalar of type T. We assume that the type T is not "too" complex, otherwise this class will be partially not very effective.

Template Parameters
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 507 of file MPolynomial.h.

Member Typedef Documentation

◆ Alloc

template<typename TRing, typename TAlloc>
typedef TAlloc DGtal::MPolynomial< 0, TRing, TAlloc >::Alloc

Definition at line 511 of file MPolynomial.h.

◆ MPolyNM1

typedef MPolynomial< n - 1, Ring, Alloc > DGtal::MPolynomial< n, TRing, TAlloc >::MPolyNM1

Definition at line 991 of file MPolynomial.h.

◆ Ring

template<typename TRing, typename TAlloc>
typedef TRing DGtal::MPolynomial< 0, TRing, TAlloc >::Ring

Definition at line 510 of file MPolynomial.h.

◆ Size

typedef Storage::Size DGtal::MPolynomial< n, TRing, TAlloc >::Size

Definition at line 1001 of file MPolynomial.h.

◆ Storage

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/2]

template<typename TRing, typename TAlloc>
DGtal::MPolynomial< 0, TRing, TAlloc >::MPolynomial ( const Ring & v = 0,
const Alloc & allocator = Alloc() )
inline

Constructor (default, or from ring value). Creates the constant polynomial v.

Parameters
vany value in the ring.
allocatoran allocator for the polynomial.

Definition at line 526 of file MPolynomial.h.

528 {}
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.

References myAllocator, and myValue.

Referenced by operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/=(), operator=(), and swap().

◆ MPolynomial() [2/2]

template<typename TRing, typename TAlloc>
DGtal::MPolynomial< 0, TRing, TAlloc >::MPolynomial ( const Alloc & allocator)
inline

Allocator constructor. Creates the constant polynomial 0, where 0 is the default value of the ring.

Parameters
allocatoran allocator for the polynomial.

Definition at line 537 of file MPolynomial.h.

References myAllocator, and myValue.

Member Function Documentation

◆ degree()

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

1125 {
1126 return (int)(myValue.size() - 1);
1127 }

◆ getAllocator()

template<typename TRing, typename TAlloc>
Alloc DGtal::MPolynomial< 0, TRing, TAlloc >::getAllocator ( ) const
inline
Returns
the allocator for this object.

Definition at line 712 of file MPolynomial.h.

713 {
714 return myAllocator;
715 }

References myAllocator.

◆ isValid()

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<typename TRing, typename TAlloc>
bool DGtal::MPolynomial< 0, TRing, TAlloc >::isZero ( ) const
inline
Returns
true if the polynomial is 0.

Definition at line 544 of file MPolynomial.h.

545 {
546 return myValue == 0;
547 }

References myValue.

◆ leading()

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 }

◆ normalize()

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 }

◆ operator const Ring &()

template<typename TRing, typename TAlloc>
DGtal::MPolynomial< 0, TRing, TAlloc >::operator const Ring & ( ) const
inline

Const cast operator to Ring value. Returns the coefficient value of this constant polynomial.

Definition at line 553 of file MPolynomial.h.

554 {
555 return myValue;
556 }

References myValue.

◆ operator!=()

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

Difference operator.

Parameters
vany value in the ring.
Returns
true iff myValue is different from v.

Definition at line 686 of file MPolynomial.h.

687 {
688 return myValue != v;
689 }

References myValue.

◆ operator()()

template<typename TRing, typename TAlloc>
Ring DGtal::MPolynomial< 0, TRing, TAlloc >::operator() ( ) const
inline

Evaluation operator for the polynomial.

Returns
the value of its coefficient.

Definition at line 573 of file MPolynomial.h.

574 {
575 return myValue;
576 }

References myValue.

◆ operator*()

template<typename TRing, typename TAlloc>
MPolynomial DGtal::MPolynomial< 0, TRing, TAlloc >::operator* ( const Ring & v) const
inline

Multiplication by value v.

Parameters
vany value in the ring.
Returns
a constant polynomial of coefficient myValue*v.

Definition at line 583 of file MPolynomial.h.

584 {
585 return MPolynomial(myValue * v);
586 }
MPolynomial(const Ring &v=0, const Alloc &allocator=Alloc())

References DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial(), MPolynomial(), and myValue.

◆ operator*=()

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

Self-multiplication by value v.

Parameters
vany value in the ring.
Returns
itself

Definition at line 632 of file MPolynomial.h.

633 {
634 myValue *= v;
635 return *this;
636 }

References MPolynomial(), and myValue.

◆ operator+()

template<typename TRing, typename TAlloc>
MPolynomial DGtal::MPolynomial< 0, TRing, TAlloc >::operator+ ( const Ring & v) const
inline

Addition by value v.

Parameters
vany value in the ring.
Returns
a constant polynomial of coefficient myValue+v.

Definition at line 603 of file MPolynomial.h.

604 {
605 return MPolynomial(myValue + v);
606 }

References DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial(), MPolynomial(), and myValue.

◆ operator+=()

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

Self-addition by value v.

Parameters
vany value in the ring.
Returns
itself

Definition at line 654 of file MPolynomial.h.

655 {
656 myValue += v;
657 return *this;
658 }

References MPolynomial(), and myValue.

◆ operator-() [1/2]

template<typename TRing, typename TAlloc>
MPolynomial DGtal::MPolynomial< 0, TRing, TAlloc >::operator- ( ) const
inline

Unary minus operator.

Returns
a constant polynomial of coefficient -myValue.

Definition at line 622 of file MPolynomial.h.

623 {
624 return MPolynomial(-myValue);
625 }

References DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial(), MPolynomial(), and myValue.

◆ operator-() [2/2]

template<typename TRing, typename TAlloc>
MPolynomial DGtal::MPolynomial< 0, TRing, TAlloc >::operator- ( const Ring & v) const
inline

Subtraction by value v.

Parameters
vany value in the ring.
Returns
a constant polynomial of coefficient myValue-v.

Definition at line 613 of file MPolynomial.h.

614 {
615 return MPolynomial(myValue - v);
616 }

References DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial(), MPolynomial(), and myValue.

◆ operator-=()

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

Self-subtraction by value v.

Parameters
vany value in the ring.
Returns
itself

Definition at line 665 of file MPolynomial.h.

666 {
667 myValue -= v;
668 return *this;
669 }

References MPolynomial(), and myValue.

◆ operator/()

template<typename TRing, typename TAlloc>
MPolynomial DGtal::MPolynomial< 0, TRing, TAlloc >::operator/ ( const Ring & v) const
inline

Division by value v.

Parameters
vany value in the ring.
Returns
a constant polynomial of coefficient myValue/v.

Definition at line 593 of file MPolynomial.h.

594 {
595 return MPolynomial(myValue / v);
596 }

References DGtal::MPolynomial< n, TRing, TAlloc >::MPolynomial(), MPolynomial(), and myValue.

◆ operator/=()

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

Self-division by value v.

Parameters
vany value in the ring.
Returns
itself

Definition at line 643 of file MPolynomial.h.

644 {
645 myValue /= v;
646 return *this;
647 }

References MPolynomial(), and myValue.

◆ operator=()

template<typename TRing, typename TAlloc>
MPolynomial & DGtal::MPolynomial< 0, TRing, TAlloc >::operator= ( const Ring & v)
inline

Assigment from coefficient in the ring.

Parameters
vany value in the ring.
Returns
itself

Definition at line 563 of file MPolynomial.h.

564 {
565 myValue = v;
566 return *this;
567 }

References MPolynomial(), and myValue.

◆ operator==()

template<typename TRing, typename TAlloc>
bool DGtal::MPolynomial< 0, TRing, TAlloc >::operator== ( const Ring & v) const
inline

Equality operator.

Parameters
vany value in the ring.
Returns
true iff myValue is equal to v.

Definition at line 676 of file MPolynomial.h.

677 {
678 return myValue == v;
679 }

References myValue.

◆ operator[]()

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 }

◆ selfDisplay()

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

Outputs itself in the stream s.

Parameters
sany stream

Definition at line 695 of file MPolynomial.h.

696 {
697 s << myValue;
698 }

References myValue.

◆ swap()

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

Swaps two polynomials.

Parameters
pany zero-degree polynomial.

Definition at line 704 of file MPolynomial.h.

705 {
707 }

References MPolynomial(), DGtal::MPolynomial< n, TRing, TAlloc >::myValue, and myValue.

◆ euclidDiv

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

friend class MPolynomialDerivativeComputer
friend

Definition at line 974 of file MPolynomial.h.

◆ MPolynomialEvaluator

friend class MPolynomialEvaluator
friend

Definition at line 983 of file MPolynomial.h.

◆ MPolynomialEvaluatorImpl

friend class MPolynomialEvaluatorImpl
friend

Definition at line 986 of file MPolynomial.h.

Field Documentation

◆ myAllocator

template<typename TRing, typename TAlloc>
Alloc DGtal::MPolynomial< 0, TRing, TAlloc >::myAllocator
private

Definition at line 514 of file MPolynomial.h.

Referenced by getAllocator(), MPolynomial(), and MPolynomial().

◆ myValue

◆ myZeroPolynomial

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: