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

Namespace providing support for rational functions. More...

Typedefs

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
using RationalFunction = std::pair<Container<Number>, Container<Number>>
 Represents a rational function \(\displaystyle f(x) = \frac{A(x)}{B(x)}\), where \(A(x)\) and \(B(x)\) are polynomials.
 

Functions

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t<!traits::has_size< Number >::value, Number > val_mul (const RationalFunction< Number, Container > &rf, const Number &x)
 Evaluates the rational function at a scalar point using Horner's method.
 
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t< traits::has_size< Container< Number > >::value, Container< Number > > val_mul (const RationalFunction< Number, Container > &rf, const Container< Number > &xx)
 Evaluates the rational function at each point in the container using val_mul for scalar values.
 
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t<!traits::has_size< Number >::value, Number > val_div (const RationalFunction< Number, Container > &rf, const Number &x)
 Evaluates the rational function at a scalar point by factoring out powers of x.
 
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t< traits::has_size< Container< Number > >::value, Container< Number > > val_div (const RationalFunction< Number, Container > &rf, const Container< Number > &xx)
 Evaluates the rational function at each point in the container using val_div for scalar values.
 
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t<!traits::has_size< Number >::value, Number > val (const RationalFunction< Number, Container > &rf, const Number &x)
 Evaluates the rational function at a scalar point.
 
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t< traits::has_size< Container< Number > >::value, Container< Number > > val (const RationalFunction< Number, Container > &rf, const Container< Number > &xx)
 Evaluates the rational function at each point in the container using val for scalar values.
 
template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
RationalFunction< Number, Container > pade (Container< Number > P, SizeT n, SizeT m, const Number &epsilon=std::numeric_limits< Number >::epsilon())
 Computes the [n / m] Pade approximant of the polynomial P about the point \(x = 0\).
 

Detailed Description

Namespace providing support for rational functions.

This namespace provides types and functions for representing, computing and evaluating rational functions of the form

\[ f(x) = \frac{A(x)}{B(x)} \]

where \(A(x)\) and \(B(x)\) are polynomials.

Typedef Documentation

◆ RationalFunction

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
using alfi::ratf::RationalFunction = std::pair<Container<Number>, Container<Number>>

Represents a rational function \(\displaystyle f(x) = \frac{A(x)}{B(x)}\), where \(A(x)\) and \(B(x)\) are polynomials.

A pair (std::pair) of polynomials {.first as numerator, .second as denominator} stored as containers of coefficients in descending degree order.

Function Documentation

◆ val_mul() [1/2]

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t<!traits::has_size< Number >::value, Number > alfi::ratf::val_mul ( const RationalFunction< Number, Container > & rf,
const Number & x )

Evaluates the rational function at a scalar point using Horner's method.

Computes \(f(x) = \frac{A(x)}{B(x)}\) by evaluating the values of the numerator \(A\) and the denominator \(B\) using Horner's method, and then dividing the results.

val utilizes this function for \(|x| \leq 1\).

◆ val_mul() [2/2]

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t< traits::has_size< Container< Number > >::value, Container< Number > > alfi::ratf::val_mul ( const RationalFunction< Number, Container > & rf,
const Container< Number > & xx )

Evaluates the rational function at each point in the container using val_mul for scalar values.

◆ val_div() [1/2]

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t<!traits::has_size< Number >::value, Number > alfi::ratf::val_div ( const RationalFunction< Number, Container > & rf,
const Number & x )

Evaluates the rational function at a scalar point by factoring out powers of x.

Computes \(f(x) = \frac{A(x)}{B(x)}\) by evaluating both numerator and denominator in reverse order, effectively factoring out the dominant power of \(x\) to improve numerical stability for large \(|x|\).

val utilizes this function for \(|x| > 1\).

◆ val_div() [2/2]

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t< traits::has_size< Container< Number > >::value, Container< Number > > alfi::ratf::val_div ( const RationalFunction< Number, Container > & rf,
const Container< Number > & xx )

Evaluates the rational function at each point in the container using val_div for scalar values.

◆ val() [1/2]

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t<!traits::has_size< Number >::value, Number > alfi::ratf::val ( const RationalFunction< Number, Container > & rf,
const Number & x )

Evaluates the rational function at a scalar point.

Calls val_mul for \(|x| \leq 1\) and val_div otherwise for the sake of numerical stability.

◆ val() [2/2]

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
std::enable_if_t< traits::has_size< Container< Number > >::value, Container< Number > > alfi::ratf::val ( const RationalFunction< Number, Container > & rf,
const Container< Number > & xx )

Evaluates the rational function at each point in the container using val for scalar values.

◆ pade()

template<typename Number = DefaultNumber, template< typename, typename... > class Container = DefaultContainer>
RationalFunction< Number, Container > alfi::ratf::pade ( Container< Number > P,
SizeT n,
SizeT m,
const Number & epsilon = std::numeric_limits<Number>::epsilon() )

Computes the [n / m] Pade approximant of the polynomial P about the point \(x = 0\).

The Pade approximant is given by the formula

\[ P(x) = \frac{A(x)}{B(x)} = \frac{\sum_{i=0}^{n}{a_ix^i}}{b_0+\sum_{j=0}^{m}{b_jx^j}} \]

where \(A(x)\) and \(B(x)\) are the numerator and denominator polynomials, respectively; \(b_0 \neq 0\).

This function computes the Pade approximant of a polynomial by applying a modified extended Euclidean algorithm for polynomials.

The modification consists in that:

  • the algorithm may terminate early if the numerator's degree already meets the requirements,
  • or perform an extra iteration involving a division by a zero polynomial in special cases.

The latter is necessary to avoid false negatives, for example, when computing the [2/2] approximant of the function \(x^5\).

Without the additional check, this also may lead to false positives, as in the case of computing the [2/2] approximant of \(x^4\).
This is prevented by verifying that the constant term of the denominator is non-zero after the algorithm completes.

Parameters
Pthe polynomial to approximate (a container of coefficients in descending degree order)
nthe maximum degree for the numerator
mthe maximum degree for the denominator
epsilonthe tolerance used to determine whether a coefficient is considered zero (default is machine epsilon)
Returns
a pair {numerator, denominator} representing the Pade approximant; if an approximant does not exist, an empty pair is returned