euclidean_ring.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*!
  2. @file
  3. Forward declares `boost::hana::EuclideanRing`.
  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_EUCLIDEAN_RING_HPP
  9. #define BOOST_HANA_FWD_CONCEPT_EUCLIDEAN_RING_HPP
  10. #include <boost/hana/config.hpp>
  11. BOOST_HANA_NAMESPACE_BEGIN
  12. //! @ingroup group-concepts
  13. //! @defgroup group-EuclideanRing Euclidean Ring
  14. //! The `EuclideanRing` concept represents a commutative `Ring` that
  15. //! can also be endowed with a division algorithm.
  16. //!
  17. //! A Ring defines a binary operation often called _multiplication_ that
  18. //! can be used to combine two elements of the ring into a new element of
  19. //! the ring. An [Euclidean ring][1], also called an Euclidean domain, adds
  20. //! the ability to define a special function that generalizes the Euclidean
  21. //! division of integers.
  22. //!
  23. //! However, an Euclidean ring must also satisfy one more property, which
  24. //! is that of having no non-zero zero divisors. In a Ring `(R, +, *)`, it
  25. //! follows quite easily from the axioms that `x * 0 == 0` for any ring
  26. //! element `x`. However, there is nothing that mandates `0` to be the
  27. //! only ring element sending other elements to `0`. Hence, in some Rings,
  28. //! it is possible to have elements `x` and `y` such that `x * y == 0`
  29. //! while not having `x == 0` nor `y == 0`. We call these elements divisors
  30. //! of zero, or zero divisors. For example, this situation arises in the
  31. //! Ring of integers modulo 4 (the set `{0, 1, 2, 3}`) with addition and
  32. //! multiplication `mod 4` as binary operations. In this case, we have that
  33. //! @code
  34. //! 2 * 2 == 4
  35. //! == 0 (mod 4)
  36. //! @endcode
  37. //! even though `2 != 0 (mod 4)`.
  38. //!
  39. //! Following this line of thought, an Euclidean ring requires its only
  40. //! zero divisor is zero itself. In other words, the multiplication in an
  41. //! Euclidean won't send two non-zero elements to zero. Also note that
  42. //! since multiplication in a `Ring` is not necessarily commutative, it
  43. //! is not always the case that
  44. //! @code
  45. //! x * y == 0 implies y * x == 0
  46. //! @endcode
  47. //! To be rigorous, we should then distinguish between elements that are
  48. //! zero divisors when multiplied to the right and to the left.
  49. //! Fortunately, the concept of an Euclidean ring requires the Ring
  50. //! multiplication to be commutative. Hence,
  51. //! @code
  52. //! x * y == y * x
  53. //! @endcode
  54. //! and we do not have to distinguish between left and right zero divisors.
  55. //!
  56. //! Typical examples of Euclidean rings include integers and polynomials
  57. //! over a field. The method names used here refer to the Euclidean ring
  58. //! of integers under the usual addition, multiplication and division
  59. //! operations.
  60. //!
  61. //!
  62. //! Minimal complete definition
  63. //! ---------------------------
  64. //! `div` and `mod` satisfying the laws below
  65. //!
  66. //!
  67. //! Laws
  68. //! ----
  69. //! To simplify the reading, we will use the `+`, `*`, `/` and `%`
  70. //! operators with infix notation to denote the application of the
  71. //! corresponding methods in Monoid, Group, Ring and EuclideanRing.
  72. //! For all objects `a` and `b` of an `EuclideanRing` `R`, the
  73. //! following laws must be satisfied:
  74. //! @code
  75. //! a * b == b * a // commutativity
  76. //! (a / b) * b + a % b == a if b is non-zero
  77. //! zero<R>() % b == zero<R>() if b is non-zero
  78. //! @endcode
  79. //!
  80. //!
  81. //! Refined concepts
  82. //! ----------------
  83. //! `Monoid`, `Group`, `Ring`
  84. //!
  85. //!
  86. //! Concrete models
  87. //! ---------------
  88. //! `hana::integral_constant`
  89. //!
  90. //!
  91. //! Free model for non-boolean integral data types
  92. //! ----------------------------------------------
  93. //! A data type `T` is integral if `std::is_integral<T>::%value` is true.
  94. //! For a non-boolean integral data type `T`, a model of `EuclideanRing`
  95. //! is automatically defined by using the `Ring` model provided for
  96. //! arithmetic data types and setting
  97. //! @code
  98. //! div(x, y) = (x / y)
  99. //! mod(x, y) = (x % y)
  100. //! @endcode
  101. //!
  102. //! @note
  103. //! The rationale for not providing an EuclideanRing model for `bool` is
  104. //! the same as for not providing Monoid, Group and Ring models.
  105. //!
  106. //!
  107. //! [1]: https://en.wikipedia.org/wiki/Euclidean_domain
  108. template <typename R>
  109. struct EuclideanRing;
  110. BOOST_HANA_NAMESPACE_END
  111. #endif // !BOOST_HANA_FWD_CONCEPT_EUCLIDEAN_RING_HPP