/usr/share/gap/doc/ref/chap20.html is in gap-doc 4r6p5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | <?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 20: Booleans</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="chap20" onload="jscontent()">
<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a> <a href="chap1.html">1</a> <a href="chap2.html">2</a> <a href="chap3.html">3</a> <a href="chap4.html">4</a> <a href="chap5.html">5</a> <a href="chap6.html">6</a> <a href="chap7.html">7</a> <a href="chap8.html">8</a> <a href="chap9.html">9</a> <a href="chap10.html">10</a> <a href="chap11.html">11</a> <a href="chap12.html">12</a> <a href="chap13.html">13</a> <a href="chap14.html">14</a> <a href="chap15.html">15</a> <a href="chap16.html">16</a> <a href="chap17.html">17</a> <a href="chap18.html">18</a> <a href="chap19.html">19</a> <a href="chap20.html">20</a> <a href="chap21.html">21</a> <a href="chap22.html">22</a> <a href="chap23.html">23</a> <a href="chap24.html">24</a> <a href="chap25.html">25</a> <a href="chap26.html">26</a> <a href="chap27.html">27</a> <a href="chap28.html">28</a> <a href="chap29.html">29</a> <a href="chap30.html">30</a> <a href="chap31.html">31</a> <a href="chap32.html">32</a> <a href="chap33.html">33</a> <a href="chap34.html">34</a> <a href="chap35.html">35</a> <a href="chap36.html">36</a> <a href="chap37.html">37</a> <a href="chap38.html">38</a> <a href="chap39.html">39</a> <a href="chap40.html">40</a> <a href="chap41.html">41</a> <a href="chap42.html">42</a> <a href="chap43.html">43</a> <a href="chap44.html">44</a> <a href="chap45.html">45</a> <a href="chap46.html">46</a> <a href="chap47.html">47</a> <a href="chap48.html">48</a> <a href="chap49.html">49</a> <a href="chap50.html">50</a> <a href="chap51.html">51</a> <a href="chap52.html">52</a> <a href="chap53.html">53</a> <a href="chap54.html">54</a> <a href="chap55.html">55</a> <a href="chap56.html">56</a> <a href="chap57.html">57</a> <a href="chap58.html">58</a> <a href="chap59.html">59</a> <a href="chap60.html">60</a> <a href="chap61.html">61</a> <a href="chap62.html">62</a> <a href="chap63.html">63</a> <a href="chap64.html">64</a> <a href="chap65.html">65</a> <a href="chap66.html">66</a> <a href="chap67.html">67</a> <a href="chap68.html">68</a> <a href="chap69.html">69</a> <a href="chap70.html">70</a> <a href="chap71.html">71</a> <a href="chap72.html">72</a> <a href="chap73.html">73</a> <a href="chap74.html">74</a> <a href="chap75.html">75</a> <a href="chap76.html">76</a> <a href="chap77.html">77</a> <a href="chap78.html">78</a> <a href="chap79.html">79</a> <a href="chap80.html">80</a> <a href="chap81.html">81</a> <a href="chap82.html">82</a> <a href="chap83.html">83</a> <a href="chap84.html">84</a> <a href="chap85.html">85</a> <a href="chap86.html">86</a> <a href="chap87.html">87</a> <a href="chapBib.html">Bib</a> <a href="chapInd.html">Ind</a> </div>
<div class="chlinkprevnexttop"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap19.html">[Previous Chapter]</a> <a href="chap21.html">[Next Chapter]</a> </div>
<p id="mathjaxlink" class="pcenter"><a href="chap20_mj.html">[MathJax on]</a></p>
<p><a id="X787B4AB77A2F5E14" name="X787B4AB77A2F5E14"></a></p>
<div class="ChapSects"><a href="chap20.html#X787B4AB77A2F5E14">20 <span class="Heading">Booleans</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap20.html#X87F9AF65832E7AD2">20.1 <span class="Heading">IsBool (Filter)</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap20.html#X7D58580284CF7894">20.1-1 IsBool</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap20.html#X85E648AA8414F303">20.2 <span class="Heading">Fail (Variable)</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap20.html#X8294AAC9860E87E5">20.2-1 fail</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap20.html#X862F17B68465B399">20.3 <span class="Heading">Comparisons of Booleans</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap20.html#X79305F9780394190">20.3-1 <span class="Heading">Equality and inequality of Booleans</span></a>
</span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap20.html#X7FEF019482AF5923">20.3-2 <span class="Heading">Ordering of Booleans</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap20.html#X79AD41A185FD7213">20.4 <span class="Heading">Operations for Booleans</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap20.html#X7DFE7E518088AA89">20.4-1 <span class="Heading">Logical disjunction</span></a>
</span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap20.html#X7A64D25F804973CD">20.4-2 <span class="Heading">Logical conjunction</span></a>
</span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap20.html#X84F5034185D7EC3C">20.4-3 <span class="Heading">Logical negation</span></a>
</span>
</div></div>
</div>
<h3>20 <span class="Heading">Booleans</span></h3>
<p>The two main <em>boolean</em> values are <code class="keyw">true</code> and <code class="keyw">false</code>. They stand for the <em>logical</em> values of the same name. They appear as values of the conditions in <code class="keyw">if</code>-statements and <code class="keyw">while</code>-loops. Booleans are also important as return values of <em>filters</em> (see <a href="chap13.html#X84EFA4C07D4277BB"><span class="RefLink">13.2</span></a>) such as <code class="func">IsFinite</code> (<a href="chap30.html#X808A4061809A6E67"><span class="RefLink">30.4-2</span></a>) and <code class="func">IsBool</code> (<a href="chap20.html#X7D58580284CF7894"><span class="RefLink">20.1-1</span></a>). Note that it is a convention that the name of a function that returns <code class="keyw">true</code> or <code class="keyw">false</code> according to the outcome, starts with <code class="code">Is</code>.</p>
<p>For technical reasons, also the value <code class="keyw">fail</code> (see <a href="chap20.html#X85E648AA8414F303"><span class="RefLink">20.2</span></a>) is regarded as a boolean.</p>
<p><a id="X87F9AF65832E7AD2" name="X87F9AF65832E7AD2"></a></p>
<h4>20.1 <span class="Heading">IsBool (Filter)</span></h4>
<p><a id="X7D58580284CF7894" name="X7D58580284CF7894"></a></p>
<h5>20.1-1 IsBool</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsBool</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<p>tests whether <var class="Arg">obj</var> is <code class="keyw">true</code>, <code class="keyw">false</code> or <code class="keyw">fail</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsBool( true ); IsBool( false ); IsBool( 17 );</span>
true
true
false
</pre></div>
<p><a id="X85E648AA8414F303" name="X85E648AA8414F303"></a></p>
<h4>20.2 <span class="Heading">Fail (Variable)</span></h4>
<p><a id="X8294AAC9860E87E5" name="X8294AAC9860E87E5"></a></p>
<h5>20.2-1 fail</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ fail</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>The value <code class="keyw">fail</code> is used to indicate situations when an operation could not be performed for the given arguments, either because of shortcomings of the arguments or because of restrictions in the implementation or computability. So for example <code class="func">Position</code> (<a href="chap21.html#X79975EC6783B4293"><span class="RefLink">21.16-1</span></a>) will return <code class="keyw">fail</code> if the point searched for is not in the list.</p>
<p><code class="keyw">fail</code> is simply an object that is different from every other object than itself.</p>
<p>For technical reasons, <code class="keyw">fail</code> is a boolean value. But note that <code class="keyw">fail</code> cannot be used to form boolean expressions with <code class="keyw">and</code>, <code class="keyw">or</code>, and <code class="keyw">not</code> (see <a href="chap20.html#X79AD41A185FD7213"><span class="RefLink">20.4</span></a> below), and <code class="keyw">fail</code> cannot appear in boolean lists (see Chapter <a href="chap22.html#X7AC531DD79B6938E"><span class="RefLink">22</span></a>).</p>
<p><a id="X862F17B68465B399" name="X862F17B68465B399"></a></p>
<h4>20.3 <span class="Heading">Comparisons of Booleans</span></h4>
<p><a id="X79305F9780394190" name="X79305F9780394190"></a></p>
<h5>20.3-1 <span class="Heading">Equality and inequality of Booleans</span></h5>
<p><code class="code"><var class="Arg">bool1</var> = <var class="Arg">bool2</var></code></p>
<p><code class="code"><var class="Arg">bool1</var> <> <var class="Arg">bool2</var></code></p>
<p>The equality operator <code class="code">=</code> evaluates to <code class="keyw">true</code> if the two boolean values <var class="Arg">bool1</var> and <var class="Arg">bool2</var> are equal, i.e., both are <code class="keyw">true</code> or both are <code class="keyw">false</code> or both <code class="keyw">fail</code>, and <code class="keyw">false</code> otherwise. The inequality operator <code class="code"><></code> evaluates to <code class="keyw">true</code> if the two boolean values <var class="Arg">bool1</var>, <var class="Arg">bool2</var> are different, and <code class="keyw">false</code> otherwise. This operation is also called the <em>exclusive or</em>, because its value is <code class="keyw">true</code> if exactly one of <var class="Arg">bool1</var> or <var class="Arg">bool2</var> is <code class="keyw">true</code>.</p>
<p>You can compare boolean values with objects of other types. Of course they are never equal.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">true = false;</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">false = (true = fail);</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">true <> 17;</span>
true
</pre></div>
<p><a id="X7FEF019482AF5923" name="X7FEF019482AF5923"></a></p>
<h5>20.3-2 <span class="Heading">Ordering of Booleans</span></h5>
<p><var class="Arg">bool1</var> <code class="code"><</code> <var class="Arg">bool2</var></p>
<p>The ordering of boolean values is defined by <code class="keyw">true</code> <code class="code"><</code> <code class="keyw">false</code> <code class="code"><</code> <code class="keyw">fail</code>. For the comparison of booleans with other <strong class="pkg">GAP</strong> objects, see Section <a href="chap4.html#X7A274A1F8553B7E6"><span class="RefLink">4.12</span></a>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">true < false; fail >= false;</span>
true
true
</pre></div>
<p><a id="X79AD41A185FD7213" name="X79AD41A185FD7213"></a></p>
<h4>20.4 <span class="Heading">Operations for Booleans</span></h4>
<p>The following boolean operations are only applicable to <code class="keyw">true</code> and <code class="keyw">false</code>.</p>
<p><a id="X7DFE7E518088AA89" name="X7DFE7E518088AA89"></a></p>
<h5>20.4-1 <span class="Heading">Logical disjunction</span></h5>
<p><var class="Arg">bool1</var> <code class="keyw">or</code> <var class="Arg">bool2</var></p>
<p>The logical operator <code class="keyw">or</code> evaluates to <code class="keyw">true</code> if at least one of the two boolean operands <var class="Arg">bool1</var> and <var class="Arg">bool2</var> is <code class="keyw">true</code>, and to <code class="keyw">false</code> otherwise.</p>
<p><code class="keyw">or</code> first evaluates <var class="Arg">bool1</var>. If the value is neither <code class="keyw">true</code> nor <code class="keyw">false</code> an error is signalled. If the value is <code class="keyw">true</code>, then <code class="keyw">or</code> returns <code class="keyw">true</code> <em>without</em> evaluating <var class="Arg">bool2</var>. If the value is <code class="keyw">false</code>, then <code class="keyw">or</code> evaluates <var class="Arg">bool2</var>. Again, if the value is neither <code class="keyw">true</code> nor <code class="keyw">false</code> an error is signalled. Otherwise <code class="keyw">or</code> returns the value of <var class="Arg">bool2</var>. This <em>short-circuited</em> evaluation is important if the value of <var class="Arg">bool1</var> is <code class="keyw">true</code> and evaluation of <var class="Arg">bool2</var> would take much time or cause an error.</p>
<p><code class="keyw">or</code> is associative, i.e., it is allowed to write <var class="Arg">b1</var> <code class="keyw">or</code> <var class="Arg">b2</var> <code class="keyw">or</code> <var class="Arg">b3</var>, which is interpreted as (<var class="Arg">b1</var> <code class="keyw">or</code> <var class="Arg">b2</var>) <code class="keyw">or</code> <var class="Arg">b3</var>. <code class="keyw">or</code> has the lowest precedence of the logical operators. All logical operators have lower precedence than the comparison operators <code class="code">=</code>, <code class="code"><</code>, <code class="keyw">in</code>, etc.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">true or false;</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">false or false;</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">i := -1;; l := [1,2,3];;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">if i <= 0 or l[i] = false then # this does not cause an error,</span>
<span class="GAPprompt">></span> <span class="GAPinput"> Print("aha\n"); fi; # because `l[i]' is not evaluated</span>
aha
</pre></div>
<p><a id="X7A64D25F804973CD" name="X7A64D25F804973CD"></a></p>
<h5>20.4-2 <span class="Heading">Logical conjunction</span></h5>
<p><var class="Arg">bool1</var> <code class="keyw">and</code> <var class="Arg">bool2</var></p>
<p><var class="Arg">fil1</var> <code class="keyw">and</code> <var class="Arg">fil2</var></p>
<p>The logical operator <code class="keyw">and</code> evaluates to <code class="keyw">true</code> if both boolean operands <var class="Arg">bool1</var>, <var class="Arg">bool2</var> are <code class="keyw">true</code>, and to <code class="keyw">false</code> otherwise.</p>
<p><code class="keyw">and</code> first evaluates <var class="Arg">bool1</var>. If the value is neither <code class="keyw">true</code> nor <code class="keyw">false</code> an error is signalled. If the value is <code class="keyw">false</code>, then <code class="keyw">and</code> returns <code class="keyw">false</code> <em>without</em> evaluating <var class="Arg">bool2</var>. If the value is <code class="keyw">true</code>, then <code class="keyw">and</code> evaluates <var class="Arg">bool2</var>. Again, if the value is neither <code class="keyw">true</code> nor <code class="keyw">false</code> an error is signalled. Otherwise <code class="keyw">and</code> returns the value of <var class="Arg">bool2</var>. This <em>short-circuited</em> evaluation is important if the value of <var class="Arg">bool1</var> is <code class="keyw">false</code> and evaluation of <var class="Arg">bool2</var> would take much time or cause an error.</p>
<p><code class="keyw">and</code> is associative, i.e., it is allowed to write <var class="Arg">b1</var> <code class="keyw">and</code> <var class="Arg">b2</var> <code class="keyw">and</code> <var class="Arg">b3</var>, which is interpreted as (<var class="Arg">b1</var> <code class="keyw">and</code> <var class="Arg">b2</var>) <code class="keyw">and</code> <var class="Arg">b3</var>. <code class="keyw">and</code> has higher precedence than the logical <code class="keyw">or</code> operator, but lower than the unary logical <code class="keyw">not</code> operator. All logical operators have lower precedence than the comparison operators <code class="code">=</code>, <code class="code"><</code>, <code class="keyw">in</code>, etc.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">true and false;</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">true and true;</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">false and 17; # does not cause error, because 17 is never looked at</span>
false
</pre></div>
<p><code class="keyw">and</code> can also be applied to filters. It returns a filter that when applied to some argument <var class="Arg">x</var>, tests <var class="Arg">fil1</var><span class="SimpleMath">(x)</span> <code class="keyw">and</code> <var class="Arg">fil2</var><span class="SimpleMath">(x)</span>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">andfilt:= IsPosRat and IsInt;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">andfilt( 17 ); andfilt( 1/2 );</span>
true
false
</pre></div>
<p><a id="X84F5034185D7EC3C" name="X84F5034185D7EC3C"></a></p>
<h5>20.4-3 <span class="Heading">Logical negation</span></h5>
<p><code class="keyw">not</code> <var class="Arg">bool</var></p>
<p>The logical operator <code class="keyw">not</code> returns <code class="keyw">true</code> if the boolean value <var class="Arg">bool</var> is <code class="keyw">false</code>, and <code class="keyw">true</code> otherwise. An error is signalled if <var class="Arg">bool</var> does not evaluate to <code class="keyw">true</code> or <code class="keyw">false</code>.</p>
<p><code class="keyw">not</code> has higher precedence than the other logical operators, <code class="keyw">or</code> and <code class="keyw">and</code>. All logical operators have lower precedence than the comparison operators <code class="code">=</code>, <code class="code"><</code>, <code class="keyw">in</code>, etc.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">true and false;</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">not true;</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">not false;</span>
true
</pre></div>
<div class="chlinkprevnextbot"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap19.html">[Previous Chapter]</a> <a href="chap21.html">[Next Chapter]</a> </div>
<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a> <a href="chap1.html">1</a> <a href="chap2.html">2</a> <a href="chap3.html">3</a> <a href="chap4.html">4</a> <a href="chap5.html">5</a> <a href="chap6.html">6</a> <a href="chap7.html">7</a> <a href="chap8.html">8</a> <a href="chap9.html">9</a> <a href="chap10.html">10</a> <a href="chap11.html">11</a> <a href="chap12.html">12</a> <a href="chap13.html">13</a> <a href="chap14.html">14</a> <a href="chap15.html">15</a> <a href="chap16.html">16</a> <a href="chap17.html">17</a> <a href="chap18.html">18</a> <a href="chap19.html">19</a> <a href="chap20.html">20</a> <a href="chap21.html">21</a> <a href="chap22.html">22</a> <a href="chap23.html">23</a> <a href="chap24.html">24</a> <a href="chap25.html">25</a> <a href="chap26.html">26</a> <a href="chap27.html">27</a> <a href="chap28.html">28</a> <a href="chap29.html">29</a> <a href="chap30.html">30</a> <a href="chap31.html">31</a> <a href="chap32.html">32</a> <a href="chap33.html">33</a> <a href="chap34.html">34</a> <a href="chap35.html">35</a> <a href="chap36.html">36</a> <a href="chap37.html">37</a> <a href="chap38.html">38</a> <a href="chap39.html">39</a> <a href="chap40.html">40</a> <a href="chap41.html">41</a> <a href="chap42.html">42</a> <a href="chap43.html">43</a> <a href="chap44.html">44</a> <a href="chap45.html">45</a> <a href="chap46.html">46</a> <a href="chap47.html">47</a> <a href="chap48.html">48</a> <a href="chap49.html">49</a> <a href="chap50.html">50</a> <a href="chap51.html">51</a> <a href="chap52.html">52</a> <a href="chap53.html">53</a> <a href="chap54.html">54</a> <a href="chap55.html">55</a> <a href="chap56.html">56</a> <a href="chap57.html">57</a> <a href="chap58.html">58</a> <a href="chap59.html">59</a> <a href="chap60.html">60</a> <a href="chap61.html">61</a> <a href="chap62.html">62</a> <a href="chap63.html">63</a> <a href="chap64.html">64</a> <a href="chap65.html">65</a> <a href="chap66.html">66</a> <a href="chap67.html">67</a> <a href="chap68.html">68</a> <a href="chap69.html">69</a> <a href="chap70.html">70</a> <a href="chap71.html">71</a> <a href="chap72.html">72</a> <a href="chap73.html">73</a> <a href="chap74.html">74</a> <a href="chap75.html">75</a> <a href="chap76.html">76</a> <a href="chap77.html">77</a> <a href="chap78.html">78</a> <a href="chap79.html">79</a> <a href="chap80.html">80</a> <a href="chap81.html">81</a> <a href="chap82.html">82</a> <a href="chap83.html">83</a> <a href="chap84.html">84</a> <a href="chap85.html">85</a> <a href="chap86.html">86</a> <a href="chap87.html">87</a> <a href="chapBib.html">Bib</a> <a href="chapInd.html">Ind</a> </div>
<hr />
<p class="foot">generated by <a href="http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>
|