Rational Numbers

The rationals form a very important field. On the one hand it is the quotient field of the integers (see chapter ). On the other hand it is the prime field of the fields of characteristic zero (see chapter ).

The former comment suggests the representation actually used. A rational is represented as a pair of integers, called numerator and denominator. Numerator and denominator are reduced, 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.

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.

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
Rationals: Global Variables
<#Include Label="Rationals">

Elementary Operations for Rationals
<#Include Label="IsRat"> <#Include Label="IsPosRat"> <#Include Label="IsNegRat"> <#Include Label="NumeratorRat"> <#Include Label="DenominatorRat"> <#Include Label="Rat">

for rationals returns pseudo random rationals which are the quotient of two random integers. See the description of for details. (Also see .)