Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  chap21.html   Sprache: HTML

 

 products/Sources/formale Sprachen/GAP/doc/ref/chap21.html


<?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 21: Lists</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="chap21"  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.

<div if level=0then

<p id list[os;
<p><a id="X7B256AE5780F140A" name="X7B256AE5780F140A"></a></java.lang.StringIndexOutOfBoundsException: Range [1, 61) out of bounds for length 5
<div =ChapSects> href"chap21.html#X7B256AE5780F140A">21 <span class="Heading">Lists</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap21.html#X86B28F5B781FFD31">21.1 <span class="Heading">List Categories</span></a>
</span>
div ="ContSSBlock>
<span class="ContSS"><br /><span class="nocss">  </span><a java.lang.StringIndexOutOfBoundsException: Range [69, 0) out of bounds for length 0
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X870AA9D8798C93DD">21.1-2 IsDenseList</a></span>
s "ontSS"</>spanclass=""  />ahref=chap21
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X80872FAF80EB5DF9">21.1-4 IsTable</a></span>
<span class="ContSS"><br /><span class="nocss">  </span<>aid=X8611EF768210625B"name=X8611EF768210625Ba<pjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
<spanclass="ContSS">br />< ""&&bsp;/< hrefchap21html
</div></div>
<div class="ContSect"><span class="tocline">
</span>
<divpcodeclass=>A"<[var ""ix</> =v"java.lang.StringIndexOutOfBoundsException: Range [98, 97) out of bounds for length 123
<span class=<Theelementassignmentassigns  < "></var,which  be of  type listwithindex<varclass""ix/var>,  the mutable ( a=chap12html#X7F0C119682196D65"><span class="RefLink">12.6</span></a>) list <var class="Arg">list</var>. That means that accessing the <var class="Arg">ix</var>-th element of the list <var class="Arg">list</var> will return <var class="Arg">object</var> after this assignment.</p>
</div></div>
div class"ContSect"spanclass=tocline< =nocss>nbsp;<span<a href=chap21#X7921047F83F5FA28">21.3 <span class="Heading">List Elements</span></a>
</span>
<div class="ContSSBlock">
<span class< =GAPprompt"gapgt;<span <spanclass="APinput">1 =3;              # assign a new object</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap21.[3, 2,3 ]
</span>
<iv class=""
<span class="ContSS"><br /><span class="nocss">  </span><a href="[ 3 [ 5 6 ] 3 
<span class="ContSS"><br /><span class="nocss">< class=GAPprompt>&;/span <class=G"l[ l[1] ] =10; l;#lt;index&   /span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X7E98B11B79BA9167">21.4-3 Remove</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X79D7E96F80A2D7C0">21.4-4 CopyListEntries</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X79E31DB27C82D6E1">21.4-5 Append</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span>
<div class="ContSSBlock">
<span class="ContSS">java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span class="ContSS"><br /><span class="nocss"d class=e"<>
</div></div>
<div class="ContSect"><span class="tocline"><<span class="GAPprompt">gap></span> <span classl[ = "anotherentry";; ;# <list> is enlarged</span>
<
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"span="APprompt"gap&;/pan> spanclass="APinput"l[ =; l;#now ltlist&;/java.lang.StringIndexOutOfBoundsException: Index 128 out of bounds for length 128
</span>
</div>
<div class="ContSect"><span /pre<div>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X7B914A287F88ED0A"><code>21.8-1 \in</code></a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap21.html#X84D6FC7E7E39ED33">21.9 <span class="Heading">Enlarging Internally Represented Lists</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X78BF67A5802E93AD">21.9-1 EmptyPlist</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap21.html#X8016D50F85147A77">21.10 <span class="Heading">Comparisons of Lists</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </spanjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
</>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap21.html#X84D642967B8546B7">21.12 <span class="Heading">Filters Controlling the Arithmetic Behaviour of Lists</span></a>
</pan>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X87ABCEE9809585A0">21.12-1 IsGeneralizedRowVector</a></span>
<span class="ContSS"<br /<pan "">nbsp;nbsp;/span<ahref="chap21.html#X7FBCA5B58308C158">21.12-2 IsMultiplicativeGeneralizedRowVector</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X7BAD12E67BFC90DE">21.12-3 IsListDefault</a></span>
<span class="java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0
 class=">br/>span class=>;nbsp<< =chap21#X84B383B97FD986CD">21.12-5 NestingDepthM</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span < =Ggap&</span>< "l =  2,3, ,7, 11,, ,19 ;<spanjava.lang.StringIndexOutOfBoundsException: Index 106 out of bounds for length 106
</span>
<div class="GAPprompt>ap>/span <spanclass"">l{[.4} : [.13;; l/pan>
<span class="ContSS"><br ,11 ,1311, 1317, ]
</span>
<span <span classGAPprompt>><span java.lang.StringIndexOutOfBoundsException: Range [60, 50) out of bounds for length 105
</span>
<span class="ContSS"><br /><span class="nocss">  </span><a java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 36
</span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X7C3DC8BE78DEECDE">21.13-4 <span class="Heading">Subtraction of lists</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap21.html#X782ED7F27D8C7FC1">21.14 <span class="Heading">Multiplicative Arithmetic for Lists</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span classjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
</span>
<span< class=">pre>
</span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X84FDB95179BFE4CD">21.14-3 <span class="Heading">Multiplication of lists</span></a>
</span>
<spanclass=ContSS"<br /< class"nocss"&;nbsp</>a href"chap21.java.lang.StringIndexOutOfBoundsException: Index 164 out of bounds for length 164
/>
<span class="ContSS"><br /><span class="nocss">/</iv
<java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
 >class"nocss&;nbsp;/span<.html#X84BB2DFB8432A1A4">21.14-6 <span class="Heading">Left quotients of lists</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap21.html#X8676EFE67972FD06">21.15 <span class="Heading">Mutability Status and List Arithmetic</span></a>
</span>
<divclass"ContSSBlock">
<span class="ContSS"><br /><spanContSS>< /<span class=nocss>nbsp;nbsp;<span<a href"chap21.html#X82B1411E7FBE925F">21.21-3 SumX</a></span>
<div</div>
<div class="ContSect"><span class="tocline"<div>/div>
</span>
<div class="ContSSBlock">
<spanclass="ContSS">""> =nocss">&bsp</>a =tml#X79596BDE7CAF8491">21.22 <span class="Heading">Ranges</span></a>
<span class="ContSS"></spanjava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
<span class=ContSS"< >< class="< /span "">nbsp /span< href=chap21.#X86DDC2FF7A50FBEE">21.22-1 IsRange</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X7D2B25B484591506">21.16-4 PositionNthOccurrence</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a< class=ContSSjava.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 0
<<>Theexact  is defined in the same way as<>div>
< =ContSect"spanclass=tocline>< class=nocss>nbsp;/span>ahref"html#X7EA3ACE27E43D174">21.23 <span class="Heading">Enumerators</span></a>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.<span>
<span class="ContSS"><br /><span class="nocss< =ContSS"< >span=nocss"><iv"<>
<span <div><java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
n =ContSS>br/< class=n>nbsp&;/>< href".tml
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html</span>
<span class="ContSS"><br /><span <span class="ContSS"><br /><span classnbsp;nbsp<span> ".#X8438CB908367254C">21.24-1 PlainListCopy</a></span>
">br /<spanclass=nocss"&&<span< =chap21html
<span class="ContSS"//>
</div></div>
 ="span=tocline>classn"&;<java.lang.StringIndexOutOfBoundsException: Range [77, 76) out of bounds for length 191
</span>
<div class="ContSSBlock">
spanclass=ContSS>br code ""varArg"java.lang.StringIndexOutOfBoundsException: Range [67, 66) out of bounds for length 540
java.lang.StringIndexOutOfBoundsException: Range [129, 5) out of bounds for length 140
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X7BAA9B0E81D4A884">21.17-3 IsSortedList</a></span>
<span class="ContSS"><br /><java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span class<iv=example">pre
<span class="ContSS"><br /><span class="nocss">  </span><a href="java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 53

<div class="ContSect"><span java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 9
<span>
<div class="ContSSBlock">
<spanif =0 java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
 class="nocss">nbsp  list[s:vals
<span class="ContSS"><br /><spanjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
span ""><br/ "" />a".html
</div></div>
<div classjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
anjava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
<div class="ContSSBlock">
<od
< class=ContSS><br/<class">n;nbsp;/>java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
<span class="ContSS"><br /><java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
s=>br/< class"ocss>n&;<span>a="</re<div
<span class="ContSS"><br /><span class="nocss"> java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span class="ContSS"ment< =code>varclass"Arg">/{varclass"o level <var class="Arg></var>iscomputedas<code class="code>ListAssignments(varclass"rg"list<var,< class""poss/var>, var class""</>,< =Arg>/var>)/code>, where <code class="code">ListAssignments</code> isdefined java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 11
<span class="ContSS"><br /><span class=java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span class="ContSS"><<div class="example"><pre
</java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 12
<div class="ContSect<>Each listconstructedthis way is mutable (see <a java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 9
/>
<div class="ContSSBlockp< id"" =<poss =;
<java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
<span class="ContSS"><br /><span class="  ijava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
spanclass=ContSS>br/<span ">&;nbsp;/java.lang.StringIndexOutOfBoundsException: Range [0, 65) out of bounds for length 54
<span class="ContSS"><br /><span class ;
span=""<br/< class""nbsp;nbsp<span< href"hap21html#X7F5D4DD87E4378AC">21.20-5 AsDuplicateFreeList</a></span>
<span class="ContSS"><br /><spanjava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0
<span <prediv
spanclass=ContSS"<br >span ="ocss"&;nbsp;/>ajava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
span t
<span class="ContSSfalse
<span class="ContSS"><br<pre>/java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
<span class="ContSS<>a="c>code2141{\=><>
</span>
<span class="ContSS"><br 
</span>
<pan ""<< ="table=func"=100"tr< =tdleft"<ode func"‣ \{\}\:\=</code>( <var class="Arg">list</var>, <var class="Arg">poss</var>, <var class="Arg">val</var> )</td><td class="tdright">( operation )</td></tr></table></div>
</span>
<span class="ContSS"><br /><span class="nocss">  </span><a table=func width=100"><><dclass""codeclass"unc>&8227;IsDenseList<code(<arclass=">bj/var>)/td><d class=
</span>
span class=ContSS>br /><span class=nocss>&bsp&;/span><a hrefjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
</span>
<span class="ContSS"><br /><span class="nocss">  </span><a href
<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
span class="ContSS">br/>spanclass=nocss">nbsp&bsp;/span>a href=chap21.html#X7C86D7F7795125F0">21.20-19 Filtered</a></span>
<span class"ontSS>br/<spanclass<class>gt</pan<an =">IsDenseList([1 2,3 ] )</pan
<span class="ContSS"><br /><span class=spanclass=GAPprompt>&;<span><pan class""l:   4 >   =>/>   class="glistvar  twoargumentversion  var =Arg"<var  theend varclass"Arg"<var>,i.e,isjava.lang.StringIndexOutOfBoundsException: Index 214 out of bounds for length 0
<span class="ContSS"><br /><span class="nocss">&bsp;nbsp;</span><a href="chap21.html#X7E5B62E780421CE9">21.20-22 Last</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X7F06961278166671">21.20-23 ForAll</a></span><p>is <class=funcAdd<code> thefunction      side<p>
spanclass
<span class="ContSS"><br /><span class<>List: lt;gt[ have assigned 
<spanclass=ContSS"< >s class=n>nbsp;nbsp;/>java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
<span class="ContSS"><br java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span class="ContSS"><<div class"func>table class=func"width=100"<tr><td class"">< class"unc>&n style='color:green'>#8227; Remove</code>( <var class="Arg">list</var>[, <var class="Arg">pos</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap21.html#X805CA0B68029B47A">21.21 <span class="Heading">Advanced List Manipulations</span></a>
</span>
<div class="ContSSBlock">
<panclassjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
< class"ContSS"< ><span = java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 124
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X82B1411E7FBE925F">21.21-3 SumX</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X7FB318B47D8783DA">21.21-4 ProductX</a></span>
</div>/ivjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
<div class="ContSect"><span java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 0
/spanjava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
<div class="ContSSBlock">
<> requestingthe  < classcode>]/code>  was  assigned,caused entryofa<ode class=keyw"break>loop see Section<ahref=chap6.tml#X8593B49F8705B486"><span class="RefLink">6.4</span></a>). After assigning a value and typing <code class="code">return;</code>, <strong class="pkg">GAP</strong> is finally able to comply with our request (by responding with <code class="code">16</code>).</p>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap21.html#X83896BC481536B07">21.22-2 IsRangeRep</a></span>
span class"">< /<pan class=nocss>nbsp&;<span< href"chap21.html#X7D22B2298167A58F">21.22-3 ConvertToRangeRep</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><<span class="GAPprompt">gap></span> <span class">(l4,2;ljava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
</span>
<div class="ContSSBlock">
pan""ContSS"br/>spanclass=nocss>nbsp;nbsp;/>=".html#X7BB462C17962647F">21.23-1 IsQuickPositionList</a></span>
</div></div>
<<>eturns< class< "GAPprompt"gap;span span ""Removel2;l;/
</span>
<div class="ContSSBlock">
 =ContSS"< />span =n"&;&;/>ahref".
<span [ 2,, 57java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
</div></div>
</<div=example<re>

<h3>21 <span class="Heading">Lists</span></h3>

  importanttotreatobjectstogether  <><>arranges   a    impliesamapping integers    elements  .I.,here  afirstelement   list,  second  third,and .Lists occurin mutableor  ,  < ="chap12.#X7F0C119682196D65"><span class="RefLink">12.6</span></a> for the concept of mutability, and <a href="chap21.html#X7ED7C0738495556F"><span class="RefLink">21.7</span></a> for the case of lists.</p>, ]

<p>This chapter deals mainly with java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 0

 ranges( java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>Severaloperationsfor lists, such as < ="func"<

<p><adiv <>A<em</em>isanonempty  of  lists    thesame Typical   tables arematrices s<hrefchap24.#X812CCAB278643A59"><span class="RefLink">24</span></a>).</p>

<h4>21spanclass">&;/pan><pan class="   <fAddcode(ajava.lang.StringIndexOutOfBoundsException: Index 318 out of bounds for length 318

  writingdown injava.lang.StringIndexOutOfBoundsException: Range [63, 62) out of bounds for length 308


< ""java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span classjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
[ 1, 2, 3 ]
<span class="GAPprompt">gap&java.lang.StringIndexOutOfBoundsException: Range [28, 0) out of bounds for length 0
[ [],[ 1] [1 2 ]<java.lang.StringIndexOutOfBoundsException: Range [5, 4) out of bounds for length 248
</pre>/div>

<p>Each list constructed this way is mutable (see <a href="chap12.html#X7F0C119682196D65"><span class="RefLink">12.6</span></a>).</p>

<p<a =X7C4CC4EA8299701E"name"X7C4CC4EA8299701E"<>2115/>

<h5>21.1-1java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<div class="func"><table<pNote<Alistlies <java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 169
<>tests whether <var class="obj<var is a list./>


<div class="example"><pre>
<span class="GAPprompt">gap><
true
false
</pre></div>

<p><a <div =example"<reC"name""//

<h5>21.1-2 IsDenseList</h5>

<div class="func"><
<p[ <class=>class="width="%tr< java.lang.StringIndexOutOfBoundsException: Range [65, 64) out of bounds for length 234


<div class="example"><pre>
<class=GAPprompt">gap&;s>s class="APprompt">ap&<span span class=""Append l, 17,23]; ;/pan>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">l := [ , 4, 9,, 25,, 49,,,, 121 ];;  IsDenseList( l );</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
9
spanclass"p>The basic operationssee<href".
List Element: <list>[4] must have an assigned value
not function
Entering break read-eval-print loop ...
you can 'quit;' to quit to outer loop, or
you can 'return;' after assigning a value to continue
<span class="GAPbrkprompt">brk></span> <span class="GAPinput">l[4] := 16;;  # assigning a value</span>
<span class="GAPbrkprompt">brk></span> <span class
16
gt;
</pre></div>

<p><p>The ter basic  =java.lang.StringIndexOutOfBoundsException: Range [55, 52) out of bounds for length 62

<p><5>21.51java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0

<h5>21.1-3 IsHomogeneousList</h5>

<div class="func"><table class="func"<>a < "><table ="func =100"<>tdclass""< class""‣ IsBound</code>( <var class="Arg">list</var>[, <var class="Arg">n</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<p>returns <code class=java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p><divclass""<table ="" =100"<=example<pre>


<div class="example"><pre>
< class="GAPprompt>>/span> <span class=GAPinput">(1 2,3])  IsHomogeneousList ];<>
true
true
span="GAPprompt>gap>/span> <spanclass="GAPinput">IsHomogeneousList [ 1, false, ) ] );/>
false
</pre></div>

<>aidX80872FAF80EB5DF9=<>>

h5211- </h5java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23

<div class="func"><table class="func" width="100%"><tr>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<p>A <em>table</em> is a nonempty list of homogeneous lists which lie java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class="example"><pre>
<span classp  java.lang.StringIndexOutOfBoundsException: Range [0, 22) out of bounds for length 0
true
<span classjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [4, 5) out of bounds for length 4
span""gap>class=" =< class=""#;ode<classArgvar< =Arg>/var, v ="><var> </td<td=tdright"(operationnbsp;<td>/tr><table></>
false
</pre></div>

<p><a id="

<h5>21.1-5 IsRectangularTable</h5>

<div class="func"><table class="func" width<pIfvar =Arg>/varisnotabuiltjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
p>p>odeclass""> classArg"listv{varclass=rgposs</>}/code>/pjava.lang.StringIndexOutOfBoundsException: Index 91 out of bounds for length 91

<p< class""prejava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26

<h5>21.1-6 IsConstantTimeAccessList<class">&;/>span class="java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 94

<div class="func"><table class="func" width="100%"><tr[2 17,2  
<>Thiscategory whetheraccess  element thelist<class"Arg">/var 1 2,a"]

 (eeahref="chap21java.lang.StringIndexOutOfBoundsException: Range [50, 0) out of bounds for length 0

<p><a id="X7B202D147A5C2884" name="X7B202D147A5C2884"></<> result < class"APprompt>&t/>< ">(l2,ewobj)/spanjava.lang.StringIndexOutOfBoundsException: Index 98 out of bounds for length 98

<h4>21.2 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

p>hebasicoperationsforlistsareelement( a ="chap21htmlX7921047F83F5FA28

<p>s class"GAPprompt"s =GAPprompt>&;/><spanclass=GAPinput"m =[ 2,3] 456,[7,,]

<p>Any ""

<p><panclass""gapgt<span <span/>

<>aidjava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4

<h5<>212-1 <>/>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

< class=func>table ="=100"<>t ""<code =func#8227; <span>\</span>[<span>\</span>]</code>( <var class="Arg">list</var>, <var class="Arg">ix</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 0
iv"" ""width"">tdclass""java.lang.StringIndexOutOfBoundsException: Range [80, 79) out of bounds for length 300
divclass%<><td">code =>#;Unbind><span>/>]/>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<521.5-Unbind<h5>

<p>Note java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 0

<p><code class=< class""<table 

<pp< =func/  with< =""varthe java.lang.StringIndexOutOfBoundsException: Range [112, 111) out of bounds for length 639

<p>Analogous statements hold for <code class="func"><span>\</span>[<span>\</span>]\:\=</code> and <code class="func">Unbind<span>\</span>[<span>\</span>]</code>. java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0

<p><a id="X7921047F83F5FA28" name="java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 4

<h4<>  codeclass"code"<varclass"Arg"list<var{<var =Arg></java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p><code class="code"><var class="Arg">list</var>[ <var class="Arg">ix</var> ]</code></p>

<p>The above construct evaluates to ListElements := function ( list, poss,


<<re>
<span class="[, 2,, 5,, ,,,, 11 ]
2
3
13
<pre</>

<> < class"Arg 2,,,,,,11 java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20

<p><code class="code"><var class="Arg">list</var/>/div>

<p>Thep<p>  codeclass"IsBoundcode( =java.lang.StringIndexOutOfBoundsException: Range [64, 63) out of bounds for length 537


<div class="example"><pre>
<span class="GAPprompt">gap></spanjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span class="GAPprompt">gap></span> <span class="GAPinput">l{[4..6]};  l{[1,7,1,8]};</span>
[ 7, 11, 13 ]
[ 2, 17, 2, 19 ]
</pre></<421. span class=Heading"IdenticalLists</pan</java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58

, that not   java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>tis possible to such <>sublist extractions


<divjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
">><span <span "GAPinput">m: [[,2,3], [,, [,,] 10,,java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
[ [ 3, 2 ], [ 6, 5 ], [ 9, 8 ] ]
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
[[ 7, 8 9 ],[  ;
</pre></div>

<p>Note the difference between the two examples. <> list assignmentassigns the  < =""object/>,  canbeof any type, to the list with index <var class="Arg">ix</var>, in the mutable (see <a hrefjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>To be precise: With each selector <code class="code">[<var class="Arg">pos</var>]<<panclass=GAPpromptgap<span><span java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class="example"><pre>
    l[pos1]{poss2}{poss3}[pos4]{poss5}[pos6]
level   0      0      1     2      2     3
</pre></div>

pThen  odeclass=ode> class""><[ar =A"posvar]code oflevel<class=Arg><>   <">(< ""list/>< "Arg"pos/,var =Arg>/)p/


mple"<>  assignment doesnot change the first list itassignsa new list  thevariable <code class="code">l</code>. On the other hand, in the following example the list <em>is</em> changed by the second assignment.</p>
<pjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
if level= 0 then
  return list[pos];<iv ""<pre
 else
   ->ListElement(elm,pos,level-1) );
 fi;
end;
</pre></div>

<p>and a selector <code class="code"><var class="Arg"span ="GAPprompt>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div</re><divjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
ListElements := java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
  level=0 then
  return list{java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
  else<pNote that assigning re
   return java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 0
  <pIf<=Arg><var  notevaluatejava.lang.StringIndexOutOfBoundsException: Range [55, 54) out of bounds for length 565
end;
</pre></div>

<p><a java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<h5><code>21.3-1 \{\}</code></h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&an style='color:green'>#8227; \{\}</code>( <var class="Arg">list</var>, <var class="Arg">poss</var> )</td><td class="tdright">( operation )</td></tr></table></div>2  ];
<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

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

<>.4 < =Heading"ListAssignment<span><h4

p< "code"<class="">/varvar> varclass""><var ]=< =Arg></><code</>

<p>The listspanjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span""gap&t =[,2];
< class=GAPprompt>gap&;/span><span class="GAPinput">l[1]]: 3l2: l1;
[ 3, 2, 3 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">l[2] := [ 4, 5, 6 ];; l;   
java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 21
<span class="
[ 3, [ 4, 5, 6 ], 10 ]
<pre>/ivjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12

<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<p>Let us now consider under which circumstances  lists identical/<classjava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 124
<span class="GAPprompt">gap></span> <span class="GAPinput">l[4] := "another entry
[3,  4, 5 6] 10 another entry" ]
<span class="java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0
try,> enterlist then byisnewlist  isnot toany other  in example <ode class=code></code> and< class=
</pre></div>

<p>The function <code class="func">Add</code> (<a href="chap21java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

thatto a list changes the list thus this listmust bemutable (ee <ahref".tml#X7F0C119682196D65"><span class="RefLink">12.6</span></a>). See <a href="chap21.html#X7DD65BEA7EDB0CD7"><span class="RefLink">21.6</span></a> for subtleties of changing lists.</p>

pIf< class=Arg"list/var>does notevaluateto a list varclass=Arg>pos/> does not evaluate  a  integer, methodselection is invoked to try and find a way of indexing <var class="Arglevel   0     1      1    2

<p

>sublistthe< =code">var<lso inexample,   list code =></ode identical../>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l := [ 2, 3, 5, 7, 11, 13, 17, 19 ];;</span>
<span class="GAPprompt">gap i;
[ 10, 11, 12, 13, 11, 13,<div class="example"     then
<span class="GAPprompt">gap></span> <span class="GAPinput">l{[else
[3,11, 12  for  1.] do
</pre>t [] java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 52

<>The next showsthatit is possible to;


<div"">
<span class="GAPprompt">gap></span> <span class="GAPinput">m java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span class="GAPprompt">gap></span> <span class="GAPinput">m{[1,2,3]}{[3,2]} := [ [11,12], [13,14], [15,16] ];; m;</span>
[ [ 1, 12, 11 ], [ 4, 14, 13 ], [ 7, 16, 15 ],< =>pre
</pre></div>

<p>The exact behaviour is defined in the same way as for list extractions (see <a href="chap21.html#X7921047F83F5FA28"><span class="RefLink">21.3</span></a>). Namely, with each selector <code class="code">[<var class="Arg">pos</var>]</code> or <code class="code">{<var class="Arg">poss</var>}</code> we associate a <em>level</em> that is defined as the number of selectors of the form <code class="code">{<var class="Arg">poss</var>}</code> to its left in the same expression. For example</p>


<div class="example"><pre>
    l[pos14
level   0      0      1     1      1     2
<

<p>Then [,3,5 java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11


<div class="example"><pre>
ListAssignment := function ( list,
 locali;
 if level = 0 then
  list[pos] := java.lang.StringIndexOutOfBoundsException: Range [0, 19) out of bounds for length 0
 else
  for i in [1..Length(list)] do
    ,pos ,-1 )
  od;
 fi;
end;
</pre></div>

<><codeclass""CopyListEntries/>  used in     < class""Add/> (<a href"hap21java.lang.StringIndexOutOfBoundsException: Range [318, 152) out of bounds for length 318


dclasse>prejava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
ListAssignments := function ( list, <h5>.45 Append/h5>
 local i;
 if level  0 
  list{poss} := vals;
 else
  for i in [1..Length(list)] do
   ] poss, vals[i,- )java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
  od;
 fi;
end;
</pre></div>

<p><a id="X813FF1637F8D2B7F" name="X813FF1637F8D2B7F"<class"

<h5><code>21.4-1 \{\[2,,5,,  17,23]

<div class="func"><table class=<< ""=>a>>
<p>This operation implements sublist assignment. java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

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

<h5>21.4-2java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<div class="func"><<div class="func"><table= =100%>tr tdleft> ">
<p>adds the element <var class="Arg">obj</var> to the mutable list <var <><odeclass=func<code>  class"><  list< ="/>has  indexvar=>, k"<code .var "/> toan for afor<class"\\<> installed otherwisean   ./>

<><re>

<p>Nothing is returned by <code class="func">Add<<pan""&;/>s "java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 106

p>"/><p>

<rue

div""< =func=100"<> class""< ">#8227; Remove</code>( <var class="Arg">list</var>[, <var class="Arg">pos</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<p>removes java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

<p>java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

<p>The two argument form returns the <><a id=X866F45D3797FDA00name=X866F45D3797FDA00>/>/>


<div class="example"><pre>
<span classdiv="< ""width"%>>tdclass"">code""&8227 code(<java.lang.StringIndexOutOfBoundsException: Range [135, 134) out of bounds for length 283
 ,3 ,  java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
<span class="GAPprompt">gap></span> <span class="GAPinput">Add(l,4,2); l;</span>
[ 2, 4, 3, 5, 7 ]
span =G>&;/><classGAPinputRl2;;<
4
[ 2, 3, 5java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<<p>Todistinguishvar Argnvarth element   varclass"">in<ar =Arglist  create  new ,suchstring< ><code (href=.htmlX7961183378DFB902< class"12.51</>a)returns code class=keyw>/>for differentmutable strings, even if their contents are the same.</p>
7
[ 2, 3, 5 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">Remove(l,5); l;</span>
[ 2, 3, 5 ]
</pre

<piv =""<pre>

<h5>21.4-4 span class="GAPprompt< spanjava.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 85

=func"<table =func ="<r>td class=tdleft"< java.lang.StringIndexOutOfBoundsException: Range [87, 85) out of bounds for length 410
<p>This function copies <var class="Arg">n</var> elements from <var class="Arg">fromlst</var>, starting at position <var class="Arg">fromind</var> and incrementing the positionjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

<p><code class="func">CopyListEntries</code> is used < class=""gap&t/>< =GAPinput>java.lang.StringIndexOutOfBoundsException: Range [78, 76) out of bounds for length 98

<< =X79E31DB27C82D6E1 ""<a<p>

<h5>21.4-5 Append</h5>

<div class="func"<5215</5>
ar>to end  mutable list< =""list1>, see< href="chap21html#X8611EF768210625B"><span class="RefLink">21.4</span></a>. <var class="Arg">list2</var> may contain holes, in which case the corresponding entries in <var class="Arg">list1</var> will be left unbound. <code class="func">Append</code> returns nothing, it is only called for its side effect.</p>

<p>Note that <code class="func">Append</code> changes its first argument, while <code class="func">Concatenation</code> (<a href=java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


d "">>
<span class=" , 2,, 5,, 7,,,, 11]
[ <span class="GAPprompt">gap></span> <span class="GAPinput">Unbind(
span class="GAPprompt">gap></span> <span class="GAPinput">Append( l, [ 17,, 23 ] ); l;</span>
[ 2, 3, 5, 7, 11, 13, 17,, 23 ]
<>/

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

<h4>/>/div  valueof< "ode"1/ode,whichcode>/ to codeclass""i</. same thing happens inthe example/java.lang.StringIndexOutOfBoundsException: Index 376 out of bounds for length 376

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

<h5>21.5-1 IsBound</h5>

<div class="func"><table class="func" width="100%"><tr><td classl : [ 1,2,3 ;
<p><code class="func">IsBound</code> returns <code class="/>java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12


<div java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
<span class="GAPprompt">gap></span> <span class="GAPinput">l := [ , 2, 3, , 5, , 7, , ,  : [1, 2 ];
< class="gapgt;/>< classclass="GAPinput"IsBoundl] )</java.lang.StringIndexOutOfBoundsException: Index 85 out of bounds for length 85
true
<span class="GAPprompt">gap></<To  think  as   .    a    names  .Ancode<class""/: =""list/><  thisthat<class=">var<var>is  for  object var class=Arg><var> At the end the  example code =code><code still thevalue <code class="code">[ 1, 2 ]</code> as this list has not been changed and nothing else has been assigned to it.</p>
false
<span class="GAPprompt">gap></span> <span class= class="example"<pre
false
</pre></div>

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

<h5>21.5-2 GetWithDefault</h5>

<div class="func"><table class="func" width="100%"><tr><java.lang.StringIndexOutOfBoundsException: Range [0, 58) out of bounds for length 0
<p><code class="func">GetWithDefault</code> returns the <var class="Arg">n</var>th element<pBut after followingexample list forwhich <code class"code">2</ode> is aname been changed  the value  <codeclass="ode"></code> is now <code class="code">[ 1,2  ]code./p

<p>While

  betweenthe<=Arg">n<var> element being unbound,unbound or var class="rg>default</> being in var class=Arg>list</> userscancreatea  mutable,such as a .< ""</>(ahref="htmljava.lang.StringIndexOutOfBoundsException: Index 443 out of bounds for length 443


< class="example"><pre>
<span class="java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 0
[,,"a"]
<span class="GAPprompt">gap></span> <span class="java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 0
"a"
<span java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
2
<span class="GAPprompt">gap></span> <span l1 : [ 1 ];
"a"
<span class="GAPprompt">gap></span> <span class="GAPinput">GetWithDefault(l, 4, newobj);</span>
"a"
<span class="GAPprompt">gap
true
<span class="GAPprompt">gapjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 26
l2 =
</pre></div>

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

<h5>21.5-3 Unbind</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&an style='color:green'>#8227; Unbind</code>( <var class="Arg">list</var>[, <var class="Arg">n</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<p><code class="func">Unbind</code> deletes the element with index <var class="Arg">n</var> in the mutable list <var class="Arg">list</var>. That is, after execution of <code class="func">Unbind</code>, <var class="Arg">list</var> no longer has an assigned value with index <var class="Arg">n</var>. Thus <code class="func">Unbind</code> can be used to produce holes in a list. Note that it is not an error to unbind a nonexistent list element. <var class="Arg">list</var> must evaluate to a list, or to an object for which a suitable method for <code class="code">Unbind\[\]</code> has been installed, otherwise an error is signalled.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l := [ , 2, 3, 5, , 7, , , , 11 ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Unbind( l[3] ); l;</span>
[ , 2,, 5,, 7,,,, 11 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">Unbind( l[4] ); l;</span>
[ , 2,,,, 7,,,, 11 ]
</pre></div>

<p>Note that <code class="func">IsBound</code> (<a href="chap21.html#X79EC565A7DCEC938"><span class="RefLink">21.5-1</span></a>) and <code class="func">Unbind</code> are special in that they do not evaluate their argument, otherwise <code class="func">IsBound</code> (<a href="chap21.html#X79EC565A7DCEC938"><span class="RefLink">21.5-1</span></a>) would always signal an error when it is supposed to return <code class="keyw">false</code> and there would be no way to tell <code class="func">Unbind</code> which component to remove.</p>

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

<h4>21.6 <span class="Heading">Identical Lists</span></h4>

<p>With the list assignment (see <a href="chap21.html#X8611EF768210625B"><span class="RefLink">21.4</span></a>) it is possible to change a mutable list. This section describes the semantic consequences of this fact. (See also <a href="chap12.html#X84545F3985C60F5B"><span class="RefLink">12.5</span></a>.)</p>

<p>First we define what it means when we say that <q>an object is changed</q>   in    changesinteger<java.lang.StringIndexOutOfBoundsException: Index 169 out of bounds for length 169


<div class="example"><pre>
i := 3;
i := i + 1;
</pre></div>

<p>But in this example it is not the <em>integer</em> <code class="code">3</code> which is changed, by adding one to it. Instead the <em>variable</em> <code class="code">i</code> is changed by assigning the value of <code class="code">i+1</code>, which happens to be <code class="code">4</code>, to <code class="code">i</code>. The same thing happens in the example below.</p>


<div class="example"><pre>
l := [ 1, 2 ];
l := [ 1, 2, 3 ];
</pre></div>

<p>The second assignment does not change the first list, instead it assigns a new list to the variable <code class="code">l</code>. On the other hand, in the following example the list <em>is</em> changed by the second assignment.</p>


<div class="example"><pre>
l := [ 1, 2 ];
l[3] := 3;
</pre></div>

<p>To understand the difference, think of a variable as a name for an object. The important point is that a list can have several names at the same time. An assignment <code class="code"><var class="Arg">var</var>:= <var class="Arg">list</var>;</code> means in <pThismeansthat anylist <class"><var,< =><code>< =html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) returns a mutable <em>new</em> list <var class="Arg">new</var> that is <em>not identical</em> to any other list (see <a href="chap21.html#X7DD65BEA7EDB0CD7"><span class="RefLink">21.6</span></a>), and whose elements are identical to the elements of <var class="Arg">list</var>.</p>


<div class="example"><pre>
l1 := [ 1, 2 ];
l2 := l1;
l1 := [ 1, 2, 3 ];
</re>/divjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12

p afterthethe forwhich <code""l2code    been and ofcode""l2  now code =c"[ 1,2  ]code>.</p>


<div class="example"><pre>
l1 := [ 1, 2 ];
l2 := l1l
l1[3] := 3;
</pre></div>

>  thatlists<>/a changestheother.isincorrect   <emtwo/ listsare identical, thereareactuallyonlytwo  foremone/> .However the    would  totheconfusion.Note identical must  ,becausethere  onlylistwith different  identity   relationthatis . ofbe  <code="unc>IsIdenticalObj</code> (<a href="chap12.html#X7961183378DFB902"><span class="RefLink">12.5-1</span></a>).</p>

<p>Let us now consider under which circumstances two lists are identical.</p>

<p>If you    i]: [];


<div class="example"><pre>
l1 := [ 1>
l2 := [ 1, 2 ];
</pre></div>

<p>Also in the following example, no lists in the list <code class="code">l</code> are<div =""<pre


<div class="example"><pre>
l := [];
fori in[1.]do l]:[,2]od;
</pre></div>

<p>If you < ="GAPprompt">gap>/span>spanclass"GAPinput">IsIdenticalObj( list1[1], list2[1] );</span>


<div class="example"><pre>
l1 : [1 2];
l2 := l1;
</pre></div>

<p>If you pass a list as an argument, the old [ [1, 2] 3, 4] ]


<div class="example"><pre>
l1 := 12;
f := function ( l ) return l; end;
l2 := f( l1 );
</pre></div>

<p<><code class=func>tructuralCopy</ < "java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 178


<div class="<span class="GAPprompt&<><class">   ,2 ; java.lang.StringIndexOutOfBoundsException: Range [100, 99) out of bounds for length 110
l1 := [ 1, 2 ];
l2 := l1;
l1[1] := 2;
</pre></div>

<>< id"" =X7ED7C0738495556F>/a>/>

>217< classHeading"Duplication  , 2]  ,2]]

<p><pre><div>

<p>The subobjects (see <code class="func">ShallowCopy</code> (<p>aid="=>/>/>

<

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>In both cases, modifying the copy<>  ( hcode218-\<>/java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32

<p><code =funcShallowCopy/> < ".tml


<div class="example"><<p both cases   copy< class"">ew/> varclass="">/>by  see<"chap21.java.lang.StringIndexOutOfBoundsException: Range [264, 137) out of bounds for length 264
 =]java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
for i in [ 1 .java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0
  if IsBound list[]  then
    new[i] := list[i];
  fi;
od;
</pre></div>


<java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
<span class="GAPprompt">gap><pan=fi
<span ""gapg;/><">(,list2 );</span>
false
<span class="GAPprompt">gap></span> <span java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 0
true
<span class="GAPprompt">gap></span> <span class="GAPinput"=chap21.tml#X8196FD4779BCCA0C"><span class="RefLink">21.16</span></a>.</p>
[ [1, , [,
[ 0, [ 3, 4 ] ]
</pre></div>

<p><code class="<panh4. c=eading" <span>/>


<div class="example"><pre>
new :
for  in[1 s""<java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 100
  if IsBound( list[i] ) then
  newi =( list[])
  fi<>/java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 12
od;
</pre></div>


<div class="example"><pre>
<span class="GAPprompt">gap>new=]java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
<pan class=GAPprompt"gap<span><class"APinput"IsIdenticalObj  )<spanjava.lang.StringIndexOutOfBoundsException: Index 100 out of bounds for length 100
false
<span class="GAPprompt">gap></<p>Suppose that <code class="func">Length/code>(   ( list[])then
false
<<p>For tuning  plainwe;
</<div>
[ [ 0, 2 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
</pre></div>

p  <21- h5java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26


div"java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 26
<span class="GAPprompt">java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
<an Gjava.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 102
[ [ 1, 2 ], [ 1, 2 ] ]
<span class="GAPprompt">gap>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
[ 0,2 ] [0 2 ]]
<span class="GAPprompt">gap></span> <span class="GAPinput">list1;</span>
[ [
<<pThefunction ""/ back java.lang.StringIndexOutOfBoundsException: Range [92, 91) out of bounds for length 263

<p><a id="java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 0

<h4>21.8 <span class="Heading">Membership Test ass

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

<h5  ]

<div class="func"><table class ]
<p>This function call or the infix variant <var class="Arg">obj</var< =>&;/ span""><span class="GAPprompt">gap></span> <span class="GAPinput"># now l and m use the same amount of memory</span>

<p>If the list<4.< class=H>   /></4>


<div class="example"><pre>
<span class="GAPprompt">gap&<5<>.- in/<java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
true
false
<span class="GAPprompt"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
s class"">< span ""17in s;  # uses binary search and only 4 comparisons</span>
false
<pre>/>

<p>For finding java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

p< ="84 ">/a<p

h4>21. <"" RepresentedLists/>/java.lang.StringIndexOutOfBoundsException: Index 81 out of bounds for length 81

<p></pre></di

<p>It would be <p>This definition will  their

> the supposejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

p>     .If listis  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>The result of this is of<>On other hand <p>Lists are ordered <em>lexicographicallyem.entriesaresmaller  That thefollowingbehaviourLet<spanclass=SimpleMath>i/>     < class""><spanjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<pjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>For fine tuning code dealing with java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p><a id="X78BF67A5802E93AD" name="X78BF67A5802E93AD"></a<> t

<h5>21.9-1 EmptyPlist</h5>

div""< 
<p>Returns: a plain <h5>21.9-1 EmptyPlist</h>

<div class="func"><table class="<div class="func"><table class="func =100%<>td "java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<Rjava.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 23

pTheclass"><>/>/java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62

<p>The function <code class="func">p>The function <code class="func">EmptyPlist  an java.lang.StringIndexOutOfBoundsException: Range [76, 75) out of bounds for length 247

<p>Note <p>The function< class=func>ShrinkAllocationPlist/code  back to <strong class="pkg">GAP</strong>'s memory manager the physical memory which is allocated for the plain list <var class="Arg">l</var>


<div class="java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
class">/>s class=GAPinput">l[>
[  ]
><<class">:())for   java.lang.StringIndexOutOfBoundsException: Index 126 out of bounds for length 126
[  ]
""# now l uses about 25% more memory than the equal list m</span>
span =GAPprompt"gap&;/> <pan
<spanpFurther aboutthe of  java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 125
</pre></div>

p< = "java.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 62

<h4.10 <span class=Heading"Comparisons ofLists<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

p> ""< "/ar>=var =A"/><p

<p><code class="code"><var class="Arg">list1</var> <<>java.lang.StringIndexOutOfBoundsException: Range [0, 7) out of bounds for length 0

<p>Two lists <<p>< class="code"><arclass=Arg>var l;g;v java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 0


d ="java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 26
<span class="GAPprompt">gap></span> <span class="GAPinputjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<
false
class"GAPpromptgapgt</> spanclass=GAPinput"[, ,3]= ,2  ;/>
false
</pre></div>

<>Thisdefinition will problems with lists which their  entries. Comparing two lists for  lead      kernel  thelistcomparisonhas  comparethe list entries which are in fact the lists themselves, and then <strong class="pkg">GAP</strong> crashes.</p>

class="Arg>/ &t; <var ; var class=""list2<var<code><p>

<p><code class="code"><var class="Arg">list1</var> <= <var <p>This definition will cause problems with lists which are their entries. Comparing  lead to aninfinite recursioninthekernel  the comparison tocomparejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

>    ><> Unboundaresmallerthananybound .Thatimplies following   < =SimpleMath><   smallest positive integer <span class="SimpleMath">i</span> such that <var class="Argjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">[ 1, 2, 3, 4 ] < [ 1, 2, 4, 8 ]; # <list1>[3] < <list2>[3]</span>
true
<<<class""< ="list1<var>&;= < class=Arg"<var<code<>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">[ 1, , 3, 4 ] < [ 1, -1, 3 ];  # <list1>[2] is unbound and thus < -1</span>
true
</pre></div>

<p>Note that forclasslt < =code>;=/>elevant  mustwithcodecode&;code>whichis <m<emthe case objectsin families see<ahref"html"class"">.<span>/>   thepossibility lists with ,see ahref".tml#X846063757EC05986"><span class="RefLink">13.1</span></a>.</p>

<>< id"" ""<a>/p

<h4>21.11 <span class="Heading">Arithmetic for Lists</span></h4>

<p>It

pDue  intended and,thedefinitions java.lang.StringIndexOutOfBoundsException: Range [74, 73) out of bounds for length 433

<p>For example, java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>For the categories and attributes

<p>For the definition of return values<iv class""<able class=func"=100"<>tdclass=tdleft"<codeclass"func">&;IsListDefault<code>( <var class="Arg">list</java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>For the <p>or  list < class"Arg"list/> c "unc"IsListDefault</ indicates that the java.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 0

<p>Further details about java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>

<h4>21.12 <span Further details""<>

<p>The arithmetic behaviour of lists is controlled by their <<=X84D642967B8546B7" "X84D642967B8546B7>/</p

<p<42112 sjava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4

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

<h5>21.12-1 IsGeneralizedRowVector</h5>

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<p>For a list <var class="<h5>21.12-1 IsGeneralizedRowVectorh5>


<div class="example"><pre>
<span class="GAPpromptjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
true
false
<span class="GAPprompt">gap></span> <span class="GAPinput">liemat:= LieObject( [ [ 1, 2 ], [ 3, 4 ] ] );</span>
 )
<span class="GAPprompt
true
</pre></div>

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

h5>21.122IsMultiplicativeGeneralizedRowVector</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class=<>  strong =""GAP/>object < =Arg>obj<var, class="func">NestingDepthM</>   <emmultiplicative nesting <em of var =Arg>obj<var> This isdefinedrecursivelyasthe integer< ="SimpleMath">0/span if<var =Argobj/var isnot in< ="">IsMultiplicativeGeneralizedRowVector/> < href".#java.lang.StringIndexOutOfBoundsException: Index 856 out of bounds for length 856
<p>For a list <var class="Arg">list</var>, the value <code class="keyw">true</code> for <code class


<div <span clas="APprompt">gap></span> <span class="GAPinput">NestingDepthA( v );  NestingDepthM( v );</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsMultiplicativeGeneralizedRowVector( liemat )1
false
<span class="GAPprompt">gap></span> <span class="GAPinput">bas:= CanonicalBasis( FullRowSpace( Rationals, 3 )<span class=>></span s =GAPinput"NestingDepthA m ) NestingDepthM;/>
CanonicalBasis( ( Rationals^3 ) )
<span class="GAPprompt">gap></span> <span class="GAPinput">IsMultiplicativeGeneralizedRowVector( java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
true
</pre></div>

<p>

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

<h5>21.12-3 IsListDefault</<span class=GAPprompt>&;</><span <span ="GAPprompt""<span> class=estingDepthA( );  ( l1 </pan>

<div class="func"><table class="func" width="100%"><tr><td class="java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 4
<p>For a list <var class="Arg">list</var>, <code class="func">IsListDefault</code> indicates that the defaultjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

<p> [[ 1, 2],[

<p>All internally represented lists are in this category, and also all lists java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class="example"><pre>
spanclass=>&;</pan java.lang.StringIndexOutOfBoundsException: Range [50, 44) out of bounds for length 101
<span class="GAPprompt">gap></span> <span class="GAPinput">IsListDefault( v );  IsListDefault( m );</span>
true
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsListDefault( bas );  IsListDefault( liemat );</span>
true
false
</pre></div>

<p><a id="X8428E77B86722D52p< ="name"A85ADC85C451DC">/a><p

<h5>21.12-4 NestingDepthA</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&an style='color:green'>#8227; NestingDepthA</code>( <var class="Arg">obj</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
pFor  ""><strongobjectvar""obj<var,<ode "></code>returns  > depth/>of var=Arg><var.Thisisdefinedrecursivelyastheinteger< ="">0/span if<var ="Arg">obj<var>isnotin<code =""IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>), as the integer <span class="SimpleMath">1</span> if <var class="Arg">obj</var> is an empty list in <code class="func">IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>), and as <span class="SimpleMath">1</span> plus the additive nesting depth of the first bound entry in <var class="Arg">obj</var> otherwise.</p>

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

<h5>21.12-5 NestingDepthM</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&an style='color:green'>#8227; NestingDepthM</code>( <var class="Arg">obj</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p>For a <strong class="pkg">GAP</strong> object <var class="Arg">obj</var>, <code class="func">NestingDepthM</code> returns the <em>multiplicative nesting depth</em> of <var class="Arg">obj</var>. This is defined recursively as the integer <span class="SimpleMath">0</span> if <var class="Arg">obj</var> is not in <code class="func">IsMultiplicativeGeneralizedRowVector</code> (<a href="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>), as the integer <span class="SimpleMath">1</span> if <var class="Arg">obj</var> is an empty list in <code class="func">IsMultiplicativeGeneralizedRowVector</code> (<a href="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>), and as <span class="SimpleMath">1</span> plus the multiplicative nesting depth of the first bound entry in <var class="Arg">obj</var> otherwise.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">NestingDepthA( v );  NestingDepthM( v );</span>
1
1
<span class="GAPprompt">gap></span> <span class="GAPinput">NestingDepthA( m );  NestingDepthM( m );</span>
2
2
<span class="GAPprompt">gap></span> <span class="GAPinput">NestingDepthA( liemat );  NestingDepthM( liemat );</span>
2
0
<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">NestingDepthA( l1 );  NestingDepthM( l1 );</span>
2
2
<span class="GAPprompt">gap></span> <span class="GAPinput">NestingDepthA( l2 );  NestingDepthM( l2 );</span>
1
1
</pre></div>

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

<h4>21.13 <span class="Heading">Additive Arithmetic for Lists</span></h4>

<p>In this general context, we define the results of additive operations only in the following situations. For unary operations (zero and additive inverse), the unique argument must be in <code class="func">IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>); for binary operations (addition and subtraction), at least one argument must be in <code class="func">IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>), and the other either is not a list or also in <code class="func">IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>).</p>

<p>(For non-list <strong class="pkg">GAP</strong> objects, defining the results of unary operations is not an issue here, and if at least one argument is a list not in <code class="func">IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>), it shall be left to this argument whether the result in question is defined and what it is.)</p>

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

<h5>21.13-1 <span class="Heading">Zero for lists</span></h5>

<p>The zero (see <code class="func">Zero</code> (<a href="chap31.html#X8040AC7A79FFC442"><span class="RefLink">31.10-3</span></a>)) of a list <span class="SimpleMath">x</span> in <code class="func">IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>) is defined as the list whose entry at position <span class="SimpleMath">i</span> is the zero of <span class="SimpleMath">x[i]</span> if this entry is bound, and is unbound otherwise.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Zero( [ 1, 2, 3 ] );  Zero( [ [ 1, 2 ], 3 ] );  Zero( liemat );</span>
[ 0, 0, 0 ]
[ [ 0, 0 ], 0 ]
LieObject( [ [ 0, 0 ], [ 0, 0 ] ] )
</pre></div>

<p><a id="X7B91CE4D814C2D08java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<h5>21.13-2 <span class="Heading">AdditiveInverse for lists</span></h5>

<p>The additive inverse (see java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class="example"><pre>
span ">gt<span "AdditiveInverse( [1 , ];java.lang.StringIndexOutOfBoundsException: Range [115, 110) out of bounds for length 137
[ -1, -2, -3 ]
[ [ -
</pre></div>

<p><a id="X842D123E7EE5E3DB" <span="&;/>< =">  ,2 , ,4 ] ] );</java.lang.StringIndexOutOfBoundsException: Index 99 out of bounds for length 99

-3<">java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 63

 ="xspan  span""<>    class"<code < ".java.lang.StringIndexOutOfBoundsException: Index 1100 out of bounds for length 1100

<p>If <span class="SimpleMath">x</span> is in <code class="func">IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>) and <span class="SimpleMath">y</span> is in <code class="func">IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>) and has lower additive nesting depth, or is neither a list nor a domain, the sum <span class="SimpleMath">x + y</span> is defined as a list whose entry at position <span class="SimpleMath">i</span> is <span class="SimpleMath">x[i] + y</span> if <span class="SimpleMath">x</span> is bound at position <span class="SimpleMath">i</span>, and is unbound if not. The equivalent holds in the reversed case, where the order of the summands is kept, as addition is not always commutative.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">1 + [ 1, 2, 3 ];  [ 1, 2, 3 ] + [ 0, 2, 4 ];  [ 1, 2 ] + [ Z(2) ];</span>
[ 2, 3, 4 ]
[ 1, 4, 7 ]
[ 0*Z(2), 2 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">l1:= [ 1, , 3, 4 ];;             l2:= [ , 2, 3, 4, 5 ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">l3:= [ [ 1, 2 ], , [ 5, 6 ] ];;  l4:= [ , [ 3, 4 ], [ 5, 6 ] ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">NestingDepthA( l1 );  NestingDepthA( l2 );</span>
1
1
<span class="GAPprompt">gap></span> <span class="GAPinput">NestingDepthA( l3 );  NestingDepthA( l4 );</span>
2
2
<span class="GAPprompt">gap></span> <span class="GAPinput">l1 + l2;</span>
[ 1, 2, 6, 8, 5 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">l1 + l3;</span>
[ [ 2, 2, 3, 4 ],, [ 6, 6, 3, 4 ] ]
<span class="GAPprompt">gap></span> <span class="GAPinput">l2 + l4;</span>
[ , [ 3, 6, 3, 4, 5 ], [ 5, 8, 3, 4, 5 ] ]
<span class="GAPprompt">gap></span> <span class="GAPinput">l3 + l4;</span>
[ [ 1, 2 ], [ 3, 4 ], [ 10, 12 ] ]
<span class="GAPprompt">gap></span> <span class="GAPinput">l1 + [];</span>
[ 1,, 3, 4 ]
</pre></div>

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

<h5>21.13-4 <span class="Heading">Subtraction of lists</span></h5>

<p>For two <strong class="pkg">GAP</strong> objects <span class="SimpleMath">x</span> and <span class="SimpleMath">y</span> of which one is in <code class="func">IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>) and the other is also in <code class="func">IsGeneralizedRowVector</code> (<a href="chap21.html#X87ABCEE9809585A0"><span class="RefLink">21.12-1</span></a>) or is neither a list nor a domain, <span class="SimpleMath">x - y</span> is defined as <span class="SimpleMath">x + (-y)</span>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l1 - l2;</span>
[ 1, -2, 0, 0, -5 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">l1 - l3;</span>
[ [ 0, -2, 3, 4 ],, [ -4, -6, 3, 4 ] ]
spanclass="GAPprompt"gapgt<span < class"GAPinput"l2-l4;/span>
[ , [ -3, -2, 3, 4, 5 ], [ -5, -4, 3, 4, 5 ] ]
<span class="GAPprompt">gap>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 [1, 2] [ -3 -4 ],[0 0] java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
<span class="GAPprompt">gap></span> <span class="GAPinput">l1 - [];</span>
[ 1,, 3, 4 ]
</pre>/div>

<p><a id="X782ED7F27D8C7FC1"

<h4>21.14 <span class="Heading">Multiplicative Arithmetic for Lists<iv "<pre

<p>In this general context, we define the results of multiplicative operations only in[ 2,1 ,[ 3/ /]]

<p>(For non-list <strong"=X84FDB95179BFE4CD>/a>/p>

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

<h5>21.14-1 <span java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>The one (see <code class="func">One</code> (<a   [


<div class="example"><pre>
span =GAPpromptapgt<span><panclassGAPinput>ne   12 , 3,]]<
[ [ 1, 0 ], [ 0, 1 ] ]
<span class="GAPprompt">gap></span> <span class="GAPinput">One( [ [ [ [ 1 ] ], [ [ 2 ] ] ], [ [ [ 3 ] ], [ [ 4 ] ] ] ] );</span>
[ [[[ 1 ] ]      ]       [1 ]]]]
</pre></div>

paid" =>/<p>

<h5>21.14-2 <span class="Heading

<p>The inverse (see <code class="func">Inverse</<><pthescalar  i.a  whose  at  <span class"SimpleMath"i>is< class=SimpleMath>[i  <span> <spanclass=SimpleMath></>     < ""i>and not/


<div class="example"><pre>
<span class="GAPprompt">gap<>   ofsimplerowandjava.lang.StringIndexOutOfBoundsException: Range [84, 83) out of bounds for length 148
[ [ -2, 1 ], [ 3/2, -1/2 ] ]
</pre></div>

<p><a id="<td class=tdcenter"</

<h5>21.14-3 <span class="Heading">Multiplication of lists</span></h5>

<p>There are three possible computations that might be triggered by a multiplication</java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5


<dl>
dtstrong class="()/<dt>
<dd=>L)/>

</dd>
<dt><strong class="Mark">(L)</strong></dt>
<dd><p>the left scalar multiple,<td class="tdcenter">vec/td>

</dd>
<dt><strong class="Mark">(R)</strong></dt>
<dd><p>the right scalar multiple, i.e., a class><java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29

</dd>
</dl>
<p>Our aim is to generalize the basic arithmetic of simple row vectors and matrices, so we first summarize the situations that shall be covered.</p>

<div class="pcenter"><table class="GAPDocTable">
<tr>
<td class="tdcenter"></td>
<td class="tdcenter">scl</td>
<td class="tdcenter">vec</td>
<td class="tdcenter">mat</td>
</tr>
<tr>
<td class="tdcenter">scl</td>
<td class="tdcenter"></td>
<td class="tdcenter">(L<p>  examplethat the product of scalar (scl with  vector (ec)oramatrix (mat)iscomputedaccording to ().Note thatthis  asymmetric.</p>
<td class="tdcenter">(L)</td>
</tr>
<tr>
<td class="tdcenter">vec</td>
<td class="tdcenter">(R)</td>
<td class="tdcenter">(I)</td>
<td class"tdcenter"(I)td>
</tr>
<tr>
<td class="tdcenter">mat</td>
< class=tdcenter">R<td>
<td class="tdcenter">(R)</td>
<td class="tdcenter">(R)</td>
</tr>
<table<br/>
</div>

<p>This means for example that the product of a scalarpexactlyone  has  nesting, the other is treatedas  scalarifit has lowermultiplicative nesting , and as a matrix otherwise. In the former case, we specify result (L) or (R), depending on ordering; in the latter case, we specify result (L) or (I), depending on ordering.</p>

<p>Now we can state the general multiplication rules.</p>

<p>If exactly one argument is in <code class="func">IsMultiplicativeGeneralizedRowVector</code> (<a href="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>) then we regard the other argument (which is then neither a list nor a domain) as a scalar, and specify result (L) or (R), depending on ordering.</p>

<p>In the remaining cases, both <span class="SimpleMath">x</span> and <span class="SimpleMath">y</span> are in <code class="func">IsMultiplicativeGeneralizedRowVector</code> (<a href="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>), and we distinguish the possibilities by their multiplicative nesting depths. An argument with <em>odd</em> multiplicative nesting depth is regarded as a vector, and an argument with <em>even</em> multiplicative nesting depth is regarded as a scalar or a matrix.</p>

<p>So if both <span class="GAPprompt>/><java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 123

<p>If exactly one argument has odd nesting depth, the other is treated as a scalar if it has lower multiplicative nesting depth, and as a matrix otherwise. In the former case, we specify result (L) or (R), depending on ordering; in the latter case, we specify result (L) or (I), depending on ordering.</p>

<p>We are left with the case that each argument has even multiplicative nesting depth. If < class">></span> < ""[,2    3, ]<spanjava.lang.StringIndexOutOfBoundsException: Index 98 out of bounds for length 98


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">[ (), (2,3), (1,2), (1,2,3), [ [7,8 ]   3,6]   
[ (1,4), (1,4)(2,3), (1,2,4), (1,2,3,4), (1,3,2,4) (1,,4 java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
span ="GAPprompt>&<span>sclass"> ,2] ;/>
[ 2, 4,, 8 ]
<span java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 2
22
<span class="GAPprompt">gap></span> <span class="GAPinput">m:= [ [ 1, 2 ], 3 ];;  m * m;</java.lang.StringIndexOutOfBoundsException: Range [0, 97) out of bounds for length 42
    ,[ ,6 ,9]java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
< ""gap&/> s =GAPinput>*  = [m]*m [2]*m];<span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">n:=
14
<span class="GAPprompt">gap>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
true
</pre></div>

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

<h5>21.14-4 <span class="Heading">Division of lists</span></h5>

<p>For two <strong class="pkg">GAP</strong> objects <span class="SimpleMath">x</span> and <span class="SimpleMath">y</span> of which one is in <code class="func">IsMultiplicativeGeneralizedRowVector</code> (<a href="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>) and the other is also in <code class="func">IsMultiplicativeGeneralizedRowVector</code> (<a href="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>) or is neither a list nor a domain, <span class="SimpleMath">x / y</span> is defined as <span class="SimpleMath">x * y^{-1}</span>.</p>


d class=example>pre
<span [ 1,, 3, 4
[1/ 1 3/2]<pre></java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
[ 1, 0 ]
</pre></div>

p< =namejava.lang.StringIndexOutOfBoundsException: Range [55, 52) out of bounds for length 62

<h5>21.14-5 <span class="Heading">mod for lists</span></h5>

<p>If <var class="Arg">x</var> and <var class="Arg">y</var> are in <code class="func">IsMultiplicativeGeneralizedRowVector</code> (<a href="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>) and have the same multiplicative nesting depth (see <code class="func">NestingDepthM</code> (<a href="chap21.html#X84B383B97FD986CD"><span class="RefLink">21.12-5</span></a>)), <code class="code"><var class="Arg">x</var> mod <var class="Arg">y</var></code> is defined <em>pointwise</em>, in the sense that the result is a list whose entry at position <span class="SimpleMath">i</span> is <code class="code"><var class="Arg">x</var>[i] mod <var class="Arg">y</var>[i]</code> if these entries are bound, is a shallow copy (see <code class="func">ShallowCopy</code> (<a href="chap12.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>)) of <span class="SimpleMath">x[i]</span> or <span class="SimpleMath">y[i]</span> if the other argument is not bound at position <span class="SimpleMath">i</span>, and is unbound if both <span class="SimpleMath">x</span> and <span class="SimpleMath">y</span> are unbound at position <span class="SimpleMath">i</span>.</p>

<p>If <span class="SimpleMath">x</span> is in <code class="func">IsMultiplicativeGeneralizedRowVector</code> (<a href="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>) and <span class="SimpleMath">y</span> is in <code class="func">IsMultiplicativeGeneralizedRowVector</code> (<a href="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>) and has lower multiplicative nesting depth or is neither a list nor a domain, <code class="code"><var class="Arg">x</var> mod <var class="Arg">y</var></code> is defined as a list whose entry at position <span class="SimpleMath">i</span> is <code class="code"><var class="Arg">x</var>[i] mod <var class="Arg">y</var></code> if <var class="Arg">x</var> is bound at position <span class="SimpleMath">i</span>, and is unbound if not. The equivalent holds in the reversed case, where the order of the arguments is kept.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">4711 mod [ 2, 3,, 5, 7 ];</span>
[ 1, 1,, 1, 0 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">[ 2, 3, 4, 5, 6 ] mod 3;</span>
[ 2, 0, 1, 2, 0 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">[ 10, 12, 14, 16 ] mod [ 3, 5, 7 ];</span>
[ 1, 2java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
</pre></div>

<p><aclass=GAPprompt"gap;/< ""l1 -</pan>

<h5>21.14-6 <span class="Heading">span class="GAPprompt">gap></span""l1-l3<

<p classgt;/> <spanclass""l3- l4;


<div class="example"><>
spanclass=GAPprompt"gapgt< span ="" [  ,2] [ ,4 ], [ , ] )/span>
[ 0, 1/2 ]
</pre></div>

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

<h4>21.15 <span class="Heading">Mutability Status and List Arithmetic</span></h4>

<p>Many results of arithmetic operations, when applied to lists, are java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>However, we do <em>not</em> define exactly the mutability status for each java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0

<p>Thus a fully mutable matrix has immutability level <span class="SimpleMath">0</span>, and a mutable matrix

<p>The immutability level of<5>.-< class="eading"One lists/span><h5>

<p>Moreover, the<>Theone(  =""One<code <ahref".

<p>Thus the sum of two mutable matrices whose first rows are mutable is a matrix all of whose rows are mutable, and the product of two matrices whose first rows are immutable is a matrix all of whose rows are immutable, independent of the mutability status of the other rows of the arguments.</p>

<p>For example<class=GAPprompt">>/ <span "">([  ,2 ],[3  ]])<java.lang.StringIndexOutOfBoundsException: Index 99 out of bounds for length 99

<[[ ]],[ 0  ] [[  ,[ [1 ] ] ]


<div class="p>< =" name="java.lang.StringIndexOutOfBoundsException: Range [55, 52) out of bounds for length 62
<span class="GAPprompt">gap></span> <span class="GAPinput">IsMutable( l1 );  IsMutable( 2 * Immutable">gap></span> <spanclass"GAPinput">sMutable(  );IsMutable(2* ( ,,3 );<span>
true
false
<span class="GAPprompt">gap&t;<span> <span class="GAPinput">IsMutable( l2 );  IsMutable( l3 );</span>
true
true
<span class=GAPprompt"gap><span> class="GAPinput">java.lang.StringIndexOutOfBoundsException: Range [70, 69) out of bounds for length 103

>example motivating the mutability rule is theofsyntactic    =code>varclass=Arg><var>< class=Arg>list/var></code> and < class=code"- varclass=Arg></>/>asanelegant  way  mutable   for manipulations   lists In  onecanconstruct   zerovector  < class"=SimpleMath><span>< class=code>]/>  latter  be  also using codeclass=func"ListWithIdenticalEntries</code (a =chap21.#X80FDB1457FF582E7"><span class="RefLink">21.15-1</span></a>).</p>

<p><a id="X80FDB1457FF582E7"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<h5>21.15-1 ListWithIdenticalEntries</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleftjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<p>is a list <var class="Arg">list</var> of length <var class="Arg">n</var> thatjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class=example"<java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
<span class="GAPprompt">gap></span> <span class="GAPinput">ListWithIdenticalEntries( 10, 0 );</span>
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
</pre></div>

<p><a<><pthe  S"x1 * y[1]+ [2] * [2 +  + [n  []/,where summands are omitted  theentry in<class=SimpleMath"x<span>  < class"impleMath"y/span   if this leaves no summandthen the multiplication is an error), or</p>

<h4>21.16 <span class="Heading">Finding Positions in Lists</span></h4>

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

<h5>21.16

<div class="func"><t<strong class=Mark">(L)</</dt
p> theposition  thefirst  varclass""obj/> < class"">list/,or="">fail<code  var class=Arg"obj/>is  containedin<var ="><var>   index<ar class=Arg><var>is ,itreturns theposition of thefirst starting thesearch <>/>position v =""from/var><p>

<p>Each call<dd>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Position( [ 2, 2, 1, 3 ], 1 );</span>
3
<span class="GAPprompt">gap></span> <span class="GAPinput">Position( [ 2, 1, 1, 3 ], 1
2
<span class="GAPprompt">gap></span> <span class="GAPinput">Position( [ 2, 1, 1, 3 ], 1, 2 );</<p>Our aim is to generalize the basic arithmetic of simple row vectors and matrices, so we first summa be<p
3
<span class="GAPprompt">gap></span> <span class="GAPinput">Position( [ 2, 1, 1, 3 ], 1, 3 );</span>
fail
<pre>/>

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

nsh5

< class=java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 29
<p>returns the set of <d=tdcenter></d>

<p>Developers who wish to adapt this for custom list types need to install suitable methods for the operation <code class="code">PositionsOp</code>.</p>


<div class="example"><pre>
<spantdclass=tdcenter">R)</td>
[ 2, 4, 6, 7 ]
<span class="</div>
[  ]
</pre></div>

<p< "X7B4B10AE81602D4E" name""<a<p>

<h5>21.16-3 PositionCanonical</h5>

<div class="func"pIfexactly one is  codeclass=func><code < ="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>) then we regard the other argument (which is then neither a list nor a domain) as a scalar, and specify result (L) or (R), depending on ordering.</p>
<p>returns <>  cases  spanclass="SimpleMath>/ and spanclass"impleMath"y/span>   codeclass""<code>(a href=".#>class"">.-<>/>),wedistinguishthe by java.lang.StringIndexOutOfBoundsException: Range [319, 318) out of bounds for length 523

<p>For example <code class="func">RightTransversal</code> 


<div class=pIfexactly   has  nesting depth,theother     scalar  it lower     a matrix.In   ,  specify result L  (R) depending  ;in  latter,we specify ()  I, ordering<p>
<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
"GAPprompt>gap&;<span <pan class=GAPinput>rt:R(,);AsList(t)/pan
[ (), (3,4), (2,3), (2,3,4), (2,4,3), (2,4) ]
<span class<panclass=GAPprompt>&;/ < class=GAPinput"[(, (23, (1,) 123,(,,2 1,)  *(,4)<span>
fail
< ="GAPprompt">ap&;/><pan class=GAPinput">PositionCanonical(t,1);/span>
2
</pre></div>

<" name"java.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 62

<>21.16- </>

<div <span class"GAPprompt"gapgt;/span> spanclass"">m*   [ [1] *, m[2] * m ]<span>
<p>returns the position of thetrue


<div class="example"><pre>
<span <span class"">&;/>< =GAPinput>*n=n1*[  n[] [];span>
1
<spanclass"">gap&t;/span> <span class="GAPinput">PositionNthOccurrence([1,2,3,2,4,2,1],1,2);</span>
7
<span class="GAPprompt">gap></span> <span class="<521144<span=""Division of <span>/h5java.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
6
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionNthOccurrence
fail
<pre<div>

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

<h5>21.16-5 PositionSorted>a =X7A0FD70C80B95C00 =java.lang.StringIndexOutOfBoundsException: Range [56, 52) out of bounds for length 62

<div=func>table =func "%>tr< ">code ""&#8227; PositionSorted</code>( <var class="Arg">list</var>, <var class="Arg">elm</var>[, <var class="Arg">func</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>Called with two<>< =SimpleMath"x/>isin< class=func></>(ahref"chap21html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>) and <span class="SimpleMath">y</span> is in <code class="func">IsMultiplicativeGeneralizedRowVector</code> (<a href="chap21.html#X7FBCA5B58308C158"><span class="RefLink">21.12-2</span></a>) and has lower multiplicative nesting depth or is neither a list nor a domain, <code class="code"><var class="Arg">x</var> mod <var class="Arg">y</var></code> is defined as a list whose entry at position <span class="SimpleMath">i</span> is <code class="code"><var class="Arg">x</var>[i] mod <var class="Arg">y</var></code> if <var class="Arg">x</var> is bound at position <span class="SimpleMath">i</span>, and is unbound if not. The equivalent holds in the reversed case, where the order of the arguments is kept.</p>

[2, 0 1, 2 0 ]

<>><span <span class=GAPinput>[10 12, 14, 16] [3,5, 7 ];<span>

<p><code class="func">PositionSorted<pre>/divjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12

p whowish toadapt forcustom list  need toinstall suitable methods for the operation <code class="code">PositionSortedOp</code>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span classjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
1
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSorted( [1,4,5,5,6,7], 2 );</span>
2
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSorted( [1,4,5,5,6,7], 4 );</span>
2
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSorted( [1,4,5,5,6,7], 5 );</span>
3
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSorted( [1,4,5,5,6,7], 8 );</span>
7
</pre></div>

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

<>21.16-PositionSortedBy</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&an style='color:green'>#8227; PositionSortedBy</code>( <var class="Arg">list</var>, <var class="Arg">val</var>, <var class="Arg">func</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function returns the same value that would be returned by <code class="code">PositionSorted(List(java.lang.StringIndexOutOfBoundsException: Index 108 out of bounds for length 1

<p>To be more precise, <var class="Arg">func</var> must be a function on one argument which returns values that can be compared java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<-PositionProperty<>

<p><code class<divclass=func"<table class"width"100"><><d class=""< "">&8227 <code var class="Arg">list</var>, <var class="Arg">func</var>[, <var class="Arg">from/])/td<td =tdright>&bsp;peration&;<>tr></table/div>

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSortedByjava.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
1
<span class="GAPprompt< class="GAPprompt>gt<span span=GAPinput>n-gt IsPrimen  ();/span
1
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSortedBy( [ "", "ab", ], 1, Length );</span>
2
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSortedBy( [ "", "ab", ], 2, Length );</span>
2
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSortedBy( [ "", "ab", ], 3, Length );</span>
3
</pre></div>

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

<h5>21.16-7 PositionSet</h5>

divclassfunc>table class="unc "100%>tr< class=tdleft>code class=func"&8227;PositionSet<code(<ar ""list/, varclass="rg"obj<var>, var "></ )/td>td class=tdright"(nbsp;function&bsp;)/>/>/table<div>
<p><code class="func">PositionSet</code> is a slight variation of <code classjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSet<h5>21.610PositionsProperty/>
fail
<span class="GAPprompt">gap></<div class=func"< class"" width=100"<r< ""<ode class="java.lang.StringIndexOutOfBoundsException: Range [92, 91) out of bounds for length 257
fail
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSet( [1,4,5,5,6,7], 4 );</span>
2
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSet( [1,4,5,5,6,7], 5 );</span>
3
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionSet( [1,4,5,5,6,7], 8 );</span>
fail
</pre></div>

<p><a id="X7FD9C1D37F300206java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<java.lang.StringIndexOutOfBoundsException: Range [0, 3) out of bounds for length 1

<div
<div class="func"><table class="span="gap;/ span ">  2 ,1,3] 1,3 ;</span>
<p>returns the position of maximum (with <code class="func">PositionMaximum</code>) or minimumjava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4


<div java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span class="GAPprompt">gap></span>
2
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionMaximum( [2,4,-6,2,4], x -> -x);</span>
3
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionMinimum( [2,4,-6,2,4] );</span>
3
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionMinimum( [2,4,-6,2,4], x -&java.lang.StringIndexOutOfBoundsException: Index 99 out of bounds for length 0
<iv class="xample"><>
</pre></div>

><code class=func"Maximum/code (< href=chap21.htmlX82CE0DE8828E4303"><span class="RefLink">21.20-12</span></a>) and <code class="func">Minimum</code> (<a href="chap21.html#X82F133EC7F89665F"><span class="RefLink">21.20-13</span></a>) allow you to find the maximum or minimum element of a list directly.</p>

[ 2 4,6,7 ]

<h5>21.16-9 PositionProperty</h5>

<div class="func"><table<pre></div>
<p>returns the position of the first entry in the list <>< ""name=java.lang.StringIndexOutOfBoundsException: Range [72, 37) out of bounds for length 256


<div class="example"><pre>
<span class="GAPprompt">gap></p> example < class="">ightTransversal</> <a ="chap39.html#X85C65D06822E716F"><span class="RefLink">39.8-1</span></a>) defines the canonical associate to be the element in the transversal defining the same coset of a subgroup in a group.</p>
20
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionProperty( [10^5..10^6],</span>
<span class="GAPprompt">><<><code class"func>PositionSorted</> uses ,whereas< =func"Position/>(< href"chap21.html#X79975EC6783B4293"><span class="RefLink">21.16-1</span></a>) can in general use only linear search, see the remark at the beginning of <a href="chap21.html#X80ABC25582343910"><span class="RefLink">21.19</span></a>. For sorting lists, see <a href="chap21.html#X83E558E37D1B44D4"><span class="RefLink">21.18</span></a>, for testing whether a list is sorted, see <code class="func">IsSortedList</code> (<a href="chap21.html#X7BAA9B0E81D4A884"><span class="RefLink">21.17-3</span></a>) and <code class="func">IsSSortedList</code> (<a href="chap21.html#X80CDAF45782E8DCB"><span class="RefLink">21.17-4</span></a>).</p>

</pre></div>

<p><code class="func">First</code> (<a href="chap21.html#X82801DFA84E11272"><span class="RefLink">21.20-21</span></a>) allows you to extract the first element of a list that satisfies a certain property.</p>

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

<h5>21.16-10 PositionsProperty</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&an style='color:green'>#8227; PositionsProperty</code>( <var class="Arg">list</var>, <var class="Arg">func</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<returns the set of all the list <ar =""list/>whichare  and for which the property tester function < class=Arg>unc/var>returns<code class=keyw"true</code>./p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l:= [ -5 .. 5 ];;</span>
span class="APprompt>></>< ="APinput>( ,IsPosInt)<spanjava.lang.StringIndexOutOfBoundsException: Index 102 out of bounds for length 102
[ 7, 8, 9, 10, 11 ]
<span class="java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 1
[ 1, 3, 4, 8, 9, 11 ]
<pre<java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12

<

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

<h5>21.16-11 PositionBound</h5>

<div class="func"><table classjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<p>returns the first bound position of the list <var class="Arg">list</var>. For


<div class="example"><pre>
span>&;/>s Gjava.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 92
1
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionBound([,1,2,3]);<< class="example"><pre>
2
</pre

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

21-java.lang.StringIndexOutOfBoundsException: Range [29, 27) out of bounds for length 32

=> =func ="%t>class">codeclass"">#8227; PositionsBound</code>( <var class="Arg">list</var> )</td><td class="tdright">( function )</td></tr></table></div>
  of  boundinthelist vclass""list</var><pjava.lang.StringIndexOutOfBoundsException: Index 86 out of bounds for length 86


<div class="example"><pre>
<span class="GAPprompt">
[ 1 .. 3 ]
< class="APprompt"gapgt<>s =GAPinput>([1,3];<spanjava.lang.StringIndexOutOfBoundsException: Index 93 out of bounds for length 93
[ 2, 4 ]
<span class="GAPprompt"<h5>1168PositionMaximum/>
[]
</pre></div>

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

<>21.16-13 PositionNot</h5>

<>returnstheof with codeclass""<code>  ( <odeclassfunc>PositionMinimum/)entry  listvarclass"Arg>list<var> Ifasecond <var class=Arg><var>is passed,then  instead  positionofthe /mallest entry in <code class="code">List( <var class="Arg">list</var> , <var class="Arg"> in <code class="code">List( <var class="Arg">list</var> , <var class="Arg">func<code>  several  of  listare equal  the maximum/java.lang.StringIndexOutOfBoundsException: Range [26, 473) out of bounds for length 26
pForalistvar""list/>andan varclass"">val<var,< ""PositionNot/>returns thesmallest nonnegativeinteger sclass"impleMath"n<span>such that span class=SimpleMath"< =Arg><var>n<span   unbound or not equal <arclass=Arg"val/var>  astartingindexv ="rg><var  given, it  the first  with propertystarting search<><em> position< class""f/>./>


<div class="example"><pre>
<span class="GAPprompt"><pre</ivjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
3
spanclass=GAPprompt">>/span> span class="APinput"PositionNot(
5
6


java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<h5>21.16-14 PositionNonZero</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&an style='color:green'>#8227; PositionNonZero</code>( <var class="Arg">vec</var>[, <var class="Arg">from</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<p>Fordivclass="p>

<p>If a starting index <var class<>2116 PositionsProperty/>

<p><code class="func">PositionNonZero</code> implements a special case of <code class="func">PositionNot</code> (<a href="chap21.html#X865EF45D87ED1384"><span class="RefLink">21.16-13</span<5>211615PositionSublist</h5>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">PositionNonZero( [ 1, 1, 2, 3, 2 ] );</span>
1
<java.lang.StringIndexOutOfBoundsException: Range [0, 5) out of bounds for length 0
2
</pre></div>

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

<h5>21.16-15 PositionSublist</h5>

<">sub</var>[, <var class="Arg">from</var>] )/<d class="dright>&o&;)/d>/r<table><div
<p>returns the smallest index in the list <var class="Arg">list</var> at which a sublist equal to <var class="Arg">sub</var> starts. If <var class="Arg">sub</

<p>To determine whether <var class="Arg">sub</var> matches <var class="Arg">list</var> at a particular position, use <code class="func">IsMatchingSublist</code> (<a href="chap21.html#X83F8EC7C7BF27EFC"><span class="RefLink">21.17-1</span></a>) instead.java.lang.StringIndexOutOfBoundsException: Index 252 out of bounds for length 32

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

<h4>21.17 <span class="Heading">Properties and Attributes for Lists</span></h4>

pAjava.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 313


<div class="example"><pre>
<span <p>A listis <em>duplicate free<em>  itisdenseand not  equal in  positions.Everydomain(ee<a href="chap12h#X7BAF69417BB925F6< =RefLink>12.4<s>/>)  duplicatefree</java.lang.StringIndexOutOfBoundsException: Index 230 out of bounds for length 230
[ [ 1 ], [ 2 ] ]
<span class="GAPprompt">gap></span> <span class="GAPinput">IsSSortedList(l);</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">l[1][1]:=3;</span>
3
<span class="GAPprompt">gap></span> <span class="GAPinput">IsSSortedList(l);</span>
false
</pre></div>

<p>For such lists these property values must be computed anew each time the property is asked for. For example, if <var class="Arg">list</var> is a list of mutable row vectors then the call of <code class="func">Position</code> (<a href="chap21.html#X79975EC6783B4293"><span class="RefLink">21.16-1</span></a>) with <var class="java.lang.StringIndexOutOfBoundsException: Index 329 out of bounds for length 150

<p><a id="X83F8EC7C7BF27EFCclass="RefLink">31.11</span></a>).</p>

<h5>21.17-1 IsMatchingSublist</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; IsMatchingSublist</code>( <var class="Arg">list</var>, <var class="Arg">sub</var>[, <var class="Arg">at</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<p>returns <code class="keyw">true</code> if <var class="Arg">sub</var> matches a sublist of <var class="Arg">list</var> from position <code class="code">1</code> (or position <var class="Arg">at</var>, in the case of three arguments), or <code class="keyw">false</code>, otherwise. If <var class="Arg">sub</var> is empty <code class="keyw">true</code> is returned. If <var class="Arg">list</var> is empty but <var class="Arg">sub</var> is non-empty <code class="keyw">false</code> is returned.</p>

<p>If you actually want to know whether there is an <var class="Arg">at</var> for which <code class="code">IsMatchingSublist( <var class="Arg">list</var>, <var class="Arg">sub</var>, <var class="Arg">at</var> )</code> is true, use a construction like <code class="code">PositionSublist( <var class="Arg">list</var>, <var class="Arg">sub</var> ) <> fail</code> instead (see <code class="func">PositionSublist</code> (<a href="chap21.html#X87A8C62A867D6DA4"><span class="RefLink">21.16-15</span></a>)); it's more efficient.</p>

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

<h5>21.17-2 IsDuplicateFree</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; IsDuplicateFree</code>( <var class="Arg">obj</var> )</td><td class="tdright">( property )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; IsDuplicateFreeList</code>( <var class="Arg">obj</var> )</td><td class="tdright">( filter )</td></tr></table></div>
<p><code class="func">IsDuplicateFree</code> returns <code class="keyw">true</code> if <var class="Arg">obj</var> is both a list or collection, and it is duplicate free; otherwise it returns <code class="keyw">false</code>. <code class="func">IsDuplicateFreeList</code> is a synonym for <code class="code">IsDuplicateFree and IsList</code>.</p>

<p>A list is <em>duplicate free</em> if it is dense and does not contain equal entries in different positions. Every domain (see <a href="chap12.html#X7BAF69417BB925F6"><span class="RefLink">12.4</span></a>) is duplicate free.</p>

<p>Note that <strong class="pkg">GAP</strong> cannot compare arbitrary objects (by equality). This can cause that <code class="func">IsDuplicateFree</code> runs into an error, if <var class="Arg">obj</var> is a list with some non-comparable entries.</p>

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

<h5>21.17-3 IsSortedList</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; IsSortedList</code>( <var class="Arg">obj</var> )</td><td class="tdright">( property )</td></tr></table></div>
<p>returns <code class="keyw">true</code> if <var class="Arg">obj</var> is a list and it is sorted, and <code class="keyw">false</code> otherwise.</p>

<p>A list <var class="Arg">list</var> is <em>sorted</em> if it is dense (see <code class="func">IsDenseList</code> (<a href="chap21.html#X870AA9D8798C93DD"><span class="RefLink">21.1-2</span></a>)) and satisfies the relation <span class="SimpleMath"><var class="Arg">list</var>[i] ≤ <var class="Arg">list</var>[j]</span> whenever <span class="SimpleMath">i < j</span>. Note that a sorted list is not necessarily duplicate free (see <code class="func">IsDuplicateFree</code> (<a href="chap21.html#X7FA892828252BB3B"><span class="RefLink">21.17-2</span></a>) and <code class="func">IsSSortedList</code> (<a href="chap21.html#X80CDAF45782E8DCB"><span class="RefLink">21.17-4</span></a>)).</p>

<p>Many sorted lists are in fact homogeneous (see <code class="func">IsHomogeneousList</code> (<a href="chap21.html#X7C71596C82B6EF35"><span class="RefLink">21.1-3</span></a>)), but also non-homogeneous lists may be sorted (see <a href="chap31.html#X7B3BC7BA7BB2646D"><span class="RefLink">31.11</span></a>).</p>

<p>In sorted lists, membership test and computing of positions can be done by binary search, see <a href="chap21.html#X80ABC25582343910"><span class="RefLink">21.19</span></a>.</p>

<p>Note that <strong class="pkg">GAP</strong> cannot compare (by less than) arbitrary objects. This can cause that <code class="func">IsSortedList</code> runs into an error, if <var class="Arg">obj</var> is a list with some non-comparable entries.</p>

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

<h5>21.17-4 IsSSortedList</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; IsSSortedList</code>( <var class="Arg">obj</var> )</td><td class="tdright">( property )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; IsSet</code>( <var class="Arg">obj</var> )</td><td class="tdright">( property )</td></tr></table></div>
<p>returns <code class="keyw">true</code> if <var class="Arg">obj</var> is a list and it is strictly sorted, and <code class="keyw">false</code> otherwise. <code class="func">IsSSortedList</code> is short for <q>is strictly sorted list</q>; <code class="func">IsSet</code> is just a synonym for <code class="func">IsSSortedList</code>.</p>

<p>A list <var class="Arg">list</var> is <em>strictly sorted</em> if it is sorted (see <code class="func">IsSortedList</code> (<a href="chap21.html#X7BAA9B0E81D4A884"><span class="RefLink">21.17-3</span></a>)) and satisfies the relation <span class="SimpleMath"><var class="Arg">list</var>[i] < <var class="Arg">list</var>[j]</span> whenever <span class="SimpleMath">i < j</span>. In particular, such lists are duplicate free (see <code class="func">IsDuplicateFree</code> (<a href="chap21.html#X7FA892828252BB3B"><span class="RefLink">21.17-2</span></a>)).</p>

<p>(Currently there is little special treatment of lists that are sorted but not strictly sorted. In particular, internally represented lists will <em>not</em> store that they 

<p>Note that <strong class="pkg">GAP</strong> cannot compare (by less than) arbitrary objects. This can cause that <code class="func">IsSSortedList</code> runs into an error, if <var class="Arg">obj</var> is a list with some non-comparable entries.</p>

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

<h5>21.17-5 Length</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; Length</code>( <var class="Arg">list</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p>returns the <em>length</em> of the list <var class="Arg">list</var>, which is defined to be the index of the last bound entry in <var class="Arg">list</var>.</p>

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

<5>21.76 ConstantTimeAccessList<h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; ConstantTimeAccessList</code>( <var class="Arg">list</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p><code class="func">ConstantTimeAccessList</code> returns an immutable list containing the same elements as the list <var class="Arg">list</var> (which may have holes) in the same order. If <var class="Arg">list</var> is already a constant time access list, <code class="func">ConstantTimeAccessList</code> returns an immutable copy of <var class="Arg">list</var> directly. Otherwise it puts all elements and holes of <var class="Arg">list</var> into a new list and makes that list immutable.</p>

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

<h4>21.18 <span class="Heading">Sorting Lists</span></h4>

<p>GAP implements three different families of sorting algorithms. The default algorithm is pattern-defeating quicksort, a variant of quicksort which performs better on partially sorted lists and has good worst-case behaviour. The functions which begin <code class="code">Stable</code> are stable (equal elements keep the same relative order in the sorted list) and use merge java.lang.StringIndexOutOfBoundsException: Index 378 out of bounds for length 356

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

<h5>21.18-1 Sort</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; Sort</code>( <var class="Arg">list</var>[, <var class="Arg">func</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; java.lang.StringIndexOutOfBoundsException: Index 106 out of bounds for length 0
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; StableSort</code>( <var class="Arg">list</var>[, <var class="Arg">func</var>] )</td><td class="tdright">( java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; StableSortBy</code>( <var class="Arg">list</var>[, <var class="Arg">func</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<p><code class="func">Sort</code> sorts the list <var class="Arg">list</var> in increasing order. In the one argument form <code class="func">Sort</code> uses the operator <code class="code"><</code> to compare the elements. (If the list is not homogeneous it is the user's responsibility to ensure that <code class="code"><</code> is defined for all element pairs, see <a href="chap31.html#X7B3BC7BA7BB2646D"><span class="RefLink">31.11</span></a>) In the two argument form <code class="func">Sort</code> uses the function <var class="Arg">func</var> to compare elements. <var class="Arg">func</var> must be a function taking two arguments that returns <code class="keyw">true</code> if the first is regarded as strictly smaller than the second, and <code class="keyw">false</code> otherwise.</p>

<p><code class="func">StableSort</code> behaves identically to <code class="func">Sort</code>, except that <code class="func">StableSort</code> will keep elements which compare equal in the same relative order, while <code class="func">Sort</code> may change their relative order.</p>

<p><code class="func">Sort</code> does not return anything, it just  class="GAPprompt">gap></span> <span class="GAPinput">IsSSortedList

<p><code class="func">SortBy</code> sorts the list <var class="Arg">list</var> into an order such that <code class=java.lang.StringIndexOutOfBoundsException: Index 115 out of bounds for length 1

<p><code class="func">StableSortBy</code> behaves java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 12


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">list := [ 5, 4, 6, 1, 7, 5 ];; Sort( list ); list;</span>
[ 1, 4, 5, 5, 6, 7 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">SortBy(list, x -> x mod 3);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput<>Forsuch lists these property values must be computed anew each time the property is asked for. For example, if <var class="Arg">list</var> is a list of mutable row vectors then the call of <code class="func">Position</code> (<a href="chap21.html#X79975EC6783B4293"><span class="RefLink">21.16-1</span></a>) with <var class="Arg">list</var> as first argument cannot take advantage of the fact that <var class="Arg">list</var> is in fact sorted. One solution is to call explicitly <code class="func">PositionSorted</code> (<a href="chap21.html#X7A122E848464E534"><span class="RefLink">21.16-5</span></a>) in such a situation, another solution is to replace <var class="Arg">list</var> by an immutable copy using <code class="func">Immutable</code> (<a href="chap12.html#X7F0ABF2C870B0CBB"><span class="RefLink">12.6-3</span></a>).</p>
[ 6, 1, 4, 7, 5, 5]
<span class="GAPprompt">gap></span> <span class="GAPinput">list := [ [0,6], [1,2], [1,3], [1,5], [0,4], [3,4] ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Sort( list, function(v,w) return v*v < w*w; end );</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">list;  # sorted according to the Euclidean distance from [0,0]</span>
[ [ 1, 2 ], [ 1, 3 ], [ 0, 4 ], [ 3, 4 ], [ 1, 5 ], [ 0, 6 ] ]
<span class="GAPprompt">gap></span> <span class="GAPinput">SortBy( list, function(v) return v[1] + v[2]; end );</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">list;  # sorted according to Manhattan distance from [0,0]</span>
[ [ 1, 2 ], [ 1, 3 ], [ 0, 4 ], [ 1, 5 ], [ 0, 6 ], [ 3, 4 ] ]
<span class="GAPprompt">gap></span> <span class="GAPinput">list := [ [0,6], [1,3], [3,4], [1,5], [1,2], [0,4], ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Sort( list, function(v,w) return v[1] < w[1]; end );</span>
<span class="GAPprompt">gap></span> <span class="GAPinput"># note the random order of the elements with equal first component:</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">list;</span>
[ [ 0, 6 ], [ 0, 4 ], [ 1, 3 ], [ 1, 5 ], [ 1, 2 ], [ 3, 4 ] ]
</pre></div>

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

<h5>21.18-2 SortParallel</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; SortParallel</code>( <var class="Arg">list1</var>, <var class="Arg">list2</var>[, <var class="Arg">func</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; StableSortParallel</code>( <var class="Arg">list1</var>, <var class="Arg">list2</var>[, <var class="Arg">func</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<p><code class="func">SortParallel</code> sorts the list <var class="Arg">list1</var> in increasing order just as <code class="func">Sort</code> (<a href="chap21.html#X7FE4975F8166884D"><span class="RefLink">21.18-1</span></a>) does. In parallel it applies the same exchanges that are necessary to sort <var class="Arg">list1</var> to the list <var class="Arg">list2</var>, which must of course have at least as many elements as <var class="Arg">list1</var> does.</p>

<p><code class="func">StableSortParallel</code> behaves identically to <code class="func">SortParallel</code>, except it keeps elements in <var class="Arg">list1</var> which compare equal in the same relative order.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">list1 := [ 5, 4, 6, 1, 7, 5 ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">list2 := [ 2, 3, 5, 7, 8, 9 ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">SortParallel( list1, list2 );</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">list1;</span>
[ 1, 4, 5, 5, 6, 7 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">list2;</span>
[ 7, 3, 2, 9, 5, 8 ]
</pre></div>

<p>Note that <code class="code">[ 7, 3, 2, 9, 5, 8 ]</code> or <code class="code">[ 7, 3, 9, 2, 5, 8 ]</code> are possible results. <code class="func">StableSortParallel</code> will always return <code class="code">[ 7, 3, 2, 9, 5, 8]</code>.</p>

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

<h5>21.18-3 Sortex</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; Sortex</code>( <var class="Arg">list</var>[, <var class="Arg">func</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<p>sorts the list <var class="Arg">list</var> and returns a permutation that can be applied to <var class="Arg">list</var> to obtain the sorted list. The one argument form sorts via the operator <code class="code"><</code>, the two argument form sorts w.r.t. the function <var class="Arg">func</var>. The permutation returned by <code class="func">Sortex</code> will keep elements which compare equal in the same relative order. (If the list is not homogeneous it is the user's responsibility to ensure that <code class="code"><</code> is defined for all element pairs, see <a href="chap31.html#X7B3BC7BA7BB2646D"><span class="RefLink">31.11</span></a>)</p>

<p><code class="func">Permuted</code> (<a href="chap21.html#X7B5A19098406347A"><span class="RefLink">21.20-17</span></a>) allows you to rearrange a list according to a given permutation.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">list1 := [ 5, 4, 6, 1, 7, 5 ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">list2 := ShallowCopy( list1 );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">perm := Sortex( list1 );</span>
(1,3,5,6,4)
<span class="GAPprompt">gap></span> <span class="GAPinput">list1;</span>
[ 1, 4, 5, 5, 6, 7 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">Permuted( list2, perm );</span>
[ 1, 4, 5, 5, 6, 7 ]
</pre></div>

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

<h5>21.18-4 SortingPerm</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; SortingPerm</code>( <var class="Arg">list</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p><code class="func">SortingPerm</code> returns the same as <code class="func">Sortex</code> (<a href="chap21.html#X87287FCA81E2B06A"><span class="RefLink">21.18-3</span></a>) but does <em>not</em> change the argument.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">list1 := [ 5, 4, 6, 1, 7, 5 ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">list2 := ShallowCopy( list1 );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">perm := SortingPerm( list1 );</span>
(1,3,5,6,4)
<span class="GAPprompt">gap></span> <span class="GAPinput">list1;</span>
[ 5, 4, 6, 1, 7, 5 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">Permuted( list2, perm );</span>
[ 1, 4, 5, 5, 6, 7 ]
</pre></div>

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

<h4>21.19 <span class="Heading">Sorted Lists and Sets</span></h4>

<p>Searching objects in a list works much quicker if the list is known to be sorted. Currently <strong class="pkg">GAP</strong> exploits the sortedness of a list automatically only if the list is <em>strictly sorted</em>, which is indicated by the property <code class="func">IsSSortedList</code> (<a href="chap21.html#X80CDAF45782E8DCB"><span class="RefLink">21.17-4</span></a>).</p>

<p>Remember that a list of <em>mutable</em> objects cannot store that it is strictly sorted but has to test it anew whenever it is asked whether it is sorted, see the remark in <a href="chap21.html#X7865747A7CCF5812"><span class="RefLink">21.17</span></a>. Therefore <strong class="pkg">GAP</strong> cannot take advantage of the sortedness of a list if this list has mutable entries. Moreover, if a sorted list <var class="Arg">list</var> with mutable elements is used as an argument of a function that <em>expects</em> this argument to be sorted, for example <code class="func">UniteSet</code> (<a href="chap21.html#X7B3469CD7EFC1A87"><span class="RefLink">21.19-6</span></a>) or <code class="func">RemoveSet</code> (<a href="chap21.html#X7FCA282E789A4F4B"><span class="RefLink">21.19-5</span></a>), then it is checked whether <var class="Arg">list</var> is in fact sorted; this check can have the effect actually to slow down the computations, compared to computations with sorted lists of immutable elements or computations that do not involve functions that do automatically check sortedness.</p>

<p>Strictly sorted lists are used to represent <em>sets</em> in <strong class="pkg">GAP</strong>. More precisely, a strictly sorted list is called a <em>proper set</em> in the following, in order to avoid confusion with domains (see <a href="chap12.html#X7BAF69417BB925F6"><span class="RefLink">12.4</span></a>) which also represent sets.</p>

<p>In short proper sets are represented by sorted lists without holes and duplicates in <strong class="pkg">GAP</strong>. Note that we guarantee this representation, so you may make use of the fact that a set is represented by a sorted list in your functions.</p>

<p>In some contexts (for example see <a href="chap16.html#X7BDA99EE7CEADA7C"><span class="RefLink">16</span></a>), we also want to talk about multisets. A <em>multiset</em> is like a set, except that an element may appear several times in a multiset. Such multisets are represented by sorted lists without holes that may have duplicates.</p>

<p>This section lists only those functions that are defined exclusively for proper sets. Set theoretic functions for general collections, such as <code class="func">Intersection</code> (<a href="chap30.html#X851069107CACF98E"><span class="RefLink">30.5-2</span></a>) and <code class="func">Union</code> (<a href="chap30.html#X799F0E2F7A502DBA"><span class="RefLink">30.5-3</span></a>), are described in Chapter <a href="chap30.html#X8050A8037984E5B6"><span class="RefLink">30</span></a>. In particular, for the construction of proper sets, see <code class="func">SSortedList</code> (<a href="chap30.html#X7E399AC97FD98217"><span class="RefLink">30.3-7</span></a>) and <code class="func">AsSSortedList</code> (<a href="chap30.html#X856D927378C33548"><span class="RefLink">30.3-10</span></a>). For finding positions in sorted lists, see <code class="func">PositionSorted</code> (<a href="chap21.html#X7A122E848464E534"><span class="RefLink">21.16-5</span></a>).</p>

<p>There are nondestructive counterparts of the functions <code class="func">UniteSet</code> (<a href="chap21.html#X7B3469CD7EFC1A87"><span class="RefLink">21.19-6</span></a>), <code class="func">IntersectSet</code> (<a href="chap21.html#X8473AA657FEC3D4D"><span class="RefLink">21.19-7</span></a>), and <code class="func">SubtractSet</code> (<a href="chap21.html#X80B427537EB07D09"><span class="RefLink">21.19-8</span></a>) available for proper sets. These are <code class="code">UnionSet</code>, <code class="code">IntersectionSet</code>, and <code class="func">Difference</code> (<a href="chap30.html#X825AC0F07E010B07"><span class="RefLink">30.5-4</span></a>). The former two are methods for the more general operations <code class="func">Union</code> (<a href="chap30.html#X799F0E2F7A502DBA"><span class="RefLink">30.5-3</span></a>) and <code class="func">Intersection</code> (<a href="chap30.html#X851069107CACF98E"><span class="RefLink">30.5-2</span></a>), the latter is itself an operation (see <code class="func">Difference</code> (<a href="chap30.html#X825AC0F07E010B07"><span class="RefLink">30.5-4</span></a>)).</p>

<p>The result of <code class="code">IntersectionSet</code> and <code class="code">UnionSet</code> is always a new list, that is not identical to any other list. The elements of that list however are identical to the corresponding elements of the first argument <var class="Arg">set</var>. If <var class="Arg">set</var> is not a proper set it is not specified to which of a number of equal elements in <var class="Arg">set</var> the element in the result is identical (see <a href="chap21.html#X7DD65BEA7EDB0CD7"><span class="RefLink">21.6</span></a>). The following functions, if not explicitly stated differently, take two arguments, <var class="Arg">set</var> and <var class="Arg">obj</var>, where <var class="Arg">set</var> must be a proper set, otherwise an error is signalled; If the second argument <var class="Arg">obj</var> is a list that is not a proper set then <code class="func">Set</code> (<a href="chap30.html#X7E399AC97FD98217"><span class="RefLink">30.3-7</span></a>) is silently applied to it first.</p>

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

<h5><code>21.19-1 \in</code></h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; \in</code>( <var class="Arg">obj</var>, <var class="Arg">list</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p>For a list <var class="Arg">list</var> that stores that it is strictly sorted, the test with <code class="func">\in</code> whether the object <var class="Arg">obj</var> is an entry of <var class="Arg">list</var> uses binary search. This test can be entered also with the infix notation <var class="Arg">obj</var> <code class="keyw">in</code> <var class="Arg">list</var>.</p>

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

<h5>21.19-2 IsEqualSet</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; IsEqualSet</code>( <var class="Arg">list1</var>, <var class="Arg">list2</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>tests whether <var class="Arg">list1</var> and <var class="Arg">list2</var> are equal <em>when viewed as sets</em>, that is if every element of <var class="Arg">list1</var> is an element of <var class="Arg">list2</var> and vice versa. Either argument of <code class="func">IsEqualSet</code> may also be a list that is not a proper set, in which case <code class="func">Set</code> (<a href="chap30.html#X7E399AC97FD98217"><span class="RefLink">30.3-7</span></a>) is applied to it first.</p>

<p>If both lists are proper sets then they are of course equal if and only if they are also equal as lists. Thus <code class="code">IsEqualSet( <var class="Arg">list1</var>, <var class="Arg">list2</var> )</code> is equivalent to <code class="code">Set( <var class="Arg">list1</var> ) = Set( <var class="Arg">list2</var> )</code> (see <code class="func">Set</code> (<a href="chap30.html#X7E399AC97FD98217"><span class="RefLink">30.3-7</span></a>)), but the former is more efficient.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsEqualSet( [2,3,5,7,11], [11,7,5,3,2] );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsEqualSet( [2,3,5,7,11], [2,3,5,7,11,13] );</span>
false
</pre></div>

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

<h5>21.19-3 IsSubsetSet</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; IsSubsetSet</code>( <var class="Arg">list1</var>, <var class="Arg">list2</var> )</td><td class="tdright">( operation )</td></tr></table></div>
whetherevery element of <var class="Arg">list2</var> is contained in <var class="Arg">list1</var>. Either argument of <code class="func">IsSubsetSet</code> may also be a list that is not a proper set, in which case <code class="func">Set</code> (<a href="chap30.html#X7E399AC97FD98217"><span class="RefLink">30.3-7</span></a>) is applied to it first.</p>

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

4 AddSet<h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; AddSet</code>( <var class="Arg">set</var>, <var class="Arg">obj</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>adds the element <var class="Arg">obj</var> to the proper set <p><id"X7FA892828252BB3B" name="X7FA892828252BB3B"></a></p>

<p>Note that <var class="Arg">obj</var> java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 32


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">s := [2,3,7,11];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">AddSet( s, 5 );  s;</span>
[ 2, 3, 5, 7, 11 ]
<pan class"GAPprompt">gap></span> <span class="GAPinput">AddSet( s, 13 );  s;</span>
[ 2, 3, 5, 7, 11, 13 ]
<span class="GAPprompt">gap></p>Note that <strong class="pkg">GAP>cannot  compare arbitrary objects (yequality). This can cause that <code class="func">IsDuplicateFree</code> runs into an error, if <var class="Arg">obj</var> is a list with some non-comparable entries.</p>
[ 2, 3, 5, 7, 11, 13 ]
</pre></div>

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

<h5>21.19-5 pr<ode=keyw"true</  v =Arg"><var> list and is sorted,  code class"><code>otherwise<pjava.lang.StringIndexOutOfBoundsException: Index 150 out of bounds for length 150

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; RemoveSet</code>( <var class="Arg">set</var>, <var class="Arg"
< from the proper set <var class="Arg">set</var>. If <var class="Arg">obj</var> is not contained in <var class="Arg">set</var> then <var class="Arg">set</var> is not changed. If <var class="Arg">obj</var> is an element of <var class="Arg">set</var> it is removed and all the following elements in the list are moved one position forward.</p>


<div class="example"><pre>
span class"">ap&;/><pan =GAPinput"s :  2 ,4,5 6  ;<s
<span class="GAPprompt">gap></span> <span class="GAPinput">RemoveSet( s, 6 ); s;</java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
 ,,,7java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
<span class="GAPprompt">gap></span> <span class="GAPinput">RemoveSet( s, 10 ); s;</span>
[ 2, 3, 4, 5, 7 ]
</pre></div>

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

<h5>21.19-6 UniteSet</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; UniteSet</code>( <var class="Arg">set</var>, <var class="Arg">list</var> )</td><td class="tdright">( operation )</td></tr></
<p>unites the proper set <var class="Arg">set</var> with <var class="Arg">list</var>. This is equivalent to adding all elements of <var class="Arg">list</var> to <var class="Arg">set</var> (see <code class="func">AddSet</code> (<a href="chap21.html#X832C23CC7FCD8892"><span class="RefLink">21.19-4</span></a>)).</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">set := [ 2, 3, 5, 7, 11 ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">UniteSet( set, [ 4, 8, 9 ] );  set;</span>
[ 2, 3, 4, 5, 7, 8, 9, 11 ]
<spanclass="GAPprompt">gap></span> <span class="GAPinput">UniteSet( set, [ 16, 9, 25, 13, 16 ] );  set;</span>
[ 2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 25 ]
</pre></div>

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

<h5>21.19-7 IntersectSet

<ivclass="func><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&# style='color: green'>8227; IntersectSet</code>( <var class="Arg">set</, var class=Arg"list</> )td><td class="tdright">( operation )</td></tr></table></div>
<p>intersects the proper set <var class="Arg">set</var> with <var class="Arg">list</var>. This is equivalent to removing from <var class="Arg">set</var> all elements of <var class="Arg">set</var> that are not contained in <var class=">codeclass=java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 498


<div class="example"><pre>
<span class="GAPprompt">gap></p><code class="func">SortBy</code> sortsvar class=Arg"><v>into order  that codeclass=code">(listi]&;func(isti+
<span class="GAPprompt">gap></span> <span class="GAPinput">IntersectSet(<>code class=func"StableSortBy/> behaves the same ascode class=func"S</ode> except ,like code class=func">StableSort<code>  keeps pairs     <codeclass">func<>is applied    the relativeorder.<p>
[ 3, 5, 7, 9java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<span class="GAPprompt">gap></span> <span class="GAPinput">java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 26
[9<GAP implements threedifferentfamilies ofsortingalgorithms.The default algorithmis pattern-defeating ,avariant   whichperformsbetter   sorted listsandhas  worst-case behaviour   which begin code =code><code>are stable(qual elements keep the relative  in  sorted list)  merge sort.Finally, the functions which begin <code class="code">Shell</code> use the shell sort which was GAP's default search algorithm before 4.9. <code class="func">Sortex</code> (<a href="chap21.html#X87287FCA81E2B06A"><span class="RefLink">21
</pre></div>

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

<h5>21.19-8 SubtractSet</h5>

<div class
<p>subtracts <var class="Arg">list<


<div class="example"><pre>
<span class="GAPprompt">gap></<spanclass"GAPprompt>gap&;</span><span =GAPinput"Sort(list, function(,wfunc">&8227; StableSortBy/(varclass=""list<var[,varclass="fnc/> )/d>td class"dright""&spoperationnbsp</>/r>/><divjava.lang.StringIndexOutOfBoundsException: Index 254 out of bounds for length 254
<pan class=GAPprompt">gap></span> <span class="GAPinput">SubtractSet( set, [ 6, 10 ] );  set;</span<panclass"APprompt"gapgt;/span>span class="APinput">list;  # sorted according to the Euclidean distance from [0,0]</span>
  3  ,55, 7 ,8,9,  ]
<span class="GAPprompt">gap></span> <span class="GAPinput">SubtractSet( set, [ 9, 4, 6, 8 ] );  set;</span>
[ 2, 3, 5, 7, 11 ]
</pre>/div>

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

<<p>code =func">ortBy/>sortsthe list <varclass=Arg">ist<var>into an ordersuch  code class=code"(ist[] lt=func(isti+)/>for all relevant< class=A"i<var> ""func</>must thusbe afunction on   whichreturnsvaluesthatcan  .Each code <p><code class="func">SortBy</code> sorts the list <var class="Arg">list</var> into an order such that <code class="code">func(list[i]) <= func(list[i+1])</code> for all relevant <var class="Arg">i</var>. <var class="Arg">func</var> must thus be a function on one argument which returns values that can be compared. Each <code class

<<=""# note the random orderofthe elementswith equal first component<span>

<p><a id<spanclass="GAPprompt">gap></span> <span class="GAPinput">list<

<h5>21.20-1 Concatenation</< =GAPprompt"g&t;<span> sclass"APinput>:  5,4,,1 7,5];; Sort(list ) list<span>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; Concatenation</code>( <var class="Arg">list1</var>, <var class="Arg"p><aidX791F2B2C7E9B9A46" name="X791F2B2C7E9B9A46"></a></p>
<div class="func"><table class="func" width="100%">< java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 92
<p>In  6, 1, 4 7, 5,5java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19

<p>In the second form <var class="Arg">list</var> must be a dense list of lists <var class=<div =func>table =func width="100< =APprompt">gap></pan>s class=GAPinput>( function(,)return * &t; *w;  )</pan>

<p>The result is a new mutable list, [[1,  ][1, ]  0, ]  3,4 ,[1,5,[0 6]]

  code =>java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 516


d class="example>pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Concatenation( [ 1, 2,p><codeclass"spanclass"APprompt"><span>,];/java.lang.StringIndexOutOfBoundsException: Index 124 out of bounds for length 124
[ 1, 2, 3, 4, 5 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">Concatenation( [2,3,,5,,7], [11,,13,,,,17,,19] );</span>
[ 2, 3,, 5,, 7, 11,, 13,,,, <iv class="example>pre>
<span class="GAPprompt">gap><pan class"&<span>s ""list1 := 5,4 6 ,7, ;<spanjava.lang.StringIndexOutOfBoundsException: Index 100 out of bounds for length 100
[ 1, 2, 3s"<span class="GAPprompt">gap
</pre></div>

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

<h5>21.14 ,=f< fwidth100%<<t=> "&8227StableSortParallel/(var=list1vjava.lang.StringIndexOutOfBoundsException: Range [156, 155) out of bounds for length 291

<java.lang.StringIndexOutOfBoundsException: Range [5, 4) out of bounds for length 220
<p>returns a new mutable list that contains the elements of <var class="Arg">list</var> in the same order but omitting the holes<re><divjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l:=[,1,,,3,,,4,[5,,,6],7];;  Compacted( 
[ 1, 3, 4, [ 5,,, 6 ], 7 ]
</re><div>

p<id="7java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

h521203Collected/>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">psorts  var < class">ap&</span>< ""list2/panjava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
<p>returns a new list <var class="Arg">new</var> that java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 12

<p>or all pairs ofelements in <var class="Arg">list</var> the comparison via <<p


<div class="<p><a id="X87287FCA81E2B06"name="87287CA81E2B06A"></a></p>
<span class="GAPprompt">gap></span> <span class="GAPinput">Factors( Factorial( 10 ) );</span>
[ 2, 2, 2, 2, 2, 2<span class="GAPprompt">gap></span> <span class="GAPinput">list1 := [ 5, 4, 6, 1, 7, 5 ];;</span>
<java.lang.StringIndexOutOfBoundsException: Range [86, 5) out of bounds for length 87
[ [ 2, 8 ], [ 3, 4 ], [ 5, 2 ], [ 7, 1 ] ]
<pan class=GAPprompt"gap&t;/span><pan class=GAPinput"Collected  );s>
[ [ [ 2, 8 ], 1 ], [ [ 3, 4 ], 1 ], [ [ 5, 2 ], 1 ], [ [ 7, 1 ], 1 ] ]
</pre></div>

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

<h5>21.20-4 DuplicateFreeList</h5>

<java.lang.StringIndexOutOfBoundsException: Range [5, 4) out of bounds for length 228
<divclass"">< "func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Unique</code>( <var class="Arg">list</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>returns a new mutable list whose entries are the elements of the list <var class="Arg

<p><code class="



<span class="GAPprompt">gap></span> <span class="GAPinput">l:=[1,Z(3),1,"abc",Group((1,2,3),(1,2)),Z(3),Group((1,2),(2,3))];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">DuplicateFreeList( l );</span>
[ 1,Z() ", Group( 123,(1spanclass">&<span>spanclass="APinput"erm  =ortingPerm list1 ;<spanjava.lang.StringIndexOutOfBoundsException: Index 98 out of bounds for length 98
</pre></div>

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

<h5>21.20-5 AsDuplicateFreeList</h5span class"GAPprompt">/ <span class=GAPinput"span "java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 100

<="width100"<>class"">code class==unc"&8227;AsDuplicateFreeList</(<ar =Arg"list</ar>)/d< class"tdright>&;ttribute&;<td>/r<t>/divjava.lang.StringIndexOutOfBoundsException: Index 230 out of bounds for length 230
<p>returns the same result as <code class="func">DuplicateFreeList</code> (<a href="chap21.html#X8727F2928467C2F9"><span class="RefLink">21.20-4</span></a>), except that the result is immutable.</p>

< 5 , 6,1, 7 5]<>a "80ABC25582343910 "X80ABC25582343910"<a>/p>

<h5>21.20-6 Flat</h5>

<div class="func"><table class="func" width="pStrictlysortedlistsareused toem>sets</em>in<trong <
=">lat</code> first  new empty <java.lang.StringIndexOutOfBoundsException: Index 183 out of bounds for length 0


dclass=example"<>
<
[ 2 3 , persetsare represented by sorted lists without holes and duplicates in <strong class="pkg">GAP</strong>. Note that we guarantee this representation, so you may make use of the fact that a set is represented by a sorted list in your functions.</p>
<span class<
[  ]
</pre></div>

p> afrom     cjava.lang.StringIndexOutOfBoundsException: Range [68, 67) out of bounds for length 157


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l:=[9..14];;w:=2;; # w is the length of each row</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
[ ,10   11 ]  ,14 ]
</pre></div>

<pa =X7C4FDB007C3F54A1"name=X7C4FDB007C3F54A1></>/>

<h521207 Reversed<h5java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25

<div class="func<p><a "X7B4C0FEE7CDF6F2A"name="java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 27
<java.lang.StringIndexOutOfBoundsException: Range [0, 2) out of bounds for length 0

<p>The argument list is unchanged. The result list is a new list, that is not identical to any other list. The elements of that list however are identical to the corresponding elementsjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p><code class="func">Reversed</code> implements a special case of list assignment, which can also be formulated in terms of the <code class="code">{}</<p>tests whether <var class="Arg">list1</var> and <var class="Arg">list2</var> are equal <em>when viewed as sets</em>, that is if every element of <var clas

<p>Developers who wish to adapt this for custom list types need to install suitable methods for the operation <code java.lang.StringIndexOutOfBoundsException: Index 119 out of bounds for length 0


<div class="example"><pre>
<span class="GAPprompt">gap></ class="GAPprompt">gap></span=GAPinput>< =GAPprompt"gapgt;/pan><class=GAPinput"( [2,3,,,11,[2,,,,,])<span>
[ 7, 6, 5, 9, 4, 1 ]
</pre></div>

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

<h5>21.20-8 java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0

<div class="func"><<div class="func"><table=width"%>tr>"> "java.lang.StringIndexOutOfBoundsException: Range [93, 91) out of bounds for length 253
<p>The argument <var class="Arg">list</var> must be a dense mutable list. This operation<> whether everyelement  <ar class="Arg">list2</var> is contained in <var class="Arg">list1</var>. Either argument of">tableclass=""="%<tr< "tdleft>< =""#8227;IsSubsetSetjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0


<div class="example"><pre>
<span class="GAPprompt">gap>java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 0
<span class"
[1..20]
<panclass"GAPprompt">apgt</span <span class="GAPinput">m := Shuffle(ShallowCopy(l))<>adds the element <var class="Arg">obj</var> to the proper set <var class="Arg">set</var>. If <var class="Arg">obj</var> is already contained in <var class="Arg">set</var> then <var class="Arg">set</var> is not changed. Otherwise <var class="Arg"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
1,2,10,19 17  9java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
  14 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">l;</span>
[ 1 .. 20 ]
<spanp>that<ar class< ">pre>
<span class=<pan class=GAPprompt"g&t<span><spanclass="APinput> =23711];/span>
[19<ivv class="xample"<>
  18 ]
e>/

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



<div class="func"><table class="func" <span class="GAPprompt">gap></span> <span class="GAPinput">AddSet( s, 3 )<pre><djava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
<p></re><divjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12

<p><code class="func">Apply</code> changes its argumentjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l:= [ 1, 2, 3
[ 1, 4, 9 ]
</re<div

81DBF6FB>a<

<h5>21.20-10 Perform</h5>

<div class="func"><table class="<pan class="GAPprompt">gap></span> <span class="GAPinput">s := [ 2[ 2,3 4 5, 7]
c<var>to everyelementof thelist varclass=Argjava.lang.StringIndexOutOfBoundsException: Index 131 out of bounds for length 0


<v "example"<>
<span class="GAPprompt">gap></span> <span class="GAPinput">l := [1, 2, 3];; Perform(l,</span>
<span <p><a id="B3469CD7EFC1A87 name=X7B3469CD7EFC1A87"<a<pjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
2
3
</pre></div>

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

h5>.20 PermListList/h5>

<div class="func"><table class="func" width="100%"><tr><td java.lang.StringIndexOutOfBoundsException: Range [26, 64) out of bounds for length 26
ength  java.lang.StringIndexOutOfBoundsException: Range [107, 106) out of bounds for length 415


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">list1 := [ 5, 4, 6, 1, 7, 5 ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">list2 := [ 4, 1, 7, 5, 5, 6 ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">perm := PermListList(list1, list2);</span>
(1,2,4)(3,5,6)
<span class="GAPprompt">gap></span> <span class="GAPinput">Permuted( list2, perm );</span>
[
<pre<div>

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

<5212012 < class"eading"Maximum</>h>

<iv class="func"><table >
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; Maximum</code>( <var class="Arg">list</var> )</td><td class="tdright">(&span class="GAPprompt">gap></span> <span class="GAPinput">set := [ 2, 3, 4, 
p java.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 345

<p>In the second form <code class="func">Maximum</code> takes a homogeneous list <var [ 3 , ,9 11,13]


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 0
700
<span class="GAPprompt">gap></span> <span class="GAPinput">Maximum( [ -123, 700, 123, 0, -1000 ] );</span>
700
<span class="GAPprompt">gap></span> <span class="GAPinput"># lists are compared elementwise:</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Maximum( [1,2], [0,15], [1,5], [2,-11]
[ 2, -11 ]
</pre></div>

<>Toget   the  element div =example">pjava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26

<p><a id="X82F133EC7F89665F" name="span class="GAPprompt">gap></span> <span class="GAPinput">SubtractSet( set, [ 9, java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 105

<h5>21.20-13 <span class="Heading">Minimum</span></h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleftjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<div class=func><ableclass="func"p> ofthefollowing functions expect the first argument to be either a list or a collection (see <a href="chap30.html#X8050A8037984E5B6"><span class="RefLink">30</span></a>), with possibly slightly different meaning for lists and non-list collections.</p>
<>In the first form<<>a id=840C55A77D1BB2E1"name=X840C55A77D1BB2E1"><a<pjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62

<

<p>  forboth <code class"func"Maximum</code> java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class="example"><pre>
<=ap&/panclass"">Minimum(-,700  ,1000<spanjava.lang.StringIndexOutOfBoundsException: Index 105 out of bounds for length 105
-1000
<span class="GAPprompt">gap></span> <span class="GAPinput">Minimum( [ -123
-1000
<span<iv "example>pre
[ 0, 15 ]
</pre></div>

<p>To get the index of the minimum element use <code class="func"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

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

<h5>21.20-14 <span class="Heading">MaximumList and MinimumList</span><[2 3,5, 7 11,13,, 17, 19

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; MaximumList</code>( <var class="Arg">list</var>[, <var class="Arg">seed</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; MinimumList</code>( <var class="Arg">list</var>[, <var class="Arg">seed</var>] )</td><</pre><div>
<p>java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0

<Ifa second v class">seed<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

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

<h5>21.20-15 <span class="Heading">Cartesian</span></h5>

<div class="func"><table class="func" width="100
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; Cartesian</code>( <var class="Arg
<p>In the first form <code<ivclass=func>table class="<iv example"prejava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26

In  var "><>mustbe alist of lists<ar class=""><var> <varclass"><>etc. java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>The <em>cartesian product</em> is a list <var class="Arg">cart</var> 

<p>The last index runs fastest. That means that the first element <var class="p>aid"X7ECE9056792F28BA"name=>/></>

<p><52120-3 Collected/>


<<ivclass="unc>  ,8 , ][ ,2 ,  7   
<span class="GAPprompt">gap></span> <span class="GAPinput class"GAPprompt"gap></span> <span class="GAPinput">Collected( last );</span>
[ [ 1, 3, 5 ], [ 1, 3, 6 ], [ 1, 4, 5 ], [ 1, 4, 6 ], [ 2, 3, 5 ],
  ,],[2java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
 class">([,,] 11
[ [ 1, 1 ], [ 1, 1 ], [ 1, 2 ], [ 2, /</>
  [ 2, 1 ], [ 2, 1 ], [ 2, 2 ] ]
</pre></div>

<p><a id="X7E76F5A782184823" namejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<h5>21.20-16 <span class="Heading">IteratorOfCartesianProduct</span></h5>

d java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 295
<div class="func"><table class="func" width="100%"><tr><td class=" class="func"><table class="func" width="100%"><tr><td class="tdleft =java.lang.StringIndexOutOfBoundsException: Range [29, 27) out of bounds for length 62
< firstform< ""java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 215

<p>In the second form <var class="Arg">list</var> must be a list of lists <var class="Arg">list1</var>, <var class="Arg">java.lang.StringIndexOutOfBoundsException: Index 126 out of bounds for length 0

<p>Resulting tuples will be returned in the lexicographic order. Usage java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 0

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

<h5>21.20-17 Permuted</h5>

< func"< ="=100%><r>tdclass=">codeclass=func"&#8227;<code> < ="<>varclass=Arg>permerm<var></>< tdright"( operation )</<tr>/>/divjava.lang.StringIndexOutOfBoundsException: Index 248 out of bounds for length 248
<>returns new list< class="Arg"><varthat containsthe  of the list <var class="Arg">list</var> permuted according to the permutation <var class="Arg">perm</var>. That is <code class="code"><var class="Arg">new</var>[<var class="Arg">i</var>^<var class="Arg">perm</var>] = <var class="Arg">list</var>[<var class="Arg">i</var>]</code> whenever <code class="code"><var class="Arg">list</var>[<var class="Arg">i</var>]</code> is bound.</p>

p<class""Sortex</> (a href="chap21.html#X87287FCA81E2B06A"><span class="RefLink">21.18-3</span></a>) allows you to compute a permutation that must be applied to a list in


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Permuted( [ 5, 4, 6, 1, 7, 5 ], (1,3,5,6,4) );<<>Developers who wish to adapt this for custom list types need to install suitable methods for the operation <code class="code">LastOp</code>.</p>
[ 1, 4, 5, 5, 6, 7 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">Permuted( [ 5, 4, 6,, 7, 5 ], (1,3,5,6,4) );</span>
[ , 4, 5, 5, 6, 7 ]
</pre></div>

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

<h5>21.20-18 List</h5>

<div class="func"><table class="func" width="100%"><trjava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
<p>Thisa ="name"7java.lang.StringIndexOutOfBoundsException: Range [56, 52) out of bounds for length 62

<p>Developers who wish to adapt this for custom list or collectiondivclass"java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 251


<div class="example"><java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 0
<span class=GAPprompt>gap></ < class;</>
[ 1, 4, 9 ]
<spanjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
,false,true,false, false  ]
<span class="GAPprompt">gap></span> <span class="GAPinput">List([,1,,3,4], x-> x > 2);</span>
[ , false,, true, true ]
</pre></div>

<""gapgt</>span =GAPinput"ForAll[,,,8,9,;/

<p><a idjava.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4

<h5>21.20-19 Filtered</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; java.lang.StringIndexOutOfBoundsException: Index 101 out of bounds for length 4
<pra list  contains those elements of the list or collection <var class="Arg">listorcoll</var> (see <a href="chap30.html#X8050A8037984E5B6"><span class="RefLink">30</span></a>), respectively, for which the unary function <var class="Arg">func</var> returns <code class="keyw">true</code>.</p>

<p>If the first argument is a list, the order of the elements in the result is the same as the order of the corresponding p>a ="Ajava.lang.StringIndexOutOfBoundsException: Range [55, 52) out of bounds for length 62

<p>For each element of <var class="Arg">listorcoll</var>, <var class="Arg">func<<5>21.20-24 ForAny</h5>

<p>The result is a new list that is not identical to any other list. The elements of that list however are identical to the corresponding elements of the argumentjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>List assignment using the operator <code class="func">\{\}</code> (<a href="chap21.html#X78791B8B838A8BA0"><span class="RefLink">21.3-1</span></a>) (see <a href="chap21.html#X8611EF768210625B"><span class="RefLink">21.4</span></a>) can be used to extract elements <p>testswhetherthe unary function <var class="Arg">func</var> returns <code class="keyw">true</code> for at least one element in the list or collection <var class="Arg">listorcoll</var>.</p>

< this for custom listor collection types need to install suitable methods for the operation <code class="code">FilteredOp</code>.</p>


<div class="example"><pre>
<java.lang.StringIndexOutOfBoundsException: Range [0, 5) out of bounds for length 4
[ 2, 3, 5, 7, 11, 13, 17, 19 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">Filtered( [ 1, 3, 4, -4, 4, 7, 10, 6 ], IsPrimePowerInt );</span>
[ 3, 4, 4, 7 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">Filtered( [ 1, 3, 4, -4, 4, 7, 10, 6 ],</span>
<span class="GAPprompt">></span> <span class="GAPinput">             n -> IsPrimePowerInt(n) and n mod 2 <> 0 );</span>
[ 3, 7 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">Filtered( Group( (1,2), (1,2,3) ), x -> Order( x ) = 2 );</span>
[ (2,3), (1,2), (1,3) ]
</pre></div>

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

<h5>21.20-20 Number</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; Number</code>( <var class="Arg">listorcoll</var>[, <var class="Arg">func</var>] )</td><td class="tdright">( function )</td></tr></table></div<
<p>Called with a list <var class="Arg">listorcoll</var>, <code class="func">Number</code> returns the number of bound entries in this list. For dense lists <code class="func">Number</code>, <code class="func">Length</code> (<a href="chap21.html#X780769238600AFD1"><span class="RefLink">

<p>Called with two arguments, a list or collection <var class="Arg">listorcoll</var> and a unary function <var class="Arg">func</var>, <code class="func">Number</code> returns the number of elements of <var class="Arg">listorcoll</var<iv class="unc"table "unc"="%>tr>td class"dleft"<class=func><class=Arg<>,var"func<var<class"tdright">&bspfunction&bsp;)</td></tr></table></div>

<p>For span class"GAPprompt>gt;/> < =""    > IsPrimePowerIntn  mod  =and IsPrimen);/java.lang.StringIndexOutOfBoundsException: Index 133 out of bounds for length 133

<p><code class="func">Filtered</code> (<a href="chap21.html#X7C86D7F7795125F0"><span class="RefLink">21.20-19</span></a>) allows you to extract the elements of a list that have a certain property.</p>

<p>Developers who wish to adapt this for custom list or collection types need to install suitable methods for the operation <code="code">/code>.</>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Number( [ 2, 3, 5, 7 ] );</span>
4
<span class="GAPprompt">gap></span> <span class="GAPinput">Number( [, 2, 3,, 5,, 7,,,, 11 ] );</span>
5
<java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 96
8
<span class="GAPprompt">gap></span> <span class="p><code class="func">Filtered</code> (<a href="chap21.html#X7C86D7F7795125F0"><span class="RefLink">21.20-19</span></a>) allows you to extract the elements of a list that have a certain property.</p>
4
<span class="GAPprompt">gap></span> <span class="GAPinput">Number( [ 1, 3, 4, -4, 4, 7, 10, 6 ],</span>
<span class="GAPprompt">></span> <span class="GAPinput">           n -> IsPrimePowerInt(n) and n mod 2 <> 0 );</span>
2
<span class="GAPprompt">gap></span> <span class="GAPinput">Number( Group( (1,2), (1,2,3) ), x -> Order( x ) = 2 );</span>
3
</pre></div>

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

<h5>21.20-21 First</h5>

<<tr><td=tdleft"<java.lang.StringIndexOutOfBoundsException: Range [80, 79) out of bounds for length 247
<p><code class="func">First</code> returns the first element of the list <var class="Arg">list</var> for which the unary function <var class="Arg">func</var> returns <code class="keyw">true</code>; if java.lang.StringIndexOutOfBoundsException: Index 201 out of bounds for length 106

<p><code class="func">PositionProperty</code> (<a href="chap21.html#X7E6C763A82C6153B"><span class="RefLink">21.16-9</span></a>) allows you to find the position of the first element in a list that satisfies a certain property.</p>

<p>Before <strong class="pkg">GAP</strong> 4.12, developers who wished to adapt this for custom list types needed to install suitable methods for the operation <code class="code">FirstOp</code>. This is still possible for backwards compatibility, but <code class="code">FirstOp</code> now is just a synonym for <code class="func">First</code>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 0
10000019
<span class=0Z
<>java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 12
100489
< ="&;/><pan ="</a</>
fail
<span class="GAPprompt">gap></span> <span class="GAPinput">First( [ fail ], x -> x = fail );</span>
fail
</pre></div>

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

<h5>21.20-22 Last</h5>

<div class="func"><table class="func"
<>class=func"Last<code>java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 711

<p>Developers who wish to adapt customlist types need to install suitable methods for the operation <code class="code">LastOp</code>.</p>


<div java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
<spanclass=GAPprompt">><s><pan => [^.108IsPrime)</>
99999989
<span class="GAPprompt">gap></span> <span class="GAPinput">Last( [10^5..10^6],</span>
<spanclass=GAPprompt"&;/>s class"APinput>      &t;not (n)  java.lang.StringIndexOutOfBoundsException: Range [107, 106) out of bounds for length 119
994009
p"( [ .20, java.lang.StringIndexOutOfBoundsException: Range [83, 82) out of bounds for length 107
fail
<span class="GAPprompt">gap></span> <span class="GAPinput">Last( [ fail ], x -> x = fail );</span>10000019
fail
</pre></div>

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

<h5>21.20-23 ForAll</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft77
<p>tests whether the unary function <var class="Argspanclass"GAPprompt">ap&/><<il

<>Developerswho wish to adapt this for custom list or collection types need to install suitable methods for the operation <code class="code">ForAllOp</code>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span>< GAPprompt"gap&;/span < </java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
false
<span class="GAPprompt">gap></span> <span class="GAPinput">ForAll( [2,3,4,5,8,9], IsPrimePowerInt );</span>
true
<span class="GAPprompt
true
span class=GAPprompt>gap>/span><span class="GAPinput">ForAll( Group( (1,2), (1,2,3) ), i -> SignPerm(i) = 1 );</span>
false
</pre></div>

<<pue

<h5>21.20-24 ForAny</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; ForAny</code>( <var class="Arg">listorcoll</var>, <var class="Arg">func</var> )</td><td class="tdright">( function )<alse
<p>tests whether the unary function <var class="Arg">func</var<pan class"ggt< ">java.lang.StringIndexOutOfBoundsException: Range [71, 69) out of bounds for length 100

<Developers who wish to adaptthis for custom list or  types   install  methods the operation<ode class="ode"ForAnyOp<>.<java.lang.StringIndexOutOfBoundsException: Range [163, 164) out of bounds for length 163


<div class="example"><div =func> " java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 225
<span class="GAPprompt">gap></span> <span class="GAPinput">ForAny( [1..20], IsPrime );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">ForAny( [2,3,4,5,8,9], IsPrimePowerInt );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">ForAny( [2..14],</span>
<span class="GAPprompt">></span> <span class="GAPinput">   n -> IsPrimePowerInt(n) and n mod 5 = 0 and not IsPrime(n) );</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">ForAny( Integers, i ->     i > 0</span>
<span class="GAPprompt">></span> <span class="GAPinput">                          and ForAll( [0,2..4], j -> IsPrime(i+j) ) );</span>
true
</pre></div>

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

<h5>21.20-25 Product</h5>

">code "func"&8227;</code>( <var class="Arg">listorcoll</var>[, <var class="Arg">func</var>][, <var class="Arg">init</var>] )</td><td class="java.lang.StringIndexOutOfBoundsException: Index 232 out of bounds for length 4
pCalledwithone  a list collection<ar class"><var, cclass=func"Product<code>returns product ofthe  of <class="Arg>listorcoll<var>(ee href=chap30.X8050A8037984E5B6"<class=RefLink"30<span<a)</>

<p>Called with a dense list or collection <<p><a id="X7AF82E747A8BDA75" name="X7AF82E747Aa>/>

<p>The general rules for arithmetic operations apply (see <a href="chap21.html#X8676EFE67972FD06"><span class="RefLink">21

<p>If <var class="Arg">listorcoll</var> contains exactly one element then this element (or its image under <var class="Arg">func</var> if applicable) itself is returned, not a shallow copy of this element.</p>

<p>If an additional initial value <var class="Arg">init</java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>Developers who wish to adapt this for custom list or collection java.lang.StringIndexOutOfBoundsException: Range [0, 72) out of bounds for length 26


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput"s java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 85
9699690
<span class="GAPprompt">gap></span> <span class="GAPinput">Product( [1(   mod5=0 not java.lang.StringIndexOutOfBoundsException: Range [121, 120) out of bounds for length 133
13168189440000
<java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 125
(1,4)(2,3)
<span class="GAPprompt">gap></span> <span class="GAPinput">Product( GF(8) );</span>
0*Z(2)
</pre></div>

<p><a id="X7A04B71C84CFCC2D" name="p> that you modify an <code class="func">IsRangeRep</code> object by assigning to one of its entries, or by using <code class="func">Add</code> (<a href="chap21.html#X795EC9D67E34DAB0"><span class="RefLink">21.4-2</span></a>) or <code class="func">Append</code> (<a href="chap21.html#X79E31DB27C82D6E1"><span class="RefLink">21.4-5</java.lang.StringIndexOutOfBoundsException: Index 343 out of bounds for length 0

<h5>21.20-26 Sum</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; Sum</code>( <var class="Arg">listorcoll</var>[, <var class=" 1,2,3]
<p>Called with one argument, a dense list or collection <var class="Arg">listorcoll</var>, <code class="func">Sum</code> returns the sum <p<a id="X7D22B2298167A58F"X7D22B2298167A58F"><a>/

<p>Called with a dense list or collection <var class="Arg">listorcoll</=f"<tableclass=f"width"100%>tr>td classtdleft"< class"unc>#8227;java.lang.StringIndexOutOfBoundsException: Range [119, 118) out of bounds for length 227

<p>The general rules for arithmetic operations apply (see <a href="chap21.html#X8676EFE67972FD06"><span class="RefLink"java.lang.StringIndexOutOfBoundsException: Index 119 out of bounds for length 0

<p>If <var class="Arg">listorcoll</var> contains exactly one element then this element (or its image under <var class="Arg">func</var> if applicable) itself is returned, not a shallow copy of this element.</p>

<p>If an additional initial value <var class="Arg">init</var> is given, <code class="

pDevelopers who wish to adapt this for custom list or collection types need to install suitable methods for the operation <code class="code">SumOp</code>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Sum( [ 2, 3, 5, 7, 11, 13, 17, 19 ] );</span>
77
<span class="GAPprompt">gap></span> <span class="GAPinput">java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 14
385
<span class="GAPprompt">gap></span> <span class="GAPinput">Sum( [ [1,2], [3,4], [5,6] ] );</span>
[ 9, 12 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">Sum( GF(8) );</span>
0*Z(2)
</pre></div>

p/>   list java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 466

<h5>21.20-27 Iterated</h5java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<div class="func"><table class="func" width="100%"><tr><td class="java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
e list< class">>. More precisely, if <var class="Arg">list</var> has length <span class="SimpleMath">n</span> then <code class="func">Iterated</code> returns the result of the following application, <span class="SimpleMath"><var class="Arg">f</var>( ... <var class="Arg">f</var>( <var class="Arg">f</var>( <var class="Arg">list</var>[1], <var class="Arg">list</var>[2] ), <var class="Arg">list</var>[3] ), ..., <var class="Arg">list</var>[n] )</span>.</p>


="<prejava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
<span class="GAPprompt">gap></span> <span class="GAPinputIf<java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 209
3
</pre></div>

<>a<evelopers adapt for  java.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 164

<h5>21.20-28 ListN</h5>

<>table func" width="100"<>tdclass="tdleft><code "func">#8227 /< =java.lang.StringIndexOutOfBoundsException: Range [24, 22) out of bounds for length 111
<p>applies the <span class="SimpleMath">n</span>-argument function <var class="Arg">f<42124 span java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7


<p> situations 
s "gapgt;s <class"">( [,2,<>2124-h>
 ,6java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
</pre></div>

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

<h4>21.21 <span class="Heading">Advanced List Manipulations</span></h4>

<p>The following functions are generalizations of <code class="func">List</code> (<a href="chap30.html#X7F12F40E87F3C3A7"><span class="RefLink">30.3-5</span></a>), <code class="func">Set</code> (<a href="chap30.html#X7E399AC97FD98217"><span class="RefLink">30.3-7</span></a>), <code class="func">Sum</code> (<

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

<h5>21p> rulesfor arithmetic apply( < java.lang.StringIndexOutOfBoundsException: Range [66, 65) out of bounds for length 212

<ivclass=">< class=func =100"<r<td class="tdleft"><code class="func">&#8227; ListX</code>( <var class="Arg">arg1</var>, <var class="Arg">arg2</var>, <var class="Arg">...</var>, <var class="Arg">argn</var>, <var class="Arg">func</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">ListX</code> returns a new list constructed from the arguments.</p>

<p>Each of the If an additional initial java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 440


<dl>
<dt><strong class="Mark">a list or collection</strong></dt>
<dd><p>this introduces a new for-loop in the sequence of nested for-loops and if-statements;</p>

</dd>
<dt><strong class="Mark">a function returning a list or collection</strong></dt>
<dd><p>this introduces a new for-loop in the sequence of nested for-loops and if-statements, where the loop-range depends on the values of the outer loop-variables; or</p>

</dd>
>a function returning <code class="keyw">true</code> or <code class="keyw">false</code></strong></dt>
<dd><p>this introduces a new if-statement in the sequence of nested for-loops and if-statements.</p>

</dd>
</pan "java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 100
<p>The last argument <var class="Arg">func</var> must be a function, it is applied to the values of the loop-variables and the results are collected.</p>

<p>Thus <code class=

<p>As a more elaborate example, assume <var class="Arg">arg1</var> is a list or java.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 0

<p><codep> the of  iterated application  thefunction <var class="Arg">f</var>, which must take two arguments, to the elements of the list <var class="Arg">list</var>. More precisely, if <var class="Arg">list</var> has length <span class="SimpleMath">n</span> then <code class="func">Iterated</code> returns the result of the following application, <span class="SimpleMath"><var class="Arg">f</var>( ... <var class="Arg">f</var>( <var class="Arg">f</var>( <var class="Arg">list</var>[1], <var class="Arg">list</java.lang.StringIndexOutOfBoundsException: Index 525 out of bounds for length 0

<p>is equivalent to</p>


<div class="example"><pre>
result := [];
for v1 in arg1 do
  if arg2( v1 ) then
    for v2 in arg3( v1
      if arg4( v1, <div class="func"><table" width=100%><tr>< class=tdleft"><code class="func">&#le='color: green'>8227; ListN</code>( <var class="Arg">list1</var>, <var class="Arg">list2</var>, <var class="Arg">...</var>, <var class="Arg">listn</var>, <var class="Arg">f</var> )</td><td class="tdright">( function )</td></tr></table></div>
        Add( result, func( v1, v2 ) );
      fi;
    od;
  fi;
od;
</pre></div>

<p>The following example shows how <code class="func">ListX</code> can be used to compute all pairs and all strictly java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l:= [ 1, 2, 3, 4 ];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">pair:= function( x, y ) return [ x, y ]; end;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">ListX( l, l, pair );</span>
[ [ 1, 1 ], [ 1, 2 ], [ 1, 3 ], [ 1, 4 ], [ 2, 1 ], [ 2, 2 ],
  [ 2, 3 ], [ 2, 4 ], [ 3, 1 ], [ 3, 2 ], [ 3, 3 ], [ 3, 4 ],
  [ 4, 1 ], [ 4, 2 ], [ 4, 3 ], [ 4, 4 ] ]
</pre></div>

In java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 176


dexample"pre
<pan class=GAPprompt">gap></span> <span class="GAPinput">ListX( l, l, \<, pair );</span>
[
</pre></div>

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

<h521212 SetX<h5>

<dd<>thisintroduces 
Tjava.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 262

<p><a id="X82B1411E7FBE925F" name="X82B1411E7FBE925F"><d<this introduces a new for-loop in the sequence of nested for-loops and if-statements, where the loop-range depends on the values of the outer loop-variables; or</p>

<h5>21.21-3 SumX</h5>

<div class="func"><table class="func" width="100%"><tr><td</dl>
<p><code class="func">SumX</code> returns the sum of the elements<p> lastjava.lang.StringIndexOutOfBoundsException: Range [22, 20) out of bounds for length 153

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

<h5>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; ProductX</code>( <var class="Arg
<odeclass="unc"ProductX</  product ofthe elements  list obtained by<odeclass=func">istXwhen  iscalled  arguments<p>

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

<h4>21.22 <span class="Heading">Ranges</span></java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 17

<p>    od;

<p><code class="code">[ <var class="Arg">first</od

<p>or, if the difference between consecutive elements is 1, as</p>

<de>.</p>

<p>If <code class="code"><var class="Arg">first</var> > <var class="Arg">last</var></code>, <code class="code">[ <var class="Arg">first</var> .. <var class="Arg">last</var> ]</code> is the empty list, which by definition is also a range; also, if <code class="code"><var class="Arg">second</var> > <var class="Arg">first</var> > <var class="Arg">last</var></code> or <code class="code"><var class="Arg">second</var> < <var class="Arg">first</var> < <var class="Arg">last</var></code>, then <code class="code">[ <var class="Arg">first</var>, <var class="Arg">second</var> .. <var class="Arg">last</var> ]</code> is the empty list. If <code class="code"><var class="Arg">first</var> = <var class="Arg">last</var></code>, <code class="code">[ <var <

<p>Currently, the integers <var class="Arg">first</var>, <var class="Arg">second</var> and <var class="Arg">last</var> and the length of a range must be <em>small integers</em> as java.lang.StringIndexOutOfBoundsException: Index 182 out of bounds for length 115

<p>Note also that a range is just a special case of a list. Thus you can access elements in a range (see <a href="chap21.html#X7921047F83F5FA28"><span class="RefLink">21.3</span></a>), test for membership etc. You can even assign to such a range if it is mutable (see <a href="chap21.html#X8611EF768210625B"><span  4  ,[,2][,]  , ]]


d class=example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">r := [10..20];</span>
[ 10 .. 20 ]
<span class="GAPprompt">gap></span> <span class="GAPinputjava.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 96
11
<span class="GAPprompt">gap></span> <span class="GAPinput">r[3];</span>
12
<span class="GAPprompt">gap></span> <span class="GAPinput">17 in r;</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput"># r still is a range but is now represented as a plain list</span>
<span class="GAPprompt">gap></span> <span 
[ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRange(r);</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput"># r is no longer a range</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">r[12] := 25;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRange(r);</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">r := [1,3..17];</span>
]
<span class="GAPprompt">gap></span> <span class="GAPinput">Length( r );</span>
9
s =GAPprompt>ap;<span> < =GAPinput">r[4];</span>
7
<span class="GAPprompt">gap></span> <span class="GAPinput">r := [0,-1..-9];</span>
[ 0, -1 .. -9 ]
<pan GAPprompt"gap&t<span <pan class="GAPinput">r[5];</span>
-4
<=GAPprompt>&;/ span =java.lang.StringIndexOutOfBoundsException: Range [61, 60) out of bounds for length 89
Error, Range: <last>-<first
</pre></<p>code class="code">[ <var class="Arg">first</var>, <var class="Arg">second</var> .. <var class="Arg">last</var> ]</code></p>

<p>Most often ranges are used in connection with the <code class="keyw">for</code>-loop see <a href="chap4.html#X78783E777867638A"><span class="RefLink">4.15-6</span></a>). Here the construct</p>

<p><code class="code">for <var class="Arg">var</var> in [ <var class="Arg">first</var> .. <var class="Arg">last</var> ] do <var class="Arg">statements</var> od</code></p>

<p>replaces the</p>

<p><code class="code">for <var class="Arg">var</var> from <var class="Arg">first</var> to <var class="Arg">last</var> do <var class="Arg">statements</var> od</code></p>

<p>which is more usual in other programming languages.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">s := [];; for i in [10..20] do Add( s, i^2 ); od; s;</span>
[ 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400 ]
</pre></div>

<p>Note that a range with <code class="code"><var class="Arg">last</var> >= <var class="Arg">first</var></code> is at the same time also a proper set (see <a href="chap21.html#X80ABC25582343910"><span class="RefLink">21.19</span></a>), because it contains no holes or duplicates and is sorted, and also a row vector (see <a href="chap23.html#X82C7E6CF7BA03391"><span class="RefLink">23</span></a>), because it contains no holes and all elements are integers.</p>

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

<h5>21.22-1 IsRange

<lass="tdleft"><code "unc>&8227;IsRange</ode> <var class">bj/var>)<td>td "tdright"(nbsp; <td<tr<table>/div>
<p>tests if the object <var class="Arg">obj</var> is a range, i.e. is a dense list of integers that is also a range (see <a href="chap21.html#X79596BDE7CAF8491"><span class="RefLink">21.22</span></a> for a definition of <q>range</q>).</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRange( [1,2,3] );  IsRange( [7,5,3,1] );</span>
true
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRange( [1 .. 3] );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRange( [1,2,4,5] );  IsRange( [1,,3,,5,,7] );</span>
false
false
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRange( [] );  IsRange( [1] );</span>
true
true
</pre></div>

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

<h5>21.22-2 IsRangeRep</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; IsRangeRep</code>( <var class="Arg">obj</var> )</td><td class="tdright">( representation )</td></tr></table></div>
<p>Tests whether <var class="Arg">obj</var> is represented as a range, that is by internally storing only the first value, the in- or decrement, and the last value of the range.</p>

<p>To test whether a list is a range in the mathematical sense see <code class="func">IsRange</code> (<a href="chap21.html#X86DDC2FF7A50FBEE"><span class="RefLink">21.22-1</span></a>).</p>

<p>Lists created by the syntactic construct <code class="code">[ <var class="Arg">first</var>, <var class="Arg">second</var> .. <var class="Arg">last</var> ]</code>, see <a href="chap21.html#X79596BDE7CAF8491"><span class="RefLink">21.22</span></a>, are in <code class="func">IsRangeRep</code>.</p>

<p>Note that if you modify an <code class="func">IsRangeRep</code> object by assigning to one of its entries, or by using <code class="func">Add</code> (<a href="chap21.html#X795EC9D67E34DAB0"><span class="RefLink">21.4-2</span></a>) or <code class="func">Append</code> (<a href="chap21.html#X79E31DB27C82D6E1"><span class="RefLink">21.4-5</span></a>), then the range may be converted into a plain list, even though the resulting list may still be a range, mathematically.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRangeRep( [1 .. 3] );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRangeRep( [1, 2, 3] );</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">l := [1..3];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">l[1] := 1;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">l;</span>
[ 1, 2, 3 ]
</pre></div>

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

<h5>21.22-3 ConvertToRangeRep</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; ConvertToRangeRep</code>( <var class="Arg">list</var> )</td><java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<p>For some lists the <strong class="pkg">GAP</strong> kernel knows that they are in fact ranges. Those lists are represented internally in a compact way, namely in <code class="func">IsRangeRep</code> (<a href="chap21.html#X83896BC481536B07"><span class="RefLink">21.22-2

<p>If <var p>Lists created thesyntactic <java.lang.StringIndexOutOfBoundsException: Range [50, 49) out of bounds for length 298


<div class="example"><pre>
<span classc""I( [1. 3]);/span>
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">ConvertToRangeRep( r );  r;</span>
[ 1 .. 10 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">l:java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
   java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
</spanGjava.lang.StringIndexOutOfBoundsException: Range [24, 22) out of bounds for length 82

<p><a id="X7EA3ACE27E43D174" name="X7EA3ACE27E43D174"></a></p[12 

<h4

<> <menumerator</em> is an immutable list that need not store its elements explicitly but knows, from a set of basic data, how to determine the <span class="SimpleMath">i</span>-th element and the position of a given object. A typical example of this is a vector space over a finite field with <span class="SimpleMath">q</span> elements for which it is very easy to enumerate all elements using <span class="SimpleMath">q</span>-adic expansions of integers.</p>

<p>Using this enumeration can be even quicker than a binary search in a sorted list of vectors, see <code class="func">IsQuickPositionList</code> (<a href="chap21.html#X7BB462C17962647F"><span class="RefLink">21.23-1</span></a>).</p>

<p>On the one hand, element access to an enumerator may take more time than element access to an internally represented list containing the same elements. On the other hand, an enumerator may save a vast amount of memory. Take for example a permutation group of size a few millions. Even for moderate degree it is unlikely that a list of all its elements will fit into memory whereas it is no problem to construct an enumerator from a stabilizer chain (see <a href="chap43.html#X7FA58C3A8283F3BD"><span class="RefLink">43.6</span></a>).</p>

<p>There are situations where one only wants to loop over the elements of a domain, without using the special facilities of an enumerator, namely the particular order of elements and the possibility to find the position of java.lang.StringIndexOutOfBoundsException: Index 230 out of bounds for length 0

<p>The functions <code class="func">Enumerator</code> (<a href="chap30.html#X7EF8910F82B45EC7"><span class="RefLink">30.3-2</span></a>) and <code class="func"<

<p>Also enumerators for non-domains can be implemented via <code class="func">EnumeratorByFunctions</code> (<a href="chap30.html#java.lang.StringIndexOutOfBoundsException: Index 131 out of bounds for length 55

<p><a id="X7BB462C17962647F" java.lang.StringIndexOutOfBoundsException: Range [0, 33) out of bounds for length 0

<h5>21.23

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; IsQuickPositionList</code>( <var class="Arg">list</var> )</td><td class="tdright">( filter )</td></tr></table></div>
<>Thisfilter  thataposition in<ar =A>list/>    about 5 or6element  <smaller/> this  case   be  use<codeclass="unc"Position<java.lang.StringIndexOutOfBoundsException: Range [228, 227) out of bounds for length 433

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

<h4>21.24 <span class="Heading">Plain Lists</span></h4>

<p>Plain lists are the default kind of lists in <strong class=

<p>Typical situations where the representation matters

<p><a id="X8438CB908367254C" name="

<> bit ordered liststorepresent of < =Argl/var.<>

<div class="func"><table class="func" width="100 /java.lang.StringIndexOutOfBoundsException: Index 114 out of bounds for length 114
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 332

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

<h5>21.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"</ody>
<p><strong class="pkg">GAP</strong> lists created by entering comma separated values in square brackets are usually represented internally as so-called <em>plain lists</em>. Other representations of lists are <code class="func">IsBlistRep</code> (<a href="chap22.html#X8453ADDA810B4C03"><span class="RefLink">22.5-1</span></a>), <code class="func">IsRangeRep</code> (<a href="chap21.html#X83896BC481536B07"><span class="RefLink">21.22-2</span></a>), <code class="func">IsStringRep</code> (<a href="chap27.html#X7A17EDF8785C9F58"><span class="RefLink">27.4-1</span></a>), or the ones that are chosen for implementing enumerators, see Section <a href="chap21.html#X7EA3ACE27E43D174"><span class="RefLink">21.23</span></a>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsPlistRep( [ 1, 2, 3 ] );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsPlistRep( "abc" );</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">IsPlistRep( [ 1 .. 5 ] );</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">IsPlistRep( BlistList( [ 1 .. 5 ], [ 1 ] ) );</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">IsPlistRep( 0 );</span>
false
</pre></div>


<java.lang.StringIndexOutOfBoundsException: Range [234, 4) out of bounds for length 253


<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<span class=GAPprompt>ap&&lt;span><class="APinput>sPlistRep  1,2 3  )<sjava.lang.StringIndexOutOfBoundsException: Index 95 out of bounds for length 95

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

Messung V0.5 in Prozent
C=99 H=99 G=98

¤ Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.0.302Bemerkung:  ¤

*Eine klare Vorstellung vom Zielzustand






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1128594
#Domains=1976912