The `Group`

concept represents `Monoid`

s where all objects have an inverse w.r.t. the `Monoid`

's binary operation.

A Group is an algebraic structure built on top of a `Monoid`

which adds the ability to invert the action of the `Monoid`

's binary operation on any element of the set. Specifically, a `Group`

is a `Monoid`

`(S, +)`

such that every element `s`

in `S`

has an inverse (say `s'`

) which is such that

s + s' == s' + s == identity of the Monoid

There are many examples of `Group`

s, one of which would be the additive `Monoid`

on integers, where the inverse of any integer `n`

is the integer `-n`

. The method names used here refer to exactly this model.

`minus`

When`minus`

is specified, the`negate`

method is defaulted by setting`negate`

When`negate`

is specified, the`minus`

method is defaulted by setting

For all objects `x`

of a `Group`

`G`

, the following laws must be satisfied:

`Monoid`

A data type `T`

is arithmetic if `std::is_arithmetic<T>::value`

is true. For a non-boolean arithmetic data type `T`

, a model of `Group`

is automatically defined by setting

- Note
- The rationale for not providing a Group model for
`bool`

is the same as for not providing a`Monoid`

model.

Let `A`

and `B`

be two `Group`

s. A function `f : A -> B`

is said to be a Group morphism if it preserves the group structure between `A`

and `B`

. Rigorously, for all objects `x, y`

of data type `A`

,

Because of the `Group`

structure, it is easy to prove that the following will then also be satisfied:

Functions with these properties interact nicely with `Group`

s, which is why they are given such a special treatment.

## Variables | |

constexpr auto | boost::hana::minus |

Subtract two elements of a group.Specifically, this performs the `Monoid` operation on the first argument and on the inverse of the second argument, thus being equivalent to: More... | |

constexpr auto | boost::hana::negate |

Return the inverse of an element of a group. More... | |

constexpr auto boost::hana::minus |

`#include <boost/hana/fwd/minus.hpp>`

= [](auto&& x, auto&& y) -> decltype(auto) {

return tag-dispatched;

}

Subtract two elements of a group.Specifically, this performs the `Monoid`

operation on the first argument and on the inverse of the second argument, thus being equivalent to:

The `minus`

method is "overloaded" to handle distinct data types with certain properties. Specifically, `minus`

is defined for *distinct* data types `A`

and `B`

such that

`A`

and`B`

share a common data type`C`

, as determined by the`common`

metafunction`A`

,`B`

and`C`

are all`Group`

s when taken individually`to<C> : A -> B`

and`to<C> : B -> C`

are`Group`

-embeddings, as determined by the`is_embedding`

metafunction.

The definition of `minus`

for data types satisfying the above properties is obtained by setting

// Copyright Louis Dionne 2013-2017

// Distributed under the Boost Software License, Version 1.0.

// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)

#include <boost/hana/assert.hpp>

#include <boost/hana/equal.hpp>

#include <boost/hana/integral_constant.hpp>

#include <boost/hana/minus.hpp>

namespace hana = boost::hana;

int main() {

BOOST_HANA_CONSTANT_CHECK(hana::minus(hana::int_c<3>, hana::int_c<5>) == hana::int_c<-2>);

static_assert(hana::minus(1, 2) == -1, "");

}

constexpr auto boost::hana::negate |

`#include <boost/hana/fwd/negate.hpp>`

= [](auto&& x) -> decltype(auto) {

return tag-dispatched;

}

Return the inverse of an element of a group.

// Copyright Louis Dionne 2013-2017

// Distributed under the Boost Software License, Version 1.0.

// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)

#include <boost/hana/assert.hpp>

#include <boost/hana/equal.hpp>

#include <boost/hana/integral_constant.hpp>

#include <boost/hana/negate.hpp>

namespace hana = boost::hana;

int main() {

BOOST_HANA_CONSTANT_CHECK(hana::negate(hana::int_c<3>) == hana::int_c<-3>);

static_assert(hana::negate(2) == -2, "");

}