ALFI
Advanced Library for Function Interpolation
Loading...
Searching...
No Matches
alfi::util::poly Namespace Reference

Namespace with utility functions for polynomial operations. More...

Functions

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
void normalize (Container< Number > &p, const Number &epsilon=std::numeric_limits< Number >::epsilon())
 Normalizes a polynomial by removing leading zero coefficients.
 
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
Container< Number > mul (const Container< Number > &p1, const Container< Number > &p2)
 Multiplies two polynomials.
 
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::pair< Container< Number >, Container< Number > > div (const Container< Number > &dividend, const Container< Number > &divisor, const Number &epsilon=std::numeric_limits< Number >::epsilon())
 Divides one polynomial by another.
 

Detailed Description

Namespace with utility functions for polynomial operations.

This namespace provides a set of functions for manipulating polynomials, such as normalization, multiplication, and division. All polynomials are represented as containers of coefficients in descending degree order.

Function Documentation

◆ normalize()

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
void alfi::util::poly::normalize ( Container< Number > & p,
const Number & epsilon = std::numeric_limits<Number>::epsilon() )

Normalizes a polynomial by removing leading zero coefficients.

Removes leading coefficients that are considered zero within a given tolerance epsilon. If all coefficients are close to zero, the last one is preserved. If the container is empty, a single zero coefficient is inserted.

Parameters
pthe polynomial to normalize (a container of coefficients in descending degree order)
epsilonthe tolerance used to determine whether a coefficient is considered zero (default is machine epsilon)

◆ mul()

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
Container< Number > alfi::util::poly::mul ( const Container< Number > & p1,
const Container< Number > & p2 )

Multiplies two polynomials.

Given two polynomials \(p_1\) and \(p_2\) represented as containers of coefficients, this function computes their product using the convolution formula:

\[ (p_1 \cdot p_2)[k] = \sum_{i+j=k}{p_1[i] \cdot p_2[j]} \]

If either polynomial is empty, the function returns an empty container.

Parameters
p1the first polynomial
p2the second polynomial
Returns
the product polynomial (either empty or of size p1.size() + p2.size() - 1)

◆ div()

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::pair< Container< Number >, Container< Number > > alfi::util::poly::div ( const Container< Number > & dividend,
const Container< Number > & divisor,
const Number & epsilon = std::numeric_limits<Number>::epsilon() )

Divides one polynomial by another.

This function divides the dividend polynomial \(A\) by the divisor polynomial \(B\), and returns the quotient \(Q\) and the remainder \(R\) such that:

\[ A(x) = B(X) \cdot Q(x) + R(x) \]

with either \(R\) being effectively zero or the degree of \(R\) being lower than the degree of \(B\).

The division is performed using a tolerance epsilon to determine when a coefficient is considered zero.

If the divisor is effectively zero or if the dividend has a lower degree than the divisor, the function returns an empty quotient and the dividend as the remainder.

Parameters
dividendthe polynomial to be divided
divisorthe polynomial to divide by
epsilonthe tolerance used to determine whether a coefficient is considered zero (default is machine epsilon)
Returns
a pair {quotient, remainder}