chsvlib
chsv helper source code
The chsvlib Concepts

A type of user-defined algebraic type implementing some kind of an algebraic structure (field, ring, etc.).

This documentation specifies requirements for user-defined components to be used cohesively with chsvlib components. The corresponding requirement is referenced in documentation to a corresponding chsvlib interface in terms: "A <object_name> should be <adjective_concept_name | noun_concept_name>" or "A <object_name> should meet the <general_concept_name> requirement(s)".

Type concepts

Requirements for user-defined types to be used in cohesion with chsvlib interfaces.

algebraic_type

The concept specifies requirements for a user-defined type which implements an algebraic structure. Adherence to the requirements can make the type compatible with some mathematical components of the chsvlib which expect respective algebraic structures. For instance, see Chusov::Math::Matrix.

Given a user-defined algebraic type T, one of the following must be satisfied.

  1. A member type T::algebraic_category should be defined as one of the algebraic tags.
  2. A nested member type with a name of the required algebraic tag should be defined, e.g.
    struct T
    {
    typedef void ring_algebraic_tag;
    //Meet requirements of a ring...
    };
  3. The type Chusov::Math::algebraic_traits<T>::type should alias an algebraic tag.
  4. The type alias std::is_floating_point<T>::type should refer to std::true_type, in which case the type T is considered a field and has to meet corresponding requirements.
  5. The type alias std::is_integral<T>::type should refer to std::true_type, in which case the type T is considered a commutative ring and has to meet its requirements.

Any of these requirements are not exclusive and are allowed to be met in conjunction. In this case the chsvlib components consider the type T an algebraic structure as defined in the above list from top to bottom, that is if types T and U are defined as:

#include <type_traits>
struct T
{
typedef Chusov::Math::division_ring_algebraic_tag algebraic_category;
//...
};
struct U
{
typedef Chusov::Math::rng_algebraic_tag algebraic_category;
//...
};
namespace std
{
template <> is_integral<T>:std::true_type {};
template <> is_floating_point<U>:std::true_type {};
};
A containing class satisfies the division_ring_concept.
Definition: chsvmath.h:833
A containing class satisfies the rng_concept.
Definition: chsvmath.h:830

then the type T is considered a division ring and the type U is considered an Rng despite the second and the third point of the above list.

Note
The types that somehow define an algebraic category have to meet the requirements that correspond to the respective algebraic structure. See additive_group_concept, rng_concept, ring_concept, commutative_ring_concept, division_ring_concept, and field_concept.

If these requirements are met by an implementation T of an algebraic type, then

Is a trait class that provides uniform interface to assess whether a type implements an abstract alge...
Definition: chsvmath.h:877

is resolved to one of the algebraic tags.

Also, objects of any algebraic type must be EquallyComparable, LessThanComparable, DefaultConstructible, CopyConstructible, and CopyAssignable.

additive_group_concept

A type implements a behaviour of a group with addition. Let T be a type which is claimed to implement the behaviour of an additive group, and x and y be any objects of this type. All objects of type T constitute the additive group if the following is true.

  1. The T class meets the requirements of the algebraic_type.
  2. The following expressions are valid and correspond to the table below:

    Expression Return/Resolution type Equivalent expression

    Notes

    A containing class implements an algebraic group over addition.
    Definition: chsvmath.h:829
    (or any of its successors).

    See algebraic_type.

    Either
    @ additive_identity
    A tag to construct additive identity element. See rng_concept.
    Definition: chsvmath.h:998
    or
    T(0)

    Constructs an object of type T which is a unique additive identity. Any object added to it equals the object, i.e. for any x of type T comparisons:

    and

    must return true.

    -x
    T

    Creates a new object which is a unique additive inversion of x and that is convertible to an object of the T type

    x + y
    T
    T new_obj = x;
    new_obj += y;

    Returns a new constructed object of type T holding a unique sum of x and y. The operation must be associative but does not need to be commutative.

    x += y
    T&
    x = x + y

    Calculates a unique sum of x and y and assigns the result to x returning a reference to it.

    x - y
    T
    x + -y

    Returns a new constructed object of type T holding a unique difference between x and y.

    x -= y
    T&
    x += -y
    Calculates a unique difference between x and y and assigns the result to x returning a reference to it.
  3. The addition must be associative, that is the following must be true for any x, y, and z of the type T which implements the [additive group]:
    (x + y) + z == x + (y + z);
    x + y + z == (x + y) + z;
    x + y + z == x + (y + z);
    Hence result of
    x + y + z
    (without specified order of calculation) is well-defined.

rng_concept

A type implements a behaviour of an Rng. Let T be a type which is claimed to implement the Rng, and x and y be any objects of this type. All objects of type T is declared to constitute the Rng if the following are true.

  1. The T class meets the requirements of the additive_group_concept with an additional requirement to the commutativity of the addition operation.
  2. The following expressions are valid and correspond to the table below:

    Expression Return/Resolution type Equivalent expression

    Notes

    (or any of its successors).

    See algebraic_type.

    x * y
    T
    T new_obj = x;
    new_obj *= y;

    Returns a new constructed object of type T holding a unique multiplication of x and y. The operation must be associative, but not commutative. Also, multiplication is distributive over addition in the Rng.

    x *= y
    T&
    x = x * y
    Calculates a unique multiplication of x and y and assigns the result to x returning a reference to it.

  3. The addition must be commutative, i.e. for any x, y, and z of the type T which implements the Rng an expression

    x + y == y + x

    must return true.

  4. The multiplication must be associative, that is the following must be true for any x, y, and z of the type T which implements the Rng:
    (x * y) * z == x * (y * z);
    x * y * z == (x * y) * z;
    x * y * z == x * (y * z);
    Hence result of
    x * y * z
    (without specified order of calculation) is well-defined.

ring_concept

A type implements a behaviour of an algebraic ring with multiplicative identity. Let T be a type which is declared to implement the ring, and x and y be any objects of this type. All objects of type T constitute the ring if the following is true.

  1. The class T meets the requirements of the rng_concept.
  2. The following expressions are valid and correspond to the table below:

    Expression Return/Resolution type Equivalent expression

    Notes

    A containing class satisfies the ring_concept.
    Definition: chsvmath.h:831
    (or any of its successors).

    See algebraic_type.

    @ multiplicative_identity
    A tag to construct multiplicative identity element. See ring_concept.
    Definition: chsvmath.h:1005
    or
    T(1)
    Constructs an object of type T that is a unique multiplicative identity. Both left and right multiplication of such an object with any object x results to x, i.e. for any x of type T comparisons: and must both return true.

commutative_ring_concept

A type implements a behaviour of an algebraic commutative ring. Any class T that is declared to implement a commutative ring has to adhere the following:

  1. The T class meets the requirements of the ring_concept.
  2. A multiplication operation is commutative, i.e. for any x and y of type T
    x * y == y * x
    is true.
  3. An expression must resolve to either Chusov::Math::commutative_ring_algebraic_tag or to one of its successors.

division_ring_concept

A type T implements a behaviour of an algebraic division ring, that is a ring where multiplication is invertible, that is for any \(x\) there exists a unique multiplicative inversion \({x}^{-1}\) such that \(x\cdot {x}^{-1} = 1\), where \(1\) is a multiplicative identity of T constructed as

. Any class implementing the division ring should adhere the following in order to be used with chsvlib:

  1. The T class meets the requirements of the ring_concept.

  2. Additionally, the class T implementing a division ring together with any instance x must adhere the following:
    Expression Return/Resolution type Equivalent expression

    Notes

    (or any of its successors).

    See algebraic_type.

    x.MultiplicativeInverse();
    T
    T y = x;
    y.MultiplicativeInverseMe();
    For built-in floating point value x, for which std::is_floating_point <T>::value is true, the following expression will also be considered equivalent:
    1.0 / x;
    x * x.MultiplicativeInverse() == T(Chusov::Math::multiplicative_identity)

    and

    x.MultiplicativeInverse() * x == T(Chusov::Math::multiplicative_identity)

    must be both true regardless of commutativity of multiplication.

    x.MultiplicativeInverseMe();
    T&
    T y = x.MultiplicativeInverse();
    x = y;
    See above.

field_concept

An algebraic field is both a division ring and a commutative ring, hence the field_concept must adhere the requirements given for both division_ring_concept and commutative_ring_concept, except for the expression

which must be aliased as Chusov::Math::field_algebraic_tag or any of its successors which can be included in future versions of chsvlib or provided by a user.