A variety of different types of operations are provided for rational elements including arithmetic operations, comparison and predicates and converting to a sequence.
The (integer) numerator of the rational number q in reduced form.
The (integer) denominator of the rational number q in reduced form. This will always be a positive integer.
> Numerator(10/-4); -5 > Denominator(10/-4); 2
Returns true if the rational number q is an element of the ring of integers, false otherwise.
The complex conjugate of q, which will be the rational number q itself.
The conjugate of q, which will be the rational number q itself.
The norm (in Q) of q, which will be the rational number q itself.
The trace (in Q) of q, which will be the rational number q itself.
Returns the minimal polynomial of the rational number q, which is the monic linear polynomial with constant coefficient q in a univariate polynomial ring R over the rational field. (If R has not been created before with a name for its indeterminate, $.1-q will be returned.)
The absolute value |q|of a rational number q.
Returns the sign of the rational number q, which is one of the integers -1, 0, 1, corresponding to the cases q<0, q=0, and q>0.
The height of q=r/s. For r and s coprime, the height is defined as the maximum of the absolute value of r and s.
The ceiling of the rational number q, that is, the least integer greater than or equal to q.
The floor of the rational number q, that is, the largest integer less than or equal to q.
This function returns the integer value of the rational number q rounded to the nearest integer. In the case of a tie, rounding is done away from zero (that is, i + (1/2) is rounded to i + 1, for non-negative integers i and i - (1/2) is rounded to i - 1, for non-positive integers i).
This function returns the integer truncation of the rational number q, that is the integral part of q. Thus the effect is that of rounding towards 0.
ContFrac: BoolElt Default: false
Finds a rational approximation d of q such that the denominator of d is bounded by M. If ContFrac is given then an optimal approximation is computed using the continued fraction process. By default d is obtained by some rounding procedure which is faster but gives worse results.
Given a rational r, return the sequence of partial quotients of the continued fraction expansion of r.
Given a continued fraction expansion C, return the rational r such that C equals ContinuedFraction(r).
Given a rational r, return the sequence of partial quotients of the Hirzebruch-Jung continued fraction expansion of r.
Given a Hirzebruch-Jung continued fraction expansion C, return the rational r so that HJContinuedFraction(r) equals C.
Under certain circumstances it is useful to have a partial inverse of the function ψm:Q -> Z/mZ of taking residues modulo m (where the obvious value of ψm is only defined for rational numbers with denominator in smallest terms coprime to m); the partial inverse of the function is sometimes referred to as `rational reconstruction'. For s∈Z/mZ the value of ψ - 1(s) is the rational number r for which ψm(r)=s and, in addition, the absolute values of both the numerator and denominator of r are at most Sqrt(m/2); such r does not always exist, but if r exists it is unique.
Given an element s of a ring S of m elements, return a Boolean flag indicating whether or not a rational number r exists such that for the representation r=n/d in minimal terms it holds that n.d - 1 ≡ s mod m, |n|≤Sqrt(m/2) and 0 < d ≤Sqrt(m/2). If the flag is true, the element r is also returned. The ring S is allowed to be a residue class ring Integers(m) or a finite field of prime cardinality p=m: FiniteField(p).In addition, s is allowed to be a matrix over a prime finite field, in which case the existence (and, if possible, value) of a rational reconstruction of the matrix is determined.
The valuation v of the rational number x at the prime p (the prime ideal I). This is the difference of the valuations of the numerator and denominator of x. The optional second return value is the rational u such that x = pv u.
The sequence [a] for compatibility with the other field types.