12.4 Comparisons of Rationals

q1 = q2
q1 < q2

The equality operator = evaluates to true if the two rationals q1 and q2 are equal and to false otherwise. The inequality operator < evaluates to true if the two rationals q1 and q2 are not equal and to false otherwise.

    gap> 2/3 = -4/-6;
    true
    gap> 66/123 <> 22/41;
    false
    gap> 17/13 = 11;
    false 

q1 < q2
q1 <= q2
q1 q2
q1 = q2

The operators <, <=, , and = evaluate to true if the rational q1 is less than, less than or equal to, greater than, and greater than or equal to the rational q2 and to false otherwise.

One rational q_1 = n_1/d_1 is less than another q_2 = n_2/d_2 if and only if n_1 d_2 < n_2 d_2. This definition is of course only valid because the denominator of rationals is always defined to be positive. This definition also extends to the comparison of rationals with integers, which are interpreted as rationals with denominator 1. Rationals can also be compared with objects of other types. They are smaller than objects of any other type by definition.

    gap> 2/3 < 22/41;
    false
    gap> -17/13 < 11;
    true 

Previous Up Top Next
Index

GAP 3.4.4
April 1997