Polymetic  1.1
A c++ library for polynomial and matrix arithmetic, focused on applications in Kinematics.
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Polynomial< FieldT > Class Template Reference

Contains the definition for the abstract base class which will be used by different multiplication algorithms. More...

#include <Polynomial.hpp>

Collaboration diagram for Polynomial< FieldT >:
Collaboration graph

Public Member Functions

 Polynomial ()
 The default constructor to make the class default constructible. More...
 
 Polynomial (std::initializer_list< FieldT >)
 Constructor to accept init list. More...
 
template<typename InputIt >
 Polynomial (InputIt first, InputIt last)
 Constructor to accept FieldT as input. Needed to support creation of a polynomial with zero degree. It also acts as implicit converting constructor. More...
 
 Polynomial (FieldT c)
 
template<typename convertibleToFieldT >
 Polynomial (convertibleToFieldT v)
 defaulted copy constructor . More...
 
 Polynomial (const Polynomial &rhs)
 
 Polynomial (Polynomial &&rhs)
 Move constructor implemented using swap. More...
 
void appendTerm (FieldT coeff)
 Append new terms by pushing back coefficients. More...
 
const FieldT & operator[] (size_t i) const
 Operator to fetch coefficients. Checks range. More...
 
FieldT & operator[] (size_t i)
 
Polynomial const & operator= (const Polynomial &rhs)
 The assignemnt operator. More...
 
Polynomial const & operator= (Polynomial &&rhs)
 The move assignemnt operator. More...
 
const Polynomialoperator+= (Polynomial const &p2)
 The += operator for polynomials. More...
 
const Polynomialoperator+= (Polynomial &&p2)
 The += operator for polynomials. More...
 
const Polynomialoperator-= (Polynomial const &p2)
 The -= operator for polynomials. More...
 
const Polynomialoperator-= (Polynomial &&p2)
 The -= operator for polynomials using rvalue ref. More...
 
Polynomial operator+ (const Polynomial &p2)
 
  • operator
More...
 
Polynomial operator+ (Polynomial p2) const
 
Polynomial operator- (const Polynomial &p2)
 
  • operator
More...
 
Polynomial operator- (Polynomial p2) const
 
size_t size ()
 
size_t size () const
 

Private Member Functions

void trim ()
 Use to maintain the invariant 1. More...
 
Polynomialminus ()
 Flip the sign of all coefs. More...
 

Private Attributes

std::list< FieldT > m_coefs
 
size_t m_size
 

Friends

class PolynomialMultiplicationInterface< FieldT >
 
void swap (Polynomial &lhs, Polynomial &rhs) noexcept
 A non-template friend swap to aid in the implementation of copy-and-swap. More...
 
Polynomial operator- (Polynomial const &rhs)
 The unary (-) operator. More...
 
Polynomial operator- (Polynomial &&temp)
 
std::ostream & operator<< (std::ostream &os, const Polynomial &p)
 

Detailed Description

template<typename FieldT>
class Polynomial< FieldT >

Contains the definition for the abstract base class which will be used by different multiplication algorithms.

Template class used for polynomial.

<

Todo:
for uniqe_ptr, can this be done using forward declaration ?
Template Parameters
FieldTThe field class. The field should support all arithmethic unary and binary operations with values 1 and 0 like, +1, *1, ==1,+0,*0,==0, etc.

Properties

  • Invariants
    1. The last coefficent will always be non-zero.

Definition at line 40 of file Polynomial.hpp.

Constructor & Destructor Documentation

template<typename FieldT>
Polynomial< FieldT >::Polynomial ( )
inline

The default constructor to make the class default constructible.

Definition at line 47 of file Polynomial.hpp.

template<typename FieldT >
Polynomial< FieldT >::Polynomial ( std::initializer_list< FieldT >  in_list)

Constructor to accept init list.

Parameters
in_listInitializer list of coefficients. Starting with the x^0

Definition at line 32 of file Polynomial_impl.ipp.

template<typename FieldT >
template<typename InputIt >
Polynomial< FieldT >::Polynomial ( InputIt  first,
InputIt  last 
)

Constructor to accept FieldT as input. Needed to support creation of a polynomial with zero degree. It also acts as implicit converting constructor.

Analogous to std containers, this constructor is provided to create a polynomial from any container which supports forward iterators.

Constructs the polynomial coeffs with the contents of the range [first, last)

Definition at line 42 of file Polynomial_impl.ipp.

template<typename FieldT >
Polynomial< FieldT >::Polynomial ( FieldT  c)
Parameters
in_listInitializer list of coefficients. Starting with the x^0

Definition at line 54 of file Polynomial_impl.ipp.

template<typename FieldT >
template<typename convertibleToFieldT >
Polynomial< FieldT >::Polynomial ( convertibleToFieldT  v)

defaulted copy constructor .

Definition at line 63 of file Polynomial_impl.ipp.

References Polynomial< FieldT >::m_size, and Polynomial< FieldT >::trim().

Here is the call graph for this function:

template<typename FieldT>
Polynomial< FieldT >::Polynomial ( const Polynomial< FieldT > &  rhs)
inline

Definition at line 64 of file Polynomial.hpp.

References Polynomial< FieldT >::m_coefs.

template<typename FieldT>
Polynomial< FieldT >::Polynomial ( Polynomial< FieldT > &&  rhs)
inline

Move constructor implemented using swap.

Definition at line 73 of file Polynomial.hpp.

References Polynomial< FieldT >::swap.

Member Function Documentation

template<typename FieldT >
void Polynomial< FieldT >::appendTerm ( FieldT  coeff)

Append new terms by pushing back coefficients.

Definition at line 73 of file Polynomial_impl.ipp.

References Polynomial< FieldT >::m_coefs, and Polynomial< FieldT >::m_size.

Referenced by main(), PolynomialMultiplicationSimple< FieldT >::multiply(), readPolynomialFromFile(), and TEST_F().

Here is the caller graph for this function:

template<typename FieldT >
Polynomial< FieldT > & Polynomial< FieldT >::minus ( )
private

Flip the sign of all coefs.

Definition at line 276 of file Polynomial_impl.ipp.

References Polynomial< FieldT >::m_coefs.

Referenced by TEST_F().

Here is the caller graph for this function:

template<typename FieldT >
Polynomial< FieldT > Polynomial< FieldT >::operator+ ( const Polynomial< FieldT > &  p2)

  • operator

Definition at line 231 of file Polynomial_impl.ipp.

template<typename FieldT >
Polynomial< FieldT > Polynomial< FieldT >::operator+ ( Polynomial< FieldT >  p2) const

Definition at line 220 of file Polynomial_impl.ipp.

template<typename FieldT >
Polynomial< FieldT > const & Polynomial< FieldT >::operator+= ( Polynomial< FieldT > const &  p2)

The += operator for polynomials.

Implemented using copy-and-add in sequence. This is cleaner but a bit inefficient(possibly). Reconsider for performance optimization later. We cannot use implicit copying by using pass by value becuse RVO will not work on input argument of a function.

Todo:
Do away with the copying by using better approach.

Definition at line 143 of file Polynomial_impl.ipp.

References Polynomial< FieldT >::m_coefs, Polynomial< FieldT >::size(), Polynomial< FieldT >::swap, and Polynomial< FieldT >::trim().

Here is the call graph for this function:

template<typename FieldT >
Polynomial< FieldT > const & Polynomial< FieldT >::operator+= ( Polynomial< FieldT > &&  p2)

The += operator for polynomials.

Definition at line 170 of file Polynomial_impl.ipp.

References Polynomial< FieldT >::m_coefs, Polynomial< FieldT >::size(), Polynomial< FieldT >::swap, and Polynomial< FieldT >::trim().

Here is the call graph for this function:

template<typename FieldT>
Polynomial Polynomial< FieldT >::operator- ( const Polynomial< FieldT > &  p2)

  • operator

template<typename FieldT >
Polynomial< FieldT > Polynomial< FieldT >::operator- ( Polynomial< FieldT >  p2) const

Definition at line 239 of file Polynomial_impl.ipp.

template<typename FieldT >
Polynomial< FieldT > const & Polynomial< FieldT >::operator-= ( Polynomial< FieldT > const &  p2)

The -= operator for polynomials.

Todo:
Do away with the copying by using better approach.

Definition at line 197 of file Polynomial_impl.ipp.

template<typename FieldT >
Polynomial< FieldT > const & Polynomial< FieldT >::operator-= ( Polynomial< FieldT > &&  p2)

The -= operator for polynomials using rvalue ref.

Definition at line 208 of file Polynomial_impl.ipp.

template<typename FieldT >
Polynomial< FieldT > const & Polynomial< FieldT >::operator= ( const Polynomial< FieldT > &  rhs)

The assignemnt operator.

Parameters
[in]RHSfor the assignment

We avoid explicit copying by passing the rhs by value. Hence the call to the copy constructor and the copy operation become implicit.

Definition at line 105 of file Polynomial_impl.ipp.

References Polynomial< FieldT >::swap.

template<typename FieldT >
Polynomial< FieldT > const & Polynomial< FieldT >::operator= ( Polynomial< FieldT > &&  rhs)

The move assignemnt operator.

Parameters
[in]RHSfor the assignment

Definition at line 121 of file Polynomial_impl.ipp.

References Polynomial< FieldT >::swap.

template<typename FieldT >
const FieldT & Polynomial< FieldT >::operator[] ( size_t  i) const

Operator to fetch coefficients. Checks range.

Exception Guarantee: Strong
The program is in a state as before the call
Parameters
iPower of the x whose coefficient we want

Definition at line 82 of file Polynomial_impl.ipp.

References Polynomial< FieldT >::m_coefs, and Polynomial< FieldT >::m_size.

template<typename FieldT >
FieldT & Polynomial< FieldT >::operator[] ( size_t  i)

Definition at line 94 of file Polynomial_impl.ipp.

template<typename FieldT>
size_t Polynomial< FieldT >::size ( )
inline
template<typename FieldT>
size_t Polynomial< FieldT >::size ( ) const
inline

Definition at line 156 of file Polynomial.hpp.

References Polynomial< FieldT >::m_size.

template<typename FieldT >
void Polynomial< FieldT >::trim ( )
private

Use to maintain the invariant 1.

Definition at line 258 of file Polynomial_impl.ipp.

References Polynomial< FieldT >::m_coefs, Polynomial< FieldT >::m_size, and Polynomial< FieldT >::size().

Referenced by Polynomial< FieldT >::operator+=(), and Polynomial< FieldT >::Polynomial().

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

template<typename FieldT >
Polynomial< FieldT > Polynomial< FieldT >::operator- ( Polynomial< FieldT > const &  rhs)
friend

The unary (-) operator.

Definition at line 114 of file Polynomial.hpp.

template<typename FieldT>
Polynomial operator- ( Polynomial< FieldT > &&  temp)
friend
Todo:
Find out why the move() is needed. RVO does not work on it own but has to be forced using move() here

Definition at line 122 of file Polynomial.hpp.

template<typename FieldT>
std::ostream& operator<< ( std::ostream &  os,
const Polynomial< FieldT > &  p 
)
friend

Definition at line 157 of file Polynomial.hpp.

template<typename FieldT>
friend class PolynomialMultiplicationInterface< FieldT >
friend

Definition at line 183 of file Polynomial.hpp.

template<typename FieldT>
void swap ( Polynomial< FieldT > &  lhs,
Polynomial< FieldT > &  rhs 
)
friend

A non-template friend swap to aid in the implementation of copy-and-swap.

Parameters
[in]lhsLHS for the swap
[in]rhsRHS for the swap {No throw}{The swap does not allocate any memory and hence should never throw}

Definition at line 97 of file Polynomial.hpp.

Referenced by Polynomial< FieldT >::operator+=(), Polynomial< FieldT >::operator=(), and Polynomial< FieldT >::Polynomial().

Member Data Documentation

template<typename FieldT>
std::list<FieldT> Polynomial< FieldT >::m_coefs
private
Todo:
Use a general container instead of std::list as the choice of container would depend on the algorithm class which is used for multiplication and addition.

The list of coefficients

Definition at line 169 of file Polynomial.hpp.

Referenced by Polynomial< FieldT >::appendTerm(), PolynomialMultiplicationInterface< FieldT >::getPolynomialCoefficients(), Polynomial< FieldT >::minus(), Polynomial< FieldT >::operator+=(), Polynomial< FieldT >::operator[](), Polynomial< FieldT >::Polynomial(), and Polynomial< FieldT >::trim().

template<typename FieldT>
size_t Polynomial< FieldT >::m_size
private

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