<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<!-- %% -->
<!-- %A  rational.msk                GAP documentation            Martin Schönert -->
<!-- %% -->
<!-- %A  @(#)<M>Id: rational.msk,v 1.8 2003/09/05 07:54:50 gap Exp </M> -->
<!-- %% -->
<!-- %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&nbsp;<Ref Chap="Integers"/>).
On the other hand it is the prime field of the fields of characteristic zero
(see chapter&nbsp;<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 Func="Random" Label="for integers"/> for details.
(Also see&nbsp;<Ref Func="Random" Label="for a list or collection"/>.)
</Description>
</ManSection>

</Section>
</Chapter>

