Group
Concepts

## Description

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.

## Minimal complete definitions

1. `minus`
   When `minus` is specified, the `negate` method is defaulted by setting
   negate(x) = minus(zero<G>(), x)
   boost::hana::negate
   constexpr auto negate
   Return the inverse of an element of a group.
   Definition: negate.hpp:26
   boost::hana::minus
   constexpr auto minus
   Subtract two elements of a group.
   Definition: minus.hpp:51
2. `negate`
   When `negate` is specified, the `minus` method is defaulted by setting
   minus(x, y) = plus(x, negate(y))
   boost::hana::plus
   constexpr auto plus
   Associative binary operation on a Monoid.
   Definition: plus.hpp:47

## Laws

For all objects `x` of a `Group` `G`, the following laws must be satisfied:

plus(x, negate(x)) == zero<G>() // right inverse
plus(negate(x), x) == zero<G>() // left inverse
boost::hana::zero
constexpr auto zero
Identity of plus.
Definition: zero.hpp:30

## Refined concept

`Monoid`

## Concrete models

`hana::integral_constant`

## Free model for non-boolean arithmetic data types

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

minus(x, y) = (x - y)
negate(x) = -x

Note
  The rationale for not providing a Group model for `bool` is the same as for not providing a `Monoid` model.

## Structure-preserving functions

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`,

f(plus(x, y)) == plus(f(x), f(y))

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

f(negate(x)) == negate(f(x))
f(zero<A>()) == zero<B>()

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. More...
constexpr auto | boost::hana::negate
| Return the inverse of an element of a group. More...

## Variable Documentation

## minus

constexpr auto boost::hana::minus

constexpr

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

Initial value:
= [](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:

minus(x, y) == plus(x, negate(y))

## Cross-type version of the method

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

1. `A` and `B` share a common data type `C`, as determined by the `common` metafunction
2. `A`, `B` and `C` are all `Group`s when taken individually
3. `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

minus(x, y) = minus(to<C>(x), to<C>(y))

## Example

// 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, "");
}
assert.hpp
Defines macros to perform different kinds of assertions.
equal.hpp
Defines boost::hana::equal.
BOOST_HANA_CONSTANT_CHECK
#define BOOST_HANA_CONSTANT_CHECK(...)
Equivalent to BOOST_HANA_CONSTANT_ASSERT, but not influenced by the BOOST_HANA_CONFIG_DISABLE_ASSERTI...
Definition: assert.hpp:239
integral_constant.hpp
Defines boost::hana::integral_constant.
minus.hpp
Defines boost::hana::minus.
boost::hana
Namespace containing everything in the library.
Definition: accessors.hpp:20

## negate

constexpr auto boost::hana::negate

constexpr

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

Initial value:
= [](auto&& x) -> decltype(auto) {
return tag-dispatched;
}

Return the inverse of an element of a group.

## Example

// 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, "");
}
negate.hpp
Defines boost::hana::negate.