/usr/share/gap/doc/ref/chap17.html is in gap-doc 4r8p8-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 | <?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 17: Rational Numbers</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="chap17" 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="chap16.html">[Previous Chapter]</a> <a href="chap18.html">[Next Chapter]</a> </div>
<p id="mathjaxlink" class="pcenter"><a href="chap17_mj.html">[MathJax on]</a></p>
<p><a id="X87003045878E74DF" name="X87003045878E74DF"></a></p>
<div class="ChapSects"><a href="chap17.html#X87003045878E74DF">17 <span class="Heading">Rational Numbers</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap17.html#X7A76497986DA921F">17.1 <span class="Heading">Rationals: Global Variables</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap17.html#X7B6029D18570C08A">17.1-1 Rationals</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap17.html#X826E2AA88679B3DF">17.2 <span class="Heading">Elementary Operations for Rationals</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap17.html#X7ED018F5794935F7">17.2-1 IsRat</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap17.html#X7BD6E170840F045D">17.2-2 IsPosRat</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap17.html#X81179AC87AC951A8">17.2-3 IsNegRat</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap17.html#X7D830E7482E7F528">17.2-4 NumeratorRat</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap17.html#X81F6B5877A81E727">17.2-5 DenominatorRat</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap17.html#X7EB4C646806A2BDE">17.2-6 Rat</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap17.html#X7C8F8693825C28A4">17.2-7 Random</a></span>
</div></div>
</div>
<h3>17 <span class="Heading">Rational Numbers</span></h3>
<p>The <em>rationals</em> form a very important field. On the one hand it is the quotient field of the integers (see chapter <a href="chap14.html#X853DF11B80068ED5"><span class="RefLink">14</span></a>). On the other hand it is the prime field of the fields of characteristic zero (see chapter <a href="chap60.html#X80510B5880521FDC"><span class="RefLink">60</span></a>).</p>
<p>The former comment suggests the representation actually used. A rational is represented as a pair of integers, called <em>numerator</em> and <em>denominator</em>. Numerator and denominator are <em>reduced</em>, i.e., their greatest common divisor is 1. If the denominator is 1, the rational is in fact an integer and is represented as such. The numerator holds the sign of the rational, thus the denominator is always positive.</p>
<p>Because the underlying integer arithmetic can compute with arbitrary size integers, the rational arithmetic is always exact, even for rationals whose numerators and denominators have thousands of digits.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">2/3;</span>
2/3
<span class="GAPprompt">gap></span> <span class="GAPinput">66/123; # numerator and denominator are made relatively prime</span>
22/41
<span class="GAPprompt">gap></span> <span class="GAPinput">17/-13; # the numerator carries the sign;</span>
-17/13
<span class="GAPprompt">gap></span> <span class="GAPinput">121/11; # rationals with denominator 1 (when canceled) are integers</span>
11
</pre></div>
<p><a id="X7A76497986DA921F" name="X7A76497986DA921F"></a></p>
<h4>17.1 <span class="Heading">Rationals: Global Variables</span></h4>
<p><a id="X7B6029D18570C08A" name="X7B6029D18570C08A"></a></p>
<h5>17.1-1 Rationals</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Rationals</code></td><td class="tdright">( global variable )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsRationals</code>( <var class="Arg">obj</var> )</td><td class="tdright">( filter )</td></tr></table></div>
<p><code class="func">Rationals</code> is the field <span class="SimpleMath">ℚ</span> of rational integers, as a set of cyclotomic numbers, see Chapter <a href="chap18.html#X7DFC03C187DE4841"><span class="RefLink">18</span></a> for basic operations, Functions for the field <code class="func">Rationals</code> can be found in the chapters <a href="chap58.html#X80A8E676814A19FD"><span class="RefLink">58</span></a> and <a href="chap60.html#X80510B5880521FDC"><span class="RefLink">60</span></a>.</p>
<p><code class="func">IsRationals</code> returns <code class="keyw">true</code> for a prime field that consists of cyclotomic numbers –for example the <strong class="pkg">GAP</strong> object <code class="func">Rationals</code>– and <code class="keyw">false</code> for all other <strong class="pkg">GAP</strong> objects.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Size( Rationals ); 2/3 in Rationals;</span>
infinity
true
</pre></div>
<p><a id="X826E2AA88679B3DF" name="X826E2AA88679B3DF"></a></p>
<h4>17.2 <span class="Heading">Elementary Operations for Rationals</span></h4>
<p><a id="X7ED018F5794935F7" name="X7ED018F5794935F7"></a></p>
<h5>17.2-1 IsRat</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsRat</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<p>Every rational number lies in the category <code class="func">IsRat</code>, which is a subcategory of <code class="func">IsCyc</code> (<a href="chap18.html#X841C425281A6F775"><span class="RefLink">18.1-3</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRat( 2/3 );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRat( 17/-13 );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRat( 11 );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRat( IsRat ); # `IsRat' is a function, not a rational</span>
false
</pre></div>
<p><a id="X7BD6E170840F045D" name="X7BD6E170840F045D"></a></p>
<h5>17.2-2 IsPosRat</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsPosRat</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<p>Every positive rational number lies in the category <code class="func">IsPosRat</code>.</p>
<p><a id="X81179AC87AC951A8" name="X81179AC87AC951A8"></a></p>
<h5>17.2-3 IsNegRat</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsNegRat</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<p>Every negative rational number lies in the category <code class="func">IsNegRat</code>.</p>
<p><a id="X7D830E7482E7F528" name="X7D830E7482E7F528"></a></p>
<h5>17.2-4 NumeratorRat</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NumeratorRat</code>( <var class="Arg">rat</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">NumeratorRat</code> returns the numerator of the rational <var class="Arg">rat</var>. Because the numerator holds the sign of the rational it may be any integer. Integers are rationals with denominator <span class="SimpleMath">1</span>, thus <code class="func">NumeratorRat</code> is the identity function for integers.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">NumeratorRat( 2/3 );</span>
2
<span class="GAPprompt">gap></span> <span class="GAPinput"># numerator and denominator are made relatively prime:</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">NumeratorRat( 66/123 );</span>
22
<span class="GAPprompt">gap></span> <span class="GAPinput">NumeratorRat( 17/-13 ); # numerator holds the sign of the rational</span>
-17
<span class="GAPprompt">gap></span> <span class="GAPinput">NumeratorRat( 11 ); # integers are rationals with denominator 1</span>
11
</pre></div>
<p><a id="X81F6B5877A81E727" name="X81F6B5877A81E727"></a></p>
<h5>17.2-5 DenominatorRat</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ DenominatorRat</code>( <var class="Arg">rat</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">DenominatorRat</code> returns the denominator of the rational <var class="Arg">rat</var>. Because the numerator holds the sign of the rational the denominator is always a positive integer. Integers are rationals with the denominator 1, thus <code class="func">DenominatorRat</code> returns 1 for integers.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">DenominatorRat( 2/3 );</span>
3
<span class="GAPprompt">gap></span> <span class="GAPinput"># numerator and denominator are made relatively prime:</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">DenominatorRat( 66/123 );</span>
41
<span class="GAPprompt">gap></span> <span class="GAPinput"># the denominator holds the sign of the rational:</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">DenominatorRat( 17/-13 );</span>
13
<span class="GAPprompt">gap></span> <span class="GAPinput">DenominatorRat( 11 ); # integers are rationals with denominator 1</span>
1
</pre></div>
<p><a id="X7EB4C646806A2BDE" name="X7EB4C646806A2BDE"></a></p>
<h5>17.2-6 Rat</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Rat</code>( <var class="Arg">elm</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p><code class="func">Rat</code> returns a rational number <var class="Arg">rat</var> whose meaning depends on the type of <var class="Arg">elm</var>.</p>
<p>If <var class="Arg">elm</var> is a string consisting of digits <code class="code">'0'</code>, <code class="code">'1'</code>, <span class="SimpleMath">...</span>, <code class="code">'9'</code> and <code class="code">'-'</code> (at the first position), <code class="code">'/'</code> and the decimal dot <code class="code">'.'</code> then <var class="Arg">rat</var> is the rational described by this string. The operation <code class="func">String</code> (<a href="chap27.html#X81FB5BE27903EC32"><span class="RefLink">27.7-6</span></a>) can be used to compute a string for rational numbers, in fact for all cyclotomics.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Rat( "1/2" ); Rat( "35/14" ); Rat( "35/-27" ); Rat( "3.14159" );</span>
1/2
5/2
-35/27
314159/100000
</pre></div>
<p><a id="X7C8F8693825C28A4" name="X7C8F8693825C28A4"></a></p>
<h5>17.2-7 Random</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Random</code>( <var class="Arg">Rationals</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p><code class="func">Random</code> for rationals returns pseudo random rationals which are the quotient of two random integers. See the description of <code class="func">Random</code> (<a href="chap14.html#X8185784B7E228DEA"><span class="RefLink">14.2-12</span></a>) for details. (Also see <code class="func">Random</code> (<a href="chap30.html#X7FF906E57D6936F8"><span class="RefLink">30.7-1</span></a>).)</p>
<div class="chlinkprevnextbot"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap16.html">[Previous Chapter]</a> <a href="chap18.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>
|