sigma  1.0.0
Loading...
Searching...
No Matches
sigma::ThresholdedAffine< ValueType > Class Template Reference

Implements affine arithmetic that drops negligible error terms. More...

#include <thresholded_affine.hpp>

Classes

struct  Threshold
 Tag type used to pass the relative threshold to constructors. More...

Public Types

using size_type = std::size_t
 Type used for indexing and offsets.
using value_t = ValueType
 Type used for storing floating point values.
using error_term_t = typename Affine<ValueType>::error_term_t
 Opaque type used to store error term information.
using error_terms_t = typename Affine<ValueType>::error_terms_t
 Type used to map error terms to their radii.
using interval_t = typename Affine<ValueType>::interval_t
 Type of an interval.
using affine_t = Affine<ValueType>
 Type of the underlying Affine form.

Public Member Functions

 ThresholdedAffine ()
 Constructs an empty ThresholdedAffine.
 ThresholdedAffine (value_t center, Threshold t=default_threshold())
 Constructs a ThresholdedAffine from a center value.
 ThresholdedAffine (value_t lo, value_t hi, Threshold t=default_threshold())
 Constructs a ThresholdedAffine from a lower and upper bound.
 ThresholdedAffine (const interval_t &interval, Threshold t=default_threshold())
 Constructs a ThresholdedAffine from an interval.
 ThresholdedAffine (value_t center, error_terms_t radii, Threshold t=default_threshold())
 Constructs a ThresholdedAffine from a center and error terms.
 ThresholdedAffine (affine_t a, value_t threshold)
 Constructs a ThresholdedAffine by wrapping an Affine form.
 ThresholdedAffine (const ThresholdedAffine &other)=default
 Copy constructor.
 ThresholdedAffine (ThresholdedAffine &&other) noexcept=default
 Move constructor.
ThresholdedAffineoperator= (const ThresholdedAffine &other)=default
 Copy assignment operator.
ThresholdedAffineoperator= (ThresholdedAffine &&other) noexcept=default
 Move assignment operator.
interval_t range () const
 Returns the interval represented by *this.
value_t center () const
 Returns the center of the affine form.
const error_terms_terror_terms () const
 Returns the error terms of the tracked affine form.
value_t radius () const
 Returns the total radius: the sum of the tracked terms.
void set_center (value_t c)
 Sets the center of the affine form.
void add_error_term (error_term_t error_term, value_t r)
 Adds an error term to the affine form and applies thresholding.
bool contains (value_t v) const
 Returns whether *this contains a scalar value v.
bool contains (const interval_t &i) const
 Returns whether *this contains an interval.
bool contains (const ThresholdedAffine &other) const
 Returns whether *this contains another ThresholdedAffine's range.
bool empty () const noexcept
 Returns whether *this is empty.
std::string print_affine_form () const
 Returns a string of the affine form (tracked terms only).
std::string print_interval_form () const
 Returns a string of the interval form.
const affine_taffine () const
 Returns the underlying Affine form (tracked terms only).
value_t threshold () const
 Returns the relative threshold.
ThresholdedAffine operator- () const
 Returns the additive inverse of *this.
ThresholdedAffineoperator+= (value_t value)
 Adds a scalar to *this.
ThresholdedAffineoperator+= (const ThresholdedAffine &other)
 Adds another ThresholdedAffine to *this.
ThresholdedAffine operator+ (value_t value) const
 Returns the sum of *this and a scalar.
ThresholdedAffine operator+ (const ThresholdedAffine &other) const
 Returns the sum of *this and another ThresholdedAffine.
ThresholdedAffineoperator-= (value_t value)
 Subtracts a scalar from *this.
ThresholdedAffineoperator-= (const ThresholdedAffine &other)
 Subtracts another ThresholdedAffine from *this.
ThresholdedAffine operator- (value_t value) const
 Returns the difference of *this and a scalar.
ThresholdedAffine operator- (const ThresholdedAffine &other) const
 Returns the difference of *this and another ThresholdedAffine.
ThresholdedAffineoperator*= (value_t value)
 Multiplies *this by a scalar.
ThresholdedAffineoperator*= (const ThresholdedAffine &other)
 Multiplies *this by another ThresholdedAffine.
ThresholdedAffine operator* (value_t value) const
 Multiplies *this by a scalar.
ThresholdedAffine operator* (const ThresholdedAffine &other) const
 Multiplies *this by another ThresholdedAffine.
ThresholdedAffineoperator/= (value_t value)
 Divides *this by a scalar.
ThresholdedAffineoperator/= (const ThresholdedAffine &other)
 Divides *this by another ThresholdedAffine.
ThresholdedAffine operator/ (value_t value) const
 Divides *this by a scalar.
ThresholdedAffine operator/ (const ThresholdedAffine &other) const
 Divides *this by another ThresholdedAffine.
bool operator== (const ThresholdedAffine &other) const
 Checks equality of two ThresholdedAffine forms.
bool operator!= (const ThresholdedAffine &other) const
 Checks inequality of two ThresholdedAffine forms.

Static Public Member Functions

static constexpr Threshold default_threshold ()
 Returns the default threshold value.

(Note that these are not member symbols.)

template<typename ValueType>
std::ostream & operator<< (std::ostream &os, const ThresholdedAffine< ValueType > &a)
 Outputs the range of a ThresholdedAffine to a stream.
template<typename ValueType>
ThresholdedAffine< ValueType > operator* (ValueType value, const ThresholdedAffine< ValueType > &a)
 Multiplies a scalar by a ThresholdedAffine.
template<typename T>
ThresholdedAffine< T > abs (const ThresholdedAffine< T > &a)
 Absolute value of a ThresholdedAffine.
template<typename T>
ThresholdedAffine< T > fabs (const ThresholdedAffine< T > &a)
 Absolute value of a ThresholdedAffine (alias for abs).
template<typename T>
ThresholdedAffine< T > sqrt (const ThresholdedAffine< T > &a)
 Square root of a ThresholdedAffine.
template<typename T>
ThresholdedAffine< T > exp (const ThresholdedAffine< T > &a)
 Exponential of a ThresholdedAffine.
template<typename T>
ThresholdedAffine< T > log (const ThresholdedAffine< T > &a)
 Natural logarithm of a ThresholdedAffine.
template<typename T, typename U>
ThresholdedAffine< T > pow (const ThresholdedAffine< T > &a, const U &exp)
 Power of a ThresholdedAffine.

Detailed Description

template<typename ValueType>
class sigma::ThresholdedAffine< ValueType >

Implements affine arithmetic that drops negligible error terms.

Template Parameters
ValueTypeThe numeric type of the center and error term radii.

ThresholdedAffine extends standard affine arithmetic with a mechanism to control the number of error symbols carried in an affine form. Each non-affine operation can introduce new error symbols (e.g. multiplication creates a nonlinearity symbol); without pruning, the symbol count grows unboundedly.

This class reduces symbol count by deleting error terms whose relative contribution falls below the threshold. Dropped terms are simply discarded; no separate "lump" radius is retained to account for them.

Constructors accept a Threshold tag type to distinguish the threshold parameter from ordinary value parameters and avoid constructor ambiguity.

Constructor & Destructor Documentation

◆ ThresholdedAffine() [1/8]

template<typename ValueType>
sigma::ThresholdedAffine< ValueType >::ThresholdedAffine ( )
inline

Constructs an empty ThresholdedAffine.

The resulting ThresholdedAffine represents the empty set and the threshold is set to the default value.

Exceptions
noneNo throw guarantee

◆ ThresholdedAffine() [2/8]

template<typename ValueType>
sigma::ThresholdedAffine< ValueType >::ThresholdedAffine ( value_t center,
Threshold t = default_threshold() )
inlineexplicit

Constructs a ThresholdedAffine from a center value.

Parameters
[in]centerThe center value.
[in]tThe relative threshold, defaults to default_threshold().
Exceptions
noneNo throw guarantee

◆ ThresholdedAffine() [3/8]

template<typename ValueType>
sigma::ThresholdedAffine< ValueType >::ThresholdedAffine ( value_t lo,
value_t hi,
Threshold t = default_threshold() )
inline

Constructs a ThresholdedAffine from a lower and upper bound.

Parameters
[in]loThe lower bound.
[in]hiThe upper bound.
[in]tThe relative threshold, defaults to default_threshold().
Exceptions
std::bad_allocIf memory allocation for the error term fails.

◆ ThresholdedAffine() [4/8]

template<typename ValueType>
sigma::ThresholdedAffine< ValueType >::ThresholdedAffine ( const interval_t & interval,
Threshold t = default_threshold() )
inlineexplicit

Constructs a ThresholdedAffine from an interval.

Parameters
[in]intervalThe interval.
[in]tThe relative threshold, defaults to default_threshold().
Exceptions
std::bad_allocIf memory allocation for the error term fails.

◆ ThresholdedAffine() [5/8]

template<typename ValueType>
sigma::ThresholdedAffine< ValueType >::ThresholdedAffine ( value_t center,
error_terms_t radii,
Threshold t = default_threshold() )
inline

Constructs a ThresholdedAffine from a center and error terms.

Parameters
[in]centerThe center value.
[in]radiiMap of error symbols to their radii.
[in]tThe relative threshold, defaults to default_threshold().
Exceptions
noneNo throw guarantee

◆ ThresholdedAffine() [6/8]

template<typename ValueType>
sigma::ThresholdedAffine< ValueType >::ThresholdedAffine ( affine_t a,
value_t threshold )
inline

Constructs a ThresholdedAffine by wrapping an Affine form.

Used internally by operations that produce an Affine result and need to re-wrap it as a ThresholdedAffine.

Parameters
[in]aThe Affine form to wrap.
[in]thresholdThe relative threshold.
Exceptions
std::bad_allocIf memory allocation for the error term fails. Strong throw guarantee.

◆ ThresholdedAffine() [7/8]

template<typename ValueType>
sigma::ThresholdedAffine< ValueType >::ThresholdedAffine ( const ThresholdedAffine< ValueType > & other)
default

Copy constructor.

Parameters
[in]otherThe ThresholdedAffine to copy.
Exceptions
std::bad_allocIf memory allocation for the error terms fails. Strong throw guarantee.

◆ ThresholdedAffine() [8/8]

template<typename ValueType>
sigma::ThresholdedAffine< ValueType >::ThresholdedAffine ( ThresholdedAffine< ValueType > && other)
defaultnoexcept

Move constructor.

Parameters
[in]otherThe ThresholdedAffine to move.
Exceptions
noneNo throw guarantee

Member Function Documentation

◆ add_error_term()

template<typename ValueType>
void sigma::ThresholdedAffine< ValueType >::add_error_term ( error_term_t error_term,
value_t r )
inline

Adds an error term to the affine form and applies thresholding.

Parameters
[in]error_termThe error symbol.
[in]rThe radius of the new term.
Exceptions
NoneNo throw guarantee.

◆ affine()

template<typename ValueType>
const affine_t & sigma::ThresholdedAffine< ValueType >::affine ( ) const
inline

Returns the underlying Affine form (tracked terms only).

Returns
Const reference to the internal Affine form.
Exceptions
noneNo throw guarantee

◆ center()

template<typename ValueType>
value_t sigma::ThresholdedAffine< ValueType >::center ( ) const
inline

Returns the center of the affine form.

Returns
The center value.
Exceptions
std::domain_errorIf *this is empty.

◆ contains() [1/3]

template<typename ValueType>
bool sigma::ThresholdedAffine< ValueType >::contains ( const interval_t & i) const
inline

Returns whether *this contains an interval.

Parameters
[in]iThe interval to test.
Returns
True if every point in i is in range().
Exceptions
noneNo throw guarantee

◆ contains() [2/3]

template<typename ValueType>
bool sigma::ThresholdedAffine< ValueType >::contains ( const ThresholdedAffine< ValueType > & other) const
inline

Returns whether *this contains another ThresholdedAffine's range.

Parameters
[in]otherThe ThresholdedAffine to test.
Returns
True if every point in other.range() is in range().
Exceptions
noneNo throw guarantee

◆ contains() [3/3]

template<typename ValueType>
bool sigma::ThresholdedAffine< ValueType >::contains ( value_t v) const
inline

Returns whether *this contains a scalar value v.

Parameters
[in]vThe value to test.
Returns
True if the value is in range().
Exceptions
noneNo throw guarantee

◆ default_threshold()

template<typename ValueType>
constexpr Threshold sigma::ThresholdedAffine< ValueType >::default_threshold ( )
inlinestaticconstexpr

Returns the default threshold value.

Returns
The default threshold (0.1%).
Exceptions
noneNo throw guarantee

◆ empty()

template<typename ValueType>
bool sigma::ThresholdedAffine< ValueType >::empty ( ) const
inlinenoexcept

Returns whether *this is empty.

Returns
True if *this represents the empty set.
Exceptions
noneNo throw guarantee

◆ error_terms()

template<typename ValueType>
const error_terms_t & sigma::ThresholdedAffine< ValueType >::error_terms ( ) const
inline

Returns the error terms of the tracked affine form.

Returns
Const reference to the error terms map.
Exceptions
NoneNo throw guarantee.

◆ operator!=()

template<typename ValueType>
bool sigma::ThresholdedAffine< ValueType >::operator!= ( const ThresholdedAffine< ValueType > & other) const
inline

Checks inequality of two ThresholdedAffine forms.

Parameters
[in]otherThe form to compare.
Returns
True if not equal.
Exceptions
noneNo throw guarantee.

◆ operator*=() [1/2]

template<typename ValueType>
ThresholdedAffine & sigma::ThresholdedAffine< ValueType >::operator*= ( const ThresholdedAffine< ValueType > & other)
inline

Multiplies *this by another ThresholdedAffine.

Multiplication introduces a new nonlinearity error term via affine arithmetic, after which sub-threshold terms are dropped.

Parameters
[in]otherThe form to multiply by.
Returns
Reference to *this.
Exceptions
NoneNo throw guarantee.

◆ operator*=() [2/2]

template<typename ValueType>
ThresholdedAffine & sigma::ThresholdedAffine< ValueType >::operator*= ( value_t value)
inline

Multiplies *this by a scalar.

Parameters
[in]valueThe scalar to multiply by.
Returns
Reference to *this.
Exceptions
NoneNo throw guarantee.

◆ operator+=() [1/2]

template<typename ValueType>
ThresholdedAffine & sigma::ThresholdedAffine< ValueType >::operator+= ( const ThresholdedAffine< ValueType > & other)
inline

Adds another ThresholdedAffine to *this.

The tracked affine terms are combined with normal affine addition (shared symbols may cancel), after which sub-threshold terms are dropped.

Parameters
[in]otherThe form to add.
Returns
Reference to *this.
Exceptions
NoneNo throw guarantee.

◆ operator+=() [2/2]

template<typename ValueType>
ThresholdedAffine & sigma::ThresholdedAffine< ValueType >::operator+= ( value_t value)
inline

Adds a scalar to *this.

Parameters
[in]valueThe scalar to add.
Returns
Reference to *this.
Exceptions
NoneNo throw guarantee.

◆ operator-()

template<typename ValueType>
ThresholdedAffine sigma::ThresholdedAffine< ValueType >::operator- ( ) const
inline

Returns the additive inverse of *this.

Negation flips the tracked affine terms.

Returns
The negated ThresholdedAffine.
Exceptions
std::bad_allocIf memory allocation fails.

◆ operator-=() [1/2]

template<typename ValueType>
ThresholdedAffine & sigma::ThresholdedAffine< ValueType >::operator-= ( const ThresholdedAffine< ValueType > & other)
inline

Subtracts another ThresholdedAffine from *this.

Tracked affine terms are combined with normal affine subtraction (shared symbols cancel, capturing dependency), after which sub-threshold terms are dropped.

Parameters
[in]otherThe form to subtract.
Returns
Reference to *this.
Exceptions
NoneNo throw guarantee.

◆ operator-=() [2/2]

template<typename ValueType>
ThresholdedAffine & sigma::ThresholdedAffine< ValueType >::operator-= ( value_t value)
inline

Subtracts a scalar from *this.

Parameters
[in]valueThe scalar to subtract.
Returns
Reference to *this.
Exceptions
NoneNo throw guarantee.

◆ operator/=() [1/2]

template<typename ValueType>
ThresholdedAffine & sigma::ThresholdedAffine< ValueType >::operator/= ( const ThresholdedAffine< ValueType > & other)
inline

Divides *this by another ThresholdedAffine.

Division is performed by affine arithmetic, after which sub-threshold terms are dropped. The divisor's interval must not contain zero.

Parameters
[in]otherThe form to divide by.
Returns
Reference to *this.
Exceptions
std::domain_errorIf other is empty or its interval contains zero.

◆ operator/=() [2/2]

template<typename ValueType>
ThresholdedAffine & sigma::ThresholdedAffine< ValueType >::operator/= ( value_t value)
inline

Divides *this by a scalar.

Parameters
[in]valueThe scalar to divide by.
Returns
Reference to *this.
Exceptions
std::domain_errorIf value is zero.

◆ operator=() [1/2]

template<typename ValueType>
ThresholdedAffine & sigma::ThresholdedAffine< ValueType >::operator= ( const ThresholdedAffine< ValueType > & other)
default

Copy assignment operator.

Parameters
[in]otherThe ThresholdedAffine to copy.
Returns
Reference to this ThresholdedAffine after assignment.
Exceptions
std::bad_allocIf memory allocation for the error terms fails. Strong throw guarantee.

◆ operator=() [2/2]

template<typename ValueType>
ThresholdedAffine & sigma::ThresholdedAffine< ValueType >::operator= ( ThresholdedAffine< ValueType > && other)
defaultnoexcept

Move assignment operator.

Parameters
[in]otherThe ThresholdedAffine to move.
Returns
Reference to this ThresholdedAffine after assignment.
Exceptions
noneNo throw guarantee

◆ operator==()

template<typename ValueType>
bool sigma::ThresholdedAffine< ValueType >::operator== ( const ThresholdedAffine< ValueType > & other) const
inline

Checks equality of two ThresholdedAffine forms.

Parameters
[in]otherThe form to compare.
Returns
True if equal.
Exceptions
noneNo throw guarantee.

◆ print_affine_form()

template<typename ValueType>
std::string sigma::ThresholdedAffine< ValueType >::print_affine_form ( ) const
inline

Returns a string of the affine form (tracked terms only).

Returns
Affine form string.
Exceptions
std::bad_allocIf memory allocation for the string fails. Strong throw guarantee.

◆ print_interval_form()

template<typename ValueType>
std::string sigma::ThresholdedAffine< ValueType >::print_interval_form ( ) const
inline

Returns a string of the interval form.

Returns
Interval form string, e.g. [lo, hi].
Exceptions
std::bad_alloc

◆ radius()

template<typename ValueType>
value_t sigma::ThresholdedAffine< ValueType >::radius ( ) const
inline

Returns the total radius: the sum of the tracked terms.

Returns
The total radius.
Exceptions
std::domain_errorIf *this is empty.

◆ range()

template<typename ValueType>
interval_t sigma::ThresholdedAffine< ValueType >::range ( ) const
inline

Returns the interval represented by *this.

The interval is [center - radius(), center + radius()], where radius() is the sum of the tracked affine terms.

Returns
The interval.
Exceptions
noneNo throw guarantee

◆ set_center()

template<typename ValueType>
void sigma::ThresholdedAffine< ValueType >::set_center ( value_t c)
inline

Sets the center of the affine form.

Parameters
[in]cThe new center.
Exceptions
NoneNo throw guarantee.

◆ threshold()

template<typename ValueType>
value_t sigma::ThresholdedAffine< ValueType >::threshold ( ) const
inline

Returns the relative threshold.

Returns
The threshold \(t\).
Exceptions
noneNo throw guarantee

◆ abs()

template<typename T>
ThresholdedAffine< T > abs ( const ThresholdedAffine< T > & a)
related

Absolute value of a ThresholdedAffine.

Template Parameters
TThe value type.

◆ exp()

template<typename T>
ThresholdedAffine< T > exp ( const ThresholdedAffine< T > & a)
related

Exponential of a ThresholdedAffine.

Template Parameters
TThe value type.

◆ fabs()

template<typename T>
ThresholdedAffine< T > fabs ( const ThresholdedAffine< T > & a)
related

Absolute value of a ThresholdedAffine (alias for abs).

Template Parameters
TThe value type.

◆ log()

template<typename T>
ThresholdedAffine< T > log ( const ThresholdedAffine< T > & a)
related

Natural logarithm of a ThresholdedAffine.

Template Parameters
TThe value type.
Exceptions
std::domain_errorIf the range contains non-positive values.

◆ operator*()

template<typename ValueType>
ThresholdedAffine< ValueType > operator* ( ValueType value,
const ThresholdedAffine< ValueType > & a )
related

Multiplies a scalar by a ThresholdedAffine.

Template Parameters
ValueTypeThe value type.

◆ operator<<()

template<typename ValueType>
std::ostream & operator<< ( std::ostream & os,
const ThresholdedAffine< ValueType > & a )
related

Outputs the range of a ThresholdedAffine to a stream.

Template Parameters
ValueTypeThe value type.

◆ pow()

template<typename T, typename U>
ThresholdedAffine< T > pow ( const ThresholdedAffine< T > & a,
const U & exp )
related

Power of a ThresholdedAffine.

Template Parameters
TThe value type.
UThe exponent type.
Exceptions
std::domain_errorSee Affine::pow for conditions.

◆ sqrt()

template<typename T>
ThresholdedAffine< T > sqrt ( const ThresholdedAffine< T > & a)
related

Square root of a ThresholdedAffine.

Template Parameters
TThe value type.
Exceptions
std::domain_errorIf the range contains negative values.

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