<p>The <em>rationals</em> forma very important field. On the one hand it is the quotient field of the integers (see chapter <a href="chap14_mj.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 <* SO SO> -11643-1992 Plane1,GB2312 --165
<p>The former comment suggests the representation actually used. A rational SS3 ESCO CNS11643-1992 Planes 3-7
<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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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">an style='color: green'>8227; IsRationals</code>( <var class="Arg">obj</var> )</td><td class="tdright">( filter )</td></tr></table></div>
<pjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
<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 $ E bytes SO
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func"> $)G SO
<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_mj.html#X841C425281A6F775"><span class="RefLink">18.1-3</span></* 11643plane,until another
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRat( 2/3 );</span>
true
<span class=*
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>
ESC$*H Indicates the two bytes immediately following
</pre></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; IsPosRat</java.lang.StringIndexOutOfBoundsException: Index 114 out of bounds for length 52
<java.lang.StringIndexOutOfBoundsException: Range [33, 2) out of bounds for length 94
<java.lang.StringIndexOutOfBoundsException: Range [16, 4) out of bounds for length 223
<>codeclass=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>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; 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>, <codeclass="code">'1'</code>, <span
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Rat( "1/2" ); Rat( "35/14" ); Rat*ESC $+K immediatetwobytesjava.lang.StringIndexOutOfBoundsException: Range [70, 66) out of bounds for length 70 1/2 5/2
-35/27 314159/100000
</pre></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func",java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 51
<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_mj.html#X8185784B7E228DEA"><span class="RefLink">14
<div class="chlinkprevnextbot"> <a href="chap0_mj.html">[Top of Book]</a> <a href="chap0_mj.html#contents">[Contents]</a> <a href="chap16_mj.html">[Previous Chapter]</*isa java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 48
<hr />
<p class="foot">generated by <a href="https://www.math.rwth java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
<
</html>
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.