Polymetic
1.1
A c++ library for polynomial and matrix arithmetic, focused on applications in Kinematics.
|
Contains the definition for the abstract base class which will be used by different multiplication algorithms. More...
#include <Polynomial.hpp>
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 Polynomial & | operator+= (Polynomial const &p2) |
The += operator for polynomials. More... | |
const Polynomial & | operator+= (Polynomial &&p2) |
The += operator for polynomials. More... | |
const Polynomial & | operator-= (Polynomial const &p2) |
The -= operator for polynomials. More... | |
const Polynomial & | operator-= (Polynomial &&p2) |
The -= operator for polynomials using rvalue ref. More... | |
Polynomial | operator+ (const Polynomial &p2) |
| |
Polynomial | operator+ (Polynomial p2) const |
Polynomial | operator- (const Polynomial &p2) |
| |
Polynomial | operator- (Polynomial p2) const |
size_t | size () |
size_t | size () const |
Private Member Functions | |
void | trim () |
Use to maintain the invariant 1. More... | |
Polynomial & | minus () |
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) |
Contains the definition for the abstract base class which will be used by different multiplication algorithms.
Template class used for polynomial.
<
FieldT | The 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
Definition at line 40 of file Polynomial.hpp.
|
inline |
The default constructor to make the class default constructible.
Definition at line 47 of file Polynomial.hpp.
Polynomial< FieldT >::Polynomial | ( | std::initializer_list< FieldT > | in_list | ) |
Constructor to accept init list.
in_list | Initializer list of coefficients. Starting with the x^0 |
Definition at line 32 of file Polynomial_impl.ipp.
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.
Polynomial< FieldT >::Polynomial | ( | FieldT | c | ) |
in_list | Initializer list of coefficients. Starting with the x^0 |
Definition at line 54 of file Polynomial_impl.ipp.
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().
|
inline |
Definition at line 64 of file Polynomial.hpp.
References Polynomial< FieldT >::m_coefs.
|
inline |
Move constructor implemented using swap.
Definition at line 73 of file Polynomial.hpp.
References Polynomial< FieldT >::swap.
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().
|
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().
Polynomial< FieldT > Polynomial< FieldT >::operator+ | ( | const Polynomial< FieldT > & | p2 | ) |
Definition at line 231 of file Polynomial_impl.ipp.
Polynomial< FieldT > Polynomial< FieldT >::operator+ | ( | Polynomial< FieldT > | p2 | ) | const |
Definition at line 220 of file Polynomial_impl.ipp.
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.
Definition at line 143 of file Polynomial_impl.ipp.
References Polynomial< FieldT >::m_coefs, Polynomial< FieldT >::size(), Polynomial< FieldT >::swap, and Polynomial< FieldT >::trim().
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().
Polynomial Polynomial< FieldT >::operator- | ( | const Polynomial< FieldT > & | p2 | ) |
Polynomial< FieldT > Polynomial< FieldT >::operator- | ( | Polynomial< FieldT > | p2 | ) | const |
Definition at line 239 of file Polynomial_impl.ipp.
Polynomial< FieldT > const & Polynomial< FieldT >::operator-= | ( | Polynomial< FieldT > const & | p2 | ) |
The -= operator for polynomials.
Definition at line 197 of file Polynomial_impl.ipp.
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.
Polynomial< FieldT > const & Polynomial< FieldT >::operator= | ( | const Polynomial< FieldT > & | rhs | ) |
The assignemnt operator.
[in] | RHS | for 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.
Polynomial< FieldT > const & Polynomial< FieldT >::operator= | ( | Polynomial< FieldT > && | rhs | ) |
The move assignemnt operator.
[in] | RHS | for the assignment |
Definition at line 121 of file Polynomial_impl.ipp.
References Polynomial< FieldT >::swap.
const FieldT & Polynomial< FieldT >::operator[] | ( | size_t | i | ) | const |
Operator to fetch coefficients. Checks range.
i | Power 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.
FieldT & Polynomial< FieldT >::operator[] | ( | size_t | i | ) |
Definition at line 94 of file Polynomial_impl.ipp.
|
inline |
Definition at line 155 of file Polynomial.hpp.
References Polynomial< FieldT >::m_size.
Referenced by PolynomialMultiplicationSimple< FieldT >::multiply(), Polynomial< FieldT >::operator+=(), operator==(), TEST_F(), and Polynomial< FieldT >::trim().
|
inline |
Definition at line 156 of file Polynomial.hpp.
References Polynomial< FieldT >::m_size.
|
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().
|
friend |
The unary (-) operator.
Definition at line 114 of file Polynomial.hpp.
|
friend |
Definition at line 122 of file Polynomial.hpp.
|
friend |
Definition at line 157 of file Polynomial.hpp.
|
friend |
Definition at line 183 of file Polynomial.hpp.
|
friend |
A non-template friend swap to aid in the implementation of copy-and-swap.
[in] | lhs | LHS for the swap |
[in] | rhs | RHS 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().
|
private |
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().
|
private |
Number of terms in the polynomial
Definition at line 170 of file Polynomial.hpp.
Referenced by Polynomial< FieldT >::appendTerm(), Polynomial< FieldT >::operator[](), Polynomial< FieldT >::Polynomial(), Polynomial< FieldT >::size(), and Polynomial< FieldT >::trim().