Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::polynomial::Polynomial< T > Class Template Reference

Template class to represent and operate on polynomials. More...

#include <polynomial1d.hpp>

Inheritance diagram for vulpes::polynomial::Polynomial< T >:
[legend]
Collaboration diagram for vulpes::polynomial::Polynomial< T >:
[legend]

Public Member Functions

 Polynomial ()
 Default constructor. Constructs a polynomial with a zero term.
 Polynomial (std::size_t size)
 Constructor. Constructs a polynomial with a given size.
 Polynomial (const std::vector< T > &coeffs)
 Constructs a polynomial with the given coefficients.
auto & data ()
const auto & data () const
std::size_t degree () const
 Returns the degree of the polynomial.
constexpr std::size_t size () const
 Returns the number of the monomials.
const T & operator[] (std::size_t i) const
 Accesses the coefficient of the x^i term.
const T & coef (std::size_t i) const
 Accesses the coefficient of the x^i term.
T & coef (std::size_t i)
 Accesses the coefficient of the x^i term.
Polynomial< T > derivative () const
 Computes the derivative of the polynomial.
Polynomial< T > derivative (std::size_t component) const
 Computes the derivative of the polynomial.
Eigen::Vector< Polynomial< T >, 1 > gradient () const
 Computes the derivative of the polynomial.
void derivative_ ()
 Computes the derivative of the polynomial in place.
T integrate (const T &left, const T &right) const
 Computes the definite integral of the polynomial between two bounds.
Polynomial< T > primitive (const T &c=T(0)) const
 Computes the indefinite integral (primitive) of the polynomial.
void primitive_ (const T &ordinate=T(0), const T &target_value=T(0))
 Computes the indefinite integral (primitive) of the polynomial in place.
T evaluate (const T &x) const
 Evaluates the polynomial at a given point using Horner's method.
T evaluate (const Eigen::Vector< T, 1 > &x) const
T evaluate (const T *x) const
T integrate (const Eigen::Map< Eigen::Vector< T, -1 > > &monomial_integrals) const
Polynomial< T > substitute (const Polynomial< T > &poly) const
 Substitutes another polynomial into the current polynomial.
template<typename U>
Polynomial< U > to () const
 Converts the underlying type of the polynomial's coefficients to another type.
Polynomial< T > & operator+= (const Polynomial< T > &other)
 Adds another polynomial to the current polynomial in place.
Polynomial< T > & operator-= (const Polynomial< T > &other)
 Subtracts another polynomial from the current polynomial in place.
Polynomial< T > & operator*= (const Polynomial< T > &other)
 Multiplies the current polynomial by another polynomial in place.
Polynomial< T > & operator*= (const T &scalar)
 Multiplies the polynomial by a scalar in place.
Polynomial< T > & operator/= (const T &scalar)
 Divides the polynomial by a scalar in place.
Polynomial< T > & operator%= (const Polynomial< T > &divisor)
 Computes the remainder of dividing the current polynomial by another polynomial in place.
Polynomial< T > & operator/= (const Polynomial< T > &divisor)
 Divides the current polynomial by another polynomial in place.
T integrate (const datastructure::SimplexDataView< Dim, SimplexData, T, std::size_t > &monomial_integrals) const
 Integrate the polynomial given the monomials integrals.
Polynomial primitive (std::size_t component) const
 Compute the primitive of the polynomial.

Static Public Member Functions

static void divide (const Polynomial< T > &divisor, Polynomial< T > &quotient, Polynomial< T > &remainder)
 Divides one polynomial by another, updating the quotient and remainder.

Protected Member Functions

void trim ()
 Removes leading zeros from the coefficients vector.
Polynomial * self ()

Protected Attributes

std::vector< T > m_coefficients
 Vector storing the coefficients of the polynomial.

Friends

Polynomial< T > operator/ (Polynomial< T > lhs, const Polynomial< T > &rhs)
 Friend function to compute the remainder of dividing one polynomial by another.
Polynomial< T > operator% (Polynomial< T > lhs, const Polynomial< T > &rhs)
 Friend function to compute the remainder of dividing one polynomial by another.
bool operator== (const Polynomial< T > &lhs, const Polynomial< T > &rhs)
 Compares two polynomials for equality.
std::ostream & operator<< (std::ostream &os, const Polynomial< T > &poly)
 Friend function to output a polynomial to an output stream.

Detailed Description

template<typename T>
class vulpes::polynomial::Polynomial< T >

Template class to represent and operate on polynomials.

This file contains the implementation of a polynomial class template that supports various operations, including addition, subtraction, multiplication, division, differentiation, integration, and more.

Constructor & Destructor Documentation

◆ Polynomial() [1/3]

template<typename T>
vulpes::polynomial::Polynomial< T >::Polynomial ( )
inlineexplicit

Default constructor. Constructs a polynomial with a zero term.

◆ Polynomial() [2/3]

template<typename T>
vulpes::polynomial::Polynomial< T >::Polynomial ( std::size_t size)
inlineexplicit

Constructor. Constructs a polynomial with a given size.

◆ Polynomial() [3/3]

template<typename T>
vulpes::polynomial::Polynomial< T >::Polynomial ( const std::vector< T > & coeffs)
inlineexplicit

Constructs a polynomial with the given coefficients.

Parameters
coeffsVector of coefficients, where the i-th element represents the coefficient of the x^i term.

Member Function Documentation

◆ coef() [1/2]

template<typename T>
T & vulpes::polynomial::Polynomial< T >::coef ( std::size_t i)
inline

Accesses the coefficient of the x^i term.

Parameters
iThe index of the coefficient to access.
Returns
The reference to coefficient of the x^i term

◆ coef() [2/2]

template<typename T>
const T & vulpes::polynomial::Polynomial< T >::coef ( std::size_t i) const
inline

Accesses the coefficient of the x^i term.

Parameters
iThe index of the coefficient to access.
Returns
The const reference to coefficient of the x^i term

◆ data() [1/2]

template<typename T>
auto & vulpes::polynomial::Polynomial< T >::data ( )
inline

◆ data() [2/2]

template<typename T>
const auto & vulpes::polynomial::Polynomial< T >::data ( ) const
inline

◆ degree()

template<typename T>
std::size_t vulpes::polynomial::Polynomial< T >::degree ( ) const
inline

Returns the degree of the polynomial.

Returns
The degree of the polynomial.

◆ derivative() [1/2]

template<typename T>
Polynomial< T > vulpes::polynomial::Polynomial< T >::derivative ( ) const
inline

Computes the derivative of the polynomial.

Returns
A new polynomial representing the derivative of the current polynomial.

◆ derivative() [2/2]

template<typename T>
Polynomial< T > vulpes::polynomial::Polynomial< T >::derivative ( std::size_t component) const
inline

Computes the derivative of the polynomial.

Returns
A new polynomial representing the derivative of the current polynomial.

◆ derivative_()

template<typename T>
void vulpes::polynomial::Polynomial< T >::derivative_ ( )
inline

Computes the derivative of the polynomial in place.

This function modifies the current polynomial to be its derivative.

◆ divide()

template<typename T>
void vulpes::polynomial::Polynomial< T >::divide ( const Polynomial< T > & divisor,
Polynomial< T > & quotient,
Polynomial< T > & remainder )
inlinestatic

Divides one polynomial by another, updating the quotient and remainder.

Parameters
divisorThe polynomial to divide by.
quotientThe quotient polynomial (output).
remainderThe remainder polynomial (output).
Note
The method is not well-defined for integral point types. Ensure T is not an integral type.

◆ evaluate() [1/3]

template<typename T>
T vulpes::polynomial::Polynomial< T >::evaluate ( const Eigen::Vector< T, 1 > & x) const
inline

◆ evaluate() [2/3]

template<typename T>
T vulpes::polynomial::Polynomial< T >::evaluate ( const T & x) const
inline

Evaluates the polynomial at a given point using Horner's method.

Horner's method is used to efficiently evaluate the polynomial of degree \( n \) at a given point \( x \). The polynomial:

\[P(x) = a_n x^n + a_{n-1} x^{n-1} + \dots + a_1 x + a_0 \]

is rewritten using Horner's rule as:

\[P(x) = (((a_n x + a_{n-1}) x + a_{n-2}) x + \dots + a_1) x + a_0 \]

This reduces the number of multiplications needed to evaluate the polynomial.

Parameters
xThe point at which to evaluate the polynomial.
Returns
The value of the polynomial at the point x.

◆ evaluate() [3/3]

template<typename T>
T vulpes::polynomial::Polynomial< T >::evaluate ( const T * x) const
inline

◆ gradient()

template<typename T>
Eigen::Vector< Polynomial< T >, 1 > vulpes::polynomial::Polynomial< T >::gradient ( ) const
inline

Computes the derivative of the polynomial.

Returns
A new polynomial representing the derivative of the current polynomial.

◆ integrate() [1/3]

template<typename T>
T vulpes::polynomial::Polynomial< T >::integrate ( const Eigen::Map< Eigen::Vector< T, -1 > > & monomial_integrals) const
inline

◆ integrate() [2/3]

template<typename T>
T vulpes::polynomial::Polynomial< T >::integrate ( const T & left,
const T & right ) const
inline

Computes the definite integral of the polynomial between two bounds.

Parameters
leftThe lower bound of the integration.
rightThe upper bound of the integration.
Returns
The definite integral of the polynomial between left and right.

◆ integrate() [3/3]

T vulpes::polynomial::PolynomialBase< T, Dim, Polynomial >::integrate ( const datastructure::SimplexDataView< Dim, SimplexData, T, std::size_t > & monomial_integrals) const
inlineinherited

Integrate the polynomial given the monomials integrals.

◆ operator%=()

template<typename T>
Polynomial< T > & vulpes::polynomial::Polynomial< T >::operator%= ( const Polynomial< T > & divisor)
inline

Computes the remainder of dividing the current polynomial by another polynomial in place.

Parameters
divisorThe polynomial to divide by.
Returns
A reference to the current polynomial after computing the remainder.

◆ operator*=() [1/2]

template<typename T>
Polynomial< T > & vulpes::polynomial::Polynomial< T >::operator*= ( const Polynomial< T > & other)
inline

Multiplies the current polynomial by another polynomial in place.

Parameters
otherThe polynomial to multiply with.
Returns
A reference to the current polynomial after multiplication.

◆ operator*=() [2/2]

template<typename T>
Polynomial< T > & vulpes::polynomial::Polynomial< T >::operator*= ( const T & scalar)
inline

Multiplies the polynomial by a scalar in place.

Parameters
scalarThe scalar to multiply with.
Returns
A reference to the current polynomial after multiplication.

◆ operator+=()

template<typename T>
Polynomial< T > & vulpes::polynomial::Polynomial< T >::operator+= ( const Polynomial< T > & other)
inline

Adds another polynomial to the current polynomial in place.

Parameters
otherThe polynomial to add.
Returns
A reference to the current polynomial after addition.

◆ operator-=()

template<typename T>
Polynomial< T > & vulpes::polynomial::Polynomial< T >::operator-= ( const Polynomial< T > & other)
inline

Subtracts another polynomial from the current polynomial in place.

Parameters
otherThe polynomial to subtract.
Returns
A reference to the current polynomial after subtraction.

◆ operator/=() [1/2]

template<typename T>
Polynomial< T > & vulpes::polynomial::Polynomial< T >::operator/= ( const Polynomial< T > & divisor)
inline

Divides the current polynomial by another polynomial in place.

Parameters
divisorThe polynomial to divide by.
Returns
A reference to the current polynomial after division.

◆ operator/=() [2/2]

template<typename T>
Polynomial< T > & vulpes::polynomial::Polynomial< T >::operator/= ( const T & scalar)
inline

Divides the polynomial by a scalar in place.

Parameters
scalarThe scalar to divide by.
Returns
A reference to the current polynomial after division.
Note
The method is not well-defined for integral point types. Ensure T is not an integral type.

◆ operator[]()

template<typename T>
const T & vulpes::polynomial::Polynomial< T >::operator[] ( std::size_t i) const
inline

Accesses the coefficient of the x^i term.

Parameters
iThe index of the coefficient to access.
Returns
The const reference to coefficient of the x^i term

◆ primitive() [1/2]

template<typename T>
Polynomial< T > vulpes::polynomial::Polynomial< T >::primitive ( const T & c = T(0)) const
inline

Computes the indefinite integral (primitive) of the polynomial.

Parameters
cThe constant of integration.
Returns
A new polynomial representing the indefinite integral of the current polynomial.

◆ primitive() [2/2]

Polynomial vulpes::polynomial::PolynomialBase< T, Dim, Polynomial >::primitive ( std::size_t component) const
inlineinherited

Compute the primitive of the polynomial.

◆ primitive_()

template<typename T>
void vulpes::polynomial::Polynomial< T >::primitive_ ( const T & ordinate = T(0),
const T & target_value = T(0) )
inline

Computes the indefinite integral (primitive) of the polynomial in place.

Parameters
ordinateThe ordinate (x-value) for which the integral at that point should equal the target_value.
target_valueThe target value of the integral at the given ordinate.
Note
The method is not well-defined for integral point types. Ensure T is not an integral type.

◆ self()

Polynomial * vulpes::polynomial::PolynomialBase< T, Dim, Polynomial >::self ( )
inlineprotectedinherited

◆ size()

template<typename T>
std::size_t vulpes::polynomial::Polynomial< T >::size ( ) const
inlineconstexpr

Returns the number of the monomials.

Returns
The size of the underlying buffer.

◆ substitute()

template<typename T>
Polynomial< T > vulpes::polynomial::Polynomial< T >::substitute ( const Polynomial< T > & poly) const
inline

Substitutes another polynomial into the current polynomial.

Parameters
polyThe polynomial to substitute into the current polynomial.
Returns
A new polynomial resulting from the substitution.

◆ to()

template<typename T>
template<typename U>
Polynomial< U > vulpes::polynomial::Polynomial< T >::to ( ) const
inline

Converts the underlying type of the polynomial's coefficients to another type.

Template Parameters
UThe target type to which the coefficients should be converted.
Returns
A new polynomial with the coefficients converted to type U.

◆ trim()

template<typename T>
void vulpes::polynomial::Polynomial< T >::trim ( )
inlineprotected

Removes leading zeros from the coefficients vector.

This function trims the polynomial by removing any leading zeros from the coefficients vector, ensuring the polynomial's degree is correctly represented.

◆ operator%

template<typename T>
Polynomial< T > operator% ( Polynomial< T > lhs,
const Polynomial< T > & rhs )
friend

Friend function to compute the remainder of dividing one polynomial by another.

Parameters
lhsThe left-hand side polynomial.
rhsThe right-hand side polynomial.
Returns
A new polynomial representing the remainder when lhs is divided by rhs.

◆ operator/

template<typename T>
Polynomial< T > operator/ ( Polynomial< T > lhs,
const Polynomial< T > & rhs )
friend

Friend function to compute the remainder of dividing one polynomial by another.

Parameters
lhsThe left-hand side polynomial.
rhsThe right-hand side polynomial.
Returns
A new polynomial representing the remainder when lhs is divided by rhs.

◆ operator<<

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

Friend function to output a polynomial to an output stream.

Parameters
osThe output stream.
polyThe polynomial to output.
Returns
The output stream after outputting the polynomial.

◆ operator==

template<typename T>
bool operator== ( const Polynomial< T > & lhs,
const Polynomial< T > & rhs )
friend

Compares two polynomials for equality.

Parameters
lhsThe left-hand side polynomial.
rhsThe right-hand side polynomial.
Returns
true if the two polynomials are equal, false otherwise.

Member Data Documentation

◆ m_coefficients

template<typename T>
std::vector<T> vulpes::polynomial::Polynomial< T >::m_coefficients
protected

Vector storing the coefficients of the polynomial.


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