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
|
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %A rational.xml GAP documentation Martin Schönert -->
<!-- %% -->
<!-- %% -->
<!-- %Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland -->
<!-- %Y Copyright (C) 2002 The GAP Group -->
<!-- %% -->
<Chapter Label="Rational Numbers">
<Heading>Rational Numbers</Heading>
The <E>rationals</E> form a very important field. On the one hand it is the
quotient field of the integers (see chapter <Ref Chap="Integers"/>).
On the other hand it is the prime field of the fields of characteristic zero
(see chapter <Ref Chap="Abelian Number Fields"/>).
<P/>
The former comment suggests the representation actually used.
A rational is represented as a pair of integers,
called <E>numerator</E> and <E>denominator</E>.
Numerator and denominator are <E>reduced</E>, 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/>
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/>
<Example><![CDATA[
gap> 2/3;
2/3
gap> 66/123; # numerator and denominator are made relatively prime
22/41
gap> 17/-13; # the numerator carries the sign;
-17/13
gap> 121/11; # rationals with denominator 1 (when canceled) are integers
11
]]></Example>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="sect:Rationals: Global Variables">
<Heading>Rationals: Global Variables</Heading>
<#Include Label="Rationals">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Elementary Operations for Rationals">
<Heading>Elementary Operations for Rationals</Heading>
<#Include Label="IsRat">
<#Include Label="IsPosRat">
<#Include Label="IsNegRat">
<#Include Label="NumeratorRat">
<#Include Label="DenominatorRat">
<#Include Label="Rat">
<ManSection>
<Oper Name="Random" Arg='Rationals' Label="for rationals"/>
<Description>
<Ref Oper="Random" Label="for rationals"/> for rationals returns
pseudo random rationals which are the quotient of two random integers.
See the description of <Ref Meth="Random" Label="for integers"/> for details.
(Also see <Ref Oper="Random" Label="for a list or collection"/>.)
</Description>
</ManSection>
</Section>
</Chapter>
|