ring.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*!
  2. @file
  3. Forward declares `boost::hana::Ring`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_FWD_CONCEPT_RING_HPP
  9. #define BOOST_HANA_FWD_CONCEPT_RING_HPP
  10. #include <boost/hana/config.hpp>
  11. BOOST_HANA_NAMESPACE_BEGIN
  12. //! @ingroup group-concepts
  13. //! @defgroup group-Ring Ring
  14. //! The `Ring` concept represents `Group`s that also form a `Monoid`
  15. //! under a second binary operation that distributes over the first.
  16. //!
  17. //! A [Ring][1] is an algebraic structure built on top of a `Group`
  18. //! which requires a monoidal structure with respect to a second binary
  19. //! operation. This second binary operation must distribute over the
  20. //! first one. Specifically, a `Ring` is a triple `(S, +, *)` such that
  21. //! `(S, +)` is a `Group`, `(S, *)` is a `Monoid` and `*` distributes
  22. //! over `+`, i.e.
  23. //! @code
  24. //! x * (y + z) == (x * y) + (x * z)
  25. //! @endcode
  26. //!
  27. //! The second binary operation is often written `*` with its identity
  28. //! written `1`, in reference to the `Ring` of integers under
  29. //! multiplication. The method names used here refer to this exact ring.
  30. //!
  31. //!
  32. //! Minimal complete definintion
  33. //! ----------------------------
  34. //! `one` and `mult` satisfying the laws
  35. //!
  36. //!
  37. //! Laws
  38. //! ----
  39. //! For all objects `x`, `y`, `z` of a `Ring` `R`, the following laws must
  40. //! be satisfied:
  41. //! @code
  42. //! mult(x, mult(y, z)) == mult(mult(x, y), z) // associativity
  43. //! mult(x, one<R>()) == x // right identity
  44. //! mult(one<R>(), x) == x // left identity
  45. //! mult(x, plus(y, z)) == plus(mult(x, y), mult(x, z)) // distributivity
  46. //! @endcode
  47. //!
  48. //!
  49. //! Refined concepts
  50. //! ----------------
  51. //! `Monoid`, `Group`
  52. //!
  53. //!
  54. //! Concrete models
  55. //! ---------------
  56. //! `hana::integral_constant`
  57. //!
  58. //!
  59. //! Free model for non-boolean arithmetic data types
  60. //! ------------------------------------------------
  61. //! A data type `T` is arithmetic if `std::is_arithmetic<T>::%value` is
  62. //! true. For a non-boolean arithmetic data type `T`, a model of `Ring` is
  63. //! automatically defined by using the provided `Group` model and setting
  64. //! @code
  65. //! mult(x, y) = (x * y)
  66. //! one<T>() = static_cast<T>(1)
  67. //! @endcode
  68. //!
  69. //! @note
  70. //! The rationale for not providing a Ring model for `bool` is the same
  71. //! as for not providing Monoid and Group models.
  72. //!
  73. //!
  74. //! Structure-preserving functions
  75. //! ------------------------------
  76. //! Let `A` and `B` be two `Ring`s. A function `f : A -> B` is said to
  77. //! be a [Ring morphism][2] if it preserves the ring structure between
  78. //! `A` and `B`. Rigorously, for all objects `x, y` of data type `A`,
  79. //! @code
  80. //! f(plus(x, y)) == plus(f(x), f(y))
  81. //! f(mult(x, y)) == mult(f(x), f(y))
  82. //! f(one<A>()) == one<B>()
  83. //! @endcode
  84. //! Because of the `Ring` structure, it is easy to prove that the
  85. //! following will then also be satisfied:
  86. //! @code
  87. //! f(zero<A>()) == zero<B>()
  88. //! f(negate(x)) == negate(f(x))
  89. //! @endcode
  90. //! which is to say that `f` will then also be a `Group` morphism.
  91. //! Functions with these properties interact nicely with `Ring`s,
  92. //! which is why they are given such a special treatment.
  93. //!
  94. //!
  95. //! [1]: http://en.wikipedia.org/wiki/Ring_(mathematics)
  96. //! [2]: http://en.wikipedia.org/wiki/Ring_homomorphism
  97. template <typename R>
  98. struct Ring;
  99. BOOST_HANA_NAMESPACE_END
  100. #endif // !BOOST_HANA_FWD_CONCEPT_RING_HPP