group__group-Group.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <!--
  2. Copyright Louis Dionne 2013-2017
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  5. -->
  6. <!-- boost-no-inspect -->
  7. <!-- HTML header for doxygen 1.8.9.1-->
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  12. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  13. <meta name="generator" content="Doxygen 1.8.15"/>
  14. <title>Boost.Hana: Group</title>
  15. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  16. <script type="text/javascript" src="jquery.js"></script>
  17. <script type="text/javascript" src="dynsections.js"></script>
  18. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  19. <script type="text/javascript" src="resize.js"></script>
  20. <script type="text/javascript" src="navtreedata.js"></script>
  21. <script type="text/javascript" src="navtree.js"></script>
  22. <script type="text/javascript">
  23. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  24. $(document).ready(initResizable);
  25. /* @license-end */</script>
  26. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  27. <script type="text/javascript" src="search/searchdata.js"></script>
  28. <script type="text/javascript" src="search/search.js"></script>
  29. <script type="text/javascript">
  30. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  31. $(document).ready(function() { init_search(); });
  32. /* @license-end */
  33. </script>
  34. <script type="text/x-mathjax-config">
  35. MathJax.Hub.Config({
  36. extensions: ["tex2jax.js"],
  37. jax: ["input/TeX","output/HTML-CSS"],
  38. });
  39. // Copyright Louis Dionne 2013-2017
  40. // Distributed under the Boost Software License, Version 1.0.
  41. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  42. MathJax.Hub.Config({
  43. "HTML-CSS": {
  44. linebreaks: {
  45. automatic: true,
  46. width: "75% container"
  47. }
  48. }
  49. });
  50. </script><script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
  51. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  52. <!-- Additional javascript for drawing charts. -->
  53. <script type="text/javascript" src="highcharts.js"></script>
  54. <script type="text/javascript" src="highcharts-data.js"></script>
  55. <script type="text/javascript" src="highcharts-exporting.js"></script>
  56. <script type="text/javascript" src="chart.js"></script>
  57. <script type="text/javascript" src="hana.js"></script>
  58. </head>
  59. <body>
  60. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  61. <div id="titlearea">
  62. <table cellspacing="0" cellpadding="0">
  63. <tbody>
  64. <tr style="height: 56px;">
  65. <td id="projectlogo"><img alt="Logo" src="Boost.png"/></td>
  66. <td style="padding-left: 0.5em;">
  67. <div id="projectname">Boost.Hana
  68. &#160;<span id="projectnumber">1.6.0</span>
  69. </div>
  70. <div id="projectbrief">Your standard library for metaprogramming</div>
  71. </td>
  72. <td> <div id="MSearchBox" class="MSearchBoxInactive">
  73. <span class="left">
  74. <img id="MSearchSelect" src="search/mag_sel.png"
  75. onmouseover="return searchBox.OnSearchSelectShow()"
  76. onmouseout="return searchBox.OnSearchSelectHide()"
  77. alt=""/>
  78. <input type="text" id="MSearchField" value="Search" accesskey="S"
  79. onfocus="searchBox.OnSearchFieldFocus(true)"
  80. onblur="searchBox.OnSearchFieldFocus(false)"
  81. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  82. </span><span class="right">
  83. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  84. </span>
  85. </div>
  86. </td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. </div>
  91. <!-- end header part -->
  92. <!-- Generated by Doxygen 1.8.15 -->
  93. <script type="text/javascript">
  94. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  95. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  96. /* @license-end */
  97. </script>
  98. </div><!-- top -->
  99. <div id="side-nav" class="ui-resizable side-nav-resizable">
  100. <div id="nav-tree">
  101. <div id="nav-tree-contents">
  102. <div id="nav-sync" class="sync"></div>
  103. </div>
  104. </div>
  105. <div id="splitbar" style="-moz-user-select:none;"
  106. class="ui-resizable-handle">
  107. </div>
  108. </div>
  109. <script type="text/javascript">
  110. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  111. $(document).ready(function(){initNavTree('group__group-Group.html','');});
  112. /* @license-end */
  113. </script>
  114. <div id="doc-content">
  115. <!-- window showing the filter options -->
  116. <div id="MSearchSelectWindow"
  117. onmouseover="return searchBox.OnSearchSelectShow()"
  118. onmouseout="return searchBox.OnSearchSelectHide()"
  119. onkeydown="return searchBox.OnSearchSelectKey(event)">
  120. </div>
  121. <!-- iframe showing the search results (closed by default) -->
  122. <div id="MSearchResultsWindow">
  123. <iframe src="javascript:void(0)" frameborder="0"
  124. name="MSearchResults" id="MSearchResults">
  125. </iframe>
  126. </div>
  127. <div class="header">
  128. <div class="summary">
  129. <a href="#var-members">Variables</a> </div>
  130. <div class="headertitle">
  131. <div class="title">Group<div class="ingroups"><a class="el" href="group__group-concepts.html">Concepts</a></div></div> </div>
  132. </div><!--header-->
  133. <div class="contents">
  134. <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
  135. <p>The <code>Group</code> concept represents <code>Monoid</code>s where all objects have an inverse w.r.t. the <code>Monoid</code>'s binary operation. </p>
  136. <p>A <a href="http://en.wikipedia.org/wiki/Group_(mathematics)">Group</a> is an algebraic structure built on top of a <code>Monoid</code> which adds the ability to invert the action of the <code>Monoid</code>'s binary operation on any element of the set. Specifically, a <code>Group</code> is a <code>Monoid</code> <code>(S, +)</code> such that every element <code>s</code> in <code>S</code> has an inverse (say &lsquo;s&rsquo;`) which is such that </p><div class="fragment"><div class="line">s + s<span class="stringliteral">&#39; == s&#39;</span> + s == identity of the Monoid</div></div><!-- fragment --><p>There are many examples of <code>Group</code>s, one of which would be the additive <code>Monoid</code> on integers, where the inverse of any integer <code>n</code> is the integer <code>-n</code>. The method names used here refer to exactly this model.</p>
  137. <h2>Minimal complete definitions </h2>
  138. <ol type="1">
  139. <li><code>minus</code><br />
  140. When <code>minus</code> is specified, the <code>negate</code> method is defaulted by setting <div class="fragment"><div class="line"><a class="code" href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">negate</a>(x) = <a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">minus</a>(zero&lt;G&gt;(), x)</div></div><!-- fragment --></li>
  141. <li><code>negate</code><br />
  142. When <code>negate</code> is specified, the <code>minus</code> method is defaulted by setting <div class="fragment"><div class="line"><a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">minus</a>(x, y) = <a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">plus</a>(x, <a class="code" href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">negate</a>(y))</div></div><!-- fragment --></li>
  143. </ol>
  144. <h2>Laws </h2>
  145. <p>For all objects <code>x</code> of a <code>Group</code> <code>G</code>, the following laws must be satisfied: </p><div class="fragment"><div class="line"><a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">plus</a>(x, <a class="code" href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">negate</a>(x)) == zero&lt;G&gt;() <span class="comment">// right inverse</span></div><div class="line"><a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">plus</a>(<a class="code" href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">negate</a>(x), x) == <a class="code" href="group__group-Monoid.html#gad459ac17b6bab8ead1cae7de0032f3c6">zero</a>&lt;G&gt;() <span class="comment">// left inverse</span></div></div><!-- fragment --><h2>Refined concept </h2>
  146. <p><code>Monoid</code></p>
  147. <h2>Concrete models </h2>
  148. <p><code><a class="el" href="structboost_1_1hana_1_1integral__constant.html" title="Compile-time value of an integral type.">hana::integral_constant</a></code></p>
  149. <h2>Free model for non-boolean arithmetic data types </h2>
  150. <p>A data type <code>T</code> is arithmetic if <code>std::is_arithmetic&lt;T&gt;::value</code> is true. For a non-boolean arithmetic data type <code>T</code>, a model of <code>Group</code> is automatically defined by setting </p><div class="fragment"><div class="line"><a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">minus</a>(x, y) = (x - y)</div><div class="line"><a class="code" href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">negate</a>(x) = -x</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>The rationale for not providing a Group model for <code>bool</code> is the same as for not providing a <code>Monoid</code> model.</dd></dl>
  151. <h2>Structure-preserving functions </h2>
  152. <p>Let <code>A</code> and <code>B</code> be two <code>Group</code>s. A function <code>f : A -&gt; B</code> is said to be a <a href="http://en.wikipedia.org/wiki/Group_homomorphism">Group morphism</a> if it preserves the group structure between <code>A</code> and <code>B</code>. Rigorously, for all objects <code>x, y</code> of data type <code>A</code>, </p><div class="fragment"><div class="line">f(<a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">plus</a>(x, y)) == <a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">plus</a>(f(x), f(y))</div></div><!-- fragment --><p> Because of the <code>Group</code> structure, it is easy to prove that the following will then also be satisfied: </p><div class="fragment"><div class="line">f(<a class="code" href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">negate</a>(x)) == <a class="code" href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">negate</a>(f(x))</div><div class="line">f(zero&lt;A&gt;()) == zero&lt;B&gt;()</div></div><!-- fragment --><p> Functions with these properties interact nicely with <code>Group</code>s, which is why they are given such a special treatment. </p>
  153. <table class="memberdecls">
  154. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
  155. Variables</h2></td></tr>
  156. <tr class="memitem:ga2020c526324f361a2b990fe8d1b07c20"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">boost::hana::minus</a></td></tr>
  157. <tr class="memdesc:ga2020c526324f361a2b990fe8d1b07c20"><td class="mdescLeft">&#160;</td><td class="mdescRight">Subtract two elements of a group.Specifically, this performs the <code>Monoid</code> operation on the first argument and on the inverse of the second argument, thus being equivalent to: <a href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">More...</a><br /></td></tr>
  158. <tr class="separator:ga2020c526324f361a2b990fe8d1b07c20"><td class="memSeparator" colspan="2">&#160;</td></tr>
  159. <tr class="memitem:ga02e81002f40ba52eac4cf1974c7e0cdb"><td class="memItemLeft" align="right" valign="top">constexpr auto&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">boost::hana::negate</a></td></tr>
  160. <tr class="memdesc:ga02e81002f40ba52eac4cf1974c7e0cdb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return the inverse of an element of a group. <a href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">More...</a><br /></td></tr>
  161. <tr class="separator:ga02e81002f40ba52eac4cf1974c7e0cdb"><td class="memSeparator" colspan="2">&#160;</td></tr>
  162. </table>
  163. <h2 class="groupheader">Variable Documentation</h2>
  164. <a id="ga2020c526324f361a2b990fe8d1b07c20"></a>
  165. <h2 class="memtitle"><span class="permalink"><a href="#ga2020c526324f361a2b990fe8d1b07c20">&#9670;&nbsp;</a></span>minus</h2>
  166. <div class="memitem">
  167. <div class="memproto">
  168. <table class="memname">
  169. <tr>
  170. <td class="memname">constexpr auto boost::hana::minus</td>
  171. </tr>
  172. </table>
  173. </div><div class="memdoc">
  174. <p><code>#include &lt;<a class="el" href="fwd_2minus_8hpp.html">boost/hana/fwd/minus.hpp</a>&gt;</code></p>
  175. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; x, <span class="keyword">auto</span>&amp;&amp; y) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> tag-dispatched;</div><div class="line"> }</div></div><!-- fragment -->
  176. <p>Subtract two elements of a group.Specifically, this performs the <code>Monoid</code> operation on the first argument and on the inverse of the second argument, thus being equivalent to: </p>
  177. <div class="fragment"><div class="line"><a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">minus</a>(x, y) == <a class="code" href="group__group-Monoid.html#gaeb5d4a1e967e319712f9e4791948896c">plus</a>(x, <a class="code" href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">negate</a>(y))</div></div><!-- fragment --><h2>Cross-type version of the method </h2>
  178. <p>The <code>minus</code> method is "overloaded" to handle distinct data types with certain properties. Specifically, <code>minus</code> is defined for <em>distinct</em> data types <code>A</code> and <code>B</code> such that</p><ol type="1">
  179. <li><code>A</code> and <code>B</code> share a common data type <code>C</code>, as determined by the <code>common</code> metafunction</li>
  180. <li><code>A</code>, <code>B</code> and <code>C</code> are all <code>Group</code>s when taken individually</li>
  181. <li><code>to&lt;C&gt; : A -&gt; B</code> and <code>to&lt;C&gt; : B -&gt; C</code> are <code>Group</code>-embeddings, as determined by the <code>is_embedding</code> metafunction.</li>
  182. </ol>
  183. <p>The definition of <code>minus</code> for data types satisfying the above properties is obtained by setting </p><div class="fragment"><div class="line"><a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">minus</a>(x, y) = <a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">minus</a>(to&lt;C&gt;(x), to&lt;C&gt;(y))</div></div><!-- fragment --><h2>Example </h2>
  184. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="integral__constant_8hpp.html">boost/hana/integral_constant.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="minus_8hpp.html">boost/hana/minus.hpp</a>&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">hana::minus</a>(hana::int_c&lt;3&gt;, hana::int_c&lt;5&gt;) == hana::int_c&lt;-2&gt;);</div><div class="line"> static_assert(<a class="code" href="group__group-Group.html#ga2020c526324f361a2b990fe8d1b07c20">hana::minus</a>(1, 2) == -1, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">}</div></div><!-- fragment -->
  185. </div>
  186. </div>
  187. <a id="ga02e81002f40ba52eac4cf1974c7e0cdb"></a>
  188. <h2 class="memtitle"><span class="permalink"><a href="#ga02e81002f40ba52eac4cf1974c7e0cdb">&#9670;&nbsp;</a></span>negate</h2>
  189. <div class="memitem">
  190. <div class="memproto">
  191. <table class="memname">
  192. <tr>
  193. <td class="memname">constexpr auto boost::hana::negate</td>
  194. </tr>
  195. </table>
  196. </div><div class="memdoc">
  197. <p><code>#include &lt;<a class="el" href="fwd_2negate_8hpp.html">boost/hana/fwd/negate.hpp</a>&gt;</code></p>
  198. <b>Initial value:</b><div class="fragment"><div class="line">= [](<span class="keyword">auto</span>&amp;&amp; x) -&gt; decltype(<span class="keyword">auto</span>) {</div><div class="line"> <span class="keywordflow">return</span> tag-dispatched;</div><div class="line"> }</div></div><!-- fragment -->
  199. <p>Return the inverse of an element of a group. </p>
  200. <h2>Example </h2>
  201. <div class="fragment"><div class="line"><span class="comment">// Copyright Louis Dionne 2013-2017</span></div><div class="line"><span class="comment">// Distributed under the Boost Software License, Version 1.0.</span></div><div class="line"><span class="comment">// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="assert_8hpp.html">boost/hana/assert.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="equal_8hpp.html">boost/hana/equal.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="integral__constant_8hpp.html">boost/hana/integral_constant.hpp</a>&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="negate_8hpp.html">boost/hana/negate.hpp</a>&gt;</span></div><div class="line"><span class="keyword">namespace </span>hana = <a class="code" href="namespaceboost_1_1hana.html">boost::hana</a>;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main() {</div><div class="line"> <a class="code" href="group__group-assertions.html#ga2c5006540936d9f8880e3a39f4fcc035">BOOST_HANA_CONSTANT_CHECK</a>(<a class="code" href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">hana::negate</a>(hana::int_c&lt;3&gt;) == hana::int_c&lt;-3&gt;);</div><div class="line"> static_assert(<a class="code" href="group__group-Group.html#ga02e81002f40ba52eac4cf1974c7e0cdb">hana::negate</a>(2) == -2, <span class="stringliteral">&quot;&quot;</span>);</div><div class="line">}</div></div><!-- fragment -->
  202. </div>
  203. </div>
  204. </div><!-- contents -->
  205. </div><!-- doc-content -->
  206. <!--
  207. Copyright Louis Dionne 2013-2017
  208. Distributed under the Boost Software License, Version 1.0.
  209. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  210. -->
  211. <!-- boost-no-inspect -->
  212. <!-- HTML footer for doxygen 1.8.9.1-->
  213. <!-- start footer part -->
  214. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  215. <ul>
  216. </ul>
  217. </div>
  218. </body>
  219. </html>