Taylor models
#include <audi/taylor_model.hpp>
-
class taylor_model
Taylor model class.
This class represents a Taylor model, containing a generalized dual number in combination with an interval. This implementation is derived from Makino (1998) and is built on top of a gdual object representing the Taylor polynomial (generalized dual number) part of the Taylor model.
A key concept here is Taylor’s theorem (formulation used from Makino (1998) p.80. Taylors theorem allows a quantitative estimate of the error that is to be expected when approximating a function by its Taylor polynomial Furthermore it even offers a way to obtain bounds for the error in practice based on bounding the \((n+1)\)st derivative a method that has sometimes been employed in interval calculations.
As a result, you get \( \forall \vec{x} \in [\vec{a}, \vec{b}] \text{, a given order } n \text{, and an expansion point} \vec{x_o} \):
\( f(\vec{x}) \in P_{\alpha, f}(\vec{x} - \vec{x_0}) + I_{\alpha, f} \)
where f is the function you’re creating a Taylor model for, P is the Taylor polynomial, and I is the interval remainder.
TODO: multiply() needs to be templated as well, but raises error with ambiguity. TODO: operator+ etc. need to become taylor_model_if_enabled (analogous to gdual_if_enabled) to specify exactly what types the operators can accept
Public Functions
-
taylor_model(const taylor_model&) = default
Constructors.
Defaulted copy constructor & assignment
-
taylor_model &operator=(const taylor_model&) = default
-
taylor_model(taylor_model&&) = default
Defaulted move constructor & assignment.
-
taylor_model &operator=(taylor_model&&) = default
-
inline taylor_model()
Default constructor.
-
inline ~taylor_model()
-
inline explicit taylor_model(const audi::gdual<double> &tpol, const int_d &rem_bound, const var_map_d &exp_point, const var_map_i &domain)
-
inline taylor_model(double constant)
-
inline const int_d &get_rem() const
-
inline const var_map_d &get_exp() const
-
inline const var_map_i &get_dom() const
-
inline const unsigned int &get_order() const
-
inline const unsigned int &get_ndim() const
-
inline void set_rem(const int_d &rem_bound)
-
inline void set_exp(const var_map_d &exp_point)
-
inline void set_dom(const var_map_i &domain)
-
inline void extend_symbol_set(const std::vector<std::string> &sym_vars, const var_map_d &exp_point, const var_map_i &domain)
-
inline int_d get_bounds() const
Compute the bounds of the polynomial over the stored domain.
Evaluates the current gdual polynomial over its associated domain and returns the interval containing its minimum and maximum values.
- Returns:
an int_d interval representing the lower and upper bounds
-
template<typename T>
inline decltype(*this = *this + d1) operator+=(const T &d1) Add and assign operator.
Adds an object to this taylor_model in place. This is equivalent to
*this = *this + d1
.- Template Parameters:
T – the type of the right operand
- Parameters:
d1 – the right operand
- Returns:
reference to this taylor_model after modification Add and assignment operator
-
template<typename T>
inline decltype(*this = *this - d1) operator-=(const T &d1) Subtract and assign operator.
Subtracts an object from this taylor_model in place. This is equivalent to
*this = *this - d1
.- Template Parameters:
T – the type of the right operand
- Parameters:
d1 – the right operand
- Returns:
reference to this taylor_model after modification
-
inline taylor_model operator-() const
Unary negation operator.
Returns the negation of this taylor_model. This is equivalent to
sub(0.0, *this)
.- Returns:
a new taylor_model representing the negated value
-
template<typename T>
inline decltype(*this = *this * d1) operator*=(const T &d1) Multiply and assign operator.
Multiplies this taylor_model by an object in place. This is equivalent to
*this = *this * d1
.- Template Parameters:
T – the type of the right operand
- Parameters:
d1 – the right operand
- Returns:
reference to this taylor_model after modification
-
template<typename T>
inline decltype(*this = *this / d1) operator/=(const T &d1) Divide and assign operator.
Divides this taylor_model by an object in place. This is equivalent to
*this = *this / d1
.- Template Parameters:
T – the type of the right operand
- Parameters:
d1 – the right operand (denominator)
- Returns:
reference to this taylor_model after modification
-
inline bool operator==(const taylor_model &other) const
Equality operator for taylor_model.
Compares two taylor_model instances for equality. Two taylor_models are considered equal if:
Their polynomials are equal (
m_tpol
)Their remainder intervals are equal (
interval_equal
)Their expansion points are equal (
map_equal
)Their domains are equal (
map_interval_equal
)
- Parameters:
other – the taylor_model to compare with
- Returns:
true if all components are equal, false otherwise
-
inline bool operator!=(const taylor_model &other) const
Inequality operator for taylor_model.
Compares two taylor_model instances for inequality. Returns the negation of the equality operator.
- Parameters:
other – the taylor_model to compare with
- Returns:
true if any component differs, false otherwise
Public Static Functions
-
static inline taylor_model identity()
-
static inline taylor_model identity(int_d rem, var_map_d exp, var_map_i domain)
-
template<typename T>
static inline int_d get_bounds(const audi::gdual<T> &tpol, const var_map_d &exp_points, const var_map_i &domain) Compute the bounds of a gdual polynomial over a given domain.
Computes the Bernstein enclosure of a gdual polynomial on a specified domain. The domain is shifted relative to the expansion points before evaluation. The result is the interval containing its minimum and maximum values.
- Template Parameters:
T – the coefficient type of the gdual
- Parameters:
tpol – the input gdual polynomial
exp_points – the expansion points (variable → double)
domain – the domain of variables as intervals (variable → int_d)
- Returns:
an int_d interval representing the minimum and maximum polynomial values
-
template<typename K, typename V>
static inline std::unordered_map<K, V> get_common_map(const std::unordered_map<K, V> &a, const std::unordered_map<K, V> &b) Static member functions for arithmetic.
Merge two maps with consistency checking Combines two unordered maps into one by taking the union of their key–value pairs. If a key is present in both maps, the values must be equal (checked using
interval_equal
), otherwise a runtime error is thrown.If the key exists in only one map, that key–value pair is added directly.
- Template Parameters:
K – the key type of the maps
V – the value type of the maps
- Parameters:
a – the first unordered map
b – the second unordered map
- Throws:
std::runtime_error – if a key is present in both maps with conflicting values
- Returns:
a new unordered_map containing the merged key–value pairs
-
template<typename K, typename V>
static inline std::unordered_map<K, V> trim_map(const std::vector<K> &symbol_set, const std::unordered_map<K, V> &a) Filter a map by a given set of keys with subset checking.
Constructs a new unordered map containing only the entries from the input map
a
whose keys are listed insymbol_set
.Each key in
symbol_set
must be present ina
. If any key is missing, the function throws a logic error, since the symbol set is expected to be a strict subset of the map’s keys.- Template Parameters:
K – the key type of the map
V – the value type of the map
- Parameters:
symbol_set – the set of keys to extract (must all exist in
a
)a – the input unordered map
- Throws:
std::logic_error – if a key in
symbol_set
does not exist ina
- Returns:
a new unordered_map containing only the key–value pairs from
a
whose keys are listed insymbol_set
-
template<typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
static inline bool interval_equal(const T &a, const T &b, std::optional<double> tol = std::nullopt) Quantity comparison utilities.
Compare two scalar values for equality Checks whether two arithmetic values are equal within a specified tolerance. For floating-point types, if no tolerance is provided, a default of 10 × machine epsilon is used. For integral types, strict equality is used.
- Template Parameters:
T – the scalar type (must be arithmetic)
- Parameters:
a – the first value
b – the second value
tol – optional tolerance for floating-point comparison
- Returns:
true if the values are considered equal, false otherwise
-
template<typename T, typename Policies, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
static inline bool interval_equal(const boost::numeric::interval<T, Policies> &a, const boost::numeric::interval<T, Policies> &b, std::optional<double> tol = std::nullopt) Compare two intervals for equality.
Checks whether two boost::numeric::interval values are equal within a specified tolerance. For floating-point types, lower and upper bounds are compared with tolerance. For integral types, strict equality of bounds is used.
- Template Parameters:
T – the interval bound type (must be arithmetic)
- Parameters:
a – the first interval
b – the second interval
tol – optional tolerance for floating-point comparison
- Returns:
true if both intervals are considered equal, false otherwise
-
static inline bool map_interval_equal(const std::unordered_map<std::string, int_d> &a, const std::unordered_map<std::string, int_d> &b, std::optional<double> tol = std::nullopt)
Compare two maps of intervals for equality.
Checks whether two unordered_maps mapping variable names to int_d intervals are equal within a specified tolerance. Both maps must have the same size and the same keys.
- Parameters:
a – the first map
b – the second map
tol – optional tolerance for floating-point comparison of interval bounds
- Returns:
true if the maps are considered equal, false otherwise
-
template<typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
static inline bool map_equal(const std::unordered_map<std::string, T> &a, const std::unordered_map<std::string, T> &b, std::optional<double> tol = std::nullopt) Compare two maps of scalar values for equality.
Checks whether two unordered_maps mapping variable names to arithmetic values are equal within a specified tolerance. Both maps must have the same size and the same keys. If no tolerance is provided, strict equality is used.
- Template Parameters:
T – the value type (must be arithmetic)
- Parameters:
a – the first map
b – the second map
tol – optional tolerance for floating-point comparison
- Returns:
true if the maps are considered equal, false otherwise
Friends
-
template<typename T, typename U>
inline friend taylor_model operator+(const T &d1, const U &d2) Overloaded arithmetic operator.
Overloaded addition operator Adds two objects and returns the result as a taylor_model. This is equivalent to calling
add(d1, d2)
.- Template Parameters:
T – the type of the left operand
U – the type of the right operand
- Parameters:
d1 – the left operand
d2 – the right operand
- Returns:
a new taylor_model representing the sum
-
template<typename T, typename U>
inline friend taylor_model operator-(const T &d1, const U &d2) Overloaded subtraction operator.
Subtracts one object from another and returns the result as a taylor_model. This is equivalent to calling
sub(d1, d2)
.- Template Parameters:
T – the type of the left operand
U – the type of the right operand
- Parameters:
d1 – the left operand
d2 – the right operand
- Returns:
a new taylor_model representing the difference
-
template<typename T, typename U>
inline friend taylor_model operator*(const T &d1, const U &d2) Overloaded multiplication operator.
Multiplies two objects and returns the result as a taylor_model. This is equivalent to calling
multiply(d1, d2)
.- Template Parameters:
T – the type of the left operand
U – the type of the right operand
- Parameters:
d1 – the left operand
d2 – the right operand
- Returns:
a new taylor_model representing the product
-
template<typename T, typename U>
inline friend taylor_model operator/(const T &d1, const U &d2) Overloaded division operator.
Divides one object by another and returns the result as a taylor_model. This is equivalent to calling
div(d1, d2)
.- Template Parameters:
T – the type of the numerator
U – the type of the denominator
- Parameters:
d1 – the numerator
d2 – the denominator
- Returns:
a new taylor_model representing the quotient
-
inline friend std::ostream &operator<<(std::ostream &os, const taylor_model &tm)
Overloaded other operator.
Stream insertion operator for taylor_model Outputs the contents of a taylor_model to the given output stream in a human-readable format.
- Parameters:
os – the output stream
tm – the taylor_model to output
- Returns:
a reference to the output stream with the formatted contents inserted
-
taylor_model(const taylor_model&) = default