/usr/share/gap/doc/ref/chap12.html is in gap-doc 4r7p5-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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | <?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 12: Objects and Elements</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="chap12" 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"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap11.html">[Previous Chapter]</a> <a href="chap13.html">[Next Chapter]</a> </div>
<p id="mathjaxlink" class="pcenter"><a href="chap12_mj.html">[MathJax on]</a></p>
<p><a id="X86710F997832ABA4" name="X86710F997832ABA4"></a></p>
<div class="ChapSects"><a href="chap12.html#X86710F997832ABA4">12 <span class="Heading">Objects and Elements</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap12.html#X78497E777FB3E402">12.1 <span class="Heading">Objects</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X7B130AC98415CAFB">12.1-1 IsObject</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap12.html#X780C66027A49D110">12.2 <span class="Heading">Elements as equivalence classes</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap12.html#X83BE0C20875DD285">12.3 <span class="Heading">Sets</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap12.html#X7BAF69417BB925F6">12.4 <span class="Heading">Domains</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap12.html#X84545F3985C60F5B">12.5 <span class="Heading">Identical Objects</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X7961183378DFB902">12.5-1 IsIdenticalObj</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X811976EC78EC5E29">12.5-2 IsNotIdenticalObj</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap12.html#X7F0C119682196D65">12.6 <span class="Heading">Mutability and Copyability</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X811EFD727EBD1ADC">12.6-1 IsCopyable</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X7999AD1D7A4F1F46">12.6-2 IsMutable</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X7F0ABF2C870B0CBB">12.6-3 Immutable</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X80CE136D804097C7">12.6-4 MakeImmutable</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X7FBA5F4D7C6872BD">12.6-5 <span class="Heading">Mutability of Iterators</span></a>
</span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X7ADB82997A16E853">12.6-6 <span class="Heading">Mutability of Results of Arithmetic Operations</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap12.html#X786B942B82D684BD">12.7 <span class="Heading">Duplication of Objects</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X846BC7107C352031">12.7-1 ShallowCopy</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X7C1E70587EBDD2CB">12.7-2 StructuralCopy</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap12.html#X86E7193D848C53FC">12.8 <span class="Heading">Other Operations Applicable to any Object</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X85D6D47B83BD02A1">12.8-1 SetName</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X7F14EF9D81432113">12.8-2 Name</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X7F6C5C3287E8B816">12.8-3 IsInternallyConsistent</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap12.html#X7F4D216B7DF7BE9D">12.8-4 MemoryUsage</a></span>
</div></div>
</div>
<h3>12 <span class="Heading">Objects and Elements</span></h3>
<p>An <em>object</em> is anything in <strong class="pkg">GAP</strong> that can be assigned to a variable, so nearly everything in <strong class="pkg">GAP</strong> is an object.</p>
<p>Different objects can be regarded as equal with respect to the equivalence relation "<code class="code">=</code>", in this case we say that the objects describe the same <em>element</em>.</p>
<p><a id="X78497E777FB3E402" name="X78497E777FB3E402"></a></p>
<h4>12.1 <span class="Heading">Objects</span></h4>
<p>Nearly all things one deals with in <strong class="pkg">GAP</strong> are <em>objects</em>. For example, an integer is an object, as is a list of integers, a matrix, a permutation, a function, a list of functions, a record, a group, a coset or a conjugacy class in a group.</p>
<p>Examples of things that are not objects are comments which are only lexical constructs, <code class="keyw">while</code> loops which are only syntactical constructs, and expressions, such as <code class="code">1 + 1</code>; but note that the value of an expression, in this case the integer <code class="code">2</code>, is an object.</p>
<p>Objects can be assigned to variables, and everything that can be assigned to a variable is an object. Analogously, objects can be used as arguments of functions, and can be returned by functions.</p>
<p><a id="X7B130AC98415CAFB" name="X7B130AC98415CAFB"></a></p>
<h5>12.1-1 IsObject</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsObject</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<p><code class="func">IsObject</code> returns <code class="keyw">true</code> if the object <var class="Arg">obj</var> is an object. Obviously it can never return <code class="keyw">false</code>.</p>
<p>It can be used as a filter in <code class="func">InstallMethod</code> (<a href="chap78.html#X837EFDAB7BEF290B"><span class="RefLink">78.2-1</span></a>) when one of the arguments can be anything.</p>
<p><a id="X780C66027A49D110" name="X780C66027A49D110"></a></p>
<h4>12.2 <span class="Heading">Elements as equivalence classes</span></h4>
<p>The equality operation "<code class="code">=</code>" defines an equivalence relation on all <strong class="pkg">GAP</strong> objects. The equivalence classes are called <em>elements</em>.</p>
<p>There are basically three reasons to regard different objects as equal. Firstly the same information may be stored in different places. Secondly the same information may be stored in different ways; for example, a polynomial can be stored sparsely or densely. Thirdly different information may be equal modulo a mathematical equivalence relation. For example, in a finitely presented group with the relation <span class="SimpleMath">a^2 = 1</span> the different objects <span class="SimpleMath">a</span> and <span class="SimpleMath">a^3</span> describe the same element.</p>
<p>As an example of all three reasons, consider the possibility of storing an integer in several places of the memory, of representing it as a fraction with denominator 1, or of representing it as a fraction with any denominator, and numerator a suitable multiple of the denominator.</p>
<p><a id="X83BE0C20875DD285" name="X83BE0C20875DD285"></a></p>
<h4>12.3 <span class="Heading">Sets</span></h4>
<p>In <strong class="pkg">GAP</strong> there is no category whose definition corresponds to the mathematical property of being a set, however in the manual we will often refer to an object as a <em>set</em> in order to convey the fact that mathematically, we are thinking of it as a set. In particular, two sets <span class="SimpleMath">A</span> and <span class="SimpleMath">B</span> are equal if and only if, <span class="SimpleMath">x ∈ A <=> x ∈ B</span>.</p>
<p>There are two types of object in <strong class="pkg">GAP</strong> which exhibit this kind of behaviour with respect to equality, namely domains (see Section <a href="chap12.html#X7BAF69417BB925F6"><span class="RefLink">12.4</span></a>) and lists whose elements are strictly sorted see <code class="func">IsSSortedList</code> (<a href="chap21.html#X80CDAF45782E8DCB"><span class="RefLink">21.17-4</span></a>). In general, <em>set</em> in this manual will mean an object of one of these types.</p>
<p>More precisely: two domains can be compared with "{<code class="code">=</code>}", the answer being <code class="keyw">true</code> if and only if the sets of elements are equal (regardless of any additional structure) and; a domain and a list can be compared with "<code class="code">=</code>", the answer being <code class="keyw">true</code> if and only if the list is equal to the strictly sorted list of elements of the domain.</p>
<p>A discussion about sorted lists and sets can be found in Section <a href="chap21.html#X80ABC25582343910"><span class="RefLink">21.19</span></a>.</p>
<p><a id="X7BAF69417BB925F6" name="X7BAF69417BB925F6"></a></p>
<h4>12.4 <span class="Heading">Domains</span></h4>
<p>An especially important class of objects in <strong class="pkg">GAP</strong> are those whose underlying mathematical abstraction is that of a structured set, for example a group, a conjugacy class, or a vector space. Such objects are called <em>domains</em>. The equality relation between domains is always equality <em>as sets</em>, so that two domains are equal if and only if they contain the same elements.</p>
<p>Domains play a central role in <strong class="pkg">GAP</strong>. In a sense, the only reason that <strong class="pkg">GAP</strong> supports objects such as integers and permutations is the wish to form domains of them and compute the properties of those domains.</p>
<p>Domains are described in Chapter <a href="chap31.html#X7E651AC287AFDCC1"><span class="RefLink">31</span></a>.</p>
<p><a id="X84545F3985C60F5B" name="X84545F3985C60F5B"></a></p>
<h4>12.5 <span class="Heading">Identical Objects</span></h4>
<p>Two objects that are equal <em>as objects</em> (that is they actually refer to the same area of computer memory) and not only w.r.t. the equality relation "<code class="code">=</code>" are called <em>identical</em>. Identical objects do of course describe the same element.</p>
<p><a id="X7961183378DFB902" name="X7961183378DFB902"></a></p>
<h5>12.5-1 IsIdenticalObj</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsIdenticalObj</code>( <var class="Arg">obj1</var>, <var class="Arg">obj2</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">IsIdenticalObj</code> tests whether the objects <var class="Arg">obj1</var> and <var class="Arg">obj2</var> are identical (that is they are either equal immediate objects or are both stored at the same location in memory.</p>
<p>If two copies of a simple constant object (see section <a href="chap12.html#X7F0C119682196D65"><span class="RefLink">12.6</span></a>) are created, it is not defined whether <strong class="pkg">GAP</strong> will actually store two equal but non-identical objects, or just a single object. For mutable objects, however, it is important to know whether two values refer to identical or non-identical objects, and the documentation of operations that return mutable values should make clear whether the values returned are new, or may be identical to values stored elsewhere.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsIdenticalObj( 10^6, 10^6);</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsIdenticalObj( 10^30, 10^30);</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">IsIdenticalObj( true, true);</span>
true
</pre></div>
<p>Generally, one may compute with objects but think of the results in terms of the underlying elements because one is not interested in locations in memory, data formats or information beyond underlying equivalence relations. But there are cases where it is important to distinguish the relations identity and equality. This is best illustrated with an example. (The reader who is not familiar with lists in <strong class="pkg">GAP</strong>, in particular element access and assignment, is referred to Chapter <a href="chap21.html#X7B256AE5780F140A"><span class="RefLink">21</span></a>.)</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l1:= [ 1, 2, 3 ];; l2:= [ 1, 2, 3 ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">l1 = l2;</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsIdenticalObj( l1, l2 );</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">l1[3]:= 4;; l1; l2;</span>
[ 1, 2, 4 ]
[ 1, 2, 3 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">l1 = l2;</span>
false
</pre></div>
<p>The two lists <code class="code">l1</code> and <code class="code">l2</code> are equal but not identical. Thus a change in <code class="code">l1</code> does not affect <code class="code">l2</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l1:= [ 1, 2, 3 ];; l2:= l1;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">l1 = l2;</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsIdenticalObj( l1, l2 );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">l1[3]:= 4;; l1; l2;</span>
[ 1, 2, 4 ]
[ 1, 2, 4 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">l1 = l2;</span>
true
</pre></div>
<p>Here, <code class="code">l1</code> and <code class="code">l2</code> are identical objects, so changing <code class="code">l1</code> means a change to <code class="code">l2</code> as well.</p>
<p><a id="X811976EC78EC5E29" name="X811976EC78EC5E29"></a></p>
<h5>12.5-2 IsNotIdenticalObj</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsNotIdenticalObj</code>( <var class="Arg">obj1</var>, <var class="Arg">obj2</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>tests whether the objects <var class="Arg">obj1</var> and <var class="Arg">obj2</var> are not identical.</p>
<p><a id="X7F0C119682196D65" name="X7F0C119682196D65"></a></p>
<h4>12.6 <span class="Heading">Mutability and Copyability</span></h4>
<p>An object in <strong class="pkg">GAP</strong> is said to be <em>immutable</em> if its mathematical value (as defined by <span class="SimpleMath">=</span>) does not change under any operation. More explicitly, suppose <span class="SimpleMath">a</span> is immutable and <span class="SimpleMath">O</span> is some operation on <span class="SimpleMath">a</span>, then if <span class="SimpleMath">a = b</span> evaluates to <code class="keyw">true</code> before executing <span class="SimpleMath">O(a)</span>, <span class="SimpleMath">a = b</span> also evaluates to <code class="keyw">true</code> afterwards. (Examples for operations <span class="SimpleMath">O</span> that change mutable objects are <code class="func">Add</code> (<a href="chap21.html#X795EC9D67E34DAB0"><span class="RefLink">21.4-2</span></a>) and <code class="func">Unbind</code> (<a href="chap21.html#X78B72FDF7BD63C0B"><span class="RefLink">21.5-2</span></a>) which are used to change list objects, see Chapter <a href="chap21.html#X7B256AE5780F140A"><span class="RefLink">21</span></a>.) An immutable object <em>may</em> change, for example to store new information, or to adopt a more efficient representation, but this does not affect its behaviour under <span class="SimpleMath">=</span>.</p>
<p>There are two points here to note. Firstly, "operation" above refers to the functions and methods which can legitimately be applied to the object, and not the <code class="code">!.</code> operation whereby virtually any aspect of any <strong class="pkg">GAP</strong> level object may be changed. The second point which follows from this, is that when implementing new types of objects, it is the programmer's responsibility to ensure that the functions and methods they write never change immutable objects mathematically.</p>
<p>In fact, most objects with which one deals in <strong class="pkg">GAP</strong> are immutable. For instance, the permutation <code class="code">(1,2)</code> will never become a different permutation or a non-permutation (although a variable which previously had <code class="code">(1,2)</code> stored in it may subsequently have some other value).</p>
<p>For many purposes, however, <em>mutable</em> objects are useful. These objects may be changed to represent different mathematical objects during their life. For example, mutable lists can be changed by assigning values to positions or by unbinding values at certain positions. Similarly, one can assign values to components of a mutable record, or unbind them.</p>
<p><a id="X811EFD727EBD1ADC" name="X811EFD727EBD1ADC"></a></p>
<h5>12.6-1 IsCopyable</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsCopyable</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<p>If a mutable form of an object <var class="Arg">obj</var> can be made in <strong class="pkg">GAP</strong>, the object is called <em>copyable</em>. Examples of copyable objects are of course lists and records. A new mutable version of the object can always be obtained by the operation <code class="func">ShallowCopy</code> (<a href="chap12.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>).</p>
<p>Objects for which only an immutable form exists in <strong class="pkg">GAP</strong> are called <em>constants</em>. Examples of constants are integers, permutations, and domains. Called with a constant as argument, <code class="func">Immutable</code> (<a href="chap12.html#X7F0ABF2C870B0CBB"><span class="RefLink">12.6-3</span></a>) and <code class="func">ShallowCopy</code> (<a href="chap12.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) return this argument.</p>
<p><a id="X7999AD1D7A4F1F46" name="X7999AD1D7A4F1F46"></a></p>
<h5>12.6-2 IsMutable</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsMutable</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<p>tests whether <var class="Arg">obj</var> is mutable.</p>
<p>If an object is mutable then it is also copyable (see <code class="func">IsCopyable</code> (<a href="chap12.html#X811EFD727EBD1ADC"><span class="RefLink">12.6-1</span></a>)), and a <code class="func">ShallowCopy</code> (<a href="chap12.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) method should be supplied for it. Note that <code class="func">IsMutable</code> must not be implied by another filter, since otherwise <code class="func">Immutable</code> (<a href="chap12.html#X7F0ABF2C870B0CBB"><span class="RefLink">12.6-3</span></a>) would be able to create paradoxical objects in the sense that <code class="func">IsMutable</code> for such an object is <code class="keyw">false</code> but the filter that implies <code class="func">IsMutable</code> is <code class="keyw">true</code>.</p>
<p>In many situations, however, one wants to ensure that objects are <em>immutable</em>. For example, take the identity of a matrix group. Since this matrix may be referred to as the identity of the group in several places, it would be fatal to modify its entries, or add or unbind rows. We can obtain an immutable copy of an object with <code class="func">Immutable</code> (<a href="chap12.html#X7F0ABF2C870B0CBB"><span class="RefLink">12.6-3</span></a>).</p>
<p><a id="X7F0ABF2C870B0CBB" name="X7F0ABF2C870B0CBB"></a></p>
<h5>12.6-3 Immutable</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Immutable</code>( <var class="Arg">obj</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>returns an immutable structural copy (see <code class="func">StructuralCopy</code> (<a href="chap12.html#X7C1E70587EBDD2CB"><span class="RefLink">12.7-2</span></a>)) of <var class="Arg">obj</var> in which the subobjects are immutable <em>copies</em> of the subobjects of <var class="Arg">obj</var>. If <var class="Arg">obj</var> is immutable then <code class="func">Immutable</code> returns <var class="Arg">obj</var> itself.</p>
<p><strong class="pkg">GAP</strong> will complain with an error if one tries to change an immutable object.</p>
<p><a id="X80CE136D804097C7" name="X80CE136D804097C7"></a></p>
<h5>12.6-4 MakeImmutable</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ MakeImmutable</code>( <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>One can turn the (mutable or immutable) object <var class="Arg">obj</var> into an immutable one with <code class="func">MakeImmutable</code>; note that this also makes all subobjects of <var class="Arg">obj</var> immutable, so one should call <code class="func">MakeImmutable</code> only if <var class="Arg">obj</var> and its mutable subobjects are newly created. If one is not sure about this, <code class="func">Immutable</code> (<a href="chap12.html#X7F0ABF2C870B0CBB"><span class="RefLink">12.6-3</span></a>) should be used.</p>
<p>Note that it is <em>not</em> possible to turn an immutable object into a mutable one; only mutable copies can be made (see <a href="chap12.html#X786B942B82D684BD"><span class="RefLink">12.7</span></a>).</p>
<p>Using <code class="func">Immutable</code> (<a href="chap12.html#X7F0ABF2C870B0CBB"><span class="RefLink">12.6-3</span></a>), it is possible to store an immutable identity matrix or an immutable list of generators, and to pass around references to this immutable object safely. Only when a mutable copy is really needed does the actual object have to be duplicated. Compared to the situation without immutable objects, much unnecessary copying is avoided this way. Another advantage of immutability is that lists of immutable objects may remember whether they are sorted (see <a href="chap21.html#X80ABC25582343910"><span class="RefLink">21.19</span></a>), which is not possible for lists of mutable objects.</p>
<p>Since the operation <code class="func">Immutable</code> (<a href="chap12.html#X7F0ABF2C870B0CBB"><span class="RefLink">12.6-3</span></a>) must work for any object in <strong class="pkg">GAP</strong>, it follows that an immutable form of every object must be possible, even if it is not sensible, and user-defined objects must allow for the possibility of becoming immutable without notice.</p>
<p><a id="X7FBA5F4D7C6872BD" name="X7FBA5F4D7C6872BD"></a></p>
<h5>12.6-5 <span class="Heading">Mutability of Iterators</span></h5>
<p>An interesting example of mutable (and thus copyable) objects is provided by <em>iterators</em>, see <a href="chap30.html#X85A3F00985453F95"><span class="RefLink">30.8</span></a>. (Of course an immutable form of an iterator is not very useful, but clearly <code class="func">Immutable</code> (<a href="chap12.html#X7F0ABF2C870B0CBB"><span class="RefLink">12.6-3</span></a>) will yield such an object.) Every call of <code class="func">NextIterator</code> (<a href="chap30.html#X879F62F77D1D1179"><span class="RefLink">30.8-5</span></a>) changes a mutable iterator until it is exhausted, and this is the only way to change an iterator. <code class="func">ShallowCopy</code> (<a href="chap12.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) for an iterator <var class="Arg">iter</var> is defined so as to return a mutable iterator that has no mutable data in common with <var class="Arg">iter</var>, and that behaves equally to <var class="Arg">iter</var> w.r.t. <code class="func">IsDoneIterator</code> (<a href="chap30.html#X8055FC557B5D899E"><span class="RefLink">30.8-4</span></a>) and (if <var class="Arg">iter</var> is mutable) <code class="func">NextIterator</code> (<a href="chap30.html#X879F62F77D1D1179"><span class="RefLink">30.8-5</span></a>). Note that this meaning of the "shallow copy" of an iterator that is returned by <code class="func">ShallowCopy</code> (<a href="chap12.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) is not as obvious as for lists and records, and must be explicitly defined.</p>
<p><a id="X7ADB82997A16E853" name="X7ADB82997A16E853"></a></p>
<h5>12.6-6 <span class="Heading">Mutability of Results of Arithmetic Operations</span></h5>
<p>Many operations return immutable results, among those in particular attributes (see <a href="chap13.html#X7C701DBF7BAE649A"><span class="RefLink">13.5</span></a>). Examples of attributes are <code class="func">Size</code> (<a href="chap30.html#X858ADA3B7A684421"><span class="RefLink">30.4-6</span></a>), <code class="func">Zero</code> (<a href="chap31.html#X8040AC7A79FFC442"><span class="RefLink">31.10-3</span></a>), <code class="func">AdditiveInverse</code> (<a href="chap31.html#X84BB723C81D55D63"><span class="RefLink">31.10-9</span></a>), <code class="func">One</code> (<a href="chap31.html#X8046262384895B2A"><span class="RefLink">31.10-2</span></a>), and <code class="func">Inverse</code> (<a href="chap31.html#X78EE524E83624057"><span class="RefLink">31.10-8</span></a>). Arithmetic operations, such as the binary infix operations <code class="code">+</code>, <code class="code">-</code>, <code class="code">*</code>, <code class="code">/</code>, <code class="code">^</code>, <code class="keyw">mod</code>, the unary <code class="code">-</code>, and operations such as <code class="func">Comm</code> (<a href="chap31.html#X80761843831B468E"><span class="RefLink">31.12-3</span></a>) and <code class="func">LeftQuotient</code> (<a href="chap31.html#X7A37082878DB3930"><span class="RefLink">31.12-2</span></a>), return <em>mutable</em> results, <em>except</em> if all arguments are immutable. So the product of two matrices or of a vector and a matrix is immutable if and only if the two matrices or both the vector and the matrix are immutable (see also <a href="chap21.html#X845EEAF083D43CCE"><span class="RefLink">21.11</span></a>). There is one exception to this rule, which arises where the result is less deeply nested than at least one of the argument, where mutable arguments may sometimes lead to an immutable result. For instance, a mutable matrix with immutable rows, multiplied by an immutable vector gives an immutable vector result. The exact rules are given in <a href="chap21.html#X845EEAF083D43CCE"><span class="RefLink">21.11</span></a>.</p>
<p>It should be noted that <code class="code">0 * <var class="Arg">obj</var></code> is equivalent to <code class="code">ZeroSM( <var class="Arg">obj</var> )</code>, <code class="code">-<var class="Arg">obj</var></code> is equivalent to <code class="code">AdditiveInverseSM( <var class="Arg">obj</var> )</code>, <code class="code"><var class="Arg">obj</var>^0</code> is equivalent to <code class="code">OneSM( <var class="Arg">obj</var>)</code>, and <code class="code"><var class="Arg">obj</var>^-1</code> is equivalent to <code class="code">InverseSM( <var class="Arg">obj</var> )</code>. The "SM" stands for "same mutability", and indicates that the result is mutable if and only if the argument is mutable.</p>
<p>The operations <code class="func">ZeroOp</code> (<a href="chap31.html#X8040AC7A79FFC442"><span class="RefLink">31.10-3</span></a>), <code class="func">AdditiveInverseOp</code> (<a href="chap31.html#X84BB723C81D55D63"><span class="RefLink">31.10-9</span></a>), <code class="func">OneOp</code> (<a href="chap31.html#X8046262384895B2A"><span class="RefLink">31.10-2</span></a>), and <code class="func">InverseOp</code> (<a href="chap31.html#X78EE524E83624057"><span class="RefLink">31.10-8</span></a>) return <em>mutable</em> results whenever a mutable version of the result exists, contrary to the attributes <code class="func">Zero</code> (<a href="chap31.html#X8040AC7A79FFC442"><span class="RefLink">31.10-3</span></a>), <code class="func">AdditiveInverse</code> (<a href="chap31.html#X84BB723C81D55D63"><span class="RefLink">31.10-9</span></a>), <code class="func">One</code> (<a href="chap31.html#X8046262384895B2A"><span class="RefLink">31.10-2</span></a>), and <code class="func">Inverse</code> (<a href="chap31.html#X78EE524E83624057"><span class="RefLink">31.10-8</span></a>).</p>
<p>If one introduces new arithmetic objects then one need not install methods for the attributes <code class="func">One</code> (<a href="chap31.html#X8046262384895B2A"><span class="RefLink">31.10-2</span></a>), <code class="func">Zero</code> (<a href="chap31.html#X8040AC7A79FFC442"><span class="RefLink">31.10-3</span></a>), etc. The methods for the associated operations <code class="func">OneOp</code> (<a href="chap31.html#X8046262384895B2A"><span class="RefLink">31.10-2</span></a>) and <code class="func">ZeroOp</code> (<a href="chap31.html#X8040AC7A79FFC442"><span class="RefLink">31.10-3</span></a>) will be called, and then the results made immutable.</p>
<p>All methods installed for the arithmetic operations must obey the rule about the mutability of the result. This means that one may try to avoid the perhaps expensive creation of a new object if both operands are immutable, and of course no problems of this kind arise at all in the (usual) case that the objects in question do not admit a mutable form, i.e., that these objects are not copyable.</p>
<p>In a few, relatively low-level algorithms, one wishes to treat a matrix partly as a data structure, and manipulate and change its entries. For this, the matrix needs to be mutable, and the rule that attribute values are immutable is an obstacle. For these situations, a number of additional operations are provided, for example <code class="func">TransposedMatMutable</code> (<a href="chap24.html#X7C52A38C79C36C35"><span class="RefLink">24.5-6</span></a>) constructs a mutable matrix (contrary to the attribute <code class="func">TransposedMat</code> (<a href="chap24.html#X7C52A38C79C36C35"><span class="RefLink">24.5-6</span></a>)), while <code class="func">TriangulizeMat</code> (<a href="chap24.html#X8384CA8E7B3850D3"><span class="RefLink">24.7-3</span></a>) modifies a mutable matrix (in place) into upper triangular form.</p>
<p>Note that being immutable does not forbid an object to store knowledge. For example, if it is found out that an immutable list is strictly sorted then the list may store this information. More precisely, an immutable object may change in any way, provided that it continues to represent the same mathematical object.</p>
<p><a id="X786B942B82D684BD" name="X786B942B82D684BD"></a></p>
<h4>12.7 <span class="Heading">Duplication of Objects</span></h4>
<p><a id="X846BC7107C352031" name="X846BC7107C352031"></a></p>
<h5>12.7-1 ShallowCopy</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ShallowCopy</code>( <var class="Arg">obj</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p><code class="func">ShallowCopy</code> returns a <em>new mutable</em> object <em>equal</em> to its argument, if this is possible. The subobjects of <code class="code">ShallowCopy( <var class="Arg">obj</var> )</code> are <em>identical</em> to the subobjects of <var class="Arg">obj</var>.</p>
<p>If <strong class="pkg">GAP</strong> does not support a mutable form of the immutable object <var class="Arg">obj</var> (see <a href="chap12.html#X7F0C119682196D65"><span class="RefLink">12.6</span></a>) then <code class="func">ShallowCopy</code> returns <var class="Arg">obj</var> itself.</p>
<p>Since <code class="func">ShallowCopy</code> is an operation, the concrete meaning of "subobject" depends on the type of <var class="Arg">obj</var>. But for any copyable object <var class="Arg">obj</var>, the definition should reflect the idea of "first level copying".</p>
<p>The definition of <code class="func">ShallowCopy</code> for lists (in particular for matrices) can be found in <a href="chap21.html#X7ED7C0738495556F"><span class="RefLink">21.7</span></a>.</p>
<p><a id="X7C1E70587EBDD2CB" name="X7C1E70587EBDD2CB"></a></p>
<h5>12.7-2 StructuralCopy</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StructuralCopy</code>( <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>In a few situations, one wants to make a <em>structural copy</em> <code class="code">scp</code> of an object <var class="Arg">obj</var>. This is defined as follows. <code class="code">scp</code> and <var class="Arg">obj</var> are identical if <var class="Arg">obj</var> is immutable. Otherwise, <code class="code">scp</code> is a mutable copy of <var class="Arg">obj</var> such that each subobject of <code class="code">scp</code> is a structural copy of the corresponding subobject of <var class="Arg">obj</var>. Furthermore, if two subobjects of <var class="Arg">obj</var> are identical then also the corresponding subobjects of <code class="code">scp</code> are identical.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">obj:= [ [ 0, 1 ] ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">obj[2]:= obj[1];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">obj[3]:= Immutable( obj[1] );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">scp:= StructuralCopy( obj );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">scp = obj; IsIdenticalObj( scp, obj );</span>
true
false
<span class="GAPprompt">gap></span> <span class="GAPinput">IsIdenticalObj( scp[1], obj[1] );</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">IsIdenticalObj( scp[3], obj[3] );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsIdenticalObj( scp[1], scp[2] );</span>
true
</pre></div>
<p>That both <code class="func">ShallowCopy</code> (<a href="chap12.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) and <code class="func">StructuralCopy</code> return the argument <var class="Arg">obj</var> itself if it is not copyable is consistent with this definition, since there is no way to change <var class="Arg">obj</var> by modifying the result of any of the two functions, because in fact there is no way to change this result at all.</p>
<p><a id="X86E7193D848C53FC" name="X86E7193D848C53FC"></a></p>
<h4>12.8 <span class="Heading">Other Operations Applicable to any Object</span></h4>
<p>There are a number of general operations which can be applied, in principle, to any object in <strong class="pkg">GAP</strong>. Some of these are documented elsewhere –see <code class="func">String</code> (<a href="chap27.html#X81FB5BE27903EC32"><span class="RefLink">27.6-6</span></a>), <code class="func">PrintObj</code> (<a href="chap6.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) and <code class="func">Display</code> (<a href="chap6.html#X83A5C59278E13248"><span class="RefLink">6.3-6</span></a>). Others are mainly somewhat technical.</p>
<p><a id="X85D6D47B83BD02A1" name="X85D6D47B83BD02A1"></a></p>
<h5>12.8-1 SetName</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SetName</code>( <var class="Arg">obj</var>, <var class="Arg">name</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>for a suitable object <var class="Arg">obj</var> sets that object to have name <var class="Arg">name</var> (a string).</p>
<p><a id="X7F14EF9D81432113" name="X7F14EF9D81432113"></a></p>
<h5>12.8-2 Name</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Name</code>( <var class="Arg">obj</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p>returns the name, a string, previously assigned to <var class="Arg">obj</var> via a call to <code class="func">SetName</code> (<a href="chap12.html#X85D6D47B83BD02A1"><span class="RefLink">12.8-1</span></a>). The name of an object is used <em>only</em> for viewing the object via this name.</p>
<p>There are no methods installed for computing names of objects, but the name may be set for suitable objects, using <code class="func">SetName</code> (<a href="chap12.html#X85D6D47B83BD02A1"><span class="RefLink">12.8-1</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">R := PolynomialRing(Integers,2);</span>
Integers[x_1,x_2]
<span class="GAPprompt">gap></span> <span class="GAPinput">SetName(R,"Z[x,y]");</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">R;</span>
Z[x,y]
<span class="GAPprompt">gap></span> <span class="GAPinput">Name(R);</span>
"Z[x,y]"
</pre></div>
<p><a id="X7F6C5C3287E8B816" name="X7F6C5C3287E8B816"></a></p>
<h5>12.8-3 IsInternallyConsistent</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsInternallyConsistent</code>( <var class="Arg">obj</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>For debugging purposes, it may be useful to check the consistency of an object <var class="Arg">obj</var> that is composed from other (composed) objects.</p>
<p>There is a default method of <code class="func">IsInternallyConsistent</code>, with rank zero, that returns <code class="keyw">true</code>. So it is possible (and recommended) to check the consistency of subobjects of <var class="Arg">obj</var> recursively by <code class="func">IsInternallyConsistent</code>.</p>
<p>(Note that <code class="func">IsInternallyConsistent</code> is not an attribute.)</p>
<p><a id="X7F4D216B7DF7BE9D" name="X7F4D216B7DF7BE9D"></a></p>
<h5>12.8-4 MemoryUsage</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ MemoryUsage</code>( <var class="Arg">obj</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>returns the amount of memory in bytes used by the object <var class="Arg">obj</var> and its subobjects. Note that in general, objects can reference each other in very difficult ways such that determining the memory usage is a recursive procedure. In particular, computing the memory usage of a complicated structure itself uses some additional memory, which is however no longer used after completion of this operation. This procedure descends into lists and records, positional and component objects, however it does not take into account the type and family objects! For functions, it only takes the memory usage of the function body, not of the local context the function was created in, although the function keeps a reference to that as well!</p>
<div class="chlinkprevnextbot"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap11.html">[Previous Chapter]</a> <a href="chap13.html">[Next Chapter]</a> </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>
|