Debian Codegraph @

doc/ref/chap17.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
7 <head>
8 <title>GAP (ref) - Chapter 17: Rational Numbers</title>
9 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
10 <meta name="generator" content="GAPDoc2HTML" />
11 <link rel="stylesheet" type="text/css" href="manual.css" />
12 <script src="manual.js" type="text/javascript"></script>
13 <script type="text/javascript">overwriteStyle();</script>
14 </head>
15 <body class="chap17" onload="jscontent()">
16
17
18 <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>
19
20 <div class="chlinkprevnexttop">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp; <a href="chap0.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap16.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap18.html">[Next Chapter]</a>&nbsp; </div>
21
22 <p id="mathjaxlink" class="pcenter"><a href="chap17_mj.html">[MathJax on]</a></p>
23 <p><a id="X87003045878E74DF" name="X87003045878E74DF"></a></p>
24 <div class="ChapSects"><a href="chap17.html#X87003045878E74DF">17 <span class="Heading">Rational Numbers</span></a>
25 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap17.html#X7A76497986DA921F">17.1 <span class="Heading">Rationals: Global Variables</span></a>
26 </span>
27 <div class="ContSSBlock">
28 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap17.html#X7B6029D18570C08A">17.1-1 Rationals</a></span>
29 </div></div>
30 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap17.html#X826E2AA88679B3DF">17.2 <span class="Heading">Elementary Operations for Rationals</span></a>
31 </span>
32 <div class="ContSSBlock">
33 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap17.html#X7ED018F5794935F7">17.2-1 IsRat</a></span>
34 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap17.html#X7BD6E170840F045D">17.2-2 IsPosRat</a></span>
35 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap17.html#X81179AC87AC951A8">17.2-3 IsNegRat</a></span>
36 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap17.html#X7D830E7482E7F528">17.2-4 NumeratorRat</a></span>
37 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap17.html#X81F6B5877A81E727">17.2-5 DenominatorRat</a></span>
38 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap17.html#X7EB4C646806A2BDE">17.2-6 Rat</a></span>
39 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap17.html#X7C8F8693825C28A4">17.2-7 Random</a></span>
40 </div></div>
41 </div>
42
43 <h3>17 <span class="Heading">Rational Numbers</span></h3>
44
45 <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>
46
47 <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>
48
49 <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>
50
51
52 <div class="example"><pre>
53 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">2/3;</span>
54 2/3
55 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">66/123; # numerator and denominator are made relatively prime</span>
56 22/41
57 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">17/-13; # the numerator carries the sign;</span>
58 -17/13
59 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">121/11; # rationals with denominator 1 (when canceled) are integers</span>
60 11
61 </pre></div>
62
63 <p><a id="X7A76497986DA921F" name="X7A76497986DA921F"></a></p>
64
65 <h4>17.1 <span class="Heading">Rationals: Global Variables</span></h4>
66
67 <p><a id="X7B6029D18570C08A" name="X7B6029D18570C08A"></a></p>
68
69 <h5>17.1-1 Rationals</h5>
70
71 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Rationals</code></td><td class="tdright">(&nbsp;global variable&nbsp;)</td></tr></table></div>
72 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsRationals</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;filter&nbsp;)</td></tr></table></div>
73 <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>
74
75 <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>
76
77
78 <div class="example"><pre>
79 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Size( Rationals ); 2/3 in Rationals;</span>
80 infinity
81 true
82 </pre></div>
83
84 <p><a id="X826E2AA88679B3DF" name="X826E2AA88679B3DF"></a></p>
85
86 <h4>17.2 <span class="Heading">Elementary Operations for Rationals</span></h4>
87
88 <p><a id="X7ED018F5794935F7" name="X7ED018F5794935F7"></a></p>
89
90 <h5>17.2-1 IsRat</h5>
91
92 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsRat</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;category&nbsp;)</td></tr></table></div>
93 <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>
94
95
96 <div class="example"><pre>
97 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsRat( 2/3 );</span>
98 true
99 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsRat( 17/-13 );</span>
100 true
101 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsRat( 11 );</span>
102 true
103 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsRat( IsRat ); # `IsRat' is a function, not a rational</span>
104 false
105 </pre></div>
106
107 <p><a id="X7BD6E170840F045D" name="X7BD6E170840F045D"></a></p>
108
109 <h5>17.2-2 IsPosRat</h5>
110
111 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsPosRat</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;category&nbsp;)</td></tr></table></div>
112 <p>Every positive rational number lies in the category <code class="func">IsPosRat</code>.</p>
113
114 <p><a id="X81179AC87AC951A8" name="X81179AC87AC951A8"></a></p>
115
116 <h5>17.2-3 IsNegRat</h5>
117
118 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsNegRat</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;category&nbsp;)</td></tr></table></div>
119 <p>Every negative rational number lies in the category <code class="func">IsNegRat</code>.</p>
120
121 <p><a id="X7D830E7482E7F528" name="X7D830E7482E7F528"></a></p>
122
123 <h5>17.2-4 NumeratorRat</h5>
124
125 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; NumeratorRat</code>( <var class="Arg">rat</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
126 <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>
127
128
129 <div class="example"><pre>
130 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NumeratorRat( 2/3 );</span>
131 2
132 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput"># numerator and denominator are made relatively prime:</span>
133 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NumeratorRat( 66/123 );</span>
134 22
135 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NumeratorRat( 17/-13 ); # numerator holds the sign of the rational</span>
136 -17
137 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NumeratorRat( 11 ); # integers are rationals with denominator 1</span>
138 11
139 </pre></div>
140
141 <p><a id="X81F6B5877A81E727" name="X81F6B5877A81E727"></a></p>
142
143 <h5>17.2-5 DenominatorRat</h5>
144
145 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DenominatorRat</code>( <var class="Arg">rat</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
146 <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>
147
148
149 <div class="example"><pre>
150 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DenominatorRat( 2/3 );</span>
151 3
152 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput"># numerator and denominator are made relatively prime:</span>
153 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DenominatorRat( 66/123 );</span>
154 41
155 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput"># the denominator holds the sign of the rational:</span>
156 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DenominatorRat( 17/-13 );</span>
157 13
158 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DenominatorRat( 11 ); # integers are rationals with denominator 1</span>
159 1
160 </pre></div>
161
162 <p><a id="X7EB4C646806A2BDE" name="X7EB4C646806A2BDE"></a></p>
163
164 <h5>17.2-6 Rat</h5>
165
166 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Rat</code>( <var class="Arg">elm</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
167 <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>
168
169 <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. If <var class="Arg">elm</var> is a rational number, then <code class="code">Rat</code> returns <var class="Arg">elm</var>. 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>
170
171
172 <div class="example"><pre>
173 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Rat( "1/2" ); Rat( "35/14" ); Rat( "35/-27" ); Rat( "3.14159" );</span>
174 1/2
175 5/2
176 -35/27
177 314159/100000
178 </pre></div>
179
180 <p><a id="X7C8F8693825C28A4" name="X7C8F8693825C28A4"></a></p>
181
182 <h5>17.2-7 Random</h5>
183
184 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Random</code>( <var class="Arg">Rationals</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
185 <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-13</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>
186
187
188 <div class="chlinkprevnextbot">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp; <a href="chap0.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap16.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap18.html">[Next Chapter]</a>&nbsp; </div>
189
190
191 <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>
192
193 <hr />
194 <p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
195 </body>
196 </html>