This file is indexed.

/usr/share/gap/doc/ref/chap78.html is in gap-doc 4r8p6-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>GAP (ref) - Chapter 78: Method Selection</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
<script src="manual.js" type="text/javascript"></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap78"  onload="jscontent()">


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chap11.html">11</a>  <a href="chap12.html">12</a>  <a href="chap13.html">13</a>  <a href="chap14.html">14</a>  <a href="chap15.html">15</a>  <a href="chap16.html">16</a>  <a href="chap17.html">17</a>  <a href="chap18.html">18</a>  <a href="chap19.html">19</a>  <a href="chap20.html">20</a>  <a href="chap21.html">21</a>  <a href="chap22.html">22</a>  <a href="chap23.html">23</a>  <a href="chap24.html">24</a>  <a href="chap25.html">25</a>  <a href="chap26.html">26</a>  <a href="chap27.html">27</a>  <a href="chap28.html">28</a>  <a href="chap29.html">29</a>  <a href="chap30.html">30</a>  <a href="chap31.html">31</a>  <a href="chap32.html">32</a>  <a href="chap33.html">33</a>  <a href="chap34.html">34</a>  <a href="chap35.html">35</a>  <a href="chap36.html">36</a>  <a href="chap37.html">37</a>  <a href="chap38.html">38</a>  <a href="chap39.html">39</a>  <a href="chap40.html">40</a>  <a href="chap41.html">41</a>  <a href="chap42.html">42</a>  <a href="chap43.html">43</a>  <a href="chap44.html">44</a>  <a href="chap45.html">45</a>  <a href="chap46.html">46</a>  <a href="chap47.html">47</a>  <a href="chap48.html">48</a>  <a href="chap49.html">49</a>  <a href="chap50.html">50</a>  <a href="chap51.html">51</a>  <a href="chap52.html">52</a>  <a href="chap53.html">53</a>  <a href="chap54.html">54</a>  <a href="chap55.html">55</a>  <a href="chap56.html">56</a>  <a href="chap57.html">57</a>  <a href="chap58.html">58</a>  <a href="chap59.html">59</a>  <a href="chap60.html">60</a>  <a href="chap61.html">61</a>  <a href="chap62.html">62</a>  <a href="chap63.html">63</a>  <a href="chap64.html">64</a>  <a href="chap65.html">65</a>  <a href="chap66.html">66</a>  <a href="chap67.html">67</a>  <a href="chap68.html">68</a>  <a href="chap69.html">69</a>  <a href="chap70.html">70</a>  <a href="chap71.html">71</a>  <a href="chap72.html">72</a>  <a href="chap73.html">73</a>  <a href="chap74.html">74</a>  <a href="chap75.html">75</a>  <a href="chap76.html">76</a>  <a href="chap77.html">77</a>  <a href="chap78.html">78</a>  <a href="chap79.html">79</a>  <a href="chap80.html">80</a>  <a href="chap81.html">81</a>  <a href="chap82.html">82</a>  <a href="chap83.html">83</a>  <a href="chap84.html">84</a>  <a href="chap85.html">85</a>  <a href="chap86.html">86</a>  <a href="chap87.html">87</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<div class="chlinkprevnexttop">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp;  <a href="chap0.html#contents">[Contents]</a>&nbsp;  &nbsp;<a href="chap77.html">[Previous Chapter]</a>&nbsp;  &nbsp;<a href="chap79.html">[Next Chapter]</a>&nbsp;  </div>

<p id="mathjaxlink" class="pcenter"><a href="chap78_mj.html">[MathJax on]</a></p>
<p><a id="X8058CC8187162644" name="X8058CC8187162644"></a></p>
<div class="ChapSects"><a href="chap78.html#X8058CC8187162644">78 <span class="Heading">Method Selection</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap78.html#X7AEED9AB824CD4DA">78.1 <span class="Heading">Operations and Methods</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap78.html#X795EE8257848B438">78.2 <span class="Heading">Method Installation</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap78.html#X837EFDAB7BEF290B">78.2-1 InstallMethod</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap78.html#X7D2C12DB841CE539">78.2-2 InstallOtherMethod</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap78.html#X851FC6387CA2B241">78.3 <span class="Heading">Applicable Methods and Method Selection</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap78.html#X846865A681D4A623">78.4 <span class="Heading">Partial Methods</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap78.html#X7EED949B83046A7F">78.4-1 TryNextMethod</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap78.html#X7B85DD797A907106">78.5 <span class="Heading">Redispatching</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap78.html#X7D4A46CE7BCFCCF5">78.5-1 RedispatchOnCondition</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap78.html#X87D38D2584D0A8AF">78.6 <span class="Heading">Immediate Methods</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap78.html#X87B47AC0849611F8">78.6-1 InstallImmediateMethod</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap78.html#X7FB5016E83DB4349">78.7 <span class="Heading">Logical Implications</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap78.html#X860B8B707995CFE3">78.7-1 InstallTrueMethod</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap78.html#X855FE25783FB0D4E">78.8 <span class="Heading">Operations and Mathematical Terms</span></a>
</span>
</div>
</div>

<h3>78 <span class="Heading">Method Selection</span></h3>

<p>This chapter explains how <strong class="pkg">GAP</strong> decides which function to call for which types of objects. It assumes that you have read the chapters about objects (Chapter <a href="chap12.html#X86710F997832ABA4"><span class="RefLink">12</span></a>) and types (Chapter <a href="chap13.html#X7E8202627B421DB1"><span class="RefLink">13</span></a>).</p>

<p>An <em>operation</em> is a special <strong class="pkg">GAP</strong> function that bundles a set of functions, its <em>methods</em>.</p>

<p>All methods of an operation compute the same result. But each method is installed for specific types of arguments.</p>

<p>If an operation is called with a tuple of arguments, one of the applicable methods is selected and called.</p>

<p>Special cases of methods are partial methods, immediate methods, and logical implications.</p>

<p><a id="X7AEED9AB824CD4DA" name="X7AEED9AB824CD4DA"></a></p>

<h4>78.1 <span class="Heading">Operations and Methods</span></h4>

<p>Operations are functions in the category <code class="func">IsOperation</code> (<a href="chap5.html#X874C7C6D8650D648"><span class="RefLink">5.5-2</span></a>).</p>

<p>So on the one hand, <em>operations</em> are <strong class="pkg">GAP</strong> functions, that is, they can be applied to arguments and return a result or cause a side-effect.</p>

<p>On the other hand, operations are more. Namely, an operation corresponds to a set of <strong class="pkg">GAP</strong> functions, called the <em>methods</em> of the operation.</p>

<p>Each call of an operation causes a suitable method to be selected and then called. The choice of which method to select is made according to the types of the arguments, the underlying mechanism is described in the following sections.</p>

<p>Examples of operations are the binary infix operators <code class="code">=</code>, <code class="code">+</code> etc., and <code class="func">PrintObj</code> (<a href="chap6.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) is the operation that is called for each argument of <code class="func">Print</code> (<a href="chap6.html#X7AFA64D97A1F39A3"><span class="RefLink">6.3-4</span></a>).</p>

<p>Also all attributes and properties are operations. Each attribute has a special method which is called if the attribute value is already stored; this method of course simply returns this value.</p>

<p>The setter of an attribute is called automatically if an attribute value has been computed. Attribute setters are operations, too. They have a default method that ignores the request to store the value. Depending on the type of the object, there may be another method to store the value in a suitable way, and then set the attribute tester for the object to <code class="keyw">true</code>.</p>

<p><a id="X795EE8257848B438" name="X795EE8257848B438"></a></p>

<h4>78.2 <span class="Heading">Method Installation</span></h4>

<p>In order to describe what it means to select a method of an operation, we must describe how the methods are connected to their operations.</p>

<p>For attributes and properties there is <code class="func">InstallImmediateMethod</code> (<a href="chap78.html#X87B47AC0849611F8"><span class="RefLink">78.6-1</span></a>).</p>

<p>For declaring that a filter is implied by other filters there is <code class="func">InstallTrueMethod</code> (<a href="chap78.html#X860B8B707995CFE3"><span class="RefLink">78.7-1</span></a>).</p>

<p><a id="X837EFDAB7BEF290B" name="X837EFDAB7BEF290B"></a></p>

<h5>78.2-1 InstallMethod</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; InstallMethod</code>( <var class="Arg">opr</var>[, <var class="Arg">info</var>][, <var class="Arg">famp</var>], <var class="Arg">args-filts</var>[, <var class="Arg">val</var>], <var class="Arg">method</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>installs a function method <var class="Arg">method</var> for the operation <var class="Arg">opr</var>; <var class="Arg">args-filts</var> should be a list of requirements for the arguments, each entry being a filter; if supplied <var class="Arg">info</var> should be a short but informative string that describes for what situation the method is installed, <var class="Arg">famp</var> should be a function to be applied to the families of the arguments, and <var class="Arg">val</var> should be an integer that measures the priority of the method.</p>

<p>The default values for <var class="Arg">info</var>, <var class="Arg">famp</var>, and <var class="Arg">val</var> are the empty string, the function <code class="func">ReturnTrue</code> (<a href="chap5.html#X7DB422A2876CCC4D"><span class="RefLink">5.4-1</span></a>), and the integer zero, respectively.</p>

<p>The exact meaning of the arguments <var class="Arg">famp</var>, <var class="Arg">args-filts</var>, and <var class="Arg">val</var> is explained in Section <a href="chap78.html#X851FC6387CA2B241"><span class="RefLink">78.3</span></a>.</p>

<p><var class="Arg">opr</var> expects its methods to require certain filters for their arguments. For example, the argument of a method for the operation <code class="func">Zero</code> (<a href="chap31.html#X8040AC7A79FFC442"><span class="RefLink">31.10-3</span></a>) must be in the category <code class="func">IsAdditiveElementWithZero</code> (<a href="chap31.html#X87F3552A789C572D"><span class="RefLink">31.14-5</span></a>). It is not possible to use <code class="func">InstallMethod</code> to install a method for which the entries of <var class="Arg">args-filts</var> do not imply the respective requirements of the operation <var class="Arg">opr</var>. If one wants to override this restriction, one has to use <code class="func">InstallOtherMethod</code> (<a href="chap78.html#X7D2C12DB841CE539"><span class="RefLink">78.2-2</span></a>) instead.</p>

<p><a id="X7D2C12DB841CE539" name="X7D2C12DB841CE539"></a></p>

<h5>78.2-2 InstallOtherMethod</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; InstallOtherMethod</code>( <var class="Arg">opr</var>[, <var class="Arg">info</var>][, <var class="Arg">famp</var>], <var class="Arg">args-filts</var>[, <var class="Arg">val</var>], <var class="Arg">method</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>installs a function method <var class="Arg">method</var> for the operation <var class="Arg">opr</var>, in the same way as for <code class="func">InstallMethod</code> (<a href="chap78.html#X837EFDAB7BEF290B"><span class="RefLink">78.2-1</span></a>), but without the restriction that the number of arguments must match a declaration of <var class="Arg">opr</var> and without the restriction that <var class="Arg">args-filts</var> imply the respective requirements of the operation <var class="Arg">opr</var>.</p>

<p><a id="X851FC6387CA2B241" name="X851FC6387CA2B241"></a></p>

<h4>78.3 <span class="Heading">Applicable Methods and Method Selection</span></h4>

<p>A method installed as above is <em>applicable</em> for an arguments tuple if the following conditions are satisfied.</p>

<p>The number of arguments equals the length of the list <var class="Arg">args-filts</var>, the <span class="SimpleMath">i</span>-th argument lies in the filter <var class="Arg">args-filts</var><span class="SimpleMath">[i]</span>, and <var class="Arg">famp</var> returns <code class="keyw">true</code> when applied to the families of the arguments. The maximal number of arguments supported for methods is six, one gets an error message if one tries to install a method with at least seven arguments.</p>

<p>So <var class="Arg">args-filt</var> describes conditions for each argument, and <var class="Arg">famp</var> describes a relation between the arguments.</p>

<p>For unary operations such as attributes and properties, there is no such relation to postulate, <var class="Arg">famp</var> is <code class="func">ReturnTrue</code> (<a href="chap5.html#X7DB422A2876CCC4D"><span class="RefLink">5.4-1</span></a>) for these operations, a function that always returns <code class="keyw">true</code>. For binary operations, the usual value of <var class="Arg">famp</var> is <code class="func">IsIdenticalObj</code> (<a href="chap12.html#X7961183378DFB902"><span class="RefLink">12.5-1</span></a>), which means that both arguments must lie in the same family.</p>

<p>Note that any properties which occur among the filters in the filter list will <em>not</em> be tested by the method selection if they are not yet known. (More exact: if <var class="Arg">prop</var> is a property then the filter implicitly uses not <var class="Arg">prop</var> but <code class="code">Has<var class="Arg">prop</var> and <var class="Arg">prop</var></code>.) If this is desired you must explicitly enforce a test (see section <a href="chap78.html#X7B85DD797A907106"><span class="RefLink">78.5</span></a>) below.</p>

<p>If no method is applicable, the error message "no method found" is signaled.</p>

<p>Otherwise, the applicable method with highest <em>rank</em> is selected and then called. This rank is given by the sum of the ranks of the filters in the list <var class="Arg">args-filt</var>, <em>including involved filters</em>, plus the number <var class="Arg">val</var> used in the call of <code class="func">InstallMethod</code> (<a href="chap78.html#X837EFDAB7BEF290B"><span class="RefLink">78.2-1</span></a>). So the argument <var class="Arg">val</var> can be used to raise the priority of a method relative to other methods for <var class="Arg">opr</var>.</p>

<p>Note that from the applicable methods, an efficient one shall be selected. This is a method that needs only little time and storage for the computations.</p>

<p>It seems to be impossible for <strong class="pkg">GAP</strong> to select an optimal method in all cases. The present ranking of methods is based on the assumption that a method installed for a special situation shall be preferred to a method installed for a more general situation.</p>

<p>For example, a method for computing a Sylow subgroup of a nilpotent group is expected to be more efficient than a method for arbitrary groups. So the more specific method will be selected if <strong class="pkg">GAP</strong> knows that the group given as argument is nilpotent.</p>

<p>Of course there is no obvious way to decide between the efficiency of incommensurable methods. For example, take an operation with one method for permutation groups, another method for nilpotent groups, but no method for nilpotent permutation groups, and call this operation with a permutation group known to be nilpotent.</p>

<p><a id="X846865A681D4A623" name="X846865A681D4A623"></a></p>

<h4>78.4 <span class="Heading">Partial Methods</span></h4>

<p><a id="X7EED949B83046A7F" name="X7EED949B83046A7F"></a></p>

<h5>78.4-1 TryNextMethod</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; TryNextMethod</code>(  )</td><td class="tdright">( function )</td></tr></table></div>
<p>After a method has been selected and called, the method may recognize that it cannot compute the desired result, and give up by calling <code class="code">TryNextMethod()</code>.</p>

<p>In effect, the execution of the method is terminated, and the method selection calls the next method that is applicable w.r.t. the original arguments. In other words, the applicable method is called that is subsequent to the one that called <code class="func">TryNextMethod</code>, according to decreasing rank of the methods.</p>

<p>For example, since every finite group of odd order is solvable, one may install a method for the property <code class="func">IsSolvableGroup</code> (<a href="chap39.html#X809C78D5877D31DF"><span class="RefLink">39.15-6</span></a>) that checks whether the size of the argument is an odd integer, returns <code class="keyw">true</code> if so, and gives up otherwise.</p>

<p>Care is needed if a partial method might modify the type of one of its arguments, for example by computing an attribute or property. If this happens, and the type has really changed, then the method should not exit using <code class="code">TryNextMethod()</code> but should call the operation again, as the new information in the type may cause some methods previously judged inapplicable to be applicable. For example, if the above method for <code class="func">IsSolvableGroup</code> (<a href="chap39.html#X809C78D5877D31DF"><span class="RefLink">39.15-6</span></a>) actually computes the size, (rather than just examining a stored size), then it must take care to check whether the type of the group has changed.</p>

<p><a id="X7B85DD797A907106" name="X7B85DD797A907106"></a></p>

<h4>78.5 <span class="Heading">Redispatching</span></h4>

<p>As mentioned above the method selection will not test unknown properties. In situations, in which algorithms are only known (or implemented) under certain conditions, however such a test might be actually desired.</p>

<p>One way to achieve this would be to install the method under weaker conditions and explicitly test the properties first, exiting via <code class="func">TryNextMethod</code> (<a href="chap78.html#X7EED949B83046A7F"><span class="RefLink">78.4-1</span></a>) if some of them are not fulfilled. A problem of this approach however is that such methods then automatically are ranked lower and that the code does not look nice.</p>

<p>A much better way is to use redispatching: Before deciding that no method has been found one tests these properties and if they turn out to be true the method selection is started anew (and will then find a method).</p>

<p>This can be achieved via the following function:</p>

<p><a id="X7D4A46CE7BCFCCF5" name="X7D4A46CE7BCFCCF5"></a></p>

<h5>78.5-1 RedispatchOnCondition</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RedispatchOnCondition</code>( <var class="Arg">oper</var>[, <var class="Arg">info</var>], <var class="Arg">fampred</var>, <var class="Arg">reqs</var>, <var class="Arg">cond</var>, <var class="Arg">val</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function installs a method for the operation <var class="Arg">oper</var> under the conditions <var class="Arg">fampred</var> and <var class="Arg">reqs</var> which has absolute value <var class="Arg">val</var>; that is, the value of the filters <var class="Arg">reqs</var> is disregarded. <var class="Arg">cond</var> is a list of filters. If not all the values of properties involved in these filters are already known for actual arguments of the method, they are explicitly tested and if they are fulfilled <em>and</em> stored after this test, the operation is dispatched again. Otherwise the method exits with <code class="func">TryNextMethod</code> (<a href="chap78.html#X7EED949B83046A7F"><span class="RefLink">78.4-1</span></a>). If supplied, <var class="Arg">info</var> should be a short but informative string that describes these conditions. This can be used to enforce tests like <code class="func">IsFinite</code> (<a href="chap30.html#X808A4061809A6E67"><span class="RefLink">30.4-2</span></a>) in situations when all existing methods require this property. The list <var class="Arg">cond</var> may have unbound entries in which case the corresponding argument is ignored for further tests.</p>

<p><a id="X87D38D2584D0A8AF" name="X87D38D2584D0A8AF"></a></p>

<h4>78.6 <span class="Heading">Immediate Methods</span></h4>

<p>Usually a method is called only if its operation has been called and if this method has been selected, see <code class="func">InstallMethod</code> (<a href="chap78.html#X837EFDAB7BEF290B"><span class="RefLink">78.2-1</span></a>).</p>

<p>For attributes and properties, one can install also <em>immediate methods</em>.</p>

<p><a id="X87B47AC0849611F8" name="X87B47AC0849611F8"></a></p>

<h5>78.6-1 InstallImmediateMethod</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; InstallImmediateMethod</code>( <var class="Arg">opr</var>[, <var class="Arg">info</var>], <var class="Arg">filter</var>, <var class="Arg">rank</var>, <var class="Arg">method</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">InstallImmediateMethod</code> installs <var class="Arg">method</var> as an immediate method for <var class="Arg">opr</var>, which must be an attribute or a property, with requirement <var class="Arg">filter</var> and rank <var class="Arg">rank</var>. The rank must be an integer value that measures the priority of <var class="Arg">method</var> among the immediate methods for <var class="Arg">opr</var>. If supplied, <var class="Arg">info</var> should be a short but informative string that describes the situation in which the method is called.</p>

<p>An immediate method is called automatically as soon as the object lies in <var class="Arg">filter</var>, provided that the value is not yet known. Afterwards the attribute setter is called in order to store the value, unless the method exits via <code class="func">TryNextMethod</code> (<a href="chap78.html#X7EED949B83046A7F"><span class="RefLink">78.4-1</span></a>).</p>

<p>Note the difference to <code class="func">InstallMethod</code> (<a href="chap78.html#X837EFDAB7BEF290B"><span class="RefLink">78.2-1</span></a>) that no family predicate occurs because <var class="Arg">opr</var> expects only one argument, and that <var class="Arg">filter</var> is not a list of requirements but the argument requirement itself.</p>

<p>Immediate methods are thought of as a possibility for objects to gain useful knowledge. They must not be used to force the storing of "defining information" in an object. In other words, <strong class="pkg">GAP</strong> should work even if all immediate methods are completely disabled. Therefore, the call to <code class="func">InstallImmediateMethod</code> installs <var class="Arg">method</var> also as an ordinary method for <var class="Arg">opr</var> with requirement <var class="Arg">filter</var>.</p>

<p>Note that in such a case <strong class="pkg">GAP</strong> executes a computation for which it was not explicitly asked by the user. So one should install only those methods as immediate methods that are <em>extremely cheap</em>. To emphasize this, immediate methods are also called <em>zero cost methods</em>. The time for their execution should really be approximately zero.</p>

<p>For example, the size of a permutation group can be computed very cheaply if a stabilizer chain of the group is known. So it is reasonable to install an immediate method for <code class="func">Size</code> (<a href="chap30.html#X858ADA3B7A684421"><span class="RefLink">30.4-6</span></a>) with requirement <code class="code">IsGroup and Tester( <var class="Arg">stab</var> )</code>, where <var class="Arg">stab</var> is the attribute corresponding to the stabilizer chain.</p>

<p>Another example would be the implementation of the conclusion that every finite group of prime power order is nilpotent. This could be done by installing an immediate method for the attribute <code class="func">IsNilpotentGroup</code> (<a href="chap39.html#X87D062608719F2CD"><span class="RefLink">39.15-3</span></a>) with requirement <code class="code">IsGroup and Tester( Size )</code>. This method would then check whether the size is a finite prime power, return <code class="keyw">true</code> in this case and otherwise call <code class="func">TryNextMethod</code> (<a href="chap78.html#X7EED949B83046A7F"><span class="RefLink">78.4-1</span></a>). But this requires factoring of an integer, which cannot be guaranteed to be very cheap, so one should not install this method as an immediate method.</p>

<p><a id="X7FB5016E83DB4349" name="X7FB5016E83DB4349"></a></p>

<h4>78.7 <span class="Heading">Logical Implications</span></h4>

<p><a id="X860B8B707995CFE3" name="X860B8B707995CFE3"></a></p>

<h5>78.7-1 InstallTrueMethod</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; InstallTrueMethod</code>( <var class="Arg">newfil</var>, <var class="Arg">filt</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>It may happen that a filter <var class="Arg">newfil</var> shall be implied by another filter <var class="Arg">filt</var>, which is usually a meet of other properties, or the meet of some properties and some categories. Such a logical implication can be installed as an "immediate method" for <var class="Arg">newfil</var> that requires <var class="Arg">filt</var> and that always returns <code class="keyw">true</code>. (This should not be mixed up with the methods installed via <code class="func">InstallImmediateMethod</code> (<a href="chap78.html#X87B47AC0849611F8"><span class="RefLink">78.6-1</span></a>), which have to be called at runtime for the actual objects.)</p>

<p><code class="func">InstallTrueMethod</code> has the effect that <var class="Arg">newfil</var> becomes an implied filter of <var class="Arg">filt</var>, see <a href="chap13.html#X84EFA4C07D4277BB"><span class="RefLink">13.2</span></a>.</p>

<p>For example, each cyclic group is abelian, each finite vector space is finite dimensional, and each division ring is integral. The first of these implications is installed as follows.</p>


<div class="example"><pre>
InstallTrueMethod( IsCommutative, IsGroup and IsCyclic );
</pre></div>

<p>Contrary to the immediate methods installed with <code class="func">InstallImmediateMethod</code> (<a href="chap78.html#X87B47AC0849611F8"><span class="RefLink">78.6-1</span></a>), logical implications cannot be switched off. This means that after the above implication has been installed, one can rely on the fact that every object in the filter <code class="code">IsGroup and IsCyclic</code> will also be in the filter <code class="func">IsCommutative</code> (<a href="chap35.html#X830A4A4C795FBC2D"><span class="RefLink">35.4-9</span></a>).</p>

<p><a id="X855FE25783FB0D4E" name="X855FE25783FB0D4E"></a></p>

<h4>78.8 <span class="Heading">Operations and Mathematical Terms</span></h4>

<p>Usually an operation stands for a mathematical concept, and the name of the operation describes this uniquely. Examples are the property <code class="func">IsFinite</code> (<a href="chap30.html#X808A4061809A6E67"><span class="RefLink">30.4-2</span></a>) and the attribute <code class="func">Size</code> (<a href="chap30.html#X858ADA3B7A684421"><span class="RefLink">30.4-6</span></a>). But there are cases where the same mathematical term is used to denote different concepts, for example <code class="code">Degree</code> is defined for polynomials, group characters, and permutation actions, and <code class="code">Rank</code> is defined for matrices, free modules, <span class="SimpleMath">p</span>-groups, and transitive permutation actions.</p>

<p>It is in principle possible to install methods for the operation <code class="code">Rank</code> that are applicable to the different types of arguments, corresponding to the different contexts. But this is not the approach taken in the <strong class="pkg">GAP</strong> library. Instead there are operations such as <code class="func">RankMat</code> (<a href="chap24.html#X7B21AE7987D4FB31"><span class="RefLink">24.7-1</span></a>) for matrices and <code class="func">DegreeOfCharacter</code> (<a href="chap72.html#X7802BC157C69DD75"><span class="RefLink">72.8-4</span></a>) (in fact these are attributes) which are installed as methods of the "ambiguous" operations <code class="code">Rank</code> and <code class="code">Degree</code>.</p>

<p>The idea is to distinguish between on the one hand different ways to compute the same thing (e.g. different methods for <code class="func">\=</code> (<a href="chap31.html#X7EF67D047F03CA6F"><span class="RefLink">31.11-1</span></a>), <code class="func">Size</code> (<a href="chap30.html#X858ADA3B7A684421"><span class="RefLink">30.4-6</span></a>), etc.), and on the other hand genuinely different things (such as the degree of a polynomial and a permutation action).</p>

<p>The former is the basic purpose of operations and attributes. The latter is provided as a user convenience where mathematical usage forces it on us <em>and</em> where no conflicts arise. In programming the library, we use the underlying mathematically precise operations or attributes, such as <code class="func">RankMat</code> (<a href="chap24.html#X7B21AE7987D4FB31"><span class="RefLink">24.7-1</span></a>) and <code class="code">RankOperation</code>. These should be attributes if appropriate, and the only role of the operation <code class="code">Rank</code> is to decide which attribute the user meant. That way, stored information is stored with "full mathematical precision" and is less likely to be retrieved for a wrong purpose later.</p>

<p>One word about possible conflicts. A typical example is the mathematical term "centre", which is defined as <span class="SimpleMath">{ x ∈ M | a * x = x * a ∀ a ∈ M }</span> for a magma <span class="SimpleMath">M</span>, and as <span class="SimpleMath">{ x ∈ L | l * x = 0 ∀ l ∈ L }</span> for a Lie algebra <span class="SimpleMath">L</span>. Here it is <em>not</em> possible to introduce an operation <code class="func">Centre</code> (<a href="chap35.html#X847ABE6F781C7FE8"><span class="RefLink">35.4-5</span></a>) that delegates to attributes <code class="code">CentreOfMagma</code> and <code class="code">CentreOfLieAlgebra</code>, depending on the type of the argument. This is because any Lie algebra in <strong class="pkg">GAP</strong> is also a magma, so both <code class="code">CentreOfMagma</code> and <code class="code">CentreOfLieAlgebra</code> would be defined for a Lie algebra, with different meaning if the characteristic is two. So we cannot achieve that one operation in <strong class="pkg">GAP</strong> corresponds to the mathematical term "centre".</p>

<p>"Ambiguous" operations such as <code class="code">Rank</code> are declared in the library file <code class="file">lib/overload.g</code>.</p>


<div class="chlinkprevnextbot">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp;  <a href="chap0.html#contents">[Contents]</a>&nbsp;  &nbsp;<a href="chap77.html">[Previous Chapter]</a>&nbsp;  &nbsp;<a href="chap79.html">[Next Chapter]</a>&nbsp;  </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chap11.html">11</a>  <a href="chap12.html">12</a>  <a href="chap13.html">13</a>  <a href="chap14.html">14</a>  <a href="chap15.html">15</a>  <a href="chap16.html">16</a>  <a href="chap17.html">17</a>  <a href="chap18.html">18</a>  <a href="chap19.html">19</a>  <a href="chap20.html">20</a>  <a href="chap21.html">21</a>  <a href="chap22.html">22</a>  <a href="chap23.html">23</a>  <a href="chap24.html">24</a>  <a href="chap25.html">25</a>  <a href="chap26.html">26</a>  <a href="chap27.html">27</a>  <a href="chap28.html">28</a>  <a href="chap29.html">29</a>  <a href="chap30.html">30</a>  <a href="chap31.html">31</a>  <a href="chap32.html">32</a>  <a href="chap33.html">33</a>  <a href="chap34.html">34</a>  <a href="chap35.html">35</a>  <a href="chap36.html">36</a>  <a href="chap37.html">37</a>  <a href="chap38.html">38</a>  <a href="chap39.html">39</a>  <a href="chap40.html">40</a>  <a href="chap41.html">41</a>  <a href="chap42.html">42</a>  <a href="chap43.html">43</a>  <a href="chap44.html">44</a>  <a href="chap45.html">45</a>  <a href="chap46.html">46</a>  <a href="chap47.html">47</a>  <a href="chap48.html">48</a>  <a href="chap49.html">49</a>  <a href="chap50.html">50</a>  <a href="chap51.html">51</a>  <a href="chap52.html">52</a>  <a href="chap53.html">53</a>  <a href="chap54.html">54</a>  <a href="chap55.html">55</a>  <a href="chap56.html">56</a>  <a href="chap57.html">57</a>  <a href="chap58.html">58</a>  <a href="chap59.html">59</a>  <a href="chap60.html">60</a>  <a href="chap61.html">61</a>  <a href="chap62.html">62</a>  <a href="chap63.html">63</a>  <a href="chap64.html">64</a>  <a href="chap65.html">65</a>  <a href="chap66.html">66</a>  <a href="chap67.html">67</a>  <a href="chap68.html">68</a>  <a href="chap69.html">69</a>  <a href="chap70.html">70</a>  <a href="chap71.html">71</a>  <a href="chap72.html">72</a>  <a href="chap73.html">73</a>  <a href="chap74.html">74</a>  <a href="chap75.html">75</a>  <a href="chap76.html">76</a>  <a href="chap77.html">77</a>  <a href="chap78.html">78</a>  <a href="chap79.html">79</a>  <a href="chap80.html">80</a>  <a href="chap81.html">81</a>  <a href="chap82.html">82</a>  <a href="chap83.html">83</a>  <a href="chap84.html">84</a>  <a href="chap85.html">85</a>  <a href="chap86.html">86</a>  <a href="chap87.html">87</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<hr />
<p class="foot">generated by <a href="http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>