The rationals form a very important field. On the one hand it is the quotient field of the integers (see Integers). On the other hand it is Subfields of Cyclotomic Fields).
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; 22/41 # numerator and denominator are made relatively prime gap> 17/-13; -17/13 # the numerator carries the sign gap> 121/11; 11 # rationals with denominator 1 (after cancelling) are integers
The first sections of this chapter describe the functions that test whether an object is a rational (see IsRat), and select the numerator and denominator of a rational (see Numerator, Denominator).
Comparisons of Rationals, and Operations for Rationals).
The GAP object
Rationals is the field domain of all rationals. All
set theoretic functions are applicable to this domain (see chapter
Domains and Set Functions for Rationals). Since
Rationals is a
field all field functions are also applicable to this domain and its
elements (see chapter Fields and Field Functions for Rationals).
All external functions are defined in the file