Speclib  0.1.2
The library for writing better CUDA libraries
sp::f::TraitsBase< CRTP, F > Struct Template Reference

The base class for functor traits. More...

#include <FunctorTraits.hpp>

Inheritance diagram for sp::f::TraitsBase< CRTP, F >:
[legend]

Public Types

using Functor = F
 The described functor. More...
 
using Inverse = void
 The inverse of this functor. More...
 
using GroupInverseOf = void
 The functor defining a group that this functor is an inverse of. More...
 
using UnaryGroupInverse = void
 The functor that acts as the unary inverse for this functor. More...
 
using BinaryGroupInverse = void
 The functor that acts as the binary inverse for this functor. More...
 

Static Public Attributes

static constexpr bool Total = false
 The function is defined for all input tuples (division is not). More...
 
static constexpr bool Even = false
 f(-x) = f(x). More...
 
static constexpr bool Odd = false
 f(-x) = -f(x). More...
 
static constexpr bool Associative = false
 f(f(a, b), c) = f(a, f(b, c)). More...
 
static constexpr bool Commutative = false
 f(a, b) = f(b, a). More...
 
static constexpr bool Anticommutative = false
 f(a, b) = -f(b, a). More...
 
static constexpr bool Invertible = false
 For all x, there exists y such that f(x, y) = f(y, x) = IdentityValue. More...
 
static constexpr bool HasIdentity = false
 The functor has an identity, c, such that f(x, c) = x. More...
 
static constexpr bool HasAbsorbingElement = false
 The functor has an absorbing element, c, such that f(c, x) = c. More...
 
template<typename G >
static constexpr bool LeftDistributiveOver = CRTP::template RightDistributiveOver<G> && CRTP::Commutative
 The functor is left-distributes under g. More...
 
template<typename G >
static constexpr bool RightDistributiveOver = false
 The functor is right-distributes under g. More...
 
static constexpr bool Involutory = std::is_same_v<typename CRTP::Inverse, Functor>
 f(f(x)) = x. More...
 
static constexpr bool Monoid = CRTP::Total && CRTP::Associative && CRTP::HasIdentity
 Simultaneously total, associative, and with identity. More...
 
static constexpr bool Group = Monoid && Invertible
 An invertible monoid. More...
 
static constexpr bool AbelianMonoid = Monoid && CRTP::Commutative
 A commutative monoid. More...
 
static constexpr bool AbelianGroup = Group && CRTP::Commutative
 A commutative group. More...
 

Detailed Description

template<typename CRTP, typename F>
struct sp::f::TraitsBase< CRTP, F >

The base class for functor traits.

The function being described is documented as being called f.

This should only be subclassed by Traits and its specializations, which should override any members for which the default is not appropriate. The defaults are chosen so that failure to override represents "no information".

See also
sp::f::Traits.
Template Parameters
CRTPA curiously recurring template parameter.
FThe functor being described.

Member Typedef Documentation

◆ BinaryGroupInverse

template<typename CRTP , typename F >
using sp::f::TraitsBase< CRTP, F >::BinaryGroupInverse = void

The functor that acts as the binary inverse for this functor.

BinaryGroupInverse(x, y) = f(x, UnaryGroupInverse(y)).

◆ Functor

template<typename CRTP , typename F >
using sp::f::TraitsBase< CRTP, F >::Functor = F

The described functor.

◆ GroupInverseOf

template<typename CRTP , typename F >
using sp::f::TraitsBase< CRTP, F >::GroupInverseOf = void

The functor defining a group that this functor is an inverse of.

That functor such that InvertOf::UnaryGroupInverse is f, or InvertOf::BinaryGroupInverse is f.

◆ Inverse

template<typename CRTP , typename F >
using sp::f::TraitsBase< CRTP, F >::Inverse = void

The inverse of this functor.

The functor, g, such that g(f(x)) = x.

Not to be confused with UnaryGroupInverse or Invertible.

◆ UnaryGroupInverse

template<typename CRTP , typename F >
using sp::f::TraitsBase< CRTP, F >::UnaryGroupInverse = void

The functor that acts as the unary inverse for this functor.

f(x, UnaryGroupInverse(x)) = IdentityValue and UnaryGroupInverse is involutory.

Not to be confused with Inverse.

Member Data Documentation

◆ AbelianGroup

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::AbelianGroup = Group && CRTP::Commutative
staticconstexpr

A commutative group.

◆ AbelianMonoid

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::AbelianMonoid = Monoid && CRTP::Commutative
staticconstexpr

A commutative monoid.

◆ Anticommutative

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::Anticommutative = false
staticconstexpr

f(a, b) = -f(b, a).

◆ Associative

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::Associative = false
staticconstexpr

f(f(a, b), c) = f(a, f(b, c)).

◆ Commutative

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::Commutative = false
staticconstexpr

f(a, b) = f(b, a).

◆ Even

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::Even = false
staticconstexpr

f(-x) = f(x).

◆ Group

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::Group = Monoid && Invertible
staticconstexpr

An invertible monoid.

◆ HasAbsorbingElement

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::HasAbsorbingElement = false
staticconstexpr

The functor has an absorbing element, c, such that f(c, x) = c.

E.g: 0 for multiplication.

If this is true, the identity itself must be specified as follows:

template <typename T>
static constexpr T AbsorbingElement = T{...};

◆ HasIdentity

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::HasIdentity = false
staticconstexpr

The functor has an identity, c, such that f(x, c) = x.

E.g: 0 for addition and subtraction, and 1 for multiplication and division.

If this is true, the identity itself must be specified as follows:

template <typename T>
static constexpr T Identity = T{...};

◆ Invertible

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::Invertible = false
staticconstexpr

For all x, there exists y such that f(x, y) = f(y, x) = IdentityValue.

Not to be confused with whether Inverse is non-void.

◆ Involutory

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::Involutory = std::is_same_v<typename CRTP::Inverse, Functor>
staticconstexpr

f(f(x)) = x.

◆ LeftDistributiveOver

template<typename CRTP , typename F >
template<typename G >
constexpr bool sp::f::TraitsBase< CRTP, F >::LeftDistributiveOver = CRTP::template RightDistributiveOver<G> && CRTP::Commutative
staticconstexpr

The functor is left-distributes under g.

I.e: True only if g(f(x, a), f(x, b)) = f(x, g(a, b)).

This only needs to be overridden for operators that are left-distributive and aren't both right distributive and commutative. Matrix multiplication over addition is an example, because it's not commutative, but is both left and right distributive.

◆ Monoid

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::Monoid = CRTP::Total && CRTP::Associative && CRTP::HasIdentity
staticconstexpr

Simultaneously total, associative, and with identity.

◆ Odd

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::Odd = false
staticconstexpr

f(-x) = -f(x).

◆ RightDistributiveOver

template<typename CRTP , typename F >
template<typename G >
constexpr bool sp::f::TraitsBase< CRTP, F >::RightDistributiveOver = false
staticconstexpr

The functor is right-distributes under g.

I.e: True only if g(f(a, x), f(b, x)) = f(g(a, b), x). e.g: If the functor is multiplication, RightDistributiveOver for addition is true.

◆ Total

template<typename CRTP , typename F >
constexpr bool sp::f::TraitsBase< CRTP, F >::Total = false
staticconstexpr

The function is defined for all input tuples (division is not).