Monoid.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <HTML>
  2. <!--
  3. Copyright (c) Jeremy Siek, Lie-Quan Lee, and Andrew Lumsdaine 2001
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <Head>
  9. <Title>Monoid</Title>
  10. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  11. ALINK="#ff0000">
  12. <IMG SRC="../../../boost.png"
  13. ALT="C++ Boost" width="277" height="86">
  14. <BR Clear>
  15. <H1><A NAME="concept:Monoid"></A>
  16. Monoid
  17. </H1>
  18. A <i>Monoid</i> is a concept that describes a simple kind of algebraic
  19. system. A <b>monoid</b> consists of a set of elements <i>S</i>, a
  20. binary operation, and an identity element. The C++ representation of a
  21. monoid consists of a function object that implements the binary
  22. operation, a set of objects that represent the elements of <i>S</i>,
  23. and an object that represents the identity element.
  24. <H3>Refinement of</H3>
  25. The element type must be a model of <a
  26. href="../../utility/Assignable.html">Assignable</a> and <a
  27. href="../../utility/CopyConstructible.html">CopyConstructible</a>.
  28. The function object type must be a model of <a
  29. href="http://www.boost.org/sgi/stl/BinaryFunction.html">BinaryFunction</a>.
  30. <h3>Notation</h3>
  31. <Table>
  32. <TR>
  33. <TD><tt>X</tt></TD>
  34. <TD>Is the element type of the Monoid.</TD>
  35. </TR>
  36. <TR>
  37. <TD><tt>a, b</tt></TD>
  38. <TD>are objects of type <tt>X</tt>.</TD>
  39. </TR>
  40. <TR>
  41. <TD><tt>op</tt></TD>
  42. <TD>Is the function object implementing the Monoid operation.</TD>
  43. </TR>
  44. <TR>
  45. <TD><tt>i</tt></TD>
  46. <TD>is an object of type <tt>X</tt> and is the identity element
  47. for the Monoid.</TD>
  48. </TR>
  49. </table>
  50. <h3>Valid Expressions</h3>
  51. <Table border>
  52. <tr>
  53. <td><a name="sec:source"><TT>op(a,&nbsp;b)</TT></a></TD>
  54. <TD>See below for semantics.<br>
  55. Return type: <TT>X</TT>
  56. </TD>
  57. </TR>
  58. <tr>
  59. <TD><TT>a&nbsp;==&nbsp;b</TT></TD>
  60. <TD>Returns true if <tt>a</tt> and <tt>b</tt> represent
  61. the same element of <i>S</i>.<br>
  62. Return type: <TT>bool</TT>
  63. </TD>
  64. </TR>
  65. <tr>
  66. <TD><TT>a&nbsp;!=&nbsp;b</TT></TD>
  67. <TD>Returns true if <tt>a</tt> and <tt>b</tt> represent
  68. different elements of <i>S</i>.<br>
  69. Return type: <TT>bool</TT>
  70. </TD>
  71. </TR>
  72. </TABLE>
  73. <P>
  74. <H3>Invariants</H3>
  75. <UL>
  76. <li>Closure<br>
  77. The result of <tt>op(a, b)</tt> is also an element of <i>S</i>.
  78. <li>Associativity<br>
  79. <tt>op(op(a, b), c) == op(a, op(b, c))</tt>
  80. <li>Definition of Identity Element<br>
  81. <tt>op(a, i) == a</tt>
  82. </UL>
  83. <br>
  84. <HR>
  85. <TABLE>
  86. <TR valign=top>
  87. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  88. <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>,
  89. Indiana University (<A
  90. HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
  91. <A HREF="http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee</A>, Indiana University (<A HREF="mailto:llee@cs.indiana.edu">llee@cs.indiana.edu</A>)<br>
  92. <A HREF="https://homes.cs.washington.edu/~al75">Andrew Lumsdaine</A>,
  93. Indiana University (<A
  94. HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
  95. </TD></TR></TABLE>
  96. </BODY>
  97. </HTML>